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

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

Loading...
Searching...
No Matches
ConvenienceApiClasses.h
Go to the documentation of this file.
1
27#ifndef SDBUS_CXX_CONVENIENCEAPICLASSES_H_
28#define SDBUS_CXX_CONVENIENCEAPICLASSES_H_
29
30#include <sdbus-c++/Message.h>
31#include <sdbus-c++/TypeTraits.h>
32#include <sdbus-c++/Flags.h>
33#include <string>
34#include <vector>
35#include <type_traits>
36#include <chrono>
37#include <future>
38#include <cstdint>
39
40// Forward declarations
41namespace sdbus {
42 class IObject;
43 class IProxy;
44 class Variant;
45 class Error;
46 class PendingAsyncCall;
47}
48
49namespace sdbus {
50
51 class MethodRegistrator
52 {
53 public:
54 MethodRegistrator(IObject& object, std::string methodName);
55 MethodRegistrator(MethodRegistrator&& other) = default;
56 ~MethodRegistrator() noexcept(false);
57
58 MethodRegistrator& onInterface(std::string interfaceName);
59 template <typename _Function> MethodRegistrator& implementedAs(_Function&& callback);
60 MethodRegistrator& withInputParamNames(std::vector<std::string> paramNames);
61 template <typename... _String> MethodRegistrator& withInputParamNames(_String... paramNames);
62 MethodRegistrator& withOutputParamNames(std::vector<std::string> paramNames);
63 template <typename... _String> MethodRegistrator& withOutputParamNames(_String... paramNames);
64 MethodRegistrator& markAsDeprecated();
65 MethodRegistrator& markAsPrivileged();
66 MethodRegistrator& withNoReply();
67
68 private:
69 IObject& object_;
70 std::string methodName_;
71 std::string interfaceName_;
72 std::string inputSignature_;
73 std::vector<std::string> inputParamNames_;
74 std::string outputSignature_;
75 std::vector<std::string> outputParamNames_;
76 method_callback methodCallback_;
77 Flags flags_;
78 int exceptions_{}; // Number of active exceptions when SignalRegistrator is constructed
79 };
80
81 class SignalRegistrator
82 {
83 public:
84 SignalRegistrator(IObject& object, std::string signalName);
85 SignalRegistrator(SignalRegistrator&& other) = default;
86 ~SignalRegistrator() noexcept(false);
87
88 SignalRegistrator& onInterface(std::string interfaceName);
89 template <typename... _Args> SignalRegistrator& withParameters();
90 template <typename... _Args> SignalRegistrator& withParameters(std::vector<std::string> paramNames);
91 template <typename... _Args, typename... _String> SignalRegistrator& withParameters(_String... paramNames);
92 SignalRegistrator& markAsDeprecated();
93
94 private:
95 IObject& object_;
96 std::string signalName_;
97 std::string interfaceName_;
98 std::string signalSignature_;
99 std::vector<std::string> paramNames_;
100 Flags flags_;
101 int exceptions_{}; // Number of active exceptions when SignalRegistrator is constructed
102 };
103
104 class PropertyRegistrator
105 {
106 public:
107 PropertyRegistrator(IObject& object, const std::string& propertyName);
108 PropertyRegistrator(PropertyRegistrator&& other) = default;
109 ~PropertyRegistrator() noexcept(false);
110
111 PropertyRegistrator& onInterface(std::string interfaceName);
112 template <typename _Function> PropertyRegistrator& withGetter(_Function&& callback);
113 template <typename _Function> PropertyRegistrator& withSetter(_Function&& callback);
114 PropertyRegistrator& markAsDeprecated();
115 PropertyRegistrator& markAsPrivileged();
116 PropertyRegistrator& withUpdateBehavior(Flags::PropertyUpdateBehaviorFlags behavior);
117
118 private:
119 IObject& object_;
120 const std::string& propertyName_;
121 std::string interfaceName_;
122 std::string propertySignature_;
123 property_get_callback getter_;
124 property_set_callback setter_;
125 Flags flags_;
126 int exceptions_{}; // Number of active exceptions when PropertyRegistrator is constructed
127 };
128
129 class InterfaceFlagsSetter
130 {
131 public:
132 InterfaceFlagsSetter(IObject& object, const std::string& interfaceName);
133 InterfaceFlagsSetter(InterfaceFlagsSetter&& other) = default;
134 ~InterfaceFlagsSetter() noexcept(false);
135
136 InterfaceFlagsSetter& markAsDeprecated();
137 InterfaceFlagsSetter& markAsPrivileged();
138 InterfaceFlagsSetter& withNoReplyMethods();
139 InterfaceFlagsSetter& withPropertyUpdateBehavior(Flags::PropertyUpdateBehaviorFlags behavior);
140
141 private:
142 IObject& object_;
143 const std::string& interfaceName_;
144 Flags flags_;
145 int exceptions_{}; // Number of active exceptions when InterfaceFlagsSetter is constructed
146 };
147
148 class SignalEmitter
149 {
150 public:
151 SignalEmitter(IObject& object, const std::string& signalName);
152 SignalEmitter(SignalEmitter&& other) = default;
153 ~SignalEmitter() noexcept(false);
154 SignalEmitter& onInterface(const std::string& interfaceName);
155 template <typename... _Args> void withArguments(_Args&&... args);
156
157 private:
158 IObject& object_;
159 const std::string& signalName_;
160 Signal signal_;
161 int exceptions_{}; // Number of active exceptions when SignalEmitter is constructed
162 };
163
164 class MethodInvoker
165 {
166 public:
167 MethodInvoker(IProxy& proxy, const std::string& methodName);
168 MethodInvoker(MethodInvoker&& other) = default;
169 ~MethodInvoker() noexcept(false);
170
171 MethodInvoker& onInterface(const std::string& interfaceName);
172 MethodInvoker& withTimeout(uint64_t usec);
173 template <typename _Rep, typename _Period>
174 MethodInvoker& withTimeout(const std::chrono::duration<_Rep, _Period>& timeout);
175 template <typename... _Args> MethodInvoker& withArguments(_Args&&... args);
176 template <typename... _Args> void storeResultsTo(_Args&... args);
177
178 void dontExpectReply();
179
180 private:
181 IProxy& proxy_;
182 const std::string& methodName_;
183 uint64_t timeout_{};
184 MethodCall method_;
185 int exceptions_{}; // Number of active exceptions when MethodInvoker is constructed
186 bool methodCalled_{};
187 };
188
189 class AsyncMethodInvoker
190 {
191 public:
192 AsyncMethodInvoker(IProxy& proxy, const std::string& methodName);
193 AsyncMethodInvoker& onInterface(const std::string& interfaceName);
194 AsyncMethodInvoker& withTimeout(uint64_t usec);
195 template <typename _Rep, typename _Period>
196 AsyncMethodInvoker& withTimeout(const std::chrono::duration<_Rep, _Period>& timeout);
197 template <typename... _Args> AsyncMethodInvoker& withArguments(_Args&&... args);
198 template <typename _Function> PendingAsyncCall uponReplyInvoke(_Function&& callback);
199 // Returned future will be std::future<void> for no (void) D-Bus method return value
200 // or std::future<T> for single D-Bus method return value
201 // or std::future<std::tuple<...>> for multiple method return values
202 template <typename... _Args> std::future<future_return_t<_Args...>> getResultAsFuture();
203
204 private:
205 IProxy& proxy_;
206 const std::string& methodName_;
207 uint64_t timeout_{};
208 MethodCall method_;
209 };
210
211 class SignalSubscriber
212 {
213 public:
214 SignalSubscriber(IProxy& proxy, const std::string& signalName);
215 SignalSubscriber& onInterface(std::string interfaceName);
216 template <typename _Function> void call(_Function&& callback);
217
218 private:
219 IProxy& proxy_;
220 const std::string& signalName_;
221 std::string interfaceName_;
222 };
223
224 class SignalUnsubscriber
225 {
226 public:
227 SignalUnsubscriber(IProxy& proxy, const std::string& signalName);
228 void onInterface(std::string interfaceName);
229
230 private:
231 IProxy& proxy_;
232 const std::string& signalName_;
233 };
234
235 class PropertyGetter
236 {
237 public:
238 PropertyGetter(IProxy& proxy, const std::string& propertyName);
239 sdbus::Variant onInterface(const std::string& interfaceName);
240
241 private:
242 IProxy& proxy_;
243 const std::string& propertyName_;
244 };
245
246 class PropertySetter
247 {
248 public:
249 PropertySetter(IProxy& proxy, const std::string& propertyName);
250 PropertySetter& onInterface(std::string interfaceName);
251 template <typename _Value> void toValue(const _Value& value);
252 void toValue(const sdbus::Variant& value);
253
254 private:
255 IProxy& proxy_;
256 const std::string& propertyName_;
257 std::string interfaceName_;
258 };
259
260}
261
262#endif /* SDBUS_CXX_CONVENIENCEAPICLASSES_H_ */
Flags.h
Message.h
TypeTraits.h
sdbus::AsyncMethodInvoker
Definition ConvenienceApiClasses.h:190
sdbus::Flags
Definition Flags.h:37
sdbus::IObject
Definition IObject.h:60
sdbus::IProxy
Definition IProxy.h:66
sdbus::InterfaceFlagsSetter
Definition ConvenienceApiClasses.h:130
sdbus::MethodCall
Definition Message.h:232
sdbus::MethodInvoker
Definition ConvenienceApiClasses.h:165
sdbus::MethodRegistrator
Definition ConvenienceApiClasses.h:52
sdbus::PendingAsyncCall
Definition IProxy.h:367
sdbus::PropertyGetter
Definition ConvenienceApiClasses.h:236
sdbus::PropertyRegistrator
Definition ConvenienceApiClasses.h:105
sdbus::PropertySetter
Definition ConvenienceApiClasses.h:247
sdbus::SignalEmitter
Definition ConvenienceApiClasses.h:149
sdbus::SignalRegistrator
Definition ConvenienceApiClasses.h:82
sdbus::SignalSubscriber
Definition ConvenienceApiClasses.h:212
sdbus::SignalUnsubscriber
Definition ConvenienceApiClasses.h:225
sdbus::Signal
Definition Message.h:270
sdbus::Variant
Definition Types.h:54