sdbus-c++ 1.0.0
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
37namespace sdbus {
38 class MethodCall;
39 class MethodReply;
40 class IConnection;
41 class PendingAsyncCall;
42 namespace internal {
43 class Proxy;
44 }
45}
46
47namespace 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
275 virtual sdbus::IConnection& getConnection() const = 0;
276
280 virtual const std::string& getObjectPath() const = 0;
281
296 virtual const Message* getCurrentlyProcessedMessage() const = 0;
297 };
298
299 /********************************************/
310 {
311 public:
312 PendingAsyncCall() = default;
313
321 void cancel();
322
331 bool isPending() const;
332
333 private:
334 friend internal::Proxy;
335 PendingAsyncCall(std::weak_ptr<void> callData);
336
337 private:
338 std::weak_ptr<void> callData_;
339 };
340
341 // Out-of-line member definitions
342
343 template <typename _Rep, typename _Period>
344 inline MethodReply IProxy::callMethod(const MethodCall& message, const std::chrono::duration<_Rep, _Period>& timeout)
345 {
346 auto microsecs = std::chrono::duration_cast<std::chrono::microseconds>(timeout);
347 return callMethod(message, microsecs.count());
348 }
349
350 template <typename _Rep, typename _Period>
351 inline PendingAsyncCall IProxy::callMethod(const MethodCall& message, async_reply_handler asyncReplyCallback, const std::chrono::duration<_Rep, _Period>& timeout)
352 {
353 auto microsecs = std::chrono::duration_cast<std::chrono::microseconds>(timeout);
354 return callMethod(message, std::move(asyncReplyCallback), microsecs.count());
355 }
356
357 inline MethodInvoker IProxy::callMethod(const std::string& methodName)
358 {
359 return MethodInvoker(*this, methodName);
360 }
361
362 inline AsyncMethodInvoker IProxy::callMethodAsync(const std::string& methodName)
363 {
364 return AsyncMethodInvoker(*this, methodName);
365 }
366
367 inline SignalSubscriber IProxy::uponSignal(const std::string& signalName)
368 {
369 return SignalSubscriber(*this, signalName);
370 }
371
372 inline PropertyGetter IProxy::getProperty(const std::string& propertyName)
373 {
374 return PropertyGetter(*this, propertyName);
375 }
376
377 inline PropertySetter IProxy::setProperty(const std::string& propertyName)
378 {
379 return PropertySetter(*this, propertyName);
380 }
381
401 [[nodiscard]] std::unique_ptr<sdbus::IProxy> createProxy( sdbus::IConnection& connection
402 , std::string destination
403 , std::string objectPath );
404
424 [[nodiscard]] std::unique_ptr<sdbus::IProxy> createProxy( std::unique_ptr<sdbus::IConnection>&& connection
425 , std::string destination
426 , std::string objectPath );
427
445 [[nodiscard]] std::unique_ptr<sdbus::IProxy> createProxy( std::string destination
446 , std::string objectPath );
447
448}
449
451
452#endif /* SDBUS_CXX_IPROXY_H_ */
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.
Definition: ConvenienceApiClasses.h:189
Definition: IConnection.h:48
Definition: IProxy.h:64
virtual const Message * getCurrentlyProcessedMessage() const =0
Provides currently processed D-Bus message.
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.
virtual MethodCall createMethodCall(const std::string &interfaceName, const std::string &methodName)=0
Creates a method call message.
virtual const std::string & getObjectPath() const =0
Returns object path of the underlying DBus object.
virtual void unregister()=0
Unregisters proxy's signal handlers and stops receving replies to pending async calls.
virtual void finishRegistration()=0
Finishes the registration of signal handlers.
virtual PendingAsyncCall callMethod(const MethodCall &message, async_reply_handler asyncReplyCallback, uint64_t timeout=0)=0
Calls method on the proxied D-Bus object asynchronously.
PropertySetter setProperty(const std::string &propertyName)
Sets value of a property of the proxied D-Bus object.
Definition: IProxy.h:377
virtual MethodReply callMethod(const MethodCall &message, uint64_t timeout=0)=0
Calls method on the proxied D-Bus object.
virtual sdbus::IConnection & getConnection() const =0
Provides D-Bus connection used by the proxy.
AsyncMethodInvoker callMethodAsync(const std::string &methodName)
Calls method on the proxied D-Bus object asynchronously.
Definition: IProxy.h:362
PropertyGetter getProperty(const std::string &propertyName)
Gets value of a property of the proxied D-Bus object.
Definition: IProxy.h:372
SignalSubscriber uponSignal(const std::string &signalName)
Registers signal handler for a given signal of the proxied D-Bus object.
Definition: IProxy.h:367
Definition: Message.h:76
Definition: Message.h:179
Definition: ConvenienceApiClasses.h:164
Definition: Message.h:204
Definition: IProxy.h:310
void cancel()
Cancels the delivery of the pending asynchronous call result.
bool isPending() const
Answers whether the asynchronous call is still pending.
Definition: ConvenienceApiClasses.h:220
Definition: ConvenienceApiClasses.h:231
Definition: ConvenienceApiClasses.h:207