summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndre Moreira Magalhaes (andrunko) <andre.magalhaes@collabora.co.uk>2012-04-04 11:17:39 -0300
committerAndre Moreira Magalhaes (andrunko) <andre.magalhaes@collabora.co.uk>2012-04-04 11:17:39 -0300
commit7e993408ddaf5ead064f86a5cfe59f1be3a93329 (patch)
treedfaced030c11b18de5566d1d0b29d840ba278818
parent6c258da57b40dab608c31b6abdff93d2792bf9c0 (diff)
DBusService: Use DBusObject.
-rw-r--r--TelepathyQt/base-connection-manager.cpp1
-rw-r--r--TelepathyQt/base-connection.cpp1
-rw-r--r--TelepathyQt/base-protocol.cpp39
-rw-r--r--TelepathyQt/base-protocol.h32
-rw-r--r--TelepathyQt/dbus-service.cpp35
-rw-r--r--TelepathyQt/dbus-service.h11
-rw-r--r--examples/cm/protocol.cpp6
7 files changed, 60 insertions, 65 deletions
diff --git a/TelepathyQt/base-connection-manager.cpp b/TelepathyQt/base-connection-manager.cpp
index aa1a35c9..122b608c 100644
--- a/TelepathyQt/base-connection-manager.cpp
+++ b/TelepathyQt/base-connection-manager.cpp
@@ -30,6 +30,7 @@
#include <TelepathyQt/BaseConnection>
#include <TelepathyQt/BaseProtocol>
+#include <TelepathyQt/DBusObject>
#include <TelepathyQt/Constants>
#include <TelepathyQt/Utils>
diff --git a/TelepathyQt/base-connection.cpp b/TelepathyQt/base-connection.cpp
index 1351ff92..87e9c10a 100644
--- a/TelepathyQt/base-connection.cpp
+++ b/TelepathyQt/base-connection.cpp
@@ -29,6 +29,7 @@
#include "TelepathyQt/debug-internal.h"
#include <TelepathyQt/Constants>
+#include <TelepathyQt/DBusObject>
#include <TelepathyQt/Utils>
#include <QString>
diff --git a/TelepathyQt/base-protocol.cpp b/TelepathyQt/base-protocol.cpp
index 9710209d..ae83c7e9 100644
--- a/TelepathyQt/base-protocol.cpp
+++ b/TelepathyQt/base-protocol.cpp
@@ -30,6 +30,7 @@
#include <TelepathyQt/BaseConnection>
#include <TelepathyQt/Constants>
+#include <TelepathyQt/DBusObject>
#include <TelepathyQt/Utils>
#include <QDBusObjectPath>
@@ -352,12 +353,6 @@ bool BaseProtocol::plugInterface(const AbstractProtocolInterfacePtr &interface)
return false;
}
- if (interface->dbusConnection().name() != dbusConnection().name()) {
- warning() << "Unable to plug protocol interface" << interface->interfaceName() <<
- "- interface must have the same D-Bus connection as the owning protocol";
- return false;
- }
-
if (interface->isRegistered()) {
warning() << "Unable to plug protocol interface" << interface->interfaceName() <<
"- interface already registered";
@@ -383,15 +378,18 @@ bool BaseProtocol::registerObject(const QString &busName, const QString &objectP
}
foreach (const AbstractProtocolInterfacePtr &iface, mPriv->interfaces) {
- iface->registerInterface(dbusObject());
+ if (!iface->registerInterface(dbusObject())) {
+ // lets not fail if an optional interface fails registering, lets warn only
+ warning() << "Unable to register interface" << iface->interfaceName() <<
+ "for protocol" << mPriv->name;
+ }
}
return DBusService::registerObject(busName, objectPath, error);
}
// AbstractProtocolInterface
-AbstractProtocolInterface::AbstractProtocolInterface(const QDBusConnection &dbusConnection,
- const QString &interfaceName)
- : AbstractDBusServiceInterface(dbusConnection, interfaceName)
+AbstractProtocolInterface::AbstractProtocolInterface(const QString &interfaceName)
+ : AbstractDBusServiceInterface(interfaceName)
{
}
@@ -463,8 +461,8 @@ struct TP_QT_NO_EXPORT BaseProtocolAddressingInterface::Private
NormalizeContactUriCallback normalizeContactUriCb;
};
-BaseProtocolAddressingInterface::BaseProtocolAddressingInterface(const QDBusConnection &dbusConnection)
- : AbstractProtocolInterface(dbusConnection, TP_QT_IFACE_PROTOCOL_INTERFACE_ADDRESSING),
+BaseProtocolAddressingInterface::BaseProtocolAddressingInterface()
+ : AbstractProtocolInterface(TP_QT_IFACE_PROTOCOL_INTERFACE_ADDRESSING),
mPriv(new Private)
{
}
@@ -534,7 +532,8 @@ QString BaseProtocolAddressingInterface::normalizeContactUri(const QString &uri,
void BaseProtocolAddressingInterface::createAdaptor()
{
Q_ASSERT(!mPriv->adaptee);
- mPriv->adaptee = new BaseProtocolAddressingInterface::Adaptee(dbusConnection(), dbusObject(), this);
+ mPriv->adaptee = new BaseProtocolAddressingInterface::Adaptee(
+ dbusObject()->dbusConnection(), dbusObject(), this);
}
// Proto.I.Avatars
@@ -601,8 +600,8 @@ struct TP_QT_NO_EXPORT BaseProtocolAvatarsInterface::Private
AvatarSpec avatarDetails;
};
-BaseProtocolAvatarsInterface::BaseProtocolAvatarsInterface(const QDBusConnection &dbusConnection)
- : AbstractProtocolInterface(dbusConnection, TP_QT_IFACE_PROTOCOL_INTERFACE_AVATARS),
+BaseProtocolAvatarsInterface::BaseProtocolAvatarsInterface()
+ : AbstractProtocolInterface(TP_QT_IFACE_PROTOCOL_INTERFACE_AVATARS),
mPriv(new Private)
{
}
@@ -644,7 +643,8 @@ void BaseProtocolAvatarsInterface::setAvatarDetails(const AvatarSpec &details)
void BaseProtocolAvatarsInterface::createAdaptor()
{
Q_ASSERT(!mPriv->adaptee);
- mPriv->adaptee = new BaseProtocolAvatarsInterface::Adaptee(dbusConnection(), dbusObject(), this);
+ mPriv->adaptee = new BaseProtocolAvatarsInterface::Adaptee(
+ dbusObject()->dbusConnection(), dbusObject(), this);
}
// Proto.I.Presence
@@ -676,8 +676,8 @@ struct TP_QT_NO_EXPORT BaseProtocolPresenceInterface::Private
PresenceSpecList statuses;
};
-BaseProtocolPresenceInterface::BaseProtocolPresenceInterface(const QDBusConnection &dbusConnection)
- : AbstractProtocolInterface(dbusConnection, TP_QT_IFACE_PROTOCOL_INTERFACE_PRESENCE),
+BaseProtocolPresenceInterface::BaseProtocolPresenceInterface()
+ : AbstractProtocolInterface(TP_QT_IFACE_PROTOCOL_INTERFACE_PRESENCE),
mPriv(new Private)
{
}
@@ -711,7 +711,8 @@ void BaseProtocolPresenceInterface::setStatuses(const PresenceSpecList &statuses
void BaseProtocolPresenceInterface::createAdaptor()
{
Q_ASSERT(!mPriv->adaptee);
- mPriv->adaptee = new BaseProtocolPresenceInterface::Adaptee(dbusConnection(), dbusObject(), this);
+ mPriv->adaptee = new BaseProtocolPresenceInterface::Adaptee(
+ dbusObject()->dbusConnection(), dbusObject(), this);
}
}
diff --git a/TelepathyQt/base-protocol.h b/TelepathyQt/base-protocol.h
index d65251a1..bd1b3ec4 100644
--- a/TelepathyQt/base-protocol.h
+++ b/TelepathyQt/base-protocol.h
@@ -132,7 +132,7 @@ class TP_QT_EXPORT AbstractProtocolInterface : public AbstractDBusServiceInterfa
Q_DISABLE_COPY(AbstractProtocolInterface)
public:
- AbstractProtocolInterface(const QDBusConnection &dbusConnection, const QString &interfaceName);
+ AbstractProtocolInterface(const QString &interfaceName);
virtual ~AbstractProtocolInterface();
protected:
@@ -148,14 +148,14 @@ class TP_QT_EXPORT BaseProtocolAddressingInterface : public AbstractProtocolInte
Q_DISABLE_COPY(BaseProtocolAddressingInterface)
public:
- static BaseProtocolAddressingInterfacePtr create(const QDBusConnection &dbusConnection)
+ static BaseProtocolAddressingInterfacePtr create()
{
- return BaseProtocolAddressingInterfacePtr(new BaseProtocolAddressingInterface(dbusConnection));
+ return BaseProtocolAddressingInterfacePtr(new BaseProtocolAddressingInterface());
}
template<typename BaseProtocolAddressingInterfaceSubclass>
- static BaseProtocolAddressingInterfacePtr create(const QDBusConnection &dbusConnection)
+ static BaseProtocolAddressingInterfacePtr create()
{
- return BaseProtocolAddressingInterfacePtr(new BaseProtocolAddressingInterfaceSubclass(dbusConnection));
+ return BaseProtocolAddressingInterfacePtr(new BaseProtocolAddressingInterfaceSubclass());
}
virtual ~BaseProtocolAddressingInterface();
@@ -177,7 +177,7 @@ public:
QString normalizeContactUri(const QString &uri, DBusError *error);
protected:
- BaseProtocolAddressingInterface(const QDBusConnection &dbusConnection);
+ BaseProtocolAddressingInterface();
private:
void createAdaptor();
@@ -194,14 +194,14 @@ class TP_QT_EXPORT BaseProtocolAvatarsInterface : public AbstractProtocolInterfa
Q_DISABLE_COPY(BaseProtocolAvatarsInterface)
public:
- static BaseProtocolAvatarsInterfacePtr create(const QDBusConnection &dbusConnection)
+ static BaseProtocolAvatarsInterfacePtr create()
{
- return BaseProtocolAvatarsInterfacePtr(new BaseProtocolAvatarsInterface(dbusConnection));
+ return BaseProtocolAvatarsInterfacePtr(new BaseProtocolAvatarsInterface());
}
template<typename BaseProtocolAvatarsInterfaceSubclass>
- static BaseProtocolAvatarsInterfacePtr create(const QDBusConnection &dbusConnection)
+ static BaseProtocolAvatarsInterfacePtr create()
{
- return BaseProtocolAvatarsInterfacePtr(new BaseProtocolAvatarsInterfaceSubclass(dbusConnection));
+ return BaseProtocolAvatarsInterfacePtr(new BaseProtocolAvatarsInterfaceSubclass());
}
virtual ~BaseProtocolAvatarsInterface();
@@ -212,7 +212,7 @@ public:
void setAvatarDetails(const AvatarSpec &spec);
protected:
- BaseProtocolAvatarsInterface(const QDBusConnection &dbusConnection);
+ BaseProtocolAvatarsInterface();
private:
void createAdaptor();
@@ -229,14 +229,14 @@ class TP_QT_EXPORT BaseProtocolPresenceInterface : public AbstractProtocolInterf
Q_DISABLE_COPY(BaseProtocolPresenceInterface)
public:
- static BaseProtocolPresenceInterfacePtr create(const QDBusConnection &dbusConnection)
+ static BaseProtocolPresenceInterfacePtr create()
{
- return BaseProtocolPresenceInterfacePtr(new BaseProtocolPresenceInterface(dbusConnection));
+ return BaseProtocolPresenceInterfacePtr(new BaseProtocolPresenceInterface());
}
template<typename BaseProtocolPresenceInterfaceSubclass>
- static BaseProtocolPresenceInterfacePtr create(const QDBusConnection &dbusConnection)
+ static BaseProtocolPresenceInterfacePtr create()
{
- return BaseProtocolPresenceInterfacePtr(new BaseProtocolPresenceInterfaceSubclass(dbusConnection));
+ return BaseProtocolPresenceInterfacePtr(new BaseProtocolPresenceInterfaceSubclass());
}
virtual ~BaseProtocolPresenceInterface();
@@ -247,7 +247,7 @@ public:
void setStatuses(const PresenceSpecList &statuses);
protected:
- BaseProtocolPresenceInterface(const QDBusConnection &dbusConnection);
+ BaseProtocolPresenceInterface();
private:
void createAdaptor();
diff --git a/TelepathyQt/dbus-service.cpp b/TelepathyQt/dbus-service.cpp
index 1ba4b44f..769ac511 100644
--- a/TelepathyQt/dbus-service.cpp
+++ b/TelepathyQt/dbus-service.cpp
@@ -27,6 +27,7 @@
#include "TelepathyQt/debug-internal.h"
#include <TelepathyQt/Constants>
+#include <TelepathyQt/DBusObject>
#include <QDBusConnection>
#include <QString>
@@ -38,17 +39,15 @@ struct TP_QT_NO_EXPORT DBusService::Private
{
Private(DBusService *parent, const QDBusConnection &dbusConnection)
: parent(parent),
- dbusConnection(dbusConnection),
- dbusObject(new QObject(parent)),
+ dbusObject(new DBusObject(dbusConnection, parent)),
registered(false)
{
}
DBusService *parent;
- QDBusConnection dbusConnection;
QString busName;
QString objectPath;
- QObject *dbusObject;
+ DBusObject *dbusObject;
bool registered;
};
@@ -64,7 +63,7 @@ DBusService::~DBusService()
QDBusConnection DBusService::dbusConnection() const
{
- return mPriv->dbusConnection;
+ return mPriv->dbusObject->dbusConnection();
}
QString DBusService::busName() const
@@ -77,7 +76,7 @@ QString DBusService::objectPath() const
return mPriv->objectPath;
}
-QObject *DBusService::dbusObject() const
+DBusObject *DBusService::dbusObject() const
{
return mPriv->dbusObject;
}
@@ -94,7 +93,7 @@ bool DBusService::registerObject(const QString &busName, const QString &objectPa
return true;
}
- if (!mPriv->dbusConnection.registerService(busName)) {
+ if (!mPriv->dbusObject->dbusConnection().registerService(busName)) {
error->set(TP_QT_ERROR_INVALID_ARGUMENT,
QString(QLatin1String("Name %s already in use by another process"))
.arg(busName));
@@ -103,7 +102,7 @@ bool DBusService::registerObject(const QString &busName, const QString &objectPa
return false;
}
- if (!mPriv->dbusConnection.registerObject(objectPath, mPriv->dbusObject)) {
+ if (!mPriv->dbusObject->dbusConnection().registerObject(objectPath, mPriv->dbusObject)) {
error->set(TP_QT_ERROR_INVALID_ARGUMENT,
QString(QLatin1String("Object at path %s already registered"))
.arg(objectPath));
@@ -122,23 +121,20 @@ bool DBusService::registerObject(const QString &busName, const QString &objectPa
struct AbstractDBusServiceInterface::Private
{
- Private(const QDBusConnection &dbusConnection, const QString &interfaceName)
+ Private(const QString &interfaceName)
: interfaceName(interfaceName),
- dbusConnection(dbusConnection),
dbusObject(0),
registered(false)
{
}
QString interfaceName;
- QDBusConnection dbusConnection;
- QObject *dbusObject;
+ DBusObject *dbusObject;
bool registered;
};
-AbstractDBusServiceInterface::AbstractDBusServiceInterface(const QDBusConnection &dbusConnection,
- const QString &interfaceName)
- : mPriv(new Private(dbusConnection, interfaceName))
+AbstractDBusServiceInterface::AbstractDBusServiceInterface(const QString &interfaceName)
+ : mPriv(new Private(interfaceName))
{
}
@@ -152,12 +148,7 @@ QString AbstractDBusServiceInterface::interfaceName() const
return mPriv->interfaceName;
}
-QDBusConnection AbstractDBusServiceInterface::dbusConnection() const
-{
- return mPriv->dbusConnection;
-}
-
-QObject *AbstractDBusServiceInterface::dbusObject() const
+DBusObject *AbstractDBusServiceInterface::dbusObject() const
{
return mPriv->dbusObject;
}
@@ -167,7 +158,7 @@ bool AbstractDBusServiceInterface::isRegistered() const
return mPriv->registered;
}
-bool AbstractDBusServiceInterface::registerInterface(QObject *dbusObject)
+bool AbstractDBusServiceInterface::registerInterface(DBusObject *dbusObject)
{
if (mPriv->registered) {
return true;
diff --git a/TelepathyQt/dbus-service.h b/TelepathyQt/dbus-service.h
index 11a68a51..81b09162 100644
--- a/TelepathyQt/dbus-service.h
+++ b/TelepathyQt/dbus-service.h
@@ -40,6 +40,8 @@ class QString;
namespace Tp
{
+class DBusObject;
+
class TP_QT_EXPORT DBusService : public Object
{
Q_OBJECT
@@ -54,7 +56,7 @@ public:
QDBusConnection dbusConnection() const;
QString busName() const;
QString objectPath() const;
- QObject *dbusObject() const;
+ DBusObject *dbusObject() const;
bool isRegistered() const;
protected:
@@ -73,19 +75,18 @@ class TP_QT_EXPORT AbstractDBusServiceInterface : public Object
Q_DISABLE_COPY(AbstractDBusServiceInterface)
public:
- AbstractDBusServiceInterface(const QDBusConnection &dbusConnection, const QString &interfaceName);
+ AbstractDBusServiceInterface(const QString &interfaceName);
virtual ~AbstractDBusServiceInterface();
QString interfaceName() const;
virtual QVariantMap immutableProperties() const = 0;
- QDBusConnection dbusConnection() const;
- QObject *dbusObject() const;
+ DBusObject *dbusObject() const;
bool isRegistered() const;
protected:
- virtual bool registerInterface(QObject *dbusObject);
+ virtual bool registerInterface(DBusObject *dbusObject);
virtual void createAdaptor() = 0;
private:
diff --git a/examples/cm/protocol.cpp b/examples/cm/protocol.cpp
index 01ab53a1..08e4a3b5 100644
--- a/examples/cm/protocol.cpp
+++ b/examples/cm/protocol.cpp
@@ -51,14 +51,14 @@ Protocol::Protocol(const QDBusConnection &dbusConnection, const QString &name)
setIdentifyAccountCallback(memFun(this, &Protocol::identifyAccount));
setNormalizeContactCallback(memFun(this, &Protocol::normalizeContact));
- addrIface = BaseProtocolAddressingInterface::create(dbusConnection);
+ addrIface = BaseProtocolAddressingInterface::create();
addrIface->setAddressableVCardFields(QStringList() << QLatin1String("x-example-vcard-field"));
addrIface->setAddressableUriSchemes(QStringList() << QLatin1String("example-uri-scheme"));
addrIface->setNormalizeVCardAddressCallback(memFun(this, &Protocol::normalizeVCardAddress));
addrIface->setNormalizeContactUriCallback(memFun(this, &Protocol::normalizeContactUri));
plugInterface(AbstractProtocolInterfacePtr::dynamicCast(addrIface));
- avatarsIface = BaseProtocolAvatarsInterface::create(dbusConnection);
+ avatarsIface = BaseProtocolAvatarsInterface::create();
avatarsIface->setAvatarDetails(AvatarSpec(QStringList() << QLatin1String("image/png"),
16, 64, 32, 16, 64, 32, 1024));
plugInterface(AbstractProtocolInterfacePtr::dynamicCast(avatarsIface));
@@ -77,7 +77,7 @@ Protocol::Protocol(const QDBusConnection &dbusConnection, const QString &name)
specs.insert(QLatin1String("available"), spAvailable);
specs.insert(QLatin1String("offline"), spOffline);
- presenceIface = BaseProtocolPresenceInterface::create(dbusConnection);
+ presenceIface = BaseProtocolPresenceInterface::create();
presenceIface->setStatuses(PresenceSpecList(specs));
plugInterface(AbstractProtocolInterfacePtr::dynamicCast(presenceIface));
}