From 78b384662f484e946a6a17c96e6c309df0c039da Mon Sep 17 00:00:00 2001 From: Chris Xiong Date: Thu, 19 May 2016 23:54:42 +0800 Subject: Added a sample plugin as a template. Implemented scanPlugin for Windows. --- ChangeLog | 4 ++++ include/qmpcorepublic.hpp | 1 + qmidiplayer-desktop/qmpplugin.cpp | 30 ++++++++++++++++++++++++++---- qmidiplayer-desktop/qmpplugin.hpp | 4 ++-- qmidiplayer.pro | 3 +++ sample-plugin/sample-plugin.pro | 23 +++++++++++++++++++++++ sample-plugin/sampleplugin.cpp | 11 +++++++++++ sample-plugin/sampleplugin.hpp | 24 ++++++++++++++++++++++++ 8 files changed, 94 insertions(+), 6 deletions(-) create mode 100644 sample-plugin/sample-plugin.pro create mode 100644 sample-plugin/sampleplugin.cpp create mode 100644 sample-plugin/sampleplugin.hpp diff --git a/ChangeLog b/ChangeLog index c184f42..87bec58 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2016-05-19 0.8.1 alpha +Added a sample plugin as a template. +Implemented scanPlugin for Windows. + 2016-05-18 0.8.1 alpha Finally finish the particle system integration. Add std::wstring version APIs to avoid wrong encoding. diff --git a/include/qmpcorepublic.hpp b/include/qmpcorepublic.hpp index eb53bb3..98b8936 100644 --- a/include/qmpcorepublic.hpp +++ b/include/qmpcorepublic.hpp @@ -1,6 +1,7 @@ #ifndef QMPCOREPUBLIC_H #define QMPCOREPUBLIC_H #include +#include #include //This struct is used by event reader callbacks and event handler callbacks //as caller data struct diff --git a/qmidiplayer-desktop/qmpplugin.cpp b/qmidiplayer-desktop/qmpplugin.cpp index 22cb696..2117bcf 100644 --- a/qmidiplayer-desktop/qmpplugin.cpp +++ b/qmidiplayer-desktop/qmpplugin.cpp @@ -18,6 +18,25 @@ void qmpPluginManager::scanPlugins() HANDLE dir; std::vector cpluginpaths; //FindFirstFile, FindNextFile, FindClose + LPWIN32_FIND_DATA file; + dir=FindFirstFileA(L".\\plugins\\*.dll",file); + if(dir!=INVALID_HANDLE_VALUE) + { + cpluginpaths.push_back(std::string(file->cFileName)); + while(FindNextFile(dir,file)) + cpluginpaths.push_back(std::string(file->cFileName)); + } + FindClose(dir); + for(unsigned i=0;ipluginGetName()),std::string(intf->pluginGetVersion()),std::string(cpluginpaths[i]),intf)); + } } #else void qmpPluginManager::scanPlugins() @@ -46,7 +65,7 @@ void qmpPluginManager::scanPlugins() void* hso=dlopen(cpluginpaths[i].c_str(),RTLD_LAZY); if(!hso){fprintf(stderr,"%s\n",dlerror());continue;} void* hndi=dlsym(hso,"qmpPluginGetInterface"); - if(!hndi)continue; + if(!hndi){fprintf(stderr,"file %s doesn't seem to be a qmidiplayer plugin.\n",cpluginpaths[i].c_str());continue;} qmpPluginEntry e=(qmpPluginEntry)hndi; qmpPluginIntf* intf=e(pluginAPI); plugins.push_back(qmpPlugin(std::string(intf->pluginGetName()),std::string(intf->pluginGetVersion()),std::string(cpluginpaths[i]),intf)); @@ -63,7 +82,7 @@ qmpPluginManager::~qmpPluginManager() { for(unsigned i=0;ideinit(); + if(plugins[i].initialized)plugins[i].interface->deinit(); delete plugins[i].interface; } qmw=NULL;qsw=NULL;delete pluginAPI; @@ -78,13 +97,16 @@ void qmpPluginManager::initPlugins() { if(!plugins[i].enabled)continue; printf("Loaded plugin: %s\n",plugins[i].path.c_str()); - plugins[i].interface->init(); + plugins[i].interface->init();plugins[i].initialized=true; } } void qmpPluginManager::deinitPlugins() { for(unsigned i=0;ideinit();plugins[i].enabled=false;} + { + if(plugins[i].initialized)plugins[i].interface->deinit(); + plugins[i].enabled=plugins[i].initialized=false; + } } qmpPluginAPI::~qmpPluginAPI(){} diff --git a/qmidiplayer-desktop/qmpplugin.hpp b/qmidiplayer-desktop/qmpplugin.hpp index 836cee2..f689f71 100644 --- a/qmidiplayer-desktop/qmpplugin.hpp +++ b/qmidiplayer-desktop/qmpplugin.hpp @@ -8,9 +8,9 @@ struct qmpPlugin { std::string name,version,path; qmpPluginIntf* interface; - bool enabled; + bool enabled,initialized; qmpPlugin(std::string _n,std::string _v,std::string _p,qmpPluginIntf* _i) - {name=_n;version=_v;path=_p;interface=_i;enabled=false;} + {name=_n;version=_v;path=_p;interface=_i;enabled=initialized=false;} }; class qmpPluginManager { diff --git a/qmidiplayer.pro b/qmidiplayer.pro index 0c08e3c..3466c67 100644 --- a/qmidiplayer.pro +++ b/qmidiplayer.pro @@ -10,3 +10,6 @@ android { SUBDIRS = \ qmidiplayer-lite } + +SUBDIRS += \ + sample-plugin diff --git a/sample-plugin/sample-plugin.pro b/sample-plugin/sample-plugin.pro new file mode 100644 index 0000000..5ee7c48 --- /dev/null +++ b/sample-plugin/sample-plugin.pro @@ -0,0 +1,23 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2016-05-19T09:25:32 +# +#------------------------------------------------- + +QT -= core gui + +CONFIG += c++11 + +TARGET = sample-plugin +TEMPLATE = lib + +DEFINES += SAMPLEPLUGIN_LIBRARY + +SOURCES += sampleplugin.cpp + +HEADERS += sampleplugin.hpp + +unix { + target.path = /usr/lib + INSTALLS += target +} diff --git a/sample-plugin/sampleplugin.cpp b/sample-plugin/sampleplugin.cpp new file mode 100644 index 0000000..64e5584 --- /dev/null +++ b/sample-plugin/sampleplugin.cpp @@ -0,0 +1,11 @@ +#include +#include "sampleplugin.hpp" + +qmpSamplePlugin::qmpSamplePlugin(qmpPluginAPI* _api){api=_api;} +qmpSamplePlugin::~qmpSamplePlugin(){api=NULL;} +void qmpSamplePlugin::init() +{fputs("Hello world from plugin init!\n",stderr);} +void qmpSamplePlugin::deinit() +{fputs("Bye!\n",stderr);} +const char* qmpSamplePlugin::pluginGetName(){return "QMidiPlayer Sample Plugin";} +const char* qmpSamplePlugin::pluginGetVersion(){return "0.0.0";} diff --git a/sample-plugin/sampleplugin.hpp b/sample-plugin/sampleplugin.hpp new file mode 100644 index 0000000..75a5dcf --- /dev/null +++ b/sample-plugin/sampleplugin.hpp @@ -0,0 +1,24 @@ +#ifndef SAMPLEPLUGIN_H +#define SAMPLEPLUGIN_H + +#include "../include/qmpcorepublic.hpp" + +class qmpSamplePlugin:public qmpPluginIntf +{ + private: + qmpPluginAPI* api; + public: + qmpSamplePlugin(qmpPluginAPI* _api); + ~qmpSamplePlugin(); + void init(); + void deinit(); + const char* pluginGetName(); + const char* pluginGetVersion(); +}; + +extern "C"{ + qmpPluginIntf* qmpPluginGetInterface(qmpPluginAPI* api) + {return new qmpSamplePlugin(api);} +} + +#endif // SAMPLEPLUGIN_H -- cgit v1.2.3