00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef _TelepathyQt4_cli_optional_interface_factory_h_HEADER_GUARD_
00023 #define _TelepathyQt4_cli_optional_interface_factory_h_HEADER_GUARD_
00024
00025 #ifndef IN_TELEPATHY_QT4_HEADER
00026 #error IN_TELEPATHY_QT4_HEADER
00027 #endif
00028
00040 #include <QtGlobal>
00041 #include <QObject>
00042
00043 namespace Telepathy
00044 {
00045 namespace Client
00046 {
00047
00048 class AbstractInterface;
00049
00050 class OptionalInterfaceCache
00051 {
00052 Q_DISABLE_COPY(OptionalInterfaceCache)
00053
00054 public:
00058 explicit OptionalInterfaceCache(QObject *proxy);
00059
00065 ~OptionalInterfaceCache();
00066
00067 protected:
00068 AbstractInterface *getCached(const QString &name) const;
00069 void cache(AbstractInterface *interface) const;
00070 QObject *proxy() const;
00071
00072 private:
00073 struct Private;
00074 Private *mPriv;
00075 };
00076
00095 template <typename DBusProxySubclass> class OptionalInterfaceFactory
00096 : private OptionalInterfaceCache
00097 {
00098 public:
00105 inline OptionalInterfaceFactory(DBusProxySubclass *this_)
00106 : OptionalInterfaceCache(this_)
00107 {
00108 }
00109
00115 inline ~OptionalInterfaceFactory()
00116 {
00117 }
00118
00137 template <typename Interface>
00138 inline Interface *interface() const
00139 {
00140 AbstractInterface* interfaceMustBeASubclassOfAbstractInterface = static_cast<Interface *>(NULL);
00141 Q_UNUSED(interfaceMustBeASubclassOfAbstractInterface);
00142
00143
00144 QString name(Interface::staticInterfaceName());
00145 AbstractInterface *cached = getCached(name);
00146 if (cached)
00147 return static_cast<Interface *>(cached);
00148
00149
00150 Interface *interface = new Interface(
00151 static_cast<DBusProxySubclass *>(proxy()));
00152 cache(interface);
00153 return interface;
00154 }
00155 };
00156
00157 }
00158 }
00159
00160 #endif