sdbus-c++  1.3.0
High-level C++ D-Bus library based on systemd D-Bus implementation
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
41 namespace sdbus {
42  class IObject;
43  class IProxy;
44  class Variant;
45  class Error;
46  class PendingAsyncCall;
47 }
48 
49 namespace 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);
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 
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(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  sdbus::Variant onInterface(const std::string& interfaceName);
240 
241  private:
242  IProxy& proxy_;
243  const std::string& propertyName_;
244  };
245 
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_ */
Definition: ConvenienceApiClasses.h:189
Definition: ConvenienceApiClasses.h:129
Definition: ConvenienceApiClasses.h:51
Definition: Types.h:53
Definition: ConvenienceApiClasses.h:164
Definition: ConvenienceApiClasses.h:224
Definition: Message.h:269
Definition: ConvenienceApiClasses.h:235
Definition: ConvenienceApiClasses.h:246
Definition: Flags.h:36
Definition: IObject.h:59
Definition: IProxy.h:366
Definition: ConvenienceApiClasses.h:81
Definition: AdaptorInterfaces.h:36
Definition: ConvenienceApiClasses.h:148
Definition: ConvenienceApiClasses.h:211
Definition: ConvenienceApiClasses.h:104
Definition: IProxy.h:65
Definition: Message.h:231