From 1996bd4a01748ae384242eb47d4ff2c679c4c5d0 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Mon, 29 Dec 2014 18:06:42 -0200 Subject: Use QDBusConnectionPrivate* when QDBusServer receives a new connection This is because the socket activity will move to a different thread; QDBusConnectionPrivate* can be queued, QDBusConnection can't easily. Change-Id: I82722016018b7fcfb246cda6043469fadbfd987d Reviewed-by: Albert Astals Cid Reviewed-by: Alex Blasche --- src/dbus/qdbusconnection.cpp | 2 +- src/dbus/qdbusconnection_p.h | 17 +++++++++++------ src/dbus/qdbusintegrator.cpp | 15 +++++++++++---- src/dbus/qdbusserver.cpp | 15 +++++++++------ src/dbus/qdbusserver.h | 2 ++ 5 files changed, 34 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/dbus/qdbusconnection.cpp b/src/dbus/qdbusconnection.cpp index fd8b34b27e..08a21c5d02 100644 --- a/src/dbus/qdbusconnection.cpp +++ b/src/dbus/qdbusconnection.cpp @@ -929,7 +929,7 @@ QObject *QDBusConnection::objectRegisteredAt(const QString &path) const */ QDBusConnectionInterface *QDBusConnection::interface() const { - if (!d) + if (!d || d->mode != QDBusConnectionPrivate::ClientMode) return 0; return d->busService; } diff --git a/src/dbus/qdbusconnection_p.h b/src/dbus/qdbusconnection_p.h index 8195ec5b3a..9e948bd684 100644 --- a/src/dbus/qdbusconnection_p.h +++ b/src/dbus/qdbusconnection_p.h @@ -1,6 +1,7 @@ /**************************************************************************** ** ** Copyright (C) 2015 The Qt Company Ltd. +** Copyright (C) 2015 Intel Corporation. ** Contact: http://www.qt.io/licensing/ ** ** This file is part of the QtDBus module of the Qt Toolkit. @@ -79,6 +80,7 @@ struct QDBusMetaObject; class QDBusAbstractInterface; class QDBusConnectionInterface; class QDBusPendingCallPrivate; +class QDBusServer; #ifndef QT_BOOTSTRAPPED @@ -191,7 +193,7 @@ public: void setBusService(const QDBusConnection &connection); void setPeer(DBusConnection *connection, const QDBusErrorInternal &error); void setConnection(DBusConnection *connection, const QDBusErrorInternal &error); - void setServer(DBusServer *server, const QDBusErrorInternal &error); + void setServer(QDBusServer *object, DBusServer *server, const QDBusErrorInternal &error); void closeConnection(); QString getNameOwner(const QString &service); @@ -228,9 +230,6 @@ public: void postEventToThread(int action, QObject *target, QEvent *event); - inline void serverConnection(const QDBusConnection &connection) - { emit newServerConnection(connection); } - private: void checkThread(); bool handleError(const QDBusErrorInternal &error); @@ -252,6 +251,8 @@ private: QString getNameOwnerNoCache(const QString &service); + void _q_newConnection(QDBusConnectionPrivate *newConnection); + protected: void customEvent(QEvent *e) Q_DECL_OVERRIDE; void timerEvent(QTimerEvent *e) Q_DECL_OVERRIDE; @@ -272,7 +273,7 @@ private slots: signals: void serviceOwnerChanged(const QString &name, const QString &oldOwner, const QString &newOwner); void callWithCallbackFailed(const QDBusError &error, const QDBusMessage &message); - void newServerConnection(const QDBusConnection &connection); + void newServerConnection(QDBusConnectionPrivate *newConnection); public: QAtomicInt ref; @@ -282,7 +283,10 @@ public: QStringList serverConnectionNames; ConnectionMode mode; - QDBusConnectionInterface *busService; + union { + QDBusConnectionInterface *busService; + QDBusServer *serverObject; + }; // the dispatch lock protects everything related to the DBusConnection or DBusServer // including the timeouts and watches @@ -333,6 +337,7 @@ public: friend class QDBusActivateObjectEvent; friend class QDBusCallDeliveryEvent; + friend class QDBusServer; }; // in qdbusmisc.cpp diff --git a/src/dbus/qdbusintegrator.cpp b/src/dbus/qdbusintegrator.cpp index 796f41bffc..04d2c93ffe 100644 --- a/src/dbus/qdbusintegrator.cpp +++ b/src/dbus/qdbusintegrator.cpp @@ -1,6 +1,7 @@ /**************************************************************************** ** ** Copyright (C) 2015 The Qt Company Ltd. +** Copyright (C) 2015 Intel Corporation. ** Contact: http://www.qt.io/licensing/ ** ** This file is part of the QtDBus module of the Qt Toolkit. @@ -52,6 +53,7 @@ #include "qdbusmetatype_p.h" #include "qdbusabstractadaptor.h" #include "qdbusabstractadaptor_p.h" +#include "qdbusserver.h" #include "qdbusutil_p.h" #include "qdbusvirtualobject.h" #include "qdbusmessage_p.h" @@ -393,10 +395,14 @@ static void qDBusNewConnection(DBusServer *server, DBusConnection *connection, v QDBusErrorInternal error; newConnection->setPeer(connection, error); - QDBusConnection retval = QDBusConnectionPrivate::q(newConnection); + // this is a queued connection and will resume in the QDBusServer's thread + emit serverConnection->newServerConnection(newConnection); +} - // make QDBusServer emit the newConnection signal - serverConnection->serverConnection(retval); +void QDBusConnectionPrivate::_q_newConnection(QDBusConnectionPrivate *newConnection) +{ + Q_ASSERT(mode == ServerMode); + emit serverObject->newConnection(QDBusConnectionPrivate::q(newConnection)); } } // extern "C" @@ -1645,9 +1651,10 @@ void QDBusConnectionPrivate::handleSignal(const QDBusMessage& msg) handleSignal(key, msg); // third try } -void QDBusConnectionPrivate::setServer(DBusServer *s, const QDBusErrorInternal &error) +void QDBusConnectionPrivate::setServer(QDBusServer *object, DBusServer *s, const QDBusErrorInternal &error) { mode = ServerMode; + serverObject = object; if (!s) { handleError(error); return; diff --git a/src/dbus/qdbusserver.cpp b/src/dbus/qdbusserver.cpp index cf1b6e9665..05156c992f 100644 --- a/src/dbus/qdbusserver.cpp +++ b/src/dbus/qdbusserver.cpp @@ -1,6 +1,7 @@ /**************************************************************************** ** ** Copyright (C) 2015 The Qt Company Ltd. +** Copyright (C) 2015 Intel Corporation. ** Contact: http://www.qt.io/licensing/ ** ** This file is part of the QtDBus module of the Qt Toolkit. @@ -64,11 +65,11 @@ QDBusServer::QDBusServer(const QString &address, QObject *parent) } d = new QDBusConnectionPrivate(this); - QObject::connect(d, SIGNAL(newServerConnection(QDBusConnection)), - this, SIGNAL(newConnection(QDBusConnection))); + QObject::connect(d, SIGNAL(newServerConnection(QDBusConnectionPrivate*)), + this, SLOT(_q_newConnection(QDBusConnectionPrivate*)), Qt::QueuedConnection); QDBusErrorInternal error; - d->setServer(q_dbus_server_listen(address.toUtf8().constData(), error), error); + d->setServer(this, q_dbus_server_listen(address.toUtf8().constData(), error), error); } /*! @@ -92,11 +93,11 @@ QDBusServer::QDBusServer(QObject *parent) } d = new QDBusConnectionPrivate(this); - QObject::connect(d, SIGNAL(newServerConnection(QDBusConnection)), - this, SIGNAL(newConnection(QDBusConnection))); + QObject::connect(d, SIGNAL(newServerConnection(QDBusConnectionPrivate*)), + this, SLOT(_q_newConnection(QDBusConnectionPrivate*)), Qt::QueuedConnection); QDBusErrorInternal error; - d->setServer(q_dbus_server_listen(address, error), error); + d->setServer(this, q_dbus_server_listen(address, error), error); } /*! @@ -186,4 +187,6 @@ bool QDBusServer::isAnonymousAuthenticationAllowed() const QT_END_NAMESPACE +#include "moc_qdbusserver.cpp" + #endif // QT_NO_DBUS diff --git a/src/dbus/qdbusserver.h b/src/dbus/qdbusserver.h index db21f268b0..2c66472a4d 100644 --- a/src/dbus/qdbusserver.h +++ b/src/dbus/qdbusserver.h @@ -1,6 +1,7 @@ /**************************************************************************** ** ** Copyright (C) 2015 The Qt Company Ltd. +** Copyright (C) 2015 Intel Corporation. ** Contact: http://www.qt.io/licensing/ ** ** This file is part of the QtDBus module of the Qt Toolkit. @@ -66,6 +67,7 @@ Q_SIGNALS: private: Q_DISABLE_COPY(QDBusServer) + Q_PRIVATE_SLOT(d, void _q_newConnection(QDBusConnectionPrivate*)) QDBusConnectionPrivate *d; }; -- cgit v1.2.3