src/dbus/qdbusconnection.cpp
changeset 3 41300fa6a67c
parent 0 1918ee327afb
child 4 3b1da2848fc7
equal deleted inserted replaced
2:56cd8111b7f7 3:41300fa6a67c
   555              can be done only when the signal is received, not at connection time.
   555              can be done only when the signal is received, not at connection time.
   556 */
   556 */
   557 bool QDBusConnection::connect(const QString &service, const QString &path, const QString& interface,
   557 bool QDBusConnection::connect(const QString &service, const QString &path, const QString& interface,
   558                               const QString &name, QObject *receiver, const char *slot)
   558                               const QString &name, QObject *receiver, const char *slot)
   559 {
   559 {
   560     return connect(service, path, interface, name, QString(), receiver, slot);
   560     return connect(service, path, interface, name, QStringList(), QString(), receiver, slot);
   561 }
       
   562 
       
   563 /*!
       
   564     Disconnects the signal specified by the \a service, \a path, \a interface and \a name parameters from
       
   565     the slot \a slot in object \a receiver. The arguments \a service and \a path can be empty,
       
   566     denoting a disconnection from all signals of the (\a interface, \a name) pair, from all remote
       
   567     applications.
       
   568 
       
   569     Returns true if the disconnection was successful.
       
   570 */
       
   571 bool QDBusConnection::disconnect(const QString &service, const QString &path, const QString &interface,
       
   572                                  const QString &name, QObject *receiver, const char *slot)
       
   573 {
       
   574     return disconnect(service, path, interface, name, QString(), receiver, slot);
       
   575 }
   561 }
   576 
   562 
   577 /*!
   563 /*!
   578     \overload
   564     \overload
   579 
   565 
   580     Connects the signal to the slot \a slot in object \a
   566     Connects the signal to the slot \a slot in object \a
   581     receiver. Unlike the other connect() overload, this function
   567     receiver. Unlike the previous connect() overload, this function
   582     allows one to specify the parameter signature to be connected
   568     allows one to specify the parameter signature to be connected
   583     using the \a signature variable. The function will then verify
   569     using the \a signature variable. The function will then verify
   584     that this signature can be delivered to the slot specified by \a
   570     that this signature can be delivered to the slot specified by \a
   585     slot and return false otherwise.
   571     slot and return false otherwise.
   586 
   572 
       
   573     Returns true if the connection was successful.
       
   574 
   587     \note This function verifies that the signal signature matches the
   575     \note This function verifies that the signal signature matches the
   588           slot's parameters, but it does not verify that the actual
   576           slot's parameters, but it does not verify that the actual
   589           signal exists with the given signature in the remote
   577           signal exists with the given signature in the remote
   590           service.
   578           service.
   591 */
   579 */
   592 bool QDBusConnection::connect(const QString &service, const QString &path, const QString& interface,
   580 bool QDBusConnection::connect(const QString &service, const QString &path, const QString& interface,
   593                               const QString &name, const QString &signature,
   581                               const QString &name, const QString &signature,
   594                               QObject *receiver, const char *slot)
   582                               QObject *receiver, const char *slot)
   595 {
   583 {
       
   584     return connect(service, path, interface, name, QStringList(), signature, receiver, slot);
       
   585 }
       
   586 
       
   587 /*!
       
   588     \overload
       
   589     \since 4.6
       
   590 
       
   591     Connects the signal to the slot \a slot in object \a
       
   592     receiver. Unlike the previous connect() overload, this function
       
   593     allows one to specify the parameter signature to be connected
       
   594     using the \a signature variable. The function will then verify
       
   595     that this signature can be delivered to the slot specified by \a
       
   596     slot and return false otherwise.
       
   597 
       
   598     The \a argumentMatch parameter lists the string parameters to be matched,
       
   599     in sequential order. Note that, to match an empty string, you need to
       
   600     pass a QString that is empty but not null (i.e., QString("")). A null
       
   601     QString skips matching at that position.
       
   602 
       
   603     Returns true if the connection was successful.
       
   604 
       
   605     \note This function verifies that the signal signature matches the
       
   606           slot's parameters, but it does not verify that the actual
       
   607           signal exists with the given signature in the remote
       
   608           service.
       
   609 */
       
   610 bool QDBusConnection::connect(const QString &service, const QString &path, const QString& interface,
       
   611                               const QString &name, const QStringList &argumentMatch, const QString &signature,
       
   612                               QObject *receiver, const char *slot)
       
   613 {
       
   614 
   596     if (!receiver || !slot || !d || !d->connection)
   615     if (!receiver || !slot || !d || !d->connection)
   597         return false;
   616         return false;
   598     if (!interface.isEmpty() && !QDBusUtil::isValidInterfaceName(interface))
   617     if (!interface.isEmpty() && !QDBusUtil::isValidInterfaceName(interface))
   599         return false;
   618         return false;
   600     if (interface.isEmpty() && name.isEmpty())
   619     if (interface.isEmpty() && name.isEmpty())
   601         return false;
   620         return false;
   602 
   621 
   603     // check the slot
       
   604     QDBusConnectionPrivate::SignalHook hook;
       
   605     QString key;
       
   606     QString name2 = name;
       
   607     if (name2.isNull())
       
   608         name2.detach();
       
   609 
       
   610     QString owner = d->getNameOwner(service); // we don't care if the owner is empty
   622     QString owner = d->getNameOwner(service); // we don't care if the owner is empty
   611     hook.signature = signature;               // it might get started later
   623                                               // it might get started later
   612     if (!d->prepareHook(hook, key, service, owner, path, interface, name, receiver, slot, 0, false))
       
   613         return false;           // don't connect
       
   614 
       
   615     // avoid duplicating:
       
   616     QDBusWriteLocker locker(ConnectAction, d);
   624     QDBusWriteLocker locker(ConnectAction, d);
   617     QDBusConnectionPrivate::SignalHookHash::ConstIterator it = d->signalHooks.find(key);
   625     return d->connectSignal(service, owner, path, interface, name, argumentMatch, signature, receiver, slot);
   618     QDBusConnectionPrivate::SignalHookHash::ConstIterator end = d->signalHooks.constEnd();
   626 }
   619     for ( ; it != end && it.key() == key; ++it) {
   627 
   620         const QDBusConnectionPrivate::SignalHook &entry = it.value();
   628 /*!
   621         if (entry.service == hook.service &&
   629     Disconnects the signal specified by the \a service, \a path, \a interface
   622             entry.owner == hook.owner &&
   630     and \a name parameters from the slot \a slot in object \a receiver. The
   623             entry.path == hook.path &&
   631     arguments must be the same as passed to the connect() function.
   624             entry.signature == hook.signature &&
   632 
   625             entry.obj == hook.obj &&
   633     Returns true if the disconnection was successful.
   626             entry.midx == hook.midx) {
   634 */
   627             // no need to compare the parameters if it's the same slot
   635 bool QDBusConnection::disconnect(const QString &service, const QString &path, const QString &interface,
   628             return true;        // already there
   636                                  const QString &name, QObject *receiver, const char *slot)
   629         }
   637 {
   630     }
   638     return disconnect(service, path, interface, name, QStringList(), QString(), receiver, slot);
   631 
       
   632     d->connectSignal(key, hook);
       
   633     return true;
       
   634 }
   639 }
   635 
   640 
   636 /*!
   641 /*!
   637     \overload
   642     \overload
   638 
   643 
   639     Disconnects the signal from the slot \a slot in object \a
   644     Disconnects the signal specified by the \a service, \a path, \a
   640     receiver. Unlike the other disconnect() overload, this function
   645     interface, \a name, and \a signature parameters from the slot \a slot in
   641     allows one to specify the parameter signature to be disconnected
   646     object \a receiver. The arguments must be the same as passed to the
   642     using the \a signature variable. The function will then verify
   647     connect() function.
   643     that this signature is connected to the slot specified by \a slot
   648 
   644     and return false otherwise.
   649     Returns true if the disconnection was successful.
   645 */
   650 */
   646 bool QDBusConnection::disconnect(const QString &service, const QString &path, const QString& interface,
   651 bool QDBusConnection::disconnect(const QString &service, const QString &path, const QString& interface,
   647                                  const QString &name, const QString &signature,
   652                                  const QString &name, const QString &signature,
       
   653                                  QObject *receiver, const char *slot)
       
   654 {
       
   655     return disconnect(service, path, interface, name, QStringList(), signature, receiver, slot);
       
   656 }
       
   657 
       
   658 /*!
       
   659     \overload
       
   660     \since 4.6
       
   661 
       
   662     Disconnects the signal specified by the \a service, \a path, \a
       
   663     interface, \a name, \a argumentMatch, and \a signature parameters from
       
   664     the slot \a slot in object \a receiver. The arguments must be the same as
       
   665     passed to the connect() function.
       
   666 
       
   667     Returns true if the disconnection was successful.
       
   668 */
       
   669 bool QDBusConnection::disconnect(const QString &service, const QString &path, const QString& interface,
       
   670                                  const QString &name, const QStringList &argumentMatch, const QString &signature,
   648                                  QObject *receiver, const char *slot)
   671                                  QObject *receiver, const char *slot)
   649 {
   672 {
   650     if (!receiver || !slot || !d || !d->connection)
   673     if (!receiver || !slot || !d || !d->connection)
   651         return false;
   674         return false;
   652     if (!interface.isEmpty() && !QDBusUtil::isValidInterfaceName(interface))
   675     if (!interface.isEmpty() && !QDBusUtil::isValidInterfaceName(interface))
   653         return false;
   676         return false;
   654     if (interface.isEmpty() && name.isEmpty())
   677     if (interface.isEmpty() && name.isEmpty())
   655         return false;
   678         return false;
   656 
   679 
   657     // check the slot
       
   658     QDBusConnectionPrivate::SignalHook hook;
       
   659     QString key;
       
   660     QString name2 = name;
       
   661     if (name2.isNull())
       
   662         name2.detach();
       
   663 
       
   664     QString owner = d->getNameOwner(service); // we don't care of owner is empty
       
   665     hook.signature = signature;
       
   666     if (!d->prepareHook(hook, key, service, owner, path, interface, name, receiver, slot, 0, false))
       
   667         return false;           // don't disconnect
       
   668 
       
   669     // avoid duplicating:
       
   670     QDBusWriteLocker locker(DisconnectAction, d);
   680     QDBusWriteLocker locker(DisconnectAction, d);
   671     QDBusConnectionPrivate::SignalHookHash::Iterator it = d->signalHooks.find(key);
   681     return d->disconnectSignal(service, path, interface, name, argumentMatch, signature, receiver, slot);
   672     QDBusConnectionPrivate::SignalHookHash::Iterator end = d->signalHooks.end();
       
   673     for ( ; it != end && it.key() == key; ++it) {
       
   674         const QDBusConnectionPrivate::SignalHook &entry = it.value();
       
   675         if (entry.service == hook.service &&
       
   676             entry.owner == hook.owner &&
       
   677             entry.path == hook.path &&
       
   678             entry.signature == hook.signature &&
       
   679             entry.obj == hook.obj &&
       
   680             entry.midx == hook.midx) {
       
   681             // no need to compare the parameters if it's the same slot
       
   682             d->disconnectSignal(it);
       
   683             return true;        // it was there
       
   684         }
       
   685     }
       
   686 
       
   687     // the slot was not found
       
   688     return false;
       
   689 }
   682 }
   690 
   683 
   691 /*!
   684 /*!
   692     Registers the object \a object at path \a path and returns true if
   685     Registers the object \a object at path \a path and returns true if
   693     the registration was successful. The \a options parameter
   686     the registration was successful. The \a options parameter
  1010 void QDBusConnectionPrivate::setBusService(const QDBusConnection &connection)
  1003 void QDBusConnectionPrivate::setBusService(const QDBusConnection &connection)
  1011 {
  1004 {
  1012     busService = new QDBusConnectionInterface(connection, this);
  1005     busService = new QDBusConnectionInterface(connection, this);
  1013     ref.deref(); // busService has increased the refcounting to us
  1006     ref.deref(); // busService has increased the refcounting to us
  1014                  // avoid cyclic refcounting
  1007                  // avoid cyclic refcounting
  1015 //    if (mode != PeerMode)
       
  1016     QObject::connect(busService, SIGNAL(serviceOwnerChanged(QString,QString,QString)),
       
  1017                      this, SIGNAL(serviceOwnerChanged(QString,QString,QString)));
       
  1018 
  1008 
  1019     QObject::connect(this, SIGNAL(callWithCallbackFailed(QDBusError,QDBusMessage)),
  1009     QObject::connect(this, SIGNAL(callWithCallbackFailed(QDBusError,QDBusMessage)),
  1020                      busService, SIGNAL(callWithCallbackFailed(QDBusError,QDBusMessage)),
  1010                      busService, SIGNAL(callWithCallbackFailed(QDBusError,QDBusMessage)),
  1021                      Qt::QueuedConnection);
  1011                      Qt::QueuedConnection);
  1022 
       
  1023 }
  1012 }
  1024 
  1013 
  1025 /*!
  1014 /*!
  1026     \namespace QDBus
  1015     \namespace QDBus
  1027     \inmodule QtDBus
  1016     \inmodule QtDBus