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

sdbus-c++ 1.3.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
298 [[nodiscard]] PropertySetter setProperty(const std::string& propertyName);
299
305 virtual sdbus::IConnection& getConnection() const = 0;
306
310 virtual const std::string& getObjectPath() const = 0;
311
326 virtual const Message* getCurrentlyProcessedMessage() const = 0;
327
344 virtual std::future<MethodReply> callMethod(const MethodCall& message, with_future_t) = 0;
345 virtual std::future<MethodReply> callMethod(const MethodCall& message, uint64_t timeout, with_future_t) = 0;
346
350 template <typename _Rep, typename _Period>
351 std::future<MethodReply> callMethod( const MethodCall& message
352 , const std::chrono::duration<_Rep, _Period>& timeout
353 , with_future_t );
354 };
355
356 /********************************************/
366 class PendingAsyncCall
367 {
368 public:
369 PendingAsyncCall() = default;
370
378 void cancel();
379
388 bool isPending() const;
389
390 private:
391 friend internal::Proxy;
392 PendingAsyncCall(std::weak_ptr<void> callData);
393
394 private:
395 std::weak_ptr<void> callData_;
396 };
397
398 // Out-of-line member definitions
399
400 template <typename _Rep, typename _Period>
401 inline MethodReply IProxy::callMethod(const MethodCall& message, const std::chrono::duration<_Rep, _Period>& timeout)
402 {
403 auto microsecs = std::chrono::duration_cast<std::chrono::microseconds>(timeout);
404 return callMethod(message, microsecs.count());
405 }
406
407 template <typename _Rep, typename _Period>
408 inline PendingAsyncCall IProxy::callMethod(const MethodCall& message, async_reply_handler asyncReplyCallback, const std::chrono::duration<_Rep, _Period>& timeout)
409 {
410 auto microsecs = std::chrono::duration_cast<std::chrono::microseconds>(timeout);
411 return callMethod(message, std::move(asyncReplyCallback), microsecs.count());
412 }
413
414 template <typename _Rep, typename _Period>
415 inline std::future<MethodReply> IProxy::callMethod( const MethodCall& message
416 , const std::chrono::duration<_Rep, _Period>& timeout
417 , with_future_t )
418 {
419 auto microsecs = std::chrono::duration_cast<std::chrono::microseconds>(timeout);
420 return callMethod(message, microsecs.count(), with_future);
421 }
422
423 inline MethodInvoker IProxy::callMethod(const std::string& methodName)
424 {
425 return MethodInvoker(*this, methodName);
426 }
427
428 inline AsyncMethodInvoker IProxy::callMethodAsync(const std::string& methodName)
429 {
430 return AsyncMethodInvoker(*this, methodName);
431 }
432
433 inline SignalSubscriber IProxy::uponSignal(const std::string& signalName)
434 {
435 return SignalSubscriber(*this, signalName);
436 }
437
438 inline SignalUnsubscriber IProxy::muteSignal(const std::string& signalName)
439 {
440 return SignalUnsubscriber(*this, signalName);
441 }
442
443 inline PropertyGetter IProxy::getProperty(const std::string& propertyName)
444 {
445 return PropertyGetter(*this, propertyName);
446 }
447
448 inline PropertySetter IProxy::setProperty(const std::string& propertyName)
449 {
450 return PropertySetter(*this, propertyName);
451 }
452
472 [[nodiscard]] std::unique_ptr<sdbus::IProxy> createProxy( sdbus::IConnection& connection
473 , std::string destination
474 , std::string objectPath );
475
495 [[nodiscard]] std::unique_ptr<sdbus::IProxy> createProxy( std::unique_ptr<sdbus::IConnection>&& connection
496 , std::string destination
497 , std::string objectPath );
498
518 [[nodiscard]] std::unique_ptr<sdbus::IProxy> createProxy( std::unique_ptr<sdbus::IConnection>&& connection
519 , std::string destination
520 , std::string objectPath
521 , dont_run_event_loop_thread_t );
522
540 [[nodiscard]] std::unique_ptr<sdbus::IProxy> createProxy( std::string destination
541 , std::string objectPath );
542
561 [[nodiscard]] std::unique_ptr<sdbus::IProxy> createProxy( std::string destination
562 , std::string objectPath
563 , dont_run_event_loop_thread_t );
564
565}
566
567#include <sdbus-c++/ConvenienceApiClasses.inl>
568
569#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::AsyncMethodInvoker
Definition ConvenienceApiClasses.h:190
sdbus::IConnection
Definition IConnection.h:50
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 proxied D-Bus object.
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 proxied 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 proxied D-Bus object.
Definition IProxy.h:438
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 proxied D-Bus object asynchronously.
sdbus::IProxy::setProperty
PropertySetter setProperty(const std::string &propertyName)
Sets value of a property of the proxied D-Bus object.
Definition IProxy.h:448
sdbus::IProxy::callMethod
virtual MethodReply callMethod(const MethodCall &message, uint64_t timeout=0)=0
Calls method on the proxied D-Bus object.
sdbus::IProxy::getConnection
virtual sdbus::IConnection & getConnection() const =0
Provides D-Bus connection used by the proxy.
sdbus::IProxy::callMethodAsync
AsyncMethodInvoker callMethodAsync(const std::string &methodName)
Calls method on the proxied D-Bus object asynchronously.
Definition IProxy.h:428
sdbus::IProxy::getProperty
PropertyGetter getProperty(const std::string &propertyName)
Gets value of a property of the proxied D-Bus object.
Definition IProxy.h:443
sdbus::IProxy::uponSignal
SignalSubscriber uponSignal(const std::string &signalName)
Registers signal handler for a given signal of the proxied D-Bus object.
Definition IProxy.h:433
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:367
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:247
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