[Telepathy-commits] [telepathy-qt4/master] Channel: Added isReady/becomeReady.
Andre Moreira Magalhaes (andrunko)
andre.magalhaes at collabora.co.uk
Wed Jan 28 13:26:05 PST 2009
---
TelepathyQt4/Client/channel.cpp | 73 +++++++++++++++++++++++++++++++++++++++
TelepathyQt4/Client/channel.h | 10 +++++
2 files changed, 83 insertions(+), 0 deletions(-)
diff --git a/TelepathyQt4/Client/channel.cpp b/TelepathyQt4/Client/channel.cpp
index d6c9744..eaf892d 100644
--- a/TelepathyQt4/Client/channel.cpp
+++ b/TelepathyQt4/Client/channel.cpp
@@ -27,6 +27,8 @@
#include "TelepathyQt4/debug-internal.h"
#include <TelepathyQt4/Client/Connection>
+#include <TelepathyQt4/Client/PendingOperation>
+#include <TelepathyQt4/Client/PendingSuccess>
#include <TelepathyQt4/Constants>
#include <QQueue>
@@ -77,6 +79,8 @@ struct Channel::Private
void changeReadiness(Readiness newReadiness);
+ class PendingReady;
+
// Public object
Channel *parent;
@@ -90,11 +94,15 @@ struct Channel::Private
ChannelInterfaceGroupInterface *group;
DBus::PropertiesInterface *properties;
+ PendingReady *pendingReady;
+
// Introspection
Readiness readiness;
QStringList interfaces;
QQueue<void (Private::*)()> introspectQueue;
+ Channel::Features features;
+
// Introspected properties
// Main interface
@@ -123,13 +131,29 @@ struct Channel::Private
GroupMemberChangeInfo groupSelfRemoveInfo;
};
+class Channel::Private::PendingReady : public PendingOperation
+{
+ // Channel is a friend so it can call finished() etc.
+ friend class Channel;
+
+public:
+ PendingReady(Channel *parent);
+};
+
+Channel::Private::PendingReady::PendingReady(Channel *parent)
+ : PendingOperation(parent)
+{
+}
+
Channel::Private::Private(Channel *parent, Connection *connection)
: parent(parent),
baseInterface(new ChannelInterface(parent->dbusConnection(),
parent->busName(), parent->objectPath(), parent)),
group(0),
properties(0),
+ pendingReady(0),
readiness(ReadinessJustCreated),
+ features(0),
targetHandleType(0),
targetHandle(0),
groupFlags(0),
@@ -640,6 +664,49 @@ uint Channel::targetHandle() const
}
/**
+ * Return whether this object has finished its initial setup.
+ *
+ * This is mostly useful as a sanity check, in code that shouldn't be run
+ * until the object is ready. To wait for the object to be ready, call
+ * becomeReady() and connect to the finished signal on the result.
+ *
+ * \param features Which features should be tested.
+ * \return \c true if the object has finished initial setup.
+ */
+bool Channel::isReady(Features features) const
+{
+ return (mPriv->readiness == ReadinessFull)
+ && ((mPriv->features & features) == features);
+}
+
+/**
+ * Return a pending operation which will succeed when this object finishes
+ * its initial setup, or will fail if a fatal error occurs during this
+ * initial setup.
+ *
+ * \param features Which features should be tested.
+ * \return A PendingOperation which will emit PendingOperation::finished
+ * when this object has finished or failed its initial setup.
+ */
+PendingOperation *Channel::becomeReady(Features features)
+{
+ if (isReady(features)) {
+ return new PendingSuccess(this);
+ }
+
+ if (features != 0) {
+ return new PendingFailure(this, TELEPATHY_ERROR_NOT_IMPLEMENTED,
+ "Unimplemented");
+ }
+
+ if (!mPriv->pendingReady) {
+ mPriv->pendingReady = new Private::PendingReady(this);
+ }
+ return mPriv->pendingReady;
+}
+
+
+/**
* Close the channel.
*
* When this method is used as a slot, it is fire-and-forget. If you want
@@ -1633,6 +1700,12 @@ void Channel::continueIntrospection()
if (mPriv->readiness < ReadinessFull) {
if (mPriv->introspectQueue.isEmpty()) {
mPriv->changeReadiness(ReadinessFull);
+
+ if (mPriv->pendingReady) {
+ mPriv->pendingReady->setFinished();
+ // it will delete itself later
+ mPriv->pendingReady = 0;
+ }
}
else {
(mPriv->*(mPriv->introspectQueue.dequeue()))();
diff --git a/TelepathyQt4/Client/channel.h b/TelepathyQt4/Client/channel.h
index 9341272..57d9bf6 100644
--- a/TelepathyQt4/Client/channel.h
+++ b/TelepathyQt4/Client/channel.h
@@ -42,6 +42,7 @@ namespace Client
{
class Connection;
+class PendingOperation;
class Channel : public StatefulDBusProxy,
private OptionalInterfaceFactory<Channel>
@@ -51,6 +52,11 @@ class Channel : public StatefulDBusProxy,
Q_ENUMS(Readiness)
public:
+ enum Feature {
+ _Paddding = 0xFFFFFFFF
+ };
+ Q_DECLARE_FLAGS(Features, Feature)
+
enum Readiness {
ReadinessJustCreated = 0,
ReadinessFull = 5,
@@ -76,6 +82,10 @@ public:
uint targetHandle() const;
+ bool isReady(Features features = 0) const;
+
+ PendingOperation *becomeReady(Features features = 0);
+
public Q_SLOTS:
QDBusPendingReply<> close();
--
1.5.6.5
More information about the telepathy-commits
mailing list