sl@0: /* sl@0: * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * sl@0: */ sl@0: sl@0: #include "T_RConsoleData.h" sl@0: sl@0: sl@0: /*@{*/ sl@0: //wrappers sl@0: _LIT(KCmdRead, "Read"); sl@0: _LIT(KCmdWrite, "Write"); sl@0: _LIT(KCmdControl, "Control"); sl@0: _LIT(KCmdInit, "Init"); sl@0: _LIT(KCmdDestroy, "Destroy"); sl@0: _LIT(KCmdCreate, "Create"); sl@0: _LIT(KCmdConstructor, "new"); sl@0: _LIT(KCmdDestructor, "~"); sl@0: _LIT(KCmdClearScreen, "ClearScreen"); sl@0: sl@0: //ini sections sl@0: _LIT(KFldText, "text"); sl@0: _LIT(KFldConsoleControl, "consoleControl"); sl@0: _LIT(KFldConsoleName, "consoleName"); sl@0: _LIT(KFldConsoleSize, "consoleSize"); sl@0: _LIT(KFldSynchronous, "synchronous"); sl@0: sl@0: //format fields sl@0: _LIT(KLogMissingParameter, "Missing parameter '%S'"); sl@0: _LIT(KLogError, "Error=%d"); sl@0: _LIT(KLogStringNotFound, "String not found %S"); sl@0: _LIT(KLogStraySignal, "Stray signal"); sl@0: _LIT(KLogAsyncError, "Async RunL Error %d"); sl@0: _LIT(KLogDataMissing, "Data missing for test"); sl@0: /*@}*/ sl@0: sl@0: sl@0: ////////////////////////////////////////////////////////////////////// sl@0: // Construction/Destruction sl@0: ////////////////////////////////////////////////////////////////////// sl@0: sl@0: CT_RConsoleData* CT_RConsoleData::NewL() sl@0: { sl@0: CT_RConsoleData* console=new (ELeave) CT_RConsoleData(); sl@0: CleanupStack::PushL(console); sl@0: console->ConstructL(); sl@0: CleanupStack::Pop(console); sl@0: return console; sl@0: } sl@0: sl@0: CT_RConsoleData::CT_RConsoleData() sl@0: : CT_RSessionBaseData() sl@0: , iActiveRConsoleRead(NULL) sl@0: , iConsole(NULL) sl@0: { sl@0: } sl@0: sl@0: void CT_RConsoleData::ConstructL() sl@0: /** sl@0: * Second phase construction sl@0: * sl@0: * @internalComponent sl@0: * sl@0: * @return N/A sl@0: * sl@0: * @pre None sl@0: * @post None sl@0: * sl@0: * @leave system wide error sl@0: */ sl@0: { sl@0: iActiveRConsoleRead = CT_ActiveRConsoleRead::NewL(*this); sl@0: } sl@0: sl@0: CT_RConsoleData::~CT_RConsoleData() sl@0: /** sl@0: * Public destructor sl@0: */ sl@0: { sl@0: DestroyData(); sl@0: delete iActiveRConsoleRead; sl@0: iActiveRConsoleRead= NULL; sl@0: } sl@0: sl@0: void CT_RConsoleData::DestroyData() sl@0: /** sl@0: * RConsole Destruction sl@0: * sl@0: */ sl@0: { sl@0: delete iConsole; sl@0: iConsole =NULL; sl@0: } sl@0: sl@0: sl@0: TAny* CT_RConsoleData::GetObject() sl@0: /** sl@0: * Return a pointer to the object that the data wraps sl@0: * sl@0: * @return pointer to the object that the data wraps sl@0: */ sl@0: { sl@0: return iConsole; sl@0: } sl@0: sl@0: RSessionBase* CT_RConsoleData::GetSessionBase() sl@0: { sl@0: return iConsole; sl@0: } sl@0: sl@0: RHandleBase* CT_RConsoleData::GetHandleBase() sl@0: { sl@0: return iConsole; sl@0: } sl@0: sl@0: TBool CT_RConsoleData::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt aAsyncErrorIndex) sl@0: /** sl@0: * Process a command read from the ini file sl@0: * sl@0: * @param aCommand The command to process sl@0: * @param aSection The section in the ini containing data for the command sl@0: * @param aAsyncErrorIndex Command index for async calls to return errors to sl@0: * sl@0: * @return ETrue if the command is processed sl@0: * sl@0: * @leave System wide error sl@0: */ sl@0: { sl@0: TBool ret =ETrue; sl@0: TInt error=KErrNone; sl@0: sl@0: if (aCommand==KCmdConstructor()) sl@0: { sl@0: error =DoCmdConstructor(); sl@0: } sl@0: else if ( aCommand==KCmdDestructor ) sl@0: { sl@0: DoCmdDestructor(); sl@0: } sl@0: else if ( aCommand==KCmdRead()) sl@0: { sl@0: error =DoCmdRead(aSection, aAsyncErrorIndex); sl@0: } sl@0: else if ( aCommand==KCmdWrite()) sl@0: { sl@0: error =DoCmdWrite(aSection); sl@0: } sl@0: else if ( aCommand==KCmdDestroy()) sl@0: { sl@0: error =DoCmdDestroy(); sl@0: } sl@0: else if ( aCommand==KCmdControl()) sl@0: { sl@0: error =DoCmdControl(aSection); sl@0: } sl@0: else if ( aCommand==KCmdInit()) sl@0: { sl@0: error =DoCmdInit(aSection); sl@0: } sl@0: else if ( aCommand==KCmdCreate()) sl@0: { sl@0: error =DoCmdCreate(); sl@0: } sl@0: else if ( aCommand==KCmdClearScreen()) sl@0: { sl@0: error =DoCmdClearScreen(); sl@0: } sl@0: else sl@0: { sl@0: ret=CT_RSessionBaseData::DoCommandL(aCommand, aSection, aAsyncErrorIndex); sl@0: } sl@0: sl@0: if ( error!=KErrNone ) sl@0: { sl@0: ERR_PRINTF2(KLogError, error); sl@0: SetError(error); sl@0: } sl@0: sl@0: return ret; sl@0: } sl@0: sl@0: TInt CT_RConsoleData::DoCmdConstructor() sl@0: /** sl@0: * Wrapper function for RConsole Construction sl@0: * sl@0: */ sl@0: { sl@0: DestroyData(); sl@0: TRAPD(err, iConsole=new (ELeave) RConsole()); sl@0: return err; sl@0: } sl@0: sl@0: void CT_RConsoleData::DoCmdDestructor() sl@0: /** sl@0: * Wrapper function for RConsole Destruction sl@0: * sl@0: */ sl@0: { sl@0: DestroyData(); sl@0: } sl@0: sl@0: TInt CT_RConsoleData::DoCmdRead(const TDesC& aSection , const TInt aAsyncErrorIndex) sl@0: /** sl@0: * Wrapper function for RConsole::Read(TConsoleKey &aKeystroke,TRequestStatus &aStatus) sl@0: * and RConsole::Read(TConsoleKey &aKeystroke) sl@0: * sl@0: * @param aSection The section in the ini containing data for the command sl@0: * @param aAsyncErrorIndex Command index for async calls to return errors to sl@0: */ sl@0: { sl@0: TBool sync=EFalse; sl@0: GETFROMCONFIGOPTIONAL(Bool, aSection, KFldSynchronous(), sync, KLogMissingParameter); sl@0: sl@0: TInt error=KErrNone; sl@0: if ( !sync ) sl@0: { sl@0: if ( !iActiveRConsoleRead->KickStartL(aSection, aAsyncErrorIndex, *iConsole) ) sl@0: { sl@0: ERR_PRINTF1(KLogDataMissing); sl@0: SetBlockResult(EFail); sl@0: } sl@0: else sl@0: { sl@0: IncOutstanding(); sl@0: } sl@0: } sl@0: else sl@0: { sl@0: TConsoleKey key; sl@0: error=iConsole->Read(key); sl@0: } sl@0: return error; sl@0: } sl@0: sl@0: TInt CT_RConsoleData::DoCmdWrite(const TDesC& aSection ) sl@0: /** sl@0: * Wrapper function for RConsole::Write(const TDesC &aDes) sl@0: * @param aSection The section in the ini containing data for the command sl@0: */ sl@0: { sl@0: TBool dataOk =EFalse; sl@0: TInt error =KErrNone; sl@0: TPtrC string; sl@0: GETSTRINGFROMCONFIGMANDATORY(aSection, KFldText(), string, KLogStringNotFound, dataOk); sl@0: if ( dataOk==KErrNone) sl@0: { sl@0: error =iConsole->Write(string); sl@0: } sl@0: return error; sl@0: } sl@0: sl@0: TInt CT_RConsoleData::DoCmdControl(const TDesC& aSection) sl@0: /** sl@0: * Wrapper function for RConsole::Control(const TDesC &aDes) sl@0: * @param aSection The section in the ini containing data for the command sl@0: */ sl@0: { sl@0: TBool dataOk =EFalse; sl@0: TInt error =KErrNone; sl@0: TPtrC control; sl@0: GETSTRINGFROMCONFIGMANDATORY(aSection, KFldConsoleControl(), control, KLogStringNotFound, dataOk); sl@0: if (dataOk==KErrNone) sl@0: { sl@0: error =iConsole->Control(control); sl@0: } sl@0: return error; sl@0: } sl@0: sl@0: TInt CT_RConsoleData::DoCmdInit(const TDesC& aSection) sl@0: /** sl@0: * Wrapper function for RConsole::Init(const TDesC &aName,const TSize &aSize sl@0: * @param aSection The section in the ini containing data for the command sl@0: */ sl@0: { sl@0: sl@0: TBool dataOk=ETrue; sl@0: sl@0: TPtrC name; sl@0: GETSTRINGFROMCONFIGMANDATORY(aSection, KFldConsoleName(), name, KLogMissingParameter, dataOk); sl@0: sl@0: TSize size(KConsFullScreen, KConsFullScreen); sl@0: GetSizeFromConfig(aSection, KFldConsoleSize(), size); sl@0: TInt error=KErrNone; sl@0: if ( dataOk ) sl@0: { sl@0: error=iConsole->Init(name, size); sl@0: } sl@0: sl@0: return error; sl@0: } sl@0: sl@0: TInt CT_RConsoleData::DoCmdDestroy() sl@0: /** sl@0: * Wrapper function for RConsole::Destroy() sl@0: */ sl@0: { sl@0: return iConsole->Destroy(); sl@0: } sl@0: sl@0: TInt CT_RConsoleData::DoCmdCreate() sl@0: /** sl@0: * Wrapper function for RConsole::Create() sl@0: */ sl@0: { sl@0: return iConsole->Create(); sl@0: } sl@0: sl@0: TInt CT_RConsoleData::DoCmdClearScreen() sl@0: /** sl@0: * Wrapper function for RConsole::ClearScreen() sl@0: * sl@0: */ sl@0: { sl@0: return iConsole->ClearScreen(); sl@0: } sl@0: sl@0: void CT_RConsoleData::RunL(CActive* aActive, TInt aIndex) sl@0: /** sl@0: * Called on completion of an asynchronous command sl@0: * @param aActive Active Object that RunL has been called on sl@0: * @param aIndex number of the command. sl@0: * @pre N/A sl@0: * @post N/A sl@0: * @leave system wide error code sl@0: */ sl@0: { sl@0: TBool activeOk=ETrue; sl@0: TInt err=KErrNone; sl@0: if ( aActive!=NULL ) sl@0: { sl@0: err=aActive->iStatus.Int(); sl@0: } sl@0: sl@0: TBool moreToDo=EFalse; sl@0: if( aActive==iActiveRConsoleRead) sl@0: { sl@0: iActiveRConsoleRead->KillTimer(); sl@0: if ( err==KErrNone ) sl@0: { sl@0: sl@0: moreToDo=iActiveRConsoleRead->VerifyDataAndKick(aIndex, *iConsole); sl@0: if ( !moreToDo ) sl@0: { sl@0: INFO_PRINTF1(_L("All Events have been read")); sl@0: } sl@0: } sl@0: sl@0: } sl@0: else sl@0: { sl@0: activeOk=EFalse; sl@0: ERR_PRINTF1(KLogStraySignal); sl@0: SetBlockResult(EFail); sl@0: } sl@0: sl@0: if ( activeOk ) sl@0: { sl@0: if ( !moreToDo ) sl@0: { sl@0: DecOutstanding(); sl@0: } sl@0: if ( err!=KErrNone ) sl@0: { sl@0: ERR_PRINTF2(KLogAsyncError, err); sl@0: SetAsyncError(aIndex, err); sl@0: } sl@0: } sl@0: } sl@0: sl@0: void CT_RConsoleData::DoCancel(CActive* aActive, TInt aIndex) sl@0: /** sl@0: * Called on cancellation of an asynchronous command sl@0: * @param aActive Active Object that RunL has been called on sl@0: * @param aIndex number of the command. sl@0: */ sl@0: { sl@0: TBool activeOk=ETrue; sl@0: TInt err=KErrNone; sl@0: sl@0: if ( aActive==iActiveRConsoleRead ) sl@0: { sl@0: INFO_PRINTF1(_L("ReadCancel Called")); sl@0: iActiveRConsoleRead->KillTimer(); sl@0: iConsole->ReadCancel(); sl@0: err=aActive->iStatus.Int(); sl@0: } sl@0: else sl@0: { sl@0: activeOk=EFalse; sl@0: ERR_PRINTF1(KLogStraySignal); sl@0: SetBlockResult(EFail); sl@0: } sl@0: sl@0: if ( activeOk ) sl@0: { sl@0: DecOutstanding(); sl@0: if( err != KErrNone ) sl@0: { sl@0: ERR_PRINTF2(_L("DoCancel Error %d"), err); sl@0: SetAsyncError( aIndex, err ); sl@0: } sl@0: } sl@0: sl@0: }