diff options
author | Gluzskiy Alexandr <sss123next@list.ru> | 2010-10-30 21:19:05 +0300 |
---|---|---|
committer | Gluzskiy Alexandr <sss123next@list.ru> | 2010-10-30 21:19:05 +0300 |
commit | 6add86d17a430db932bc0dc9af44da5dcb327fec (patch) | |
tree | a8e360a8736b91f9acaa2b94b91c4ea695c128c6 | |
parent | 7991233458276eb1d24617880bed8da52e866889 (diff) |
service usage example
-rw-r--r-- | core/basic-services.cpp | 4 | ||||
-rw-r--r-- | core/core.project | 1 | ||||
-rw-r--r-- | core/main.cpp | 2 | ||||
-rw-r--r-- | core/modules.cpp | 16 | ||||
-rw-r--r-- | evil_core.tags | bin | 54272 -> 6948864 bytes | |||
-rw-r--r-- | evil_core.workspace | 2 | ||||
-rw-r--r-- | plugins/example/main.cpp | 14 |
7 files changed, 29 insertions, 10 deletions
diff --git a/core/basic-services.cpp b/core/basic-services.cpp index 3774007..ffefa3a 100644 --- a/core/basic-services.cpp +++ b/core/basic-services.cpp @@ -1,8 +1,8 @@ #include "commonheaders.h" -SERVICE get_version(void*) +void *get_version(void*) { - return 0; + return (void*)ec_version; } diff --git a/core/core.project b/core/core.project index b9a5038..aa4654e 100644 --- a/core/core.project +++ b/core/core.project @@ -21,6 +21,7 @@ <File Name="globals.h"/> <File Name="modules.h"/> <File Name="services.h"/> + <File Name="../api/ec_pluginapi.h"/> </VirtualDirectory> <Settings Type="Executable"> <Configuration Name="Debug" CompilerType="gnu gcc" DebuggerType="GNU gdb debugger" Type="Executable" BuildCmpWithGlobalSettings="append" BuildLnkWithGlobalSettings="append" BuildResWithGlobalSettings="append"> diff --git a/core/main.cpp b/core/main.cpp index 36b6f92..2d0ca24 100644 --- a/core/main.cpp +++ b/core/main.cpp @@ -22,6 +22,8 @@ int ACE_MAIN(int argc, char *argv[]) #endif void load_modules(); void run_plugins(); + void register_core_services(); + register_core_services(); logger.log(LM_DEBUG, "Loading plugins...\n"); load_modules(); logger.log(LM_DEBUG, "Running plugins...\n"); diff --git a/core/modules.cpp b/core/modules.cpp index a8b6644..437c401 100644 --- a/core/modules.cpp +++ b/core/modules.cpp @@ -73,14 +73,20 @@ void run_plugins() std::list<plugin*>::iterator end = plugins.end(); for(std::list<plugin*>::iterator i = plugins.begin(); i != end; ++i) { - boost::thread *thr; - thr = new boost::thread(boost::bind((*i)->get_exported_functions()->Load, &pluglink)); + boost::thread *thr = new boost::thread(boost::bind((*i)->get_exported_functions()->Load, &pluglink)); if(!thr->timed_join(boost::posix_time::seconds(10))) - logger.log(LM_DEBUG, "Thread execution timeout, plugin %s basic initialisation failed.\n", toUTF8((*i)->get_plugininfo()->name).c_str()); + logger.log(LM_DEBUG, "Thread execution timeout, plugin \"%s\" basic initialisation failed.\n", toUTF8((*i)->get_plugininfo()->name).c_str()); + else + logger.log(LM_DEBUG, "plugin \"%s\" basic initialisation success.\n", toUTF8((*i)->get_plugininfo()->name).c_str()); delete thr; - thr = new boost::thread(boost::bind((*i)->get_exported_functions()->OnModulesLoaded)); + } + for(std::list<plugin*>::iterator i = plugins.begin(); i != end; ++i) + { + boost::thread *thr = new boost::thread(boost::bind((*i)->get_exported_functions()->OnModulesLoaded)); if(!thr->timed_join(boost::posix_time::seconds(15))) - logger.log(LM_DEBUG, "Thread execution timeout, plugin %s main initialisation failed.\n", toUTF8((*i)->get_plugininfo()->name).c_str()); + logger.log(LM_DEBUG, "Thread execution timeout, plugin \"%s\" main initialisation failed.\n", toUTF8((*i)->get_plugininfo()->name).c_str()); + else + logger.log(LM_DEBUG, "plugin \"%s\" main initialisation success.\n", toUTF8((*i)->get_plugininfo()->name).c_str()); delete thr; } } diff --git a/evil_core.tags b/evil_core.tags Binary files differindex 24cba7c..9a2fcfe 100644 --- a/evil_core.tags +++ b/evil_core.tags diff --git a/evil_core.workspace b/evil_core.workspace index 4e90fc5..9671776 100644 --- a/evil_core.workspace +++ b/evil_core.workspace @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="utf-8"?> <CodeLite_Workspace Name="evil_core" Database="./evil_core.tags"> <Project Name="core" Path="core/core.project" Active="Yes"/> - <Project Name="example" Path="plugins/example/example.project"/> + <Project Name="example" Path="plugins/example/example.project" Active="No"/> <BuildMatrix> <WorkspaceConfiguration Name="Debug" Selected="yes"> <Project Name="core" ConfigName="Debug"/> diff --git a/plugins/example/main.cpp b/plugins/example/main.cpp index 4ca212c..bd1f65b 100644 --- a/plugins/example/main.cpp +++ b/plugins/example/main.cpp @@ -5,8 +5,11 @@ #include <ec_pluginapi.h> //this is necessary, PLUGININFO structure, other related to load/unload plugin code + PLUGINLINK *pluginLink; +#define CallService(service, param) pluginLink->CallService(service,param) + class wxPluginForEvilCore: public wxApp //this is like on default wxwidgets application { virtual bool OnInit(); @@ -17,7 +20,14 @@ PLUGINLINK *pluginLink; bool wxPluginForEvilCore::OnInit() { wxMessageBox(_T("I am a plugin example") ,_T("Info"), wxOK | wxICON_INFORMATION); - return true; + int *core_version = (int*)CallService("EC/GetVersionInt", NULL); //using service implemented somewhere (in core, in plugins, in other place), NULL is data required for service + if(core_version) + { + wxChar msg[32]; + wxSnprintf(msg, 31, _T("Core version is %d."), core_version); + wxMessageBox(msg, _T("Info"), wxOK | wxICON_INFORMATION); + } + return true; } #ifdef _WIN32 @@ -69,7 +79,7 @@ extern "C" int on_modules_loaded() //load main code from here, all services from #ifdef _WIN32 wxEntry(GetModuleHandle(NULL),NULL,NULL,SW_SHOW); #else - int i = 0; + int i = 1; char **params = (char**)malloc(2); params[0] = (char*)malloc(2); strcpy(params[0], ""); |