EM-ODP 4.4.0
Event Machine on ODP
Loading...
Searching...
No Matches
event_machine_hooks.c
Go to the documentation of this file.
1/*
2 * Copyright (c) 2019-2023, Nokia Solutions and Networks
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * * Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * * Neither the name of the copyright holder nor the names of its
15 * contributors may be used to endorse or promote products derived
16 * from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31/**
32 * @file
33 *
34 * Event Machine API callback hooks.
35 *
36 */
37
38#ifndef _GNU_SOURCE
39#define _GNU_SOURCE
40#endif
41
42#ifdef HAVE_CONFIG_H
43#include "config.h"
44#endif
45
46#include <stdint.h>
47
48#include <event_machine.h>
49
50#include "em_error.h"
51#include "em_hooks.h"
52#include "em_hook_types.h"
53#include "em_mem.h"
54
57{
58 hook_fn_t hook_fn;
59 em_status_t stat;
60
62 EM_ESCOPE_HOOKS_REGISTER_ALLOC,
63 "EM API callback hooks disabled");
64
65 hook_fn.alloc = func;
66 stat = hook_register(ALLOC_HOOK, hook_fn);
67 RETURN_ERROR_IF(stat != EM_OK, stat, EM_ESCOPE_HOOKS_REGISTER_ALLOC,
68 "Alloc hook register failed");
69
70 return EM_OK;
71}
72
75{
76 hook_fn_t hook_fn;
77 em_status_t stat;
78
80 EM_ESCOPE_HOOKS_UNREGISTER_ALLOC,
81 "EM API callback hooks disabled");
82
83 hook_fn.alloc = func;
84 stat = hook_unregister(ALLOC_HOOK, hook_fn);
85 RETURN_ERROR_IF(stat != EM_OK, stat, EM_ESCOPE_HOOKS_UNREGISTER_ALLOC,
86 "Alloc hook unregister failed");
87
88 return EM_OK;
89}
90
93{
94 hook_fn_t hook_fn;
95 em_status_t stat;
96
98 EM_ESCOPE_HOOKS_REGISTER_FREE,
99 "EM API callback hooks disabled");
100
101 hook_fn.free = func;
102 stat = hook_register(FREE_HOOK, hook_fn);
103 RETURN_ERROR_IF(stat != EM_OK, stat, EM_ESCOPE_HOOKS_REGISTER_FREE,
104 "Free hook register failed");
105
106 return EM_OK;
107}
108
111{
112 hook_fn_t hook_fn;
113 em_status_t stat;
114
116 EM_ESCOPE_HOOKS_UNREGISTER_FREE,
117 "EM API callback hooks disabled");
118
119 hook_fn.free = func;
120 stat = hook_unregister(FREE_HOOK, hook_fn);
121 RETURN_ERROR_IF(stat != EM_OK, stat, EM_ESCOPE_HOOKS_UNREGISTER_FREE,
122 "Free hook unregister failed");
123
124 return EM_OK;
125}
126
129{
130 hook_fn_t hook_fn;
131 em_status_t stat;
132
134 EM_ESCOPE_HOOKS_REGISTER_SEND,
135 "EM API callback hooks disabled");
136
137 hook_fn.send = func;
138 stat = hook_register(SEND_HOOK, hook_fn);
139 RETURN_ERROR_IF(stat != EM_OK, stat, EM_ESCOPE_HOOKS_REGISTER_SEND,
140 "Send hook register failed");
141
142 return EM_OK;
143}
144
147{
148 hook_fn_t hook_fn;
149 em_status_t stat;
150
152 EM_ESCOPE_HOOKS_UNREGISTER_SEND,
153 "EM API callback hooks disabled");
154
155 hook_fn.send = func;
156 stat = hook_unregister(SEND_HOOK, hook_fn);
157 RETURN_ERROR_IF(stat != EM_OK, stat, EM_ESCOPE_HOOKS_UNREGISTER_SEND,
158 "Send hook unregister failed");
159
160 return EM_OK;
161}
162
165{
166 hook_fn_t hook_fn;
167 em_status_t stat;
168
170 EM_ESCOPE_HOOKS_REGISTER_TO_IDLE,
171 "EM IDLE callback hooks disabled");
172
173 hook_fn.to_idle = func;
174 stat = hook_register(TO_IDLE_HOOK, hook_fn);
175 RETURN_ERROR_IF(stat != EM_OK, stat, EM_ESCOPE_HOOKS_REGISTER_TO_IDLE,
176 "To_idle hook register failed");
177
178 return EM_OK;
179}
180
183{
184 hook_fn_t hook_fn;
185 em_status_t stat;
186
188 EM_ESCOPE_HOOKS_UNREGISTER_TO_IDLE,
189 "EM IDLE callback hooks disabled");
190
191 hook_fn.to_idle = func;
192 stat = hook_unregister(TO_IDLE_HOOK, hook_fn);
193 RETURN_ERROR_IF(stat != EM_OK, stat, EM_ESCOPE_HOOKS_UNREGISTER_TO_IDLE,
194 "To_idle hook unregister failed");
195
196 return EM_OK;
197}
198
201{
202 hook_fn_t hook_fn;
203 em_status_t stat;
204
206 EM_ESCOPE_HOOKS_REGISTER_TO_ACTIVE,
207 "EM IDLE callback hooks disabled");
208
209 hook_fn.to_active = func;
210 stat = hook_register(TO_ACTIVE_HOOK, hook_fn);
211 RETURN_ERROR_IF(stat != EM_OK, stat, EM_ESCOPE_HOOKS_REGISTER_TO_ACTIVE,
212 "To_active hook register failed");
213
214 return EM_OK;
215}
216
219{
220 hook_fn_t hook_fn;
221 em_status_t stat;
222
224 EM_ESCOPE_HOOKS_UNREGISTER_TO_ACTIVE,
225 "EM IDLE callback hooks disabled");
226
227 hook_fn.to_active = func;
228 stat = hook_unregister(TO_ACTIVE_HOOK, hook_fn);
229 RETURN_ERROR_IF(stat != EM_OK, stat, EM_ESCOPE_HOOKS_UNREGISTER_TO_ACTIVE,
230 "To_active hook unregister failed");
231
232 return EM_OK;
233}
234
237{
238 hook_fn_t hook_fn;
239 em_status_t stat;
240
242 EM_ESCOPE_HOOKS_REGISTER_WHILE_IDLE,
243 "EM IDLE callback hooks disabled");
244
245 hook_fn.while_idle = func;
246 stat = hook_register(WHILE_IDLE_HOOK, hook_fn);
247 RETURN_ERROR_IF(stat != EM_OK, stat, EM_ESCOPE_HOOKS_REGISTER_WHILE_IDLE,
248 "While_idle hook register failed");
249
250 return EM_OK;
251}
252
255{
256 hook_fn_t hook_fn;
257 em_status_t stat;
258
260 EM_ESCOPE_HOOKS_UNREGISTER_WHILE_IDLE,
261 "EM IDLE callback hooks disabled");
262
263 hook_fn.while_idle = func;
264 stat = hook_unregister(WHILE_IDLE_HOOK, hook_fn);
265 RETURN_ERROR_IF(stat != EM_OK, stat, EM_ESCOPE_HOOKS_UNREGISTER_WHILE_IDLE,
266 "While_idle hook unregister failed");
267
268 return EM_OK;
269}
#define RETURN_ERROR_IF(cond, error, escope, fmt,...)
Definition em_error.h:65
#define EM_IDLE_HOOKS_ENABLE
#define EM_API_HOOKS_ENABLE
#define EM_OK
uint32_t em_status_t
@ EM_ERR_NOT_IMPLEMENTED
void(* em_idle_hook_while_idle_t)(void)
em_status_t em_hooks_register_to_active(em_idle_hook_to_active_t func)
em_status_t em_hooks_unregister_alloc(em_api_hook_alloc_t func)
void(* em_idle_hook_to_active_t)(void)
em_status_t em_hooks_unregister_to_active(em_idle_hook_to_active_t func)
em_status_t em_hooks_register_alloc(em_api_hook_alloc_t func)
void(* em_api_hook_send_t)(const em_event_t events[], int num, em_queue_t queue, em_event_group_t event_group)
em_status_t em_hooks_register_free(em_api_hook_free_t func)
void(* em_idle_hook_to_idle_t)(uint64_t to_idle_delay_ns)
void(* em_api_hook_alloc_t)(const em_event_t events[], int num_act, int num_req, uint32_t size, em_event_type_t type, em_pool_t pool)
em_status_t em_hooks_unregister_to_idle(em_idle_hook_to_idle_t func)
void(* em_api_hook_free_t)(const em_event_t events[], int num)
em_status_t em_hooks_register_to_idle(em_idle_hook_to_idle_t func)
em_status_t em_hooks_register_while_idle(em_idle_hook_while_idle_t func)
em_status_t em_hooks_unregister_free(em_api_hook_free_t func)
em_status_t em_hooks_unregister_send(em_api_hook_send_t func)
em_status_t em_hooks_register_send(em_api_hook_send_t func)
em_status_t em_hooks_unregister_while_idle(em_idle_hook_while_idle_t func)