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

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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2