A lightweight, service-agnostic D-Bus method-call client. More...
#include <phosphor-dbus/include/PhosphorDBus/Client.h>
Public Member Functions | |
| Client (QDBusConnection connection, QString service, QString objectPath, const QLoggingCategory *log=nullptr) | |
| QDBusConnection | connection () const |
| QString | service () const |
| QString | objectPath () const |
| void | fireAndForget (QObject *parent, const QString &interface, const QString &method, const QVariantList &args, const QString &logContext={}) const |
| Fire-and-forget async call with error logging. | |
| void | sendOneWay (const QString &interface, const QString &method, const QVariantList &args={}) const |
| Send a one-way notification with no expected reply. | |
| QDBusPendingCall | asyncCall (const QString &interface, const QString &method, const QVariantList &args={}) const |
| Issue an async method call and return the pending result. | |
| QDBusMessage | syncCall (const QString &interface, const QString &method, const QVariantList &args={}, int timeoutMs=-1) const |
| Blocking method call with an explicit timeout. | |
| QDBusMessage | createCall (const QString &interface, const QString &method, const QVariantList &args={}) const |
| Build (but do not send) a method-call message for this target. | |
A lightweight, service-agnostic D-Bus method-call client.
Client is a plain value object — copyable, cheap to construct, holding no shared global state. It binds a (connection, service, objectPath) triple so callers issue method calls without re-typing the destination on every invocation. Each consumer constructs its own; there is no singleton.
All calls use QDBusMessage::createMethodCall directly rather than QDBusInterface, so no synchronous wire introspection ever blocks the calling thread (important for compositor plugins).
To talk to a different service, construct another Client. A project that always targets one daemon typically wraps construction in a small factory (e.g. PhosphorProtocol::daemonClient()).
| PhosphorDBus::Client::Client | ( | QDBusConnection | connection, |
| QString | service, | ||
| QString | objectPath, | ||
| const QLoggingCategory * | log = nullptr |
||
| ) |
| connection | Bus connection to issue calls on (e.g. session bus). |
| service | Destination D-Bus service name. |
| objectPath | Destination object path. |
| log | Logging category for call-failure warnings; when null, lcPhosphorDBus() is used. Must have static / program lifetime: fireAndForget's async callback dereferences it after the Client itself may be gone. Categories declared with Q_LOGGING_CATEGORY satisfy this; a stack-allocated category does not. |
| QDBusPendingCall PhosphorDBus::Client::asyncCall | ( | const QString & | interface, |
| const QString & | method, | ||
| const QVariantList & | args = {} |
||
| ) | const |
Issue an async method call and return the pending result.
The caller attaches its own QDBusPendingCallWatcher to consume the reply.
|
inline |
| QDBusMessage PhosphorDBus::Client::createCall | ( | const QString & | interface, |
| const QString & | method, | ||
| const QVariantList & | args = {} |
||
| ) | const |
Build (but do not send) a method-call message for this target.
Exposed for callers that need the raw QDBusMessage — e.g. to attach a bespoke watcher or batch sends.
| void PhosphorDBus::Client::fireAndForget | ( | QObject * | parent, |
| const QString & | interface, | ||
| const QString & | method, | ||
| const QVariantList & | args, | ||
| const QString & | logContext = {} |
||
| ) | const |
Fire-and-forget async call with error logging.
Allocates a QDBusPendingCallWatcher parented to parent so the call is cancelled if the parent is destroyed first. The reply is discarded; only errors are logged.
| parent | QObject parent for the watcher (must be non-null). |
| interface | D-Bus interface name. |
| method | Method name. |
| args | Method arguments. |
| logContext | Human-readable label for the warning log. |
|
inline |
| void PhosphorDBus::Client::sendOneWay | ( | const QString & | interface, |
| const QString & | method, | ||
| const QVariantList & | args = {} |
||
| ) | const |
Send a one-way notification with no expected reply.
Uses QDBusConnection::send, so no watcher is allocated and no reply timeout applies. Use for genuine notifications where allocating a watcher just to ignore the reply would be wasted state.
|
inline |
| QDBusMessage PhosphorDBus::Client::syncCall | ( | const QString & | interface, |
| const QString & | method, | ||
| const QVariantList & | args = {}, |
||
| int | timeoutMs = -1 |
||
| ) | const |
Blocking method call with an explicit timeout.
For the rare paths that legitimately need a synchronous reply. Prefer asyncCall whenever the caller can tolerate a callback.
| timeoutMs | Reply timeout; pass a negative value for the QtDBus default. Returns a message of type ErrorMessage on failure or timeout. |