[Telepathy-commits] [telepathy-qt4/master] Add stub PendingHandles class to be used for Connection::{request, reference}Handles
Olli Salli
olli.salli at collabora.co.uk
Wed Jan 21 04:42:12 PST 2009
---
TelepathyQt4/cli-connection.cpp | 111 +++++++++++++++++++++++++++++
TelepathyQt4/cli-connection.h | 149 +++++++++++++++++++++++++++++++++++++++
2 files changed, 260 insertions(+), 0 deletions(-)
diff --git a/TelepathyQt4/cli-connection.cpp b/TelepathyQt4/cli-connection.cpp
index 4219987..e2a7554 100644
--- a/TelepathyQt4/cli-connection.cpp
+++ b/TelepathyQt4/cli-connection.cpp
@@ -478,5 +478,116 @@ PendingOperation* Connection::requestDisconnect()
return new PendingVoidMethodCall(this, this->Disconnect());
}
+struct PendingHandles::Private
+{
+ Connection* connection;
+ uint handleType;
+ bool isRequest;
+ QStringList namesRequested;
+ UIntList handlesToReference;
+ QDBusError error;
+};
+
+PendingHandles::PendingHandles(Connection* connection, uint handleType, const QStringList& names)
+ : QObject(connection), mPriv(new Private)
+{
+ mPriv->connection = connection;
+ mPriv->handleType = handleType;
+ mPriv->isRequest = true;
+ mPriv->namesRequested = names;
+}
+
+PendingHandles::PendingHandles(Connection* connection, uint handleType, const UIntList& handles)
+ : QObject(connection), mPriv(new Private)
+{
+ mPriv->connection = connection;
+ mPriv->handleType = handleType;
+ mPriv->isRequest = false;
+ mPriv->handlesToReference = handles;
+}
+
+PendingHandles::~PendingHandles()
+{
+ delete mPriv;
+}
+
+Connection* PendingHandles::connection() const
+{
+ return mPriv->connection;
+}
+
+uint PendingHandles::handleType() const
+{
+ return mPriv->handleType;
+}
+
+bool PendingHandles::isRequest() const
+{
+ return mPriv->isRequest;
+}
+
+bool PendingHandles::isReference() const
+{
+ return !isRequest();
+}
+
+const QStringList& PendingHandles::namesRequested() const
+{
+ return mPriv->namesRequested;
+}
+
+const UIntList& PendingHandles::handlesToReference() const
+{
+ return mPriv->handlesToReference;
+}
+
+bool PendingHandles::isFinished() const
+{
+ // TODO
+ return false || !mPriv->error.message().isEmpty();
+}
+
+bool PendingHandles::isError() const
+{
+ return !mPriv->error.message().isEmpty();
+}
+
+const QDBusError& PendingHandles::error() const
+{
+ if (isValid())
+ warning() << "PendingHandles::error() called when valid";
+ else if (!isFinished())
+ warning() << "PendingHandles::error() called before finished";
+
+ return mPriv->error;
+}
+
+bool PendingHandles::isValid() const
+{
+ return isFinished() && !isError();
+}
+
+void PendingHandles::onCallFinished(QDBusPendingCallWatcher* watcher)
+{
+ QDBusPendingReply<QDBusObjectPath> reply = *watcher;
+
+ if (mPriv->isRequest)
+ debug() << "Received reply to RequestHandles";
+ else
+ debug() << "Received reply to HoldHandles";
+
+ if (!reply.isError()) {
+ debug() << " Success";
+ } else {
+ debug().nospace() << " Failure: error " << reply.error().name() << ": " << reply.error().message();
+ mPriv->error = reply.error();
+ }
+
+ debug() << " Emitting finished()";
+ emit finished(this);
+
+ watcher->deleteLater();
+}
+
}
}
diff --git a/TelepathyQt4/cli-connection.h b/TelepathyQt4/cli-connection.h
index 4c4acf5..417d822 100644
--- a/TelepathyQt4/cli-connection.h
+++ b/TelepathyQt4/cli-connection.h
@@ -44,6 +44,7 @@
namespace Telepathy {
namespace Client {
class Connection;
+class PendingHandles;
}
}
@@ -452,6 +453,154 @@ private:
Private *mPriv;
};
+/**
+ * \class PendingHandles
+ * \ingroup clientconn
+ * \headerfile <TelepathyQt4/cli-connection.h> <TelepathyQt4/Client/Connection>
+ *
+ * Class containing the parameters of and the reply to an asynchronous handle
+ * request/hold. Instances of this class cannot be constructed directly; the
+ * only ways to get one are to use Connection::requestHandles() or
+ * Connection::referenceHandles().
+ */
+class PendingHandles : public QObject
+{
+ Q_OBJECT
+
+public:
+ /**
+ * Class destructor.
+ */
+ ~PendingHandles();
+
+ /**
+ * Returns the Connection object through which the operation was made.
+ *
+ * \return Pointer to the Connection.
+ */
+ Connection* connection() const;
+
+ /**
+ * Returns the handle type specified in the operation.
+ *
+ * \return The handle type, as specified in #HandleType.
+ */
+ uint handleType() const;
+
+ /**
+ * Returns whether the operation was a handle request (as opposed to a
+ * reference of existing handles).
+ *
+ * \sa isReference()
+ *
+ * \return Whether the operation was a request (== !isReference()).
+ */
+ bool isRequest() const;
+
+ /**
+ * Returns whether the operation was a handle reference (as opposed to a
+ * request for new handles).
+ *
+ * \sa isRequest()
+ *
+ * \return Whether the operation was a reference (== !isRequest()).
+ */
+ bool isReference() const;
+
+ /**
+ * If the operation was a request (as returned by isRequest()), returns the
+ * names of the entities for which handles were requested for. Otherwise,
+ * returns an empty list.
+ *
+ * \return Reference to a list of the names of the entities.
+ */
+ const QStringList& namesRequested() const;
+
+ /**
+ * If the operation was a reference (as returned by isReference()), returns
+ * the handles which were to be referenced. Otherwise, returns an empty
+ * list.
+ *
+ * \return Reference to a list of the handles specified to be referenced.
+ */
+ const UIntList& handlesToReference() const;
+
+ /**
+ * Returns whether or not the operation has finished processing.
+ *
+ * \sa finished()
+ *
+ * \return If the operation is finished.
+ */
+ bool isFinished() const;
+
+ /**
+ * Returns whether or not the operation resulted in an error. If the
+ * operation has not yet finished processing (isFinished() returns
+ * <code>false</code>), this cannot yet be known, and <code>false</code>
+ * will be returned.
+ *
+ * \return <code>true</code> iff the operation has finished processing AND
+ * has resulted in an error.
+ */
+ bool isError() const;
+
+ /**
+ * Returns the error which the operation resulted in, if any. If isError()
+ * returns <code>false</code>, the operation has not (at least yet) resulted
+ * in an error, and an undefined value will be returned.
+ *
+ * \return The error as a QDBusError.
+ */
+ const QDBusError& error() const;
+
+ /**
+ * Returns whether or not the operation completed successfully. If the operation
+ * has not yet finished processing (isFinished() returns <code>false</code>),
+ * this cannot yet be known, and <code>false</code> will be returned.
+ *
+ * \return <code>true</code> iff the operation has finished processing AND has
+ * completed successfully.
+ */
+ bool isValid() const;
+
+ /*
+ * TODO: Add ReferencedHandles and way to get it from here
+ *
+ * Probably like this:
+ *
+ * const ReferencedHandles& handles() const;
+ *
+ * So that the first user getting a copy of the handles doesn't have to do
+ * an extra ref. An internal ReferencedHandles can be stored anyway for
+ * unrefing purposes.
+ */
+
+Q_SIGNALS:
+ /**
+ * Emitted when the operation finishes processing. isFinished() will then
+ * start returning <code>true</code> and isError(), error(), isValid() and
+ * channel() will become meaningful to use.
+ *
+ * \param pendingHandles The PendingHandles object for which the operation has
+ * finished.
+ */
+ void finished(Telepathy::Client::PendingHandles* pendingHandles);
+
+private Q_SLOTS:
+ void onCallFinished(QDBusPendingCallWatcher* watcher);
+
+private:
+ friend class Connection;
+
+ PendingHandles(Connection* connection, uint handleType, const QStringList& names);
+ PendingHandles(Connection* connection, uint handleType, const UIntList& handles);
+
+ struct Private;
+ friend struct Private;
+ Private *mPriv;
+};
+
}
}
--
1.5.6.5
More information about the Telepathy-commits
mailing list