From 94fd3c88d8dba42263ed4badfd629659ec5b3f2b Mon Sep 17 00:00:00 2001 From: Stanislav Angelovic Date: Thu, 4 Apr 2019 20:39:03 +0200 Subject: [PATCH] Add getConnection() method to IObject so we ask Object about its connection --- include/sdbus-c++/IObject.h | 7 +++++++ include/sdbus-c++/Interfaces.h | 4 ++-- src/Object.cpp | 5 +++++ src/Object.h | 2 ++ 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/include/sdbus-c++/IObject.h b/include/sdbus-c++/IObject.h index 5b48c0d..bb3856f 100644 --- a/include/sdbus-c++/IObject.h +++ b/include/sdbus-c++/IObject.h @@ -173,6 +173,13 @@ namespace sdbus { */ virtual void emitSignal(const sdbus::Signal& message) = 0; + /*! + * @brief Provides D-Bus connection used by the object + * + * @return Reference to the D-Bus connection + */ + virtual sdbus::IConnection& getConnection() const = 0; + /*! * @brief Registers method that the object will provide on D-Bus * diff --git a/include/sdbus-c++/Interfaces.h b/include/sdbus-c++/Interfaces.h index 2d0e6ac..1bc547a 100644 --- a/include/sdbus-c++/Interfaces.h +++ b/include/sdbus-c++/Interfaces.h @@ -74,7 +74,7 @@ namespace sdbus { ***********************************************/ template class Interfaces - : private ObjectHolder + : protected ObjectHolder , public _Interfaces... { public: @@ -96,7 +96,7 @@ namespace sdbus { ***********************************************/ template class ProxyInterfaces - : private ObjectHolder + : protected ObjectHolder , public _Interfaces... { public: diff --git a/src/Object.cpp b/src/Object.cpp index c364972..6361601 100644 --- a/src/Object.cpp +++ b/src/Object.cpp @@ -130,6 +130,11 @@ void Object::emitSignal(const sdbus::Signal& message) message.send(); } +sdbus::IConnection& Object::getConnection() const +{ + return dynamic_cast(connection_); +} + const std::vector& Object::createInterfaceVTable(InterfaceData& interfaceData) { auto& vtable = interfaceData.vtable_; diff --git a/src/Object.h b/src/Object.h index 5baeb7b..6ee54ff 100644 --- a/src/Object.h +++ b/src/Object.h @@ -77,6 +77,8 @@ namespace internal { sdbus::Signal createSignal(const std::string& interfaceName, const std::string& signalName) override; void emitSignal(const sdbus::Signal& message) override; + sdbus::IConnection& getConnection() const override; + private: using InterfaceName = std::string; struct InterfaceData