From 0ceb3ad75e04f477e26e35603611e2c3b780b346 Mon Sep 17 00:00:00 2001 From: Roland Winklmeier Date: Sat, 26 Apr 2014 20:45:12 +0200 Subject: [PATCH] Remove former plugin management and samples refs #221 --- client.pro | 2 - samples/plugin/CMakeLists.txt | 9 -- samples/plugin/plugin.cpp | 21 ---- samples/plugin/plugin.h | 37 ------- samples/plugin/sample_plugin.pro | 25 ----- samples/pluginmgr/CMakeLists.txt | 6 -- samples/pluginmgr/main.cpp | 52 ---------- samples/pluginmgr/sample_pluginmgr.pro | 26 ----- src/blackcore/pluginmgr.cpp | 105 ------------------- src/blackcore/pluginmgr.h | 136 ------------------------- src/blackmisc/plugins.h | 124 ---------------------- 11 files changed, 543 deletions(-) delete mode 100644 samples/plugin/CMakeLists.txt delete mode 100644 samples/plugin/plugin.cpp delete mode 100644 samples/plugin/plugin.h delete mode 100644 samples/plugin/sample_plugin.pro delete mode 100644 samples/pluginmgr/CMakeLists.txt delete mode 100644 samples/pluginmgr/main.cpp delete mode 100644 samples/pluginmgr/sample_pluginmgr.pro delete mode 100644 src/blackcore/pluginmgr.cpp delete mode 100644 src/blackcore/pluginmgr.h delete mode 100644 src/blackmisc/plugins.h diff --git a/client.pro b/client.pro index 43087006d..ef7d67223 100644 --- a/client.pro +++ b/client.pro @@ -34,8 +34,6 @@ contains(BLACK_CONFIG, XPlane) { contains(BLACK_CONFIG, Samples) { SUBDIRS += samples/cli_client/sample_cli_client.pro - SUBDIRS += samples/plugin/sample_plugin.pro - SUBDIRS += samples/pluginmgr/sample_pluginmgr.pro SUBDIRS += samples/blackmiscvectorgeo/sample_vector_geo.pro SUBDIRS += samples/blackmiscquantities/sample_quantities_aviation.pro SUBDIRS += samples/blackmiscdbus/sample_blackmisc_dbus.pro diff --git a/samples/plugin/CMakeLists.txt b/samples/plugin/CMakeLists.txt deleted file mode 100644 index 20f045f54..000000000 --- a/samples/plugin/CMakeLists.txt +++ /dev/null @@ -1,9 +0,0 @@ -FILE(GLOB SRC *.cpp) -SET(HEADERS server.h) - -QT4_WRAP_CPP(HEADERS_MOC ${HEADERS}) - -ADD_LIBRARY(sample_plugin MODULE ${SRC} ${HEADERS_MOC}) - -TARGET_LINK_LIBRARIES(sample_plugin blackmisc ${QT_LIBRARIES}) -SET_TARGET_PROPERTIES(sample_plugin PROPERTIES PROJECT_LABEL "Samples - Plugin") \ No newline at end of file diff --git a/samples/plugin/plugin.cpp b/samples/plugin/plugin.cpp deleted file mode 100644 index 8fcadd0f2..000000000 --- a/samples/plugin/plugin.cpp +++ /dev/null @@ -1,21 +0,0 @@ -/* Copyright (C) 2013 VATSIM Community / authors - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#include "plugin.h" -#include - -CPlugin::CPlugin(BlackMisc::IPluginFactory &factory, BlackMisc::IContext &context) -: m_ctorOK(false), - m_factory(factory), - m_context(context) -{ - std::cout << "Sample plugin constructor" << std::endl; - m_ctorOK = true; -} - -CPlugin::~CPlugin() -{ - std::cout << "Sample plugin destructor" << std::endl; -} \ No newline at end of file diff --git a/samples/plugin/plugin.h b/samples/plugin/plugin.h deleted file mode 100644 index 104bbd3af..000000000 --- a/samples/plugin/plugin.h +++ /dev/null @@ -1,37 +0,0 @@ -/* Copyright (C) 2013 VATSIM Community / authors - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#ifndef SAMPLE_PLUGIN_H -#define SAMPLE_PLUGIN_H - -#include "blackmisc/plugins.h" - -class CPlugin : public BlackMisc::IPlugin -{ -public: - CPlugin(BlackMisc::IPluginFactory &factory, BlackMisc::IContext &context); - - virtual ~CPlugin(); - - virtual bool isValid() const override { return m_ctorOK; } - - virtual BlackMisc::IPluginFactory &getFactory() override { return m_factory; } - -private: - bool m_ctorOK; - BlackMisc::IPluginFactory &m_factory; - BlackMisc::IContext &m_context; -}; - -// This needs to be in the header so that Qt's "moc" processor can see it. -class CPluginFactory : public QObject, public BlackMisc::IPluginFactory -{ - Q_OBJECT - Q_INTERFACES(BlackMisc::IPluginFactory) - Q_PLUGIN_METADATA(IID BLACKMISC_IPLUGINFACTORY_IID) - BLACKMISC_IMPLEMENT_IPLUGINFACTORY(CPlugin, "sample_plugin", "An example minimal plugin") -}; - -#endif //SAMPLE_PLUGIN_H \ No newline at end of file diff --git a/samples/plugin/sample_plugin.pro b/samples/plugin/sample_plugin.pro deleted file mode 100644 index dfacf7715..000000000 --- a/samples/plugin/sample_plugin.pro +++ /dev/null @@ -1,25 +0,0 @@ -include (../../config.pri) -include (../../build.pri) - -QT += core -QT -= gui - -TARGET = sample_plugin -TEMPLATE = lib - -CONFIG += plugin -CONFIG += blackmisc blackcore - - -DEPENDPATH += . ../../src -INCLUDEPATH += . ../../src - -SOURCES += *.cpp -HEADERS += *.h - -win32:!win32-g++*: PRE_TARGETDEPS += ../../lib/blackmisc.lib -else: PRE_TARGETDEPS += ../../lib/libblackmisc.a - -DESTDIR = ../../bin - -include (../../libraries.pri) diff --git a/samples/pluginmgr/CMakeLists.txt b/samples/pluginmgr/CMakeLists.txt deleted file mode 100644 index 7c07f94e2..000000000 --- a/samples/pluginmgr/CMakeLists.txt +++ /dev/null @@ -1,6 +0,0 @@ -FILE(GLOB SRC *.cpp) - -ADD_EXECUTABLE(sample_pluginmgr ${SRC}) - -TARGET_LINK_LIBRARIES(sample_pluginmgr blackmisc ${QT_LIBRARIES}) -SET_TARGET_PROPERTIES(sample_pluginmgr PROPERTIES PROJECT_LABEL "Samples - Plugin Manager") \ No newline at end of file diff --git a/samples/pluginmgr/main.cpp b/samples/pluginmgr/main.cpp deleted file mode 100644 index 18433ee37..000000000 --- a/samples/pluginmgr/main.cpp +++ /dev/null @@ -1,52 +0,0 @@ -#include "blackcore/pluginmgr.h" -#include "blackmisc/plugins.h" -#include "blackmisc/context.h" -#include -#include -#include - -int main(int argc, char *argv[]) -{ - QCoreApplication a(argc, argv); - - BlackMisc::CApplicationContext ctx; - BlackMisc::IContext::setInstance(ctx); - - { - const QString pluginPath = "../../build/bin"; - - std::cout << "Loading plugins from " << pluginPath.toStdString() << std::endl; - - BlackCore::CPluginManager pluginmgr; - pluginmgr.loadAllPlugins(pluginPath); - size_t count = pluginmgr.getPluginCount(); - - std::cout << count << " plugins loaded" << std::endl << std::endl; - - for (size_t i = 0; i < count; ++i) - { - std::cout << "Plugin " << i << ": " << pluginmgr.getName(i).toStdString() - << ": " << pluginmgr.getDescription(i).toStdString() << std::endl; - } - std::cout << std::endl; - - std::vector plugins; - - for (size_t i = 0; i < count; ++i) - { - std::cout << "Constructing plugin " << i << std::endl; - - plugins.push_back(pluginmgr.constructPlugin(i)); - } - - size_t i = 0; - for (std::vector::iterator it = plugins.begin(); it != plugins.end(); ++it, ++i) - { - std::cout << "Destroying plugin " << i << std::endl; - - (*it)->getFactory().destroy(*it); - } - } - - //return a.exec(); -} diff --git a/samples/pluginmgr/sample_pluginmgr.pro b/samples/pluginmgr/sample_pluginmgr.pro deleted file mode 100644 index 756d55799..000000000 --- a/samples/pluginmgr/sample_pluginmgr.pro +++ /dev/null @@ -1,26 +0,0 @@ -include (../../config.pri) -include (../../build.pri) - -QT += core -QT -= gui - -TARGET = sample_pluginmgr -TEMPLATE = app - -CONFIG += console -CONFIG -= app_bundle -CONFIG += blackmisc blackcore - -DEPENDPATH += . ../../src -INCLUDEPATH += . ../../src - -SOURCES += *.cpp - -win32:!win32-g++*: PRE_TARGETDEPS += ../../lib/blackmisc.lib \ - ../../lib/blackcore.lib -else: PRE_TARGETDEPS += ../../lib/libblackmisc.a \ - ../../lib/libblackcore.a - -DESTDIR = ../../bin - -include (../../libraries.pri) diff --git a/src/blackcore/pluginmgr.cpp b/src/blackcore/pluginmgr.cpp deleted file mode 100644 index f8a00c9f0..000000000 --- a/src/blackcore/pluginmgr.cpp +++ /dev/null @@ -1,105 +0,0 @@ -/* Copyright (C) 2013 VATSIM Community / authors - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#include "blackcore/pluginmgr.h" -#include "blackmisc/plugins.h" -#include "blackmisc/context.h" -#include -#include -#include - -namespace BlackCore -{ - - CPluginManager::~CPluginManager() - { - for (QVector::iterator it = m_plugins.begin(); it != m_plugins.end(); ++it) - { - Q_ASSERT_X(it->loader, "Plugin manager", "Previously loaded plugin's loader ptr is null"); - - it->loader->unload(); - } - } - - void CPluginManager::loadAllPlugins(const QString &pluginsPath) - { - //TODO should we use a custom extension, so we don't attempt to load non-plugin .dll/.so files? - #ifdef Q_OS_WIN - static const QStringList pluginsFilter("*.dll"); - #else - static const QStringList pluginsFilter("*.so"); - #endif - - QDirIterator iter (pluginsPath, pluginsFilter, QDir::Files); - while (iter.hasNext()) - { - QString filename = iter.next(); - - QSharedPointer loader (new QPluginLoader (filename)); - try - { - if (! loader->load()) - { - throw std::runtime_error(QString("Failed loading plugin from %1").arg(filename).toStdString()); - } - - PluginEntry entry; - entry.loader = loader; - entry.factory = qobject_cast(loader->instance()); - - if (! entry.factory) - { - throw std::runtime_error(QString("Plugin loaded from %1 is not compatible").arg(filename).toStdString()); - } - - m_plugins.push_back(entry); - } - catch (...) - { - //TODO warning? - } - } - } - - const CPluginManager::PluginEntry &CPluginManager::getEntry(int index) const - { - Q_ASSERT_X(index < getPluginCount(), "Plugin manager", "Plugin index out of bounds"); - - const PluginEntry &entry = m_plugins[index]; - - Q_ASSERT_X(entry.factory, "Plugin manager", "Previously loaded plugin's factory ptr is null"); - Q_ASSERT_X(entry.loader, "Plugin manager", "Previously loaded plugin's loader ptr is null"); - - if (! entry.loader->isLoaded()) - { - //TODO throw plugin loader unexpectedly unloaded - } - - return entry; - } - - const QString CPluginManager::getName(int index) const - { - return getFactory(index)->getName(); - } - - const QString CPluginManager::getDescription(int index) const - { - return getFactory(index)->getDescription(); - } - - BlackMisc::IPlugin *CPluginManager::constructPlugin(int index) - { - BlackMisc::IPlugin *plugin = getFactory(index)->create(BlackMisc::IContext::getInstance()); - if (! plugin->isValid()) - { - delete plugin; - plugin = 0; - //TODO throw plugin construction failed - } - return plugin; - } - -} // namespace BlackCore \ No newline at end of file diff --git a/src/blackcore/pluginmgr.h b/src/blackcore/pluginmgr.h deleted file mode 100644 index b10c4433c..000000000 --- a/src/blackcore/pluginmgr.h +++ /dev/null @@ -1,136 +0,0 @@ -/* Copyright (C) 2013 VATSIM Community / authors - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -/*! - \file -*/ - -#ifndef BLACKCORE_PLUGINMGR_H -#define BLACKCORE_PLUGINMGR_H - -#include -#include -#include - -namespace BlackMisc -{ - class IPlugin; - class IPluginFactory; -} - -namespace BlackCore -{ - - /*! - Plugin manager. - Loads plugins and allows them to be queried and instantiated. - */ - class CPluginManager - { - public: - /*! - Destructor. - */ - virtual ~CPluginManager(); - - /*! - Attempt to load all plugins found at the given path. - \param pluginsPath - */ - void loadAllPlugins(const QString &pluginsPath); - - /*! - Return the total number of plugins loaded so far. - \return - */ - int getPluginCount() const - { - return m_plugins.size(); - } - - /*! - Return the name of a plugin. - \param index the plugin's index in the vector of plugins. - \return - */ - const QString getName(int index) const; - - /*! - Return the description of a plugin. - \param index the plugin's index in the vector of plugins. - \return - */ - const QString getDescription(int index) const; - - /*! - Construct a plugin. - \param index the plugin's index in the vector of plugins. - \return a pointer to the newly created plugin. - \warning You must release this pointer with IPluginFactory::destroy(). - */ - BlackMisc::IPlugin *constructPlugin(int index); - - /*! - Direct access to the factory. You don't usually need this. - \param index - \return - */ - BlackMisc::IPluginFactory *getFactory(int index) - { - return const_cast(static_cast(this)->getFactory(index)); - } - - /*! - Direct access to the factory. You don't usually need this. - \param index - \return - */ - const BlackMisc::IPluginFactory *getFactory(int index) const - { - return getEntry(index).factory; - } - - /*! - Direct access to the QPluginLoader. You don't usually need this. - \param index - \return - */ - QPluginLoader *getLoader(int index) - { - return const_cast(static_cast(this)->getLoader(index)); - } - - /*! - Direct access to the QPluginLoader. You don't usually need this. - \param index - \return - */ - const QPluginLoader *getLoader(int index) const - { - return getEntry(index).loader.data(); - } - - private: - class PluginEntry - { - public: - PluginEntry() : factory(0) {} - BlackMisc::IPluginFactory *factory; - QSharedPointer loader; - }; - - QVector m_plugins; - - PluginEntry &getEntry(int index) - { - return const_cast(static_cast(this)->getEntry(index)); - } - - const PluginEntry &getEntry(int index) const; - }; - -} // namespace BlackCore - -#endif //BLACKCORE_PLUGINMGR_H \ No newline at end of file diff --git a/src/blackmisc/plugins.h b/src/blackmisc/plugins.h deleted file mode 100644 index ad7c26598..000000000 --- a/src/blackmisc/plugins.h +++ /dev/null @@ -1,124 +0,0 @@ -/* Copyright (C) 2013 VATSIM Community / authors - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -/*! - \file -*/ - -#ifndef BLACKMISC_PLUGINS_H -#define BLACKMISC_PLUGINS_H - -#include -#include - -namespace BlackMisc -{ - - class IContext; - class IPluginFactory; - - /*! - The interface implemented by the main worker class in a plugin. - Constructed by a factory implementing IPluginFactory and - accessible to the application through the CPluginManager. - */ - class IPlugin - { - public: - /*! - Destructor. - */ - virtual ~IPlugin() {} - - /*! - Exceptions are not allowed to leave plugins, so we use this function - to test whether the plugin was constructed successfully. - \return False if an error occurred during plugin construction. - */ - virtual bool isValid() const = 0; - - /*! - Return the factory used to construct this object. - This is usually passed to the plugin's constructor by the factory itself. - \return - */ - virtual IPluginFactory &getFactory() = 0; - }; - - /*! - The root interface for classes exported from plugins. - This is a factory pattern for creating and destroying instances of IPlugin. - You usually don't need to worry about this, if you use the - MAKE_BLACK_PLUGIN macro to define your factory. - */ - class IPluginFactory - { - public: - /*! - Destructor. - */ - virtual ~IPluginFactory() {} - - /*! - Construct an instance of the plugin. - \param context The application context. - \return a pointer to the newly created plugin. - \warning You must release this pointer with IPluginFactory::destroy(). - */ - virtual IPlugin *create(IContext &context) = 0; - - /*! - Destroy a plugin which was created by this factory. - */ - virtual void destroy(IPlugin *plugin) = 0; - - /*! - Return the plugin's short name. - \return - */ - virtual const char *getName() const = 0; - - /*! - Return the plugin's description. - \return - */ - virtual const char *getDescription() const = 0; - }; - - /*! - Custom deleter for QScopedPointer. - */ - struct TPluginDeleter - { - //! Delete a plugin - static void cleanup(IPlugin *plugin) - { - if (plugin) { - plugin->getFactory().destroy(plugin); - } - } - }; - -} //namespace BlackMisc - -//! Qt interface ID for IPluginFactory. -#define BLACKMISC_IPLUGINFACTORY_IID "net.vatsim.client.BlackMisc.IPluginFactory" - -Q_DECLARE_INTERFACE(BlackMisc::IPluginFactory, BLACKMISC_IPLUGINFACTORY_IID) - -/*! - Macro to put inside an IPluginFactory subclass to help with implementation. - \param CLASS The plugin class which this factory constructs. - \param NAME A string literal, the plugin's short name. - \param DESCRIPTION A string literal, a brief description of the plugin. -*/ -#define BLACKMISC_IMPLEMENT_IPLUGINFACTORY(CLASS, NAME, DESCRIPTION) \ - public: \ - BlackMisc::IPlugin *create(BlackMisc::IContext &context) { return new CLASS(*this, context); } \ - void destroy(BlackMisc::IPlugin *plugin) { if (plugin) delete plugin; } \ - const char *getName() const { return NAME; } \ - const char *getDescription() const { return DESCRIPTION; } - -#endif //BLACKMISC_PLUGINS_H \ No newline at end of file