ICU 66.1 66.1
utrace.h
Go to the documentation of this file.
1// © 2016 and later: Unicode, Inc. and others.
2// License & terms of use: http://www.unicode.org/copyright.html
3/*
4*******************************************************************************
5*
6* Copyright (C) 2003-2013, International Business Machines
7* Corporation and others. All Rights Reserved.
8*
9*******************************************************************************
10* file name: utrace.h
11* encoding: UTF-8
12* tab size: 8 (not used)
13* indentation:4
14*
15* created on: 2003aug06
16* created by: Markus W. Scherer
17*
18* Definitions for ICU tracing/logging.
19*
20*/
21
22#ifndef __UTRACE_H__
23#define __UTRACE_H__
24
25#include <stdarg.h>
26#include "unicode/utypes.h"
27
40
46typedef enum UTraceLevel {
60
66 UTRACE_FUNCTION_START=0,
67 UTRACE_U_INIT=UTRACE_FUNCTION_START,
68 UTRACE_U_CLEANUP,
69
70#ifndef U_HIDE_DEPRECATED_API
76#endif // U_HIDE_DEPRECATED_API
77
78 UTRACE_CONVERSION_START=0x1000,
79 UTRACE_UCNV_OPEN=UTRACE_CONVERSION_START,
80 UTRACE_UCNV_OPEN_PACKAGE,
81 UTRACE_UCNV_OPEN_ALGORITHMIC,
82 UTRACE_UCNV_CLONE,
83 UTRACE_UCNV_CLOSE,
84 UTRACE_UCNV_FLUSH_CACHE,
85 UTRACE_UCNV_LOAD,
86 UTRACE_UCNV_UNLOAD,
87
88#ifndef U_HIDE_DEPRECATED_API
94#endif // U_HIDE_DEPRECATED_API
95
96 UTRACE_COLLATION_START=0x2000,
97 UTRACE_UCOL_OPEN=UTRACE_COLLATION_START,
98 UTRACE_UCOL_CLOSE,
99 UTRACE_UCOL_STRCOLL,
100 UTRACE_UCOL_GET_SORTKEY,
101 UTRACE_UCOL_GETLOCALE,
102 UTRACE_UCOL_NEXTSORTKEYPART,
103 UTRACE_UCOL_STRCOLLITER,
104 UTRACE_UCOL_OPEN_FROM_SHORT_STRING,
107#ifndef U_HIDE_DEPRECATED_API
113#endif // U_HIDE_DEPRECATED_API
114
115#ifndef U_HIDE_DRAFT_API
116
122
139
147
156
169
170#endif // U_HIDE_DRAFT_API
171
172#ifndef U_HIDE_INTERNAL_API
178#endif // U_HIDE_INTERNAL_API
179
181
187U_STABLE void U_EXPORT2
188utrace_setLevel(int32_t traceLevel);
189
195U_STABLE int32_t U_EXPORT2
197
198/* Trace function pointers types ----------------------------- */
199
206typedef void U_CALLCONV
207UTraceEntry(const void *context, int32_t fnNumber);
208
222typedef void U_CALLCONV
223UTraceExit(const void *context, int32_t fnNumber,
224 const char *fmt, va_list args);
225
237typedef void U_CALLCONV
238UTraceData(const void *context, int32_t fnNumber, int32_t level,
239 const char *fmt, va_list args);
240
269U_STABLE void U_EXPORT2
270utrace_setFunctions(const void *context,
272
283U_STABLE void U_EXPORT2
284utrace_getFunctions(const void **context,
285 UTraceEntry **e, UTraceExit **x, UTraceData **d);
286
287
288
289/*
290 *
291 * ICU trace format string syntax
292 *
293 * Format Strings are passed to UTraceData functions, and define the
294 * number and types of the trace data being passed on each call.
295 *
296 * The UTraceData function, which is supplied by the application,
297 * not by ICU, can either forward the trace data (passed via
298 * varargs) and the format string back to ICU for formatting into
299 * a displayable string, or it can interpret the format itself,
300 * and do as it wishes with the trace data.
301 *
302 *
303 * Goals for the format string
304 * - basic data output
305 * - easy to use for trace programmer
306 * - sufficient provision for data types for trace output readability
307 * - well-defined types and binary portable APIs
308 *
309 * Non-goals
310 * - printf compatibility
311 * - fancy formatting
312 * - argument reordering and other internationalization features
313 *
314 * ICU trace format strings contain plain text with argument inserts,
315 * much like standard printf format strings.
316 * Each insert begins with a '%', then optionally contains a 'v',
317 * then exactly one type character.
318 * Two '%' in a row represent a '%' instead of an insert.
319 * The trace format strings need not have \n at the end.
320 *
321 *
322 * Types
323 * -----
324 *
325 * Type characters:
326 * - c A char character in the default codepage.
327 * - s A NUL-terminated char * string in the default codepage.
328 * - S A UChar * string. Requires two params, (ptr, length). Length=-1 for nul term.
329 * - b A byte (8-bit integer).
330 * - h A 16-bit integer. Also a 16 bit Unicode code unit.
331 * - d A 32-bit integer. Also a 20 bit Unicode code point value.
332 * - l A 64-bit integer.
333 * - p A data pointer.
334 *
335 * Vectors
336 * -------
337 *
338 * If the 'v' is not specified, then one item of the specified type
339 * is passed in.
340 * If the 'v' (for "vector") is specified, then a vector of items of the
341 * specified type is passed in, via a pointer to the first item
342 * and an int32_t value for the length of the vector.
343 * Length==-1 means zero or NUL termination. Works for vectors of all types.
344 *
345 * Note: %vS is a vector of (UChar *) strings. The strings must
346 * be nul terminated as there is no way to provide a
347 * separate length parameter for each string. The length
348 * parameter (required for all vectors) is the number of
349 * strings, not the length of the strings.
350 *
351 * Examples
352 * --------
353 *
354 * These examples show the parameters that will be passed to an application's
355 * UTraceData() function for various formats.
356 *
357 * - the precise formatting is up to the application!
358 * - the examples use type casts for arguments only to _show_ the types of
359 * arguments without needing variable declarations in the examples;
360 * the type casts will not be necessary in actual code
361 *
362 * UTraceDataFunc(context, fnNumber, level,
363 * "There is a character %c in the string %s.", // Format String
364 * (char)c, (const char *)s); // varargs parameters
365 * -> There is a character 0x42 'B' in the string "Bravo".
366 *
367 * UTraceDataFunc(context, fnNumber, level,
368 * "Vector of bytes %vb vector of chars %vc",
369 * (const uint8_t *)bytes, (int32_t)bytesLength,
370 * (const char *)chars, (int32_t)charsLength);
371 * -> Vector of bytes
372 * 42 63 64 3f [4]
373 * vector of chars
374 * "Bcd?"[4]
375 *
376 * UTraceDataFunc(context, fnNumber, level,
377 * "An int32_t %d and a whole bunch of them %vd",
378 * (int32_t)-5, (const int32_t *)ints, (int32_t)intsLength);
379 * -> An int32_t 0xfffffffb and a whole bunch of them
380 * fffffffb 00000005 0000010a [3]
381 *
382 */
383
384
385
405U_STABLE int32_t U_EXPORT2
406utrace_vformat(char *outBuf, int32_t capacity,
407 int32_t indent, const char *fmt, va_list args);
408
426U_STABLE int32_t U_EXPORT2
427utrace_format(char *outBuf, int32_t capacity,
428 int32_t indent, const char *fmt, ...);
429
430
431
432/* Trace function numbers --------------------------------------------------- */
433
443U_STABLE const char * U_EXPORT2
444utrace_functionName(int32_t fnNumber);
445
447
448#endif
#define U_CALLCONV
Similar to U_CDECL_BEGIN/U_CDECL_END, this qualifier is necessary in callback function typedefs to ma...
Definition: platform.h:870
#define U_CDECL_END
This is used to end a declaration of a library private ICU C API.
Definition: umachine.h:85
#define U_CDECL_BEGIN
This is used to begin a declaration of a library private ICU C API.
Definition: umachine.h:84
#define U_STABLE
This is used to declare a function as a stable public ICU C API.
Definition: umachine.h:111
void utrace_getFunctions(const void **context, UTraceEntry **e, UTraceExit **x, UTraceData **d)
Get the currently installed ICU tracing functions.
void UTraceData(const void *context, int32_t fnNumber, int32_t level, const char *fmt, va_list args)
Type signature for the trace function to be called from within an ICU function to display data or mes...
Definition: utrace.h:238
const char * utrace_functionName(int32_t fnNumber)
Get the name of a function from its trace function number.
void UTraceEntry(const void *context, int32_t fnNumber)
Type signature for the trace function to be called when entering a function.
Definition: utrace.h:207
UTraceFunctionNumber
These are the ICU functions that will be traced when tracing is enabled.
Definition: utrace.h:65
@ UTRACE_FUNCTION_LIMIT
One more than the highest normal collation trace location.
Definition: utrace.h:75
@ UTRACE_UCOL_STRCOLLUTF8
Definition: utrace.h:105
@ UTRACE_COLLATION_LIMIT
One more than the highest normal collation trace location.
Definition: utrace.h:112
@ UTRACE_UDATA_BUNDLE
Indicates that a resource bundle was opened.
Definition: utrace.h:146
@ UTRACE_UDATA_DATA_FILE
Indicates that a data file was opened, but not *.res files.
Definition: utrace.h:155
@ UTRACE_UDATA_START
The lowest resource/data location.
Definition: utrace.h:121
@ UTRACE_UDATA_RESOURCE
Indicates that a value was read from a resource bundle.
Definition: utrace.h:138
@ UTRACE_UDATA_RES_FILE
Indicates that a *.res file was opened.
Definition: utrace.h:168
@ UTRACE_RES_DATA_LIMIT
One more than the highest normal resource/data trace location.
Definition: utrace.h:177
@ UTRACE_CONVERSION_LIMIT
One more than the highest normal collation trace location.
Definition: utrace.h:93
UTraceLevel
Trace severity levels.
Definition: utrace.h:46
@ UTRACE_WARNING
Trace errors and warnings.
Definition: utrace.h:52
@ UTRACE_ERROR
Trace error conditions only.
Definition: utrace.h:50
@ UTRACE_OPEN_CLOSE
Trace opens and closes of ICU services.
Definition: utrace.h:54
@ UTRACE_OFF
Disable all tracing.
Definition: utrace.h:48
@ UTRACE_INFO
Trace an intermediate number of ICU operations.
Definition: utrace.h:56
@ UTRACE_VERBOSE
Trace the maximum number of ICU operations.
Definition: utrace.h:58
void utrace_setFunctions(const void *context, UTraceEntry *e, UTraceExit *x, UTraceData *d)
Set ICU Tracing functions.
int32_t utrace_format(char *outBuf, int32_t capacity, int32_t indent, const char *fmt,...)
Trace output Formatter.
int32_t utrace_vformat(char *outBuf, int32_t capacity, int32_t indent, const char *fmt, va_list args)
Trace output Formatter.
void UTraceExit(const void *context, int32_t fnNumber, const char *fmt, va_list args)
Type signature for the trace function to be called when exiting from a function.
Definition: utrace.h:223
void utrace_setLevel(int32_t traceLevel)
Setter for the trace level.
int32_t utrace_getLevel(void)
Getter for the trace level.
Basic definitions for ICU, for both C and C++ APIs.