sdbus-c++ 2.0.0
High-level C++ D-Bus library based on systemd D-Bus implementation
|
#include <IProxy.h>
Public Member Functions | |
MethodInvoker | callMethod (const MethodName &methodName) |
Calls method on the D-Bus object. | |
MethodInvoker | callMethod (const std::string &methodName) |
Calls method on the D-Bus object. | |
MethodInvoker | callMethod (const char *methodName) |
Calls method on the D-Bus object. | |
AsyncMethodInvoker | callMethodAsync (const MethodName &methodName) |
Calls method on the D-Bus object asynchronously. | |
AsyncMethodInvoker | callMethodAsync (const std::string &methodName) |
Calls method on the D-Bus object asynchronously. | |
AsyncMethodInvoker | callMethodAsync (const char *methodName) |
Calls method on the D-Bus object asynchronously. | |
SignalSubscriber | uponSignal (const SignalName &signalName) |
Registers signal handler for a given signal of the D-Bus object. | |
SignalSubscriber | uponSignal (const std::string &signalName) |
Registers signal handler for a given signal of the D-Bus object. | |
SignalSubscriber | uponSignal (const char *signalName) |
Registers signal handler for a given signal of the D-Bus object. | |
PropertyGetter | getProperty (const PropertyName &propertyName) |
Gets value of a property of the D-Bus object. | |
PropertyGetter | getProperty (std::string_view propertyName) |
Gets value of a property of the D-Bus object. | |
AsyncPropertyGetter | getPropertyAsync (const PropertyName &propertyName) |
Gets value of a property of the D-Bus object asynchronously. | |
AsyncPropertyGetter | getPropertyAsync (std::string_view propertyName) |
Gets value of a property of the D-Bus object asynchronously. | |
PropertySetter | setProperty (const PropertyName &propertyName) |
Sets value of a property of the D-Bus object. | |
PropertySetter | setProperty (std::string_view propertyName) |
Sets value of a property of the D-Bus object. | |
AsyncPropertySetter | setPropertyAsync (const PropertyName &propertyName) |
Sets value of a property of the D-Bus object asynchronously. | |
AsyncPropertySetter | setPropertyAsync (std::string_view propertyName) |
Sets value of a property of the D-Bus object asynchronously. | |
AllPropertiesGetter | getAllProperties () |
Gets values of all properties of the D-Bus object. | |
AsyncAllPropertiesGetter | getAllPropertiesAsync () |
Gets values of all properties of the D-Bus object asynchronously. | |
virtual sdbus::IConnection & | getConnection () const =0 |
Provides D-Bus connection used by the proxy. | |
virtual const ObjectPath & | getObjectPath () const =0 |
Returns object path of the underlying DBus object. | |
virtual Message | getCurrentlyProcessedMessage () const =0 |
Provides access to the currently processed D-Bus message. | |
virtual void | unregister ()=0 |
Unregisters proxy's signal handlers and stops receiving replies to pending async calls. | |
virtual MethodCall | createMethodCall (const InterfaceName &interfaceName, const MethodName &methodName)=0 |
Creates a method call message. | |
virtual MethodReply | callMethod (const MethodCall &message)=0 |
Calls method on the remote D-Bus object. | |
virtual MethodReply | callMethod (const MethodCall &message, uint64_t timeout)=0 |
Calls method on the remote D-Bus object. | |
template<typename _Rep , typename _Period > | |
MethodReply | callMethod (const MethodCall &message, const std::chrono::duration< _Rep, _Period > &timeout) |
Calls method on the remote D-Bus object. | |
virtual PendingAsyncCall | callMethodAsync (const MethodCall &message, async_reply_handler asyncReplyCallback)=0 |
Calls method on the D-Bus object asynchronously. | |
virtual Slot | callMethodAsync (const MethodCall &message, async_reply_handler asyncReplyCallback, return_slot_t)=0 |
Calls method on the D-Bus object asynchronously. | |
virtual PendingAsyncCall | callMethodAsync (const MethodCall &message, async_reply_handler asyncReplyCallback, uint64_t timeout)=0 |
Calls method on the D-Bus object asynchronously, with custom timeout. | |
virtual Slot | callMethodAsync (const MethodCall &message, async_reply_handler asyncReplyCallback, uint64_t timeout, return_slot_t)=0 |
Calls method on the D-Bus object asynchronously, with custom timeout. | |
template<typename _Rep , typename _Period > | |
PendingAsyncCall | callMethodAsync (const MethodCall &message, async_reply_handler asyncReplyCallback, const std::chrono::duration< _Rep, _Period > &timeout) |
template<typename _Rep , typename _Period > | |
Slot | callMethodAsync (const MethodCall &message, async_reply_handler asyncReplyCallback, const std::chrono::duration< _Rep, _Period > &timeout, return_slot_t) |
virtual std::future< MethodReply > | callMethodAsync (const MethodCall &message, with_future_t)=0 |
Calls method on the D-Bus object asynchronously. | |
virtual std::future< MethodReply > | callMethodAsync (const MethodCall &message, uint64_t timeout, with_future_t)=0 |
Calls method on the D-Bus object asynchronously, with custom timeout. | |
template<typename _Rep , typename _Period > | |
std::future< MethodReply > | callMethodAsync (const MethodCall &message, const std::chrono::duration< _Rep, _Period > &timeout, with_future_t) |
virtual void | registerSignalHandler (const InterfaceName &interfaceName, const SignalName &signalName, signal_handler signalHandler)=0 |
Registers a handler for the desired signal emitted by the D-Bus object. | |
virtual Slot | registerSignalHandler (const InterfaceName &interfaceName, const SignalName &signalName, signal_handler signalHandler, return_slot_t)=0 |
Registers a handler for the desired signal emitted by the D-Bus object. | |
Protected Member Functions | |
virtual MethodCall | createMethodCall (const char *interfaceName, const char *methodName)=0 |
virtual void | registerSignalHandler (const char *interfaceName, const char *signalName, signal_handler signalHandler)=0 |
virtual Slot | registerSignalHandler (const char *interfaceName, const char *signalName, signal_handler signalHandler, return_slot_t)=0 |
Protected Attributes | |
friend | MethodInvoker |
friend | AsyncMethodInvoker |
friend | SignalSubscriber |
IProxy class represents a proxy object, which is a convenient local object created to represent a remote D-Bus object in another process. The proxy enables calling methods on remote objects, receiving signals from remote objects, and getting/setting properties of remote objects.
All IProxy member methods throw sdbus::Error
in case of D-Bus or sdbus-c++ error. The IProxy class has been designed as thread-aware. However, the operation of creating and sending method calls (both synchronously and asynchronously) is thread-safe by design.
|
inlinenodiscard |
Calls method on the D-Bus object.
[in] | methodName | Name of the method |
This is a high-level, convenience way of calling D-Bus methods that abstracts from the D-Bus message concept. Method arguments/return value are automatically (de)serialized in a message and D-Bus signatures automatically deduced from the provided native arguments and return values.
Example of use:
sdbus::Error | in case of failure |
|
pure virtual |
Calls method on the remote D-Bus object.
[in] | message | Message representing a method call |
The call does not block if the method call has dont-expect-reply flag set. In that case, the call returns immediately and the return value is an empty, invalid method reply.
The call blocks otherwise, waiting for the remote peer to send back a reply or an error, or until the call times out.
While blocking, other concurrent operations (in other threads) on the underlying bus connection are stalled until the call returns. This is not an issue in vast majority of (simple, single-threaded) applications. In asynchronous, multi-threaded designs involving shared bus connections, this may be an issue. It is advised to instead use an asynchronous callMethod() function overload, which does not block the bus connection, or do the synchronous call from another Proxy instance created just before the call and then destroyed (which is anyway quite a typical approach in D-Bus implementations). Such proxy instance must have its own bus connection. So-called light-weight proxies (ones created with dont_run_event_loop_thread
tag are designed for exactly that purpose.
The default D-Bus method call timeout is used. See IConnection::getMethodCallTimeout().
Note: To avoid messing with messages, use API on a higher level of abstraction defined below.
sdbus::Error | in case of failure (also in case the remote function returned an error) |
|
inline |
Calls method on the remote D-Bus object.
[in] | message | Message representing a method call |
[in] | timeout | Method call timeout (in microseconds) |
The call does not block if the method call has dont-expect-reply flag set. In that case, the call returns immediately and the return value is an empty, invalid method reply.
The call blocks otherwise, waiting for the remote peer to send back a reply or an error, or until the call times out.
While blocking, other concurrent operations (in other threads) on the underlying bus connection are stalled until the call returns. This is not an issue in vast majority of (simple, single-threaded) applications. In asynchronous, multi-threaded designs involving shared bus connections, this may be an issue. It is advised to instead use an asynchronous callMethod() function overload, which does not block the bus connection, or do the synchronous call from another Proxy instance created just before the call and then destroyed (which is anyway quite a typical approach in D-Bus implementations). Such proxy instance must have its own bus connection. So-called light-weight proxies (ones created with dont_run_event_loop_thread
tag are designed for exactly that purpose.
If timeout is zero, the default D-Bus method call timeout is used. See IConnection::getMethodCallTimeout().
Note: To avoid messing with messages, use API on a higher level of abstraction defined below.
sdbus::Error | in case of failure (also in case the remote function returned an error) |
|
pure virtual |
Calls method on the remote D-Bus object.
[in] | message | Message representing a method call |
[in] | timeout | Method call timeout (in microseconds) |
The call does not block if the method call has dont-expect-reply flag set. In that case, the call returns immediately and the return value is an empty, invalid method reply.
The call blocks otherwise, waiting for the remote peer to send back a reply or an error, or until the call times out.
While blocking, other concurrent operations (in other threads) on the underlying bus connection are stalled until the call returns. This is not an issue in vast majority of (simple, single-threaded) applications. In asynchronous, multi-threaded designs involving shared bus connections, this may be an issue. It is advised to instead use an asynchronous callMethod() function overload, which does not block the bus connection, or do the synchronous call from another Proxy instance created just before the call and then destroyed (which is anyway quite a typical approach in D-Bus implementations). Such proxy instance must have its own bus connection. So-called light-weight proxies (ones created with dont_run_event_loop_thread
tag are designed for exactly that purpose.
If timeout is zero, the default D-Bus method call timeout is used. See IConnection::getMethodCallTimeout().
Note: To avoid messing with messages, use API on a higher level of abstraction defined below.
sdbus::Error | in case of failure (also in case the remote function returned an error) |
|
inlinenodiscard |
Calls method on the D-Bus object.
[in] | methodName | Name of the method |
This is a high-level, convenience way of calling D-Bus methods that abstracts from the D-Bus message concept. Method arguments/return value are automatically (de)serialized in a message and D-Bus signatures automatically deduced from the provided native arguments and return values.
Example of use:
sdbus::Error | in case of failure |
|
inlinenodiscard |
Calls method on the D-Bus object.
[in] | methodName | Name of the method |
This is a high-level, convenience way of calling D-Bus methods that abstracts from the D-Bus message concept. Method arguments/return value are automatically (de)serialized in a message and D-Bus signatures automatically deduced from the provided native arguments and return values.
Example of use:
sdbus::Error | in case of failure |
|
inlinenodiscard |
Calls method on the D-Bus object asynchronously.
[in] | methodName | Name of the method |
This is a high-level, convenience way of calling D-Bus methods that abstracts from the D-Bus message concept. Method arguments/return value are automatically (de)serialized in a message and D-Bus signatures automatically deduced from the provided native arguments and return values.
Example of use:
sdbus::Error | in case of failure |
|
pure virtual |
Calls method on the D-Bus object asynchronously.
[in] | message | Message representing an async method call |
[in] | asyncReplyCallback | Handler for the async reply |
This is a callback-based way of asynchronously calling a remote D-Bus method.
The call itself is non-blocking. It doesn't wait for the reply. Once the reply arrives, the provided async reply handler will get invoked from the context of the bus connection I/O event loop thread.
An non-owning, observing async call handle is returned that can be used to query call status or cancel the call.
The default D-Bus method call timeout is used. See IConnection::getMethodCallTimeout().
Note: To avoid messing with messages, use API on a higher level of abstraction defined below.
sdbus::Error | in case of failure |
|
inline |
|
inlinenodiscard |
|
nodiscardpure virtual |
Calls method on the D-Bus object asynchronously.
[in] | message | Message representing an async method call |
[in] | asyncReplyCallback | Handler for the async reply |
This is a callback-based way of asynchronously calling a remote D-Bus method.
The call itself is non-blocking. It doesn't wait for the reply. Once the reply arrives, the provided async reply handler will get invoked from the context of the bus connection I/O event loop thread.
A slot (an owning handle) is returned for the async call. Lifetime of the call is bound to the lifetime of the slot. The slot can be used to cancel the method call at a later time by simply destroying it.
The default D-Bus method call timeout is used. See IConnection::getMethodCallTimeout().
Note: To avoid messing with messages, use API on a higher level of abstraction defined below.
sdbus::Error | in case of failure |
|
pure virtual |
Calls method on the D-Bus object asynchronously, with custom timeout.
[in] | message | Message representing an async method call |
[in] | asyncReplyCallback | Handler for the async reply |
[in] | timeout | Method call timeout (in microseconds) |
This is a callback-based way of asynchronously calling a remote D-Bus method.
The call itself is non-blocking. It doesn't wait for the reply. Once the reply arrives, the provided async reply handler will get invoked from the context of the bus connection I/O event loop thread.
An non-owning, observing async call handle is returned that can be used to query call status or cancel the call.
If timeout is zero, the default D-Bus method call timeout is used. See IConnection::getMethodCallTimeout().
Note: To avoid messing with messages, use API on a higher level of abstraction defined below.
sdbus::Error | in case of failure |
|
nodiscardpure virtual |
Calls method on the D-Bus object asynchronously, with custom timeout.
[in] | message | Message representing an async method call |
[in] | asyncReplyCallback | Handler for the async reply |
[in] | timeout | Method call timeout (in microseconds) |
This is a callback-based way of asynchronously calling a remote D-Bus method.
The call itself is non-blocking. It doesn't wait for the reply. Once the reply arrives, the provided async reply handler will get invoked from the context of the bus connection I/O event loop thread.
A slot (an owning handle) is returned for the async call. Lifetime of the call is bound to the lifetime of the slot. The slot can be used to cancel the method call at a later time by simply destroying it.
If timeout is zero, the default D-Bus method call timeout is used. See IConnection::getMethodCallTimeout().
Note: To avoid messing with messages, use API on a higher level of abstraction defined below.
sdbus::Error | in case of failure |
|
inline |
|
pure virtual |
Calls method on the D-Bus object asynchronously, with custom timeout.
[in] | message | Message representing an async method call |
[in] | timeout | Method call timeout |
[in] | Tag | denoting a std::future-based overload |
This is a std::future-based way of asynchronously calling a remote D-Bus method.
The call itself is non-blocking. It doesn't wait for the reply. Once the reply arrives, the provided future object will be set to contain the reply (or sdbus::Error in case the remote method threw an exception, or the call timed out).
If timeout is zero, the default D-Bus method call timeout is used. See IConnection::getMethodCallTimeout().
Note: To avoid messing with messages, use higher-level API defined below.
sdbus::Error | in case of failure |
|
pure virtual |
Calls method on the D-Bus object asynchronously.
[in] | message | Message representing an async method call |
[in] | Tag | denoting a std::future-based overload |
This is a std::future-based way of asynchronously calling a remote D-Bus method.
The call itself is non-blocking. It doesn't wait for the reply. Once the reply arrives, the provided future object will be set to contain the reply (or sdbus::Error in case the remote method threw an exception).
The default D-Bus method call timeout is used. See IConnection::getMethodCallTimeout().
Note: To avoid messing with messages, use higher-level API defined below.
sdbus::Error | in case of failure |
|
inlinenodiscard |
Calls method on the D-Bus object asynchronously.
[in] | methodName | Name of the method |
This is a high-level, convenience way of calling D-Bus methods that abstracts from the D-Bus message concept. Method arguments/return value are automatically (de)serialized in a message and D-Bus signatures automatically deduced from the provided native arguments and return values.
Example of use:
sdbus::Error | in case of failure |
|
inlinenodiscard |
Calls method on the D-Bus object asynchronously.
[in] | methodName | Name of the method |
This is a high-level, convenience way of calling D-Bus methods that abstracts from the D-Bus message concept. Method arguments/return value are automatically (de)serialized in a message and D-Bus signatures automatically deduced from the provided native arguments and return values.
Example of use:
sdbus::Error | in case of failure |
|
nodiscardpure virtual |
Creates a method call message.
[in] | interfaceName | Name of an interface that provides a given method |
[in] | methodName | Name of the method |
Serialize method arguments into the returned message and invoke the method by passing the message with serialized arguments to the callMethod
function. Alternatively, use higher-level API callMethod(const std::string& methodName)
defined below.
sdbus::Error | in case of failure |
|
inlinenodiscard |
Gets values of all properties of the D-Bus object.
This is a high-level, convenience way of reading D-Bus properties' values that abstracts from the D-Bus message concept.
Example of use:
sdbus::Error | in case of failure |
|
inlinenodiscard |
Gets values of all properties of the D-Bus object asynchronously.
This is a high-level, convenience way of reading D-Bus properties' values that abstracts from the D-Bus message concept.
Example of use:
sdbus::Error | in case of failure |
|
nodiscardpure virtual |
Provides D-Bus connection used by the proxy.
|
nodiscardpure virtual |
Provides access to the currently processed D-Bus message.
This method provides access to the currently processed incoming D-Bus message. "Currently processed" means that the registered callback handler(s) for that message are being invoked. This method is meant to be called from within a callback handler (e.g. from a D-Bus signal handler, or async method reply handler, etc.). In such a case it is guaranteed to return a valid D-Bus message instance for which the handler is called. If called from other contexts/threads, it may return a valid or invalid message, depending on whether a message was processed or not at the time of the call.
|
inlinenodiscard |
Gets value of a property of the D-Bus object.
[in] | propertyName | Name of the property |
This is a high-level, convenience way of reading D-Bus property values that abstracts from the D-Bus message concept. sdbus::Variant is returned which shall then be converted to the real property type (implicit conversion is supported).
Example of use:
sdbus::Error | in case of failure |
|
inlinenodiscard |
Gets value of a property of the D-Bus object.
[in] | propertyName | Name of the property |
This is a high-level, convenience way of reading D-Bus property values that abstracts from the D-Bus message concept. sdbus::Variant is returned which shall then be converted to the real property type (implicit conversion is supported).
Example of use:
sdbus::Error | in case of failure |
|
inlinenodiscard |
Gets value of a property of the D-Bus object asynchronously.
[in] | propertyName | Name of the property |
This is a high-level, convenience way of reading D-Bus property values that abstracts from the D-Bus message concept.
Example of use:
sdbus::Error | in case of failure |
|
inlinenodiscard |
Gets value of a property of the D-Bus object asynchronously.
[in] | propertyName | Name of the property |
This is a high-level, convenience way of reading D-Bus property values that abstracts from the D-Bus message concept.
Example of use:
sdbus::Error | in case of failure |
|
pure virtual |
Registers a handler for the desired signal emitted by the D-Bus object.
[in] | interfaceName | Name of an interface that the signal belongs to |
[in] | signalName | Name of the signal |
[in] | signalHandler | Callback that implements the body of the signal handler |
A signal can be subscribed to at any time during proxy lifetime. The subscription is active immediately after the call, and stays active for the entire lifetime of the Proxy object.
To be able to unsubscribe from the signal at a later time, use the registerSignalHandler() overload with request_slot tag.
sdbus::Error | in case of failure |
|
nodiscardpure virtual |
Registers a handler for the desired signal emitted by the D-Bus object.
[in] | interfaceName | Name of an interface that the signal belongs to |
[in] | signalName | Name of the signal |
[in] | signalHandler | Callback that implements the body of the signal handler |
A signal can be subscribed to and unsubscribed from at any time during proxy lifetime. The subscription is active immediately after the call. The lifetime of the subscription is bound to the lifetime of the slot object. The subscription is unregistered by letting go of the slot object.
sdbus::Error | in case of failure |
|
inlinenodiscard |
Sets value of a property of the D-Bus object.
[in] | propertyName | Name of the property |
This is a high-level, convenience way of writing D-Bus property values that abstracts from the D-Bus message concept. Setting property value with NoReply flag is also supported.
Example of use:
sdbus::Error | in case of failure |
|
inlinenodiscard |
Sets value of a property of the D-Bus object.
[in] | propertyName | Name of the property |
This is a high-level, convenience way of writing D-Bus property values that abstracts from the D-Bus message concept. Setting property value with NoReply flag is also supported.
Example of use:
sdbus::Error | in case of failure |
|
inlinenodiscard |
Sets value of a property of the D-Bus object asynchronously.
[in] | propertyName | Name of the property |
This is a high-level, convenience way of writing D-Bus property values that abstracts from the D-Bus message concept.
Example of use:
sdbus::Error | in case of failure |
|
inlinenodiscard |
Sets value of a property of the D-Bus object asynchronously.
[in] | propertyName | Name of the property |
This is a high-level, convenience way of writing D-Bus property values that abstracts from the D-Bus message concept.
Example of use:
sdbus::Error | in case of failure |
|
pure virtual |
Unregisters proxy's signal handlers and stops receiving replies to pending async calls.
Unregistration is done automatically also in proxy's destructor. This method makes sense if, in the process of proxy removal, we need to make sure that callbacks are unregistered explicitly before the final destruction of the proxy instance.
sdbus::Error | in case of failure |
|
inlinenodiscard |
Registers signal handler for a given signal of the D-Bus object.
[in] | signalName | Name of the signal |
This is a high-level, convenience way of registering to D-Bus signals that abstracts from the D-Bus message concept. Signal arguments are automatically serialized in a message and D-Bus signatures automatically deduced from the parameters of the provided native signal callback.
A signal can be subscribed to and unsubscribed from at any time during proxy lifetime. The subscription is active immediately after the call.
Example of use:
sdbus::Error | in case of failure |
|
inlinenodiscard |
Registers signal handler for a given signal of the D-Bus object.
[in] | signalName | Name of the signal |
This is a high-level, convenience way of registering to D-Bus signals that abstracts from the D-Bus message concept. Signal arguments are automatically serialized in a message and D-Bus signatures automatically deduced from the parameters of the provided native signal callback.
A signal can be subscribed to and unsubscribed from at any time during proxy lifetime. The subscription is active immediately after the call.
Example of use:
sdbus::Error | in case of failure |
|
inlinenodiscard |
Registers signal handler for a given signal of the D-Bus object.
[in] | signalName | Name of the signal |
This is a high-level, convenience way of registering to D-Bus signals that abstracts from the D-Bus message concept. Signal arguments are automatically serialized in a message and D-Bus signatures automatically deduced from the parameters of the provided native signal callback.
A signal can be subscribed to and unsubscribed from at any time during proxy lifetime. The subscription is active immediately after the call.
Example of use:
sdbus::Error | in case of failure |