[Telepathy-commits] [telepathy-qt4/master] Use OptionalInterfaceFactory in Channel (currently only for Properties)

Olli Salli olli.salli at collabora.co.uk
Tue Sep 9 13:18:44 PDT 2008


---
 TelepathyQt4/cli-channel.cpp |   13 +++++++---
 TelepathyQt4/cli-channel.h   |   52 +++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 60 insertions(+), 5 deletions(-)

diff --git a/TelepathyQt4/cli-channel.cpp b/TelepathyQt4/cli-channel.cpp
index 84e3413..c3c051f 100644
--- a/TelepathyQt4/cli-channel.cpp
+++ b/TelepathyQt4/cli-channel.cpp
@@ -42,7 +42,7 @@ struct Channel::Private
     Channel& parent;
 
     // Optional interface proxies
-    DBus::PropertiesInterface properties;
+    DBus::PropertiesInterface* properties;
 
     // Introspection
     Readiness readiness;
@@ -55,11 +55,11 @@ struct Channel::Private
     uint targetHandle;
 
     Private(Channel& parent)
-        : parent(parent),
-          properties(parent)
+        : parent(parent)
     {
         debug() << "Creating new Channel";
 
+        properties = 0;
         readiness = ReadinessJustCreated;
 
         debug() << "Connecting to Channel::Closed()";
@@ -73,10 +73,15 @@ struct Channel::Private
 
     void introspectMain()
     {
+        if (!properties) {
+            properties = parent.propertiesInterface();
+            Q_ASSERT(properties != 0);
+        }
+
         debug() << "Calling Properties::GetAll(Channel)";
         QDBusPendingCallWatcher* watcher =
             new QDBusPendingCallWatcher(
-                    properties.GetAll(TELEPATHY_INTERFACE_CHANNEL), &parent);
+                    properties->GetAll(TELEPATHY_INTERFACE_CHANNEL), &parent);
         parent.connect(watcher,
                        SIGNAL(finished(QDBusPendingCallWatcher*)),
                        SLOT(gotMainProperties(QDBusPendingCallWatcher*)));
diff --git a/TelepathyQt4/cli-channel.h b/TelepathyQt4/cli-channel.h
index 1cc2773..2cdb533 100644
--- a/TelepathyQt4/cli-channel.h
+++ b/TelepathyQt4/cli-channel.h
@@ -43,6 +43,9 @@
 
 #include <TelepathyQt4/_gen/cli-channel.h>
 
+#include <TelepathyQt4/Client/DBus>
+#include <TelepathyQt4/Client/OptionalInterfaceFactory>
+
 namespace Telepathy
 {
 namespace Client
@@ -59,6 +62,7 @@ namespace Client
  * <ul>
  *  <li>Life cycle tracking</li>
  *  <li>Getting the channel type, handle type, handle and interfaces automatically</li>
+ *  <li>Shared optional interface proxy instances</li>
  * </ul>
  *
  * The remote object state accessor functions on this object (interfaces(),
@@ -67,7 +71,7 @@ namespace Client
  * process populates their values in the most efficient way possible based on
  * what the service implements.
  */
-class Channel : public ChannelInterface
+class Channel : public ChannelInterface, private OptionalInterfaceFactory
 {
     Q_OBJECT
     Q_ENUMS(Readiness)
@@ -173,6 +177,52 @@ public:
      */
     uint targetHandle() const;
 
+    /**
+     * Returns a pointer to a valid instance of a given %Channel optional
+     * interface class, associated with the same remote object the Channel is
+     * associated with, and destroyed together with the Channel.
+     *
+     * If the list returned by interfaces() doesn't contain the name of the
+     * interface requested, or the Channel doesn't have readiness
+     * #ReadinessFull, <code>0</code> is returned. This check can be bypassed by
+     * specifying <code>true</code> for <code>forcePresent</code>, in which case
+     * a valid instance is always returned.
+     *
+     * \see OptionalInterfaceFactory::interface
+     *
+     * \tparam Interface Class of the optional interface to get.
+     * \param forcePresent Should an instance be returned even if it can't be
+     *                     determined that the remote object supports the
+     *                     requested interface.
+     * \return Pointer to an instance of the interface class, or <code>0</code>.
+     */
+    template <class Interface>
+    inline Interface* optionalInterface(bool forcePresent = false) const
+    {
+        // Check for the remote object supporting the interface
+        QString name(Interface::staticInterfaceName());
+        if (!forcePresent && !interfaces().contains(name))
+            return 0;
+
+        // If present or forced, delegate to OptionalInterfaceFactory
+        return OptionalInterfaceFactory::interface<Interface>(*this);
+    }
+
+    /**
+     * Convenience function for getting a Properties interface proxy. The
+     * Properties interface is not necessarily reported by the services, so a
+     * <code>forcePresent</code> parameter is not provided, and the interface is
+     * always assumed to be present.
+     *
+     * \see optionalInterface()
+     *
+     * \return <code>optionalInterface<DBus::PropertiesInterface>(true)</code>
+     */
+    inline DBus::PropertiesInterface* propertiesInterface() const
+    {
+        return optionalInterface<DBus::PropertiesInterface>(true);
+    }
+
 Q_SIGNALS:
     /**
      * Emitted whenever the readiness of the Channel changes.
-- 
1.5.6.5




More information about the Telepathy-commits mailing list