searcher/tsrc/logplayer/src/logplayerconsole.cpp
changeset 0 671dee74050a
equal deleted inserted replaced
-1:000000000000 0:671dee74050a
       
     1 /*
       
     2 * Copyright (c) 2010 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: 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 //  Include Files  
       
    20 
       
    21 #include "LogPlayerConsole.h"
       
    22 #include <e32base.h>
       
    23 #include <e32std.h>
       
    24 #include <e32cons.h>			// Console
       
    25 
       
    26 #include "LogPlayerManager.h"
       
    27 
       
    28 //  Constants
       
    29 
       
    30 _LIT(KTextConsoleTitle, "Console");
       
    31 _LIT(KTextFailed, " failed, leave code = %d");
       
    32 _LIT(KTextPressAnyKey, " [press any key]\n");
       
    33 
       
    34 //  Global Variables
       
    35 
       
    36 LOCAL_D CConsoleBase* console; // write all messages to this
       
    37 
       
    38 
       
    39 //  Local Functions
       
    40 
       
    41 LOCAL_C void MainL()
       
    42     {
       
    43     _LIT( KConfigurationFile, "c:\\data\\LPConf.txt" );
       
    44     _LIT( KDefaultLogFile, "c:\\data\\LPDefault.txt" );
       
    45 
       
    46 	console->Printf( _L("Starting application\n") );
       
    47     
       
    48     // Get log file names from configuration file
       
    49     RFs fs;
       
    50     User::LeaveIfError( fs.Connect() );
       
    51     CleanupClosePushL( fs );
       
    52 
       
    53     RFile file;
       
    54     TInt err = file.Open( fs, KConfigurationFile, EFileRead );
       
    55     CleanupClosePushL( file );
       
    56     
       
    57     if ( err == KErrNone ) // Read configuration file
       
    58     {
       
    59     	TInt size;
       
    60     	file.Size( size );
       
    61     	HBufC8* data = HBufC8::NewLC( size );
       
    62     	TPtr8 dataPtr = data->Des();
       
    63     	
       
    64     	User::LeaveIfError( file.Read( dataPtr ) );
       
    65     	
       
    66     	HBufC* data16 = HBufC::NewLC( size );
       
    67     	data16->Des().Copy( dataPtr );
       
    68     	
       
    69     	TLex16 lex(*data16);
       
    70     	
       
    71     	while ( !lex.Eos() )
       
    72     	{
       
    73     		TPtrC pathName = lex.NextToken();
       
    74     		
       
    75     	    CLogPlayerManager* manager = CLogPlayerManager::NewLC( pathName );
       
    76     		TRAP_IGNORE( manager->ExecuteLogL( console ) );
       
    77     		CleanupStack::PopAndDestroy( manager );
       
    78     		
       
    79     		lex.SkipSpace();
       
    80     	}
       
    81     	CleanupStack::PopAndDestroy( data16 );
       
    82     	CleanupStack::PopAndDestroy( data );
       
    83     }
       
    84     else // Use default file
       
    85     {
       
    86 	    CLogPlayerManager* manager = CLogPlayerManager::NewLC( KDefaultLogFile()  );
       
    87     	TRAP_IGNORE( manager->ExecuteLogL( console ) );
       
    88 		CleanupStack::PopAndDestroy( manager );
       
    89     }
       
    90     
       
    91     CleanupStack::PopAndDestroy( &file );
       
    92     CleanupStack::PopAndDestroy( &fs );
       
    93     }
       
    94 
       
    95 LOCAL_C void DoStartL()
       
    96     {
       
    97     // Create active scheduler (to run active objects)
       
    98     CActiveScheduler* scheduler = new (ELeave) CActiveScheduler();
       
    99     CleanupStack::PushL(scheduler);
       
   100     CActiveScheduler::Install(scheduler);
       
   101 
       
   102     MainL();
       
   103 
       
   104     // Delete active scheduler
       
   105     CleanupStack::PopAndDestroy(scheduler);
       
   106     }
       
   107 
       
   108 //  Global Functions
       
   109 
       
   110 GLDEF_C TInt E32Main()
       
   111     {
       
   112     // Create cleanup stack
       
   113     __UHEAP_MARK;
       
   114     CTrapCleanup* cleanup = CTrapCleanup::New();
       
   115 
       
   116     // Create output console
       
   117     TRAPD(createError, console = Console::NewL(KTextConsoleTitle, TSize(
       
   118             KConsFullScreen, KConsFullScreen)));
       
   119     if (createError)
       
   120         return createError;
       
   121 
       
   122     // Run application code inside TRAP harness, wait keypress when terminated
       
   123     TRAPD(mainError, DoStartL());
       
   124     if (mainError)
       
   125         console->Printf(KTextFailed, mainError);
       
   126     console->Printf(KTextPressAnyKey);
       
   127     console->Getch();
       
   128 
       
   129     delete console;
       
   130     delete cleanup;
       
   131     __UHEAP_MARKEND;
       
   132     return KErrNone;
       
   133     }
       
   134