diff options
-rw-r--r-- | api/pluginapi.h | 28 | ||||
-rw-r--r-- | core/core.cbp | 13 | ||||
-rw-r--r-- | core/main.cpp | 22 | ||||
-rw-r--r-- | core/modules.cpp | 63 | ||||
-rw-r--r-- | core/modules.h | 30 |
5 files changed, 142 insertions, 14 deletions
diff --git a/api/pluginapi.h b/api/pluginapi.h new file mode 100644 index 0000000..9b89b66 --- /dev/null +++ b/api/pluginapi.h @@ -0,0 +1,28 @@ +#ifndef PLUGINAPI_H_INCLUDED
+#define PLUGINAPI_H_INCLUDED
+ +/* +this is genereic plugin api header, only baisc c/c++ here +we need to support also non wxwidgets plugins +*/ + + +typedef void* (*SERVICE)(void*); + + +typedef struct +{ + void* (*CreateServiceFunction)(const char *,SERVICE); + void* (*CallService)(const char *,void*); + int (*ServiceExists)(const char *); +} PLUGINLINK; + +typedef struct +{ + wchar_t *name, *description, *author, *authoremail; + unsigned long version; + +}PLUGININFO;
+
+
+#endif // PLUGINAPI_H_INCLUDED
diff --git a/core/core.cbp b/core/core.cbp index f4eeb66..674714a 100644 --- a/core/core.cbp +++ b/core/core.cbp @@ -14,10 +14,10 @@ <Option projectLinkerOptionsRelation="2" /> <Compiler> <Add option="-g" /> - <Add option="`wx-config --version=2.8 --static=yes --unicode=yes --debug=yes --cflags`" /> + <Add option="`wx-config --unicode=yes --cflags`" /> </Compiler> <Linker> - <Add option="`wx-config --version=2.8 --static=yes --unicode=yes --debug=yes --libs`" /> + <Add option="`wx-config --unicode=yes --libs`" /> </Linker> </Target> <Target title="Release"> @@ -28,18 +28,23 @@ <Option projectLinkerOptionsRelation="2" /> <Compiler> <Add option="-O2" /> - <Add option="`wx-config --unicode=yes --debug=no --cflags`" /> + <Add option="`wx-config --cflags --cxxflags`" /> </Compiler> <Linker> <Add option="-s" /> - <Add option="`wx-config --unicode=yes --debug=no --libs`" /> + <Add option="`wx-config --libs`" /> </Linker> </Target> </Build> <Compiler> <Add option="-Wall" /> </Compiler> + <Unit filename="../api/pluginapi.h" /> + <Unit filename="commonheaders.h" /> <Unit filename="main.cpp" /> + <Unit filename="modules.cpp" /> + <Unit filename="modules.h" /> + <Unit filename="services.h" /> <Extensions> <envvars /> <code_completion /> diff --git a/core/main.cpp b/core/main.cpp index cd47654..b7d2204 100644 --- a/core/main.cpp +++ b/core/main.cpp @@ -1,16 +1,18 @@ -// For compilers that support precompilation, includes "wx.h". -#include <wx/wxprec.h> -#ifdef __BORLANDC__ -#pragma hdrstop -#endif +#include "commonheaders.h" + +class EvilCore: public wxApp +{ +public: + virtual bool OnInit(); +}; -#ifndef WX_PRECOMP -// Include your minimal set of headers here, or wx.h -#include <wx/wx.h> -#endif -int main() +bool EvilCore::OnInit() { + void load_modules(); + load_modules(); return 0; } +IMPLEMENT_APP(EvilCore) + diff --git a/core/modules.cpp b/core/modules.cpp new file mode 100644 index 0000000..50bb7ac --- /dev/null +++ b/core/modules.cpp @@ -0,0 +1,63 @@ +#include "commonheaders.h" + +std::list<plugin*> plugins; + +void load_modules() +{ + wxDir dir((wxChar*)"./plugins"); + if(!dir.IsOpened()) + { + wxLogDebug("Plugins directory does not exists\n"); + return; + } + wxString filename; +#ifdef _WIN32 + if(!dir.GetFirst(&filename, (wxChar*)".dll", 0)) + { + wxLogDebug("Plugins directory does not contain plugins\n"); + return; + } + +#else + if(!dir.GetFirst(&filename, (wxChar*)".so", 0)) + { + wxLogDebug("Plugins directory does not contain plugins\n"); + return; + } + +#endif + do + { + wxDynamicLibrary *plug = new wxDynamicLibrary(filename); + bool is_plugin = true; + plugin::exported_functions_s *funcs = new plugin::exported_functions_s; + if((funcs->Load = (load)plug->GetSymbol((wxChar*)"load")) == NULL) + is_plugin = false; + if((funcs->OnModulesLoaded = (on_modules_loaded)plug->GetSymbol((wxChar*)"on_modules_loaded")) == NULL) + is_plugin = false; + if((funcs->Unload = (unload)plug->GetSymbol((wxChar*)"unload")) == NULL) + is_plugin = false; + if((funcs->SetPluginInfo = (set_plugin_info)plug->GetSymbol((wxChar*)"set_plugin_info")) == NULL) + is_plugin = false; + if(!is_plugin) + { + delete plug; + delete funcs; + continue; + } + PLUGININFO *info = funcs->SetPluginInfo(); + plugins.push_back(new plugin(plug, info, funcs)); + } + while(dir.GetNext(&filename)); + +} + +plugin::plugin(wxDynamicLibrary *lib, PLUGININFO *info, exported_functions_s *funcs) +{ + if(lib) + plug = lib; + if(info) + plugininfo = info; + if(funcs) + exported_funcs = funcs; +} diff --git a/core/modules.h b/core/modules.h new file mode 100644 index 0000000..d4a7929 --- /dev/null +++ b/core/modules.h @@ -0,0 +1,30 @@ +#ifndef MODULE_H_INCLUDED
+#define MODULE_H_INCLUDED
+ +typedef PLUGININFO* (*set_plugin_info)(); +typedef int (*load)(PLUGINLINK *link); +typedef int (*on_modules_loaded)(); +typedef int (*unload)(); + +class plugin +{ +public: + struct exported_functions_s + { + load Load; + on_modules_loaded OnModulesLoaded; + unload Unload; + set_plugin_info SetPluginInfo; + }; + wxDynamicLibrary *get_plugin(); + void set_plugin(); + const exported_functions_s *get_exported_functions(); + plugin(wxDynamicLibrary *lib, PLUGININFO *info, exported_functions_s *funcs); + ~plugin(); +private: + wxDynamicLibrary *plug; + exported_functions_s *exported_funcs; + PLUGININFO *plugininfo; +};
+
+#endif // MODULE_H_INCLUDED
|