00001 /* 00002 ******************************************************************************* 00003 * 00004 * Copyright (C) 2003-2005, International Business Machines 00005 * Corporation and others. All Rights Reserved. 00006 * 00007 ******************************************************************************* 00008 * file name: utrace.h 00009 * encoding: US-ASCII 00010 * tab size: 8 (not used) 00011 * indentation:4 00012 * 00013 * created on: 2003aug06 00014 * created by: Markus W. Scherer 00015 * 00016 * Definitions for ICU tracing/logging. 00017 * 00018 */ 00019 00020 #ifndef __UTRACE_H__ 00021 #define __UTRACE_H__ 00022 00023 #include <stdarg.h> 00024 #include "unicode/utypes.h" 00025 00031 U_CDECL_BEGIN 00032 00033 #ifndef U_HIDE_DRAFT_API 00034 00040 typedef enum UTraceLevel { 00042 UTRACE_OFF=-1, 00044 UTRACE_ERROR=0, 00046 UTRACE_WARNING=3, 00048 UTRACE_OPEN_CLOSE=5, 00050 UTRACE_INFO=7, 00052 UTRACE_VERBOSE=9 00053 } UTraceLevel; 00054 00059 typedef enum UTraceFunctionNumber { 00060 UTRACE_FUNCTION_START=0, 00061 UTRACE_U_INIT=UTRACE_FUNCTION_START, 00062 UTRACE_U_CLEANUP, 00063 UTRACE_FUNCTION_LIMIT, 00064 00065 UTRACE_CONVERSION_START=0x1000, 00066 UTRACE_UCNV_OPEN=UTRACE_CONVERSION_START, 00067 UTRACE_UCNV_OPEN_PACKAGE, 00068 UTRACE_UCNV_OPEN_ALGORITHMIC, 00069 UTRACE_UCNV_CLONE, 00070 UTRACE_UCNV_CLOSE, 00071 UTRACE_UCNV_FLUSH_CACHE, 00072 UTRACE_UCNV_LOAD, 00073 UTRACE_UCNV_UNLOAD, 00074 UTRACE_CONVERSION_LIMIT, 00075 00076 UTRACE_COLLATION_START=0x2000, 00077 UTRACE_UCOL_OPEN=UTRACE_COLLATION_START, 00078 UTRACE_UCOL_CLOSE, 00079 UTRACE_UCOL_STRCOLL, 00080 UTRACE_UCOL_GET_SORTKEY, 00081 UTRACE_UCOL_GETLOCALE, 00082 UTRACE_UCOL_NEXTSORTKEYPART, 00083 UTRACE_UCOL_STRCOLLITER, 00084 UTRACE_UCOL_OPEN_FROM_SHORT_STRING, 00085 UTRACE_COLLATION_LIMIT 00086 } UTraceFunctionNumber; 00087 00088 #endif /*U_HIDE_DRAFT_API*/ 00089 00095 U_STABLE void U_EXPORT2 00096 utrace_setLevel(int32_t traceLevel); 00097 00103 U_STABLE int32_t U_EXPORT2 00104 utrace_getLevel(void); 00105 00106 /* Trace function pointers types ----------------------------- */ 00107 00114 typedef void U_CALLCONV 00115 UTraceEntry(const void *context, int32_t fnNumber); 00116 00130 typedef void U_CALLCONV 00131 UTraceExit(const void *context, int32_t fnNumber, 00132 const char *fmt, va_list args); 00133 00145 typedef void U_CALLCONV 00146 UTraceData(const void *context, int32_t fnNumber, int32_t level, 00147 const char *fmt, va_list args); 00148 00177 U_STABLE void U_EXPORT2 00178 utrace_setFunctions(const void *context, 00179 UTraceEntry *e, UTraceExit *x, UTraceData *d); 00180 00191 U_STABLE void U_EXPORT2 00192 utrace_getFunctions(const void **context, 00193 UTraceEntry **e, UTraceExit **x, UTraceData **d); 00194 00195 00196 00197 /* 00198 * 00199 * ICU trace format string syntax 00200 * 00201 * Format Strings are passed to UTraceData functions, and define the 00202 * number and types of the trace data being passed on each call. 00203 * 00204 * The UTraceData function, which is supplied by the application, 00205 * not by ICU, can either forward the trace data (passed via 00206 * varargs) and the format string back to ICU for formatting into 00207 * a displayable string, or it can interpret the format itself, 00208 * and do as it wishes with the trace data. 00209 * 00210 * 00211 * Goals for the format string 00212 * - basic data output 00213 * - easy to use for trace programmer 00214 * - sufficient provision for data types for trace output readability 00215 * - well-defined types and binary portable APIs 00216 * 00217 * Non-goals 00218 * - printf compatibility 00219 * - fancy formatting 00220 * - argument reordering and other internationalization features 00221 * 00222 * ICU trace format strings contain plain text with argument inserts, 00223 * much like standard printf format strings. 00224 * Each insert begins with a '%', then optionally contains a 'v', 00225 * then exactly one type character. 00226 * Two '%' in a row represent a '%' instead of an insert. 00227 * The trace format strings need not have \n at the end. 00228 * 00229 * 00230 * Types 00231 * ----- 00232 * 00233 * Type characters: 00234 * - c A char character in the default codepage. 00235 * - s A NUL-terminated char * string in the default codepage. 00236 * - S A UChar * string. Requires two params, (ptr, length). Length=-1 for nul term. 00237 * - b A byte (8-bit integer). 00238 * - h A 16-bit integer. Also a 16 bit Unicode code unit. 00239 * - d A 32-bit integer. Also a 20 bit Unicode code point value. 00240 * - l A 64-bit integer. 00241 * - p A data pointer. 00242 * 00243 * Vectors 00244 * ------- 00245 * 00246 * If the 'v' is not specified, then one item of the specified type 00247 * is passed in. 00248 * If the 'v' (for "vector") is specified, then a vector of items of the 00249 * specified type is passed in, via a pointer to the first item 00250 * and an int32_t value for the length of the vector. 00251 * Length==-1 means zero or NUL termination. Works for vectors of all types. 00252 * 00253 * Note: %vS is a vector of (UChar *) strings. The strings must 00254 * be nul terminated as there is no way to provide a 00255 * separate length parameter for each string. The length 00256 * parameter (required for all vectors) is the number of 00257 * strings, not the length of the strings. 00258 * 00259 * Examples 00260 * -------- 00261 * 00262 * These examples show the parameters that will be passed to an application's 00263 * UTraceData() function for various formats. 00264 * 00265 * - the precise formatting is up to the application! 00266 * - the examples use type casts for arguments only to _show_ the types of 00267 * arguments without needing variable declarations in the examples; 00268 * the type casts will not be necessary in actual code 00269 * 00270 * UTraceDataFunc(context, fnNumber, level, 00271 * "There is a character %c in the string %s.", // Format String 00272 * (char)c, (const char *)s); // varargs parameters 00273 * -> There is a character 0x42 'B' in the string "Bravo". 00274 * 00275 * UTraceDataFunc(context, fnNumber, level, 00276 * "Vector of bytes %vb vector of chars %vc", 00277 * (const uint8_t *)bytes, (int32_t)bytesLength, 00278 * (const char *)chars, (int32_t)charsLength); 00279 * -> Vector of bytes 00280 * 42 63 64 3f [4] 00281 * vector of chars 00282 * "Bcd?"[4] 00283 * 00284 * UTraceDataFunc(context, fnNumber, level, 00285 * "An int32_t %d and a whole bunch of them %vd", 00286 * (int32_t)-5, (const int32_t *)ints, (int32_t)intsLength); 00287 * -> An int32_t 0xfffffffb and a whole bunch of them 00288 * fffffffb 00000005 0000010a [3] 00289 * 00290 */ 00291 00292 00293 00313 U_STABLE int32_t U_EXPORT2 00314 utrace_vformat(char *outBuf, int32_t capacity, 00315 int32_t indent, const char *fmt, va_list args); 00316 00334 U_STABLE int32_t U_EXPORT2 00335 utrace_format(char *outBuf, int32_t capacity, 00336 int32_t indent, const char *fmt, ...); 00337 00338 00339 00340 /* Trace function numbers --------------------------------------------------- */ 00341 00351 U_STABLE const char * U_EXPORT2 00352 utrace_functionName(int32_t fnNumber); 00353 00354 U_CDECL_END 00355 00356 #endif