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
93 changes: 48 additions & 45 deletions src/dbus/qdbusintegrator.cpp
Original file line number Diff line number Diff line change
@@ -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);
25 changes: 20 additions & 5 deletions src/dbus/qdbusserver.cpp
Original file line number Diff line number Diff line change
@@ -41,6 +41,7 @@

#include "qdbusserver.h"
#include "qdbusconnection_p.h"
#include "qdbusconnectionmanager_p.h"

#ifndef QT_NO_DBUS

@@ -62,23 +63,36 @@ QT_BEGIN_NAMESPACE
QDBusServer::QDBusServer(const QString &address, QObject *parent)
: QObject(parent)
{
if (address.isEmpty())
return;

if (!qdbus_loadLibDBus()) {
d = 0;
return;
}
d = new QDBusConnectionPrivate(this);

if (address.isEmpty())
return;
QMutexLocker locker(&QDBusConnectionManager::instance()->mutex);
QDBusConnectionManager::instance()->setConnection(QLatin1String("QDBusServer-") + QString::number(reinterpret_cast<qulonglong>(d)), d);

QObject::connect(d, SIGNAL(newServerConnection(QDBusConnection)),
this, SIGNAL(newConnection(QDBusConnection)));

// server = q_dbus_server_listen( "unix:tmpdir=/tmp", &error);
QDBusErrorInternal error;
d->setServer(q_dbus_server_listen(address.toUtf8().constData(), error), error);
}

/*!
Destructs a QDBusServer
*/
QDBusServer::~QDBusServer()
{
if (QDBusConnectionManager::instance()) {
QMutexLocker locker(&QDBusConnectionManager::instance()->mutex);
QDBusConnectionManager::instance()->removeConnection(d->name);
}
}

/*!
Returns true if this QDBusServer object is connected.
@@ -113,11 +127,12 @@ QString QDBusServer::address() const

return addr;
}

/*!
\fn void QDBusServer::newConnection(const QDBusConnection &connection)
This signal is currently not used, but if and when it is
used, \a connection will be the new connection.
This signal is emitted when a new client connection \a connection is
established to the server.
*/

QT_END_NAMESPACE
3 changes: 2 additions & 1 deletion src/dbus/qdbusserver.h
Original file line number Diff line number Diff line change
@@ -61,7 +61,8 @@ class Q_DBUS_EXPORT QDBusServer: public QObject
{
Q_OBJECT
public:
QDBusServer(const QString &address, QObject *parent = 0);
QDBusServer(const QString &address = "unix:tmpdir=/tmp", QObject *parent = 0);
virtual ~QDBusServer();

bool isConnected() const;
QDBusError lastError() const;
286 changes: 286 additions & 0 deletions tests/auto/qdbusabstractadaptor/myobject.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,286 @@
/****************************************************************************
**
** 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 test suite 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$
**
****************************************************************************/

#ifndef MYOBJECT_H
#define MYOBJECT_H

#include <QtCore/QObject>
#include <QtDBus/QtDBus>

extern const char *slotSpy;
extern QString valueSpy;

class QDBusSignalSpy: public QObject
{
Q_OBJECT

public slots:
void slot(const QDBusMessage &msg)
{
++count;
interface = msg.interface();
name = msg.member();
signature = msg.signature();
path = msg.path();
value.clear();
if (msg.arguments().count())
value = msg.arguments().at(0);
}

public:
QDBusSignalSpy() : count(0) { }

int count;
QString interface;
QString name;
QString signature;
QString path;
QVariant value;
};

class Interface1: public QDBusAbstractAdaptor
{
Q_OBJECT
Q_CLASSINFO("D-Bus Interface", "local.Interface1")
public:
Interface1(QObject *parent) : QDBusAbstractAdaptor(parent)
{ }
};

class Interface2: public QDBusAbstractAdaptor
{
Q_OBJECT
Q_CLASSINFO("D-Bus Interface", "local.Interface2")
Q_PROPERTY(QString prop1 READ prop1)
Q_PROPERTY(QString prop2 READ prop2 WRITE setProp2 SCRIPTABLE true)
Q_PROPERTY(QUrl nonDBusProperty READ nonDBusProperty)
public:
Interface2(QObject *parent) : QDBusAbstractAdaptor(parent)
{ setAutoRelaySignals(true); }

QString prop1() const
{ return QLatin1String("QString Interface2::prop1() const"); }

QString prop2() const
{ return QLatin1String("QString Interface2::prop2() const"); }

void setProp2(const QString &value)
{
slotSpy = "void Interface2::setProp2(const QString &)";
valueSpy = value;
}

QUrl nonDBusProperty() const
{ return QUrl(); }

void emitSignal(const QString &, const QVariant &)
{ emit signal(); }

public slots:
void method()
{
slotSpy = "void Interface2::method()";
}

Q_SCRIPTABLE void scriptableMethod()
{
slotSpy = "void Interface2::scriptableMethod()";
}

signals:
void signal();
};

class Interface3: public QDBusAbstractAdaptor
{
Q_OBJECT
Q_CLASSINFO("D-Bus Interface", "local.Interface3")
Q_PROPERTY(QString prop1 READ prop1)
Q_PROPERTY(QString prop2 READ prop2 WRITE setProp2)
Q_PROPERTY(QString interface3prop READ interface3prop)
public:
Interface3(QObject *parent) : QDBusAbstractAdaptor(parent)
{ setAutoRelaySignals(true); }

QString prop1() const
{ return QLatin1String("QString Interface3::prop1() const"); }

QString prop2() const
{ return QLatin1String("QString Interface3::prop2() const"); }

void setProp2(const QString &value)
{
slotSpy = "void Interface3::setProp2(const QString &)";
valueSpy = value;
}

QString interface3prop() const
{ return QLatin1String("QString Interface3::interface3prop() const"); }

void emitSignal(const QString &name, const QVariant &value)
{
if (name == "signalVoid")
emit signalVoid();
else if (name == "signalInt")
emit signalInt(value.toInt());
else if (name == "signalString")
emit signalString(value.toString());
}

public slots:
void methodVoid() { slotSpy = "void Interface3::methodVoid()"; }
void methodInt(int) { slotSpy = "void Interface3::methodInt(int)"; }
void methodString(QString) { slotSpy = "void Interface3::methodString(QString)"; }

int methodStringString(const QString &s, QString &out)
{
slotSpy = "int Interface3::methodStringString(const QString &, QString &)";
out = s;
return 42;
}

signals:
void signalVoid();
void signalInt(int);
void signalString(const QString &);
};

class Interface4: public QDBusAbstractAdaptor
{
Q_OBJECT
Q_CLASSINFO("D-Bus Interface", "local.Interface4")
Q_PROPERTY(QString prop1 READ prop1)
Q_PROPERTY(QString prop2 READ prop2 WRITE setProp2)
Q_PROPERTY(QString interface4prop READ interface4prop)
public:
Interface4(QObject *parent) : QDBusAbstractAdaptor(parent)
{ setAutoRelaySignals(true); }

QString prop1() const
{ return QLatin1String("QString Interface4::prop1() const"); }

QString prop2() const
{ return QLatin1String("QString Interface4::prop2() const"); }

QString interface4prop() const
{ return QLatin1String("QString Interface4::interface4prop() const"); }

void setProp2(const QString &value)
{
slotSpy = "void Interface4::setProp2(const QString &)";
valueSpy = value;
}

void emitSignal(const QString &, const QVariant &value)
{
switch (value.type())
{
case QVariant::Invalid:
emit signal();
break;
case QVariant::Int:
emit signal(value.toInt());
break;
case QVariant::String:
emit signal(value.toString());
break;
default:
break;
}
}

public slots:
void method() { slotSpy = "void Interface4::method()"; }
void method(int) { slotSpy = "void Interface4::method(int)"; }
void method(QString) { slotSpy = "void Interface4::method(QString)"; }

signals:
void signal();
void signal(int);
void signal(const QString &);
};

class MyObject: public QObject
{
Q_OBJECT
Q_CLASSINFO("D-Bus Interface", "local.MyObject")
public:
Interface1 *if1;
Interface2 *if2;
Interface3 *if3;
Interface4 *if4;

MyObject(int n = 4)
: if1(0), if2(0), if3(0), if4(0)
{
switch (n)
{
case 4:
if4 = new Interface4(this);
case 3:
if3 = new Interface3(this);
case 2:
if2 = new Interface2(this);
case 1:
if1 = new Interface1(this);
}
}

void emitSignal(const QString &name, const QVariant &value)
{
if (name == "scriptableSignalVoid")
emit scriptableSignalVoid();
else if (name == "scriptableSignalInt")
emit scriptableSignalInt(value.toInt());
else if (name == "scriptableSignalString")
emit scriptableSignalString(value.toString());
else if (name == "nonScriptableSignalVoid")
emit nonScriptableSignalVoid();
}

signals:
Q_SCRIPTABLE void scriptableSignalVoid();
Q_SCRIPTABLE void scriptableSignalInt(int);
Q_SCRIPTABLE void scriptableSignalString(QString);
void nonScriptableSignalVoid();
};

#endif // MYOBJECT_H
9 changes: 4 additions & 5 deletions tests/auto/qdbusabstractadaptor/qdbusabstractadaptor.pro
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
load(qttest_p4)
QT = core
contains(QT_CONFIG,dbus): {
SOURCES += tst_qdbusabstractadaptor.cpp
QT += dbus
TEMPLATE = subdirs
CONFIG += ordered
SUBDIRS = qmyserver test
} else {
SOURCES += ../qdbusmarshall/dummy.cpp
SOURCES += ../qdbusmarshall/dummy.cpp
}


167 changes: 167 additions & 0 deletions tests/auto/qdbusabstractadaptor/qmyserver/qmyserver.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
/****************************************************************************
**
** 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 test suite 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$
**
****************************************************************************/
#include <QtCore/QtCore>
#include <QtDBus/QtDBus>

#include "../myobject.h"

static const char serviceName[] = "com.trolltech.autotests.qmyserver";
static const char objectPath[] = "/com/trolltech/qmyserver";
//static const char *interfaceName = serviceName;

const char *slotSpy;
QString valueSpy;

Q_DECLARE_METATYPE(QDBusConnection::RegisterOptions)

class MyServer : public QDBusServer
{
Q_OBJECT
Q_CLASSINFO("D-Bus Interface", "com.trolltech.autotests.qmyserver")

public:
MyServer(QString addr = "unix:tmpdir=/tmp", QObject* parent = 0)
: QDBusServer(addr, parent),
m_conn("none"),
obj(NULL)
{
connect(this, SIGNAL(newConnection(const QDBusConnection&)), SLOT(handleConnection(const QDBusConnection&)));
}

~MyServer()
{
if (obj)
obj->deleteLater();
}

public slots:
QString address() const
{
return QDBusServer::address();
}

bool isConnected() const
{
return m_conn.isConnected();
}

void emitSignal(const QString& interface, const QString& name, const QDBusVariant& parameter)
{
if (interface.endsWith('2'))
obj->if2->emitSignal(name, parameter.variant());
else if (interface.endsWith('3'))
obj->if3->emitSignal(name, parameter.variant());
else if (interface.endsWith('4'))
obj->if4->emitSignal(name, parameter.variant());
else
obj->emitSignal(name, parameter.variant());
}

void emitSignal2(const QString& interface, const QString& name)
{
if (interface.endsWith('2'))
obj->if2->emitSignal(name, QVariant());
else if (interface.endsWith('3'))
obj->if3->emitSignal(name, QVariant());
else if (interface.endsWith('4'))
obj->if4->emitSignal(name, QVariant());
else
obj->emitSignal(name, QVariant());
}

void newMyObject(int nInterfaces = 4)
{
if (obj)
obj->deleteLater();
obj = new MyObject(nInterfaces);
}

void registerMyObject(const QString & path, int options)
{
m_conn.registerObject(path, obj, (QDBusConnection::RegisterOptions)options);
}

QString slotSpyServer()
{
return QLatin1String(slotSpy);
}

QString valueSpyServer()
{
return valueSpy;
}

void clearValueSpy()
{
valueSpy.clear();
}

private slots:
void handleConnection(const QDBusConnection& con)
{
m_conn = con;
}

private:
QDBusConnection m_conn;
MyObject* obj;
};

int main(int argc, char *argv[])
{
QCoreApplication app(argc, argv);

QDBusConnection con = QDBusConnection::sessionBus();
if (!con.isConnected())
exit(1);

if (!con.registerService(serviceName))
exit(2);

MyServer server;
con.registerObject(objectPath, &server, QDBusConnection::ExportAllSlots);

printf("ready.\n");

return app.exec();
}

#include "qmyserver.moc"
5 changes: 5 additions & 0 deletions tests/auto/qdbusabstractadaptor/qmyserver/qmyserver.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
SOURCES = qmyserver.cpp
HEADERS = ../myobject.h
TARGET = qmyserver
QT += dbus
QT -= gui
7 changes: 7 additions & 0 deletions tests/auto/qdbusabstractadaptor/test/test.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
load(qttest_p4)
SOURCES += ../tst_qdbusabstractadaptor.cpp
HEADERS += ../myobject.h
TARGET = ../tst_qdbusabstractadaptor

QT = core
QT += dbus
1,091 changes: 771 additions & 320 deletions tests/auto/qdbusabstractadaptor/tst_qdbusabstractadaptor.cpp

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -24,7 +24,7 @@
</method>
<method name="multiOutMethod">
<arg type="s" direction="out"/>
<arg type="i" direction="out"/
<arg type="i" direction="out"/>
</method>
</interface>
</node>
1 change: 1 addition & 0 deletions tests/auto/qdbusabstractinterface/interface.h
Original file line number Diff line number Diff line change
@@ -84,6 +84,7 @@ class Interface: public QObject
Q_PROPERTY(RegisteredType complexProp READ complexProp WRITE setComplexProp SCRIPTABLE true)

friend class tst_QDBusAbstractInterface;
friend class PingerServer;
QString m_stringProp;
QDBusVariant m_variantProp;
RegisteredType m_complexProp;
17 changes: 6 additions & 11 deletions tests/auto/qdbusabstractinterface/qdbusabstractinterface.pro
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
load(qttest_p4)
QT = core
contains(QT_CONFIG,dbus): {
SOURCES += tst_qdbusabstractinterface.cpp interface.cpp
HEADERS += interface.h
QT += dbus

# These are generated sources
# To regenerate, see the command-line at the top of the files
SOURCES += pinger.cpp
HEADERS += pinger.h
contains(QT_CONFIG,dbus): {
TEMPLATE = subdirs
CONFIG += ordered
SUBDIRS = qpinger test
} else {
SOURCES += ../qdbusmarshall/dummy.cpp
}
else:SOURCES += ../qdbusmarshall/dummy.cpp

OTHER_FILES += com.trolltech.QtDBus.Pinger.xml
131 changes: 131 additions & 0 deletions tests/auto/qdbusabstractinterface/qpinger/qpinger.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
/****************************************************************************
**
** 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 test suite 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$
**
****************************************************************************/
#include <QtCore/QtCore>
#include <QtDBus/QtDBus>
#include "../interface.h"

static const char serviceName[] = "com.trolltech.autotests.qpinger";
static const char objectPath[] = "/com/trolltech/qpinger";
//static const char *interfaceName = serviceName;

class PingerServer : public QDBusServer
{
Q_OBJECT
Q_CLASSINFO("D-Bus Interface", "com.trolltech.autotests.qpinger")
public:
PingerServer(QString addr = "unix:tmpdir=/tmp", QObject* parent = 0)
: QDBusServer(addr, parent),
m_conn("none")
{
connect(this, SIGNAL(newConnection(const QDBusConnection&)), SLOT(handleConnection(const QDBusConnection&)));
reset();
}

public slots:
QString address() const
{
return QDBusServer::address();
}

bool isConnected() const
{
return m_conn.isConnected();
}

void reset()
{
targetObj.m_stringProp = "This is a test";
targetObj.m_variantProp = QDBusVariant(QVariant(42));
targetObj.m_complexProp = RegisteredType("This is a test");
}

void voidSignal()
{
emit targetObj.voidSignal();
}

void stringSignal(const QString& value)
{
emit targetObj.stringSignal(value);
}

void complexSignal(const QString& value)
{
RegisteredType reg(value);
emit targetObj.complexSignal(reg);
}

private slots:
void handleConnection(const QDBusConnection& con)
{
m_conn = con;
m_conn.registerObject("/", &targetObj, QDBusConnection::ExportScriptableContents);
}

private:
Interface targetObj;
QDBusConnection m_conn;
};

int main(int argc, char *argv[])
{
QCoreApplication app(argc, argv);

// register the meta types
qDBusRegisterMetaType<RegisteredType>();
qRegisterMetaType<UnregisteredType>();

QDBusConnection con = QDBusConnection::sessionBus();
if (!con.isConnected())
exit(1);

if (!con.registerService(serviceName))
exit(2);

PingerServer server;
con.registerObject(objectPath, &server, QDBusConnection::ExportAllSlots);

printf("ready.\n");

return app.exec();
}

#include "qpinger.moc"
5 changes: 5 additions & 0 deletions tests/auto/qdbusabstractinterface/qpinger/qpinger.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
SOURCES = qpinger.cpp ../interface.cpp
HEADERS = ../interface.h
TARGET = qpinger
QT += dbus
QT -= gui
13 changes: 13 additions & 0 deletions tests/auto/qdbusabstractinterface/test/test.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
load(qttest_p4)
SOURCES += ../tst_qdbusabstractinterface.cpp ../interface.cpp
HEADERS += ../interface.h

# These are generated sources
# To regenerate, see the command-line at the top of the files
SOURCES += ../pinger.cpp
HEADERS += ../pinger.h

TARGET = ../tst_qdbusabstractinterface

QT = core
QT += dbus
573 changes: 573 additions & 0 deletions tests/auto/qdbusabstractinterface/tst_qdbusabstractinterface.cpp

Large diffs are not rendered by default.

382 changes: 382 additions & 0 deletions tests/auto/qdbusconnection/tst_qdbusconnection.cpp

Large diffs are not rendered by default.

164 changes: 164 additions & 0 deletions tests/auto/qdbusinterface/myobject.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
/****************************************************************************
**
** 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 test suite 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$
**
****************************************************************************/

#ifndef MYOBJECT_H
#define MYOBJECT_H

#include <QtCore/QObject>
#include <QtDBus/QtDBus>

Q_DECLARE_METATYPE(QVariantList)

class MyObject: public QObject
{
Q_OBJECT
Q_CLASSINFO("D-Bus Interface", "com.trolltech.QtDBus.MyObject")
Q_CLASSINFO("D-Bus Introspection", ""
" <interface name=\"com.trolltech.QtDBus.MyObject\" >\n"
" <property access=\"readwrite\" type=\"i\" name=\"prop1\" />\n"
" <property name=\"complexProp\" type=\"ai\" access=\"readwrite\">\n"
" <annotation name=\"com.trolltech.QtDBus.QtTypeName\" value=\"QList&lt;int&gt;\"/>\n"
" </property>\n"
" <signal name=\"somethingHappened\" >\n"
" <arg direction=\"out\" type=\"s\" />\n"
" </signal>\n"
" <method name=\"ping\" >\n"
" <arg direction=\"in\" type=\"v\" name=\"ping\" />\n"
" <arg direction=\"out\" type=\"v\" name=\"ping\" />\n"
" </method>\n"
" <method name=\"ping_invokable\" >\n"
" <arg direction=\"in\" type=\"v\" name=\"ping_invokable\" />\n"
" <arg direction=\"out\" type=\"v\" name=\"ping_invokable\" />\n"
" </method>\n"
" <method name=\"ping\" >\n"
" <arg direction=\"in\" type=\"v\" name=\"ping1\" />\n"
" <arg direction=\"in\" type=\"v\" name=\"ping2\" />\n"
" <arg direction=\"out\" type=\"v\" name=\"pong1\" />\n"
" <arg direction=\"out\" type=\"v\" name=\"pong2\" />\n"
" </method>\n"
" <method name=\"ping_invokable\" >\n"
" <arg direction=\"in\" type=\"v\" name=\"ping1_invokable\" />\n"
" <arg direction=\"in\" type=\"v\" name=\"ping2_invokable\" />\n"
" <arg direction=\"out\" type=\"v\" name=\"pong1_invokable\" />\n"
" <arg direction=\"out\" type=\"v\" name=\"pong2_invokable\" />\n"
" </method>\n"
" <method name=\"ping\" >\n"
" <arg direction=\"in\" type=\"ai\" name=\"ping\" />\n"
" <arg direction=\"out\" type=\"ai\" name=\"ping\" />\n"
" <annotation name=\"com.trolltech.QtDBus.QtTypeName.In0\" value=\"QList&lt;int&gt;\"/>\n"
" <annotation name=\"com.trolltech.QtDBus.QtTypeName.Out0\" value=\"QList&lt;int&gt;\"/>\n"
" </method>\n"
" <method name=\"ping_invokable\" >\n"
" <arg direction=\"in\" type=\"ai\" name=\"ping_invokable\" />\n"
" <arg direction=\"out\" type=\"ai\" name=\"ping_invokable\" />\n"
" <annotation name=\"com.trolltech.QtDBus.QtTypeName.In0\" value=\"QList&lt;int&gt;\"/>\n"
" <annotation name=\"com.trolltech.QtDBus.QtTypeName.Out0\" value=\"QList&lt;int&gt;\"/>\n"
" </method>\n"
" </interface>\n"
"")
Q_PROPERTY(int prop1 READ prop1 WRITE setProp1)
Q_PROPERTY(QList<int> complexProp READ complexProp WRITE setComplexProp)

public:
static int callCount;
static QVariantList callArgs;
MyObject()
{
QObject *subObject = new QObject(this);
subObject->setObjectName("subObject");
}

int m_prop1;
int prop1() const
{
++callCount;
return m_prop1;
}
void setProp1(int value)
{
++callCount;
m_prop1 = value;
}

QList<int> m_complexProp;
QList<int> complexProp() const
{
++callCount;
return m_complexProp;
}
void setComplexProp(const QList<int> &value)
{
++callCount;
m_complexProp = value;
}

Q_INVOKABLE void ping_invokable(QDBusMessage msg)
{
QDBusConnection sender = QDBusConnection::sender();
if (!sender.isConnected())
exit(1);

++callCount;
callArgs = msg.arguments();

msg.setDelayedReply(true);
if (!sender.send(msg.createReply(callArgs)))
exit(1);
}

public slots:

void ping(QDBusMessage msg)
{
QDBusConnection sender = QDBusConnection::sender();
if (!sender.isConnected())
exit(1);

++callCount;
callArgs = msg.arguments();

msg.setDelayedReply(true);
if (!sender.send(msg.createReply(callArgs)))
exit(1);
}
};

#endif // INTERFACE_H
7 changes: 4 additions & 3 deletions tests/auto/qdbusinterface/qdbusinterface.pro
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
load(qttest_p4)
QT = core
contains(QT_CONFIG,dbus): {
SOURCES += tst_qdbusinterface.cpp
QT += dbus
TEMPLATE = subdirs
CONFIG += ordered
SUBDIRS = qmyserver test
} else {
SOURCES += ../qdbusmarshall/dummy.cpp
SOURCES += ../qdbusmarshall/dummy.cpp
}


155 changes: 155 additions & 0 deletions tests/auto/qdbusinterface/qmyserver/qmyserver.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
/****************************************************************************
**
** 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 test suite 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$
**
****************************************************************************/
#include <QtCore/QtCore>
#include <QtDBus/QtDBus>

#include "../myobject.h"

static const char serviceName[] = "com.trolltech.autotests.qmyserver";
static const char objectPath[] = "/com/trolltech/qmyserver";
//static const char *interfaceName = serviceName;

int MyObject::callCount = 0;
QVariantList MyObject::callArgs;

class MyServer : public QDBusServer
{
Q_OBJECT
Q_CLASSINFO("D-Bus Interface", "com.trolltech.autotests.qmyserver")

public:
MyServer(QString addr = "unix:tmpdir=/tmp", QObject* parent = 0)
: QDBusServer(addr, parent),
m_conn("none")
{
connect(this, SIGNAL(newConnection(const QDBusConnection&)), SLOT(handleConnection(const QDBusConnection&)));
}

public slots:
QString address() const
{
return QDBusServer::address();
}

bool isConnected() const
{
return m_conn.isConnected();
}

void emitSignal(const QString &interface, const QString &name, const QString &arg)
{
QDBusMessage msg = QDBusMessage::createSignal("/", interface, name);
msg << arg;
m_conn.send(msg);
}

void reset()
{
MyObject::callCount = 0;
obj.m_complexProp.clear();
}

int callCount()
{
return MyObject::callCount;
}

QVariantList callArgs()
{
qDebug() << "callArgs" << MyObject::callArgs.count();
return MyObject::callArgs;
}

void setProp1(int val)
{
obj.m_prop1 = val;
}

int prop1()
{
return obj.m_prop1;
}

void setComplexProp(QList<int> val)
{
obj.m_complexProp = val;
}

QList<int> complexProp()
{
return obj.m_complexProp;
}


private slots:
void handleConnection(const QDBusConnection& con)
{
m_conn = con;
m_conn.registerObject("/", &obj, QDBusConnection::ExportAllProperties
| QDBusConnection::ExportAllSlots
| QDBusConnection::ExportAllInvokables);
}

private:
QDBusConnection m_conn;
MyObject obj;
};

int main(int argc, char *argv[])
{
QCoreApplication app(argc, argv);

QDBusConnection con = QDBusConnection::sessionBus();
if (!con.isConnected())
exit(1);

if (!con.registerService(serviceName))
exit(2);

MyServer server;
con.registerObject(objectPath, &server, QDBusConnection::ExportAllSlots);

printf("ready.\n");

return app.exec();
}

#include "qmyserver.moc"
5 changes: 5 additions & 0 deletions tests/auto/qdbusinterface/qmyserver/qmyserver.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
SOURCES = qmyserver.cpp
HEADERS = ../myobject.h
TARGET = qmyserver
QT += dbus
QT -= gui
7 changes: 7 additions & 0 deletions tests/auto/qdbusinterface/test/test.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
load(qttest_p4)
SOURCES += ../tst_qdbusinterface.cpp
HEADERS += ../myobject.h
TARGET = ../tst_qdbusinterface

QT = core
QT += dbus
629 changes: 505 additions & 124 deletions tests/auto/qdbusinterface/tst_qdbusinterface.cpp

Large diffs are not rendered by default.

0 comments on commit 685df07

Please sign in to comment.