[telepathy-qt4/master] ReferencedHandles: Return ConnectionPtr on connection() method.
Andre Moreira Magalhaes (andrunko)
andre.magalhaes at collabora.co.uk
Tue Mar 31 15:07:32 PDT 2009
---
TelepathyQt4/Client/pending-contacts.cpp | 4 +-
TelepathyQt4/Client/referenced-handles.cpp | 54 ++++++++++++++++++----------
TelepathyQt4/Client/referenced-handles.h | 14 ++-----
tests/pinocchio/handles.cpp | 4 +-
4 files changed, 43 insertions(+), 33 deletions(-)
diff --git a/TelepathyQt4/Client/pending-contacts.cpp b/TelepathyQt4/Client/pending-contacts.cpp
index f2871ca..086521f 100644
--- a/TelepathyQt4/Client/pending-contacts.cpp
+++ b/TelepathyQt4/Client/pending-contacts.cpp
@@ -278,7 +278,7 @@ void PendingContacts::onReferenceHandlesFinished(PendingOperation *operation)
ReferencedHandles validHandles = pendingHandles->handles();
UIntList invalidHandles = pendingHandles->invalidHandles();
ConnectionPtr conn = mPriv->manager->connection();
- mPriv->handlesToInspect = ReferencedHandles(conn.data(), HandleTypeContact, UIntList());
+ mPriv->handlesToInspect = ReferencedHandles(conn, HandleTypeContact, UIntList());
foreach (uint handle, mPriv->handles) {
if (!mPriv->satisfyingContacts.contains(handle)) {
int indexInValid = validHandles.indexOf(handle);
@@ -338,7 +338,7 @@ void PendingContacts::onInspectHandlesFinished(QDBusPendingCallWatcher *watcher)
foreach (uint handle, mPriv->handlesToInspect) {
QVariantMap handleAttributes;
handleAttributes.insert(TELEPATHY_INTERFACE_CONNECTION "/contact-id", names[i++]);
- ReferencedHandles referencedHandle(conn.data(), HandleTypeContact,
+ ReferencedHandles referencedHandle(conn, HandleTypeContact,
UIntList() << handle);
mPriv->satisfyingContacts.insert(handle, manager()->ensureContact(referencedHandle,
features(), handleAttributes));
diff --git a/TelepathyQt4/Client/referenced-handles.cpp b/TelepathyQt4/Client/referenced-handles.cpp
index 1e2ca89..a10c28f 100644
--- a/TelepathyQt4/Client/referenced-handles.cpp
+++ b/TelepathyQt4/Client/referenced-handles.cpp
@@ -35,7 +35,7 @@ namespace Client
struct ReferencedHandles::Private : public QSharedData
{
- QPointer<Connection> connection;
+ WeakPtr<Connection> connection;
uint handleType;
UIntList handles;
@@ -44,10 +44,11 @@ struct ReferencedHandles::Private : public QSharedData
handleType = 0;
}
- Private(Connection* connection, uint handleType, const UIntList& handles)
+ Private(const ConnectionPtr &connection, uint handleType,
+ const UIntList& handles)
: connection(connection), handleType(handleType), handles(handles)
{
- Q_ASSERT(connection != 0);
+ Q_ASSERT(connection);
Q_ASSERT(handleType != 0);
foreach (uint handle, handles)
@@ -66,10 +67,12 @@ struct ReferencedHandles::Private : public QSharedData
return;
}
+ ConnectionPtr conn(connection);
for (const_iterator i = handles.begin();
i != handles.end();
- ++i)
- connection->refHandle(handleType, *i);
+ ++i) {
+ conn->refHandle(handleType, *i);
+ }
}
}
@@ -81,10 +84,12 @@ struct ReferencedHandles::Private : public QSharedData
return;
}
+ ConnectionPtr conn(connection);
for (const_iterator i = handles.begin();
i != handles.end();
- ++i)
- connection->unrefHandle(handleType, *i);
+ ++i) {
+ conn->unrefHandle(handleType, *i);
+ }
}
}
@@ -106,7 +111,7 @@ ReferencedHandles::~ReferencedHandles()
{
}
-Connection* ReferencedHandles::connection() const
+ConnectionPtr ReferencedHandles::connection() const
{
return mPriv->connection;
}
@@ -175,8 +180,10 @@ void ReferencedHandles::clear()
{
if (!mPriv->handles.empty()) {
if (mPriv->connection) {
- foreach (uint handle, mPriv->handles)
- mPriv->connection->unrefHandle(handleType(), handle);
+ ConnectionPtr conn(mPriv->connection);
+ foreach (uint handle, mPriv->handles) {
+ conn->unrefHandle(handleType(), handle);
+ }
} else {
warning() << "Connection already destroyed in ReferencedHandles::clear() so can't unref!";
}
@@ -196,8 +203,10 @@ int ReferencedHandles::removeAll(uint handle)
if (count > 0) {
if (mPriv->connection) {
- for (int i = 0; i < count; i++)
- mPriv->connection->unrefHandle(handleType(), handle);
+ ConnectionPtr conn(mPriv->connection);
+ for (int i = 0; i < count; i++) {
+ conn->unrefHandle(handleType(), handle);
+ }
} else {
warning() << "Connection already destroyed in ReferencedHandles::removeAll() with handle ==" << handle << "so can't unref!";
}
@@ -208,8 +217,10 @@ int ReferencedHandles::removeAll(uint handle)
void ReferencedHandles::removeAt(int i)
{
- if (mPriv->connection)
- mPriv->connection->unrefHandle(handleType(), at(i));
+ if (mPriv->connection) {
+ ConnectionPtr conn(mPriv->connection);
+ conn->unrefHandle(handleType(), at(i));
+ }
else
warning() << "Connection already destroyed in ReferencedHandles::removeAt() with i ==" << i << "so can't unref!";
@@ -221,8 +232,10 @@ bool ReferencedHandles::removeOne(uint handle)
bool wasThere = mPriv->handles.removeOne(handle);
if (wasThere) {
- if (mPriv->connection)
- mPriv->connection->unrefHandle(handleType(), handle);
+ if (mPriv->connection) {
+ ConnectionPtr conn(mPriv->connection);
+ conn->unrefHandle(handleType(), handle);
+ }
else
warning() << "Connection already destroyed in ReferencedHandles::removeOne() with handle ==" << handle << "so can't unref!";
}
@@ -237,8 +250,10 @@ void ReferencedHandles::swap(int i, int j)
uint ReferencedHandles::takeAt(int i)
{
- if (mPriv->connection)
- mPriv->connection->unrefHandle(handleType(), at(i));
+ if (mPriv->connection) {
+ ConnectionPtr conn(mPriv->connection);
+ conn->unrefHandle(handleType(), at(i));
+ }
else
warning() << "Connection already destroyed in ReferencedHandles::takeAt() with i ==" << i << "so can't unref!";
@@ -278,7 +293,8 @@ UIntList ReferencedHandles::toList() const
return mPriv->handles;
}
-ReferencedHandles::ReferencedHandles(Connection* connection, uint handleType, const UIntList& handles)
+ReferencedHandles::ReferencedHandles(const ConnectionPtr &connection,
+ uint handleType, const UIntList& handles)
: mPriv(new Private(connection, handleType, handles))
{
}
diff --git a/TelepathyQt4/Client/referenced-handles.h b/TelepathyQt4/Client/referenced-handles.h
index 370ab00..44ddea8 100644
--- a/TelepathyQt4/Client/referenced-handles.h
+++ b/TelepathyQt4/Client/referenced-handles.h
@@ -45,14 +45,7 @@
* interfaces.
*/
-namespace Telepathy
-{
-namespace Client
-{
-class ReferencedHandles;
-}
-}
-
+#include <TelepathyQt4/Client/Types>
#include <TelepathyQt4/Types>
#include <list>
@@ -103,7 +96,7 @@ class ReferencedHandles
ReferencedHandles(const ReferencedHandles& other);
~ReferencedHandles();
- Connection* connection() const;
+ ConnectionPtr connection() const;
uint handleType() const;
uint at(int i) const;
@@ -286,7 +279,8 @@ class ReferencedHandles
friend class PendingContacts;
friend class PendingHandles;
- ReferencedHandles(Connection* connection, uint handleType, const UIntList& handles);
+ ReferencedHandles(const ConnectionPtr &connection,
+ uint handleType, const UIntList& handles);
struct Private;
QSharedDataPointer<Private> mPriv;
diff --git a/tests/pinocchio/handles.cpp b/tests/pinocchio/handles.cpp
index 711ad52..1b9b3cb 100644
--- a/tests/pinocchio/handles.cpp
+++ b/tests/pinocchio/handles.cpp
@@ -196,14 +196,14 @@ void TestHandles::testBasics()
mHandles = ReferencedHandles();
// Check that the ReferencedHandles are what we asked for
- QCOMPARE(handles.connection(), mConn1a.data());
+ QCOMPARE(handles.connection(), mConn1a);
QCOMPARE(handles.handleType(), static_cast<uint>(Telepathy::HandleTypeContact));
QVERIFY(handles == shouldBe);
// Check that a copy of the received ReferencedHandles is also what we asked for (it's supposed
// to be equivalent with one that we already verified as being that)
ReferencedHandles copy = handles;
- QCOMPARE(copy.connection(), mConn1a.data());
+ QCOMPARE(copy.connection(), mConn1a);
QCOMPARE(copy.handleType(), static_cast<uint>(Telepathy::HandleTypeContact));
QVERIFY(copy == handles);
--
1.5.6.5
More information about the telepathy-commits
mailing list