sdbus-c++ 2.0.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 /********************************************/
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 /********************************************/
91 template <typename... _Interfaces>
93 : protected ObjectHolder
94 , public _Interfaces...
95 {
96 public:
105 AdaptorInterfaces(IConnection& connection, ObjectPath objectPath)
106 : ObjectHolder(createObject(connection, std::move(objectPath)))
107 , _Interfaces(getObject())...
108 {
109 }
110
119 {
120 (_Interfaces::registerAdaptor(), ...);
121 }
122
131 {
133 }
134
138 using ObjectHolder::getObject;
139
140 protected:
141 using base_type = AdaptorInterfaces;
142
143 AdaptorInterfaces(const AdaptorInterfaces&) = delete;
144 AdaptorInterfaces& operator=(const AdaptorInterfaces&) = delete;
146 AdaptorInterfaces& operator=(AdaptorInterfaces&&) = delete;
147 ~AdaptorInterfaces() = default;
148 };
149
150}
151
152#endif /* SDBUS_CXX_ADAPTORINTERFACES_H_ */
std::unique_ptr< sdbus::IObject > createObject(sdbus::IConnection &connection, ObjectPath objectPath)
Creates instance representing a D-Bus object.
Definition AdaptorInterfaces.h:95
AdaptorInterfaces(IConnection &connection, ObjectPath objectPath)
Creates object instance.
Definition AdaptorInterfaces.h:105
void unregisterAdaptor()
Unregisters adaptors's API and removes it from the bus.
Definition AdaptorInterfaces.h:130
const IObject & getObject() const
Returns reference to the underlying IObject instance.
Definition AdaptorInterfaces.h:58
void registerAdaptor()
Adds object vtable (i.e. D-Bus API) definitions for all interfaces it implements.
Definition AdaptorInterfaces.h:118
Definition IConnection.h:61
Definition IObject.h:63
virtual void unregister()=0
Unregisters object's API and removes object from the bus.
Definition AdaptorInterfaces.h:51
Definition Types.h:177