sdbus-c++: include/sdbus-c++/AdaptorInterfaces.h Source File

sdbus-c++ 1.3.0 High-level C++ D-Bus library based on systemd D-Bus implementation

Loading...
Searching...
No Matches
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 /********************************************/
50 class ObjectHolder
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>
91 class AdaptorInterfaces
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
117 void registerAdaptor()
118 {
119 getObject().finishRegistration();
120 }
121
129 void unregisterAdaptor()
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
145 AdaptorInterfaces(const AdaptorInterfaces&) = delete;
146 AdaptorInterfaces& operator=(const AdaptorInterfaces&) = delete;
147 AdaptorInterfaces(AdaptorInterfaces&&) = default;
148 AdaptorInterfaces& operator=(AdaptorInterfaces&&) = default;
149 ~AdaptorInterfaces() = default;
150 };
151
152}
153
154#endif /* SDBUS_CXX_ADAPTORINTERFACES_H_ */
IObject.h
sdbus::createObject
std::unique_ptr< sdbus::IObject > createObject(sdbus::IConnection &connection, std::string objectPath)
Creates instance representing a D-Bus object.
sdbus::AdaptorInterfaces
Definition AdaptorInterfaces.h:94
sdbus::AdaptorInterfaces::getObjectPath
const std::string & getObjectPath() const
Returns object path of the underlying DBus object.
Definition AdaptorInterfaces.h:137
sdbus::AdaptorInterfaces::AdaptorInterfaces
AdaptorInterfaces(IConnection &connection, std::string objectPath)
Creates object instance.
Definition AdaptorInterfaces.h:104
sdbus::AdaptorInterfaces::unregisterAdaptor
void unregisterAdaptor()
Unregisters adaptors's API and removes it from the bus.
Definition AdaptorInterfaces.h:129
sdbus::AdaptorInterfaces::registerAdaptor
void registerAdaptor()
Finishes adaptor API registration and publishes the adaptor on the bus.
Definition AdaptorInterfaces.h:117
sdbus::IConnection
Definition IConnection.h:50
sdbus::IObject
Definition IObject.h:60
sdbus::IObject::getObjectPath
virtual const std::string & getObjectPath() const =0
Returns object path of the underlying DBus object.
sdbus::IObject::finishRegistration
virtual void finishRegistration()=0
Finishes object API registration and publishes the object on the bus.
sdbus::IObject::unregister
virtual void unregister()=0
Unregisters object's API and removes object from the bus.
sdbus::ObjectHolder
Definition AdaptorInterfaces.h:51