ICU 73.2  73.2
utrace.h
Go to the documentation of this file.
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 
00070 #ifndef U_HIDE_DEPRECATED_API
00071 
00075     UTRACE_FUNCTION_LIMIT,
00076 #endif  // U_HIDE_DEPRECATED_API
00077 
00078     UTRACE_CONVERSION_START=0x1000,
00079     UTRACE_UCNV_OPEN=UTRACE_CONVERSION_START,
00080     UTRACE_UCNV_OPEN_PACKAGE,
00081     UTRACE_UCNV_OPEN_ALGORITHMIC,
00082     UTRACE_UCNV_CLONE,
00083     UTRACE_UCNV_CLOSE,
00084     UTRACE_UCNV_FLUSH_CACHE,
00085     UTRACE_UCNV_LOAD,
00086     UTRACE_UCNV_UNLOAD,
00087 
00088 #ifndef U_HIDE_DEPRECATED_API
00089 
00093     UTRACE_CONVERSION_LIMIT,
00094 #endif  // U_HIDE_DEPRECATED_API
00095 
00096     UTRACE_COLLATION_START=0x2000,
00097     UTRACE_UCOL_OPEN=UTRACE_COLLATION_START,
00098     UTRACE_UCOL_CLOSE,
00099     UTRACE_UCOL_STRCOLL,
00100     UTRACE_UCOL_GET_SORTKEY,
00101     UTRACE_UCOL_GETLOCALE,
00102     UTRACE_UCOL_NEXTSORTKEYPART,
00103     UTRACE_UCOL_STRCOLLITER,
00104     UTRACE_UCOL_OPEN_FROM_SHORT_STRING,
00105     UTRACE_UCOL_STRCOLLUTF8, 
00107 #ifndef U_HIDE_DEPRECATED_API
00108 
00112     UTRACE_COLLATION_LIMIT,
00113 #endif  // U_HIDE_DEPRECATED_API
00114 
00119     UTRACE_UDATA_START=0x3000,
00120 
00136     UTRACE_UDATA_RESOURCE=UTRACE_UDATA_START,
00137 
00144     UTRACE_UDATA_BUNDLE,
00145 
00153     UTRACE_UDATA_DATA_FILE,
00154 
00166     UTRACE_UDATA_RES_FILE,
00167 
00168 #ifndef U_HIDE_INTERNAL_API
00169 
00173     UTRACE_RES_DATA_LIMIT,
00174 #endif  // U_HIDE_INTERNAL_API
00175 
00180     UTRACE_UBRK_START=0x4000,
00181 
00187     UTRACE_UBRK_CREATE_CHARACTER = UTRACE_UBRK_START,
00188 
00194     UTRACE_UBRK_CREATE_WORD,
00195 
00204     UTRACE_UBRK_CREATE_LINE,
00205 
00211     UTRACE_UBRK_CREATE_SENTENCE,
00212 
00218     UTRACE_UBRK_CREATE_TITLE,
00219 
00228     UTRACE_UBRK_CREATE_BREAK_ENGINE,
00229 
00230 #ifndef U_HIDE_INTERNAL_API
00231 
00235     UTRACE_UBRK_LIMIT,
00236 #endif  // U_HIDE_INTERNAL_API
00237 
00238 } UTraceFunctionNumber;
00239 
00245 U_CAPI void U_EXPORT2
00246 utrace_setLevel(int32_t traceLevel);
00247 
00253 U_CAPI int32_t U_EXPORT2
00254 utrace_getLevel(void);
00255 
00256 /* Trace function pointers types  ----------------------------- */
00257 
00264 typedef void U_CALLCONV
00265 UTraceEntry(const void *context, int32_t fnNumber);
00266 
00280 typedef void U_CALLCONV
00281 UTraceExit(const void *context, int32_t fnNumber, 
00282            const char *fmt, va_list args);
00283 
00295 typedef void U_CALLCONV
00296 UTraceData(const void *context, int32_t fnNumber, int32_t level,
00297            const char *fmt, va_list args);
00298 
00327 U_CAPI void U_EXPORT2
00328 utrace_setFunctions(const void *context,
00329                     UTraceEntry *e, UTraceExit *x, UTraceData *d);
00330 
00341 U_CAPI void U_EXPORT2
00342 utrace_getFunctions(const void **context,
00343                     UTraceEntry **e, UTraceExit **x, UTraceData **d);
00344 
00345 
00346 
00347 /*
00348  *
00349  * ICU trace format string syntax
00350  *
00351  * Format Strings are passed to UTraceData functions, and define the
00352  * number and types of the trace data being passed on each call.
00353  *
00354  * The UTraceData function, which is supplied by the application,
00355  * not by ICU, can either forward the trace data (passed via
00356  * varargs) and the format string back to ICU for formatting into
00357  * a displayable string, or it can interpret the format itself,
00358  * and do as it wishes with the trace data.
00359  *
00360  *
00361  * Goals for the format string
00362  * - basic data output
00363  * - easy to use for trace programmer
00364  * - sufficient provision for data types for trace output readability
00365  * - well-defined types and binary portable APIs
00366  *
00367  * Non-goals
00368  * - printf compatibility
00369  * - fancy formatting
00370  * - argument reordering and other internationalization features
00371  *
00372  * ICU trace format strings contain plain text with argument inserts,
00373  * much like standard printf format strings.
00374  * Each insert begins with a '%', then optionally contains a 'v',
00375  * then exactly one type character.
00376  * Two '%' in a row represent a '%' instead of an insert.
00377  * The trace format strings need not have \n at the end.
00378  *
00379  *
00380  * Types
00381  * -----
00382  *
00383  * Type characters:
00384  * - c A char character in the default codepage.
00385  * - s A NUL-terminated char * string in the default codepage.
00386  * - S A UChar * string.  Requires two params, (ptr, length).  Length=-1 for nul term.
00387  * - b A byte (8-bit integer).
00388  * - h A 16-bit integer.  Also a 16 bit Unicode code unit.
00389  * - d A 32-bit integer.  Also a 20 bit Unicode code point value. 
00390  * - l A 64-bit integer.
00391  * - p A data pointer.
00392  *
00393  * Vectors
00394  * -------
00395  *
00396  * If the 'v' is not specified, then one item of the specified type
00397  * is passed in.
00398  * If the 'v' (for "vector") is specified, then a vector of items of the
00399  * specified type is passed in, via a pointer to the first item
00400  * and an int32_t value for the length of the vector.
00401  * Length==-1 means zero or NUL termination.  Works for vectors of all types.
00402  *
00403  * Note:  %vS is a vector of (UChar *) strings.  The strings must
00404  *        be nul terminated as there is no way to provide a
00405  *        separate length parameter for each string.  The length
00406  *        parameter (required for all vectors) is the number of
00407  *        strings, not the length of the strings.
00408  *
00409  * Examples
00410  * --------
00411  *
00412  * These examples show the parameters that will be passed to an application's
00413  *   UTraceData() function for various formats.
00414  *
00415  * - the precise formatting is up to the application!
00416  * - the examples use type casts for arguments only to _show_ the types of
00417  *   arguments without needing variable declarations in the examples;
00418  *   the type casts will not be necessary in actual code
00419  *
00420  * UTraceDataFunc(context, fnNumber, level,
00421  *              "There is a character %c in the string %s.",   // Format String 
00422  *              (char)c, (const char *)s);                     // varargs parameters
00423  * ->   There is a character 0x42 'B' in the string "Bravo".
00424  *
00425  * UTraceDataFunc(context, fnNumber, level,
00426  *              "Vector of bytes %vb vector of chars %vc",
00427  *              (const uint8_t *)bytes, (int32_t)bytesLength,
00428  *              (const char *)chars, (int32_t)charsLength);
00429  * ->  Vector of bytes
00430  *      42 63 64 3f [4]
00431  *     vector of chars
00432  *      "Bcd?"[4]
00433  *
00434  * UTraceDataFunc(context, fnNumber, level,
00435  *              "An int32_t %d and a whole bunch of them %vd",
00436  *              (int32_t)-5, (const int32_t *)ints, (int32_t)intsLength);
00437  * ->   An int32_t 0xfffffffb and a whole bunch of them
00438  *      fffffffb 00000005 0000010a [3]
00439  *
00440  */
00441 
00442 
00443 
00463 U_CAPI int32_t U_EXPORT2
00464 utrace_vformat(char *outBuf, int32_t capacity,
00465               int32_t indent, const char *fmt,  va_list args);
00466 
00484 U_CAPI int32_t U_EXPORT2
00485 utrace_format(char *outBuf, int32_t capacity,
00486               int32_t indent, const char *fmt,  ...);
00487 
00488 
00489 
00490 /* Trace function numbers --------------------------------------------------- */
00491 
00501 U_CAPI const char * U_EXPORT2
00502 utrace_functionName(int32_t fnNumber);
00503 
00504 U_CDECL_END
00505 
00506 #endif