sdbus-c++ 1.5.0
High-level C++ D-Bus library based on systemd D-Bus implementation
Loading...
Searching...
No Matches
IProxy.h
Go to the documentation of this file.
1
27#ifndef SDBUS_CXX_IPROXY_H_
28#define SDBUS_CXX_IPROXY_H_
29
32#include <string>
33#include <memory>
34#include <functional>
35#include <chrono>
36#include <future>
37
38// Forward declarations
39namespace sdbus {
40 class MethodCall;
41 class MethodReply;
42 class IConnection;
43 class PendingAsyncCall;
44 namespace internal {
45 class Proxy;
46 }
47}
48
49namespace sdbus {
50
51 /********************************************/
65 class IProxy
66 {
67 public:
68 virtual ~IProxy() = default;
69
83 virtual MethodCall createMethodCall(const std::string& interfaceName, const std::string& methodName) = 0;
84
103 virtual MethodReply callMethod(const MethodCall& message, uint64_t timeout = 0) = 0;
104
108 template <typename _Rep, typename _Period>
109 MethodReply callMethod(const MethodCall& message, const std::chrono::duration<_Rep, _Period>& timeout);
110
127 virtual PendingAsyncCall callMethod(const MethodCall& message, async_reply_handler asyncReplyCallback, uint64_t timeout = 0) = 0;
128
132 template <typename _Rep, typename _Period>
133 PendingAsyncCall callMethod(const MethodCall& message, async_reply_handler asyncReplyCallback, const std::chrono::duration<_Rep, _Period>& timeout);
134
144 virtual void registerSignalHandler( const std::string& interfaceName
145 , const std::string& signalName
146 , signal_handler signalHandler ) = 0;
147
156 virtual void unregisterSignalHandler( const std::string& interfaceName
157 , const std::string& signalName ) = 0;
158
167 virtual void finishRegistration() = 0;
168
178 virtual void unregister() = 0;
179
199 [[nodiscard]] MethodInvoker callMethod(const std::string& methodName);
200
223 [[nodiscard]] AsyncMethodInvoker callMethodAsync(const std::string& methodName);
224
243 [[nodiscard]] SignalSubscriber uponSignal(const std::string& signalName);
244
260 [[nodiscard]] SignalUnsubscriber muteSignal(const std::string& signalName);
261
279 [[nodiscard]] PropertyGetter getProperty(const std::string& propertyName);
280
299 [[nodiscard]] AsyncPropertyGetter getPropertyAsync(const std::string& propertyName);
300
321 [[nodiscard]] PropertySetter setProperty(const std::string& propertyName);
322
341 [[nodiscard]] AsyncPropertySetter setPropertyAsync(const std::string& propertyName);
342
359
377
383 virtual sdbus::IConnection& getConnection() const = 0;
384
388 virtual const std::string& getObjectPath() const = 0;
389
404 virtual const Message* getCurrentlyProcessedMessage() const = 0;
405
422 virtual std::future<MethodReply> callMethod(const MethodCall& message, with_future_t) = 0;
423 virtual std::future<MethodReply> callMethod(const MethodCall& message, uint64_t timeout, with_future_t) = 0;
424
428 template <typename _Rep, typename _Period>
429 std::future<MethodReply> callMethod( const MethodCall& message
430 , const std::chrono::duration<_Rep, _Period>& timeout
431 , with_future_t );
432 };
433
434 /********************************************/
445 {
446 public:
447 PendingAsyncCall() = default;
448
456 void cancel();
457
466 bool isPending() const;
467
468 private:
469 friend internal::Proxy;
470 PendingAsyncCall(std::weak_ptr<void> callData);
471
472 private:
473 std::weak_ptr<void> callData_;
474 };
475
476 // Out-of-line member definitions
477
478 template <typename _Rep, typename _Period>
479 inline MethodReply IProxy::callMethod(const MethodCall& message, const std::chrono::duration<_Rep, _Period>& timeout)
480 {
481 auto microsecs = std::chrono::duration_cast<std::chrono::microseconds>(timeout);
482 return callMethod(message, microsecs.count());
483 }
484
485 template <typename _Rep, typename _Period>
486 inline PendingAsyncCall IProxy::callMethod(const MethodCall& message, async_reply_handler asyncReplyCallback, const std::chrono::duration<_Rep, _Period>& timeout)
487 {
488 auto microsecs = std::chrono::duration_cast<std::chrono::microseconds>(timeout);
489 return callMethod(message, std::move(asyncReplyCallback), microsecs.count());
490 }
491
492 template <typename _Rep, typename _Period>
493 inline std::future<MethodReply> IProxy::callMethod( const MethodCall& message
494 , const std::chrono::duration<_Rep, _Period>& timeout
495 , with_future_t )
496 {
497 auto microsecs = std::chrono::duration_cast<std::chrono::microseconds>(timeout);
498 return callMethod(message, microsecs.count(), with_future);
499 }
500
501 inline MethodInvoker IProxy::callMethod(const std::string& methodName)
502 {
503 return MethodInvoker(*this, methodName);
504 }
505
506 inline AsyncMethodInvoker IProxy::callMethodAsync(const std::string& methodName)
507 {
508 return AsyncMethodInvoker(*this, methodName);
509 }
510
511 inline SignalSubscriber IProxy::uponSignal(const std::string& signalName)
512 {
513 return SignalSubscriber(*this, signalName);
514 }
515
516 inline SignalUnsubscriber IProxy::muteSignal(const std::string& signalName)
517 {
518 return SignalUnsubscriber(*this, signalName);
519 }
520
521 inline PropertyGetter IProxy::getProperty(const std::string& propertyName)
522 {
523 return PropertyGetter(*this, propertyName);
524 }
525
526 inline AsyncPropertyGetter IProxy::getPropertyAsync(const std::string& propertyName)
527 {
528 return AsyncPropertyGetter(*this, propertyName);
529 }
530
531 inline PropertySetter IProxy::setProperty(const std::string& propertyName)
532 {
533 return PropertySetter(*this, propertyName);
534 }
535
536 inline AsyncPropertySetter IProxy::setPropertyAsync(const std::string& propertyName)
537 {
538 return AsyncPropertySetter(*this, propertyName);
539 }
540
542 {
543 return AllPropertiesGetter(*this);
544 }
545
550
573 [[nodiscard]] std::unique_ptr<sdbus::IProxy> createProxy( sdbus::IConnection& connection
574 , std::string destination
575 , std::string objectPath );
576
599 [[nodiscard]] std::unique_ptr<sdbus::IProxy> createProxy( std::unique_ptr<sdbus::IConnection>&& connection
600 , std::string destination
601 , std::string objectPath );
602
626 [[nodiscard]] std::unique_ptr<sdbus::IProxy> createProxy( std::unique_ptr<sdbus::IConnection>&& connection
627 , std::string destination
628 , std::string objectPath
630
648 [[nodiscard]] std::unique_ptr<sdbus::IProxy> createProxy( std::string destination
649 , std::string objectPath );
650
669 [[nodiscard]] std::unique_ptr<sdbus::IProxy> createProxy( std::string destination
670 , std::string objectPath
672
673}
674
676
677#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:294
Definition ConvenienceApiClasses.h:304
Definition ConvenienceApiClasses.h:190
Definition ConvenienceApiClasses.h:247
Definition ConvenienceApiClasses.h:277
Definition IConnection.h:52
Definition IProxy.h:66
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 D-Bus object.
AsyncAllPropertiesGetter getAllPropertiesAsync()
Gets values of all properties of the D-Bus object asynchronously.
Definition IProxy.h:546
virtual void unregisterSignalHandler(const std::string &interfaceName, const std::string &signalName)=0
Unregisters the handler of the desired signal.
virtual std::future< MethodReply > callMethod(const MethodCall &message, with_future_t)=0
Calls method on the D-Bus object asynchronously.
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.
SignalUnsubscriber muteSignal(const std::string &signalName)
Unregisters signal handler of a given signal of the D-Bus object.
Definition IProxy.h:516
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 D-Bus object asynchronously.
AsyncPropertyGetter getPropertyAsync(const std::string &propertyName)
Gets value of a property of the D-Bus object asynchronously.
Definition IProxy.h:526
PropertySetter setProperty(const std::string &propertyName)
Sets value of a property of the D-Bus object.
Definition IProxy.h:531
virtual MethodReply callMethod(const MethodCall &message, uint64_t timeout=0)=0
Calls method on the D-Bus object.
virtual sdbus::IConnection & getConnection() const =0
Provides D-Bus connection used by the proxy.
AsyncPropertySetter setPropertyAsync(const std::string &propertyName)
Sets value of a property of the D-Bus object asynchronously.
Definition IProxy.h:536
AsyncMethodInvoker callMethodAsync(const std::string &methodName)
Calls method on the D-Bus object asynchronously.
Definition IProxy.h:506
PropertyGetter getProperty(const std::string &propertyName)
Gets value of a property of the D-Bus object.
Definition IProxy.h:521
AllPropertiesGetter getAllProperties()
Gets values of all properties of the D-Bus object.
Definition IProxy.h:541
SignalSubscriber uponSignal(const std::string &signalName)
Registers signal handler for a given signal of the D-Bus object.
Definition IProxy.h:511
Definition Message.h:77
Definition Message.h:233
Definition ConvenienceApiClasses.h:165
Definition Message.h:261
Definition IProxy.h:445
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:236
Definition ConvenienceApiClasses.h:261
Definition ConvenienceApiClasses.h:212
Definition ConvenienceApiClasses.h:225
Definition TypeTraits.h:91
Definition TypeTraits.h:94