summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDario Freddi <dario.freddi@collabora.com>2011-11-11 23:32:34 +0100
committerDario Freddi <dario.freddi@collabora.com>2012-07-03 11:11:23 +0200
commitc3977453476780e60a3c9809b72f2228ed7cd3c7 (patch)
tree35b6359f086d2fc7472e4ce212ed0abcf91141f5
parentc3fb6ef81c21c255764ef1acb639c1779476d634 (diff)
dbus-tubes: Invert the mapping Contact->Bus Name
This makes the API more consistent with Stream tubes. Also, split the busNamesChanged signal into two separate signals, giving out more details.
-rw-r--r--TelepathyQt/dbus-tube-channel.cpp43
-rw-r--r--TelepathyQt/dbus-tube-channel.h5
-rw-r--r--tests/dbus/dbus-tube-chan.cpp97
3 files changed, 80 insertions, 65 deletions
diff --git a/TelepathyQt/dbus-tube-channel.cpp b/TelepathyQt/dbus-tube-channel.cpp
index cdc61bb4..53fabff6 100644
--- a/TelepathyQt/dbus-tube-channel.cpp
+++ b/TelepathyQt/dbus-tube-channel.cpp
@@ -52,7 +52,7 @@ struct TP_QT_NO_EXPORT DBusTubeChannel::Private
// Properties
UIntList accessControls;
QString serviceName;
- QHash<ContactPtr, QString> busNames;
+ QHash<QString, Tp::ContactPtr> contactsForBusNames;
QString address;
QHash<QUuid, QString> pendingNewBusNamesToAdd;
@@ -101,7 +101,7 @@ void DBusTubeChannel::Private::extractProperties(const QVariantMap &props)
void DBusTubeChannel::Private::extractParticipants(const Tp::DBusTubeParticipants &participants)
{
- busNames.clear();
+ contactsForBusNames.clear();
for (DBusTubeParticipants::const_iterator i = participants.constBegin();
i != participants.constEnd();
++i) {
@@ -325,15 +325,15 @@ QString DBusTubeChannel::address() const
*
* \returns A list of active connection ids known to this tube
*/
-QHash<ContactPtr, QString> DBusTubeChannel::busNames() const
+QHash<QString, Tp::ContactPtr> DBusTubeChannel::contactsForBusNames() const
{
if (!isReady(FeatureBusNameMonitoring)) {
- warning() << "DBusTubeChannel::busNames() used with "
+ warning() << "DBusTubeChannel::contactsForBusNames() used with "
"FeatureBusNameMonitoring not ready";
- return QHash<ContactPtr, QString>();
+ return QHash<QString, Tp::ContactPtr>();
}
- return mPriv->busNames;
+ return mPriv->contactsForBusNames;
}
void DBusTubeChannel::onRequestAllPropertiesFinished(PendingOperation *op)
@@ -418,37 +418,36 @@ void DBusTubeChannel::onContactsRetrieved(const QUuid &uuid, const QList<Contact
// Retrieve our hash
if (mPriv->pendingNewBusNamesToAdd.contains(uuid)) {
QString busName = mPriv->pendingNewBusNamesToAdd.take(uuid);
- QHash<ContactPtr, QString> added;
// Add it to our connections hash
foreach (const Tp::ContactPtr &contact, contacts) {
- mPriv->busNames.insert(contact, busName);
- added.insert(contact, busName);
- }
+ mPriv->contactsForBusNames.insert(busName, contact);
- // Time for us to emit the signal - if the feature is ready
- if (isReady(FeatureBusNameMonitoring)) {
- emit busNamesChanged(added, QList<ContactPtr>());
+ // Time for us to emit the signal - if the feature is ready
+ if (isReady(FeatureBusNameMonitoring)) {
+ emit busNameAdded(busName, contact);
+ }
}
+
+
} else if (mPriv->pendingNewBusNamesToRemove.contains(uuid)) {
mPriv->pendingNewBusNamesToRemove.removeOne(uuid);
- QList<ContactPtr> removed;
// Remove it from our connections hash
foreach (const Tp::ContactPtr &contact, contacts) {
- if (mPriv->busNames.contains(contact)) {
- mPriv->busNames.remove(contact);
- removed << contact;
+ if (mPriv->contactsForBusNames.values().contains(contact)) {
+ QString busName = mPriv->contactsForBusNames.key(contact);
+ mPriv->contactsForBusNames.remove(busName);
+
+ // Time for us to emit the signal - if the feature is ready
+ if (isReady(FeatureBusNameMonitoring)) {
+ emit busNameRemoved(busName, contact);
+ }
} else {
warning() << "Trying to remove a bus name for contact " << contact->id()
<< " which has not been retrieved previously!";
}
}
-
- // Time for us to emit the signal - if the feature is ready
- if (isReady(FeatureBusNameMonitoring)) {
- emit busNamesChanged(QHash<ContactPtr, QString>(), removed);
- }
} else {
warning() << "Contacts retrieved but no pending bus names were found";
return;
diff --git a/TelepathyQt/dbus-tube-channel.h b/TelepathyQt/dbus-tube-channel.h
index 97d3e45a..bb32a888 100644
--- a/TelepathyQt/dbus-tube-channel.h
+++ b/TelepathyQt/dbus-tube-channel.h
@@ -50,7 +50,7 @@ public:
bool supportsRestrictingToCurrentUser() const;
- QHash<Tp::ContactPtr, QString> busNames() const;
+ QHash<QString, Tp::ContactPtr> contactsForBusNames() const;
QString address() const;
@@ -61,7 +61,8 @@ protected:
void setAddress(const QString &address);
Q_SIGNALS:
- void busNamesChanged(const QHash<ContactPtr, QString> &added, const QList<ContactPtr> &removed);
+ void busNameAdded(const QString &busName, const Tp::ContactPtr &contact);
+ void busNameRemoved(const QString &busName, const Tp::ContactPtr &contact);
private Q_SLOTS:
TP_QT_NO_EXPORT void onRequestAllPropertiesFinished(Tp::PendingOperation*);
diff --git a/tests/dbus/dbus-tube-chan.cpp b/tests/dbus/dbus-tube-chan.cpp
index 03f80838..3797aa29 100644
--- a/tests/dbus/dbus-tube-chan.cpp
+++ b/tests/dbus/dbus-tube-chan.cpp
@@ -60,8 +60,8 @@ public:
{ }
protected Q_SLOTS:
- void onBusNamesChanged(const QHash<ContactPtr,QString> &added,
- const QList<ContactPtr> &removed);
+ void onBusNameAdded(const QString &busName, const Tp::ContactPtr &contact);
+ void onBusNameRemoved(const QString &busName, const Tp::ContactPtr &contact);
void onOfferFinished(Tp::PendingOperation *op);
void expectPendingTubeConnectionFinished(Tp::PendingOperation *op);
@@ -92,7 +92,7 @@ private:
uint mCurrentContext;
- QHash<ContactPtr, QString> mCurrentBusNames;
+ QHash<QString, Tp::ContactPtr> mCurrentContactsForBusNames;
bool mGotRemoteConnection;
bool mGotConnectionClosed;
bool mOfferFinished;
@@ -102,29 +102,32 @@ private:
QString mExpectedService;
};
-void TestDBusTubeChan::onBusNamesChanged(const QHash<ContactPtr, QString> &added,
- const QList<ContactPtr> &removed)
+void TestDBusTubeChan::onBusNameAdded(const QString &busName,
+ const Tp::ContactPtr &contact)
{
- qDebug() << "Bus names changed!";
- for (QHash<ContactPtr, QString>::const_iterator i = added.constBegin();
- i != added.constEnd(); ++i) {
- mCurrentBusNames.insert(i.key(), i.value());
- mGotRemoteConnection = true;
- qDebug() << "Adding " << i.key()->id();
-
- QCOMPARE(i.value(), mExpectedService);
- QCOMPARE(i.key()->handle().first(), mExpectedHandle);
- }
- Q_FOREACH (const ContactPtr &contact, removed) {
- QVERIFY(mCurrentBusNames.contains(contact));
- mCurrentBusNames.remove(contact);
- mGotConnectionClosed = true;
- qDebug() << "Removing " << contact->id();
+ mCurrentContactsForBusNames.insert(busName, contact);
+ mGotRemoteConnection = true;
+ qDebug() << "Adding bus name" << busName << "for" << contact->id();
- QCOMPARE(contact->handle().first(), mExpectedHandle);
- }
+ QCOMPARE(busName, mExpectedService);
+ QCOMPARE(contact->handle().first(), mExpectedHandle);
- QCOMPARE(mChan->busNames().size(), mCurrentBusNames.size());
+ QCOMPARE(mChan->contactsForBusNames().size(), mCurrentContactsForBusNames.size());
+
+ mLoop->quit();
+}
+
+void TestDBusTubeChan::onBusNameRemoved(const QString &busName,
+ const Tp::ContactPtr &contact)
+{
+ QVERIFY(mCurrentContactsForBusNames.contains(busName));
+ mCurrentContactsForBusNames.remove(busName);
+ mGotConnectionClosed = true;
+ qDebug() << "Removing bus name" << busName << "for" << contact->id();
+
+ QCOMPARE(contact->handle().first(), mExpectedHandle);
+
+ QCOMPARE(mChan->contactsForBusNames().size(), mCurrentContactsForBusNames.size());
mLoop->quit();
}
@@ -269,7 +272,7 @@ void TestDBusTubeChan::testCreation()
QCOMPARE(mChan->parameters().isEmpty(), true);
QCOMPARE(mChan->serviceName(), QLatin1String("com.test.Test"));
QCOMPARE(mChan->supportsRestrictingToCurrentUser(), false);
- QCOMPARE(mChan->busNames().isEmpty(), true);
+ QCOMPARE(mChan->contactsForBusNames().isEmpty(), true);
QCOMPARE(mChan->address(), QString());
/* incoming tube */
@@ -288,7 +291,7 @@ void TestDBusTubeChan::testCreation()
QCOMPARE(mChan->parameters().value(QLatin1String("badger")), QVariant(42));
QCOMPARE(mChan->serviceName(), QLatin1String("com.test.Test"));
QCOMPARE(mChan->supportsRestrictingToCurrentUser(), false);
- QCOMPARE(mChan->busNames().isEmpty(), true);
+ QCOMPARE(mChan->contactsForBusNames().isEmpty(), true);
QCOMPARE(mChan->address(), QString());
}
@@ -314,8 +317,11 @@ void TestDBusTubeChan::testAcceptSuccess()
QCOMPARE(mChan->state(), TubeChannelStateLocalPending);
QVERIFY(connect(mChan.data(),
- SIGNAL(busNamesChanged(QHash<ContactPtr,QString>,QList<ContactPtr>)),
- SLOT(onBusNamesChanged(QHash<ContactPtr,QString>,QList<ContactPtr>))));
+ SIGNAL(busNameAdded(QString,Tp::ContactPtr)),
+ SLOT(onBusNameAdded(QString,Tp::ContactPtr))));
+ QVERIFY(connect(mChan.data(),
+ SIGNAL(busNameRemoved(QString,Tp::ContactPtr)),
+ SLOT(onBusNameRemoved(QString,Tp::ContactPtr))));
bool allowsOtherUsers = ((contexts[i].accessControl == TP_SOCKET_ACCESS_CONTROL_LOCALHOST) ?
true : false);
@@ -407,8 +413,11 @@ void TestDBusTubeChan::testOfferSuccess()
mGotRemoteConnection = false;
QVERIFY(connect(mChan.data(),
- SIGNAL(busNamesChanged(QHash<ContactPtr,QString>,QList<ContactPtr>)),
- SLOT(onBusNamesChanged(QHash<ContactPtr,QString>,QList<ContactPtr>))));
+ SIGNAL(busNameAdded(QString,Tp::ContactPtr)),
+ SLOT(onBusNameAdded(QString,Tp::ContactPtr))));
+ QVERIFY(connect(mChan.data(),
+ SIGNAL(busNameRemoved(QString,Tp::ContactPtr)),
+ SLOT(onBusNameRemoved(QString,Tp::ContactPtr))));
bool allowsOtherUsers = ((contexts[i].accessControl == TP_SOCKET_ACCESS_CONTROL_LOCALHOST) ?
true : false);
@@ -489,11 +498,11 @@ void TestDBusTubeChan::testOfferSuccess()
QCOMPARE(mLoop->exec(), 0);
QCOMPARE(mGotConnectionClosed, true);
- /* let the internal OutgoingDBusTubeChannel::onBusNamesChanged slot be called before
+ /* let the internal DBusTubeChannel::onBusNamesChanged slot be called before
* checking the data for that connection */
mLoop->processEvents();
- QCOMPARE(chan->busNames().isEmpty(), true);
+ QCOMPARE(chan->contactsForBusNames().isEmpty(), true);
}
/* as we run several tests here, let's init/cleanup properly */
@@ -513,8 +522,11 @@ void TestDBusTubeChan::testOutgoingBusNameMonitoring()
QCOMPARE(mLoop->exec(), 0);
QVERIFY(connect(mChan.data(),
- SIGNAL(busNamesChanged(QHash<ContactPtr,QString>,QList<ContactPtr>)),
- SLOT(onBusNamesChanged(QHash<ContactPtr,QString>,QList<ContactPtr>))));
+ SIGNAL(busNameAdded(QString,Tp::ContactPtr)),
+ SLOT(onBusNameAdded(QString,Tp::ContactPtr))));
+ QVERIFY(connect(mChan.data(),
+ SIGNAL(busNameRemoved(QString,Tp::ContactPtr)),
+ SLOT(onBusNameRemoved(QString,Tp::ContactPtr))));
OutgoingDBusTubeChannelPtr chan = OutgoingDBusTubeChannelPtr::qObjectCast(mChan);
QVERIFY(connect(chan->offerTube(QVariantMap()), // DISCARD
@@ -545,13 +557,13 @@ void TestDBusTubeChan::testOutgoingBusNameMonitoring()
QCOMPARE(mLoop->exec(), 0);
}
- QCOMPARE(mChan->busNames().size(), 1);
+ QCOMPARE(mChan->contactsForBusNames().size(), 1);
- // The busNamesChanged emission should finally exit the main loop
+ // The busNameRemoved emission should finally exit the main loop
QCOMPARE(mLoop->exec(), 0);
QVERIFY(mGotConnectionClosed);
- QCOMPARE(mChan->busNames().size(), 0);
+ QCOMPARE(mChan->contactsForBusNames().size(), 0);
g_free (service);
}
@@ -566,8 +578,11 @@ void TestDBusTubeChan::testExtractBusNameMonitoring()
QCOMPARE(mLoop->exec(), 0);
QVERIFY(connect(mChan.data(),
- SIGNAL(busNamesChanged(QHash<ContactPtr,QString>,QList<ContactPtr>)),
- SLOT(onBusNamesChanged(QHash<ContactPtr,QString>,QList<ContactPtr>))));
+ SIGNAL(busNameAdded(QString,Tp::ContactPtr)),
+ SLOT(onBusNameAdded(QString,Tp::ContactPtr))));
+ QVERIFY(connect(mChan.data(),
+ SIGNAL(busNameRemoved(QString,Tp::ContactPtr)),
+ SLOT(onBusNameRemoved(QString,Tp::ContactPtr))));
OutgoingDBusTubeChannelPtr chan = OutgoingDBusTubeChannelPtr::qObjectCast(mChan);
QVERIFY(connect(chan->offerTube(QVariantMap()), // DISCARD
@@ -603,7 +618,7 @@ void TestDBusTubeChan::testExtractBusNameMonitoring()
QVERIFY(!mGotRemoteConnection);
// This should also trigger a warning
- QCOMPARE(mChan->busNames().size(), 0);
+ QCOMPARE(mChan->contactsForBusNames().size(), 0);
// Now, enable the feature, and let it extract participants
QVERIFY(connect(mChan->becomeReady(OutgoingDBusTubeChannel::FeatureBusNameMonitoring),
@@ -612,9 +627,9 @@ void TestDBusTubeChan::testExtractBusNameMonitoring()
QCOMPARE(mLoop->exec(), 0);
// This should now be fine
- QCOMPARE(mChan->busNames().size(), 1);
+ QCOMPARE(mChan->contactsForBusNames().size(), 1);
// The name should match
- QCOMPARE(mChan->busNames().value(mChan->busNames().keys().first()), QLatin1String("org.not.seen.yet"));
+ QCOMPARE(mChan->contactsForBusNames().keys().first(), QLatin1String("org.not.seen.yet"));
// And the signal shouldn't have been called
QVERIFY(!mGotConnectionClosed);
QVERIFY(!mGotRemoteConnection);