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