sdbus-c++  0.8.1
High-level C++ D-Bus library based on systemd D-Bus implementation
AdaptorInterfaces.h
Go to the documentation of this file.
1 
27 #ifndef SDBUS_CXX_ADAPTORINTERFACES_H_
28 #define SDBUS_CXX_ADAPTORINTERFACES_H_
29 
30 #include <sdbus-c++/IObject.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  /********************************************/
51  {
52  protected:
53  ObjectHolder(std::unique_ptr<IObject>&& object)
54  : object_(std::move(object))
55  {
56  }
57 
58  const IObject& getObject() const
59  {
60  assert(object_ != nullptr);
61  return *object_;
62  }
63 
64  IObject& getObject()
65  {
66  assert(object_ != nullptr);
67  return *object_;
68  }
69 
70  private:
71  std::unique_ptr<IObject> object_;
72  };
73 
74  /********************************************/
90  template <typename... _Interfaces>
92  : protected ObjectHolder
93  , public _Interfaces...
94  {
95  public:
104  AdaptorInterfaces(IConnection& connection, std::string objectPath)
105  : ObjectHolder(createObject(connection, std::move(objectPath)))
106  , _Interfaces(getObject())...
107  {
108  }
109 
118  {
119  getObject().finishRegistration();
120  }
121 
130  {
131  getObject().unregister();
132  }
133 
134  protected:
135  using base_type = AdaptorInterfaces;
136  };
137 
138 }
139 
140 #endif /* SDBUS_CXX_ADAPTORINTERFACES_H_ */
sdbus::IObject::finishRegistration
virtual void finishRegistration()=0
Finishes object API registration and publishes the object on the bus.
sdbus::AdaptorInterfaces::unregisterAdaptor
void unregisterAdaptor()
Unregisters adaptors's API and removes it from the bus.
Definition: AdaptorInterfaces.h:129
sdbus::AdaptorInterfaces::AdaptorInterfaces
AdaptorInterfaces(IConnection &connection, std::string objectPath)
Creates object instance.
Definition: AdaptorInterfaces.h:104
sdbus::IObject::unregister
virtual void unregister()=0
Unregisters object's API and removes object from the bus.
IObject.h
sdbus::IObject
Definition: IObject.h:59
sdbus::createObject
std::unique_ptr< sdbus::IObject > createObject(sdbus::IConnection &connection, std::string objectPath)
Creates instance representing a D-Bus object.
sdbus::IConnection
Definition: IConnection.h:47
sdbus::AdaptorInterfaces::registerAdaptor
void registerAdaptor()
Finishes adaptor API registration and publishes the adaptor on the bus.
Definition: AdaptorInterfaces.h:117
sdbus::ObjectHolder
Definition: AdaptorInterfaces.h:50
sdbus::AdaptorInterfaces
Definition: AdaptorInterfaces.h:91