[Telepathy-commits] [telepathy-qt4/master] Add OptionalInterfaceFactory mixin class
Olli Salli
olli.salli at collabora.co.uk
Tue Sep 9 05:30:46 PDT 2008
---
TelepathyQt4/Client/OptionalInterfaceFactory | 1 +
TelepathyQt4/Makefile.am | 3 +
TelepathyQt4/cli-optional-interface-factory.cpp | 70 ++++++++++++++++++
TelepathyQt4/cli-optional-interface-factory.h | 90 +++++++++++++++++++++++
TelepathyQt4/header-compile-test.cpp | 1 +
5 files changed, 165 insertions(+), 0 deletions(-)
create mode 100644 TelepathyQt4/Client/OptionalInterfaceFactory
create mode 100644 TelepathyQt4/cli-optional-interface-factory.cpp
create mode 100644 TelepathyQt4/cli-optional-interface-factory.h
diff --git a/TelepathyQt4/Client/OptionalInterfaceFactory b/TelepathyQt4/Client/OptionalInterfaceFactory
new file mode 100644
index 0000000..c60b34c
--- /dev/null
+++ b/TelepathyQt4/Client/OptionalInterfaceFactory
@@ -0,0 +1 @@
+#include <TelepathyQt4/cli-optional-interface-factory.h>
diff --git a/TelepathyQt4/Makefile.am b/TelepathyQt4/Makefile.am
index 5d51ae8..0d581d2 100644
--- a/TelepathyQt4/Makefile.am
+++ b/TelepathyQt4/Makefile.am
@@ -35,6 +35,7 @@ libtelepathy_qt4_la_SOURCES = \
cli-dbus.cpp \
cli-media-session-handler.cpp \
cli-media-stream-handler.cpp \
+ cli-optional-interface-factory.cpp \
cli-properties.cpp \
debug.cpp \
debug-internal.hpp \
@@ -68,6 +69,7 @@ tpqt4include_HEADERS = \
cli-dbus.h \
cli-media-session-handler.h \
cli-media-stream-handler.h \
+ cli-optional-interface-factory.h \
cli-properties.h \
constants.h \
debug.h \
@@ -80,6 +82,7 @@ tpqt4clientinclude_HEADERS = \
Client/DBus \
Client/MediaSessionHandler \
Client/MediaStreamHandler \
+ Client/OptionalInterfaceFactory \
Client/Properties
nodist_geninclude_HEADERS = \
diff --git a/TelepathyQt4/cli-optional-interface-factory.cpp b/TelepathyQt4/cli-optional-interface-factory.cpp
new file mode 100644
index 0000000..2c92047
--- /dev/null
+++ b/TelepathyQt4/cli-optional-interface-factory.cpp
@@ -0,0 +1,70 @@
+/*
+ * This file is part of TelepathyQt4
+ *
+ * Copyright (C) 2008 Collabora Ltd. <http://www.collabora.co.uk/>
+ * Copyright (C) 2008 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 "cli-optional-interface-factory.h"
+
+#include <QMap>
+#include <QString>
+
+#include "debug-internal.hpp"
+
+namespace Telepathy
+{
+namespace Client
+{
+
+struct OptionalInterfaceFactory::Private
+{
+ QMap<QString, QDBusAbstractInterface*> interfaces;
+};
+
+OptionalInterfaceFactory::OptionalInterfaceFactory()
+ : mPriv(new Private())
+{
+}
+
+OptionalInterfaceFactory::~OptionalInterfaceFactory()
+{
+ delete mPriv;
+}
+
+QDBusAbstractInterface* OptionalInterfaceFactory::getCached(const QString& name) const
+{
+ if (mPriv->interfaces.contains(name)) {
+ debug() << "Returning cached interface for" << name;
+ return mPriv->interfaces.value(name);
+ } else {
+ debug() << "No interface found for" << name;
+ return 0;
+ }
+}
+
+void OptionalInterfaceFactory::cache(QDBusAbstractInterface* interface) const
+{
+ QString name = interface->interface();
+ Q_ASSERT(!mPriv->interfaces.contains(name));
+
+ debug() << "Caching interface" << name;
+ mPriv->interfaces[name] = interface;
+}
+
+}
+}
diff --git a/TelepathyQt4/cli-optional-interface-factory.h b/TelepathyQt4/cli-optional-interface-factory.h
new file mode 100644
index 0000000..eff7f22
--- /dev/null
+++ b/TelepathyQt4/cli-optional-interface-factory.h
@@ -0,0 +1,90 @@
+/*
+ * This file is part of TelepathyQt4
+ *
+ * Copyright (C) 2008 Collabora Ltd. <http://www.collabora.co.uk/>
+ * Copyright (C) 2008 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_Client_OptionalInterfaceFactory_HEADER_GUARD_
+#define _TelepathyQt4_Client_OptionalInterfaceFactory_HEADER_GUARD_
+
+/**
+ * \addtogroup clientsideproxies Client-side proxies
+ *
+ * Proxy objects representing remote service objects accessed via D-Bus.
+ *
+ * In addition to providing direct access to methods, signals and properties
+ * exported by the remote objects, some of these proxies offer features like
+ * automatic inspection of remote object capabilities, property tracking,
+ * backwards compatibility helpers for older services and other utilities.
+ */
+
+#include <QtGlobal>
+
+#include <QDBusAbstractInterface>
+
+namespace Telepathy
+{
+namespace Client
+{
+
+class OptionalInterfaceFactory
+{
+ public:
+ /**
+ * Class constructor.
+ */
+ OptionalInterfaceFactory();
+
+ /**
+ * Class destructor.
+ */
+ ~OptionalInterfaceFactory();
+
+ template <typename OptionalInterface, typename MainInterface>
+ inline OptionalInterface* interface(MainInterface* mainInterface) const
+ {
+ // Check that the types given are both subclasses of QDBusAbstractInterface
+ QDBusAbstractInterface* mainInterfaceMustBeASubclassOfQDBusAbstractInterface = static_cast<MainInterface*>(NULL);
+ QDBusAbstractInterface* optionalInterfaceMustBeASubclassOfQDBusAbstractInterface = static_cast<OptionalInterface*>(NULL);
+ Q_UNUSED(mainInterfaceMustBeASubclassOfQDBusAbstractInterface);
+ Q_UNUSED(optionalInterfaceMustBeASubclassOfQDBusAbstractInterface);
+
+ // If there is a interface cached already, return it
+ QString name(OptionalInterface::staticInterfaceName());
+ QDBusAbstractInterface* cached = getCached(name);
+ if (cached)
+ return static_cast<OptionalInterface*>(cached);
+
+ // Otherwise, cache and return a newly constructed proxy
+ OptionalInterface* interface = new OptionalInterface(*mainInterface, mainInterface);
+ cache(interface);
+ return interface;
+ }
+
+ private:
+ QDBusAbstractInterface* getCached(const QString& name) const;
+ void cache(QDBusAbstractInterface* interface) const;
+
+ struct Private;
+ Private* mPriv;
+};
+
+}
+}
+
+#endif
diff --git a/TelepathyQt4/header-compile-test.cpp b/TelepathyQt4/header-compile-test.cpp
index 136857b..081cd27 100644
--- a/TelepathyQt4/header-compile-test.cpp
+++ b/TelepathyQt4/header-compile-test.cpp
@@ -9,6 +9,7 @@
#include <TelepathyQt4/Client/DBus>
#include <TelepathyQt4/Client/MediaSessionHandler>
#include <TelepathyQt4/Client/MediaStreamHandler>
+#include <TelepathyQt4/Client/OptionalInterfaceFactory>
#include <TelepathyQt4/Client/Properties>
#include <TelepathyQt4/Constants>
#include <TelepathyQt4/Types>
--
1.5.6.3
More information about the Telepathy-commits
mailing list