os/boardsupport/haitest/bspsvs/suite/e32/src/T_RConsoleData.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /*
     2 * Copyright (c) 2005-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:
    15 *
    16 */
    17 
    18 #include "T_RConsoleData.h"
    19 
    20 
    21 /*@{*/
    22 //wrappers
    23 _LIT(KCmdRead,				"Read");
    24 _LIT(KCmdWrite,				"Write");
    25 _LIT(KCmdControl,			"Control");
    26 _LIT(KCmdInit,				"Init");
    27 _LIT(KCmdDestroy,			"Destroy");
    28 _LIT(KCmdCreate,			"Create");
    29 _LIT(KCmdConstructor,		"new");
    30 _LIT(KCmdDestructor,		"~");
    31 _LIT(KCmdClearScreen,		"ClearScreen");
    32 
    33 //ini sections
    34 _LIT(KFldText,				"text");
    35 _LIT(KFldConsoleControl,	"consoleControl");
    36 _LIT(KFldConsoleName,		"consoleName");
    37 _LIT(KFldConsoleSize,		"consoleSize");
    38 _LIT(KFldSynchronous,		"synchronous");
    39 
    40 //format fields
    41 _LIT(KLogMissingParameter,	"Missing parameter '%S'");
    42 _LIT(KLogError,				"Error=%d");
    43 _LIT(KLogStringNotFound,	"String not found %S");
    44 _LIT(KLogStraySignal,		"Stray signal");
    45 _LIT(KLogAsyncError,		"Async RunL Error %d");
    46 _LIT(KLogDataMissing,		"Data missing for test");
    47 /*@}*/
    48 
    49 
    50 //////////////////////////////////////////////////////////////////////
    51 // Construction/Destruction
    52 //////////////////////////////////////////////////////////////////////
    53 
    54 CT_RConsoleData* CT_RConsoleData::NewL()
    55 	{
    56 	CT_RConsoleData* console=new (ELeave) CT_RConsoleData();
    57 	CleanupStack::PushL(console);
    58 	console->ConstructL();
    59 	CleanupStack::Pop(console);
    60 	return console;
    61 	}
    62 
    63 CT_RConsoleData::CT_RConsoleData()
    64 :	CT_RSessionBaseData()
    65 ,	iActiveRConsoleRead(NULL)
    66 ,	iConsole(NULL)
    67 	{
    68 	}
    69 
    70 void CT_RConsoleData::ConstructL()
    71 /**
    72  * Second phase construction
    73  *
    74  * @internalComponent
    75  *
    76  * @return	N/A
    77  *
    78  * @pre		None
    79  * @post	None
    80  *
    81  * @leave	system wide error
    82  */
    83 	{
    84 	iActiveRConsoleRead	= CT_ActiveRConsoleRead::NewL(*this);
    85 	}
    86 
    87 CT_RConsoleData::~CT_RConsoleData()
    88 /**
    89  * Public destructor
    90  */
    91 	{
    92 	DestroyData();
    93 	delete iActiveRConsoleRead;
    94 	iActiveRConsoleRead= 	NULL;
    95 	}
    96 
    97 void CT_RConsoleData::DestroyData()
    98  /**
    99  *	RConsole Destruction
   100  *
   101  */
   102 	{
   103  	delete	iConsole;
   104  	iConsole	=NULL;
   105 	}
   106 
   107 
   108  TAny* CT_RConsoleData::GetObject()
   109 /**
   110  * Return a pointer to the object that the data wraps
   111  *
   112  * @return	pointer to the object that the data wraps
   113  */
   114 	{
   115 	return iConsole;
   116 	}
   117 
   118 RSessionBase* CT_RConsoleData::GetSessionBase()
   119 	{
   120 	return iConsole;
   121 	}
   122 
   123 RHandleBase* CT_RConsoleData::GetHandleBase()
   124 	{
   125 	return iConsole;
   126 	}
   127 
   128 TBool CT_RConsoleData::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt aAsyncErrorIndex)
   129 /**
   130  * Process a command read from the ini file
   131  *
   132  * @param aCommand                      The command to process
   133  * @param aSection                      The section in the ini containing data for the command
   134  * @param aAsyncErrorIndex              Command index for async calls to return errors to
   135  *
   136  * @return                              ETrue if the command is processed
   137  *
   138  * @leave                               System wide error
   139  */
   140 	{
   141 	TBool 	ret	=ETrue;
   142 	TInt	error=KErrNone;
   143 
   144 	if (aCommand==KCmdConstructor())
   145 		{
   146 		error	=DoCmdConstructor();
   147 		}
   148 	else if ( aCommand==KCmdDestructor )
   149 		{
   150 		DoCmdDestructor();
   151 		}
   152 	else if ( aCommand==KCmdRead())
   153 		{
   154 		error	=DoCmdRead(aSection, aAsyncErrorIndex);
   155 		}
   156 	else if ( aCommand==KCmdWrite())
   157 		{
   158 		error	=DoCmdWrite(aSection);
   159 		}
   160 	else if ( aCommand==KCmdDestroy())
   161 		{
   162 		error	=DoCmdDestroy();
   163 		}
   164 	else if ( aCommand==KCmdControl())
   165 		{
   166 		error	=DoCmdControl(aSection);
   167 		}
   168 	else if ( aCommand==KCmdInit())
   169 		{
   170 		error	=DoCmdInit(aSection);
   171 		}
   172 	else if ( aCommand==KCmdCreate())
   173 		{
   174 		error	=DoCmdCreate();
   175 		}
   176 	else if ( aCommand==KCmdClearScreen())
   177 		{
   178 		error	=DoCmdClearScreen();
   179 		}
   180 	else
   181 		{
   182 		ret=CT_RSessionBaseData::DoCommandL(aCommand, aSection, aAsyncErrorIndex);
   183 		}
   184 
   185 	if ( error!=KErrNone )
   186 		{
   187 		ERR_PRINTF2(KLogError, error);
   188 		SetError(error);
   189 		}
   190 
   191 	return ret;
   192 	}
   193 
   194 TInt CT_RConsoleData::DoCmdConstructor()
   195  /**
   196  *	Wrapper function for RConsole Construction
   197  *
   198  */
   199 	{
   200 	DestroyData();
   201 	TRAPD(err, iConsole=new (ELeave) RConsole());
   202 	return err;
   203 	}
   204 
   205 void CT_RConsoleData::DoCmdDestructor()
   206  /**
   207  *	Wrapper function for RConsole Destruction
   208  *
   209  */
   210 	{
   211 	DestroyData();
   212 	}
   213 
   214 TInt CT_RConsoleData::DoCmdRead(const TDesC& aSection , const TInt aAsyncErrorIndex)
   215  /**
   216  *	Wrapper function for RConsole::Read(TConsoleKey &aKeystroke,TRequestStatus &aStatus)
   217  * 	and RConsole::Read(TConsoleKey &aKeystroke)
   218  *
   219  *	@param		aSection			The section in the ini containing data for the command
   220  * 	@param		aAsyncErrorIndex	Command index for async calls to return errors to
   221  */
   222  	{
   223  	TBool	sync=EFalse;
   224 	GETFROMCONFIGOPTIONAL(Bool, aSection, KFldSynchronous(), sync, KLogMissingParameter);
   225 
   226 	TInt	error=KErrNone;
   227 	if ( !sync )
   228 		{
   229 		if ( !iActiveRConsoleRead->KickStartL(aSection, aAsyncErrorIndex, *iConsole) )
   230 			{
   231 			ERR_PRINTF1(KLogDataMissing);
   232 			SetBlockResult(EFail);
   233 			}
   234 		else
   235 			{
   236 			IncOutstanding();
   237 			}
   238 		}
   239 	else
   240 		{
   241 		TConsoleKey	key;
   242 		error=iConsole->Read(key);
   243 		}
   244 	return error;
   245  	}
   246 
   247 TInt CT_RConsoleData::DoCmdWrite(const TDesC& aSection )
   248  /**
   249  *	Wrapper function for RConsole::Write(const TDesC &aDes)
   250  *	@param		aSection			The section in the ini containing data for the command
   251  */
   252  	{
   253 	TBool dataOk	=EFalse;
   254 	TInt error		=KErrNone;
   255 	TPtrC string;
   256 	GETSTRINGFROMCONFIGMANDATORY(aSection, KFldText(), string, KLogStringNotFound,  dataOk);
   257 	if ( dataOk==KErrNone)
   258 		{
   259 		error	=iConsole->Write(string);
   260 		}
   261 	return error;
   262  	}
   263 
   264 TInt CT_RConsoleData::DoCmdControl(const TDesC& aSection)
   265  /**
   266  *	Wrapper function for RConsole::Control(const TDesC &aDes)
   267  *	@param		aSection			The section in the ini containing data for the command
   268  */
   269 	{
   270 	TBool dataOk	=EFalse;
   271 	TInt error	=KErrNone;
   272 	TPtrC control;
   273 	GETSTRINGFROMCONFIGMANDATORY(aSection, KFldConsoleControl(), control, KLogStringNotFound, dataOk);
   274 	if (dataOk==KErrNone)
   275 		{
   276 		error	=iConsole->Control(control);
   277 		}
   278 	return error;
   279 	}
   280 
   281 TInt CT_RConsoleData::DoCmdInit(const TDesC& aSection)
   282  /**
   283  *	Wrapper function for RConsole::Init(const TDesC &aName,const TSize &aSize
   284  *	@param		aSection			The section in the ini containing data for the command
   285  */
   286 	{
   287 
   288 	TBool	dataOk=ETrue;
   289 
   290 	TPtrC	name;
   291 	GETSTRINGFROMCONFIGMANDATORY(aSection, KFldConsoleName(), name, KLogMissingParameter, dataOk);
   292 
   293 	TSize	size(KConsFullScreen, KConsFullScreen);
   294 	GetSizeFromConfig(aSection, KFldConsoleSize(), size);
   295 	TInt	error=KErrNone;
   296 	if ( dataOk )
   297 		{
   298 		error=iConsole->Init(name, size);
   299 		}
   300 
   301 	return error;
   302 	}
   303 
   304 TInt CT_RConsoleData::DoCmdDestroy()
   305  /**
   306  *	Wrapper function for RConsole::Destroy()
   307  */
   308 	{
   309 	return iConsole->Destroy();
   310 	}
   311 
   312 TInt CT_RConsoleData::DoCmdCreate()
   313  /**
   314  *	Wrapper function for RConsole::Create()
   315  */
   316 	{
   317 	return iConsole->Create();
   318 	}
   319 
   320 TInt CT_RConsoleData::DoCmdClearScreen()
   321  /**
   322  *	Wrapper function for RConsole::ClearScreen()
   323  *
   324  */
   325 	{
   326 	return iConsole->ClearScreen();
   327 	}
   328 
   329 void CT_RConsoleData::RunL(CActive* aActive, TInt aIndex)
   330  /**
   331  * Called on completion of an asynchronous command
   332  * @param               aActive Active Object that RunL has been called on
   333  * @param               aIndex number of the command.
   334  * @pre                 N/A
   335  * @post                N/A
   336  * @leave               system wide error code
   337  */
   338 	{
   339 	TBool	activeOk=ETrue;
   340 	TInt	err=KErrNone;
   341 	if ( aActive!=NULL )
   342 		{
   343 		err=aActive->iStatus.Int();
   344 		}
   345 
   346 	TBool	moreToDo=EFalse;
   347 	if(	aActive==iActiveRConsoleRead)
   348 		{
   349 		iActiveRConsoleRead->KillTimer();
   350 		if ( err==KErrNone )
   351 			{
   352 			
   353 			moreToDo=iActiveRConsoleRead->VerifyDataAndKick(aIndex, *iConsole);
   354 			if ( !moreToDo )
   355 				{
   356 				INFO_PRINTF1(_L("All Events have been read"));
   357 				}
   358 			}
   359 
   360 		}
   361 	else
   362 		{
   363 		activeOk=EFalse;
   364 		ERR_PRINTF1(KLogStraySignal);
   365 		SetBlockResult(EFail);
   366 		}
   367 
   368 	if ( activeOk )
   369 		{
   370 		if ( !moreToDo )
   371 			{
   372 			DecOutstanding();
   373 			}
   374 		if ( err!=KErrNone )
   375 			{
   376 			ERR_PRINTF2(KLogAsyncError, err);
   377 			SetAsyncError(aIndex, err);
   378 			}
   379 		}
   380 	}
   381 
   382 void CT_RConsoleData::DoCancel(CActive* aActive, TInt aIndex)
   383  /**
   384  * Called on cancellation of an asynchronous command
   385  * @param               aActive Active Object that RunL has been called on
   386  * @param               aIndex number of the command.
   387  */
   388 	{
   389 	TBool	activeOk=ETrue;
   390 	TInt	err=KErrNone;
   391 		
   392 	if ( aActive==iActiveRConsoleRead )
   393 		{
   394 		INFO_PRINTF1(_L("ReadCancel Called"));
   395 		iActiveRConsoleRead->KillTimer();
   396 		iConsole->ReadCancel();
   397 		err=aActive->iStatus.Int();
   398 		}
   399 	else
   400 		{
   401 		activeOk=EFalse;
   402 		ERR_PRINTF1(KLogStraySignal);
   403 		SetBlockResult(EFail);
   404 		}
   405 
   406 	if ( activeOk )
   407 		{
   408 		DecOutstanding();
   409 	 	if( err != KErrNone )
   410             {
   411             ERR_PRINTF2(_L("DoCancel Error %d"), err);
   412             SetAsyncError( aIndex, err );
   413             }
   414 		}
   415 
   416 	}