Client interface to a remote service object. More...
#include <qdbusproxy.h>
Signals | |
void | dbusSignal (const QDBusMessage &message) |
Signal emitted for D-Bus signals from the peer. | |
void | asyncReply (int callID, const QDBusMessage &message) |
Signal emitted for received replies to asynchronous method calls. | |
Public Member Functions | |
QDBusProxy (QObject *parent=0, const char *name=0) | |
Creates a proxy without binding it to a service or connection. | |
QDBusProxy (const QDBusConnection &connection, QObject *parent=0, const char *name=0) | |
Creates a proxy on a given connection without binding it to a service. | |
QDBusProxy (const QString &service, const QString &path, const QString &interface, const QDBusConnection &connection, QObject *parent=0, const char *name=0) | |
Creates a proxy for a given peer on a given connection. | |
virtual | ~QDBusProxy () |
Destroys the proxy instance. | |
bool | setConnection (const QDBusConnection &connection) |
Sets the D-Bus connection to work on. | |
const QDBusConnection & | connection () const |
Returns the currently used D-Bus connection. | |
void | setService (const QString &service) |
Sets the peer's service name. | |
QString | service () const |
Returns the peer's service name. | |
void | setPath (const QString &path) |
Sets the peer's object path. | |
QString | path () const |
Returns the peer's object path. | |
void | setInterface (const QString &interface) |
Sets the name of the peer interface. | |
QString | interface () const |
Returns the name of the peer interface. | |
bool | canSend () const |
Returns whether the proxy can be used to send method calls. | |
bool | send (const QString &method, const QValueList< QDBusData > ¶ms) const |
Sends a method call to the peer object. | |
QDBusMessage | sendWithReply (const QString &method, const QValueList< QDBusData > ¶ms, QDBusError *error=0) const |
Sends a method call to the peer object and waits for the reply. | |
int | sendWithAsyncReply (const QString &method, const QValueList< QDBusData > ¶ms) |
Sends a method call to the peer object but does not wait for an answer. | |
QDBusError | lastError () const |
Returns the last error seen by the proxy. | |
Protected Slots | |
virtual void | handleDBusSignal (const QDBusMessage &message) |
Handles D-Bus signals received on the proxy's connection. | |
virtual void | handleAsyncReply (const QDBusMessage &message) |
Handles replies to asynchronous method calls. |
Client interface to a remote service object.
QDBusProxy provides a convenience interface for working with D-Bus services, or more precisely, interfaces of D-Bus service objects.
A D-Bus service object is identified through the name of its host application on the bus and its path (logical location) within the host application. Such a service object can implement any number of interfaces, i.e. groups methods and signals, and can create a QDBusProxy instance for every one your application needs to work with.
See section Using D-Bus as a client for documentation on how to use QDBusProxy
QDBusProxy::QDBusProxy | ( | QObject * | parent = 0 , |
|
const char * | name = 0 | |||
) |
Creates a proxy without binding it to a service or connection.
This basic constructor allows to create a proxy and specify the peer object and interface later on.
parent | QObject parent | |
name | QObject name |
QDBusProxy::QDBusProxy | ( | const QDBusConnection & | connection, | |
QObject * | parent = 0 , |
|||
const char * | name = 0 | |||
) |
Creates a proxy on a given connection without binding it to a service.
Similar to the above constructor, it does not yet specify and details about the proxy's peer, but already specifies which connection to work on.
This can be useful to monitor all signal on a connection without filtering for a specific peer.
connection | the D-Bus connection to work on | |
parent | QObject parent | |
name | QObject name |
QDBusProxy::QDBusProxy | ( | const QString & | service, | |
const QString & | path, | |||
const QString & | interface, | |||
const QDBusConnection & | connection, | |||
QObject * | parent = 0 , |
|||
const char * | name = 0 | |||
) |
Creates a proxy for a given peer on a given connection.
This creates a proxy for a specific peer object-interface combination It is equvalent to creating an "empty" proxy and calling setConnection(), setService(), setPath() and setInterface() manually.
service | the name the peer's host application uses on the bus | |
path | the peer object's path within its host application | |
interface | the interface to work with | |
connection | the D-Bus connection to work on | |
parent | QObject parent | |
name | QObject name |
virtual QDBusProxy::~QDBusProxy | ( | ) | [virtual] |
Destroys the proxy instance.
void QDBusProxy::asyncReply | ( | int | callID, | |
const QDBusMessage & | message | |||
) | [signal] |
Signal emitted for received replies to asynchronous method calls.
If a method invoked by using sendWithAsyncReply() send a response, e.g. method return value or errors, this signal is emitted to notify the proxy's user.
callID | the method call's serial number as returned by sendWithAsyncReply() | |
message | the reply's content |
bool QDBusProxy::canSend | ( | ) | const |
Returns whether the proxy can be used to send method calls.
The capabilitly to send method calls depends on having all necessary base information:
and a working connection, see setConnection()
true
if method calls can be sent, false
if any of the three base information is missing or if the connection is not connectedconst QDBusConnection& QDBusProxy::connection | ( | ) | const |
Returns the currently used D-Bus connection.
void QDBusProxy::dbusSignal | ( | const QDBusMessage & | message | ) | [signal] |
Signal emitted for D-Bus signals from the peer.
Signals received on the proxy's connection are filtered by handleDBusSignal() for all proxy properties that are not empty.
message | the signal's content |
virtual void QDBusProxy::handleAsyncReply | ( | const QDBusMessage & | message | ) | [protected, virtual, slot] |
Handles replies to asynchronous method calls.
The base implementation simply extracts the reply's error and makes it available for lastError(). It then emits asyncReply()
message | the D-Bus reply message as received |
virtual void QDBusProxy::handleDBusSignal | ( | const QDBusMessage & | message | ) | [protected, virtual, slot] |
Handles D-Bus signals received on the proxy's connection.
The base implementation checks each non-empty property, i.e. service name, object path and interface, with the respective field of the signal's D-Bus message.
If all available matches succeed, the message is emitted by dbusSignal(), otherwise it is discarded.
service
will only happen if service
is a unique D-Bus name, i.e. if it starts with a colon ":"
since D-Bus signals carry the sender's unique name and filtering by a requested name would reject all signals.message | the D-Bus signal message as received |
QString QDBusProxy::interface | ( | ) | const |
QDBusError QDBusProxy::lastError | ( | ) | const |
Returns the last error seen by the proxy.
The last error can a connection error, e.g. sending a message failed due connection being lost, or the error of the last call to sendWithReply or the error of the last received asyncReply()
QString QDBusProxy::path | ( | ) | const |
bool QDBusProxy::send | ( | const QString & | method, | |
const QValueList< QDBusData > & | params | |||
) | const |
Sends a method call to the peer object.
This is roughly equivalent to calling a C++ method with no return value or like ignoring the it.
method | the name of the method to invoke | |
params | the method parameters. Use an empty list if the method does not require parameters |
true
if sending succeeded, false
if sending failed, the method name was empty or any of the conditions for successfull sending as described for canSend() are not metint QDBusProxy::sendWithAsyncReply | ( | const QString & | method, | |
const QValueList< QDBusData > & | params | |||
) |
Sends a method call to the peer object but does not wait for an answer.
This is roughly equivalent to calling a C++ method on a local Qt event loop driven object, where the result of the method call is delivered later through a signal.
method | the name of the method to invoke | |
params | the method parameters. Use an empty list if the method does not require parameters |
QDBusMessage QDBusProxy::sendWithReply | ( | const QString & | method, | |
const QValueList< QDBusData > & | params, | |||
QDBusError * | error = 0 | |||
) | const |
Sends a method call to the peer object and waits for the reply.
This is roughly equivalent to calling a C++ method on a local object.
method | the name of the method to invoke | |
params | the method parameters. Use an empty list if the method does not require parameters | |
error | optional parameter to get any error directly |
error
or through lastError()QString QDBusProxy::service | ( | ) | const |
bool QDBusProxy::setConnection | ( | const QDBusConnection & | connection | ) |
Sets the D-Bus connection to work on.
Disconnects from any previously used connection and connects to the new connection's signal distribution. If no peer information has been provided at creation time or through the other set methods, the instance's signal dbusSignal() will emit all signals received on the given connection.
connection | the D-Bus connection to work on |
true
if connecting to the new connection's signal succeeded, false
if it failed, e.g. if the connection is a "null" connectionvoid QDBusProxy::setInterface | ( | const QString & | interface | ) |
Sets the name of the peer interface.
A non-empty interface name is required if the proxy is to be used for method calls. See section Interface names for details.
If a string other than QString::null
is set, it will be used to filter signals, i.e. a signal received by the proxy will only be emitted if the interface name matches.
interface | the peer's interface to work with |
void QDBusProxy::setPath | ( | const QString & | path | ) |
Sets the peer's object path.
A non-empty object path is required if the proxy is to be used for method calls. See section Object paths for details.
If a string other than QString::null
is set, it will be used to filter signals, i.e. a signal received by the proxy will only be emitted if the object path matches.
path | the peer's object path inside its host application (logical address) |
void QDBusProxy::setService | ( | const QString & | service | ) |
Sets the peer's service name.
A non-empty service name is required if the proxy is to be used for method calls. See section Service names for details.
If a string other than QString::null
is set, it will be used to filter signals, i.e. a signal received by the proxy will only be emitted if the service name matches.
service | the peer's name on the bus |