1 /*----------------------------------------------------------------------------
2  *
3  * File:
4  * eas_report.c
5  *
6  * Contents and purpose:
7  * This file contains the debug message handling routines for the EAS library.
8  * These routines should be modified as needed for your system.
9  *
10  * Copyright 2005 Sonic Network Inc.
11 
12  * Licensed under the Apache License, Version 2.0 (the "License");
13  * you may not use this file except in compliance with the License.
14  * You may obtain a copy of the License at
15  *
16  *      http://www.apache.org/licenses/LICENSE-2.0
17  *
18  * Unless required by applicable law or agreed to in writing, software
19  * distributed under the License is distributed on an "AS IS" BASIS,
20  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21  * See the License for the specific language governing permissions and
22  * limitations under the License.
23  *
24  *----------------------------------------------------------------------------
25  * Revision Control:
26  *   $Revision: 659 $
27  *   $Date: 2007-04-24 13:36:35 -0700 (Tue, 24 Apr 2007) $
28  *----------------------------------------------------------------------------
29 */
30 
31 #ifdef _lint
32 #include "lint_stdlib.h"
33 #else
34 #include <stdlib.h>
35 #include <stdio.h>
36 #include <stdarg.h>
37 #endif
38 
39 #include "eas_report.h"
40 
41 static int severityLevel = 9999;
42 
43 /* debug file */
44 static FILE *debugFile = NULL;
45 int flush = 0;
46 
47 #ifndef _NO_DEBUG_PREPROCESSOR
48 
49 /* structure should have an #include for each error message header file */
50 S_DEBUG_MESSAGES debugMessages[] =
51 {
52 #ifndef UNIFIED_DEBUG_MESSAGES
53 #include "eas_config_msgs.h"
54 
55 
56 #include "eas_host_msgs.h"
57 #include "eas_hostmm_msgs.h"
58 #include "eas_math_msgs.h"
59 #include "eas_midi_msgs.h"
60 #include "eas_mixer_msgs.h"
61 #include "eas_pcm_msgs.h"
62 #include "eas_public_msgs.h"
63 #include "eas_smf_msgs.h"
64 #include "eas_wave_msgs.h"
65 #include "eas_voicemgt_msgs.h"
66 
67 #ifdef _FM_SYNTH
68 #include "eas_fmsynth_msgs.h"
69 #include "eas_fmengine_msgs.h"
70 #endif
71 
72 #ifdef _WT_SYNTH
73 #include "eas_wtsynth_msgs.h"
74 #include "eas_wtengine_msgs.h"
75 #endif
76 
77 #ifdef _ARM_TEST_MAIN
78 #include "arm_main_msgs.h"
79 #endif
80 
81 #ifdef _EAS_MAIN
82 #include "eas_main_msgs.h"
83 #endif
84 
85 #ifdef _EAS_MAIN_IPC
86 #include "eas_main_ipc_msgs.h"
87 #endif
88 
89 #ifdef _METRICS_ENABLED
90 #include "eas_perf_msgs.h"
91 #endif
92 
93 #ifdef _COMPRESSOR_ENABLED
94 #include "eas_compressor_msgs.h"
95 #endif
96 
97 #ifdef _ENHANCER_ENABLED
98 #include "eas_enhancer_msgs.h"
99 #endif
100 
101 #ifdef _WOW_ENABLED
102 #include "eas_wow_msgs.h"
103 #endif
104 
105 #ifdef _SMAF_PARSER
106 #include "eas_smaf_msgs.h"
107 #endif
108 
109 #ifdef _OTA_PARSER
110 #include "eas_ota_msgs.h"
111 #endif
112 
113 #ifdef _IMELODY_PARSER
114 #include "eas_imelody_msgs.h"
115 #endif
116 
117 #ifdef _WAVE_PARSER
118 #include "eas_wavefile_msgs.h"
119 #endif
120 
121 #if defined(_CMX_PARSER) || defined(_MFI_PARSER)
122 #include "eas_cmf_msgs.h"
123 #endif
124 
125 #if defined(_CMX_PARSER) || defined(_MFI_PARSER) || defined(_WAVE_PARSER)
126 #include "eas_imaadpcm_msgs.h"
127 #endif
128 
129 #else
130 #include "eas_debugmsgs.h"
131 #endif
132 
133 /* denotes end of error messages */
134 { 0,0,0 }
135 };
136 
137 /*----------------------------------------------------------------------------
138  * EAS_ReportEx()
139  *
140  * This is the error message handler. The default handler outputs error
141  * messages to stdout. Modify this as needed for your system.
142  *----------------------------------------------------------------------------
143 */
EAS_ReportEx(int severity,unsigned long hashCode,int serialNum,...)144 void EAS_ReportEx (int severity, unsigned long hashCode, int serialNum, ...)
145 {
146     va_list vargs;
147     int i;
148 
149     /* check severity level */
150     if (severity > severityLevel)
151         return;
152 
153     /* find the error message and output to stdout */
154     /*lint -e{661} we check for NULL pointer - no fence post error here */
155     for (i = 0; debugMessages[i].m_pDebugMsg; i++)
156     {
157         if ((debugMessages[i].m_nHashCode == hashCode) &&
158         (debugMessages[i].m_nSerialNum == serialNum))
159         {
160             /*lint -e{826} <allow variable args> */
161             va_start(vargs, serialNum);
162             if (debugFile)
163             {
164                 vfprintf(debugFile, debugMessages[i].m_pDebugMsg, vargs);
165                 if (flush)
166                     fflush(debugFile);
167             }
168             else
169             {
170                 vprintf(debugMessages[i].m_pDebugMsg, vargs);
171             }
172             va_end(vargs);
173             return;
174         }
175     }
176     printf("Unrecognized error: Severity=%d; HashCode=%lu; SerialNum=%d\n", severity, hashCode, serialNum);
177 } /* end EAS_ReportEx */
178 
179 #else
180 /*----------------------------------------------------------------------------
181  * EAS_Report()
182  *
183  * This is the error message handler. The default handler outputs error
184  * messages to stdout. Modify this as needed for your system.
185  *----------------------------------------------------------------------------
186 */
EAS_Report(int severity,const char * fmt,...)187 void EAS_Report (int severity, const char *fmt, ...)
188 {
189     va_list vargs;
190 
191     /* check severity level */
192     if (severity > severityLevel)
193         return;
194 
195     /*lint -e{826} <allow variable args> */
196     va_start(vargs, fmt);
197     if (debugFile)
198     {
199         vfprintf(debugFile, fmt, vargs);
200         if (flush)
201             fflush(debugFile);
202     }
203     else
204     {
205         vprintf(fmt, vargs);
206     }
207     va_end(vargs);
208 } /* end EAS_Report */
209 
210 /*----------------------------------------------------------------------------
211  * EAS_ReportX()
212  *
213  * This is the error message handler. The default handler outputs error
214  * messages to stdout. Modify this as needed for your system.
215  *----------------------------------------------------------------------------
216 */
EAS_ReportX(int severity,const char * fmt,...)217 void EAS_ReportX (int severity, const char *fmt, ...)
218 {
219     va_list vargs;
220 
221     /* check severity level */
222     if (severity > severityLevel)
223         return;
224 
225     /*lint -e{826} <allow variable args> */
226     va_start(vargs, fmt);
227     if (debugFile)
228     {
229         vfprintf(debugFile, fmt, vargs);
230         if (flush)
231             fflush(debugFile);
232     }
233     else
234     {
235         vprintf(fmt, vargs);
236     }
237     va_end(vargs);
238 } /* end EAS_ReportX */
239 #endif
240 
241 /*----------------------------------------------------------------------------
242  * EAS_SetDebugLevel()
243  *
244  * Sets the level for debug message output
245  *----------------------------------------------------------------------------
246 */
247 
EAS_SetDebugLevel(int severity)248 void EAS_SetDebugLevel (int severity)
249 {
250     severityLevel = severity;
251 } /* end EAS_SetDebugLevel */
252 
253 /*----------------------------------------------------------------------------
254  * EAS_SetDebugFile()
255  *
256  * Redirect debugger output to the specified file.
257  *----------------------------------------------------------------------------
258 */
EAS_SetDebugFile(void * file,int flushAfterWrite)259 void EAS_SetDebugFile (void *file, int flushAfterWrite)
260 {
261     debugFile = (FILE*) file;
262     flush = flushAfterWrite;
263 } /* end EAS_SetDebugFile */
264 
265