1 /******************************************************************************
2  *
3  * Copyright (C) 2018 The Android Open Source Project
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at:
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *****************************************************************************
18  * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19 */
20 
21 #ifndef IMPD_ERROR_HANDLER_H
22 #define IMPD_ERROR_HANDLER_H
23 
24 /*****************************************************************************/
25 /* File includes                                                             */
26 /*****************************************************************************/
27 
28 /* these definitions are used by error handling function         */
29 /* the error handler will work on a structure which identifies a */
30 /* particular error with a module, context and error_code        */
31 /* within error_code, MSB identifies FATAL (1), NONFATAL (0)     */
32 /* next 4 ms_bs identify a class of error                        */
33 
34 /*****************************************************************************/
35 /* Constant hash defines                                                     */
36 /*****************************************************************************/
37 #define IA_ERROR_NON_FATAL_IDX 0x0
38 #define IA_ERROR_FATAL_IDX 0x1
39 
40 #define IA_ERROR_CLASS_0 0x0
41 #define IA_ERROR_CLASS_1 0x1
42 #define IA_ERROR_CLASS_2 0x2
43 #define IA_ERROR_CLASS_3 0x3
44 #define IA_ERROR_CLASS_4 0x4
45 #define IA_ERROR_CLASS_5 0x5
46 #define IA_ERROR_CLASS_6 0x6
47 #define IA_ERROR_CLASS_7 0x7
48 #define IA_ERROR_CLASS_8 0x8
49 #define IA_ERROR_CLASS_9 0x9
50 #define IA_ERROR_CLASS_A 0xA
51 #define IA_ERROR_CLASS_B 0xB
52 #define IA_ERROR_CLASS_C 0xC
53 #define IA_ERROR_CLASS_D 0xD
54 #define IA_ERROR_CLASS_E 0xE
55 #define IA_ERROR_CLASS_F 0xF
56 
57 /* each module, hence, needs to copy the following structure          */
58 /* the first index is for FATAL/NONFATAL                              */
59 /* the second index is for the classes                                */
60 /* then in a module specific initialization, fill in the following    */
61 /* structure with the pointers to the particular error message arrays */
62 
63 /*****************************************************************************/
64 /* Type definitions                                                          */
65 /*****************************************************************************/
66 typedef struct {
67   pWORD8 pb_module_name;
68   pWORD8 ppb_class_names[16];
69   WORD8 **ppppb_error_msg_pointers[2][16];
70 } ia_error_info_struct;
71 
72 /*****************************************************************************/
73 /* Function prototypes                                                       */
74 /*****************************************************************************/
75 /* this error handler maps the code generated by a module to a error string */
76 /* pb_context is a string to specify where the module broke                 */
77 IA_ERRORCODE ia_error_handler(ia_error_info_struct *p_mod_err_info,
78                               WORD8 *pb_context, IA_ERRORCODE code);
79 
80 /*****************************************************************************/
81 /* Macro functions                                                           */
82 /*****************************************************************************/
83 /* the following macro does a line job of returning back to the parent */
84 /* in case a fatal error occurs after calling the errorhandler         */
85 #define _IA_HANDLE_ERROR(p_mod_err_info, context, e)    \
86   if ((e) != IA_NO_ERROR) {                             \
87     ia_error_handler((p_mod_err_info), (context), (e)); \
88     if ((e)&IA_FATAL_ERROR) return (e);                 \
89   }
90 
91 #endif
92