EM-ODP  3.7.0
Event Machine on ODP
em_error.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015, 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 /**
41  * Internal error reporting macro
42  */
43 #define INTERNAL_ERROR(error, escope, fmt, ...) \
44  internal_error((error), (escope), __FILE__, __func__, \
45  __LINE__, fmt, ## __VA_ARGS__)
46 
47 /**
48  * Internal macro for return on error
49  */
50 #define RETURN_ERROR_IF(cond, error, escope, fmt, ...) \
51  do { \
52  if (unlikely((cond))) { \
53  return INTERNAL_ERROR((error), (escope), \
54  fmt, ## __VA_ARGS__); \
55  } \
56  } while (0)
57 
58 #define EM_LOG(level, fmt, ...) \
59  do { \
60  em_log_func_t log_fn = em_locm.log_fn; \
61  if (log_fn) \
62  log_fn((level), fmt, ## __VA_ARGS__); \
63  else \
64  em_shm->log_fn((level), fmt, ## __VA_ARGS__); \
65  } while (0)
66 
67 #define EM_VLOG(level, fmt, args) \
68  do { \
69  em_vlog_func_t vlog_fn = em_locm.vlog_fn; \
70  if (vlog_fn) \
71  vlog_fn((level), fmt, (args)); \
72  else \
73  em_shm->vlog_fn((level), fmt, (args)); \
74  } while (0)
75 
76 #define EM_PRINT(fmt, ...) EM_LOG(EM_LOG_PRINT, fmt, ## __VA_ARGS__)
77 
78 /*
79  * Print debug message to log (only if EM_DEBUG_PRINT is set)
80  */
81 #define EM_DBG(fmt, ...) \
82  do { \
83  if (EM_DEBUG_PRINT == 1) \
84  EM_LOG(EM_LOG_DBG, fmt, ##__VA_ARGS__); \
85  } while (0)
86 
87 /**
88  * EM internal error
89  * Don't call directly, should _always_ be used from within the error-macros
90  */
92 internal_error(em_status_t error, em_escope_t escope, ...);
93 
95 early_log_init(em_log_func_t user_log_fn, em_vlog_func_t user_vlog_fn);
96 
97 void
98 log_init(void);
99 
100 void
101 error_init(void);
102 
104 default_error_handler(em_eo_t eo, em_status_t error, em_escope_t escope,
105  va_list args);
106 
108 select_error_handler(em_status_t error, em_escope_t escope, va_list args_list);
109 
110 uint64_t
111 load_global_err_cnt(void);
112 
113 ODP_PRINTF_FORMAT(2, 3)
114 int default_log(em_log_level_t level, const char *fmt, ...);
115 
116 int
117 vdefault_log(em_log_level_t level, const char *fmt, va_list args);
118 
119 #endif /* EM_ERROR_H_ */
error_init
void error_init(void)
Definition: em_error.c:339
em_log_func_t
int(* em_log_func_t)(em_log_level_t level, const char *fmt,...) __attribute__((format(printf
Definition: event_machine_hw_types.h:329
internal_error
em_status_t internal_error(em_status_t error, em_escope_t escope,...)
Definition: em_error.c:316
select_error_handler
em_status_t select_error_handler(em_status_t error, em_escope_t escope, va_list args_list)
Definition: em_error.c:250
em_escope_t
uint32_t em_escope_t
Definition: event_machine_types.h:348
em_status_t
uint32_t em_status_t
Definition: event_machine_types.h:321
em_log_level_t
em_log_level_t
Definition: event_machine_hw_types.h:318
em_vlog_func_t
int(*) typedef int(* em_vlog_func_t)(em_log_level_t level, const char *fmt, va_list args)
Definition: event_machine_hw_types.h:337
default_error_handler
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:180