diff options
-rw-r--r-- | api/ec_pluginapi.h | 2 | ||||
-rw-r--r-- | core/services.cpp | 8 | ||||
-rw-r--r-- | core/services.h | 2 | ||||
-rw-r--r-- | plugins/example/main.cpp | 23 |
4 files changed, 32 insertions, 3 deletions
diff --git a/api/ec_pluginapi.h b/api/ec_pluginapi.h index 67b7c7d..6bcf5e7 100644 --- a/api/ec_pluginapi.h +++ b/api/ec_pluginapi.h @@ -34,7 +34,7 @@ typedef void* (*EVENT_HANDLER)(void*); typedef struct { - void (*CreateServiceFunction)(const char *,SERVICE); //register new service "service name" in core (will be avaible for all modules) + int (*CreateServiceFunction)(const char *,SERVICE); //register new service "service name" in core (will be avaible for all modules) void* (*CallService)(const char *,void*); //execute "service name" service with custom data (service dependent) int (*ServiceExists)(const char *); //check if "service name" service exists int (*RegisterEventHandler)(int, EVENT_HANDLER); //event type, handler function, return 0 on success diff --git a/core/services.cpp b/core/services.cpp index 903ee1a..27574b2 100644 --- a/core/services.cpp +++ b/core/services.cpp @@ -21,10 +21,16 @@ extern std::list<service*> services; extern boost::mutex service_list_mutex; int ServiceExists(const char *name); -void CreateServiceFunction(const char* name, SERVICE svc) +int CreateServiceFunction(const char* name, SERVICE svc) { if(!ServiceExists(name)) + { + logger.log(LM_DEBUG, "Succesfuly registered service %s.\n", name); services.push_back(new service(name, svc)); + return 0; + } + logger.log(LM_DEBUG, "Failed to register service %s.\n", name); + return 1; } void* CallService(const char *name,void* data) diff --git a/core/services.h b/core/services.h index 15da2f3..9d397b1 100644 --- a/core/services.h +++ b/core/services.h @@ -31,7 +31,7 @@ private: SERVICE pService; };
-void CreateServiceFunction(const char* name, SERVICE svc); +int CreateServiceFunction(const char* name, SERVICE svc); void* CallService(const char *,void*); int ServiceExists(const char *); diff --git a/plugins/example/main.cpp b/plugins/example/main.cpp index 00fde1e..b5af37f 100644 --- a/plugins/example/main.cpp +++ b/plugins/example/main.cpp @@ -25,6 +25,12 @@ EVENT_HANDLER our_handler(void* data) //this is event handler fuction return (void*(*)(void*))data; //just return data which we obtaned } +SERVICE our_service(void *data) //this is a service function +{ + wxMessageBox(_T("Our test service are working )"), _T("Info"), wxOK | wxICON_INFORMATION); + return 0; +} + bool wxPluginForEvilCore::OnInit() { wxMessageBox(_T("I am a plugin example") ,_T("Info"), wxOK | wxICON_INFORMATION); @@ -76,6 +82,23 @@ bool wxPluginForEvilCore::OnInit() free(str); //should be freed wxMessageBox(msg, _T("Info"), wxOK | wxICON_INFORMATION); } + //register our service in core + { + if(!pluginLink->CreateServiceFunction("ExamplePlugin/TestService", (void* (*)(void*))our_service)) + { + wxChar msg[64]; + wxSnprintf(msg, 63, _T("we have succesfuly registered service \"ExamplePlugin/TestService\"")); + wxMessageBox(msg, _T("Info"), wxOK | wxICON_INFORMATION); + } + else + { + wxChar msg[128]; + wxSnprintf(msg, 127, _T("we have failed to register service \"ExamplePlugin/TestService\"")); + wxMessageBox(msg, _T("Info"), wxOK | wxICON_INFORMATION); + } + } + if(pluginLink->ServiceExists("ExamplePlugin/TestService")) //check if service which we want to call exists + CallService("ExamplePlugin/TestService", 0); //call service return true; } |