sdbus-c++  0.8.3
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
36 namespace sdbus {
37  class IConnection;
38 }
39 
40 namespace 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_ */
sdbus::IProxy
Definition: IProxy.h:63
sdbus::ProxyInterfaces
Definition: ProxyInterfaces.h:92
sdbus::ProxyInterfaces::ProxyInterfaces
ProxyInterfaces(IConnection &connection, std::string destination, std::string objectPath)
Creates native-like proxy object instance.
Definition: ProxyInterfaces.h:122
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::ProxyObjectHolder
Definition: ProxyInterfaces.h:51
sdbus::ProxyInterfaces::registerProxy
void registerProxy()
Finishes proxy registration and makes the proxy ready for use.
Definition: ProxyInterfaces.h:151
sdbus::ProxyInterfaces::ProxyInterfaces
ProxyInterfaces(std::string destination, std::string objectPath)
Creates native-like proxy object instance.
Definition: ProxyInterfaces.h:106
sdbus::IConnection
Definition: IConnection.h:47
sdbus::ProxyInterfaces::unregisterProxy
void unregisterProxy()
Unregisters the proxy so it no more receives signals and async call replies.
Definition: ProxyInterfaces.h:163
sdbus::IProxy::finishRegistration
virtual void finishRegistration()=0
Finishes the registration of signal handlers.
sdbus::IProxy::unregister
virtual void unregister()=0
Unregisters proxy's signal handlers and stops receving replies to pending async calls.
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:138
sdbus::IProxy::getObjectPath
virtual const std::string & getObjectPath() const =0
Returns object path of the underlying DBus object.
sdbus::ProxyInterfaces::getObjectPath
const std::string & getObjectPath() const
Returns object path of the underlying DBus object.
Definition: ProxyInterfaces.h:171