From ee695f119bbc7b3f1557ab01b7953de2ca03e00b Mon Sep 17 00:00:00 2001 From: Gluzskiy Alexandr Date: Wed, 16 Mar 2011 20:57:59 +0200 Subject: modified: api/ec_pluginapi.h modified: core/commonheaders.h modified: core/core.project modified: core/events.cpp modified: core/events.h modified: core/main.cpp --- core/commonheaders.h | 3 ++- core/core.project | 38 +++++++++++++++------------- core/events.cpp | 71 ++++++++++++++++++++++++++++++++++++++++++++++++---- core/events.h | 15 +++++++++-- core/main.cpp | 2 ++ 5 files changed, 103 insertions(+), 26 deletions(-) (limited to 'core') diff --git a/core/commonheaders.h b/core/commonheaders.h index ff628d8..6305006 100644 --- a/core/commonheaders.h +++ b/core/commonheaders.h @@ -25,7 +25,8 @@ //boost #include #include -#include +#include +#include //ACE #include #include diff --git a/core/core.project b/core/core.project index d277579..7f169ba 100644 --- a/core/core.project +++ b/core/core.project @@ -27,13 +27,28 @@ + + + + + + + + + + + + + - + - + + + - + @@ -57,12 +72,12 @@ - + - + @@ -85,18 +100,5 @@ - - - - - - - - - - - - - diff --git a/core/events.cpp b/core/events.cpp index 58e6b24..d858696 100644 --- a/core/events.cpp +++ b/core/events.cpp @@ -15,13 +15,74 @@ * along with evil_core. If not, see .*/ #include "commonheaders.h" -#include -bool RegisterEventHandler(void* func) +extern std::list event_handlers; +extern boost::mutex event_handlers_mutex; + + +const int evt_handler::getType() +{ + return evt_type; +} + +evt_handler::evt_handler(int type) +{ + evt_type = type; +} + +void evt_handler::AddHandler(EVENT_HANDLER add_handler) { - return false; + handler.connect(add_handler); } -bool RegisterEventType(int type) +void* evt_handler::Execute(void* data) +{ + return handler(data); +} + +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) + { + if((*i)->getType() == type) + { + (*i)->AddHandler(func); + } + } + } + return true; +} +void* RegisterEventType(int type) +{ + 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 (void*)-1; + } + } + event_handlers.push_back(new evt_handler(type)); + return 0; +} + +void* ExecuteEvent(int type,void* data) { - return false; + 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 (*i)->Execute(data); + } + } + event_handlers.push_back(new evt_handler(type)); +// return (void*)&event_handlers.back()->Execute; TODO: } diff --git a/core/events.h b/core/events.h index ec2d714..909efa7 100644 --- a/core/events.h +++ b/core/events.h @@ -16,7 +16,18 @@ #ifndef EVENTS_H_INCLUDED #define EVENTS_H_INCLUDED -bool RegisterEventHandler(void*); -bool RegisterEventType(int); +bool RegisterEventHandler(int, EVENT_HANDLER); +void* RegisterEventType(int); + +class evt_handler{ +public: + void AddHandler(EVENT_HANDLER); + const int getType(); + evt_handler(int); + void* Execute(void*); +private: + int evt_type; + boost::signal handler; +}; #endif diff --git a/core/main.cpp b/core/main.cpp index 1fe689c..9f3e25c 100644 --- a/core/main.cpp +++ b/core/main.cpp @@ -21,6 +21,8 @@ std::list plugins; boost::mutex plugin_list_mutex; std::list services; boost::mutex service_list_mutex; +std::list event_handlers; +boost::mutex event_handlers_mutex; ACE_Log_Msg logger; bool halt_requested = false; -- cgit v1.2.3