(file) Return to Tracer.h CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / Common

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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2