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