00001 /* 00002 ******************************************************************************* 00003 * 00004 * Copyright (C) 2003-2012, 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 00037 U_CDECL_BEGIN 00038 00044 typedef enum UTraceLevel { 00046 UTRACE_OFF=-1, 00048 UTRACE_ERROR=0, 00050 UTRACE_WARNING=3, 00052 UTRACE_OPEN_CLOSE=5, 00054 UTRACE_INFO=7, 00056 UTRACE_VERBOSE=9 00057 } UTraceLevel; 00058 00063 typedef enum UTraceFunctionNumber { 00064 UTRACE_FUNCTION_START=0, 00065 UTRACE_U_INIT=UTRACE_FUNCTION_START, 00066 UTRACE_U_CLEANUP, 00067 UTRACE_FUNCTION_LIMIT, 00068 00069 UTRACE_CONVERSION_START=0x1000, 00070 UTRACE_UCNV_OPEN=UTRACE_CONVERSION_START, 00071 UTRACE_UCNV_OPEN_PACKAGE, 00072 UTRACE_UCNV_OPEN_ALGORITHMIC, 00073 UTRACE_UCNV_CLONE, 00074 UTRACE_UCNV_CLOSE, 00075 UTRACE_UCNV_FLUSH_CACHE, 00076 UTRACE_UCNV_LOAD, 00077 UTRACE_UCNV_UNLOAD, 00078 UTRACE_CONVERSION_LIMIT, 00079 00080 UTRACE_COLLATION_START=0x2000, 00081 UTRACE_UCOL_OPEN=UTRACE_COLLATION_START, 00082 UTRACE_UCOL_CLOSE, 00083 UTRACE_UCOL_STRCOLL, 00084 UTRACE_UCOL_GET_SORTKEY, 00085 UTRACE_UCOL_GETLOCALE, 00086 UTRACE_UCOL_NEXTSORTKEYPART, 00087 UTRACE_UCOL_STRCOLLITER, 00088 UTRACE_UCOL_OPEN_FROM_SHORT_STRING, 00089 UTRACE_UCOL_STRCOLLUTF8, 00090 UTRACE_COLLATION_LIMIT 00091 } UTraceFunctionNumber; 00092 00098 U_STABLE void U_EXPORT2 00099 utrace_setLevel(int32_t traceLevel); 00100 00106 U_STABLE int32_t U_EXPORT2 00107 utrace_getLevel(void); 00108 00109 /* Trace function pointers types ----------------------------- */ 00110 00117 typedef void U_CALLCONV 00118 UTraceEntry(const void *context, int32_t fnNumber); 00119 00133 typedef void U_CALLCONV 00134 UTraceExit(const void *context, int32_t fnNumber, 00135 const char *fmt, va_list args); 00136 00148 typedef void U_CALLCONV 00149 UTraceData(const void *context, int32_t fnNumber, int32_t level, 00150 const char *fmt, va_list args); 00151 00180 U_STABLE void U_EXPORT2 00181 utrace_setFunctions(const void *context, 00182 UTraceEntry *e, UTraceExit *x, UTraceData *d); 00183 00194 U_STABLE void U_EXPORT2 00195 utrace_getFunctions(const void **context, 00196 UTraceEntry **e, UTraceExit **x, UTraceData **d); 00197 00198 00199 00200 /* 00201 * 00202 * ICU trace format string syntax 00203 * 00204 * Format Strings are passed to UTraceData functions, and define the 00205 * number and types of the trace data being passed on each call. 00206 * 00207 * The UTraceData function, which is supplied by the application, 00208 * not by ICU, can either forward the trace data (passed via 00209 * varargs) and the format string back to ICU for formatting into 00210 * a displayable string, or it can interpret the format itself, 00211 * and do as it wishes with the trace data. 00212 * 00213 * 00214 * Goals for the format string 00215 * - basic data output 00216 * - easy to use for trace programmer 00217 * - sufficient provision for data types for trace output readability 00218 * - well-defined types and binary portable APIs 00219 * 00220 * Non-goals 00221 * - printf compatibility 00222 * - fancy formatting 00223 * - argument reordering and other internationalization features 00224 * 00225 * ICU trace format strings contain plain text with argument inserts, 00226 * much like standard printf format strings. 00227 * Each insert begins with a '%', then optionally contains a 'v', 00228 * then exactly one type character. 00229 * Two '%' in a row represent a '%' instead of an insert. 00230 * The trace format strings need not have \n at the end. 00231 * 00232 * 00233 * Types 00234 * ----- 00235 * 00236 * Type characters: 00237 * - c A char character in the default codepage. 00238 * - s A NUL-terminated char * string in the default codepage. 00239 * - S A UChar * string. Requires two params, (ptr, length). Length=-1 for nul term. 00240 * - b A byte (8-bit integer). 00241 * - h A 16-bit integer. Also a 16 bit Unicode code unit. 00242 * - d A 32-bit integer. Also a 20 bit Unicode code point value. 00243 * - l A 64-bit integer. 00244 * - p A data pointer. 00245 * 00246 * Vectors 00247 * ------- 00248 * 00249 * If the 'v' is not specified, then one item of the specified type 00250 * is passed in. 00251 * If the 'v' (for "vector") is specified, then a vector of items of the 00252 * specified type is passed in, via a pointer to the first item 00253 * and an int32_t value for the length of the vector. 00254 * Length==-1 means zero or NUL termination. Works for vectors of all types. 00255 * 00256 * Note: %vS is a vector of (UChar *) strings. The strings must 00257 * be nul terminated as there is no way to provide a 00258 * separate length parameter for each string. The length 00259 * parameter (required for all vectors) is the number of 00260 * strings, not the length of the strings. 00261 * 00262 * Examples 00263 * -------- 00264 * 00265 * These examples show the parameters that will be passed to an application's 00266 * UTraceData() function for various formats. 00267 * 00268 * - the precise formatting is up to the application! 00269 * - the examples use type casts for arguments only to _show_ the types of 00270 * arguments without needing variable declarations in the examples; 00271 * the type casts will not be necessary in actual code 00272 * 00273 * UTraceDataFunc(context, fnNumber, level, 00274 * "There is a character %c in the string %s.", // Format String 00275 * (char)c, (const char *)s); // varargs parameters 00276 * -> There is a character 0x42 'B' in the string "Bravo". 00277 * 00278 * UTraceDataFunc(context, fnNumber, level, 00279 * "Vector of bytes %vb vector of chars %vc", 00280 * (const uint8_t *)bytes, (int32_t)bytesLength, 00281 * (const char *)chars, (int32_t)charsLength); 00282 * -> Vector of bytes 00283 * 42 63 64 3f [4] 00284 * vector of chars 00285 * "Bcd?"[4] 00286 * 00287 * UTraceDataFunc(context, fnNumber, level, 00288 * "An int32_t %d and a whole bunch of them %vd", 00289 * (int32_t)-5, (const int32_t *)ints, (int32_t)intsLength); 00290 * -> An int32_t 0xfffffffb and a whole bunch of them 00291 * fffffffb 00000005 0000010a [3] 00292 * 00293 */ 00294 00295 00296 00316 U_STABLE int32_t U_EXPORT2 00317 utrace_vformat(char *outBuf, int32_t capacity, 00318 int32_t indent, const char *fmt, va_list args); 00319 00337 U_STABLE int32_t U_EXPORT2 00338 utrace_format(char *outBuf, int32_t capacity, 00339 int32_t indent, const char *fmt, ...); 00340 00341 00342 00343 /* Trace function numbers --------------------------------------------------- */ 00344 00354 U_STABLE const char * U_EXPORT2 00355 utrace_functionName(int32_t fnNumber); 00356 00357 U_CDECL_END 00358 00359 #endif