Changeset 846 for trunk/src/dbus/qdbusintegrator.cpp
- Timestamp:
- May 5, 2011, 5:36:53 AM (14 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:mergeinfo changed
/branches/vendor/nokia/qt/4.7.2 (added) merged: 845 /branches/vendor/nokia/qt/current merged: 844 /branches/vendor/nokia/qt/4.6.3 removed
- Property svn:mergeinfo changed
-
trunk/src/dbus/qdbusintegrator.cpp
r769 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation (qt-info@nokia.com) … … 65 65 #include "qdbusthreaddebug_p.h" 66 66 67 #ifndef QT_NO_DBUS 68 67 69 QT_BEGIN_NAMESPACE 68 70 69 71 static bool isDebugging; 70 72 #define qDBusDebug if (!::isDebugging); else qDebug 73 74 Q_GLOBAL_STATIC_WITH_ARGS(const QString, orgFreedesktopDBusString, (QLatin1String(DBUS_SERVICE_DBUS))) 75 76 static inline QString dbusServiceString() 77 { return *orgFreedesktopDBusString(); } 78 static inline QString dbusInterfaceString() 79 { 80 // it's the same string, but just be sure 81 Q_ASSERT(*orgFreedesktopDBusString() == QLatin1String(DBUS_INTERFACE_DBUS)); 82 return *orgFreedesktopDBusString(); 83 } 71 84 72 85 static inline QDebug operator<<(QDebug dbg, const QThread *th) … … 507 520 } 508 521 509 extern Q DBUS_EXPORT void qDBusAddSpyHook(QDBusSpyHook);522 extern Q_DBUS_EXPORT void qDBusAddSpyHook(QDBusSpyHook); 510 523 void qDBusAddSpyHook(QDBusSpyHook hook) 511 524 { … … 539 552 (*(*list)[i])(amsg); 540 553 } 554 555 if (!ref) 556 return false; 541 557 542 558 switch (amsg.type()) { … … 550 566 case QDBusMessage::ReplyMessage: 551 567 case QDBusMessage::ErrorMessage: 568 case QDBusMessage::InvalidMessage: 552 569 return false; // we don't handle those here 553 case QDBusMessage::InvalidMessage:554 Q_ASSERT_X(false, "QDBusConnection", "Invalid message found when processing");555 break;556 570 } 557 571 … … 617 631 618 632 // check type: 619 if (mm.methodType() != QMetaMethod::Slot )633 if (mm.methodType() != QMetaMethod::Slot && mm.methodType() != QMetaMethod::Method) 620 634 continue; 621 635 … … 681 695 continue; 682 696 683 if (isScriptable && (flags & QDBusConnection::ExportScriptableSlots) == 0) 684 continue; // not exported 685 if (!isScriptable && (flags & QDBusConnection::ExportNonScriptableSlots) == 0) 686 continue; // not exported 697 if (mm.methodType() == QMetaMethod::Slot) { 698 if (isScriptable && (flags & QDBusConnection::ExportScriptableSlots) == 0) 699 continue; // scriptable slots not exported 700 if (!isScriptable && (flags & QDBusConnection::ExportNonScriptableSlots) == 0) 701 continue; // non-scriptable slots not exported 702 } else { 703 if (isScriptable && (flags & QDBusConnection::ExportScriptableInvokables) == 0) 704 continue; // scriptable invokables not exported 705 if (!isScriptable && (flags & QDBusConnection::ExportNonScriptableInvokables) == 0) 706 continue; // non-scriptable invokables not exported 707 } 687 708 688 709 // if we got here, this slot matched … … 693 714 return -1; 694 715 } 716 717 static QDBusCallDeliveryEvent * const DIRECT_DELIVERY = (QDBusCallDeliveryEvent *)1; 695 718 696 719 QDBusCallDeliveryEvent* QDBusConnectionPrivate::prepareReply(QDBusConnectionPrivate *target, … … 705 728 if (metaTypes[n] == QDBusMetaTypeId::message) 706 729 --n; 730 731 if (msg.arguments().count() < n) 732 return 0; // too few arguments 707 733 708 734 // check that types match … … 714 740 // we can deliver 715 741 // prepare for the call 742 if (target == object) 743 return DIRECT_DELIVERY; 716 744 return new QDBusCallDeliveryEvent(QDBusConnection(target), idx, target, msg, metaTypes); 717 745 } … … 728 756 // Slots receive read-only copies of the message (i.e., pass by value or by const-ref) 729 757 QDBusCallDeliveryEvent *call = prepareReply(this, hook.obj, hook.midx, hook.params, msg); 758 if (call == DIRECT_DELIVERY) { 759 // short-circuit delivery 760 Q_ASSERT(this == hook.obj); 761 deliverCall(this, 0, msg, hook.params, hook.midx); 762 return; 763 } 730 764 if (call) 731 765 postEventToThread(ActivateSignalAction, hook.obj, call); … … 759 793 return false; 760 794 795 #ifndef QT_NO_PROPERTIES 761 796 Q_ASSERT_X(QThread::currentThread() == object->thread(), 762 797 "QDBusConnection: internal threading error", … … 778 813 if (cacheIt == slotCache.hash.constEnd() || cacheIt.key() != cacheKey) 779 814 { 780 // not cached, analy se the meta object815 // not cached, analyze the meta object 781 816 const QMetaObject *mo = object->metaObject(); 782 817 QByteArray memberName = msg.member().toUtf8(); … … 817 852 return true; 818 853 } 854 #endif // QT_NO_PROPERTIES 855 return false; 819 856 } 820 857 … … 948 985 949 986 rootNode.flags = 0; 987 988 // prepopulate watchedServices: 989 // we know that the owner of org.freedesktop.DBus is itself 990 watchedServices.insert(dbusServiceString(), WatchedServiceData(dbusServiceString(), 1)); 991 992 // prepopulate matchRefCounts: 993 // we know that org.freedesktop.DBus will never change owners 994 matchRefCounts.insert("type='signal',sender='org.freedesktop.DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged',arg0='org.freedesktop.DBus'", 1); 950 995 } 951 996 … … 1174 1219 } 1175 1220 1176 void QDBusConnectionPrivate:: _q_serviceOwnerChanged(const QString &name,1177 const QString &oldOwner, const QString &newOwner)1221 void QDBusConnectionPrivate::serviceOwnerChangedNoLock(const QString &name, 1222 const QString &oldOwner, const QString &newOwner) 1178 1223 { 1179 1224 Q_UNUSED(oldOwner); 1180 QDBusWriteLocker locker(UpdateSignalHookOwnerAction, this);1225 // QDBusWriteLocker locker(UpdateSignalHookOwnerAction, this); 1181 1226 WatchedServicesHash::Iterator it = watchedServices.find(name); 1182 1227 if (it == watchedServices.end()) … … 1375 1420 1376 1421 // try the object itself: 1377 if (node.flags & (QDBusConnection::ExportScriptableSlots|QDBusConnection::ExportNonScriptableSlots)) { 1422 if (node.flags & (QDBusConnection::ExportScriptableSlots|QDBusConnection::ExportNonScriptableSlots) || 1423 node.flags & (QDBusConnection::ExportScriptableInvokables|QDBusConnection::ExportNonScriptableInvokables)) { 1378 1424 bool interfaceFound = true; 1379 1425 if (!msg.interface().isEmpty()) … … 1631 1677 mode = ClientMode; 1632 1678 1679 const char *service = q_dbus_bus_get_unique_name(connection); 1680 Q_ASSERT(service); 1681 baseService = QString::fromUtf8(service); 1682 1633 1683 q_dbus_connection_set_exit_on_disconnect(connection, false); 1634 1684 q_dbus_connection_set_watch_functions(connection, qDBusAddWatch, qDBusRemoveWatch, … … 1637 1687 qDBusToggleTimeout, this, 0); 1638 1688 q_dbus_connection_set_dispatch_status_function(connection, qDBusUpdateDispatchStatus, this, 0); 1639 1640 // Initialize the match rules1641 // We want all messages that have us as destination1642 // signals don't have destinations, but connectSignal() takes care of them1643 const char *service = q_dbus_bus_get_unique_name(connection);1644 if (service) {1645 QVarLengthArray<char, 56> filter;1646 filter.append("destination='", 13);1647 filter.append(service, qstrlen(service));1648 filter.append("\'\0", 2);1649 1650 QDBusErrorInternal error;1651 q_dbus_bus_add_match(connection, filter.constData(), error);1652 if (handleError(error)) {1653 closeConnection();1654 return;1655 }1656 1657 baseService = QString::fromUtf8(service);1658 } else {1659 qWarning("QDBusConnectionPrivate::setConnection: Unable to get base service");1660 }1661 1662 QString busService = QLatin1String(DBUS_SERVICE_DBUS);1663 connectSignal(busService, QString(), QString(), QLatin1String("NameAcquired"), QStringList(), QString(),1664 this, SLOT(registerService(QString)));1665 connectSignal(busService, QString(), QString(), QLatin1String("NameLost"), QStringList(), QString(),1666 this, SLOT(unregisterService(QString)));1667 1668 1669 1689 q_dbus_connection_add_filter(connection, qDBusSignalFilter, this, 0); 1690 1691 // Initialize the hooks for the NameAcquired and NameLost signals 1692 // we don't use connectSignal here because we don't need the rules to be sent to the bus 1693 // the bus will always send us these two signals 1694 SignalHook hook; 1695 hook.service = dbusServiceString(); 1696 hook.path.clear(); // no matching 1697 hook.obj = this; 1698 hook.params << QMetaType::Void << QVariant::String; // both functions take a QString as parameter and return void 1699 1700 hook.midx = staticMetaObject.indexOfSlot("registerServiceNoLock(QString)"); 1701 Q_ASSERT(hook.midx != -1); 1702 signalHooks.insert(QLatin1String("NameAcquired:" DBUS_INTERFACE_DBUS), hook); 1703 1704 hook.midx = staticMetaObject.indexOfSlot("unregisterServiceNoLock(QString)"); 1705 Q_ASSERT(hook.midx != -1); 1706 signalHooks.insert(QLatin1String("NameLost:" DBUS_INTERFACE_DBUS), hook); 1670 1707 1671 1708 qDBusDebug() << this << ": connected successfully"; … … 2054 2091 if (++data.refcount == 1) { 2055 2092 // we need to watch for this service changing 2056 QString dbusServerService = QLatin1String(DBUS_SERVICE_DBUS); 2057 connectSignal(dbusServerService, QString(), QLatin1String(DBUS_INTERFACE_DBUS), 2093 connectSignal(dbusServiceString(), QString(), dbusInterfaceString(), 2058 2094 QLatin1String("NameOwnerChanged"), QStringList() << hook.service, QString(), 2059 this, SLOT( _q_serviceOwnerChanged(QString,QString,QString)));2095 this, SLOT(serviceOwnerChangedNoLock(QString,QString,QString))); 2060 2096 data.owner = getNameOwnerNoCache(hook.service); 2061 2097 qDBusDebug() << this << "Watching service" << hook.service << "for owner changes (current owner:" … … 2134 2170 if (--sit.value().refcount == 0) { 2135 2171 watchedServices.erase(sit); 2136 QString dbusServerService = QLatin1String(DBUS_SERVICE_DBUS); 2137 disconnectSignal(dbusServerService, QString(), QLatin1String(DBUS_INTERFACE_DBUS), 2172 disconnectSignal(dbusServiceString(), QString(), dbusInterfaceString(), 2138 2173 QLatin1String("NameOwnerChanged"), QStringList() << hook.service, QString(), 2139 2174 this, SLOT(_q_serviceOwnerChanged(QString,QString,QString))); … … 2257 2292 QString QDBusConnectionPrivate::getNameOwnerNoCache(const QString &serviceName) 2258 2293 { 2259 QDBusMessage msg = QDBusMessage::createMethodCall( QLatin1String(DBUS_SERVICE_DBUS),2260 QLatin1String(DBUS_PATH_DBUS), QLatin1String(DBUS_INTERFACE_DBUS),2294 QDBusMessage msg = QDBusMessage::createMethodCall(dbusServiceString(), 2295 QLatin1String(DBUS_PATH_DBUS), dbusInterfaceString(), 2261 2296 QLatin1String("GetNameOwner")); 2262 2297 QDBusMessagePrivate::setParametersValidated(msg, true); … … 2319 2354 { 2320 2355 QDBusWriteLocker locker(RegisterServiceAction, this); 2356 registerServiceNoLock(serviceName); 2357 } 2358 2359 void QDBusConnectionPrivate::registerServiceNoLock(const QString &serviceName) 2360 { 2321 2361 serviceNames.append(serviceName); 2322 2362 } … … 2325 2365 { 2326 2366 QDBusWriteLocker locker(UnregisterServiceAction, this); 2367 unregisterServiceNoLock(serviceName); 2368 } 2369 2370 void QDBusConnectionPrivate::unregisterServiceNoLock(const QString &serviceName) 2371 { 2327 2372 serviceNames.removeAll(serviceName); 2328 2373 } … … 2344 2389 2345 2390 QT_END_NAMESPACE 2391 2392 #endif // QT_NO_DBUS
Note:
See TracChangeset
for help on using the changeset viewer.