os/textandloc/fontservices/textshaperplugin/IcuSource/common/unicode/utrace.h
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /*
     2 *******************************************************************************
     3 *
     4 *   Copyright (C) 2003-2005, International Business Machines
     5 *   Corporation and others.  All Rights Reserved.
     6 *
     7 *******************************************************************************
     8 *   file name:  utrace.h
     9 *   encoding:   US-ASCII
    10 *   tab size:   8 (not used)
    11 *   indentation:4
    12 *
    13 *   created on: 2003aug06
    14 *   created by: Markus W. Scherer
    15 *
    16 *   Definitions for ICU tracing/logging.
    17 *
    18 */
    19 
    20 #ifndef __UTRACE_H__
    21 #define __UTRACE_H__
    22 
    23 #include <stdarg.h>
    24 #include "unicode/utypes.h"
    25 
    26 /**
    27  * \file
    28  * \brief C API:  Definitions for ICU tracing/logging. 
    29  */
    30  
    31 U_CDECL_BEGIN
    32 
    33 #ifndef U_HIDE_DRAFT_API
    34 
    35 /**
    36  * Trace severity levels.  Higher levels increase the verbosity of the trace output.
    37  * @see utrace_setLevel
    38  * @stable ICU 2.8
    39  */
    40 typedef enum UTraceLevel {
    41     /** Disable all tracing  @stable ICU 2.8*/
    42     UTRACE_OFF=-1,
    43     /** Trace error conditions only  @stable ICU 2.8*/
    44     UTRACE_ERROR=0,
    45     /** Trace errors and warnings  @stable ICU 2.8*/
    46     UTRACE_WARNING=3,
    47     /** Trace opens and closes of ICU services  @stable ICU 2.8*/
    48     UTRACE_OPEN_CLOSE=5,
    49     /** Trace an intermediate number of ICU operations  @stable ICU 2.8*/
    50     UTRACE_INFO=7,
    51     /** Trace the maximum number of ICU operations  @stable ICU 2.8*/
    52     UTRACE_VERBOSE=9
    53 } UTraceLevel;
    54 
    55 /**
    56  *  These are the ICU functions that will be traced when tracing is enabled.
    57  *  @stable ICU 2.8
    58  */
    59 typedef enum UTraceFunctionNumber {
    60     UTRACE_FUNCTION_START=0,
    61     UTRACE_U_INIT=UTRACE_FUNCTION_START,
    62     UTRACE_U_CLEANUP,
    63     UTRACE_FUNCTION_LIMIT,
    64 
    65     UTRACE_CONVERSION_START=0x1000,
    66     UTRACE_UCNV_OPEN=UTRACE_CONVERSION_START,
    67     UTRACE_UCNV_OPEN_PACKAGE,
    68     UTRACE_UCNV_OPEN_ALGORITHMIC,
    69     UTRACE_UCNV_CLONE,
    70     UTRACE_UCNV_CLOSE,
    71     UTRACE_UCNV_FLUSH_CACHE,
    72     UTRACE_UCNV_LOAD,
    73     UTRACE_UCNV_UNLOAD,
    74     UTRACE_CONVERSION_LIMIT,
    75 
    76     UTRACE_COLLATION_START=0x2000,
    77     UTRACE_UCOL_OPEN=UTRACE_COLLATION_START,
    78     UTRACE_UCOL_CLOSE,
    79     UTRACE_UCOL_STRCOLL,
    80     UTRACE_UCOL_GET_SORTKEY,
    81     UTRACE_UCOL_GETLOCALE,
    82     UTRACE_UCOL_NEXTSORTKEYPART,
    83     UTRACE_UCOL_STRCOLLITER,
    84     UTRACE_UCOL_OPEN_FROM_SHORT_STRING,
    85     UTRACE_COLLATION_LIMIT
    86 } UTraceFunctionNumber;
    87 
    88 #endif /*U_HIDE_DRAFT_API*/
    89 
    90 /**
    91  * Setter for the trace level.
    92  * @param traceLevel A UTraceLevel value.
    93  * @stable ICU 2.8
    94  */
    95 U_STABLE void U_EXPORT2
    96 utrace_setLevel(int32_t traceLevel);
    97 
    98 /**
    99  * Getter for the trace level.
   100  * @return The UTraceLevel value being used by ICU.
   101  * @stable ICU 2.8
   102  */
   103 U_STABLE int32_t U_EXPORT2
   104 utrace_getLevel(void);
   105 
   106 /* Trace function pointers types  ----------------------------- */
   107 
   108 /**
   109   *  Type signature for the trace function to be called when entering a function.
   110   *  @param context value supplied at the time the trace functions are set.
   111   *  @param fnNumber Enum value indicating the ICU function being entered.
   112   *  @stable ICU 2.8
   113   */
   114 typedef void U_CALLCONV
   115 UTraceEntry(const void *context, int32_t fnNumber);
   116 
   117 /**
   118   *  Type signature for the trace function to be called when exiting from a function.
   119   *  @param context value supplied at the time the trace functions are set.
   120   *  @param fnNumber Enum value indicating the ICU function being exited.
   121   *  @param fmt     A formatting string that describes the number and types
   122   *                 of arguments included with the variable args.  The fmt
   123   *                 string has the same form as the utrace_vformat format
   124   *                 string.
   125   *  @param args    A variable arguments list.  Contents are described by
   126   *                 the fmt parameter.
   127   *  @see   utrace_vformat
   128   *  @stable ICU 2.8
   129   */
   130 typedef void U_CALLCONV
   131 UTraceExit(const void *context, int32_t fnNumber, 
   132            const char *fmt, va_list args);
   133 
   134 /**
   135   *  Type signature for the trace function to be called from within an ICU function
   136   *  to display data or messages.
   137   *  @param context  value supplied at the time the trace functions are set.
   138   *  @param fnNumber Enum value indicating the ICU function being exited.
   139   *  @param level    The current tracing level
   140   *  @param fmt      A format string describing the tracing data that is supplied
   141   *                  as variable args
   142   *  @param args     The data being traced, passed as variable args.
   143   *  @stable ICU 2.8
   144   */
   145 typedef void U_CALLCONV
   146 UTraceData(const void *context, int32_t fnNumber, int32_t level,
   147            const char *fmt, va_list args);
   148 
   149 /**
   150   *  Set ICU Tracing functions.  Installs application-provided tracing
   151   *  functions into ICU.  After doing this, subsequent ICU operations
   152   *  will call back to the installed functions, providing a trace
   153   *  of the use of ICU.  Passing a NULL pointer for a tracing function
   154   *  is allowed, and inhibits tracing action at points where that function
   155   *  would be called.
   156   *  <p>
   157   *  Tracing and Threads:  Tracing functions are global to a process, and
   158   *  will be called in response to ICU operations performed by any
   159   *  thread.  If tracing of an individual thread is desired, the
   160   *  tracing functions must themselves filter by checking that the
   161   *  current thread is the desired thread.
   162   *
   163   *  @param context an uninterpretted pointer.  Whatever is passed in
   164   *                 here will in turn be passed to each of the tracing
   165   *                 functions UTraceEntry, UTraceExit and UTraceData.
   166   *                 ICU does not use or alter this pointer.
   167   *  @param e       Callback function to be called on entry to a 
   168   *                 a traced ICU function.
   169   *  @param x       Callback function to be called on exit from a
   170   *                 traced ICU function.
   171   *  @param d       Callback function to be called from within a 
   172   *                 traced ICU function, for the purpose of providing
   173   *                 data to the trace.
   174   *
   175   *  @stable ICU 2.8
   176   */
   177 U_STABLE void U_EXPORT2
   178 utrace_setFunctions(const void *context,
   179                     UTraceEntry *e, UTraceExit *x, UTraceData *d);
   180 
   181 /**
   182   * Get the currently installed ICU tracing functions.   Note that a null function
   183   *   pointer will be returned if no trace function has been set.
   184   *
   185   * @param context  The currently installed tracing context.
   186   * @param e        The currently installed UTraceEntry function.
   187   * @param x        The currently installed UTraceExit function.
   188   * @param d        The currently installed UTraceData function.
   189   * @stable ICU 2.8
   190   */
   191 U_STABLE void U_EXPORT2
   192 utrace_getFunctions(const void **context,
   193                     UTraceEntry **e, UTraceExit **x, UTraceData **d);
   194 
   195 
   196 
   197 /*
   198  *
   199  * ICU trace format string syntax
   200  *
   201  * Format Strings are passed to UTraceData functions, and define the
   202  * number and types of the trace data being passed on each call.
   203  *
   204  * The UTraceData function, which is supplied by the application,
   205  * not by ICU, can either forward the trace data (passed via
   206  * varargs) and the format string back to ICU for formatting into
   207  * a displayable string, or it can interpret the format itself,
   208  * and do as it wishes with the trace data.
   209  *
   210  *
   211  * Goals for the format string
   212  * - basic data output
   213  * - easy to use for trace programmer
   214  * - sufficient provision for data types for trace output readability
   215  * - well-defined types and binary portable APIs
   216  *
   217  * Non-goals
   218  * - printf compatibility
   219  * - fancy formatting
   220  * - argument reordering and other internationalization features
   221  *
   222  * ICU trace format strings contain plain text with argument inserts,
   223  * much like standard printf format strings.
   224  * Each insert begins with a '%', then optionally contains a 'v',
   225  * then exactly one type character.
   226  * Two '%' in a row represent a '%' instead of an insert.
   227  * The trace format strings need not have \n at the end.
   228  *
   229  *
   230  * Types
   231  * -----
   232  *
   233  * Type characters:
   234  * - c A char character in the default codepage.
   235  * - s A NUL-terminated char * string in the default codepage.
   236  * - S A UChar * string.  Requires two params, (ptr, length).  Length=-1 for nul term.
   237  * - b A byte (8-bit integer).
   238  * - h A 16-bit integer.  Also a 16 bit Unicode code unit.
   239  * - d A 32-bit integer.  Also a 20 bit Unicode code point value. 
   240  * - l A 64-bit integer.
   241  * - p A data pointer.
   242  *
   243  * Vectors
   244  * -------
   245  *
   246  * If the 'v' is not specified, then one item of the specified type
   247  * is passed in.
   248  * If the 'v' (for "vector") is specified, then a vector of items of the
   249  * specified type is passed in, via a pointer to the first item
   250  * and an int32_t value for the length of the vector.
   251  * Length==-1 means zero or NUL termination.  Works for vectors of all types.
   252  *
   253  * Note:  %vS is a vector of (UChar *) strings.  The strings must
   254  *        be nul terminated as there is no way to provide a
   255  *        separate length parameter for each string.  The length
   256  *        parameter (required for all vectors) is the number of
   257  *        strings, not the length of the strings.
   258  *
   259  * Examples
   260  * --------
   261  *
   262  * These examples show the parameters that will be passed to an application's
   263  *   UTraceData() function for various formats.
   264  *
   265  * - the precise formatting is up to the application!
   266  * - the examples use type casts for arguments only to _show_ the types of
   267  *   arguments without needing variable declarations in the examples;
   268  *   the type casts will not be necessary in actual code
   269  *
   270  * UTraceDataFunc(context, fnNumber, level,
   271  *              "There is a character %c in the string %s.",   // Format String 
   272  *              (char)c, (const char *)s);                     // varargs parameters
   273  * ->   There is a character 0x42 'B' in the string "Bravo".
   274  *
   275  * UTraceDataFunc(context, fnNumber, level,
   276  *              "Vector of bytes %vb vector of chars %vc",
   277  *              (const uint8_t *)bytes, (int32_t)bytesLength,
   278  *              (const char *)chars, (int32_t)charsLength);
   279  * ->  Vector of bytes
   280  *      42 63 64 3f [4]
   281  *     vector of chars
   282  *      "Bcd?"[4]
   283  *
   284  * UTraceDataFunc(context, fnNumber, level,
   285  *              "An int32_t %d and a whole bunch of them %vd",
   286  *              (int32_t)-5, (const int32_t *)ints, (int32_t)intsLength);
   287  * ->   An int32_t 0xfffffffb and a whole bunch of them
   288  *      fffffffb 00000005 0000010a [3]
   289  *
   290  */
   291 
   292 
   293 
   294 /**
   295   *  Trace output Formatter.  An application's UTraceData tracing functions may call
   296   *                 back to this function to format the trace output in a
   297   *                 human readable form.  Note that a UTraceData function may choose
   298   *                 to not format the data;  it could, for example, save it in
   299   *                 in the raw form it was received (more compact), leaving
   300   *                 formatting for a later trace analyis tool.
   301   *  @param outBuf  pointer to a buffer to receive the formatted output.  Output
   302   *                 will be nul terminated if there is space in the buffer -
   303   *                 if the length of the requested output < the output buffer size.
   304   *  @param capacity  Length of the output buffer.
   305   *  @param indent  Number of spaces to indent the output.  Intended to allow
   306   *                 data displayed from nested functions to be indented for readability.
   307   *  @param fmt     Format specification for the data to output
   308   *  @param args    Data to be formatted.
   309   *  @return        Length of formatted output, including the terminating NUL.
   310   *                 If buffer capacity is insufficient, the required capacity is returned. 
   311   *  @stable ICU 2.8
   312   */
   313 U_STABLE int32_t U_EXPORT2
   314 utrace_vformat(char *outBuf, int32_t capacity,
   315               int32_t indent, const char *fmt,  va_list args);
   316 
   317 /**
   318   *  Trace output Formatter.  An application's UTraceData tracing functions may call
   319   *                 this function to format any additional trace data, beyond that
   320   *                 provided by default, in human readable form with the same
   321   *                 formatting conventions used by utrace_vformat().
   322   *  @param outBuf  pointer to a buffer to receive the formatted output.  Output
   323   *                 will be nul terminated if there is space in the buffer -
   324   *                 if the length of the requested output < the output buffer size.
   325   *  @param capacity  Length of the output buffer.
   326   *  @param indent  Number of spaces to indent the output.  Intended to allow
   327   *                 data displayed from nested functions to be indented for readability.
   328   *  @param fmt     Format specification for the data to output
   329   *  @param ...     Data to be formatted.
   330   *  @return        Length of formatted output, including the terminating NUL.
   331   *                 If buffer capacity is insufficient, the required capacity is returned. 
   332   *  @stable ICU 2.8
   333   */
   334 U_STABLE int32_t U_EXPORT2
   335 utrace_format(char *outBuf, int32_t capacity,
   336               int32_t indent, const char *fmt,  ...);
   337 
   338 
   339 
   340 /* Trace function numbers --------------------------------------------------- */
   341 
   342 /**
   343  * Get the name of a function from its trace function number.
   344  *
   345  * @param fnNumber The trace number for an ICU function.
   346  * @return The name string for the function.
   347  *
   348  * @see UTraceFunctionNumber
   349  * @stable ICU 2.8
   350  */
   351 U_STABLE const char * U_EXPORT2
   352 utrace_functionName(int32_t fnNumber);
   353 
   354 U_CDECL_END
   355 
   356 #endif