diff --git a/include/sdbus-c++/AdaptorInterfaces.h b/include/sdbus-c++/AdaptorInterfaces.h index 23ccb52..c64ae00 100644 --- a/include/sdbus-c++/AdaptorInterfaces.h +++ b/include/sdbus-c++/AdaptorInterfaces.h @@ -131,6 +131,14 @@ namespace sdbus { getObject().unregister(); } + /*! + * @brief Returns object path of the underlying DBus object + */ + const std::string& getObjectPath() const + { + return getObject().getObjectPath(); + } + protected: using base_type = AdaptorInterfaces; }; diff --git a/include/sdbus-c++/IObject.h b/include/sdbus-c++/IObject.h index f32e80f..8be06aa 100644 --- a/include/sdbus-c++/IObject.h +++ b/include/sdbus-c++/IObject.h @@ -435,6 +435,11 @@ namespace sdbus { * @throws sdbus::Error in case of failure */ [[nodiscard]] SignalEmitter emitSignal(const std::string& signalName); + + /*! + * @brief Returns object path of the underlying DBus object + */ + virtual const std::string& getObjectPath() const = 0; }; // Out-of-line member definitions diff --git a/include/sdbus-c++/IProxy.h b/include/sdbus-c++/IProxy.h index c317cdf..aaff213 100644 --- a/include/sdbus-c++/IProxy.h +++ b/include/sdbus-c++/IProxy.h @@ -266,6 +266,11 @@ namespace sdbus { * @throws sdbus::Error in case of failure */ [[nodiscard]] PropertySetter setProperty(const std::string& propertyName); + + /*! + * @brief Returns object path of the underlying DBus object + */ + virtual const std::string& getObjectPath() const = 0; }; /********************************************//** diff --git a/include/sdbus-c++/ProxyInterfaces.h b/include/sdbus-c++/ProxyInterfaces.h index 010b10d..406bb16 100644 --- a/include/sdbus-c++/ProxyInterfaces.h +++ b/include/sdbus-c++/ProxyInterfaces.h @@ -165,6 +165,14 @@ namespace sdbus { getProxy().unregister(); } + /*! + * @brief Returns object path of the underlying DBus object + */ + const std::string& getObjectPath() const + { + return getProxy().getObjectPath(); + } + protected: using base_type = ProxyInterfaces; }; diff --git a/src/Object.cpp b/src/Object.cpp index 2a2c54f..c507eaf 100644 --- a/src/Object.cpp +++ b/src/Object.cpp @@ -225,6 +225,11 @@ sdbus::IConnection& Object::getConnection() const return dynamic_cast(connection_); } +const std::string& Object::getObjectPath() const +{ + return objectPath_; +} + const std::vector& Object::createInterfaceVTable(InterfaceData& interfaceData) { auto& vtable = interfaceData.vtable; diff --git a/src/Object.h b/src/Object.h index 1641769..c6dfee2 100644 --- a/src/Object.h +++ b/src/Object.h @@ -101,6 +101,7 @@ namespace sdbus::internal { bool hasObjectManager() const override; sdbus::IConnection& getConnection() const override; + const std::string& getObjectPath() const override; private: using InterfaceName = std::string; diff --git a/src/Proxy.cpp b/src/Proxy.cpp index 568ef8f..839227c 100644 --- a/src/Proxy.cpp +++ b/src/Proxy.cpp @@ -198,6 +198,11 @@ void Proxy::unregister() interfaces_.clear(); } +const std::string& Proxy::getObjectPath() const +{ + return objectPath_; +} + int Proxy::sdbus_async_reply_handler(sd_bus_message *sdbusMessage, void *userData, sd_bus_error */*retError*/) { auto* asyncCallData = static_cast(userData); diff --git a/src/Proxy.h b/src/Proxy.h index dc373a9..b64d8f3 100644 --- a/src/Proxy.h +++ b/src/Proxy.h @@ -60,6 +60,8 @@ namespace sdbus::internal { void finishRegistration() override; void unregister() override; + const std::string& getObjectPath() const override; + private: class SyncCallReplyData {