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