QDBusAbstractAdaptor Class Reference

#include <qdbusabstractadaptor.h>

Inheritance diagram for QDBusAbstractAdaptor:

Inheritance graph
[legend]
Collaboration diagram for QDBusAbstractAdaptor:

Collaboration graph
[legend]
List of all members.

Detailed Description

The QDBusAbstractAdaptor class is the base class of D-Bus adaptor classes.

QtDBus

Since:
4.2
The QDBusAbstractAdaptor class is the starting point for all objects intending to provide interfaces to the external world using D-Bus. This is accomplished by attaching a one or more classes derived from QDBusAbstractAdaptor to a normal QObject and then registering that QObject with QDBusConnection::registerObject. QDBusAbstractAdaptor objects are intended to be light-weight wrappers, mostly just relaying calls into the real object (its parent) and the signals from it.

Each QDBusAbstractAdaptor-derived class should define the D-Bus interface it is implementing using the Q_CLASSINFO macro in the class definition.

QDBusAbstractAdaptor uses the standard QObject mechanism of signals, slots and properties to determine what signals, methods and properties to export to the bus. Any signal emitted by QDBusAbstractAdaptor-derived classes will be automatically be relayed through any D-Bus connections the object is registered on.

Classes derived from QDBusAbstractAdaptor must be created on the heap using the new operator and must not be deleted by the user (they will be deleted automatically when the object they are connected to is also deleted).

See also:
{usingadaptors.html}{Using adaptors}, QDBusConnection

Definition at line 34 of file qdbusabstractadaptor.h.

Public Member Functions

 ~QDBusAbstractAdaptor ()

Protected Member Functions

 QDBusAbstractAdaptor (QObject *parent)
void setAutoRelaySignals (bool enable)
bool autoRelaySignals () const


Constructor & Destructor Documentation

QDBusAbstractAdaptor::QDBusAbstractAdaptor ( QObject obj  )  [protected]

Constructs a QDBusAbstractAdaptor with obj as the parent object.

Definition at line 111 of file qdbusabstractadaptor.cpp.

References QCoreApplication::instance(), QMetaObject::invokeMethod(), qDBusCreateAdaptorConnector(), Qt::QueuedConnection, QObject::thread(), and QDBusAdaptorConnector::waitingForPolish.

00112     : QObject(*new QDBusAbstractAdaptorPrivate, obj)
00113 {
00114     Q_ASSERT_X(QCoreApplication::instance() == 0 ||
00115                thread() == QCoreApplication::instance()->thread(),
00116                "QDBusAbstractAdaptor", "D-BUS Adaptors must be created in the main thread");
00117 
00118     QDBusAdaptorConnector *connector = qDBusCreateAdaptorConnector(obj);
00119 
00120     connector->waitingForPolish = true;
00121     QMetaObject::invokeMethod(connector, "polish", Qt::QueuedConnection);
00122 }

Here is the call graph for this function:

QDBusAbstractAdaptor::~QDBusAbstractAdaptor (  ) 

Destroys the adaptor.

Warning:
Adaptors are destroyed automatically when the real object they refer to is destroyed. Do not delete the adaptors yourself.

Definition at line 130 of file qdbusabstractadaptor.cpp.

00131 {
00132 }


Member Function Documentation

void QDBusAbstractAdaptor::setAutoRelaySignals ( bool  enable  )  [protected]

Toggles automatic signal relaying from the real object (see object()).

Automatic signal relaying consists of signal-to-signal connection of the signals on the parent that have the exact same method signatue in both classes.

If enable is set to true, connect the signals; if set to false, disconnect all signals.

Definition at line 142 of file qdbusabstractadaptor.cpp.

References QObject::connect(), QObject::disconnect(), QMetaObject::indexOfSignal(), QMetaObject::method(), QMetaObject::methodCount(), QMetaObject::normalizedSignature(), QObject::parent(), QByteArray::prepend(), QSIGNAL_CODE, and QMetaMethod::Signal.

00143 {
00144     const QMetaObject *us = metaObject();
00145     const QMetaObject *them = parent()->metaObject();
00146     bool connected = false;
00147     for (int idx = staticMetaObject.methodCount(); idx < us->methodCount(); ++idx) {
00148         QMetaMethod mm = us->method(idx);
00149 
00150         if (mm.methodType() != QMetaMethod::Signal)
00151             continue;
00152 
00153         // try to connect/disconnect to a signal on the parent that has the same method signature
00154         QByteArray sig = QMetaObject::normalizedSignature(mm.signature());
00155         if (them->indexOfSignal(sig) == -1)
00156             continue;
00157         sig.prepend(QSIGNAL_CODE + '0');
00158         parent()->disconnect(sig, this, sig);
00159         if (enable)
00160             connected = connect(parent(), sig, sig) || connected;
00161     }
00162     d_func()->autoRelaySignals = connected;
00163 }

Here is the call graph for this function:

bool QDBusAbstractAdaptor::autoRelaySignals (  )  const [protected]

Returns true if automatic signal relaying from the real object (see object()) is enabled, otherwiser returns false.

See also:
setAutoRelaySignals()

Definition at line 171 of file qdbusabstractadaptor.cpp.

00172 {
00173     return d_func()->autoRelaySignals;
00174 }


The documentation for this class was generated from the following files:
Generated on Thu Mar 15 17:09:25 2007 for Qt 4.2 User's Guide by  doxygen 1.5.1