00001 // © 2016 and later: Unicode, Inc. and others. 00002 // License & terms of use: http://www.unicode.org/copyright.html 00003 /* 00004 ******************************************************************************* 00005 * 00006 * Copyright (C) 2003-2013, International Business Machines 00007 * Corporation and others. All Rights Reserved. 00008 * 00009 ******************************************************************************* 00010 * file name: utrace.h 00011 * encoding: UTF-8 00012 * tab size: 8 (not used) 00013 * indentation:4 00014 * 00015 * created on: 2003aug06 00016 * created by: Markus W. Scherer 00017 * 00018 * Definitions for ICU tracing/logging. 00019 * 00020 */ 00021 00022 #ifndef __UTRACE_H__ 00023 #define __UTRACE_H__ 00024 00025 #include <stdarg.h> 00026 #include "unicode/utypes.h" 00027 00039 U_CDECL_BEGIN 00040 00046 typedef enum UTraceLevel { 00048 UTRACE_OFF=-1, 00050 UTRACE_ERROR=0, 00052 UTRACE_WARNING=3, 00054 UTRACE_OPEN_CLOSE=5, 00056 UTRACE_INFO=7, 00058 UTRACE_VERBOSE=9 00059 } UTraceLevel; 00060 00065 typedef enum UTraceFunctionNumber { 00066 UTRACE_FUNCTION_START=0, 00067 UTRACE_U_INIT=UTRACE_FUNCTION_START, 00068 UTRACE_U_CLEANUP, 00069 #ifndef U_HIDE_DEPRECATED_API 00070 00074 UTRACE_FUNCTION_LIMIT, 00075 #endif // U_HIDE_DEPRECATED_API 00076 00077 UTRACE_CONVERSION_START=0x1000, 00078 UTRACE_UCNV_OPEN=UTRACE_CONVERSION_START, 00079 UTRACE_UCNV_OPEN_PACKAGE, 00080 UTRACE_UCNV_OPEN_ALGORITHMIC, 00081 UTRACE_UCNV_CLONE, 00082 UTRACE_UCNV_CLOSE, 00083 UTRACE_UCNV_FLUSH_CACHE, 00084 UTRACE_UCNV_LOAD, 00085 UTRACE_UCNV_UNLOAD, 00086 #ifndef U_HIDE_DEPRECATED_API 00087 00091 UTRACE_CONVERSION_LIMIT, 00092 #endif // U_HIDE_DEPRECATED_API 00093 00094 UTRACE_COLLATION_START=0x2000, 00095 UTRACE_UCOL_OPEN=UTRACE_COLLATION_START, 00096 UTRACE_UCOL_CLOSE, 00097 UTRACE_UCOL_STRCOLL, 00098 UTRACE_UCOL_GET_SORTKEY, 00099 UTRACE_UCOL_GETLOCALE, 00100 UTRACE_UCOL_NEXTSORTKEYPART, 00101 UTRACE_UCOL_STRCOLLITER, 00102 UTRACE_UCOL_OPEN_FROM_SHORT_STRING, 00103 UTRACE_UCOL_STRCOLLUTF8, 00104 #ifndef U_HIDE_DEPRECATED_API 00105 00109 UTRACE_COLLATION_LIMIT 00110 #endif // U_HIDE_DEPRECATED_API 00111 } UTraceFunctionNumber; 00112 00118 U_STABLE void U_EXPORT2 00119 utrace_setLevel(int32_t traceLevel); 00120 00126 U_STABLE int32_t U_EXPORT2 00127 utrace_getLevel(void); 00128 00129 /* Trace function pointers types ----------------------------- */ 00130 00137 typedef void U_CALLCONV 00138 UTraceEntry(const void *context, int32_t fnNumber); 00139 00153 typedef void U_CALLCONV 00154 UTraceExit(const void *context, int32_t fnNumber, 00155 const char *fmt, va_list args); 00156 00168 typedef void U_CALLCONV 00169 UTraceData(const void *context, int32_t fnNumber, int32_t level, 00170 const char *fmt, va_list args); 00171 00200 U_STABLE void U_EXPORT2 00201 utrace_setFunctions(const void *context, 00202 UTraceEntry *e, UTraceExit *x, UTraceData *d); 00203 00214 U_STABLE void U_EXPORT2 00215 utrace_getFunctions(const void **context, 00216 UTraceEntry **e, UTraceExit **x, UTraceData **d); 00217 00218 00219 00220 /* 00221 * 00222 * ICU trace format string syntax 00223 * 00224 * Format Strings are passed to UTraceData functions, and define the 00225 * number and types of the trace data being passed on each call. 00226 * 00227 * The UTraceData function, which is supplied by the application, 00228 * not by ICU, can either forward the trace data (passed via 00229 * varargs) and the format string back to ICU for formatting into 00230 * a displayable string, or it can interpret the format itself, 00231 * and do as it wishes with the trace data. 00232 * 00233 * 00234 * Goals for the format string 00235 * - basic data output 00236 * - easy to use for trace programmer 00237 * - sufficient provision for data types for trace output readability 00238 * - well-defined types and binary portable APIs 00239 * 00240 * Non-goals 00241 * - printf compatibility 00242 * - fancy formatting 00243 * - argument reordering and other internationalization features 00244 * 00245 * ICU trace format strings contain plain text with argument inserts, 00246 * much like standard printf format strings. 00247 * Each insert begins with a '%', then optionally contains a 'v', 00248 * then exactly one type character. 00249 * Two '%' in a row represent a '%' instead of an insert. 00250 * The trace format strings need not have \n at the end. 00251 * 00252 * 00253 * Types 00254 * ----- 00255 * 00256 * Type characters: 00257 * - c A char character in the default codepage. 00258 * - s A NUL-terminated char * string in the default codepage. 00259 * - S A UChar * string. Requires two params, (ptr, length). Length=-1 for nul term. 00260 * - b A byte (8-bit integer). 00261 * - h A 16-bit integer. Also a 16 bit Unicode code unit. 00262 * - d A 32-bit integer. Also a 20 bit Unicode code point value. 00263 * - l A 64-bit integer. 00264 * - p A data pointer. 00265 * 00266 * Vectors 00267 * ------- 00268 * 00269 * If the 'v' is not specified, then one item of the specified type 00270 * is passed in. 00271 * If the 'v' (for "vector") is specified, then a vector of items of the 00272 * specified type is passed in, via a pointer to the first item 00273 * and an int32_t value for the length of the vector. 00274 * Length==-1 means zero or NUL termination. Works for vectors of all types. 00275 * 00276 * Note: %vS is a vector of (UChar *) strings. The strings must 00277 * be nul terminated as there is no way to provide a 00278 * separate length parameter for each string. The length 00279 * parameter (required for all vectors) is the number of 00280 * strings, not the length of the strings. 00281 * 00282 * Examples 00283 * -------- 00284 * 00285 * These examples show the parameters that will be passed to an application's 00286 * UTraceData() function for various formats. 00287 * 00288 * - the precise formatting is up to the application! 00289 * - the examples use type casts for arguments only to _show_ the types of 00290 * arguments without needing variable declarations in the examples; 00291 * the type casts will not be necessary in actual code 00292 * 00293 * UTraceDataFunc(context, fnNumber, level, 00294 * "There is a character %c in the string %s.", // Format String 00295 * (char)c, (const char *)s); // varargs parameters 00296 * -> There is a character 0x42 'B' in the string "Bravo". 00297 * 00298 * UTraceDataFunc(context, fnNumber, level, 00299 * "Vector of bytes %vb vector of chars %vc", 00300 * (const uint8_t *)bytes, (int32_t)bytesLength, 00301 * (const char *)chars, (int32_t)charsLength); 00302 * -> Vector of bytes 00303 * 42 63 64 3f [4] 00304 * vector of chars 00305 * "Bcd?"[4] 00306 * 00307 * UTraceDataFunc(context, fnNumber, level, 00308 * "An int32_t %d and a whole bunch of them %vd", 00309 * (int32_t)-5, (const int32_t *)ints, (int32_t)intsLength); 00310 * -> An int32_t 0xfffffffb and a whole bunch of them 00311 * fffffffb 00000005 0000010a [3] 00312 * 00313 */ 00314 00315 00316 00336 U_STABLE int32_t U_EXPORT2 00337 utrace_vformat(char *outBuf, int32_t capacity, 00338 int32_t indent, const char *fmt, va_list args); 00339 00357 U_STABLE int32_t U_EXPORT2 00358 utrace_format(char *outBuf, int32_t capacity, 00359 int32_t indent, const char *fmt, ...); 00360 00361 00362 00363 /* Trace function numbers --------------------------------------------------- */ 00364 00374 U_STABLE const char * U_EXPORT2 00375 utrace_functionName(int32_t fnNumber); 00376 00377 U_CDECL_END 00378 00379 #endif
1.6.1