Phosphor
Qt6 / Wayland library suite for window-management tools
 
Loading...
Searching...
No Matches
PhosphorDBus::Client Class Reference

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.
 

Detailed Description

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()).

Constructor & Destructor Documentation

◆ Client()

PhosphorDBus::Client::Client ( QDBusConnection  connection,
QString  service,
QString  objectPath,
const QLoggingCategory *  log = nullptr 
)
Parameters
connectionBus connection to issue calls on (e.g. session bus).
serviceDestination D-Bus service name.
objectPathDestination object path.
logLogging 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.

Member Function Documentation

◆ asyncCall()

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.

◆ connection()

QDBusConnection PhosphorDBus::Client::connection ( ) const
inline

◆ createCall()

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.

◆ fireAndForget()

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.

Parameters
parentQObject parent for the watcher (must be non-null).
interfaceD-Bus interface name.
methodMethod name.
argsMethod arguments.
logContextHuman-readable label for the warning log.

◆ objectPath()

QString PhosphorDBus::Client::objectPath ( ) const
inline

◆ sendOneWay()

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.

◆ service()

QString PhosphorDBus::Client::service ( ) const
inline

◆ syncCall()

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.

Parameters
timeoutMsReply timeout; pass a negative value for the QtDBus default. Returns a message of type ErrorMessage on failure or timeout.

The documentation for this class was generated from the following file: