mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-22 14:55:36 +08:00
- Fixed: using Qt5 plugin system based on Q_PLUGIN_METADATA
This commit is contained in:
@@ -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")
|
||||
@@ -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 <iostream>
|
||||
|
||||
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),
|
||||
|
||||
36
samples/plugin/plugin.h
Normal file
36
samples/plugin/plugin.h
Normal file
@@ -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
|
||||
@@ -9,6 +9,7 @@ DEPENDPATH += . ../../src
|
||||
INCLUDEPATH += . ../../src
|
||||
|
||||
SOURCES += *.cpp
|
||||
HEADERS += *.h
|
||||
|
||||
LIBS += -L../../lib -lblackmisc
|
||||
|
||||
|
||||
@@ -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 P>
|
||||
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<FQCLASS> \
|
||||
{ \
|
||||
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
|
||||
Reference in New Issue
Block a user