blob: d8586963ca4d9df89ceb5618aebc342d0864f668 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
/* Copyright 2011 sss
* This file is part of evil_core.
*
* evil_core is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* evil_core is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with evil_core. If not, see <http://www.gnu.org/licenses/>.*/
#include "commonheaders.h"
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)
{
handler.connect(add_handler);
}
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)
{
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:
}
|