sdbus-c++ 1.5.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>
32#include <sdbus-c++/Types.h>
33#include <sdbus-c++/Flags.h>
34#include <string>
35#include <vector>
36#include <type_traits>
37#include <chrono>
38#include <future>
39#include <cstdint>
40
41// Forward declarations
42namespace sdbus {
43 class IObject;
44 class IProxy;
45 class Error;
46 class PendingAsyncCall;
47}
48
49namespace sdbus {
50
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
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
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
130 {
131 public:
132 InterfaceFlagsSetter(IObject& object, const std::string& interfaceName);
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
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
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
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
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
225 {
226 public:
227 SignalUnsubscriber(IProxy& proxy, const std::string& signalName);
228 void onInterface(const std::string& interfaceName);
229
230 private:
231 IProxy& proxy_;
232 const std::string& signalName_;
233 };
234
236 {
237 public:
238 PropertyGetter(IProxy& proxy, const std::string& propertyName);
239 Variant onInterface(const std::string& interfaceName);
240
241 private:
242 IProxy& proxy_;
243 const std::string& propertyName_;
244 };
245
247 {
248 public:
249 AsyncPropertyGetter(IProxy& proxy, const std::string& propertyName);
250 AsyncPropertyGetter& onInterface(const std::string& interfaceName);
251 template <typename _Function> PendingAsyncCall uponReplyInvoke(_Function&& callback);
252 std::future<Variant> getResultAsFuture();
253
254 private:
255 IProxy& proxy_;
256 const std::string& propertyName_;
257 const std::string* interfaceName_{};
258 };
259
261 {
262 public:
263 PropertySetter(IProxy& proxy, const std::string& propertyName);
264 PropertySetter& onInterface(const std::string& interfaceName);
265 template <typename _Value> void toValue(const _Value& value);
266 template <typename _Value> void toValue(const _Value& value, dont_expect_reply_t);
267 void toValue(const Variant& value);
268 void toValue(const Variant& value, dont_expect_reply_t);
269
270 private:
271 IProxy& proxy_;
272 const std::string& propertyName_;
273 const std::string* interfaceName_{};
274 };
275
277 {
278 public:
279 AsyncPropertySetter(IProxy& proxy, const std::string& propertyName);
280 AsyncPropertySetter& onInterface(const std::string& interfaceName);
281 template <typename _Value> AsyncPropertySetter& toValue(_Value&& value);
282 AsyncPropertySetter& toValue(Variant value);
283 template <typename _Function> PendingAsyncCall uponReplyInvoke(_Function&& callback);
284 std::future<void> getResultAsFuture();
285
286 private:
287 IProxy& proxy_;
288 const std::string& propertyName_;
289 const std::string* interfaceName_{};
290 Variant value_;
291 };
292
294 {
295 public:
297 std::map<std::string, Variant> onInterface(const std::string& interfaceName);
298
299 private:
300 IProxy& proxy_;
301 };
302
304 {
305 public:
307 AsyncAllPropertiesGetter& onInterface(const std::string& interfaceName);
308 template <typename _Function> PendingAsyncCall uponReplyInvoke(_Function&& callback);
309 std::future<std::map<std::string, Variant>> getResultAsFuture();
310
311 private:
312 IProxy& proxy_;
313 const std::string* interfaceName_{};
314 };
315
316}
317
318#endif /* SDBUS_CXX_CONVENIENCEAPICLASSES_H_ */
Definition ConvenienceApiClasses.h:294
Definition ConvenienceApiClasses.h:304
Definition ConvenienceApiClasses.h:190
Definition ConvenienceApiClasses.h:247
Definition ConvenienceApiClasses.h:277
Definition Flags.h:37
Definition IObject.h:60
Definition IProxy.h:66
Definition ConvenienceApiClasses.h:130
Definition Message.h:233
Definition ConvenienceApiClasses.h:165
Definition ConvenienceApiClasses.h:52
Definition IProxy.h:445
Definition ConvenienceApiClasses.h:236
Definition ConvenienceApiClasses.h:105
Definition ConvenienceApiClasses.h:261
Definition ConvenienceApiClasses.h:149
Definition ConvenienceApiClasses.h:82
Definition ConvenienceApiClasses.h:212
Definition ConvenienceApiClasses.h:225
Definition Message.h:271
Definition Types.h:54
Definition TypeTraits.h:97