Qt 4.8
Macros | Typedefs | Functions | Variables
qdbusintegrator.cpp File Reference
#include <qcoreapplication.h>
#include <qdebug.h>
#include <qmetaobject.h>
#include <qobject.h>
#include <qsocketnotifier.h>
#include <qstringlist.h>
#include <qtimer.h>
#include <qthread.h>
#include "qdbusargument.h"
#include "qdbusconnection_p.h"
#include "qdbusconnectionmanager_p.h"
#include "qdbusinterface_p.h"
#include "qdbusmessage.h"
#include "qdbusmetatype.h"
#include "qdbusmetatype_p.h"
#include "qdbusabstractadaptor.h"
#include "qdbusabstractadaptor_p.h"
#include "qdbusutil_p.h"
#include "qdbusvirtualobject.h"
#include "qdbusmessage_p.h"
#include "qdbuscontext_p.h"
#include "qdbuspendingcall_p.h"
#include "qdbusintegrator_p.h"
#include "qdbusthreaddebug_p.h"

Go to the source code of this file.

Macros

#define DBUS_TYPE_UNIX_FD   int('h')
 
#define qDBusDebug   if (!::isDebugging); else qDebug
 

Typedefs

typedef void(* QDBusSpyHook) (const QDBusMessage &)
 
typedef QVarLengthArray< QDBusSpyHook, 4 > QDBusSpyHookList
 

Functions

static QByteArray buildMatchRule (const QString &service, const QString &objectPath, const QString &interface, const QString &member, const QStringList &argMatch, const QString &)
 
static void cleanupDeletedNodes (QDBusConnectionPrivate::ObjectTreeNode &parent)
 
static QDBusConnection::ConnectionCapabilities connectionCapabilies (DBusConnection *connection)
 
static QString dbusInterfaceString ()
 
static QObjectfindChildObject (const QDBusConnectionPrivate::ObjectTreeNode *root, const QString &fullpath, int start)
 
static bool findObject (const QDBusConnectionPrivate::ObjectTreeNode *root, const QString &fullpath, int &usedLength, QDBusConnectionPrivate::ObjectTreeNode &result)
 
static int findSlot (const QMetaObject *mo, const QByteArray &name, int flags, const QString &signature_, QList< int > &metaTypes)
 
static void huntAndDestroy (QObject *needle, QDBusConnectionPrivate::ObjectTreeNode &haystack)
 
static void huntAndEmit (DBusConnection *connection, DBusMessage *msg, QObject *needle, const QDBusConnectionPrivate::ObjectTreeNode &haystack, bool isScriptable, bool isAdaptor, const QString &path=QString())
 
static QDebug operator<< (QDebug dbg, const QThread *th)
 
 Q_GLOBAL_STATIC_WITH_ARGS (const QString, orgFreedesktopDBusString,(QLatin1String(DBUS_SERVICE_DBUS))) static inline QString dbusServiceString()
 
Q_DBUS_EXPORT void qDBusAddSpyHook (QDBusSpyHook)
 
static dbus_bool_t qDBusAddTimeout (DBusTimeout *timeout, void *data)
 
static dbus_bool_t qDBusAddWatch (DBusWatch *watch, void *data)
 
bool qDBusInitThreads ()
 
static void qDBusNewConnection (DBusServer *server, DBusConnection *connection, void *data)
 
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 qDBusRemoveTimeout (DBusTimeout *timeout, void *data)
 
static void qDBusRemoveWatch (DBusWatch *watch, void *data)
 
static void qDBusResultReceived (DBusPendingCall *pending, void *user_data)
 
static DBusHandlerResult qDBusSignalFilter (DBusConnection *connection, DBusMessage *message, void *data)
 
static void qDBusToggleTimeout (DBusTimeout *timeout, void *data)
 
static void qDBusToggleWatch (DBusWatch *watch, void *data)
 
static void qDBusUpdateDispatchStatus (DBusConnection *connection, DBusDispatchStatus new_status, void *data)
 
static bool shouldWatchService (const QString &service)
 

Variables

static QDBusCallDeliveryEvent *const DIRECT_DELIVERY = (QDBusCallDeliveryEvent *)1
 
static bool isDebugging
 
static dbus_int32_t server_slot = -1
 

Macro Definition Documentation

◆ DBUS_TYPE_UNIX_FD

#define DBUS_TYPE_UNIX_FD   int('h')

Referenced by connectionCapabilies().

◆ qDBusDebug

#define qDBusDebug   if (!::isDebugging); else qDebug

Typedef Documentation

◆ QDBusSpyHook

typedef void(* QDBusSpyHook) (const QDBusMessage &)

Definition at line 134 of file qdbusintegrator.cpp.

◆ QDBusSpyHookList

Definition at line 135 of file qdbusintegrator.cpp.

Function Documentation

◆ buildMatchRule()

static QByteArray buildMatchRule ( const QString service,
const QString objectPath,
const QString interface,
const QString member,
const QStringList argMatch,
const QString  
)
static

Definition at line 408 of file qdbusintegrator.cpp.

Referenced by QDBusConnectionPrivate::prepareHook().

411 {
412  QString result = QLatin1String("type='signal',");
413  QString keyValue = QLatin1String("%1='%2',");
414 
415  if (!service.isEmpty())
416  result += keyValue.arg(QLatin1String("sender"), service);
417  if (!objectPath.isEmpty())
418  result += keyValue.arg(QLatin1String("path"), objectPath);
419  if (!interface.isEmpty())
420  result += keyValue.arg(QLatin1String("interface"), interface);
421  if (!member.isEmpty())
422  result += keyValue.arg(QLatin1String("member"), member);
423 
424  // add the argument string-matching now
425  if (!argMatch.isEmpty()) {
426  keyValue = QLatin1String("arg%1='%2',");
427  for (int i = 0; i < argMatch.count(); ++i)
428  if (!argMatch.at(i).isNull())
429  result += keyValue.arg(i).arg(argMatch.at(i));
430  }
431 
432  result.chop(1); // remove ending comma
433  return result.toLatin1();
434 }
void chop(int n)
Removes n characters from the end of the string.
Definition: qstring.cpp:4623
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
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
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
QByteArray toLatin1() const Q_REQUIRED_RESULT
Returns a Latin-1 representation of the string as a QByteArray.
Definition: qstring.cpp:3993
bool isNull() const
Returns true if this string is null; otherwise returns false.
Definition: qstring.h:505
QString arg(qlonglong a, int fieldwidth=0, int base=10, const QChar &fillChar=QLatin1Char(' ')) const Q_REQUIRED_RESULT
Definition: qstring.cpp:7186

◆ cleanupDeletedNodes()

static void cleanupDeletedNodes ( QDBusConnectionPrivate::ObjectTreeNode parent)
static

Definition at line 2230 of file qdbusintegrator.cpp.

Referenced by QDBusConnectionPrivate::registerObject().

2231 {
2232  QMutableVectorIterator<QDBusConnectionPrivate::ObjectTreeNode> it(parent.children);
2233  while (it.hasNext()) {
2235  if (node.obj == 0 && node.children.isEmpty())
2236  it.remove();
2237  else
2238  cleanupDeletedNodes(node);
2239  }
2240 }
#define it(className, varName)
bool isEmpty() const
Returns true if the vector has size 0; otherwise returns false.
Definition: qvector.h:139
static void cleanupDeletedNodes(QDBusConnectionPrivate::ObjectTreeNode &parent)

◆ connectionCapabilies()

static QDBusConnection::ConnectionCapabilities connectionCapabilies ( DBusConnection *  connection)
static

Definition at line 1686 of file qdbusintegrator.cpp.

Referenced by QDBusConnectionPrivate::setConnection().

1687 {
1688  QDBusConnection::ConnectionCapabilities result = 0;
1689  typedef dbus_bool_t (*can_send_type_t)(DBusConnection *, int);
1690  static can_send_type_t can_send_type = 0;
1691 
1692 #if defined(QT_LINKED_LIBDBUS)
1693 # if DBUS_VERSION-0 >= 0x010400
1694  can_send_type = dbus_connection_can_send_type;
1695 # endif
1696 #else
1697  // run-time check if the next functions are available
1698  can_send_type = (can_send_type_t)qdbus_resolve_conditionally("dbus_connection_can_send_type");
1699 #endif
1700 
1701 #ifndef DBUS_TYPE_UNIX_FD
1702 # define DBUS_TYPE_UNIX_FD int('h')
1703 #endif
1704  if (can_send_type && can_send_type(connection, DBUS_TYPE_UNIX_FD))
1706 
1707  return result;
1708 }
#define DBUS_TYPE_UNIX_FD
void * qdbus_resolve_conditionally(const char *name)

◆ dbusInterfaceString()

static QString dbusInterfaceString ( )
inlinestatic

Definition at line 80 of file qdbusintegrator.cpp.

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

81 {
82  // it's the same string, but just be sure
83  Q_ASSERT(*orgFreedesktopDBusString() == QLatin1String(DBUS_INTERFACE_DBUS));
84  return *orgFreedesktopDBusString();
85 }
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
#define Q_ASSERT(cond)
Definition: qglobal.h:1823

◆ findChildObject()

static QObject* findChildObject ( const QDBusConnectionPrivate::ObjectTreeNode root,
const QString fullpath,
int  start 
)
static

Definition at line 485 of file qdbusintegrator.cpp.

Referenced by QDBusConnectionPrivate::activateObject().

487 {
488  int length = fullpath.length();
489 
490  // any object in the tree can tell us to switch to its own object tree:
491  const QDBusConnectionPrivate::ObjectTreeNode *node = root;
492  if (node && node->flags & QDBusConnection::ExportChildObjects) {
493  QObject *obj = node->obj;
494 
495  while (obj) {
496  if (start >= length)
497  // we're at the correct level
498  return obj;
499 
500  int pos = fullpath.indexOf(QLatin1Char('/'), start);
501  pos = (pos == -1 ? length : pos);
502  QStringRef pathComponent(&fullpath, start, pos - start);
503 
504  const QObjectList children = obj->children();
505 
506  // find a child with the proper name
507  QObject *next = 0;
510  for ( ; it != end; ++it)
511  if ((*it)->objectName() == pathComponent) {
512  next = *it;
513  break;
514  }
515 
516  if (!next)
517  break;
518 
519  obj = next;
520  start = pos + 1;
521  }
522  }
523 
524  // object not found
525  return 0;
526 }
#define it(className, varName)
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the list.
Definition: qlist.h:269
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
int indexOf(QChar c, int from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.cpp:2838
The QStringRef class provides a thin wrapper around QString substrings.
Definition: qstring.h:1099
const_iterator ConstIterator
Qt-style synonym for QList::const_iterator.
Definition: qlist.h:279
const QObjectList & children() const
Returns a list of child objects.
Definition: qobject.h:197
static const KeyPair *const end
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the list...
Definition: qlist.h:272

◆ findObject()

static bool findObject ( const QDBusConnectionPrivate::ObjectTreeNode root,
const QString fullpath,
int &  usedLength,
QDBusConnectionPrivate::ObjectTreeNode result 
)
static

Definition at line 436 of file qdbusintegrator.cpp.

Referenced by QDBusConnectionPrivate::handleObjectCall().

439 {
440  if (!fullpath.compare(QLatin1String("/")) && root->obj) {
441  usedLength = 1;
442  result = *root;
443  return root;
444  }
445  int start = 0;
446  int length = fullpath.length();
447  if (fullpath.at(0) == QLatin1Char('/'))
448  start = 1;
449 
450  // walk the object tree
451  const QDBusConnectionPrivate::ObjectTreeNode *node = root;
452  while (start < length && node) {
454  break;
456  break;
457  int end = fullpath.indexOf(QLatin1Char('/'), start);
458  end = (end == -1 ? length : end);
459  QStringRef pathComponent(&fullpath, start, end - start);
460 
462  qLowerBound(node->children.constBegin(), node->children.constEnd(), pathComponent);
463  if (it != node->children.constEnd() && it->name == pathComponent)
464  // match
465  node = it;
466  else
467  node = 0;
468 
469  start = end + 1;
470  }
471 
472  // found our object
473  usedLength = (start > length ? length : start);
474  if (node) {
475  if (node->obj || !node->children.isEmpty())
476  result = *node;
477  else
478  // there really is no object here
479  // we're just looking at an unused space in the QVector
480  node = 0;
481  }
482  return node;
483 }
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)
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
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the vector.
Definition: qvector.h:249
int indexOf(QChar c, int from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.cpp:2838
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
The QStringRef class provides a thin wrapper around QString substrings.
Definition: qstring.h:1099
Q_OUTOFLINE_TEMPLATE RandomAccessIterator qLowerBound(RandomAccessIterator begin, RandomAccessIterator end, const T &value)
Definition: qalgorithms.h:227
int compare(const QString &s) const
Definition: qstring.cpp:5037
const_iterator ConstIterator
Qt-style synonym for QVector::const_iterator.
Definition: qvector.h:279
bool isEmpty() const
Returns true if the vector has size 0; otherwise returns false.
Definition: qvector.h:139
static const KeyPair *const end
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ findSlot()

static int findSlot ( const QMetaObject mo,
const QByteArray name,
int  flags,
const QString signature_,
QList< int > &  metaTypes 
)
static

Definition at line 632 of file qdbusintegrator.cpp.

634 {
635  QByteArray msgSignature = signature_.toLatin1();
636 
637  for (int idx = mo->methodCount() - 1 ; idx >= QObject::staticMetaObject.methodCount(); --idx) {
638  QMetaMethod mm = mo->method(idx);
639 
640  // check access:
641  if (mm.access() != QMetaMethod::Public)
642  continue;
643 
644  // check type:
646  continue;
647 
648  // check name:
649  QByteArray slotname = mm.signature();
650  int paren = slotname.indexOf('(');
651  if (paren != name.length() || !slotname.startsWith(name))
652  continue;
653 
654  int returnType = qDBusNameToTypeId(mm.typeName());
655  bool isAsync = qDBusCheckAsyncTag(mm.tag());
656  bool isScriptable = mm.attributes() & QMetaMethod::Scriptable;
657 
658  // consistency check:
659  if (isAsync && returnType != QMetaType::Void)
660  continue;
661 
662  int inputCount = qDBusParametersForMethod(mm, metaTypes);
663  if (inputCount == -1)
664  continue; // problem parsing
665 
666  metaTypes[0] = returnType;
667  bool hasMessage = false;
668  if (inputCount > 0 &&
669  metaTypes.at(inputCount) == QDBusMetaTypeId::message) {
670  // "no input parameters" is allowed as long as the message meta type is there
671  hasMessage = true;
672  --inputCount;
673  }
674 
675  // try to match the parameters
676  int i;
677  QByteArray reconstructedSignature;
678  for (i = 1; i <= inputCount; ++i) {
679  const char *typeSignature = QDBusMetaType::typeToSignature( metaTypes.at(i) );
680  if (!typeSignature)
681  break; // invalid
682 
683  reconstructedSignature += typeSignature;
684  if (!msgSignature.startsWith(reconstructedSignature))
685  break;
686  }
687 
688  if (reconstructedSignature != msgSignature)
689  continue; // we didn't match them all
690 
691  if (hasMessage)
692  ++i;
693 
694  // make sure that the output parameters have signatures too
695  if (returnType != 0 && QDBusMetaType::typeToSignature(returnType) == 0)
696  continue;
697 
698  bool ok = true;
699  for (int j = i; ok && j < metaTypes.count(); ++j)
700  if (QDBusMetaType::typeToSignature(metaTypes.at(i)) == 0)
701  ok = false;
702  if (!ok)
703  continue;
704 
705  // consistency check:
706  if (isAsync && metaTypes.count() > i + 1)
707  continue;
708 
709  if (mm.methodType() == QMetaMethod::Slot) {
710  if (isScriptable && (flags & QDBusConnection::ExportScriptableSlots) == 0)
711  continue; // scriptable slots not exported
712  if (!isScriptable && (flags & QDBusConnection::ExportNonScriptableSlots) == 0)
713  continue; // non-scriptable slots not exported
714  } else {
715  if (isScriptable && (flags & QDBusConnection::ExportScriptableInvokables) == 0)
716  continue; // scriptable invokables not exported
717  if (!isScriptable && (flags & QDBusConnection::ExportNonScriptableInvokables) == 0)
718  continue; // non-scriptable invokables not exported
719  }
720 
721  // if we got here, this slot matched
722  return idx;
723  }
724 
725  // no slot matched
726  return -1;
727 }
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
static const QMetaObject staticMetaObject
This variable stores the meta-object for the class.
Definition: qobject.h:128
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
const char * typeName() const
Returns the return type of this method, or an empty string if the return type is void.
bool startsWith(const QByteArray &a) const
Returns true if this byte array starts with byte array ba; otherwise returns false.
bool qDBusCheckAsyncTag(const char *tag)
Definition: qdbusmisc.cpp:57
int qDBusParametersForMethod(const QMetaMethod &mm, QList< int > &metaTypes)
Definition: qdbusmisc.cpp:137
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
QByteArray toLatin1() const Q_REQUIRED_RESULT
Returns a Latin-1 representation of the string as a QByteArray.
Definition: qstring.cpp:3993
int indexOf(char c, int from=0) const
Returns the index position of the first occurrence of the character ch in the byte array...
int length() const
Same as size().
Definition: qbytearray.h:356
MethodType methodType() const
Returns the type of this method (signal, slot, or method).
int qDBusNameToTypeId(const char *name)
Definition: qdbusmisc.cpp:72
const char * tag() const
Returns the tag associated with this method.
int attributes() const
QMetaMethod method(int index) const
Returns the meta-data for the method with the given index.
const char * signature() const
Returns the signature of this method (e.g., setValue(double)).
Access access() const
Returns the access specification of this method (private, protected, or public).
int methodCount() const
Returns the number of methods known to the meta-object system in this class, including the number of ...
The QMetaMethod class provides meta-data about a member function.
Definition: qmetaobject.h:56

◆ huntAndDestroy()

static void huntAndDestroy ( QObject needle,
QDBusConnectionPrivate::ObjectTreeNode haystack 
)
static

Definition at line 587 of file qdbusintegrator.cpp.

Referenced by QDBusConnectionPrivate::objectDestroyed().

588 {
591  for ( ; it != end; ++it)
592  huntAndDestroy(needle, *it);
593 
594  if (needle == haystack.obj) {
595  haystack.obj = 0;
596  haystack.flags = 0;
597  }
598 }
#define it(className, varName)
iterator Iterator
Qt-style synonym for QVector::iterator.
Definition: qvector.h:278
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the vector...
Definition: qvector.h:250
iterator begin()
Returns an STL-style iterator pointing to the first item in the vector.
Definition: qvector.h:247
static const KeyPair *const end
static void huntAndDestroy(QObject *needle, QDBusConnectionPrivate::ObjectTreeNode &haystack)

◆ huntAndEmit()

static void huntAndEmit ( DBusConnection *  connection,
DBusMessage *  msg,
QObject needle,
const QDBusConnectionPrivate::ObjectTreeNode haystack,
bool  isScriptable,
bool  isAdaptor,
const QString path = QString() 
)
static

Definition at line 600 of file qdbusintegrator.cpp.

Referenced by QDBusConnectionPrivate::relaySignal().

603 {
606  for ( ; it != end; ++it)
607  huntAndEmit(connection, msg, needle, *it, isScriptable, isAdaptor, path + QLatin1Char('/') + it->name);
608 
609  if (needle == haystack.obj) {
610  // is this a signal we should relay?
611  if (isAdaptor && (haystack.flags & QDBusConnection::ExportAdaptors) == 0)
612  return; // no: it comes from an adaptor and we're not exporting adaptors
613  else if (!isAdaptor) {
614  int mask = isScriptable
617  if ((haystack.flags & mask) == 0)
618  return; // signal was not exported
619  }
620 
621  QByteArray p = path.toLatin1();
622  if (p.isEmpty())
623  p = "/";
624  qDBusDebug() << QThread::currentThread() << "emitting signal at" << p;
625  DBusMessage *msg2 = q_dbus_message_copy(msg);
626  q_dbus_message_set_path(msg2, p);
627  q_dbus_connection_send(connection, msg2, 0);
628  q_dbus_message_unref(msg2);
629  }
630 }
#define it(className, varName)
static void huntAndEmit(DBusConnection *connection, DBusMessage *msg, QObject *needle, const QDBusConnectionPrivate::ObjectTreeNode &haystack, bool isScriptable, bool isAdaptor, const QString &path=QString())
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
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
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the vector.
Definition: qvector.h:249
static QThread * currentThread()
Returns a pointer to a QThread which manages the currently executing thread.
Definition: qthread.cpp:419
QByteArray toLatin1() const Q_REQUIRED_RESULT
Returns a Latin-1 representation of the string as a QByteArray.
Definition: qstring.cpp:3993
#define qDBusDebug
const_iterator ConstIterator
Qt-style synonym for QVector::const_iterator.
Definition: qvector.h:279
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
Definition: qbytearray.h:421
static const KeyPair *const end
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ operator<<()

static QDebug operator<< ( QDebug  dbg,
const QThread th 
)
inlinestatic

Definition at line 87 of file qdbusintegrator.cpp.

88 {
89  dbg.nospace() << "QThread(ptr=" << (void*)th;
90  if (th && !th->objectName().isEmpty())
91  dbg.nospace() << ", name=" << th->objectName();
92  dbg.nospace() << ')';
93  return dbg.space();
94 }
QDebug & nospace()
Clears the stream&#39;s internal flag that records whether the last character was a space and returns a r...
Definition: qdebug.h:92
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
QString objectName() const
QDebug & space()
Writes a space character to the debug stream and returns a reference to the stream.
Definition: qdebug.h:91

◆ Q_GLOBAL_STATIC_WITH_ARGS()

Q_GLOBAL_STATIC_WITH_ARGS ( const QString  ,
orgFreedesktopDBusString  ,
(QLatin1String(DBUS_SERVICE_DBUS))   
)

Definition at line 76 of file qdbusintegrator.cpp.

79 { return *orgFreedesktopDBusString(); }

◆ qDBusAddSpyHook()

void qDBusAddSpyHook ( QDBusSpyHook  hook)

Definition at line 534 of file qdbusintegrator.cpp.

Referenced by shouldWatchService().

535 {
536  qDBusSpyHookList()->append(hook);
537 }

◆ qDBusAddTimeout()

static dbus_bool_t qDBusAddTimeout ( DBusTimeout *  timeout,
void *  data 
)
static

Definition at line 143 of file qdbusintegrator.cpp.

Referenced by qDBusToggleTimeout(), QDBusConnectionPrivate::setConnection(), QDBusConnectionPrivate::setPeer(), and QDBusConnectionPrivate::setServer().

144 {
145  Q_ASSERT(timeout);
146  Q_ASSERT(data);
147 
148  // qDebug("addTimeout %d", q_dbus_timeout_get_interval(timeout));
149 
151 
152  if (!q_dbus_timeout_get_enabled(timeout))
153  return true;
154 
157  // correct thread
158  return qDBusRealAddTimeout(d, timeout, q_dbus_timeout_get_interval(timeout));
159  } else {
160  // wrong thread: sync back
163  d->timeoutsPendingAdd.append(qMakePair(timeout, q_dbus_timeout_get_interval(timeout)));
165  return true;
166  }
167 }
double d
Definition: qnumeric_p.h:62
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
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
static const char * data(const QByteArray &arr)
PendingTimeoutList timeoutsPendingAdd
static bool qDBusRealAddTimeout(QDBusConnectionPrivate *d, DBusTimeout *timeout, int ms)
static QCoreApplication * instance()
Returns a pointer to the application&#39;s QCoreApplication (or QApplication) instance.
Q_OUTOFLINE_TEMPLATE QPair< T1, T2 > qMakePair(const T1 &x, const T2 &y)
Definition: qpair.h:102
enum QDBusConnectionCallbackEvent::Subtype subtype
QThread * thread() const
Returns the thread in which the object lives.
Definition: qobject.cpp:1419
void postEventToThread(int action, QObject *target, QEvent *event)

◆ qDBusAddWatch()

static dbus_bool_t qDBusAddWatch ( DBusWatch *  watch,
void *  data 
)
static

Definition at line 236 of file qdbusintegrator.cpp.

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

237 {
238  Q_ASSERT(watch);
239  Q_ASSERT(data);
240 
242 
243  int flags = q_dbus_watch_get_flags(watch);
244  int fd = q_dbus_watch_get_fd(watch);
245 
247  return qDBusRealAddWatch(d, watch, flags, fd);
248  } else {
251  ev->watch = watch;
252  ev->fd = fd;
253  ev->extra = flags;
255  return true;
256  }
257 }
double d
Definition: qnumeric_p.h:62
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
static QThread * currentThread()
Returns a pointer to a QThread which manages the currently executing thread.
Definition: qthread.cpp:419
static const char * data(const QByteArray &arr)
static QCoreApplication * instance()
Returns a pointer to the application&#39;s QCoreApplication (or QApplication) instance.
static bool qDBusRealAddWatch(QDBusConnectionPrivate *d, DBusWatch *watch, int flags, int fd)
enum QDBusConnectionCallbackEvent::Subtype subtype
QThread * thread() const
Returns the thread in which the object lives.
Definition: qobject.cpp:1419
void postEventToThread(int action, QObject *target, QEvent *event)

◆ qDBusInitThreads()

bool qDBusInitThreads ( )

◆ qDBusNewConnection()

static void qDBusNewConnection ( DBusServer *  server,
DBusConnection *  connection,
void *  data 
)
static

Definition at line 380 of file qdbusintegrator.cpp.

Referenced by QDBusConnectionPrivate::setServer().

381 {
382  // ### We may want to separate the server from the QDBusConnectionPrivate
384  Q_ASSERT(connection);
385  Q_ASSERT(data);
386 
387  // keep the connection alive
388  q_dbus_connection_ref(connection);
389  QDBusConnectionPrivate *serverConnection = static_cast<QDBusConnectionPrivate *>(data);
390 
391  QDBusConnectionPrivate *newConnection = new QDBusConnectionPrivate(serverConnection->parent());
393  QDBusConnectionManager::instance()->setConnection(QLatin1String("QDBusServer-") + QString::number(reinterpret_cast<qulonglong>(newConnection)), newConnection);
394  serverConnection->serverConnectionNames << newConnection->name;
395 
396  // setPeer does the error handling for us
398  newConnection->setPeer(connection, error);
399 
400  QDBusConnection retval = QDBusConnectionPrivate::q(newConnection);
401 
402  // make QDBusServer emit the newConnection signal
403  serverConnection->serverConnection(retval);
404 }
static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qstring.cpp:6448
#define error(msg)
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
static QDBusConnection q(QDBusConnectionPrivate *connection)
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
static QDBusConnectionManager * instance()
static const char * data(const QByteArray &arr)
void setConnection(const QString &name, QDBusConnectionPrivate *c)
static QAuServer & server()
Definition: qsound.cpp:79
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
The QDBusConnection class represents a connection to the D-Bus bus daemon.
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
void setPeer(DBusConnection *connection, const QDBusErrorInternal &error)
#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
void serverConnection(const QDBusConnection &connection)

◆ qDBusRealAddTimeout()

static bool qDBusRealAddTimeout ( QDBusConnectionPrivate d,
DBusTimeout *  timeout,
int  ms 
)
static

Definition at line 169 of file qdbusintegrator.cpp.

Referenced by QDBusConnectionPrivate::customEvent(), and qDBusAddTimeout().

170 {
171  Q_ASSERT(d->timeouts.keys(timeout).isEmpty());
172 
173  int timerId = d->startTimer(ms);
174  if (!timerId)
175  return false;
176 
177  d->timeouts[timerId] = timeout;
178  return true;
179 }
int startTimer(int interval)
Starts a timer and returns a timer identifier, or returns zero if it could not start a timer...
Definition: qobject.cpp:1623
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
QList< Key > keys() const
Returns a list containing all the keys in the hash, in an arbitrary order.
Definition: qhash.h:648

◆ qDBusRealAddWatch()

static bool qDBusRealAddWatch ( QDBusConnectionPrivate d,
DBusWatch *  watch,
int  flags,
int  fd 
)
static

Definition at line 259 of file qdbusintegrator.cpp.

Referenced by QDBusConnectionPrivate::customEvent(), qDBusAddWatch(), and qDBusToggleTimeout().

260 {
262 
264  if (flags & DBUS_WATCH_READABLE) {
265  //qDebug("addReadWatch %d", fd);
266  watcher.watch = watch;
268  watcher.read = new QSocketNotifier(fd, QSocketNotifier::Read, d);
269  watcher.read->setEnabled(q_dbus_watch_get_enabled(watch));
270  d->connect(watcher.read, SIGNAL(activated(int)), SLOT(socketRead(int)));
271  }
272  }
273  if (flags & DBUS_WATCH_WRITABLE) {
274  //qDebug("addWriteWatch %d", fd);
275  watcher.watch = watch;
277  watcher.write = new QSocketNotifier(fd, QSocketNotifier::Write, d);
278  watcher.write->setEnabled(q_dbus_watch_get_enabled(watch));
279  d->connect(watcher.write, SIGNAL(activated(int)), SLOT(socketWrite(int)));
280  }
281  }
282  d->watchers.insertMulti(fd, watcher);
283 
284  return true;
285 }
#define SLOT(a)
Definition: qobjectdefs.h:226
The QSocketNotifier class provides support for monitoring activity on a file descriptor.
#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
static QCoreApplication * instance()
Returns a pointer to the application&#39;s QCoreApplication (or QApplication) instance.
void setEnabled(bool)
If enable is true, the notifier is enabled; otherwise the notifier is disabled.
iterator insertMulti(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition: qhash.h:772

◆ qDBusRealToggleWatch()

static void qDBusRealToggleWatch ( QDBusConnectionPrivate d,
DBusWatch *  watch,
int  fd 
)
static

Definition at line 339 of file qdbusintegrator.cpp.

Referenced by QDBusConnectionPrivate::customEvent(), qDBusRemoveWatch(), and qDBusToggleWatch().

340 {
342 
344  while (i != d->watchers.end() && i.key() == fd) {
345  if (i.value().watch == watch) {
346  bool enabled = q_dbus_watch_get_enabled(watch);
347  int flags = q_dbus_watch_get_flags(watch);
348 
349  //qDebug("toggle watch %d to %d (write: %d, read: %d)", q_dbus_watch_get_fd(watch), enabled, flags & DBUS_WATCH_WRITABLE, flags & DBUS_WATCH_READABLE);
350 
351  if (flags & DBUS_WATCH_READABLE && i.value().read)
352  i.value().read->setEnabled(enabled);
353  if (flags & DBUS_WATCH_WRITABLE && i.value().write)
354  i.value().write->setEnabled(enabled);
355  return;
356  }
357  ++i;
358  }
359 }
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
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the hash...
Definition: qhash.h:467
#define enabled
friend class iterator
Definition: qhash.h:393

◆ qDBusRemoveTimeout()

static void qDBusRemoveTimeout ( DBusTimeout *  timeout,
void *  data 
)
static

Definition at line 181 of file qdbusintegrator.cpp.

Referenced by qDBusToggleTimeout(), QDBusConnectionPrivate::setConnection(), QDBusConnectionPrivate::setPeer(), and QDBusConnectionPrivate::setServer().

182 {
183  Q_ASSERT(timeout);
184  Q_ASSERT(data);
185 
186  // qDebug("removeTimeout");
187 
189 
191 
192  // is it pending addition?
194  while (pit != d->timeoutsPendingAdd.end()) {
195  if (pit->first == timeout)
196  pit = d->timeoutsPendingAdd.erase(pit);
197  else
198  ++pit;
199  }
200 
201  // is it a running timer?
202  bool correctThread = QCoreApplication::instance() && QThread::currentThread() == d->thread();
204  while (it != d->timeouts.end()) {
205  if (it.value() == timeout) {
206  if (correctThread) {
207  // correct thread
208  d->killTimer(it.key());
209  } else {
210  // incorrect thread or no application, post an event for later
213  ev->timerId = it.key();
215  }
216  it = d->timeouts.erase(it);
217  break;
218  } else {
219  ++it;
220  }
221  }
222 }
double d
Definition: qnumeric_p.h:62
#define it(className, varName)
iterator begin()
Returns an STL-style iterator pointing to the first item in the list.
Definition: qlist.h:267
T & value() const
Returns a modifiable reference to the current item&#39;s value.
Definition: qhash.h:348
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
static QThread * currentThread()
Returns a pointer to a QThread which manages the currently executing thread.
Definition: qthread.cpp:419
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the list...
Definition: qlist.h:270
static const char * data(const QByteArray &arr)
const Key & key() const
Returns the current item&#39;s key as a const reference.
Definition: qhash.h:347
PendingTimeoutList timeoutsPendingAdd
iterator erase(iterator pos)
Removes the item associated with the iterator pos from the list, and returns an iterator to the next ...
Definition: qlist.h:464
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the hash...
Definition: qhash.h:467
static QCoreApplication * instance()
Returns a pointer to the application&#39;s QCoreApplication (or QApplication) instance.
The QHash::iterator class provides an STL-style non-const iterator for QHash and QMultiHash.
Definition: qhash.h:330
iterator begin()
Returns an STL-style iterator pointing to the first item in the hash.
Definition: qhash.h:464
enum QDBusConnectionCallbackEvent::Subtype subtype
QThread * thread() const
Returns the thread in which the object lives.
Definition: qobject.cpp:1419
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
void postEventToThread(int action, QObject *target, QEvent *event)
void killTimer(int id)
Kills the timer with timer identifier, id.
Definition: qobject.cpp:1650

◆ qDBusRemoveWatch()

static void qDBusRemoveWatch ( DBusWatch *  watch,
void *  data 
)
static

Definition at line 287 of file qdbusintegrator.cpp.

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

288 {
289  Q_ASSERT(watch);
290  Q_ASSERT(data);
291 
292  //qDebug("remove watch");
293 
295  int fd = q_dbus_watch_get_fd(watch);
296 
299  while (i != d->watchers.end() && i.key() == fd) {
300  if (i.value().watch == watch) {
302  // correct thread, delete the socket notifiers
303  delete i.value().read;
304  delete i.value().write;
305  } else {
306  // incorrect thread or no application, use delete later
307  if (i->read)
308  i->read->deleteLater();
309  if (i->write)
310  i->write->deleteLater();
311  }
312  i = d->watchers.erase(i);
313  } else {
314  ++i;
315  }
316  }
317 }
double d
Definition: qnumeric_p.h:62
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
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
static QThread * currentThread()
Returns a pointer to a QThread which manages the currently executing thread.
Definition: qthread.cpp:419
static const char * data(const QByteArray &arr)
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the hash...
Definition: qhash.h:467
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
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

◆ qDBusResultReceived()

static void qDBusResultReceived ( DBusPendingCall *  pending,
void *  user_data 
)
static

Definition at line 1757 of file qdbusintegrator.cpp.

Referenced by QDBusConnectionPrivate::sendWithReplyAsync().

1758 {
1759  QDBusPendingCallPrivate *call = reinterpret_cast<QDBusPendingCallPrivate *>(user_data);
1760  Q_ASSERT(call->pending == pending);
1761  Q_UNUSED(pending);
1763 }
static void processFinishedCall(QDBusPendingCallPrivate *call)
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
DBusPendingCall * pending
#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

◆ qDBusSignalFilter()

static DBusHandlerResult qDBusSignalFilter ( DBusConnection *  connection,
DBusMessage *  message,
void *  data 
)
static

Definition at line 541 of file qdbusintegrator.cpp.

Referenced by QDBusConnectionPrivate::setConnection(), and QDBusConnectionPrivate::setPeer().

542 {
543  Q_ASSERT(data);
544  Q_UNUSED(connection);
547  return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
548 
550  qDBusDebug() << d << "got message (signal):" << amsg;
551 
552  return d->handleMessage(amsg) ?
553  DBUS_HANDLER_RESULT_HANDLED :
554  DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
555 }
double d
Definition: qnumeric_p.h:62
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
static QDBusMessage fromDBusMessage(DBusMessage *dmsg, QDBusConnection::ConnectionCapabilities capabilities)
Constructs a QDBusMessage by parsing the given DBusMessage object.
static const char * data(const QByteArray &arr)
QDBusConnection::ConnectionCapabilities capabilities
bool handleMessage(const QDBusMessage &msg)
#define qDBusDebug
The QDBusMessage class represents one message sent or received over the D-Bus bus.
Definition: qdbusmessage.h:59
#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

◆ qDBusToggleTimeout()

static void qDBusToggleTimeout ( DBusTimeout *  timeout,
void *  data 
)
static

Definition at line 224 of file qdbusintegrator.cpp.

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

225 {
226  Q_ASSERT(timeout);
227  Q_ASSERT(data);
228 
229  //qDebug("ToggleTimeout");
230 
231  qDBusRemoveTimeout(timeout, data);
232  qDBusAddTimeout(timeout, data);
233 }
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
static void qDBusRemoveTimeout(DBusTimeout *timeout, void *data)
static const char * data(const QByteArray &arr)
static dbus_bool_t qDBusAddTimeout(DBusTimeout *timeout, void *data)

◆ qDBusToggleWatch()

static void qDBusToggleWatch ( DBusWatch *  watch,
void *  data 
)
static

Definition at line 320 of file qdbusintegrator.cpp.

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

321 {
322  Q_ASSERT(watch);
323  Q_ASSERT(data);
324 
326  int fd = q_dbus_watch_get_fd(watch);
327 
329  qDBusRealToggleWatch(d, watch, fd);
330  } else {
333  ev->watch = watch;
334  ev->fd = fd;
336  }
337 }
double d
Definition: qnumeric_p.h:62
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
static QThread * currentThread()
Returns a pointer to a QThread which manages the currently executing thread.
Definition: qthread.cpp:419
static const char * data(const QByteArray &arr)
static QCoreApplication * instance()
Returns a pointer to the application&#39;s QCoreApplication (or QApplication) instance.
static void qDBusRealToggleWatch(QDBusConnectionPrivate *d, DBusWatch *watch, int fd)
enum QDBusConnectionCallbackEvent::Subtype subtype
QThread * thread() const
Returns the thread in which the object lives.
Definition: qobject.cpp:1419
void postEventToThread(int action, QObject *target, QEvent *event)

◆ qDBusUpdateDispatchStatus()

static void qDBusUpdateDispatchStatus ( DBusConnection *  connection,
DBusDispatchStatus  new_status,
void *  data 
)
static

Definition at line 361 of file qdbusintegrator.cpp.

Referenced by QDBusConnectionPrivate::setConnection(), and QDBusConnectionPrivate::setPeer().

362 {
363  Q_ASSERT(connection);
364  Q_UNUSED(connection);
366 
367  static int slotId; // 0 is QObject::deleteLater()
368  if (!slotId) {
369  // it's ok to do this: there's no race condition because the store is atomic
370  // and we always set to the same value
371  slotId = QDBusConnectionPrivate::staticMetaObject.indexOfSlot("doDispatch()");
372  }
373 
374  //qDBusDebug() << "Updating dispatcher status" << slotId;
375  if (new_status == DBUS_DISPATCH_DATA_REMAINS)
377  invoke(d, Qt::QueuedConnection);
378 }
double d
Definition: qnumeric_p.h:62
static const QMetaObject staticMetaObject
This variable stores the meta-object for the class.
Definition: qobject.h:128
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
static const char * data(const QByteArray &arr)
int indexOfSlot(const char *slot) const
Finds slot and returns its index; otherwise returns -1.
QMetaMethod method(int index) const
Returns the meta-data for the method with the given index.
#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

◆ shouldWatchService()

static bool shouldWatchService ( const QString service)
static

Definition at line 528 of file qdbusintegrator.cpp.

Referenced by QDBusConnectionPrivate::connectSignal(), and QDBusConnectionPrivate::handleSignal().

529 {
530  return !service.isEmpty() && !service.startsWith(QLatin1Char(':'));
531 }
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
Definition: qstring.cpp:3734
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

Variable Documentation

◆ DIRECT_DELIVERY

QDBusCallDeliveryEvent* const DIRECT_DELIVERY = (QDBusCallDeliveryEvent *)1
static

Definition at line 729 of file qdbusintegrator.cpp.

Referenced by QDBusConnectionPrivate::prepareReply().

◆ isDebugging

bool isDebugging
static

◆ server_slot

dbus_int32_t server_slot = -1
static

Definition at line 1618 of file qdbusintegrator.cpp.