aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Chris Xiong <chirs241097@gmail.com> 2016-05-19 23:54:42 +0800
committerGravatar Chris Xiong <chirs241097@gmail.com> 2016-05-19 23:54:42 +0800
commit78b384662f484e946a6a17c96e6c309df0c039da (patch)
tree70093f05f4e9d02bbc8ddfdd2ddc8bef1cca1751
parent8ef9703ee2a4b22395935030606fcf69e3acad86 (diff)
downloadQMidiPlayer-78b384662f484e946a6a17c96e6c309df0c039da.tar.xz
Added a sample plugin as a template.
Implemented scanPlugin for Windows.
-rw-r--r--ChangeLog4
-rw-r--r--include/qmpcorepublic.hpp1
-rw-r--r--qmidiplayer-desktop/qmpplugin.cpp30
-rw-r--r--qmidiplayer-desktop/qmpplugin.hpp4
-rw-r--r--qmidiplayer.pro3
-rw-r--r--sample-plugin/sample-plugin.pro23
-rw-r--r--sample-plugin/sampleplugin.cpp11
-rw-r--r--sample-plugin/sampleplugin.hpp24
8 files changed, 94 insertions, 6 deletions
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 <cstdint>
+#include <vector>
#include <string>
//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<std::string> 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;i<cpluginpaths.size();++i)
+ {
+ HMODULE hso=LoadLibraryA(cpluginpaths[i].c_str());
+ if(!hso){fprintf(stderr,"Error while loading library: %d\n",GetLastError());continue;}
+ FARPROC hndi=GetProcAddress(hso,"qmpPluginGetInterface");
+ 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));
+ }
}
#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;i<plugins.size();++i)
{
- if(plugins[i].enabled)plugins[i].interface->deinit();
+ 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;i<plugins.size();++i)
- {plugins[i].interface->deinit();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 <cstdio>
+#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