diff options
author | George Kiagiadakis <george.kiagiadakis@collabora.com> | 2012-04-09 20:55:34 +0300 |
---|---|---|
committer | George Kiagiadakis <george.kiagiadakis@collabora.com> | 2012-04-12 16:36:21 +0300 |
commit | 39a083a71ea9b1f6e295b9e02ecc2c83020d2c8f (patch) | |
tree | 360a123105e9d77f30655f730f48c0172cfb80d0 | |
parent | aa817e46ab60120084e82926caf0c1cef8dcaacf (diff) |
BaseProtocol interfaces: Create adaptee classes earlier than adaptors
This is better practice than having mPriv->adaptee be NULL before
the interface has been registered and prevents a crash in
BaseProtocolAvatarsInterface::immutableProperties() if this
gets called with adaptee being NULL.
We could also make immutableProperties() return an empty map if the
adaptee has not been created, but it's probably safer for the future
to always create the adaptee object and don't bother to check if it's
NULL or not.
-rw-r--r-- | TelepathyQt/base-protocol-internal.h | 9 | ||||
-rw-r--r-- | TelepathyQt/base-protocol.cpp | 45 |
2 files changed, 21 insertions, 33 deletions
diff --git a/TelepathyQt/base-protocol-internal.h b/TelepathyQt/base-protocol-internal.h index 1f992aa3..fc152fc6 100644 --- a/TelepathyQt/base-protocol-internal.h +++ b/TelepathyQt/base-protocol-internal.h @@ -76,8 +76,7 @@ class TP_QT_NO_EXPORT BaseProtocolAddressingInterface::Adaptee : public QObject Q_PROPERTY(QStringList addressableURISchemes READ addressableURISchemes) public: - Adaptee(const QDBusConnection &dbusConnection, QObject *dbusObject, - BaseProtocolAddressingInterface *interface); + Adaptee(BaseProtocolAddressingInterface *interface); ~Adaptee(); QStringList addressableVCardFields() const; @@ -106,8 +105,7 @@ class TP_QT_NO_EXPORT BaseProtocolAvatarsInterface::Adaptee : public QObject Q_PROPERTY(uint maximumAvatarBytes READ maximumAvatarBytes) public: - Adaptee(const QDBusConnection &dbusConnection, QObject *dbusObject, - BaseProtocolAvatarsInterface *interface); + Adaptee(BaseProtocolAvatarsInterface *interface); ~Adaptee(); QStringList supportedAvatarMIMETypes() const; @@ -129,8 +127,7 @@ class TP_QT_NO_EXPORT BaseProtocolPresenceInterface::Adaptee : public QObject Q_PROPERTY(Tp::SimpleStatusSpecMap statuses READ statuses) public: - Adaptee(const QDBusConnection &dbusConnection, QObject *dbusObject, - BaseProtocolPresenceInterface *interface); + Adaptee(BaseProtocolPresenceInterface *interface); ~Adaptee(); SimpleStatusSpecMap statuses() const; diff --git a/TelepathyQt/base-protocol.cpp b/TelepathyQt/base-protocol.cpp index 0d386267..c1e0a5f0 100644 --- a/TelepathyQt/base-protocol.cpp +++ b/TelepathyQt/base-protocol.cpp @@ -704,12 +704,10 @@ AbstractProtocolInterface::~AbstractProtocolInterface() } // Proto.I.Addressing -BaseProtocolAddressingInterface::Adaptee::Adaptee(const QDBusConnection &dbusConnection, - QObject *dbusObject, BaseProtocolAddressingInterface *interface) +BaseProtocolAddressingInterface::Adaptee::Adaptee(BaseProtocolAddressingInterface *interface) : QObject(interface), mInterface(interface) { - (void) new Service::ProtocolInterfaceAddressingAdaptor(dbusConnection, this, dbusObject); } BaseProtocolAddressingInterface::Adaptee::~Adaptee() @@ -755,8 +753,8 @@ void BaseProtocolAddressingInterface::Adaptee::normalizeContactURI(const QString struct TP_QT_NO_EXPORT BaseProtocolAddressingInterface::Private { - Private() - : adaptee(0) + Private(BaseProtocolAddressingInterface *parent) + : adaptee(new BaseProtocolAddressingInterface::Adaptee(parent)) { } @@ -780,7 +778,7 @@ struct TP_QT_NO_EXPORT BaseProtocolAddressingInterface::Private */ BaseProtocolAddressingInterface::BaseProtocolAddressingInterface() : AbstractProtocolInterface(TP_QT_IFACE_PROTOCOL_INTERFACE_ADDRESSING), - mPriv(new Private) + mPriv(new Private(this)) { } @@ -941,18 +939,15 @@ QString BaseProtocolAddressingInterface::normalizeContactUri(const QString &uri, void BaseProtocolAddressingInterface::createAdaptor() { - Q_ASSERT(!mPriv->adaptee); - mPriv->adaptee = new BaseProtocolAddressingInterface::Adaptee( - dbusObject()->dbusConnection(), dbusObject(), this); + (void) new Service::ProtocolInterfaceAddressingAdaptor(dbusObject()->dbusConnection(), + mPriv->adaptee, dbusObject()); } // Proto.I.Avatars -BaseProtocolAvatarsInterface::Adaptee::Adaptee(const QDBusConnection &dbusConnection, - QObject *dbusObject, BaseProtocolAvatarsInterface *interface) +BaseProtocolAvatarsInterface::Adaptee::Adaptee(BaseProtocolAvatarsInterface *interface) : QObject(interface), mInterface(interface) { - (void) new Service::ProtocolInterfaceAvatarsAdaptor(dbusConnection, this, dbusObject); } BaseProtocolAvatarsInterface::Adaptee::~Adaptee() @@ -1001,8 +996,8 @@ uint BaseProtocolAvatarsInterface::Adaptee::maximumAvatarBytes() const struct TP_QT_NO_EXPORT BaseProtocolAvatarsInterface::Private { - Private() - : adaptee(0) + Private(BaseProtocolAvatarsInterface *parent) + : adaptee(new BaseProtocolAvatarsInterface::Adaptee(parent)) { } @@ -1023,7 +1018,7 @@ struct TP_QT_NO_EXPORT BaseProtocolAvatarsInterface::Private */ BaseProtocolAvatarsInterface::BaseProtocolAvatarsInterface() : AbstractProtocolInterface(TP_QT_IFACE_PROTOCOL_INTERFACE_AVATARS), - mPriv(new Private) + mPriv(new Private(this)) { } @@ -1097,18 +1092,15 @@ void BaseProtocolAvatarsInterface::setAvatarDetails(const AvatarSpec &details) void BaseProtocolAvatarsInterface::createAdaptor() { - Q_ASSERT(!mPriv->adaptee); - mPriv->adaptee = new BaseProtocolAvatarsInterface::Adaptee( - dbusObject()->dbusConnection(), dbusObject(), this); + (void) new Service::ProtocolInterfaceAvatarsAdaptor(dbusObject()->dbusConnection(), + mPriv->adaptee, dbusObject()); } // Proto.I.Presence -BaseProtocolPresenceInterface::Adaptee::Adaptee(const QDBusConnection &dbusConnection, - QObject *dbusObject, BaseProtocolPresenceInterface *interface) +BaseProtocolPresenceInterface::Adaptee::Adaptee(BaseProtocolPresenceInterface *interface) : QObject(interface), mInterface(interface) { - (void) new Service::ProtocolInterfacePresenceAdaptor(dbusConnection, this, dbusObject); } BaseProtocolPresenceInterface::Adaptee::~Adaptee() @@ -1122,8 +1114,8 @@ SimpleStatusSpecMap BaseProtocolPresenceInterface::Adaptee::statuses() const struct TP_QT_NO_EXPORT BaseProtocolPresenceInterface::Private { - Private() - : adaptee(0) + Private(BaseProtocolPresenceInterface *parent) + : adaptee(new BaseProtocolPresenceInterface::Adaptee(parent)) { } @@ -1144,7 +1136,7 @@ struct TP_QT_NO_EXPORT BaseProtocolPresenceInterface::Private */ BaseProtocolPresenceInterface::BaseProtocolPresenceInterface() : AbstractProtocolInterface(TP_QT_IFACE_PROTOCOL_INTERFACE_PRESENCE), - mPriv(new Private) + mPriv(new Private(this)) { } @@ -1212,9 +1204,8 @@ void BaseProtocolPresenceInterface::setStatuses(const PresenceSpecList &statuses void BaseProtocolPresenceInterface::createAdaptor() { - Q_ASSERT(!mPriv->adaptee); - mPriv->adaptee = new BaseProtocolPresenceInterface::Adaptee( - dbusObject()->dbusConnection(), dbusObject(), this); + (void) new Service::ProtocolInterfacePresenceAdaptor(dbusObject()->dbusConnection(), + mPriv->adaptee, dbusObject()); } } |