message: Add get bus function
Function to get the dbus bus from a dbus message.
Forward declare it and implement it in bus.hpp so
that the return type is sdbusplus::bus::bus.
Change-Id: Ice55c8ce484ae1b575e762cc0d9e2826b4ba6504
Signed-off-by: Adriana Kobylak <anoo@us.ibm.com>
diff --git a/sdbusplus/bus.hpp b/sdbusplus/bus.hpp
index d0536d7..5ec1ff7 100644
--- a/sdbusplus/bus.hpp
+++ b/sdbusplus/bus.hpp
@@ -211,4 +211,15 @@
} // namespace bus
+/** @brief Get the dbus bus from the message.
+ *
+ * @return The dbus bus.
+ */
+inline auto message::message::get_bus()
+{
+ sd_bus* b = nullptr;
+ b = sd_bus_message_get_bus(_msg.get());
+ return bus::bus(sd_bus_ref(b));
+}
+
} // namespace sdbusplus
diff --git a/sdbusplus/message.hpp b/sdbusplus/message.hpp
index 7ef81e6..8c9414e 100644
--- a/sdbusplus/message.hpp
+++ b/sdbusplus/message.hpp
@@ -96,6 +96,10 @@
sdbusplus::message::read(_msg.get(), std::forward<Args>(args)...);
}
+ /** @brief Get the dbus bus from the message. */
+ // Forward declare.
+ auto get_bus();
+
/** @brief Get the signature of a message.
*
* @return A [weak] pointer to the signature of the message.