sdbus-c++: include/sdbus-c++/ProxyInterfaces.h Source File

sdbus-c++ 1.3.0 High-level C++ D-Bus library based on systemd D-Bus implementation

Loading...
Searching...
No Matches
ProxyInterfaces.h
Go to the documentation of this file.
1
27#ifndef SDBUS_CXX_PROXYINTERFACES_H_
28#define SDBUS_CXX_PROXYINTERFACES_H_
29
30#include <sdbus-c++/IProxy.h>
31#include <cassert>
32#include <string>
33#include <memory>
34
35// Forward declarations
36namespace sdbus {
37 class IConnection;
38}
39
40namespace sdbus {
41
42 /********************************************/
51 class ProxyObjectHolder
52 {
53 protected:
54 ProxyObjectHolder(std::unique_ptr<IProxy>&& proxy)
55 : proxy_(std::move(proxy))
56 {
57 assert(proxy_ != nullptr);
58 }
59
60 const IProxy& getProxy() const
61 {
62 assert(proxy_ != nullptr);
63 return *proxy_;
64 }
65
66 IProxy& getProxy()
67 {
68 assert(proxy_ != nullptr);
69 return *proxy_;
70 }
71
72 private:
73 std::unique_ptr<IProxy> proxy_;
74 };
75
76 /********************************************/
91 template <typename... _Interfaces>
92 class ProxyInterfaces
93 : protected ProxyObjectHolder
94 , public _Interfaces...
95 {
96 public:
106 ProxyInterfaces(std::string destination, std::string objectPath)
107 : ProxyObjectHolder(createProxy(std::move(destination), std::move(objectPath)))
108 , _Interfaces(getProxy())...
109 {
110 }
111
121 ProxyInterfaces(std::string destination, std::string objectPath, dont_run_event_loop_thread_t)
122 : ProxyObjectHolder(createProxy(std::move(destination), std::move(objectPath), dont_run_event_loop_thread))
123 , _Interfaces(getProxy())...
124 {
125 }
126
137 ProxyInterfaces(IConnection& connection, std::string destination, std::string objectPath)
138 : ProxyObjectHolder(createProxy(connection, std::move(destination), std::move(objectPath)))
139 , _Interfaces(getProxy())...
140 {
141 }
142
153 ProxyInterfaces(std::unique_ptr<sdbus::IConnection>&& connection, std::string destination, std::string objectPath)
154 : ProxyObjectHolder(createProxy(std::move(connection), std::move(destination), std::move(objectPath)))
155 , _Interfaces(getProxy())...
156 {
157 }
158
169 ProxyInterfaces(std::unique_ptr<sdbus::IConnection>&& connection, std::string destination, std::string objectPath, dont_run_event_loop_thread_t)
170 : ProxyObjectHolder(createProxy(std::move(connection), std::move(destination), std::move(objectPath), dont_run_event_loop_thread))
171 , _Interfaces(getProxy())...
172 {
173 }
174
182 void registerProxy()
183 {
184 getProxy().finishRegistration();
185 }
186
194 void unregisterProxy()
195 {
196 getProxy().unregister();
197 }
198
202 const std::string& getObjectPath() const
203 {
204 return getProxy().getObjectPath();
205 }
206
207 protected:
208 using base_type = ProxyInterfaces;
209
210 ProxyInterfaces(const ProxyInterfaces&) = delete;
211 ProxyInterfaces& operator=(const ProxyInterfaces&) = delete;
212 ProxyInterfaces(ProxyInterfaces&&) = default;
213 ProxyInterfaces& operator=(ProxyInterfaces&&) = default;
214 ~ProxyInterfaces() = default;
215 };
216
217}
218
219#endif /* SDBUS_CXX_INTERFACES_H_ */
IProxy.h
sdbus::createProxy
std::unique_ptr< sdbus::IProxy > createProxy(sdbus::IConnection &connection, std::string destination, std::string objectPath)
Creates a proxy object for a specific remote D-Bus object.
sdbus::IConnection
Definition IConnection.h:50
sdbus::IProxy
Definition IProxy.h:66
sdbus::IProxy::getObjectPath
virtual const std::string & getObjectPath() const =0
Returns object path of the underlying DBus object.
sdbus::IProxy::unregister
virtual void unregister()=0
Unregisters proxy's signal handlers and stops receving replies to pending async calls.
sdbus::IProxy::finishRegistration
virtual void finishRegistration()=0
Finishes the registration of signal handlers.
sdbus::ProxyInterfaces
Definition ProxyInterfaces.h:95
sdbus::ProxyInterfaces::unregisterProxy
void unregisterProxy()
Unregisters the proxy so it no more receives signals and async call replies.
Definition ProxyInterfaces.h:194
sdbus::ProxyInterfaces::ProxyInterfaces
ProxyInterfaces(std::string destination, std::string objectPath)
Creates native-like proxy object instance.
Definition ProxyInterfaces.h:106
sdbus::ProxyInterfaces::registerProxy
void registerProxy()
Finishes proxy registration and makes the proxy ready for use.
Definition ProxyInterfaces.h:182
sdbus::ProxyInterfaces::ProxyInterfaces
ProxyInterfaces(std::string destination, std::string objectPath, dont_run_event_loop_thread_t)
Creates native-like proxy object instance.
Definition ProxyInterfaces.h:121
sdbus::ProxyInterfaces::ProxyInterfaces
ProxyInterfaces(IConnection &connection, std::string destination, std::string objectPath)
Creates native-like proxy object instance.
Definition ProxyInterfaces.h:137
sdbus::ProxyInterfaces::getObjectPath
const std::string & getObjectPath() const
Returns object path of the underlying DBus object.
Definition ProxyInterfaces.h:202
sdbus::ProxyInterfaces::ProxyInterfaces
ProxyInterfaces(std::unique_ptr< sdbus::IConnection > &&connection, std::string destination, std::string objectPath, dont_run_event_loop_thread_t)
Creates native-like proxy object instance.
Definition ProxyInterfaces.h:169
sdbus::ProxyInterfaces::ProxyInterfaces
ProxyInterfaces(std::unique_ptr< sdbus::IConnection > &&connection, std::string destination, std::string objectPath)
Creates native-like proxy object instance.
Definition ProxyInterfaces.h:153
sdbus::ProxyObjectHolder
Definition ProxyInterfaces.h:52
sdbus::dont_run_event_loop_thread_t
Definition TypeTraits.h:91