sdbus-c++ 2.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
26
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} // namespace sdbus
39
40namespace sdbus {
41
42 /********************************************/
50 class ObjectHolder
51 {
52 protected:
53 explicit ObjectHolder(std::unique_ptr<IObject>&& object)
54 : object_(std::move(object))
55 {
56 }
57
58 [[nodiscard]] const IObject& getObject() const
59 {
60 assert(object_ != nullptr);
61 return *object_;
62 }
63
64 [[nodiscard]] 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:
97 AdaptorInterfaces(const AdaptorInterfaces&) = delete;
98 AdaptorInterfaces& operator=(const AdaptorInterfaces&) = delete;
99 AdaptorInterfaces(AdaptorInterfaces&&) = delete;
100 AdaptorInterfaces& operator=(AdaptorInterfaces&&) = delete;
101
110 AdaptorInterfaces(IConnection& connection, ObjectPath objectPath)
111 : ObjectHolder(createObject(connection, std::move(objectPath)))
112 , Interfaces(getObject())...
113 {
114 }
115
123 void registerAdaptor()
124 {
125 (Interfaces::registerAdaptor(), ...);
126 }
127
135 void unregisterAdaptor()
136 {
137 getObject().unregister();
138 }
139
143 using ObjectHolder::getObject;
144
145 protected:
146 using base_type = AdaptorInterfaces;
147
148 ~AdaptorInterfaces() = default;
149 };
150
151} // namespace sdbus
152
153#endif /* SDBUS_CXX_ADAPTORINTERFACES_H_ */
std::unique_ptr< IObject > createObject(IConnection &connection, ObjectPath objectPath)
Creates instance representing a D-Bus object.
Definition IConnection.h:61