sdbus-c++ 1.5.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 /********************************************/
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>
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
183 {
184 getProxy().finishRegistration();
185 }
186
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_ */
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.
Definition IConnection.h:52
Definition IProxy.h:66
virtual const std::string & getObjectPath() const =0
Returns object path of the underlying DBus object.
virtual void unregister()=0
Unregisters proxy's signal handlers and stops receving replies to pending async calls.
virtual void finishRegistration()=0
Finishes the registration of signal handlers.
Definition ProxyInterfaces.h:95
void unregisterProxy()
Unregisters the proxy so it no more receives signals and async call replies.
Definition ProxyInterfaces.h:194
ProxyInterfaces(std::string destination, std::string objectPath)
Creates native-like proxy object instance.
Definition ProxyInterfaces.h:106
void registerProxy()
Finishes proxy registration and makes the proxy ready for use.
Definition ProxyInterfaces.h:182
ProxyInterfaces(std::string destination, std::string objectPath, dont_run_event_loop_thread_t)
Creates native-like proxy object instance.
Definition ProxyInterfaces.h:121
ProxyInterfaces(IConnection &connection, std::string destination, std::string objectPath)
Creates native-like proxy object instance.
Definition ProxyInterfaces.h:137
const std::string & getObjectPath() const
Returns object path of the underlying DBus object.
Definition ProxyInterfaces.h:202
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
ProxyInterfaces(std::unique_ptr< sdbus::IConnection > &&connection, std::string destination, std::string objectPath)
Creates native-like proxy object instance.
Definition ProxyInterfaces.h:153
Definition ProxyInterfaces.h:52
Definition TypeTraits.h:91