diff options
-rw-r--r-- | src/libraries/qmfmessageserver/qmailmessageserverplugin.cpp | 170 | ||||
-rw-r--r-- | src/libraries/qmfmessageserver/qmailmessageserverplugin.h | 68 | ||||
-rw-r--r-- | src/libraries/qmfmessageserver/qmfmessageserver.pro | 9 | ||||
-rw-r--r-- | src/tools/messageserver/messageserver.cpp | 15 | ||||
-rw-r--r-- | src/tools/messageserver/messageserver.pro | 1 |
5 files changed, 261 insertions, 2 deletions
diff --git a/src/libraries/qmfmessageserver/qmailmessageserverplugin.cpp b/src/libraries/qmfmessageserver/qmailmessageserverplugin.cpp new file mode 100644 index 00000000..0fa857b7 --- /dev/null +++ b/src/libraries/qmfmessageserver/qmailmessageserverplugin.cpp @@ -0,0 +1,170 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Jolla Ltd. +** Contact: Valério Valério <valerio.valerio@jollamobile.com> +** +** This file is part of the Qt Messaging Framework. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qmailmessageserverplugin.h" +#include <qmailpluginmanager.h> +#include <QDebug> + +#define PLUGIN_KEY "messageserverplugins" + +typedef QMap<QString, QMailMessageServerPlugin*> PluginMap; + +/*! \internal + Load all the plugins into a map for quicker reference +*/ +static PluginMap initMap(QMailPluginManager& manager) +{ + PluginMap map; + + foreach (const QString &item, manager.list()) { + QObject *instance = manager.instance(item); + if (QMailMessageServerPlugin* iface = qobject_cast<QMailMessageServerPlugin*>(instance)) + map.insert(iface->key(), iface); + } + return map; +} +/*! \internal + Return a reference to a map containing all loaded plugin objects +*/ +static PluginMap& pluginMap() +{ + static QMailPluginManager pluginManager(PLUGIN_KEY); + static PluginMap map(initMap(pluginManager)); + + return map; +} + +/*! \internal + Return the plugin object matching the specified ID +*/ +static QMailMessageServerPlugin* mapping(const QString& key) +{ + PluginMap::ConstIterator it; + if ((it = pluginMap().find(key)) != pluginMap().end()) + return it.value(); + + qWarning() << "Failed attempt to map plugin: " << key; + return 0; +} + +/*! + \class QMailMessageServerPlugin + \ingroup libmessageserver + + \brief The QMailMessageServerPlugin class defines the interface to plugins that provide additional services + for the messageserver daemon. + + The QMailMessageServerPlugin class defines the interface to messageserver plugins. Plugins will + be loaded and executed in the messageserver main loop, these plugins should only be used for services + that need to be informed about operations initiated by all clients connected to messageserver. + + \sa QMailMessageServerPluginFactory +*/ + +/*! + \fn QString QMailMessageServerPlugin::key() const + + Returns a string identifying the plugin. +*/ + +/*! + \fn QString QMailMessageServerPlugin::exec() + + The starting point for the plugin. + Plugin implementations should use this function as execution + entry point for the service(s) provided by the plugin. +*/ + +/*! + \fn QMailMessageServerPlugin* QMailMessageServerPlugin::createService() + + Creates an instance of the service provided by the plugin. +*/ + + +QMailMessageServerPlugin::QMailMessageServerPlugin(QObject *parent) + : QObject(parent) +{ +} + +QMailMessageServerPlugin::~QMailMessageServerPlugin() +{ +} + +/*! + \class QMailMessageServerPluginFactory + \ingroup libmessageserver + + \brief The QMailMessageServerPluginFactory class creates objects implementing the QMailMessageServerPlugin interface. + + The QMailMessageServerPluginFactory class creates objects that provide plugins services to the + messageserver daemon. The factory allows implementations to be loaded from plugin libraries, + and to be retrieved and instantiated by name. + + To create a new service that can be created via the QMailMessageServerPluginFactory, derive from the + QMailMessageServerPlugin base class. + + \sa QMailMessageServerPlugin +*/ + +/*! + Returns a list of the keys of the installed plugins. + */ +QStringList QMailMessageServerPluginFactory::keys() +{ + QStringList in; + + foreach (PluginMap::mapped_type plugin, pluginMap()) + in << plugin->key(); + + return in; +} + +/*! + Creates a plugin object of the class identified by \a key. +*/ +QMailMessageServerPlugin* QMailMessageServerPluginFactory::createService(const QString& key) +{ + if (QMailMessageServerPlugin* plugin = mapping(key)) + return plugin->createService(); + + return 0; +} diff --git a/src/libraries/qmfmessageserver/qmailmessageserverplugin.h b/src/libraries/qmfmessageserver/qmailmessageserverplugin.h new file mode 100644 index 00000000..1f1413ef --- /dev/null +++ b/src/libraries/qmfmessageserver/qmailmessageserverplugin.h @@ -0,0 +1,68 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Jolla Ltd. +** Contact: Valério Valério <valerio.valerio@jollamobile.com> +** +** This file is part of the Qt Messaging Framework. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QMAILMESSAGESERVERPLUGIN_H +#define QMAILMESSAGESERVERPLUGIN_H + +#include "qmailglobal.h" +#include <QObject> + +class MESSAGESERVER_EXPORT QMailMessageServerPlugin : public QObject +{ + Q_OBJECT + +public: + QMailMessageServerPlugin(QObject* parent = 0); + ~QMailMessageServerPlugin(); + + virtual QString key() const = 0; + virtual void exec() = 0; + virtual QMailMessageServerPlugin *createService() = 0; +}; + +class MESSAGESERVER_EXPORT QMailMessageServerPluginFactory +{ +public: + static QStringList keys(); + static QMailMessageServerPlugin *createService(const QString& key); +}; + +#endif // QMAILMESSAGESERVERPLUGIN_H diff --git a/src/libraries/qmfmessageserver/qmfmessageserver.pro b/src/libraries/qmfmessageserver/qmfmessageserver.pro index ccfcb508..768b5e6d 100644 --- a/src/libraries/qmfmessageserver/qmfmessageserver.pro +++ b/src/libraries/qmfmessageserver/qmfmessageserver.pro @@ -37,8 +37,6 @@ PUBLIC_HEADERS += qmailauthenticator.h \ qmailtransport.h \ qmailheartbeattimer.h -HEADERS += $$PUBLIC_HEADERS $$PRIVATE_HEADERS - SOURCES += qmailauthenticator.cpp \ qmailmessagebuffer.cpp \ qmailmessageclassifier.cpp \ @@ -48,6 +46,13 @@ SOURCES += qmailauthenticator.cpp \ qmailtransport.cpp \ qmailheartbeattimer_qtimer.cpp # NB: There are multiple implementations +contains(DEFINES,MESSAGESERVER_PLUGINS) { + PUBLIC_HEADERS += qmailmessageserverplugin.h + SOURCES += qmailmessageserverplugin.cpp +} + +HEADERS += $$PUBLIC_HEADERS $$PRIVATE_HEADERS + equals(QT_MAJOR_VERSION, 4): header_files.path=$$QMF_INSTALL_ROOT/include/qmfmessageserver equals(QT_MAJOR_VERSION, 5): header_files.path=$$QMF_INSTALL_ROOT/include/qmfmessageserver5 header_files.files=$$PUBLIC_HEADERS diff --git a/src/tools/messageserver/messageserver.cpp b/src/tools/messageserver/messageserver.cpp index da2b47dd..43a61d66 100644 --- a/src/tools/messageserver/messageserver.cpp +++ b/src/tools/messageserver/messageserver.cpp @@ -51,6 +51,7 @@ #include <qmailipc.h> #include <newcountnotifier.h> #include <qcopserver.h> +#include <qmailmessageserverplugin.h> extern "C" { #ifndef Q_OS_WIN @@ -59,6 +60,10 @@ extern "C" { #include <signal.h> } +#ifdef MESSAGESERVER_PLUGINS +#include "messageserverplugins.h" +#endif + #if defined(Q_OS_UNIX) int MessageServer::sighupFd[2]; #endif @@ -252,6 +257,16 @@ MessageServer::MessageServer(QObject *parent) emit client->actionsListed(QMailActionDataList()); } + +#ifdef MESSAGESERVER_PLUGINS + qMailLog(Messaging) << "Initiating messageserver plugins."; + QStringList availablePlugins = QMailMessageServerPluginFactory::keys(); + + for (int i = 0; i < availablePlugins.size(); i++) { + QMailMessageServerPlugin *plugin = QMailMessageServerPluginFactory::createService(availablePlugins.at(i)); + plugin->exec(); + } +#endif } MessageServer::~MessageServer() diff --git a/src/tools/messageserver/messageserver.pro b/src/tools/messageserver/messageserver.pro index fcfe535a..e4202bb4 100644 --- a/src/tools/messageserver/messageserver.pro +++ b/src/tools/messageserver/messageserver.pro @@ -46,6 +46,7 @@ SOURCES += mailmessageclient.cpp \ prepareaccounts.cpp \ newcountnotifier.cpp \ servicehandler.cpp + !SERVER_AS_DLL: { SOURCES += main.cpp } |