Qt 4.8
Classes | Public Types | Public Slots | Signals | Public Functions | Static Public Functions | Public Variables | Protected Functions | Private Slots | Private Functions | Friends | List of all members
QDBusConnectionPrivate Class Reference

#include <qdbusconnection_p.h>

Inheritance diagram for QDBusConnectionPrivate:
QObject

Classes

struct  ObjectTreeNode
 
struct  SignalHook
 
struct  WatchedServiceData
 
struct  Watcher
 

Public Types

enum  ConnectionMode { InvalidMode, ServerMode, ClientMode, PeerMode }
 
typedef QHash< QByteArray, int > MatchRefCountHash
 
typedef QHash< QString, QDBusMetaObject *> MetaObjectHash
 
typedef QList< QPair< DBusTimeout *, int > > PendingTimeoutList
 
typedef QMultiHash< QString, SignalHookSignalHookHash
 
typedef QHash< int, DBusTimeout * > TimeoutHash
 
enum  TreeNodeType { Object = 0x0, VirtualObject = 0x01000000 }
 
typedef QHash< QString, WatchedServiceDataWatchedServicesHash
 
typedef QMultiHash< int, WatcherWatcherHash
 

Public Slots

void doDispatch ()
 
void objectDestroyed (QObject *o)
 
void relaySignal (QObject *obj, const QMetaObject *, int signalId, const QVariantList &args)
 
void socketRead (int)
 
void socketWrite (int)
 
- Public Slots inherited from QObject
void deleteLater ()
 Schedules this object for deletion. More...
 

Signals

void callWithCallbackFailed (const QDBusError &error, const QDBusMessage &message)
 
void newServerConnection (const QDBusConnection &connection)
 
void serviceOwnerChanged (const QString &name, const QString &oldOwner, const QString &newOwner)
 
- Signals inherited from QObject
void destroyed (QObject *=0)
 This signal is emitted immediately before the object obj is destroyed, and can not be blocked. More...
 

Public Functions

void closeConnection ()
 
void connectRelay (const QString &service, const QString &path, const QString &interface, QDBusAbstractInterface *receiver, const char *signal)
 
bool connectSignal (const QString &service, const QString &path, const QString &interface, const QString &name, const QStringList &argumentMatch, const QString &signature, QObject *receiver, const char *slot)
 
void connectSignal (const QString &key, const SignalHook &hook)
 
void deleteYourself ()
 
void disconnectRelay (const QString &service, const QString &path, const QString &interface, QDBusAbstractInterface *receiver, const char *signal)
 
SignalHookHash::Iterator disconnectSignal (SignalHookHash::Iterator &it)
 
bool disconnectSignal (const QString &service, const QString &path, const QString &interface, const QString &name, const QStringList &argumentMatch, const QString &signature, QObject *receiver, const char *slot)
 
QDBusMetaObjectfindMetaObject (const QString &service, const QString &path, const QString &interface, QDBusError &error)
 
QString getNameOwner (const QString &service)
 
bool handleMessage (const QDBusMessage &msg)
 
void postEventToThread (int action, QObject *target, QEvent *event)
 
 QDBusConnectionPrivate (QObject *parent=0)
 
void registerObject (const ObjectTreeNode *node)
 
void registerService (const QString &serviceName)
 
int send (const QDBusMessage &message)
 
QDBusMessage sendWithReply (const QDBusMessage &message, int mode, int timeout=-1)
 
QDBusPendingCallPrivatesendWithReplyAsync (const QDBusMessage &message, QObject *receiver, const char *returnMethod, const char *errorMethod, int timeout=-1)
 
QDBusMessage sendWithReplyLocal (const QDBusMessage &message)
 
void serverConnection (const QDBusConnection &connection)
 
void setBusService (const QDBusConnection &connection)
 
void setConnection (DBusConnection *connection, const QDBusErrorInternal &error)
 
void setPeer (DBusConnection *connection, const QDBusErrorInternal &error)
 
void setServer (DBusServer *server, const QDBusErrorInternal &error)
 
void unregisterService (const QString &serviceName)
 
void waitForFinished (QDBusPendingCallPrivate *pcall)
 
 ~QDBusConnectionPrivate ()
 
- Public Functions inherited from QObject
bool blockSignals (bool b)
 If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it). More...
 
const QObjectListchildren () const
 Returns a list of child objects. More...
 
bool connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const
 
bool disconnect (const char *signal=0, const QObject *receiver=0, const char *member=0)
 
bool disconnect (const QObject *receiver, const char *member=0)
 
void dumpObjectInfo ()
 Dumps information about signal connections, etc. More...
 
void dumpObjectTree ()
 Dumps a tree of children to the debug output. More...
 
QList< QByteArraydynamicPropertyNames () const
 Returns the names of all properties that were dynamically added to the object using setProperty(). More...
 
virtual bool event (QEvent *)
 This virtual function receives events to an object and should return true if the event e was recognized and processed. More...
 
virtual bool eventFilter (QObject *, QEvent *)
 Filters events if this object has been installed as an event filter for the watched object. More...
 
template<typename T >
findChild (const QString &aName=QString()) const
 Returns the child of this object that can be cast into type T and that is called name, or 0 if there is no such object. More...
 
template<typename T >
QList< T > findChildren (const QString &aName=QString()) const
 Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects. More...
 
template<typename T >
QList< T > findChildren (const QRegExp &re) const
 
bool inherits (const char *classname) const
 Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false. More...
 
void installEventFilter (QObject *)
 Installs an event filter filterObj on this object. More...
 
bool isWidgetType () const
 Returns true if the object is a widget; otherwise returns false. More...
 
void killTimer (int id)
 Kills the timer with timer identifier, id. More...
 
virtual const QMetaObjectmetaObject () const
 Returns a pointer to the meta-object of this object. More...
 
void moveToThread (QThread *thread)
 Changes the thread affinity for this object and its children. More...
 
QString objectName () const
 
QObjectparent () const
 Returns a pointer to the parent object. More...
 
QVariant property (const char *name) const
 Returns the value of the object's name property. More...
 
Q_INVOKABLE QObject (QObject *parent=0)
 Constructs an object with parent object parent. More...
 
void removeEventFilter (QObject *)
 Removes an event filter object obj from this object. More...
 
void setObjectName (const QString &name)
 
void setParent (QObject *)
 Makes the object a child of parent. More...
 
bool setProperty (const char *name, const QVariant &value)
 Sets the value of the object's name property to value. More...
 
void setUserData (uint id, QObjectUserData *data)
 
bool signalsBlocked () const
 Returns true if signals are blocked; otherwise returns false. More...
 
int startTimer (int interval)
 Starts a timer and returns a timer identifier, or returns zero if it could not start a timer. More...
 
QThreadthread () const
 Returns the thread in which the object lives. More...
 
QObjectUserDatauserData (uint id) const
 
virtual ~QObject ()
 Destroys the object, deleting all its child objects. More...
 

Static Public Functions

static bool checkReplyForDelivery (QDBusConnectionPrivate *target, QObject *object, int idx, const QList< int > &metaTypes, const QDBusMessage &msg)
 
static QDBusConnectionPrivated (const QDBusConnection &q)
 
static int findSlot (QObject *obj, const QByteArray &normalizedName, QList< int > &params)
 
static DBusHandlerResult messageFilter (DBusConnection *, DBusMessage *, void *)
 
static bool prepareHook (QDBusConnectionPrivate::SignalHook &hook, QString &key, const QString &service, const QString &path, const QString &interface, const QString &name, const QStringList &argMatch, QObject *receiver, const char *signal, int minMIdx, bool buildSignature)
 
static QDBusCallDeliveryEventprepareReply (QDBusConnectionPrivate *target, QObject *object, int idx, const QList< int > &metaTypes, const QDBusMessage &msg)
 
static void processFinishedCall (QDBusPendingCallPrivate *call)
 
static QDBusConnection q (QDBusConnectionPrivate *connection)
 
static void setSender (const QDBusConnectionPrivate *s)
 
- Static Public Functions inherited from QObject
static bool connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
 Creates a connection of the given type from the signal in the sender object to the method in the receiver object. More...
 
static bool connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member)
 Disconnects signal in object sender from method in object receiver. More...
 
static bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member)
 
static uint registerUserData ()
 
static QString tr (const char *sourceText, const char *comment=0, int n=-1)
 
static QString trUtf8 (const char *sourceText, const char *comment=0, int n=-1)
 

Public Variables

QString baseService
 
QDBusConnectionInterfacebusService
 
MetaObjectHash cachedMetaObjects
 
QMutex callDeliveryMutex
 
QDBusCallDeliveryEventcallDeliveryState
 
QDBusConnection::ConnectionCapabilities capabilities
 
DBusConnection * connection
 
QMutex dispatchLock
 
QDBusError lastError
 
QReadWriteLock lock
 
MatchRefCountHash matchRefCounts
 
ConnectionMode mode
 
QString name
 
QAtomicInt ref
 
ObjectTreeNode rootNode
 
DBusServer * server
 
QStringList serverConnectionNames
 
QStringList serviceNames
 
SignalHookHash signalHooks
 
TimeoutHash timeouts
 
PendingTimeoutList timeoutsPendingAdd
 
QMutex watchAndTimeoutLock
 
WatchedServicesHash watchedServices
 
WatcherHash watchers
 

Protected Functions

void customEvent (QEvent *e)
 This event handler can be reimplemented in a subclass to receive custom events. More...
 
void timerEvent (QTimerEvent *e)
 This event handler can be reimplemented in a subclass to receive timer events for the object. More...
 
- Protected Functions inherited from QObject
virtual void childEvent (QChildEvent *)
 This event handler can be reimplemented in a subclass to receive child events. More...
 
virtual void connectNotify (const char *signal)
 This virtual function is called when something has been connected to signal in this object. More...
 
virtual void disconnectNotify (const char *signal)
 This virtual function is called when something has been disconnected from signal in this object. More...
 
 QObject (QObjectPrivate &dd, QObject *parent=0)
 
int receivers (const char *signal) const
 Returns the number of receivers connected to the signal. More...
 
QObjectsender () const
 Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns 0. More...
 
int senderSignalIndex () const
 

Private Slots

void registerServiceNoLock (const QString &serviceName)
 
void serviceOwnerChangedNoLock (const QString &name, const QString &oldOwner, const QString &newOwner)
 
void unregisterServiceNoLock (const QString &serviceName)
 

Private Functions

bool activateCall (QObject *object, int flags, const QDBusMessage &msg)
 
bool activateInternalFilters (const ObjectTreeNode &node, const QDBusMessage &msg)
 
void activateObject (ObjectTreeNode &node, const QDBusMessage &msg, int pathStartPos)
 
void activateSignal (const SignalHook &hook, const QDBusMessage &msg)
 
void checkThread ()
 
void deliverCall (QObject *object, int flags, const QDBusMessage &msg, const QList< int > &metaTypes, int slotIdx)
 
QString getNameOwnerNoCache (const QString &service)
 
bool handleError (const QDBusErrorInternal &error)
 
void handleObjectCall (const QDBusMessage &message)
 
void handleSignal (const QString &key, const QDBusMessage &msg)
 
void handleSignal (const QDBusMessage &msg)
 
bool isServiceRegisteredByThread (const QString &serviceName) const
 
void sendError (const QDBusMessage &msg, QDBusError::ErrorType code)
 

Friends

class QDBusActivateObjectEvent
 
class QDBusCallDeliveryEvent
 

Additional Inherited Members

- Static Public Variables inherited from QObject
static const QMetaObject staticMetaObject
 This variable stores the meta-object for the class. More...
 
- Protected Variables inherited from QObject
QScopedPointer< QObjectDatad_ptr
 
- Static Protected Variables inherited from QObject
static const QMetaObject staticQtMetaObject
 

Detailed Description

Definition at line 106 of file qdbusconnection_p.h.

Typedefs

◆ MatchRefCountHash

Definition at line 168 of file qdbusconnection_p.h.

◆ MetaObjectHash

Definition at line 167 of file qdbusconnection_p.h.

◆ PendingTimeoutList

Definition at line 164 of file qdbusconnection_p.h.

◆ SignalHookHash

Definition at line 166 of file qdbusconnection_p.h.

◆ TimeoutHash

typedef QHash<int, DBusTimeout *> QDBusConnectionPrivate::TimeoutHash

Definition at line 163 of file qdbusconnection_p.h.

◆ WatchedServicesHash

Definition at line 178 of file qdbusconnection_p.h.

◆ WatcherHash

Definition at line 162 of file qdbusconnection_p.h.

Enumerations

◆ ConnectionMode

◆ TreeNodeType

Enumerator
Object 
VirtualObject 

Definition at line 132 of file qdbusconnection_p.h.

Constructors and Destructors

◆ QDBusConnectionPrivate()

QDBusConnectionPrivate::QDBusConnectionPrivate ( QObject parent = 0)
explicit

Definition at line 978 of file qdbusintegrator.cpp.

979  : QObject(p), ref(1), capabilities(0), mode(InvalidMode), connection(0), server(0), busService(0),
982 {
983  static const bool threads = q_dbus_threads_init_default();
984  static const int debugging = qgetenv("QDBUS_DEBUG").toInt();
985  ::isDebugging = debugging;
986  Q_UNUSED(threads)
987  Q_UNUSED(debugging)
988 
989 #ifdef QDBUS_THREAD_DEBUG
990  if (debugging > 1)
991  qdbusThreadDebug = qdbusDefaultThreadDebug;
992 #endif
993 
995 
996  rootNode.flags = 0;
997 
998  // prepopulate watchedServices:
999  // we know that the owner of org.freedesktop.DBus is itself
1000  watchedServices.insert(dbusServiceString(), WatchedServiceData(dbusServiceString(), 1));
1001 
1002  // prepopulate matchRefCounts:
1003  // we know that org.freedesktop.DBus will never change owners
1004  matchRefCounts.insert("type='signal',sender='org.freedesktop.DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged',arg0='org.freedesktop.DBus'", 1);
1005 }
Q_CORE_EXPORT QByteArray qgetenv(const char *varName)
static bool isDebugging
MatchRefCountHash matchRefCounts
The QString class provides a Unicode character string.
Definition: qstring.h:83
DBusConnection * connection
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition: qhash.h:753
static void init()
QDBusConnection::ConnectionCapabilities capabilities
Q_INVOKABLE QObject(QObject *parent=0)
Constructs an object with parent object parent.
Definition: qobject.cpp:753
int toInt(bool *ok=0, int base=10) const
Returns the byte array converted to an int using base base, which is 10 by default and must be betwee...
WatchedServicesHash watchedServices
QDBusConnectionInterface * busService
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ ~QDBusConnectionPrivate()

QDBusConnectionPrivate::~QDBusConnectionPrivate ( )

Definition at line 1007 of file qdbusintegrator.cpp.

1008 {
1009  if (thread() && thread() != QThread::currentThread())
1010  qWarning("QDBusConnection(name=\"%s\")'s last reference in not in its creation thread! "
1011  "Timer and socket errors will follow and the program will probably crash",
1012  qPrintable(name));
1013 
1014  closeConnection();
1015  rootNode.children.clear(); // free resources
1017 
1018  if (server)
1019  q_dbus_server_unref(server);
1020  if (connection)
1021  q_dbus_connection_unref(connection);
1022 
1023  connection = 0;
1024  server = 0;
1025 }
DBusConnection * connection
MetaObjectHash cachedMetaObjects
static QThread * currentThread()
Returns a pointer to a QThread which manages the currently executing thread.
Definition: qthread.cpp:419
void clear()
Removes all the elements from the vector and releases the memory used by the vector.
Definition: qvector.h:347
Q_CORE_EXPORT void qWarning(const char *,...)
QThread * thread() const
Returns the thread in which the object lives.
Definition: qobject.cpp:1419
#define qPrintable(string)
Definition: qglobal.h:1750
Q_OUTOFLINE_TEMPLATE void qDeleteAll(ForwardIterator begin, ForwardIterator end)
Definition: qalgorithms.h:319

Functions

◆ activateCall()

bool QDBusConnectionPrivate::activateCall ( QObject object,
int  flags,
const QDBusMessage msg 
)
private

Definition at line 780 of file qdbusintegrator.cpp.

Referenced by activateObject().

781 {
782  // This is called by QDBusConnectionPrivate::handleObjectCall to place a call
783  // to a slot on the object.
784  //
785  // The call is delivered to the first slot that matches the following conditions:
786  // - has the same name as the message's target member
787  // - ALL of the message's types are found in slot's parameter list
788  // - optionally has one more parameter of type QDBusMessage
789  // If none match, then the slot of the same name as the message target and with
790  // the first type of QDBusMessage is delivered.
791  //
792  // The D-Bus specification requires that all MethodCall messages be replied to, unless the
793  // caller specifically waived this requirement. This means that we inspect if the user slot
794  // generated a reply and, if it didn't, we will. Obviously, if the user slot doesn't take a
795  // QDBusMessage parameter, it cannot generate a reply.
796  //
797  // When a return message is generated, the slot's return type, if any, will be placed
798  // in the message's first position. If there are non-const reference parameters to the
799  // slot, they must appear at the end and will be placed in the subsequent message
800  // positions.
801 
802  static const char cachePropertyName[] = "_qdbus_slotCache";
803 
804  if (!object)
805  return false;
806 
807 #ifndef QT_NO_PROPERTIES
809  "QDBusConnection: internal threading error",
810  "function called for an object that is in another thread!!");
811 
812  QDBusSlotCache slotCache =
813  qvariant_cast<QDBusSlotCache>(object->property(cachePropertyName));
814  QString cacheKey = msg.member(), signature = msg.signature();
815  if (!signature.isEmpty()) {
816  cacheKey.reserve(cacheKey.length() + 1 + signature.length());
817  cacheKey += QLatin1Char('.');
818  cacheKey += signature;
819  }
820 
821  QDBusSlotCache::Hash::ConstIterator cacheIt = slotCache.hash.constFind(cacheKey);
822  while (cacheIt != slotCache.hash.constEnd() && cacheIt->flags != flags &&
823  cacheIt.key() == cacheKey)
824  ++cacheIt;
825  if (cacheIt == slotCache.hash.constEnd() || cacheIt.key() != cacheKey)
826  {
827  // not cached, analyze the meta object
828  const QMetaObject *mo = object->metaObject();
830 
831  // find a slot that matches according to the rules above
832  QDBusSlotCache::Data slotData;
833  slotData.flags = flags;
834  slotData.slotIdx = ::findSlot(mo, memberName, flags, msg.signature(), slotData.metaTypes);
835  if (slotData.slotIdx == -1) {
836  // ### this is where we want to add the connection as an arg too
837  // try with no parameters, but with a QDBusMessage
838  slotData.slotIdx = ::findSlot(mo, memberName, flags, QString(), slotData.metaTypes);
839  if (slotData.metaTypes.count() != 2 ||
840  slotData.metaTypes.at(1) != QDBusMetaTypeId::message) {
841  // not found
842  // save the negative lookup
843  slotData.slotIdx = -1;
844  slotData.metaTypes.clear();
845  slotCache.hash.insert(cacheKey, slotData);
846  object->setProperty(cachePropertyName, QVariant::fromValue(slotCache));
847  return false;
848  }
849  }
850 
851  // save to the cache
852  slotCache.hash.insert(cacheKey, slotData);
853  object->setProperty(cachePropertyName, QVariant::fromValue(slotCache));
854 
855  // found the slot to be called
856  deliverCall(object, flags, msg, slotData.metaTypes, slotData.slotIdx);
857  return true;
858  } else if (cacheIt->slotIdx == -1) {
859  // negative cache
860  return false;
861  } else {
862  // use the cache
863  deliverCall(object, flags, msg, cacheIt->metaTypes, cacheIt->slotIdx);
864  return true;
865  }
866 #endif // QT_NO_PROPERTIES
867  return false;
868 }
The QMetaObject class contains meta-information about Qt objects.
Definition: qobjectdefs.h:304
QByteArray toUtf8() const Q_REQUIRED_RESULT
Returns a UTF-8 representation of the string as a QByteArray.
Definition: qstring.cpp:4074
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
const_iterator ConstIterator
Qt-style synonym for QHash::const_iterator.
Definition: qhash.h:474
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
void deliverCall(QObject *object, int flags, const QDBusMessage &msg, const QList< int > &metaTypes, int slotIdx)
The QString class provides a Unicode character string.
Definition: qstring.h:83
static int findSlot(QObject *obj, const QByteArray &normalizedName, QList< int > &params)
QString signature() const
Returns the signature of the signal that was received or for the output arguments of a method call...
void reserve(int size)
Attempts to allocate memory for at least size characters.
Definition: qstring.h:881
static QThread * currentThread()
Returns a pointer to a QThread which manages the currently executing thread.
Definition: qthread.cpp:419
static int message
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
void clear()
Removes all items from the list.
Definition: qlist.h:764
QString member() const
Returns the name of the signal that was emitted or the name of the method that was called...
static QVariant fromValue(const T &value)
Returns a QVariant containing a copy of value.
Definition: qvariant.h:336
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
T qvariant_cast(const QVariant &)
Definition: qvariant.h:571
static QByteArray memberName(const QMetaMethod &member)
QThread * thread() const
Returns the thread in which the object lives.
Definition: qobject.cpp:1419
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ activateInternalFilters()

bool QDBusConnectionPrivate::activateInternalFilters ( const ObjectTreeNode node,
const QDBusMessage msg 
)
private

Definition at line 1331 of file qdbusintegrator.cpp.

Referenced by activateObject().

1333 {
1334  // object may be null
1335  const QString interface = msg.interface();
1336 
1337  if (interface.isEmpty() || interface == QLatin1String(DBUS_INTERFACE_INTROSPECTABLE)) {
1338  if (msg.member() == QLatin1String("Introspect") && msg.signature().isEmpty()) {
1339  //qDebug() << "QDBusConnectionPrivate::activateInternalFilters introspect" << msg.d_ptr->msg;
1340  QDBusMessage reply = msg.createReply(qDBusIntrospectObject(node, msg.path()));
1341  send(reply);
1342  return true;
1343  }
1344 
1345  if (!interface.isEmpty()) {
1347  return true;
1348  }
1349  }
1350 
1351  if (node.obj && (interface.isEmpty() ||
1352  interface == QLatin1String(DBUS_INTERFACE_PROPERTIES))) {
1353  //qDebug() << "QDBusConnectionPrivate::activateInternalFilters properties" << msg.d_ptr->msg;
1354  if (msg.member() == QLatin1String("Get") && msg.signature() == QLatin1String("ss")) {
1355  QDBusMessage reply = qDBusPropertyGet(node, msg);
1356  send(reply);
1357  return true;
1358  } else if (msg.member() == QLatin1String("Set") && msg.signature() == QLatin1String("ssv")) {
1359  QDBusMessage reply = qDBusPropertySet(node, msg);
1360  send(reply);
1361  return true;
1362  } else if (msg.member() == QLatin1String("GetAll") && msg.signature() == QLatin1String("s")) {
1363  QDBusMessage reply = qDBusPropertyGetAll(node, msg);
1364  send(reply);
1365  return true;
1366  }
1367 
1368  if (!interface.isEmpty()) {
1370  return true;
1371  }
1372  }
1373 
1374  return false;
1375 }
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
QString signature() const
Returns the signature of the signal that was received or for the output arguments of a method call...
QString path() const
Returns the path of the object that this message is being sent to (in the case of a method call) or b...
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
QString member() const
Returns the name of the signal that was emitted or the name of the method that was called...
QDBusMessage qDBusPropertyGet(const QDBusConnectionPrivate::ObjectTreeNode &node, const QDBusMessage &msg)
QDBusMessage createReply(const QList< QVariant > &arguments=QList< QVariant >()) const
Constructs a new DBus message representing a reply, with the given arguments.
QDBusMessage qDBusPropertySet(const QDBusConnectionPrivate::ObjectTreeNode &node, const QDBusMessage &msg)
QDBusMessage qDBusPropertyGetAll(const QDBusConnectionPrivate::ObjectTreeNode &node, const QDBusMessage &msg)
QString qDBusIntrospectObject(const QDBusConnectionPrivate::ObjectTreeNode &node, const QString &path)
void sendError(const QDBusMessage &msg, QDBusError::ErrorType code)
The QDBusMessage class represents one message sent or received over the D-Bus bus.
Definition: qdbusmessage.h:59
int send(const QDBusMessage &message)

◆ activateObject()

void QDBusConnectionPrivate::activateObject ( ObjectTreeNode node,
const QDBusMessage msg,
int  pathStartPos 
)
private

Definition at line 1377 of file qdbusintegrator.cpp.

Referenced by handleObjectCall(), and QDBusActivateObjectEvent::placeMetaCall().

1379 {
1380  // This is called by QDBusConnectionPrivate::handleObjectCall to place a call to a slot
1381  // on the object.
1382  //
1383  // The call is routed through the adaptor sub-objects if we have any
1384 
1385  // object may be null
1386 
1387  if (node.flags & QDBusConnectionPrivate::VirtualObject) {
1388  if (node.treeNode->handleMessage(msg, q(this))) {
1389  return;
1390  } else {
1391  if (activateInternalFilters(node, msg))
1392  return;
1393  }
1394  }
1395 
1396  if (pathStartPos != msg.path().length()) {
1397  node.flags &= ~QDBusConnection::ExportAllSignals;
1398  node.obj = findChildObject(&node, msg.path(), pathStartPos);
1399  if (!node.obj) {
1401  return;
1402  }
1403  }
1404 
1405  QDBusAdaptorConnector *connector;
1406  if (node.flags & QDBusConnection::ExportAdaptors &&
1407  (connector = qDBusFindAdaptorConnector(node.obj))) {
1408  int newflags = node.flags | QDBusConnection::ExportAllSlots;
1409 
1410  if (msg.interface().isEmpty()) {
1411  // place the call in all interfaces
1412  // let the first one that handles it to work
1414  connector->adaptors.constBegin();
1416  connector->adaptors.constEnd();
1417 
1418  for ( ; it != end; ++it)
1419  if (activateCall(it->adaptor, newflags, msg))
1420  return;
1421  } else {
1422  // check if we have an interface matching the name that was asked:
1424  it = qLowerBound(connector->adaptors.constBegin(), connector->adaptors.constEnd(),
1425  msg.interface());
1426  if (it != connector->adaptors.constEnd() && msg.interface() == QLatin1String(it->interface)) {
1427  if (!activateCall(it->adaptor, newflags, msg))
1429  return;
1430  }
1431  }
1432  }
1433 
1434  // no adaptors matched or were exported
1435  // try our standard filters
1436  if (activateInternalFilters(node, msg))
1437  return; // internal filters have already run or an error has been sent
1438 
1439  // try the object itself:
1442  bool interfaceFound = true;
1443  if (!msg.interface().isEmpty())
1444  interfaceFound = qDBusInterfaceInObject(node.obj, msg.interface());
1445 
1446  if (interfaceFound) {
1447  if (!activateCall(node.obj, node.flags, msg))
1449  return;
1450  }
1451  }
1452 
1453  // nothing matched, send an error code
1454  if (msg.interface().isEmpty())
1456  else
1458 }
QDBusAdaptorConnector * qDBusFindAdaptorConnector(QObject *obj)
#define it(className, varName)
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the vector...
Definition: qvector.h:252
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
static QDBusConnection q(QDBusConnectionPrivate *connection)
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the vector.
Definition: qvector.h:249
bool activateCall(QObject *object, int flags, const QDBusMessage &msg)
QString path() const
Returns the path of the object that this message is being sent to (in the case of a method call) or b...
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
QString interface() const
Returns the interface of the method being called (in the case of a method call) or of the signal bein...
Q_OUTOFLINE_TEMPLATE RandomAccessIterator qLowerBound(RandomAccessIterator begin, RandomAccessIterator end, const T &value)
Definition: qalgorithms.h:227
The QDBusConnection class represents a connection to the D-Bus bus daemon.
bool qDBusInterfaceInObject(QObject *obj, const QString &interface_name)
Definition: qdbusmisc.cpp:116
void sendError(const QDBusMessage &msg, QDBusError::ErrorType code)
const_iterator ConstIterator
Qt-style synonym for QVector::const_iterator.
Definition: qvector.h:279
bool activateInternalFilters(const ObjectTreeNode &node, const QDBusMessage &msg)
static const KeyPair *const end
static QObject * findChildObject(const QDBusConnectionPrivate::ObjectTreeNode *root, const QString &fullpath, int start)

◆ activateSignal()

void QDBusConnectionPrivate::activateSignal ( const SignalHook hook,
const QDBusMessage msg 
)
private

Definition at line 759 of file qdbusintegrator.cpp.

Referenced by handleSignal().

761 {
762  // This is called by QDBusConnectionPrivate::handleSignal to deliver a signal
763  // that was received from D-Bus
764  //
765  // Signals are delivered to slots if the parameters match
766  // Slots can have less parameters than there are on the message
767  // Slots can optionally have one final parameter that is a QDBusMessage
768  // Slots receive read-only copies of the message (i.e., pass by value or by const-ref)
769  QDBusCallDeliveryEvent *call = prepareReply(this, hook.obj, hook.midx, hook.params, msg);
770  if (call == DIRECT_DELIVERY) {
771  // short-circuit delivery
772  Q_ASSERT(this == hook.obj);
773  deliverCall(this, 0, msg, hook.params, hook.midx);
774  return;
775  }
776  if (call)
777  postEventToThread(ActivateSignalAction, hook.obj, call);
778 }
void deliverCall(QObject *object, int flags, const QDBusMessage &msg, const QList< int > &metaTypes, int slotIdx)
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
static QDBusCallDeliveryEvent *const DIRECT_DELIVERY
static QDBusCallDeliveryEvent * prepareReply(QDBusConnectionPrivate *target, QObject *object, int idx, const QList< int > &metaTypes, const QDBusMessage &msg)
void postEventToThread(int action, QObject *target, QEvent *event)

◆ callWithCallbackFailed

void QDBusConnectionPrivate::callWithCallbackFailed ( const QDBusError error,
const QDBusMessage message 
)
signal

Referenced by processFinishedCall().

◆ checkReplyForDelivery()

static bool QDBusConnectionPrivate::checkReplyForDelivery ( QDBusConnectionPrivate target,
QObject object,
int  idx,
const QList< int > &  metaTypes,
const QDBusMessage msg 
)
static

◆ checkThread()

void QDBusConnectionPrivate::checkThread ( )
private

Definition at line 1061 of file qdbusintegrator.cpp.

Referenced by send(), sendWithReply(), and sendWithReplyAsync().

1062 {
1063  if (!thread()) {
1066  else
1067  qWarning("The thread that had QDBusConnection('%s') has died and there is no main thread",
1068  qPrintable(name));
1069  }
1070 }
Q_CORE_EXPORT void qWarning(const char *,...)
void moveToThread(QThread *thread)
Changes the thread affinity for this object and its children.
Definition: qobject.cpp:1458
static QCoreApplication * instance()
Returns a pointer to the application&#39;s QCoreApplication (or QApplication) instance.
QThread * thread() const
Returns the thread in which the object lives.
Definition: qobject.cpp:1419
#define qPrintable(string)
Definition: qglobal.h:1750

◆ closeConnection()

void QDBusConnectionPrivate::closeConnection ( )

Definition at line 1041 of file qdbusintegrator.cpp.

Referenced by QDBusConnectionManager::~QDBusConnectionManager(), and ~QDBusConnectionPrivate().

1042 {
1044  ConnectionMode oldMode = mode;
1045  mode = InvalidMode; // prevent reentrancy
1046  baseService.clear();
1047 
1048  if (server)
1049  q_dbus_server_disconnect(server);
1050 
1051  if (oldMode == ClientMode || oldMode == PeerMode) {
1052  if (connection) {
1053  q_dbus_connection_close(connection);
1054  // send the "close" message
1055  while (q_dbus_connection_dispatch(connection) == DBUS_DISPATCH_DATA_REMAINS)
1056  ;
1057  }
1058  }
1059 }
DBusConnection * connection
void clear()
Clears the contents of the string and makes it empty.
Definition: qstring.h:723

◆ connectRelay()

void QDBusConnectionPrivate::connectRelay ( const QString service,
const QString path,
const QString interface,
QDBusAbstractInterface receiver,
const char *  signal 
)

Definition at line 2271 of file qdbusintegrator.cpp.

Referenced by QDBusAbstractInterface::connectNotify().

2275 {
2276  // this function is called by QDBusAbstractInterface when one of its signals is connected
2277  // we set up a relay from D-Bus into it
2278  SignalHook hook;
2279  QString key;
2280 
2281  if (!prepareHook(hook, key, service, path, interface, QString(), QStringList(), receiver, signal,
2282  QDBusAbstractInterface::staticMetaObject.methodCount(), true))
2283  return; // don't connect
2284 
2285  // add it to our list:
2286  QDBusWriteLocker locker(ConnectRelayAction, this);
2289  for ( ; it != end && it.key() == key; ++it) {
2290  const SignalHook &entry = it.value();
2291  if (entry.service == hook.service &&
2292  entry.path == hook.path &&
2293  entry.signature == hook.signature &&
2294  entry.obj == hook.obj &&
2295  entry.midx == hook.midx)
2296  return; // already there, no need to re-add
2297  }
2298 
2299  connectSignal(key, hook);
2300 }
#define it(className, varName)
const_iterator ConstIterator
Qt-style synonym for QHash::const_iterator.
Definition: qhash.h:474
static const QMetaObject staticMetaObject
This variable stores the meta-object for the class.
Definition: qobject.h:128
The QString class provides a Unicode character string.
Definition: qstring.h:83
QHash< Key, T >::iterator find(const Key &key, const T &value)
Returns an iterator pointing to the item with the key and value.
Definition: qhash.h:972
static bool prepareHook(QDBusConnectionPrivate::SignalHook &hook, QString &key, const QString &service, const QString &path, const QString &interface, const QString &name, const QStringList &argMatch, QObject *receiver, const char *signal, int minMIdx, bool buildSignature)
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
bool connectSignal(const QString &service, const QString &path, const QString &interface, const QString &name, const QStringList &argumentMatch, const QString &signature, QObject *receiver, const char *slot)
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the hash...
Definition: qhash.h:469
int key
static const KeyPair *const end

◆ connectSignal() [1/2]

bool QDBusConnectionPrivate::connectSignal ( const QString service,
const QString path,
const QString interface,
const QString name,
const QStringList argumentMatch,
const QString signature,
QObject receiver,
const char *  slot 
)

Definition at line 2075 of file qdbusintegrator.cpp.

Referenced by connectRelay(), and connectSignal().

2079 {
2080  // check the slot
2082  QString key;
2083  QString name2 = name;
2084  if (name2.isNull())
2085  name2.detach();
2086 
2087  hook.signature = signature;
2088  if (!prepareHook(hook, key, service, path, interface, name, argumentMatch, receiver, slot, 0, false))
2089  return false; // don't connect
2090 
2091  // avoid duplicating:
2094  for ( ; it != end && it.key() == key; ++it) {
2095  const QDBusConnectionPrivate::SignalHook &entry = it.value();
2096  if (entry.service == hook.service &&
2097  entry.path == hook.path &&
2098  entry.signature == hook.signature &&
2099  entry.obj == hook.obj &&
2100  entry.midx == hook.midx &&
2101  entry.argumentMatch == hook.argumentMatch) {
2102  // no need to compare the parameters if it's the same slot
2103  return true; // already there
2104  }
2105  }
2106 
2107  connectSignal(key, hook);
2108  return true;
2109 }
#define it(className, varName)
const_iterator ConstIterator
Qt-style synonym for QHash::const_iterator.
Definition: qhash.h:474
The QString class provides a Unicode character string.
Definition: qstring.h:83
QHash< Key, T >::iterator find(const Key &key, const T &value)
Returns an iterator pointing to the item with the key and value.
Definition: qhash.h:972
static bool prepareHook(QDBusConnectionPrivate::SignalHook &hook, QString &key, const QString &service, const QString &path, const QString &interface, const QString &name, const QStringList &argMatch, QObject *receiver, const char *signal, int minMIdx, bool buildSignature)
bool connectSignal(const QString &service, const QString &path, const QString &interface, const QString &name, const QStringList &argumentMatch, const QString &signature, QObject *receiver, const char *slot)
void detach()
Definition: qstring.h:714
bool isNull() const
Returns true if this string is null; otherwise returns false.
Definition: qstring.h:505
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the hash...
Definition: qhash.h:469
int key
static const KeyPair *const end

◆ connectSignal() [2/2]

void QDBusConnectionPrivate::connectSignal ( const QString key,
const SignalHook hook 
)

Definition at line 2111 of file qdbusintegrator.cpp.

2112 {
2113  signalHooks.insertMulti(key, hook);
2116 
2118 
2119  if (it != matchRefCounts.end()) { // Match already present
2120  it.value() = it.value() + 1;
2121  return;
2122  }
2123 
2124  matchRefCounts.insert(hook.matchRule, 1);
2125 
2126  if (connection) {
2128  qDBusDebug("Adding rule: %s", hook.matchRule.constData());
2129  q_dbus_bus_add_match(connection, hook.matchRule, NULL);
2130 
2131  // Successfully connected the signal
2132  // Do we need to watch for this name?
2133  if (shouldWatchService(hook.service)) {
2135  if (++data.refcount == 1) {
2136  // we need to watch for this service changing
2137  connectSignal(dbusServiceString(), QString(), dbusInterfaceString(),
2138  QLatin1String("NameOwnerChanged"), QStringList() << hook.service, QString(),
2140  data.owner = getNameOwnerNoCache(hook.service);
2141  qDBusDebug() << this << "Watching service" << hook.service << "for owner changes (current owner:"
2142  << data.owner << ")";
2143  }
2144  }
2145  }
2146  }
2147 }
#define it(className, varName)
void serviceOwnerChangedNoLock(const QString &name, const QString &oldOwner, const QString &newOwner)
#define SLOT(a)
Definition: qobjectdefs.h:226
WatchedServiceData mapped_type
Typedef for T.
Definition: qhash.h:484
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
MatchRefCountHash matchRefCounts
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
DBusConnection * connection
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition: qhash.h:753
ConnectionType
Definition: qnamespace.h:1469
#define SIGNAL(a)
Definition: qobjectdefs.h:227
void destroyed(QObject *=0)
This signal is emitted immediately before the object obj is destroyed, and can not be blocked...
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
Definition: qobject.cpp:2580
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
bool connectSignal(const QString &service, const QString &path, const QString &interface, const QString &name, const QStringList &argumentMatch, const QString &signature, QObject *receiver, const char *slot)
static const char * data(const QByteArray &arr)
void objectDestroyed(QObject *o)
static QString dbusInterfaceString()
#define qDBusDebug
QString getNameOwnerNoCache(const QString &service)
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the hash...
Definition: qhash.h:467
static bool shouldWatchService(const QString &service)
WatchedServicesHash watchedServices
iterator find(const Key &key)
Returns an iterator pointing to the item with the key in the hash.
Definition: qhash.h:865
iterator insertMulti(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition: qhash.h:772
friend class iterator
Definition: qhash.h:393

◆ customEvent()

void QDBusConnectionPrivate::customEvent ( QEvent )
protectedvirtual

This event handler can be reimplemented in a subclass to receive custom events.

Custom events are user-defined events with a type value at least as large as the QEvent::User item of the QEvent::Type enum, and is typically a QEvent subclass. The event is passed in the event parameter.

See also
event(), QEvent

Reimplemented from QObject.

Definition at line 1095 of file qdbusintegrator.cpp.

1096 {
1097  Q_ASSERT(e->type() == QEvent::User);
1098 
1100  QDBusLockerBase::reportThreadAction(int(AddTimeoutAction) + int(ev->subtype),
1102  switch (ev->subtype)
1103  {
1106  while (!timeoutsPendingAdd.isEmpty()) {
1108  qDBusRealAddTimeout(this, entry.first, entry.second);
1109  }
1110  break;
1111  }
1112 
1114  killTimer(ev->timerId);
1115  break;
1116 
1118  qDBusRealAddWatch(this, ev->watch, ev->extra, ev->fd);
1119  break;
1120 
1122  qDBusRealToggleWatch(this, ev->watch, ev->fd);
1123  break;
1124  }
1125  QDBusLockerBase::reportThreadAction(int(AddTimeoutAction) + int(ev->subtype),
1127 }
T1 first
Definition: qpair.h:65
T2 second
Definition: qpair.h:66
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
T takeFirst()
Removes the first item in the list and returns it.
Definition: qlist.h:489
PendingTimeoutList timeoutsPendingAdd
static bool qDBusRealAddTimeout(QDBusConnectionPrivate *d, DBusTimeout *timeout, int ms)
static bool qDBusRealAddWatch(QDBusConnectionPrivate *d, DBusWatch *watch, int flags, int fd)
static void qDBusRealToggleWatch(QDBusConnectionPrivate *d, DBusWatch *watch, int fd)
static void reportThreadAction(int, int, QDBusConnectionPrivate *)
void killTimer(int id)
Kills the timer with timer identifier, id.
Definition: qobject.cpp:1650

◆ d()

static QDBusConnectionPrivate* QDBusConnectionPrivate::d ( const QDBusConnection q)
inlinestatic

◆ deleteYourself()

void QDBusConnectionPrivate::deleteYourself ( )

Definition at line 1027 of file qdbusintegrator.cpp.

Referenced by QDBusConnectionManager::removeConnection(), and QDBusConnectionManager::~QDBusConnectionManager().

1028 {
1029  if (thread() && thread() != QThread::currentThread()) {
1030  // last reference dropped while not in the correct thread
1031  // ask the correct thread to delete
1032 
1033  // note: since we're posting an event to another thread, we
1034  // must consider deleteLater() to take effect immediately
1035  deleteLater();
1036  } else {
1037  delete this;
1038  }
1039 }
static QThread * currentThread()
Returns a pointer to a QThread which manages the currently executing thread.
Definition: qthread.cpp:419
QThread * thread() const
Returns the thread in which the object lives.
Definition: qobject.cpp:1419
void deleteLater()
Schedules this object for deletion.
Definition: qobject.cpp:2145

◆ deliverCall()

void QDBusConnectionPrivate::deliverCall ( QObject object,
int  flags,
const QDBusMessage msg,
const QList< int > &  metaTypes,
int  slotIdx 
)
private

Definition at line 870 of file qdbusintegrator.cpp.

Referenced by activateCall(), activateSignal(), and QDBusCallDeliveryEvent::placeMetaCall().

872 {
873  Q_ASSERT_X(!object || QThread::currentThread() == object->thread(),
874  "QDBusConnection: internal threading error",
875  "function called for an object that is in another thread!!");
876 
878  params.reserve(metaTypes.count());
879 
880  QVariantList auxParameters;
881  // let's create the parameter list
882 
883  // first one is the return type -- add it below
884  params.append(0);
885 
886  // add the input parameters
887  int i;
888  int pCount = qMin(msg.arguments().count(), metaTypes.count() - 1);
889  for (i = 1; i <= pCount; ++i) {
890  int id = metaTypes[i];
891  if (id == QDBusMetaTypeId::message)
892  break;
893 
894  const QVariant &arg = msg.arguments().at(i - 1);
895  if (arg.userType() == id)
896  // no conversion needed
897  params.append(const_cast<void *>(arg.constData()));
898  else if (arg.userType() == qMetaTypeId<QDBusArgument>()) {
899  // convert to what the function expects
900  void *null = 0;
901  auxParameters.append(QVariant(id, null));
902 
903  const QDBusArgument &in =
904  *reinterpret_cast<const QDBusArgument *>(arg.constData());
905  QVariant &out = auxParameters[auxParameters.count() - 1];
906 
907  if (!QDBusMetaType::demarshall(in, out.userType(), out.data()))
908  qFatal("Internal error: demarshalling function for type '%s' (%d) failed!",
909  out.typeName(), out.userType());
910 
911  params.append(const_cast<void *>(out.constData()));
912  } else {
913  qFatal("Internal error: got invalid meta type %d (%s) "
914  "when trying to convert to meta type %d (%s)",
915  arg.userType(), QMetaType::typeName(arg.userType()),
916  id, QMetaType::typeName(id));
917  }
918  }
919 
920  if (metaTypes.count() > i && metaTypes[i] == QDBusMetaTypeId::message) {
921  params.append(const_cast<void*>(static_cast<const void*>(&msg)));
922  ++i;
923  }
924 
925  // output arguments
926  QVariantList outputArgs;
927  void *null = 0;
928  if (metaTypes[0] != QMetaType::Void) {
929  QVariant arg(metaTypes[0], null);
930  outputArgs.append( arg );
931  params[0] = const_cast<void*>(outputArgs.at( outputArgs.count() - 1 ).constData());
932  }
933  for ( ; i < metaTypes.count(); ++i) {
934  QVariant arg(metaTypes[i], null);
935  outputArgs.append( arg );
936  params.append(const_cast<void*>(outputArgs.at( outputArgs.count() - 1 ).constData()));
937  }
938 
939  // make call:
940  bool fail;
941  if (!object) {
942  fail = true;
943  } else {
944  // FIXME: save the old sender!
945  QDBusContextPrivate context(QDBusConnection(this), msg);
946  QDBusContextPrivate *old = QDBusContextPrivate::set(object, &context);
948 
949  QPointer<QObject> ptr = object;
950  fail = object->qt_metacall(QMetaObject::InvokeMetaMethod,
951  slotIdx, params.data()) >= 0;
953  // the object might be deleted in the slot
954  if (!ptr.isNull())
955  QDBusContextPrivate::set(object, old);
956  }
957 
958  // do we create a reply? Only if the caller is waiting for a reply and one hasn't been sent
959  // yet.
960  if (msg.isReplyRequired() && !msg.isDelayedReply()) {
961  if (!fail) {
962  // normal reply
963  qDBusDebug() << this << "Automatically sending reply:" << outputArgs;
964  send(msg.createReply(outputArgs));
965  } else {
966  // generate internal error
967  qWarning("Internal error: Failed to deliver message");
969  QLatin1String("Failed to deliver message")));
970  }
971  }
972 
973  return;
974 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
bool isNull() const
Returns true if the referenced object has been destroyed or if there is no referenced object; otherwi...
Definition: qpointer.h:70
The QDBusArgument class is used to marshall and demarshall D-Bus arguments.
Definition: qdbusargument.h:69
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
static void setSender(const QDBusConnectionPrivate *s)
QDBusMessage createErrorReply(const QString name, const QString &msg) const
Constructs a new DBus message representing an error reply message, with the given name and msg...
static QThread * currentThread()
Returns a pointer to a QThread which manages the currently executing thread.
Definition: qthread.cpp:419
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
void * data()
Definition: qvariant.cpp:3077
QList< QVariant > arguments() const
Returns the list of arguments that are going to be sent or were received from D-Bus.
static bool demarshall(const QDBusArgument &, int id, void *data)
Executes the demarshalling of type id (whose data will be placed in data) from the D-Bus marshalling ...
static int message
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
bool isReplyRequired() const
Returns the flag that indicates if this message should see a reply or not.
Q_CORE_EXPORT void qWarning(const char *,...)
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
const T * ptr(const T &t)
bool isDelayedReply() const
Returns the delayed reply flag, as set by setDelayedReply().
const char * typeName() const
Returns the name of the type stored in the variant.
Definition: qvariant.cpp:1984
QDBusMessage createReply(const QList< QVariant > &arguments=QList< QVariant >()) const
Constructs a new DBus message representing a reply, with the given arguments.
Q_CORE_EXPORT void qFatal(const char *,...)
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
int userType() const
Returns the storage type of the value stored in the variant.
Definition: qvariant.cpp:1913
#define qDBusDebug
static const char * typeName(int type)
Returns the type name associated with the given type, or 0 if no matching type was found...
Definition: qmetatype.cpp:406
The QDBusConnection class represents a connection to the D-Bus bus daemon.
const void * constData() const
Definition: qvariant.cpp:3065
static QDBusContextPrivate * set(QObject *obj, QDBusContextPrivate *newContext)
QThread * thread() const
Returns the thread in which the object lives.
Definition: qobject.cpp:1419
int send(const QDBusMessage &message)
void reserve(int size)

◆ disconnectRelay()

void QDBusConnectionPrivate::disconnectRelay ( const QString service,
const QString path,
const QString interface,
QDBusAbstractInterface receiver,
const char *  signal 
)

Definition at line 2302 of file qdbusintegrator.cpp.

Referenced by QDBusAbstractInterface::disconnectNotify().

2306 {
2307  // this function is called by QDBusAbstractInterface when one of its signals is disconnected
2308  // we remove relay from D-Bus into it
2309  SignalHook hook;
2310  QString key;
2311 
2312  if (!prepareHook(hook, key, service, path, interface, QString(), QStringList(), receiver, signal,
2313  QDBusAbstractInterface::staticMetaObject.methodCount(), true))
2314  return; // don't connect
2315 
2316  // remove it from our list:
2320  for ( ; it != end && it.key() == key; ++it) {
2321  const SignalHook &entry = it.value();
2322  if (entry.service == hook.service &&
2323  entry.path == hook.path &&
2324  entry.signature == hook.signature &&
2325  entry.obj == hook.obj &&
2326  entry.midx == hook.midx) {
2327  // found it
2328  disconnectSignal(it);
2329  return;
2330  }
2331  }
2332 
2333  qWarning("QDBusConnectionPrivate::disconnectRelay called for a signal that was not found");
2334 }
#define it(className, varName)
static const QMetaObject staticMetaObject
This variable stores the meta-object for the class.
Definition: qobject.h:128
The QString class provides a Unicode character string.
Definition: qstring.h:83
QHash< Key, T >::iterator find(const Key &key, const T &value)
Returns an iterator pointing to the item with the key and value.
Definition: qhash.h:972
static bool prepareHook(QDBusConnectionPrivate::SignalHook &hook, QString &key, const QString &service, const QString &path, const QString &interface, const QString &name, const QStringList &argMatch, QObject *receiver, const char *signal, int minMIdx, bool buildSignature)
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
SignalHookHash::Iterator disconnectSignal(SignalHookHash::Iterator &it)
Q_CORE_EXPORT void qWarning(const char *,...)
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the hash...
Definition: qhash.h:467
int key
static const KeyPair *const end
iterator Iterator
Qt-style synonym for QHash::iterator.
Definition: qhash.h:473

◆ disconnectSignal() [1/2]

QDBusConnectionPrivate::SignalHookHash::Iterator QDBusConnectionPrivate::disconnectSignal ( SignalHookHash::Iterator it)

Definition at line 2187 of file qdbusintegrator.cpp.

Referenced by disconnectRelay(), disconnectSignal(), and objectDestroyed().

2188 {
2189  const SignalHook &hook = it.value();
2190 
2191  bool erase = false;
2192  MatchRefCountHash::iterator i = matchRefCounts.find(hook.matchRule);
2193  if (i == matchRefCounts.end()) {
2194  qWarning("QDBusConnectionPrivate::disconnectSignal: MatchRule not found in matchRefCounts!!");
2195  } else {
2196  if (i.value() == 1) {
2197  erase = true;
2198  matchRefCounts.erase(i);
2199  }
2200  else {
2201  i.value() = i.value() - 1;
2202  }
2203  }
2204 
2205  // we don't care about errors here
2206  if (connection && erase) {
2208  qDBusDebug("Removing rule: %s", hook.matchRule.constData());
2209  q_dbus_bus_remove_match(connection, hook.matchRule, NULL);
2210 
2211  // Successfully disconnected the signal
2212  // Were we watching for this name?
2214  if (sit != watchedServices.end()) {
2215  if (--sit.value().refcount == 0) {
2216  watchedServices.erase(sit);
2217  disconnectSignal(dbusServiceString(), QString(), dbusInterfaceString(),
2218  QLatin1String("NameOwnerChanged"), QStringList() << hook.service, QString(),
2219  this, SLOT(_q_serviceOwnerChanged(QString,QString,QString)));
2220  }
2221  }
2222  }
2223 
2224  }
2225 
2226  return signalHooks.erase(it);
2227 }
#define it(className, varName)
#define SLOT(a)
Definition: qobjectdefs.h:226
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
MatchRefCountHash matchRefCounts
The QString class provides a Unicode character string.
Definition: qstring.h:83
DBusConnection * connection
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
SignalHookHash::Iterator disconnectSignal(SignalHookHash::Iterator &it)
Q_CORE_EXPORT void qWarning(const char *,...)
static QString dbusInterfaceString()
#define qDBusDebug
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the hash...
Definition: qhash.h:467
WatchedServicesHash watchedServices
iterator find(const Key &key)
Returns an iterator pointing to the item with the key in the hash.
Definition: qhash.h:865
iterator erase(iterator it)
Removes the (key, value) pair associated with the iterator pos from the hash, and returns an iterator...
Definition: qhash.h:827
friend class iterator
Definition: qhash.h:393
iterator Iterator
Qt-style synonym for QHash::iterator.
Definition: qhash.h:473

◆ disconnectSignal() [2/2]

bool QDBusConnectionPrivate::disconnectSignal ( const QString service,
const QString path,
const QString interface,
const QString name,
const QStringList argumentMatch,
const QString signature,
QObject receiver,
const char *  slot 
)

Definition at line 2149 of file qdbusintegrator.cpp.

2153 {
2154  // check the slot
2156  QString key;
2157  QString name2 = name;
2158  if (name2.isNull())
2159  name2.detach();
2160 
2161  hook.signature = signature;
2162  if (!prepareHook(hook, key, service, path, interface, name, argumentMatch, receiver, slot, 0, false))
2163  return false; // don't disconnect
2164 
2165  // avoid duplicating:
2168  for ( ; it != end && it.key() == key; ++it) {
2169  const QDBusConnectionPrivate::SignalHook &entry = it.value();
2170  if (entry.service == hook.service &&
2171  entry.path == hook.path &&
2172  entry.signature == hook.signature &&
2173  entry.obj == hook.obj &&
2174  entry.midx == hook.midx &&
2175  entry.argumentMatch == hook.argumentMatch) {
2176  // no need to compare the parameters if it's the same slot
2177  disconnectSignal(it);
2178  return true; // it was there
2179  }
2180  }
2181 
2182  // the slot was not found
2183  return false;
2184 }
#define it(className, varName)
The QString class provides a Unicode character string.
Definition: qstring.h:83
QHash< Key, T >::iterator find(const Key &key, const T &value)
Returns an iterator pointing to the item with the key and value.
Definition: qhash.h:972
static bool prepareHook(QDBusConnectionPrivate::SignalHook &hook, QString &key, const QString &service, const QString &path, const QString &interface, const QString &name, const QStringList &argMatch, QObject *receiver, const char *signal, int minMIdx, bool buildSignature)
SignalHookHash::Iterator disconnectSignal(SignalHookHash::Iterator &it)
void detach()
Definition: qstring.h:714
bool isNull() const
Returns true if this string is null; otherwise returns false.
Definition: qstring.h:505
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the hash...
Definition: qhash.h:467
int key
static const KeyPair *const end
iterator Iterator
Qt-style synonym for QHash::iterator.
Definition: qhash.h:473

◆ doDispatch

void QDBusConnectionPrivate::doDispatch ( )
slot

Definition at line 1129 of file qdbusintegrator.cpp.

Referenced by socketRead(), and timerEvent().

1130 {
1131  QDBusDispatchLocker locker(DoDispatchAction, this);
1132  if (mode == ClientMode || mode == PeerMode)
1133  while (q_dbus_connection_dispatch(connection) == DBUS_DISPATCH_DATA_REMAINS) ;
1134 }
DBusConnection * connection

◆ findMetaObject()

QDBusMetaObject * QDBusConnectionPrivate::findMetaObject ( const QString service,
const QString path,
const QString interface,
QDBusError error 
)

Definition at line 2369 of file qdbusintegrator.cpp.

Referenced by QDBusInterfacePrivate::QDBusInterfacePrivate().

2371 {
2372  // service must be a unique connection name
2373  if (!interface.isEmpty()) {
2374  QDBusReadLocker locker(FindMetaObject1Action, this);
2375  QDBusMetaObject *mo = cachedMetaObjects.value(interface, 0);
2376  if (mo)
2377  return mo;
2378  }
2379 
2380  // introspect the target object
2381  QDBusMessage msg = QDBusMessage::createMethodCall(service, path,
2382  QLatin1String(DBUS_INTERFACE_INTROSPECTABLE),
2383  QLatin1String("Introspect"));
2385 
2386  QDBusMessage reply = sendWithReply(msg, QDBus::Block);
2387 
2388  // it doesn't exist yet, we have to create it
2390  QDBusMetaObject *mo = 0;
2391  if (!interface.isEmpty())
2392  mo = cachedMetaObjects.value(interface, 0);
2393  if (mo)
2394  // maybe it got created when we switched from read to write lock
2395  return mo;
2396 
2397  QString xml;
2398  if (reply.type() == QDBusMessage::ReplyMessage) {
2399  if (reply.signature() == QLatin1String("s"))
2400  // fetch the XML description
2401  xml = reply.arguments().at(0).toString();
2402  } else {
2403  error = reply;
2404  lastError = error;
2405  if (reply.type() != QDBusMessage::ErrorMessage || error.type() != QDBusError::UnknownMethod)
2406  return 0; // error
2407  }
2408 
2409  // release the lock and return
2410  QDBusMetaObject *result = QDBusMetaObject::createMetaObject(interface, xml,
2411  cachedMetaObjects, error);
2412  lastError = error;
2413  return result;
2414 }
#define error(msg)
QString toString() const
Returns the variant as a QString if the variant has type() String , Bool , ByteArray ...
Definition: qvariant.cpp:2270
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
MetaObjectHash cachedMetaObjects
const T value(const Key &key) const
Returns the value associated with the key.
Definition: qhash.h:606
ErrorType type() const
Returns this error&#39;s ErrorType.
Definition: qdbuserror.cpp:323
QString signature() const
Returns the signature of the signal that was received or for the output arguments of a method call...
static QDBusMetaObject * createMetaObject(const QString &interface, const QString &xml, QHash< QString, QDBusMetaObject *> &map, QDBusError &error)
static void setParametersValidated(QDBusMessage &msg, bool enable)
QList< QVariant > arguments() const
Returns the list of arguments that are going to be sent or were received from D-Bus.
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
QDBusMessage sendWithReply(const QDBusMessage &message, int mode, int timeout=-1)
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
static QDBusMessage createMethodCall(const QString &destination, const QString &path, const QString &interface, const QString &method)
Constructs a new DBus message representing a method call.
The QDBusMessage class represents one message sent or received over the D-Bus bus.
Definition: qdbusmessage.h:59
MessageType type() const
Returns the message type.

◆ findSlot()

int QDBusConnectionPrivate::findSlot ( QObject obj,
const QByteArray normalizedName,
QList< int > &  params 
)
static

Definition at line 1246 of file qdbusintegrator.cpp.

Referenced by activateCall(), prepareHook(), and QDBusPendingCallPrivate::setReplyCallback().

1248 {
1249  int midx = obj->metaObject()->indexOfMethod(normalizedName);
1250  if (midx == -1)
1251  return -1;
1252 
1253  int inputCount = qDBusParametersForMethod(obj->metaObject()->method(midx), params);
1254  if ( inputCount == -1 || inputCount + 1 != params.count() )
1255  return -1; // failed to parse or invalid arguments or output arguments
1256 
1257  return midx;
1258 }
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
int qDBusParametersForMethod(const QMetaMethod &mm, QList< int > &metaTypes)
Definition: qdbusmisc.cpp:137
int indexOfMethod(const char *method) const
Finds method and returns its index; otherwise returns -1.
QMetaMethod method(int index) const
Returns the meta-data for the method with the given index.
virtual const QMetaObject * metaObject() const
Returns a pointer to the meta-object of this object.

◆ getNameOwner()

QString QDBusConnectionPrivate::getNameOwner ( const QString service)

Definition at line 2336 of file qdbusintegrator.cpp.

Referenced by QDBusAbstractInterfacePrivate::QDBusAbstractInterfacePrivate().

2337 {
2338  if (QDBusUtil::isValidUniqueConnectionName(serviceName))
2339  return serviceName;
2340  if (!connection)
2341  return QString();
2342 
2343  {
2344  // acquire a read lock for the cache
2345  QReadLocker locker(&lock);
2347  if (it != watchedServices.constEnd())
2348  return it->owner;
2349  }
2350 
2351  // not cached
2352  return getNameOwnerNoCache(serviceName);
2353 }
#define it(className, varName)
const_iterator ConstIterator
Qt-style synonym for QHash::const_iterator.
Definition: qhash.h:474
The QString class provides a Unicode character string.
Definition: qstring.h:83
DBusConnection * connection
const_iterator constFind(const Key &key) const
Returns an iterator pointing to the item with the key in the hash.
Definition: qhash.h:859
The QReadLocker class is a convenience class that simplifies locking and unlocking read-write locks f...
bool isValidUniqueConnectionName(const QString &connName)
Returns true if connName is a valid unique connection name.
Definition: qdbusutil.cpp:393
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the hash...
Definition: qhash.h:469
QString getNameOwnerNoCache(const QString &service)
WatchedServicesHash watchedServices

◆ getNameOwnerNoCache()

QString QDBusConnectionPrivate::getNameOwnerNoCache ( const QString service)
private

Definition at line 2355 of file qdbusintegrator.cpp.

Referenced by connectSignal(), and getNameOwner().

2356 {
2357  QDBusMessage msg = QDBusMessage::createMethodCall(dbusServiceString(),
2358  QLatin1String(DBUS_PATH_DBUS), dbusInterfaceString(),
2359  QLatin1String("GetNameOwner"));
2361  msg << serviceName;
2362  QDBusMessage reply = sendWithReply(msg, QDBus::Block);
2363  if (reply.type() == QDBusMessage::ReplyMessage)
2364  return reply.arguments().at(0).toString();
2365  return QString();
2366 }
QString toString() const
Returns the variant as a QString if the variant has type() String , Bool , ByteArray ...
Definition: qvariant.cpp:2270
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
static void setParametersValidated(QDBusMessage &msg, bool enable)
QList< QVariant > arguments() const
Returns the list of arguments that are going to be sent or were received from D-Bus.
QDBusMessage sendWithReply(const QDBusMessage &message, int mode, int timeout=-1)
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
static QString dbusInterfaceString()
static QDBusMessage createMethodCall(const QString &destination, const QString &path, const QString &interface, const QString &method)
Constructs a new DBus message representing a method call.
The QDBusMessage class represents one message sent or received over the D-Bus bus.
Definition: qdbusmessage.h:59
MessageType type() const
Returns the message type.

◆ handleError()

bool QDBusConnectionPrivate::handleError ( const QDBusErrorInternal error)
private

Definition at line 1072 of file qdbusintegrator.cpp.

Referenced by setConnection(), setPeer(), and setServer().

1073 {
1074  if (!error)
1075  return false; // no error
1076 
1077  //lock.lockForWrite();
1078  lastError = error;
1079  //lock.unlock();
1080  return true;
1081 }
#define error(msg)

◆ handleMessage()

bool QDBusConnectionPrivate::handleMessage ( const QDBusMessage msg)

Definition at line 558 of file qdbusintegrator.cpp.

Referenced by qDBusSignalFilter(), and sendWithReplyLocal().

559 {
560  const QDBusSpyHookList *list = qDBusSpyHookList();
561  for (int i = 0; i < list->size(); ++i) {
562  qDBusDebug() << "calling the message spy hook";
563  (*(*list)[i])(amsg);
564  }
565 
566  if (!ref)
567  return false;
568 
569  switch (amsg.type()) {
571  handleSignal(amsg);
572  // if there are any other filters in this DBusConnection,
573  // let them see the signal too
574  return false;
576  handleObjectCall(amsg);
577  return true;
581  return false; // we don't handle those here
582  }
583 
584  return false;
585 }
void handleObjectCall(const QDBusMessage &message)
void handleSignal(const QString &key, const QDBusMessage &msg)
#define qDBusDebug
int size() const

◆ handleObjectCall()

void QDBusConnectionPrivate::handleObjectCall ( const QDBusMessage message)
private

Definition at line 1460 of file qdbusintegrator.cpp.

Referenced by handleMessage().

1461 {
1462  // if the msg is external, we were called from inside doDispatch
1463  // that means the dispatchLock mutex is locked
1464  // must not call out to user code in that case
1465  //
1466  // however, if the message is internal, handleMessage was called
1467  // directly and no lock is in place. We can therefore call out to
1468  // user code, if necessary
1469  ObjectTreeNode result;
1470  int usedLength;
1471  QThread *objThread = 0;
1472  QSemaphore sem;
1473  bool semWait;
1474 
1475  {
1477  if (!findObject(&rootNode, msg.path(), usedLength, result)) {
1478  // qDebug("Call failed: no object found at %s", qPrintable(msg.path()));
1480  return;
1481  }
1482 
1483  if (!result.obj) {
1484  // no object -> no threading issues
1485  // it's either going to be an error, or an internal filter
1486  activateObject(result, msg, usedLength);
1487  return;
1488  }
1489 
1490  objThread = result.obj->thread();
1491  if (!objThread) {
1492  send(msg.createErrorReply(QDBusError::InternalError,
1493  QString::fromLatin1("Object '%1' (at path '%2')"
1494  " has no thread. Cannot deliver message.")
1495  .arg(result.obj->objectName(), msg.path())));
1496  return;
1497  }
1498 
1499  if (!QDBusMessagePrivate::isLocal(msg)) {
1500  // external incoming message
1501  // post it and forget
1503  new QDBusActivateObjectEvent(QDBusConnection(this), this, result,
1504  usedLength, msg));
1505  return;
1506  } else if (objThread != QThread::currentThread()) {
1507  // synchronize with other thread
1509  new QDBusActivateObjectEvent(QDBusConnection(this), this, result,
1510  usedLength, msg, &sem));
1511  semWait = true;
1512  } else {
1513  semWait = false;
1514  }
1515  } // release the lock
1516 
1517  if (semWait)
1519  else
1520  activateObject(result, msg, usedLength);
1521 }
void activateObject(ObjectTreeNode &node, const QDBusMessage &msg, int pathStartPos)
static bool isLocal(const QDBusMessage &msg)
The QSemaphore class provides a general counting semaphore.
Definition: qsemaphore.h:57
static bool findObject(const QDBusConnectionPrivate::ObjectTreeNode *root, const QString &fullpath, int &usedLength, QDBusConnectionPrivate::ObjectTreeNode &result)
static QThread * currentThread()
Returns a pointer to a QThread which manages the currently executing thread.
Definition: qthread.cpp:419
QString arg(qlonglong a, int fieldwidth=0, int base=10, const QChar &fillChar=QLatin1Char(' ')) const Q_REQUIRED_RESULT
Definition: qstring.cpp:7186
#define SEM_ACQUIRE(action, sem)
The QDBusConnection class represents a connection to the D-Bus bus daemon.
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
void sendError(const QDBusMessage &msg, QDBusError::ErrorType code)
QThread * thread() const
Returns the thread in which the object lives.
Definition: qobject.cpp:1419
The QThread class provides a platform-independent way to manage threads.
Definition: qthread.h:59
void postEventToThread(int action, QObject *target, QEvent *event)
int send(const QDBusMessage &message)

◆ handleSignal() [1/2]

void QDBusConnectionPrivate::handleSignal ( const QString key,
const QDBusMessage msg 
)
private

Definition at line 1548 of file qdbusintegrator.cpp.

Referenced by handleMessage(), and handleSignal().

1549 {
1552  //qDebug("looking for: %s", path.toLocal8Bit().constData());
1553  //qDBusDebug() << signalHooks.keys();
1554  for ( ; it != end && it.key() == key; ++it) {
1555  const SignalHook &hook = it.value();
1556  if (!hook.service.isEmpty()) {
1557  const QString owner =
1558  shouldWatchService(hook.service) ?
1559  watchedServices.value(hook.service).owner :
1560  hook.service;
1561  if (owner != msg.service())
1562  continue;
1563  }
1564  if (!hook.path.isEmpty() && hook.path != msg.path())
1565  continue;
1566  if (!hook.signature.isEmpty() && hook.signature != msg.signature())
1567  continue;
1568  if (hook.signature.isEmpty() && !hook.signature.isNull() && !msg.signature().isEmpty())
1569  continue;
1570  if (!hook.argumentMatch.isEmpty()) {
1571  const QVariantList arguments = msg.arguments();
1572  if (hook.argumentMatch.size() > arguments.size())
1573  continue;
1574 
1575  bool matched = true;
1576  for (int i = 0; i < hook.argumentMatch.size(); ++i) {
1577  const QString &param = hook.argumentMatch.at(i);
1578  if (param.isNull())
1579  continue; // don't try to match against this
1580  if (param == arguments.at(i).toString())
1581  continue; // matched
1582  matched = false;
1583  break;
1584  }
1585  if (!matched)
1586  continue;
1587  }
1588 
1589  activateSignal(hook, msg);
1590  }
1591 }
const QChar at(int i) const
Returns the character at the given index position in the string.
Definition: qstring.h:698
#define it(className, varName)
QString service() const
Returns the name of the service or the bus address of the remote method call.
QString toString() const
Returns the variant as a QString if the variant has type() String , Bool , ByteArray ...
Definition: qvariant.cpp:2270
The QString class provides a Unicode character string.
Definition: qstring.h:83
static QWidget * owner
QHash< Key, T >::iterator find(const Key &key, const T &value)
Returns an iterator pointing to the item with the key and value.
Definition: qhash.h:972
const T value(const Key &key) const
Returns the value associated with the key.
Definition: qhash.h:606
QString signature() const
Returns the signature of the signal that was received or for the output arguments of a method call...
QList< QVariant > arguments() const
Returns the list of arguments that are going to be sent or were received from D-Bus.
QString path() const
Returns the path of the object that this message is being sent to (in the case of a method call) or b...
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
void activateSignal(const SignalHook &hook, const QDBusMessage &msg)
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
bool isNull() const
Returns true if this string is null; otherwise returns false.
Definition: qstring.h:505
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the hash...
Definition: qhash.h:469
static bool shouldWatchService(const QString &service)
WatchedServicesHash watchedServices
int key
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
static const KeyPair *const end
friend class const_iterator
Definition: qhash.h:461

◆ handleSignal() [2/2]

void QDBusConnectionPrivate::handleSignal ( const QDBusMessage msg)
private

Definition at line 1593 of file qdbusintegrator.cpp.

1594 {
1595  // We call handlesignal(QString, QDBusMessage) three times:
1596  // one with member:interface
1597  // one with member:
1598  // one with :interface
1599  // This allows us to match signals with wildcards on member or interface
1600  // (but not both)
1601 
1602  QString key = msg.member();
1603  key.reserve(key.length() + 1 + msg.interface().length());
1604  key += QLatin1Char(':');
1605  key += msg.interface();
1606 
1607  QDBusReadLocker locker(HandleSignalAction, this);
1608  handleSignal(key, msg); // one try
1609 
1610  key.truncate(msg.member().length() + 1); // keep the ':'
1611  handleSignal(key, msg); // second try
1612 
1613  key = QLatin1Char(':');
1614  key += msg.interface();
1615  handleSignal(key, msg); // third try
1616 }
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
void handleSignal(const QString &key, const QDBusMessage &msg)
The QString class provides a Unicode character string.
Definition: qstring.h:83
void reserve(int size)
Attempts to allocate memory for at least size characters.
Definition: qstring.h:881
void truncate(int pos)
Truncates the string at the given position index.
Definition: qstring.cpp:4603
QString member() const
Returns the name of the signal that was emitted or the name of the method that was called...
QString interface() const
Returns the interface of the method being called (in the case of a method call) or of the signal bein...
int key
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ isServiceRegisteredByThread()

bool QDBusConnectionPrivate::isServiceRegisteredByThread ( const QString serviceName) const
private

Definition at line 2438 of file qdbusintegrator.cpp.

Referenced by sendWithReply(), and sendWithReplyAsync().

2439 {
2440  if (!serviceName.isEmpty() && serviceName == baseService)
2441  return true;
2442  QStringList copy = serviceNames;
2443  return copy.contains(serviceName);
2444 }
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
QBool contains(const QString &str, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the list contains the string str; otherwise returns false.
Definition: qstringlist.h:172

◆ messageFilter()

static DBusHandlerResult QDBusConnectionPrivate::messageFilter ( DBusConnection *  ,
DBusMessage *  ,
void *   
)
static

◆ newServerConnection

void QDBusConnectionPrivate::newServerConnection ( const QDBusConnection connection)
signal

◆ objectDestroyed

void QDBusConnectionPrivate::objectDestroyed ( QObject o)
slot

Definition at line 1175 of file qdbusintegrator.cpp.

Referenced by connectSignal(), and registerObject().

1176 {
1178  huntAndDestroy(obj, rootNode);
1179 
1181  while (sit != signalHooks.end()) {
1182  if (static_cast<QObject *>(sit.value().obj) == obj)
1183  sit = disconnectSignal(sit);
1184  else
1185  ++sit;
1186  }
1187 
1188  obj->disconnect(this);
1189 }
SignalHookHash::Iterator disconnectSignal(SignalHookHash::Iterator &it)
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the hash...
Definition: qhash.h:467
iterator begin()
Returns an STL-style iterator pointing to the first item in the hash.
Definition: qhash.h:464
static void huntAndDestroy(QObject *needle, QDBusConnectionPrivate::ObjectTreeNode &haystack)
friend class iterator
Definition: qhash.h:393

◆ postEventToThread()

void QDBusConnectionPrivate::postEventToThread ( int  action,
QObject target,
QEvent event 
)

Definition at line 2446 of file qdbusintegrator.cpp.

Referenced by activateSignal(), handleObjectCall(), processFinishedCall(), qDBusAddTimeout(), qDBusAddWatch(), qDBusRemoveTimeout(), and qDBusToggleWatch().

2447 {
2449  QCoreApplication::postEvent(object, ev);
2451 }
static void postEvent(QObject *receiver, QEvent *event)
Adds the event event, with the object receiver as the receiver of the event, to an event queue and re...
static void reportThreadAction(int, int, QDBusConnectionPrivate *)

◆ prepareHook()

bool QDBusConnectionPrivate::prepareHook ( QDBusConnectionPrivate::SignalHook hook,
QString key,
const QString service,
const QString path,
const QString interface,
const QString name,
const QStringList argMatch,
QObject receiver,
const char *  signal,
int  minMIdx,
bool  buildSignature 
)
static

Definition at line 1260 of file qdbusintegrator.cpp.

Referenced by connectRelay(), connectSignal(), disconnectRelay(), and disconnectSignal().

1266 {
1267  QByteArray normalizedName = signal + 1;
1268  hook.midx = findSlot(receiver, signal + 1, hook.params);
1269  if (hook.midx == -1) {
1270  normalizedName = QMetaObject::normalizedSignature(signal + 1);
1271  hook.midx = findSlot(receiver, normalizedName, hook.params);
1272  }
1273  if (hook.midx < minMIdx) {
1274  if (hook.midx == -1)
1275  {}
1276  return false;
1277  }
1278 
1279  hook.service = service;
1280  hook.path = path;
1281  hook.obj = receiver;
1282  hook.argumentMatch = argMatch;
1283 
1284  // build the D-Bus signal name and signature
1285  // This should not happen for QDBusConnection::connect, use buildSignature here, since
1286  // QDBusConnection::connect passes false and everything else uses true
1287  QString mname = name;
1288  if (buildSignature && mname.isNull()) {
1289  normalizedName.truncate(normalizedName.indexOf('('));
1290  mname = QString::fromUtf8(normalizedName);
1291  }
1292  key = mname;
1293  key.reserve(interface.length() + 1 + mname.length());
1294  key += QLatin1Char(':');
1295  key += interface;
1296 
1297  if (buildSignature) {
1298  hook.signature.clear();
1299  for (int i = 1; i < hook.params.count(); ++i)
1300  if (hook.params.at(i) != QDBusMetaTypeId::message)
1302  }
1303 
1304  hook.matchRule = buildMatchRule(service, path, interface, mname, argMatch, hook.signature);
1305  return true; // connect to this signal
1306 }
void truncate(int pos)
Truncates the byte array at index position pos.
static QByteArray normalizedSignature(const char *method)
Normalizes the signature of the given method.
static QByteArray buildMatchRule(const QString &service, const QString &objectPath, const QString &interface, const QString &member, const QStringList &argMatch, const QString &)
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
The QString class provides a Unicode character string.
Definition: qstring.h:83
static int findSlot(QObject *obj, const QByteArray &normalizedName, QList< int > &params)
void reserve(int size)
Attempts to allocate memory for at least size characters.
Definition: qstring.h:881
static const char * typeToSignature(int type)
Returns the D-Bus signature equivalent to the supplied meta type id type.
static int message
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
static QString fromUtf8(const char *, int size=-1)
Returns a QString initialized with the first size bytes of the UTF-8 string str.
Definition: qstring.cpp:4302
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
int indexOf(char c, int from=0) const
Returns the index position of the first occurrence of the character ch in the byte array...
bool isNull() const
Returns true if this string is null; otherwise returns false.
Definition: qstring.h:505
void clear()
Clears the contents of the string and makes it empty.
Definition: qstring.h:723
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ prepareReply()

QDBusCallDeliveryEvent * QDBusConnectionPrivate::prepareReply ( QDBusConnectionPrivate target,
QObject object,
int  idx,
const QList< int > &  metaTypes,
const QDBusMessage msg 
)
static

Definition at line 731 of file qdbusintegrator.cpp.

Referenced by activateSignal(), and processFinishedCall().

735 {
736  Q_ASSERT(object);
737  Q_UNUSED(object);
738 
739  int n = metaTypes.count() - 1;
740  if (metaTypes[n] == QDBusMetaTypeId::message)
741  --n;
742 
743  if (msg.arguments().count() < n)
744  return 0; // too few arguments
745 
746  // check that types match
747  for (int i = 0; i < n; ++i)
748  if (metaTypes.at(i + 1) != msg.arguments().at(i).userType() &&
749  msg.arguments().at(i).userType() != qMetaTypeId<QDBusArgument>())
750  return 0; // no match
751 
752  // we can deliver
753  // prepare for the call
754  if (target == object)
755  return DIRECT_DELIVERY;
756  return new QDBusCallDeliveryEvent(QDBusConnection(target), idx, target, msg, metaTypes);
757 }
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
static QDBusCallDeliveryEvent *const DIRECT_DELIVERY
QList< QVariant > arguments() const
Returns the list of arguments that are going to be sent or were received from D-Bus.
static int message
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
friend class QDBusCallDeliveryEvent
int userType() const
Returns the storage type of the value stored in the variant.
Definition: qvariant.cpp:1913
The QDBusConnection class represents a connection to the D-Bus bus daemon.
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729

◆ processFinishedCall()

void QDBusConnectionPrivate::processFinishedCall ( QDBusPendingCallPrivate call)
static

Definition at line 1794 of file qdbusintegrator.cpp.

Referenced by qDBusResultReceived(), and sendWithReplyAsync().

1795 {
1797 
1798  QMutexLocker locker(&call->mutex);
1799 
1800  QDBusMessage &msg = call->replyMessage;
1801  if (call->pending) {
1802  // decode the message
1803  DBusMessage *reply = q_dbus_pending_call_steal_reply(call->pending);
1804  msg = QDBusMessagePrivate::fromDBusMessage(reply, connection->capabilities);
1805  q_dbus_message_unref(reply);
1806  }
1807  qDBusDebug() << connection << "got message reply (async):" << msg;
1808 
1809  // Check if the reply has the expected signature
1810  call->checkReceivedSignature();
1811 
1812  if (!call->receiver.isNull() && call->methodIdx != -1 && msg.type() == QDBusMessage::ReplyMessage) {
1813  // Deliver the return values of a remote function call.
1814  //
1815  // There is only one connection and it is specified by idx
1816  // The slot must have the same parameter types that the message does
1817  // The slot may have less parameters than the message
1818  // The slot may optionally have one final parameter that is QDBusMessage
1819  // The slot receives read-only copies of the message (i.e., pass by value or by const-ref)
1820 
1821  QDBusCallDeliveryEvent *e = prepareReply(connection, call->receiver, call->methodIdx,
1822  call->metaTypes, msg);
1823  if (e)
1825  else
1826  qDBusDebug() << "Deliver failed!";
1827  }
1828 
1829  if (call->pending && !call->waitingForFinished) {
1830  q_dbus_pending_call_unref(call->pending);
1831  call->pending = 0;
1832  }
1833 
1834  locker.unlock();
1835 
1836  // Are there any watchers?
1837  if (call->watcherHelper)
1838  call->watcherHelper->emitSignals(msg, call->sentMessage);
1839 
1840  if (msg.type() == QDBusMessage::ErrorMessage)
1841  emit connection->callWithCallbackFailed(QDBusError(msg), call->sentMessage);
1842 
1843  if (!call->ref.deref())
1844  delete call;
1845 }
QAtomicInt ref
Definition: qshareddata.h:59
void callWithCallbackFailed(const QDBusError &error, const QDBusMessage &message)
bool isNull() const
Returns true if the referenced object has been destroyed or if there is no referenced object; otherwi...
Definition: qpointer.h:70
The QDBusError class represents an error received from the D-Bus bus or from remote applications foun...
Definition: qdbuserror.h:60
DBusConnection * connection
static QDBusMessage fromDBusMessage(DBusMessage *dmsg, QDBusConnection::ConnectionCapabilities capabilities)
Constructs a QDBusMessage by parsing the given DBusMessage object.
const QDBusMessage sentMessage
QPointer< QObject > receiver
#define emit
Definition: qobjectdefs.h:76
bool deref()
Atomically decrements the value of this QAtomicInt.
void emitSignals(const QDBusMessage &replyMessage, const QDBusMessage &sentMessage)
QDBusConnection::ConnectionCapabilities capabilities
static QDBusCallDeliveryEvent * prepareReply(QDBusConnectionPrivate *target, QObject *object, int idx, const QList< int > &metaTypes, const QDBusMessage &msg)
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
#define qDBusDebug
QDBusPendingCallWatcherHelper * watcherHelper
QDBusConnectionPrivate *const connection
DBusPendingCall * pending
volatile bool waitingForFinished
The QDBusMessage class represents one message sent or received over the D-Bus bus.
Definition: qdbusmessage.h:59
void postEventToThread(int action, QObject *target, QEvent *event)

◆ q()

static QDBusConnection QDBusConnectionPrivate::q ( QDBusConnectionPrivate connection)
inlinestatic

Definition at line 329 of file qdbusconnection_p.h.

Referenced by activateObject(), and qDBusNewConnection().

329 { return QDBusConnection(connection); }
The QDBusConnection class represents a connection to the D-Bus bus daemon.

◆ registerObject()

void QDBusConnectionPrivate::registerObject ( const ObjectTreeNode node)

Definition at line 2242 of file qdbusintegrator.cpp.

2243 {
2246 
2247  if (node->flags & (QDBusConnection::ExportAdaptors
2250  QDBusAdaptorConnector *connector = qDBusCreateAdaptorConnector(node->obj);
2251 
2252  if (node->flags & (QDBusConnection::ExportScriptableSignals
2254  connector->disconnectAllSignals(node->obj);
2255  connector->connectAllSignals(node->obj);
2256  }
2257 
2258  // disconnect and reconnect to avoid duplicates
2259  connector->disconnect(SIGNAL(relaySignal(QObject*,const QMetaObject*,int,QVariantList)),
2260  this, SLOT(relaySignal(QObject*,const QMetaObject*,int,QVariantList)));
2261  connect(connector, SIGNAL(relaySignal(QObject*,const QMetaObject*,int,QVariantList)),
2262  this, SLOT(relaySignal(QObject*,const QMetaObject*,int,QVariantList)),
2264  }
2265 
2266  static int counter = 0;
2267  if ((++counter % 20) == 0)
2269 }
The QMetaObject class contains meta-information about Qt objects.
Definition: qobjectdefs.h:304
QDBusAdaptorConnector * qDBusCreateAdaptorConnector(QObject *obj)
#define SLOT(a)
Definition: qobjectdefs.h:226
void disconnectAllSignals(QObject *object)
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
void relaySignal(QObject *obj, const QMetaObject *, int signalId, const QVariantList &args)
void connectAllSignals(QObject *object)
#define SIGNAL(a)
Definition: qobjectdefs.h:227
void destroyed(QObject *=0)
This signal is emitted immediately before the object obj is destroyed, and can not be blocked...
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
Definition: qobject.cpp:2580
static bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *member)
Disconnects signal in object sender from method in object receiver.
Definition: qobject.cpp:2895
void objectDestroyed(QObject *o)
static void cleanupDeletedNodes(QDBusConnectionPrivate::ObjectTreeNode &parent)

◆ registerService()

void QDBusConnectionPrivate::registerService ( const QString serviceName)

Definition at line 2416 of file qdbusintegrator.cpp.

2417 {
2419  registerServiceNoLock(serviceName);
2420 }
void registerServiceNoLock(const QString &serviceName)

◆ registerServiceNoLock

void QDBusConnectionPrivate::registerServiceNoLock ( const QString serviceName)
privateslot

Definition at line 2422 of file qdbusintegrator.cpp.

Referenced by registerService().

2423 {
2424  serviceNames.append(serviceName);
2425 }
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507

◆ relaySignal

void QDBusConnectionPrivate::relaySignal ( QObject obj,
const QMetaObject mo,
int  signalId,
const QVariantList args 
)
slot

Definition at line 1191 of file qdbusintegrator.cpp.

Referenced by registerObject().

1193 {
1194  QString interface = qDBusInterfaceFromMetaObject(mo);
1195 
1196  QMetaMethod mm = mo->method(signalId);
1197  QByteArray memberName = mm.signature();
1198  memberName.truncate(memberName.indexOf('('));
1199 
1200  // check if it's scriptable
1201  bool isScriptable = mm.attributes() & QMetaMethod::Scriptable;
1202  bool isAdaptor = false;
1203  for ( ; mo; mo = mo->superClass())
1205  isAdaptor = true;
1206  break;
1207  }
1208 
1209  QDBusReadLocker locker(RelaySignalAction, this);
1210  QDBusMessage message = QDBusMessage::createSignal(QLatin1String("/"), interface,
1211  QLatin1String(memberName));
1213  message.setArguments(args);
1214  QDBusError error;
1215  DBusMessage *msg = QDBusMessagePrivate::toDBusMessage(message, capabilities, &error);
1216  if (!msg) {
1217  qWarning("QDBusConnection: Could not emit signal %s.%s: %s", qPrintable(interface), memberName.constData(),
1218  qPrintable(error.message()));
1219  lastError = error;
1220  return;
1221  }
1222 
1223  //qDBusDebug() << "Emitting signal" << message;
1224  //qDBusDebug() << "for paths:";
1225  q_dbus_message_set_no_reply(msg, true); // the reply would not be delivered to anything
1226  huntAndEmit(connection, msg, obj, rootNode, isScriptable, isAdaptor);
1227  q_dbus_message_unref(msg);
1228 }
void truncate(int pos)
Truncates the byte array at index position pos.
static QDBusMessage createSignal(const QString &path, const QString &interface, const QString &name)
Constructs a new DBus message with the given path, interface and name, representing a signal emission...
static void huntAndEmit(DBusConnection *connection, DBusMessage *msg, QObject *needle, const QDBusConnectionPrivate::ObjectTreeNode &haystack, bool isScriptable, bool isAdaptor, const QString &path=QString())
#define error(msg)
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
The QDBusError class represents an error received from the D-Bus bus or from remote applications foun...
Definition: qdbuserror.h:60
static const QMetaObject staticMetaObject
This variable stores the meta-object for the class.
Definition: qobject.h:128
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
DBusConnection * connection
static void setParametersValidated(QDBusMessage &msg, bool enable)
Q_CORE_EXPORT void qWarning(const char *,...)
static DBusMessage * toDBusMessage(const QDBusMessage &message, QDBusConnection::ConnectionCapabilities capabilities, QDBusError *error)
Constructs a DBusMessage object from message.
QDBusConnection::ConnectionCapabilities capabilities
const QMetaObject * superClass() const
Returns the meta-object of the superclass, or 0 if there is no such object.
Definition: qobjectdefs.h:494
int indexOf(char c, int from=0) const
Returns the index position of the first occurrence of the character ch in the byte array...
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
The QDBusMessage class represents one message sent or received over the D-Bus bus.
Definition: qdbusmessage.h:59
static QByteArray memberName(const QMetaMethod &member)
void setArguments(const QList< QVariant > &arguments)
Sets the arguments that are going to be sent over D-Bus to arguments.
QMetaMethod method(int index) const
Returns the meta-data for the method with the given index.
#define qPrintable(string)
Definition: qglobal.h:1750
The QMetaMethod class provides meta-data about a member function.
Definition: qmetaobject.h:56
QString message() const
Returns the message that the callee associated with this error.
Definition: qdbuserror.cpp:346

◆ send()

int QDBusConnectionPrivate::send ( const QDBusMessage message)

Definition at line 1847 of file qdbusintegrator.cpp.

Referenced by activateInternalFilters(), deliverCall(), handleObjectCall(), and sendError().

1848 {
1849  if (QDBusMessagePrivate::isLocal(message))
1850  return -1; // don't send; the reply will be retrieved by the caller
1851  // through the d_ptr->localReply link
1852 
1853  QDBusError error;
1854  DBusMessage *msg = QDBusMessagePrivate::toDBusMessage(message, capabilities, &error);
1855  if (!msg) {
1856  if (message.type() == QDBusMessage::MethodCallMessage)
1857  qWarning("QDBusConnection: error: could not send message to service \"%s\" path \"%s\" interface \"%s\" member \"%s\": %s",
1858  qPrintable(message.service()), qPrintable(message.path()),
1859  qPrintable(message.interface()), qPrintable(message.member()),
1860  qPrintable(error.message()));
1861  else if (message.type() == QDBusMessage::SignalMessage)
1862  qWarning("QDBusConnection: error: could not send signal path \"%s\" interface \"%s\" member \"%s\": %s",
1863  qPrintable(message.path()), qPrintable(message.interface()),
1864  qPrintable(message.member()),
1865  qPrintable(error.message()));
1866  else
1867  qWarning("QDBusConnection: error: could not send %s message to service \"%s\": %s",
1868  message.type() == QDBusMessage::ReplyMessage ? "reply" :
1869  message.type() == QDBusMessage::ErrorMessage ? "error" :
1870  "invalid", qPrintable(message.service()),
1871  qPrintable(error.message()));
1872  lastError = error;
1873  return 0;
1874  }
1875 
1876  q_dbus_message_set_no_reply(msg, true); // the reply would not be delivered to anything
1877 
1878  qDBusDebug() << this << "sending message (no reply):" << message;
1879  checkThread();
1880  bool isOk = q_dbus_connection_send(connection, msg, 0);
1881  int serial = 0;
1882  if (isOk)
1883  serial = q_dbus_message_get_serial(msg);
1884 
1885  q_dbus_message_unref(msg);
1886  return serial;
1887 }
static bool isLocal(const QDBusMessage &msg)
#define error(msg)
QString service() const
Returns the name of the service or the bus address of the remote method call.
The QDBusError class represents an error received from the D-Bus bus or from remote applications foun...
Definition: qdbuserror.h:60
DBusConnection * connection
QString path() const
Returns the path of the object that this message is being sent to (in the case of a method call) or b...
Q_CORE_EXPORT void qWarning(const char *,...)
static DBusMessage * toDBusMessage(const QDBusMessage &message, QDBusConnection::ConnectionCapabilities capabilities, QDBusError *error)
Constructs a DBusMessage object from message.
QString member() const
Returns the name of the signal that was emitted or the name of the method that was called...
QDBusConnection::ConnectionCapabilities capabilities
QString interface() const
Returns the interface of the method being called (in the case of a method call) or of the signal bein...
#define qDBusDebug
MessageType type() const
Returns the message type.
#define qPrintable(string)
Definition: qglobal.h:1750
QString message() const
Returns the message that the callee associated with this error.
Definition: qdbuserror.cpp:346

◆ sendError()

void QDBusConnectionPrivate::sendError ( const QDBusMessage msg,
QDBusError::ErrorType  code 
)
private

Definition at line 1308 of file qdbusintegrator.cpp.

Referenced by activateInternalFilters(), activateObject(), handleObjectCall(), and QDBusActivateObjectEvent::~QDBusActivateObjectEvent().

1309 {
1310  if (code == QDBusError::UnknownMethod) {
1311  QString interfaceMsg;
1312  if (msg.interface().isEmpty())
1313  interfaceMsg = QLatin1String("any interface");
1314  else
1315  interfaceMsg = QString::fromLatin1("interface '%1'").arg(msg.interface());
1316 
1317  send(msg.createErrorReply(code,
1318  QString::fromLatin1("No such method '%1' in %2 at object path '%3' "
1319  "(signature '%4')")
1320  .arg(msg.member(), interfaceMsg, msg.path(), msg.signature())));
1321  } else if (code == QDBusError::UnknownInterface) {
1323  QString::fromLatin1("No such interface '%1' at object path '%2'")
1324  .arg(msg.interface(), msg.path())));
1325  } else if (code == QDBusError::UnknownObject) {
1327  QString::fromLatin1("No such object path '%1'").arg(msg.path())));
1328  }
1329 }
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
QDBusMessage createErrorReply(const QString name, const QString &msg) const
Constructs a new DBus message representing an error reply message, with the given name and msg...
QString signature() const
Returns the signature of the signal that was received or for the output arguments of a method call...
QString path() const
Returns the path of the object that this message is being sent to (in the case of a method call) or b...
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
QString member() const
Returns the name of the signal that was emitted or the name of the method that was called...
QString interface() const
Returns the interface of the method being called (in the case of a method call) or of the signal bein...
QString arg(qlonglong a, int fieldwidth=0, int base=10, const QChar &fillChar=QLatin1Char(' ')) const Q_REQUIRED_RESULT
Definition: qstring.cpp:7186
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
int send(const QDBusMessage &message)

◆ sendWithReply()

QDBusMessage QDBusConnectionPrivate::sendWithReply ( const QDBusMessage message,
int  mode,
int  timeout = -1 
)

Definition at line 1889 of file qdbusintegrator.cpp.

Referenced by findMetaObject(), and getNameOwnerNoCache().

1891 {
1892  checkThread();
1893  if ((sendMode == QDBus::BlockWithGui || sendMode == QDBus::Block)
1894  && isServiceRegisteredByThread(message.service()))
1895  // special case for synchronous local calls
1896  return sendWithReplyLocal(message);
1897 
1898  if (!QCoreApplication::instance() || sendMode == QDBus::Block) {
1899  QDBusError err;
1900  DBusMessage *msg = QDBusMessagePrivate::toDBusMessage(message, capabilities, &err);
1901  if (!msg) {
1902  qWarning("QDBusConnection: error: could not send message to service \"%s\" path \"%s\" interface \"%s\" member \"%s\": %s",
1903  qPrintable(message.service()), qPrintable(message.path()),
1904  qPrintable(message.interface()), qPrintable(message.member()),
1905  qPrintable(err.message()));
1906  lastError = err;
1907  return QDBusMessage::createError(err);
1908  }
1909 
1910  qDBusDebug() << this << "sending message (blocking):" << message;
1912  DBusMessage *reply = q_dbus_connection_send_with_reply_and_block(connection, msg, timeout, error);
1913 
1914  q_dbus_message_unref(msg);
1915 
1916  if (!!error) {
1917  lastError = err = error;
1918  return QDBusMessage::createError(err);
1919  }
1920 
1922  q_dbus_message_unref(reply);
1923  qDBusDebug() << this << "got message reply (blocking):" << amsg;
1924 
1925  return amsg;
1926  } else { // use the event loop
1927  QDBusPendingCallPrivate *pcall = sendWithReplyAsync(message, 0, 0, 0, timeout);
1928  Q_ASSERT(pcall);
1929 
1932  QEventLoop loop;
1933  loop.connect(pcall->watcherHelper, SIGNAL(reply(QDBusMessage)), SLOT(quit()));
1934  loop.connect(pcall->watcherHelper, SIGNAL(error(QDBusError,QDBusMessage)), SLOT(quit()));
1935 
1936  // enter the event loop and wait for a reply
1938  }
1939 
1940  QDBusMessage reply = pcall->replyMessage;
1941  lastError = reply; // set or clear error
1942 
1943  bool r = pcall->ref.deref();
1944  Q_ASSERT(!r);
1945  Q_UNUSED(r);
1946 
1947  delete pcall;
1948  return reply;
1949  }
1950 }
QAtomicInt ref
Definition: qshareddata.h:59
static QDBusMessage createError(const QString &name, const QString &msg)
Constructs a new DBus message representing an error, with the given name and msg. ...
#define error(msg)
#define SLOT(a)
Definition: qobjectdefs.h:226
QString service() const
Returns the name of the service or the bus address of the remote method call.
The QDBusError class represents an error received from the D-Bus bus or from remote applications foun...
Definition: qdbuserror.h:60
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
DBusConnection * connection
static QDBusMessage fromDBusMessage(DBusMessage *dmsg, QDBusConnection::ConnectionCapabilities capabilities)
Constructs a QDBusMessage by parsing the given DBusMessage object.
#define SIGNAL(a)
Definition: qobjectdefs.h:227
QString path() const
Returns the path of the object that this message is being sent to (in the case of a method call) or b...
The QEventLoop class provides a means of entering and leaving an event loop.
Definition: qeventloop.h:55
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
Definition: qobject.cpp:2580
bool deref()
Atomically decrements the value of this QAtomicInt.
Q_CORE_EXPORT void qWarning(const char *,...)
static DBusMessage * toDBusMessage(const QDBusMessage &message, QDBusConnection::ConnectionCapabilities capabilities, QDBusError *error)
Constructs a DBusMessage object from message.
QString member() const
Returns the name of the signal that was emitted or the name of the method that was called...
QDBusConnection::ConnectionCapabilities capabilities
QDBusPendingCallPrivate * sendWithReplyAsync(const QDBusMessage &message, QObject *receiver, const char *returnMethod, const char *errorMethod, int timeout=-1)
QString interface() const
Returns the interface of the method being called (in the case of a method call) or of the signal bein...
#define qDBusDebug
bool isServiceRegisteredByThread(const QString &serviceName) const
static QCoreApplication * instance()
Returns a pointer to the application&#39;s QCoreApplication (or QApplication) instance.
QDBusPendingCallWatcherHelper * watcherHelper
QDBusMessage sendWithReplyLocal(const QDBusMessage &message)
The QDBusMessage class represents one message sent or received over the D-Bus bus.
Definition: qdbusmessage.h:59
MessageType type() const
Returns the message type.
#define qPrintable(string)
Definition: qglobal.h:1750
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
int exec(ProcessEventsFlags flags=AllEvents)
Enters the main event loop and waits until exit() is called.
Definition: qeventloop.cpp:181
QString message() const
Returns the message that the callee associated with this error.
Definition: qdbuserror.cpp:346

◆ sendWithReplyAsync()

QDBusPendingCallPrivate * QDBusConnectionPrivate::sendWithReplyAsync ( const QDBusMessage message,
QObject receiver,
const char *  returnMethod,
const char *  errorMethod,
int  timeout = -1 
)

Definition at line 1985 of file qdbusintegrator.cpp.

Referenced by sendWithReply().

1988 {
1989  if (isServiceRegisteredByThread(message.service())) {
1990  // special case for local calls
1991  QDBusPendingCallPrivate *pcall = new QDBusPendingCallPrivate(message, this);
1992  pcall->replyMessage = sendWithReplyLocal(message);
1993  if (receiver && returnMethod)
1994  pcall->setReplyCallback(receiver, returnMethod);
1995 
1996  if (errorMethod) {
1998  connect(pcall->watcherHelper, SIGNAL(error(QDBusError,QDBusMessage)), receiver, errorMethod,
2000  pcall->watcherHelper->moveToThread(thread());
2001  }
2002 
2003  if ((receiver && returnMethod) || errorMethod) {
2004  // no one waiting, will delete pcall in processFinishedCall()
2005  pcall->ref = 1;
2006  } else {
2007  // set double ref to prevent race between processFinishedCall() and ref counting
2008  // by QDBusPendingCall::QExplicitlySharedDataPointer<QDBusPendingCallPrivate>
2009  pcall->ref = 2;
2010  }
2011  processFinishedCall(pcall);
2012  return pcall;
2013  }
2014 
2015  checkThread();
2016  QDBusPendingCallPrivate *pcall = new QDBusPendingCallPrivate(message, this);
2017  if (receiver && returnMethod)
2018  pcall->setReplyCallback(receiver, returnMethod);
2019 
2020  if (errorMethod) {
2022  connect(pcall->watcherHelper, SIGNAL(error(QDBusError,QDBusMessage)), receiver, errorMethod,
2024  pcall->watcherHelper->moveToThread(thread());
2025  }
2026 
2027  if ((receiver && returnMethod) || errorMethod) {
2028  // no one waiting, will delete pcall in processFinishedCall()
2029  pcall->ref = 1;
2030  } else {
2031  // set double ref to prevent race between processFinishedCall() and ref counting
2032  // by QDBusPendingCall::QExplicitlySharedDataPointer<QDBusPendingCallPrivate>
2033  pcall->ref = 2;
2034  }
2035 
2036  QDBusError error;
2037  DBusMessage *msg = QDBusMessagePrivate::toDBusMessage(message, capabilities, &error);
2038  if (!msg) {
2039  qWarning("QDBusConnection: error: could not send message to service \"%s\" path \"%s\" interface \"%s\" member \"%s\": %s",
2040  qPrintable(message.service()), qPrintable(message.path()),
2041  qPrintable(message.interface()), qPrintable(message.member()),
2042  qPrintable(error.message()));
2043  pcall->replyMessage = QDBusMessage::createError(error);
2044  lastError = error;
2045  processFinishedCall(pcall);
2046  return pcall;
2047  }
2048 
2049  qDBusDebug() << this << "sending message (async):" << message;
2050  DBusPendingCall *pending = 0;
2051 
2053  if (q_dbus_connection_send_with_reply(connection, msg, &pending, timeout)) {
2054  if (pending) {
2055  q_dbus_message_unref(msg);
2056 
2057  pcall->pending = pending;
2058  q_dbus_pending_call_set_notify(pending, qDBusResultReceived, pcall, 0);
2059 
2060  return pcall;
2061  } else {
2062  // we're probably disconnected at this point
2063  lastError = error = QDBusError(QDBusError::Disconnected, QLatin1String("Not connected to server"));
2064  }
2065  } else {
2066  lastError = error = QDBusError(QDBusError::NoMemory, QLatin1String("Out of memory"));
2067  }
2068 
2069  q_dbus_message_unref(msg);
2070  pcall->replyMessage = QDBusMessage::createError(error);
2071  processFinishedCall(pcall);
2072  return pcall;
2073 }
QAtomicInt ref
Definition: qshareddata.h:59
static QDBusMessage createError(const QString &name, const QString &msg)
Constructs a new DBus message representing an error, with the given name and msg. ...
#define error(msg)
QString service() const
Returns the name of the service or the bus address of the remote method call.
bool setReplyCallback(QObject *target, const char *member)
The QDBusError class represents an error received from the D-Bus bus or from remote applications foun...
Definition: qdbuserror.h:60
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
static void processFinishedCall(QDBusPendingCallPrivate *call)
DBusConnection * connection
static void qDBusResultReceived(DBusPendingCall *pending, void *user_data)
#define SIGNAL(a)
Definition: qobjectdefs.h:227
QString path() const
Returns the path of the object that this message is being sent to (in the case of a method call) or b...
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
Definition: qobject.cpp:2580
Q_CORE_EXPORT void qWarning(const char *,...)
static DBusMessage * toDBusMessage(const QDBusMessage &message, QDBusConnection::ConnectionCapabilities capabilities, QDBusError *error)
Constructs a DBusMessage object from message.
void moveToThread(QThread *thread)
Changes the thread affinity for this object and its children.
Definition: qobject.cpp:1458
QString member() const
Returns the name of the signal that was emitted or the name of the method that was called...
QDBusConnection::ConnectionCapabilities capabilities
QString interface() const
Returns the interface of the method being called (in the case of a method call) or of the signal bein...
#define qDBusDebug
bool isServiceRegisteredByThread(const QString &serviceName) const
QDBusPendingCallWatcherHelper * watcherHelper
QDBusMessage sendWithReplyLocal(const QDBusMessage &message)
DBusPendingCall * pending
The QDBusMessage class represents one message sent or received over the D-Bus bus.
Definition: qdbusmessage.h:59
QThread * thread() const
Returns the thread in which the object lives.
Definition: qobject.cpp:1419
#define qPrintable(string)
Definition: qglobal.h:1750
QString message() const
Returns the message that the callee associated with this error.
Definition: qdbuserror.cpp:346

◆ sendWithReplyLocal()

QDBusMessage QDBusConnectionPrivate::sendWithReplyLocal ( const QDBusMessage message)

Definition at line 1952 of file qdbusintegrator.cpp.

Referenced by sendWithReply(), and sendWithReplyAsync().

1953 {
1954  qDBusDebug() << this << "sending message via local-loop:" << message;
1955 
1956  QDBusMessage localCallMsg = QDBusMessagePrivate::makeLocal(*this, message);
1957  bool handled = handleMessage(localCallMsg);
1958 
1959  if (!handled) {
1960  QString interface = message.interface();
1961  if (interface.isEmpty())
1962  interface = QLatin1String("<no-interface>");
1964  QString::fromLatin1("Internal error trying to call %1.%2 at %3 (signature '%4'")
1965  .arg(interface, message.member(),
1966  message.path(), message.signature()));
1967  }
1968 
1969  // if the message was handled, there might be a reply
1970  QDBusMessage localReplyMsg = QDBusMessagePrivate::makeLocalReply(*this, localCallMsg);
1971  if (localReplyMsg.type() == QDBusMessage::InvalidMessage) {
1972  qWarning("QDBusConnection: cannot call local method '%s' at object %s (with signature '%s') "
1973  "on blocking mode", qPrintable(message.member()), qPrintable(message.path()),
1974  qPrintable(message.signature()));
1977  QLatin1String("local-loop message cannot have delayed replies")));
1978  }
1979 
1980  // there is a reply
1981  qDBusDebug() << this << "got message via local-loop:" << localReplyMsg;
1982  return localReplyMsg;
1983 }
static QDBusMessage createError(const QString &name, const QString &msg)
Constructs a new DBus message representing an error, with the given name and msg. ...
The QDBusError class represents an error received from the D-Bus bus or from remote applications foun...
Definition: qdbuserror.h:60
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
QString signature() const
Returns the signature of the signal that was received or for the output arguments of a method call...
static QDBusMessage makeLocal(const QDBusConnectionPrivate &conn, const QDBusMessage &asSent)
QString path() const
Returns the path of the object that this message is being sent to (in the case of a method call) or b...
Q_CORE_EXPORT void qWarning(const char *,...)
QString member() const
Returns the name of the signal that was emitted or the name of the method that was called...
bool handleMessage(const QDBusMessage &msg)
#define qDBusDebug
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
The QDBusMessage class represents one message sent or received over the D-Bus bus.
Definition: qdbusmessage.h:59
MessageType type() const
Returns the message type.
static QDBusMessage makeLocalReply(const QDBusConnectionPrivate &conn, const QDBusMessage &asSent)
#define qPrintable(string)
Definition: qglobal.h:1750

◆ serverConnection()

void QDBusConnectionPrivate::serverConnection ( const QDBusConnection connection)
inline

Definition at line 225 of file qdbusconnection_p.h.

Referenced by qDBusNewConnection().

226  { emit newServerConnection(connection); }
void newServerConnection(const QDBusConnection &connection)
#define emit
Definition: qobjectdefs.h:76

◆ serviceOwnerChanged

void QDBusConnectionPrivate::serviceOwnerChanged ( const QString name,
const QString oldOwner,
const QString newOwner 
)
signal

◆ serviceOwnerChangedNoLock

void QDBusConnectionPrivate::serviceOwnerChangedNoLock ( const QString name,
const QString oldOwner,
const QString newOwner 
)
privateslot

Definition at line 1230 of file qdbusintegrator.cpp.

Referenced by connectSignal().

1232 {
1233  Q_UNUSED(oldOwner);
1234 // QDBusWriteLocker locker(UpdateSignalHookOwnerAction, this);
1236  if (it == watchedServices.end())
1237  return;
1238  if (oldOwner != it->owner)
1239  qWarning("QDBusConnection: name '%s' had owner '%s' but we thought it was '%s'",
1240  qPrintable(name), qPrintable(oldOwner), qPrintable(it->owner));
1241 
1242  qDBusDebug() << this << "Updating name" << name << "from" << oldOwner << "to" << newOwner;
1243  it->owner = newOwner;
1244 }
#define it(className, varName)
Q_CORE_EXPORT void qWarning(const char *,...)
#define qDBusDebug
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the hash...
Definition: qhash.h:467
WatchedServicesHash watchedServices
iterator find(const Key &key)
Returns an iterator pointing to the item with the key in the hash.
Definition: qhash.h:865
#define qPrintable(string)
Definition: qglobal.h:1750
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
iterator Iterator
Qt-style synonym for QHash::iterator.
Definition: qhash.h:473

◆ setBusService()

void QDBusConnectionPrivate::setBusService ( const QDBusConnection connection)
Warning
This function is not part of the public interface.

Definition at line 1229 of file qdbusconnection.cpp.

Referenced by QDBusConnection::connectToBus().

1230 {
1231  busService = new QDBusConnectionInterface(connection, this);
1232  ref.deref(); // busService has increased the refcounting to us
1233  // avoid cyclic refcounting
1234 
1238 }
The QDBusConnectionInterface class provides access to the D-Bus bus daemon service.
void callWithCallbackFailed(const QDBusError &error, const QDBusMessage &message)
The QDBusError class represents an error received from the D-Bus bus or from remote applications foun...
Definition: qdbuserror.h:60
#define SIGNAL(a)
Definition: qobjectdefs.h:227
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
Definition: qobject.cpp:2580
bool deref()
Atomically decrements the value of this QAtomicInt.
The QDBusMessage class represents one message sent or received over the D-Bus bus.
Definition: qdbusmessage.h:59
QDBusConnectionInterface * busService

◆ setConnection()

void QDBusConnectionPrivate::setConnection ( DBusConnection *  connection,
const QDBusErrorInternal error 
)

Definition at line 1710 of file qdbusintegrator.cpp.

Referenced by QDBusConnection::connectToBus().

1711 {
1712  if (!dbc) {
1713  handleError(error);
1714  return;
1715  }
1716 
1717  connection = dbc;
1718  mode = ClientMode;
1719 
1720  const char *service = q_dbus_bus_get_unique_name(connection);
1721  Q_ASSERT(service);
1722  baseService = QString::fromUtf8(service);
1724 
1725  q_dbus_connection_set_exit_on_disconnect(connection, false);
1726  q_dbus_connection_set_watch_functions(connection, qDBusAddWatch, qDBusRemoveWatch,
1727  qDBusToggleWatch, this, 0);
1728  q_dbus_connection_set_timeout_functions(connection, qDBusAddTimeout, qDBusRemoveTimeout,
1729  qDBusToggleTimeout, this, 0);
1730  q_dbus_connection_set_dispatch_status_function(connection, qDBusUpdateDispatchStatus, this, 0);
1731  q_dbus_connection_add_filter(connection, qDBusSignalFilter, this, 0);
1732 
1733  // Initialize the hooks for the NameAcquired and NameLost signals
1734  // we don't use connectSignal here because we don't need the rules to be sent to the bus
1735  // the bus will always send us these two signals
1736  SignalHook hook;
1737  hook.service = dbusServiceString();
1738  hook.path.clear(); // no matching
1739  hook.obj = this;
1740  hook.params << QMetaType::Void << QVariant::String; // both functions take a QString as parameter and return void
1741 
1742  hook.midx = staticMetaObject.indexOfSlot("registerServiceNoLock(QString)");
1743  Q_ASSERT(hook.midx != -1);
1744  signalHooks.insert(QLatin1String("NameAcquired:" DBUS_INTERFACE_DBUS), hook);
1745 
1746  hook.midx = staticMetaObject.indexOfSlot("unregisterServiceNoLock(QString)");
1747  Q_ASSERT(hook.midx != -1);
1748  signalHooks.insert(QLatin1String("NameLost:" DBUS_INTERFACE_DBUS), hook);
1749 
1750  qDBusDebug() << this << ": connected successfully";
1751 
1752  // schedule a dispatch:
1753  QMetaObject::invokeMethod(this, "doDispatch", Qt::QueuedConnection);
1754 }
bool handleError(const QDBusErrorInternal &error)
static const QMetaObject staticMetaObject
This variable stores the meta-object for the class.
Definition: qobject.h:128
static dbus_bool_t qDBusAddWatch(DBusWatch *watch, void *data)
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
DBusConnection * connection
static void qDBusRemoveTimeout(DBusTimeout *timeout, void *data)
static QString fromUtf8(const char *, int size=-1)
Returns a QString initialized with the first size bytes of the UTF-8 string str.
Definition: qstring.cpp:4302
int indexOfSlot(const char *slot) const
Finds slot and returns its index; otherwise returns -1.
static void qDBusToggleTimeout(DBusTimeout *timeout, void *data)
QDBusConnection::ConnectionCapabilities capabilities
QHash< Key, T >::iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition: qhash.h:934
static void qDBusUpdateDispatchStatus(DBusConnection *connection, DBusDispatchStatus new_status, void *data)
#define qDBusDebug
static void qDBusToggleWatch(DBusWatch *watch, void *data)
static bool invokeMethod(QObject *obj, const char *member, Qt::ConnectionType, QGenericReturnArgument ret, QGenericArgument val0=QGenericArgument(0), QGenericArgument val1=QGenericArgument(), QGenericArgument val2=QGenericArgument(), QGenericArgument val3=QGenericArgument(), QGenericArgument val4=QGenericArgument(), QGenericArgument val5=QGenericArgument(), QGenericArgument val6=QGenericArgument(), QGenericArgument val7=QGenericArgument(), QGenericArgument val8=QGenericArgument(), QGenericArgument val9=QGenericArgument())
Invokes the member (a signal or a slot name) on the object obj.
static QDBusConnection::ConnectionCapabilities connectionCapabilies(DBusConnection *connection)
static void qDBusRemoveWatch(DBusWatch *watch, void *data)
static dbus_bool_t qDBusAddTimeout(DBusTimeout *timeout, void *data)
static DBusHandlerResult qDBusSignalFilter(DBusConnection *connection, DBusMessage *message, void *data)

◆ setPeer()

void QDBusConnectionPrivate::setPeer ( DBusConnection *  connection,
const QDBusErrorInternal error 
)

Definition at line 1657 of file qdbusintegrator.cpp.

Referenced by QDBusConnection::connectToPeer(), and qDBusNewConnection().

1658 {
1659  if (!c) {
1660  handleError(error);
1661  return;
1662  }
1663 
1664  connection = c;
1665  mode = PeerMode;
1666 
1667  q_dbus_connection_set_exit_on_disconnect(connection, false);
1668  q_dbus_connection_set_watch_functions(connection,
1669  qDBusAddWatch,
1672  this, 0);
1673  q_dbus_connection_set_timeout_functions(connection,
1677  this, 0);
1678  q_dbus_connection_set_dispatch_status_function(connection, qDBusUpdateDispatchStatus, this, 0);
1679  q_dbus_connection_add_filter(connection,
1681  this, 0);
1682 
1683  QMetaObject::invokeMethod(this, "doDispatch", Qt::QueuedConnection);
1684 }
unsigned char c[8]
Definition: qnumeric_p.h:62
bool handleError(const QDBusErrorInternal &error)
static dbus_bool_t qDBusAddWatch(DBusWatch *watch, void *data)
DBusConnection * connection
static void qDBusRemoveTimeout(DBusTimeout *timeout, void *data)
static void qDBusToggleTimeout(DBusTimeout *timeout, void *data)
static void qDBusUpdateDispatchStatus(DBusConnection *connection, DBusDispatchStatus new_status, void *data)
static void qDBusToggleWatch(DBusWatch *watch, void *data)
static bool invokeMethod(QObject *obj, const char *member, Qt::ConnectionType, QGenericReturnArgument ret, QGenericArgument val0=QGenericArgument(0), QGenericArgument val1=QGenericArgument(), QGenericArgument val2=QGenericArgument(), QGenericArgument val3=QGenericArgument(), QGenericArgument val4=QGenericArgument(), QGenericArgument val5=QGenericArgument(), QGenericArgument val6=QGenericArgument(), QGenericArgument val7=QGenericArgument(), QGenericArgument val8=QGenericArgument(), QGenericArgument val9=QGenericArgument())
Invokes the member (a signal or a slot name) on the object obj.
static void qDBusRemoveWatch(DBusWatch *watch, void *data)
static dbus_bool_t qDBusAddTimeout(DBusTimeout *timeout, void *data)
static DBusHandlerResult qDBusSignalFilter(DBusConnection *connection, DBusMessage *message, void *data)

◆ setSender()

void QDBusConnectionPrivate::setSender ( const QDBusConnectionPrivate s)
static
Warning
This function is not part of the public interface.

Definition at line 1221 of file qdbusconnection.cpp.

Referenced by deliverCall().

1222 {
1223  _q_manager()->setSender(s);
1224 }

◆ setServer()

void QDBusConnectionPrivate::setServer ( DBusServer *  server,
const QDBusErrorInternal error 
)

Definition at line 1620 of file qdbusintegrator.cpp.

Referenced by QDBusServer::QDBusServer().

1621 {
1622  if (!s) {
1623  handleError(error);
1624  return;
1625  }
1626 
1627  server = s;
1628  mode = ServerMode;
1629 
1630  dbus_bool_t data_allocated = q_dbus_server_allocate_data_slot(&server_slot);
1631  if (data_allocated && server_slot < 0)
1632  return;
1633 
1634  dbus_bool_t watch_functions_set = q_dbus_server_set_watch_functions(server,
1635  qDBusAddWatch,
1638  this, 0);
1639  //qDebug() << "watch_functions_set" << watch_functions_set;
1640  Q_UNUSED(watch_functions_set);
1641 
1642  dbus_bool_t time_functions_set = q_dbus_server_set_timeout_functions(server,
1646  this, 0);
1647  //qDebug() << "time_functions_set" << time_functions_set;
1648  Q_UNUSED(time_functions_set);
1649 
1650  q_dbus_server_set_new_connection_function(server, qDBusNewConnection, this, 0);
1651 
1652  dbus_bool_t data_set = q_dbus_server_set_data(server, server_slot, this, 0);
1653  //qDebug() << "data_set" << data_set;
1654  Q_UNUSED(data_set);
1655 }
static dbus_int32_t server_slot
static void qDBusNewConnection(DBusServer *server, DBusConnection *connection, void *data)
bool handleError(const QDBusErrorInternal &error)
static dbus_bool_t qDBusAddWatch(DBusWatch *watch, void *data)
static void qDBusRemoveTimeout(DBusTimeout *timeout, void *data)
static void qDBusToggleTimeout(DBusTimeout *timeout, void *data)
static void qDBusToggleWatch(DBusWatch *watch, void *data)
static void qDBusRemoveWatch(DBusWatch *watch, void *data)
static dbus_bool_t qDBusAddTimeout(DBusTimeout *timeout, void *data)
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729

◆ socketRead

void QDBusConnectionPrivate::socketRead ( int  fd)
slot

Definition at line 1136 of file qdbusintegrator.cpp.

1137 {
1138  QVarLengthArray<DBusWatch *, 2> pendingWatches;
1139 
1140  {
1143  while (it != watchers.constEnd() && it.key() == fd) {
1144  if (it->watch && it->read && it->read->isEnabled())
1145  pendingWatches.append(it.value().watch);
1146  ++it;
1147  }
1148  }
1149 
1150  for (int i = 0; i < pendingWatches.size(); ++i)
1151  if (!q_dbus_watch_handle(pendingWatches[i], DBUS_WATCH_READABLE))
1152  qDebug("OUT OF MEM");
1153  doDispatch();
1154 }
QHash< Key, T >::const_iterator constFind(const Key &key, const T &value) const
Returns an iterator pointing to the item with the key and the value in the hash.
Definition: qhash.h:992
#define it(className, varName)
const_iterator ConstIterator
Qt-style synonym for QHash::const_iterator.
Definition: qhash.h:474
void append(const T &t)
Q_CORE_EXPORT void qDebug(const char *,...)
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the hash...
Definition: qhash.h:469
int size() const

◆ socketWrite

void QDBusConnectionPrivate::socketWrite ( int  fd)
slot

Definition at line 1156 of file qdbusintegrator.cpp.

1157 {
1158  QVarLengthArray<DBusWatch *, 2> pendingWatches;
1159 
1160  {
1163  while (it != watchers.constEnd() && it.key() == fd) {
1164  if (it->watch && it->write && it->write->isEnabled())
1165  pendingWatches.append(it.value().watch);
1166  ++it;
1167  }
1168  }
1169 
1170  for (int i = 0; i < pendingWatches.size(); ++i)
1171  if (!q_dbus_watch_handle(pendingWatches[i], DBUS_WATCH_WRITABLE))
1172  qDebug("OUT OF MEM");
1173 }
QHash< Key, T >::const_iterator constFind(const Key &key, const T &value) const
Returns an iterator pointing to the item with the key and the value in the hash.
Definition: qhash.h:992
#define it(className, varName)
const_iterator ConstIterator
Qt-style synonym for QHash::const_iterator.
Definition: qhash.h:474
void append(const T &t)
Q_CORE_EXPORT void qDebug(const char *,...)
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the hash...
Definition: qhash.h:469
int size() const

◆ timerEvent()

void QDBusConnectionPrivate::timerEvent ( QTimerEvent event)
protectedvirtual

This event handler can be reimplemented in a subclass to receive timer events for the object.

QTimer provides a higher-level interface to the timer functionality, and also more general information about timers. The timer event is passed in the event parameter.

See also
startTimer(), killTimer(), event()

Reimplemented from QObject.

Definition at line 1083 of file qdbusintegrator.cpp.

1084 {
1085  {
1087  DBusTimeout *timeout = timeouts.value(e->timerId(), 0);
1088  if (timeout)
1089  q_dbus_timeout_handle(timeout);
1090  }
1091 
1092  doDispatch();
1093 }
const T value(const Key &key) const
Returns the value associated with the key.
Definition: qhash.h:606

◆ unregisterService()

void QDBusConnectionPrivate::unregisterService ( const QString serviceName)

Definition at line 2427 of file qdbusintegrator.cpp.

2428 {
2430  unregisterServiceNoLock(serviceName);
2431 }
void unregisterServiceNoLock(const QString &serviceName)

◆ unregisterServiceNoLock

void QDBusConnectionPrivate::unregisterServiceNoLock ( const QString serviceName)
privateslot

Definition at line 2433 of file qdbusintegrator.cpp.

Referenced by unregisterService().

2434 {
2435  serviceNames.removeAll(serviceName);
2436 }
int removeAll(const T &t)
Removes all occurrences of value in the list and returns the number of entries removed.
Definition: qlist.h:770

◆ waitForFinished()

void QDBusConnectionPrivate::waitForFinished ( QDBusPendingCallPrivate pcall)

Definition at line 1766 of file qdbusintegrator.cpp.

1767 {
1768  Q_ASSERT(pcall->pending);
1769  //Q_ASSERT(pcall->mutex.isLocked()); // there's no such function
1770 
1771  if (pcall->waitingForFinished) {
1772  // another thread is already waiting
1773  pcall->waitForFinishedCondition.wait(&pcall->mutex);
1774  } else {
1775  pcall->waitingForFinished = true;
1776  pcall->mutex.unlock();
1777 
1778  {
1780  q_dbus_pending_call_block(pcall->pending);
1781  // QDBusConnectionPrivate::processFinishedCall() is called automatically
1782  }
1783  pcall->mutex.lock();
1784 
1785  if (pcall->pending) {
1786  q_dbus_pending_call_unref(pcall->pending);
1787  pcall->pending = 0;
1788  }
1789 
1791  }
1792 }
void lock()
Locks the mutex.
Definition: qmutex.cpp:151
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
void unlock()
Unlocks the mutex.
Definition: qmutex.cpp:296
bool wait(QMutex *mutex, unsigned long time=ULONG_MAX)
DBusPendingCall * pending
volatile bool waitingForFinished
QWaitCondition waitForFinishedCondition

Friends and Related Functions

◆ QDBusActivateObjectEvent

Definition at line 333 of file qdbusconnection_p.h.

◆ QDBusCallDeliveryEvent

Definition at line 334 of file qdbusconnection_p.h.

Referenced by prepareReply().

Properties

◆ baseService

QString QDBusConnectionPrivate::baseService

◆ busService

QDBusConnectionInterface* QDBusConnectionPrivate::busService

Definition at line 285 of file qdbusconnection_p.h.

◆ cachedMetaObjects

MetaObjectHash QDBusConnectionPrivate::cachedMetaObjects

Definition at line 305 of file qdbusconnection_p.h.

Referenced by findMetaObject(), and ~QDBusConnectionPrivate().

◆ callDeliveryMutex

QMutex QDBusConnectionPrivate::callDeliveryMutex

Definition at line 307 of file qdbusconnection_p.h.

◆ callDeliveryState

QDBusCallDeliveryEvent* QDBusConnectionPrivate::callDeliveryState

Definition at line 308 of file qdbusconnection_p.h.

◆ capabilities

QDBusConnection::ConnectionCapabilities QDBusConnectionPrivate::capabilities

◆ connection

DBusConnection* QDBusConnectionPrivate::connection

Definition at line 283 of file qdbusconnection_p.h.

◆ dispatchLock

QMutex QDBusConnectionPrivate::dispatchLock

Definition at line 296 of file qdbusconnection_p.h.

◆ lastError

QDBusError QDBusConnectionPrivate::lastError

◆ lock

QReadWriteLock QDBusConnectionPrivate::lock

Definition at line 297 of file qdbusconnection_p.h.

Referenced by getNameOwner().

◆ matchRefCounts

MatchRefCountHash QDBusConnectionPrivate::matchRefCounts

Definition at line 303 of file qdbusconnection_p.h.

Referenced by connectSignal(), disconnectSignal(), and QDBusConnectionPrivate().

◆ mode

ConnectionMode QDBusConnectionPrivate::mode

◆ name

QString QDBusConnectionPrivate::name

◆ ref

QAtomicInt QDBusConnectionPrivate::ref

◆ rootNode

ObjectTreeNode QDBusConnectionPrivate::rootNode

◆ server

DBusServer* QDBusConnectionPrivate::server

◆ serverConnectionNames

QStringList QDBusConnectionPrivate::serverConnectionNames

Definition at line 276 of file qdbusconnection_p.h.

Referenced by qDBusNewConnection(), and QDBusServer::~QDBusServer().

◆ serviceNames

QStringList QDBusConnectionPrivate::serviceNames

◆ signalHooks

SignalHookHash QDBusConnectionPrivate::signalHooks

◆ timeouts

TimeoutHash QDBusConnectionPrivate::timeouts

Definition at line 292 of file qdbusconnection_p.h.

Referenced by qDBusRealAddTimeout(), qDBusRemoveTimeout(), and timerEvent().

◆ timeoutsPendingAdd

PendingTimeoutList QDBusConnectionPrivate::timeoutsPendingAdd

Definition at line 293 of file qdbusconnection_p.h.

Referenced by customEvent(), qDBusAddTimeout(), and qDBusRemoveTimeout().

◆ watchAndTimeoutLock

QMutex QDBusConnectionPrivate::watchAndTimeoutLock

Definition at line 290 of file qdbusconnection_p.h.

◆ watchedServices

WatchedServicesHash QDBusConnectionPrivate::watchedServices

◆ watchers

WatcherHash QDBusConnectionPrivate::watchers

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