-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy patheventbase.cpp
70 lines (54 loc) · 1.17 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
#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
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);
if (!base_)
{
throw BadBaseException();
}
event_base_get_method(base_);
event_config_free(config);
}
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