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 <aacid@kde.org>
Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
bb10
Thiago Macieira 2014-12-29 18:06:42 -02:00
parent 2bcc913a7f
commit 1996bd4a01
5 changed files with 34 additions and 17 deletions

View File

@ -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;
}

View File

@ -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

View File

@ -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;

View File

@ -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

View File

@ -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;
};