match: add signal callback registerer
Change-Id: I833e32360391cef8acbb8268e239fbc047173835
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
diff --git a/sdbusplus/bus.hpp b/sdbusplus/bus.hpp
index 84f45ce..b814380 100644
--- a/sdbusplus/bus.hpp
+++ b/sdbusplus/bus.hpp
@@ -12,6 +12,7 @@
namespace server { namespace interface { struct interface; } }
namespace server { namespace manager { struct manager; } }
namespace server { namespace object { template<class...> struct object; } }
+namespace server { namespace match { struct match; } }
namespace bus
{
@@ -169,6 +170,7 @@
friend struct server::interface::interface;
friend struct server::manager::manager;
template<class... Args> friend struct server::object::object;
+ friend struct server::match::match;
private:
busp_t get() { return _bus.get(); }
diff --git a/sdbusplus/server.hpp b/sdbusplus/server.hpp
index 6ec9757..bbea03b 100644
--- a/sdbusplus/server.hpp
+++ b/sdbusplus/server.hpp
@@ -6,3 +6,4 @@
#include <sdbusplus/server/interface.hpp>
#include <sdbusplus/server/manager.hpp>
#include <sdbusplus/server/object.hpp>
+#include <sdbusplus/server/match.hpp>
diff --git a/sdbusplus/server/match.hpp b/sdbusplus/server/match.hpp
new file mode 100644
index 0000000..e7902f6
--- /dev/null
+++ b/sdbusplus/server/match.hpp
@@ -0,0 +1,56 @@
+#pragma once
+
+#include <sdbusplus/slot.hpp>
+#include <sdbusplus/bus.hpp>
+
+namespace sdbusplus
+{
+
+namespace server
+{
+
+namespace match
+{
+
+struct match
+{
+ /* Define all of the basic class operations:
+ * Not allowed:
+ * - Default constructor to avoid nullptrs.
+ * - Copy operations due to internal unique_ptr.
+ * Allowed:
+ * - Move operations.
+ * - Destructor.
+ */
+ match() = delete;
+ match(const match&) = delete;
+ match& operator=(const match&) = delete;
+ match(match&&) = default;
+ match& operator=(match&&) = default;
+ ~match() = default;
+
+ /** @brief Register a signal match.
+ *
+ * @param[in] bus - The bus to register on.
+ * @param[in] match - The match to register.
+ * @param[in] handler - The callback for matches.
+ */
+ match(sdbusplus::bus::bus& bus, const char* match,
+ sd_bus_message_handler_t handler) : _slot(nullptr)
+ {
+ sd_bus_slot* slot = nullptr;
+ sd_bus_add_match(bus.get(), &slot, match, handler, nullptr);
+
+ _slot = decltype(_slot){slot};
+ }
+
+ private:
+ slot::slot _slot;
+};
+
+} // namespace match
+
+using match_t = match::match;
+
+} // namespace server
+} // namespace sdbusplus