forked from zeek/zeek
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEventRegistry.cc
99 lines (79 loc) · 1.85 KB
/
EventRegistry.cc
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
89
90
91
92
93
94
95
96
97
98
#include "EventRegistry.h"
#include "EventHandler.h"
#include "RE.h"
#include "Reporter.h"
void EventRegistry::Register(EventHandlerPtr handler)
{
handlers[string(handler->Name())] = handler.Ptr();
}
EventHandler* EventRegistry::Lookup(const string& name)
{
auto it = handlers.find(name);
if ( it != handlers.end() )
return it->second;
return nullptr;
}
EventRegistry::string_list EventRegistry::Match(RE_Matcher* pattern)
{
string_list names;
for ( const auto& entry : handlers )
{
EventHandler* v = entry.second;
if ( v->LocalHandler() && pattern->MatchExactly(v->Name()) )
names.push_back(entry.first);
}
return names;
}
EventRegistry::string_list EventRegistry::UnusedHandlers()
{
string_list names;
for ( const auto& entry : handlers )
{
EventHandler* v = entry.second;
if ( v->LocalHandler() && ! v->Used() )
names.push_back(entry.first);
}
return names;
}
EventRegistry::string_list EventRegistry::UsedHandlers()
{
string_list names;
for ( const auto& entry : handlers )
{
EventHandler* v = entry.second;
if ( v->LocalHandler() && v->Used() )
names.push_back(entry.first);
}
return names;
}
EventRegistry::string_list EventRegistry::AllHandlers()
{
string_list names;
for ( const auto& entry : handlers )
{
names.push_back(entry.first);
}
return names;
}
void EventRegistry::PrintDebug()
{
for ( const auto& entry : handlers )
{
EventHandler* v = entry.second;
fprintf(stderr, "Registered event %s (%s handler / %s)\n", v->Name(),
v->LocalHandler()? "local" : "no",
*v ? "active" : "not active"
);
}
}
void EventRegistry::SetErrorHandler(const string& name)
{
EventHandler* eh = Lookup(name);
if ( eh )
{
eh->SetErrorHandler();
return;
}
reporter->InternalWarning("unknown event handler '%s' in SetErrorHandler()",
name.c_str());
}