diff options
author | Gluzskiy Alexandr <sss123next@list.ru> | 2011-03-16 20:57:59 +0200 |
---|---|---|
committer | Gluzskiy Alexandr <sss123next@list.ru> | 2011-03-16 20:57:59 +0200 |
commit | ee695f119bbc7b3f1557ab01b7953de2ca03e00b (patch) | |
tree | e18dd1fb3f0518bb8714df16e5de0402b3991c18 | |
parent | 7041ab5d41644bc3310b5c16b9c0aa3818a03d10 (diff) |
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
-rw-r--r-- | api/ec_pluginapi.h | 5 | ||||
-rw-r--r-- | core/commonheaders.h | 3 | ||||
-rw-r--r-- | core/core.project | 38 | ||||
-rw-r--r-- | core/events.cpp | 71 | ||||
-rw-r--r-- | core/events.h | 15 | ||||
-rw-r--r-- | core/main.cpp | 2 |
6 files changed, 106 insertions, 28 deletions
diff --git a/api/ec_pluginapi.h b/api/ec_pluginapi.h index 50bb776..94f7eaf 100644 --- a/api/ec_pluginapi.h +++ b/api/ec_pluginapi.h @@ -25,6 +25,7 @@ typedef void* (*SERVICE)(void*); +typedef void* (*EVENT_HANDLER)(void*); /* * CreateServiceFunction should be called with service name like: PluginName/ServiceName @@ -36,8 +37,8 @@ typedef struct void (*CreateServiceFunction)(const char *,SERVICE); void* (*CallService)(const char *,void*); bool (*ServiceExists)(const char *); - bool (*RegisterEventHandler)(void*); - bool (*RegisterEventType)(int); + bool (*RegisterEventHandler)(int, EVENT_HANDLER); + void* (*RegisterEventType)(int); } PLUGINLINK; typedef struct 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 <boost/thread.hpp> #include <boost/filesystem.hpp>
-#include <boost/shared_ptr.hpp>
+#include <boost/shared_ptr.hpp> +#include <boost/signal.hpp> //ACE
#include <ace/ACE.h> #include <ace/DLL.h> 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 @@ <File Name="events.h"/> </VirtualDirectory> <Settings Type="Executable"> + <GlobalSettings> + <Compiler Options="" C_Options=""> + <IncludePath Value="."/> + </Compiler> + <Linker Options=""> + <LibraryPath Value="."/> + <Library Value="boost_system-mt.so"/> + <Library Value="ACE.so"/> + <Library Value="boost_thread-mt.so"/> + <Library Value="boost_filesystem-mt.so"/> + </Linker> + <ResourceCompiler Options=""/> + </GlobalSettings> <Configuration Name="Debug" CompilerType="gnu gcc" DebuggerType="GNU gdb debugger" Type="Executable" BuildCmpWithGlobalSettings="append" BuildLnkWithGlobalSettings="append" BuildResWithGlobalSettings="append"> - <Compiler Options="-g" Required="yes" PreCompiledHeader=""> + <Compiler Options="-g" C_Options="-g" Required="yes" PreCompiledHeader=""> <IncludePath Value="."/> </Compiler> - <Linker Options="" Required="yes"/> + <Linker Options="" Required="yes"> + <Library Value="boost_signals-mt"/> + </Linker> <ResourceCompiler Options="" Required="no"/> - <General OutputFile="$(IntermediateDirectory)/$(ProjectName)" IntermediateDirectory="./Debug" Command="./$(ProjectName)" CommandArguments="" WorkingDirectory="$(IntermediateDirectory)" PauseExecWhenProcTerminates="yes"/> + <General OutputFile="$(IntermediateDirectory)/$(ProjectName)" IntermediateDirectory="./Debug" Command="./$(ProjectName)" CommandArguments="" UseSeparateDebugArgs="no" DebugArguments="" WorkingDirectory="$(IntermediateDirectory)" PauseExecWhenProcTerminates="yes"/> <Environment EnvVarSetName="<Use Defaults>" DbgSetName="<Use Defaults>"/> <Debugger IsRemote="no" RemoteHostName="" RemoteHostPort="" DebuggerPath=""> <PostConnectCommands/> @@ -57,12 +72,12 @@ </AdditionalRules> </Configuration> <Configuration Name="Release" CompilerType="gnu gcc" DebuggerType="GNU gdb debugger" Type="" BuildCmpWithGlobalSettings="append" BuildLnkWithGlobalSettings="append" BuildResWithGlobalSettings="append"> - <Compiler Options="" Required="yes" PreCompiledHeader=""> + <Compiler Options="" C_Options="" Required="yes" PreCompiledHeader=""> <IncludePath Value="."/> </Compiler> <Linker Options="-O2" Required="yes"/> <ResourceCompiler Options="" Required="no"/> - <General OutputFile="$(IntermediateDirectory)/$(ProjectName)" IntermediateDirectory="./Release" Command="./$(ProjectName)" CommandArguments="" WorkingDirectory="$(IntermediateDirectory)" PauseExecWhenProcTerminates="yes"/> + <General OutputFile="$(IntermediateDirectory)/$(ProjectName)" IntermediateDirectory="./Release" Command="./$(ProjectName)" CommandArguments="" UseSeparateDebugArgs="no" DebugArguments="" WorkingDirectory="$(IntermediateDirectory)" PauseExecWhenProcTerminates="yes"/> <Environment EnvVarSetName="<Use Defaults>" DbgSetName="<Use Defaults>"/> <Debugger IsRemote="no" RemoteHostName="" RemoteHostPort="" DebuggerPath=""> <PostConnectCommands/> @@ -85,18 +100,5 @@ <CustomPreBuild/> </AdditionalRules> </Configuration> - <GlobalSettings> - <Compiler Options=""> - <IncludePath Value="."/> - </Compiler> - <Linker Options=""> - <LibraryPath Value="."/> - <Library Value="boost_system-mt.so"/> - <Library Value="ACE.so"/> - <Library Value="boost_thread-mt.so"/> - <Library Value="boost_filesystem-mt.so"/> - </Linker> - <ResourceCompiler Options=""/> - </GlobalSettings> </Settings> </CodeLite_Project> 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 <http://www.gnu.org/licenses/>.*/ #include "commonheaders.h" -#include <boost/signal.hpp> -bool RegisterEventHandler(void* func) +extern std::list<evt_handler*> 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<evt_handler*>::iterator end = event_handlers.end(); + for(std::list<evt_handler*>::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<evt_handler*>::iterator end = event_handlers.end(); + for(std::list<evt_handler*>::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<evt_handler*>::iterator end = event_handlers.end(); + for(std::list<evt_handler*>::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<void*(void*)> 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<plugin*> plugins; boost::mutex plugin_list_mutex; std::list<service*> services; boost::mutex service_list_mutex; +std::list<evt_handler*> event_handlers; +boost::mutex event_handlers_mutex; ACE_Log_Msg logger; bool halt_requested = false; |