EM-ODP 4.4.0
Event Machine on ODP
Loading...
Searching...
No Matches
em_hooks.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2019, 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#ifndef EM_HOOKS_H_
32#define EM_HOOKS_H_
33
34/**
35 * @file
36 * EM internal API callback hook functions
37 */
38
39#include <stdint.h>
40
41#include <event_machine.h>
42
43#include "em_hook_types.h"
44#include "em_mem.h"
45
46#ifdef __cplusplus
47extern "C" {
48#endif
49
50/**
51 * EM API-callback and idle hooks init function (called once at startup).
52 */
54hooks_init(const em_api_hooks_t *api_hooks, const em_idle_hooks_t *idle_hooks);
55
56/**
57 * Helper function for registering callback hook functions.
58 *
59 * @return EM_OK if there was room left to register a new callback
60 */
62hook_register(uint8_t type, hook_fn_t hook_fn);
63
64/**
65 * Helper function for unregistering dispatcher callback functions.
66 *
67 * @return EM_OK if there was room left to register a new callback
68 */
70hook_unregister(uint8_t type, hook_fn_t hook_fn);
71
72static inline void
73call_api_hooks_alloc(const em_event_t events[], const int num_act,
74 const int num_req, uint32_t size, em_event_type_t type,
75 em_pool_t pool)
76{
77 const hook_tbl_t *alloc_hook_tbl = em_shm->alloc_hook_tbl;
78 em_api_hook_alloc_t alloc_hook_fn;
79
80 for (int i = 0; i < EM_CALLBACKS_MAX; i++) {
81 alloc_hook_fn = alloc_hook_tbl->tbl[i].alloc;
82 if (alloc_hook_fn == NULL)
83 return;
84 alloc_hook_fn(events, num_act, num_req, size, type, pool);
85 }
86}
87
88static inline void
89call_api_hooks_free(const em_event_t events[], const int num)
90{
91 const hook_tbl_t *free_hook_tbl = em_shm->free_hook_tbl;
92 em_api_hook_free_t free_hook_fn;
93
94 for (int i = 0; i < EM_CALLBACKS_MAX; i++) {
95 free_hook_fn = free_hook_tbl->tbl[i].free;
96 if (free_hook_fn == NULL)
97 return;
98 free_hook_fn(events, num);
99 }
100}
101
102static inline void
103call_api_hooks_send(const em_event_t events[], const int num,
104 em_queue_t queue, em_event_group_t event_group)
105{
106 const hook_tbl_t *send_hook_tbl = em_shm->send_hook_tbl;
107 em_api_hook_send_t send_hook_fn;
108
109 for (int i = 0; i < EM_CALLBACKS_MAX; i++) {
110 send_hook_fn = send_hook_tbl->tbl[i].send;
111 if (send_hook_fn == NULL)
112 return;
113 send_hook_fn(events, num, queue, event_group);
114 }
115}
116
117static inline void call_idle_hooks_to_idle(uint64_t to_idle_delay_ns)
118{
119 const hook_tbl_t *to_idle_hook_tbl = em_shm->to_idle_hook_tbl;
120 em_idle_hook_to_idle_t to_idle_hook_fn;
121
122 for (int i = 0; i < EM_CALLBACKS_MAX; i++) {
123 to_idle_hook_fn = to_idle_hook_tbl->tbl[i].to_idle;
124 if (to_idle_hook_fn == NULL)
125 return;
126 to_idle_hook_fn(to_idle_delay_ns);
127 }
128}
129
130static inline void call_idle_hooks_to_active(void)
131{
132 const hook_tbl_t *to_active_hook_tbl = em_shm->to_active_hook_tbl;
133 em_idle_hook_to_active_t to_active_hook_fn;
134
135 for (int i = 0; i < EM_CALLBACKS_MAX; i++) {
136 to_active_hook_fn = to_active_hook_tbl->tbl[i].to_active;
137 if (to_active_hook_fn == NULL)
138 return;
139 to_active_hook_fn();
140 }
141}
142
143static inline void call_idle_hooks_while_idle(void)
144{
145 const hook_tbl_t *while_idle_hook_tbl = em_shm->while_idle_hook_tbl;
146 em_idle_hook_while_idle_t while_idle_hook_fn;
147
148 for (int i = 0; i < EM_CALLBACKS_MAX; i++) {
149 while_idle_hook_fn = while_idle_hook_tbl->tbl[i].while_idle;
150 if (while_idle_hook_fn == NULL)
151 return;
152 while_idle_hook_fn();
153 }
154}
155
156#ifdef __cplusplus
157}
158#endif
159
160#endif /* EM_HOOKS_H_ */
em_status_t hooks_init(const em_api_hooks_t *api_hooks, const em_idle_hooks_t *idle_hooks)
Definition em_hooks.c:62
em_status_t hook_unregister(uint8_t type, hook_fn_t hook_fn)
Definition em_hooks.c:215
em_status_t hook_register(uint8_t type, hook_fn_t hook_fn)
Definition em_hooks.c:161
em_shm_t * em_shm
#define EM_CALLBACKS_MAX
uint32_t em_event_type_t
uint32_t em_status_t
void(* em_idle_hook_while_idle_t)(void)
void(* em_idle_hook_to_active_t)(void)
void(* em_api_hook_send_t)(const em_event_t events[], int num, em_queue_t queue, em_event_group_t event_group)
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)
void(* em_api_hook_free_t)(const em_event_t events[], int num)
hook_tbl_t * alloc_hook_tbl
Definition em_mem.h:140
hook_tbl_t * to_idle_hook_tbl
Definition em_mem.h:146
hook_tbl_t * to_active_hook_tbl
Definition em_mem.h:148
hook_tbl_t * while_idle_hook_tbl
Definition em_mem.h:150
hook_tbl_t * free_hook_tbl
Definition em_mem.h:142
hook_tbl_t * send_hook_tbl
Definition em_mem.h:144