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