EM-ODP  3.7.0
Event Machine on ODP
event_machine_error.c
1 /*
2  * Copyright (c) 2015-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 #include "em_include.h"
32 
35 {
36  RETURN_ERROR_IF(!em_shm->error_handler.initialized,
37  EM_ERR_NOT_INITIALIZED, EM_ESCOPE_REGISTER_ERROR_HANDLER,
38  "Error Handling not initialized!");
39 
40  env_spinlock_lock(&em_shm->error_handler.lock);
41 
42  em_shm->error_handler.em_error_handler = handler;
43 
44  env_spinlock_unlock(&em_shm->error_handler.lock);
45 
46  return EM_OK;
47 }
48 
51 {
52  RETURN_ERROR_IF(!em_shm->error_handler.initialized,
53  EM_ERR_NOT_INITIALIZED, EM_ESCOPE_UNREGISTER_ERROR_HANDLER,
54  "Error Handling not initialized!");
55 
56  env_spinlock_lock(&em_shm->error_handler.lock);
57 
58  em_shm->error_handler.em_error_handler = default_error_handler;
59 
60  env_spinlock_unlock(&em_shm->error_handler.lock);
61 
62  return EM_OK;
63 }
64 
65 void
66 em_error(em_status_t error, em_escope_t escope, ...)
67 {
68  va_list args_list;
69 
70  va_start(args_list, escope);
71 
72  select_error_handler(error, escope, args_list);
73 
74  va_end(args_list);
75 }
EM_OK
#define EM_OK
Definition: event_machine_types.h:329
EM_ERR_NOT_INITIALIZED
@ EM_ERR_NOT_INITIALIZED
Definition: event_machine_hw_types.h:280
em_error
void em_error(em_status_t error, em_escope_t escope,...)
Definition: event_machine_error.c:66
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
RETURN_ERROR_IF
#define RETURN_ERROR_IF(cond, error, escope, fmt,...)
Definition: em_error.h:50
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_unregister_error_handler
em_status_t em_unregister_error_handler(void)
Definition: event_machine_error.c:50
em_error_handler_t
em_status_t(* em_error_handler_t)(em_eo_t eo, em_status_t error, em_escope_t escope, va_list args)
Definition: event_machine_error.h:94
em_shm
em_shm_t * em_shm
Definition: event_machine_init.c:41
em_include.h
em_register_error_handler
em_status_t em_register_error_handler(em_error_handler_t handler)
Definition: event_machine_error.c:34
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