Add a PluginManager class

This class is currently very small but the reason of existence
is to allow subsurface to be easily extendable via plugins.
The current type of plugin that I'm making is Social Network,
but another possibilities:

- Dive Simulation Algorithm
- Import/Export Filters
- Profile Overlays

Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Tomaz Canabrava 2015-10-09 19:18:45 -03:00 committed by Dirk Hohndel
parent 1d3bf5f407
commit 66d3e99ff2
3 changed files with 64 additions and 0 deletions

View file

@ -72,6 +72,7 @@ set(SUBSURFACE_CORE_LIB_SRCS
qtserialbluetooth.cpp
metrics.cpp
color.cpp
pluginmanager.cpp
${SERIAL_FTDI}
${PLATFORM_SRC}
${BT_CORE_SRC_FILES}

View file

@ -0,0 +1,44 @@
#include "pluginmanager.h"
#include <QApplication>
#include <QDir>
#include <QPluginLoader>
static QList<ISocialNetworkIntegration*> _socialNetworks;
PluginManager& PluginManager::instance() {
static PluginManager self;
return self;
}
void PluginManager::loadPlugins() {
QDir pluginsDir(qApp->applicationDirPath());
#if defined(Q_OS_WIN)
if (pluginsDir.dirName().toLower() == "debug" || pluginsDir.dirName().toLower() == "release")
pluginsDir.cdUp();
#elif defined(Q_OS_MAC)
if (pluginsDir.dirName() == "MacOS") {
pluginsDir.cdUp();
pluginsDir.cdUp();
pluginsDir.cdUp();
}
#endif
pluginsDir.cd("plugins");
foreach (const QString& fileName, pluginsDir.entryList(QDir::Files)) {
QPluginLoader loader(pluginsDir.absoluteFilePath(fileName));
QObject *plugin = loader.instance();
if(!plugin) {
continue;
}
if (ISocialNetworkIntegration *social = qobject_cast<ISocialNetworkIntegration*>(plugin)){
_socialNetworks.push_back(social);
}
}
}
QList<ISocialNetworkIntegration*> PluginManager::socialNetworkIntegrationPlugins() const {
return _socialNetworks;
}

View file

@ -0,0 +1,19 @@
#ifndef PLUGINMANAGER_H
#define PLUGINMANAGER_H
#include <QObject>
#include "isocialnetworkintegration.h"
class PluginManager {
public:
static PluginManager& instance();
void loadPlugins();
QList<ISocialNetworkIntegration*> socialNetworkIntegrationPlugins() const;
private:
PluginManager();
PluginManager(const PluginManager&) = delete;
PluginManager& operator=(const PluginManager&) = delete;
};
#endif