1 karl 1.18 //%2005////////////////////////////////////////////////////////////////////////
|
2 mike 1.2 //
|
3 karl 1.16 // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
4 // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
5 // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
|
6 karl 1.13 // IBM Corp.; EMC Corporation, The Open Group.
|
7 karl 1.16 // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
8 // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
|
9 karl 1.18 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
10 // EMC Corporation; VERITAS Software Corporation; The Open Group.
|
11 mike 1.2 //
12 // Permission is hereby granted, free of charge, to any person obtaining a copy
13 // of this software and associated documentation files (the "Software"), to
14 // deal in the Software without restriction, including without limitation the
15 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
16 // sell copies of the Software, and to permit persons to whom the Software is
17 // furnished to do so, subject to the following conditions:
|
18 kumpf 1.9 //
|
19 mike 1.2 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
20 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
21 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
22 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
23 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
24 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
25 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 //
28 //==============================================================================
29 //
30 // Author: Sushma Fernandes, Hewlett-Packard Company (sushma_fernandes@hp.com)
31 //
|
32 kumpf 1.6 // Modified By: Jenny Yu, Hewlett-Packard Company (jenny_yu@hp.com)
|
33 a.arora 1.14 // Amit K Arora, IBM (amita@in.ibm.com) for PEP#101
|
34 kumpf 1.15 // Roger Kumpf, Hewlett-Packard Company (roger_kumpf@hp.com)
|
35 mike 1.2 //
36 //%/////////////////////////////////////////////////////////////////////////////
37
38 #ifndef Pegasus_Tracer_h
39 #define Pegasus_Tracer_h
40
41 #include <stdarg.h>
42 #include <Pegasus/Common/String.h>
43 #include <Pegasus/Common/System.h>
44 #include <Pegasus/Common/Logger.h>
|
45 kumpf 1.12 #include <Pegasus/Common/InternalException.h>
|
46 mike 1.2 #include <Pegasus/Common/TraceComponents.h>
47 #include <Pegasus/Common/TraceFileHandler.h>
|
48 kumpf 1.11 #include <Pegasus/Common/Linkage.h>
|
49 a.arora 1.14 #include <Pegasus/Common/AutoPtr.h>
|
50 mike 1.2
51 PEGASUS_NAMESPACE_BEGIN
52
53 /** Tracer implements tracing of messages to a defined file
54 */
55
56 class PEGASUS_COMMON_LINKAGE Tracer
57 {
58 public:
59
60 /** Levels of trace
61 Trace messages are written to the trace file only if they are at or
62 above a given trace level
63 LEVEL1 - Function Entry/Exit
64 LEVEL2 - Basic flow trace messages, low data detail
65 LEVEL3 - Inter-function logic flow, medium data detail
66 LEVEL4 - High data detail
67 */
68 static const Uint32 LEVEL1;
69 static const Uint32 LEVEL2;
70 static const Uint32 LEVEL3;
71 mike 1.2 static const Uint32 LEVEL4;
72
73 // PEGASUS_REMOVE_TRACE defines the compile time inclusion of the Trace
74 // interfaces. If defined the interfaces map to empty functions
75
76 #ifdef PEGASUS_REMOVE_TRACE
77
78 inline static void traceBuffer(
79 const char* fileName,
80 const Uint32 lineNum,
81 const Uint32 traceComponent,
82 const Uint32 traceLevel,
83 const char* data,
84 const Uint32 size)
85 {
86 // empty function
87 }
88 inline static void traceBuffer(
89 const Uint32 traceComponent,
90 const Uint32 traceLevel,
91 const char* data,
92 mike 1.2 const Uint32 size)
93 {
94 // empty function
95 }
96
97 inline static void trace(
98 const Uint32 traceComponent,
99 const Uint32 traceLevel,
100 const char *fmt,
101 ...)
102 {
103 // empty function
104 }
105
106 inline static void trace(
107 const char* fileName,
108 const Uint32 lineNum,
109 const Uint32 traceComponent,
110 const Uint32 traceLevel,
111 const char* fmt,
112 ...)
113 mike 1.2 {
114 // empty function
115 }
116
|
117 kumpf 1.6 inline static void trace(
118 const char* fileName,
119 const Uint32 lineNum,
120 const Uint32 traceComponent,
121 const Uint32 traceLevel,
122 const String& traceString)
123 {
124 // empty function
125 }
126
127 inline static void traceCIMException(
128 const Uint32 traceComponent,
129 const Uint32 traceLevel,
130 CIMException cimException)
131 {
132 // empty function
133 }
134
|
135 mike 1.2 static Uint32 setTraceFile(const char* traceFile)
136 {
137 // empty function
138 return 0;
139 }
140
141 static Uint32 setTraceLevel(const Uint32 traceLevel)
142 {
143 // empty function
144 return 0;
145 }
146
147 static void setTraceComponents(
|
148 kumpf 1.15 const String& traceComponents)
|
149 mike 1.2 {
150 // empty function
151 }
152
153
154 #else
155 /** Traces the specified number of bytes in a given buffer
156 @param traceComponent component being traced
157 @param traceLevel trace level of the trace message
158 @param data buffer to be traced
159 @param size number of bytes to be traced
160 */
161 inline static void traceBuffer(
162 const Uint32 traceComponent,
163 const Uint32 traceLevel,
164 const char* data,
165 const Uint32 size)
166 {
167 _traceBuffer( traceComponent, traceLevel, data, size );
168 }
169
170 mike 1.2 /** Traces the specified number of bytes in a given buffer
171 Overloaded to include the filename and the line number
172 of trace origin.
173 @param fileName filename of the trace originator
174 @param lineNum line number of the trace originator
175 @param traceComponent component being traced
176 @param traceLevel trace level of the trace message
177 @param data buffer to be traced
178 @param size size of the buffer
179 */
180 inline static void traceBuffer(
181 const char* fileName,
182 const Uint32 lineNum,
183 const Uint32 traceComponent,
184 const Uint32 traceLevel,
185 const char* data,
186 const Uint32 size)
187 {
188 _traceBuffer( fileName, lineNum,
189 traceComponent, traceLevel, data, size );
190 }
191 mike 1.2
192
193 /** Traces the given message
194 @param traceComponent component being traced
195 @param traceLevel trace level of the trace message
196 @param *fmt printf style format string
197 @param ... variable argument list
198 */
199 inline static void trace(
200 const Uint32 traceComponent,
201 const Uint32 traceLevel,
202 const char *fmt,
203 ...)
204 {
205 va_list argList;
206
207 va_start(argList,fmt);
208 _trace(traceComponent,traceLevel,fmt,argList);
209 va_end(argList);
210 }
211
212 mike 1.2 /** Traces the given message. Overloaded to include the filename and
213 the line number of trace origin.
214 @param fileName filename of the trace originator
215 @param lineNum line number of the trace originator
216 @param traceComponent component being traced
217 @param traceLevel trace level of the trace message
218 @param *fmt printf style format string
219 @param ... variable argument list
220 */
221 inline static void trace(
222 const char* fileName,
223 const Uint32 lineNum,
224 const Uint32 traceComponent,
225 const Uint32 traceLevel,
226 const char* fmt,
227 ...)
228 {
229 va_list argList;
230
231 va_start(argList,fmt);
232 _trace(fileName,lineNum,traceComponent,traceLevel,fmt,argList);
233 mike 1.2 va_end(argList);
234 }
235
|
236 kumpf 1.6 /** Traces the given string. Overloaded to include the filename
237 and line number of trace origin.
238 @param fileName filename of the trace originator
239 @param lineNum line number of the trace originator
240 @param traceComponent component being traced
241 @param traceLevel trace level of the trace message
242 @param traceString the string to be traced
243 */
244 inline static void trace(
245 const char* fileName,
246 const Uint32 lineNum,
247 const Uint32 traceComponent,
248 const Uint32 traceLevel,
249 const String& traceString)
250 {
251 _traceString( fileName, lineNum, traceComponent, traceLevel,
252 traceString );
253 }
254
255 /** Traces the message in the given CIMException object. The message
256 written to the trace file will include the source filename and
257 kumpf 1.6 line number of the CIMException originator.
258 @param traceComponent component being traced
259 @param traceLevel trace level of the trace message
260 @param CIMException the CIMException to be traced.
261 */
262 inline static void traceCIMException(
263 const Uint32 traceComponent,
264 const Uint32 traceLevel,
265 CIMException cimException)
266 {
267 _traceCIMException( traceComponent, traceLevel, cimException );
268 }
269
|
270 mike 1.2 /** Set the trace file to the given file
271 @param traceFile full path of the trace file
272 @return 0 if the filepath is valid
|
273 kumpf 1.17 1 if the traceFile is an empty string or
274 if an error occurs while opening the file
|
275 mike 1.2 in append mode
276 */
277 static Uint32 setTraceFile(const char* traceFile);
278
279 /** Set the trace level to the given level
280 @param traceLevel trace level to be set
281 @return 0 if trace level is valid
282 1 if trace level is invalid
283 */
284 static Uint32 setTraceLevel(const Uint32 traceLevel);
285
286 /** Set components to be traced
287 @param traceComponents list of components to be traced,
288 components should be separated by ','
289 */
290 static void setTraceComponents(
|
291 kumpf 1.15 const String& traceComponents);
|
292 mike 1.2
293 #endif
294
295 // End of PEGASUS_REMOVE_TRACE
296
297 /** Traces method entry.
298 @param fileName filename of the trace originator
299 @param lineNum line number of the trace originator
300 @param traceComponent component being traced
301 @param methodName method being traced
302 */
303 inline static void traceEnter(
304 const char* fileName,
305 const Uint32 lineNum,
306 const Uint32 traceComponent,
307 const char* methodName)
308 {
309 _traceEnter( fileName, lineNum, traceComponent, "%s %s",
|
310 kumpf 1.10 _METHOD_ENTER_MSG, methodName);
|
311 mike 1.2 }
312
313 /** Traces method exit.
314 @param fileName filename of the trace originator
315 @param lineNum line number of the trace originator
316 @param traceComponent component being traced
317 @param methodName method being traced
318 */
319 inline static void traceExit(
320 const char* fileName,
321 const Uint32 lineNum,
322 const Uint32 traceComponent,
323 const char* methodName)
324 {
325 _traceExit( fileName, lineNum, traceComponent, "%s %s",
|
326 kumpf 1.10 _METHOD_EXIT_MSG, methodName);
|
327 mike 1.2 }
328
329 /** Validates the File Path for the trace File
330 @param filePath full path of the file
331 @return 1 if the file path is valid
332 0 if the file path is invalid
333 */
|
334 kumpf 1.7 static Boolean isValidFileName(const char* filePath);
335
336 /** Validates the trace components
337 @param traceComponents comma separated list of trace components
338 @return 1 if the components are valid
339 0 if one or more components are invalid
340 */
|
341 kumpf 1.15 static Boolean isValidComponents(const String& traceComponents);
|
342 mike 1.2
343 /** Validates the trace components
344 @param traceComponents comma separated list of trace components
345 @param invalidComponents comma separated list of invalid components
346 @return 1 if the components are valid
347 0 if one or more components are invalid
348 */
|
349 kumpf 1.7 static Boolean isValidComponents(
|
350 kumpf 1.15 const String& traceComponents,
|
351 kumpf 1.7 String& invalidComponents);
|
352 mike 1.2
|
353 kumpf 1.15 /** Specify the name of the module being traced. If non-empty, this
354 value is used as an extension to the name of the trace file.
355 @param moduleName Name of the module being traced.
356 */
357 static void setModuleName(const String& moduleName);
358
|
359 mike 1.2 private:
360
361 static const char _COMPONENT_SEPARATOR;
362 static const Uint32 _NUM_COMPONENTS;
363 static const Uint32 _STRLEN_MAX_UNSIGNED_INT;
|
364 kumpf 1.4 static const Uint32 _STRLEN_MAX_PID_TID;
|
365 mike 1.2 static const Boolean _SUCCESS;
366 static const Boolean _FAILURE;
|
367 kumpf 1.15 AutoArrayPtr<Boolean> _traceComponentMask;
|
368 mike 1.2 Uint32 _traceLevelMask;
|
369 kumpf 1.15 AutoPtr<TraceFileHandler> _traceHandler;
370 String _moduleName;
|
371 mike 1.2 static Tracer* _tracerInstance;
372
|
373 kumpf 1.10 // Message Strings for function Entry and Exit
374 static const char _METHOD_ENTER_MSG[];
375 static const char _METHOD_EXIT_MSG[];
|
376 mike 1.2
377 // Message Strings for Logger
|
378 kumpf 1.6 static const char _LOG_MSG[];
|
379 mike 1.2
380 // Checks if trace is enabled for the given component and trace level
381 // @param traceComponent component being traced
382 // @param traceLevel level of the trace message
383 // @return 0 if the component and level are not enabled
384 // 1 if the component and level are enabled
385 static Boolean _isTraceEnabled(
386 const Uint32 traceComponent,
387 const Uint32 traceLevel);
388
389 // Traces the given message
390 // @param traceComponent component being traced
391 // @param traceLevel level of the trace message
392 // @param *fmt printf style format string
393 // @param argList variable argument list
394 static void _trace(
395 const Uint32 traceComponent,
396 const Uint32 traceLevel,
397 const char* fmt,
398 va_list argList);
399
400 mike 1.2 // Traces the given message. Overloaded to include the file name and the
401 // line number as one of the parameters.
402 // @param traceComponent component being traced
403 // @param traceLevel level of the trace message
404 // @param message message header (file name:line number)
405 // @param *fmt printf style format string
406 // @param argList variable argument list
407 static void _trace(
408 const char* fileName,
409 const Uint32 lineNum,
410 const Uint32 traceComponent,
411 const Uint32 traceLevel,
412 const char* fmt,
413 va_list argList);
414
415 // Traces the specified number of bytes in a given buffer
416 // @param traceComponent component being traced
417 // @param traceLevel trace level of the trace message
418 // @param data buffer to be traced
419 // @param size number of bytes to be traced
420 static void _traceBuffer(
421 mike 1.2 const Uint32 traceComponent,
422 const Uint32 traceLevel,
423 const char* data,
424 const Uint32 size);
425
426 // Traces the specified number of bytes in a given buffer
427 // Overloaded to include the filename and the line number
428 // of trace origin.
429 // @param fileName filename of the trace originator
430 // @param lineNum line number of the trace originator
431 // @param traceComponent component being traced
432 // @param traceLevel trace level of the trace message
433 // @param data buffer to be traced
434 // @param size size of the buffer
435 static void _traceBuffer(
436 const char* fileName,
437 const Uint32 lineNum,
438 const Uint32 traceComponent,
439 const Uint32 traceLevel,
440 const char* data,
441 const Uint32 size);
442 mike 1.2
|
443 kumpf 1.6 // Traces the given string.
444 // @param traceComponent component being traced
445 // @param traceLevel trace level of the trace message
446 // @param traceString the string to be traced
447 //
448 static void _traceString(
449 const Uint32 traceComponent,
450 const Uint32 traceLevel,
451 const String& traceString);
452
453 // Traces a given string. Overloaded to include the filename
454 // and line number of trace origin.
455 // @param fileName filename of the trace originator
456 // @param lineNum line number of the trace originator
457 // @param traceComponent component being traced
458 // @param traceLevel trace level of the trace message
459 // @param traceString the string to be traced
460 //
461 static void _traceString(
462 const char* fileName,
463 const Uint32 lineNum,
464 kumpf 1.6 const Uint32 traceComponent,
465 const Uint32 traceLevel,
466 const String& traceString);
467
468 // Traces the message in the given CIMException object. The message
469 // to be written to the trace file will include the source filename and
470 // line number of the CIMException originator.
471 // @param traceComponent component being traced
472 // @param traceLevel trace level of the trace message
473 // @param CIMException the CIMException to be traced.
474 //
475 static void _traceCIMException(
476 const Uint32 traceComponent,
477 const Uint32 traceLevel,
478 CIMException cimException);
479
|
480 mike 1.2 // Called by all the trace interfaces to log message to the
481 // trace file
482 // @param fileName filename of the trace originator
483 // @param lineNum line number of the trace originator
484 // @param traceComponent component being traced
485 // @param *fmt printf style format string
486 // @param argList variable argument list
487 static void _trace(
488 const Uint32 traceComponent,
489 const char* message,
490 const char* fmt,
491 va_list argList);
492
493 // Traces method enter
494 // @param fileName filename of the trace originator
495 // @param lineNum line number of the trace originator
496 // @param traceComponent component being traced
497 // @param *fmt printf style format string
498 // @param ... variable argument list
499 static void _traceEnter(
500 const char* fileName,
501 mike 1.2 const Uint32 lineNum,
502 const Uint32 traceComponent,
503 const char* fmt,
504 ...);
505
506 // Traces method exit
507 // @param fileName filename of the trace originator
508 // @param traceComponent component being traced
509 // @param *fmt printf style format string
510 // @param ... variable argument list
511 static void _traceExit(
512 const char* fileName,
513 const Uint32 lineNum,
514 const Uint32 traceComponent,
515 const char* fmt,
516 ...);
517
518 // Tracer constructor
519 // Constructor is private to prevent construction of Tracer objects
520 // Single Instance of Tracer is maintained for each process.
521 Tracer();
522 mike 1.2
523 // Tracer destructor
524 ~Tracer();
525
526 // Returns the Singleton instance of the Tracer
527 // @return Tracer* Instance of Tracer
528 static Tracer* _getInstance();
529 };
530
|
531 kumpf 1.6 // Define the macros for method entry/exit, and tracing a given string
|
532 mike 1.2 #ifdef PEGASUS_REMOVE_TRACE
|
533 kumpf 1.5 #define PEG_METHOD_ENTER(traceComponent,methodName)
534 #define PEG_METHOD_EXIT()
|
535 kumpf 1.6 #define PEG_TRACE_STRING(traceComponent,traceLevel,traceString)
|
536 mike 1.2 #else
|
537 kumpf 1.5 /** Macro for tracing method entry
538 @param traceComponent component being traced
539 @param methodName name of the method
540 */
541 #define PEG_METHOD_ENTER(traceComponent,methodName) \
542 const char *PEG_METHOD_NAME = methodName; \
543 const Uint32 PEG_TRACE_COMPONENT = traceComponent; \
544 Tracer::traceEnter(__FILE__,__LINE__,PEG_TRACE_COMPONENT,PEG_METHOD_NAME)
545
546 /** Macro for tracing method exit
547 */
548 #define PEG_METHOD_EXIT() \
549 Tracer::traceExit(__FILE__,__LINE__,PEG_TRACE_COMPONENT,PEG_METHOD_NAME)
|
550 kumpf 1.6
551 /** Macro for tracing a string
552 @param traceComponent component being traced
553 @param traceLevel trace level of the trace message
554 @param traceString the string to be traced
555 */
556 #define PEG_TRACE_STRING(traceComponent,traceLevel,traceString) \
557 Tracer::trace(__FILE__, __LINE__,traceComponent,traceLevel,traceString)
|
558 mday 1.8
|
559 mike 1.2 #endif
560
561 PEGASUS_NAMESPACE_END
562
563 #endif /* Pegasus_Tracer_h */
|