sdbus-c++  0.8.3
High-level C++ D-Bus library based on systemd D-Bus implementation
IProxy.h
Go to the documentation of this file.
1 
27 #ifndef SDBUS_CXX_IPROXY_H_
28 #define SDBUS_CXX_IPROXY_H_
29 
31 #include <string>
32 #include <memory>
33 #include <functional>
34 #include <chrono>
35 
36 // Forward declarations
37 namespace sdbus {
38  class MethodCall;
39  class MethodReply;
40  class IConnection;
41  class PendingAsyncCall;
42  namespace internal {
43  class Proxy;
44  }
45 }
46 
47 namespace sdbus {
48 
49  /********************************************/
63  class IProxy
64  {
65  public:
66  virtual ~IProxy() = default;
67 
81  virtual MethodCall createMethodCall(const std::string& interfaceName, const std::string& methodName) = 0;
82 
101  virtual MethodReply callMethod(const MethodCall& message, uint64_t timeout = 0) = 0;
102 
106  template <typename _Rep, typename _Period>
107  MethodReply callMethod(const MethodCall& message, const std::chrono::duration<_Rep, _Period>& timeout);
108 
125  virtual PendingAsyncCall callMethod(const MethodCall& message, async_reply_handler asyncReplyCallback, uint64_t timeout = 0) = 0;
126 
130  template <typename _Rep, typename _Period>
131  PendingAsyncCall callMethod(const MethodCall& message, async_reply_handler asyncReplyCallback, const std::chrono::duration<_Rep, _Period>& timeout);
132 
142  virtual void registerSignalHandler( const std::string& interfaceName
143  , const std::string& signalName
144  , signal_handler signalHandler ) = 0;
145 
154  virtual void finishRegistration() = 0;
155 
165  virtual void unregister() = 0;
166 
186  [[nodiscard]] MethodInvoker callMethod(const std::string& methodName);
187 
210  [[nodiscard]] AsyncMethodInvoker callMethodAsync(const std::string& methodName);
211 
230  [[nodiscard]] SignalSubscriber uponSignal(const std::string& signalName);
231 
249  [[nodiscard]] PropertyGetter getProperty(const std::string& propertyName);
250 
268  [[nodiscard]] PropertySetter setProperty(const std::string& propertyName);
269 
273  virtual const std::string& getObjectPath() const = 0;
274  };
275 
276  /********************************************/
287  {
288  public:
296  void cancel();
297 
306  bool isPending() const;
307 
308  private:
309  friend internal::Proxy;
310  PendingAsyncCall(std::weak_ptr<void> callData);
311 
312  private:
313  std::weak_ptr<void> callData_;
314  };
315 
316  // Out-of-line member definitions
317 
318  template <typename _Rep, typename _Period>
319  inline MethodReply IProxy::callMethod(const MethodCall& message, const std::chrono::duration<_Rep, _Period>& timeout)
320  {
321  auto microsecs = std::chrono::duration_cast<std::chrono::microseconds>(timeout);
322  return callMethod(message, microsecs.count());
323  }
324 
325  template <typename _Rep, typename _Period>
326  inline PendingAsyncCall IProxy::callMethod(const MethodCall& message, async_reply_handler asyncReplyCallback, const std::chrono::duration<_Rep, _Period>& timeout)
327  {
328  auto microsecs = std::chrono::duration_cast<std::chrono::microseconds>(timeout);
329  return callMethod(message, std::move(asyncReplyCallback), microsecs.count());
330  }
331 
332  inline MethodInvoker IProxy::callMethod(const std::string& methodName)
333  {
334  return MethodInvoker(*this, methodName);
335  }
336 
337  inline AsyncMethodInvoker IProxy::callMethodAsync(const std::string& methodName)
338  {
339  return AsyncMethodInvoker(*this, methodName);
340  }
341 
342  inline SignalSubscriber IProxy::uponSignal(const std::string& signalName)
343  {
344  return SignalSubscriber(*this, signalName);
345  }
346 
347  inline PropertyGetter IProxy::getProperty(const std::string& propertyName)
348  {
349  return PropertyGetter(*this, propertyName);
350  }
351 
352  inline PropertySetter IProxy::setProperty(const std::string& propertyName)
353  {
354  return PropertySetter(*this, propertyName);
355  }
356 
376  [[nodiscard]] std::unique_ptr<sdbus::IProxy> createProxy( sdbus::IConnection& connection
377  , std::string destination
378  , std::string objectPath );
379 
399  [[nodiscard]] std::unique_ptr<sdbus::IProxy> createProxy( std::unique_ptr<sdbus::IConnection>&& connection
400  , std::string destination
401  , std::string objectPath );
402 
420  [[nodiscard]] std::unique_ptr<sdbus::IProxy> createProxy( std::string destination
421  , std::string objectPath );
422 
423 }
424 
426 
427 #endif /* SDBUS_CXX_IPROXY_H_ */
Definition: Message.h:192
virtual MethodCall createMethodCall(const std::string &interfaceName, const std::string &methodName)=0
Creates a method call message.
Definition: ConvenienceApiClasses.h:188
virtual void registerSignalHandler(const std::string &interfaceName, const std::string &signalName, signal_handler signalHandler)=0
Registers a handler for the desired signal emitted by the proxied D-Bus object.
bool isPending() const
Answers whether the asynchronous call is still pending.
SignalSubscriber uponSignal(const std::string &signalName)
Registers signal handler for a given signal of the proxied D-Bus object.
Definition: IProxy.h:342
AsyncMethodInvoker callMethodAsync(const std::string &methodName)
Calls method on the proxied D-Bus object asynchronously.
Definition: IProxy.h:337
Definition: ConvenienceApiClasses.h:163
virtual void finishRegistration()=0
Finishes the registration of signal handlers.
std::unique_ptr< sdbus::IProxy > createProxy(sdbus::IConnection &connection, std::string destination, std::string objectPath)
Creates a proxy object for a specific remote D-Bus object.
void cancel()
Cancels the delivery of the pending asynchronous call result.
Definition: ConvenienceApiClasses.h:219
virtual void unregister()=0
Unregisters proxy&#39;s signal handlers and stops receving replies to pending async calls.
Definition: ConvenienceApiClasses.h:230
PropertySetter setProperty(const std::string &propertyName)
Sets value of a property of the proxied D-Bus object.
Definition: IProxy.h:352
PropertyGetter getProperty(const std::string &propertyName)
Gets value of a property of the proxied D-Bus object.
Definition: IProxy.h:347
Definition: IProxy.h:286
virtual const std::string & getObjectPath() const =0
Returns object path of the underlying DBus object.
virtual MethodReply callMethod(const MethodCall &message, uint64_t timeout=0)=0
Calls method on the proxied D-Bus object.
Definition: AdaptorInterfaces.h:36
Definition: IConnection.h:47
Definition: ConvenienceApiClasses.h:206
Definition: IProxy.h:63
Definition: Message.h:167