sl@0: /* sl@0: ******************************************************************************* sl@0: * sl@0: * Copyright (C) 2003-2005, International Business Machines sl@0: * Corporation and others. All Rights Reserved. sl@0: * sl@0: ******************************************************************************* sl@0: * file name: utrace.h sl@0: * encoding: US-ASCII sl@0: * tab size: 8 (not used) sl@0: * indentation:4 sl@0: * sl@0: * created on: 2003aug06 sl@0: * created by: Markus W. Scherer sl@0: * sl@0: * Definitions for ICU tracing/logging. sl@0: * sl@0: */ sl@0: sl@0: #ifndef __UTRACE_H__ sl@0: #define __UTRACE_H__ sl@0: sl@0: #include sl@0: #include "unicode/utypes.h" sl@0: sl@0: /** sl@0: * \file sl@0: * \brief C API: Definitions for ICU tracing/logging. sl@0: */ sl@0: sl@0: U_CDECL_BEGIN sl@0: sl@0: #ifndef U_HIDE_DRAFT_API sl@0: sl@0: /** sl@0: * Trace severity levels. Higher levels increase the verbosity of the trace output. sl@0: * @see utrace_setLevel sl@0: * @stable ICU 2.8 sl@0: */ sl@0: typedef enum UTraceLevel { sl@0: /** Disable all tracing @stable ICU 2.8*/ sl@0: UTRACE_OFF=-1, sl@0: /** Trace error conditions only @stable ICU 2.8*/ sl@0: UTRACE_ERROR=0, sl@0: /** Trace errors and warnings @stable ICU 2.8*/ sl@0: UTRACE_WARNING=3, sl@0: /** Trace opens and closes of ICU services @stable ICU 2.8*/ sl@0: UTRACE_OPEN_CLOSE=5, sl@0: /** Trace an intermediate number of ICU operations @stable ICU 2.8*/ sl@0: UTRACE_INFO=7, sl@0: /** Trace the maximum number of ICU operations @stable ICU 2.8*/ sl@0: UTRACE_VERBOSE=9 sl@0: } UTraceLevel; sl@0: sl@0: /** sl@0: * These are the ICU functions that will be traced when tracing is enabled. sl@0: * @stable ICU 2.8 sl@0: */ sl@0: typedef enum UTraceFunctionNumber { sl@0: UTRACE_FUNCTION_START=0, sl@0: UTRACE_U_INIT=UTRACE_FUNCTION_START, sl@0: UTRACE_U_CLEANUP, sl@0: UTRACE_FUNCTION_LIMIT, sl@0: sl@0: UTRACE_CONVERSION_START=0x1000, sl@0: UTRACE_UCNV_OPEN=UTRACE_CONVERSION_START, sl@0: UTRACE_UCNV_OPEN_PACKAGE, sl@0: UTRACE_UCNV_OPEN_ALGORITHMIC, sl@0: UTRACE_UCNV_CLONE, sl@0: UTRACE_UCNV_CLOSE, sl@0: UTRACE_UCNV_FLUSH_CACHE, sl@0: UTRACE_UCNV_LOAD, sl@0: UTRACE_UCNV_UNLOAD, sl@0: UTRACE_CONVERSION_LIMIT, sl@0: sl@0: UTRACE_COLLATION_START=0x2000, sl@0: UTRACE_UCOL_OPEN=UTRACE_COLLATION_START, sl@0: UTRACE_UCOL_CLOSE, sl@0: UTRACE_UCOL_STRCOLL, sl@0: UTRACE_UCOL_GET_SORTKEY, sl@0: UTRACE_UCOL_GETLOCALE, sl@0: UTRACE_UCOL_NEXTSORTKEYPART, sl@0: UTRACE_UCOL_STRCOLLITER, sl@0: UTRACE_UCOL_OPEN_FROM_SHORT_STRING, sl@0: UTRACE_COLLATION_LIMIT sl@0: } UTraceFunctionNumber; sl@0: sl@0: #endif /*U_HIDE_DRAFT_API*/ sl@0: sl@0: /** sl@0: * Setter for the trace level. sl@0: * @param traceLevel A UTraceLevel value. sl@0: * @stable ICU 2.8 sl@0: */ sl@0: U_STABLE void U_EXPORT2 sl@0: utrace_setLevel(int32_t traceLevel); sl@0: sl@0: /** sl@0: * Getter for the trace level. sl@0: * @return The UTraceLevel value being used by ICU. sl@0: * @stable ICU 2.8 sl@0: */ sl@0: U_STABLE int32_t U_EXPORT2 sl@0: utrace_getLevel(void); sl@0: sl@0: /* Trace function pointers types ----------------------------- */ sl@0: sl@0: /** sl@0: * Type signature for the trace function to be called when entering a function. sl@0: * @param context value supplied at the time the trace functions are set. sl@0: * @param fnNumber Enum value indicating the ICU function being entered. sl@0: * @stable ICU 2.8 sl@0: */ sl@0: typedef void U_CALLCONV sl@0: UTraceEntry(const void *context, int32_t fnNumber); sl@0: sl@0: /** sl@0: * Type signature for the trace function to be called when exiting from a function. sl@0: * @param context value supplied at the time the trace functions are set. sl@0: * @param fnNumber Enum value indicating the ICU function being exited. sl@0: * @param fmt A formatting string that describes the number and types sl@0: * of arguments included with the variable args. The fmt sl@0: * string has the same form as the utrace_vformat format sl@0: * string. sl@0: * @param args A variable arguments list. Contents are described by sl@0: * the fmt parameter. sl@0: * @see utrace_vformat sl@0: * @stable ICU 2.8 sl@0: */ sl@0: typedef void U_CALLCONV sl@0: UTraceExit(const void *context, int32_t fnNumber, sl@0: const char *fmt, va_list args); sl@0: sl@0: /** sl@0: * Type signature for the trace function to be called from within an ICU function sl@0: * to display data or messages. sl@0: * @param context value supplied at the time the trace functions are set. sl@0: * @param fnNumber Enum value indicating the ICU function being exited. sl@0: * @param level The current tracing level sl@0: * @param fmt A format string describing the tracing data that is supplied sl@0: * as variable args sl@0: * @param args The data being traced, passed as variable args. sl@0: * @stable ICU 2.8 sl@0: */ sl@0: typedef void U_CALLCONV sl@0: UTraceData(const void *context, int32_t fnNumber, int32_t level, sl@0: const char *fmt, va_list args); sl@0: sl@0: /** sl@0: * Set ICU Tracing functions. Installs application-provided tracing sl@0: * functions into ICU. After doing this, subsequent ICU operations sl@0: * will call back to the installed functions, providing a trace sl@0: * of the use of ICU. Passing a NULL pointer for a tracing function sl@0: * is allowed, and inhibits tracing action at points where that function sl@0: * would be called. sl@0: *

sl@0: * Tracing and Threads: Tracing functions are global to a process, and sl@0: * will be called in response to ICU operations performed by any sl@0: * thread. If tracing of an individual thread is desired, the sl@0: * tracing functions must themselves filter by checking that the sl@0: * current thread is the desired thread. sl@0: * sl@0: * @param context an uninterpretted pointer. Whatever is passed in sl@0: * here will in turn be passed to each of the tracing sl@0: * functions UTraceEntry, UTraceExit and UTraceData. sl@0: * ICU does not use or alter this pointer. sl@0: * @param e Callback function to be called on entry to a sl@0: * a traced ICU function. sl@0: * @param x Callback function to be called on exit from a sl@0: * traced ICU function. sl@0: * @param d Callback function to be called from within a sl@0: * traced ICU function, for the purpose of providing sl@0: * data to the trace. sl@0: * sl@0: * @stable ICU 2.8 sl@0: */ sl@0: U_STABLE void U_EXPORT2 sl@0: utrace_setFunctions(const void *context, sl@0: UTraceEntry *e, UTraceExit *x, UTraceData *d); sl@0: sl@0: /** sl@0: * Get the currently installed ICU tracing functions. Note that a null function sl@0: * pointer will be returned if no trace function has been set. sl@0: * sl@0: * @param context The currently installed tracing context. sl@0: * @param e The currently installed UTraceEntry function. sl@0: * @param x The currently installed UTraceExit function. sl@0: * @param d The currently installed UTraceData function. sl@0: * @stable ICU 2.8 sl@0: */ sl@0: U_STABLE void U_EXPORT2 sl@0: utrace_getFunctions(const void **context, sl@0: UTraceEntry **e, UTraceExit **x, UTraceData **d); sl@0: sl@0: sl@0: sl@0: /* sl@0: * sl@0: * ICU trace format string syntax sl@0: * sl@0: * Format Strings are passed to UTraceData functions, and define the sl@0: * number and types of the trace data being passed on each call. sl@0: * sl@0: * The UTraceData function, which is supplied by the application, sl@0: * not by ICU, can either forward the trace data (passed via sl@0: * varargs) and the format string back to ICU for formatting into sl@0: * a displayable string, or it can interpret the format itself, sl@0: * and do as it wishes with the trace data. sl@0: * sl@0: * sl@0: * Goals for the format string sl@0: * - basic data output sl@0: * - easy to use for trace programmer sl@0: * - sufficient provision for data types for trace output readability sl@0: * - well-defined types and binary portable APIs sl@0: * sl@0: * Non-goals sl@0: * - printf compatibility sl@0: * - fancy formatting sl@0: * - argument reordering and other internationalization features sl@0: * sl@0: * ICU trace format strings contain plain text with argument inserts, sl@0: * much like standard printf format strings. sl@0: * Each insert begins with a '%', then optionally contains a 'v', sl@0: * then exactly one type character. sl@0: * Two '%' in a row represent a '%' instead of an insert. sl@0: * The trace format strings need not have \n at the end. sl@0: * sl@0: * sl@0: * Types sl@0: * ----- sl@0: * sl@0: * Type characters: sl@0: * - c A char character in the default codepage. sl@0: * - s A NUL-terminated char * string in the default codepage. sl@0: * - S A UChar * string. Requires two params, (ptr, length). Length=-1 for nul term. sl@0: * - b A byte (8-bit integer). sl@0: * - h A 16-bit integer. Also a 16 bit Unicode code unit. sl@0: * - d A 32-bit integer. Also a 20 bit Unicode code point value. sl@0: * - l A 64-bit integer. sl@0: * - p A data pointer. sl@0: * sl@0: * Vectors sl@0: * ------- sl@0: * sl@0: * If the 'v' is not specified, then one item of the specified type sl@0: * is passed in. sl@0: * If the 'v' (for "vector") is specified, then a vector of items of the sl@0: * specified type is passed in, via a pointer to the first item sl@0: * and an int32_t value for the length of the vector. sl@0: * Length==-1 means zero or NUL termination. Works for vectors of all types. sl@0: * sl@0: * Note: %vS is a vector of (UChar *) strings. The strings must sl@0: * be nul terminated as there is no way to provide a sl@0: * separate length parameter for each string. The length sl@0: * parameter (required for all vectors) is the number of sl@0: * strings, not the length of the strings. sl@0: * sl@0: * Examples sl@0: * -------- sl@0: * sl@0: * These examples show the parameters that will be passed to an application's sl@0: * UTraceData() function for various formats. sl@0: * sl@0: * - the precise formatting is up to the application! sl@0: * - the examples use type casts for arguments only to _show_ the types of sl@0: * arguments without needing variable declarations in the examples; sl@0: * the type casts will not be necessary in actual code sl@0: * sl@0: * UTraceDataFunc(context, fnNumber, level, sl@0: * "There is a character %c in the string %s.", // Format String sl@0: * (char)c, (const char *)s); // varargs parameters sl@0: * -> There is a character 0x42 'B' in the string "Bravo". sl@0: * sl@0: * UTraceDataFunc(context, fnNumber, level, sl@0: * "Vector of bytes %vb vector of chars %vc", sl@0: * (const uint8_t *)bytes, (int32_t)bytesLength, sl@0: * (const char *)chars, (int32_t)charsLength); sl@0: * -> Vector of bytes sl@0: * 42 63 64 3f [4] sl@0: * vector of chars sl@0: * "Bcd?"[4] sl@0: * sl@0: * UTraceDataFunc(context, fnNumber, level, sl@0: * "An int32_t %d and a whole bunch of them %vd", sl@0: * (int32_t)-5, (const int32_t *)ints, (int32_t)intsLength); sl@0: * -> An int32_t 0xfffffffb and a whole bunch of them sl@0: * fffffffb 00000005 0000010a [3] sl@0: * sl@0: */ sl@0: sl@0: sl@0: sl@0: /** sl@0: * Trace output Formatter. An application's UTraceData tracing functions may call sl@0: * back to this function to format the trace output in a sl@0: * human readable form. Note that a UTraceData function may choose sl@0: * to not format the data; it could, for example, save it in sl@0: * in the raw form it was received (more compact), leaving sl@0: * formatting for a later trace analyis tool. sl@0: * @param outBuf pointer to a buffer to receive the formatted output. Output sl@0: * will be nul terminated if there is space in the buffer - sl@0: * if the length of the requested output < the output buffer size. sl@0: * @param capacity Length of the output buffer. sl@0: * @param indent Number of spaces to indent the output. Intended to allow sl@0: * data displayed from nested functions to be indented for readability. sl@0: * @param fmt Format specification for the data to output sl@0: * @param args Data to be formatted. sl@0: * @return Length of formatted output, including the terminating NUL. sl@0: * If buffer capacity is insufficient, the required capacity is returned. sl@0: * @stable ICU 2.8 sl@0: */ sl@0: U_STABLE int32_t U_EXPORT2 sl@0: utrace_vformat(char *outBuf, int32_t capacity, sl@0: int32_t indent, const char *fmt, va_list args); sl@0: sl@0: /** sl@0: * Trace output Formatter. An application's UTraceData tracing functions may call sl@0: * this function to format any additional trace data, beyond that sl@0: * provided by default, in human readable form with the same sl@0: * formatting conventions used by utrace_vformat(). sl@0: * @param outBuf pointer to a buffer to receive the formatted output. Output sl@0: * will be nul terminated if there is space in the buffer - sl@0: * if the length of the requested output < the output buffer size. sl@0: * @param capacity Length of the output buffer. sl@0: * @param indent Number of spaces to indent the output. Intended to allow sl@0: * data displayed from nested functions to be indented for readability. sl@0: * @param fmt Format specification for the data to output sl@0: * @param ... Data to be formatted. sl@0: * @return Length of formatted output, including the terminating NUL. sl@0: * If buffer capacity is insufficient, the required capacity is returned. sl@0: * @stable ICU 2.8 sl@0: */ sl@0: U_STABLE int32_t U_EXPORT2 sl@0: utrace_format(char *outBuf, int32_t capacity, sl@0: int32_t indent, const char *fmt, ...); sl@0: sl@0: sl@0: sl@0: /* Trace function numbers --------------------------------------------------- */ sl@0: sl@0: /** sl@0: * Get the name of a function from its trace function number. sl@0: * sl@0: * @param fnNumber The trace number for an ICU function. sl@0: * @return The name string for the function. sl@0: * sl@0: * @see UTraceFunctionNumber sl@0: * @stable ICU 2.8 sl@0: */ sl@0: U_STABLE const char * U_EXPORT2 sl@0: utrace_functionName(int32_t fnNumber); sl@0: sl@0: U_CDECL_END sl@0: sl@0: #endif