EM-ODP  3.7.0
Event Machine on ODP
event_machine_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 #ifndef EVENT_MACHINE_ERROR_H_
32 #define EVENT_MACHINE_ERROR_H_
33 
34 #pragma GCC visibility push(default)
35 
36 /**
37  * @file
38  * @defgroup em_error Error management
39  * Error/Exception management
40  *
41  * EM provides two basic mechanisms to manage operational exceptions
42  *
43  * -# Return value
44  * - Most API calls return a status which can be checked by the application
45  *
46  * -# Error handler
47  * - An optional error handler function can be registered. The given
48  * function is called by the EM implementation when an error occurs. This
49  * makes it possible to centralize the error management or even modify
50  * some API behavior as an error handler can modify the original API call
51  * return value as well. For instance, a global error handler could modify
52  * the em_send() behavior in such a way that the application never has to
53  * check the return value by catching all errors, fixing them (like
54  * deallocating event on failed send) and returning EM_OK.
55  * - There can be one global error handler and additionally one per each EO.
56  * @{
57  */
58 
59 #ifdef __cplusplus
60 extern "C" {
61 #endif
62 
64 
65 /**
66  * Error handler prototype
67  *
68  * The error handler is called after EM notices an error or the user has called
69  * em_error().
70  *
71  * The user can register EO specific and/or EM global error handlers. When an
72  * error occurs, EM calls the EO specific error handler, if registered. If
73  * there's no EO specific handler registered or the error occurs outside of an
74  * EO context, EM calls the global error handler.
75  *
76  * The error handler is called with the original error code (that's about to be
77  * returned) from the API call or em_error(). The error scope identifies the
78  * source of the error and how the error code and the variable arguments should
79  * be interpreted (number of arguments and types) in an implementation specific
80  * way.
81  *
82  * @param eo Execution object id
83  * @param error The error code
84  * @param escope Error scope. Identifies the scope for interpreting the
85  * error code and variable arguments.
86  * @param args Variable number and type of arguments
87  *
88  * @return The function may not return depending on implementation, error code
89  * or error scope. If it returns, it can return the original or
90  * modified error code or even EM_OK if it was able to fix the problem.
91  *
92  * @see em_register_error_handler(), em_eo_register_error_handler()
93  */
94 typedef em_status_t (*em_error_handler_t)(em_eo_t eo, em_status_t error,
95  em_escope_t escope, va_list args);
96 
97 /**
98  * Register a global error handler.
99  *
100  * The global error handler is called on EM errors or by em_error() calls,
101  * except when running in an EO context with an EO specific error handler
102  * registered (in which case the EO specific error handler takes precedence).
103  * Note, the provided function will override any previously registered
104  * global error handler.
105  * The EM default global error handler is used when no user provided global
106  * error handler is registered.
107  *
108  * @param handler Error handler.
109  *
110  * @return EM_OK if successful.
111  *
112  * @see em_eo_register_error_handler(), em_unregister_error_handler(),
113  * em_error_handler_t()
114  */
116 
117 /**
118  * Unregister a global error handler.
119  *
120  * Unregisters any previously registered global error handler and
121  * restores the EM default global error handler into use.
122  *
123  * @return EM_OK if successful.
124  *
125  * @see em_register_error_handler()
126  */
128 
129 /**
130  * Report an error.
131  *
132  * Reported errors are handled by the appropriate (EO specific or global)
133  * error handler.
134  *
135  * Depending on the error/scope/implementation, the function call may not
136  * return.
137  *
138  * @param error Error code
139  * @param escope Error scope. Identifies the scope for interpreting the
140  * error code and the variable arguments.
141  * @param ... Variable number and type of arguments
142  *
143  * @see em_register_error_handler(), em_error_handler_t()
144  */
145 void em_error(em_status_t error, em_escope_t escope, ...);
146 
147 /**
148  * @}
149  */
150 #ifdef __cplusplus
151 }
152 #endif
153 
154 #pragma GCC visibility pop
155 #endif /* EVENT_MACHINE_ERROR_H_ */
em_error
void em_error(em_status_t error, em_escope_t escope,...)
Definition: event_machine_error.c:66
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_register_error_handler
em_status_t em_register_error_handler(em_error_handler_t handler)
Definition: event_machine_error.c:34
event_machine_types.h