|
1 |
|
2 /* |
|
3 * Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 * All rights reserved. |
|
5 * This component and the accompanying materials are made available |
|
6 * under the terms of "Eclipse Public License v1.0" |
|
7 * which accompanies this distribution, and is available |
|
8 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * Description : |
|
14 * |
|
15 */ |
|
16 |
|
17 |
|
18 |
|
19 // INCLUDES |
|
20 #include <hwrmlightdomaincrkeys.h> |
|
21 #include <coreapplicationuisdomainpskeys.h> |
|
22 #include <hal.h> |
|
23 #include <atcmdpluginresource.rsg> |
|
24 #include <barsread.h> |
|
25 #include <barsc.h> |
|
26 #include <bautils.h> |
|
27 #include <e32math.h> |
|
28 #include <e32base.h> |
|
29 #include <eikenv.h> |
|
30 #include <apgtask.h> |
|
31 #include "debug.h" |
|
32 #include "atcmdplugin.h" |
|
33 |
|
34 // CONSTANTS |
|
35 _LIT8( KAtCkpd, "+CKPD" ); |
|
36 _LIT8( KAtCbklt, "+CBKLT" ); |
|
37 _LIT8( KCRLF, "\r\n" ); |
|
38 _LIT8( KAtCtsa, "+CTSA"); |
|
39 |
|
40 const TInt KCustomKeyCodeIdentifier = -1; |
|
41 const TInt KGranularity = 10; |
|
42 const TInt KTimeMultiplier = 100000; |
|
43 const TInt KMicroSeconds = 1000000; |
|
44 |
|
45 #define REPLY_BUFFER_SIZE 200 |
|
46 |
|
47 // These values are based on testing results. |
|
48 // Values less than 2000 causes some times missing key events |
|
49 // even all keys are simulated with long commands. |
|
50 const TInt KDefaultStrokeDelay = 50000; |
|
51 const TInt KDefaultStrokeTime = 10000; |
|
52 |
|
53 const TInt KLightTarget = CHWRMLight::EPrimaryDisplayAndKeyboard; |
|
54 |
|
55 _LIT8( KParameterSeparator, "," ); |
|
56 _LIT8( Kok, "\r\nOK\r\n"); |
|
57 _LIT8( KCmeErrorNotSupported, "\r\n+CME ERROR: 4\r\n"); |
|
58 _LIT8( KTestCommand, "=?" ); |
|
59 _LIT8( KReadCommand, "?" ); |
|
60 _LIT8( KCbkltTestCommandResp, ":(0,1,2)" ); |
|
61 _LIT8( KCkpdTestCommandResp, ":(GSM)" ); |
|
62 _LIT8( KCtsaTestCommandResp, ":(0,1,2),(width),(height)" ); |
|
63 _LIT( KFileName, "\\resource\\apps\\atcmdpluginresource.rsc" ); |
|
64 |
|
65 |
|
66 // ============================= MEMBER FUNCTIONS ============================= |
|
67 |
|
68 // ---------------------------------------------------------------------------- |
|
69 // CATCmdPluginEcom::NewL |
|
70 // 2-phased constructor |
|
71 // (may leave) |
|
72 // ---------------------------------------------------------------------------- |
|
73 // |
|
74 CATCmdPluginEcom* CATCmdPluginEcom::NewL() |
|
75 { |
|
76 CATCmdPluginEcom* self = new (ELeave) CATCmdPluginEcom(); |
|
77 CleanupStack::PushL( self ); |
|
78 self->ConstructL(); |
|
79 CleanupStack::Pop( self ); |
|
80 |
|
81 return self; |
|
82 } |
|
83 |
|
84 // ---------------------------------------------------------------------------- |
|
85 // CATCmdPluginEcom::CATCmdPluginEcom |
|
86 // Constructor |
|
87 // ---------------------------------------------------------------------------- |
|
88 // |
|
89 CATCmdPluginEcom::CATCmdPluginEcom() |
|
90 : CATExtPluginBase() |
|
91 { |
|
92 TRACE_FUNC |
|
93 } |
|
94 |
|
95 // ---------------------------------------------------------------------------- |
|
96 // CATCmdPluginEcom::ConstructL |
|
97 // Constructor |
|
98 // (may leave) |
|
99 // ---------------------------------------------------------------------------- |
|
100 // |
|
101 void CATCmdPluginEcom::ConstructL() |
|
102 { |
|
103 TRACE_FUNC |
|
104 |
|
105 LEAVE_IF_ERROR( iWsSession.Connect() ); |
|
106 iCkpdCmdArray = new (ELeave) CArrayFixFlat<TATCkpdCmd>( KGranularity ); |
|
107 |
|
108 iKpdTimer = new ( ELeave ) CATCmdTimer( *this, ECmdCkpd ); |
|
109 iKpdTimer->ConstructL(); |
|
110 |
|
111 iBkltTimer = new ( ELeave ) CATCmdTimer( *this, ECmdCbklt ); |
|
112 iBkltTimer->ConstructL(); |
|
113 |
|
114 iKeepAliveTimer = new ( ELeave ) CATCmdTimer( *this, EKeepAlive ); |
|
115 iKeepAliveTimer->ConstructL(); |
|
116 |
|
117 |
|
118 LoadResourcesL(); |
|
119 } |
|
120 |
|
121 // ---------------------------------------------------------------------------- |
|
122 // CATCmdPluginEcom::::LoadResourcesL |
|
123 // Load resources |
|
124 // (may leave) |
|
125 // Status : Approved |
|
126 // ---------------------------------------------------------------------------- |
|
127 // |
|
128 void CATCmdPluginEcom::LoadResourcesL() |
|
129 { |
|
130 TRACE_FUNC_ENTRY |
|
131 |
|
132 RFs fs; |
|
133 CleanupClosePushL( fs ); |
|
134 |
|
135 TFileName fileName; |
|
136 fileName.Copy( KFileName ); |
|
137 User::LeaveIfError( fs.Connect() ); |
|
138 BaflUtils::NearestLanguageFile( fs, fileName ); |
|
139 |
|
140 RResourceFile resourceFile; |
|
141 CleanupClosePushL( resourceFile ); |
|
142 resourceFile.OpenL( fs, fileName ); |
|
143 resourceFile.ConfirmSignatureL(); |
|
144 |
|
145 HBufC8* buf8 = resourceFile.AllocReadLC( R_ATCMDPLUGIN_TRANSLATIONTABLE ); |
|
146 |
|
147 TResourceReader reader; |
|
148 reader.SetBuffer( buf8 ); |
|
149 |
|
150 TInt count = reader.ReadInt16(); // array count |
|
151 iTranslations = new ( ELeave ) CArrayPtrFlat<CATCmdTranslation>( count ); |
|
152 |
|
153 while ( count-- ) |
|
154 { |
|
155 const TInt code = reader.ReadInt32(); |
|
156 |
|
157 HBufC8* param = reader.ReadHBufC8L(); |
|
158 CleanupStack::PushL( param ); |
|
159 CATCmdTranslation* t = new (ELeave) CATCmdTranslation( *param, code ); |
|
160 CleanupStack::Pop( param ); // transfer ownership |
|
161 |
|
162 CleanupStack::PushL( t ); |
|
163 iTranslations->AppendL( t ); |
|
164 CleanupStack::Pop( t ); // transfer ownership |
|
165 } |
|
166 |
|
167 CleanupStack::PopAndDestroy( 3 ); // resourceFile, fs, buf8 |
|
168 |
|
169 TRACE_FUNC_EXIT |
|
170 } |
|
171 |
|
172 |
|
173 // ---------------------------------------------------------------------------- |
|
174 // CATCmdPluginEcom::~CATCmdPluginEcom |
|
175 // C++ Destructor |
|
176 // ---------------------------------------------------------------------------- |
|
177 // |
|
178 CATCmdPluginEcom::~CATCmdPluginEcom() |
|
179 { |
|
180 TRACE_FUNC |
|
181 |
|
182 if(iKpdTimer) |
|
183 { |
|
184 iKpdTimer->Cancel(); |
|
185 delete iKpdTimer; |
|
186 } |
|
187 if(iBkltTimer) |
|
188 { |
|
189 iBkltTimer->Cancel(); |
|
190 delete iBkltTimer; |
|
191 } |
|
192 if(iKeepAliveTimer) |
|
193 { |
|
194 iKeepAliveTimer->Cancel(); |
|
195 delete iKeepAliveTimer; |
|
196 } |
|
197 if ( iTranslations) |
|
198 { |
|
199 iTranslations->ResetAndDestroy(); |
|
200 delete iTranslations; |
|
201 } |
|
202 if ( iCkpdCmdArray) |
|
203 { |
|
204 iCkpdCmdArray->Reset(); |
|
205 delete iCkpdCmdArray; |
|
206 } |
|
207 iWsSession.Close(); |
|
208 } |
|
209 |
|
210 |
|
211 // ---------------------------------------------------------------------------- |
|
212 // CATCmdPluginEcom::HandleCommand |
|
213 // Handle given command |
|
214 // ---------------------------------------------------------------------------- |
|
215 // |
|
216 void CATCmdPluginEcom::HandleCommand( const TDesC8& aCmd, RBuf8& aReply, TBool /* aReplyNeeded */) |
|
217 { |
|
218 TRACE_FUNC_ENTRY |
|
219 aReply.Create(REPLY_BUFFER_SIZE); |
|
220 aReply.Zero(); |
|
221 iReplyBuf = &aReply; |
|
222 |
|
223 if ( IsCommandSupported( aCmd ) ) |
|
224 { |
|
225 |
|
226 TRAPD( err, HandleCommandL( aCmd ) ); |
|
227 |
|
228 if ( err ) |
|
229 { |
|
230 iReplyBuf->Append( KCmeErrorNotSupported ); |
|
231 } |
|
232 else |
|
233 { |
|
234 if(iReplyBuf->Length() == 0) |
|
235 { |
|
236 iReplyBuf->Append( Kok ); |
|
237 } |
|
238 } |
|
239 HandleCommandCompleted( KErrNone,EReplyTypeOk ); |
|
240 } |
|
241 TRACE_FUNC_EXIT |
|
242 } |
|
243 |
|
244 // ---------------------------------------------------------------------------- |
|
245 // CATCmdPluginEcom::HandleCommandL |
|
246 // Handle given command |
|
247 // (may leave) |
|
248 // ---------------------------------------------------------------------------- |
|
249 // |
|
250 void CATCmdPluginEcom::HandleCommandL( const TDesC8& aCmd ) |
|
251 { |
|
252 // Verify command |
|
253 TInt offset; |
|
254 HBufC8* cmd = aCmd.AllocLC(); |
|
255 // CleanupStack:: PushL(cmd); |
|
256 TPtr8 ptr = cmd->Des(); |
|
257 |
|
258 ptr.Trim(); |
|
259 TPtrC8 cptr; |
|
260 |
|
261 if ( ( offset = ptr.FindF(KAtCkpd) ) >= 0 ) |
|
262 { |
|
263 cptr.Set( ptr.Mid( offset + KAtCkpd().Length() ) ); |
|
264 HandleCkpdCommandL( cptr ); |
|
265 } |
|
266 else if ( ( offset = ptr.FindF(KAtCbklt) ) >= 0 ) |
|
267 { |
|
268 cptr.Set( ptr.Mid( offset + KAtCbklt().Length() ) ); |
|
269 HandleCbkltCommandL( cptr ); |
|
270 } |
|
271 else if ( ( offset = ptr.FindF(KAtCtsa) ) >= 0 ) |
|
272 { |
|
273 cptr.Set( ptr.Mid( offset + KAtCtsa().Length() ) ); |
|
274 HandleCtsaCommandL( cptr ); |
|
275 } |
|
276 CleanupStack::PopAndDestroy( cmd ); |
|
277 } |
|
278 |
|
279 // ------------------------- |
|
280 // HandleCtsaCommandL |
|
281 // |
|
282 // ------------------------- |
|
283 |
|
284 void CATCmdPluginEcom::HandleCtsaCommandL( const TDesC8& aCmd ) |
|
285 { |
|
286 |
|
287 if ( aCmd.Compare( KTestCommand ) == 0 ) |
|
288 { |
|
289 // Test command just returns "OK" |
|
290 iReplyBuf->Append( KCRLF ); |
|
291 iReplyBuf->Append( KAtCtsa ); |
|
292 iReplyBuf->Append( KCtsaTestCommandResp ); |
|
293 iReplyBuf->Append( KCRLF ); |
|
294 TRACE_FUNC_EXIT |
|
295 return; |
|
296 } |
|
297 |
|
298 // Check boundary condition |
|
299 if ( ( aCmd.Length() < 6 ) || ( aCmd[2] != ',' )) |
|
300 { |
|
301 // Command Syntax Error |
|
302 User::Leave( KErrNotSupported ); |
|
303 } |
|
304 TInt pos=0; |
|
305 TInt8 actionValue = aCmd[1] - '0'; |
|
306 TInt16 xCoordinateValue = 0; |
|
307 TInt16 yCoordinateValue = 0; |
|
308 TInt16 commandLen = aCmd.Length(); |
|
309 |
|
310 |
|
311 if( actionValue < 0 || actionValue > 4 ) |
|
312 { |
|
313 // Command Syntax Error |
|
314 User::Leave( KErrNotSupported ); |
|
315 } |
|
316 |
|
317 pos=3; // X Cordinate starts from 3d character |
|
318 |
|
319 CWsScreenDevice *scrnDevPointer = new(ELeave) CWsScreenDevice(iWsSession); |
|
320 TSize coordinateSize; |
|
321 |
|
322 scrnDevPointer->Construct(); |
|
323 coordinateSize = scrnDevPointer->SizeInPixels(); |
|
324 delete scrnDevPointer; |
|
325 |
|
326 while(pos < commandLen) |
|
327 { |
|
328 if((aCmd[pos] >= '0') && (aCmd[pos] <= '9')) |
|
329 { |
|
330 xCoordinateValue *= 10; |
|
331 xCoordinateValue += aCmd[pos] - '0'; |
|
332 pos++; |
|
333 if(xCoordinateValue > coordinateSize.iWidth ) |
|
334 { |
|
335 // Command Syntax Error |
|
336 User::Leave( KErrNotSupported ); |
|
337 } |
|
338 } |
|
339 else if((aCmd[pos] == ',') && pos > 3 ) |
|
340 { |
|
341 pos++; |
|
342 break; |
|
343 } |
|
344 else |
|
345 { |
|
346 // Command Syntax Error |
|
347 User::Leave( KErrNotSupported ); |
|
348 } |
|
349 } |
|
350 if(pos == commandLen) |
|
351 { |
|
352 // Command of type =0,100 /* Command Syntax Error */ |
|
353 User::Leave( KErrNotSupported ); |
|
354 } |
|
355 while(pos < commandLen) |
|
356 { |
|
357 if((aCmd[pos] >= '0') && (aCmd[pos] <= '9')) |
|
358 { |
|
359 yCoordinateValue *= 10; |
|
360 yCoordinateValue += aCmd[pos] - '0'; |
|
361 pos++; |
|
362 if(yCoordinateValue > coordinateSize.iHeight) |
|
363 { |
|
364 // Command Syntax Error |
|
365 User::Leave( KErrNotSupported ); |
|
366 } |
|
367 } |
|
368 else |
|
369 { |
|
370 // Command Syntax Error |
|
371 User::Leave( KErrNotSupported ); |
|
372 } |
|
373 } |
|
374 |
|
375 TRawEvent rawEvent; |
|
376 switch(actionValue) |
|
377 { |
|
378 case 0: // Release pointer event |
|
379 { |
|
380 rawEvent.Set( TRawEvent::EButton1Up, xCoordinateValue, yCoordinateValue); |
|
381 iWsSession.SimulateRawEvent(rawEvent); |
|
382 iWsSession.Flush(); |
|
383 break; |
|
384 } |
|
385 case 1: // Depress pointer event |
|
386 { |
|
387 rawEvent.Set( TRawEvent::EButton1Down, xCoordinateValue, yCoordinateValue); |
|
388 iWsSession.SimulateRawEvent(rawEvent); |
|
389 iWsSession.Flush(); |
|
390 break; |
|
391 } |
|
392 case 2: // Single tap pointer event |
|
393 { |
|
394 rawEvent.Set( TRawEvent::EButton1Down, xCoordinateValue, yCoordinateValue); |
|
395 iWsSession.SimulateRawEvent(rawEvent); |
|
396 rawEvent.Set( TRawEvent::EButton1Up, xCoordinateValue+1, yCoordinateValue+1); |
|
397 iWsSession.SimulateRawEvent(rawEvent); |
|
398 iWsSession.Flush(); |
|
399 break; |
|
400 } |
|
401 case 3: // Double tap pointer event |
|
402 { |
|
403 rawEvent.Set( TRawEvent::EButton1Down, xCoordinateValue, yCoordinateValue); |
|
404 iWsSession.SimulateRawEvent(rawEvent); |
|
405 rawEvent.Set( TRawEvent::EButton1Up, xCoordinateValue+1, yCoordinateValue+1); |
|
406 iWsSession.SimulateRawEvent(rawEvent); |
|
407 rawEvent.Set( TRawEvent::EButton1Down, xCoordinateValue, yCoordinateValue); |
|
408 iWsSession.SimulateRawEvent(rawEvent); |
|
409 rawEvent.Set( TRawEvent::EButton1Up, xCoordinateValue+1, yCoordinateValue+1); |
|
410 iWsSession.SimulateRawEvent(rawEvent); |
|
411 iWsSession.Flush(); |
|
412 break; |
|
413 } |
|
414 } |
|
415 } |
|
416 |
|
417 |
|
418 // ---------------------------------------------------------------------------- |
|
419 // CATCmdPluginEcom::HandleCkpdCommandL |
|
420 // Handle CKPD command |
|
421 // (may leave) |
|
422 // ---------------------------------------------------------------------------- |
|
423 // |
|
424 void CATCmdPluginEcom::HandleCkpdCommandL( const TDesC8& aCmd ) |
|
425 { |
|
426 TRACE_FUNC_ENTRY |
|
427 TBool commandVerified(EFalse); |
|
428 TInt strokeTime = 0; |
|
429 TInt strokeDelay = 0; |
|
430 |
|
431 if ( aCmd.Compare( KTestCommand ) == 0 ) |
|
432 { |
|
433 iReplyBuf->Append( KCRLF ); |
|
434 iReplyBuf->Append( KAtCkpd ); |
|
435 iReplyBuf->Append( KCkpdTestCommandResp ); |
|
436 iReplyBuf->Append( KCRLF ); |
|
437 TRACE_FUNC_EXIT |
|
438 return; |
|
439 } |
|
440 |
|
441 CArrayFix<TATCkpdCmd>* ckpdCmds = |
|
442 new (ELeave) CArrayFixFlat<TATCkpdCmd>( KGranularity ); |
|
443 CleanupStack::PushL( ckpdCmds ); |
|
444 |
|
445 // Check that keys are defined |
|
446 if ( aCmd.Length() <= 1 ) |
|
447 { |
|
448 // Command Syntax Error |
|
449 User::Leave( KErrNotSupported ); |
|
450 } |
|
451 |
|
452 // Go through keys |
|
453 TBuf8<2> key; |
|
454 for (TInt i = 1 ; i < aCmd.Length(); i++ ) |
|
455 { |
|
456 key.Copy(&aCmd[i],1); |
|
457 |
|
458 // Go through translation table for every character |
|
459 for ( TInt j = 0; j < iTranslations->Count(); j++ ) |
|
460 { |
|
461 CATCmdTranslation& translation = *iTranslations->At( j ); |
|
462 if ( key.CompareF( translation.Param() ) == 0 ) |
|
463 { |
|
464 // Check if key is escape character for manufacturer specific keys |
|
465 if ( translation.Code() == KCustomKeyCodeIdentifier ) |
|
466 { |
|
467 // Read next key to form key combination |
|
468 i++; |
|
469 |
|
470 // Check that there are key after escape character |
|
471 if ( i >= aCmd.Length() ) |
|
472 { |
|
473 TRACE_INFO(( _L( "INFO: invalid manufacturer specific key" ) )) |
|
474 // Not handled |
|
475 User::Leave( KErrNotSupported ); |
|
476 } |
|
477 |
|
478 if ( key.Length() < key.MaxLength() ) |
|
479 { |
|
480 key.Append(aCmd[i]); |
|
481 } |
|
482 |
|
483 // Start looping again for looking keycombination |
|
484 // from translation table |
|
485 j = 0; |
|
486 } |
|
487 else |
|
488 { |
|
489 // Command verified |
|
490 commandVerified = ETrue; |
|
491 |
|
492 if ( translation.Code() != EKeyNull ) |
|
493 { |
|
494 TATCkpdCmd cmd; |
|
495 cmd.iCode = translation.Code(); |
|
496 ckpdCmds->AppendL( cmd ); |
|
497 } |
|
498 |
|
499 break; |
|
500 } |
|
501 } |
|
502 } |
|
503 |
|
504 if (!commandVerified) |
|
505 { |
|
506 // Check if character is parameter separator |
|
507 if ( key.Compare( KParameterSeparator ) == 0 ) |
|
508 { |
|
509 i++; |
|
510 |
|
511 if ( i > aCmd.Length() ) |
|
512 { |
|
513 TRACE_ERROR(( _L( "ERROR: invalid stroke time parameter" ) )) |
|
514 |
|
515 // Not handled |
|
516 User::Leave( KErrNotSupported ); |
|
517 } |
|
518 |
|
519 ParseParametersL( |
|
520 aCmd.Right(aCmd.Length()-i), |
|
521 strokeTime, |
|
522 strokeDelay); |
|
523 |
|
524 strokeTime *= KTimeMultiplier; |
|
525 strokeDelay *= KTimeMultiplier; |
|
526 |
|
527 break; |
|
528 } |
|
529 else |
|
530 { |
|
531 TRACE_ERROR(( _L8( "ERROR: Command %S not supported" ), &key )) |
|
532 |
|
533 // Not handled |
|
534 User::Leave( KErrNotSupported ); |
|
535 } |
|
536 } |
|
537 |
|
538 commandVerified = EFalse; |
|
539 } |
|
540 |
|
541 // Set default stroke time and delay if those are not set with parameters or |
|
542 // parameter value have been zero. If values are not greater than ~2ms there |
|
543 // is possibility to loose key events with long commands even all keys are |
|
544 // simulated by atcmdplugin |
|
545 if ( !strokeTime ) |
|
546 { |
|
547 strokeTime = KDefaultStrokeTime; |
|
548 } |
|
549 |
|
550 if ( !strokeDelay ) |
|
551 { |
|
552 strokeDelay = KDefaultStrokeDelay; |
|
553 } |
|
554 |
|
555 // Append commands to command array |
|
556 for ( TInt count = 0; count < ckpdCmds->Count(); count++ ) |
|
557 { |
|
558 TATCkpdCmd cmd = ckpdCmds->At(count); |
|
559 cmd.iStrokeTime = strokeTime; |
|
560 cmd.iStrokeDelay = strokeDelay; |
|
561 |
|
562 iCkpdCmdArray->AppendL( cmd ); |
|
563 } |
|
564 |
|
565 CleanupStack::PopAndDestroy(ckpdCmds); |
|
566 |
|
567 SendKeyL(); |
|
568 |
|
569 TRACE_FUNC_EXIT |
|
570 } |
|
571 |
|
572 // ---------------------------------------------------------------------------- |
|
573 // CATCmdPluginEcom::HandleCbkltCommandL |
|
574 // Handle CKPD command |
|
575 // (may leave) |
|
576 // ---------------------------------------------------------------------------- |
|
577 // |
|
578 void CATCmdPluginEcom::HandleCbkltCommandL( const TDesC8& aCmd ) |
|
579 { |
|
580 TRACE_FUNC_ENTRY |
|
581 |
|
582 |
|
583 if ( aCmd.Compare( KTestCommand ) == 0 ) |
|
584 { |
|
585 iReplyBuf->Append( KCRLF ); |
|
586 iReplyBuf->Append( KAtCbklt ); |
|
587 iReplyBuf->Append( KCbkltTestCommandResp ); |
|
588 iReplyBuf->Append( KCRLF ); |
|
589 TRACE_FUNC_EXIT |
|
590 return; |
|
591 } |
|
592 |
|
593 if(iLightStatus != ELightOnWithDuration) |
|
594 { |
|
595 iLight = CHWRMLight::NewL( this ); |
|
596 |
|
597 iLightStatus = |
|
598 ( iLight->LightStatus( KLightTarget ) == CHWRMLight::ELightOff )? |
|
599 ELightOff : ELightOn; |
|
600 delete iLight; |
|
601 } |
|
602 |
|
603 if ( aCmd.Compare( KReadCommand ) == 0 ) |
|
604 { |
|
605 iReplyBuf->Append( KCRLF ); |
|
606 iReplyBuf->Append( KAtCbklt ); |
|
607 iReplyBuf->Append( ':' ); |
|
608 iReplyBuf->Append( ' ' ); |
|
609 iReplyBuf->AppendNum( iLightStatus ); |
|
610 if ( iLightStatus == ELightOnWithDuration ) |
|
611 { |
|
612 iReplyBuf->Append( ',' ); |
|
613 iReplyBuf->AppendNum( iDuration ); |
|
614 } |
|
615 iReplyBuf->Append( KCRLF ); |
|
616 TRACE_FUNC_EXIT |
|
617 return; |
|
618 } |
|
619 |
|
620 if ( aCmd.Length() <= 1 ) |
|
621 { |
|
622 // Command Syntax Error |
|
623 User::Leave( KErrNotSupported ); |
|
624 } |
|
625 |
|
626 switch ( aCmd[ 1 ] ) |
|
627 { |
|
628 case '0': |
|
629 { |
|
630 if ( aCmd.Length() == 2 ) |
|
631 { |
|
632 iKeepAliveTimer->Cancel(); |
|
633 DisableBackLight(); |
|
634 iLightStatus = ELightOff; |
|
635 } |
|
636 else |
|
637 { |
|
638 //if the command is too long it means that is incorrect |
|
639 User::Leave( KErrNotSupported ); |
|
640 } |
|
641 break; |
|
642 } |
|
643 case '1': |
|
644 { |
|
645 if ( ( aCmd.Length() > 3 ) && ( aCmd[ 2 ] == ',' ) ) |
|
646 { |
|
647 TInt pos = 3; |
|
648 TInt commandLen = aCmd.Length(); |
|
649 iDuration = 0; |
|
650 while(pos < commandLen) |
|
651 { |
|
652 if((aCmd[pos] >= '0') && (aCmd[pos] <= '9')) |
|
653 { |
|
654 iDuration *= 10; |
|
655 iDuration += aCmd[pos] - '0'; |
|
656 pos++; |
|
657 } |
|
658 else |
|
659 { |
|
660 User::Leave( KErrNotSupported ); |
|
661 } |
|
662 } |
|
663 iBkltTimer->Cancel(); |
|
664 iBkltTimer->After( iDuration * KMicroSeconds ); |
|
665 EnableBackLight(); |
|
666 if ( !iKeepAliveTimer->IsActive() ) |
|
667 { |
|
668 iKeepAliveTimer->After( 2000000 ); |
|
669 } |
|
670 iLightStatus = ELightOnWithDuration; |
|
671 } |
|
672 else |
|
673 { |
|
674 //the command is wrong |
|
675 User::Leave( KErrNotSupported ); |
|
676 } |
|
677 break; |
|
678 } |
|
679 case '2': |
|
680 { |
|
681 if ( aCmd.Length() == 2 ) |
|
682 { |
|
683 iBkltTimer->Cancel(); |
|
684 EnableBackLight(); |
|
685 if ( !iKeepAliveTimer->IsActive() ) |
|
686 { |
|
687 iKeepAliveTimer->After( 2000000 ); |
|
688 } |
|
689 iLightStatus = ELightOn; |
|
690 } |
|
691 else |
|
692 { |
|
693 //if the command is too long it means that is incorrect |
|
694 User::Leave( KErrNotSupported ); |
|
695 } |
|
696 break; |
|
697 } |
|
698 default: |
|
699 { |
|
700 User::Leave( KErrNotSupported ); |
|
701 } |
|
702 } |
|
703 TRACE_FUNC_EXIT |
|
704 } |
|
705 |
|
706 // ---------------------------------------------------------------------------- |
|
707 // CATCmdPluginEcom::EnableBackLight() |
|
708 // ---------------------------------------------------------------------------- |
|
709 // |
|
710 void CATCmdPluginEcom::EnableBackLight() |
|
711 { |
|
712 TRACE_FUNC |
|
713 RProperty::Set( KPSUidCoreApplicationUIs, KLightsATCForcedLightsOn, EForcedLightsOn ); |
|
714 } |
|
715 |
|
716 // ---------------------------------------------------------------------------- |
|
717 // CATCmdPluginEcom::DisableBackLight() |
|
718 // ---------------------------------------------------------------------------- |
|
719 // |
|
720 void CATCmdPluginEcom::DisableBackLight() |
|
721 { |
|
722 TRACE_FUNC |
|
723 RProperty::Set( KPSUidCoreApplicationUIs, KLightsATCForcedLightsOn, EForcedLightsOff ); |
|
724 } |
|
725 |
|
726 // ----------------------------------------------------------------------------- |
|
727 // CATCmdPluginEcom::LightStatusChanged() |
|
728 // ----------------------------------------------------------------------------- |
|
729 // |
|
730 void CATCmdPluginEcom::LightStatusChanged( TInt /*aTarget*/, CHWRMLight::TLightStatus /*aStatus*/ ) |
|
731 { |
|
732 //TRACE_STATE(( _L( "** LightStatusChanged %d, %d" ), aTarget, aStatus )) |
|
733 } |
|
734 |
|
735 // ---------------------------------------------------------------------------- |
|
736 // CATCmdPluginEcom::IsCommandSupported |
|
737 // - |
|
738 // ---------------------------------------------------------------------------- |
|
739 // |
|
740 TBool CATCmdPluginEcom::IsCommandSupported( const TDesC8& aCmd ) |
|
741 { |
|
742 TRACE_FUNC |
|
743 TBool ret(EFalse); |
|
744 |
|
745 if ( aCmd != KNullDesC8 && ( aCmd.FindF(KAtCkpd) >= 0 || |
|
746 aCmd.FindF(KAtCbklt) >= 0 || aCmd.FindF(KAtCtsa) >= 0 )) |
|
747 { |
|
748 ret = ETrue; |
|
749 } |
|
750 return ret; |
|
751 } |
|
752 |
|
753 // CATCmdPluginEcom::ParseParameterL |
|
754 // - |
|
755 // (may leave) |
|
756 // ---------------------------------------------------------------------------- |
|
757 // |
|
758 void CATCmdPluginEcom::ParseParametersL( |
|
759 const TDesC8& aCmd, |
|
760 TInt& aStrokeTime, |
|
761 TInt& aStrokeDelay ) |
|
762 { |
|
763 TRACE_FUNC_ENTRY |
|
764 |
|
765 TInt i(0); |
|
766 |
|
767 if ( !aCmd.Length() ) |
|
768 { |
|
769 TRACE_ERROR(( _L( "ERROR: invalid stroke time parameter" ) )) |
|
770 // Not handled |
|
771 User::Leave( KErrNotSupported ); |
|
772 } |
|
773 |
|
774 |
|
775 // Parse stroke time parameter |
|
776 TBuf8<3> strokeTimeBuf; |
|
777 |
|
778 // Go through command until end or parameter separator is reached |
|
779 for ( ; i < aCmd.Length(); i++ ) |
|
780 { |
|
781 if ( aCmd[i] >= '0' && aCmd[i] <= '9' ) |
|
782 { |
|
783 strokeTimeBuf.Append(aCmd[i]); |
|
784 continue; |
|
785 } |
|
786 else if ( aCmd[i] == ',' || aCmd[i] == '\r' || aCmd[i] == '\n' ) |
|
787 { |
|
788 i++; |
|
789 break; |
|
790 } |
|
791 else |
|
792 { |
|
793 TRACE_ERROR(( _L( "ERROR: invalid stroke time parameter" ) )) |
|
794 |
|
795 // Not handled |
|
796 User::Leave( KErrNotSupported ); |
|
797 } |
|
798 } |
|
799 |
|
800 TLex8 strokeTimeLex( strokeTimeBuf ); |
|
801 strokeTimeLex.Val( aStrokeTime ); |
|
802 |
|
803 // Verify parsed parameter |
|
804 if ( aStrokeTime < 0 || aStrokeTime > 255 ) |
|
805 { |
|
806 TRACE_ERROR(( _L( "ERROR: invalid stroke time parameter" ) )) |
|
807 |
|
808 // Not handled |
|
809 User::Leave( KErrNotSupported ); |
|
810 } |
|
811 |
|
812 |
|
813 // Parse stroke delay parameter |
|
814 TBuf8<3> strokeDelayBuf; |
|
815 |
|
816 for ( ; i < aCmd.Length(); i++ ) |
|
817 { |
|
818 if ( aCmd[i] >= '0' && aCmd[i] <= '9' ) |
|
819 { |
|
820 strokeDelayBuf.Append(aCmd[i]); |
|
821 continue; |
|
822 } |
|
823 else if ( aCmd[i] == ',' || aCmd[i] == '\r' || aCmd[i] == '\n' ) |
|
824 { |
|
825 break; |
|
826 } |
|
827 else |
|
828 { |
|
829 TRACE_ERROR(( _L( "ERROR: invalid stroke delay parameter" ) )) |
|
830 |
|
831 // Not handled |
|
832 User::Leave( KErrNotSupported ); |
|
833 } |
|
834 } |
|
835 |
|
836 TLex8 strokeDelayLex( strokeDelayBuf ); |
|
837 strokeDelayLex.Val( aStrokeDelay ); |
|
838 |
|
839 if ( aStrokeDelay < 0 || aStrokeDelay > 255 ) |
|
840 { |
|
841 TRACE_ERROR(( _L( "ERROR: invalid stroke delay parameter" ) )) |
|
842 |
|
843 // Not handled |
|
844 User::Leave( KErrNotSupported ); |
|
845 } |
|
846 |
|
847 TRACE_FUNC_EXIT |
|
848 } |
|
849 |
|
850 // ---------------------------------------------------------------------------- |
|
851 // CATCmdPluginEcom::SendKeyL |
|
852 // - |
|
853 // (may leave) |
|
854 // ---------------------------------------------------------------------------- |
|
855 // |
|
856 void CATCmdPluginEcom::SendKeyL() |
|
857 { |
|
858 TRACE_FUNC |
|
859 |
|
860 if ( !iKpdTimer->IsActive() ) |
|
861 { |
|
862 const TInt count = iCkpdCmdArray->Count(); |
|
863 if ( count ) |
|
864 { |
|
865 TATCkpdCmd cmd = iCkpdCmdArray->At(0); |
|
866 TKeyEvent key; |
|
867 key.iScanCode = cmd.iCode; |
|
868 key.iCode = 0; |
|
869 key.iRepeats = 0; |
|
870 |
|
871 TTimeIntervalMicroSeconds32 strokeTime = cmd.iStrokeTime; |
|
872 TTimeIntervalMicroSeconds32 strokeDelay = cmd.iStrokeDelay; |
|
873 |
|
874 TRACE_INFO(( _L( " Scancode:%d, stroke time:%d, stroke delay: %d" ), |
|
875 key.iScanCode, strokeTime.Int(), strokeDelay.Int() )) |
|
876 |
|
877 if ( iLastEvent == EEventNull || iLastEvent == EEventKeyUp) |
|
878 { |
|
879 SimulateRawEventL( key, EEventKeyDown ); |
|
880 |
|
881 if ( strokeTime.Int() > 0) |
|
882 { |
|
883 iKpdTimer->After( strokeTime ); |
|
884 return; |
|
885 } |
|
886 } |
|
887 |
|
888 if ( iLastEvent == EEventKeyDown || iLastEvent == EEventKey ) |
|
889 { |
|
890 SimulateRawEventL( key, EEventKeyUp ); |
|
891 |
|
892 iCkpdCmdArray->Delete( 0 ); |
|
893 |
|
894 if ( strokeDelay.Int() > 0 && iCkpdCmdArray->Count() > 0 ) |
|
895 { |
|
896 iKpdTimer->After( strokeDelay ); |
|
897 return; |
|
898 } |
|
899 else |
|
900 { |
|
901 SendNextKeyL(); |
|
902 } |
|
903 } |
|
904 } |
|
905 } |
|
906 } |
|
907 |
|
908 |
|
909 // ---------------------------------------------------------------------------- |
|
910 // CATCmdPluginEcom::SendNextKeyL |
|
911 // - |
|
912 // (may leave) |
|
913 // ---------------------------------------------------------------------------- |
|
914 // |
|
915 void CATCmdPluginEcom::SendNextKeyL() |
|
916 { |
|
917 TRACE_FUNC |
|
918 |
|
919 const TInt count = iCkpdCmdArray->Count(); |
|
920 if ( count ) |
|
921 { |
|
922 SendKeyL(); |
|
923 } |
|
924 } |
|
925 |
|
926 // ---------------------------------------------------------------------------- |
|
927 // CATCmdPluginEcom::TimerExpiredL |
|
928 // - |
|
929 // (may leave) |
|
930 // ---------------------------------------------------------------------------- |
|
931 // |
|
932 void CATCmdPluginEcom::TimerExpiredL( TInt aRelatedCommand ) |
|
933 { |
|
934 TRACE_FUNC |
|
935 |
|
936 if( aRelatedCommand == ECmdCkpd ) |
|
937 { |
|
938 SendNextKeyL(); |
|
939 } |
|
940 else if ( aRelatedCommand == ECmdCbklt ) |
|
941 { |
|
942 DisableBackLight(); |
|
943 iLightStatus = ELightOff; |
|
944 iKeepAliveTimer->Cancel(); |
|
945 } |
|
946 else |
|
947 { |
|
948 User::ResetInactivityTime(); |
|
949 iKeepAliveTimer->After( 2000000 ); |
|
950 } |
|
951 } |
|
952 |
|
953 // ---------------------------------------------------------------------------- |
|
954 // CATCmdPluginEcom::SimulateRawEventL |
|
955 // - |
|
956 // (may leave) |
|
957 // ---------------------------------------------------------------------------- |
|
958 // |
|
959 void CATCmdPluginEcom::SimulateRawEventL( TKeyEvent& aKey, TEventCode aEvent ) |
|
960 { |
|
961 TRACE_FUNC |
|
962 |
|
963 TRawEvent rawEvent; |
|
964 TRawEvent::TType rawType( TRawEvent::ENone ); |
|
965 switch ( aEvent ) |
|
966 { |
|
967 case EEventKeyUp: |
|
968 rawType = TRawEvent::EKeyUp; |
|
969 break; |
|
970 case EEventKeyDown: |
|
971 rawType = TRawEvent::EKeyDown; |
|
972 break; |
|
973 default: |
|
974 break; |
|
975 } |
|
976 |
|
977 if ( rawType != TRawEvent::ENone ) |
|
978 { |
|
979 rawEvent.Set( rawType, aKey.iScanCode ); |
|
980 iWsSession.SimulateRawEvent( rawEvent ); |
|
981 iWsSession.Flush(); |
|
982 } |
|
983 |
|
984 iLastEvent = aEvent; |
|
985 } |
|
986 |
|
987 // ========================= OTHER EXPORTED FUNCTIONS ========================= |
|
988 |
|
989 // ---------------------------------------------------------------------------- |
|
990 // CATCmdPluginEcom::CATCmdTimer::CATCmdTimer |
|
991 // C++Constructor |
|
992 // ---------------------------------------------------------------------------- |
|
993 // |
|
994 CATCmdPluginEcom::CATCmdTimer::CATCmdTimer( MATCmdTimer& aObserver, |
|
995 TInt aRelatedCommand ) |
|
996 : CTimer( EPriorityStandard ), |
|
997 iObserver( aObserver ), |
|
998 iRelatedCommand( aRelatedCommand ) |
|
999 { |
|
1000 TRACE_FUNC |
|
1001 |
|
1002 CActiveScheduler::Add( this ); |
|
1003 } |
|
1004 |
|
1005 // ---------------------------------------------------------------------------- |
|
1006 // CATCmdPluginEcom::CATCmdTimer::ConstructL |
|
1007 // 2nd phase constructor |
|
1008 // ---------------------------------------------------------------------------- |
|
1009 // |
|
1010 void CATCmdPluginEcom::CATCmdTimer::ConstructL() |
|
1011 { |
|
1012 TRACE_FUNC |
|
1013 CTimer::ConstructL(); |
|
1014 } |
|
1015 |
|
1016 // ---------------------------------------------------------------------------- |
|
1017 // CATCmdPluginEcom::CATCmdTimer::RunL |
|
1018 // Timer callback |
|
1019 // ---------------------------------------------------------------------------- |
|
1020 // |
|
1021 void CATCmdPluginEcom::CATCmdTimer::RunL() |
|
1022 { |
|
1023 TRACE_FUNC |
|
1024 |
|
1025 const TInt err = iStatus.Int(); |
|
1026 if ( err != KErrCancel ) |
|
1027 { |
|
1028 iObserver.TimerExpiredL( iRelatedCommand ); |
|
1029 } |
|
1030 } |
|
1031 |
|
1032 |
|
1033 void CATCmdPluginEcom::ReportConnectionName( const TDesC8& /* aName */) |
|
1034 { |
|
1035 |
|
1036 } |
|
1037 void CATCmdPluginEcom::HandleCommandCancel() |
|
1038 { |
|
1039 |
|
1040 } |
|
1041 void CATCmdPluginEcom::ReportExternalHandleCommandError() |
|
1042 { |
|
1043 |
|
1044 } |
|
1045 void CATCmdPluginEcom::ReportNvramStatusChange( const TDesC8& /* aNvram */) |
|
1046 { |
|
1047 |
|
1048 } |
|
1049 void CATCmdPluginEcom::ReceiveUnsolicitedResultCancel() |
|
1050 { |
|
1051 |
|
1052 } |
|
1053 void CATCmdPluginEcom::ReceiveUnsolicitedResult() |
|
1054 { |
|
1055 |
|
1056 } |
|
1057 TInt CATCmdPluginEcom::GetNextPartOfReply( RBuf8& /* aNextReply */) |
|
1058 { |
|
1059 return KErrNone; |
|
1060 } |
|
1061 TInt CATCmdPluginEcom::NextReplyPartLength() |
|
1062 { |
|
1063 return KErrNone; |
|
1064 } |
|
1065 |
|
1066 |
|
1067 // End of File |