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

  1 karl  1.24 //%2004////////////////////////////////////////////////////////////////////////
  2 mike  1.2  //
  3 karl  1.24 // 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.21 // IBM Corp.; EMC Corporation, The Open Group.
  7 karl  1.24 // 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 karl  1.21 // 
 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.5  // Modified By: Jenny Yu, Hewlett-Packard Company (jenny_yu@hp.com)
 31 a.arora 1.22 //              Amit K Arora, IBM (amita@in.ibm.com) for PEP#101
 32 kumpf   1.23 //              Roger Kumpf, Hewlett-Packard Company (roger_kumpf@hp.com)
 33 mike    1.2  //
 34              //%/////////////////////////////////////////////////////////////////////////////
 35              
 36 sage    1.4  #include <Pegasus/Common/Config.h>
 37 mike    1.2  #include <Pegasus/Common/Tracer.h>
 38 kumpf   1.3  #include <Pegasus/Common/Thread.h>
 39              #include <Pegasus/Common/IPC.h>
 40              #include <Pegasus/Common/System.h>
 41 mike    1.2  
 42              PEGASUS_USING_STD;
 43              
 44              PEGASUS_NAMESPACE_BEGIN
 45              
 46              // Set the trace levels
 47              // These levels will be compared against a trace level mask to determine
 48 chip    1.20 // if a specific trace level is enabled
 49 mike    1.2  
 50              const Uint32 Tracer::LEVEL1 = (1 << 0);
 51              const Uint32 Tracer::LEVEL2 = (1 << 1);
 52              const Uint32 Tracer::LEVEL3 = (1 << 2);
 53              const Uint32 Tracer::LEVEL4 = (1 << 3);
 54              
 55              // Set the return codes
 56              const Boolean Tracer::_SUCCESS = 1;
 57              const Boolean Tracer::_FAILURE = 0;
 58              
 59              // Set the Enter and Exit messages
 60 kumpf   1.13 const char Tracer::_METHOD_ENTER_MSG[] = "Entering method";
 61              const char Tracer::_METHOD_EXIT_MSG[]  = "Exiting method";
 62 mike    1.2  
 63              // Set Log messages
 64 kumpf   1.13 const char Tracer::_LOG_MSG[] = "LEVEL1 may only be used with trace macros PEG_METHOD_ENTER/PEG_METHOD_EXIT.";
 65 mike    1.2  
 66              // Initialize singleton instance of Tracer
 67              Tracer* Tracer::_tracerInstance = 0;
 68 chip    1.20 
 69 mike    1.2  // Set component separator
 70              const char Tracer::_COMPONENT_SEPARATOR = ',';
 71              
 72              // Set the number of defined components
 73 chip    1.20 const Uint32 Tracer::_NUM_COMPONENTS =
 74 mike    1.2      sizeof(TRACE_COMPONENT_LIST)/sizeof(TRACE_COMPONENT_LIST[0]);
 75              
 76              // Set the line maximum
 77              const Uint32 Tracer::_STRLEN_MAX_UNSIGNED_INT = 21;
 78              
 79 kumpf   1.3  // Set the max PID and Thread ID Length
 80              const Uint32 Tracer::_STRLEN_MAX_PID_TID = 20;
 81              
 82 mike    1.2  ////////////////////////////////////////////////////////////////////////////////
 83              // Tracer constructor
 84              // Constructor is private to preclude construction of Tracer objects
 85              // Single Instance of Tracer is maintained for each process.
 86              ////////////////////////////////////////////////////////////////////////////////
 87              Tracer::Tracer()
 88              {
 89                  // Initialize Trace File Handler
 90 a.arora 1.22     _traceHandler.reset(new TraceFileHandler());
 91 mike    1.2      _traceLevelMask=0;
 92 a.arora 1.22     _traceComponentMask.reset(new Boolean[_NUM_COMPONENTS]);
 93 mike    1.2  
 94                  // Initialize ComponentMask array to false
 95 chip    1.20     for (Uint32 index=0;index < _NUM_COMPONENTS;
 96 a.arora 1.22 	(_traceComponentMask.get())[index++]=false);
 97 mike    1.2  }
 98 chip    1.20 
 99 mike    1.2  ////////////////////////////////////////////////////////////////////////////////
100              //Tracer destructor
101              ////////////////////////////////////////////////////////////////////////////////
102              Tracer::~Tracer()
103              {
104                  delete _tracerInstance;
105              }
106              
107              
108              ////////////////////////////////////////////////////////////////////////////////
109              //Traces the given message
110              ////////////////////////////////////////////////////////////////////////////////
111              void Tracer::_trace(
112                  const Uint32 traceComponent,
113                  const Uint32 traceLevel,
114                  const char* fmt,
115                  va_list argList)
116              {
117                  if ( traceLevel == LEVEL1 )
118                  {
119 kumpf   1.14         trace( traceComponent, Tracer::LEVEL4, "%s", _LOG_MSG );
120 mike    1.2      }
121                  else
122                  {
123                      if (_isTraceEnabled(traceComponent,traceLevel))
124                      {
125 chip    1.20             _trace(traceComponent,"",fmt,argList);
126 mike    1.2  	}
127                  }
128              }
129              
130              ////////////////////////////////////////////////////////////////////////////////
131              //Traces the given message - Overloaded for including FileName and Line number
132              ////////////////////////////////////////////////////////////////////////////////
133              void Tracer::_trace(
134                  const char* fileName,
135                  const Uint32 lineNum,
136                  const Uint32 traceComponent,
137                  const Uint32 traceLevel,
138                  const char* fmt,
139                  va_list argList)
140              {
141                  char* message;
142              
143                  if ( traceLevel == LEVEL1 )
144                  {
145 kumpf   1.14         trace( traceComponent, Tracer::LEVEL4, "%s", _LOG_MSG );
146 mike    1.2      }
147                  else
148                  {
149                      if (_isTraceEnabled(traceComponent,traceLevel))
150                      {
151 kumpf   1.3              //
152                          // Allocate memory for the message string
153                          // Needs to be updated if additional info is added
154                          //
155 chip    1.20 	    message = new char[ strlen(fileName) +
156 mday    1.19 		_STRLEN_MAX_UNSIGNED_INT + (_STRLEN_MAX_PID_TID * 2) + 8 ];
157 kumpf   1.3              sprintf(
158                             message,
159 kumpf   1.9                 "[%d:%u:%s:%u]: ",
160 kumpf   1.3                 System::getPID(),
161 kumpf   1.9                 Uint32(pegasus_thread_self()),
162 kumpf   1.3                 fileName,
163                             lineNum);
164 mike    1.2  
165 chip    1.20             _trace(traceComponent,message,fmt,argList);
166 mike    1.2  	    delete []message;
167                      }
168                  }
169              }
170              
171              ////////////////////////////////////////////////////////////////////////////////
172              //Traces the given buffer
173              ////////////////////////////////////////////////////////////////////////////////
174              void Tracer::_traceBuffer(
175                  const Uint32 traceComponent,
176                  const Uint32 traceLevel,
177                  const char*  data,
178                  const Uint32 size)
179              {
180                  if ( traceLevel == LEVEL1 )
181                  {
182 kumpf   1.14         trace( traceComponent, Tracer::LEVEL4, "%s", _LOG_MSG );
183 mike    1.2      }
184                  else
185                  {
186                      if (_isTraceEnabled(traceComponent,traceLevel))
187                      {
188                          char* tmpBuf = new char[size+1];
189              
190                          strncpy( tmpBuf, data, size );
191                          tmpBuf[size] = '\0';
192                          trace(traceComponent,traceLevel,"%s",tmpBuf);
193              
194                          delete []tmpBuf;
195                      }
196                  }
197              }
198              ////////////////////////////////////////////////////////////////////////////////
199              //Traces the given buffer - Overloaded for including FileName and Line number
200              ////////////////////////////////////////////////////////////////////////////////
201              void Tracer::_traceBuffer(
202                  const char* fileName,
203                  const Uint32 lineNum,
204 mike    1.2      const Uint32 traceComponent,
205                  const Uint32 traceLevel,
206                  const char*  data,
207                  const Uint32 size)
208              {
209                  if ( traceLevel == LEVEL1 )
210                  {
211 kumpf   1.14         trace( traceComponent, Tracer::LEVEL4, "%s", _LOG_MSG );
212 mike    1.2      }
213                  else
214                  {
215                      if ( _isTraceEnabled( traceComponent, traceLevel ) )
216                      {
217                          char* tmpBuf = new char[size+1];
218              
219                          strncpy( tmpBuf, data, size );
220                          tmpBuf[size] = '\0';
221                          trace(fileName,lineNum,traceComponent,traceLevel,"%s",tmpBuf);
222              
223                          delete []tmpBuf;
224 kumpf   1.5          }
225                  }
226              }
227              
228              ////////////////////////////////////////////////////////////////////////////////
229              //Traces the given string
230              ////////////////////////////////////////////////////////////////////////////////
231              void Tracer::_traceString(
232                  const Uint32   traceComponent,
233                  const Uint32   traceLevel,
234                  const String&  traceString)
235              {
236                  if ( traceLevel == LEVEL1 )
237                  {
238 kumpf   1.14         trace( traceComponent, Tracer::LEVEL4, "%s", _LOG_MSG );
239 kumpf   1.5      }
240                  else
241                  {
242                      if (_isTraceEnabled(traceComponent,traceLevel))
243                      {
244 kumpf   1.18             trace(traceComponent,traceLevel,"%s",
245                                     (const char *)traceString.getCString());
246 kumpf   1.5          }
247                  }
248              }
249              
250              ////////////////////////////////////////////////////////////////////////////////
251              //Traces the given string - Overloaded to include the fileName and line number
252              //of trace origin.
253              ////////////////////////////////////////////////////////////////////////////////
254              void Tracer::_traceString(
255                  const char*   fileName,
256                  const Uint32  lineNum,
257                  const Uint32  traceComponent,
258                  const Uint32  traceLevel,
259                  const String& traceString)
260              {
261                  if ( traceLevel == LEVEL1 )
262                  {
263 kumpf   1.14         trace( traceComponent, Tracer::LEVEL4, "%s", _LOG_MSG );
264 kumpf   1.5      }
265                  else
266                  {
267                      if ( _isTraceEnabled( traceComponent, traceLevel ) )
268                      {
269 kumpf   1.18             trace(fileName,lineNum,traceComponent,traceLevel,"%s",
270                                   (const char *)traceString.getCString());
271 kumpf   1.5          }
272                  }
273              }
274              
275              ////////////////////////////////////////////////////////////////////////////////
276              //Traces the message in the given CIMException object.
277              ////////////////////////////////////////////////////////////////////////////////
278              void Tracer::_traceCIMException(
279                  const Uint32 traceComponent,
280                  const Uint32 traceLevel,
281                  CIMException cimException)
282              {
283                  if ( traceLevel == LEVEL1 )
284                  {
285 kumpf   1.14         trace( traceComponent, Tracer::LEVEL4, "%s", _LOG_MSG );
286 kumpf   1.5      }
287                  else
288                  {
289                      if ( _isTraceEnabled( traceComponent, traceLevel ) )
290                      {
291                          // get the CIMException trace message string
292 kumpf   1.15             String traceMsg =
293                              TraceableCIMException(cimException).getTraceDescription();
294 kumpf   1.5  
295                          // trace the string
296                          _traceString(traceComponent, traceLevel, traceMsg);
297 mike    1.2          }
298                  }
299              }
300              
301              ////////////////////////////////////////////////////////////////////////////////
302              //Traces method entry
303              ////////////////////////////////////////////////////////////////////////////////
304              void Tracer::_traceEnter(
305                  const char* fileName,
306                  const Uint32 lineNum,
307                  const Uint32 traceComponent,
308                  const char* fmt,
309                  ...)
310              {
311                  va_list argList;
312                  char* message;
313              
314                  if (_isTraceEnabled(traceComponent,LEVEL1))
315                  {
316 kumpf   1.3  
317 mike    1.2          va_start(argList,fmt);
318              
319 kumpf   1.3          //
320                      // Allocate memory for the message string
321                      // Needs to be updated if additional info is added
322                      //
323 chip    1.20 	message = new char[ strlen(fileName) +
324 mday    1.19 			    _STRLEN_MAX_UNSIGNED_INT + (_STRLEN_MAX_PID_TID * 2) + 8 ];
325              	
326 kumpf   1.3          sprintf(
327                         message,
328 kumpf   1.9             "[%d:%u:%s:%u]: ",
329 kumpf   1.3             System::getPID(),
330 kumpf   1.9             Uint32(pegasus_thread_self()),
331 kumpf   1.3             fileName,
332                         lineNum);
333 chip    1.20         _trace(traceComponent,message,fmt,argList);
334 mike    1.2  
335                      va_end(argList);
336                      delete []message;
337                  }
338              }
339              
340              ////////////////////////////////////////////////////////////////////////////////
341              //Traces method exit
342              ////////////////////////////////////////////////////////////////////////////////
343              void Tracer::_traceExit(
344                  const char* fileName,
345                  const Uint32 lineNum,
346                  const Uint32 traceComponent,
347                  const char* fmt
348                  ...)
349              {
350                  va_list argList;
351                  char* message;
352              
353                  if (_isTraceEnabled(traceComponent,LEVEL1))
354                  {
355 mike    1.2          va_start(argList,fmt);
356 chip    1.20 
357 kumpf   1.3          //
358                      // Allocate memory for the message string
359                      // Needs to be updated if additional info is added
360                      //
361 chip    1.20 	message = new char[ strlen(fileName) +
362 mday    1.19 			    _STRLEN_MAX_UNSIGNED_INT + (_STRLEN_MAX_PID_TID * 2) + 8 ];
363              	
364 kumpf   1.3          sprintf(
365                         message,
366 kumpf   1.9             "[%d:%u:%s:%u]: ",
367 kumpf   1.3             System::getPID(),
368 kumpf   1.9             Uint32(pegasus_thread_self()),
369 kumpf   1.3             fileName,
370                         lineNum);
371 chip    1.20         _trace(traceComponent,message,fmt,argList);
372 mike    1.2          va_end(argList);
373              
374                      delete []message;
375                  }
376              }
377              
378              ////////////////////////////////////////////////////////////////////////////////
379              //Checks if trace is enabled for the given component and level
380              ////////////////////////////////////////////////////////////////////////////////
381              Boolean Tracer::_isTraceEnabled(const Uint32 traceComponent,
382                  const Uint32 traceLevel)
383              {
384                  Tracer* instance = _getInstance();
385                  if (traceComponent >= _NUM_COMPONENTS)
386                  {
387              	return false;
388                  }
389 a.arora 1.22     return (((instance->_traceComponentMask.get())[traceComponent]) &&
390 mike    1.2  	    (traceLevel  & instance->_traceLevelMask));
391              }
392              
393              ////////////////////////////////////////////////////////////////////////////////
394              //Called by all trace interfaces to log message to trace file
395              ////////////////////////////////////////////////////////////////////////////////
396              void Tracer::_trace(
397                  const Uint32 traceComponent,
398                  const char* message,
399                  const char* fmt,
400                  va_list argList)
401              {
402                  char* msgHeader;
403              
404                  // Get the current system time and prepend to message
405                  String currentTime = System::getCurrentASCIITime();
406 kumpf   1.17     CString timeStamp = currentTime.getCString();
407 mike    1.2  
408 kumpf   1.3      //
409 chip    1.20     // Allocate messageHeader.
410 kumpf   1.3      // Needs to be updated if additional info is added
411                  //
412 mday    1.19 
413              
414 mike    1.2  
415                  // Construct the message header
416 chip    1.20     // The message header is in the following format
417 mike    1.2      // timestamp: <component name> [file name:line number]
418                  if (strcmp(message,"") != 0)
419                  {
420 mday    1.19        // << Wed Jul 16 10:58:40 2003 mdd >> _STRLEN_MAX_PID_TID is not used in this format string
421                     msgHeader = new char [strlen(message)
422 chip    1.20 			     + strlen(TRACE_COMPONENT_LIST[traceComponent])
423 mday    1.19 			     + strlen(timeStamp) + _STRLEN_MAX_PID_TID + 5];
424 chip    1.20 
425 kumpf   1.17         sprintf(msgHeader,"%s: %s %s",(const char*)timeStamp,
426 mike    1.2              TRACE_COMPONENT_LIST[traceComponent] ,message);
427 chip    1.20         //delete [] msgHeader;
428 mike    1.2      }
429                  else
430                  {
431 kumpf   1.3          //
432                      // Since the message is blank form a string using the pid and tid
433                      //
434                      char*  tmpBuffer;
435              
436                      //
437 chip    1.20         // Allocate messageHeader.
438 kumpf   1.3          // Needs to be updated if additional info is added
439                      //
440 mday    1.19 	tmpBuffer = new char[_STRLEN_MAX_PID_TID + 6];
441 kumpf   1.9          sprintf(tmpBuffer, "[%u:%u]: ", System::getPID(),
442                              Uint32(pegasus_thread_self()));
443 chip    1.20 	msgHeader = new char [ strlen(timeStamp) + strlen(TRACE_COMPONENT_LIST[traceComponent]) +
444 mday    1.19 			       strlen(tmpBuffer) + 1  + 5 ];
445              	
446 kumpf   1.17         sprintf(msgHeader,"%s: %s %s ",(const char*)timeStamp,
447 kumpf   1.3              TRACE_COMPONENT_LIST[traceComponent] ,tmpBuffer );
448                      delete []tmpBuffer;
449 chip    1.20         //delete [] msgHeader;
450 mday    1.19 	
451 mike    1.2      }
452              
453                  // Call trace file handler to write message
454                  _getInstance()->_traceHandler->handleMessage(msgHeader,fmt,argList);
455 chip    1.20 
456                  delete [] msgHeader;
457 mike    1.2  }
458              
459              ////////////////////////////////////////////////////////////////////////////////
460              //Validate the trace file
461              ////////////////////////////////////////////////////////////////////////////////
462 kumpf   1.10 Boolean Tracer::isValidFileName(const char* filePath)
463 mike    1.2  {
464 kumpf   1.23     String moduleName = _getInstance()->_moduleName;
465                  if (moduleName == String::EMPTY)
466                  {
467                      return (_getInstance()->_traceHandler->isValidFilePath(filePath));
468                  }
469                  else
470                  {
471                      String extendedFilePath = String(filePath) + "." + moduleName;
472                      return (_getInstance()->_traceHandler->isValidFilePath(
473                          extendedFilePath.getCString()));
474                  }
475 mike    1.2  }
476              
477              ////////////////////////////////////////////////////////////////////////////////
478              //Validate the trace components
479              ////////////////////////////////////////////////////////////////////////////////
480 kumpf   1.23 Boolean Tracer::isValidComponents(const String& traceComponents)
481 kumpf   1.10 {
482                  String invalidComponents;
483                  return isValidComponents(traceComponents, invalidComponents);
484              }
485              
486              Boolean Tracer::isValidComponents(
487 kumpf   1.23     const String& traceComponents, String& invalidComponents)
488 mike    1.2  {
489                  // Validate the trace components and modify the traceComponents argument
490                  // to reflect the invalid components
491              
492                  Uint32    position=0;
493                  Uint32    index=0;
494                  String    componentName = String::EMPTY;
495                  String    componentStr = String::EMPTY;
496                  Boolean   validComponent=false;
497                  Boolean   retCode=true;
498              
499                  componentStr = traceComponents;
500                  invalidComponents = String::EMPTY;
501              
502                  if (componentStr != String::EMPTY)
503                  {
504                      // Check if ALL is specified
505                      if (String::equalNoCase(componentStr,"ALL"))
506                      {
507                          return _SUCCESS;
508                      }
509 mike    1.2  
510                      // Append _COMPONENT_SEPARATOR to the end of the traceComponents
511 kumpf   1.16         componentStr.append(_COMPONENT_SEPARATOR);
512 mike    1.2  
513                      while (componentStr != String::EMPTY)
514                      {
515              	    //
516                          // Get the Component name from traceComponents.
517                          // Components are separated by _COMPONENT_SEPARATOR
518              	    //
519                          position = componentStr.find(_COMPONENT_SEPARATOR);
520                          componentName = componentStr.subString(0,(position));
521              
522                          // Lookup the index for Component name in TRACE_COMPONENT_LIST
523                          index = 0;
524                          validComponent = false;
525              
526                          while (index < _NUM_COMPONENTS)
527                          {
528 chip    1.20                 if (String::equalNoCase(
529 mike    1.2  		       componentName, TRACE_COMPONENT_LIST[index]))
530                              {
531                                  // Found component, break from the loop
532              		    validComponent = true;
533                                  break;
534                              }
535                              else
536                              {
537                                 index++;
538                              }
539                          }
540              
541                          // Remove the searched componentname from the traceComponents
542                          componentStr.remove(0,position+1);
543              
544              	    if ( !validComponent )
545              	    {
546 kumpf   1.16 		invalidComponents.append(componentName);
547              		invalidComponents.append(_COMPONENT_SEPARATOR);
548 mike    1.2              }
549                      }
550                  }
551                  else
552                  {
553              	// trace components is empty, it is a valid value so return true
554              	return _SUCCESS;
555                  }
556                  if ( invalidComponents != String::EMPTY )
557                  {
558              	retCode = false;
559              	//
560              	// Remove the extra ',' at the end
561              	//
562              	invalidComponents.remove(
563              	    invalidComponents.reverseFind(_COMPONENT_SEPARATOR));
564                  }
565                  return retCode;
566              }
567 chip    1.20 
568 mike    1.2  ////////////////////////////////////////////////////////////////////////////////
569 kumpf   1.23 //Set the name of the module being traced
570              ////////////////////////////////////////////////////////////////////////////////
571              void Tracer::setModuleName(const String& moduleName)
572              {
573                  _getInstance()->_moduleName = moduleName;
574              }
575              
576              ////////////////////////////////////////////////////////////////////////////////
577 mike    1.2  //Returns the Singleton instance of the Tracer
578              ////////////////////////////////////////////////////////////////////////////////
579              Tracer* Tracer::_getInstance()
580              {
581                  if (_tracerInstance == 0)
582                  {
583                      _tracerInstance = new Tracer();
584                  }
585                  return _tracerInstance;
586              }
587              
588 chip    1.20 // PEGASUS_REMOVE_TRACE defines the compile time inclusion of the Trace
589 mike    1.2  // interfaces. If defined the interfaces map to empty functions
590              
591              #ifndef PEGASUS_REMOVE_TRACE
592              
593              ////////////////////////////////////////////////////////////////////////////////
594              //Set the trace file
595              ////////////////////////////////////////////////////////////////////////////////
596              Uint32 Tracer::setTraceFile(const char* traceFile)
597              {
598 kumpf   1.25     if (*traceFile == 0)
599                  {
600                      return 1;
601                  }
602              
603 kumpf   1.23     String moduleName = _getInstance()->_moduleName;
604                  if (moduleName == String::EMPTY)
605                  {
606                      return (_getInstance()->_traceHandler->setFileName(traceFile));
607                  }
608                  else
609                  {
610                      String extendedTraceFile = String(traceFile) + "." + moduleName;
611                      return (_getInstance()->_traceHandler->setFileName(
612                          extendedTraceFile.getCString()));
613                  }
614 chip    1.20 }
615 mike    1.2  
616              ////////////////////////////////////////////////////////////////////////////////
617              //Set the trace level
618              ////////////////////////////////////////////////////////////////////////////////
619              Uint32 Tracer::setTraceLevel(const Uint32 traceLevel)
620              {
621                  Uint32 retCode = 0;
622              
623                  switch (traceLevel)
624                  {
625              	case LEVEL1:
626                          _getInstance()->_traceLevelMask = 0x01;
627              	    break;
628 chip    1.20 
629 mike    1.2          case LEVEL2:
630                          _getInstance()->_traceLevelMask = 0x03;
631              	    break;
632              
633                      case LEVEL3:
634                          _getInstance()->_traceLevelMask = 0x07;
635              	    break;
636              
637                      case LEVEL4:
638                          _getInstance()->_traceLevelMask = 0x0F;
639              	    break;
640              
641                      default:
642                          _getInstance()->_traceLevelMask = 0;
643                          retCode = 1;
644                  }
645                  return retCode;
646              }
647              
648              ////////////////////////////////////////////////////////////////////////////////
649 chip    1.20 // Set components to be traced.
650 mike    1.2  ////////////////////////////////////////////////////////////////////////////////
651 kumpf   1.23 void Tracer::setTraceComponents(const String& traceComponents)
652 mike    1.2  {
653                  Uint32 position          = 0;
654                  Uint32 index             = 0;
655                  String componentName     = String::EMPTY;
656                  String componentStr      = traceComponents;
657                  String invalidComponents = String::EMPTY;
658 chip    1.20 
659 mike    1.2      if (componentStr != String::EMPTY)
660                  {
661                      // Check if ALL is specified
662                      if (String::equalNoCase(componentStr,"ALL"))
663                      {
664                          for (index=0; index < _NUM_COMPONENTS;
665 a.arora 1.22                     (_getInstance()->_traceComponentMask.get())[index++] = true);
666 chip    1.20             return ;
667 mike    1.2          }
668              
669                      // initialise ComponentMask array to False
670 chip    1.20         for (index = 0;index < _NUM_COMPONENTS;
671 a.arora 1.22 	        (_getInstance()->_traceComponentMask.get())[index++] = false);
672 mike    1.2  
673               	// Append _COMPONENT_SEPARATOR to the end of the traceComponents
674 kumpf   1.16         componentStr.append(_COMPONENT_SEPARATOR);
675 mike    1.2  
676                      while (componentStr != String::EMPTY)
677                      {
678 chip    1.20             // Get the Component name from traceComponents.
679 mike    1.2  	    // Components are separated by _COMPONENT_SEPARATOR
680                          position = componentStr.find(_COMPONENT_SEPARATOR);
681               	    componentName = componentStr.subString(0,(position));
682              
683              	    // Lookup the index for Component name in TRACE_COMPONENT_LIST
684                          index = 0;
685              	    while (index < _NUM_COMPONENTS)
686              	    {
687              	        if (String::equalNoCase(
688              		       componentName,TRACE_COMPONENT_LIST[index]))
689              	        {
690 a.arora 1.22                     (_getInstance()->_traceComponentMask.get())[index]=true;
691 mike    1.2  
692                                  // Found component, break from the loop
693                                  break;
694              	        }
695              	        else
696              	        {
697              	 	    index++;
698                              }
699 chip    1.20             }
700 mike    1.2  
701                          // Remove the searched componentname from the traceComponents
702                          componentStr.remove(0,position+1);
703                      }
704                  }
705                  else
706                  {
707                      // initialise ComponentMask array to False
708 chip    1.20         for (Uint32 index = 0;index < _NUM_COMPONENTS;
709 a.arora 1.22                  (_getInstance()->_traceComponentMask.get())[index++] = false);
710 mike    1.2      }
711                  return ;
712              }
713              
714              #endif
715              
716              PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2