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

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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2