EM-ODP 4.4.0
Event Machine on ODP
Loading...
Searching...
No Matches
em_error.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2015-2025, 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 Error Handler functions
35 */
36
37#ifndef EM_ERROR_H
38#define EM_ERROR_H
39
40#include <stdarg.h>
41#include <stdbool.h>
42#include <stddef.h>
43#include <stdint.h>
44
45#include <odp_api.h>
46
47#include <event_machine.h>
48
49#include "em_mem.h"
50
51#ifdef __cplusplus
52extern "C" {
53#endif
54
55/**
56 * Internal error reporting macro
57 */
58#define INTERNAL_ERROR(error, escope, fmt, ...) \
59 internal_error((error), (escope), __FILE__, __func__, \
60 __LINE__, fmt, ## __VA_ARGS__)
61
62/**
63 * Internal macro for return on error
64 */
65#define RETURN_ERROR_IF(cond, error, escope, fmt, ...) \
66 do { \
67 if (unlikely((cond))) { \
68 return INTERNAL_ERROR((error), (escope), \
69 fmt, ## __VA_ARGS__); \
70 } \
71 } while (0)
72
73#define EM_LOG(level, fmt, ...) \
74 do { \
75 em_log_func_t log_fn = em_locm.log_fn; \
76 if (log_fn) \
77 log_fn((level), fmt, ## __VA_ARGS__); \
78 else \
79 em_shm->log_fn((level), fmt, ## __VA_ARGS__); \
80 } while (0)
81
82#define EM_VLOG(level, fmt, args) \
83 do { \
84 em_vlog_func_t vlog_fn = em_locm.vlog_fn; \
85 if (vlog_fn) \
86 vlog_fn((level), fmt, (args)); \
87 else \
88 em_shm->vlog_fn((level), fmt, (args)); \
89 } while (0)
90
91#define EM_PRINT(fmt, ...) EM_LOG(EM_LOG_PRINT, fmt, ## __VA_ARGS__)
92
93/*
94 * Print debug message to log (only if related EM_DEBUG_PRINT... is set on)
95 */
96#define EM_DBG(em_dbg_flag, fmt, ...) \
97 do { \
98 if (em_dbg_flag) \
99 EM_LOG(EM_LOG_DBG, fmt, ##__VA_ARGS__); \
100 } while (0)
101
102/*
103 * Print debug message to log (only if EM_DEBUG_PRINT_BASE is set on)
104 */
105#define DBG_PRINT(fmt, ...) \
106 EM_DBG(EM_DEBUG_PRINT_BASE, fmt, ## __VA_ARGS__)
107
108const char *err_status_str(em_status_t status);
109const char *escope_api_str(em_escope_t escope);
110const char *escope_internal_str(em_escope_t escope);
111const char *escope_addon_api_str(em_escope_t escope);
112
113size_t format_errmsg(em_status_t error, em_escope_t escope,
114 const char *eo_str, va_list args, bool early_mode,
115 char err_msg[/*out*/], size_t errmsg_sz);
116
117/**
118 * EM internal error
119 * Don't call directly, should _always_ be used from within the error-macros
120 */
122
123em_status_t early_log_init(em_log_func_t user_log_fn, em_vlog_func_t user_vlog_fn);
124
125void log_init(void);
126void error_init(void);
127
129 em_escope_t escope, va_list args);
131 va_list args_list);
132uint64_t load_global_err_cnt(void);
133
134ODP_PRINTF_FORMAT(2, 3)
135int default_log(em_log_level_t level, const char *fmt, ...);
136int vdefault_log(em_log_level_t level, const char *fmt, va_list args);
137
138#ifdef __cplusplus
139}
140#endif
141
142#endif /* EM_ERROR_H_ */
em_status_t select_error_handler(em_status_t error, em_escope_t escope, va_list args_list)
Definition em_error.c:732
em_status_t default_error_handler(em_eo_t eo, em_status_t error, em_escope_t escope, va_list args)
Definition em_error.c:673
em_status_t internal_error(em_status_t error, em_escope_t escope,...)
Definition em_error.c:797
void error_init(void)
Definition em_error.c:819
uint32_t em_escope_t
uint32_t em_status_t
int(* em_log_func_t)(em_log_level_t level, const char *fmt,...) __attribute__((format(printf
int(*) typedef int(* em_vlog_func_t)(em_log_level_t level, const char *fmt, va_list args)