]>
Commit | Line | Data |
---|---|---|
374ca955 A |
1 | /* |
2 | ******************************************************************************* | |
3 | * | |
4 | * Copyright (C) 2003-2004, International Business Machines | |
5 | * Corporation and others. All Rights Reserved. | |
6 | * | |
7 | ******************************************************************************* | |
8 | * file name: utrace.h | |
9 | * encoding: US-ASCII | |
10 | * tab size: 8 (not used) | |
11 | * indentation:4 | |
12 | * | |
13 | * created on: 2003aug06 | |
14 | * created by: Markus W. Scherer | |
15 | * | |
16 | * Definitions for ICU tracing/logging. | |
17 | * | |
18 | */ | |
19 | ||
20 | #ifndef __UTRACE_H__ | |
21 | #define __UTRACE_H__ | |
22 | ||
23 | #include <stdarg.h> | |
24 | #include "unicode/utypes.h" | |
25 | ||
26 | U_CDECL_BEGIN | |
27 | ||
28 | #ifndef U_HIDE_DRAFT_API | |
29 | ||
30 | /** | |
31 | * Trace severity levels. Higher levels increase the verbosity of the trace output. | |
32 | * @see utrace_setLevel | |
33 | * @draft ICU 2.8 | |
34 | */ | |
35 | typedef enum UTraceLevel { | |
36 | /** Disable all tracing @draft ICU 2.8*/ | |
37 | UTRACE_OFF=-1, | |
38 | /** Trace error conditions only @draft ICU 2.8*/ | |
39 | UTRACE_ERROR=0, | |
40 | /** Trace errors and warnings @draft ICU 2.8*/ | |
41 | UTRACE_WARNING=3, | |
42 | /** Trace opens and closes of ICU services @draft ICU 2.8*/ | |
43 | UTRACE_OPEN_CLOSE=5, | |
44 | /** Trace an intermediate number of ICU operations @draft ICU 2.8*/ | |
45 | UTRACE_INFO=7, | |
46 | /** Trace the maximum number of ICU operations @draft ICU 2.8*/ | |
47 | UTRACE_VERBOSE=9 | |
48 | } UTraceLevel; | |
49 | ||
50 | /** | |
51 | * These are the ICU functions that will be traced when tracing is enabled. | |
52 | * @draft ICU 2.8 | |
53 | */ | |
54 | typedef enum UTraceFunctionNumber { | |
55 | UTRACE_FUNCTION_START=0, | |
56 | UTRACE_U_INIT=UTRACE_FUNCTION_START, | |
57 | UTRACE_U_CLEANUP, | |
58 | UTRACE_FUNCTION_LIMIT, | |
59 | ||
60 | UTRACE_CONVERSION_START=0x1000, | |
61 | UTRACE_UCNV_OPEN=UTRACE_CONVERSION_START, | |
62 | UTRACE_UCNV_OPEN_PACKAGE, | |
63 | UTRACE_UCNV_OPEN_ALGORITHMIC, | |
64 | UTRACE_UCNV_CLONE, | |
65 | UTRACE_UCNV_CLOSE, | |
66 | UTRACE_UCNV_FLUSH_CACHE, | |
67 | UTRACE_UCNV_LOAD, | |
68 | UTRACE_UCNV_UNLOAD, | |
69 | UTRACE_CONVERSION_LIMIT, | |
70 | ||
71 | UTRACE_COLLATION_START=0x2000, | |
72 | UTRACE_UCOL_OPEN=UTRACE_COLLATION_START, | |
73 | UTRACE_UCOL_CLOSE, | |
74 | UTRACE_UCOL_STRCOLL, | |
75 | UTRACE_UCOL_GET_SORTKEY, | |
76 | UTRACE_UCOL_GETLOCALE, | |
77 | UTRACE_UCOL_NEXTSORTKEYPART, | |
78 | UTRACE_UCOL_STRCOLLITER, | |
79 | UTRACE_UCOL_OPEN_FROM_SHORT_STRING, | |
80 | UTRACE_COLLATION_LIMIT | |
81 | } UTraceFunctionNumber; | |
82 | ||
83 | #endif /*U_HIDE_DRAFT_API*/ | |
84 | ||
85 | /** | |
86 | * Setter for the trace level. | |
87 | * @param traceLevel A UTraceLevel value. | |
88 | * @draft ICU 2.8 | |
89 | */ | |
90 | U_DRAFT void U_EXPORT2 | |
91 | utrace_setLevel(int32_t traceLevel); | |
92 | ||
93 | /** | |
94 | * Getter for the trace level. | |
95 | * @return The UTraceLevel value being used by ICU. | |
96 | * @draft ICU 2.8 | |
97 | */ | |
98 | U_DRAFT int32_t U_EXPORT2 | |
99 | utrace_getLevel(void); | |
100 | ||
101 | /* Trace function pointers types ----------------------------- */ | |
102 | ||
103 | /** | |
104 | * Type signature for the trace function to be called when entering a function. | |
105 | * @param context value supplied at the time the trace functions are set. | |
106 | * @param fnNumber Enum value indicating the ICU function being entered. | |
107 | * @draft ICU 2.8 | |
108 | */ | |
109 | typedef void U_CALLCONV | |
110 | UTraceEntry(const void *context, int32_t fnNumber); | |
111 | ||
112 | /** | |
113 | * Type signature for the trace function to be called when exiting from a function. | |
114 | * @param context value supplied at the time the trace functions are set. | |
115 | * @param fnNumber Enum value indicating the ICU function being exited. | |
116 | * @param fmt A formatting string that describes the number and types | |
117 | * of arguments included with the variable args. The fmt | |
118 | * string has the same form as the utrace_vformat format | |
119 | * string. | |
120 | * @param args A variable arguments list. Contents are described by | |
121 | * the fmt parameter. | |
122 | * @see utrace_vformat | |
123 | * @draft ICU 2.8 | |
124 | */ | |
125 | typedef void U_CALLCONV | |
126 | UTraceExit(const void *context, int32_t fnNumber, | |
127 | const char *fmt, va_list args); | |
128 | ||
129 | /** | |
130 | * Type signature for the trace function to be called from within an ICU function | |
131 | * to display data or messages. | |
132 | * @param context value supplied at the time the trace functions are set. | |
133 | * @param fnNumber Enum value indicating the ICU function being exited. | |
134 | * @param level The current tracing level | |
135 | * @param fmt A format string describing the tracing data that is supplied | |
136 | * as variable args | |
137 | * @param args The data being traced, passed as variable args. | |
138 | * @draft ICU 2.8 | |
139 | */ | |
140 | typedef void U_CALLCONV | |
141 | UTraceData(const void *context, int32_t fnNumber, int32_t level, | |
142 | const char *fmt, va_list args); | |
143 | ||
144 | /** | |
145 | * Set ICU Tracing functions. Installs application-provided tracing | |
146 | * functions into ICU. After doing this, subsequent ICU operations | |
147 | * will call back to the installed functions, providing a trace | |
148 | * of the use of ICU. Passing a NULL pointer for a tracing function | |
149 | * is allowed, and inhibits tracing action at points where that function | |
150 | * would be called. | |
151 | * <p> | |
152 | * Tracing and Threads: Tracing functions are global to a process, and | |
153 | * will be called in response to ICU operations performed by any | |
154 | * thread. If tracing of an individual thread is desired, the | |
155 | * tracing functions must themselves filter by checking that the | |
156 | * current thread is the desired thread. | |
157 | * | |
158 | * @param context an uninterpretted pointer. Whatever is passed in | |
159 | * here will in turn be passed to each of the tracing | |
160 | * functions UTraceEntry, UTraceExit and UTraceData. | |
161 | * ICU does not use or alter this pointer. | |
162 | * @param e Callback function to be called on entry to a | |
163 | * a traced ICU function. | |
164 | * @param x Callback function to be called on exit from a | |
165 | * traced ICU function. | |
166 | * @param d Callback function to be called from within a | |
167 | * traced ICU function, for the purpose of providing | |
168 | * data to the trace. | |
169 | * | |
170 | * @draft ICU 2.8 | |
171 | */ | |
172 | U_DRAFT void U_EXPORT2 | |
173 | utrace_setFunctions(const void *context, | |
174 | UTraceEntry *e, UTraceExit *x, UTraceData *d); | |
175 | ||
176 | /** | |
177 | * Get the currently installed ICU tracing functions. Note that a null function | |
178 | * pointer will be returned if no trace function has been set. | |
179 | * | |
180 | * @param context The currently installed tracing context. | |
181 | * @param e The currently installed UTraceEntry function. | |
182 | * @param x The currently installed UTraceExit function. | |
183 | * @param d The currently installed UTraceData function. | |
184 | * @draft ICU 2.8 | |
185 | */ | |
186 | U_DRAFT void U_EXPORT2 | |
187 | utrace_getFunctions(const void **context, | |
188 | UTraceEntry **e, UTraceExit **x, UTraceData **d); | |
189 | ||
190 | ||
191 | ||
192 | /* | |
193 | * | |
194 | * ICU trace format string syntax | |
195 | * | |
196 | * Format Strings are passed to UTraceData functions, and define the | |
197 | * number and types of the trace data being passed on each call. | |
198 | * | |
199 | * The UTraceData function, which is supplied by the application, | |
200 | * not by ICU, can either forward the trace data (passed via | |
201 | * varargs) and the format string back to ICU for formatting into | |
202 | * a displayable string, or it can interpret the format itself, | |
203 | * and do as it wishes with the trace data. | |
204 | * | |
205 | * | |
206 | * Goals for the format string | |
207 | * - basic data output | |
208 | * - easy to use for trace programmer | |
209 | * - sufficient provision for data types for trace output readability | |
210 | * - well-defined types and binary portable APIs | |
211 | * | |
212 | * Non-goals | |
213 | * - printf compatibility | |
214 | * - fancy formatting | |
215 | * - argument reordering and other internationalization features | |
216 | * | |
217 | * ICU trace format strings contain plain text with argument inserts, | |
218 | * much like standard printf format strings. | |
219 | * Each insert begins with a '%', then optionally contains a 'v', | |
220 | * then exactly one type character. | |
221 | * Two '%' in a row represent a '%' instead of an insert. | |
222 | * The trace format strings need not have \n at the end. | |
223 | * | |
224 | * | |
225 | * Types | |
226 | * ----- | |
227 | * | |
228 | * Type characters: | |
229 | * - c A char character in the default codepage. | |
230 | * - s A NUL-terminated char * string in the default codepage. | |
231 | * - S A UChar * string. Requires two params, (ptr, length). Length=-1 for nul term. | |
232 | * - b A byte (8-bit integer). | |
233 | * - h A 16-bit integer. Also a 16 bit Unicode code unit. | |
234 | * - d A 32-bit integer. Also a 20 bit Unicode code point value. | |
235 | * - l A 64-bit integer. | |
236 | * - p A data pointer. | |
237 | * | |
238 | * Vectors | |
239 | * ------- | |
240 | * | |
241 | * If the 'v' is not specified, then one item of the specified type | |
242 | * is passed in. | |
243 | * If the 'v' (for "vector") is specified, then a vector of items of the | |
244 | * specified type is passed in, via a pointer to the first item | |
245 | * and an int32_t value for the length of the vector. | |
246 | * Length==-1 means zero or NUL termination. Works for vectors of all types. | |
247 | * | |
248 | * Note: %vS is a vector of (UChar *) strings. The strings must | |
249 | * be nul terminated as there is no way to provide a | |
250 | * separate length parameter for each string. The length | |
251 | * parameter (required for all vectors) is the number of | |
252 | * strings, not the length of the strings. | |
253 | * | |
254 | * Examples | |
255 | * -------- | |
256 | * | |
257 | * These examples show the parameters that will be passed to an application's | |
258 | * UTraceData() function for various formats. | |
259 | * | |
260 | * - the precise formatting is up to the application! | |
261 | * - the examples use type casts for arguments only to _show_ the types of | |
262 | * arguments without needing variable declarations in the examples; | |
263 | * the type casts will not be necessary in actual code | |
264 | * | |
265 | * UTraceDataFunc(context, fnNumber, level, | |
266 | * "There is a character %c in the string %s.", // Format String | |
267 | * (char)c, (const char *)s); // varargs parameters | |
268 | * -> There is a character 0x42 'B' in the string "Bravo". | |
269 | * | |
270 | * UTraceDataFunc(context, fnNumber, level, | |
271 | * "Vector of bytes %vb vector of chars %vc", | |
272 | * (const uint8_t *)bytes, (int32_t)bytesLength, | |
273 | * (const char *)chars, (int32_t)charsLength); | |
274 | * -> Vector of bytes | |
275 | * 42 63 64 3f [4] | |
276 | * vector of chars | |
277 | * "Bcd?"[4] | |
278 | * | |
279 | * UTraceDataFunc(context, fnNumber, level, | |
280 | * "An int32_t %d and a whole bunch of them %vd", | |
281 | * (int32_t)-5, (const int32_t *)ints, (int32_t)intsLength); | |
282 | * -> An int32_t 0xfffffffb and a whole bunch of them | |
283 | * fffffffb 00000005 0000010a [3] | |
284 | * | |
285 | */ | |
286 | ||
287 | ||
288 | ||
289 | /** | |
290 | * Trace output Formatter. An application's UTraceData tracing functions may call | |
291 | * back to this function to format the trace output in a | |
292 | * human readable form. Note that a UTraceData function may choose | |
293 | * to not format the data; it could, for example, save it in | |
294 | * in the raw form it was received (more compact), leaving | |
295 | * formatting for a later trace analyis tool. | |
296 | * @param outBuf pointer to a buffer to receive the formatted output. Output | |
297 | * will be nul terminated if there is space in the buffer - | |
298 | * if the length of the requested output < the output buffer size. | |
299 | * @param capacity Length of the output buffer. | |
300 | * @param indent Number of spaces to indent the output. Intended to allow | |
301 | * data displayed from nested functions to be indented for readability. | |
302 | * @param fmt Format specification for the data to output | |
303 | * @param args Data to be formatted. | |
304 | * @return Length of formatted output, including the terminating NUL. | |
305 | * If buffer capacity is insufficient, the required capacity is returned. | |
306 | * @draft ICU 2.8 | |
307 | */ | |
308 | U_DRAFT int32_t U_EXPORT2 | |
309 | utrace_vformat(char *outBuf, int32_t capacity, | |
310 | int32_t indent, const char *fmt, va_list args); | |
311 | ||
312 | /** | |
313 | * Trace output Formatter. An application's UTraceData tracing functions may call | |
314 | * this function to format any additional trace data, beyond that | |
315 | * provided by default, in human readable form with the same | |
316 | * formatting conventions used by utrace_vformat(). | |
317 | * @param outBuf pointer to a buffer to receive the formatted output. Output | |
318 | * will be nul terminated if there is space in the buffer - | |
319 | * if the length of the requested output < the output buffer size. | |
320 | * @param capacity Length of the output buffer. | |
321 | * @param indent Number of spaces to indent the output. Intended to allow | |
322 | * data displayed from nested functions to be indented for readability. | |
323 | * @param fmt Format specification for the data to output | |
324 | * @param ... Data to be formatted. | |
325 | * @return Length of formatted output, including the terminating NUL. | |
326 | * If buffer capacity is insufficient, the required capacity is returned. | |
327 | * @draft ICU 2.8 | |
328 | */ | |
329 | U_DRAFT int32_t U_EXPORT2 | |
330 | utrace_format(char *outBuf, int32_t capacity, | |
331 | int32_t indent, const char *fmt, ...); | |
332 | ||
333 | ||
334 | ||
335 | /* Trace function numbers --------------------------------------------------- */ | |
336 | ||
337 | /** | |
338 | * Get the name of a function from its trace function number. | |
339 | * | |
340 | * @param fnNumber The trace number for an ICU function. | |
341 | * @return The name string for the function. | |
342 | * | |
343 | * @see UTraceFunctionNumber | |
344 | * @draft ICU 2.8 | |
345 | */ | |
346 | U_DRAFT const char * U_EXPORT2 | |
347 | utrace_functionName(int32_t fnNumber); | |
348 | ||
349 | U_CDECL_END | |
350 | ||
351 | #endif |