stif/TouchConsoleUI/src/ConsoleUI.cpp
branchRCL_3
changeset 59 8ad140f3dd41
equal deleted inserted replaced
49:7fdc9a71d314 59:8ad140f3dd41
       
     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 CConsoleMain 
       
    15 * and CModule class member functions.
       
    16 *
       
    17 */
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <e32base.h>
       
    21 #include <e32cons.h>
       
    22 #include <e32svr.h>
       
    23 #include <f32file.h>
       
    24 #include <hal.h>
       
    25 #include <hal_data.h>
       
    26 
       
    27 
       
    28 
       
    29 #include <stifinternal/UIStoreIf.h>
       
    30 
       
    31 #include "ConsoleUI.h"
       
    32 #include "ConsoleMenus.h"
       
    33 
       
    34 #include "StifTestInterface.h"
       
    35 
       
    36 // EXTERNAL DATA STRUCTURES
       
    37 
       
    38 // EXTERNAL FUNCTION PROTOTYPES  
       
    39 
       
    40 // CONSTANTS
       
    41 _LIT(KNameTxt,"STIF");
       
    42 _LIT( KConsoleMain, "CConsoleMain" );
       
    43 
       
    44 // Commandline params
       
    45 _LIT( KTestModule,      "-testmodule" );
       
    46 _LIT( KTestModuleIni,   "-testmoduleini" );
       
    47 _LIT( KTestCaseFile,    "-testcasefile" );
       
    48 _LIT( KTestSet,         "-testset" );
       
    49 _LIT( KTestRun,         "-run" );
       
    50 _LIT( KTestRunAll,      "all" );
       
    51 _LIT( KTestRunSeq,      "sequential" );
       
    52 _LIT( KTestRunPar,      "parallel" );
       
    53 
       
    54 // MACROS
       
    55 
       
    56 // LOCAL CONSTANTS AND MACROS
       
    57 
       
    58 // MODULE DATA STRUCTURES
       
    59 
       
    60 // LOCAL FUNCTION PROTOTYPES
       
    61 
       
    62 // FORWARD DECLARATIONS
       
    63 LOCAL_C void MainL();
       
    64 
       
    65 
       
    66 
       
    67 // ==================== LOCAL FUNCTIONS =======================================
       
    68 
       
    69 // None
       
    70 
       
    71 
       
    72 // ================= MEMBER FUNCTIONS =========================================
       
    73 
       
    74 
       
    75 
       
    76 /*
       
    77 -------------------------------------------------------------------------------
       
    78 
       
    79     Class: CConsoleMain
       
    80 
       
    81     Method: NewL
       
    82 
       
    83     Description: Construct the console main class
       
    84 
       
    85     Parameters: None
       
    86 
       
    87     Return Values: CConsoleMain*                    New object
       
    88 
       
    89     Errors/Exceptions: Leaves if memory allocation fails or
       
    90                        ConstructL leaves.
       
    91 
       
    92     Status: Draft
       
    93 
       
    94 -------------------------------------------------------------------------------
       
    95 */
       
    96 CConsoleMain* CConsoleMain::NewL( )
       
    97     {
       
    98 
       
    99     CConsoleMain* self = new ( ELeave ) CConsoleMain();
       
   100     CleanupStack::PushL( self );
       
   101     self->ConstructL();
       
   102     CleanupStack::Pop( self );
       
   103     return self;
       
   104 
       
   105     }
       
   106 
       
   107 
       
   108 /*
       
   109 -------------------------------------------------------------------------------
       
   110 
       
   111     Class: CConsoleMain
       
   112 
       
   113     Method: ConstructL
       
   114 
       
   115     Description: Second level constructor.
       
   116 
       
   117     Construct the console
       
   118     Construct module and case containers
       
   119     Retrieve command line parameters
       
   120     Connect to test engine
       
   121 
       
   122     Parameters: None
       
   123 
       
   124     Return Values: None
       
   125 
       
   126     Errors/Exceptions: Leaves if memory allocation fails or fileserver or
       
   127                        test engine can't be connected.
       
   128 
       
   129     Status: Draft
       
   130 
       
   131 -------------------------------------------------------------------------------
       
   132 */
       
   133 void CConsoleMain::ConstructL( )
       
   134     {
       
   135     _LIT( KEnableMaximised,  "+Maximised" );
       
   136     //_LIT( KDisableMaximised, "-Maximised" );
       
   137     _LIT( KEnableInform,     "+Inform" );
       
   138     //_LIT( KDisableInform,    "-Inform" );
       
   139     _LIT( KEnableRaw,        "+Raw" );
       
   140     //_LIT( KDisableRaw,       "-Raw" );
       
   141     _LIT( KEnablePointer,    "+Pointer" );
       
   142     //_LIT( KDisablePointer,   "-Pointer" );
       
   143     //_LIT( KDescription,   "-Pointer" );
       
   144     
       
   145     CUIStoreIf::ConstructL();
       
   146 
       
   147     rConsoleCreated = false;
       
   148     // Construct the console
       
   149     //iConsole = Console::NewL( KNameTxt,
       
   150     //                         TSize( KConsFullScreen, KConsFullScreen ) );
       
   151  
       
   152     TInt ret = iConsole.Create(); 
       
   153     
       
   154     if(ret != KErrNone)
       
   155     	{
       
   156     	RDebug::Print(_L("Could not create console, err = (%d)"), ret);
       
   157     	User::Leave(ret);
       
   158     	}
       
   159     
       
   160     rConsoleCreated = true;
       
   161     
       
   162     ret = iConsole.Init(KNameTxt, TSize( KConsFullScreen, KConsFullScreen ));
       
   163     if(ret != KErrNone)
       
   164     	{
       
   165     	RDebug::Print(_L("Could not initialize console, err = (%d)"), ret);
       
   166     	User::Leave(ret);
       
   167     	}
       
   168     
       
   169     ret = iConsole.Control( KEnableMaximised );
       
   170     if(ret != KErrNone)
       
   171     	{
       
   172     	RDebug::Print(_L("Could not initialize console controls(+Maximised), err = (%d)"), ret);
       
   173     	User::Leave(ret);
       
   174     	}
       
   175     ret = iConsole.Control( KEnableInform );
       
   176     if(ret != KErrNone)
       
   177         	{
       
   178         	RDebug::Print(_L("Could not initialize console controls(+Inform), err = (%d)"), ret);
       
   179         	User::Leave(ret);
       
   180         	}
       
   181     ret = iConsole.Control( KEnablePointer );
       
   182     if(ret != KErrNone)
       
   183         	{
       
   184         	RDebug::Print(_L("Could not initialize console controls(+Pointer), err = (%d)"), ret);
       
   185         	User::Leave(ret);
       
   186         	}
       
   187     ret = iConsole.Control( KEnableRaw );
       
   188     if(ret != KErrNone)
       
   189         	{
       
   190         	RDebug::Print(_L("Could not initialize console controls(+Raw), err = (%d)"), ret);
       
   191         	User::Leave(ret);
       
   192         	}
       
   193     
       
   194     
       
   195 
       
   196     RDebug::Print(_L("Creating module list object"));
       
   197     TRAPD(err, iModuleList = CTestModuleList::NewL(NULL));
       
   198     if(err != KErrNone)
       
   199         {
       
   200         RDebug::Print(_L("Could not create module list (%d)"), err);
       
   201         UiError(_L("Could not create module list (err)"));
       
   202         User::Leave(err);
       
   203         }
       
   204     if(!iModuleList)
       
   205         {
       
   206         RDebug::Print(_L("Could not create module list (NULL)"));
       
   207         UiError(_L("Could not create module list (NULL)"));
       
   208         User::Leave(KErrGeneral);
       
   209         }
       
   210 
       
   211     // Get command line parameters
       
   212     TFileName iniFile; // TestFramework initialization file
       
   213                     
       
   214     ProcessCommandlineL( iniFile );
       
   215 
       
   216     if(iTestModule)
       
   217         {
       
   218         // Add to module list info about module taken from command line
       
   219         RDebug::Print(_L("Adding command line module to list"));
       
   220         TName moduleName;
       
   221         moduleName.Copy(iTestModule->Des());
       
   222         moduleName.LowerCase();
       
   223         err = iModuleList->AddTestModule(moduleName);
       
   224         if(err != KErrNone && err != KErrAlreadyExists)
       
   225             {
       
   226             RDebug::Print(_L("Could not add module to list of modules (%d)"), err);
       
   227             UiError(_L("Could not add module to list of modules (err)"));
       
   228             User::Leave(err);
       
   229             }
       
   230 
       
   231         //Get added module
       
   232         CTestModuleInfo* moduleInfo = iModuleList->GetModule(moduleName);
       
   233         if(!moduleInfo)
       
   234             {
       
   235             RDebug::Print(_L("Could not add get module info from list"));
       
   236             UiError(_L("Could not add get module info from list"));
       
   237             User::Leave(KErrGeneral);
       
   238             }
       
   239 
       
   240         //Add ini file if given
       
   241         if(iTestModuleIni && iTestModuleIni->Length() > 0)
       
   242             {
       
   243             TFileName filename;
       
   244             filename.Copy(iTestModuleIni->Des());
       
   245             filename.LowerCase();
       
   246             moduleInfo->SetIniFile(filename);
       
   247             }
       
   248 
       
   249         //Add config file if given
       
   250         if(iTestCaseFile && iTestCaseFile->Length() > 0)
       
   251             {
       
   252             TFileName filename;
       
   253             filename.Copy(iTestCaseFile->Des());
       
   254             filename.LowerCase();
       
   255             moduleInfo->AddCfgFile(filename);
       
   256             }
       
   257 
       
   258         //Now check all config files if there are included modules
       
   259         _LIT(KIncludeModuleStart, "[New_Include_Module]");
       
   260         _LIT(KIncludeModuleEnd, "[End_Include_Module]");
       
   261 
       
   262         RDebug::Print(_L("Start parsing included modules"));
       
   263         CTestCaseFileInfo* finfo = iModuleList->GetUncheckedCfgFile();
       
   264         while(finfo)
       
   265             {
       
   266             TFileName fname;
       
   267             finfo->GetCfgFileName(fname);
       
   268 
       
   269             RDebug::Print(_L("Checking file: '%S'"), &fname);
       
   270             finfo->SetChecked();
       
   271 
       
   272             CStifParser* parser = NULL;
       
   273  
       
   274             TRAP(err, parser = CStifParser::NewL(_L(""), fname));
       
   275             if(err != KErrNone)
       
   276                 {
       
   277                 RDebug::Print(_L("Could not create parser to read content of config file (%d)"), err);
       
   278                 UiError(_L("Could not create parser to read content of config file (err)"));
       
   279                 User::Leave(err);
       
   280                 }
       
   281             CleanupStack::PushL(parser);
       
   282 
       
   283             ParseTestModulesL(parser, iModuleList, KIncludeModuleStart, KIncludeModuleEnd);
       
   284 
       
   285             CleanupStack::PopAndDestroy(parser);
       
   286             finfo = iModuleList->GetUncheckedCfgFile();
       
   287             }
       
   288         RDebug::Print(_L("End parsing included modules"));
       
   289         }
       
   290 
       
   291     //iConsole->Printf(_L("\nTest Framework starting\n"));
       
   292     iConsole.Write(_L("\nTest Framework starting\n"));
       
   293 
       
   294     // CUIStore open
       
   295     User::LeaveIfError( UIStore().Open( iniFile ) );
       
   296     
       
   297     }
       
   298         
       
   299 /*
       
   300 -------------------------------------------------------------------------------
       
   301 
       
   302     Class: CConsoleMain
       
   303 
       
   304     Method: CConsoleMain
       
   305 
       
   306     Description: Constructor.
       
   307     Initialize non-zero member variables.
       
   308 
       
   309     Parameters: None
       
   310 
       
   311     Return Values: None
       
   312 
       
   313     Errors/Exceptions: None
       
   314 
       
   315     Status: Draft
       
   316 
       
   317 -------------------------------------------------------------------------------
       
   318 */
       
   319 CConsoleMain::CConsoleMain( ):iStartCases( EStartCaseNo )
       
   320     {
       
   321     }
       
   322 
       
   323 
       
   324 /*
       
   325 -------------------------------------------------------------------------------
       
   326 
       
   327     Class: CConsoleMain
       
   328 
       
   329     Method: ~CConsoleMain
       
   330 
       
   331     Description: Destructor
       
   332 
       
   333     Parameters: None
       
   334 
       
   335     Return Values: None
       
   336 
       
   337     Errors/Exceptions: None
       
   338 
       
   339     Status: Draft
       
   340 
       
   341 -------------------------------------------------------------------------------
       
   342 */
       
   343 CConsoleMain::~CConsoleMain( )
       
   344     {	
       
   345 
       
   346     iDialogs.ResetAndDestroy();
       
   347     iDialogs.Close();
       
   348  
       
   349     // CUIStore close
       
   350     UIStore().Close();
       
   351     
       
   352     delete iReader;
       
   353     iReader = NULL;
       
   354     
       
   355 	delete iScroller;
       
   356 	iScroller = NULL;
       
   357     
       
   358     //delete iConsole;
       
   359     //iConsole = NULL;
       
   360 	if(rConsoleCreated){
       
   361 		iConsole.Destroy();
       
   362 	}
       
   363     delete iMainMenu;
       
   364     iMainMenu = NULL;
       
   365 
       
   366     delete iTestModule;
       
   367     iTestModule = 0;
       
   368     
       
   369     delete iTestModuleIni;
       
   370     iTestModuleIni = 0;
       
   371     
       
   372     delete iTestCaseFile;
       
   373     iTestCaseFile = 0;
       
   374     
       
   375     delete iTestSetName;
       
   376     iTestSetName = 0;
       
   377 
       
   378     delete iModuleList;
       
   379     iModuleList = 0;
       
   380     
       
   381     iFilters.ResetAndDestroy();
       
   382     iFilters.Close();
       
   383     }
       
   384 
       
   385 /*
       
   386 -------------------------------------------------------------------------------
       
   387 
       
   388     Class: CConsoleMain
       
   389 
       
   390     Method: ProcessCommandlineL
       
   391 
       
   392     Description: Process commandline parameters.
       
   393 
       
   394     Parameters: None
       
   395 
       
   396     Return Values: None
       
   397 
       
   398     Errors/Exceptions: Leaves on error.
       
   399 
       
   400     Status: Draft
       
   401 
       
   402 -------------------------------------------------------------------------------
       
   403 */
       
   404 void CConsoleMain::ProcessCommandlineL( TFileName& aIniFile )
       
   405     {
       
   406 
       
   407 	User me;
       
   408     TInt lineLength = me.CommandLineLength();
       
   409     HBufC* lineBuf = HBufC::NewLC( lineLength );
       
   410     TPtr line( lineBuf->Des() );
       
   411     TBool firstTime = ETrue;
       
   412     TInt offset = 0;
       
   413     TPtrC param;
       
   414     TChar c;
       
   415     
       
   416     me.CommandLine( line );
       
   417     TLex lex( line );
       
   418     
       
   419     while( offset < lineLength )
       
   420         {    
       
   421         // Get first charecter of the parameter
       
   422         lex.SkipSpace();
       
   423         c = lex.Peek();
       
   424         if( c == 0 )
       
   425             {
       
   426             // End of line
       
   427             break;
       
   428             }
       
   429         
       
   430         // Get the whole parameter 
       
   431         param.Set( lex.NextToken() );
       
   432         if( firstTime )
       
   433             {
       
   434             // Filebrowser workaround. It gives the exe name as command line param
       
   435             // verify that it is not the same as the executable name
       
   436             //@spe TFileName exePath = me.FileName();
       
   437 			TFileName exePath = RProcess().FileName();
       
   438             if ( param == exePath )
       
   439                 {
       
   440                 // Discard command line parameters when using filebrowser
       
   441                 break;
       
   442                 }
       
   443 
       
   444             firstTime = EFalse;
       
   445             }
       
   446         // Check if -param option
       
   447         if( c == '-' )
       
   448             {
       
   449             // This is option
       
   450             if( param == KTestModule )
       
   451                 {
       
   452                 // Get test module name
       
   453                 param.Set( lex.NextToken() );
       
   454                 if( param.Length() == 0 )
       
   455                     {
       
   456                     UiError( _L("Test module name not given"));
       
   457                     break;
       
   458                     }
       
   459                 if( param.Length() > KMaxName )
       
   460                     {
       
   461                     UiError( _L("Test module name too long"));
       
   462                     break;
       
   463                     }
       
   464                 iTestModule = param.AllocL();
       
   465                 }
       
   466             else if( param == KTestModuleIni )
       
   467                 {
       
   468                 // Get test module initialization file
       
   469                 param.Set( lex.NextToken() );
       
   470                 if( param.Length() == 0 )
       
   471                     {
       
   472                     UiError( _L("Test module initialization file name not given"));
       
   473                     break;
       
   474                     }
       
   475                 if( param.Length() > KMaxFileName )
       
   476                     {
       
   477                     UiError( _L("Test module initialization file name too long"));
       
   478                     break;
       
   479                     }
       
   480                 TFileName tmpTestModuleIni( param );
       
   481                 TStifUtil::CorrectFilePathL( tmpTestModuleIni );
       
   482                 iTestModuleIni = tmpTestModuleIni.AllocL();
       
   483                 }
       
   484             else if( param == KTestCaseFile )
       
   485                 {
       
   486                 // Get test case file name
       
   487                 param.Set( lex.NextToken() );
       
   488                 if( param.Length() == 0 )
       
   489                     {
       
   490                     UiError( _L("Test case file name not given"));
       
   491                     break;
       
   492                     }
       
   493                 if( param.Length() > KMaxFileName )
       
   494                     {
       
   495                     UiError( _L("Test case file name too long"));
       
   496                     break;
       
   497                     }
       
   498                 TFileName tmpTestCaseFile( param );
       
   499                 TStifUtil::CorrectFilePathL( tmpTestCaseFile );
       
   500                 iTestCaseFile = tmpTestCaseFile.AllocL();
       
   501                 }
       
   502             else if( param == KTestSet )
       
   503                 {
       
   504                 // Get test set name
       
   505                 param.Set( lex.NextToken() );
       
   506                 if( param.Length() == 0 )
       
   507                     {
       
   508                     UiError( _L("Test set name not given"));
       
   509                     break;
       
   510                     }
       
   511                 if( param.Length() > KMaxFileName )
       
   512                     {
       
   513                     UiError( _L("Test set name too long"));
       
   514                     
       
   515                     break;
       
   516                     }
       
   517                 iTestSetName = param.AllocL();
       
   518                 }
       
   519             else if( param == KTestRun )
       
   520                 {
       
   521                 if( iStartCases )
       
   522                     {
       
   523                     UiError( _L("Only one -run option allowed") );
       
   524                     // Do not start anything
       
   525                     iStartCases = EStartCaseNo;
       
   526                     break;
       
   527                     }
       
   528                 // Get run type
       
   529                 lex.Mark();
       
   530                 param.Set( lex.NextToken() );
       
   531                 if( param.Length() == 0 )
       
   532                     {
       
   533                     UiError( _L("Test set name not given"));
       
   534                     break;
       
   535                     }
       
   536                 if( ( param == KTestRunAll ) ||
       
   537                     ( param == KTestRunSeq ) )
       
   538                     {
       
   539                     iStartCases = EStartCasesSeq;
       
   540                     }
       
   541                 else if( param == KTestRunPar )
       
   542                     {
       
   543                     iStartCases = EStartCasesPar;
       
   544                     }
       
   545                 else
       
   546                     {
       
   547                     lex.UnGetToMark();
       
   548                     lex.SkipSpace();
       
   549                     if( lex.Val( iTestCaseNum ) != KErrNone )
       
   550                         { 
       
   551                         UiError( _L("Unknown run type given, valid values are all/sequential/parallel/test case number"));
       
   552                         }
       
   553                     else
       
   554                         {
       
   555                         iStartCases = EStartSingleCase;
       
   556                         }    
       
   557                     break;
       
   558                     }
       
   559                 }            
       
   560             }
       
   561         else 
       
   562             {
       
   563             // This is Test Framework ini file
       
   564             aIniFile = param;
       
   565             TStifUtil::CorrectFilePathL( aIniFile );
       
   566             // ini file is last option
       
   567             break;
       
   568             }
       
   569         
       
   570         }
       
   571       
       
   572     CleanupStack::PopAndDestroy( lineBuf );
       
   573 
       
   574     }
       
   575     
       
   576     
       
   577 /*
       
   578 -------------------------------------------------------------------------------
       
   579 
       
   580     Class: CConsoleMain
       
   581 
       
   582     Method: Panic
       
   583 
       
   584     Description: Console UI panic function
       
   585 
       
   586     Parameters: TInt
       
   587 
       
   588     Return Values: 
       
   589 
       
   590     Errors/Exceptions: Does not return.
       
   591 
       
   592     Status: Draft
       
   593 
       
   594 -------------------------------------------------------------------------------
       
   595 */
       
   596 void CConsoleMain::Panic(TConsoleUIPanic aPanic )
       
   597     {
       
   598         
       
   599     User::Panic (_L("STIF TestFramework Console UI panic"), aPanic );
       
   600     
       
   601     }
       
   602 
       
   603 
       
   604 /*
       
   605 -------------------------------------------------------------------------------
       
   606 
       
   607     Class: CConsoleMain
       
   608 
       
   609     Method: StartL
       
   610 
       
   611     Description: Construct menu objects and start the menu handling
       
   612 
       
   613     Parameters: None
       
   614 
       
   615     Return Values: None
       
   616 
       
   617     Errors/Exceptions:
       
   618 
       
   619     Status: Draft
       
   620 
       
   621 -------------------------------------------------------------------------------
       
   622 */
       
   623 TInt CConsoleMain::StartL()
       
   624     {
       
   625     
       
   626     // Construct keystroke reader
       
   627     iReader           = CConsoleReader::NewL( this, &iConsole );
       
   628 
       
   629     // Construct the main menu
       
   630     TInt majorV;
       
   631     TInt minorV;
       
   632     TInt buildV;
       
   633     TBuf<30> relDate;
       
   634     TStifUtil::STIFVersion(majorV, minorV, buildV, relDate);
       
   635     
       
   636     TBuf<128> version;
       
   637     version.Format(_L("STIF v%d.%d.%d - "), majorV, minorV, buildV);
       
   638     version.Append(relDate);
       
   639     version.Append(_L("\n"));
       
   640     iMainMenu = CMainMenu::NewL( this, NULL, _L("Main menu"), version );
       
   641 
       
   642     // Add the case menu
       
   643     CMenu* caseMenu   = CMenu::NewL( this, iMainMenu, _L("Case menu") );
       
   644     iMainMenu->AddItemL ( caseMenu );
       
   645 
       
   646     // Add the module menu
       
   647     CMenu* moduleMenu = CModuleListView::NewL( this, iMainMenu, _L("Module menu") );
       
   648     iMainMenu->AddItemL ( moduleMenu );
       
   649 
       
   650     // Add test set menu
       
   651     CTestSetMenu* testSetMenu = CTestSetMenu::NewL( this, iMainMenu, _L("Test set menu") );
       
   652     iMainMenu->AddItemL ( testSetMenu );
       
   653  
       
   654     // Construct the case menus
       
   655     CMenu* casestart  = NULL;
       
   656     CMenu* casestartshow  = NULL;
       
   657     
       
   658     // Load filters
       
   659     UIStore().ReadFiltersL(iFilters);
       
   660     
       
   661     // If there are no filters defined, then construct menu without filter's menu
       
   662     if(iFilters.Count() == 0)
       
   663         {
       
   664         casestart = CCaseStartMenu::NewL(this, caseMenu, _L("Start new case"));
       
   665         caseMenu->AddItemL(casestart);
       
   666     CMenu* casestartshow  = NULL;
       
   667         casestartshow = CCaseStartMenu::NewL(this, caseMenu, _L("Start & show output"), ETrue);
       
   668         caseMenu->AddItemL(casestartshow);
       
   669         }
       
   670     else // if there are filters defined, create also filter's menu
       
   671         {
       
   672         CFilterMenu* filtercasestart = NULL;
       
   673         CFilterMenu* filtercasestartshow = NULL;
       
   674         
       
   675         filtercasestart = CFilterMenu::NewL(this, caseMenu, _L("Start new case (filter)"));
       
   676         caseMenu->AddItemL(filtercasestart);
       
   677         casestart = CCaseStartMenu::NewL(this, caseMenu, _L("Start new case"));
       
   678         filtercasestart->SetTestCaseMenu(casestart);
       
   679         
       
   680         filtercasestartshow = CFilterMenu::NewL(this, caseMenu, _L("Start & show output (filter)"));
       
   681         caseMenu->AddItemL(filtercasestartshow);
       
   682         casestartshow = CCaseStartMenu::NewL(this, caseMenu, _L("Start & show output"), ETrue);
       
   683         filtercasestartshow->SetTestCaseMenu(casestartshow);
       
   684         }
       
   685 
       
   686 	CMultipleCaseMenu* multicasestart =
       
   687 	    CMultipleCaseMenu::NewL (this, caseMenu, _L("Run multiple tests") );
       
   688     caseMenu->AddItemL( multicasestart );
       
   689     casestart = CCaseMenu::NewL ( this, caseMenu, _L("Ongoing cases"), 
       
   690         CUIStoreIf::EStatusRunning );
       
   691     caseMenu->AddItemL( casestart );
       
   692     casestart = CCaseMenu::NewL ( this, caseMenu, _L("Executed cases"), 
       
   693         CUIStoreIf::EStatusExecuted );
       
   694     caseMenu->AddItemL( casestart );
       
   695     casestart = CCaseMenu::NewL ( this, caseMenu, _L("Passed cases"), 
       
   696         CUIStoreIf::EStatusPassed );
       
   697     caseMenu->AddItemL( casestart );
       
   698     casestart = CCaseMenu::NewL ( this, caseMenu, _L("Failed cases"), 
       
   699         CUIStoreIf::EStatusFailed );
       
   700     caseMenu->AddItemL( casestart );
       
   701     casestart = CCaseMenu::NewL ( this, caseMenu, _L("Aborted/Crashed cases"), 
       
   702         ( CUIStoreIf::EStatusAborted | CUIStoreIf::EStatusCrashed) );
       
   703     caseMenu->AddItemL( casestart );
       
   704     //Add "test set choice" menu
       
   705     CTestSetChoiceMenu* testChoiceMenu = CTestSetChoiceMenu::NewL( this, testSetMenu, _L("Load test set") );
       
   706  	testSetMenu->AddItemL( testChoiceMenu );
       
   707 
       
   708     // Start stuff according to command line parameters
       
   709     if( iTestSetName )
       
   710         { 
       
   711         // Set test set name
       
   712         testSetMenu->SetTestSetFileName( iTestSetName->Des() );
       
   713         
       
   714         // Load test set
       
   715         if( UIStore().LoadTestSet( iTestSetName->Des() ) != KErrNone )
       
   716  	       {
       
   717            UiError( _L("Test set loading failed"));
       
   718            }
       
   719         else 
       
   720            {
       
   721            // Inform test set menu that set is loaded
       
   722            testSetMenu->SetCreated();
       
   723     
       
   724             // Check if test set should be started
       
   725     	    if( ( iStartCases == EStartCasesPar ) || 
       
   726     	    	( iStartCases == EStartCasesSeq ))         	
       
   727             	{
       
   728             
       
   729 	            // Check set starting type
       
   730     	    	CStartedTestSet::TSetType setType = 
       
   731        	        CStartedTestSet::ESetSequential;
       
   732        	        
       
   733                 if( iStartCases == EStartCasesPar )
       
   734                     {
       
   735                     setType = 
       
   736                         CStartedTestSet::ESetParallel;
       
   737                     }
       
   738                     
       
   739                 // Start test set
       
   740                 RRefArray<CTestSetInfo> setInfos;
       
   741                 TInt ret = UIStore().TestSets( setInfos );
       
   742                 if( (  ret != KErrNone ) ||
       
   743                     ( setInfos.Count() != 1 ) )
       
   744                     {
       
   745                     // Should never ever happen
       
   746                     User::Panic( KConsoleMain, KErrGeneral );
       
   747                     }
       
   748                 
       
   749                 const CTestSetInfo& set = setInfos[0];
       
   750                 setInfos.Reset();
       
   751                 setInfos.Close();
       
   752                 
       
   753                 TInt index;
       
   754                 ret = UIStore().StartTestSet( set, index, setType );
       
   755                 if( ret != KErrNone )
       
   756                     {
       
   757                     UiError( _L("Test set starting failed") );
       
   758                     }
       
   759                 } 
       
   760             }
       
   761         delete iTestSetName;
       
   762         iTestSetName = 0;     
       
   763         }
       
   764     if( iTestModule )
       
   765         {
       
   766         TPtrC module( iTestModule->Des() ); 
       
   767 
       
   768         // Add all test modules and config files
       
   769         RDebug::Print(_L("Start creating test modules"));
       
   770         CTestModuleInfo* moduleInfo = NULL;
       
   771         TInt i;
       
   772         TInt modCnt = iModuleList->Count();
       
   773         TInt ret;
       
   774 
       
   775         for(i = 0; i < modCnt; i++)
       
   776             {
       
   777             RDebug::Print(_L("Processing module"));
       
   778             // Get module
       
   779             moduleInfo = iModuleList->GetModule(i);
       
   780             if(!moduleInfo)
       
   781                 {
       
   782                 RDebug::Print(_L("Could not get module info at index %d"), i);
       
   783                 continue;
       
   784                 }
       
   785 
       
   786             // Get module name
       
   787             TName moduleName;
       
   788             moduleInfo->GetModuleName(moduleName);
       
   789             RDebug::Print(_L("module name: '%S'"), &moduleName);
       
   790 
       
   791             // Get ini file, if exists
       
   792             TFileName ini;
       
   793             moduleInfo->GetIniFileName(ini);
       
   794             if(ini.Length() == 0)
       
   795                 {
       
   796                 RDebug::Print(_L("ini file not found"));
       
   797                 }
       
   798             else
       
   799                 {
       
   800                 RDebug::Print(_L("ini file: '%S'"), &ini);
       
   801                 }
       
   802 
       
   803             // Create test module
       
   804             RDebug::Print(_L("Adding module to UI store"));
       
   805             ret = UIStore().AddTestModule(moduleName, ini);
       
   806             if(ret != KErrNone && ret != KErrAlreadyExists)
       
   807                 {
       
   808                 RDebug::Print(_L("Test module adding failed (%d)"), ret);
       
   809                 UiError(_L("Test module adding failed"));
       
   810                 continue;
       
   811                 }
       
   812 
       
   813             //Add test case files
       
   814             TInt cfgCnt = moduleInfo->CountCfgFiles();
       
   815             TInt j;
       
   816             TFileName cfgFile;
       
   817             for(j = 0; j < cfgCnt; j++)
       
   818                 {
       
   819                 moduleInfo->GetCfgFileName(j, cfgFile);
       
   820                 if(cfgFile.Length() > 0)
       
   821                     {
       
   822                     RDebug::Print(_L("config file: '%S'"), &cfgFile);
       
   823 
       
   824                     ret = UIStore().AddTestCaseFile(moduleName, cfgFile);
       
   825                     if(ret != KErrNone)
       
   826                         {
       
   827                         // Log error
       
   828                         RDebug::Print(_L("Test case file adding failed (%d)"), ret);
       
   829                         UiError(_L("Test case file adding failed"));
       
   830                         continue;
       
   831                         }
       
   832                     }
       
   833                 else
       
   834                     {
       
   835                     RDebug::Print(_L("Got empty cfg file"));
       
   836                     }
       
   837                 }
       
   838             if(cfgCnt == 0)
       
   839                 {
       
   840                 RDebug::Print(_L("cfg file not found"));
       
   841                 }
       
   842 
       
   843             RDebug::Print(_L("Module '%S' processed correctly"), &moduleName);
       
   844             }
       
   845 
       
   846         RDebug::Print(_L("End creating test modules"));
       
   847 
       
   848         if( ( iStartCases == EStartCasesPar ) ||
       
   849             ( iStartCases == EStartCasesSeq ) )
       
   850             {
       
   851             // Start running
       
   852             CMultipleBaseMenu::TRunType runType = 
       
   853                 CMultipleBaseMenu::ERunSequential;
       
   854             if( iStartCases == EStartCasesPar )
       
   855                 {
       
   856                 runType = CMultipleBaseMenu::ERunParallel;
       
   857                 }
       
   858             TRAPD( err,
       
   859                 //multicasestart->StartRunningL( runType, module, file );
       
   860                 multicasestart->StartRunningL(runType, KNullDesC, KNullDesC);
       
   861                 );
       
   862             if( err != KErrNone )
       
   863                 {
       
   864                 UiError( _L("Stating test cases failed") );
       
   865                 }
       
   866             }
       
   867         else if( iStartCases == EStartSingleCase )
       
   868             {
       
   869             // Get test case
       
   870             RRefArray<CTestInfo> testCases;
       
   871             //ret = UIStore().TestCases( testCases, module, file );
       
   872             ret = UIStore().TestCases(testCases, KNullDesC, KNullDesC);
       
   873             if( ret == KErrNone )
       
   874                 {
       
   875                 if( ( iTestCaseNum < 0 ) ||
       
   876                     ( iTestCaseNum >= testCases.Count() ) )
       
   877                     {
       
   878                     ret = KErrNotFound;
       
   879                     }
       
   880                 else
       
   881                     {         
       
   882                     TInt index;           
       
   883                     // Start single test case
       
   884                     ret = UIStore().StartTestCase( testCases[iTestCaseNum], index );
       
   885                     }                                       
       
   886                 }
       
   887             testCases.Reset();       
       
   888             testCases.Close();
       
   889             if( ret != KErrNone )
       
   890                 {
       
   891                 UiError( _L("Starting test case failed"));        
       
   892                 }
       
   893             }
       
   894 
       
   895         delete iTestCaseFile;
       
   896         iTestCaseFile = 0;
       
   897         delete iTestModuleIni;
       
   898         iTestModuleIni = 0;
       
   899         delete iTestModule;
       
   900         iTestModule = 0;
       
   901         }
       
   902         
       
   903     iStartCases = EStartCaseNo;
       
   904     
       
   905     // Load testcase if some stored 
       
   906     UIStore().LoadSavedTestCases();
       
   907            
       
   908 	iScroller = CScrollerTimer::NewL ( this );
       
   909 	iScroller->StartL();	
       
   910 
       
   911     // Print the main menu
       
   912     iCurrentMenu = iMainMenu;
       
   913     iCurrentMenu->PrintMenuL( CMenu::EMenuPrint );
       
   914 
       
   915     // Start to process keyboard events
       
   916     iReader->StartL();
       
   917     
       
   918     return KErrNone;
       
   919 
       
   920     }
       
   921 
       
   922 
       
   923 /*
       
   924 -------------------------------------------------------------------------------
       
   925 
       
   926     Class: CConsoleMain
       
   927 
       
   928     Method: KeyPressed
       
   929 
       
   930     Description: Process keyboard events. Print new menu
       
   931 
       
   932     Parameters: None
       
   933 
       
   934     Return Values: None
       
   935 
       
   936     Errors/Exceptions: Leaves if SelectL leaves
       
   937 
       
   938     Status: Draft
       
   939 
       
   940 -------------------------------------------------------------------------------
       
   941 */
       
   942 void CConsoleMain::KeyPressed()
       
   943     {
       
   944 
       
   945     TBool cont = ETrue;
       
   946 
       
   947     // Read the key
       
   948    // TKeyCode key = iConsole->KeyCode();
       
   949     
       
   950     TKeyCode key = mapKey();
       
   951     if(key == EKeyNull)
       
   952     	{
       
   953     	iReader->StartL();
       
   954     	return;
       
   955     	}
       
   956 //    TKeyCode key = EKeyDownArrow; //TODO
       
   957     CMenu* tmp = iCurrentMenu;
       
   958 
       
   959     // Let the menu handle the key press
       
   960     TRAPD( err, 
       
   961         iCurrentMenu = iCurrentMenu->SelectL( key, cont );
       
   962         );
       
   963     if( err != KErrNone )
       
   964         {
       
   965         User::InfoPrint( 
       
   966             _L("Processing keystroke failed") );  
       
   967         }
       
   968             
       
   969     if ( iCurrentMenu == NULL )
       
   970         {
       
   971         iCurrentMenu = tmp;
       
   972         }
       
   973 
       
   974    // If "not-exit" key pressed, continue
       
   975     if ( cont )
       
   976         {
       
   977 
       
   978         // Either only update old menu or new menu.
       
   979         if ( tmp == iCurrentMenu )
       
   980             {
       
   981             TRAP( err, iCurrentMenu->PrintMenuL( CMenu::EMenuRefresh ); );
       
   982             }
       
   983         else
       
   984             {
       
   985             TRAP( err, iCurrentMenu->PrintMenuL( CMenu::EMenuPrint ); )
       
   986             }
       
   987         
       
   988         if( err != KErrNone )
       
   989             {
       
   990             if ( err == KErrNoMemory )
       
   991             	{            	
       
   992             	ExitWithNoMemoryErrorMessage();                
       
   993             	}
       
   994             else
       
   995             	{
       
   996 	            User::InfoPrint( 
       
   997 	                _L("Printing menu failed") );
       
   998             	}
       
   999             }
       
  1000 
       
  1001         // Enable keystrokes
       
  1002         iReader->StartL();
       
  1003 
       
  1004         }
       
  1005     else
       
  1006         {
       
  1007         // "Exit", stop scheduler and exit
       
  1008         CActiveScheduler::Stop();
       
  1009         }
       
  1010 
       
  1011     }
       
  1012 
       
  1013 
       
  1014 TKeyCode CConsoleMain::mapKey()
       
  1015 	{
       
  1016 	TInt event   = key.Type();
       
  1017 	TInt keyCode = key.Code();
       
  1018 	
       
  1019 	if( event == TRawEvent::EButton1Down )
       
  1020 		{
       
  1021 		TInt ret;
       
  1022 		//displayXPixels contains X of screen resolution
       
  1023 		TInt displayXPixels;    
       
  1024 		//retrieve EDisplayXPixels value of this phone
       
  1025 		ret = HAL::Get( HALData::EDisplayXPixels, displayXPixels );
       
  1026 		 
       
  1027 		//displayYPixelscontains Y of screen resolution
       
  1028 		TInt displayYPixels;    
       
  1029 		//retrieve EDisplayYPixels value of this phone
       
  1030 		ret =HAL::Get( HALData::EDisplayYPixels, displayYPixels );
       
  1031 		
       
  1032 		if(ret != KErrNone)
       
  1033 			{
       
  1034 			UiError( _L("Unable to get screen resolution"));
       
  1035 			}
       
  1036 		
       
  1037 	//if(keyCode ==EKeyEnter )
       
  1038 		TPoint currPos = key.MousePos();	
       
  1039 		if(currPos.iY < ((displayYPixels/2)-(displayYPixels*0.3)) && currPos.iX < (displayXPixels -(displayXPixels*0.2)) && currPos.iX >(displayXPixels*0.3) )
       
  1040 			{
       
  1041 			return EKeyUpArrow;
       
  1042 			}
       
  1043 		else if(currPos.iY > (displayYPixels/2+(displayYPixels*0.3))&& currPos.iX < (displayXPixels -(displayXPixels*0.2)) && currPos.iX >(displayXPixels*0.3))
       
  1044 			{
       
  1045 			return EKeyDownArrow;
       
  1046 			}
       
  1047 		if(currPos.iX < ((displayXPixels/2)-(displayXPixels*0.3)) && currPos.iY < (displayYPixels -(displayYPixels*0.2)) && currPos.iY >(displayYPixels*0.3) )
       
  1048 			{
       
  1049 			return EKeyLeftArrow;
       
  1050 			}
       
  1051 		else if(currPos.iX > (displayXPixels/2+(displayXPixels*0.3))&& currPos.iY < (displayYPixels -(displayYPixels*0.2)) && currPos.iY >(displayYPixels*0.3))
       
  1052 			{
       
  1053 			return EKeyRightArrow;
       
  1054 			}
       
  1055 		
       
  1056 		
       
  1057 		}
       
  1058 	else if (event == TRawEvent::EKeyDown)
       
  1059 		{
       
  1060 		 switch (keyCode) 
       
  1061 			{
       
  1062 			case 16:
       
  1063 				return EKeyUpArrow;
       
  1064 			case 17:
       
  1065 				return EKeyDownArrow;
       
  1066 			case 15:
       
  1067 				return EKeyRightArrow;
       
  1068 			case 14:
       
  1069 				return EKeyLeftArrow;
       
  1070 			case 851971:
       
  1071 				return EKeyEnter;
       
  1072 			case 4:
       
  1073 				return EKeyEscape;
       
  1074 				
       
  1075 			// Additional keys
       
  1076 			case 180: 
       
  1077 				return EKeyHome;
       
  1078 							
       
  1079 			default:
       
  1080 				return EKeyNull;
       
  1081 
       
  1082 			}
       
  1083 		}
       
  1084 	return EKeyNull;
       
  1085 	}
       
  1086 
       
  1087 
       
  1088 /*
       
  1089 -------------------------------------------------------------------------------
       
  1090 
       
  1091     Class: CConsoleMain
       
  1092 
       
  1093     Method: ExitWithNoMemoryErrorMessage
       
  1094 
       
  1095     Description: Displays no memory error message and closes ConsoleUI
       
  1096     
       
  1097     Parameters: None
       
  1098 
       
  1099     Return Values: None
       
  1100 
       
  1101     Errors/Exceptions: None
       
  1102 
       
  1103     Status: Approved
       
  1104 
       
  1105 -------------------------------------------------------------------------------
       
  1106 */
       
  1107 void CConsoleMain::ExitWithNoMemoryErrorMessage()
       
  1108 	{
       
  1109     // "Exit", stop scheduler and exit
       
  1110     CActiveScheduler::Stop();
       
  1111 
       
  1112     _LIT( KErrorTitle, "Error:\n" );
       
  1113     _LIT( KErrorMessage, "Test cases execution have been stopped. ConsoleUI does not have enough memory to store information about executed test cases.  Results of executed test cases can be found in TestReport file. ConsoleUI will be closed now." );
       
  1114     _LIT( KErrorPressAnyKey, "\n\nPress any key" );
       
  1115     
       
  1116 //    TSize size = GetConsole()->ScreenSize();
       
  1117     TSize size;
       
  1118     GetConsole()->Size(size);
       
  1119     size.iWidth = Min( size.iWidth - KMenuOverhead, 
       
  1120                        KErrorMessage().Length() );
       
  1121     size.iHeight = ( KErrorTitle().Length() + KErrorMessage().Length() + 
       
  1122     				 KErrorPressAnyKey().Length() ) / size.iWidth + 3;
       
  1123     
       
  1124     CConsoleBase* console = NULL;
       
  1125     TRAPD( err, console = Console::NewL( _L("Error note"), size ) );
       
  1126     if ( err != KErrNone )
       
  1127     	{
       
  1128     	// We can't create console, exit without displaying error message
       
  1129     	return;
       
  1130     	}
       
  1131     
       
  1132     console->Printf( KErrorTitle );    
       
  1133     console->Printf( KErrorMessage ); 
       
  1134     console->Printf( KErrorPressAnyKey );
       
  1135         
       
  1136     console->Getch();
       
  1137     
       
  1138     delete console;    
       
  1139 	}
       
  1140 
       
  1141 /*
       
  1142 -------------------------------------------------------------------------------
       
  1143 
       
  1144     Class: CConsoleMain
       
  1145 
       
  1146     Method: UiError
       
  1147 
       
  1148     Description: Function is called when UI hit an error.
       
  1149     
       
  1150     Parameters: const TDesC& aInfo: in: information
       
  1151 
       
  1152     Return Values: None
       
  1153 
       
  1154     Errors/Exceptions: None
       
  1155 
       
  1156     Status: Draft
       
  1157 
       
  1158 -------------------------------------------------------------------------------
       
  1159 */
       
  1160 
       
  1161 void CConsoleMain::UiError( const TDesC& aInfo )
       
  1162     {
       
  1163     
       
  1164     // Error note deletes itself when it completes
       
  1165     CMenuNotifier::NewL( aInfo, this );
       
  1166     
       
  1167     }
       
  1168     
       
  1169 /*
       
  1170 -------------------------------------------------------------------------------
       
  1171 
       
  1172     Class: CConsoleMain
       
  1173 
       
  1174     Method: Update
       
  1175 
       
  1176     Description: Receives output update notification from CUIStore.
       
  1177     
       
  1178     Parameters: CStartedTestCase* aTestCase: in: Test case information
       
  1179                 TInt aFlags: in: Update reason flags
       
  1180 
       
  1181     Return Values: None
       
  1182 
       
  1183     Errors/Exceptions: None
       
  1184 
       
  1185     Status: Draft
       
  1186 
       
  1187 -------------------------------------------------------------------------------
       
  1188 */
       
  1189 void CConsoleMain::Update( CStartedTestCase* aTestCase, TInt aFlags )
       
  1190     {
       
  1191     
       
  1192    	TInt err( KErrNone );
       
  1193     
       
  1194     // First check if some menu should be signaled 
       
  1195     if( ( aFlags & CUIStoreIf::EStatusExecuted ) &&
       
  1196         ( aTestCase->iBackPtr ) )
       
  1197         {
       
  1198         CMenu* menu = ( CMenu* )aTestCase->iBackPtr;
       
  1199         TRAP( err, 
       
  1200             menu->SignalL( aTestCase ); 
       
  1201             );            
       
  1202         }
       
  1203 
       
  1204     // Update console if needed
       
  1205     if( iCurrentMenu && ( iCurrentMenu->Type() & aFlags ) )
       
  1206         {
       
  1207         if( aFlags & CUIStoreIf::EPrintUpdate )
       
  1208             {
       
  1209             CCaseExecutionView* view = 
       
  1210                 ( CCaseExecutionView* )iCurrentMenu;
       
  1211             if( view->TestCase() == aTestCase )
       
  1212                 {
       
  1213                 TRAP( err, iCurrentMenu->PrintMenuL( CMenu::EMenuRefresh ) );
       
  1214                 }
       
  1215             }
       
  1216         else
       
  1217             {
       
  1218             TRAP( err, iCurrentMenu->PrintMenuL( CMenu::EMenuRefresh ); )
       
  1219             }
       
  1220         }
       
  1221     
       
  1222     	if ( err != KErrNone )
       
  1223     		{
       
  1224     		if ( err == KErrNoMemory )
       
  1225     			{
       
  1226     			ExitWithNoMemoryErrorMessage();
       
  1227     			}
       
  1228     		}
       
  1229     
       
  1230     }
       
  1231                                                               
       
  1232 
       
  1233 
       
  1234 /*
       
  1235 -------------------------------------------------------------------------------
       
  1236 
       
  1237     Class: CConsoleMain
       
  1238 
       
  1239     Method: Error
       
  1240 
       
  1241     Description: Function is called when test framework prints error.
       
  1242     
       
  1243     Parameters: TErrorNotification& aError: in: Error description
       
  1244 
       
  1245     Return Values: None
       
  1246 
       
  1247     Errors/Exceptions: None
       
  1248 
       
  1249     Status: Draft
       
  1250 
       
  1251 -------------------------------------------------------------------------------
       
  1252 */
       
  1253 
       
  1254 void CConsoleMain::Error( TErrorNotification& aError )
       
  1255     {
       
  1256     
       
  1257     // Error note deletes itself when it completes
       
  1258     CMenuNotifier::NewL( aError.iText, this );
       
  1259     
       
  1260     }
       
  1261 
       
  1262 /*
       
  1263 -------------------------------------------------------------------------------
       
  1264 
       
  1265     Class: CConsoleMain
       
  1266 
       
  1267     Method: PopupMsg
       
  1268 
       
  1269     Description: Function is called when testframework 
       
  1270         wants to print a popup window.
       
  1271     
       
  1272     Parameters: TDesC& aMsg: in: message
       
  1273                 
       
  1274 
       
  1275     Return Values: Symbian OS error code
       
  1276 
       
  1277     Errors/Exceptions: None
       
  1278 
       
  1279     Status: Draft
       
  1280 
       
  1281 -------------------------------------------------------------------------------
       
  1282 */
       
  1283 
       
  1284 TInt CConsoleMain::PopupMsg( const TDesC& aLine1, 
       
  1285                              const TDesC& aLine2, 
       
  1286                              TInt aTimeInSecs )
       
  1287     {
       
  1288     
       
  1289     TInt ret = KErrNone;
       
  1290     
       
  1291     CMenuDialog* dialog = NULL;
       
  1292 
       
  1293     TRAP( ret, dialog = CMenuDialog::NewL( this, aLine1, aLine2, aTimeInSecs ); );
       
  1294 
       
  1295     if( ret == KErrNone )
       
  1296         {
       
  1297         iDialogs.Append( dialog ); 
       
  1298         return (TInt)dialog;
       
  1299         }
       
  1300 
       
  1301     return ret;
       
  1302     
       
  1303     }
       
  1304 
       
  1305 /*
       
  1306 -------------------------------------------------------------------------------
       
  1307 
       
  1308     Class: CConsoleMain
       
  1309 
       
  1310     Method: PopupMsg
       
  1311 
       
  1312     Description: Function is called when testframework 
       
  1313         wants to print a popup window.
       
  1314     
       
  1315     Parameters: TDesC& aMsg: in: message
       
  1316                 
       
  1317 
       
  1318     Return Values: Symbian OS error code
       
  1319 
       
  1320     Errors/Exceptions: None
       
  1321 
       
  1322     Status: Draft
       
  1323 
       
  1324 -------------------------------------------------------------------------------
       
  1325 */
       
  1326 
       
  1327 TInt CConsoleMain::PopupMsg( const TDesC& aLine1, 
       
  1328                              const TDesC& aLine2, 
       
  1329                              TInt aTimeInSecs,
       
  1330                              TKeyCode& aKey,
       
  1331                              TRequestStatus& aStatus )
       
  1332     {
       
  1333     
       
  1334     TInt ret = PopupMsg( aLine1, aLine2, aTimeInSecs );
       
  1335     if( ret < 0 )
       
  1336         {
       
  1337         return ret;
       
  1338         }    
       
  1339         
       
  1340     CMenuDialog* dialog = (CMenuDialog*) ret; 
       
  1341     ret = dialog->WaitForKeypress( aKey, aStatus );
       
  1342 
       
  1343     return (TInt) dialog;
       
  1344     
       
  1345     }
       
  1346 /*
       
  1347 -------------------------------------------------------------------------------
       
  1348 
       
  1349     Class: CConsoleMain
       
  1350 
       
  1351     Method: Close
       
  1352 
       
  1353     Description: Close instance.
       
  1354     
       
  1355     Parameters: TInt aHandle: in: handle to open instance.                
       
  1356 
       
  1357     Return Values: Symbian OS error code
       
  1358 
       
  1359     Errors/Exceptions: None
       
  1360 
       
  1361     Status: Draft
       
  1362 
       
  1363 -------------------------------------------------------------------------------
       
  1364 */
       
  1365 void CConsoleMain::Close( TInt aHandle )
       
  1366     {
       
  1367     
       
  1368     if( aHandle < 0 )
       
  1369         {
       
  1370         return;
       
  1371         }
       
  1372     CMenuDialog* dialog = (CMenuDialog*) aHandle;
       
  1373     TInt index = iDialogs.Find( dialog );
       
  1374     if( index >= 0 )
       
  1375         {
       
  1376         delete dialog;
       
  1377         iDialogs.Remove( index );
       
  1378         }
       
  1379         
       
  1380     }
       
  1381            
       
  1382 /*
       
  1383 -------------------------------------------------------------------------------
       
  1384 
       
  1385     Class: CConsoleMain
       
  1386 
       
  1387     Method: GetConsole
       
  1388 
       
  1389     Description: Returns the console
       
  1390 
       
  1391     Parameters: None
       
  1392 
       
  1393     Return Values: CConsoleBase*                    Console
       
  1394 
       
  1395     Errors/Exceptions: None
       
  1396 
       
  1397     Status: Draft
       
  1398 
       
  1399 -------------------------------------------------------------------------------
       
  1400 */
       
  1401 //CConsoleBase* CConsoleMain::GetConsole()
       
  1402 RConsole* CConsoleMain::GetConsole()
       
  1403     {
       
  1404 
       
  1405     return &iConsole;
       
  1406 
       
  1407     }
       
  1408 
       
  1409 /*
       
  1410 -------------------------------------------------------------------------------
       
  1411 
       
  1412     Class: CConsoleMain
       
  1413 
       
  1414     Method: TimerUpdate
       
  1415 
       
  1416     Description: Updates current menu from timer
       
  1417 
       
  1418     Parameters: None
       
  1419 
       
  1420     Return Values: None
       
  1421 
       
  1422     Errors/Exceptions: None
       
  1423 
       
  1424     Status: Draft
       
  1425 
       
  1426 -------------------------------------------------------------------------------
       
  1427 */
       
  1428 void CConsoleMain::TimerUpdate()
       
  1429     {
       
  1430 
       
  1431 	iCurrentMenu->TimerUpdate();
       
  1432 
       
  1433     }
       
  1434 
       
  1435 /*
       
  1436 -------------------------------------------------------------------------------
       
  1437 
       
  1438     Class: CConsoleMain
       
  1439 
       
  1440     Method: ParseTestModulesL
       
  1441 
       
  1442     Description: Parse and search for module info and fill list of modules.
       
  1443 
       
  1444     Parameters: CStifParser*     aParser:       in: CStifParser object
       
  1445                 CTestModuleList* aModuleList:   in: list of modules
       
  1446                 TPtrC&           aSectionStart: in: descriptor with start of section string
       
  1447                 TPTrC&           aSectionEnd:   in: descriptor with end of section string
       
  1448 
       
  1449     Return Values: None
       
  1450 
       
  1451     Errors/Exceptions: Leaves if some of called leaving methods leaves
       
  1452 
       
  1453     Status: Approved
       
  1454 
       
  1455 -------------------------------------------------------------------------------
       
  1456 */
       
  1457 void CConsoleMain::ParseTestModulesL(CStifParser* aParser, CTestModuleList* aModuleList, const TDesC& aSectionStart, const TDesC& aSectionEnd)
       
  1458     {
       
  1459     //First let's find all modules given in Stif's ini file and store that info in CTestModuleList object
       
  1460     CStifSectionParser* sectionParser = NULL;
       
  1461     CStifItemParser* item = NULL;
       
  1462 
       
  1463     sectionParser = aParser->SectionL(aSectionStart, aSectionEnd);
       
  1464 
       
  1465     while(sectionParser)
       
  1466         {
       
  1467         RDebug::Print(_L("Found '%S' and '%S' sections"), &aSectionStart, &aSectionEnd);
       
  1468         CleanupStack::PushL(sectionParser);
       
  1469         RDebug::Print(_L("Starting to read module information"));
       
  1470 
       
  1471         // Get name of module
       
  1472         _LIT(KModuleName, "ModuleName=");
       
  1473         item = sectionParser->GetItemLineL(KModuleName);
       
  1474         CleanupStack::PushL(item);
       
  1475         if(!item)
       
  1476             {
       
  1477             CleanupStack::PopAndDestroy(item);
       
  1478             UiError(_L("Line not found from module section"));
       
  1479             User::Leave(KErrGeneral);
       
  1480             }
       
  1481         else
       
  1482             {
       
  1483             RDebug::Print(_L("'%S' found"), &KModuleName);
       
  1484             }
       
  1485 
       
  1486         TPtrC name;
       
  1487         TName moduleName;
       
  1488         TInt ret(KErrNone);
       
  1489         ret = item->GetString(KModuleName, name);
       
  1490         if(ret != KErrNone)
       
  1491             {
       
  1492             CleanupStack::PopAndDestroy(item);
       
  1493             RDebug::Print(_L("Module name parsing left with error (%d)"), ret);
       
  1494             UiError(_L("Module name parsing left with error (err)"));
       
  1495             User::Leave(ret);
       
  1496             }
       
  1497         else
       
  1498             {
       
  1499             RDebug::Print(_L("Module '%S' found from ini-file"), &name);
       
  1500             moduleName.Copy(name);
       
  1501             moduleName.LowerCase();
       
  1502             ret = aModuleList->AddTestModule(moduleName);
       
  1503             if(ret != KErrNone && ret != KErrAlreadyExists)
       
  1504                 {
       
  1505                 RDebug::Print(_L("Could not add module to list of modules (%d)"), ret);
       
  1506                 UiError(_L("Could not add module to list of modules (err)"));
       
  1507                 User::Leave(ret);
       
  1508                 }
       
  1509             }
       
  1510         CleanupStack::PopAndDestroy(item);
       
  1511 
       
  1512         //Get pointer to added module
       
  1513         CTestModuleInfo* moduleInfo = aModuleList->GetModule(moduleName);
       
  1514         if(!moduleInfo)
       
  1515             {
       
  1516                 RDebug::Print(_L("Could not add get module info from list"));
       
  1517                 UiError(_L("Could not add get module info from list"));
       
  1518                 User::Leave(KErrNotFound);
       
  1519             }
       
  1520 
       
  1521         // Get ini file, if it exists
       
  1522         RDebug::Print(_L("Start parsing ini file"));
       
  1523         _LIT(KIniFile, "IniFile=");
       
  1524         item = sectionParser->GetItemLineL(KIniFile);
       
  1525         if(item)
       
  1526             {
       
  1527             RDebug::Print(_L("'%S' found"), &KIniFile);
       
  1528             CleanupStack::PushL(item);
       
  1529             TPtrC iniFile;
       
  1530             ret = item->GetString(KIniFile, iniFile);
       
  1531             if(ret == KErrNone)
       
  1532                 {
       
  1533                 RDebug::Print(_L("Initialization file '%S' found, file can be empty"), &iniFile);
       
  1534                 TFileName filename;
       
  1535                 filename.Copy(iniFile);
       
  1536 				TStifUtil::CorrectFilePathL(filename);
       
  1537                 filename.LowerCase();
       
  1538                 moduleInfo->SetIniFile(filename);
       
  1539                 }
       
  1540             else
       
  1541                 {
       
  1542                 RDebug::Print(_L("Initialization file not found"));
       
  1543                 }
       
  1544             CleanupStack::PopAndDestroy(item);
       
  1545             }
       
  1546         else
       
  1547             {
       
  1548             RDebug::Print(_L("'%S' not found"), &KIniFile);
       
  1549             }
       
  1550 
       
  1551         // Get config (testcase) file
       
  1552         RDebug::Print(_L("Start parsing cfg files"));
       
  1553         TPtrC cfgTag;
       
  1554         for(TInt i = 0; i < 2; i++)
       
  1555             {
       
  1556             //Set tag for config files
       
  1557             if(i == 0)
       
  1558                 {
       
  1559                 cfgTag.Set(_L("ConfigFile="));
       
  1560                 }
       
  1561                 else
       
  1562                 {
       
  1563                 cfgTag.Set(_L("TestCaseFile="));
       
  1564                 }
       
  1565             //Read data
       
  1566             item = sectionParser->GetItemLineL(cfgTag);
       
  1567             while(item)
       
  1568                 {
       
  1569                 CleanupStack::PushL(item);
       
  1570                 RDebug::Print(_L("Item '%S' found"), &cfgTag);
       
  1571                 TPtrC cfgFile;
       
  1572                 ret = item->GetString(cfgTag, cfgFile);
       
  1573                 if(ret == KErrNone)
       
  1574                     {
       
  1575                     RDebug::Print(_L("Configuration file '%S' found"), &cfgFile);
       
  1576                     TFileName ifile;
       
  1577                     ifile.Copy(cfgFile);
       
  1578 					TStifUtil::CorrectFilePathL(ifile);
       
  1579                     ifile.LowerCase();
       
  1580                     moduleInfo->AddCfgFile(ifile);
       
  1581                     }
       
  1582                 else
       
  1583                     {
       
  1584                     RDebug::Print(_L("Configuration file not found"));
       
  1585                     }
       
  1586                 CleanupStack::PopAndDestroy(item);
       
  1587                 item = sectionParser->GetNextItemLineL(cfgTag);
       
  1588                 }
       
  1589             }
       
  1590 
       
  1591         RDebug::Print(_L("Module '%S' information read correctly"), &moduleName);
       
  1592 
       
  1593         // Get next section
       
  1594         CleanupStack::PopAndDestroy(sectionParser);
       
  1595         sectionParser = aParser->NextSectionL(aSectionStart, aSectionEnd);
       
  1596         }
       
  1597     }
       
  1598 
       
  1599 /*
       
  1600 -------------------------------------------------------------------------------
       
  1601 
       
  1602     Class: CConsoleMain
       
  1603 
       
  1604     Method: GetMainMenu
       
  1605 
       
  1606     Description: Return main menu of console.
       
  1607 
       
  1608     Parameters: None
       
  1609 
       
  1610     Return Values: CMainMenu*  pointer to main menu
       
  1611 
       
  1612     Errors/Exceptions: None
       
  1613 
       
  1614     Status: Approved
       
  1615 
       
  1616 -------------------------------------------------------------------------------
       
  1617 */
       
  1618 CMainMenu* CConsoleMain::GetMainMenu()
       
  1619     {
       
  1620     return dynamic_cast<CMainMenu*>(iMainMenu);
       
  1621     }
       
  1622 
       
  1623 /*
       
  1624 -------------------------------------------------------------------------------
       
  1625 
       
  1626     Class: CConsoleMain
       
  1627 
       
  1628     Method: GetFilterArray
       
  1629 
       
  1630     Description: Get filter array for reading purposes
       
  1631 
       
  1632     Parameters: None
       
  1633 
       
  1634     Return Values: const RPointerArray<TDesC>&  array with filters
       
  1635 
       
  1636     Errors/Exceptions: None
       
  1637 
       
  1638     Status: Approved
       
  1639 
       
  1640 -------------------------------------------------------------------------------
       
  1641 */
       
  1642 const RPointerArray<TDesC>& CConsoleMain::GetFilterArray(void) const
       
  1643     {
       
  1644     return iFilters;
       
  1645     }
       
  1646 
       
  1647 /*
       
  1648 -------------------------------------------------------------------------------
       
  1649 
       
  1650     Class: CConsoleMain
       
  1651 
       
  1652     Method: SetFilterIndex
       
  1653 
       
  1654     Description: Set info about which index filter is used
       
  1655 
       
  1656     Parameters: TInt aFilterIndex: filter index selected by user
       
  1657 
       
  1658     Return Values: None
       
  1659 
       
  1660     Errors/Exceptions: None
       
  1661 
       
  1662     Status: Approved
       
  1663 
       
  1664 -------------------------------------------------------------------------------
       
  1665 */
       
  1666 void CConsoleMain::SetFilterIndex(TInt aFilterIndex)
       
  1667     {
       
  1668     iChosenFilterIndex = aFilterIndex;
       
  1669     }
       
  1670 
       
  1671 /*
       
  1672 -------------------------------------------------------------------------------
       
  1673 
       
  1674     Class: CConsoleMain
       
  1675 
       
  1676     Method: GetFilterIndex
       
  1677 
       
  1678     Description: Get info about which index filter is used
       
  1679 
       
  1680     Parameters: None
       
  1681 
       
  1682     Return Values: TInt: filter index selected by user
       
  1683 
       
  1684     Errors/Exceptions: None
       
  1685 
       
  1686     Status: Approved
       
  1687 
       
  1688 -------------------------------------------------------------------------------
       
  1689 */
       
  1690 TInt CConsoleMain::GetFilterIndex(void)
       
  1691     {
       
  1692     return iChosenFilterIndex;
       
  1693     }
       
  1694 
       
  1695 /*
       
  1696 -------------------------------------------------------------------------------
       
  1697 
       
  1698     Class: CScrollerTimer
       
  1699 
       
  1700     Method: NewL
       
  1701 
       
  1702     Description: Construct a new CScrollerTimer object
       
  1703 
       
  1704     Parameters: CConsoleMain*             :in:      Pointer to main console               
       
  1705 
       
  1706     Return Values: CScrollerTimer*                         New CScrollerTimer object
       
  1707 
       
  1708     Errors/Exceptions: Leaves if memory allocation or ConstructL leaves
       
  1709 
       
  1710     Status: Draft
       
  1711 
       
  1712 -------------------------------------------------------------------------------
       
  1713 */
       
  1714 CScrollerTimer* CScrollerTimer::NewL( CConsoleMain* aMain )
       
  1715     {
       
  1716 
       
  1717     CScrollerTimer* self = new ( ELeave ) CScrollerTimer();
       
  1718     CleanupStack::PushL( self );
       
  1719     self->ConstructL( aMain );
       
  1720     CleanupStack::Pop( self );
       
  1721     return self;
       
  1722 
       
  1723     }
       
  1724 
       
  1725 /*
       
  1726 -------------------------------------------------------------------------------
       
  1727 
       
  1728     Class: CScrollerTimer
       
  1729 
       
  1730     Method: ConstructL
       
  1731 
       
  1732     Description: Second level constructor
       
  1733 
       
  1734     Parameters: CConsoleMain*             :in:      Pointer to main console
       
  1735 
       
  1736     Return Values: None
       
  1737 
       
  1738     Errors/Exceptions: None
       
  1739 
       
  1740     Status: Draft
       
  1741 
       
  1742 -------------------------------------------------------------------------------
       
  1743 */
       
  1744 void CScrollerTimer::ConstructL( CConsoleMain* aMain )
       
  1745     {
       
  1746 
       
  1747     // Store module information
       
  1748     iMain = aMain;
       
  1749 	iTimer.CreateLocal();
       
  1750 
       
  1751 	CActiveScheduler::Add ( this );
       
  1752 
       
  1753     }
       
  1754 
       
  1755 /*
       
  1756 -------------------------------------------------------------------------------
       
  1757 
       
  1758     Class: CScrollerTimer
       
  1759 
       
  1760     Method: CScrollerTimer
       
  1761 
       
  1762     Description: Constructor.
       
  1763 
       
  1764     Parameters: None
       
  1765 
       
  1766     Return Values: None
       
  1767 
       
  1768     Errors/Exceptions: None
       
  1769 
       
  1770     Status: Draft
       
  1771     
       
  1772 -------------------------------------------------------------------------------
       
  1773 */
       
  1774 CScrollerTimer::CScrollerTimer() : CActive (CActive::EPriorityStandard)
       
  1775     {
       
  1776 
       
  1777     }
       
  1778 
       
  1779 
       
  1780 /*
       
  1781 -------------------------------------------------------------------------------
       
  1782 
       
  1783     Class: CScrollerTimer
       
  1784 
       
  1785     Method: ~CScrollerTimer
       
  1786 
       
  1787     Description: None
       
  1788 
       
  1789     Parameters: None
       
  1790 
       
  1791     Return Values: None
       
  1792 
       
  1793     Errors/Exceptions: None
       
  1794 
       
  1795     Status: Draft
       
  1796     
       
  1797 -------------------------------------------------------------------------------
       
  1798 */
       
  1799 CScrollerTimer::~CScrollerTimer( )
       
  1800     {
       
  1801 
       
  1802 	Cancel();
       
  1803 	iTimer.Close();
       
  1804 
       
  1805     }
       
  1806 
       
  1807 /*
       
  1808 -------------------------------------------------------------------------------
       
  1809 
       
  1810     Class: CScrollerTimer
       
  1811 
       
  1812     Method: StartL
       
  1813 
       
  1814     Description: None
       
  1815 
       
  1816     Parameters: None
       
  1817 
       
  1818     Return Values: None
       
  1819 
       
  1820     Errors/Exceptions: None
       
  1821 
       
  1822     Status: Draft
       
  1823     
       
  1824 -------------------------------------------------------------------------------
       
  1825 */
       
  1826 void CScrollerTimer::StartL( )
       
  1827     {
       
  1828 
       
  1829 	SetActive();
       
  1830 	iTimer.After ( iStatus, KScrollPeriod );	
       
  1831 
       
  1832     }
       
  1833 
       
  1834 /*
       
  1835 -------------------------------------------------------------------------------
       
  1836 
       
  1837     Class: CScrollerTimer
       
  1838 
       
  1839     Method: RunL
       
  1840 
       
  1841     Description: None
       
  1842 
       
  1843     Parameters: None
       
  1844 
       
  1845     Return Values: None
       
  1846 
       
  1847     Errors/Exceptions: None
       
  1848 
       
  1849     Status: Draft
       
  1850     
       
  1851 -------------------------------------------------------------------------------
       
  1852 */
       
  1853 void CScrollerTimer::RunL( )
       
  1854     {
       
  1855 
       
  1856 	iMain->TimerUpdate();
       
  1857 
       
  1858 	// Restart request
       
  1859 	SetActive();
       
  1860 	iTimer.After ( iStatus, KScrollPeriod );
       
  1861 
       
  1862     }
       
  1863 
       
  1864 /*
       
  1865 -------------------------------------------------------------------------------
       
  1866 
       
  1867     Class: CScrollerTimer
       
  1868 
       
  1869     Method: DoCancel
       
  1870 
       
  1871     Description: None
       
  1872 
       
  1873     Parameters: None
       
  1874 
       
  1875     Return Values: None
       
  1876 
       
  1877     Errors/Exceptions: None
       
  1878 
       
  1879     Status: Draft
       
  1880     
       
  1881 -------------------------------------------------------------------------------
       
  1882 */
       
  1883 void CScrollerTimer::DoCancel( )
       
  1884     {
       
  1885 
       
  1886 	iTimer.Cancel();
       
  1887 
       
  1888     }
       
  1889 
       
  1890 /*
       
  1891 -------------------------------------------------------------------------------
       
  1892 
       
  1893     Class: CScrollerTimer
       
  1894 
       
  1895     Method: RunError
       
  1896 
       
  1897     Description: None
       
  1898 
       
  1899     Parameters: None
       
  1900 
       
  1901     Return Values: None
       
  1902 
       
  1903     Errors/Exceptions: None
       
  1904 
       
  1905     Status: Draft
       
  1906     
       
  1907 -------------------------------------------------------------------------------
       
  1908 */
       
  1909 TInt CScrollerTimer::RunError( TInt aError)
       
  1910     {
       
  1911     if ( aError == KErrNoMemory )
       
  1912     	{
       
  1913     	iMain->ExitWithNoMemoryErrorMessage();
       
  1914     	}
       
  1915   
       
  1916 	return aError;
       
  1917     }    
       
  1918 
       
  1919 /*
       
  1920 -------------------------------------------------------------------------------
       
  1921 
       
  1922     DESCRIPTION
       
  1923 
       
  1924     This module contains implementation of CConsoleReader class.
       
  1925 
       
  1926 -------------------------------------------------------------------------------
       
  1927 */
       
  1928 
       
  1929 // ================= MEMBER FUNCTIONS =========================================
       
  1930 
       
  1931 
       
  1932 
       
  1933 /*
       
  1934 -------------------------------------------------------------------------------
       
  1935 
       
  1936     Class: CConsoleReader
       
  1937 
       
  1938     Method: NewL
       
  1939 
       
  1940     Description: Construct the console main class
       
  1941 
       
  1942     Parameters: CConsoleMain* aMain: in: Pointer to main console
       
  1943                 CConsoleBase* aConsole: in: Console pointer
       
  1944 
       
  1945     Return Values: CConsoleReader*                    New object
       
  1946 
       
  1947     Errors/Exceptions: Leaves if memory allocation fails or
       
  1948                        ConstructL leaves.
       
  1949 
       
  1950     Status: Draft
       
  1951 
       
  1952 -------------------------------------------------------------------------------
       
  1953 */
       
  1954 CConsoleReader* CConsoleReader::NewL( CConsoleMain* aMain, 
       
  1955                                       //CConsoleBase* aConsole )
       
  1956                                       RConsole* aConsole )
       
  1957     {
       
  1958 
       
  1959     CConsoleReader* self = 
       
  1960         new ( ELeave ) CConsoleReader( aMain, aConsole );
       
  1961     CleanupStack::PushL( self );
       
  1962     self->ConstructL();
       
  1963     CleanupStack::Pop( self );
       
  1964     return self;
       
  1965 
       
  1966     }
       
  1967 
       
  1968 
       
  1969 /*
       
  1970 -------------------------------------------------------------------------------
       
  1971 
       
  1972     Class: CConsoleReader
       
  1973 
       
  1974     Method: ConstructL
       
  1975 
       
  1976     Description: Second level constructor.
       
  1977     
       
  1978     Parameters: None
       
  1979 
       
  1980     Return Values: None
       
  1981 
       
  1982     Errors/Exceptions: 
       
  1983 
       
  1984     Status: Draft
       
  1985 
       
  1986 -------------------------------------------------------------------------------
       
  1987 */
       
  1988 void CConsoleReader::ConstructL( )
       
  1989     {
       
  1990     }
       
  1991 
       
  1992 
       
  1993 /*
       
  1994 -------------------------------------------------------------------------------
       
  1995 
       
  1996     Class: CConsoleReader
       
  1997 
       
  1998     Method: CConsoleReader
       
  1999 
       
  2000     Description: Constructor.
       
  2001 
       
  2002     Parameters: CConsoleMain* aMain: in: Pointer to main console
       
  2003                 CConsoleBase* aConsole: in: Console pointer
       
  2004 
       
  2005     Return Values: None
       
  2006 
       
  2007     Errors/Exceptions: None
       
  2008 
       
  2009     Status: Draft
       
  2010 
       
  2011 -------------------------------------------------------------------------------
       
  2012 */
       
  2013 CConsoleReader::CConsoleReader( CConsoleMain* aMain, 
       
  2014                                 //CConsoleBase* aConsole ): 
       
  2015                                 RConsole* aConsole ): 
       
  2016     CActive( EPriorityStandard )
       
  2017     {
       
  2018     
       
  2019     iMain = aMain;
       
  2020     iConsole = aConsole;
       
  2021     
       
  2022     CActiveScheduler::Add( this );
       
  2023 
       
  2024     }
       
  2025 
       
  2026 
       
  2027 /*
       
  2028 -------------------------------------------------------------------------------
       
  2029 
       
  2030     Class: CConsoleReader
       
  2031 
       
  2032     Method: ~CConsoleReader
       
  2033 
       
  2034     Description: Destructor
       
  2035 
       
  2036     Parameters: None
       
  2037 
       
  2038     Return Values: None
       
  2039 
       
  2040     Errors/Exceptions: None
       
  2041 
       
  2042     Status: Draft
       
  2043 
       
  2044 -------------------------------------------------------------------------------
       
  2045 */
       
  2046 CConsoleReader::~CConsoleReader( )
       
  2047     {	
       
  2048     
       
  2049     Cancel();    
       
  2050     
       
  2051     }
       
  2052 
       
  2053 /*
       
  2054 -------------------------------------------------------------------------------
       
  2055 
       
  2056     Class: CConsoleReader
       
  2057 
       
  2058     Method: StartL
       
  2059 
       
  2060     Description: Construct menu objects and start the menu handling
       
  2061 
       
  2062     Parameters: None
       
  2063 
       
  2064     Return Values: None
       
  2065 
       
  2066     Errors/Exceptions:
       
  2067 
       
  2068     Status: Draft
       
  2069 
       
  2070 -------------------------------------------------------------------------------
       
  2071 */
       
  2072 void CConsoleReader::StartL( )
       
  2073     {
       
  2074 
       
  2075     // Start to process keyboard events
       
  2076     SetActive();
       
  2077     //iConsole->Read(iStatus);
       
  2078     iConsole->Read(iMain->key, iStatus);
       
  2079 
       
  2080     }
       
  2081 /*
       
  2082 -------------------------------------------------------------------------------
       
  2083 
       
  2084     Class: CConsoleReader
       
  2085 
       
  2086     Method: RunError
       
  2087 
       
  2088     Description: None
       
  2089 
       
  2090     Parameters: TInt aError
       
  2091 
       
  2092     Return Values: Error code
       
  2093 
       
  2094     Errors/Exceptions: None
       
  2095 
       
  2096     Status: Draft
       
  2097     
       
  2098 -------------------------------------------------------------------------------
       
  2099 */    
       
  2100 TInt CConsoleReader::RunError(TInt aError)
       
  2101     {
       
  2102     return aError;
       
  2103     }
       
  2104 
       
  2105 
       
  2106 /*
       
  2107 -------------------------------------------------------------------------------
       
  2108 
       
  2109     Class: CConsoleReader
       
  2110 
       
  2111     Method: RunL
       
  2112 
       
  2113     Description: Process keyboard events. Print new menu
       
  2114 
       
  2115     Parameters: None
       
  2116 
       
  2117     Return Values: None
       
  2118 
       
  2119     Errors/Exceptions: Leaves if SelectL leaves
       
  2120 
       
  2121     Status: Draft
       
  2122 
       
  2123 -------------------------------------------------------------------------------
       
  2124 */
       
  2125 void CConsoleReader::RunL()
       
  2126     {
       
  2127 
       
  2128     iMain->KeyPressed();
       
  2129     
       
  2130     }
       
  2131 
       
  2132 
       
  2133 /*
       
  2134 -------------------------------------------------------------------------------
       
  2135 
       
  2136     Class: CConsoleReader
       
  2137 
       
  2138     Method: DoCancel
       
  2139 
       
  2140     Description: Cancel request
       
  2141 
       
  2142     Parameters: None
       
  2143 
       
  2144     Return Values: None
       
  2145 
       
  2146     Errors/Exceptions: None
       
  2147 
       
  2148     Status: Draft
       
  2149 
       
  2150 -------------------------------------------------------------------------------
       
  2151 */
       
  2152 void CConsoleReader::DoCancel()
       
  2153     {
       
  2154     
       
  2155     iConsole->ReadCancel();
       
  2156     
       
  2157     }
       
  2158 
       
  2159 
       
  2160 // ================= OTHER EXPORTED FUNCTIONS =================================
       
  2161 
       
  2162 /*
       
  2163 -------------------------------------------------------------------------------
       
  2164 
       
  2165     Class: -
       
  2166 
       
  2167     Method: MainL
       
  2168 
       
  2169     Description: The main function that can leave.
       
  2170     Create the CMainConsole object and create, initialise and 
       
  2171     start active scheduler.
       
  2172 
       
  2173     When active scheduler is stopped, clean up memory and exit.
       
  2174 
       
  2175     Parameters: None
       
  2176 
       
  2177     Return Values: None
       
  2178 
       
  2179     Errors/Exceptions: Leaves if memory allocation or CConsoleMain construction
       
  2180                        leaves.
       
  2181 
       
  2182     Status: Draft
       
  2183 
       
  2184 -------------------------------------------------------------------------------
       
  2185 */
       
  2186 LOCAL_C void MainL()
       
  2187     {
       
  2188 
       
  2189     // Construct and install active scheduler
       
  2190     CActiveScheduler* scheduler=new ( ELeave ) CActiveScheduler;
       
  2191     CleanupStack::PushL( scheduler );
       
  2192     CActiveScheduler::Install( scheduler );
       
  2193 
       
  2194     // Construct the console
       
  2195     CConsoleMain* mainConsole = CConsoleMain::NewL();
       
  2196     CleanupStack::PushL( mainConsole );
       
  2197 
       
  2198     // Start the console
       
  2199     mainConsole->StartL();
       
  2200 
       
  2201     // Start handling requests
       
  2202     CActiveScheduler::Start();
       
  2203     // Execution continues from here after CActiveScheduler::Stop()
       
  2204 
       
  2205     // Clean-up
       
  2206     CleanupStack::PopAndDestroy( mainConsole );
       
  2207     CleanupStack::PopAndDestroy( scheduler );
       
  2208 
       
  2209     }
       
  2210 
       
  2211 
       
  2212 /*
       
  2213 -------------------------------------------------------------------------------
       
  2214 
       
  2215     Class: -
       
  2216 
       
  2217     Method: E32Main
       
  2218 
       
  2219     Description: The main function. Execution starts from here.
       
  2220     Create clean-up stack and trap the MainL function which does the
       
  2221     real work.
       
  2222 
       
  2223     Parameters: None
       
  2224 
       
  2225     Return Values: TInt                             Error code
       
  2226 
       
  2227     Errors/Exceptions: None
       
  2228 
       
  2229     Status: Draft
       
  2230 
       
  2231 -------------------------------------------------------------------------------
       
  2232 */
       
  2233 GLDEF_C TInt E32Main()
       
  2234     {
       
  2235 
       
  2236     __UHEAP_MARK;
       
  2237 
       
  2238     // Get clean-up stack
       
  2239     CTrapCleanup* cleanup=CTrapCleanup::New();
       
  2240 
       
  2241     // Call the main function
       
  2242     TRAPD( error, MainL() );
       
  2243 
       
  2244     // Clean-up
       
  2245     delete cleanup; 
       
  2246     cleanup = NULL;
       
  2247 
       
  2248     __UHEAP_MARKEND;
       
  2249 
       
  2250     return error;
       
  2251 
       
  2252     }
       
  2253 
       
  2254 #if defined(__WINS__)
       
  2255 /*
       
  2256 -------------------------------------------------------------------------------
       
  2257 
       
  2258     Class: -
       
  2259 
       
  2260     Method: WinsMain
       
  2261 
       
  2262     Description: The WinsMain function.
       
  2263 
       
  2264     Parameters: None
       
  2265 
       
  2266     Return Values: TInt                             Error code
       
  2267 
       
  2268     Errors/Exceptions: None
       
  2269 
       
  2270     Status: Draft
       
  2271 
       
  2272 -------------------------------------------------------------------------------
       
  2273 */
       
  2274 EXPORT_C TInt WinsMain()
       
  2275 	{
       
  2276 	E32Main();
       
  2277 	return KErrNone;
       
  2278 	}
       
  2279 
       
  2280 #endif // __WINS__
       
  2281 
       
  2282 // End of File