summaryrefslogtreecommitdiffstats
path: root/src/dbus/qdbusintegrator.cpp
diff options
context:
space:
mode:
authorQt Continuous Integration System <qt-info@nokia.com>2011-04-18 22:17:02 (GMT)
committerQt Continuous Integration System <qt-info@nokia.com>2011-04-18 22:17:02 (GMT)
commit685df07ff7e357f6848c50cffa311641afdca307 (patch)
tree760e1e6f7189513785133071ab408260f09210b4 /src/dbus/qdbusintegrator.cpp
parenta359d21a84acc4b7eb73931e47acd4440327be19 (diff)
parent4c8c5ef3866723124fe8cf2c8bdd3b846549b129 (diff)
downloadQt-685df07ff7e357f6848c50cffa311641afdca307.zip
Qt-685df07ff7e357f6848c50cffa311641afdca307.tar.gz
Qt-685df07ff7e357f6848c50cffa311641afdca307.tar.bz2
Merge branch 'master' of scm.dev.nokia.troll.no:qt/oslo-staging-1 into master-integration
* 'master' of scm.dev.nokia.troll.no:qt/oslo-staging-1: QtDBus: Add unit tests for QDBusAbstractAdaptor QtDBus: Add unit tests for QDBusInterface QtDBus: Add unit tests for QDBusAbstractInterface QtDBus: Register QDBusServer connection name in QDBusConnectionManager QtDBus: Skip bus name check for peer-to-peer connection QtDBus: Fix minor coding style issues QtDBus: Add default constructor to QDBusServer QtDBus: Add unit tests for peer-to-peer connection QtDBus: Add method QDBusConnection::disconnectFromPeer() QtDBus: Add method QDBusConnection::connectToPeer() QtDBus: Fix QDBusConnection::disconnectFromBus() for peer-to-peer connections QtDBus: Fix bus in peer-to-peer connections should not be used QtDBus: Fix empty service name in peer-to-peer connections QtDBus: Fix registering objects using path '/' in peer-to-peer connections QtDBus: Fix QDBusServer to handle correctly new dbus connections QtDBus: Cleaning comments, spacing, etc.
Diffstat (limited to 'src/dbus/qdbusintegrator.cpp')
-rw-r--r--src/dbus/qdbusintegrator.cpp93
1 files changed, 48 insertions, 45 deletions
diff --git a/src/dbus/qdbusintegrator.cpp b/src/dbus/qdbusintegrator.cpp
index 5d53390..b2095c7 100644
--- a/src/dbus/qdbusintegrator.cpp
+++ b/src/dbus/qdbusintegrator.cpp
@@ -377,28 +377,23 @@ static void qDBusUpdateDispatchStatus(DBusConnection *connection, DBusDispatchSt
static void qDBusNewConnection(DBusServer *server, DBusConnection *connection, void *data)
{
- // ### We may want to separate the server from the QDBusConnectionPrivate
+ // ### We may want to separate the server from the QDBusConnectionPrivate
Q_ASSERT(server); Q_UNUSED(server);
Q_ASSERT(connection);
Q_ASSERT(data);
// keep the connection alive
q_dbus_connection_ref(connection);
- QDBusConnectionPrivate *d = new QDBusConnectionPrivate;
-
- // setConnection does the error handling for us
+ QDBusConnectionPrivate *d = static_cast<QDBusConnectionPrivate *>(data);
+
+ // setPeer does the error handling for us
QDBusErrorInternal error;
d->setPeer(connection, error);
QDBusConnection retval = QDBusConnectionPrivate::q(d);
- d->setBusService(retval);
-
- //d->name = QString::number(reinterpret_cast<int>(d));
- //d->setConnection(d->name, d);
// make QDBusServer emit the newConnection signal
- QDBusConnectionPrivate *server_d = static_cast<QDBusConnectionPrivate *>(data);
- server_d->serverConnection(retval);
+ d->serverConnection(retval);
}
} // extern "C"
@@ -435,6 +430,11 @@ static bool findObject(const QDBusConnectionPrivate::ObjectTreeNode *root,
const QString &fullpath, int &usedLength,
QDBusConnectionPrivate::ObjectTreeNode &result)
{
+ if (!fullpath.compare(QLatin1String("/")) && root->obj) {
+ usedLength = 1;
+ result = *root;
+ return root;
+ }
int start = 0;
int length = fullpath.length();
if (fullpath.at(0) == QLatin1Char('/'))
@@ -1036,11 +1036,10 @@ void QDBusConnectionPrivate::closeConnection()
mode = InvalidMode; // prevent reentrancy
baseService.clear();
- if (oldMode == ServerMode) {
- if (server) {
- q_dbus_server_disconnect(server);
- }
- } else if (oldMode == ClientMode || oldMode == PeerMode) {
+ if (server)
+ q_dbus_server_disconnect(server);
+
+ if (oldMode == ClientMode || oldMode == PeerMode) {
if (connection) {
q_dbus_connection_close(connection);
// send the "close" message
@@ -1629,7 +1628,7 @@ void QDBusConnectionPrivate::setServer(DBusServer *s, const QDBusErrorInternal &
this, 0);
//qDebug() << "time_functions_set" << time_functions_set;
Q_UNUSED(time_functions_set);
-
+
q_dbus_server_set_new_connection_function(server, qDBusNewConnection, this, 0);
dbus_bool_t data_set = q_dbus_server_set_data(server, server_slot, this, 0);
@@ -1646,7 +1645,7 @@ void QDBusConnectionPrivate::setPeer(DBusConnection *c, const QDBusErrorInternal
connection = c;
mode = PeerMode;
-
+
q_dbus_connection_set_exit_on_disconnect(connection, false);
q_dbus_connection_set_watch_functions(connection,
qDBusAddWatch,
@@ -2098,21 +2097,23 @@ void QDBusConnectionPrivate::connectSignal(const QString &key, const SignalHook
matchRefCounts.insert(hook.matchRule, 1);
if (connection) {
- qDBusDebug("Adding rule: %s", hook.matchRule.constData());
- q_dbus_bus_add_match(connection, hook.matchRule, NULL);
-
- // Successfully connected the signal
- // Do we need to watch for this name?
- if (shouldWatchService(hook.service)) {
- WatchedServicesHash::mapped_type &data = watchedServices[hook.service];
- if (++data.refcount == 1) {
- // we need to watch for this service changing
- connectSignal(dbusServiceString(), QString(), dbusInterfaceString(),
- QLatin1String("NameOwnerChanged"), QStringList() << hook.service, QString(),
- this, SLOT(serviceOwnerChangedNoLock(QString,QString,QString)));
- data.owner = getNameOwnerNoCache(hook.service);
- qDBusDebug() << this << "Watching service" << hook.service << "for owner changes (current owner:"
- << data.owner << ")";
+ if (mode != QDBusConnectionPrivate::PeerMode) {
+ qDBusDebug("Adding rule: %s", hook.matchRule.constData());
+ q_dbus_bus_add_match(connection, hook.matchRule, NULL);
+
+ // Successfully connected the signal
+ // Do we need to watch for this name?
+ if (shouldWatchService(hook.service)) {
+ WatchedServicesHash::mapped_type &data = watchedServices[hook.service];
+ if (++data.refcount == 1) {
+ // we need to watch for this service changing
+ connectSignal(dbusServiceString(), QString(), dbusInterfaceString(),
+ QLatin1String("NameOwnerChanged"), QStringList() << hook.service, QString(),
+ this, SLOT(serviceOwnerChangedNoLock(QString,QString,QString)));
+ data.owner = getNameOwnerNoCache(hook.service);
+ qDBusDebug() << this << "Watching service" << hook.service << "for owner changes (current owner:"
+ << data.owner << ")";
+ }
}
}
}
@@ -2176,18 +2177,20 @@ QDBusConnectionPrivate::disconnectSignal(SignalHookHash::Iterator &it)
// we don't care about errors here
if (connection && erase) {
- qDBusDebug("Removing rule: %s", hook.matchRule.constData());
- q_dbus_bus_remove_match(connection, hook.matchRule, NULL);
-
- // Successfully disconnected the signal
- // Were we watching for this name?
- WatchedServicesHash::Iterator sit = watchedServices.find(hook.service);
- if (sit != watchedServices.end()) {
- if (--sit.value().refcount == 0) {
- watchedServices.erase(sit);
- disconnectSignal(dbusServiceString(), QString(), dbusInterfaceString(),
- QLatin1String("NameOwnerChanged"), QStringList() << hook.service, QString(),
- this, SLOT(_q_serviceOwnerChanged(QString,QString,QString)));
+ if (mode != QDBusConnectionPrivate::PeerMode) {
+ qDBusDebug("Removing rule: %s", hook.matchRule.constData());
+ q_dbus_bus_remove_match(connection, hook.matchRule, NULL);
+
+ // Successfully disconnected the signal
+ // Were we watching for this name?
+ WatchedServicesHash::Iterator sit = watchedServices.find(hook.service);
+ if (sit != watchedServices.end()) {
+ if (--sit.value().refcount == 0) {
+ watchedServices.erase(sit);
+ disconnectSignal(dbusServiceString(), QString(), dbusInterfaceString(),
+ QLatin1String("NameOwnerChanged"), QStringList() << hook.service, QString(),
+ this, SLOT(_q_serviceOwnerChanged(QString,QString,QString)));
+ }
}
}
@@ -2390,7 +2393,7 @@ void QDBusConnectionPrivate::unregisterServiceNoLock(const QString &serviceName)
bool QDBusConnectionPrivate::isServiceRegisteredByThread(const QString &serviceName) const
{
- if (serviceName == baseService)
+ if (!serviceName.isEmpty() && serviceName == baseService)
return true;
QStringList copy = serviceNames;
return copy.contains(serviceName);