utrace.h

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

Generated on Mon Aug 13 07:17:25 2007 for ICU 3.6 by  doxygen 1.5.2