os/boardsupport/haitest/bspsvs/suite/e32/src/T_RConsoleData.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/boardsupport/haitest/bspsvs/suite/e32/src/T_RConsoleData.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,416 @@
     1.4 +/*
     1.5 +* Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). 
     1.6 +* All rights reserved.
     1.7 +* This component and the accompanying materials are made available
     1.8 +* under the terms of "Eclipse Public License v1.0"
     1.9 +* which accompanies this distribution, and is available
    1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.11 +*
    1.12 +* Initial Contributors:
    1.13 +* Nokia Corporation - initial contribution.
    1.14 +*
    1.15 +* Contributors:
    1.16 +*
    1.17 +* Description:
    1.18 +*
    1.19 +*/
    1.20 +
    1.21 +#include "T_RConsoleData.h"
    1.22 +
    1.23 +
    1.24 +/*@{*/
    1.25 +//wrappers
    1.26 +_LIT(KCmdRead,				"Read");
    1.27 +_LIT(KCmdWrite,				"Write");
    1.28 +_LIT(KCmdControl,			"Control");
    1.29 +_LIT(KCmdInit,				"Init");
    1.30 +_LIT(KCmdDestroy,			"Destroy");
    1.31 +_LIT(KCmdCreate,			"Create");
    1.32 +_LIT(KCmdConstructor,		"new");
    1.33 +_LIT(KCmdDestructor,		"~");
    1.34 +_LIT(KCmdClearScreen,		"ClearScreen");
    1.35 +
    1.36 +//ini sections
    1.37 +_LIT(KFldText,				"text");
    1.38 +_LIT(KFldConsoleControl,	"consoleControl");
    1.39 +_LIT(KFldConsoleName,		"consoleName");
    1.40 +_LIT(KFldConsoleSize,		"consoleSize");
    1.41 +_LIT(KFldSynchronous,		"synchronous");
    1.42 +
    1.43 +//format fields
    1.44 +_LIT(KLogMissingParameter,	"Missing parameter '%S'");
    1.45 +_LIT(KLogError,				"Error=%d");
    1.46 +_LIT(KLogStringNotFound,	"String not found %S");
    1.47 +_LIT(KLogStraySignal,		"Stray signal");
    1.48 +_LIT(KLogAsyncError,		"Async RunL Error %d");
    1.49 +_LIT(KLogDataMissing,		"Data missing for test");
    1.50 +/*@}*/
    1.51 +
    1.52 +
    1.53 +//////////////////////////////////////////////////////////////////////
    1.54 +// Construction/Destruction
    1.55 +//////////////////////////////////////////////////////////////////////
    1.56 +
    1.57 +CT_RConsoleData* CT_RConsoleData::NewL()
    1.58 +	{
    1.59 +	CT_RConsoleData* console=new (ELeave) CT_RConsoleData();
    1.60 +	CleanupStack::PushL(console);
    1.61 +	console->ConstructL();
    1.62 +	CleanupStack::Pop(console);
    1.63 +	return console;
    1.64 +	}
    1.65 +
    1.66 +CT_RConsoleData::CT_RConsoleData()
    1.67 +:	CT_RSessionBaseData()
    1.68 +,	iActiveRConsoleRead(NULL)
    1.69 +,	iConsole(NULL)
    1.70 +	{
    1.71 +	}
    1.72 +
    1.73 +void CT_RConsoleData::ConstructL()
    1.74 +/**
    1.75 + * Second phase construction
    1.76 + *
    1.77 + * @internalComponent
    1.78 + *
    1.79 + * @return	N/A
    1.80 + *
    1.81 + * @pre		None
    1.82 + * @post	None
    1.83 + *
    1.84 + * @leave	system wide error
    1.85 + */
    1.86 +	{
    1.87 +	iActiveRConsoleRead	= CT_ActiveRConsoleRead::NewL(*this);
    1.88 +	}
    1.89 +
    1.90 +CT_RConsoleData::~CT_RConsoleData()
    1.91 +/**
    1.92 + * Public destructor
    1.93 + */
    1.94 +	{
    1.95 +	DestroyData();
    1.96 +	delete iActiveRConsoleRead;
    1.97 +	iActiveRConsoleRead= 	NULL;
    1.98 +	}
    1.99 +
   1.100 +void CT_RConsoleData::DestroyData()
   1.101 + /**
   1.102 + *	RConsole Destruction
   1.103 + *
   1.104 + */
   1.105 +	{
   1.106 + 	delete	iConsole;
   1.107 + 	iConsole	=NULL;
   1.108 +	}
   1.109 +
   1.110 +
   1.111 + TAny* CT_RConsoleData::GetObject()
   1.112 +/**
   1.113 + * Return a pointer to the object that the data wraps
   1.114 + *
   1.115 + * @return	pointer to the object that the data wraps
   1.116 + */
   1.117 +	{
   1.118 +	return iConsole;
   1.119 +	}
   1.120 +
   1.121 +RSessionBase* CT_RConsoleData::GetSessionBase()
   1.122 +	{
   1.123 +	return iConsole;
   1.124 +	}
   1.125 +
   1.126 +RHandleBase* CT_RConsoleData::GetHandleBase()
   1.127 +	{
   1.128 +	return iConsole;
   1.129 +	}
   1.130 +
   1.131 +TBool CT_RConsoleData::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt aAsyncErrorIndex)
   1.132 +/**
   1.133 + * Process a command read from the ini file
   1.134 + *
   1.135 + * @param aCommand                      The command to process
   1.136 + * @param aSection                      The section in the ini containing data for the command
   1.137 + * @param aAsyncErrorIndex              Command index for async calls to return errors to
   1.138 + *
   1.139 + * @return                              ETrue if the command is processed
   1.140 + *
   1.141 + * @leave                               System wide error
   1.142 + */
   1.143 +	{
   1.144 +	TBool 	ret	=ETrue;
   1.145 +	TInt	error=KErrNone;
   1.146 +
   1.147 +	if (aCommand==KCmdConstructor())
   1.148 +		{
   1.149 +		error	=DoCmdConstructor();
   1.150 +		}
   1.151 +	else if ( aCommand==KCmdDestructor )
   1.152 +		{
   1.153 +		DoCmdDestructor();
   1.154 +		}
   1.155 +	else if ( aCommand==KCmdRead())
   1.156 +		{
   1.157 +		error	=DoCmdRead(aSection, aAsyncErrorIndex);
   1.158 +		}
   1.159 +	else if ( aCommand==KCmdWrite())
   1.160 +		{
   1.161 +		error	=DoCmdWrite(aSection);
   1.162 +		}
   1.163 +	else if ( aCommand==KCmdDestroy())
   1.164 +		{
   1.165 +		error	=DoCmdDestroy();
   1.166 +		}
   1.167 +	else if ( aCommand==KCmdControl())
   1.168 +		{
   1.169 +		error	=DoCmdControl(aSection);
   1.170 +		}
   1.171 +	else if ( aCommand==KCmdInit())
   1.172 +		{
   1.173 +		error	=DoCmdInit(aSection);
   1.174 +		}
   1.175 +	else if ( aCommand==KCmdCreate())
   1.176 +		{
   1.177 +		error	=DoCmdCreate();
   1.178 +		}
   1.179 +	else if ( aCommand==KCmdClearScreen())
   1.180 +		{
   1.181 +		error	=DoCmdClearScreen();
   1.182 +		}
   1.183 +	else
   1.184 +		{
   1.185 +		ret=CT_RSessionBaseData::DoCommandL(aCommand, aSection, aAsyncErrorIndex);
   1.186 +		}
   1.187 +
   1.188 +	if ( error!=KErrNone )
   1.189 +		{
   1.190 +		ERR_PRINTF2(KLogError, error);
   1.191 +		SetError(error);
   1.192 +		}
   1.193 +
   1.194 +	return ret;
   1.195 +	}
   1.196 +
   1.197 +TInt CT_RConsoleData::DoCmdConstructor()
   1.198 + /**
   1.199 + *	Wrapper function for RConsole Construction
   1.200 + *
   1.201 + */
   1.202 +	{
   1.203 +	DestroyData();
   1.204 +	TRAPD(err, iConsole=new (ELeave) RConsole());
   1.205 +	return err;
   1.206 +	}
   1.207 +
   1.208 +void CT_RConsoleData::DoCmdDestructor()
   1.209 + /**
   1.210 + *	Wrapper function for RConsole Destruction
   1.211 + *
   1.212 + */
   1.213 +	{
   1.214 +	DestroyData();
   1.215 +	}
   1.216 +
   1.217 +TInt CT_RConsoleData::DoCmdRead(const TDesC& aSection , const TInt aAsyncErrorIndex)
   1.218 + /**
   1.219 + *	Wrapper function for RConsole::Read(TConsoleKey &aKeystroke,TRequestStatus &aStatus)
   1.220 + * 	and RConsole::Read(TConsoleKey &aKeystroke)
   1.221 + *
   1.222 + *	@param		aSection			The section in the ini containing data for the command
   1.223 + * 	@param		aAsyncErrorIndex	Command index for async calls to return errors to
   1.224 + */
   1.225 + 	{
   1.226 + 	TBool	sync=EFalse;
   1.227 +	GETFROMCONFIGOPTIONAL(Bool, aSection, KFldSynchronous(), sync, KLogMissingParameter);
   1.228 +
   1.229 +	TInt	error=KErrNone;
   1.230 +	if ( !sync )
   1.231 +		{
   1.232 +		if ( !iActiveRConsoleRead->KickStartL(aSection, aAsyncErrorIndex, *iConsole) )
   1.233 +			{
   1.234 +			ERR_PRINTF1(KLogDataMissing);
   1.235 +			SetBlockResult(EFail);
   1.236 +			}
   1.237 +		else
   1.238 +			{
   1.239 +			IncOutstanding();
   1.240 +			}
   1.241 +		}
   1.242 +	else
   1.243 +		{
   1.244 +		TConsoleKey	key;
   1.245 +		error=iConsole->Read(key);
   1.246 +		}
   1.247 +	return error;
   1.248 + 	}
   1.249 +
   1.250 +TInt CT_RConsoleData::DoCmdWrite(const TDesC& aSection )
   1.251 + /**
   1.252 + *	Wrapper function for RConsole::Write(const TDesC &aDes)
   1.253 + *	@param		aSection			The section in the ini containing data for the command
   1.254 + */
   1.255 + 	{
   1.256 +	TBool dataOk	=EFalse;
   1.257 +	TInt error		=KErrNone;
   1.258 +	TPtrC string;
   1.259 +	GETSTRINGFROMCONFIGMANDATORY(aSection, KFldText(), string, KLogStringNotFound,  dataOk);
   1.260 +	if ( dataOk==KErrNone)
   1.261 +		{
   1.262 +		error	=iConsole->Write(string);
   1.263 +		}
   1.264 +	return error;
   1.265 + 	}
   1.266 +
   1.267 +TInt CT_RConsoleData::DoCmdControl(const TDesC& aSection)
   1.268 + /**
   1.269 + *	Wrapper function for RConsole::Control(const TDesC &aDes)
   1.270 + *	@param		aSection			The section in the ini containing data for the command
   1.271 + */
   1.272 +	{
   1.273 +	TBool dataOk	=EFalse;
   1.274 +	TInt error	=KErrNone;
   1.275 +	TPtrC control;
   1.276 +	GETSTRINGFROMCONFIGMANDATORY(aSection, KFldConsoleControl(), control, KLogStringNotFound, dataOk);
   1.277 +	if (dataOk==KErrNone)
   1.278 +		{
   1.279 +		error	=iConsole->Control(control);
   1.280 +		}
   1.281 +	return error;
   1.282 +	}
   1.283 +
   1.284 +TInt CT_RConsoleData::DoCmdInit(const TDesC& aSection)
   1.285 + /**
   1.286 + *	Wrapper function for RConsole::Init(const TDesC &aName,const TSize &aSize
   1.287 + *	@param		aSection			The section in the ini containing data for the command
   1.288 + */
   1.289 +	{
   1.290 +
   1.291 +	TBool	dataOk=ETrue;
   1.292 +
   1.293 +	TPtrC	name;
   1.294 +	GETSTRINGFROMCONFIGMANDATORY(aSection, KFldConsoleName(), name, KLogMissingParameter, dataOk);
   1.295 +
   1.296 +	TSize	size(KConsFullScreen, KConsFullScreen);
   1.297 +	GetSizeFromConfig(aSection, KFldConsoleSize(), size);
   1.298 +	TInt	error=KErrNone;
   1.299 +	if ( dataOk )
   1.300 +		{
   1.301 +		error=iConsole->Init(name, size);
   1.302 +		}
   1.303 +
   1.304 +	return error;
   1.305 +	}
   1.306 +
   1.307 +TInt CT_RConsoleData::DoCmdDestroy()
   1.308 + /**
   1.309 + *	Wrapper function for RConsole::Destroy()
   1.310 + */
   1.311 +	{
   1.312 +	return iConsole->Destroy();
   1.313 +	}
   1.314 +
   1.315 +TInt CT_RConsoleData::DoCmdCreate()
   1.316 + /**
   1.317 + *	Wrapper function for RConsole::Create()
   1.318 + */
   1.319 +	{
   1.320 +	return iConsole->Create();
   1.321 +	}
   1.322 +
   1.323 +TInt CT_RConsoleData::DoCmdClearScreen()
   1.324 + /**
   1.325 + *	Wrapper function for RConsole::ClearScreen()
   1.326 + *
   1.327 + */
   1.328 +	{
   1.329 +	return iConsole->ClearScreen();
   1.330 +	}
   1.331 +
   1.332 +void CT_RConsoleData::RunL(CActive* aActive, TInt aIndex)
   1.333 + /**
   1.334 + * Called on completion of an asynchronous command
   1.335 + * @param               aActive Active Object that RunL has been called on
   1.336 + * @param               aIndex number of the command.
   1.337 + * @pre                 N/A
   1.338 + * @post                N/A
   1.339 + * @leave               system wide error code
   1.340 + */
   1.341 +	{
   1.342 +	TBool	activeOk=ETrue;
   1.343 +	TInt	err=KErrNone;
   1.344 +	if ( aActive!=NULL )
   1.345 +		{
   1.346 +		err=aActive->iStatus.Int();
   1.347 +		}
   1.348 +
   1.349 +	TBool	moreToDo=EFalse;
   1.350 +	if(	aActive==iActiveRConsoleRead)
   1.351 +		{
   1.352 +		iActiveRConsoleRead->KillTimer();
   1.353 +		if ( err==KErrNone )
   1.354 +			{
   1.355 +			
   1.356 +			moreToDo=iActiveRConsoleRead->VerifyDataAndKick(aIndex, *iConsole);
   1.357 +			if ( !moreToDo )
   1.358 +				{
   1.359 +				INFO_PRINTF1(_L("All Events have been read"));
   1.360 +				}
   1.361 +			}
   1.362 +
   1.363 +		}
   1.364 +	else
   1.365 +		{
   1.366 +		activeOk=EFalse;
   1.367 +		ERR_PRINTF1(KLogStraySignal);
   1.368 +		SetBlockResult(EFail);
   1.369 +		}
   1.370 +
   1.371 +	if ( activeOk )
   1.372 +		{
   1.373 +		if ( !moreToDo )
   1.374 +			{
   1.375 +			DecOutstanding();
   1.376 +			}
   1.377 +		if ( err!=KErrNone )
   1.378 +			{
   1.379 +			ERR_PRINTF2(KLogAsyncError, err);
   1.380 +			SetAsyncError(aIndex, err);
   1.381 +			}
   1.382 +		}
   1.383 +	}
   1.384 +
   1.385 +void CT_RConsoleData::DoCancel(CActive* aActive, TInt aIndex)
   1.386 + /**
   1.387 + * Called on cancellation of an asynchronous command
   1.388 + * @param               aActive Active Object that RunL has been called on
   1.389 + * @param               aIndex number of the command.
   1.390 + */
   1.391 +	{
   1.392 +	TBool	activeOk=ETrue;
   1.393 +	TInt	err=KErrNone;
   1.394 +		
   1.395 +	if ( aActive==iActiveRConsoleRead )
   1.396 +		{
   1.397 +		INFO_PRINTF1(_L("ReadCancel Called"));
   1.398 +		iActiveRConsoleRead->KillTimer();
   1.399 +		iConsole->ReadCancel();
   1.400 +		err=aActive->iStatus.Int();
   1.401 +		}
   1.402 +	else
   1.403 +		{
   1.404 +		activeOk=EFalse;
   1.405 +		ERR_PRINTF1(KLogStraySignal);
   1.406 +		SetBlockResult(EFail);
   1.407 +		}
   1.408 +
   1.409 +	if ( activeOk )
   1.410 +		{
   1.411 +		DecOutstanding();
   1.412 +	 	if( err != KErrNone )
   1.413 +            {
   1.414 +            ERR_PRINTF2(_L("DoCancel Error %d"), err);
   1.415 +            SetAsyncError( aIndex, err );
   1.416 +            }
   1.417 +		}
   1.418 +
   1.419 +	}