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