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