testexecfw/stf/stffw/logger/STFLoggingServer/src/HtmlLogger.cpp
changeset 2 8bb370ba6d1d
equal deleted inserted replaced
1:bbd31066657e 2:8bb370ba6d1d
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 * 
       
    14 * Description: This module contains implementation of CHtmlLogger 
       
    15 * class member functions.
       
    16 *
       
    17 */
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <e32std.h>
       
    21 #include "HtmlLogger.h"
       
    22 #include "Output.h"
       
    23 #include "LoggerTracing.h"
       
    24 #include "LoggerOverFlow.h"
       
    25 
       
    26 // EXTERNAL DATA STRUCTURES
       
    27 // None
       
    28 
       
    29 // EXTERNAL FUNCTION PROTOTYPES  
       
    30 // None
       
    31 
       
    32 // CONSTANTS
       
    33 // None
       
    34 
       
    35 // MACROS
       
    36 // None
       
    37 
       
    38 // LOCAL CONSTANTS AND MACROS
       
    39 // None
       
    40 
       
    41 // MODULE DATA STRUCTURES
       
    42 // None
       
    43 
       
    44 // LOCAL FUNCTION PROTOTYPES
       
    45 // None
       
    46 
       
    47 // FORWARD DECLARATIONS
       
    48 // None
       
    49 
       
    50 // ==================== LOCAL FUNCTIONS =======================================
       
    51 // None
       
    52 
       
    53 // ================= MEMBER FUNCTIONS =========================================
       
    54 
       
    55 /*
       
    56 -------------------------------------------------------------------------------
       
    57 
       
    58     Class: CHtmlLogger
       
    59 
       
    60     Method: CHtmlLogger
       
    61 
       
    62     Description: Default constructor
       
    63 
       
    64     C++ default constructor can NOT contain any code, that
       
    65     might leave.
       
    66 
       
    67     Parameters: COutput* output: in: Output source
       
    68                 const TDesC& aTestFile: in: Log filename
       
    69                 TBool aThreadIdToLogFile: in: Indicator to thread id adding to
       
    70                                               end of the log file
       
    71 
       
    72     Return Values: None
       
    73 
       
    74     Errors/Exceptions: None
       
    75 
       
    76     Status: Approved
       
    77 
       
    78 -------------------------------------------------------------------------------
       
    79 */
       
    80 CHtmlLogger::CHtmlLogger( COutput* output,
       
    81                           const TDesC& aTestFile,
       
    82                           TBool aThreadIdToLogFile )
       
    83     {
       
    84     iOutput = output;
       
    85     StartHtmlPage( aTestFile, aThreadIdToLogFile );
       
    86     }
       
    87 
       
    88 
       
    89 /*
       
    90 -------------------------------------------------------------------------------
       
    91 
       
    92     Class: CHtmlLogger
       
    93 
       
    94     Method: ConstructL
       
    95 
       
    96     Description: Symbian OS second phase constructor
       
    97 
       
    98     Symbian OS default constructor can leave.
       
    99 
       
   100     Parameters: None
       
   101 
       
   102     Return Values: None
       
   103 
       
   104     Errors/Exceptions: None
       
   105 
       
   106     Status: Approved
       
   107 
       
   108 -------------------------------------------------------------------------------
       
   109 */
       
   110 void CHtmlLogger::ConstructL()
       
   111     {
       
   112     //nothing to do.    
       
   113     }
       
   114 
       
   115 /*
       
   116 -------------------------------------------------------------------------------
       
   117 
       
   118     Class: CHtmlLogger
       
   119 
       
   120     Method: NewL
       
   121 
       
   122     Description: Two-phased constructor.
       
   123 
       
   124     Parameters: const TDesC& aTestPath: in: Log path
       
   125                 const TDesC& aTestFile: in: Log filename
       
   126                 TLoggerType aLoggerType: in: File type
       
   127                 TOutput aOutput: in: Output source
       
   128                 TBool aOverWrite: in: For file overwrite
       
   129                 TBool aWithTimeStamp: in: For timestamp
       
   130                 TBool aWithLineBreak: in: For line break
       
   131                 TBool aWithEventRanking: in: For events ranking to file
       
   132                 TBool aThreadIdToLogFile: in: Indicator to thread id adding to
       
   133                                               end of the log file
       
   134                 TBool aCreateLogDir: in: Indicator to directory creation
       
   135                 TInt  aStaticBufferSize
       
   136                 TBool aUnicode: in: Indicator if file has to be in unicode format
       
   137 
       
   138     Return Values: CHtmlLogger*: pointer to CHtmlLogger object
       
   139 
       
   140     Errors/Exceptions: Leaves if called COutput::NewL method fails
       
   141 
       
   142     Status: Proposal
       
   143 
       
   144 -------------------------------------------------------------------------------
       
   145 */
       
   146 CHtmlLogger* CHtmlLogger::NewL( const TDesC& aTestPath,
       
   147                                 const TDesC& aTestFile,
       
   148                                 CStifLogger::TLoggerType aLoggerType,
       
   149                                 CStifLogger::TOutput aOutput,
       
   150                                 TBool aOverWrite,
       
   151                                 TBool aWithTimeStamp,
       
   152                                 TBool aWithLineBreak,
       
   153                                 TBool aWithEventRanking,
       
   154                                 TBool aThreadIdToLogFile,
       
   155                                 TBool aCreateLogDir,
       
   156                                 TInt aStaticBufferSize,
       
   157                                 TBool aUnicode,
       
   158                                 TInt aThreadId)
       
   159     {
       
   160     
       
   161     __TRACE( KInfo, ( _L( "STIFLOGGER: Creating html logger" ) ) );
       
   162 
       
   163     // Create COutput object output
       
   164     COutput* output = COutput::NewL( aTestPath,
       
   165                                         aTestFile,
       
   166                                         aLoggerType,
       
   167                                         aOutput,
       
   168                                         aOverWrite,
       
   169                                         aWithTimeStamp,
       
   170                                         aWithLineBreak,
       
   171                                         aWithEventRanking,
       
   172                                         aThreadIdToLogFile,
       
   173                                         aCreateLogDir,
       
   174                                         aStaticBufferSize,
       
   175                                         aUnicode,
       
   176                                         aThreadId);
       
   177 
       
   178     CleanupStack::PushL( output ); 
       
   179     __ASSERT_ALWAYS( output != NULL, User::Leave( KErrNotFound ) );
       
   180     // Create CTxtLogger object htmlLogger and bind to COutput
       
   181     CHtmlLogger* htmlLogger = new (ELeave) CHtmlLogger( output,
       
   182                                                         aTestFile,
       
   183                                                         aThreadIdToLogFile );
       
   184     // HTML logger owns output object and it will be destroyed in STIFLogger
       
   185     // destructor.
       
   186     CleanupStack::Pop( output ); 
       
   187     
       
   188     CleanupStack::PushL( htmlLogger );
       
   189     htmlLogger->ConstructL();
       
   190     CleanupStack::Pop( htmlLogger );
       
   191 
       
   192     return htmlLogger;
       
   193 
       
   194     }
       
   195 
       
   196 /*
       
   197 -------------------------------------------------------------------------------
       
   198 
       
   199     Class: CHtmlLogger
       
   200 
       
   201     Method: ~CHtmlLogger
       
   202 
       
   203     Description: Destructor
       
   204 
       
   205     Parameters: None
       
   206 
       
   207     Return Values: None
       
   208 
       
   209     Errors/Exceptions: None
       
   210 
       
   211     Status: Approved
       
   212 
       
   213 -------------------------------------------------------------------------------
       
   214 */
       
   215 CHtmlLogger::~CHtmlLogger()
       
   216     {
       
   217 
       
   218     EndHtmlPage();
       
   219 
       
   220     }
       
   221 
       
   222 /*
       
   223 -------------------------------------------------------------------------------
       
   224 
       
   225     Class: CHtmlLogger
       
   226 
       
   227     Method: StartHtmlPage
       
   228 
       
   229     Description: Initialize html page.
       
   230 
       
   231     Parameters: const TDesC& aTestFile: in: Log filename
       
   232                 TBool aThreadIdToLogFile: in: Indicator to thread id adding to
       
   233                                               end of the log file
       
   234 
       
   235     Return Values: None
       
   236 
       
   237     Errors/Exceptions:  TDesLoggerOverflowHandler called if logged data is 
       
   238                         over KMaxFileName.
       
   239 
       
   240     Status: Approved
       
   241 
       
   242 -------------------------------------------------------------------------------
       
   243 */
       
   244 void CHtmlLogger::StartHtmlPage( const TDesC& aTestFile,
       
   245                                     TBool aThreadIdToLogFile )
       
   246     {
       
   247     TFileName title;
       
   248 
       
   249     // Create overflow handler.
       
   250     TDesLoggerOverflowHandler overFlowHandler( this, 4 );
       
   251 
       
   252     // Title
       
   253     if( aTestFile.Length() < KMaxFileName )
       
   254         {
       
   255         title.Append( aTestFile );
       
   256         }    
       
   257     else
       
   258         {
       
   259         // If the title size is over the KMaxFileName rest of the title
       
   260         // will cut. Use normal overflowhandler to print overflow information.
       
   261         TBuf<4> empty; // Not really used.
       
   262         overFlowHandler.Overflow( empty );
       
   263         TPtrC cuttedtitle = aTestFile.Left( KMaxFileName );
       
   264         title.Append( cuttedtitle );
       
   265         }        
       
   266         
       
   267     // Add Thread id to title if enough space and test file is given and 
       
   268     // aThreadIdToLogFile is true
       
   269     if( title.Length() <  ( KMaxFileName - 3 ) && aTestFile.Length() > 0 &&
       
   270         aThreadIdToLogFile )
       
   271         {
       
   272         title.Append( _L( "_" ) );
       
   273         RThread threadHandle;                   // A handle to a thread
       
   274         TThreadId id = threadHandle.Id();       // Encapsulates the 
       
   275                                                 // Id of a thread
       
   276         // Appends id in hexadesimal format                           
       
   277         title.AppendFormat( _L( "%x" ), (TInt)id );   
       
   278         }
       
   279 
       
   280     // Html start tags to whole page and header section
       
   281     iOutput->Write( EFalse, EFalse, EFalse,
       
   282                     _L8( "\n<html>\n<head>\n<title>" ) );
       
   283     // Html file title
       
   284     iOutput->Write( EFalse, EFalse, EFalse, title );
       
   285     // Html header section end tags and start tag to body section
       
   286     iOutput->Write( EFalse, EFalse, EFalse,
       
   287                     _L8( "</title>\n</head>\n\n\n<body>\n" ) );
       
   288 
       
   289     }
       
   290 
       
   291 /*
       
   292 -------------------------------------------------------------------------------
       
   293 
       
   294     Class: CHtmlLogger
       
   295 
       
   296     Method: EndHtmlPage
       
   297 
       
   298     Description: Finalize html page.
       
   299 
       
   300     Parameters: None
       
   301 
       
   302     Return Values: None
       
   303 
       
   304     Errors/Exceptions: None
       
   305 
       
   306     Status: Approved
       
   307 
       
   308 -------------------------------------------------------------------------------
       
   309 */
       
   310 void CHtmlLogger::EndHtmlPage()
       
   311     {
       
   312     // Html page and body section end tags
       
   313     iOutput->Write( EFalse, EFalse, EFalse,
       
   314                     _L8( "\n\n\n</html>\n</body>\n\n\n" ) );
       
   315 
       
   316     }
       
   317 
       
   318 /*
       
   319 -------------------------------------------------------------------------------
       
   320 
       
   321     Class: CHtmlLogger
       
   322 
       
   323     Method: StyleStarting
       
   324 
       
   325     Description: Start style information logging.
       
   326 
       
   327     Parameters: TInt aStyle: in: Style information
       
   328                 TBool aTimeStamp: inout: Time stamp indicator
       
   329                 TBool aEventRanking: inout: Event ranking indicator
       
   330 
       
   331     Return Values: None
       
   332 
       
   333     Errors/Exceptions: None
       
   334 
       
   335     Status: Approved
       
   336 
       
   337 -------------------------------------------------------------------------------
       
   338 */
       
   339 void CHtmlLogger::StyleStarting( TInt aStyle, TBool& aTimeStamp,
       
   340                                     TBool& aEventRanking )
       
   341     {
       
   342     if ( 0x00020 <= aStyle ||       // ERed, 0x00020 => 32
       
   343             0x00040 <= aStyle ||    // EImportant, 0x00040 => 64
       
   344             0x00080 <= aStyle ||    // EWarning, 0x00080 => 128
       
   345             0x00100 <= aStyle )     // EError, 0x00100 => 256
       
   346         {
       
   347         iOutput->Write( EFalse, EFalse, EFalse,
       
   348                                         _L8( "<FONT COLOR='#FF0000'>" ) );
       
   349         if ( 0x00100 <= aStyle )
       
   350             {
       
   351             iOutput->Write( aTimeStamp, EFalse, aEventRanking,
       
   352                                         _L8( "ERROR..." ) );
       
   353             aStyle -= 0x00100;
       
   354             aTimeStamp = EFalse;    // Time stamp added no time stamp to the
       
   355                                     // forward operations
       
   356             aEventRanking = EFalse; // Event ranking added no event ranking
       
   357                                     // to the forward operations
       
   358             }
       
   359         if ( 0x00080 <= aStyle )
       
   360             {
       
   361             iOutput->Write( aTimeStamp, EFalse, aEventRanking,
       
   362                                         _L8( "WARNING..." ) );
       
   363             aStyle -= 0x00080;
       
   364             aTimeStamp = EFalse;    // Time stamp added no time stamp to the 
       
   365                                     // forward operations
       
   366             aEventRanking = EFalse; // Event ranking added no event ranking
       
   367                                     // to the forward operations
       
   368             }
       
   369         if ( 0x00040 <= aStyle )
       
   370             {
       
   371             iOutput->Write( aTimeStamp, EFalse, aEventRanking,
       
   372                                         _L8( "IMPORTANT..." ) );
       
   373             aStyle -= 0x00040;
       
   374             aTimeStamp = EFalse;    // Time stamp added no time stamp to the 
       
   375                                     // forward operations
       
   376             aEventRanking = EFalse; // Event ranking added no event ranking
       
   377                                     // to the forward operations
       
   378             }
       
   379         if ( 0x00020 <= aStyle )
       
   380             {
       
   381             aStyle -= 0x00020;
       
   382             }
       
   383         }
       
   384     // EGreen, 0x00010 => 16
       
   385     if ( 0x00010 <= aStyle )
       
   386         {
       
   387         iOutput->Write( EFalse, EFalse, EFalse,
       
   388                         _L8( "<FONT COLOR='#009900'>" ) );
       
   389         aStyle -= 0x00010;
       
   390         }
       
   391     // EBlue, 0x00008 => 8
       
   392     if ( 0x00008 <= aStyle )
       
   393         {
       
   394         iOutput->Write( EFalse, EFalse, EFalse,
       
   395                         _L8( "<FONT COLOR='#3333FF'>" ) );
       
   396         aStyle -= 0x00008;
       
   397         }
       
   398     // EUnderline, 0x00004 => 4
       
   399     if ( 0x00004 <= aStyle )
       
   400         {
       
   401         iOutput->Write( EFalse, EFalse, EFalse, _L8( "<U>" ) );
       
   402         aStyle -= 0x00004;
       
   403         }
       
   404     // ECursive, 0x00002 => 2
       
   405     if ( 0x00002 <= aStyle )
       
   406         {
       
   407         iOutput->Write( EFalse, EFalse, EFalse, _L8( "<I>" ) );
       
   408         aStyle -= 0x00002;
       
   409         }
       
   410     // EBold, 0x00001 => 1
       
   411     if ( 0x00001 <= aStyle )
       
   412         {
       
   413         iOutput->Write( EFalse, EFalse, EFalse, _L8( "<B>" ) );
       
   414         aStyle -= 0x00001;
       
   415         }
       
   416 
       
   417     }
       
   418 
       
   419 /*
       
   420 -------------------------------------------------------------------------------
       
   421 
       
   422     Class: CHtmlLogger
       
   423 
       
   424     Method: StyleEnding
       
   425 
       
   426     Description: Ends style information logging.
       
   427 
       
   428     Parameters: TInt aStyle: in: Style information
       
   429 
       
   430     Return Values: None
       
   431 
       
   432     Errors/Exceptions: None
       
   433 
       
   434     Status: Approved
       
   435 
       
   436 -------------------------------------------------------------------------------
       
   437 */
       
   438 void CHtmlLogger::StyleEnding( TInt aStyle )
       
   439     {
       
   440     if ( 0x00020 <= aStyle ||       // ERed, 0x00020 => 32
       
   441             0x00040 <= aStyle ||    // EImportant, 0x00040 => 64
       
   442             0x00080 <= aStyle ||    // EWarning, 0x00080 => 128
       
   443             0x00100 <= aStyle )     // EError, 0x00100 => 256
       
   444         {
       
   445         iOutput->Write( EFalse, EFalse, EFalse, _L8( "</FONT>" ) );
       
   446         if ( 0x00100 <= aStyle )
       
   447             {
       
   448             aStyle -= 0x00100;
       
   449             }
       
   450         if ( 0x00080 <= aStyle )
       
   451             {
       
   452             aStyle -= 0x00080;
       
   453             }
       
   454         if ( 0x00040 <= aStyle )
       
   455             {
       
   456             aStyle -= 0x00040;
       
   457             }
       
   458         if ( 0x00020 <= aStyle )
       
   459             {
       
   460             aStyle -= 0x00020;
       
   461             }
       
   462         }
       
   463     // EGreen, 0x00010 => 16
       
   464     if ( 0x00010 <= aStyle )
       
   465         {
       
   466         iOutput->Write( EFalse, EFalse, EFalse, _L8( "</FONT>" ) );
       
   467         aStyle -= 0x00010;
       
   468         }
       
   469     // EBlue, 0x00008 => 8
       
   470     if ( 0x00008 <= aStyle )
       
   471         {
       
   472         iOutput->Write( EFalse, EFalse, EFalse, _L8( "</FONT>" ) );
       
   473         aStyle -= 0x00008;
       
   474         }
       
   475     // EUnderline, 0x00004 => 4
       
   476     if ( 0x00004 <= aStyle )
       
   477         {
       
   478         iOutput->Write( EFalse, EFalse, EFalse, _L8( "</U>" ) );
       
   479         aStyle -= 0x00004;
       
   480         }
       
   481     // ECursive, 0x00002 => 2
       
   482     if ( 0x00002 <= aStyle )
       
   483         {
       
   484         iOutput->Write( EFalse, EFalse, EFalse, _L8( "</I>" ) );
       
   485         aStyle -= 0x00002;
       
   486         }
       
   487     // EBold, 0x00001 => 1
       
   488     if ( 0x00001 <= aStyle )
       
   489         {
       
   490         iOutput->Write( EFalse, EFalse, EFalse, _L8( "</B>" ) );
       
   491         aStyle -= 0x00001;
       
   492         }
       
   493 
       
   494     }
       
   495 
       
   496 /*
       
   497 -------------------------------------------------------------------------------
       
   498 
       
   499     Class: CHtmlLogger
       
   500 
       
   501     Method: Send
       
   502 
       
   503     Description: Send style information and 16 bit data to the output module
       
   504 
       
   505     Parameters: TInt TStyle: in: Text forming
       
   506                 const TDesC& aData: in: Data to be logged
       
   507 
       
   508     Return Values: TInt: Symbian error code.
       
   509 
       
   510     Errors/Exceptions: None
       
   511 
       
   512     Status: Approved
       
   513 
       
   514 -------------------------------------------------------------------------------
       
   515 */
       
   516 TInt CHtmlLogger::Send( TInt aStyle, const TDesC& aData )
       
   517     {
       
   518     // Time stamp indicator
       
   519     TBool timestamp( ETrue );
       
   520     // Event ranking indicator
       
   521     TBool eventranking( ETrue );
       
   522 
       
   523     StyleStarting( aStyle, timestamp, eventranking );
       
   524 
       
   525     TInt ret = iOutput->Write( timestamp, ETrue, eventranking, aData );
       
   526 
       
   527     StyleEnding( aStyle );
       
   528 
       
   529     return ret;
       
   530 
       
   531     }
       
   532 
       
   533 /*
       
   534 -------------------------------------------------------------------------------
       
   535 
       
   536     Class: CHtmlLogger
       
   537 
       
   538     Method: Send
       
   539 
       
   540     Description: Send style information and 8 bit data to the output module
       
   541 
       
   542     Parameters: TInt TStyle: in: Text forming
       
   543                 const TDesC8& aData: in: Data to be logged
       
   544 
       
   545     Return Values: TInt: Symbian error code.
       
   546 
       
   547     Errors/Exceptions: None
       
   548 
       
   549     Status: Approved
       
   550 
       
   551 -------------------------------------------------------------------------------
       
   552 */
       
   553 TInt CHtmlLogger::Send( TInt aStyle, const TDesC8& aData )
       
   554     {
       
   555     // Time stamp indicator
       
   556     TBool timestamp( ETrue );
       
   557     // Event ranking indicator
       
   558     TBool eventranking( ETrue );
       
   559 
       
   560     StyleStarting( aStyle, timestamp, eventranking );
       
   561 
       
   562     TInt ret = iOutput->Write( timestamp, ETrue, eventranking, aData );
       
   563 
       
   564     StyleEnding( aStyle );
       
   565 
       
   566     return ret;
       
   567 
       
   568     }
       
   569 
       
   570 // ================= OTHER EXPORTED FUNCTIONS =================================
       
   571 // None
       
   572 
       
   573 //  End of File