sdbus-c++ 2.1.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 /********************************************/
91 template <typename... _Interfaces>
92 class AdaptorInterfaces
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
118 void registerAdaptor()
119 {
120 (_Interfaces::registerAdaptor(), ...);
121 }
122
130 void unregisterAdaptor()
131 {
132 getObject().unregister();
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;
145 AdaptorInterfaces(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.