[Telepathy-commits] [telepathy-qt4/master] ReadyObject: Added to repository.

Andre Moreira Magalhaes (andrunko) andre.magalhaes at collabora.co.uk
Wed Mar 18 08:48:45 PDT 2009


ReadyObject is a base class for all classes that wants to implement
isReady/becomeReady features.
---
 TelepathyQt4/Client/ReadyObject        |   13 +++
 TelepathyQt4/Client/readiness-helper.h |    4 +-
 TelepathyQt4/Client/ready-object.cpp   |  147 ++++++++++++++++++++++++++++++++
 TelepathyQt4/Client/ready-object.h     |   67 +++++++++++++++
 TelepathyQt4/Makefile.am               |    3 +
 5 files changed, 232 insertions(+), 2 deletions(-)
 create mode 100644 TelepathyQt4/Client/ReadyObject
 create mode 100644 TelepathyQt4/Client/ready-object.cpp
 create mode 100644 TelepathyQt4/Client/ready-object.h

diff --git a/TelepathyQt4/Client/ReadyObject b/TelepathyQt4/Client/ReadyObject
new file mode 100644
index 0000000..37e4419
--- /dev/null
+++ b/TelepathyQt4/Client/ReadyObject
@@ -0,0 +1,13 @@
+#ifndef _TelepathyQt4_Client_ReadyObject_HEADER_GUARD_
+#define _TelepathyQt4_Client_ReadyObject_HEADER_GUARD_
+
+#ifndef IN_TELEPATHY_QT4_HEADER
+#define IN_TELEPATHY_QT4_HEADER
+#endif
+
+#include <TelepathyQt4/Client/ready-object.h>
+
+#undef IN_TELEPATHY_QT4_HEADER
+
+#endif
+// vim:set ft=cpp:
diff --git a/TelepathyQt4/Client/readiness-helper.h b/TelepathyQt4/Client/readiness-helper.h
index 201cb13..1ee9861 100644
--- a/TelepathyQt4/Client/readiness-helper.h
+++ b/TelepathyQt4/Client/readiness-helper.h
@@ -85,8 +85,8 @@ public:
     typedef QMap<Feature, Introspectable> Introspectables;
 
     ReadinessHelper(DBusProxy *proxy,
-            uint currentStatus,
-            const Introspectables &introspectables,
+            uint currentStatus = 0,
+            const Introspectables &introspectables = Introspectables(),
             QObject *parent = 0);
     ~ReadinessHelper();
 
diff --git a/TelepathyQt4/Client/ready-object.cpp b/TelepathyQt4/Client/ready-object.cpp
new file mode 100644
index 0000000..5e3af3c
--- /dev/null
+++ b/TelepathyQt4/Client/ready-object.cpp
@@ -0,0 +1,147 @@
+/*
+ * This file is part of TelepathyQt4
+ *
+ * Copyright (C) 2009 Collabora Ltd. <http://www.collabora.co.uk/>
+ * Copyright (C) 2009 Nokia Corporation
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#include <TelepathyQt4/Client/ReadyObject>
+
+#include "TelepathyQt4/debug-internal.h"
+
+#include <TelepathyQt4/Client/PendingReady>
+#include <TelepathyQt4/Client/ReadinessHelper>
+
+namespace Telepathy
+{
+namespace Client
+{
+
+struct ReadyObject::Private
+{
+    Private(ReadyObject *parent, DBusProxy *proxy,
+            Feature featureCore);
+    ~Private();
+
+    ReadyObject *parent;
+    DBusProxy *proxy;
+    Feature featureCore;
+    ReadinessHelper *readinessHelper;
+};
+
+ReadyObject::Private::Private(ReadyObject *parent, DBusProxy *proxy,
+        Feature featureCore)
+    : parent(parent),
+      proxy(proxy),
+      featureCore(featureCore),
+      readinessHelper(new ReadinessHelper(proxy))
+{
+}
+
+ReadyObject::Private::~Private()
+{
+    delete readinessHelper;
+}
+
+/**
+ * \class ReadyObject
+ * \ingroup clientreadiness
+ * \headerfile TelepathyQt4/Client/ready-object.h> <TelepathyQt4/Client/ReadyObject>
+ */
+
+/**
+ * Construct a new ReadyObject object.
+ *
+ * \param proxy The DBusProxy the object refers to.
+ * \param featureCore The core feature of the object.
+ */
+ReadyObject::ReadyObject(DBusProxy *proxy, const Feature &featureCore)
+    : mPriv(new Private(this, proxy, featureCore))
+{
+}
+
+/**
+ * Class destructor.
+ */
+ReadyObject::~ReadyObject()
+{
+    delete mPriv;
+}
+
+/**
+ * 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 The features which should be tested
+ * \return \c true if the object has finished its initial setup for basic
+ *         functionality plus the given features
+ */
+bool ReadyObject::isReady(const Features &features) const
+{
+    if (features.isEmpty()) {
+        return mPriv->readinessHelper->isReady(Features() << mPriv->featureCore);
+    }
+    return mPriv->readinessHelper->isReady(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.
+ *
+ * If an empty set is used FeatureCore will be considered as the requested
+ * feature.
+ *
+ * \param requestedFeatures The features which should be enabled
+ * \return A PendingReady object which will emit finished
+ *         when this object has finished or failed initial setup for basic
+ *         functionality plus the given features
+ */
+PendingReady *ReadyObject::becomeReady(const Features &requestedFeatures)
+{
+    if (requestedFeatures.isEmpty()) {
+        return mPriv->readinessHelper->becomeReady(Features() << mPriv->featureCore);
+    }
+    return mPriv->readinessHelper->becomeReady(requestedFeatures);
+
+}
+
+Features ReadyObject::requestedFeatures() const
+{
+    return mPriv->readinessHelper->requestedFeatures();
+}
+
+Features ReadyObject::actualFeatures() const
+{
+    return mPriv->readinessHelper->actualFeatures();
+}
+
+Features ReadyObject::missingFeatures() const
+{
+    return mPriv->readinessHelper->missingFeatures();
+}
+
+ReadinessHelper *ReadyObject::readinessHelper() const
+{
+    return mPriv->readinessHelper;
+}
+
+} // Telepathy::Client
+} // Telepathy
diff --git a/TelepathyQt4/Client/ready-object.h b/TelepathyQt4/Client/ready-object.h
new file mode 100644
index 0000000..c8e8349
--- /dev/null
+++ b/TelepathyQt4/Client/ready-object.h
@@ -0,0 +1,67 @@
+/*
+ * This file is part of TelepathyQt4
+ *
+ * Copyright (C) 2009 Collabora Ltd. <http://www.collabora.co.uk/>
+ * Copyright (C) 2009 Nokia Corporation
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#ifndef _TelepathyQt4_cli_ready_object_h_HEADER_GUARD_
+#define _TelepathyQt4_cli_ready_object_h_HEADER_GUARD_
+
+#ifndef IN_TELEPATHY_QT4_HEADER
+#error IN_TELEPATHY_QT4_HEADER
+#endif
+
+#include <TelepathyQt4/Client/Feature>
+
+namespace Telepathy
+{
+namespace Client
+{
+
+class DBusProxy;
+class PendingReady;
+class ReadinessHelper;
+
+class ReadyObject
+{
+    Q_DISABLE_COPY(ReadyObject)
+
+public:
+    ReadyObject(DBusProxy *proxy, const Feature &featureCore);
+    ~ReadyObject();
+
+    virtual bool isReady(const Features &features = Features()) const;
+    virtual PendingReady *becomeReady(const Features &requestedFeatures = Features());
+
+    virtual Features requestedFeatures() const;
+    virtual Features actualFeatures() const;
+    virtual Features missingFeatures() const;
+
+protected:
+    ReadinessHelper *readinessHelper() const;
+
+private:
+    struct Private;
+    friend struct Private;
+    Private *mPriv;
+};
+
+} // Telepathy::Client
+} // Telepathy
+
+#endif
diff --git a/TelepathyQt4/Makefile.am b/TelepathyQt4/Makefile.am
index e3cafce..1152241 100644
--- a/TelepathyQt4/Makefile.am
+++ b/TelepathyQt4/Makefile.am
@@ -64,6 +64,7 @@ libtelepathy_qt4_la_SOURCES = \
     Client/pending-string-list.cpp \
     Client/properties.cpp \
     Client/readiness-helper.cpp \
+    Client/ready-object.cpp \
     Client/referenced-handles.cpp \
     Client/room-list.cpp \
     Client/streamed-media-channel.cpp \
@@ -165,6 +166,7 @@ tpqt4clientinclude_HEADERS = \
     Client/PendingVoidMethodCall \
     Client/Properties \
     Client/ReadinessHelper \
+    Client/ReadyObject \
     Client/ReceivedMessage \
     Client/ReferencedHandles \
     Client/ReferencedHandlesIterator \
@@ -231,6 +233,7 @@ tpqt4clientinclude_HEADERS = \
     Client/pending-string-list.h \
     Client/properties.h \
     Client/readiness-helper.h \
+    Client/ready-object.h \
     Client/referenced-handles.h \
     Client/room-list.h \
     Client/simple-pending-operations.h \
-- 
1.5.6.5




More information about the telepathy-commits mailing list