From c6ceb73febc0f5afcd01341a16dca768d5c627cd Mon Sep 17 00:00:00 2001 From: Gluzskiy Alexandr Date: Thu, 17 Mar 2011 21:39:28 +0200 Subject: modified: api/ec_pluginapi.h modified: core/events.cpp modified: core/events.h modified: core/globals.h modified: core/modules.cpp modified: core/modules.h --- api/ec_pluginapi.h | 4 ++-- core/events.cpp | 25 ++++++++++++++++++------- core/events.h | 2 +- core/globals.h | 5 +++++ core/modules.cpp | 14 +++++++++++++- core/modules.h | 3 +++ 6 files changed, 42 insertions(+), 11 deletions(-) diff --git a/api/ec_pluginapi.h b/api/ec_pluginapi.h index 7f13634..e58b55a 100644 --- a/api/ec_pluginapi.h +++ b/api/ec_pluginapi.h @@ -38,7 +38,7 @@ typedef struct void* (*CallService)(const char *,void*); bool (*ServiceExists)(const char *); bool (*RegisterEventHandler)(int, EVENT_HANDLER); - int (*RegisterEventType)(int); + int (*RegisterEventType)(int, int); //event type, special id } PLUGINLINK; typedef struct @@ -46,7 +46,7 @@ typedef struct // int size; wchar_t *name, *description, *author, *authoremail; unsigned long version; - int pluginid; //will be set by core, neede to call some core services + int pluginid; //special id will be set by core, neede to call some core services }PLUGININFO; diff --git a/core/events.cpp b/core/events.cpp index b4a2396..4d206c8 100644 --- a/core/events.cpp +++ b/core/events.cpp @@ -16,9 +16,6 @@ #include "commonheaders.h" -extern std::list event_handlers; -extern boost::mutex event_handlers_mutex; - const int evt_handler::getType() { @@ -43,7 +40,6 @@ bool RegisterEventHandler(int type, EVENT_HANDLER func) { if(!event_handlers.empty()) { - event_handlers_mutex.lock(); std::list::iterator end = event_handlers.end(); for(std::list::iterator i = event_handlers.begin(); i != end; ++i) { @@ -55,19 +51,34 @@ bool RegisterEventHandler(int type, EVENT_HANDLER func) } return true; } -int RegisterEventType(int type) +int RegisterEventType(int type, int specialid) { + plugin *p = NULL; + if(!plugins.empty()) + { + std::list::iterator end = plugins.end(); + for(std::list::iterator i = plugins.begin(); i!= end; ++i) + { + if((*i)->get_plugin_id() == specialid) + { + p = *i; + break; + } + } + if(!p) + return 1; + } if(!event_handlers.empty()) { - event_handlers_mutex.lock(); std::list::iterator end = event_handlers.end(); for(std::list::iterator i = event_handlers.begin(); i != end; ++i) { if((*i)->getType() == type) - return -1; + return 1; } } event_handlers.push_back(new evt_handler(type)); + p->register_event(type); return 0; } diff --git a/core/events.h b/core/events.h index 1d968df..17b2497 100644 --- a/core/events.h +++ b/core/events.h @@ -17,7 +17,7 @@ #ifndef EVENTS_H_INCLUDED #define EVENTS_H_INCLUDED bool RegisterEventHandler(int, EVENT_HANDLER); -int RegisterEventType(int); +int RegisterEventType(int, int); class evt_handler{ public: diff --git a/core/globals.h b/core/globals.h index a82e512..2700403 100644 --- a/core/globals.h +++ b/core/globals.h @@ -21,4 +21,9 @@ extern ACE_Log_Msg logger; extern int current_plugin_id; + +extern std::list event_handlers; +extern boost::mutex event_handlers_mutex; + +extern std::list plugins; #endif \ No newline at end of file diff --git a/core/modules.cpp b/core/modules.cpp index 6eaf038..bcdcbe6 100644 --- a/core/modules.cpp +++ b/core/modules.cpp @@ -17,7 +17,7 @@ #include "commonheaders.h" -extern std::list plugins; + extern PLUGINLINK pluglink; @@ -150,3 +150,15 @@ const int plugin::get_plugin_id() { return pluginid; } + +const std::list plugin::get_event_list() +{ + return events; +} + + +int plugin::register_event(int type) +{ + events.push_back(type); + return 0; +} \ No newline at end of file diff --git a/core/modules.h b/core/modules.h index ca61aee..81d2c84 100644 --- a/core/modules.h +++ b/core/modules.h @@ -46,6 +46,8 @@ public: const PLUGININFO *get_plugininfo(); const exported_functions_s *get_exported_functions(); const int get_plugin_id(); + const std::list get_event_list(); + int register_event(int); plugin(ACE_DLL *lib, PLUGININFO *info, exported_functions_s *funcs); ~plugin(); private: @@ -53,6 +55,7 @@ private: exported_functions_s *exported_funcs; PLUGININFO *plugininfo; int pluginid; + std::list events; }; #endif // MODULE_H_INCLUDED -- cgit v1.2.3