[Telepathy-commits] [telepathy-qt4/master] OptionalInterfaceFactory: Be a template parameterized by DBusProxy subclasses
Simon McVittie
simon.mcvittie at collabora.co.uk
Fri Jan 23 01:49:17 PST 2009
This requires splitting out most of OIF into a non-template base class,
OptionalInterfaceCache, and a change to the calling convention of
interface().
---
TelepathyQt4/Client/account-manager.h | 6 +-
TelepathyQt4/Client/account.h | 5 +-
TelepathyQt4/Client/channel.h | 7 +-
TelepathyQt4/Client/connection-manager.h | 5 +-
TelepathyQt4/Client/connection.h | 8 ++-
TelepathyQt4/Client/optional-interface-factory.cpp | 14 ++--
TelepathyQt4/Client/optional-interface-factory.h | 68 +++++++++++++-------
7 files changed, 68 insertions(+), 45 deletions(-)
diff --git a/TelepathyQt4/Client/account-manager.h b/TelepathyQt4/Client/account-manager.h
index 662e99e..1ab0c58 100644
--- a/TelepathyQt4/Client/account-manager.h
+++ b/TelepathyQt4/Client/account-manager.h
@@ -42,11 +42,12 @@ namespace Client
{
class Account;
+class AccountManager;
class PendingAccount;
class PendingOperation;
class AccountManager : public StatelessDBusProxy,
- private OptionalInterfaceFactory
+ private OptionalInterfaceFactory<AccountManager>
{
Q_OBJECT
@@ -65,8 +66,7 @@ public:
inline DBus::PropertiesInterface *propertiesInterface() const
{
- return OptionalInterfaceFactory::interface<DBus::PropertiesInterface>(
- *baseInterface());
+ return OptionalInterfaceFactory<AccountManager>::interface<DBus::PropertiesInterface>(this);
}
QStringList validAccountPaths() const;
diff --git a/TelepathyQt4/Client/account.h b/TelepathyQt4/Client/account.h
index 6e3f663..962a00e 100644
--- a/TelepathyQt4/Client/account.h
+++ b/TelepathyQt4/Client/account.h
@@ -43,6 +43,7 @@ namespace Telepathy
namespace Client
{
+class Account;
class AccountManager;
class Connection;
class PendingConnection;
@@ -50,7 +51,7 @@ class PendingOperation;
class ProtocolInfo;
class Account : public StatelessDBusProxy,
- private OptionalInterfaceFactory
+ private OptionalInterfaceFactory<Account>
{
Q_OBJECT
@@ -144,7 +145,7 @@ public:
}
// If present or forced, delegate to OptionalInterfaceFactory
- return OptionalInterfaceFactory::interface<Interface>(*baseInterface());
+ return OptionalInterfaceFactory<Account>::interface<Interface>(this);
}
inline DBus::PropertiesInterface *propertiesInterface() const
diff --git a/TelepathyQt4/Client/channel.h b/TelepathyQt4/Client/channel.h
index 6465c56..bca870f 100644
--- a/TelepathyQt4/Client/channel.h
+++ b/TelepathyQt4/Client/channel.h
@@ -92,7 +92,8 @@ class Connection;
* signaled by Connection::readinessChanged) or is deleted, the Channel object
* will transition to ReadinessDead too.
*/
-class Channel : public StatefulDBusProxy, private OptionalInterfaceFactory
+class Channel : public StatefulDBusProxy,
+ private OptionalInterfaceFactory<Channel>
{
Q_OBJECT
Q_ENUMS(Readiness)
@@ -585,7 +586,7 @@ public:
return 0;
// If present or forced, delegate to OptionalInterfaceFactory
- return OptionalInterfaceFactory::interface<Interface>(*baseInterface());
+ return OptionalInterfaceFactory<Channel>::interface<Interface>(this);
}
/**
@@ -711,7 +712,7 @@ public:
return 0;
// If correct type or check bypassed, delegate to OIF
- return OptionalInterfaceFactory::interface<Interface>(*baseInterface());
+ return OptionalInterfaceFactory<Channel>::interface<Interface>(this);
}
/**
diff --git a/TelepathyQt4/Client/connection-manager.h b/TelepathyQt4/Client/connection-manager.h
index ba400c8..52df936 100644
--- a/TelepathyQt4/Client/connection-manager.h
+++ b/TelepathyQt4/Client/connection-manager.h
@@ -113,7 +113,7 @@ private:
class ConnectionManager : public StatelessDBusProxy,
- private OptionalInterfaceFactory
+ private OptionalInterfaceFactory<ConnectionManager>
{
Q_OBJECT
@@ -136,8 +136,7 @@ public:
inline DBus::PropertiesInterface *propertiesInterface() const
{
- return OptionalInterfaceFactory::interface<DBus::PropertiesInterface>(
- *baseInterface());
+ return OptionalInterfaceFactory<ConnectionManager>::interface<DBus::PropertiesInterface>(this);
}
bool isReady() const;
diff --git a/TelepathyQt4/Client/connection.h b/TelepathyQt4/Client/connection.h
index 4ae9a43..3538f3c 100644
--- a/TelepathyQt4/Client/connection.h
+++ b/TelepathyQt4/Client/connection.h
@@ -98,8 +98,10 @@ namespace Client
* #ReadinessFull indicates that the introspection process is finished. See the
* individual accessor descriptions for details on which functions can be used
* in the different states.
+ *
*/
-class Connection : public StatefulDBusProxy, private OptionalInterfaceFactory
+class Connection : public StatefulDBusProxy,
+ private OptionalInterfaceFactory<Connection>
{
Q_OBJECT
Q_ENUMS(Readiness);
@@ -295,7 +297,7 @@ public:
* \return Pointer to an instance of the interface class, or <code>0</code>.
*/
template <class Interface>
- inline Interface* optionalInterface(InterfaceSupportedChecking check = CheckInterfaceSupported) const
+ inline Interface *optionalInterface(InterfaceSupportedChecking check = CheckInterfaceSupported) const
{
// Check for the remote object supporting the interface
QString name(Interface::staticInterfaceName());
@@ -303,7 +305,7 @@ public:
return 0;
// If present or forced, delegate to OptionalInterfaceFactory
- return OptionalInterfaceFactory::interface<Interface>(*baseInterface());
+ return OptionalInterfaceFactory<Connection>::interface<Interface>(this);
}
/**
diff --git a/TelepathyQt4/Client/optional-interface-factory.cpp b/TelepathyQt4/Client/optional-interface-factory.cpp
index a44c7b3..5ff2400 100644
--- a/TelepathyQt4/Client/optional-interface-factory.cpp
+++ b/TelepathyQt4/Client/optional-interface-factory.cpp
@@ -31,20 +31,20 @@ namespace Telepathy
namespace Client
{
-struct OptionalInterfaceFactory::Private
+struct OptionalInterfaceCache::Private
{
QMap<QString, AbstractInterface*> interfaces;
};
-OptionalInterfaceFactory::OptionalInterfaceFactory()
+OptionalInterfaceCache::OptionalInterfaceCache()
: mPriv(new Private())
{
- debug() << "Constructing OptionalInterfaceFactory";
+ debug() << "Constructing OptionalInterfaceCache";
}
-OptionalInterfaceFactory::~OptionalInterfaceFactory()
+OptionalInterfaceCache::~OptionalInterfaceCache()
{
- debug() << "Destroying OptionalInterfaceFactory";
+ debug() << "Destroying OptionalInterfaceCache";
for (QMap<QString, AbstractInterface *>::iterator i = mPriv->interfaces.begin();
i != mPriv->interfaces.end();
@@ -56,7 +56,7 @@ OptionalInterfaceFactory::~OptionalInterfaceFactory()
delete mPriv;
}
-AbstractInterface *OptionalInterfaceFactory::getCached(const QString &name) const
+AbstractInterface *OptionalInterfaceCache::getCached(const QString &name) const
{
if (mPriv->interfaces.contains(name)) {
debug() << "Returning cached interface for" << name;
@@ -67,7 +67,7 @@ AbstractInterface *OptionalInterfaceFactory::getCached(const QString &name) cons
}
}
-void OptionalInterfaceFactory::cache(AbstractInterface *interface) const
+void OptionalInterfaceCache::cache(AbstractInterface *interface) const
{
QString name = interface->interface();
Q_ASSERT(!mPriv->interfaces.contains(name));
diff --git a/TelepathyQt4/Client/optional-interface-factory.h b/TelepathyQt4/Client/optional-interface-factory.h
index ac3b2bf..c150fd7 100644
--- a/TelepathyQt4/Client/optional-interface-factory.h
+++ b/TelepathyQt4/Client/optional-interface-factory.h
@@ -46,6 +46,30 @@ namespace Telepathy
namespace Client
{
+class OptionalInterfaceCache
+{
+ public:
+ /**
+ * Class constructor.
+ */
+ OptionalInterfaceCache();
+
+ /**
+ * Class destructor.
+ *
+ * Frees all interface instances constructed by this factory.
+ */
+ ~OptionalInterfaceCache();
+
+ protected:
+ AbstractInterface *getCached(const QString &name) const;
+ void cache(AbstractInterface *interface) const;
+
+ private:
+ struct Private;
+ Private *mPriv;
+};
+
/**
* \class OptionalInterfaceFactory
* \ingroup clientsideproxies
@@ -56,21 +80,28 @@ namespace Client
*
* This class is included in the public API for the benefit of high-level
* proxies in extensions.
+ *
+ * \tparam DBusProxySubclass A subclass of DBusProxy
*/
-class OptionalInterfaceFactory
+template <typename DBusProxySubclass> class OptionalInterfaceFactory
+ : private OptionalInterfaceCache
{
public:
/**
* Class constructor.
*/
- OptionalInterfaceFactory();
+ inline OptionalInterfaceFactory() : OptionalInterfaceCache()
+ {
+ }
/**
* Class destructor.
*
* Frees all interface instances constructed by this factory.
*/
- ~OptionalInterfaceFactory();
+ inline ~OptionalInterfaceFactory()
+ {
+ }
/**
* Return a pointer to a valid instance of a interface class, associated
@@ -87,38 +118,27 @@ class OptionalInterfaceFactory
* it after destroying the factory will likely produce a crash. As the
* instance is shared, it should not be freed directly.
*
- * \tparam OptionalInterface Class of the interface instance to get.
- * \tparam MainInterface Class of the main interface.
- * \param mainInterface Main interface instance to use.
+ * \tparam Interface Class of the interface instance to get.
+ * \param proxy An instance of the appropriate DBusProxy subclass.
* \return A pointer to an optional interface instance.
*/
- template <typename OptionalInterface, typename MainInterface>
- inline OptionalInterface* interface(const MainInterface& mainInterface) const
+ template <typename Interface>
+ inline Interface *interface(const DBusProxySubclass *proxy) const
{
- // Check that the types given are both subclasses of AbstractInterface
- AbstractInterface* mainInterfaceMustBeASubclassOfAbstractInterface = static_cast<MainInterface*>(NULL);
- AbstractInterface* optionalInterfaceMustBeASubclassOfAbstractInterface = static_cast<OptionalInterface*>(NULL);
- Q_UNUSED(mainInterfaceMustBeASubclassOfAbstractInterface);
- Q_UNUSED(optionalInterfaceMustBeASubclassOfAbstractInterface);
+ AbstractInterface* interfaceMustBeASubclassOfAbstractInterface = static_cast<Interface *>(NULL);
+ Q_UNUSED(interfaceMustBeASubclassOfAbstractInterface);
// If there is a interface cached already, return it
- QString name(OptionalInterface::staticInterfaceName());
- AbstractInterface* cached = getCached(name);
+ QString name(Interface::staticInterfaceName());
+ AbstractInterface *cached = getCached(name);
if (cached)
- return static_cast<OptionalInterface*>(cached);
+ return static_cast<Interface *>(cached);
// Otherwise, cache and return a newly constructed proxy
- OptionalInterface* interface = new OptionalInterface(mainInterface, 0);
+ Interface *interface = new Interface(proxy, 0);
cache(interface);
return interface;
}
-
- private:
- AbstractInterface *getCached(const QString &name) const;
- void cache(AbstractInterface *interface) const;
-
- struct Private;
- Private* mPriv;
};
}
--
1.5.6.5
More information about the Telepathy-commits
mailing list