Qt 4.8
qdbusconnection.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtDBus module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include <qdebug.h>
43 #include <qcoreapplication.h>
44 #include <qstringlist.h>
45 #include <qthread.h>
46 
47 #include "qdbusconnection.h"
49 #include "qdbuserror.h"
50 #include "qdbusmessage.h"
51 #include "qdbusmessage_p.h"
52 #include "qdbusconnection_p.h"
53 #include "qdbusinterface_p.h"
54 #include "qdbusutil_p.h"
56 #include "qdbuspendingcall_p.h"
57 
58 #include "qdbusthreaddebug_p.h"
59 
60 #ifndef QT_NO_DBUS
61 
63 
65 
67 {
68  QMutexLocker locker(&senderMutex);
69  return connection(senderName);
70 }
71 
73 {
74  QMutexLocker locker(&senderMutex);
75  senderName = (s ? s->name : QString());
76 }
77 
79 {
80  return connectionHash.value(name, 0);
81 }
82 
84 {
86  d = connectionHash.take(name);
87  if (d && !d->ref.deref())
88  d->deleteYourself();
89 
90  // Static objects may be keeping the connection open.
91  // However, it is harmless to have outstanding references to a connection that is
92  // closing as long as those references will be soon dropped without being used.
93 
94  // ### Output a warning if connections are being used after they have been removed.
95 }
96 
98 {
100  it != connectionHash.constEnd(); ++it) {
101  QDBusConnectionPrivate *d = it.value();
102  if (!d->ref.deref())
103  d->deleteYourself();
104  else
105  d->closeConnection();
106  }
108 }
109 
111 {
112  return _q_manager();
113 }
114 
117 {
118 }
119 
121 {
122  connectionHash[name] = c;
123  c->name = name;
124 }
125 
290 {
291  if (name.isEmpty()) {
292  d = 0;
293  } else {
294  QMutexLocker locker(&_q_manager()->mutex);
295  d = _q_manager()->connection(name);
296  if (d)
297  d->ref.ref();
298  }
299 }
300 
305 {
306  d = other.d;
307  if (d)
308  d->ref.ref();
309 }
310 
319 {
320  d = dd;
321  if (d)
322  d->ref.ref();
323 }
324 
330 {
331  if (d && !d->ref.deref())
332  d->deleteYourself();
333 }
334 
343 {
344  if (other.d)
345  other.d->ref.ref();
346  if (d && !d->ref.deref())
347  d->deleteYourself();
348  d = other.d;
349  return *this;
350 }
351 
358 {
359 // Q_ASSERT_X(QCoreApplication::instance(), "QDBusConnection::addConnection",
360 // "Cannot create connection without a Q[Core]Application instance");
361  if (!qdbus_loadLibDBus()) {
363  return QDBusConnection(d);
364  }
365 
366  QMutexLocker locker(&_q_manager()->mutex);
367 
368  QDBusConnectionPrivate *d = _q_manager()->connection(name);
369  if (d || name.isEmpty())
370  return QDBusConnection(d);
371 
372  d = new QDBusConnectionPrivate;
373  DBusConnection *c = 0;
375  switch (type) {
376  case SystemBus:
377  c = q_dbus_bus_get_private(DBUS_BUS_SYSTEM, error);
378  break;
379  case SessionBus:
380  c = q_dbus_bus_get_private(DBUS_BUS_SESSION, error);
381  break;
382  case ActivationBus:
383  c = q_dbus_bus_get_private(DBUS_BUS_STARTER, error);
384  break;
385  }
386  d->setConnection(c, error); //setConnection does the error handling for us
387 
388  _q_manager()->setConnection(name, d);
389 
390  QDBusConnection retval(d);
391 
392  // create the bus service
393  // will lock in QDBusConnectionPrivate::connectRelay()
394  d->setBusService(retval);
395 
396  return retval;
397 }
398 
404  const QString &name)
405 {
406 // Q_ASSERT_X(QCoreApplication::instance(), "QDBusConnection::addConnection",
407 // "Cannot create connection without a Q[Core]Application instance");
408  if (!qdbus_loadLibDBus()) {
410  return QDBusConnection(d);
411  }
412 
413  QMutexLocker locker(&_q_manager()->mutex);
414 
415  QDBusConnectionPrivate *d = _q_manager()->connection(name);
416  if (d || name.isEmpty())
417  return QDBusConnection(d);
418 
419  d = new QDBusConnectionPrivate;
420  // setConnection does the error handling for us
422  DBusConnection *c = q_dbus_connection_open_private(address.toUtf8().constData(), error);
423  if (c) {
424  if (!q_dbus_bus_register(c, error)) {
425  q_dbus_connection_unref(c);
426  c = 0;
427  }
428  }
429  d->setConnection(c, error);
430  _q_manager()->setConnection(name, d);
431 
432  QDBusConnection retval(d);
433 
434  // create the bus service
435  // will lock in QDBusConnectionPrivate::connectRelay()
436  d->setBusService(retval);
437 
438  return retval;
439 }
450  const QString &name)
451 {
452 // Q_ASSERT_X(QCoreApplication::instance(), "QDBusConnection::addConnection",
453 // "Cannot create connection without a Q[Core]Application instance");
454  if (!qdbus_loadLibDBus()) {
456  return QDBusConnection(d);
457  }
458 
459  QMutexLocker locker(&_q_manager()->mutex);
460 
461  QDBusConnectionPrivate *d = _q_manager()->connection(name);
462  if (d || name.isEmpty())
463  return QDBusConnection(d);
464 
465  d = new QDBusConnectionPrivate;
466  // setPeer does the error handling for us
468  DBusConnection *c = q_dbus_connection_open_private(address.toUtf8().constData(), error);
469 
470  d->setPeer(c, error);
471  _q_manager()->setConnection(name, d);
472 
473  QDBusConnection retval(d);
474 
475  return retval;
476 }
477 
487 {
488  if (_q_manager()) {
489  QMutexLocker locker(&_q_manager()->mutex);
490  QDBusConnectionPrivate *d = _q_manager()->connection(name);
492  return;
493  _q_manager()->removeConnection(name);
494  }
495 }
496 
511 {
512  if (_q_manager()) {
513  QMutexLocker locker(&_q_manager()->mutex);
514  QDBusConnectionPrivate *d = _q_manager()->connection(name);
515  if (d && d->mode != QDBusConnectionPrivate::PeerMode)
516  return;
517  _q_manager()->removeConnection(name);
518  }
519 }
520 
528 bool QDBusConnection::send(const QDBusMessage &message) const
529 {
530  if (!d || !d->connection) {
532  QLatin1String("Not connected to D-BUS server"));
533  if (d)
534  d->lastError = err;
535  return false;
536  }
537  return d->send(message) != 0;
538 }
539 
560  const char *returnMethod, const char *errorMethod,
561  int timeout) const
562 {
563  if (!d || !d->connection) {
565  QLatin1String("Not connected to D-BUS server"));
566  if (d)
567  d->lastError = err;
568  return false;
569  }
570  return d->sendWithReplyAsync(message, receiver, returnMethod, errorMethod, timeout) != 0;
571 }
572 
594  const char *returnMethod, int timeout) const
595 {
596  return callWithCallback(message, receiver, returnMethod, 0, timeout);
597 }
598 
622 QDBusMessage QDBusConnection::call(const QDBusMessage &message, QDBus::CallMode mode, int timeout) const
623 {
624  if (!d || !d->connection) {
626  QLatin1String("Not connected to D-Bus server"));
627  if (d)
628  d->lastError = err;
629 
630  return QDBusMessage::createError(err);
631  }
632 
633  if (mode != QDBus::NoBlock)
634  return d->sendWithReply(message, mode, timeout);
635 
636  d->send(message);
637  QDBusMessage retval;
638  retval << QVariant(); // add one argument (to avoid .at(0) problems)
639  return retval;
640 }
641 
662 QDBusPendingCall QDBusConnection::asyncCall(const QDBusMessage &message, int timeout) const
663 {
664  if (!d || !d->connection) {
665  return QDBusPendingCall(0); // null pointer -> disconnected
666  }
667 
668  QDBusPendingCallPrivate *priv = d->sendWithReplyAsync(message, 0, 0, 0, timeout);
669  return QDBusPendingCall(priv);
670 }
671 
683 bool QDBusConnection::connect(const QString &service, const QString &path, const QString& interface,
684  const QString &name, QObject *receiver, const char *slot)
685 {
686  return connect(service, path, interface, name, QStringList(), QString(), receiver, slot);
687 }
688 
709 bool QDBusConnection::connect(const QString &service, const QString &path, const QString& interface,
710  const QString &name, const QString &signature,
711  QObject *receiver, const char *slot)
712 {
713  return connect(service, path, interface, name, QStringList(), signature, receiver, slot);
714 }
715 
742 bool QDBusConnection::connect(const QString &service, const QString &path, const QString& interface,
743  const QString &name, const QStringList &argumentMatch, const QString &signature,
744  QObject *receiver, const char *slot)
745 {
746 
747  if (!receiver || !slot || !d || !d->connection)
748  return false;
749  if (interface.isEmpty() && name.isEmpty())
750  return false;
751  if (!interface.isEmpty() && !QDBusUtil::isValidInterfaceName(interface)) {
752 #ifndef QT_NO_DEBUG
753  qWarning("QDBusConnection::connect: interface name '%s' is not valid", interface.toLatin1().constData());
754 #endif
755  return false;
756  }
757  if (!service.isEmpty() && !QDBusUtil::isValidBusName(service)) {
758 #ifndef QT_NO_DEBUG
759  qWarning("QDBusConnection::connect: service name '%s' is not valid", service.toLatin1().constData());
760 #endif
761  return false;
762  }
763  if (!path.isEmpty() && !QDBusUtil::isValidObjectPath(path)) {
764 #ifndef QT_NO_DEBUG
765  qWarning("QDBusConnection::connect: object path '%s' is not valid", path.toLatin1().constData());
766 #endif
767  return false;
768  }
769 
771  return d->connectSignal(service, path, interface, name, argumentMatch, signature, receiver, slot);
772 }
773 
781 bool QDBusConnection::disconnect(const QString &service, const QString &path, const QString &interface,
782  const QString &name, QObject *receiver, const char *slot)
783 {
784  return disconnect(service, path, interface, name, QStringList(), QString(), receiver, slot);
785 }
786 
800 bool QDBusConnection::disconnect(const QString &service, const QString &path, const QString& interface,
801  const QString &name, const QString &signature,
802  QObject *receiver, const char *slot)
803 {
804  return disconnect(service, path, interface, name, QStringList(), signature, receiver, slot);
805 }
806 
821 bool QDBusConnection::disconnect(const QString &service, const QString &path, const QString& interface,
822  const QString &name, const QStringList &argumentMatch, const QString &signature,
823  QObject *receiver, const char *slot)
824 {
825  if (!receiver || !slot || !d || !d->connection)
826  return false;
827  if (!interface.isEmpty() && !QDBusUtil::isValidInterfaceName(interface))
828  return false;
829  if (interface.isEmpty() && name.isEmpty())
830  return false;
831 
833  return d->disconnectSignal(service, path, interface, name, argumentMatch, signature, receiver, slot);
834 }
835 
848 bool QDBusConnection::registerObject(const QString &path, QObject *object, RegisterOptions options)
849 {
850  Q_ASSERT_X(QDBusUtil::isValidObjectPath(path), "QDBusConnection::registerObject",
851  "Invalid object path given");
852  if (!d || !d->connection || !object || !options || !QDBusUtil::isValidObjectPath(path))
853  return false;
854 
855  QStringList pathComponents = path.split(QLatin1Char('/'));
856  if (pathComponents.last().isEmpty())
857  pathComponents.removeLast();
859 
860  // lower-bound search for where this object should enter in the tree
861  QDBusConnectionPrivate::ObjectTreeNode *node = &d->rootNode;
862  int i = 1;
863  while (node) {
864  if (pathComponents.count() == i) {
865  // this node exists
866  // consider it free if there's no object here and the user is not trying to
867  // replace the object sub-tree
868  if (node->obj)
869  return false;
870 
872  // technically the check for children needs to go even deeper
873  if (options & SubPath) {
874  foreach (const QDBusConnectionPrivate::ObjectTreeNode &child, node->children) {
875  if (child.obj)
876  return false;
877  }
878  }
879  } else {
880  if ((options & ExportChildObjects && !node->children.isEmpty()))
881  return false;
882  }
883  // we can add the object here
884  node->obj = object;
885  node->flags = options;
886 
887  d->registerObject(node);
888  //qDebug("REGISTERED FOR %s", path.toLocal8Bit().constData());
889  return true;
890  }
891 
892  // if a virtual object occupies this path, return false
893  if (node->obj && (node->flags & QDBusConnectionPrivate::VirtualObject) && (node->flags & QDBusConnection::SubPath)) {
894  qDebug("Cannot register object at %s because QDBusVirtualObject handles all sub-paths.",
895  qPrintable(path));
896  return false;
897  }
898 
899  // find the position where we'd insert the node
901  qLowerBound(node->children.begin(), node->children.end(), pathComponents.at(i));
902  if (it != node->children.end() && it->name == pathComponents.at(i)) {
903  // match: this node exists
904  node = it;
905 
906  // are we allowed to go deeper?
907  if (node->flags & ExportChildObjects) {
908  // we're not
909  qDebug("Cannot register object at %s because %s exports its own child objects",
910  qPrintable(path), qPrintable(pathComponents.at(i)));
911  return false;
912  }
913  } else {
914  // add entry
915  node = node->children.insert(it, pathComponents.at(i));
916  }
917 
918  // iterate
919  ++i;
920  }
921 
922  Q_ASSERT_X(false, "QDBusConnection::registerObject", "The impossible happened");
923  return false;
924 }
925 
939 {
940  int opts = options | QDBusConnectionPrivate::VirtualObject;
941  return registerObject(path, (QObject*) treeNode, (RegisterOptions) opts);
942 }
943 
951 {
952  if (!d || !d->connection || !QDBusUtil::isValidObjectPath(path))
953  return;
954 
955  QStringList pathComponents = path.split(QLatin1Char('/'));
957  QDBusConnectionPrivate::ObjectTreeNode *node = &d->rootNode;
958  int i = 1;
959 
960  // find the object
961  while (node) {
962  if (pathComponents.count() == i || !path.compare(QLatin1String("/"))) {
963  // found it
964  node->obj = 0;
965  node->flags = 0;
966 
967  if (mode == UnregisterTree) {
968  // clear the sub-tree as well
969  node->children.clear(); // can't disconnect the objects because we really don't know if they can
970  // be found somewhere else in the path too
971  }
972 
973  return;
974  }
975 
977  qLowerBound(node->children.begin(), node->children.end(), pathComponents.at(i));
978  if (it == node->children.end() || it->name != pathComponents.at(i))
979  break; // node not found
980 
981  node = it;
982  ++i;
983  }
984 }
985 
991 {
992  Q_ASSERT_X(QDBusUtil::isValidObjectPath(path), "QDBusConnection::registeredObject",
993  "Invalid object path given");
994  if (!d || !d->connection || !QDBusUtil::isValidObjectPath(path))
995  return 0;
996 
997  QStringList pathComponents = path.split(QLatin1Char('/'));
998  if (pathComponents.last().isEmpty())
999  pathComponents.removeLast();
1000 
1001  // lower-bound search for where this object should enter in the tree
1003  const QDBusConnectionPrivate::ObjectTreeNode *node = &d->rootNode;
1004 
1005  int i = 1;
1006  while (node) {
1007  if (pathComponents.count() == i)
1008  return node->obj;
1010  return node->obj;
1011 
1013  qLowerBound(node->children.constBegin(), node->children.constEnd(), pathComponents.at(i));
1014  if (it == node->children.constEnd() || it->name != pathComponents.at(i))
1015  break; // node not found
1016 
1017  node = it;
1018  ++i;
1019  }
1020  return 0;
1021 }
1022 
1023 
1024 
1030 {
1031  if (!d)
1032  return 0;
1033  return d->busService;
1034 }
1035 
1047 {
1048  return d ? d->connection : 0;
1049 }
1050 
1055 {
1056  return d && d->connection && q_dbus_connection_get_is_connected(d->connection);
1057 }
1058 
1069 {
1070  return d ? d->lastError : QDBusError();
1071 }
1072 
1084 {
1085  return d ? d->baseService : QString();
1086 }
1087 
1109 {
1110  return d ? d->name : QString();
1111 }
1112 
1123 QDBusConnection::ConnectionCapabilities QDBusConnection::connectionCapabilities() const
1124 {
1125  return d ? d->capabilities : ConnectionCapabilities(0);
1126 }
1127 
1136 {
1137  if (interface() && interface()->registerService(serviceName)) {
1138  if (d) d->registerService(serviceName);
1139  return true;
1140  }
1141  return false;
1142 }
1143 
1152 {
1153  if (interface()->unregisterService(serviceName)) {
1154  if (d) d->unregisterService(serviceName);
1155  return true;
1156  }
1157  return false;
1158 }
1159 
1160 static const char _q_sessionBusName[] = "qt_default_session_bus";
1161 static const char _q_systemBusName[] = "qt_default_system_bus";
1162 
1164 {
1165  const char *ownName;
1166 public:
1168  : QDBusConnection(connectToBus(type, QString::fromLatin1(name))), ownName(name)
1169  {
1170  // make sure this connection is running on the main thread
1172  if (!instance) {
1173  qWarning("QDBusConnection: %s D-Bus connection created before QCoreApplication. Application may misbehave.",
1174  type == SessionBus ? "session" : type == SystemBus ? "system" : "generic");
1175  } else if (QDBusConnectionPrivate::d(*this)) {
1176  QDBusConnectionPrivate::d(*this)->moveToThread(instance->thread());
1177  }
1178  }
1179 
1181  { disconnectFromBus(QString::fromLatin1(ownName)); }
1182 };
1183 
1187  (QDBusConnection::SystemBus, _q_systemBusName))
1188 
1190 {
1191  return *_q_sessionBus();
1192 }
1193 
1195 {
1196  return *_q_systemBus();
1197 }
1198 
1214 {
1215  return QDBusConnection(_q_manager()->sender());
1216 }
1217 
1222 {
1223  _q_manager()->setSender(s);
1224 }
1225 
1230 {
1231  busService = new QDBusConnectionInterface(connection, this);
1232  ref.deref(); // busService has increased the refcounting to us
1233  // avoid cyclic refcounting
1234 
1235  QObject::connect(this, SIGNAL(callWithCallbackFailed(QDBusError,QDBusMessage)),
1236  busService, SIGNAL(callWithCallbackFailed(QDBusError,QDBusMessage)),
1238 }
1239 
1257 {
1258  char *dbus_machine_id = q_dbus_get_local_machine_id();
1259  QByteArray result = dbus_machine_id;
1260  q_dbus_free(dbus_machine_id);
1261  return result;
1262 }
1263 
1298 
1299 #endif // QT_NO_DBUS
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
UnregisterMode
The mode for unregistering an object path:
QHash< QString, QDBusConnectionPrivate * > connectionHash
double d
Definition: qnumeric_p.h:62
static QDBusMessage createError(const QString &name, const QString &msg)
Constructs a new DBus message representing an error, with the given name and msg. ...
The QDBusConnectionInterface class provides access to the D-Bus bus daemon service.
The QHash::const_iterator class provides an STL-style const iterator for QHash and QMultiHash...
Definition: qhash.h:395
int type
Definition: qmetatype.cpp:239
QDBusConnectionInterface * interface() const
Returns a QDBusConnectionInterface object that represents the D-Bus server interface on this connecti...
unsigned char c[8]
Definition: qnumeric_p.h:62
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
void removeConnection(const QString &name)
bool isValidObjectPath(const QString &path)
Returns true if path is valid object path.
Definition: qdbusutil.cpp:515
void clear()
Removes all items from the hash.
Definition: qhash.h:574
bool registerVirtualObject(const QString &path, QDBusVirtualObject *object, VirtualObjectRegisterOption options=SingleNode)
Registers a QDBusTreeNode for a path.
bool send(const QDBusMessage &message) const
Sends the message over this connection, without waiting for a reply.
#define it(className, varName)
bool registerObject(const QString &path, QObject *object, RegisterOptions options=ExportAdaptors)
Registers the object object at path path and returns true if the registration was successful...
CallMode
This enum describes the various ways of placing a function call.
QDBusPendingCall asyncCall(const QDBusMessage &message, int timeout=-1) const
Sends the message over this connection and returns immediately.
QByteArray toUtf8() const Q_REQUIRED_RESULT
Returns a UTF-8 representation of the string as a QByteArray.
Definition: qstring.cpp:4074
QDBusConnection & operator=(const QDBusConnection &other)
Creates a copy of the connection other in this object.
#define error(msg)
static QDBusConnectionPrivate * d(const QDBusConnection &q)
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
static QDBusConnection connectToPeer(const QString &address, const QString &name)
Opens a peer-to-peer connection on address address and associate with it the connection name name...
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
The QDBusError class represents an error received from the D-Bus bus or from remote applications foun...
Definition: qdbuserror.h:60
void unregisterObject(const QString &path, UnregisterMode mode=UnregisterNode)
Unregisters an object that was registered with the registerObject() at the object path given by path ...
The QDBusPendingCall class refers to one pending asynchronous call.
void setSender(const QDBusConnectionPrivate *s)
QString baseService() const
Returns the unique connection name for this connection, if this QDBusConnection object is connected...
QDBusMessage call(const QDBusMessage &message, QDBus::CallMode mode=QDBus::Block, int timeout=-1) const
Sends the message over this connection and blocks, waiting for a reply, for at most timeout milliseco...
void removeLast()
Removes the last item in the list.
Definition: qlist.h:287
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
static QDBusConnection systemBus()
Returns a QDBusConnection object opened with the system bus.
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
bool ref()
Atomically increments the value of this QAtomicInt.
static QDBusConnection sender()
Returns the connection that sent the signal, if called in a slot activated by QDBus; otherwise it ret...
The QString class provides a Unicode character string.
Definition: qstring.h:83
T take(const Key &key)
Removes the item with the key from the hash and returns the value associated with it...
Definition: qhash.h:807
QDBusDefaultConnection(BusType type, const char *name)
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
static void setSender(const QDBusConnectionPrivate *s)
ConnectionCapabilities connectionCapabilities() const
Returns the capabilities of this connection as negotiated with the bus server or peer.
bool unregisterService(const QString &serviceName)
Unregisters the service serviceName that was previously registered with registerService() and returns...
bool isValidInterfaceName(const QString &ifaceName)
Returns true if this is ifaceName is a valid interface name.
Definition: qdbusutil.cpp:367
iterator Iterator
Qt-style synonym for QVector::iterator.
Definition: qvector.h:278
QString name() const
Returns the connection name for this connection, as given as the name parameter to connectToBus()...
const T value(const Key &key) const
Returns the value associated with the key.
Definition: qhash.h:606
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the vector...
Definition: qvector.h:250
Q_CORE_EXPORT void qDebug(const char *,...)
static QDBusConnectionManager * instance()
#define SIGNAL(a)
Definition: qobjectdefs.h:227
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the vector.
Definition: qvector.h:249
void * internalPointer() const
QDBusConnection(const QString &name)
Creates a QDBusConnection object attached to the connection with name name.
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
static void disconnectFromBus(const QString &name)
Closes the bus connection of name name.
bool registerService(const QString &serviceName)
Attempts to register the serviceName on the D-Bus server and returns true if the registration succeed...
void clear()
Removes all the elements from the vector and releases the memory used by the vector.
Definition: qvector.h:347
static const char _q_systemBusName[]
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 isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
const char * name
#define Q_GLOBAL_STATIC(TYPE, NAME)
Declares a global static variable with the given type and name.
Definition: qglobal.h:1968
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
bool deref()
Atomically decrements the value of this QAtomicInt.
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
QDBusConnectionPrivate * sender() const
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
void setConnection(const QString &name, QDBusConnectionPrivate *c)
BusType
Specifies the type of the bus connection.
QByteArray toLatin1() const Q_REQUIRED_RESULT
Returns a Latin-1 representation of the string as a QByteArray.
Definition: qstring.cpp:3993
QDBusError lastError() const
Returns the last error that happened in this connection.
The QDBusVirtualObject class is used to handle several DBus paths with one class. ...
QDBusConnectionPrivate * d
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the hash.
Definition: qhash.h:466
void insert(int i, const T &t)
Inserts value at index position i in the vector.
Definition: qvector.h:362
Q_OUTOFLINE_TEMPLATE RandomAccessIterator qLowerBound(RandomAccessIterator begin, RandomAccessIterator end, const T &value)
Definition: qalgorithms.h:227
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
bool connect(const QString &service, const QString &path, const QString &interface, const QString &name, QObject *receiver, const char *slot)
Connects the signal specified by the service, path, interface and name parameters to the slot slot in...
The QCoreApplication class provides an event loop for console Qt applications.
static QByteArray localMachineId()
Returns the local machine ID as known to the D-Bus system.
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
int compare(const QString &s) const
Definition: qstring.cpp:5037
iterator begin()
Returns an STL-style iterator pointing to the first item in the vector.
Definition: qvector.h:247
static QCoreApplication * instance()
Returns a pointer to the application&#39;s QCoreApplication (or QApplication) instance.
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
Q_GLOBAL_STATIC_WITH_ARGS(QDBusDefaultConnection, _q_sessionBus,(QDBusConnection::SessionBus, _q_sessionBusName)) Q_GLOBAL_STATIC_WITH_ARGS(QDBusDefaultConnection
void setPeer(DBusConnection *connection, const QDBusErrorInternal &error)
T & last()
Returns a reference to the last item in the list.
Definition: qlist.h:284
static const QMetaObjectPrivate * priv(const uint *data)
static QReadWriteLock lock
Definition: proxyconf.cpp:399
static QDBusConnection connectToBus(BusType type, const QString &name)
Opens a connection of type type to one of the known busses and associate with it the connection name ...
#define Q_DBUS_EXPORT
Definition: qglobal.h:1463
if(void) toggleToolbarShown
QDBusConnectionPrivate * connection(const QString &name) const
The QDBusMessage class represents one message sent or received over the D-Bus bus.
Definition: qdbusmessage.h:59
bool qdbus_loadLibDBus()
QObject * objectRegisteredAt(const QString &path) const
Return the object that was registered with the registerObject() at the object path given by path...
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
QStringList split(const QString &sep, SplitBehavior behavior=KeepEmptyParts, Qt::CaseSensitivity cs=Qt::CaseSensitive) const Q_REQUIRED_RESULT
Splits the string into substrings wherever sep occurs, and returns the list of those strings...
Definition: qstring.cpp:6526
VirtualObjectRegisterOption
Specifies the options for registering virtual objects with the connection.
QThread * thread() const
Returns the thread in which the object lives.
Definition: qobject.cpp:1419
Q_DBUS_EXPORT void qDBusBindToApplication()
bool isConnected() const
Returns true if this QDBusConnection object is connected.
~QDBusConnection()
Disposes of this object.
bool disconnect(const QString &service, const QString &path, const QString &interface, const QString &name, QObject *receiver, const char *slot)
Disconnects the signal specified by the service, path, interface and name parameters from the slot sl...
#define qPrintable(string)
Definition: qglobal.h:1750
void setBusService(const QDBusConnection &connection)
_q_systemBus
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
void setConnection(DBusConnection *connection, const QDBusErrorInternal &error)
static const char _q_sessionBusName[]
bool callWithCallback(const QDBusMessage &message, QObject *receiver, const char *returnMethod, const char *errorMethod, int timeout=-1) const
Sends the message over this connection and returns immediately.
static void disconnectFromPeer(const QString &name)
Closes the peer connection of name name.
bool isValidBusName(const QString &busName)
Returns true if busName is a valid bus name.
Definition: qdbusutil.cpp:435