From a160bc5b6f07ebd94088f2fc835db3b9cc0c3a22 Mon Sep 17 00:00:00 2001 From: Olli Salli Date: Wed, 15 Dec 2010 08:57:17 +0200 Subject: Channel: Remove connection destroyed handling A channel holds a strong ref to its Connection, so by definition that won't be destroyed during the Channel's lifetime. This is probably clutter from the bad old times when there was only a weak ref. --- TelepathyQt4/channel.cpp | 12 ------------ TelepathyQt4/channel.h | 1 - 2 files changed, 13 deletions(-) diff --git a/TelepathyQt4/channel.cpp b/TelepathyQt4/channel.cpp index 2cbd5ed0..fd8a7fa8 100644 --- a/TelepathyQt4/channel.cpp +++ b/TelepathyQt4/channel.cpp @@ -288,10 +288,6 @@ Channel::Private::Private(Channel *parent, const ConnectionPtr &connection, parent->connect(connection.data(), SIGNAL(invalidated(Tp::DBusProxy*,QString,QString)), SLOT(onConnectionInvalidated())); - - parent->connect(connection.data(), - SIGNAL(destroyed()), - SLOT(onConnectionDestroyed())); } else { warning() << "Connection given as the owner for a Channel was " @@ -2628,14 +2624,6 @@ void Channel::onConnectionInvalidated() QLatin1String("Connection given as the owner of this channel was invalidate")); } -void Channel::onConnectionDestroyed() -{ - debug() << "Owning connection destroyed, cutting off dangling pointer"; - mPriv->connection.reset(); - invalidate(QLatin1String(TELEPATHY_ERROR_CANCELLED), - QLatin1String("Connection given as the owner of this channel was destroyed")); -} - void Channel::gotGroupProperties(QDBusPendingCallWatcher *watcher) { QDBusPendingReply reply = *watcher; diff --git a/TelepathyQt4/channel.h b/TelepathyQt4/channel.h index d3cdc730..dce22c4e 100644 --- a/TelepathyQt4/channel.h +++ b/TelepathyQt4/channel.h @@ -204,7 +204,6 @@ private Q_SLOTS: void onConnectionReady(Tp::PendingOperation *op); void onConnectionInvalidated(); - void onConnectionDestroyed(); void gotGroupProperties(QDBusPendingCallWatcher *watcher); void gotGroupFlags(QDBusPendingCallWatcher *watcher); -- cgit v1.2.3 From 2caf0468265bbf265957d9f0a62ea1242e19e595 Mon Sep 17 00:00:00 2001 From: Olli Salli Date: Sun, 19 Dec 2010 17:54:36 +0200 Subject: Add QLatin1String versions of hand-written string constants --- TelepathyQt4/constants.h | 87 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) diff --git a/TelepathyQt4/constants.h b/TelepathyQt4/constants.h index 668ef56b..0a707d06 100644 --- a/TelepathyQt4/constants.h +++ b/TelepathyQt4/constants.h @@ -47,12 +47,24 @@ */ #define TELEPATHY_CONNECTION_MANAGER_BUS_NAME_BASE "org.freedesktop.Telepathy.ConnectionManager." +/** + * The prefix for a connection manager's bus name, to which the CM's name (e.g. + * "gabble") should be appended. + */ +#define TP_QT4_CONNECTION_MANAGER_BUS_NAME_BASE QLatin1String("org.freedesktop.Telepathy.ConnectionManager.") + /** * The prefix for a connection manager's object path, to which the CM's name * (e.g. "gabble") should be appended. */ #define TELEPATHY_CONNECTION_MANAGER_OBJECT_PATH_BASE "/org/freedesktop/Telepathy/ConnectionManager/" +/** + * The prefix for a connection manager's object path, to which the CM's name + * (e.g. "gabble") should be appended. + */ +#define TP_QT4_CONNECTION_MANAGER_OBJECT_PATH_BASE QLatin1String("/org/freedesktop/Telepathy/ConnectionManager/") + /** * The prefix for a connection's bus name, to which the CM's name (e.g. * "gabble"), the protocol (e.g. "jabber") and an element @@ -60,6 +72,13 @@ */ #define TELEPATHY_CONNECTION_BUS_NAME_BASE "org.freedesktop.Telepathy.Connection." +/** + * The prefix for a connection's bus name, to which the CM's name (e.g. + * "gabble"), the protocol (e.g. "jabber") and an element + * representing the account should be appended. + */ +#define TP_QT4_CONNECTION_BUS_NAME_BASE QLatin1String("org.freedesktop.Telepathy.Connection.") + /** * The prefix for a connection's object path, to which the CM's name (e.g. * "gabble"), the protocol (e.g. "jabber") and an element @@ -75,6 +94,14 @@ #define TELEPATHY_ACCOUNT_MANAGER_BUS_NAME \ "org.freedesktop.Telepathy.AccountManager" +/** + * The well-known bus name of the Account Manager. + * + * \see Tp::AccountManager + */ +#define TP_QT4_ACCOUNT_MANAGER_BUS_NAME \ + QLatin1String("org.freedesktop.Telepathy.AccountManager") + /** * The object path of the Account Manager object. * @@ -83,6 +110,14 @@ #define TELEPATHY_ACCOUNT_MANAGER_OBJECT_PATH \ "/org/freedesktop/Telepathy/AccountManager" +/** + * The object path of the Account Manager object. + * + * \see Tp::AccountManager + */ +#define TP_QT4_ACCOUNT_MANAGER_OBJECT_PATH \ + QLatin1String("/org/freedesktop/Telepathy/AccountManager") + /** * The prefix for an Account's object path, to which the CM's name (e.g. * "gabble"), the protocol (e.g. "jabber") and an element @@ -93,6 +128,16 @@ #define TELEPATHY_ACCOUNT_OBJECT_PATH_BASE \ "/org/freedesktop/Telepathy/Account" +/** + * The prefix for an Account's object path, to which the CM's name (e.g. + * "gabble"), the protocol (e.g. "jabber") and an element + * identifying the particular account should be appended. + * + * \see Tp::Account + */ +#define TP_QT4_ACCOUNT_OBJECT_PATH_BASE \ + QLatin1String("/org/freedesktop/Telepathy/Account") + /** * @} */ @@ -114,6 +159,21 @@ #define TELEPATHY_DBUS_ERROR_NAME_HAS_NO_OWNER \ "org.freedesktop.DBus.Error.NameHasNoOwner" +/** + * \ingroup errorstrconsts + * + * The error name "org.freedesktop.DBus.Error.NameHasNoOwner" as a QLatin1String. + * + * Raised by the D-Bus daemon when looking up the owner of a well-known name, + * if no process owns that name. + * + * Also used by DBusProxy to indicate that the owner of a well-known name + * has disappeared (usually indicating that the process owning that name + * exited or crashed). + */ +#define TP_QT4_DBUS_ERROR_NAME_HAS_NO_OWNER \ + QLatin1String("org.freedesktop.DBus.Error.NameHasNoOwner") + /** * \ingroup errorstrconsts * @@ -125,6 +185,17 @@ #define TELEPATHY_DBUS_ERROR_UNKNOWN_METHOD \ "org.freedesktop.DBus.Error.UnknownMethod" +/** + * \ingroup errorstrconsts + * + * The error name "org.freedesktop.DBus.Error.UnknownMethod" as a QLatin1String. + * + * Raised by the D-Bus daemon when the method name invoked isn't + * known by the object you invoked it on. + */ +#define TP_QT4_DBUS_ERROR_UNKNOWN_METHOD \ + QLatin1String("org.freedesktop.DBus.Error.UnknownMethod") + /** * \ingroup errorstrconsts * @@ -133,6 +204,14 @@ #define TELEPATHY_QT4_ERROR_OBJECT_REMOVED \ "org.freedesktop.Telepathy.Qt4.Error.ObjectRemoved" +/** + * \ingroup errorstrconsts + * + * The error name "org.freedesktop.Telepathy.Qt4.Error.ObjectRemoved" as a QLatin1String. + */ +#define TP_QT4_ERROR_OBJECT_REMOVED \ + QLatin1String("org.freedesktop.Telepathy.Qt4.Error.ObjectRemoved") + /** * \ingroup errorstrconsts * @@ -141,4 +220,12 @@ #define TELEPATHY_QT4_ERROR_INCONSISTENT \ "org.freedesktop.Telepathy.Qt4.Error.Inconsistent" +/** + * \ingroup errorstrconsts + * + * The error name "org.freedesktop.Telepathy.Qt4.Error.Inconsistent" as a QLatin1String. + */ +#define TP_QT4_ERROR_INCONSISTENT \ + QLatin1String("org.freedesktop.Telepathy.Qt4.Error.Inconsistent") + #endif -- cgit v1.2.3 From 0a361e3495b7586b90797f13c8dfbff5b7e59709 Mon Sep 17 00:00:00 2001 From: Olli Salli Date: Sun, 19 Dec 2010 18:40:17 +0200 Subject: Guard all QLatin1String string constant macro expansions from unwanted XYZQLatin1String errors --- TelepathyQt4/constants.h | 14 +++++++------- tools/qt4-constants-gen.py | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/TelepathyQt4/constants.h b/TelepathyQt4/constants.h index 0a707d06..bb2d84f1 100644 --- a/TelepathyQt4/constants.h +++ b/TelepathyQt4/constants.h @@ -100,7 +100,7 @@ * \see Tp::AccountManager */ #define TP_QT4_ACCOUNT_MANAGER_BUS_NAME \ - QLatin1String("org.freedesktop.Telepathy.AccountManager") + (QLatin1String("org.freedesktop.Telepathy.AccountManager")) /** * The object path of the Account Manager object. @@ -116,7 +116,7 @@ * \see Tp::AccountManager */ #define TP_QT4_ACCOUNT_MANAGER_OBJECT_PATH \ - QLatin1String("/org/freedesktop/Telepathy/AccountManager") + (QLatin1String("/org/freedesktop/Telepathy/AccountManager")) /** * The prefix for an Account's object path, to which the CM's name (e.g. @@ -136,7 +136,7 @@ * \see Tp::Account */ #define TP_QT4_ACCOUNT_OBJECT_PATH_BASE \ - QLatin1String("/org/freedesktop/Telepathy/Account") + (QLatin1String("/org/freedesktop/Telepathy/Account")) /** * @} @@ -172,7 +172,7 @@ * exited or crashed). */ #define TP_QT4_DBUS_ERROR_NAME_HAS_NO_OWNER \ - QLatin1String("org.freedesktop.DBus.Error.NameHasNoOwner") + (QLatin1String("org.freedesktop.DBus.Error.NameHasNoOwner")) /** * \ingroup errorstrconsts @@ -194,7 +194,7 @@ * known by the object you invoked it on. */ #define TP_QT4_DBUS_ERROR_UNKNOWN_METHOD \ - QLatin1String("org.freedesktop.DBus.Error.UnknownMethod") + (QLatin1String("org.freedesktop.DBus.Error.UnknownMethod")) /** * \ingroup errorstrconsts @@ -210,7 +210,7 @@ * The error name "org.freedesktop.Telepathy.Qt4.Error.ObjectRemoved" as a QLatin1String. */ #define TP_QT4_ERROR_OBJECT_REMOVED \ - QLatin1String("org.freedesktop.Telepathy.Qt4.Error.ObjectRemoved") + (QLatin1String("org.freedesktop.Telepathy.Qt4.Error.ObjectRemoved")) /** * \ingroup errorstrconsts @@ -226,6 +226,6 @@ * The error name "org.freedesktop.Telepathy.Qt4.Error.Inconsistent" as a QLatin1String. */ #define TP_QT4_ERROR_INCONSISTENT \ - QLatin1String("org.freedesktop.Telepathy.Qt4.Error.Inconsistent") + (QLatin1String("org.freedesktop.Telepathy.Qt4.Error.Inconsistent")) #endif diff --git a/tools/qt4-constants-gen.py b/tools/qt4-constants-gen.py index 47a7a4e1..11c4b5ed 100644 --- a/tools/qt4-constants-gen.py +++ b/tools/qt4-constants-gen.py @@ -150,7 +150,7 @@ namespace %s * The interface name "%(name)s" as a QLatin1String, usable in QString requiring contexts even when * building with Q_NO_CAST_FROM_ASCII defined. */ -#define %(DEFINE)s QLatin1String("%(name)s") +#define %(DEFINE)s (QLatin1String("%(name)s")) """ % {'name' : iface.getAttribute('name'), 'DEFINE' : self.define_prefix + 'IFACE_' + get_by_path(iface, '../@name').upper().replace('/', '')}) -- cgit v1.2.3 From 4d46c26ca96d1deef1c91d0771e42a4763b7cd6c Mon Sep 17 00:00:00 2001 From: Olli Salli Date: Sun, 19 Dec 2010 18:56:40 +0200 Subject: Use a new error TP_QT4_ERROR_ORPHANED when a Channel's parent Conn dies --- TelepathyQt4/channel.cpp | 4 ++-- TelepathyQt4/constants.h | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/TelepathyQt4/channel.cpp b/TelepathyQt4/channel.cpp index fd8a7fa8..340adc59 100644 --- a/TelepathyQt4/channel.cpp +++ b/TelepathyQt4/channel.cpp @@ -2620,8 +2620,8 @@ void Channel::onConnectionInvalidated() { debug() << "Owning connection died leaving an orphan Channel, " "changing to closed"; - invalidate(QLatin1String(TELEPATHY_ERROR_CANCELLED), - QLatin1String("Connection given as the owner of this channel was invalidate")); + invalidate(QLatin1String(TP_QT4_ERROR_ORPHANED), + QLatin1String("Connection given as the owner of this channel was invalidated")); } void Channel::gotGroupProperties(QDBusPendingCallWatcher *watcher) diff --git a/TelepathyQt4/constants.h b/TelepathyQt4/constants.h index bb2d84f1..2f926e73 100644 --- a/TelepathyQt4/constants.h +++ b/TelepathyQt4/constants.h @@ -228,4 +228,15 @@ #define TP_QT4_ERROR_INCONSISTENT \ (QLatin1String("org.freedesktop.Telepathy.Qt4.Error.Inconsistent")) +/** + * \ingroup errorstrconsts + * + * The error name "org.freedesktop.Telepathy.Qt4.Error.Orphaned" as a QLatin1String. + * + * This error is used when the "parent" proxy of an object gets invalidated. For example, a Channel + * whose corresponding Connection is invalidated invalidates itself with this error. + */ +#define TP_QT4_ERROR_ORPHANED \ + (QLatin1String("org.freedesktop.Telepathy.Qt4.Error.Orphaned")) + #endif -- cgit v1.2.3 From 1624ae180a4a0bf4f2e2358a557acd389426974e Mon Sep 17 00:00:00 2001 From: Olli Salli Date: Sun, 19 Dec 2010 19:15:28 +0200 Subject: Make TestChanBasics less ridiculous --- tests/dbus/chan-basics.cpp | 109 ++++++++++++++++++++++----------------------- 1 file changed, 54 insertions(+), 55 deletions(-) diff --git a/tests/dbus/chan-basics.cpp b/tests/dbus/chan-basics.cpp index 4cbe1e78..2c67944f 100644 --- a/tests/dbus/chan-basics.cpp +++ b/tests/dbus/chan-basics.cpp @@ -36,7 +36,7 @@ public: protected Q_SLOTS: void expectConnReady(Tp::ConnectionStatus, Tp::ConnectionStatusReason); - void expectConnInvalidated(); + void expectInvalidated(const QString &reason); void expectPendingHandleFinished(Tp::PendingOperation*); void expectCreateChannelFinished(Tp::PendingOperation *); void expectEnsureChannelFinished(Tp::PendingOperation *); @@ -85,8 +85,9 @@ void TestChanBasics::expectConnReady(Tp::ConnectionStatus newStatus, } } -void TestChanBasics::expectConnInvalidated() +void TestChanBasics::expectInvalidated(const QString &reason) { + qDebug() << sender() << "invalidated:" << reason; mLoop->exit(0); } @@ -234,6 +235,8 @@ void TestChanBasics::initTestCase() void TestChanBasics::init() { initImpl(); + + mChan.reset(); } void TestChanBasics::testRequestHandle() @@ -268,31 +271,29 @@ void TestChanBasics::testCreateChannel() SLOT(expectCreateChannelFinished(Tp::PendingOperation*)))); QCOMPARE(mLoop->exec(), 0); - if (mChan) { - QVERIFY(connect(mChan->becomeReady(), - SIGNAL(finished(Tp::PendingOperation*)), - SLOT(expectSuccessfulCall(Tp::PendingOperation*)))); - QCOMPARE(mLoop->exec(), 0); - QCOMPARE(mChan->isReady(), true); - QCOMPARE(mChan->isRequested(), true); - QCOMPARE(mChan->groupCanAddContacts(), false); - QCOMPARE(mChan->groupCanRemoveContacts(), false); - QCOMPARE(mChan->initiatorContact()->id(), QString(QLatin1String("me@example.com"))); - QCOMPARE(mChan->groupSelfContact()->id(), QString(QLatin1String("me@example.com"))); - QCOMPARE(mChan->groupSelfContact(), mConn->selfContact()); - - QStringList ids; - Q_FOREACH (const ContactPtr &contact, mChan->groupContacts()) { - ids << contact->id(); - } - ids.sort(); - QStringList toCheck = QStringList() << QLatin1String("me@example.com") - << QLatin1String("alice"); - toCheck.sort(); - QCOMPARE(ids, toCheck); + Q_ASSERT(!mChan.isNull()); - mChan.reset(); + QVERIFY(connect(mChan->becomeReady(), + SIGNAL(finished(Tp::PendingOperation*)), + SLOT(expectSuccessfulCall(Tp::PendingOperation*)))); + QCOMPARE(mLoop->exec(), 0); + QCOMPARE(mChan->isReady(), true); + QCOMPARE(mChan->isRequested(), true); + QCOMPARE(mChan->groupCanAddContacts(), false); + QCOMPARE(mChan->groupCanRemoveContacts(), false); + QCOMPARE(mChan->initiatorContact()->id(), QString(QLatin1String("me@example.com"))); + QCOMPARE(mChan->groupSelfContact()->id(), QString(QLatin1String("me@example.com"))); + QCOMPARE(mChan->groupSelfContact(), mConn->selfContact()); + + QStringList ids; + Q_FOREACH (const ContactPtr &contact, mChan->groupContacts()) { + ids << contact->id(); } + ids.sort(); + QStringList toCheck = QStringList() << QLatin1String("me@example.com") + << QLatin1String("alice"); + toCheck.sort(); + QCOMPARE(ids, toCheck); } void TestChanBasics::testEnsureChannel() @@ -309,37 +310,35 @@ void TestChanBasics::testEnsureChannel() SLOT(expectEnsureChannelFinished(Tp::PendingOperation*)))); QCOMPARE(mLoop->exec(), 0); - if (mChan) { - QVERIFY(connect(mChan->becomeReady(), - SIGNAL(finished(Tp::PendingOperation*)), - SLOT(expectSuccessfulCall(Tp::PendingOperation*)))); - QCOMPARE(mLoop->exec(), 0); - QCOMPARE(mChan->isReady(), true); - QCOMPARE(mChan->isRequested(), true); - QCOMPARE(mChan->groupCanAddContacts(), false); - QCOMPARE(mChan->groupCanRemoveContacts(), false); - QCOMPARE(mChan->initiatorContact()->id(), QString(QLatin1String("me@example.com"))); - QCOMPARE(mChan->groupSelfContact()->id(), QString(QLatin1String("me@example.com"))); - QCOMPARE(mChan->groupSelfContact(), mConn->selfContact()); - - QStringList ids; - Q_FOREACH (const ContactPtr &contact, mChan->groupContacts()) { - ids << contact->id(); - } - ids.sort(); - QStringList toCheck = QStringList() << QLatin1String("me@example.com") - << QLatin1String("alice"); - toCheck.sort(); - QCOMPARE(ids, toCheck); - - QVERIFY(connect(mChan->requestClose(), - SIGNAL(finished(Tp::PendingOperation*)), - SLOT(expectSuccessfulCall(Tp::PendingOperation*)))); - QCOMPARE(mLoop->exec(), 0); - QCOMPARE(mChan->isValid(), false); + QVERIFY(!mChan.isNull()); - mChan.reset(); + QVERIFY(connect(mChan->becomeReady(), + SIGNAL(finished(Tp::PendingOperation*)), + SLOT(expectSuccessfulCall(Tp::PendingOperation*)))); + QCOMPARE(mLoop->exec(), 0); + QCOMPARE(mChan->isReady(), true); + QCOMPARE(mChan->isRequested(), true); + QCOMPARE(mChan->groupCanAddContacts(), false); + QCOMPARE(mChan->groupCanRemoveContacts(), false); + QCOMPARE(mChan->initiatorContact()->id(), QString(QLatin1String("me@example.com"))); + QCOMPARE(mChan->groupSelfContact()->id(), QString(QLatin1String("me@example.com"))); + QCOMPARE(mChan->groupSelfContact(), mConn->selfContact()); + + QStringList ids; + Q_FOREACH (const ContactPtr &contact, mChan->groupContacts()) { + ids << contact->id(); } + ids.sort(); + QStringList toCheck = QStringList() << QLatin1String("me@example.com") + << QLatin1String("alice"); + toCheck.sort(); + QCOMPARE(ids, toCheck); + + QVERIFY(connect(mChan->requestClose(), + SIGNAL(finished(Tp::PendingOperation*)), + SLOT(expectSuccessfulCall(Tp::PendingOperation*)))); + QCOMPARE(mLoop->exec(), 0); + QCOMPARE(mChan->isValid(), false); } void TestChanBasics::cleanup() @@ -360,7 +359,7 @@ void TestChanBasics::cleanupTestCase() QVERIFY(connect(mConn.data(), SIGNAL(invalidated(Tp::DBusProxy *, const QString &, const QString &)), - SLOT(expectConnInvalidated()))); + SLOT(expectInvalidated(QString)))); QCOMPARE(mLoop->exec(), 0); } } -- cgit v1.2.3 From 90763ff7b2f677dd2f40e403137623e1432031cd Mon Sep 17 00:00:00 2001 From: Olli Salli Date: Sun, 19 Dec 2010 19:33:51 +0200 Subject: Use Cancelled as the default invalidation reason when a channel is Closed --- TelepathyQt4/channel.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/TelepathyQt4/channel.cpp b/TelepathyQt4/channel.cpp index 340adc59..dd2d5562 100644 --- a/TelepathyQt4/channel.cpp +++ b/TelepathyQt4/channel.cpp @@ -2583,9 +2583,8 @@ void Channel::onClosed() mPriv->groupSelfContactRemoveInfo); message = mPriv->groupSelfContactRemoveInfo.message(); } else { - // I think this is the nearest error code we can get at the moment - error = QLatin1String(TELEPATHY_ERROR_TERMINATED); - message = QLatin1String("Closed"); + error = TP_QT4_ERROR_CANCELLED; + message = QLatin1String("channel closed"); } invalidate(error, message); -- cgit v1.2.3 From c781044b64b4abd4ed67ada73e4ffc62657318dd Mon Sep 17 00:00:00 2001 From: Olli Salli Date: Sun, 19 Dec 2010 19:35:21 +0200 Subject: TestChanBasics: Test that the Channel invalidates itself with a reasonable error --- tests/dbus/chan-basics.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/tests/dbus/chan-basics.cpp b/tests/dbus/chan-basics.cpp index 2c67944f..f82ffd65 100644 --- a/tests/dbus/chan-basics.cpp +++ b/tests/dbus/chan-basics.cpp @@ -364,9 +364,17 @@ void TestChanBasics::cleanupTestCase() } } - if (mConnService != 0) { - g_object_unref(mConnService); - mConnService = 0; + if (mChan) { + if (mChan->isValid()) { + QVERIFY(connect(mChan.data(), + SIGNAL(invalidated(Tp::DBusProxy *, + const QString &, const QString &)), + SLOT(expectInvalidated(QString)))); + QCOMPARE(mLoop->exec(), 0); + } + + QVERIFY(mChan->invalidationReason() == TP_QT4_ERROR_CANCELLED || + mChan->invalidationReason() == TP_QT4_ERROR_ORPHANED); } cleanupTestCaseImpl(); -- cgit v1.2.3