|
1 // Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // $Header$ |
|
15 // This module implements the collection of stadard command classes for the |
|
16 // tester framework. |
|
17 // rev: mjdavey, symbian@mjdss.com, July 2002 |
|
18 // for: Typhoon (7.0s) & JetStream (8.0) |
|
19 // Include Definition Files |
|
20 // |
|
21 // |
|
22 |
|
23 #include "CCmdStandard.h" |
|
24 |
|
25 //----------------------------------------------------------------------------- |
|
26 //----------------------------------------------------------------------------- |
|
27 // Comment command. |
|
28 //----------------------------------------------------------------------------- |
|
29 //----------------------------------------------------------------------------- |
|
30 |
|
31 CCmdRemark *CCmdRemark::NewL(TInt aCommandId, const TDesC& aKeyphrase) |
|
32 { |
|
33 CCmdRemark* self = NewLC(aCommandId, aKeyphrase); |
|
34 CleanupStack::Pop(); |
|
35 return self; |
|
36 } |
|
37 |
|
38 //----------------------------------------------------------------------------- |
|
39 |
|
40 CCmdRemark *CCmdRemark::NewLC( TInt aCommandId, const TDesC& aKeyphrase ) |
|
41 { |
|
42 CCmdRemark* self = new (ELeave) CCmdRemark(); |
|
43 CleanupStack::PushL(self); |
|
44 self->ConstructL( aCommandId, aKeyphrase ); |
|
45 return self; |
|
46 } |
|
47 |
|
48 //----------------------------------------------------------------------------- |
|
49 |
|
50 void CCmdRemark::ConstructL( TInt aCommandId, const TDesC& aKeyphrase ) |
|
51 { |
|
52 CCmdBase::ConstructL( aCommandId, aKeyphrase ); |
|
53 } |
|
54 |
|
55 //----------------------------------------------------------------------------- |
|
56 |
|
57 TBool CCmdRemark::Recognize( const TDesC& aCommand ) |
|
58 { |
|
59 // Obey the command family's step over mode. |
|
60 SetStepOver(Family()->StepOver()); |
|
61 |
|
62 // Check if is empty or begins with # character. |
|
63 TPtrC cmd = TfrLex::Trim(aCommand); |
|
64 |
|
65 // look for empty, # or // |
|
66 return ((cmd.Length() == 0) || (cmd.Match( _L("#*")) == 0) || (cmd.Match(_L("//*")) == 0 )); |
|
67 } |
|
68 |
|
69 //----------------------------------------------------------------------------- |
|
70 |
|
71 TInt CCmdRemark::ProcessL( const TDesC& aCommand ) |
|
72 { |
|
73 // Complete the test machine - will then get the next cmd |
|
74 Machine()->CompleteRequest(); |
|
75 |
|
76 if (!Recognize(aCommand)) |
|
77 return Error(KErrArgument, TFR_KFmtErrBadCmd, &Keyphrase()); |
|
78 |
|
79 // Do nothing. |
|
80 return KErrNone; |
|
81 } |
|
82 |
|
83 //----------------------------------------------------------------------------- |
|
84 //----------------------------------------------------------------------------- |
|
85 // Command: EXIT command. |
|
86 //----------------------------------------------------------------------------- |
|
87 //----------------------------------------------------------------------------- |
|
88 |
|
89 CCmdExit *CCmdExit::NewL( TInt aCommandId, const TDesC& aKeyphrase ) |
|
90 { |
|
91 CCmdExit* self = NewLC( aCommandId, aKeyphrase ); |
|
92 CleanupStack::Pop(); |
|
93 return self; |
|
94 } |
|
95 |
|
96 //----------------------------------------------------------------------------- |
|
97 |
|
98 CCmdExit *CCmdExit::NewLC(TInt aCommandId, const TDesC &aKeyphrase) |
|
99 { |
|
100 CCmdExit* self = new (ELeave) CCmdExit(); |
|
101 CleanupStack::PushL(self); |
|
102 self->ConstructL(aCommandId, aKeyphrase); |
|
103 return self; |
|
104 } |
|
105 |
|
106 //----------------------------------------------------------------------------- |
|
107 |
|
108 void CCmdExit::ConstructL(TInt aCommandId, const TDesC &aKeyphrase) |
|
109 { |
|
110 CCmdBase::ConstructL(aCommandId, aKeyphrase); |
|
111 } |
|
112 |
|
113 //----------------------------------------------------------------------------- |
|
114 |
|
115 TInt CCmdExit::ProcessL(const TDesC &aCommand) |
|
116 { |
|
117 // Complete the test machine - will then get the next cmd |
|
118 Machine()->CompleteRequest(); |
|
119 |
|
120 TPtrC param; |
|
121 TRAPD(error, param.Set(ParamsL(aCommand))); |
|
122 if (error != KErrNone ) |
|
123 return Error(error, TFR_KFmtErrBadCmd, &Keyphrase()); |
|
124 |
|
125 TLex parse( param ); |
|
126 if (!parse.Eos() && !parse.Peek().IsSpace()) |
|
127 return Error( error, TFR_KFmtErrBadCmd, &Keyphrase()); |
|
128 |
|
129 // Print out param if any and stop. |
|
130 param.Set( TfrLex::Peel(param)); |
|
131 if (param.Length() > 0) |
|
132 Print(param); |
|
133 |
|
134 Machine()->StopEngine(); |
|
135 return error; |
|
136 } |
|
137 |
|
138 //----------------------------------------------------------------------------- |
|
139 //----------------------------------------------------------------------------- |
|
140 // Command: ECHOMODE On/Off command. |
|
141 //----------------------------------------------------------------------------- |
|
142 //----------------------------------------------------------------------------- |
|
143 |
|
144 CCmdEchoMode *CCmdEchoMode::NewL( TInt aCommandId, const TDesC& aKeyphrase ) |
|
145 { |
|
146 CCmdEchoMode* self = NewLC( aCommandId, aKeyphrase ); |
|
147 CleanupStack::Pop(); |
|
148 return self; |
|
149 } |
|
150 |
|
151 //----------------------------------------------------------------------------- |
|
152 |
|
153 CCmdEchoMode *CCmdEchoMode::NewLC( TInt aCommandId, const TDesC& aKeyphrase ) |
|
154 { |
|
155 CCmdEchoMode* self = new (ELeave) CCmdEchoMode(); |
|
156 CleanupStack::PushL( self ); |
|
157 self->ConstructL( aCommandId, aKeyphrase ); |
|
158 return self; |
|
159 } |
|
160 |
|
161 //----------------------------------------------------------------------------- |
|
162 |
|
163 void CCmdEchoMode::ConstructL( TInt aCommandId, const TDesC& aKeyphrase ) |
|
164 { |
|
165 CCmdBase::ConstructL( aCommandId, aKeyphrase ); |
|
166 } |
|
167 |
|
168 //----------------------------------------------------------------------------- |
|
169 |
|
170 TInt CCmdEchoMode::ProcessL(const TDesC& aCommand) |
|
171 { |
|
172 // Complete the test machine - will then get the next cmd |
|
173 Machine()->CompleteRequest(); |
|
174 |
|
175 TPtrC param; |
|
176 TRAPD(error, param.Set(ParamsL(aCommand))); |
|
177 if (error != KErrNone) |
|
178 return Error(error, TFR_KFmtErrBadCmd, &Keyphrase()); |
|
179 |
|
180 TLex parse( param ); |
|
181 if (!parse.Peek().IsSpace()) |
|
182 return Error(error, TFR_KFmtErrBadCmd, &Keyphrase()); |
|
183 |
|
184 // Param shall be On or Off? |
|
185 param.Set(TfrLex::TrimAndPeel(param)); |
|
186 TBool value = (param.CompareF(TFR_KTxtTermOn) == 0); |
|
187 if ( !value && param.CompareF(TFR_KTxtTermOff) != 0) |
|
188 return Error(KErrArgument, TFR_KFmtErrBadCmd, &Keyphrase()); |
|
189 |
|
190 // Set Echo Mode On/Off. |
|
191 Machine()->SetEchoMode(value); |
|
192 return error; |
|
193 } |
|
194 |
|
195 //----------------------------------------------------------------------------- |
|
196 //----------------------------------------------------------------------------- |
|
197 // Command: CHECKMODE on/off command. |
|
198 //----------------------------------------------------------------------------- |
|
199 //----------------------------------------------------------------------------- |
|
200 |
|
201 CCmdCheckMode* CCmdCheckMode::NewL( TInt aCommandId, const TDesC& aKeyphrase ) |
|
202 { |
|
203 CCmdCheckMode* self = NewLC( aCommandId, aKeyphrase ); |
|
204 CleanupStack::Pop(); |
|
205 return self; |
|
206 } |
|
207 |
|
208 //----------------------------------------------------------------------------- |
|
209 |
|
210 CCmdCheckMode* CCmdCheckMode::NewLC( TInt aCommandId, const TDesC& aKeyphrase ) |
|
211 { |
|
212 CCmdCheckMode* self = new (ELeave) CCmdCheckMode(); |
|
213 CleanupStack::PushL( self ); |
|
214 self->ConstructL( aCommandId, aKeyphrase ); |
|
215 return self; |
|
216 } |
|
217 |
|
218 //----------------------------------------------------------------------------- |
|
219 |
|
220 void CCmdCheckMode::ConstructL( TInt aCommandId, const TDesC& aKeyphrase ) |
|
221 { |
|
222 CCmdBase::ConstructL( aCommandId, aKeyphrase ); |
|
223 } |
|
224 |
|
225 //----------------------------------------------------------------------------- |
|
226 |
|
227 TInt CCmdCheckMode::ProcessL( const TDesC& aCommand ) |
|
228 { |
|
229 // Complete the test machine - will then get the next cmd |
|
230 Machine()->CompleteRequest(); |
|
231 |
|
232 TPtrC param; |
|
233 TRAPD( error, param.Set( ParamsL( aCommand )) ); |
|
234 if ( error != KErrNone ) |
|
235 return Error( error, TFR_KFmtErrBadCmd, &Keyphrase() ); |
|
236 |
|
237 TLex parse( param ); |
|
238 if ( !parse.Peek().IsSpace() ) |
|
239 return Error( error, TFR_KFmtErrBadCmd, &Keyphrase() ); |
|
240 |
|
241 // Param shall On or Off? |
|
242 param.Set( TfrLex::TrimAndPeel( param ) ); |
|
243 TBool value = (param.CompareF(TFR_KTxtTermOn) == 0); |
|
244 if ( !value && param.CompareF(TFR_KTxtTermOff) != 0 ) |
|
245 return Error( KErrArgument, TFR_KFmtErrBadCmd, &Keyphrase() ); |
|
246 |
|
247 // Set Check Mode (ParseOnly) On/Off. |
|
248 Family()->SetSwitch(CCmdFamily::EParseOnly, value); |
|
249 return error; |
|
250 } |
|
251 |
|
252 //----------------------------------------------------------------------------- |
|
253 //----------------------------------------------------------------------------- |
|
254 // Command: PRINT command. |
|
255 //----------------------------------------------------------------------------- |
|
256 //----------------------------------------------------------------------------- |
|
257 |
|
258 CCmdPrint *CCmdPrint::NewL(TInt aCommandId, const TDesC& aKeyphrase, const TDesC& aHelpPhrase) |
|
259 { |
|
260 CCmdPrint *self = NewLC(aCommandId, aKeyphrase, aHelpPhrase); |
|
261 CleanupStack::Pop(); |
|
262 return self; |
|
263 } |
|
264 |
|
265 //----------------------------------------------------------------------------- |
|
266 |
|
267 CCmdPrint *CCmdPrint::NewLC(TInt aCommandId, const TDesC& aKeyphrase, const TDesC& aHelpPhrase) |
|
268 { |
|
269 CCmdPrint *self = new (ELeave) CCmdPrint(); |
|
270 CleanupStack::PushL(self); |
|
271 self->ConstructL(aCommandId, aKeyphrase, aHelpPhrase); |
|
272 return self; |
|
273 } |
|
274 |
|
275 //----------------------------------------------------------------------------- |
|
276 |
|
277 void CCmdPrint::ConstructL(TInt aCommandId, const TDesC& aKeyphrase, const TDesC& aHelpPhrase) |
|
278 { |
|
279 CCmdBase::ConstructL(aCommandId, aKeyphrase, aHelpPhrase); |
|
280 |
|
281 // set the dummy echo mode |
|
282 iCurEchoMode = EFalse; |
|
283 } |
|
284 |
|
285 //----------------------------------------------------------------------------- |
|
286 // look for PRINT* but note that Match is casesensitive and hence use temp TBuf value to check |
|
287 // and note that the command string might be quite long (and we're only interested in the |
|
288 // first left bit!! |
|
289 |
|
290 TBool CCmdPrint::Recognize(const TDesC& aCommand) |
|
291 { |
|
292 TBuf<16> iCmd = aCommand.Left(5); |
|
293 iCmd.UpperCase(); |
|
294 TInt iResult = iCmd.Match(THA_TxtCmdPrint); |
|
295 |
|
296 if (iResult == KErrNotFound) // NF(-1) otherwise >=0 here means position of string in host |
|
297 return EFalse; |
|
298 |
|
299 return ETrue; // accept it for now! |
|
300 } |
|
301 |
|
302 //----------------------------------------------------------------------------- |
|
303 |
|
304 TInt CCmdPrint::ProcessL(const TDesC& aCommand) |
|
305 { |
|
306 // Complete the test machine - will then get the next cmd |
|
307 Machine()->CompleteRequest(); |
|
308 |
|
309 TPtrC param; |
|
310 TRAPD(error, param.Set(ParamsL(aCommand))); |
|
311 if (error != KErrNone) |
|
312 return Error(error, TFR_KFmtErrBadCmd, &Keyphrase()); |
|
313 |
|
314 TLex parse(param); |
|
315 if ( !parse.Eos() && !parse.Peek().IsSpace() ) |
|
316 return Error(error, TFR_KFmtErrBadCmd, &Keyphrase()); |
|
317 |
|
318 // ParseOnly => not executed. |
|
319 if (Family()->Switch(CCmdFamily::EParseOnly)) |
|
320 return error; |
|
321 |
|
322 iCurEchoMode = Machine()->EchoMode(); |
|
323 Machine()->SetEchoMode(EFalse); |
|
324 |
|
325 // Print out the param text. |
|
326 param.Set(TfrLex::TrimAndPeel(param)); |
|
327 //Print(param, EFalse); |
|
328 Print(param, ETrue); |
|
329 //Print(param.Mid(6), EFalse); |
|
330 |
|
331 // reset the echo mode to that of before this command! |
|
332 Machine()->SetEchoMode(iCurEchoMode); |
|
333 |
|
334 return error; |
|
335 } |
|
336 |
|
337 //----------------------------------------------------------------------------- |
|
338 //----------------------------------------------------------------------------- |
|
339 // Command: PAUSE command. |
|
340 //----------------------------------------------------------------------------- |
|
341 //----------------------------------------------------------------------------- |
|
342 |
|
343 CCmdPause* CCmdPause::NewL( TInt aCommandId, const TDesC& aKeyphrase ) |
|
344 { |
|
345 CCmdPause* self = NewLC( aCommandId, aKeyphrase ); |
|
346 CleanupStack::Pop(); |
|
347 return self; |
|
348 } |
|
349 |
|
350 //----------------------------------------------------------------------------- |
|
351 |
|
352 CCmdPause* CCmdPause::NewLC(TInt aCommandId, const TDesC& aKeyphrase) |
|
353 { |
|
354 CCmdPause* self = new (ELeave) CCmdPause(); |
|
355 CleanupStack::PushL(self); |
|
356 self->ConstructL(aCommandId, aKeyphrase); |
|
357 return self; |
|
358 } |
|
359 |
|
360 //----------------------------------------------------------------------------- |
|
361 |
|
362 void CCmdPause::ConstructL(TInt aCommandId, const TDesC& aKeyphrase) |
|
363 { |
|
364 CCmdBase::ConstructL(aCommandId, aKeyphrase); |
|
365 } |
|
366 |
|
367 //----------------------------------------------------------------------------- |
|
368 |
|
369 TInt CCmdPause::ProcessL(const TDesC& aCommand) |
|
370 { |
|
371 TPtrC param; |
|
372 TRAPD(error, param.Set(ParamsL(aCommand))); |
|
373 if (error != KErrNone) |
|
374 { |
|
375 // Complete the test machine - will then get the next cmd |
|
376 Machine()->CompleteRequest(); |
|
377 return Error(error, TFR_KFmtErrBadCmd, &Keyphrase()); |
|
378 } |
|
379 |
|
380 TLex parse( param ); |
|
381 if (!parse.Eos() && !parse.Peek().IsSpace()) |
|
382 { |
|
383 // Complete the test machine - will then get the next cmd |
|
384 Machine()->CompleteRequest(); |
|
385 return Error(error, TFR_KFmtErrBadCmd, &Keyphrase()); |
|
386 } |
|
387 |
|
388 // ParseOnly => not executed. |
|
389 if (Family()->Switch(CCmdFamily::EParseOnly)) |
|
390 { |
|
391 // Complete the test machine - will then get the next cmd |
|
392 Machine()->CompleteRequest(); |
|
393 return error; |
|
394 } |
|
395 |
|
396 // Ask any key, prompt is either param or a default. |
|
397 param.Set( TfrLex::TrimAndPeel(param)); |
|
398 if (param.Length() == 0) |
|
399 param.Set(TFR_KTxtMsgPressAnyKey); |
|
400 |
|
401 Machine()->Pause(param); |
|
402 return error; |
|
403 } |
|
404 |
|
405 //----------------------------------------------------------------------------- |
|
406 //----------------------------------------------------------------------------- |
|
407 // Command: HOLD command. |
|
408 //----------------------------------------------------------------------------- |
|
409 //----------------------------------------------------------------------------- |
|
410 |
|
411 CCmdHold* CCmdHold::NewL( TInt aCommandId, const TDesC& aKeyphrase ) |
|
412 { |
|
413 CCmdHold* self = NewLC( aCommandId, aKeyphrase ); |
|
414 CleanupStack::Pop(); |
|
415 return self; |
|
416 } |
|
417 |
|
418 //----------------------------------------------------------------------------- |
|
419 |
|
420 CCmdHold* CCmdHold::NewLC( TInt aCommandId, const TDesC& aKeyphrase ) |
|
421 { |
|
422 CCmdHold* self = new (ELeave) CCmdHold(); |
|
423 CleanupStack::PushL( self ); |
|
424 self->ConstructL( aCommandId, aKeyphrase ); |
|
425 return self; |
|
426 } |
|
427 |
|
428 //----------------------------------------------------------------------------- |
|
429 |
|
430 void CCmdHold::ConstructL( TInt aCommandId, const TDesC& aKeyphrase ) |
|
431 { |
|
432 CCmdBase::ConstructL ( aCommandId, aKeyphrase ); |
|
433 } |
|
434 |
|
435 //----------------------------------------------------------------------------- |
|
436 |
|
437 TInt CCmdHold::ProcessL( const TDesC& aCommand ) |
|
438 { |
|
439 TPtrC param; |
|
440 TRAPD( error, param.Set( ParamsL( aCommand )) ); |
|
441 if ( error != KErrNone ) |
|
442 { |
|
443 // Complete the test machine - will then get the next cmd |
|
444 Machine()->CompleteRequest(); |
|
445 return Error(error, TFR_KFmtErrBadCmd, &Keyphrase() ); |
|
446 } |
|
447 |
|
448 TLex parse( param ); |
|
449 if ( !parse.Eos() && !parse.Peek().IsSpace() ) |
|
450 { |
|
451 // Complete the test machine - will then get the next cmd |
|
452 Machine()->CompleteRequest(); |
|
453 return Error( error, TFR_KFmtErrBadCmd, &Keyphrase() ); |
|
454 } |
|
455 |
|
456 // Param must be integer. If no param then default is 1 second. |
|
457 param.Set( TfrLex::TrimAndPeel(param) ); |
|
458 parse = param; |
|
459 |
|
460 TInt n; |
|
461 if ( parse.Eos() ) |
|
462 n = 1; |
|
463 |
|
464 else if (parse.Val(n) != KErrNone || !parse.Eos()) |
|
465 { |
|
466 // Complete the test machine - will then get the next cmd |
|
467 Machine()->CompleteRequest(); |
|
468 return Error(error, TFR_KFmtErrBadCmd, &Keyphrase()); |
|
469 } |
|
470 |
|
471 // ParseOnly => not executed! |
|
472 if (Family()->Switch(CCmdFamily::EParseOnly) ) |
|
473 { |
|
474 // Complete the test machine - will then get the next cmd |
|
475 Machine()->CompleteRequest(); |
|
476 return error; |
|
477 } |
|
478 |
|
479 // Hold processing for n seconds. |
|
480 TTimeIntervalMicroSeconds32 microseconds; |
|
481 microseconds = 1000000 * n; |
|
482 Machine()->Hold(microseconds); |
|
483 return error; |
|
484 } |
|
485 |
|
486 //----------------------------------------------------------------------------- |
|
487 //----------------------------------------------------------------------------- |
|
488 // Command: SETPROMPT command. |
|
489 //----------------------------------------------------------------------------- |
|
490 //----------------------------------------------------------------------------- |
|
491 |
|
492 CCmdSetPrompt* CCmdSetPrompt::NewL( TInt aCommandId, const TDesC& aKeyphrase ) |
|
493 { |
|
494 CCmdSetPrompt* self = NewLC( aCommandId, aKeyphrase ); |
|
495 CleanupStack::Pop(); |
|
496 return self; |
|
497 } |
|
498 |
|
499 //----------------------------------------------------------------------------- |
|
500 |
|
501 CCmdSetPrompt* CCmdSetPrompt::NewLC( TInt aCommandId, const TDesC& aKeyphrase ) |
|
502 { |
|
503 CCmdSetPrompt* self = new (ELeave) CCmdSetPrompt(); |
|
504 CleanupStack::PushL( self ); |
|
505 self->ConstructL( aCommandId, aKeyphrase ); |
|
506 return self; |
|
507 } |
|
508 |
|
509 //----------------------------------------------------------------------------- |
|
510 |
|
511 void CCmdSetPrompt::ConstructL( TInt aCommandId, const TDesC& aKeyphrase ) |
|
512 { |
|
513 CCmdBase::ConstructL ( aCommandId, aKeyphrase ); |
|
514 } |
|
515 |
|
516 //----------------------------------------------------------------------------- |
|
517 |
|
518 TInt CCmdSetPrompt::ProcessL( const TDesC& aCommand ) |
|
519 { |
|
520 // Complete the test machine - will then get the next cmd |
|
521 Machine()->CompleteRequest(); |
|
522 |
|
523 TPtrC param; |
|
524 TRAPD( error, param.Set( ParamsL( aCommand )) ); |
|
525 if ( error != KErrNone ) |
|
526 return Error( error, TFR_KFmtErrBadCmd, &Keyphrase() ); |
|
527 |
|
528 TLex parse( param ); |
|
529 if ( !parse.Eos() && !parse.Peek().IsSpace() ) |
|
530 return Error( error, TFR_KFmtErrBadCmd, &Keyphrase() ); |
|
531 |
|
532 // ParseOnly => not executed. |
|
533 if ( Family()->Switch(CCmdFamily::EParseOnly) ) |
|
534 return error; |
|
535 |
|
536 // Alter prompt, back to the default one if no new one. |
|
537 param.Set( TfrLex::TrimAndPeel( param ) ); |
|
538 if ( param.Length() == 0 ) |
|
539 param.Set(THA_CommandPrompt); |
|
540 |
|
541 if ( error = Machine()->SetPrompt( param ), error != KErrNone ) |
|
542 // ### Failure |
|
543 Log( TFR_KFmtErrFailed, &Keyphrase(), error ); |
|
544 |
|
545 return error; |
|
546 } |
|
547 |
|
548 //----------------------------------------------------------------------------- |
|
549 //----------------------------------------------------------------------------- |
|
550 // Command: SETPATH command. |
|
551 //----------------------------------------------------------------------------- |
|
552 //----------------------------------------------------------------------------- |
|
553 |
|
554 CCmdSetPath *CCmdSetPath::NewL( TInt aCommandId, const TDesC& aKeyphrase ) |
|
555 { |
|
556 CCmdSetPath* self = NewLC( aCommandId, aKeyphrase ); |
|
557 CleanupStack::Pop(); |
|
558 return self; |
|
559 } |
|
560 |
|
561 //----------------------------------------------------------------------------- |
|
562 |
|
563 CCmdSetPath *CCmdSetPath::NewLC( TInt aCommandId, const TDesC& aKeyphrase ) |
|
564 { |
|
565 CCmdSetPath* self = new (ELeave) CCmdSetPath(); |
|
566 CleanupStack::PushL( self ); |
|
567 self->ConstructL( aCommandId, aKeyphrase ); |
|
568 return self; |
|
569 } |
|
570 |
|
571 //----------------------------------------------------------------------------- |
|
572 |
|
573 void CCmdSetPath::ConstructL( TInt aCommandId, const TDesC& aKeyphrase ) |
|
574 { |
|
575 CCmdBase::ConstructL ( aCommandId, aKeyphrase ); |
|
576 } |
|
577 |
|
578 //----------------------------------------------------------------------------- |
|
579 |
|
580 TInt CCmdSetPath::ProcessL( const TDesC& aCommand ) |
|
581 { |
|
582 // Complete the test machine - will then get the next cmd |
|
583 Machine()->CompleteRequest(); |
|
584 |
|
585 TPtrC param; |
|
586 TRAPD(error, param.Set(ParamsL(aCommand))); |
|
587 if (error != KErrNone) |
|
588 return Error(error, TFR_KFmtErrBadCmd, &Keyphrase()); |
|
589 |
|
590 TLex parse( param ); |
|
591 if ( !parse.Eos() && !parse.Peek().IsSpace() ) |
|
592 return Error(error, TFR_KFmtErrBadCmd, &Keyphrase()); |
|
593 |
|
594 // Set the command file path. |
|
595 param.Set( TfrLex::TrimAndPeel(param)); |
|
596 error = Machine()->SetCmdPath(param); |
|
597 switch (error) |
|
598 { |
|
599 // Bad argument |
|
600 case KErrArgument : Log(TFR_KFmtErrParams, &Keyphrase()); break; |
|
601 case KErrNone : break; |
|
602 // Other errors |
|
603 default : Log(TFR_KFmtErrFailed, &Keyphrase(), error); break; |
|
604 } |
|
605 |
|
606 return error; |
|
607 } |
|
608 |
|
609 //----------------------------------------------------------------------------- |
|
610 //----------------------------------------------------------------------------- |
|
611 // Command: CALL command. |
|
612 //----------------------------------------------------------------------------- |
|
613 //----------------------------------------------------------------------------- |
|
614 // |
|
615 // This executes a script file (!) and stacks the commands in it ready for the |
|
616 // scheduler... |
|
617 |
|
618 CCmdCall* CCmdCall::NewL( TInt aCommandId, const TDesC& aKeyphrase, const TDesC& aHelpPhrase) |
|
619 { |
|
620 CCmdCall* self = NewLC( aCommandId, aKeyphrase, aHelpPhrase); |
|
621 CleanupStack::Pop(); |
|
622 return self; |
|
623 } |
|
624 |
|
625 //----------------------------------------------------------------------------- |
|
626 |
|
627 CCmdCall* CCmdCall::NewLC( TInt aCommandId, const TDesC& aKeyphrase, const TDesC& aHelpPhrase) |
|
628 { |
|
629 CCmdCall* self = new (ELeave) CCmdCall(); |
|
630 CleanupStack::PushL( self ); |
|
631 self->ConstructL( aCommandId, aKeyphrase, aHelpPhrase); |
|
632 return self; |
|
633 } |
|
634 |
|
635 //----------------------------------------------------------------------------- |
|
636 |
|
637 void CCmdCall::ConstructL( TInt aCommandId, const TDesC& aKeyphrase, const TDesC& aHelpPhrase) |
|
638 { |
|
639 CCmdBase::ConstructL ( aCommandId, aKeyphrase, aHelpPhrase); |
|
640 } |
|
641 |
|
642 //----------------------------------------------------------------------------- |
|
643 |
|
644 TInt CCmdCall::ProcessL( const TDesC& aCommand ) |
|
645 { |
|
646 // Complete the test machine - will then get the next cmd |
|
647 Machine()->CompleteRequest(); |
|
648 |
|
649 TPtrC param; |
|
650 TRAPD( error, param.Set( ParamsL( aCommand )) ); |
|
651 if ( error != KErrNone ) |
|
652 return Error( error, TFR_KFmtErrBadCmd, &Keyphrase() ); |
|
653 |
|
654 TLex parse( param ); |
|
655 if ( !parse.Peek().IsSpace() ) |
|
656 return Error( error, TFR_KFmtErrBadCmd, &Keyphrase() ); |
|
657 |
|
658 // Extract command file name. |
|
659 parse = TfrLex::Trim( param ); |
|
660 TPtrC file; |
|
661 TRAP(error,file.Set(TfrLex::GetL(parse))); |
|
662 if ( error != KErrNone ) |
|
663 return Error( error, TFR_KFmtErrBadCmd, &Keyphrase() ); |
|
664 |
|
665 file.Set(TfrLex::PeelAndTrim(file)); |
|
666 if ( file.Length() == 0 ) |
|
667 return Error( error, TFR_KFmtErrBadCmd, &Keyphrase() ); |
|
668 |
|
669 // The remainder contains optional arguments |
|
670 TPtrC args = TfrLex::Trim(parse.Remainder()); |
|
671 |
|
672 // Before calling the command file, do check that the argument list |
|
673 // is lexically correct and that there are not too many of them.... |
|
674 TPtrC argv; |
|
675 TInt argc = -1; |
|
676 do |
|
677 { |
|
678 argc++; |
|
679 TRAP(error, argv.Set(TfrLex::GetL(parse))); |
|
680 } while ( error == KErrNone && argv.Length() > 0 ); |
|
681 |
|
682 // Well, how was it? |
|
683 if ( error != KErrNone || argc > TFR_MAX_CALL_ARGUMENTS ) |
|
684 { |
|
685 if ( error == KErrNone ) |
|
686 error = KErrArgument; |
|
687 return Error( error, TFR_KFmtErrBadCmd, &Keyphrase() ); |
|
688 } |
|
689 |
|
690 // Call the command file with the argument list. |
|
691 error = Machine()->CallCmdFile(file, args); |
|
692 if (error != KErrNone ) |
|
693 // ### Failure |
|
694 Log( TFR_KFmtErrFailed, &Keyphrase(), error ); |
|
695 |
|
696 return error; |
|
697 } |
|
698 |
|
699 //----------------------------------------------------------------------------- |
|
700 //----------------------------------------------------------------------------- |
|
701 // Command: RETURN command. |
|
702 //----------------------------------------------------------------------------- |
|
703 //----------------------------------------------------------------------------- |
|
704 |
|
705 CCmdReturn* CCmdReturn::NewL( TInt aCommandId, const TDesC& aKeyphrase ) |
|
706 { |
|
707 CCmdReturn* self = NewLC( aCommandId, aKeyphrase ); |
|
708 CleanupStack::Pop(); |
|
709 return self; |
|
710 } |
|
711 |
|
712 //----------------------------------------------------------------------------- |
|
713 |
|
714 CCmdReturn* CCmdReturn::NewLC( TInt aCommandId, const TDesC& aKeyphrase ) |
|
715 { |
|
716 CCmdReturn* self = new (ELeave) CCmdReturn(); |
|
717 CleanupStack::PushL( self ); |
|
718 self->ConstructL( aCommandId, aKeyphrase ); |
|
719 return self; |
|
720 } |
|
721 |
|
722 //----------------------------------------------------------------------------- |
|
723 |
|
724 void CCmdReturn::ConstructL( TInt aCommandId, const TDesC& aKeyphrase ) |
|
725 { |
|
726 CCmdBase::ConstructL( aCommandId, aKeyphrase ); |
|
727 } |
|
728 |
|
729 //----------------------------------------------------------------------------- |
|
730 |
|
731 TInt CCmdReturn::ProcessL(const TDesC& aCommand) |
|
732 { |
|
733 // Complete the test machine |
|
734 Machine()->CompleteRequest(); |
|
735 |
|
736 TPtrC param; |
|
737 TRAPD(error, param.Set(ParamsL(aCommand))); |
|
738 if (error != KErrNone) |
|
739 return Error(error, TFR_KFmtErrBadCmd, &Keyphrase()); |
|
740 |
|
741 TLex parse(param); |
|
742 parse.SkipSpace(); |
|
743 if (!parse.Eos()) |
|
744 return Error(error, TFR_KFmtErrBadCmd, &Keyphrase()); |
|
745 |
|
746 // Return from the current command file |
|
747 error = Machine()->CloseCmdFile(); |
|
748 if (error != KErrNone) |
|
749 Log(TFR_KFmtErrFailed, &Keyphrase(), error); |
|
750 |
|
751 return error; |
|
752 } |
|
753 |
|
754 //----------------------------------------------------------------------------- |
|
755 //----------------------------------------------------------------------------- |
|
756 // Command: LOGPATH command. |
|
757 //----------------------------------------------------------------------------- |
|
758 //----------------------------------------------------------------------------- |
|
759 |
|
760 CCmdLogPath* CCmdLogPath::NewL( TInt aCommandId, const TDesC& aKeyphrase ) |
|
761 { |
|
762 CCmdLogPath* self = NewLC( aCommandId, aKeyphrase ); |
|
763 CleanupStack::Pop(); |
|
764 return self; |
|
765 } |
|
766 |
|
767 //----------------------------------------------------------------------------- |
|
768 |
|
769 CCmdLogPath* CCmdLogPath::NewLC( TInt aCommandId, const TDesC& aKeyphrase ) |
|
770 { |
|
771 CCmdLogPath* self = new (ELeave) CCmdLogPath(); |
|
772 CleanupStack::PushL( self ); |
|
773 self->ConstructL( aCommandId, aKeyphrase ); |
|
774 return self; |
|
775 } |
|
776 |
|
777 //----------------------------------------------------------------------------- |
|
778 |
|
779 void CCmdLogPath::ConstructL( TInt aCommandId, const TDesC& aKeyphrase ) |
|
780 { |
|
781 CCmdBase::ConstructL ( aCommandId, aKeyphrase ); |
|
782 } |
|
783 |
|
784 //----------------------------------------------------------------------------- |
|
785 |
|
786 TInt CCmdLogPath::ProcessL( const TDesC& aCommand ) |
|
787 { |
|
788 // Complete the test machine - will then get the next cmd |
|
789 Machine()->CompleteRequest(); |
|
790 |
|
791 TPtrC param; |
|
792 TRAPD( error, param.Set( ParamsL( aCommand )) ); |
|
793 if ( error != KErrNone ) |
|
794 return Error( error, TFR_KFmtErrBadCmd, &Keyphrase() ); |
|
795 |
|
796 TLex parse( param ); |
|
797 if ( !parse.Eos() && !parse.Peek().IsSpace() ) |
|
798 return Error( error, TFR_KFmtErrBadCmd, &Keyphrase() ); |
|
799 |
|
800 // Set log file path. |
|
801 param.Set( TfrLex::TrimAndPeel( param ) ); |
|
802 |
|
803 // |
|
804 if ( error = Machine()->SetLogPath( param ), error != KErrNone ) |
|
805 { |
|
806 // Failed |
|
807 if ( error == KErrArgument ) |
|
808 // Bad arguments |
|
809 Log( TFR_KFmtErrParams, &Keyphrase() ); |
|
810 else |
|
811 // Other errors |
|
812 Log( TFR_KFmtErrFailed, &Keyphrase(), error ); |
|
813 } |
|
814 |
|
815 return error; |
|
816 } |
|
817 |
|
818 //----------------------------------------------------------------------------- |
|
819 //----------------------------------------------------------------------------- |
|
820 // Command: LOGFILE command. |
|
821 //----------------------------------------------------------------------------- |
|
822 //----------------------------------------------------------------------------- |
|
823 |
|
824 CCmdLogFile* CCmdLogFile::NewL( TInt aCommandId, const TDesC& aKeyphrase ) |
|
825 { |
|
826 CCmdLogFile *self = NewLC(aCommandId, aKeyphrase); |
|
827 CleanupStack::Pop(); |
|
828 return self; |
|
829 } |
|
830 |
|
831 //----------------------------------------------------------------------------- |
|
832 |
|
833 CCmdLogFile* CCmdLogFile::NewLC( TInt aCommandId, const TDesC& aKeyphrase ) |
|
834 { |
|
835 CCmdLogFile *self = new (ELeave) CCmdLogFile(); |
|
836 CleanupStack::PushL(self); |
|
837 self->ConstructL(aCommandId, aKeyphrase); |
|
838 return self; |
|
839 } |
|
840 |
|
841 //----------------------------------------------------------------------------- |
|
842 |
|
843 void CCmdLogFile::ConstructL( TInt aCommandId, const TDesC& aKeyphrase ) |
|
844 { |
|
845 CCmdBase::ConstructL(aCommandId, aKeyphrase); |
|
846 } |
|
847 |
|
848 //----------------------------------------------------------------------------- |
|
849 |
|
850 TInt CCmdLogFile::ProcessL( const TDesC& aCommand ) |
|
851 { |
|
852 // Complete the test machine - will then get the next cmd |
|
853 Machine()->CompleteRequest(); |
|
854 |
|
855 TPtrC param; |
|
856 TRAPD(error, param.Set(ParamsL(aCommand))); |
|
857 if (error != KErrNone) |
|
858 return Error(error, TFR_KFmtErrBadCmd, &Keyphrase()); |
|
859 |
|
860 TLex parse(param); |
|
861 if (!parse.Peek().IsSpace()) |
|
862 return Error(error, TFR_KFmtErrBadCmd, &Keyphrase()); |
|
863 |
|
864 // Open log file. |
|
865 param.Set(TfrLex::TrimAndPeel(param)); |
|
866 error = Machine()->OpenLogFile(param); |
|
867 if (error != KErrNone) |
|
868 // ### Failure |
|
869 Log(TFR_KFmtErrFailed, &Keyphrase(), error); |
|
870 |
|
871 return error; |
|
872 } |
|
873 |
|
874 //----------------------------------------------------------------------------- |
|
875 //----------------------------------------------------------------------------- |
|
876 // Command: ENDLOG command. |
|
877 //----------------------------------------------------------------------------- |
|
878 //----------------------------------------------------------------------------- |
|
879 |
|
880 CCmdEndLog* CCmdEndLog::NewL( TInt aCommandId, const TDesC& aKeyphrase ) |
|
881 { |
|
882 CCmdEndLog* self = NewLC(aCommandId, aKeyphrase); |
|
883 CleanupStack::Pop(); |
|
884 return self; |
|
885 } |
|
886 |
|
887 //----------------------------------------------------------------------------- |
|
888 |
|
889 CCmdEndLog* CCmdEndLog::NewLC( TInt aCommandId, const TDesC& aKeyphrase ) |
|
890 { |
|
891 CCmdEndLog* self = new (ELeave) CCmdEndLog(); |
|
892 CleanupStack::PushL(self); |
|
893 self->ConstructL(aCommandId, aKeyphrase); |
|
894 return self; |
|
895 } |
|
896 |
|
897 //----------------------------------------------------------------------------- |
|
898 |
|
899 void CCmdEndLog::ConstructL( TInt aCommandId, const TDesC& aKeyphrase ) |
|
900 { |
|
901 CCmdBase::ConstructL( aCommandId, aKeyphrase ); |
|
902 } |
|
903 |
|
904 //----------------------------------------------------------------------------- |
|
905 |
|
906 TInt CCmdEndLog::ProcessL( const TDesC& aCommand ) |
|
907 { |
|
908 // Complete the test machine - will then get the next cmd |
|
909 Machine()->CompleteRequest(); |
|
910 |
|
911 TPtrC param; |
|
912 TRAPD( error, param.Set( ParamsL( aCommand )) ); |
|
913 if ( error != KErrNone ) |
|
914 return Error( error, TFR_KFmtErrBadCmd, &Keyphrase() ); |
|
915 |
|
916 TLex parse( param ); |
|
917 parse.SkipSpace(); |
|
918 if ( !parse.Eos() ) |
|
919 return Error( error, TFR_KFmtErrBadCmd, &Keyphrase() ); |
|
920 |
|
921 // Close present log file |
|
922 if ( error = Machine()->CloseLogFile(), error != KErrNone ) |
|
923 // ### Failure |
|
924 Log( TFR_KFmtErrFailed, &Keyphrase(), error ); |
|
925 |
|
926 return error; |
|
927 } |
|
928 |
|
929 //----------------------------------------------------------------------------- |
|
930 //----------------------------------------------------------------------------- |
|
931 // Command: DEFINE command. |
|
932 //----------------------------------------------------------------------------- |
|
933 //----------------------------------------------------------------------------- |
|
934 |
|
935 CCmdDefine *CCmdDefine::NewL( TInt aCommandId, const TDesC& aKeyphrase, const TDesC& aHelpPhrase) |
|
936 { |
|
937 CCmdDefine *self = NewLC( aCommandId, aKeyphrase, aHelpPhrase); |
|
938 CleanupStack::Pop(); |
|
939 return self; |
|
940 } |
|
941 |
|
942 //----------------------------------------------------------------------------- |
|
943 |
|
944 CCmdDefine *CCmdDefine::NewLC( TInt aCommandId, const TDesC& aKeyphrase, const TDesC& aHelpPhrase) |
|
945 { |
|
946 CCmdDefine *self = new (ELeave) CCmdDefine(); |
|
947 CleanupStack::PushL( self ); |
|
948 self->ConstructL( aCommandId, aKeyphrase, aHelpPhrase); |
|
949 return self; |
|
950 } |
|
951 |
|
952 //----------------------------------------------------------------------------- |
|
953 |
|
954 void CCmdDefine::ConstructL( TInt aCommandId, const TDesC& aKeyphrase, const TDesC& aHelpPhrase) |
|
955 { |
|
956 CCmdBase::ConstructL(aCommandId, aKeyphrase, aHelpPhrase); |
|
957 } |
|
958 |
|
959 //----------------------------------------------------------------------------- |
|
960 // We can define variables ($var16charname$) which can then be used by the |
|
961 // commands we supply |
|
962 |
|
963 TInt CCmdDefine::ProcessL(const TDesC& aCommand) |
|
964 { |
|
965 // Complete the test machine - will then get the next cmd |
|
966 Machine()->CompleteRequest(); |
|
967 |
|
968 TPtrC param; |
|
969 TRAPD(error, param.Set(ParamsL(aCommand))); |
|
970 if ( error != KErrNone ) |
|
971 return Error( error, TFR_KFmtErrBadCmd, &Keyphrase()); |
|
972 |
|
973 TLex parse(param); |
|
974 if ( !parse.Eos() && !parse.Peek().IsSpace()) |
|
975 return Error(error, TFR_KFmtErrBadCmd, &Keyphrase()); |
|
976 |
|
977 parse.SkipSpace(); |
|
978 if (parse.Eos()) |
|
979 { |
|
980 // If no params, print out present tag definitions. |
|
981 CCatalogue* catalog = Machine()->Defines(); |
|
982 for (TInt i = 0; i < catalog->Count(); ++i) |
|
983 { |
|
984 CLabeledText *tag = catalog->At(i); |
|
985 TPtrC label = tag->Label(); |
|
986 TPtrC value = tag->Value(); |
|
987 Printf( _L("\t%S \"%S\""), &label, &value ); |
|
988 } |
|
989 return error; |
|
990 } |
|
991 |
|
992 // Get tag name, must not exceed 16 characters. |
|
993 TPtrC tagname; |
|
994 TRAP(error,tagname.Set(TfrLex::GetL(parse))); |
|
995 if ( error != KErrNone) |
|
996 return Error(KErrArgument, TFR_KFmtErrBadCmd, &Keyphrase()); |
|
997 |
|
998 tagname.Set(TfrLex::Peel(tagname)); |
|
999 if ( tagname.Length() > 32 ) |
|
1000 return Error(KErrArgument, TFR_KFmtErrBadCmd, &Keyphrase()); |
|
1001 |
|
1002 // Get tag value (is optional). |
|
1003 TPtrC tagvalue; |
|
1004 TRAP(error,tagvalue.Set(TfrLex::GetL(parse))); |
|
1005 if (error != KErrNone) |
|
1006 return Error(KErrArgument, TFR_KFmtErrBadCmd, &Keyphrase()); |
|
1007 |
|
1008 // There shall not be anything more. |
|
1009 TPtrC remainder = TfrLex::Trim(parse.Remainder()); |
|
1010 if (remainder.Length() > 0) |
|
1011 return Error(KErrArgument, TFR_KFmtErrBadCmd, &Keyphrase()); |
|
1012 |
|
1013 // Execute... |
|
1014 // Construct tag label = $tagname$ (never more than 16+2 chars). |
|
1015 TBuf<32+2> taglabel; |
|
1016 taglabel.Format(_L("$%S$"), &tagname); |
|
1017 |
|
1018 // Tag value specified? |
|
1019 if (tagvalue.Length() > 0) |
|
1020 { |
|
1021 // Check if the tag already is defined. Depending on that, |
|
1022 // either alter the tag or add a new one. |
|
1023 tagvalue.Set(TfrLex::Peel(tagvalue)); |
|
1024 |
|
1025 CLabeledText *tag = Machine()->Defines()->Text(taglabel); |
|
1026 |
|
1027 if (tag != NULL) |
|
1028 { |
|
1029 // alter tag |
|
1030 TRAP(error, tag->SetL(tagvalue) ); |
|
1031 } |
|
1032 else |
|
1033 { |
|
1034 // Add a tag. |
|
1035 TRAP(error, Machine()->Defines()->AddL(taglabel, tagvalue)); |
|
1036 } |
|
1037 |
|
1038 } |
|
1039 else |
|
1040 { |
|
1041 // Define with no tag value: delete tag if it's defined. |
|
1042 Machine()->Defines()->Delete(taglabel); |
|
1043 error = KErrNone; |
|
1044 } |
|
1045 |
|
1046 if (error != KErrNone) |
|
1047 Log(TFR_KFmtErrFailed, &Keyphrase(), error); |
|
1048 |
|
1049 return error; |
|
1050 } |
|
1051 |
|
1052 //----------------------------------------------------------------------------- |
|
1053 //----------------------------------------------------------------------------- |
|
1054 // Comment ? - the ListAll Command. |
|
1055 //----------------------------------------------------------------------------- |
|
1056 //----------------------------------------------------------------------------- |
|
1057 |
|
1058 CCmdListAll *CCmdListAll::NewL(TInt aCommandId, const TDesC& aKeyphrase, const TDesC& aHelpPhrase) |
|
1059 { |
|
1060 CCmdListAll* self = NewLC(aCommandId, aKeyphrase, aHelpPhrase); |
|
1061 CleanupStack::Pop(); |
|
1062 return self; |
|
1063 } |
|
1064 |
|
1065 //----------------------------------------------------------------------------- |
|
1066 |
|
1067 CCmdListAll *CCmdListAll::NewLC( TInt aCommandId, const TDesC& aKeyphrase, const TDesC& aHelpPhrase) |
|
1068 { |
|
1069 CCmdListAll* self = new (ELeave) CCmdListAll(); |
|
1070 CleanupStack::PushL( self ); |
|
1071 self->ConstructL( aCommandId, aKeyphrase, aHelpPhrase); |
|
1072 return self; |
|
1073 } |
|
1074 |
|
1075 //----------------------------------------------------------------------------- |
|
1076 |
|
1077 void CCmdListAll::ConstructL( TInt aCommandId, const TDesC& aKeyphrase, const TDesC& aHelpPhrase) |
|
1078 { |
|
1079 CCmdBase::ConstructL( aCommandId, aKeyphrase, aHelpPhrase); |
|
1080 } |
|
1081 |
|
1082 //----------------------------------------------------------------------------- |
|
1083 |
|
1084 TBool CCmdListAll::Recognize( const TDesC& aCommand ) |
|
1085 { |
|
1086 // Check if is empty or begins with # character. |
|
1087 TPtrC cmd = TfrLex::Trim(aCommand); |
|
1088 |
|
1089 return (cmd.Match( _L("?")) == 0); |
|
1090 } |
|
1091 |
|
1092 //----------------------------------------------------------------------------- |
|
1093 |
|
1094 TInt CCmdListAll::ProcessL(const TDesC& aCommand) |
|
1095 { |
|
1096 // Complete the test machine - will then get the next cmd |
|
1097 Machine()->CompleteRequest(); |
|
1098 |
|
1099 if (!Recognize(aCommand)) |
|
1100 return Error(KErrArgument, TFR_KFmtErrBadCmd, &Keyphrase()); |
|
1101 |
|
1102 // List commands out |
|
1103 Family()->ListAll(Console()); |
|
1104 return KErrNone; |
|
1105 } |
|
1106 |
|
1107 //----------------------------------------------------------------------------- |
|
1108 //----------------------------------------------------------------------------- |
|
1109 // Command: IF command. |
|
1110 //----------------------------------------------------------------------------- |
|
1111 //----------------------------------------------------------------------------- |
|
1112 |
|
1113 CCmdIf *CCmdIf::NewL(TInt aCommandId, const TDesC& aKeyphrase, const TDesC& aHelpPhrase) |
|
1114 { |
|
1115 CCmdIf *self = NewLC(aCommandId, aKeyphrase, aHelpPhrase); |
|
1116 CleanupStack::Pop(); |
|
1117 return self; |
|
1118 } |
|
1119 |
|
1120 //----------------------------------------------------------------------------- |
|
1121 |
|
1122 CCmdIf *CCmdIf::NewLC(TInt aCommandId, const TDesC& aKeyphrase, const TDesC& aHelpPhrase) |
|
1123 { |
|
1124 CCmdIf *self = new (ELeave) CCmdIf(); |
|
1125 CleanupStack::PushL(self); |
|
1126 self->ConstructL(aCommandId, aKeyphrase, aHelpPhrase); |
|
1127 return self; |
|
1128 } |
|
1129 |
|
1130 //----------------------------------------------------------------------------- |
|
1131 |
|
1132 void CCmdIf::ConstructL(TInt aCommandId, const TDesC& aKeyphrase, const TDesC& aHelpPhrase) |
|
1133 { |
|
1134 CCmdBase::ConstructL(aCommandId, aKeyphrase, aHelpPhrase); |
|
1135 } |
|
1136 |
|
1137 //----------------------------------------------------------------------------- |
|
1138 // recognize offers us a mechanism of 'peeking' at the command such that |
|
1139 // we can then decide if we need to process it. This is vital for IF, ELSE and ENDIF |
|
1140 // since we need to look at the command, see if its one that can change the course |
|
1141 // of processing or not. Clearly doing this for every other command is wasteful and |
|
1142 // unnecessary |
|
1143 // |
|
1144 // NOTE: we must return true only if the command does indeed match |
|
1145 // we can do all other processing if necessary! |
|
1146 |
|
1147 TBool CCmdIf::Recognize(const TDesC& aCommand) |
|
1148 { |
|
1149 // look for IF* but note that Match is casesensitive and hence use temp TBuf value to check |
|
1150 // and note that the command string might be quite long (and we're only interested in the |
|
1151 // first left bit!! |
|
1152 TBuf<16> iCmd = aCommand.Left(15); |
|
1153 iCmd.UpperCase(); |
|
1154 TInt iResult = iCmd.Match(THA_TxtCmdIfS); |
|
1155 if (iResult == KErrNotFound) // NF(-1) otherwise >=0here means position of string in host |
|
1156 return EFalse; |
|
1157 |
|
1158 // determine what the state is and if already in an IF, need to increment the IF counter! |
|
1159 //Machine()->UpdateIFState(CIFControl::EInIF); |
|
1160 |
|
1161 return ETrue; // accept it for now! |
|
1162 } |
|
1163 |
|
1164 //----------------------------------------------------------------------------- |
|
1165 // the command is [ IF $definedname$ == givenvalue ] |
|
1166 // the result is either TRUE or FALSE |
|
1167 // we should expect 3 parameters (including ==) and evaluate the resultant |
|
1168 // comparison |
|
1169 |
|
1170 TInt CCmdIf::ProcessL(const TDesC &aCommand) |
|
1171 { |
|
1172 // Complete the test machine - will then get the next cmd |
|
1173 Machine()->CompleteRequest(); |
|
1174 |
|
1175 // this converts the first parameter (if found) into something useful! |
|
1176 TPtrC param; |
|
1177 TRAPD(error, param.Set(ParamsL(aCommand))); |
|
1178 if (error != KErrNone) |
|
1179 return Error(error, TFR_KFmtErrBadCmd, &Keyphrase()); |
|
1180 |
|
1181 TLex parse(param); |
|
1182 if (!parse.Eos() && !parse.Peek().IsSpace()) |
|
1183 return Error(error, TFR_KFmtErrBadCmd, &Keyphrase()); |
|
1184 |
|
1185 parse.SkipSpace(); |
|
1186 if (parse.Eos()) |
|
1187 // no parameters so invalid command |
|
1188 return Error(error, TFR_KFmtErrBadCmd, &Keyphrase()); |
|
1189 |
|
1190 // convert into our LValue |
|
1191 TPtrC lvalue; |
|
1192 TRAP(error, lvalue.Set(TfrLex::GetL(parse))); |
|
1193 if (error != KErrNone) |
|
1194 return Error(error, TFR_KFmtErrBadCmd, &Keyphrase()); |
|
1195 |
|
1196 lvalue.Set(TfrLex::Peel(lvalue)); |
|
1197 if (lvalue.Length() > 32) |
|
1198 return Error(error, TFR_KFmtErrBadCmd, &Keyphrase()); |
|
1199 |
|
1200 // now check that the second 'param' is one of our comparison tokens... |
|
1201 TPtrC opr; |
|
1202 TRAP(error, opr.Set(TfrLex::GetL(parse))); |
|
1203 if (error != KErrNone) |
|
1204 return Error(KErrArgument, TFR_KFmtErrBadCmd, &opr); |
|
1205 |
|
1206 // check is valid length |
|
1207 opr.Set(TfrLex::Peel(opr)); |
|
1208 if (opr.Length() > 16) |
|
1209 return Error(KErrArgument, THA_KErrParameterLong, &opr); |
|
1210 |
|
1211 // check operator is one of our known list |
|
1212 // Param shall be HTTP or WSP |
|
1213 opr.Set(TfrLex::TrimAndPeel(opr)); |
|
1214 TBool eValue; |
|
1215 if (opr.CompareF(KTxtEquals) == 0) |
|
1216 eValue = TCO_Equals; |
|
1217 |
|
1218 else if (opr.CompareF(KTxtNotEqual) == 0) |
|
1219 eValue = TCO_NotEqual; |
|
1220 |
|
1221 else if (opr.CompareF(KTxtGreaterThan) == 0) |
|
1222 eValue = TCO_GreaterThan; |
|
1223 |
|
1224 else if (opr.CompareF(KTxtLessThan) == 0) |
|
1225 eValue = TCO_LessThan; |
|
1226 |
|
1227 else if (opr.CompareF(KTxtGreaterThanEq) == 0) |
|
1228 eValue = TCO_GreaterThanEq; |
|
1229 |
|
1230 else if (opr.CompareF(KTxtLessThanEq) == 0) |
|
1231 eValue = TCO_LessThanEq; |
|
1232 |
|
1233 else // not recognized the comp.operator so error |
|
1234 return Error(KErrArgument, THA_KErrInvalidOptr, &opr); |
|
1235 |
|
1236 // now look at the final parameter and convert into our LValue |
|
1237 // assuming that there is anything more. |
|
1238 TPtrC rvalue = TfrLex::Trim(parse.Remainder()); |
|
1239 if (rvalue.Length() == 0) |
|
1240 return Error(KErrArgument, TFR_KFmtErrBadCmd, &aCommand); |
|
1241 |
|
1242 rvalue.Set(TfrLex::TrimAndPeel(rvalue)); |
|
1243 if (rvalue.Length() > 16) |
|
1244 return Error(error, TFR_KFmtErrBadCmd, &Keyphrase()); |
|
1245 |
|
1246 // ParseOnly => not executed. |
|
1247 if (Family()->Switch(CCmdFamily::EParseOnly)) |
|
1248 return error; |
|
1249 |
|
1250 // determine if we're comparing numeric or data (or both!) |
|
1251 TBool iNumeric = ETrue; |
|
1252 TInt ilval; |
|
1253 TInt irval; |
|
1254 if (InetProtTextUtils::ConvertDescriptorToInt(lvalue,ilval) < 0) |
|
1255 iNumeric = EFalse; |
|
1256 |
|
1257 // check we're not comparing apples with oranges... |
|
1258 iNumeric = ((InetProtTextUtils::ConvertDescriptorToInt(rvalue,irval) < 0) && iNumeric) ? EFalse : ETrue; |
|
1259 |
|
1260 // now determine the comparison result (also |
|
1261 // -1 => error or failure (i.e. < 0) 0 = false, 1 = true |
|
1262 TInt iResult = -2; |
|
1263 switch (eValue) |
|
1264 { |
|
1265 case TCO_Equals : |
|
1266 iResult = (iNumeric) ? ((TInt) (ilval == irval)) : ((lvalue.Match(rvalue) == 0) ? 1 : 0); break; |
|
1267 case TCO_NotEqual : |
|
1268 iResult = (iNumeric) ? ((TInt) (ilval != irval)) : ((lvalue.Match(rvalue) != 0) ? 1 : 0); break; |
|
1269 case TCO_GreaterThan : |
|
1270 iResult = (iNumeric) ? ((TInt) (ilval > irval)) : ((lvalue.Match(rvalue) == 1) ? 1 : 0); break; |
|
1271 case TCO_LessThan : |
|
1272 iResult = (iNumeric) ? ((TInt) (ilval < irval)) : ((lvalue.Match(rvalue) == -1) ? 1 : 0); break; |
|
1273 case TCO_GreaterThanEq : |
|
1274 iResult = (iNumeric) ? ((TInt) (ilval >= irval)) : ((lvalue.Match(rvalue) >= 0) ? 1 : 0); break; |
|
1275 case TCO_LessThanEq : |
|
1276 iResult = (iNumeric) ? ((TInt) (ilval <= irval)) : ((lvalue.Match(rvalue) < 1) ? 1 : 0); break; |
|
1277 } |
|
1278 |
|
1279 // the result now determines if we continue processing (and ignore any following ELSE) |
|
1280 // before we meet the ENDIF or we skip and perform the ELSE clause... |
|
1281 // NOTE: now we can nest IF's etc, we MUST count those that are met when we |
|
1282 // 'ignore' lines as these MAY be incorrectly nested... |
|
1283 TBool iSuccess = (TBool) iResult; |
|
1284 if (iSuccess) |
|
1285 Machine()->IfL(CIFControl::EIFTrue, iSuccess, CIFControl::EInIF); |
|
1286 else |
|
1287 // failed test so skip the true block |
|
1288 Machine()->IfL(CIFControl::EELSETrue, iSuccess, CIFControl::EInIF); |
|
1289 |
|
1290 // whilst we would be better off returning the actual result, it bears little consequence |
|
1291 // - in fact if we get here we're ok anyway... |
|
1292 return KErrNone; |
|
1293 } |
|
1294 |
|
1295 //----------------------------------------------------------------------------- |
|
1296 //----------------------------------------------------------------------------- |
|
1297 // Command: ELSE command. |
|
1298 //----------------------------------------------------------------------------- |
|
1299 //----------------------------------------------------------------------------- |
|
1300 |
|
1301 CCmdElse *CCmdElse::NewL(TInt aCommandId, const TDesC& aKeyphrase, const TDesC& aHelpPhrase) |
|
1302 { |
|
1303 CCmdElse *self = NewLC(aCommandId, aKeyphrase, aHelpPhrase); |
|
1304 CleanupStack::Pop(); |
|
1305 return self; |
|
1306 } |
|
1307 |
|
1308 //----------------------------------------------------------------------------- |
|
1309 |
|
1310 CCmdElse *CCmdElse::NewLC(TInt aCommandId, const TDesC& aKeyphrase, const TDesC& aHelpPhrase) |
|
1311 { |
|
1312 CCmdElse *self = new (ELeave) CCmdElse(); |
|
1313 CleanupStack::PushL(self); |
|
1314 self->ConstructL(aCommandId, aKeyphrase, aHelpPhrase); |
|
1315 return self; |
|
1316 } |
|
1317 |
|
1318 //----------------------------------------------------------------------------- |
|
1319 |
|
1320 void CCmdElse::ConstructL(TInt aCommandId, const TDesC& aKeyphrase, const TDesC& aHelpPhrase) |
|
1321 { |
|
1322 CCmdBase::ConstructL(aCommandId, aKeyphrase, aHelpPhrase); |
|
1323 } |
|
1324 |
|
1325 //----------------------------------------------------------------------------- |
|
1326 // if we read ELSE then we need to check: |
|
1327 // a) we're in an IF clause |
|
1328 // b) the current branch to execute |
|
1329 // c) if we need to change the stepover state |
|
1330 |
|
1331 TBool CCmdElse::Recognize(const TDesC& aCommand) |
|
1332 { |
|
1333 // look for ELSE |
|
1334 TBuf<16> iCmd = aCommand.Left(15); |
|
1335 iCmd.UpperCase(); |
|
1336 TInt iResult = iCmd.Match(THA_TxtCmdElse); |
|
1337 if (iResult == KErrNotFound) |
|
1338 return EFalse; |
|
1339 |
|
1340 // determine the next course of action in the ProcessL section |
|
1341 // otherwise we won't complete the request! |
|
1342 return ETrue; |
|
1343 } |
|
1344 |
|
1345 //----------------------------------------------------------------------------- |
|
1346 // the command is [ IF $definedname$ == givenvalue ] |
|
1347 // the result is either TRUE or FALSE |
|
1348 // we should expect 3 parameters (including ==) and evaluate the resultant |
|
1349 // comparison |
|
1350 |
|
1351 TInt CCmdElse::ProcessL(const TDesC &aCommand) |
|
1352 { |
|
1353 // Complete the test machine - will then get the next cmd |
|
1354 Machine()->CompleteRequest(); |
|
1355 |
|
1356 TPtrC param; |
|
1357 TRAPD(ret, param.Set(ParamsL(aCommand))); |
|
1358 if (ret != KErrNone) |
|
1359 return Error(ret, KFmtErrInvalidCmd, &Keyphrase()); |
|
1360 |
|
1361 // determine what the state is and if already in an IF, need to increment the IF counter! |
|
1362 //Machine()->UpdateIFState(CIFControl::EInELSE); |
|
1363 |
|
1364 Machine()->SetIfState(CIFControl::EInELSE); |
|
1365 |
|
1366 // expect endif next |
|
1367 //TBool iResult = (iIFPile->Peek()) ? (iIFPile->Peek())->GetIFResult() : EFalse; |
|
1368 //Machine()->SetIfMode(CIFControl::EENDIF, iResult); |
|
1369 |
|
1370 return ret; |
|
1371 } |
|
1372 |
|
1373 //----------------------------------------------------------------------------- |
|
1374 //----------------------------------------------------------------------------- |
|
1375 // Command: ENDIF command. |
|
1376 //----------------------------------------------------------------------------- |
|
1377 //----------------------------------------------------------------------------- |
|
1378 |
|
1379 CCmdEndIf *CCmdEndIf::NewL(TInt aCommandId, const TDesC& aKeyphrase, const TDesC& aHelpPhrase) |
|
1380 { |
|
1381 CCmdEndIf *self = NewLC(aCommandId, aKeyphrase, aHelpPhrase); |
|
1382 CleanupStack::Pop(); |
|
1383 return self; |
|
1384 } |
|
1385 |
|
1386 //----------------------------------------------------------------------------- |
|
1387 |
|
1388 CCmdEndIf *CCmdEndIf::NewLC(TInt aCommandId, const TDesC& aKeyphrase, const TDesC& aHelpPhrase) |
|
1389 { |
|
1390 CCmdEndIf *self = new (ELeave) CCmdEndIf(); |
|
1391 CleanupStack::PushL(self); |
|
1392 self->ConstructL(aCommandId, aKeyphrase, aHelpPhrase); |
|
1393 return self; |
|
1394 } |
|
1395 |
|
1396 //----------------------------------------------------------------------------- |
|
1397 |
|
1398 void CCmdEndIf::ConstructL(TInt aCommandId, const TDesC& aKeyphrase, const TDesC& aHelpPhrase) |
|
1399 { |
|
1400 CCmdBase::ConstructL(aCommandId, aKeyphrase, aHelpPhrase); |
|
1401 } |
|
1402 |
|
1403 //----------------------------------------------------------------------------- |
|
1404 // if we read ENDIF then we need to: |
|
1405 // a) ensure we're in an IF clause |
|
1406 // b) to reset the stepover state |
|
1407 |
|
1408 TBool CCmdEndIf::Recognize(const TDesC& aCommand) |
|
1409 { |
|
1410 // look for ENDIF |
|
1411 TBuf<16> iCmd = aCommand.Left(15); |
|
1412 iCmd.UpperCase(); |
|
1413 TInt iResult = iCmd.Match(THA_TxtCmdEndIf); |
|
1414 if (iResult == KErrNotFound) |
|
1415 return EFalse; |
|
1416 |
|
1417 // check we processing an IF sequence |
|
1418 TBool iIFInProgress = (TBool) (Machine()->GetIfMode() == CIFControl::ENotIf); |
|
1419 if (iIFInProgress) |
|
1420 return EFalse; // abort if not in IF seq |
|
1421 |
|
1422 return ETrue; |
|
1423 } |
|
1424 |
|
1425 //----------------------------------------------------------------------------- |
|
1426 // the command is [ IF $definedname$ == givenvalue ] |
|
1427 // the result is either TRUE or FALSE |
|
1428 // we should expect 3 parameters (including ==) and evaluate the resultant |
|
1429 // comparison |
|
1430 |
|
1431 TInt CCmdEndIf::ProcessL(const TDesC& aCommand) |
|
1432 { |
|
1433 // Complete the test machine - will then get the next cmd |
|
1434 Machine()->CompleteRequest(); |
|
1435 |
|
1436 TPtrC param; |
|
1437 TRAPD(ret, param.Set(ParamsL(aCommand))); |
|
1438 if (ret != KErrNone) |
|
1439 return Error(ret, KFmtErrInvalidCmd, &Keyphrase()); |
|
1440 |
|
1441 // clearing the end if block is actually not as simple as at first |
|
1442 // might be thought. we should get the 'machine' to verify that |
|
1443 // the endif is appropriate (i.e. we are not reading an endif within |
|
1444 // a step'd over clause |
|
1445 |
|
1446 // probably academic now! |
|
1447 //Machine()->SetIfState(CIFControl::EIgnoreIF); |
|
1448 |
|
1449 Machine()->EndIf(); |
|
1450 |
|
1451 return ret; |
|
1452 } |
|
1453 |
|
1454 //----------------------------------------------------------------------------- |
|
1455 // End of File |
|
1456 //----------------------------------------------------------------------------- |