#include "commonheaders.h" std::list plugins; extern PLUGINLINK pluglink; void load_modules() { wxStandardPaths *pth = new wxStandardPaths; wxString path = wxPathOnly(pth->GetExecutablePath()); delete pth; #ifdef _WIN32 path.append((wxChar*)_T("\\plugins")); #else path.append((wxChar*)_T("/plugins")); #endif wxDir dir(path); // wxMessageBox(path ,_("path"), wxOK | wxICON_INFORMATION); if(!dir.IsOpened()) { wxMessageBox(_T("Plugins directory does not exists") ,_T("Error"), wxOK | wxICON_ERROR); wxLogDebug(_T("Plugins directory does not exists\n")); return; } wxString filename; #ifdef _WIN32 if(!dir.GetFirst(&filename, _T("*.dll"), wxDIR_FILES | wxDIR_HIDDEN)) { wxMessageBox(_T("Plugins directory does not contain plugins") ,_T("Error"), wxOK | wxICON_ERROR); wxLogDebug((wxChar*)_T("Plugins directory does not contain plugins\n")); return; } #else if(!dir.GetFirst(&filename, _T("*.so"), wxDIR_FILES | wxDIR_HIDDEN)) { wxMessageBox(_T("Plugins directory does not contain plugins") ,_T("Error"), wxOK | wxICON_ERROR); wxLogDebug(_T("Plugins directory does not contain plugins\n")); return; } #endif do { wxString lib_path = path; #ifdef _WIN32 lib_path += _T("\\"); #else lib_path += _T("/"); #endif lib_path += filename; wxDynamicLibrary *plug = new wxDynamicLibrary(lib_path); if(!plug->IsLoaded()) { wxMessageBox(_T("Failed to load plugin") ,_T("Error"), wxOK | wxICON_ERROR); wxLogDebug(_T("Failed to load plugin\n")); } bool is_plugin = true; plugin::exported_functions_s *funcs = new plugin::exported_functions_s; if((funcs->Load = (load)plug->GetSymbol(_T("load"))) == NULL) is_plugin = false; if((funcs->OnModulesLoaded = (on_modules_loaded)plug->GetSymbol(_T("on_modules_loaded"))) == NULL) is_plugin = false; if((funcs->Unload = (unload)plug->GetSymbol(_T("unload"))) == NULL) is_plugin = false; if((funcs->SetPluginInfo = (set_plugin_info)plug->GetSymbol(_T("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)); lib_path.clear(); } while(dir.GetNext(&filename)); } void run_plugins() { if(!plugins.empty()) for(std::list::iterator i = plugins.begin(); i != plugins.end(); i++) { (*i)->get_exported_functions()->Load(&pluglink); (*i)->get_exported_functions()->OnModulesLoaded(); } } plugin::plugin(wxDynamicLibrary *lib, PLUGININFO *info, exported_functions_s *funcs) { if(lib) plug = lib; if(info) plugininfo = info; if(funcs) exported_funcs = funcs; } const plugin::exported_functions_s* plugin::get_exported_functions() { return exported_funcs; }