sdbus-c++ 2.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
26
27#ifndef SDBUS_CXX_PROXYINTERFACES_H_
28#define SDBUS_CXX_PROXYINTERFACES_H_
29
30#include <sdbus-c++/IProxy.h>
31#include <cassert>
32#include <memory>
33
34// Forward declarations
35namespace sdbus {
36 class IConnection;
37} // namespace sdbus
38
39namespace sdbus {
40
41 /********************************************/
50 class ProxyObjectHolder
51 {
52 protected:
53 explicit ProxyObjectHolder(std::unique_ptr<IProxy>&& proxy)
54 : proxy_(std::move(proxy))
55 {
56 assert(proxy_ != nullptr);
57 }
58
59 [[nodiscard]] const IProxy& getProxy() const
60 {
61 assert(proxy_ != nullptr);
62 return *proxy_;
63 }
64
65 [[nodiscard]] IProxy& getProxy()
66 {
67 assert(proxy_ != nullptr);
68 return *proxy_;
69 }
70
71 private:
72 std::unique_ptr<IProxy> proxy_;
73 };
74
75 /********************************************/
91 template <typename... Interfaces>
92 class ProxyInterfaces
93 : protected ProxyObjectHolder
94 , public Interfaces...
95 {
96 public:
97 ProxyInterfaces(const ProxyInterfaces&) = delete;
98 ProxyInterfaces& operator=(const ProxyInterfaces&) = delete;
99 ProxyInterfaces(ProxyInterfaces&&) = delete;
100 ProxyInterfaces& operator=(ProxyInterfaces&&) = delete;
101
111 ProxyInterfaces(ServiceName destination, ObjectPath objectPath)
112 : ProxyObjectHolder(createProxy(std::move(destination), std::move(objectPath)))
113 , Interfaces(getProxy())...
114 {
115 }
116
126 ProxyInterfaces(ServiceName destination, ObjectPath objectPath, dont_run_event_loop_thread_t)
127 : ProxyObjectHolder(createProxy(std::move(destination), std::move(objectPath), dont_run_event_loop_thread))
128 , Interfaces(getProxy())...
129 {
130 }
131
142 ProxyInterfaces(IConnection& connection, ServiceName destination, ObjectPath objectPath)
143 : ProxyObjectHolder(createProxy(connection, std::move(destination), std::move(objectPath)))
144 , Interfaces(getProxy())...
145 {
146 }
147
158 ProxyInterfaces(std::unique_ptr<IConnection>&& connection, ServiceName destination, ObjectPath objectPath)
159 : ProxyObjectHolder(createProxy(std::move(connection), std::move(destination), std::move(objectPath)))
160 , Interfaces(getProxy())...
161 {
162 }
163
174 ProxyInterfaces(std::unique_ptr<IConnection>&& connection, ServiceName destination, ObjectPath objectPath, dont_run_event_loop_thread_t)
175 : ProxyObjectHolder(createProxy(std::move(connection), std::move(destination), std::move(objectPath), dont_run_event_loop_thread))
176 , Interfaces(getProxy())...
177 {
178 }
179
188 {
189 (Interfaces::registerProxy(), ...);
190 }
191
200 {
202 }
203
207 using ProxyObjectHolder::getProxy;
208
209 protected:
210 using base_type = ProxyInterfaces;
211
212 ~ProxyInterfaces() = default;
213 };
214
215} // namespace sdbus
216
217#endif /* SDBUS_CXX_PROXYINTERFACES_H_ */
std::unique_ptr< IProxy > createProxy(IConnection &connection, ServiceName destination, ObjectPath objectPath)
Creates a proxy object for a specific remote D-Bus object.
Definition IConnection.h:61
Definition IProxy.h:70
virtual void unregister()=0
Unregisters proxy's signal handlers and stops receiving replies to pending async calls.
Definition Types.h:208
Definition ProxyInterfaces.h:95
void registerProxy()
Registers handlers for D-Bus signals of the remote object.
Definition ProxyInterfaces.h:187
ProxyInterfaces(std::unique_ptr< IConnection > &&connection, ServiceName destination, ObjectPath objectPath, dont_run_event_loop_thread_t)
Creates native-like proxy object instance.
Definition ProxyInterfaces.h:174
ProxyInterfaces(ServiceName destination, ObjectPath objectPath, dont_run_event_loop_thread_t)
Creates native-like proxy object instance.
Definition ProxyInterfaces.h:126
ProxyInterfaces(ServiceName destination, ObjectPath objectPath)
Creates native-like proxy object instance.
Definition ProxyInterfaces.h:111
ProxyInterfaces(std::unique_ptr< IConnection > &&connection, ServiceName destination, ObjectPath objectPath)
Creates native-like proxy object instance.
Definition ProxyInterfaces.h:158
void unregisterProxy()
Unregisters the proxy so it no more receives signals and async call replies.
Definition ProxyInterfaces.h:199
ProxyInterfaces(IConnection &connection, ServiceName destination, ObjectPath objectPath)
Creates native-like proxy object instance.
Definition ProxyInterfaces.h:142
const IProxy & getProxy() const
Returns reference to the underlying IProxy instance.
Definition ProxyInterfaces.h:59
Definition TypeTraits.h:101