EM-ODP  3.7.0
Event Machine on ODP
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 #include "em_include.h"
39 
42 {
43  hook_fn_t hook_fn;
44  em_status_t stat;
45 
48  "EM API callback hooks disabled");
49 
50  hook_fn.alloc = func;
51  stat = hook_register(ALLOC_HOOK, hook_fn);
53  "Alloc hook register failed");
54 
55  return EM_OK;
56 }
57 
60 {
61  hook_fn_t hook_fn;
62  em_status_t stat;
63 
66  "EM API callback hooks disabled");
67 
68  hook_fn.alloc = func;
69  stat = hook_unregister(ALLOC_HOOK, hook_fn);
71  "Alloc hook unregister failed");
72 
73  return EM_OK;
74 }
75 
78 {
79  hook_fn_t hook_fn;
80  em_status_t stat;
81 
84  "EM API callback hooks disabled");
85 
86  hook_fn.free = func;
87  stat = hook_register(FREE_HOOK, hook_fn);
89  "Free hook register failed");
90 
91  return EM_OK;
92 }
93 
96 {
97  hook_fn_t hook_fn;
98  em_status_t stat;
99 
102  "EM API callback hooks disabled");
103 
104  hook_fn.free = func;
105  stat = hook_unregister(FREE_HOOK, hook_fn);
107  "Free hook unregister failed");
108 
109  return EM_OK;
110 }
111 
114 {
115  hook_fn_t hook_fn;
116  em_status_t stat;
117 
120  "EM API callback hooks disabled");
121 
122  hook_fn.send = func;
123  stat = hook_register(SEND_HOOK, hook_fn);
125  "Send hook register failed");
126 
127  return EM_OK;
128 }
129 
132 {
133  hook_fn_t hook_fn;
134  em_status_t stat;
135 
138  "EM API callback hooks disabled");
139 
140  hook_fn.send = func;
141  stat = hook_unregister(SEND_HOOK, hook_fn);
143  "Send hook unregister failed");
144 
145  return EM_OK;
146 }
147 
150 {
151  hook_fn_t hook_fn;
152  em_status_t stat;
153 
156  "EM IDLE callback hooks disabled");
157 
158  hook_fn.to_idle = func;
159  stat = hook_register(TO_IDLE_HOOK, hook_fn);
161  "To_idle hook register failed");
162 
163  return EM_OK;
164 }
165 
168 {
169  hook_fn_t hook_fn;
170  em_status_t stat;
171 
174  "EM IDLE callback hooks disabled");
175 
176  hook_fn.to_idle = func;
177  stat = hook_unregister(TO_IDLE_HOOK, hook_fn);
179  "To_idle hook unregister failed");
180 
181  return EM_OK;
182 }
183 
186 {
187  hook_fn_t hook_fn;
188  em_status_t stat;
189 
192  "EM IDLE callback hooks disabled");
193 
194  hook_fn.to_active = func;
195  stat = hook_register(TO_ACTIVE_HOOK, hook_fn);
197  "To_active hook register failed");
198 
199  return EM_OK;
200 }
201 
204 {
205  hook_fn_t hook_fn;
206  em_status_t stat;
207 
210  "EM IDLE callback hooks disabled");
211 
212  hook_fn.to_active = func;
213  stat = hook_unregister(TO_ACTIVE_HOOK, hook_fn);
215  "To_active hook unregister failed");
216 
217  return EM_OK;
218 }
219 
222 {
223  hook_fn_t hook_fn;
224  em_status_t stat;
225 
228  "EM IDLE callback hooks disabled");
229 
230  hook_fn.while_idle = func;
231  stat = hook_register(WHILE_IDLE_HOOK, hook_fn);
233  "While_idle hook register failed");
234 
235  return EM_OK;
236 }
237 
240 {
241  hook_fn_t hook_fn;
242  em_status_t stat;
243 
246  "EM IDLE callback hooks disabled");
247 
248  hook_fn.while_idle = func;
249  stat = hook_unregister(WHILE_IDLE_HOOK, hook_fn);
251  "While_idle hook unregister failed");
252 
253  return EM_OK;
254 }
EM_OK
#define EM_OK
Definition: event_machine_types.h:329
hook_register
em_status_t hook_register(uint8_t type, hook_fn_t hook_fn)
Definition: em_hooks.c:140
em_hooks_unregister_alloc
em_status_t em_hooks_unregister_alloc(em_api_hook_alloc_t func)
Definition: event_machine_hooks.c:59
EM_API_HOOKS_ENABLE
#define EM_API_HOOKS_ENABLE
Definition: event_machine_config.h:182
EM_ESCOPE_HOOKS_UNREGISTER_FREE
#define EM_ESCOPE_HOOKS_UNREGISTER_FREE
Definition: event_machine_hw_types.h:574
EM_ESCOPE_HOOKS_UNREGISTER_TO_ACTIVE
#define EM_ESCOPE_HOOKS_UNREGISTER_TO_ACTIVE
Definition: event_machine_hw_types.h:604
em_idle_hook_to_active_t
void(* em_idle_hook_to_active_t)(void)
Definition: event_machine_hooks.h:186
EM_ESCOPE_HOOKS_REGISTER_TO_IDLE
#define EM_ESCOPE_HOOKS_REGISTER_TO_IDLE
Definition: event_machine_hw_types.h:589
em_api_hook_send_t
void(* em_api_hook_send_t)(const em_event_t events[], int num, em_queue_t queue, em_event_group_t event_group)
Definition: event_machine_hooks.h:158
em_idle_hook_while_idle_t
void(* em_idle_hook_while_idle_t)(void)
Definition: event_machine_hooks.h:196
em_idle_hook_to_idle_t
void(* em_idle_hook_to_idle_t)(uint64_t to_idle_delay_ns)
Definition: event_machine_hooks.h:175
em_hooks_unregister_to_idle
em_status_t em_hooks_unregister_to_idle(em_idle_hook_to_idle_t func)
Definition: event_machine_hooks.c:167
em_hooks_register_free
em_status_t em_hooks_register_free(em_api_hook_free_t func)
Definition: event_machine_hooks.c:77
em_hooks_register_alloc
em_status_t em_hooks_register_alloc(em_api_hook_alloc_t func)
Definition: event_machine_hooks.c:41
em_hooks_unregister_send
em_status_t em_hooks_unregister_send(em_api_hook_send_t func)
Definition: event_machine_hooks.c:131
EM_ESCOPE_HOOKS_REGISTER_ALLOC
#define EM_ESCOPE_HOOKS_REGISTER_ALLOC
Definition: event_machine_hw_types.h:559
EM_ESCOPE_HOOKS_UNREGISTER_ALLOC
#define EM_ESCOPE_HOOKS_UNREGISTER_ALLOC
Definition: event_machine_hw_types.h:564
em_hooks_unregister_to_active
em_status_t em_hooks_unregister_to_active(em_idle_hook_to_active_t func)
Definition: event_machine_hooks.c:203
EM_ESCOPE_HOOKS_REGISTER_TO_ACTIVE
#define EM_ESCOPE_HOOKS_REGISTER_TO_ACTIVE
Definition: event_machine_hw_types.h:599
hook_unregister
em_status_t hook_unregister(uint8_t type, hook_fn_t hook_fn)
Definition: em_hooks.c:194
EM_ESCOPE_HOOKS_UNREGISTER_WHILE_IDLE
#define EM_ESCOPE_HOOKS_UNREGISTER_WHILE_IDLE
Definition: event_machine_hw_types.h:614
RETURN_ERROR_IF
#define RETURN_ERROR_IF(cond, error, escope, fmt,...)
Definition: em_error.h:50
EM_ESCOPE_HOOKS_REGISTER_FREE
#define EM_ESCOPE_HOOKS_REGISTER_FREE
Definition: event_machine_hw_types.h:569
EM_IDLE_HOOKS_ENABLE
#define EM_IDLE_HOOKS_ENABLE
Definition: event_machine_config.h:200
em_hooks_register_while_idle
em_status_t em_hooks_register_while_idle(em_idle_hook_while_idle_t func)
Definition: event_machine_hooks.c:221
em_status_t
uint32_t em_status_t
Definition: event_machine_types.h:321
em_api_hook_alloc_t
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)
Definition: event_machine_hooks.h:113
em_include.h
em_hooks_unregister_free
em_status_t em_hooks_unregister_free(em_api_hook_free_t func)
Definition: event_machine_hooks.c:95
EM_ESCOPE_HOOKS_UNREGISTER_SEND
#define EM_ESCOPE_HOOKS_UNREGISTER_SEND
Definition: event_machine_hw_types.h:584
em_hooks_register_send
em_status_t em_hooks_register_send(em_api_hook_send_t func)
Definition: event_machine_hooks.c:113
EM_ESCOPE_HOOKS_UNREGISTER_TO_IDLE
#define EM_ESCOPE_HOOKS_UNREGISTER_TO_IDLE
Definition: event_machine_hw_types.h:594
em_hooks_unregister_while_idle
em_status_t em_hooks_unregister_while_idle(em_idle_hook_while_idle_t func)
Definition: event_machine_hooks.c:239
hook_fn_t
Definition: em_hook_types.h:61
EM_ERR_NOT_IMPLEMENTED
@ EM_ERR_NOT_IMPLEMENTED
Definition: event_machine_hw_types.h:282
EM_ESCOPE_HOOKS_REGISTER_WHILE_IDLE
#define EM_ESCOPE_HOOKS_REGISTER_WHILE_IDLE
Definition: event_machine_hw_types.h:609
EM_ESCOPE_HOOKS_REGISTER_SEND
#define EM_ESCOPE_HOOKS_REGISTER_SEND
Definition: event_machine_hw_types.h:579
em_api_hook_free_t
void(* em_api_hook_free_t)(const em_event_t events[], int num)
Definition: event_machine_hooks.h:138
em_hooks_register_to_active
em_status_t em_hooks_register_to_active(em_idle_hook_to_active_t func)
Definition: event_machine_hooks.c:185
em_hooks_register_to_idle
em_status_t em_hooks_register_to_idle(em_idle_hook_to_idle_t func)
Definition: event_machine_hooks.c:149