Remove the old QDBusConnection::sender functionality

This has been deprecated since QDBusContext was introduced (Qt 4.3). So
it's time to remove the functionality.

[ChangeLog][Important Behavior Change] QDBusConnection::sender()
(deprecated since Qt 4.3) has changed to always return an invalid
QDBusConnection. To know what connection the incoming call was received
from, use QDBusContext.

Change-Id: I355efb82c14e54ed718c8f892d8267e727b19118
Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
bb10
Thiago Macieira 2014-12-28 21:51:30 -02:00
parent 32cbb363b9
commit 2e2cf8a549
6 changed files with 17 additions and 47 deletions

View File

@ -58,18 +58,6 @@ QT_BEGIN_NAMESPACE
Q_GLOBAL_STATIC(QDBusConnectionManager, _q_manager)
QDBusConnectionPrivate *QDBusConnectionManager::sender() const
{
QMutexLocker locker(&senderMutex);
return connection(senderName);
}
void QDBusConnectionManager::setSender(const QDBusConnectionPrivate *s)
{
QMutexLocker locker(&senderMutex);
senderName = (s ? s->name : QString());
}
QDBusConnectionPrivate *QDBusConnectionManager::connection(const QString &name) const
{
return connectionHash.value(name, 0);
@ -1096,29 +1084,20 @@ QDBusConnection QDBusConnection::systemBus()
return *_q_systemBus();
}
#if QT_DEPRECATED_SINCE(5,5)
/*!
\nonreentrant
\deprecated
Returns the connection that sent the signal, if called in a slot activated
by QDBus; otherwise it returns 0.
Always returns a disconnected, invalid QDBusConnection object. For the old
functionality of determining the sender connection, please use \ref QDBusContext.
\note Please avoid this function. This function is not thread-safe, so if
there's any other thread delivering a D-Bus call, this function may return
the wrong connection. In new code, please use QDBusContext::connection()
(see that class for a description on how to use it).
\sa QDBusContext
*/
QDBusConnection QDBusConnection::sender()
{
return QDBusConnection(_q_manager()->sender());
}
/*!
\internal
*/
void QDBusConnectionPrivate::setSender(const QDBusConnectionPrivate *s)
{
_q_manager()->setSender(s);
return QDBusConnection(QString());
}
#endif
/*!
\internal

View File

@ -1,6 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Copyright (C) 2015 Intel Corporation.
** Contact: http://www.qt-project.org/legal
**
** This file is part of the QtDBus module of the Qt Toolkit.
@ -184,7 +185,10 @@ public:
static QDBusConnection sessionBus();
static QDBusConnection systemBus();
static QDBusConnection sender();
#if QT_DEPRECATED_SINCE(5,5)
static QT_DEPRECATED_X("This function no longer works, use QDBusContext instead")
QDBusConnection sender();
#endif
protected:
explicit QDBusConnection(QDBusConnectionPrivate *dd);

View File

@ -331,8 +331,6 @@ public:
static QDBusConnectionPrivate *d(const QDBusConnection& q) { return q.d; }
static QDBusConnection q(QDBusConnectionPrivate *connection) { return QDBusConnection(connection); }
static void setSender(const QDBusConnectionPrivate *s);
friend class QDBusActivateObjectEvent;
friend class QDBusCallDeliveryEvent;
};

View File

@ -63,9 +63,6 @@ public:
void removeConnection(const QString &name);
void setConnection(const QString &name, QDBusConnectionPrivate *c);
QDBusConnectionPrivate *sender() const;
void setSender(const QDBusConnectionPrivate *s);
mutable QMutex mutex;
private:
QHash<QString, QDBusConnectionPrivate *> connectionHash;

View File

@ -985,12 +985,10 @@ void QDBusConnectionPrivate::deliverCall(QObject *object, int /*flags*/, const Q
// FIXME: save the old sender!
QDBusContextPrivate context(QDBusConnection(this), msg);
QDBusContextPrivate *old = QDBusContextPrivate::set(object, &context);
QDBusConnectionPrivate::setSender(this);
QPointer<QObject> ptr = object;
fail = object->qt_metacall(QMetaObject::InvokeMetaMethod,
slotIdx, params.data()) >= 0;
QDBusConnectionPrivate::setSender(0);
// the object might be deleted in the slot
if (!ptr.isNull())
QDBusContextPrivate::set(object, old);

View File

@ -38,7 +38,7 @@
#include <QtDBus/QtDBus>
class MyObject: public QObject
class MyObject: public QObject, protected QDBusContext
{
Q_OBJECT
Q_CLASSINFO("D-Bus Interface", "org.qtproject.QtDBus.MyObject")
@ -123,15 +123,12 @@ public:
Q_INVOKABLE void ping_invokable(QDBusMessage msg)
{
QDBusConnection sender = QDBusConnection::sender();
if (!sender.isConnected())
exit(1);
Q_ASSERT(QDBusContext::calledFromDBus());
++callCount;
callArgs = msg.arguments();
msg.setDelayedReply(true);
if (!sender.send(msg.createReply(callArgs)))
if (!QDBusContext::connection().send(msg.createReply(callArgs)))
exit(1);
}
@ -139,15 +136,12 @@ public slots:
void ping(QDBusMessage msg)
{
QDBusConnection sender = QDBusConnection::sender();
if (!sender.isConnected())
exit(1);
Q_ASSERT(QDBusContext::calledFromDBus());
++callCount;
callArgs = msg.arguments();
msg.setDelayedReply(true);
if (!sender.send(msg.createReply(callArgs)))
if (!QDBusContext::connection().send(msg.createReply(callArgs)))
exit(1);
}
};