ICU 59.1  59.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 
46 typedef enum UTraceLevel {
59 } UTraceLevel;
60 
65 typedef enum UTraceFunctionNumber {
66  UTRACE_FUNCTION_START=0,
67  UTRACE_U_INIT=UTRACE_FUNCTION_START,
68  UTRACE_U_CLEANUP,
69 #ifndef U_HIDE_DEPRECATED_API
70 
75 #endif // U_HIDE_DEPRECATED_API
76 
77  UTRACE_CONVERSION_START=0x1000,
78  UTRACE_UCNV_OPEN=UTRACE_CONVERSION_START,
79  UTRACE_UCNV_OPEN_PACKAGE,
80  UTRACE_UCNV_OPEN_ALGORITHMIC,
81  UTRACE_UCNV_CLONE,
82  UTRACE_UCNV_CLOSE,
83  UTRACE_UCNV_FLUSH_CACHE,
84  UTRACE_UCNV_LOAD,
85  UTRACE_UCNV_UNLOAD,
86 #ifndef U_HIDE_DEPRECATED_API
87 
92 #endif // U_HIDE_DEPRECATED_API
93 
94  UTRACE_COLLATION_START=0x2000,
95  UTRACE_UCOL_OPEN=UTRACE_COLLATION_START,
96  UTRACE_UCOL_CLOSE,
97  UTRACE_UCOL_STRCOLL,
98  UTRACE_UCOL_GET_SORTKEY,
99  UTRACE_UCOL_GETLOCALE,
100  UTRACE_UCOL_NEXTSORTKEYPART,
101  UTRACE_UCOL_STRCOLLITER,
102  UTRACE_UCOL_OPEN_FROM_SHORT_STRING,
104 #ifndef U_HIDE_DEPRECATED_API
105 
110 #endif // U_HIDE_DEPRECATED_API
112 
118 U_STABLE void U_EXPORT2
119 utrace_setLevel(int32_t traceLevel);
120 
126 U_STABLE int32_t U_EXPORT2
127 utrace_getLevel(void);
128 
129 /* Trace function pointers types ----------------------------- */
130 
137 typedef void U_CALLCONV
138 UTraceEntry(const void *context, int32_t fnNumber);
139 
153 typedef void U_CALLCONV
154 UTraceExit(const void *context, int32_t fnNumber,
155  const char *fmt, va_list args);
156 
168 typedef void U_CALLCONV
169 UTraceData(const void *context, int32_t fnNumber, int32_t level,
170  const char *fmt, va_list args);
171 
200 U_STABLE void U_EXPORT2
201 utrace_setFunctions(const void *context,
202  UTraceEntry *e, UTraceExit *x, UTraceData *d);
203 
214 U_STABLE void U_EXPORT2
215 utrace_getFunctions(const void **context,
216  UTraceEntry **e, UTraceExit **x, UTraceData **d);
217 
218 
219 
220 /*
221  *
222  * ICU trace format string syntax
223  *
224  * Format Strings are passed to UTraceData functions, and define the
225  * number and types of the trace data being passed on each call.
226  *
227  * The UTraceData function, which is supplied by the application,
228  * not by ICU, can either forward the trace data (passed via
229  * varargs) and the format string back to ICU for formatting into
230  * a displayable string, or it can interpret the format itself,
231  * and do as it wishes with the trace data.
232  *
233  *
234  * Goals for the format string
235  * - basic data output
236  * - easy to use for trace programmer
237  * - sufficient provision for data types for trace output readability
238  * - well-defined types and binary portable APIs
239  *
240  * Non-goals
241  * - printf compatibility
242  * - fancy formatting
243  * - argument reordering and other internationalization features
244  *
245  * ICU trace format strings contain plain text with argument inserts,
246  * much like standard printf format strings.
247  * Each insert begins with a '%', then optionally contains a 'v',
248  * then exactly one type character.
249  * Two '%' in a row represent a '%' instead of an insert.
250  * The trace format strings need not have \n at the end.
251  *
252  *
253  * Types
254  * -----
255  *
256  * Type characters:
257  * - c A char character in the default codepage.
258  * - s A NUL-terminated char * string in the default codepage.
259  * - S A UChar * string. Requires two params, (ptr, length). Length=-1 for nul term.
260  * - b A byte (8-bit integer).
261  * - h A 16-bit integer. Also a 16 bit Unicode code unit.
262  * - d A 32-bit integer. Also a 20 bit Unicode code point value.
263  * - l A 64-bit integer.
264  * - p A data pointer.
265  *
266  * Vectors
267  * -------
268  *
269  * If the 'v' is not specified, then one item of the specified type
270  * is passed in.
271  * If the 'v' (for "vector") is specified, then a vector of items of the
272  * specified type is passed in, via a pointer to the first item
273  * and an int32_t value for the length of the vector.
274  * Length==-1 means zero or NUL termination. Works for vectors of all types.
275  *
276  * Note: %vS is a vector of (UChar *) strings. The strings must
277  * be nul terminated as there is no way to provide a
278  * separate length parameter for each string. The length
279  * parameter (required for all vectors) is the number of
280  * strings, not the length of the strings.
281  *
282  * Examples
283  * --------
284  *
285  * These examples show the parameters that will be passed to an application's
286  * UTraceData() function for various formats.
287  *
288  * - the precise formatting is up to the application!
289  * - the examples use type casts for arguments only to _show_ the types of
290  * arguments without needing variable declarations in the examples;
291  * the type casts will not be necessary in actual code
292  *
293  * UTraceDataFunc(context, fnNumber, level,
294  * "There is a character %c in the string %s.", // Format String
295  * (char)c, (const char *)s); // varargs parameters
296  * -> There is a character 0x42 'B' in the string "Bravo".
297  *
298  * UTraceDataFunc(context, fnNumber, level,
299  * "Vector of bytes %vb vector of chars %vc",
300  * (const uint8_t *)bytes, (int32_t)bytesLength,
301  * (const char *)chars, (int32_t)charsLength);
302  * -> Vector of bytes
303  * 42 63 64 3f [4]
304  * vector of chars
305  * "Bcd?"[4]
306  *
307  * UTraceDataFunc(context, fnNumber, level,
308  * "An int32_t %d and a whole bunch of them %vd",
309  * (int32_t)-5, (const int32_t *)ints, (int32_t)intsLength);
310  * -> An int32_t 0xfffffffb and a whole bunch of them
311  * fffffffb 00000005 0000010a [3]
312  *
313  */
314 
315 
316 
336 U_STABLE int32_t U_EXPORT2
337 utrace_vformat(char *outBuf, int32_t capacity,
338  int32_t indent, const char *fmt, va_list args);
339 
357 U_STABLE int32_t U_EXPORT2
358 utrace_format(char *outBuf, int32_t capacity,
359  int32_t indent, const char *fmt, ...);
360 
361 
362 
363 /* Trace function numbers --------------------------------------------------- */
364 
374 U_STABLE const char * U_EXPORT2
375 utrace_functionName(int32_t fnNumber);
376 
378 
379 #endif
UTraceLevel
Trace severity levels.
Definition: utrace.h:46
One more than the highest normal collation trace location.
Definition: utrace.h:74
Trace the maximum number of ICU operations.
Definition: utrace.h:58
void UTraceEntry(const void *context, int32_t fnNumber)
Type signature for the trace function to be called when entering a function.
Definition: utrace.h:138
#define U_CALLCONV
Similar to U_CDECL_BEGIN/U_CDECL_END, this qualifier is necessary in callback function typedefs to ma...
Definition: platform.h:871
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:154
int32_t utrace_getLevel(void)
Getter for the trace level.
Trace error conditions only.
Definition: utrace.h:50
#define U_CDECL_BEGIN
This is used to begin a declaration of a library private ICU C API.
Definition: umachine.h:84
Trace an intermediate number of ICU operations.
Definition: utrace.h:56
One more than the highest normal collation trace location.
Definition: utrace.h:109
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:169
void utrace_setLevel(int32_t traceLevel)
Setter for the trace level.
One more than the highest normal collation trace location.
Definition: utrace.h:91
const char * utrace_functionName(int32_t fnNumber)
Get the name of a function from its trace function number.
Trace errors and warnings.
Definition: utrace.h:52
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.
UTraceFunctionNumber
These are the ICU functions that will be traced when tracing is enabled.
Definition: utrace.h:65
#define U_CDECL_END
This is used to end a declaration of a library private ICU C API.
Definition: umachine.h:85
Disable all tracing.
Definition: utrace.h:48
Basic definitions for ICU, for both C and C++ APIs.
Trace opens and closes of ICU services.
Definition: utrace.h:54
int32_t utrace_vformat(char *outBuf, int32_t capacity, int32_t indent, const char *fmt, va_list args)
Trace output Formatter.
#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.