|
1 /* |
|
2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #include <hal.h> |
|
21 |
|
22 #ifndef LIGHT_MODE |
|
23 #include <eikenv.h> |
|
24 #include <apgtask.h> //for TApaTask usage |
|
25 #include <apgwgnam.h> //for CApaWindowGroupName usage |
|
26 #endif |
|
27 #include "assert.h" |
|
28 #include "stat.h" |
|
29 #include "statapi_commanddecoder.h" |
|
30 #include "keycodes.h" |
|
31 #include "modifiers.h" |
|
32 #include "statapi_deviceinformation.h" |
|
33 #include "datasupplier_memory.h" |
|
34 #include "datasupplier_file.h" |
|
35 #include "dataconsumer_memory.h" |
|
36 #include "test/testshareddata.h" |
|
37 #include "test/tefshareddata.h" |
|
38 |
|
39 #ifndef LIGHT_MODE |
|
40 #include <s32mem.h> |
|
41 #include "appinstall.h" |
|
42 #endif // ifndef LIGHT_MODE |
|
43 // This redefinition is because CTRL ends in an L and so is picked up (incorrectly) by leavescan |
|
44 #define CTRLA CTRL |
|
45 |
|
46 #define ESTATNoMoreKeys (EStdKeyDecBrightness+1) |
|
47 |
|
48 #define ESMLShift 1 |
|
49 #define ESMRShift 2 |
|
50 #define ESMLAlt 4 |
|
51 #define ESMRAlt 8 |
|
52 #define ESMLCtrl 16 |
|
53 #define ESMRCtrl 32 |
|
54 #define ESMLFunc 64 |
|
55 #define ESMRFunc 128 |
|
56 |
|
57 const TInt KMaxSharedDataName = 128; |
|
58 const TInt KMaxSharedDataString = 1048; |
|
59 |
|
60 #ifndef LIGHT_MODE |
|
61 _LIT8( newLine, "\r\n" ); |
|
62 _LIT8( driveFormat, "%c,%S,%Ld%S" ); |
|
63 _LIT8( entryFormat, "%S,%d,%S,%d%S" ); |
|
64 _LIT8( dateFormat, "%02d/%02d/%04d %02d:%02d" ); |
|
65 |
|
66 #endif // ifndef LIGHT_MODE |
|
67 |
|
68 //----------------------------------------------------------------------------------- |
|
69 //constructor |
|
70 CStatApiCommandDecoder::CStatApiCommandDecoder() |
|
71 : iFs( NULL ), pMsg(NULL) |
|
72 { |
|
73 } |
|
74 |
|
75 //----------------------------------------------------------------------------------- |
|
76 |
|
77 CStatApiCommandDecoder* CStatApiCommandDecoder::NewL(RFs *const aSession, MNotifyLogMessage *const aMsg) |
|
78 { |
|
79 CStatApiCommandDecoder* self = new(ELeave) CStatApiCommandDecoder(); |
|
80 |
|
81 CleanupStack::PushL(self); |
|
82 |
|
83 self -> ConstructL(aSession, aMsg); |
|
84 |
|
85 CleanupStack::Pop(); |
|
86 |
|
87 return self; |
|
88 } |
|
89 |
|
90 //----------------------------------------------------------------------------------- |
|
91 |
|
92 void CStatApiCommandDecoder::ConstructL(RFs *const aSession, MNotifyLogMessage *const aMsg) |
|
93 { |
|
94 #ifndef LIGHT_MODE |
|
95 // Try to connect to the window session server. |
|
96 // Do not leave if there is an error as we may be in a |
|
97 // text only mode (text shell) and the window server is not |
|
98 // available. |
|
99 // We carry on for now but certain features of the command |
|
100 // decoder will become 'unsupported' and will fail. |
|
101 //creation of a new windows server session |
|
102 if(iWs.Connect() != KErrNone) { |
|
103 return; |
|
104 } |
|
105 // This line is for debug purposes. |
|
106 // It is replicated in the function 'IsWindowServerAvailable'. |
|
107 // TInt wsHandle = iWs.WsHandle(); |
|
108 #endif // ifndef LIGHT_MODE |
|
109 |
|
110 iFs = aSession; |
|
111 pMsg = aMsg; |
|
112 |
|
113 #ifndef LIGHT_MODE |
|
114 if(IsWindowServerAvailable()) |
|
115 { |
|
116 // Only start the font and bitmap server if we are in |
|
117 // window shell mode. |
|
118 User::LeaveIfError(FbsStartup()); |
|
119 User::LeaveIfError(RFbsSession::Connect()); //font and bitmap server |
|
120 |
|
121 // Create the data we use for screen capture. |
|
122 // Do this just once and re-use for each screen image. |
|
123 iDevice = new(ELeave) CWsScreenDevice(iWs); //Create new bitmap |
|
124 iDevice -> Construct(); |
|
125 |
|
126 // create new bitmap |
|
127 screenBitmap = new(ELeave) CWsBitmap(iWs); //Create new bitmap |
|
128 |
|
129 // set the display mode for the bitmap |
|
130 TInt gray; |
|
131 TInt color; |
|
132 TDisplayMode mode = iWs.GetDefModeMaxNumColors(color, gray); |
|
133 |
|
134 TSize size = iDevice -> SizeInPixels(); |
|
135 |
|
136 TInt ret = screenBitmap->Create(size, mode); |
|
137 |
|
138 if (ret != KErrNone) |
|
139 { |
|
140 User::Leave(ret); |
|
141 } |
|
142 } |
|
143 #endif // ifndef LIGHT_MODE |
|
144 |
|
145 HAL::Get(HALData::EMachineUid, iUIDValue);; |
|
146 |
|
147 //set system drive |
|
148 |
|
149 TDriveNumber defaultSysDrive(EDriveC); |
|
150 RLibrary pluginLibrary; |
|
151 TInt pluginErr = pluginLibrary.Load(KFileSrvDll); |
|
152 |
|
153 if (pluginErr == KErrNone) |
|
154 { |
|
155 typedef TDriveNumber(*fun1)(); |
|
156 fun1 sysdrive; |
|
157 |
|
158 #ifdef __EABI__ |
|
159 sysdrive = (fun1)pluginLibrary.Lookup(336); |
|
160 #else |
|
161 sysdrive = (fun1)pluginLibrary.Lookup(304); |
|
162 #endif |
|
163 if(sysdrive!=NULL) |
|
164 { |
|
165 defaultSysDrive = sysdrive(); |
|
166 } |
|
167 } |
|
168 pluginLibrary.Close(); |
|
169 |
|
170 iSystemDrive.Append(TDriveUnit(defaultSysDrive).Name()); |
|
171 iSystemDrive.Append(KFileSeparator); |
|
172 |
|
173 |
|
174 |
|
175 |
|
176 RefreshStatus( ); |
|
177 } |
|
178 |
|
179 //----------------------------------------------------------------------------------- |
|
180 //destructor |
|
181 CStatApiCommandDecoder::~CStatApiCommandDecoder() |
|
182 { |
|
183 #ifndef LIGHT_MODE |
|
184 // Clean-up objects created for screen capture. |
|
185 if(iDevice != NULL) |
|
186 { |
|
187 delete iDevice; |
|
188 } |
|
189 |
|
190 if(screenBitmap != NULL) |
|
191 { |
|
192 delete screenBitmap; |
|
193 } |
|
194 |
|
195 RFbsSession::Disconnect(); |
|
196 iWs.Close(); |
|
197 #endif // ifndef LIGHT_MODE |
|
198 } |
|
199 |
|
200 //------------------------------------------------------------------------------ |
|
201 // |
|
202 // Do whatever the user requested |
|
203 // |
|
204 TInt CStatApiCommandDecoder::ExecuteCommand(TUint commandtype, |
|
205 MDataConsumer *const aDataConsumer, MDataSupplier **aDataSupplier) |
|
206 { |
|
207 TInt ret = KErrNone; |
|
208 TInt exp = KErrNone; |
|
209 |
|
210 TInt commandLength = 0; |
|
211 |
|
212 if (aDataConsumer) |
|
213 { |
|
214 aDataConsumer->GetTotalSize(commandLength); |
|
215 pMsg->Msg (_L("DECODER: Decoding [%c] with [%d] bytes of data"), commandtype, commandLength); |
|
216 } |
|
217 else |
|
218 { |
|
219 pMsg->Msg (_L("DECODER: Decoding [%c]"), commandtype); |
|
220 } |
|
221 |
|
222 // make local copy but not for raw data (Transfer file command), Keypress or WriteTEFSharedData |
|
223 command.Zero(); |
|
224 if (commandtype != 'T' && commandtype != 'K' && commandtype != 'O' && |
|
225 aDataConsumer && commandLength) |
|
226 { |
|
227 command.Copy( *(aDataConsumer) ); |
|
228 } |
|
229 |
|
230 // Screen saver activates regardless of activity. |
|
231 // Will check for navigation and keypresses here and reset the |
|
232 // inactivity timer. |
|
233 // Ultimately, this should be handled by lower layer key |
|
234 // event processing. |
|
235 if (commandtype == 'K' || commandtype == 'L' || |
|
236 commandtype == 'M' || commandtype == 'H') |
|
237 { |
|
238 User::ResetInactivityTime(); |
|
239 } |
|
240 |
|
241 // Check if we are doing a command that depends upon the |
|
242 // window session server or the application architecture |
|
243 // (which may not be available if we are in text shell mode). |
|
244 // If there is no window server or application architecture |
|
245 // then we do not support: |
|
246 // SendText, SendSystemKey, SendCombinationKeys, |
|
247 // SendKeyHold, StopApplicationL, OpenIcon, |
|
248 // OpenFile, StartESHell, Screenshot and |
|
249 // StartApplication. |
|
250 if (commandtype == 'K' || commandtype == 'L' || |
|
251 commandtype == 'M' || commandtype == 'H' || |
|
252 commandtype == 'C' || commandtype == 'I' || |
|
253 commandtype == 'F' || commandtype == '!' || |
|
254 commandtype == 'A' || commandtype == 'S' ) |
|
255 { |
|
256 |
|
257 if( ! IsWindowServerAvailable()) |
|
258 { |
|
259 ret = KErrNotSupported; |
|
260 } |
|
261 } |
|
262 |
|
263 if(ret == KErrNone) |
|
264 { |
|
265 //check message header type |
|
266 switch (commandtype) |
|
267 { |
|
268 |
|
269 case ('K'): |
|
270 { |
|
271 if (aDataConsumer && commandLength) |
|
272 { |
|
273 ret = SendText(aDataConsumer, commandLength); |
|
274 } |
|
275 } |
|
276 break; |
|
277 case ('L'): |
|
278 ret = SendSystemKeys(); |
|
279 break; |
|
280 case ('M'): |
|
281 ret = SendCombinationKeys(); |
|
282 break; |
|
283 case ('H'): |
|
284 ret = SendKeyHold(); |
|
285 break; |
|
286 case ('A'): |
|
287 TRAP( exp, (ret = StartApplicationL()) ); |
|
288 ret = ((exp != KErrNone) ? exp : ret); |
|
289 break; |
|
290 case ('J'): |
|
291 TRAP( exp, (ret = StartProgramL(aDataSupplier)) ); |
|
292 ret = ((exp != KErrNone) ? exp : ret); |
|
293 break; |
|
294 case ('C'): |
|
295 TRAP(ret, StopApplicationL()); |
|
296 break; |
|
297 case ('F'): |
|
298 TRAP( exp, (ret = OpenFileL()) ); |
|
299 ret = ((exp != KErrNone) ? exp : ret); |
|
300 break; |
|
301 case ('I'): |
|
302 ret = OpenIcon(); |
|
303 break; |
|
304 case ('!'): |
|
305 if(command.Length() == 0) |
|
306 { |
|
307 TRAP(ret, StartEShellL()); |
|
308 } |
|
309 else |
|
310 { |
|
311 if(command == _L("!")) |
|
312 { |
|
313 TRAP(ret, StopEShellL()); |
|
314 } |
|
315 } |
|
316 break; |
|
317 case ('U'): |
|
318 TRAP( exp, ret = DeleteFileL() ); |
|
319 ret = ((exp != KErrNone) ? exp : ret); |
|
320 break; |
|
321 case ('2'): |
|
322 if(aDataConsumer) |
|
323 { |
|
324 TRAP( exp, ret = RenameFileL(aDataConsumer) ); |
|
325 ret = ((exp != KErrNone) ? exp : ret); |
|
326 } |
|
327 break; |
|
328 case ('1'): |
|
329 if(aDataConsumer) |
|
330 { |
|
331 ret = CheckLocation(aDataConsumer); |
|
332 } |
|
333 break; |
|
334 case ('Y'): |
|
335 ret = CreateFolder(); |
|
336 break; |
|
337 case ('Z'): |
|
338 ret = RemoveFolder(); |
|
339 break; |
|
340 case ('T'): |
|
341 if(aDataConsumer) |
|
342 { |
|
343 ret = TransferFile(aDataConsumer); |
|
344 } |
|
345 break; |
|
346 case ('R'): |
|
347 if(aDataConsumer) |
|
348 { |
|
349 ret = ReceiveFile(commandtype, aDataConsumer, aDataSupplier); |
|
350 } |
|
351 break; |
|
352 case ('X'): |
|
353 case ('S'): |
|
354 if(aDataConsumer) |
|
355 { |
|
356 ret = ReceiveFile(commandtype, aDataConsumer, aDataSupplier); |
|
357 } |
|
358 //DeleteLastFile(); |
|
359 break; |
|
360 case ('D'): |
|
361 ret = DeviceInfo(aDataSupplier); |
|
362 break; |
|
363 case ('G'): |
|
364 SaveLogFile(aDataSupplier); |
|
365 break; |
|
366 case ('W'): |
|
367 ret = GetDiskDriveInformationL(aDataSupplier); |
|
368 break; |
|
369 case ('V'): |
|
370 if(aDataConsumer) |
|
371 { |
|
372 ret = GetDirectoryInformationL(aDataConsumer, aDataSupplier); |
|
373 } |
|
374 break; |
|
375 case ('B'): |
|
376 RefreshStatus( ); |
|
377 break; |
|
378 case ('E'): // end of script |
|
379 break; |
|
380 case ('?'): // resync command |
|
381 break; |
|
382 case ('N'): // Retrieve TEF shared data |
|
383 TRAP( exp, ret = ReadTEFSharedDataL( aDataSupplier ) ); |
|
384 ret = ((exp != KErrNone) ? exp : ret); |
|
385 break; |
|
386 case ('O'): // Update TEF shared data |
|
387 if(aDataConsumer) |
|
388 { |
|
389 TRAP( exp, ret = WriteTEFSharedDataL(aDataConsumer, commandLength) ); |
|
390 ret = ((exp != KErrNone) ? exp : ret); |
|
391 } |
|
392 break; |
|
393 case ('|'): |
|
394 //emulator restart |
|
395 HAL::Set(HAL::ECustomRestart,1); |
|
396 break; |
|
397 case ('3'): |
|
398 TRAP( exp, (ret = ProgramStatusL(command, aDataSupplier))); |
|
399 ret = ((exp != KErrNone) ? exp : ret); |
|
400 break; |
|
401 case ('~'): |
|
402 TRAP( exp, (ret = StopProgramL(command)) ); |
|
403 ret = ((exp != KErrNone) ? exp : ret); |
|
404 break; |
|
405 |
|
406 #ifndef LIGHT_MODE |
|
407 case ('+'): // install command |
|
408 //modify the name in case doesn't contain drive |
|
409 //if the filname starts with a back slash. |
|
410 // if( command.Find(KFileSeparator)== 0 ) |
|
411 // { |
|
412 // //replace the filename with one refering to system drive |
|
413 // command.Delete(0,1); |
|
414 // command.Insert(0, iSystemDrive); |
|
415 // } |
|
416 updatePathWithSysDrive(command) ; |
|
417 ret = CAppInstall::Install(command); |
|
418 break; |
|
419 case ('-'): // uninstall command |
|
420 ret = CAppInstall::Uninstall(command); |
|
421 break; |
|
422 #endif // ifndef LIGHT_MODE |
|
423 |
|
424 default: |
|
425 ret = KErrNotSupported; |
|
426 } |
|
427 } |
|
428 |
|
429 // put the error code into the response |
|
430 if(ret != KErrNone) |
|
431 { |
|
432 if(*aDataSupplier) |
|
433 { |
|
434 (*aDataSupplier)->Delete( ); |
|
435 *aDataSupplier = NULL; |
|
436 } |
|
437 AppendErrorCode(ret, aDataSupplier); |
|
438 } |
|
439 |
|
440 return ret; |
|
441 } |
|
442 |
|
443 //------------------------------------------------------------------------------ |
|
444 // |
|
445 // Initialise our command handling status. |
|
446 // |
|
447 void CStatApiCommandDecoder::RefreshStatus(void) |
|
448 { |
|
449 iName = 1; |
|
450 } |
|
451 |
|
452 |
|
453 //------------------------------------------------------------------------------ |
|
454 // |
|
455 // Delete a file once we've finished with it |
|
456 // |
|
457 TInt CStatApiCommandDecoder::DeleteLastFile() |
|
458 { |
|
459 TInt exp = KErrNone; |
|
460 command = filename; |
|
461 TRAP( exp, DeleteFileL(FALSE) ); |
|
462 return exp; |
|
463 } |
|
464 |
|
465 |
|
466 //------------------------------------------------------------------------------ |
|
467 // Function used to decode data received and send text to an app |
|
468 // We need to avoid using 'command' buffer because we don't know |
|
469 // how big the actual data will be whereas the other commands all fit |
|
470 // easily into the 1024 length limit... |
|
471 // |
|
472 TInt CStatApiCommandDecoder::SendText( |
|
473 MDataConsumer *const aDataConsumer, int commandLength) |
|
474 { |
|
475 // Check we have a window server because it is needed by |
|
476 // DoKeyEvent. |
|
477 // If this assert triggers it is because we are running in |
|
478 // text shell mode without a window server and the call |
|
479 // requires the window server to be available. |
|
480 // A command filter in ExecuteCommand should have prevented |
|
481 // this call from being made. |
|
482 assert(IsWindowServerAvailable()); |
|
483 |
|
484 TInt err = KErrNone; |
|
485 TInt i = 0; |
|
486 |
|
487 HBufC8 *keyData = HBufC8::New( commandLength ); |
|
488 |
|
489 if( ! keyData ) |
|
490 { |
|
491 err = KErrNoMemory; |
|
492 } |
|
493 |
|
494 if( err == KErrNone ) |
|
495 { |
|
496 err = aDataConsumer->GetData( *keyData ); |
|
497 } |
|
498 |
|
499 if( err == KErrNone ) |
|
500 { |
|
501 TBuf16<1> x; |
|
502 |
|
503 for(i=0;i<commandLength;i++) |
|
504 { |
|
505 x.Zero(); |
|
506 x.Append((*keyData)[i]); |
|
507 DoKeyEvent(static_cast<TInt>(x[0])); |
|
508 |
|
509 // Do not delay this thread for any time but simply |
|
510 // give up the rest of our time-slice to allow |
|
511 // the system to process the key event. |
|
512 User::After(0); |
|
513 } |
|
514 |
|
515 // Yield here to give the OS time to actually complete this command. |
|
516 User::After(0); |
|
517 } |
|
518 |
|
519 if( keyData ) |
|
520 { |
|
521 delete keyData; |
|
522 keyData = NULL; |
|
523 } |
|
524 |
|
525 return (err); |
|
526 } |
|
527 |
|
528 |
|
529 //------------------------------------------------------------------------------ |
|
530 // |
|
531 //Function used to decode data received and send system keys to an app (ie - Menu, LeftArrow etc) |
|
532 // |
|
533 |
|
534 TInt CStatApiCommandDecoder::SendSystemKeys() |
|
535 { |
|
536 #ifndef LIGHT_MODE |
|
537 // If this assert triggers it is because we are running in |
|
538 // text shell mode without a window server and the call |
|
539 // requires the window server to be available. |
|
540 // A command filter in ExecuteCommand should have prevented |
|
541 // this call from being made. |
|
542 assert(IsWindowServerAvailable()); |
|
543 |
|
544 TInt ret = KErrArgument; |
|
545 TInt i = 0; |
|
546 TBuf<140> scancodevalue = ENUM_TEXTSCANCODEArray[i]; //scancode strings stored here |
|
547 TBuf<100> keycodevalue = ENUM_TEXTKEYArray[i]; //keycode strings entered here |
|
548 |
|
549 // look for correct system command from scancodes first |
|
550 while (scancodevalue.Compare(TPtrC(NO_MORE_SCANCODEKEYS)) != 0) |
|
551 { |
|
552 if (command.Compare(scancodevalue) == 0) |
|
553 { |
|
554 //send using SimulateRawEvent... |
|
555 TRawEvent rawEventa; |
|
556 rawEventa.Set(TRawEvent::EKeyDown, ENUM_VALSCANCODEArray[i]); |
|
557 iWs.SimulateRawEvent(rawEventa); |
|
558 iWs.Flush(); |
|
559 |
|
560 rawEventa.Set(TRawEvent::EKeyUp, ENUM_VALSCANCODEArray[i]); |
|
561 iWs.SimulateRawEvent(rawEventa); |
|
562 iWs.Flush(); |
|
563 |
|
564 ret = KErrNone; |
|
565 break; |
|
566 } |
|
567 |
|
568 i++; |
|
569 scancodevalue = ENUM_TEXTSCANCODEArray[i]; |
|
570 } |
|
571 |
|
572 //if there is no scancode then now try the remaining key codes... |
|
573 if(ret != KErrNone) |
|
574 { |
|
575 i = 0; //reinitialise |
|
576 |
|
577 while (keycodevalue.Compare(TPtrC(NO_MORE_KEYS)) != 0) |
|
578 { |
|
579 if (command.Compare(keycodevalue) == 0) |
|
580 { |
|
581 // set the event |
|
582 DoKeyEvent(ENUM_VALKEYArray[i]); |
|
583 ret = KErrNone; |
|
584 break; |
|
585 } |
|
586 |
|
587 i++; |
|
588 keycodevalue = ENUM_TEXTKEYArray[i]; |
|
589 } |
|
590 } |
|
591 |
|
592 return (ret); |
|
593 #else // ifndef LIGHT_MODE |
|
594 return (KErrNotSupported); |
|
595 #endif // ifndef LIGHT_MODE |
|
596 } |
|
597 |
|
598 |
|
599 //------------------------------------------------------------------------------ |
|
600 // |
|
601 //Function used to decode data received and send combination keys to the device (ie - Ctrl+S) |
|
602 // |
|
603 |
|
604 TInt CStatApiCommandDecoder::SendCombinationKeys() |
|
605 { |
|
606 #ifndef LIGHT_MODE |
|
607 // If this assert triggers it is because we are running in |
|
608 // text shell mode without a window server and the call |
|
609 // requires the window server to be available. |
|
610 // A command filter in ExecuteCommand should have prevented |
|
611 // this call from being made. |
|
612 assert(IsWindowServerAvailable()); |
|
613 |
|
614 TInt plusposition = 0; //used for combination key data |
|
615 TInt i = 0; |
|
616 TInt counter = 0; |
|
617 TInt index = 0; |
|
618 |
|
619 TBuf<100> input = _L(""); |
|
620 |
|
621 TBuf<20> myModifierKey[4]; //there are 4 maximum combination keys that can be used for one command - they will be stored here |
|
622 |
|
623 TKeyEvent event; //the key event structure |
|
624 TEventModifier em[5]; //modifier keys required for each of the modifiers available (shift, ctrl, func) |
|
625 TKeyCode kp = EKeyNull; |
|
626 |
|
627 //*****Initialisation section***** |
|
628 |
|
629 int a = 0; |
|
630 for (a=0;a<4;a++) |
|
631 { |
|
632 myModifierKey[a] = _L(""); |
|
633 myModifierKey[a].SetLength(0); |
|
634 } |
|
635 |
|
636 int b = 0; |
|
637 for (b=0;b<5;b++) |
|
638 { |
|
639 em[b] = (TEventModifier)0; |
|
640 } |
|
641 |
|
642 //******************************** |
|
643 |
|
644 TInt DataLength = command.Length(); //copy passed data length into local variable |
|
645 |
|
646 //The following section splits the data up and puts them into the array |
|
647 while ((DataLength >= 1) && (counter <= 4)) //while length > 1 |
|
648 { |
|
649 plusposition = command.Locate('+'); //search for this char |
|
650 |
|
651 if (plusposition != KErrNotFound) |
|
652 { |
|
653 myModifierKey[counter] = command.Left(plusposition); //chars left of plus are stored |
|
654 command.Delete(0, (plusposition + 1)); //delete all chars from pos 0 up to and including '+' with null terminator |
|
655 counter++; |
|
656 } |
|
657 else //no more '+' in string |
|
658 { |
|
659 myModifierKey[counter] = command.Left(command.Length());//store remaining string into array |
|
660 command.Delete(0, plusposition + 1); //delete remaining string |
|
661 counter = 5; //make sure exits |
|
662 } |
|
663 } |
|
664 |
|
665 counter = 0; |
|
666 event.iCode = 0; |
|
667 event.iScanCode = 0; |
|
668 event.iRepeats = 0; |
|
669 event.iModifiers = 0; //initialisation |
|
670 |
|
671 //now check the new data in each of the elements in the array |
|
672 while (counter <= 4) |
|
673 { |
|
674 input = myModifierKey[counter]; //assign value from string |
|
675 |
|
676 if (input == _L("Ctrl") || input == _L("LeftCtrl") || input == _L("RightCtrl") |
|
677 || input == _L("Shift") || input == _L("LeftShift") || input == _L("RightShift") |
|
678 || input == _L("Func") || input == _L("LeftFunc") || input == _L("RightFunc") |
|
679 || input == _L("Alt") || input == _L("LeftAlt") || input == _L("RightAlt")) |
|
680 { |
|
681 TBuf<100> value; |
|
682 value = ENUM_TEXTMODIFIERSArray[i]; //assign initial data in array to value (element 0) |
|
683 |
|
684 while (value.Compare(TPtrC(NO_MORE_MODIFIERKEYS)) != 0) //make sure not end of array |
|
685 { |
|
686 if (input.Compare(value) == 0) //if the string has been found in the text array |
|
687 { |
|
688 em[counter] = ENUM_VALMODIFIERSArray[i]; //assign em element with the same value from the val array by comparing counter num (location) |
|
689 i = 0; //reinitialise so that the search can restart at the beginning of the enumerated type list |
|
690 break; |
|
691 } |
|
692 |
|
693 i++; |
|
694 value = ENUM_TEXTMODIFIERSArray[i]; //update contents of value for the next pass |
|
695 } //end while |
|
696 } |
|
697 else //no combination keys left |
|
698 { |
|
699 if (input.Length() > 1) //if the remaining data is longer than 1 char (ie - could be 'LeftArrow') |
|
700 { |
|
701 TBuf<100> valuekey; |
|
702 valuekey = ENUM_TEXTKEYArray[i]; //assign initial data in array to value (element 0) |
|
703 |
|
704 while (valuekey.Compare(TPtrC(NO_MORE_KEYS)) != 0) //make sure not end of array |
|
705 { |
|
706 if (input.Compare(valuekey) == 0) //if the string has been found in the text array |
|
707 { |
|
708 //kp.iScanCode = ENUM_VALKEYArray[i]; |
|
709 kp = ENUM_VALKEYArray[i]; //assign kp with the same value from the val array |
|
710 |
|
711 if(kp < ENonCharacterKeyBase) |
|
712 { |
|
713 event.iCode = kp; |
|
714 em[2] = EModifierPureKeycode; |
|
715 index = 3; |
|
716 counter = 5; |
|
717 } |
|
718 else |
|
719 { |
|
720 event.iCode = kp; |
|
721 index = 3; |
|
722 counter = 5; |
|
723 } |
|
724 |
|
725 break; |
|
726 |
|
727 } //end if |
|
728 |
|
729 i++; |
|
730 valuekey = ENUM_TEXTKEYArray[i]; //update contents of value for the next pass |
|
731 } |
|
732 } |
|
733 else //must be single char combination, so pass into iCode and set counter to four to exit! |
|
734 { |
|
735 input.LowerCase(); |
|
736 |
|
737 while (index < 3) //need to check array and see if need to send CTRL or not |
|
738 { |
|
739 if ((em[index] == EModifierLeftCtrl) || (em[index] == EModifierRightCtrl) || (em[index] == EModifierCtrl)) |
|
740 { |
|
741 event.iCode = CTRLA(input.Ptr()[0]); |
|
742 counter = 4; |
|
743 break; |
|
744 } |
|
745 else |
|
746 { |
|
747 event.iCode = input.Ptr()[0]; |
|
748 index++; |
|
749 counter = 4; |
|
750 } |
|
751 } |
|
752 } |
|
753 |
|
754 event.iModifiers = em[0] | em[1] | em[2]; //used to set up Ctrl+Shift+...etc |
|
755 |
|
756 } //end else |
|
757 |
|
758 counter++; |
|
759 input = _L(""); //reinitialise for next pass |
|
760 |
|
761 } //end while |
|
762 |
|
763 |
|
764 iWs.SimulateKeyEvent(event); // send keystroke |
|
765 iWs.Flush(); // flush client-side window server buffer |
|
766 |
|
767 return KErrNone; |
|
768 #else // ifndef LIGHT_MODE |
|
769 return (KErrNotSupported); |
|
770 #endif // ifndef LIGHT_MODE |
|
771 } |
|
772 |
|
773 //////////////////////////////////////////////////////////////////////////////////////////// |
|
774 // |
|
775 //Function used to hold down keys |
|
776 // |
|
777 //////////////////////////////////////////////////////////////////////////////////////////// |
|
778 TInt CStatApiCommandDecoder::ConvertKeycodeToScancode( TDesC& key, TInt& scancode, TInt& modifiers ) |
|
779 { |
|
780 TInt i, j; |
|
781 TBuf<20> base_punctuation( _L("`,./\\;'#[]-=/*-") ); |
|
782 TBuf<20> shift_punctuation( _L("?>?|:@~{}_+XX_") ); |
|
783 TBuf<20> numeric_punctuation( _L(")!\"?%^&*(") ); |
|
784 |
|
785 // clear the modifiers field |
|
786 modifiers = 0; |
|
787 |
|
788 // make sure the key is not completely empty |
|
789 if( key.Length() == 0 ) { |
|
790 return -1; |
|
791 } |
|
792 |
|
793 // If the key is longer than one char then it must be a special key that we need to |
|
794 // lookup in the table. If it's not in the table then return error |
|
795 if( key.Length() > 1 ) { |
|
796 for( i = 0; ENUM_TEXTSCANCODEArray[i] != NO_MORE_SCANCODEKEYS; i++ ) { |
|
797 if( key.Compare(TPtrC(ENUM_TEXTSCANCODEArray[i])) == 0 ) { |
|
798 scancode = ENUM_VALSCANCODEArray[i]; |
|
799 return 0; |
|
800 } |
|
801 } |
|
802 return -1; |
|
803 } |
|
804 |
|
805 // get the first key (saves getting it heaps of times) |
|
806 TChar keycode( key.Ptr()[0] ); |
|
807 |
|
808 // handle lowercase alpha characters |
|
809 if( keycode.IsAlpha() && keycode.IsLower() ) { |
|
810 keycode.UpperCase(); |
|
811 scancode = keycode; |
|
812 return 0; |
|
813 } |
|
814 |
|
815 // handle uppercase alpha characters |
|
816 if( keycode.IsAlpha() && keycode.IsUpper() ) { |
|
817 scancode = keycode; |
|
818 modifiers = ESMLShift; |
|
819 return 0; |
|
820 } |
|
821 |
|
822 // handle numbers |
|
823 if( keycode.IsDigit() ) { |
|
824 scancode = keycode; |
|
825 return 0; |
|
826 } |
|
827 |
|
828 // handle punctuation -- just offset by 36 for some unknown reason |
|
829 if( keycode.IsPunctuation() ) { |
|
830 |
|
831 j = base_punctuation.Locate( keycode ); |
|
832 if( j != KErrNotFound ) { |
|
833 scancode = 120 + j; |
|
834 return 0; |
|
835 } |
|
836 |
|
837 j = shift_punctuation.Locate( keycode ); |
|
838 if( j != KErrNotFound ) { |
|
839 scancode = 120 + j; |
|
840 modifiers = ESMLShift; |
|
841 return 0; |
|
842 } |
|
843 |
|
844 j = numeric_punctuation.Locate( keycode ); |
|
845 if( j != KErrNotFound ) { |
|
846 scancode = '0' + j; |
|
847 modifiers = ESMLShift; |
|
848 return 0; |
|
849 } |
|
850 |
|
851 scancode = keycode; |
|
852 return 0; |
|
853 } |
|
854 |
|
855 // For some reason certain characters are not recognized as punctuation though they |
|
856 // should be. These are handled specifically here. |
|
857 bool found = false; |
|
858 switch( keycode ) { |
|
859 |
|
860 case 0x24: |
|
861 scancode = 0x34; |
|
862 modifiers = ESMLShift; |
|
863 found = true; |
|
864 break; |
|
865 |
|
866 case 0xa3: |
|
867 scancode = 0x33; |
|
868 modifiers = ESMLShift; |
|
869 found = true; |
|
870 break; |
|
871 |
|
872 case 0x80: |
|
873 scancode = 0x34; |
|
874 // modifiers = ESMRFunc | ESMLCtrl; |
|
875 modifiers = ESMRAlt; |
|
876 found = true; |
|
877 break; |
|
878 |
|
879 case 0xa6: |
|
880 scancode = 0x78; |
|
881 modifiers = ESMRFunc; |
|
882 found = true; |
|
883 break; |
|
884 } |
|
885 |
|
886 if (found) |
|
887 return 0; |
|
888 else |
|
889 // key not found |
|
890 return -1; |
|
891 } |
|
892 |
|
893 TInt CStatApiCommandDecoder::SendKeyHold() |
|
894 { |
|
895 #ifndef LIGHT_MODE |
|
896 // If this assert triggers it is because we are running in |
|
897 // text shell mode without a window server and the call |
|
898 // requires the window server to be available. |
|
899 // A command filter in ExecuteCommand should have prevented |
|
900 // this call from being made. |
|
901 assert(IsWindowServerAvailable()); |
|
902 |
|
903 TLex Lexcounter; |
|
904 TInt key_action = 0; |
|
905 TRawEvent rawEventa; |
|
906 TInt scancodefound; |
|
907 TInt scancode; |
|
908 TInt modifiers; |
|
909 |
|
910 // H commands must have the format <HC,N> where 'C' is the command to be executed and |
|
911 // N is either -1 (key up) or 0 (key down) |
|
912 TInt commaposition = command.Locate(','); |
|
913 if( commaposition == KErrNotFound ) { |
|
914 return KErrArgument; |
|
915 } |
|
916 |
|
917 // convert the key action from a string to an integer |
|
918 Lexcounter = command.Mid( commaposition + 1 ); |
|
919 Lexcounter.Val( key_action ); |
|
920 |
|
921 // get the scancode for the key |
|
922 command.SetLength( commaposition ); |
|
923 scancodefound = ConvertKeycodeToScancode( command, scancode, modifiers ); |
|
924 if( scancodefound == -1 ) { |
|
925 return KErrArgument; |
|
926 } |
|
927 |
|
928 // set the appropriate modifier keys |
|
929 if( modifiers & ESMLShift ) { |
|
930 rawEventa.Set(TRawEvent::EKeyDown, EStdKeyLeftShift); |
|
931 iWs.SimulateRawEvent(rawEventa); |
|
932 iWs.Flush(); |
|
933 } |
|
934 if( modifiers & ESMRFunc ) { |
|
935 rawEventa.Set(TRawEvent::EKeyDown, EStdKeyRightFunc); |
|
936 iWs.SimulateRawEvent(rawEventa); |
|
937 iWs.Flush(); |
|
938 } |
|
939 if( modifiers & ESMRAlt ) { |
|
940 rawEventa.Set(TRawEvent::EKeyDown, EStdKeyRightAlt); |
|
941 iWs.SimulateRawEvent(rawEventa); |
|
942 iWs.Flush(); |
|
943 } |
|
944 if( modifiers & ESMLCtrl ) { |
|
945 rawEventa.Set(TRawEvent::EKeyDown, EStdKeyLeftCtrl); |
|
946 iWs.SimulateRawEvent(rawEventa); |
|
947 iWs.Flush(); |
|
948 } |
|
949 |
|
950 // now handle the key_action -1 == key_up, 0 == key_down, > 0 == milliseconds to hold the key down |
|
951 switch( key_action ) { |
|
952 |
|
953 case -1: |
|
954 rawEventa.Set(TRawEvent::EKeyUp, scancode); |
|
955 iWs.SimulateRawEvent(rawEventa); |
|
956 iWs.Flush(); |
|
957 break; |
|
958 |
|
959 case 0: |
|
960 rawEventa.Set(TRawEvent::EKeyDown, scancode); |
|
961 iWs.SimulateRawEvent(rawEventa); |
|
962 iWs.Flush(); |
|
963 break; |
|
964 |
|
965 default: |
|
966 rawEventa.Set(TRawEvent::EKeyDown, scancode); |
|
967 iWs.SimulateRawEvent(rawEventa); |
|
968 iWs.Flush(); |
|
969 |
|
970 key_action *= 1000; |
|
971 User::After(TTimeIntervalMicroSeconds32(key_action)); |
|
972 |
|
973 rawEventa.Set(TRawEvent::EKeyUp, scancode); |
|
974 iWs.SimulateRawEvent(rawEventa); |
|
975 iWs.Flush(); |
|
976 break; |
|
977 } |
|
978 |
|
979 // release appropriate function keys |
|
980 if( modifiers & ESMLShift ) { |
|
981 rawEventa.Set(TRawEvent::EKeyUp, EStdKeyLeftShift); |
|
982 iWs.SimulateRawEvent(rawEventa); |
|
983 iWs.Flush(); |
|
984 } |
|
985 if( modifiers & ESMRFunc ) { |
|
986 rawEventa.Set(TRawEvent::EKeyUp, EStdKeyRightFunc); |
|
987 iWs.SimulateRawEvent(rawEventa); |
|
988 iWs.Flush(); |
|
989 } |
|
990 if( modifiers & ESMRAlt ) { |
|
991 rawEventa.Set(TRawEvent::EKeyUp, EStdKeyRightAlt); |
|
992 iWs.SimulateRawEvent(rawEventa); |
|
993 iWs.Flush(); |
|
994 } |
|
995 if( modifiers & ESMLCtrl ) { |
|
996 rawEventa.Set(TRawEvent::EKeyUp, EStdKeyLeftCtrl); |
|
997 iWs.SimulateRawEvent(rawEventa); |
|
998 iWs.Flush(); |
|
999 } |
|
1000 |
|
1001 return KErrNone; |
|
1002 #else // ifndef LIGHT_MODE |
|
1003 return (KErrNotSupported); |
|
1004 #endif // ifndef LIGHT_MODE |
|
1005 } |
|
1006 |
|
1007 |
|
1008 //------------------------------------------------------------------------------ |
|
1009 // |
|
1010 //Function used to start application(s) |
|
1011 // |
|
1012 TInt CStatApiCommandDecoder::StartApplicationL() |
|
1013 { |
|
1014 #ifndef LIGHT_MODE |
|
1015 // If this assert triggers it is because we are running in |
|
1016 // text shell mode without a window server and the call |
|
1017 // requires the window server to be available. |
|
1018 // A command filter in ExecuteCommand should have prevented |
|
1019 // this call from being made. |
|
1020 assert(IsWindowServerAvailable()); |
|
1021 |
|
1022 TInt ret = KErrNone; |
|
1023 |
|
1024 TBuf<KMaxFileName> docName; |
|
1025 CApaCommandLine* cmdLine = CApaCommandLine::NewLC(); |
|
1026 |
|
1027 TInt commaposition = command.Locate(','); |
|
1028 if (commaposition != KErrNotFound) |
|
1029 { |
|
1030 // set the application name |
|
1031 cmdLine -> SetExecutableNameL(command.Mid(0, commaposition)); |
|
1032 |
|
1033 // use document name supplied in command string |
|
1034 docName = command.Mid(commaposition + 1); |
|
1035 } |
|
1036 else |
|
1037 { |
|
1038 TBuf<10> timestring; |
|
1039 TTime DateAndTime; |
|
1040 DateAndTime.HomeTime(); |
|
1041 DateAndTime.FormatL(timestring, (_L("%J%T%S%*B"))); |
|
1042 |
|
1043 // create a default document name based on the system date and time |
|
1044 |
|
1045 docName.Append(iSystemDrive); |
|
1046 docName.Append(timestring); |
|
1047 |
|
1048 // set the application name |
|
1049 cmdLine -> SetExecutableNameL(command); |
|
1050 } |
|
1051 |
|
1052 cmdLine -> SetDocumentNameL(docName); |
|
1053 cmdLine -> SetCommandL(EApaCommandCreate); |
|
1054 |
|
1055 if( ret == KErrNone ) |
|
1056 { |
|
1057 //initialise |
|
1058 ret = iApaS.Connect(); |
|
1059 if(ret != KErrNone) |
|
1060 pMsg->Msg (_L("DECODER: Application Architecture server error [%c]"), ret); |
|
1061 } |
|
1062 |
|
1063 if( ret == KErrNone ) |
|
1064 { |
|
1065 // startup |
|
1066 ret = iApaS.StartApp(*cmdLine); |
|
1067 if(ret != KErrNone) |
|
1068 pMsg->Msg (_L("DECODER: Unable to start application [%c]"), ret); |
|
1069 } |
|
1070 |
|
1071 //cleanup |
|
1072 iApaS.Close(); |
|
1073 CleanupStack::PopAndDestroy(); |
|
1074 |
|
1075 if( ret == KErrNone ) |
|
1076 { |
|
1077 // need to sleep a bit here to give the OS time to actually start the application |
|
1078 User::After(3000000); |
|
1079 } |
|
1080 |
|
1081 return (ret); |
|
1082 #else // ifndef LIGHT_MODE |
|
1083 return (KErrNotSupported); |
|
1084 #endif // ifndef LIGHT_MODE |
|
1085 } |
|
1086 |
|
1087 //------------------------------------------------------------------------------ |
|
1088 // |
|
1089 //Function used to start executables(s) |
|
1090 // |
|
1091 TInt CStatApiCommandDecoder::StartProgramL(MDataSupplier **aDataSupplier) |
|
1092 { |
|
1093 TInt ret = KErrNone; |
|
1094 |
|
1095 TBuf<KMaxFileName> programName; |
|
1096 TBuf<KMaxFileName> parameters; |
|
1097 |
|
1098 TInt commaposition = command.Locate(','); |
|
1099 if (commaposition != KErrNotFound) |
|
1100 { |
|
1101 // set the program name |
|
1102 programName = command.Mid(0, commaposition); |
|
1103 |
|
1104 // set the parameters |
|
1105 parameters = command.Mid(commaposition + 1); |
|
1106 } |
|
1107 else |
|
1108 { |
|
1109 programName = command; |
|
1110 } |
|
1111 |
|
1112 updatePathWithSysDrive(programName) ; |
|
1113 updatePathWithSysDrive(parameters) ; |
|
1114 RProcess newProcess; |
|
1115 ret = newProcess.Create(programName,parameters); |
|
1116 |
|
1117 if(ret == KErrNone) |
|
1118 { |
|
1119 |
|
1120 TProcessId handle = newProcess.Id(); |
|
1121 |
|
1122 if(ret == KErrNone) |
|
1123 { |
|
1124 newProcess.Resume(); |
|
1125 newProcess.Close(); // get rid of our handle |
|
1126 } |
|
1127 |
|
1128 // Return the PID |
|
1129 |
|
1130 CDataSupplierMemory *pDataSupplier = CDataSupplierMemory::NewL( ); |
|
1131 |
|
1132 TBuf8<50> handleNumber; |
|
1133 |
|
1134 handleNumber.Num(handle.Id()); |
|
1135 |
|
1136 TInt err; |
|
1137 |
|
1138 if (pDataSupplier) |
|
1139 { |
|
1140 // Set the data in the data supplier. |
|
1141 err = pDataSupplier->SetData( handleNumber ); |
|
1142 |
|
1143 if (err != KErrNone) |
|
1144 { |
|
1145 pMsg->Msg(_L("Failed to set data in data supplier") ); |
|
1146 } |
|
1147 } |
|
1148 else |
|
1149 { |
|
1150 err = KErrNoMemory; |
|
1151 pMsg->Msg(_L("Failed to create data supply object") ); |
|
1152 } |
|
1153 |
|
1154 if (err == KErrNone) |
|
1155 { |
|
1156 *aDataSupplier = pDataSupplier; |
|
1157 } |
|
1158 else |
|
1159 { |
|
1160 if (pDataSupplier) |
|
1161 { |
|
1162 pDataSupplier->Delete( ); |
|
1163 pDataSupplier = NULL; |
|
1164 } |
|
1165 } |
|
1166 } |
|
1167 |
|
1168 return ret; |
|
1169 } |
|
1170 |
|
1171 //------------------------------------------------------------------------------ |
|
1172 // |
|
1173 //Function used to close application in foreground |
|
1174 // |
|
1175 void CStatApiCommandDecoder::StopApplicationL() |
|
1176 { |
|
1177 #ifndef LIGHT_MODE |
|
1178 // If this assert triggers it is because we are running in |
|
1179 // text shell mode without a window server and the call |
|
1180 // requires the window server to be available. |
|
1181 // A command filter in ExecuteCommand should have prevented |
|
1182 // this call from being made. |
|
1183 assert(IsWindowServerAvailable()); |
|
1184 |
|
1185 TInt AppIdentifier = 0; |
|
1186 TThreadId ThreadIdentifier; |
|
1187 |
|
1188 AppIdentifier = iWs.GetFocusWindowGroup(); //retrieves identifier of the window group that currently has the keyboard focus |
|
1189 |
|
1190 TInt ret = iWs.GetWindowGroupClientThreadId(AppIdentifier, ThreadIdentifier); |
|
1191 if(ret == KErrNone) |
|
1192 { |
|
1193 TInt prev = 0; |
|
1194 TInt winGid = iWs.FindWindowGroupIdentifier(prev, ThreadIdentifier); //Get identifier by thread ID |
|
1195 |
|
1196 TApaTask task(iWs); |
|
1197 task.SetWgId(winGid); |
|
1198 |
|
1199 if (task.Exists()) |
|
1200 { |
|
1201 CApaWindowGroupName* wgName = CApaWindowGroupName::NewLC(iWs, winGid); |
|
1202 |
|
1203 // check if application is busy |
|
1204 if (wgName -> IsSystem() || wgName -> IsBusy() || !wgName -> RespondsToShutdownEvent()) |
|
1205 ret = KErrAccessDenied; |
|
1206 |
|
1207 CleanupStack::PopAndDestroy(); // wgName |
|
1208 |
|
1209 if(ret == KErrNone) |
|
1210 task.SendSystemEvent(EApaSystemEventShutdown); //close app |
|
1211 } |
|
1212 else |
|
1213 { |
|
1214 ret = KErrNotFound; //return error if task is non-existent |
|
1215 } |
|
1216 } |
|
1217 |
|
1218 User::Leave(ret); |
|
1219 #endif // ifndef LIGHT_MODE |
|
1220 } |
|
1221 |
|
1222 // |
|
1223 //Function used to close application in foreground |
|
1224 // |
|
1225 void CStatApiCommandDecoder::StopEShellL() |
|
1226 { |
|
1227 #ifndef LIGHT_MODE |
|
1228 // If this assert triggers it is because we are running in |
|
1229 // text shell mode without a window server and the call |
|
1230 // requires the window server to be available. |
|
1231 // A command filter in ExecuteCommand should have prevented |
|
1232 // this call from being made. |
|
1233 assert(IsWindowServerAvailable()); |
|
1234 |
|
1235 TInt AppIdentifier = 0; |
|
1236 TThreadId ThreadIdentifier; |
|
1237 |
|
1238 AppIdentifier = iWs.GetFocusWindowGroup(); //retrieves identifier of the window group that currently has the keyboard focus |
|
1239 |
|
1240 TInt ret = iWs.GetWindowGroupClientThreadId(AppIdentifier, ThreadIdentifier); |
|
1241 if(ret == KErrNone) |
|
1242 { |
|
1243 TInt prev = 0; |
|
1244 TInt winGid = iWs.FindWindowGroupIdentifier(prev, ThreadIdentifier); //Get identifier by thread ID |
|
1245 |
|
1246 TApaTask task(iWs); |
|
1247 task.SetWgId(winGid); |
|
1248 |
|
1249 if (task.Exists()) |
|
1250 { |
|
1251 CApaWindowGroupName* wgName = CApaWindowGroupName::NewLC(iWs, winGid); |
|
1252 |
|
1253 // check if application is busy |
|
1254 if (wgName -> IsSystem()) |
|
1255 ret = KErrAccessDenied; |
|
1256 else |
|
1257 { |
|
1258 RThread newThread; |
|
1259 RProcess newProcess; |
|
1260 |
|
1261 ret = newThread.Open(ThreadIdentifier); |
|
1262 if(ret == KErrNone) |
|
1263 { |
|
1264 ret = newThread.Process(newProcess); |
|
1265 if(ret == KErrNone) |
|
1266 { |
|
1267 if(newProcess.FileName().Right(10).CompareF(_L("eshell.exe")) == 0) |
|
1268 { |
|
1269 newProcess.Kill(1); |
|
1270 } |
|
1271 else |
|
1272 { |
|
1273 ret = KErrNotFound; |
|
1274 } |
|
1275 newProcess.Close(); |
|
1276 } |
|
1277 newThread.Close(); |
|
1278 } |
|
1279 } |
|
1280 |
|
1281 CleanupStack::PopAndDestroy(); // wgName |
|
1282 } |
|
1283 else |
|
1284 { |
|
1285 ret = KErrNotFound; //return error if task is non-existent |
|
1286 } |
|
1287 } |
|
1288 |
|
1289 User::Leave(ret); |
|
1290 #endif // ifndef LIGHT_MODE |
|
1291 } |
|
1292 |
|
1293 //------------------------------------------------------------------------------ |
|
1294 // |
|
1295 //Function used to read some TEF shared data |
|
1296 // |
|
1297 |
|
1298 TInt CStatApiCommandDecoder::ReadTEFSharedDataL( MDataSupplier **aDataSupplier ) |
|
1299 { |
|
1300 TInt ret = KErrNone; |
|
1301 |
|
1302 TBuf<KMaxSharedDataName> sharedDataName; |
|
1303 |
|
1304 // Set the shared data name |
|
1305 TInt length = command.Length(); |
|
1306 if( length > 0 && length < KMaxSharedDataName ) |
|
1307 { |
|
1308 sharedDataName.Zero(); |
|
1309 sharedDataName.Copy( command ); |
|
1310 sharedDataName.ZeroTerminate(); |
|
1311 } |
|
1312 else |
|
1313 { |
|
1314 ret = KErrArgument; |
|
1315 } |
|
1316 |
|
1317 // Now read the shared data area |
|
1318 if( ret == KErrNone ) |
|
1319 { |
|
1320 // Read the shared data from the global RChunk |
|
1321 HBufC* buffer = NULL; |
|
1322 CTestSharedData* sharedDataObject = NULL; |
|
1323 CTEFSharedData<CTestSharedData> *tefSharedData = CTEFSharedData<CTestSharedData>::NewLC( sharedDataObject, |
|
1324 sharedDataName ); |
|
1325 if( sharedDataObject != NULL ) |
|
1326 { |
|
1327 tefSharedData->EnterCriticalSection(); |
|
1328 TRAP( ret, buffer = HBufC::NewL(sharedDataObject->TextLength()) ); |
|
1329 if( ret == KErrNone ) |
|
1330 { |
|
1331 TPtr bufferPtr( buffer->Des() ); |
|
1332 sharedDataObject->GetText( bufferPtr ); |
|
1333 tefSharedData->ExitCriticalSection(); |
|
1334 |
|
1335 // Create the response data supplier |
|
1336 CDataSupplierMemory *pDataSupplier = NULL; |
|
1337 TRAP( ret, pDataSupplier = CDataSupplierMemory::NewL() ); |
|
1338 if( pDataSupplier && ret == KErrNone ) |
|
1339 { |
|
1340 HBufC8 *buffer8 = NULL; |
|
1341 TRAP( ret, buffer8 = HBufC8::NewL(buffer->Length()) ); |
|
1342 if( ret == KErrNone ) |
|
1343 { |
|
1344 TPtr8 buffer8Ptr( buffer8->Des() ); |
|
1345 buffer8Ptr.Copy( buffer->Des() ); |
|
1346 |
|
1347 // Set the data in the data supplier. |
|
1348 ret = pDataSupplier->SetData( *buffer8 ); |
|
1349 |
|
1350 // Cleanup |
|
1351 delete buffer8; |
|
1352 } |
|
1353 |
|
1354 if( ret != KErrNone ) |
|
1355 { |
|
1356 pMsg->Msg(_L("Failed to set data in data supplier") ); |
|
1357 } |
|
1358 } |
|
1359 else |
|
1360 { |
|
1361 ret = KErrNoMemory; |
|
1362 pMsg->Msg(_L("Failed to create data supply object") ); |
|
1363 } |
|
1364 |
|
1365 if (ret == KErrNone) |
|
1366 { |
|
1367 *aDataSupplier = pDataSupplier; |
|
1368 } |
|
1369 else |
|
1370 { |
|
1371 if (pDataSupplier) |
|
1372 { |
|
1373 pDataSupplier->Delete( ); |
|
1374 pDataSupplier = NULL; |
|
1375 } |
|
1376 } |
|
1377 } |
|
1378 |
|
1379 delete buffer; |
|
1380 } |
|
1381 else |
|
1382 { |
|
1383 ret = KErrNotFound; |
|
1384 } |
|
1385 CleanupStack::PopAndDestroy(tefSharedData); |
|
1386 } |
|
1387 |
|
1388 return ret; |
|
1389 } |
|
1390 |
|
1391 //------------------------------------------------------------------------------ |
|
1392 // |
|
1393 //Function used to write some TEF shared data |
|
1394 // |
|
1395 |
|
1396 TInt CStatApiCommandDecoder::WriteTEFSharedDataL( MDataConsumer *const aDataConsumer, int commandLength ) |
|
1397 { |
|
1398 TInt ret = KErrNone; |
|
1399 |
|
1400 // Retrieve the data |
|
1401 if( commandLength <= KMaxSharedDataString ) |
|
1402 { |
|
1403 HBufC8* sharedDataString = HBufC8::NewLC( commandLength ); |
|
1404 if( aDataConsumer != NULL ) |
|
1405 { |
|
1406 ret = aDataConsumer->GetData( *sharedDataString ); |
|
1407 |
|
1408 // Set the shared data name |
|
1409 if( ret == KErrNone ) |
|
1410 { |
|
1411 TBuf<KMaxSharedDataName> sharedDataName; |
|
1412 TInt commaposition = sharedDataString->Locate(','); |
|
1413 if( commaposition != KErrNotFound ) |
|
1414 { |
|
1415 if( commaposition < KMaxSharedDataName ) |
|
1416 { |
|
1417 sharedDataName.Zero(); |
|
1418 sharedDataName.Copy(sharedDataString->Mid(0, commaposition)); |
|
1419 sharedDataName.ZeroTerminate(); |
|
1420 |
|
1421 // Set the shared data value |
|
1422 HBufC* sharedDataValue = HBufC::NewLC(commandLength-commaposition+1); |
|
1423 TPtr ptrSharedDataValue(sharedDataValue->Des()); |
|
1424 ptrSharedDataValue.Zero(); |
|
1425 ptrSharedDataValue.Copy(sharedDataString->Mid(commaposition+1)); |
|
1426 ptrSharedDataValue.ZeroTerminate(); |
|
1427 |
|
1428 // Now update the shared data area |
|
1429 if( ret == KErrNone ) |
|
1430 { |
|
1431 // Update the shared data with the data passed in |
|
1432 CTestSharedData* sharedDataObject = NULL; |
|
1433 CTEFSharedData<CTestSharedData> *tefSharedData = CTEFSharedData<CTestSharedData>::NewLC( sharedDataObject, |
|
1434 sharedDataName ); |
|
1435 if( sharedDataObject != NULL ) |
|
1436 { |
|
1437 tefSharedData->EnterCriticalSection(); |
|
1438 // Copy the data contents across |
|
1439 // No need to check the data length as it was checked above |
|
1440 sharedDataObject->SetText( *sharedDataValue ); |
|
1441 tefSharedData->ExitCriticalSection(); |
|
1442 } |
|
1443 else |
|
1444 { |
|
1445 ret = KErrNotFound; |
|
1446 } |
|
1447 |
|
1448 CleanupStack::PopAndDestroy(tefSharedData); |
|
1449 } |
|
1450 |
|
1451 // Cleanup |
|
1452 CleanupStack::PopAndDestroy(sharedDataValue); |
|
1453 } |
|
1454 else |
|
1455 { |
|
1456 ret = KErrArgument; |
|
1457 } |
|
1458 } |
|
1459 else |
|
1460 { |
|
1461 ret = KErrArgument; |
|
1462 } |
|
1463 } |
|
1464 } |
|
1465 else |
|
1466 { |
|
1467 ret = KErrArgument; |
|
1468 } |
|
1469 CleanupStack::PopAndDestroy(sharedDataString); |
|
1470 } |
|
1471 else |
|
1472 { |
|
1473 ret = KErrTooBig; |
|
1474 } |
|
1475 |
|
1476 return ret; |
|
1477 } |
|
1478 |
|
1479 //------------------------------------------------------------------------------ |
|
1480 // |
|
1481 //Function used to open file(s) |
|
1482 // |
|
1483 |
|
1484 TInt CStatApiCommandDecoder::OpenFileL() |
|
1485 { |
|
1486 #ifndef LIGHT_MODE |
|
1487 TInt ret = KErrArgument; |
|
1488 |
|
1489 TBuf<KMaxFileName> docName; |
|
1490 CApaCommandLine* cmdLine = CApaCommandLine::NewLC(); |
|
1491 |
|
1492 TInt commaposition = command.Locate(','); |
|
1493 if (commaposition != KErrNotFound) |
|
1494 { |
|
1495 // set the application name |
|
1496 cmdLine -> SetExecutableNameL(command.Mid(0, commaposition)); |
|
1497 |
|
1498 // use document name supplied in command string |
|
1499 docName = command.Mid(commaposition + 1); |
|
1500 |
|
1501 updatePathWithSysDrive(docName); |
|
1502 cmdLine -> SetDocumentNameL(docName); |
|
1503 cmdLine -> SetCommandL(EApaCommandOpen); |
|
1504 |
|
1505 //initialise |
|
1506 TRAP(ret, iApaS.Connect()) |
|
1507 if(ret != KErrNone) |
|
1508 pMsg->Msg(_L("DECODER: Application Architecture server error...%d"), ret); |
|
1509 |
|
1510 // startup |
|
1511 TRAP(ret, iApaS.StartApp(*cmdLine)) |
|
1512 if(ret != KErrNone) |
|
1513 pMsg->Msg(_L("DECODER: Unable to start application...%d"), ret); |
|
1514 |
|
1515 //cleanup |
|
1516 iApaS.Close(); |
|
1517 |
|
1518 // need to sleep a bit here to give the OS time to actually start the application |
|
1519 User::After(3000000); |
|
1520 } |
|
1521 |
|
1522 CleanupStack::PopAndDestroy(); |
|
1523 return ret; |
|
1524 #else // ifndef LIGHT_MODE |
|
1525 return (KErrNotSupported); |
|
1526 #endif // ifndef LIGHT_MODE |
|
1527 } |
|
1528 //------------------------------------------------------------------------------ |
|
1529 // |
|
1530 //Function used to capture screens |
|
1531 // |
|
1532 |
|
1533 void CStatApiCommandDecoder::ScreenCaptureL() |
|
1534 { |
|
1535 #ifndef LIGHT_MODE |
|
1536 |
|
1537 //_LIT(KDriveD, "d:\\"); |
|
1538 |
|
1539 // Optimize screen captures by only creating device objects |
|
1540 // once and re-using them. |
|
1541 // Create screen device object is now done in |
|
1542 // CStatApiCommandDecoder::ConstructL and removed |
|
1543 // in CStatApiCommandDecoder::~CStatApiCommandDecoder(). |
|
1544 |
|
1545 User::LeaveIfError(iDevice->CopyScreenToBitmap(screenBitmap)); |
|
1546 |
|
1547 // retrieve machine id information |
|
1548 TBuf<20> buffer; |
|
1549 buffer.Num(iUIDValue); |
|
1550 |
|
1551 TBuf<KMaxFileName> tempfilename; |
|
1552 |
|
1553 tempfilename.Append(iSystemDrive); |
|
1554 tempfilename.Append(buffer); |
|
1555 tempfilename.Append(_L("00")); //substation id |
|
1556 |
|
1557 // create date/time string for filename |
|
1558 TBuf<25> datestring; |
|
1559 TTime DateAndTime; |
|
1560 DateAndTime.HomeTime(); |
|
1561 DateAndTime.FormatL(datestring, (_L("%D%M%*Y%1%2%3%J%T%S"))); |
|
1562 tempfilename.Append(datestring); |
|
1563 |
|
1564 //bitmap image extension |
|
1565 tempfilename.Append(_L(".mbm")); |
|
1566 |
|
1567 // save the image to file |
|
1568 User::LeaveIfError(screenBitmap->Save(tempfilename)); |
|
1569 { |
|
1570 filename = tempfilename; |
|
1571 } |
|
1572 #endif // ifndef LIGHT_MODE |
|
1573 } |
|
1574 |
|
1575 //------------------------------------------------------------------------------ |
|
1576 //function used to simulate a screen press using stylus |
|
1577 |
|
1578 TInt CStatApiCommandDecoder::OpenIcon() |
|
1579 { |
|
1580 #ifndef LIGHT_MODE |
|
1581 // If this assert triggers it is because we are running in |
|
1582 // text shell mode without a window server and the call |
|
1583 // requires the window server to be available. |
|
1584 // A command filter in ExecuteCommand should have prevented |
|
1585 // this call from being made. |
|
1586 assert(IsWindowServerAvailable()); |
|
1587 |
|
1588 TInt ret = KErrArgument; |
|
1589 |
|
1590 TInt commaposition = command.Locate(','); |
|
1591 if (commaposition != KErrNotFound) |
|
1592 { |
|
1593 // get x coord |
|
1594 TInt x = 0; |
|
1595 TLex Lexcoord = command.Mid(0, commaposition); |
|
1596 Lexcoord.Val(x); |
|
1597 |
|
1598 // get y coord |
|
1599 TInt y = 0; |
|
1600 Lexcoord = command.Mid(commaposition + 1); |
|
1601 Lexcoord.Val(y); |
|
1602 |
|
1603 //mouse click down |
|
1604 TRawEvent rawEventa; |
|
1605 rawEventa.Set(TRawEvent::EButton1Down, x, y); |
|
1606 iWs.SimulateRawEvent(rawEventa); |
|
1607 iWs.Flush(); |
|
1608 User::After(TTimeIntervalMicroSeconds32(100000)); |
|
1609 |
|
1610 //mouse click up |
|
1611 rawEventa.Set(TRawEvent::EButton1Up, x, y); |
|
1612 iWs.SimulateRawEvent(rawEventa); |
|
1613 iWs.Flush(); |
|
1614 User::After(TTimeIntervalMicroSeconds32(100000)); |
|
1615 ret = KErrNone; |
|
1616 } |
|
1617 |
|
1618 return (ret); |
|
1619 #else // ifndef LIGHT_MODE |
|
1620 return (KErrNotSupported); |
|
1621 #endif // ifndef LIGHT_MODE |
|
1622 } |
|
1623 |
|
1624 |
|
1625 //------------------------------------------------------------------------------ |
|
1626 //function used to invoke the ESHELL command interpreter |
|
1627 // |
|
1628 // This is done alternatively to starting an app because the ESHELL |
|
1629 // cannot be invoked from it's current location in z: |
|
1630 // |
|
1631 // So we copy it first to C: then start it... |
|
1632 // |
|
1633 void CStatApiCommandDecoder::StartEShellL() |
|
1634 { |
|
1635 #ifndef LIGHT_MODE |
|
1636 // If this assert triggers it is because we are running in |
|
1637 // text shell mode without a window server and the call |
|
1638 // requires the window server to be available. |
|
1639 // A command filter in ExecuteCommand should have prevented |
|
1640 // this call from being made. |
|
1641 assert(IsWindowServerAvailable()); |
|
1642 |
|
1643 _LIT(KNewFile, "z:\\sys\\bin\\EShell.exe"); |
|
1644 |
|
1645 |
|
1646 // set command line |
|
1647 CApaCommandLine* cmdLine = CApaCommandLine::NewLC(); //creation of command line structure |
|
1648 cmdLine -> SetExecutableNameL(KNewFile); |
|
1649 |
|
1650 // call it |
|
1651 User::LeaveIfError(iApaS.Connect()); //initialise |
|
1652 User::LeaveIfError(iApaS.StartApp(*cmdLine)); //start the app |
|
1653 iApaS.Close(); |
|
1654 |
|
1655 // clean up |
|
1656 CleanupStack::PopAndDestroy(1); // cmdLine |
|
1657 |
|
1658 // need to sleep a bit here to give the OS time to actually start the application |
|
1659 User::After(3000000); |
|
1660 |
|
1661 User::Leave(KErrNone); |
|
1662 #endif // ifndef LIGHT_MODE |
|
1663 } |
|
1664 |
|
1665 //------------------------------------------------------------------------------ |
|
1666 //function used to delete file from the device |
|
1667 // |
|
1668 TInt CStatApiCommandDecoder::DeleteFileL(TInt bDisplayMessage) |
|
1669 { |
|
1670 CFileMan *theFile = CFileMan::NewL(*iFs); |
|
1671 CleanupStack::PushL(theFile); |
|
1672 |
|
1673 updatePathWithSysDrive(command) ; |
|
1674 TInt err = theFile->Delete(command); |
|
1675 if (err!= KErrNone && err!= KErrNotFound) |
|
1676 { |
|
1677 if (bDisplayMessage) |
|
1678 pMsg->Msg(_L("DECODER: Error deleting file %S...%d"), &command, err); |
|
1679 } |
|
1680 |
|
1681 CleanupStack::PopAndDestroy(); |
|
1682 return err; |
|
1683 } |
|
1684 |
|
1685 //------------------------------------------------------------------------------ |
|
1686 //function used to rename file from the device |
|
1687 // |
|
1688 TInt CStatApiCommandDecoder::RenameFileL(MDataConsumer *const aDataConsumer) |
|
1689 { |
|
1690 |
|
1691 TInt err = KErrNone; |
|
1692 |
|
1693 CFileMan *theFile = CFileMan::NewL(*iFs); |
|
1694 CleanupStack::PushL(theFile); |
|
1695 |
|
1696 TBuf<KMaxPath> dataFiles; |
|
1697 |
|
1698 TBuf<KMaxPath> dataFileNameFrom; |
|
1699 TBuf<KMaxPath> dataFileNameTo; |
|
1700 |
|
1701 dataFiles.Copy( *aDataConsumer ); |
|
1702 |
|
1703 if( err == KErrNone ) |
|
1704 { |
|
1705 // locate the destination part of the filename |
|
1706 TInt commaposition = dataFiles.Locate(','); |
|
1707 if (commaposition != KErrNotFound) |
|
1708 { |
|
1709 //name of existing file |
|
1710 dataFileNameFrom.Zero(); |
|
1711 dataFileNameFrom.Copy(dataFiles.Left(commaposition)); |
|
1712 filename.ZeroTerminate(); |
|
1713 |
|
1714 //name of destination file |
|
1715 dataFileNameTo.Zero(); |
|
1716 dataFileNameTo.Copy(dataFiles.Right(dataFiles.Length()-commaposition-1)); |
|
1717 dataFileNameTo.ZeroTerminate(); |
|
1718 |
|
1719 updatePathWithSysDrive(dataFileNameFrom) ; |
|
1720 updatePathWithSysDrive(dataFileNameTo) ; |
|
1721 err = theFile->Copy( dataFileNameFrom, dataFileNameTo ); |
|
1722 |
|
1723 if( err == KErrNone ) |
|
1724 { |
|
1725 err = theFile->Delete(dataFileNameFrom); |
|
1726 } |
|
1727 |
|
1728 } |
|
1729 else |
|
1730 { |
|
1731 err = KErrNotFound; |
|
1732 } |
|
1733 } |
|
1734 |
|
1735 CleanupStack::PopAndDestroy(); |
|
1736 return err; |
|
1737 } |
|
1738 |
|
1739 |
|
1740 |
|
1741 //------------------------------------------------------------------------------ |
|
1742 //function used to check if a location exists on the device |
|
1743 // |
|
1744 TInt CStatApiCommandDecoder::CheckLocation(MDataConsumer *const aDataConsumer) |
|
1745 { |
|
1746 |
|
1747 TInt err = KErrNone; |
|
1748 TEntry aEntry; |
|
1749 TVolumeInfo aVolume; |
|
1750 TInt aDrive; |
|
1751 TBuf<KMaxPath> aPath; |
|
1752 |
|
1753 aPath.Copy(*aDataConsumer); |
|
1754 updatePathWithSysDrive(aPath); |
|
1755 |
|
1756 iFs->CharToDrive((char)aPath[0],aDrive); |
|
1757 |
|
1758 //try to get drive info |
|
1759 err = iFs->Volume(aVolume,aDrive); |
|
1760 |
|
1761 if(err == KErrNone && aPath.Length() > 3) |
|
1762 { |
|
1763 //try to get file info |
|
1764 err = iFs->Entry(aPath,aEntry); |
|
1765 } |
|
1766 |
|
1767 return err; |
|
1768 |
|
1769 } |
|
1770 |
|
1771 |
|
1772 |
|
1773 |
|
1774 //------------------------------------------------------------------------------ |
|
1775 //function used to create a folder on the device |
|
1776 // |
|
1777 TInt CStatApiCommandDecoder::CreateFolder() |
|
1778 { |
|
1779 updatePathWithSysDrive(command); |
|
1780 TInt err = iFs->MkDirAll(command); |
|
1781 |
|
1782 // no error or already exists are acceptable return codes |
|
1783 if (err == KErrAlreadyExists) |
|
1784 err = KErrNone; |
|
1785 |
|
1786 return err; |
|
1787 } |
|
1788 |
|
1789 //------------------------------------------------------------------------------ |
|
1790 //function used to remove a folder from the device |
|
1791 // |
|
1792 TInt CStatApiCommandDecoder::RemoveFolder() |
|
1793 { |
|
1794 |
|
1795 updatePathWithSysDrive(command) ; |
|
1796 TInt err = iFs->RmDir(command); |
|
1797 |
|
1798 // no error or not found are acceptable return codes |
|
1799 if (err == KErrNotFound) |
|
1800 err = KErrNone; |
|
1801 |
|
1802 return err; |
|
1803 } |
|
1804 |
|
1805 //------------------------------------------------------------------------------ |
|
1806 |
|
1807 TInt CStatApiCommandDecoder::TransferFile(MDataConsumer *const aDataConsumer) |
|
1808 { |
|
1809 TInt err = KErrNone; |
|
1810 |
|
1811 // the Transfer command comes in 2 parts - first the name, then the contents |
|
1812 if (iName) |
|
1813 { |
|
1814 pMsg->Msg(_L("DECODER: Saving filename...")); |
|
1815 |
|
1816 TBuf<KMaxPath> dataFileName; |
|
1817 dataFileName.Copy(*aDataConsumer ) ; |
|
1818 updatePathWithSysDrive(dataFileName) ; |
|
1819 |
|
1820 if( err == KErrNone ) |
|
1821 { |
|
1822 // locate the destination part of the filename |
|
1823 TInt commaposition = dataFileName.Locate(','); |
|
1824 if (commaposition != KErrNotFound) |
|
1825 { |
|
1826 // use document name supplied in command string |
|
1827 filename.Zero(); |
|
1828 filename.Copy(dataFileName.Mid(commaposition + 1)); |
|
1829 filename.ZeroTerminate(); |
|
1830 pMsg->Msg(_L("DECODER: File name (%S)."), &filename); |
|
1831 iName = 0; |
|
1832 err = KErrNone; |
|
1833 } |
|
1834 } |
|
1835 } |
|
1836 else |
|
1837 { |
|
1838 // save the file |
|
1839 pMsg->Msg(_L("DECODER: Saving file %S"), &filename); |
|
1840 |
|
1841 if( aDataConsumer != NULL ) |
|
1842 { |
|
1843 err = aDataConsumer->SaveData( filename ); |
|
1844 } |
|
1845 else |
|
1846 { |
|
1847 CDataConsumerMemory *dataConsumer = NULL; |
|
1848 TRAP(err, dataConsumer = CDataConsumerMemory::NewL( )); |
|
1849 |
|
1850 if( err == KErrNone ) |
|
1851 { |
|
1852 err = dataConsumer->SaveData( filename ); |
|
1853 } |
|
1854 |
|
1855 if( NULL != dataConsumer ) |
|
1856 { |
|
1857 dataConsumer->Delete(); |
|
1858 dataConsumer = NULL; |
|
1859 } |
|
1860 } |
|
1861 |
|
1862 iName = 1; |
|
1863 } |
|
1864 |
|
1865 return err; |
|
1866 } |
|
1867 |
|
1868 |
|
1869 //------------------------------------------------------------------------------ |
|
1870 |
|
1871 TInt CStatApiCommandDecoder::ReceiveFile(TUint commandtype, |
|
1872 MDataConsumer *const aDataConsumer, MDataSupplier **aDataSupplier) |
|
1873 { |
|
1874 TInt err = KErrNone; |
|
1875 |
|
1876 // take screenshot first? filename will be generated automatically |
|
1877 if (commandtype == 'S') |
|
1878 { |
|
1879 // If this assert triggers it is because we are running in |
|
1880 // text shell mode without a window server and the call |
|
1881 // requires the window server to be available. |
|
1882 // A command filter in ExecuteCommand should have prevented |
|
1883 // this call from being made. |
|
1884 assert(IsWindowServerAvailable()); |
|
1885 |
|
1886 TRAP(err, ScreenCaptureL()); |
|
1887 } |
|
1888 else |
|
1889 { |
|
1890 TPath dataFileName; |
|
1891 |
|
1892 dataFileName.Copy( *aDataConsumer ); |
|
1893 updatePathWithSysDrive(dataFileName) ; |
|
1894 if( err == KErrNone ) |
|
1895 { |
|
1896 // get the filename from the command |
|
1897 TInt commaposition = dataFileName.Locate(','); |
|
1898 if (commaposition != KErrNotFound) |
|
1899 filename.Copy(dataFileName.Mid(0, commaposition)); |
|
1900 else |
|
1901 filename.Copy(dataFileName); |
|
1902 } |
|
1903 } |
|
1904 |
|
1905 MDataSupplier *pDataSupplier = NULL; |
|
1906 |
|
1907 // Use a data supplier class. |
|
1908 // Initialise it with the file name and allocate |
|
1909 // an initial data buffer. |
|
1910 |
|
1911 if (err == KErrNone) |
|
1912 { |
|
1913 // Create the data supplier. |
|
1914 pDataSupplier = CDataSupplierFile::NewL( ); |
|
1915 |
|
1916 if (pDataSupplier) |
|
1917 { |
|
1918 // Set the data in the data supplier. |
|
1919 TBuf8<KMaxPath> filePath; |
|
1920 filePath.Copy( filename ); |
|
1921 |
|
1922 err = pDataSupplier->SetData( filePath ); |
|
1923 |
|
1924 if (err != KErrNone) |
|
1925 { |
|
1926 TBuf16<KMaxPath> wFilePath; |
|
1927 wFilePath.Copy( filePath ); |
|
1928 pMsg->Msg(_L("Failed to set data in data supplier, (%d)."), err ); |
|
1929 pMsg->Msg(_L("File path %S."), &wFilePath ); |
|
1930 } |
|
1931 } |
|
1932 else |
|
1933 { |
|
1934 err = KErrNoMemory; |
|
1935 pMsg->Msg(_L("Failed to create data supply object") ); |
|
1936 } |
|
1937 } |
|
1938 |
|
1939 // If we are sending a screen image file then we |
|
1940 // use another data supplier class as the file is to be deleted. |
|
1941 if (commandtype == 'S') |
|
1942 { |
|
1943 TInt size = 0; |
|
1944 HBufC8 *buffer = NULL; |
|
1945 |
|
1946 if (err == KErrNone) |
|
1947 { |
|
1948 err = pDataSupplier->GetTotalSize( size ); |
|
1949 |
|
1950 if( err != KErrNone ) |
|
1951 { |
|
1952 pMsg->Msg(_L("Failed to get total size of screen image file") ); |
|
1953 } |
|
1954 } |
|
1955 |
|
1956 if (err == KErrNone) |
|
1957 { |
|
1958 buffer = HBufC8::New(size); |
|
1959 |
|
1960 if( ! buffer ) |
|
1961 { |
|
1962 err = KErrNoMemory; |
|
1963 pMsg->Msg(_L("Failed to allocate buffer for screen image file") ); |
|
1964 } |
|
1965 } |
|
1966 |
|
1967 if (err == KErrNone) |
|
1968 { |
|
1969 err = pDataSupplier->GetData( *buffer, size, size ); |
|
1970 |
|
1971 if (err != KErrNone) |
|
1972 { |
|
1973 pMsg->Msg(_L("Failed to read data from screen image data supplier") ); |
|
1974 } |
|
1975 } |
|
1976 |
|
1977 if (err == KErrNone) |
|
1978 { |
|
1979 pDataSupplier->Delete( ); |
|
1980 |
|
1981 pDataSupplier = CDataSupplierMemory::NewL( ); |
|
1982 |
|
1983 if( ! pDataSupplier ) |
|
1984 { |
|
1985 err = KErrNoMemory; |
|
1986 pMsg->Msg(_L("Failed to create data supply object") ); |
|
1987 } |
|
1988 } |
|
1989 |
|
1990 if (err == KErrNone) |
|
1991 { |
|
1992 err = pDataSupplier->SetData( *buffer ); |
|
1993 |
|
1994 if (err != KErrNone) |
|
1995 { |
|
1996 pMsg->Msg(_L("Failed to set data in data supplier") ); |
|
1997 } |
|
1998 } |
|
1999 |
|
2000 if( NULL != buffer ) |
|
2001 { |
|
2002 delete buffer; |
|
2003 buffer = NULL; |
|
2004 } |
|
2005 } |
|
2006 |
|
2007 if (err == KErrNone) |
|
2008 { |
|
2009 *aDataSupplier = pDataSupplier; |
|
2010 } |
|
2011 else |
|
2012 { |
|
2013 if (pDataSupplier) |
|
2014 { |
|
2015 pDataSupplier->Delete( ); |
|
2016 pDataSupplier = NULL; |
|
2017 } |
|
2018 } |
|
2019 |
|
2020 return err; |
|
2021 } |
|
2022 |
|
2023 |
|
2024 //------------------------------------------------------------------------------ |
|
2025 |
|
2026 TInt CStatApiCommandDecoder::DeviceInfo(MDataSupplier **aDataSupplier) |
|
2027 { |
|
2028 TBuf8<20> buffer = _L8(""); |
|
2029 TBuf8<150> finalbuffer = _L8("\r\n"); |
|
2030 |
|
2031 TInt DeviceInfoValue; |
|
2032 TInt err = KErrNone; |
|
2033 TInt i = 0; |
|
2034 |
|
2035 //device info required: UID, manufacturer, ROM, RAM, etc |
|
2036 HALData::TAttribute AttribArray[14] = { |
|
2037 HALData::EMachineUid, |
|
2038 HALData::ECPU, |
|
2039 HALData::ECPUABI, |
|
2040 HALData::EDeviceFamily, |
|
2041 HALData::EManufacturer, |
|
2042 |
|
2043 HALData::EModel, |
|
2044 HALData::EDeviceFamilyRev, |
|
2045 HALData::EManufacturerHardwareRev, |
|
2046 HALData::EManufacturerSoftwareRev, |
|
2047 HALData::EManufacturerSoftwareBuild, |
|
2048 HALData::EMemoryPageSize, |
|
2049 HALData::EMemoryRAM, |
|
2050 HALData::EMemoryRAMFree, |
|
2051 HALData::EMemoryROM |
|
2052 }; |
|
2053 |
|
2054 finalbuffer.Append(_L("STAT Version ")); |
|
2055 |
|
2056 buffer.Num(KVersionMajor); |
|
2057 finalbuffer.Append(buffer); |
|
2058 finalbuffer.Append(_L(".")); |
|
2059 |
|
2060 buffer.Num(KVersionMinor); |
|
2061 finalbuffer.Append(buffer); |
|
2062 finalbuffer.Append(_L(".")); |
|
2063 |
|
2064 buffer.Num(KVersionPatch); |
|
2065 finalbuffer.Append(buffer); |
|
2066 finalbuffer.Append(_L("\r\n")); |
|
2067 |
|
2068 while(i < 14) //retrieve all the information and write to a buffer |
|
2069 { |
|
2070 // get the attribute value |
|
2071 HAL::Get(AttribArray[i], DeviceInfoValue); |
|
2072 buffer.Num(DeviceInfoValue); |
|
2073 |
|
2074 // need to convert the value to a meaningful string |
|
2075 if (i < 5) |
|
2076 { |
|
2077 GetData(i, buffer); |
|
2078 } |
|
2079 |
|
2080 finalbuffer.Append(buffer); |
|
2081 finalbuffer.Append(_L8("\r\n")); |
|
2082 i++; |
|
2083 } |
|
2084 |
|
2085 CDataSupplierMemory *pDataSupplier = CDataSupplierMemory::NewL( ); |
|
2086 |
|
2087 if (pDataSupplier) |
|
2088 { |
|
2089 // Set the data in the data supplier. |
|
2090 err = pDataSupplier->SetData( finalbuffer ); |
|
2091 |
|
2092 if (err != KErrNone) |
|
2093 { |
|
2094 pMsg->Msg(_L("Failed to set data in data supplier") ); |
|
2095 } |
|
2096 } |
|
2097 else |
|
2098 { |
|
2099 err = KErrNoMemory; |
|
2100 pMsg->Msg(_L("Failed to create data supply object") ); |
|
2101 } |
|
2102 |
|
2103 if (err == KErrNone) |
|
2104 { |
|
2105 *aDataSupplier = pDataSupplier; |
|
2106 } |
|
2107 else |
|
2108 { |
|
2109 if (pDataSupplier) |
|
2110 { |
|
2111 pDataSupplier->Delete( ); |
|
2112 pDataSupplier = NULL; |
|
2113 } |
|
2114 } |
|
2115 |
|
2116 return err; |
|
2117 } |
|
2118 |
|
2119 //------------------------------------------------------------------------------ |
|
2120 |
|
2121 TInt CStatApiCommandDecoder::SaveLogFile(MDataSupplier **aDataSupplier) |
|
2122 { |
|
2123 TInt err = KErrNone; |
|
2124 |
|
2125 CDataConsumerMemory *data = NULL; |
|
2126 |
|
2127 // if the log file is not enabled then we return an empty buffer |
|
2128 if( pMsg->IsInitialised() == EFalse ) |
|
2129 { |
|
2130 return KErrNone; |
|
2131 } |
|
2132 |
|
2133 //open the file an copy it into the return buffer |
|
2134 data = CDataConsumerMemory::NewL( ); |
|
2135 |
|
2136 if( ! data ) |
|
2137 { |
|
2138 err = KErrNoMemory; |
|
2139 } |
|
2140 |
|
2141 if( err == KErrNone ) |
|
2142 { |
|
2143 pMsg->CloseFile(); |
|
2144 } |
|
2145 |
|
2146 |
|
2147 |
|
2148 TBuf<KMaxPath> filePath; |
|
2149 TBuf<17> statLogFile; |
|
2150 statLogFile.Append(iSystemDrive); |
|
2151 statLogFile.Append(KStatLogFile); |
|
2152 if( err == KErrNone ) |
|
2153 { |
|
2154 |
|
2155 RFile file; |
|
2156 |
|
2157 err = file.Temp( *iFs, iSystemDrive, |
|
2158 filePath, EFileShareExclusive ); |
|
2159 |
|
2160 if( err == KErrNone ) |
|
2161 { |
|
2162 file.Close( ); |
|
2163 |
|
2164 CFileMan* fileMan = CFileMan::NewL( *iFs ); |
|
2165 err = fileMan->Copy(statLogFile,filePath); |
|
2166 delete fileMan; |
|
2167 fileMan = NULL; |
|
2168 } |
|
2169 } |
|
2170 |
|
2171 if( err == KErrNone ) |
|
2172 { |
|
2173 TBuf8<KMaxPath> cFilePath; |
|
2174 cFilePath.Copy( filePath ); |
|
2175 err = data->AddData( cFilePath ); |
|
2176 } |
|
2177 |
|
2178 if( err == KErrNone ) |
|
2179 { |
|
2180 err = ReceiveFile('R', data, aDataSupplier); |
|
2181 } |
|
2182 |
|
2183 |
|
2184 if( err == KErrNone ) |
|
2185 { |
|
2186 // reset the logger |
|
2187 pMsg->Init( *iFs, statLogFile, NULL ); |
|
2188 } |
|
2189 |
|
2190 if( data ) |
|
2191 { |
|
2192 data->Delete( ); |
|
2193 data = NULL; |
|
2194 } |
|
2195 |
|
2196 return err; |
|
2197 } |
|
2198 |
|
2199 //------------------------------------------------------------------------------ |
|
2200 |
|
2201 #ifndef LIGHT_MODE |
|
2202 TInt CStatApiCommandDecoder::GetDiskDriveInformationL(MDataSupplier **aDataSupplier) |
|
2203 #else // ifndef LIGHT_MODE |
|
2204 TInt CStatApiCommandDecoder::GetDiskDriveInformationL(MDataSupplier **) |
|
2205 #endif // ifndef LIGHT_MODE |
|
2206 { |
|
2207 #ifndef LIGHT_MODE |
|
2208 TInt err = KErrNone; |
|
2209 |
|
2210 // Get the disk drive information and save to the data supplier object |
|
2211 // as a text string. |
|
2212 |
|
2213 static const TInt bufferGrow = (4*1024); |
|
2214 RBufWriteStream strWrite; |
|
2215 CBufFlat* dynBuffer = NULL; |
|
2216 |
|
2217 if( err == KErrNone ) |
|
2218 { |
|
2219 dynBuffer = CBufFlat::NewL(bufferGrow); |
|
2220 |
|
2221 if( dynBuffer == NULL ) |
|
2222 { |
|
2223 err = KErrNoMemory; |
|
2224 } |
|
2225 } |
|
2226 |
|
2227 if( err == KErrNone ) |
|
2228 { |
|
2229 strWrite.Open( *dynBuffer, 0 ); |
|
2230 } |
|
2231 |
|
2232 if( err == KErrNone ) |
|
2233 { |
|
2234 RFs fileSystem; |
|
2235 |
|
2236 err = fileSystem.Connect(); |
|
2237 |
|
2238 if( err == KErrNone ) |
|
2239 { |
|
2240 TDriveList driveList; |
|
2241 |
|
2242 if( err == KErrNone ) |
|
2243 { |
|
2244 err = fileSystem.DriveList( driveList ); |
|
2245 } |
|
2246 |
|
2247 if( err == KErrNone ) |
|
2248 { |
|
2249 TBuf8<KMaxFileName> name; // Store volume name |
|
2250 // in 8 bit format. |
|
2251 TBuf8<KMaxFileName*2> buffer; // Store volume information. |
|
2252 |
|
2253 TVolumeInfo volumeInfo; |
|
2254 TInt drive = 0; |
|
2255 for( drive = 0; drive < KMaxDrives; drive++ ) |
|
2256 { |
|
2257 if( driveList[drive] ) |
|
2258 { |
|
2259 err = fileSystem.Volume( volumeInfo, drive ); |
|
2260 |
|
2261 if( err == KErrNone ) |
|
2262 { |
|
2263 // Copy the volume name to an 8 bit buffer. |
|
2264 name.Copy( volumeInfo.iName ); |
|
2265 // Format the text string. |
|
2266 buffer.Format( driveFormat, drive + 'A', |
|
2267 &name, volumeInfo.iSize, &newLine ); |
|
2268 // Add details of the current drive to our |
|
2269 // buffer. |
|
2270 TRAP( err, strWrite.WriteL( buffer ) ); |
|
2271 } |
|
2272 } |
|
2273 } |
|
2274 } |
|
2275 fileSystem.Close(); |
|
2276 } |
|
2277 } |
|
2278 |
|
2279 if( err == KErrNone || err == KErrNotReady ) |
|
2280 { |
|
2281 TRAP( err, strWrite.WriteL( newLine ) ); |
|
2282 |
|
2283 CDataSupplierMemory *pDataSupplier = CDataSupplierMemory::NewL( ); |
|
2284 |
|
2285 if (pDataSupplier) |
|
2286 { |
|
2287 // Set the data in the data supplier. |
|
2288 err = pDataSupplier->SetData( dynBuffer->Ptr( 0 ) ); |
|
2289 |
|
2290 if (err != KErrNone) |
|
2291 { |
|
2292 pMsg->Msg(_L("Failed to set data in data supplier") ); |
|
2293 } |
|
2294 } |
|
2295 else |
|
2296 { |
|
2297 err = KErrNoMemory; |
|
2298 pMsg->Msg(_L("Failed to create data supply object") ); |
|
2299 } |
|
2300 |
|
2301 if (err == KErrNone) |
|
2302 { |
|
2303 *aDataSupplier = pDataSupplier; |
|
2304 } |
|
2305 else |
|
2306 { |
|
2307 if (pDataSupplier) |
|
2308 { |
|
2309 pDataSupplier->Delete( ); |
|
2310 pDataSupplier = NULL; |
|
2311 } |
|
2312 } |
|
2313 } |
|
2314 |
|
2315 strWrite.Close( ); |
|
2316 |
|
2317 if( dynBuffer != NULL ) |
|
2318 { |
|
2319 delete dynBuffer; |
|
2320 dynBuffer = NULL; |
|
2321 } |
|
2322 |
|
2323 return err; |
|
2324 #else // ifndef LIGHT_MODE |
|
2325 return (KErrNotSupported); |
|
2326 #endif // ifndef LIGHT_MODE |
|
2327 } |
|
2328 |
|
2329 //------------------------------------------------------------------------------ |
|
2330 |
|
2331 #ifndef LIGHT_MODE |
|
2332 TInt CStatApiCommandDecoder::GetDirectoryInformationL(MDataConsumer *const aDataConsumer, |
|
2333 MDataSupplier **aDataSupplier) |
|
2334 #else // ifndef LIGHT_MODE |
|
2335 TInt CStatApiCommandDecoder::GetDirectoryInformationL(MDataConsumer *const, |
|
2336 MDataSupplier **) |
|
2337 #endif // ifndef LIGHT_MODE |
|
2338 { |
|
2339 #ifndef LIGHT_MODE |
|
2340 TInt err = KErrNone; |
|
2341 |
|
2342 // Get the directory entries for a specified directory |
|
2343 // and save to the data supplier object as a text string. |
|
2344 |
|
2345 TBuf<KMaxPath> directoryName; |
|
2346 |
|
2347 static const TInt bufferGrow = (4*1024); |
|
2348 RBufWriteStream strWrite; |
|
2349 CBufFlat* dynBuffer = NULL; |
|
2350 |
|
2351 if( err == KErrNone ) |
|
2352 { |
|
2353 directoryName.Copy( *aDataConsumer ); |
|
2354 } |
|
2355 |
|
2356 if( err == KErrNone ) |
|
2357 { |
|
2358 dynBuffer = CBufFlat::NewL(bufferGrow); |
|
2359 |
|
2360 if( dynBuffer == NULL ) |
|
2361 { |
|
2362 err = KErrNoMemory; |
|
2363 } |
|
2364 } |
|
2365 |
|
2366 if( err == KErrNone ) |
|
2367 { |
|
2368 strWrite.Open( *dynBuffer, 0 ); |
|
2369 } |
|
2370 |
|
2371 if( err == KErrNone ) |
|
2372 { |
|
2373 RFs fileSystem; |
|
2374 |
|
2375 err = fileSystem.Connect(); |
|
2376 |
|
2377 if( err == KErrNone ) |
|
2378 { |
|
2379 CDir *entryList = NULL; |
|
2380 |
|
2381 if( err == KErrNone ) |
|
2382 { |
|
2383 err = fileSystem.GetDir( directoryName, KEntryAttMaskSupported, EDirsFirst | ESortByName, |
|
2384 entryList ); |
|
2385 } |
|
2386 |
|
2387 if( err == KErrNone ) |
|
2388 { |
|
2389 TBuf8<KMaxFileName> name; // Store entry name |
|
2390 // in 8 bit format. |
|
2391 TBuf8<KMaxFileName*2> buffer; // Store entry information. |
|
2392 |
|
2393 static const TInt maxDateLength = 32; |
|
2394 TBuf8<maxDateLength> dateBuffer; |
|
2395 |
|
2396 TDateTime dateTime; |
|
2397 |
|
2398 TInt count = entryList->Count(); |
|
2399 TInt entry = 0; |
|
2400 for( entry = 0; (entry < count) && (err == KErrNone); entry++ ) |
|
2401 { |
|
2402 const TEntry &anEntry = entryList->operator[](entry); |
|
2403 |
|
2404 // Format the date into readable text. |
|
2405 dateTime = anEntry.iModified.DateTime(); |
|
2406 dateBuffer.Format( dateFormat, dateTime.Day() + 1, dateTime.Month() + 1, |
|
2407 dateTime.Year(), dateTime.Hour(), dateTime.Minute() ); |
|
2408 |
|
2409 // Copy the volume name to an 8 bit buffer. |
|
2410 name.Copy( anEntry.iName ); |
|
2411 // Format the text string. |
|
2412 buffer.Format( entryFormat, &name, |
|
2413 anEntry.iAtt, &dateBuffer, anEntry.iSize, &newLine ); |
|
2414 // Add details of the current drive to our |
|
2415 // buffer. |
|
2416 TRAP( err, strWrite.WriteL( buffer ) ); |
|
2417 } |
|
2418 } |
|
2419 |
|
2420 if( entryList != NULL ) |
|
2421 { |
|
2422 delete entryList; |
|
2423 entryList = NULL; |
|
2424 } |
|
2425 fileSystem.Close(); |
|
2426 } |
|
2427 } |
|
2428 |
|
2429 if( err == KErrNone ) |
|
2430 { |
|
2431 TRAP( err, strWrite.WriteL( newLine ) ); |
|
2432 |
|
2433 CDataSupplierMemory *pDataSupplier = CDataSupplierMemory::NewL( ); |
|
2434 |
|
2435 if (pDataSupplier) |
|
2436 { |
|
2437 // Set the data in the data supplier. |
|
2438 err = pDataSupplier->SetData( dynBuffer->Ptr( 0 ) ); |
|
2439 |
|
2440 if (err != KErrNone) |
|
2441 { |
|
2442 pMsg->Msg(_L("Failed to set data in data supplier") ); |
|
2443 } |
|
2444 } |
|
2445 else |
|
2446 { |
|
2447 err = KErrNoMemory; |
|
2448 pMsg->Msg(_L("Failed to create data supply object") ); |
|
2449 } |
|
2450 |
|
2451 if (err == KErrNone) |
|
2452 { |
|
2453 *aDataSupplier = pDataSupplier; |
|
2454 } |
|
2455 else |
|
2456 { |
|
2457 if (pDataSupplier) |
|
2458 { |
|
2459 pDataSupplier->Delete( ); |
|
2460 pDataSupplier = NULL; |
|
2461 } |
|
2462 } |
|
2463 } |
|
2464 |
|
2465 strWrite.Close( ); |
|
2466 |
|
2467 if( dynBuffer != NULL ) |
|
2468 { |
|
2469 delete dynBuffer; |
|
2470 dynBuffer = NULL; |
|
2471 } |
|
2472 |
|
2473 return err; |
|
2474 #else // ifndef LIGHT_MODE |
|
2475 return (KErrNotSupported); |
|
2476 #endif // ifndef LIGHT_MODE |
|
2477 } |
|
2478 |
|
2479 //------------------------------------------------------------------------------ |
|
2480 |
|
2481 #ifndef LIGHT_MODE |
|
2482 void CStatApiCommandDecoder::DoKeyEvent(TInt key) |
|
2483 #else // ifndef LIGHT_MODE |
|
2484 void CStatApiCommandDecoder::DoKeyEvent(TInt) |
|
2485 #endif // ifndef LIGHT_MODE |
|
2486 { |
|
2487 #ifndef LIGHT_MODE |
|
2488 // If this assert triggers it is because we are running in |
|
2489 // text shell mode without a window server and the call |
|
2490 // requires the window server to be available. |
|
2491 // A command filter in ExecuteCommand should have prevented |
|
2492 // this call from being made. |
|
2493 assert(IsWindowServerAvailable()); |
|
2494 |
|
2495 TKeyEvent event; //the key event structure |
|
2496 event.iCode = key; // pass character code into the struct value |
|
2497 event.iScanCode = 0; |
|
2498 event.iModifiers = 0; |
|
2499 event.iRepeats = 0; // no repeats for keypress |
|
2500 |
|
2501 iWs.SimulateKeyEvent(event); // send keystroke |
|
2502 iWs.Flush(); // flush client-side window server buffer |
|
2503 #endif // ifndef LIGHT_MODE |
|
2504 } |
|
2505 |
|
2506 //------------------------------------------------------------------------------ |
|
2507 //Get the required device information |
|
2508 TInt CStatApiCommandDecoder::GetData(TInt i, TDes8& info) |
|
2509 { |
|
2510 TInt err = KErrNone; |
|
2511 TInt a = 0; |
|
2512 TBuf8<150> devicevalue = _L8(""); |
|
2513 TBool found = EFalse; |
|
2514 |
|
2515 devicevalue.Num(ENUM_VALDEVICEINFORMATIONArray[i][a]); //assign initial data in array to value (element 0) |
|
2516 while (ENUM_DEVICEINFORMATIONArray[i][a] != NULL) |
|
2517 { |
|
2518 if (info.Compare(devicevalue) == 0) //if the string has been found in the value array |
|
2519 { |
|
2520 info = ENUM_DEVICEINFORMATIONArray[i][a]; //set the value to the string equivalent |
|
2521 found = ETrue; |
|
2522 break; |
|
2523 } |
|
2524 |
|
2525 a++; |
|
2526 devicevalue.Num(ENUM_VALDEVICEINFORMATIONArray[i][a]); //update contents of value for the next pass |
|
2527 } //end while |
|
2528 |
|
2529 if (!found) |
|
2530 info = _L8("Not available"); |
|
2531 |
|
2532 return err; |
|
2533 } |
|
2534 |
|
2535 //------------------------------------------------------------------------------ |
|
2536 void CStatApiCommandDecoder::AppendErrorCode(TInt ret, MDataSupplier **aDataSupplier) |
|
2537 { |
|
2538 HBufC8 *buffer = HBufC8::New(10); |
|
2539 if (buffer) |
|
2540 { |
|
2541 // add the error code |
|
2542 TPtr8 pBuffer(buffer->Des()); |
|
2543 pBuffer.Zero(); |
|
2544 pBuffer.Num(ret); |
|
2545 pBuffer.ZeroTerminate(); |
|
2546 |
|
2547 *aDataSupplier = CDataSupplierMemory::NewL( ); |
|
2548 if (*aDataSupplier) |
|
2549 { |
|
2550 // Set the data in the data supplier. |
|
2551 (*aDataSupplier)->SetData( *buffer ); |
|
2552 } |
|
2553 |
|
2554 delete buffer; |
|
2555 buffer = NULL; |
|
2556 } |
|
2557 } |
|
2558 |
|
2559 TInt CStatApiCommandDecoder::StopProgramL(const TDesC& aHandleNumber) |
|
2560 { |
|
2561 TLex conv(aHandleNumber); |
|
2562 |
|
2563 TInt64 handleNumber; |
|
2564 |
|
2565 TInt err = conv.Val(handleNumber); |
|
2566 |
|
2567 if(err==KErrNone) |
|
2568 { |
|
2569 RProcess newProcess; |
|
2570 err = newProcess.Open(TProcessId(handleNumber)); |
|
2571 if(err==KErrNone) |
|
2572 { |
|
2573 newProcess.Kill(1); |
|
2574 } |
|
2575 newProcess.Close(); |
|
2576 } |
|
2577 |
|
2578 return err; |
|
2579 } |
|
2580 |
|
2581 |
|
2582 TInt CStatApiCommandDecoder::ProgramStatusL(const TDesC& aHandleNumber, MDataSupplier **aDataSupplier) |
|
2583 { |
|
2584 |
|
2585 CDataSupplierMemory *pDataSupplier = CDataSupplierMemory::NewL( ); |
|
2586 |
|
2587 TBuf8<50> exitData; |
|
2588 |
|
2589 TLex conv(aHandleNumber); |
|
2590 |
|
2591 TInt64 handleNumber; |
|
2592 |
|
2593 TInt err = conv.Val(handleNumber); |
|
2594 |
|
2595 if(err==KErrNone) |
|
2596 { |
|
2597 RProcess newProcess; |
|
2598 TInt status = newProcess.Open(TProcessId(handleNumber)); |
|
2599 |
|
2600 switch(status) |
|
2601 { |
|
2602 case KErrNone: |
|
2603 exitData.Num(ETrue); |
|
2604 break; |
|
2605 default: |
|
2606 exitData.Num(EFalse); |
|
2607 } |
|
2608 |
|
2609 if (pDataSupplier) |
|
2610 { |
|
2611 // Set the data in the data supplier. |
|
2612 err = pDataSupplier->SetData( exitData ); |
|
2613 |
|
2614 if (err != KErrNone) |
|
2615 { |
|
2616 pMsg->Msg(_L("Failed to set data in data supplier") ); |
|
2617 } |
|
2618 } |
|
2619 else |
|
2620 { |
|
2621 err = KErrNoMemory; |
|
2622 pMsg->Msg(_L("Failed to create data supply object") ); |
|
2623 } |
|
2624 |
|
2625 if (err == KErrNone) |
|
2626 { |
|
2627 *aDataSupplier = pDataSupplier; |
|
2628 } |
|
2629 else |
|
2630 { |
|
2631 if (pDataSupplier) |
|
2632 { |
|
2633 pDataSupplier->Delete( ); |
|
2634 pDataSupplier = NULL; |
|
2635 } |
|
2636 } |
|
2637 |
|
2638 newProcess.Close(); |
|
2639 } |
|
2640 |
|
2641 return err; |
|
2642 } |
|
2643 |
|
2644 |
|
2645 void CStatApiCommandDecoder::updatePathWithSysDrive(TBuf<1024>& pathToChange ) |
|
2646 { |
|
2647 //try it here... |
|
2648 //check for the sysdrive being diff from C: |
|
2649 TBufC<KMaxPath> workingPath(pathToChange) ; |
|
2650 TInt indx = workingPath.Des().Find(KReDrive) ; |
|
2651 while( indx > KErrNotFound ) |
|
2652 { |
|
2653 workingPath.Des().Replace(indx,2,getSystemDrive()); |
|
2654 pathToChange = workingPath.Des() ; |
|
2655 indx = workingPath.Des().Find(KReDrive) ; |
|
2656 } |
|
2657 |
|
2658 } |
|
2659 |
|
2660 void CStatApiCommandDecoder::updatePathWithSysDrive(TBuf<KMaxPath>& pathToChange ) |
|
2661 { |
|
2662 TBufC<KMaxPath> workingPath(pathToChange) ; |
|
2663 TInt indx = workingPath.Des().Find(KReDrive) ; |
|
2664 while( indx > KErrNotFound ) |
|
2665 { |
|
2666 workingPath.Des().Replace(indx,2,getSystemDrive()); |
|
2667 pathToChange = workingPath.Des() ; |
|
2668 indx = workingPath.Des().Find(KReDrive) ; |
|
2669 } |
|
2670 |
|
2671 } |
|
2672 |
|
2673 TDriveName CStatApiCommandDecoder::getSystemDrive() |
|
2674 { |
|
2675 |
|
2676 TDriveNumber defaultSysDrive(EDriveC); |
|
2677 RLibrary pluginLibrary; |
|
2678 TInt pluginErr = pluginLibrary.Load(KFileSrvDll); |
|
2679 if (pluginErr == KErrNone) |
|
2680 { |
|
2681 typedef TDriveNumber(*fun1)(); |
|
2682 fun1 sysdrive; |
|
2683 |
|
2684 #ifdef __EABI__ |
|
2685 sysdrive = (fun1)pluginLibrary.Lookup(336); |
|
2686 #else |
|
2687 sysdrive = (fun1)pluginLibrary.Lookup(304); |
|
2688 #endif |
|
2689 |
|
2690 if(sysdrive!=NULL) |
|
2691 { |
|
2692 defaultSysDrive = sysdrive(); |
|
2693 } |
|
2694 } |
|
2695 pluginLibrary.Close(); |
|
2696 |
|
2697 //TDriveName drive( TDriveUnit(defaultSysDrive).Name()) ; |
|
2698 return TDriveUnit(defaultSysDrive).Name() ; |
|
2699 |
|
2700 } |