sdbus-c++ 1.2.0
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
36namespace sdbus {
37 class IConnection;
38}
39
40namespace 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
137 const std::string& getObjectPath() const
138 {
139 return getObject().getObjectPath();
140 }
141
142 protected:
143 using base_type = AdaptorInterfaces;
144 ~AdaptorInterfaces() = default;
145 };
146
147}
148
149#endif /* SDBUS_CXX_ADAPTORINTERFACES_H_ */
std::unique_ptr< sdbus::IObject > createObject(sdbus::IConnection &connection, std::string objectPath)
Creates instance representing a D-Bus object.
Definition: AdaptorInterfaces.h:94
const std::string & getObjectPath() const
Returns object path of the underlying DBus object.
Definition: AdaptorInterfaces.h:137
AdaptorInterfaces(IConnection &connection, std::string objectPath)
Creates object instance.
Definition: AdaptorInterfaces.h:104
void unregisterAdaptor()
Unregisters adaptors's API and removes it from the bus.
Definition: AdaptorInterfaces.h:129
void registerAdaptor()
Finishes adaptor API registration and publishes the adaptor on the bus.
Definition: AdaptorInterfaces.h:117
Definition: IConnection.h:50
Definition: IObject.h:60
virtual const std::string & getObjectPath() const =0
Returns object path of the underlying DBus object.
virtual void finishRegistration()=0
Finishes object API registration and publishes the object on the bus.
virtual void unregister()=0
Unregisters object's API and removes object from the bus.
Definition: AdaptorInterfaces.h:51