![]() |
CopperSpice DBUS
1.7.4
|
The QDBusContext class allows slots to determine the D-Bus context of the calls. More...
Public Methods | |
QDBusContext () | |
~QDBusContext () | |
bool | calledFromDBus () const |
QDBusConnection | connection () const |
bool | isDelayedReply () const |
const QDBusMessage & | message () const |
void | sendErrorReply (const QString &name, const QString &msg=QString ()) const |
void | sendErrorReply (QDBusError::ErrorType type, const QString &msg=QString ()) const |
void | setDelayedReply (bool enable) const |
The QDBusContext class allows slots to determine the D-Bus context of the calls. When a slot is called in an object due to a signal delivery or due to a remote method call, it is sometimes necessary to know the context in which that happened. In particular, if the slot determines that it wants to send the reply at a later opportunity or if it wants to reply with an error, the context is needed.
The QDBusContext class is an alternative to accessing the context that does not involve modifying the code generated by the &CsDbus XML compiler (qdbusxml2cpp).
QDBusContext is used by subclassing it from the objects being exported using QDBusConnection::registerObject(). The following example illustrates the usage:
BROOM - fix
QDBusContext::QDBusContext | ( | ) |
Constructs an empty QDBusContext.
QDBusContext::~QDBusContext | ( | ) |
The destructor does nothing.
bool QDBusContext::calledFromDBus | ( | ) | const |
broom text
Returns true if a CsDbus call is currently being processed. If this method returns false, then calling other methods in this class can result in undefined behavior.
QDBusConnection QDBusContext::connection | ( | ) | const |
Returns the connection from which this call was received.
bool QDBusContext::isDelayedReply | ( | ) | const |
Returns true if this call will have a delayed reply.
const QDBusMessage & QDBusContext::message | ( | ) | const |
Returns the message that generated this call.
void QDBusContext::sendErrorReply | ( | const QString & | name, |
const QString & | msg = QString() |
||
) | const |
Sends an error name as a reply to the caller. The optional msg parameter is a human-readable text explaining the failure. If an error is sent the return value and any output parameters from the called slot will be ignored by &CsDbus.
void QDBusContext::sendErrorReply | ( | QDBusError::ErrorType | type, |
const QString & | msg = QString() |
||
) | const |
Sends an error type as a reply to the caller. The optional msg parameter is a human-readable text explaining the failure. If an error is sent, the return value and any output parameters from the called slot will be ignored by &CsDbus.
void QDBusContext::setDelayedReply | ( | bool | enable | ) | const |
Sets whether this call will have a delayed reply or not.
If enable is false &CsDbus will automatically generate a reply back to the caller, if needed, as soon as the called slot returns. If enable is true &CsDbus will not generate automatic replies. It will also ignore the return value from the slot and any output parameters. Instead, the called object is responsible for storing the incoming message and send a reply or error at a later time.
Failing to send a reply will result in an automatic timeout error being generated by D-Bus.