[Telepathy-commits] [telepathy-qt4/master] Use OptionalInterfaceFactory for the optional interfaces in Connection

Olli Salli olli.salli at collabora.co.uk
Tue Sep 9 07:07:24 PDT 2008


---
 TelepathyQt4/cli-connection.cpp |   21 ---------------------
 TelepathyQt4/cli-connection.h   |   17 ++++-------------
 2 files changed, 4 insertions(+), 34 deletions(-)

diff --git a/TelepathyQt4/cli-connection.cpp b/TelepathyQt4/cli-connection.cpp
index f6d6e52..e4f361d 100644
--- a/TelepathyQt4/cli-connection.cpp
+++ b/TelepathyQt4/cli-connection.cpp
@@ -43,7 +43,6 @@ struct Connection::Private
     Connection& parent;
 
     // Optional interface proxies
-    QMap<QString, QDBusAbstractInterface*> optionalInterfaces;
     ConnectionInterfaceAliasingInterface* aliasing;
     ConnectionInterfacePresenceInterface* presence;
     DBus::PropertiesInterface* properties;
@@ -264,26 +263,6 @@ SimpleStatusSpecMap Connection::simplePresenceStatuses() const
     return mPriv->simplePresenceStatuses;
 }
 
-QDBusAbstractInterface* Connection::internalCachedInterface(const QString& name) const
-{
-    if (mPriv->optionalInterfaces.contains(name)) {
-        debug() << "Returning cached interface for" << name;
-        return mPriv->optionalInterfaces.value(name);
-    } else {
-        debug() << "No interface found for" << name;
-        return 0;
-    }
-}
-
-void Connection::internalInterfaceCache(QDBusAbstractInterface* interface) const
-{
-    QString name = interface->interface();
-    Q_ASSERT(!mPriv->optionalInterfaces.contains(name));
-
-    debug() << "Caching interface" << name;
-    mPriv->optionalInterfaces[name] = interface;
-}
-
 void Connection::onStatusChanged(uint status, uint reason)
 {
     debug() << "Status changed from" << mPriv->status << "to" << status << "because of" << reason;
diff --git a/TelepathyQt4/cli-connection.h b/TelepathyQt4/cli-connection.h
index fd1d348..313ee09 100644
--- a/TelepathyQt4/cli-connection.h
+++ b/TelepathyQt4/cli-connection.h
@@ -48,6 +48,7 @@
 
 #include <TelepathyQt4/Constants>
 #include <TelepathyQt4/Client/DBus>
+#include <TelepathyQt4/Client/OptionalInterfaceFactory>
 
 namespace Telepathy
 {
@@ -75,7 +76,7 @@ namespace Client
  * don't make any DBus calls; instead, they return values cached from a previous
  * introspection run.
  */
-class Connection : public ConnectionInterface
+class Connection : public ConnectionInterface, private OptionalInterfaceFactory
 {
     Q_OBJECT
     Q_ENUMS(Readiness);
@@ -244,15 +245,8 @@ public:
         if (!forcePresent && !interfaces().contains(name))
             return 0;
 
-        // If there is a interface cached already, return it
-        QDBusAbstractInterface* cached = internalCachedInterface(name);
-        if (cached)
-            return static_cast<Interface*>(cached);
-
-        // Otherwise, cache and return a newly constructed proxy
-        Interface* interface = new Interface(*this, 0);
-        internalInterfaceCache(interface);
-        return interface;
+        // If present or forced, delegate to OptionalInterfaceFactory
+        return OptionalInterfaceFactory::interface<Interface>(*this);
     }
 
     inline ConnectionInterfaceAliasingInterface* aliasingInterface(bool forcePresent = false) const
@@ -302,9 +296,6 @@ private Q_SLOTS:
     void gotSimpleStatuses(QDBusPendingCallWatcher* watcher);
 
 private:
-    QDBusAbstractInterface* internalCachedInterface(const QString& name) const;
-    void internalInterfaceCache(QDBusAbstractInterface* interface) const;
-
     struct Private;
     friend struct Private;
     Private *mPriv;
-- 
1.5.6.5




More information about the Telepathy-commits mailing list