Update contrib.
2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
18 #include "T_RConsoleData.h"
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");
34 _LIT(KFldText, "text");
35 _LIT(KFldConsoleControl, "consoleControl");
36 _LIT(KFldConsoleName, "consoleName");
37 _LIT(KFldConsoleSize, "consoleSize");
38 _LIT(KFldSynchronous, "synchronous");
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");
50 //////////////////////////////////////////////////////////////////////
51 // Construction/Destruction
52 //////////////////////////////////////////////////////////////////////
54 CT_RConsoleData* CT_RConsoleData::NewL()
56 CT_RConsoleData* console=new (ELeave) CT_RConsoleData();
57 CleanupStack::PushL(console);
58 console->ConstructL();
59 CleanupStack::Pop(console);
63 CT_RConsoleData::CT_RConsoleData()
64 : CT_RSessionBaseData()
65 , iActiveRConsoleRead(NULL)
70 void CT_RConsoleData::ConstructL()
72 * Second phase construction
81 * @leave system wide error
84 iActiveRConsoleRead = CT_ActiveRConsoleRead::NewL(*this);
87 CT_RConsoleData::~CT_RConsoleData()
93 delete iActiveRConsoleRead;
94 iActiveRConsoleRead= NULL;
97 void CT_RConsoleData::DestroyData()
99 * RConsole Destruction
108 TAny* CT_RConsoleData::GetObject()
110 * Return a pointer to the object that the data wraps
112 * @return pointer to the object that the data wraps
118 RSessionBase* CT_RConsoleData::GetSessionBase()
123 RHandleBase* CT_RConsoleData::GetHandleBase()
128 TBool CT_RConsoleData::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt aAsyncErrorIndex)
130 * Process a command read from the ini file
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
136 * @return ETrue if the command is processed
138 * @leave System wide error
144 if (aCommand==KCmdConstructor())
146 error =DoCmdConstructor();
148 else if ( aCommand==KCmdDestructor )
152 else if ( aCommand==KCmdRead())
154 error =DoCmdRead(aSection, aAsyncErrorIndex);
156 else if ( aCommand==KCmdWrite())
158 error =DoCmdWrite(aSection);
160 else if ( aCommand==KCmdDestroy())
162 error =DoCmdDestroy();
164 else if ( aCommand==KCmdControl())
166 error =DoCmdControl(aSection);
168 else if ( aCommand==KCmdInit())
170 error =DoCmdInit(aSection);
172 else if ( aCommand==KCmdCreate())
174 error =DoCmdCreate();
176 else if ( aCommand==KCmdClearScreen())
178 error =DoCmdClearScreen();
182 ret=CT_RSessionBaseData::DoCommandL(aCommand, aSection, aAsyncErrorIndex);
185 if ( error!=KErrNone )
187 ERR_PRINTF2(KLogError, error);
194 TInt CT_RConsoleData::DoCmdConstructor()
196 * Wrapper function for RConsole Construction
201 TRAPD(err, iConsole=new (ELeave) RConsole());
205 void CT_RConsoleData::DoCmdDestructor()
207 * Wrapper function for RConsole Destruction
214 TInt CT_RConsoleData::DoCmdRead(const TDesC& aSection , const TInt aAsyncErrorIndex)
216 * Wrapper function for RConsole::Read(TConsoleKey &aKeystroke,TRequestStatus &aStatus)
217 * and RConsole::Read(TConsoleKey &aKeystroke)
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
224 GETFROMCONFIGOPTIONAL(Bool, aSection, KFldSynchronous(), sync, KLogMissingParameter);
229 if ( !iActiveRConsoleRead->KickStartL(aSection, aAsyncErrorIndex, *iConsole) )
231 ERR_PRINTF1(KLogDataMissing);
232 SetBlockResult(EFail);
242 error=iConsole->Read(key);
247 TInt CT_RConsoleData::DoCmdWrite(const TDesC& aSection )
249 * Wrapper function for RConsole::Write(const TDesC &aDes)
250 * @param aSection The section in the ini containing data for the command
253 TBool dataOk =EFalse;
254 TInt error =KErrNone;
256 GETSTRINGFROMCONFIGMANDATORY(aSection, KFldText(), string, KLogStringNotFound, dataOk);
257 if ( dataOk==KErrNone)
259 error =iConsole->Write(string);
264 TInt CT_RConsoleData::DoCmdControl(const TDesC& aSection)
266 * Wrapper function for RConsole::Control(const TDesC &aDes)
267 * @param aSection The section in the ini containing data for the command
270 TBool dataOk =EFalse;
271 TInt error =KErrNone;
273 GETSTRINGFROMCONFIGMANDATORY(aSection, KFldConsoleControl(), control, KLogStringNotFound, dataOk);
274 if (dataOk==KErrNone)
276 error =iConsole->Control(control);
281 TInt CT_RConsoleData::DoCmdInit(const TDesC& aSection)
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
291 GETSTRINGFROMCONFIGMANDATORY(aSection, KFldConsoleName(), name, KLogMissingParameter, dataOk);
293 TSize size(KConsFullScreen, KConsFullScreen);
294 GetSizeFromConfig(aSection, KFldConsoleSize(), size);
298 error=iConsole->Init(name, size);
304 TInt CT_RConsoleData::DoCmdDestroy()
306 * Wrapper function for RConsole::Destroy()
309 return iConsole->Destroy();
312 TInt CT_RConsoleData::DoCmdCreate()
314 * Wrapper function for RConsole::Create()
317 return iConsole->Create();
320 TInt CT_RConsoleData::DoCmdClearScreen()
322 * Wrapper function for RConsole::ClearScreen()
326 return iConsole->ClearScreen();
329 void CT_RConsoleData::RunL(CActive* aActive, TInt aIndex)
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.
336 * @leave system wide error code
339 TBool activeOk=ETrue;
343 err=aActive->iStatus.Int();
346 TBool moreToDo=EFalse;
347 if( aActive==iActiveRConsoleRead)
349 iActiveRConsoleRead->KillTimer();
353 moreToDo=iActiveRConsoleRead->VerifyDataAndKick(aIndex, *iConsole);
356 INFO_PRINTF1(_L("All Events have been read"));
364 ERR_PRINTF1(KLogStraySignal);
365 SetBlockResult(EFail);
376 ERR_PRINTF2(KLogAsyncError, err);
377 SetAsyncError(aIndex, err);
382 void CT_RConsoleData::DoCancel(CActive* aActive, TInt aIndex)
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.
389 TBool activeOk=ETrue;
392 if ( aActive==iActiveRConsoleRead )
394 INFO_PRINTF1(_L("ReadCancel Called"));
395 iActiveRConsoleRead->KillTimer();
396 iConsole->ReadCancel();
397 err=aActive->iStatus.Int();
402 ERR_PRINTF1(KLogStraySignal);
403 SetBlockResult(EFail);
409 if( err != KErrNone )
411 ERR_PRINTF2(_L("DoCancel Error %d"), err);
412 SetAsyncError( aIndex, err );