diff --git a/samples/plugin/CMakeLists.txt b/samples/plugin/CMakeLists.txt index 63d30b352..20f045f54 100644 --- a/samples/plugin/CMakeLists.txt +++ b/samples/plugin/CMakeLists.txt @@ -1,6 +1,9 @@ FILE(GLOB SRC *.cpp) +SET(HEADERS server.h) -ADD_LIBRARY(sample_plugin MODULE ${SRC}) +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 index 0b183c767..8fcadd0f2 100644 --- a/samples/plugin/plugin.cpp +++ b/samples/plugin/plugin.cpp @@ -3,28 +3,9 @@ * 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 "blackmisc/plugins.h" +#include "plugin.h" #include -class CPlugin : public BlackMisc::IPlugin -{ -public: - CPlugin(BlackMisc::IPluginFactory &factory, BlackMisc::IContext &context); - - virtual ~CPlugin(); - - virtual bool isValid() const { return m_ctorOK; } - - virtual BlackMisc::IPluginFactory &getFactory() { return m_factory; } - -private: - bool m_ctorOK; - BlackMisc::IPluginFactory &m_factory; - BlackMisc::IContext &m_context; -}; - -MAKE_BLACK_PLUGIN(sample_plugin, CPlugin, "An example minimal plugin") - CPlugin::CPlugin(BlackMisc::IPluginFactory &factory, BlackMisc::IContext &context) : m_ctorOK(false), m_factory(factory), diff --git a/samples/plugin/plugin.h b/samples/plugin/plugin.h new file mode 100644 index 000000000..9383f864d --- /dev/null +++ b/samples/plugin/plugin.h @@ -0,0 +1,36 @@ +/* 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 { return m_ctorOK; } + + virtual BlackMisc::IPluginFactory &getFactory() { return m_factory; } + +private: + bool m_ctorOK; + BlackMisc::IPluginFactory &m_factory; + BlackMisc::IContext &m_context; +}; + +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 index c01de703c..e0e3f7291 100644 --- a/samples/plugin/sample_plugin.pro +++ b/samples/plugin/sample_plugin.pro @@ -9,6 +9,7 @@ DEPENDPATH += . ../../src INCLUDEPATH += . ../../src SOURCES += *.cpp +HEADERS += *.h LIBS += -L../../lib -lblackmisc diff --git a/src/blackmisc/plugins.h b/src/blackmisc/plugins.h index 4178933bb..6e4182cd4 100644 --- a/src/blackmisc/plugins.h +++ b/src/blackmisc/plugins.h @@ -87,51 +87,6 @@ namespace BlackMisc virtual const char *getDescription() const = 0; }; -} //namespace BlackMisc - -// must be placed outside namespace and before CPluginFactoryBase -Q_DECLARE_INTERFACE(BlackMisc::IPluginFactory, "net.vatsim.client.BlackMisc.IPluginFactory") - -namespace BlackMisc -{ - - /*! - Base class for CPluginFactory template used by MAKE_BLACK_PLUGIN. - */ - class CPluginFactoryBase : public QObject, public IPluginFactory - { - Q_OBJECT - Q_INTERFACES(BlackMisc::IPluginFactory) - }; - - /*! - Template used by MAKE_BLACK_PLUGIN. - */ - template - class CPluginFactory : public CPluginFactoryBase - { - public: - IPlugin *create(IContext &context) { return new P(*this, context); } - - void destroy(IPlugin *plugin) { if (plugin) delete plugin; } - }; - - /*! - Simplifies the process of building a plugin. - Put this macro somewhere in one of your plugin's .cpp files (but not in a namespace) - to export the necessary factory class for your plugin. - FQCLASS must have a constructor with the signature (IPluginFactory&, IContext&). - \param NAME A short name for your plugin with no spaces (a bareword, not a string). - \param FQCLASS The fully qualified name of the IPlugin subclass that the factory will construct. - */ - #define MAKE_BLACK_PLUGIN(NAME, FQCLASS, DESCR) \ - class CPluginFactory_##NAME : public BlackMisc::CPluginFactory \ - { \ - const char *getName() const { return #NAME ; } \ - const char *getDescription() const { return DESCR; } \ - }; \ - Q_EXPORT_PLUGIN2(NAME, CPluginFactory_##NAME ) - /*! Custom deleter for QScopedPointer. */ @@ -147,4 +102,22 @@ namespace BlackMisc } //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