Skip to content

Commit

Permalink
Merge branch 'master' of scm.dev.nokia.troll.no:qt/oslo-staging-1 int…
Browse files Browse the repository at this point in the history
…o 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.
Qt Continuous Integration System committed Apr 18, 2011
2 parents a359d21 + 4c8c5ef commit 685df07
Showing 28 changed files with 3,426 additions and 545 deletions.
9 changes: 5 additions & 4 deletions src/dbus/qdbusabstractinterface.cpp
Original file line number Diff line number Diff line change
@@ -58,7 +58,7 @@
QT_BEGIN_NAMESPACE

static QDBusError checkIfValid(const QString &service, const QString &path,
const QString &interface, bool isDynamic)
const QString &interface, bool isDynamic, bool isPeer)
{
// We should be throwing exceptions here... oh well
QDBusError error;
@@ -69,7 +69,7 @@ static QDBusError checkIfValid(const QString &service, const QString &path,
// use assertion here because this should never happen, at all
Q_ASSERT_X(!interface.isEmpty(), "QDBusAbstractInterface", "Interface name cannot be empty");
}
if (!QDBusUtil::checkBusName(service, isDynamic ? QDBusUtil::EmptyNotAllowed : QDBusUtil::EmptyAllowed, &error))
if (!QDBusUtil::checkBusName(service, (isDynamic && !isPeer) ? QDBusUtil::EmptyNotAllowed : QDBusUtil::EmptyAllowed, &error))
return error;
if (!QDBusUtil::checkObjectPath(path, isDynamic ? QDBusUtil::EmptyNotAllowed : QDBusUtil::EmptyAllowed, &error))
return error;
@@ -86,7 +86,8 @@ QDBusAbstractInterfacePrivate::QDBusAbstractInterfacePrivate(const QString &serv
const QDBusConnection& con,
bool isDynamic)
: connection(con), service(serv), path(p), interface(iface),
lastError(checkIfValid(serv, p, iface, isDynamic)),
lastError(checkIfValid(serv, p, iface, isDynamic, (connectionPrivate() &&
connectionPrivate()->mode == QDBusConnectionPrivate::PeerMode))),
isValid(!lastError.isValid())
{
if (!isValid)
@@ -107,7 +108,7 @@ bool QDBusAbstractInterfacePrivate::canMakeCalls() const
{
// recheck only if we have a wildcard (i.e. empty) service or path
// if any are empty, set the error message according to QDBusUtil
if (service.isEmpty())
if (service.isEmpty() && connectionPrivate()->mode != QDBusConnectionPrivate::PeerMode)
return QDBusUtil::checkBusName(service, QDBusUtil::EmptyNotAllowed, &lastError);
if (path.isEmpty())
return QDBusUtil::checkObjectPath(path, QDBusUtil::EmptyNotAllowed, &lastError);
93 changes: 68 additions & 25 deletions src/dbus/qdbusconnection.cpp
Original file line number Diff line number Diff line change
@@ -52,34 +52,14 @@
#include "qdbusconnection_p.h"
#include "qdbusinterface_p.h"
#include "qdbusutil_p.h"
#include "qdbusconnectionmanager_p.h"

#include "qdbusthreaddebug_p.h"

#ifndef QT_NO_DBUS

QT_BEGIN_NAMESPACE

class QDBusConnectionManager
{
public:
QDBusConnectionManager() {}
~QDBusConnectionManager();

QDBusConnectionPrivate *connection(const QString &name) const;
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;

mutable QMutex senderMutex;
QString senderName; // internal; will probably change
};

Q_GLOBAL_STATIC(QDBusConnectionManager, _q_manager)

QDBusConnectionPrivate *QDBusConnectionManager::sender() const
@@ -126,6 +106,11 @@ QDBusConnectionManager::~QDBusConnectionManager()
connectionHash.clear();
}

QDBusConnectionManager* QDBusConnectionManager::instance()
{
return _q_manager();
}

Q_DBUS_EXPORT void qDBusBindToApplication();
void qDBusBindToApplication()
{
@@ -371,15 +356,15 @@ QDBusConnection QDBusConnection::connectToBus(BusType type, const QString &name)
}

/*!
Opens a peer-to-peer connection on address \a address and associate with it the
Opens a connection to a private bus on address \a address and associate with it the
connection name \a name. Returns a QDBusConnection object associated with that connection.
*/
QDBusConnection QDBusConnection::connectToBus(const QString &address,
const QString &name)
{
// Q_ASSERT_X(QCoreApplication::instance(), "QDBusConnection::addConnection",
// "Cannot create connection without a Q[Core]Application instance");
if (!qdbus_loadLibDBus()){
if (!qdbus_loadLibDBus()) {
QDBusConnectionPrivate *d = 0;
return QDBusConnection(d);
}
@@ -411,9 +396,43 @@ QDBusConnection QDBusConnection::connectToBus(const QString &address,

return retval;
}
/*!
\since 4.8
Opens a peer-to-peer connection on address \a address and associate with it the
connection name \a name. Returns a QDBusConnection object associated with that connection.
*/
QDBusConnection QDBusConnection::connectToPeer(const QString &address,
const QString &name)
{
// Q_ASSERT_X(QCoreApplication::instance(), "QDBusConnection::addConnection",
// "Cannot create connection without a Q[Core]Application instance");
if (!qdbus_loadLibDBus()) {
QDBusConnectionPrivate *d = 0;
return QDBusConnection(d);
}

QMutexLocker locker(&_q_manager()->mutex);

QDBusConnectionPrivate *d = _q_manager()->connection(name);
if (d || name.isEmpty())
return QDBusConnection(d);

d = new QDBusConnectionPrivate;
// setPeer does the error handling for us
QDBusErrorInternal error;
DBusConnection *c = q_dbus_connection_open_private(address.toUtf8().constData(), error);

d->setPeer(c, error);
_q_manager()->setConnection(name, d);

QDBusConnection retval(d);

return retval;
}

/*!
Closes the connection of name \a name.
Closes the bus connection of name \a name.
Note that if there are still QDBusConnection objects associated
with the same connection, the connection will not be closed until
@@ -424,6 +443,30 @@ void QDBusConnection::disconnectFromBus(const QString &name)
{
if (_q_manager()) {
QMutexLocker locker(&_q_manager()->mutex);
QDBusConnectionPrivate *d = _q_manager()->connection(name);
if (d && d->mode != QDBusConnectionPrivate::ClientMode)
return;
_q_manager()->removeConnection(name);
}
}

/*!
\since 4.8
Closes the peer connection of name \a name.
Note that if there are still QDBusConnection objects associated
with the same connection, the connection will not be closed until
all references are dropped. However, no further references can be
created using the QDBusConnection constructor.
*/
void QDBusConnection::disconnectFromPeer(const QString &name)
{
if (_q_manager()) {
QMutexLocker locker(&_q_manager()->mutex);
QDBusConnectionPrivate *d = _q_manager()->connection(name);
if (d && d->mode != QDBusConnectionPrivate::PeerMode)
return;
_q_manager()->removeConnection(name);
}
}
@@ -814,7 +857,7 @@ void QDBusConnection::unregisterObject(const QString &path, UnregisterMode mode)

// find the object
while (node) {
if (pathComponents.count() == i) {
if (pathComponents.count() == i || !path.compare(QLatin1String("/"))) {
// found it
node->obj = 0;
node->flags = 0;
2 changes: 2 additions & 0 deletions src/dbus/qdbusconnection.h
Original file line number Diff line number Diff line change
@@ -172,7 +172,9 @@ class Q_DBUS_EXPORT QDBusConnection

static QDBusConnection connectToBus(BusType type, const QString &name);
static QDBusConnection connectToBus(const QString &address, const QString &name);
static QDBusConnection connectToPeer(const QString &address, const QString &name);
static void disconnectFromBus(const QString &name);
static void disconnectFromPeer(const QString &name);

static QDBusConnection sessionBus();
static QDBusConnection systemBus();
2 changes: 1 addition & 1 deletion src/dbus/qdbusconnection_p.h
Original file line number Diff line number Diff line change
@@ -216,7 +216,7 @@ class QDBusConnectionPrivate: public QObject

inline void serverConnection(const QDBusConnection &connection)
{ emit newServerConnection(connection); }

private:
void checkThread();
bool handleError(const QDBusErrorInternal &error);
88 changes: 88 additions & 0 deletions src/dbus/qdbusconnectionmanager_p.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/****************************************************************************
**
** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the QtDBus module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/

//
// W A R N I N G
// -------------
//
// This file is not part of the public API. This header file may
// change from version to version without notice, or even be
// removed.
//
// We mean it.
//
//

#ifndef QDBUSCONNECTIONMANAGER_P_H
#define QDBUSCONNECTIONMANAGER_P_H

#include "qdbusconnection_p.h"

#ifndef QT_NO_DBUS

QT_BEGIN_NAMESPACE

class QDBusConnectionManager
{
public:
QDBusConnectionManager() {}
~QDBusConnectionManager();
static QDBusConnectionManager* instance();

QDBusConnectionPrivate *connection(const QString &name) const;
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;

mutable QMutex senderMutex;
QString senderName; // internal; will probably change
};

QT_END_NAMESPACE

#endif // QT_NO_DBUS
#endif
Loading

0 comments on commit 685df07

Please sign in to comment.