src/dbus/qdbusintegrator.cpp
branchRCL_3
changeset 5 d3bac044e0f0
parent 4 3b1da2848fc7
child 8 3f74d0d4af4c
equal deleted inserted replaced
4:3b1da2848fc7 5:d3bac044e0f0
  1658     } else {
  1658     } else {
  1659         qWarning("QDBusConnectionPrivate::setConnection: Unable to get base service");
  1659         qWarning("QDBusConnectionPrivate::setConnection: Unable to get base service");
  1660     }
  1660     }
  1661 
  1661 
  1662     QString busService = QLatin1String(DBUS_SERVICE_DBUS);
  1662     QString busService = QLatin1String(DBUS_SERVICE_DBUS);
  1663     WatchedServicesHash::mapped_type &bus = watchedServices[busService];
       
  1664     bus.refcount = 1;
       
  1665     bus.owner = getNameOwnerNoCache(busService);
       
  1666     connectSignal(busService, QString(), QString(), QLatin1String("NameAcquired"), QStringList(), QString(),
  1663     connectSignal(busService, QString(), QString(), QLatin1String("NameAcquired"), QStringList(), QString(),
  1667                   this, SLOT(registerService(QString)));
  1664                   this, SLOT(registerService(QString)));
  1668     connectSignal(busService, QString(), QString(), QLatin1String("NameLost"), QStringList(), QString(),
  1665     connectSignal(busService, QString(), QString(), QLatin1String("NameLost"), QStringList(), QString(),
  1669                   this, SLOT(unregisterService(QString)));
  1666                   this, SLOT(unregisterService(QString)));
  1670 
  1667 
  2002         const QDBusConnectionPrivate::SignalHook &entry = it.value();
  1999         const QDBusConnectionPrivate::SignalHook &entry = it.value();
  2003         if (entry.service == hook.service &&
  2000         if (entry.service == hook.service &&
  2004             entry.path == hook.path &&
  2001             entry.path == hook.path &&
  2005             entry.signature == hook.signature &&
  2002             entry.signature == hook.signature &&
  2006             entry.obj == hook.obj &&
  2003             entry.obj == hook.obj &&
  2007             entry.midx == hook.midx) {
  2004             entry.midx == hook.midx &&
       
  2005             entry.argumentMatch == hook.argumentMatch) {
  2008             // no need to compare the parameters if it's the same slot
  2006             // no need to compare the parameters if it's the same slot
  2009             return true;        // already there
  2007             return true;        // already there
  2010         }
  2008         }
  2011     }
  2009     }
  2012 
  2010 
  2044         } else {
  2042         } else {
  2045             // Successfully connected the signal
  2043             // Successfully connected the signal
  2046             // Do we need to watch for this name?
  2044             // Do we need to watch for this name?
  2047             if (shouldWatchService(hook.service)) {
  2045             if (shouldWatchService(hook.service)) {
  2048                 WatchedServicesHash::mapped_type &data = watchedServices[hook.service];
  2046                 WatchedServicesHash::mapped_type &data = watchedServices[hook.service];
  2049                 if (data.refcount) {
  2047                 if (++data.refcount == 1) {
  2050                     // already watching
       
  2051                     ++data.refcount;
       
  2052                 } else {
       
  2053                     // we need to watch for this service changing
  2048                     // we need to watch for this service changing
  2054                     QString dbusServerService = QLatin1String(DBUS_SERVICE_DBUS);
  2049                     QString dbusServerService = QLatin1String(DBUS_SERVICE_DBUS);
  2055                     connectSignal(dbusServerService, QString(), QLatin1String(DBUS_INTERFACE_DBUS),
  2050                     connectSignal(dbusServerService, QString(), QLatin1String(DBUS_INTERFACE_DBUS),
  2056                                   QLatin1String("NameOwnerChanged"), QStringList() << hook.service, QString(),
  2051                                   QLatin1String("NameOwnerChanged"), QStringList() << hook.service, QString(),
  2057                                   this, SLOT(_q_serviceOwnerChanged(QString,QString,QString)));
  2052                                   this, SLOT(_q_serviceOwnerChanged(QString,QString,QString)));
  2087         const QDBusConnectionPrivate::SignalHook &entry = it.value();
  2082         const QDBusConnectionPrivate::SignalHook &entry = it.value();
  2088         if (entry.service == hook.service &&
  2083         if (entry.service == hook.service &&
  2089             entry.path == hook.path &&
  2084             entry.path == hook.path &&
  2090             entry.signature == hook.signature &&
  2085             entry.signature == hook.signature &&
  2091             entry.obj == hook.obj &&
  2086             entry.obj == hook.obj &&
  2092             entry.midx == hook.midx) {
  2087             entry.midx == hook.midx &&
       
  2088             entry.argumentMatch == hook.argumentMatch) {
  2093             // no need to compare the parameters if it's the same slot
  2089             // no need to compare the parameters if it's the same slot
  2094             disconnectSignal(it);
  2090             disconnectSignal(it);
  2095             return true;        // it was there
  2091             return true;        // it was there
  2096         }
  2092         }
  2097     }
  2093     }
  2102 
  2098 
  2103 QDBusConnectionPrivate::SignalHookHash::Iterator
  2099 QDBusConnectionPrivate::SignalHookHash::Iterator
  2104 QDBusConnectionPrivate::disconnectSignal(SignalHookHash::Iterator &it)
  2100 QDBusConnectionPrivate::disconnectSignal(SignalHookHash::Iterator &it)
  2105 {
  2101 {
  2106     const SignalHook &hook = it.value();
  2102     const SignalHook &hook = it.value();
  2107 
       
  2108     WatchedServicesHash::Iterator sit = watchedServices.find(hook.service);
       
  2109     if (sit != watchedServices.end()) {
       
  2110         if (sit.value().refcount == 1) {
       
  2111             watchedServices.erase(sit);
       
  2112             QString dbusServerService = QLatin1String(DBUS_SERVICE_DBUS);
       
  2113             disconnectSignal(dbusServerService, QString(), QLatin1String(DBUS_INTERFACE_DBUS),
       
  2114                           QLatin1String("NameOwnerChanged"), QStringList() << hook.service, QString(),
       
  2115                           this, SLOT(_q_serviceOwnerChanged(QString,QString,QString)));
       
  2116         } else {
       
  2117             --sit.value().refcount;
       
  2118         }
       
  2119     }
       
  2120 
  2103 
  2121     bool erase = false;
  2104     bool erase = false;
  2122     MatchRefCountHash::iterator i = matchRefCounts.find(hook.matchRule);
  2105     MatchRefCountHash::iterator i = matchRefCounts.find(hook.matchRule);
  2123     if (i == matchRefCounts.end()) {
  2106     if (i == matchRefCounts.end()) {
  2124         qWarning("QDBusConnectionPrivate::disconnectSignal: MatchRule not found in matchRefCounts!!");
  2107         qWarning("QDBusConnectionPrivate::disconnectSignal: MatchRule not found in matchRefCounts!!");
  2134 
  2117 
  2135     // we don't care about errors here
  2118     // we don't care about errors here
  2136     if (connection && erase) {
  2119     if (connection && erase) {
  2137         qDBusDebug("Removing rule: %s", hook.matchRule.constData());
  2120         qDBusDebug("Removing rule: %s", hook.matchRule.constData());
  2138         q_dbus_bus_remove_match(connection, hook.matchRule, NULL);
  2121         q_dbus_bus_remove_match(connection, hook.matchRule, NULL);
       
  2122 
       
  2123         // Successfully disconnected the signal
       
  2124         // Were we watching for this name?
       
  2125         WatchedServicesHash::Iterator sit = watchedServices.find(hook.service);
       
  2126         if (sit != watchedServices.end()) {
       
  2127             if (--sit.value().refcount == 0) {
       
  2128                 watchedServices.erase(sit);
       
  2129                 QString dbusServerService = QLatin1String(DBUS_SERVICE_DBUS);
       
  2130                 disconnectSignal(dbusServerService, QString(), QLatin1String(DBUS_INTERFACE_DBUS),
       
  2131                               QLatin1String("NameOwnerChanged"), QStringList() << hook.service, QString(),
       
  2132                               this, SLOT(_q_serviceOwnerChanged(QString,QString,QString)));
       
  2133             }
       
  2134         }
       
  2135 
  2139     }
  2136     }
  2140 
  2137 
  2141     return signalHooks.erase(it);
  2138     return signalHooks.erase(it);
  2142 }
  2139 }
  2143 
  2140