forked from espressif/esp-idf-cxx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
esp_event_api.cpp
115 lines (97 loc) · 3.29 KB
/
esp_event_api.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#include "esp_event.h"
#include "esp_event_cxx.hpp"
#include "esp_event_api.hpp"
#ifdef __cpp_exceptions
namespace idf {
namespace event {
ESPEventAPIDefault::ESPEventAPIDefault()
{
esp_err_t res = esp_event_loop_create_default();
if (res != ESP_OK) {
throw idf::event::EventException(res);
}
}
ESPEventAPIDefault::~ESPEventAPIDefault()
{
esp_event_loop_delete_default();
}
esp_err_t ESPEventAPIDefault::handler_register(esp_event_base_t event_base,
int32_t event_id,
esp_event_handler_t event_handler,
void *event_handler_arg,
esp_event_handler_instance_t *instance)
{
return esp_event_handler_instance_register(event_base,
event_id,
event_handler,
event_handler_arg,
instance);
}
esp_err_t ESPEventAPIDefault::handler_unregister(esp_event_base_t event_base,
int32_t event_id,
esp_event_handler_instance_t instance)
{
return esp_event_handler_instance_unregister(event_base, event_id, instance);
}
esp_err_t ESPEventAPIDefault::post(esp_event_base_t event_base,
int32_t event_id,
void* event_data,
size_t event_data_size,
TickType_t ticks_to_wait)
{
return esp_event_post(event_base,
event_id,
event_data,
event_data_size,
ticks_to_wait);
}
ESPEventAPICustom::ESPEventAPICustom(const esp_event_loop_args_t &event_loop_args)
{
esp_err_t res = esp_event_loop_create(&event_loop_args, &event_loop);
if (res != ESP_OK) {
throw idf::event::EventException(res);
}
}
ESPEventAPICustom::~ESPEventAPICustom()
{
esp_event_loop_delete(event_loop);
}
esp_err_t ESPEventAPICustom::handler_register(esp_event_base_t event_base,
int32_t event_id,
esp_event_handler_t event_handler,
void *event_handler_arg,
esp_event_handler_instance_t *instance)
{
return esp_event_handler_instance_register_with(event_loop,
event_base,
event_id,
event_handler,
event_handler_arg,
instance);
}
esp_err_t ESPEventAPICustom::handler_unregister(esp_event_base_t event_base,
int32_t event_id,
esp_event_handler_instance_t instance)
{
return esp_event_handler_instance_unregister_with(event_loop, event_base, event_id, instance);
}
esp_err_t ESPEventAPICustom::post(esp_event_base_t event_base,
int32_t event_id,
void* event_data,
size_t event_data_size,
TickType_t ticks_to_wait)
{
return esp_event_post_to(event_loop,
event_base,
event_id,
event_data,
event_data_size,
ticks_to_wait);
}
esp_err_t ESPEventAPICustom::run(TickType_t ticks_to_run)
{
return esp_event_loop_run(event_loop, ticks_to_run);
}
} // event
} // idf
#endif // __cpp_exceptions