sdbus-c++ 1.2.0
High-level C++ D-Bus library based on systemd D-Bus implementation
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
122 ProxyInterfaces(IConnection& connection, std::string destination, std::string objectPath)
123 : ProxyObjectHolder(createProxy(connection, std::move(destination), std::move(objectPath)))
124 , _Interfaces(getProxy())...
125 {
126 }
127
138 ProxyInterfaces(std::unique_ptr<sdbus::IConnection>&& connection, std::string destination, std::string objectPath)
139 : ProxyObjectHolder(createProxy(std::move(connection), std::move(destination), std::move(objectPath)))
140 , _Interfaces(getProxy())...
141 {
142 }
143
152 {
153 getProxy().finishRegistration();
154 }
155
164 {
165 getProxy().unregister();
166 }
167
171 const std::string& getObjectPath() const
172 {
173 return getProxy().getObjectPath();
174 }
175
176 protected:
177 using base_type = ProxyInterfaces;
178 ~ProxyInterfaces() = default;
179 };
180
181}
182
183#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:50
Definition: IProxy.h:64
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:163
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:151
ProxyInterfaces(IConnection &connection, std::string destination, std::string objectPath)
Creates native-like proxy object instance.
Definition: ProxyInterfaces.h:122
const std::string & getObjectPath() const
Returns object path of the underlying DBus object.
Definition: ProxyInterfaces.h:171
ProxyInterfaces(std::unique_ptr< sdbus::IConnection > &&connection, std::string destination, std::string objectPath)
Creates native-like proxy object instance.
Definition: ProxyInterfaces.h:138
Definition: ProxyInterfaces.h:52