-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheventbase.cpp
executable file
·79 lines (61 loc) · 1.35 KB
/
eventbase.cpp
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
#include "eventbase.hpp"
#include <event2/thread.h>
#include <string.h>
#include "badbaseexception.hpp"
namespace dm {
EventBase::EventBase(const char* method)
{
// enable locking for libevent structure
if (evthread_use_pthreads())
{
throw std::exception();
}
#ifdef DEBUG
evthread_enable_lock_debuging();
event_enable_debug_mode();
#endif
if (NULL == method || !strcmp(method, ""))
{
// get the best base available on this system
base_ = event_base_new();
}
else
{
struct event_config *config;
config = event_config_new();
int i = 0;
const char** availMethods = event_get_supported_methods();
for (i = 0; availMethods[i] != NULL; i++)
{
if (strcmp(availMethods[i], method)) {
event_config_avoid_method(config, availMethods[i]);
}
}
base_ = event_base_new_with_config(config);
event_config_free(config);
}
if (!base_)
{
throw BadBaseException();
}
}
EventBase::~EventBase()
{
event_base_free(base_);
}
const char*
EventBase::getMethod()
{
return event_base_get_method(base_);
}
struct event_base*
EventBase::getBase()
{
return base_;
}
const char**
EventBase::getAvailableMethods()
{
return event_get_supported_methods();
}
} // namespace dm