[Telepathy-commits] [telepathy-qt4/master] Add naive requestHandles and referenceHandles to Connection
Olli Salli
olli.salli at collabora.co.uk
Wed Jan 21 04:42:12 PST 2009
---
TelepathyQt4/cli-connection.cpp | 71 +++++++++++++++++++++++++++++++++------
TelepathyQt4/cli-connection.h | 56 ++++++++++++++++++++++++++++++-
2 files changed, 115 insertions(+), 12 deletions(-)
diff --git a/TelepathyQt4/cli-connection.cpp b/TelepathyQt4/cli-connection.cpp
index e2a7554..ef2ccfa 100644
--- a/TelepathyQt4/cli-connection.cpp
+++ b/TelepathyQt4/cli-connection.cpp
@@ -473,6 +473,36 @@ PendingOperation* Connection::requestConnect()
}
#endif
+PendingHandles* Connection::requestHandles(uint handleType, const QStringList& names)
+{
+ debug() << "Request for" << names.length() << "handles of type" << handleType;
+
+ PendingHandles* pending =
+ new PendingHandles(this, handleType, names);
+ QDBusPendingCallWatcher* watcher =
+ new QDBusPendingCallWatcher(RequestHandles(handleType, names), pending);
+
+ pending->connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)),
+ SLOT(onCallFinished(QDBusPendingCallWatcher*)));
+
+ return pending;
+}
+
+PendingHandles* Connection::referenceHandles(uint handleType, const UIntList& handles)
+{
+ debug() << "Reference of" << handles.length() << "handles of type" << handleType;
+
+ PendingHandles* pending =
+ new PendingHandles(this, handleType, handles, false);
+ QDBusPendingCallWatcher* watcher =
+ new QDBusPendingCallWatcher(HoldHandles(handleType, handles), pending);
+
+ pending->connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)),
+ SLOT(onCallFinished(QDBusPendingCallWatcher*)));
+
+ return pending;
+}
+
PendingOperation* Connection::requestDisconnect()
{
return new PendingVoidMethodCall(this, this->Disconnect());
@@ -486,6 +516,8 @@ struct PendingHandles::Private
QStringList namesRequested;
UIntList handlesToReference;
QDBusError error;
+ // Replace with the ReferencedHandles instance
+ bool replyReceived;
};
PendingHandles::PendingHandles(Connection* connection, uint handleType, const QStringList& names)
@@ -495,15 +527,17 @@ PendingHandles::PendingHandles(Connection* connection, uint handleType, const QS
mPriv->handleType = handleType;
mPriv->isRequest = true;
mPriv->namesRequested = names;
+ mPriv->replyReceived = false;
}
-PendingHandles::PendingHandles(Connection* connection, uint handleType, const UIntList& handles)
+PendingHandles::PendingHandles(Connection* connection, uint handleType, const UIntList& handles, bool allHeld)
: QObject(connection), mPriv(new Private)
{
mPriv->connection = connection;
mPriv->handleType = handleType;
mPriv->isRequest = false;
mPriv->handlesToReference = handles;
+ mPriv->replyReceived = false;
}
PendingHandles::~PendingHandles()
@@ -543,8 +577,8 @@ const UIntList& PendingHandles::handlesToReference() const
bool PendingHandles::isFinished() const
{
- // TODO
- return false || !mPriv->error.message().isEmpty();
+ // Replace with check for the ReferencedHandles instance
+ return mPriv->replyReceived || !mPriv->error.message().isEmpty();
}
bool PendingHandles::isError() const
@@ -569,18 +603,33 @@ bool PendingHandles::isValid() const
void PendingHandles::onCallFinished(QDBusPendingCallWatcher* watcher)
{
- QDBusPendingReply<QDBusObjectPath> reply = *watcher;
+ // Thanks QDBus for this the need for this error-handling code duplication
+ if (mPriv->isRequest) {
+ QDBusPendingReply<UIntList> reply;
- if (mPriv->isRequest)
debug() << "Received reply to RequestHandles";
- else
- debug() << "Received reply to HoldHandles";
- if (!reply.isError()) {
- debug() << " Success";
+ if (reply.isError()) {
+ debug().nospace() << " Failure: error " << reply.error().name() << ": " << reply.error().message();
+ mPriv->error = reply.error();
+ } else {
+ // Replace with constructing the ReferencedHandles from
+ // reply.value()
+ mPriv->replyReceived = true;
+ }
} else {
- debug().nospace() << " Failure: error " << reply.error().name() << ": " << reply.error().message();
- mPriv->error = reply.error();
+ QDBusPendingReply<void> reply;
+
+ debug() << "Received reply to HoldHandles";
+
+ if (reply.isError()) {
+ debug().nospace() << " Failure: error " << reply.error().name() << ": " << reply.error().message();
+ mPriv->error = reply.error();
+ } else {
+ // Replace with constructing the ReferencedHandles from
+ // handlesToReference()
+ mPriv->replyReceived = true;
+ }
}
debug() << " Emitting finished()";
diff --git a/TelepathyQt4/cli-connection.h b/TelepathyQt4/cli-connection.h
index 417d822..701c5eb 100644
--- a/TelepathyQt4/cli-connection.h
+++ b/TelepathyQt4/cli-connection.h
@@ -431,6 +431,60 @@ public:
*/
PendingOperation* requestDisconnect();
+ /*
+ * Requests handles of the given type for the given entities (contacts,
+ * rooms, lists, etc.).
+ *
+ * Upon completion, the reply to the request can be retrieved through the
+ * returned PendingHandles object. The object also provides access to the
+ * parameters with which the call was made and a signal to connect to to get
+ * notification of the request finishing processing. See the documentation
+ * for that class for more info.
+ *
+ * The returned PendingHandles object should be freed using
+ * its QObject::deleteLater() method after it is no longer used. However,
+ * all PendingHandles objects resulting from requests to a particular
+ * Connection will be freed when the Connection itself is freed. Conversely,
+ * this means that the PendingHandles object should not be used after the
+ * Connection is destroyed.
+ *
+ * \sa PendingHandles
+ *
+ * \param handleType Type for the handles to request, as specified in
+ * #HandleType.
+ * \param names Names of the entities to request handles for.
+ * \return Pointer to a newly constructed PendingHandles object, tracking
+ * the progress of the request.
+ */
+ PendingHandles* requestHandles(uint handleType, const QStringList& names);
+
+ /**
+ * Requests a reference to the given handles. Handles not explicitly
+ * requested (via requestHandles()) but eg. observed in a signal need to be
+ * referenced to guarantee them staying valid.
+ *
+ * Upon completion, the reply to the operation can be retrieved through the
+ * returned PendingHandles object. The object also provides access to the
+ * parameters with which the call was made and a signal to connect to to get
+ * notification of the request finishing processing. See the documentation
+ * for that class for more info.
+ *
+ * The returned PendingHandles object should be freed using
+ * its QObject::deleteLater() method after it is no longer used. However,
+ * all PendingHandles objects resulting from requests to a particular
+ * Connection will be freed when the Connection itself is freed. Conversely,
+ * this means that the PendingHandles object should not be used after the
+ * Connection is destroyed.
+ *
+ * \sa PendingHandles
+ *
+ * \param handleType Type of the handles given, as specified in #HandleType.
+ * \param handles Handles to request a reference to.
+ * \return Pointer to a newly constructed PendingHandles object, tracking
+ * the progress of the request.
+ */
+ PendingHandles* referenceHandles(uint handleType, const UIntList& handles);
+
Q_SIGNALS:
/**
* Emitted whenever the readiness of the Connection changes.
@@ -594,7 +648,7 @@ private:
friend class Connection;
PendingHandles(Connection* connection, uint handleType, const QStringList& names);
- PendingHandles(Connection* connection, uint handleType, const UIntList& handles);
+ PendingHandles(Connection* connection, uint handleType, const UIntList& handles, bool allHeld);
struct Private;
friend struct Private;
--
1.5.6.5
More information about the Telepathy-commits
mailing list