sdbus-c++: include/sdbus-c++/IProxy.h Source File

sdbus-c++ 1.4.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
30#include <sdbus-c++/ConvenienceApiClasses.h>
31#include <sdbus-c++/TypeTraits.h>
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
358 [[nodiscard]] AllPropertiesGetter getAllProperties();
359
376 [[nodiscard]] AsyncAllPropertiesGetter getAllPropertiesAsync();
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 /********************************************/
444 class PendingAsyncCall
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
541 inline AllPropertiesGetter IProxy::getAllProperties()
542 {
543 return AllPropertiesGetter(*this);
544 }
545
546 inline AsyncAllPropertiesGetter IProxy::getAllPropertiesAsync()
547 {
548 return AsyncAllPropertiesGetter(*this);
549 }
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
629 , dont_run_event_loop_thread_t );
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
671 , dont_run_event_loop_thread_t );
672
673}
674
675#include <sdbus-c++/ConvenienceApiClasses.inl>
676
677#endif /* SDBUS_CXX_IPROXY_H_ */
ConvenienceApiClasses.h
ConvenienceApiClasses.inl
sdbus::createProxy
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.
TypeTraits.h
sdbus::AllPropertiesGetter
Definition ConvenienceApiClasses.h:294
sdbus::AsyncAllPropertiesGetter
Definition ConvenienceApiClasses.h:304
sdbus::AsyncMethodInvoker
Definition ConvenienceApiClasses.h:190
sdbus::AsyncPropertyGetter
Definition ConvenienceApiClasses.h:247
sdbus::AsyncPropertySetter
Definition ConvenienceApiClasses.h:277
sdbus::IConnection
Definition IConnection.h:52
sdbus::IProxy
Definition IProxy.h:66
sdbus::IProxy::getCurrentlyProcessedMessage
virtual const Message * getCurrentlyProcessedMessage() const =0
Provides currently processed D-Bus message.
sdbus::IProxy::registerSignalHandler
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.
sdbus::IProxy::getAllPropertiesAsync
AsyncAllPropertiesGetter getAllPropertiesAsync()
Gets values of all properties of the D-Bus object asynchronously.
Definition IProxy.h:546
sdbus::IProxy::unregisterSignalHandler
virtual void unregisterSignalHandler(const std::string &interfaceName, const std::string &signalName)=0
Unregisters the handler of the desired signal.
sdbus::IProxy::callMethod
virtual std::future< MethodReply > callMethod(const MethodCall &message, with_future_t)=0
Calls method on the D-Bus object asynchronously.
sdbus::IProxy::createMethodCall
virtual MethodCall createMethodCall(const std::string &interfaceName, const std::string &methodName)=0
Creates a method call message.
sdbus::IProxy::getObjectPath
virtual const std::string & getObjectPath() const =0
Returns object path of the underlying DBus object.
sdbus::IProxy::muteSignal
SignalUnsubscriber muteSignal(const std::string &signalName)
Unregisters signal handler of a given signal of the D-Bus object.
Definition IProxy.h:516
sdbus::IProxy::unregister
virtual void unregister()=0
Unregisters proxy's signal handlers and stops receving replies to pending async calls.
sdbus::IProxy::finishRegistration
virtual void finishRegistration()=0
Finishes the registration of signal handlers.
sdbus::IProxy::callMethod
virtual PendingAsyncCall callMethod(const MethodCall &message, async_reply_handler asyncReplyCallback, uint64_t timeout=0)=0
Calls method on the D-Bus object asynchronously.
sdbus::IProxy::getPropertyAsync
AsyncPropertyGetter getPropertyAsync(const std::string &propertyName)
Gets value of a property of the D-Bus object asynchronously.
Definition IProxy.h:526
sdbus::IProxy::setProperty
PropertySetter setProperty(const std::string &propertyName)
Sets value of a property of the D-Bus object.
Definition IProxy.h:531
sdbus::IProxy::callMethod
virtual MethodReply callMethod(const MethodCall &message, uint64_t timeout=0)=0
Calls method on the D-Bus object.
sdbus::IProxy::getConnection
virtual sdbus::IConnection & getConnection() const =0
Provides D-Bus connection used by the proxy.
sdbus::IProxy::setPropertyAsync
AsyncPropertySetter setPropertyAsync(const std::string &propertyName)
Sets value of a property of the D-Bus object asynchronously.
Definition IProxy.h:536
sdbus::IProxy::callMethodAsync
AsyncMethodInvoker callMethodAsync(const std::string &methodName)
Calls method on the D-Bus object asynchronously.
Definition IProxy.h:506
sdbus::IProxy::getProperty
PropertyGetter getProperty(const std::string &propertyName)
Gets value of a property of the D-Bus object.
Definition IProxy.h:521
sdbus::IProxy::getAllProperties
AllPropertiesGetter getAllProperties()
Gets values of all properties of the D-Bus object.
Definition IProxy.h:541
sdbus::IProxy::uponSignal
SignalSubscriber uponSignal(const std::string &signalName)
Registers signal handler for a given signal of the D-Bus object.
Definition IProxy.h:511
sdbus::Message
Definition Message.h:76
sdbus::MethodCall
Definition Message.h:232
sdbus::MethodInvoker
Definition ConvenienceApiClasses.h:165
sdbus::MethodReply
Definition Message.h:260
sdbus::PendingAsyncCall
Definition IProxy.h:445
sdbus::PendingAsyncCall::cancel
void cancel()
Cancels the delivery of the pending asynchronous call result.
sdbus::PendingAsyncCall::isPending
bool isPending() const
Answers whether the asynchronous call is still pending.
sdbus::PropertyGetter
Definition ConvenienceApiClasses.h:236
sdbus::PropertySetter
Definition ConvenienceApiClasses.h:261
sdbus::SignalSubscriber
Definition ConvenienceApiClasses.h:212
sdbus::SignalUnsubscriber
Definition ConvenienceApiClasses.h:225
sdbus::dont_run_event_loop_thread_t
Definition TypeTraits.h:91
sdbus::with_future_t
Definition TypeTraits.h:94