|
1 /* |
|
2 * Copyright (c) 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: HtiAppServicePlugin implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <badesca.h> |
|
21 #include <f32file.h> |
|
22 |
|
23 #include "HtiAppServicePlugin.h" |
|
24 #include <HtiDispatcherInterface.h> |
|
25 #include <HTILogging.h> |
|
26 |
|
27 // CONSTANTS |
|
28 const static TUid KAppServiceUid = { 0x1020DEC7 }; |
|
29 |
|
30 //error descriptions |
|
31 _LIT8( KErrDescrNoMemory, "No memory" ); |
|
32 _LIT8( KErrDescrInvalidCmd, "Invalid command" ); |
|
33 _LIT8( KErrDescrInvalidArguments, "Invalid arguments" ); |
|
34 _LIT8( KErrDescrFailedCreateProcess, "Failed create process" ); |
|
35 _LIT8( KErrDescrFailedOpenProcess, "Failed open process" ); |
|
36 _LIT8( KErrDescrInvalidProcessId, "Invalid process id" ); |
|
37 _LIT8( KErrDescrNotSupported, "Command not supported" ); |
|
38 _LIT( KHtiAppControlDll, "HtiAppControl.dll" ); |
|
39 |
|
40 const static TUint8 KUnicodeMask = 0x01; |
|
41 const static TInt KTerminateReason = 0; |
|
42 const static TInt KTUintLength = sizeof(TUint); |
|
43 |
|
44 // MACROS |
|
45 |
|
46 // LOCAL CONSTANTS AND MACROS |
|
47 |
|
48 // MODULE DATA STRUCTURES |
|
49 |
|
50 // LOCAL FUNCTION PROTOTYPES |
|
51 |
|
52 // FORWARD DECLARATIONS |
|
53 |
|
54 // ============================ MEMBER FUNCTIONS =============================== |
|
55 |
|
56 // Create instance of concrete ECOM interface implementation |
|
57 CHtiAppServicePlugin* CHtiAppServicePlugin::NewL() |
|
58 { |
|
59 CHtiAppServicePlugin* self = new ( ELeave ) CHtiAppServicePlugin; |
|
60 CleanupStack::PushL( self ); |
|
61 self->ConstructL(); |
|
62 CleanupStack::Pop(); |
|
63 return self; |
|
64 } |
|
65 |
|
66 // Constructor |
|
67 CHtiAppServicePlugin::CHtiAppServicePlugin() |
|
68 { |
|
69 } |
|
70 |
|
71 CHtiAppServicePlugin::~CHtiAppServicePlugin() |
|
72 { |
|
73 HTI_LOG_FUNC_IN( "~CHtiAppServicePlugin" ); |
|
74 |
|
75 for ( TInt i = 0; i < iProcessHandleArray.Count(); i++ ) |
|
76 { |
|
77 iProcessHandleArray[i].Close(); |
|
78 } |
|
79 iProcessHandleArray.Close(); |
|
80 |
|
81 delete iAppServiceUiPlugin; |
|
82 |
|
83 iLibrary.Close(); |
|
84 |
|
85 HTI_LOG_FUNC_OUT( "~CHtiAppServicePlugin" ); |
|
86 } |
|
87 |
|
88 //Second phase construction. |
|
89 void CHtiAppServicePlugin::ConstructL() |
|
90 { |
|
91 HTI_LOG_FUNC_IN( "CHtiAppServicePlugin::ConstructL" ); |
|
92 |
|
93 TInt err = iLibrary.Load( KHtiAppControlDll ); |
|
94 HTI_LOG_FORMAT( "HtiAppControlDll library load returned %d", err ); |
|
95 |
|
96 if ( err == KErrNone && |
|
97 iLibrary.Type()[1] == KHTIServiceInterfaceUid ) |
|
98 { |
|
99 HTI_LOG_TEXT( "HtiAppControlDll DLL found" ); |
|
100 TLibraryFunction entry = iLibrary.Lookup( 1 ); |
|
101 if ( entry != NULL ) |
|
102 { |
|
103 iAppServiceUiPlugin = ( CHTIServicePluginInterface* ) entry(); |
|
104 } |
|
105 } |
|
106 else if ( err == KErrNotFound ) |
|
107 { |
|
108 //No HtiAppControl.dll found so CHtiAppServicePlugin can handle only |
|
109 //process control commands |
|
110 HTI_LOG_TEXT( "HtiAppControlDll DLL not found" ); |
|
111 } |
|
112 |
|
113 HTI_LOG_FUNC_OUT( "CHtiAppServicePlugin::ConstructL" ); |
|
114 } |
|
115 |
|
116 void CHtiAppServicePlugin::InitL() |
|
117 { |
|
118 if ( iAppServiceUiPlugin ) |
|
119 { |
|
120 iAppServiceUiPlugin->SetDispatcher( iDispatcher ); |
|
121 } |
|
122 } |
|
123 |
|
124 TInt CHtiAppServicePlugin::ParseString( const TDesC8& aRequest, |
|
125 TInt anOffset, |
|
126 TBool aUnicode, |
|
127 TDes& aResult ) |
|
128 { |
|
129 HTI_LOG_FUNC_IN( "CHtiAppServicePlugin::ParseString" ); |
|
130 //validate parameters |
|
131 //if offset outside the string return empty string |
|
132 if ( anOffset >= aRequest.Size() ) |
|
133 { |
|
134 return anOffset; |
|
135 } |
|
136 |
|
137 TInt len = aRequest[anOffset]; |
|
138 HTI_LOG_FORMAT( "length %d", len ); |
|
139 |
|
140 if ( len > aResult.MaxLength() ) |
|
141 { |
|
142 return KErrBadDescriptor; |
|
143 } |
|
144 |
|
145 TInt nextOffset = ( aUnicode ? len * 2 : len ) + anOffset + 1; |
|
146 HTI_LOG_FORMAT( "nextOffset %d", nextOffset ); |
|
147 HTI_LOG_FORMAT( "reqSize %d", aRequest.Size() ); |
|
148 if ( nextOffset > aRequest.Size() ) |
|
149 { |
|
150 return KErrArgument; |
|
151 } |
|
152 |
|
153 if ( aUnicode ) |
|
154 { |
|
155 const TPtrC8 aFrom( aRequest.Mid( anOffset + 1, len * 2 ) ); |
|
156 aResult.SetLength( len ); |
|
157 for ( TInt i = 0; i < len; ++i ) |
|
158 { |
|
159 aResult[i] = ( TUint16 ) aFrom[i << 1] + |
|
160 ( ( ( TUint16 ) aFrom[( i << 1 ) + 1] ) << 8 ); |
|
161 } |
|
162 } |
|
163 else |
|
164 { |
|
165 aResult.Copy( aRequest.Mid( anOffset + 1, len ) ); |
|
166 } |
|
167 |
|
168 HTI_LOG_FUNC_OUT( "CHtiAppServicePlugin::ParseString" ); |
|
169 return nextOffset; |
|
170 } |
|
171 |
|
172 void CHtiAppServicePlugin::ProcessMessageL( const TDesC8& aMessage, |
|
173 THtiMessagePriority aPriority ) |
|
174 { |
|
175 HTI_LOG_FUNC_IN( "CHtiAppServicePlugin::ProcessMessage" ); |
|
176 if ( aMessage.Length() < 1 ) |
|
177 { |
|
178 // no command |
|
179 SendErrorMsg( KErrArgument, KErrDescrInvalidCmd ); |
|
180 return; |
|
181 } |
|
182 |
|
183 if ( aMessage.Length() < 2 && |
|
184 aMessage[0] != EListProcesses && |
|
185 aMessage[0] != EListProcesses_u ) |
|
186 { |
|
187 // parameter is required with all command except listing processes |
|
188 SendErrorMsg( KErrArgument, KErrDescrInvalidCmd ); |
|
189 return; |
|
190 } |
|
191 |
|
192 HTI_LOG_FORMAT( "cmd %d", aMessage[0] ); |
|
193 if ( aMessage[0] < EProcessLastCommand ) |
|
194 { |
|
195 HandleProcessControlL( aMessage ); |
|
196 } |
|
197 else if ( aMessage[0] <= EUnInstallName ) |
|
198 { |
|
199 if ( iAppServiceUiPlugin ) |
|
200 { |
|
201 iAppServiceUiPlugin->ProcessMessageL( aMessage, aPriority ); |
|
202 } |
|
203 else |
|
204 { |
|
205 SendErrorMsg( KErrNotSupported, KErrDescrNotSupported ); |
|
206 } |
|
207 } |
|
208 else |
|
209 { |
|
210 SendErrorMsg( KErrArgument, KErrDescrInvalidCmd ); |
|
211 } |
|
212 HTI_LOG_FUNC_OUT( "CHtiAppServicePlugin::ProcessMessage" ); |
|
213 } |
|
214 |
|
215 void CHtiAppServicePlugin::HandleProcessControlL( const TDesC8& aMessage ) |
|
216 { |
|
217 HTI_LOG_FUNC_IN( "CHtiAppServicePlugin::HandleProcessControl" ); |
|
218 TBool unicode = aMessage[0] & KUnicodeMask; |
|
219 |
|
220 HTI_LOG_FORMAT( "unicode %d", unicode ); |
|
221 |
|
222 TFileName programName; |
|
223 |
|
224 switch ( aMessage[0] ) |
|
225 { |
|
226 case EStartProcess: |
|
227 case EStartProcess_u: |
|
228 { |
|
229 TFileName cmdLine; |
|
230 TInt offset = ParseString( aMessage, 1, unicode, programName ); |
|
231 if ( offset >= 0 ) |
|
232 { |
|
233 offset = ParseString( aMessage, offset, unicode, cmdLine ); |
|
234 if ( offset >= 0 ) |
|
235 { |
|
236 HandleStartProcessL( programName, cmdLine, EFalse ); |
|
237 } |
|
238 } |
|
239 if ( offset < 0 ) |
|
240 { |
|
241 SendErrorMsg( offset, KErrDescrInvalidArguments ); |
|
242 } |
|
243 } |
|
244 break; |
|
245 case EStopProcess: |
|
246 case EStopProcess_u: |
|
247 { |
|
248 TInt err = ParseString( aMessage, 1, unicode, programName ); |
|
249 if ( err >= 0 ) |
|
250 { |
|
251 RProcess process; |
|
252 err = OpenProcessL( process, programName ); |
|
253 if ( err == KErrNone ) |
|
254 { |
|
255 CleanupClosePushL( process ); |
|
256 |
|
257 HandleStopProcessL( process ); |
|
258 |
|
259 CleanupStack::PopAndDestroy(); |
|
260 } |
|
261 else if ( err == KErrNotFound ) |
|
262 { |
|
263 SendMessageL( ENotFound ); |
|
264 } |
|
265 else |
|
266 { |
|
267 SendErrorMsg( err , KErrDescrFailedOpenProcess ); |
|
268 } |
|
269 } |
|
270 else |
|
271 { |
|
272 SendErrorMsg( err , KErrDescrInvalidArguments ); |
|
273 } |
|
274 } |
|
275 break; |
|
276 case EStopProcess_id: |
|
277 { |
|
278 TPtrC8 processId8 = aMessage.Mid( 1 ); |
|
279 if ( processId8.Length() == 4 ) |
|
280 { |
|
281 RProcess process; |
|
282 TUint32 processId = Parse32<TUint32>( processId8 ); |
|
283 TInt err = process.Open( TProcessId( processId ) ); |
|
284 if ( err == KErrNone ) |
|
285 { |
|
286 CleanupClosePushL( process ); |
|
287 |
|
288 HandleStopProcessL( process ); |
|
289 |
|
290 CleanupStack::PopAndDestroy(); |
|
291 } |
|
292 else if ( err == KErrNotFound ) |
|
293 { |
|
294 SendMessageL( ENotFound ); |
|
295 } |
|
296 else |
|
297 { |
|
298 SendErrorMsg( err , KErrDescrFailedOpenProcess ); |
|
299 } |
|
300 } |
|
301 else |
|
302 { |
|
303 SendErrorMsg( KErrArgument , KErrDescrInvalidProcessId ); |
|
304 } |
|
305 } |
|
306 break; |
|
307 case EStatusProcess: |
|
308 case EStatusProcess_u: |
|
309 { |
|
310 TInt err = ParseString( aMessage, 1, unicode, programName ); |
|
311 if ( err >= 0 ) |
|
312 { |
|
313 RProcess process; |
|
314 err = OpenProcessL( process, programName ); |
|
315 if ( err == KErrNone ) |
|
316 { |
|
317 CleanupClosePushL( process ); |
|
318 |
|
319 HandleStatusProcessL( process ); |
|
320 |
|
321 CleanupStack::PopAndDestroy(); |
|
322 } |
|
323 else if ( err == KErrNotFound ) |
|
324 { |
|
325 SendMessageL( ENotFound ); |
|
326 } |
|
327 else |
|
328 { |
|
329 SendErrorMsg( err , KErrDescrFailedOpenProcess ); |
|
330 } |
|
331 } |
|
332 else |
|
333 { |
|
334 SendErrorMsg( err , KErrDescrInvalidArguments ); |
|
335 } |
|
336 } |
|
337 break; |
|
338 case EStatusProcess_id: |
|
339 { |
|
340 TPtrC8 processId8 = aMessage.Mid( 1 ); |
|
341 if ( processId8.Length() == 4 ) |
|
342 { |
|
343 RProcess process; |
|
344 TUint32 processId = Parse32<TUint32>( processId8 ); |
|
345 TInt err = process.Open( TProcessId( processId ) ); |
|
346 if ( err == KErrNone ) |
|
347 { |
|
348 CleanupClosePushL( process ); |
|
349 |
|
350 HandleStatusProcessL( process ); |
|
351 |
|
352 CleanupStack::PopAndDestroy(); |
|
353 } |
|
354 else if ( err == KErrNotFound ) |
|
355 { |
|
356 SendMessageL( ENotFound ); |
|
357 } |
|
358 else |
|
359 { |
|
360 SendErrorMsg( err , KErrDescrFailedOpenProcess ); |
|
361 } |
|
362 } |
|
363 else |
|
364 { |
|
365 SendErrorMsg( KErrArgument , KErrDescrInvalidProcessId ); |
|
366 } |
|
367 } |
|
368 break; |
|
369 case EListProcesses: |
|
370 case EListProcesses_u: |
|
371 { |
|
372 if ( aMessage.Length() > 1 ) |
|
373 { |
|
374 // there is a match pattern as a parameter |
|
375 TInt err = ParseString( aMessage, 1, unicode, programName ); |
|
376 if ( err >= 0 ) |
|
377 { |
|
378 HandleListProcessesL( programName ); |
|
379 } |
|
380 else |
|
381 { |
|
382 SendErrorMsg( err , KErrDescrInvalidArguments ); |
|
383 } |
|
384 } |
|
385 else |
|
386 { |
|
387 // no match pattern defined |
|
388 HandleListProcessesL( KNullDesC ); |
|
389 } |
|
390 |
|
391 } |
|
392 break; |
|
393 |
|
394 case EStartProcessRetVal: |
|
395 case EStartProcessRetVal_u: |
|
396 { |
|
397 TFileName cmdLine; |
|
398 TInt offset = ParseString( aMessage, 1, unicode, programName ); |
|
399 if ( offset >= 0 ) |
|
400 { |
|
401 offset = ParseString( aMessage, offset, unicode, cmdLine ); |
|
402 if ( offset >= 0 ) |
|
403 { |
|
404 HandleStartProcessL( programName, cmdLine, ETrue ); |
|
405 } |
|
406 } |
|
407 if ( offset < 0 ) |
|
408 { |
|
409 SendErrorMsg( offset, KErrDescrInvalidArguments ); |
|
410 } |
|
411 } |
|
412 break; |
|
413 |
|
414 case EGetProcessExitCode: |
|
415 { |
|
416 HTI_LOG_TEXT( "EGetProcessExitCode" ); |
|
417 TPtrC8 processId8 = aMessage.Mid( 1 ); |
|
418 if ( processId8.Length() == 4 ) |
|
419 { |
|
420 TBool processFound = EFalse; |
|
421 TUint processId = Parse32<TUint>( processId8 ); |
|
422 RProcess process; |
|
423 TBuf8<1 + 4 + 1 + KMaxExitCategoryName> response; |
|
424 |
|
425 HTI_LOG_FORMAT( "Starting to search process with id: %d", processId ); |
|
426 |
|
427 for ( TInt i = 0; i < iProcessHandleArray.Count(); i++ ) |
|
428 { |
|
429 process = iProcessHandleArray[i]; |
|
430 TUint id = process.Id(); |
|
431 |
|
432 if ( id == processId ) |
|
433 { |
|
434 HTI_LOG_TEXT( "Matching process found" ); |
|
435 |
|
436 TInt exitReason = process.ExitReason(); |
|
437 response.Append( process.ExitType() ); |
|
438 response.Append( (TUint8*)(&exitReason), 4 ); |
|
439 response.Append( process.ExitCategory().Length() ); |
|
440 response.Append( process.ExitCategory() ); |
|
441 |
|
442 SendMessageL( EOk, response ); |
|
443 |
|
444 // Close the process handle and remove it from the array |
|
445 // if the process is not running anymore and the exit |
|
446 // code has been queried. |
|
447 if ( process.ExitType() != EExitPending ) |
|
448 { |
|
449 HTI_LOG_TEXT( "Closing and removing the handle" ); |
|
450 iProcessHandleArray[i].Close(); |
|
451 iProcessHandleArray.Remove( i ); |
|
452 } |
|
453 |
|
454 processFound = ETrue; |
|
455 break; |
|
456 } |
|
457 } |
|
458 |
|
459 if ( !processFound ) |
|
460 { |
|
461 SendErrorMsg( KErrNotFound , KErrDescrInvalidProcessId ); |
|
462 } |
|
463 } |
|
464 else |
|
465 { |
|
466 SendErrorMsg( KErrArgument , KErrDescrInvalidProcessId ); |
|
467 } |
|
468 } |
|
469 break; |
|
470 |
|
471 default: |
|
472 { |
|
473 SendErrorMsg( KErrArgument, KErrDescrInvalidCmd ); |
|
474 } |
|
475 } |
|
476 HTI_LOG_FUNC_OUT( "CHtiAppServicePlugin::HandleProcessControl" ); |
|
477 } |
|
478 |
|
479 void CHtiAppServicePlugin::HandleStartProcessL( const TDesC& aProgramName, |
|
480 const TDesC& aCmdLine, |
|
481 TBool aStoreProcessHandle ) |
|
482 { |
|
483 HTI_LOG_FUNC_IN( "CHtiAppServicePlugin::HandleStartProcessL" ); |
|
484 HTI_LOG_FORMAT( "progr name %d", aProgramName.Length() ); |
|
485 HTI_LOG_DES( aProgramName ); |
|
486 |
|
487 RProcess process; |
|
488 TInt err = process.Create( aProgramName, aCmdLine ); // command parameters |
|
489 |
|
490 if ( err == KErrNone ) |
|
491 { |
|
492 CleanupClosePushL( process ); |
|
493 |
|
494 //convert process id to binary des |
|
495 TUint processId = process.Id(); |
|
496 HTI_LOG_FORMAT( "process id %d", processId ); |
|
497 |
|
498 TBuf8<KTUintLength> processIdDes; |
|
499 processIdDes.Append( |
|
500 ( TUint8* )( &processId ), KTUintLength ); |
|
501 |
|
502 SendMessageL( EOk, processIdDes ); |
|
503 |
|
504 process.Resume(); |
|
505 |
|
506 if ( aStoreProcessHandle ) |
|
507 { |
|
508 HTI_LOG_TEXT( "Storing the process handle" ); |
|
509 iProcessHandleArray.Append( process ); |
|
510 CleanupStack::Pop(); |
|
511 } |
|
512 else |
|
513 { |
|
514 CleanupStack::PopAndDestroy(); |
|
515 } |
|
516 } |
|
517 else if ( err == KErrNotFound ) |
|
518 { |
|
519 SendMessageL( ENotFound ); |
|
520 } |
|
521 else |
|
522 { |
|
523 SendErrorMsg( err ,KErrDescrFailedCreateProcess ); |
|
524 } |
|
525 |
|
526 HTI_LOG_FUNC_OUT( "CHtiAppServicePlugin::HandleStartProcessL" ); |
|
527 } |
|
528 |
|
529 void CHtiAppServicePlugin::HandleStopProcessL( RProcess& aProcess ) |
|
530 { |
|
531 if ( aProcess.ExitType() == EExitPending ) |
|
532 { |
|
533 aProcess.Kill( KTerminateReason ); |
|
534 SendMessageL( EOk ); |
|
535 } |
|
536 else |
|
537 { |
|
538 SendMessageL( EAlreadyStopped ); |
|
539 } |
|
540 } |
|
541 |
|
542 void CHtiAppServicePlugin::HandleStatusProcessL( RProcess& aProcess ) |
|
543 { |
|
544 TExitType exT = aProcess.ExitType(); |
|
545 |
|
546 switch ( exT ) |
|
547 { |
|
548 case EExitPending: |
|
549 { |
|
550 SendMessageL( ERunning ); |
|
551 } |
|
552 break; |
|
553 case EExitKill: |
|
554 case EExitTerminate: |
|
555 { |
|
556 SendMessageL( EKilled ); |
|
557 } |
|
558 break; |
|
559 case EExitPanic: |
|
560 { |
|
561 SendMessageL( EPanic ); |
|
562 } |
|
563 break; |
|
564 }; |
|
565 } |
|
566 |
|
567 |
|
568 void CHtiAppServicePlugin::HandleListProcessesL( const TDesC& aMatch ) |
|
569 { |
|
570 HTI_LOG_FUNC_IN( "CHtiAppServicePlugin::HandleListProcessesL" ); |
|
571 |
|
572 RProcess process; |
|
573 TFullName processName; |
|
574 TUint processId; |
|
575 TBuf8<KTUintLength> processIdDes; |
|
576 TExitType exitType; |
|
577 |
|
578 TBuf8<128> buf; |
|
579 CBufFlat* processListBuf = NULL; |
|
580 TRAPD( err, processListBuf = CBufFlat::NewL( 128 ) ); |
|
581 if ( err ) |
|
582 { |
|
583 SendErrorMsg( err ,KErrDescrNoMemory ); |
|
584 return; |
|
585 } |
|
586 |
|
587 CleanupStack::PushL( processListBuf ); |
|
588 |
|
589 // The default match pattern is the single character * |
|
590 TFindProcess finder; |
|
591 |
|
592 // if some real match pattern is defined, use it |
|
593 if ( aMatch.Length() > 0 ) |
|
594 { |
|
595 HTI_LOG_TEXT( "Match pattern was given:" ); |
|
596 HTI_LOG_DES( aMatch ); |
|
597 finder.Find( aMatch ); |
|
598 } |
|
599 |
|
600 TInt pos = 0; |
|
601 TUint numberOfEntries = 0; |
|
602 |
|
603 while ( finder.Next( processName ) == KErrNone ) |
|
604 { |
|
605 err = process.Open( finder ); |
|
606 |
|
607 //convert process id to binary des |
|
608 processId = process.Id(); |
|
609 processIdDes.Append( ( TUint8* ) ( &processId ), KTUintLength ); |
|
610 buf.Append( processIdDes ); |
|
611 |
|
612 // status |
|
613 exitType = process.ExitType(); |
|
614 switch ( exitType ) |
|
615 { |
|
616 case EExitPending: |
|
617 { |
|
618 buf.Append( ERunning ); |
|
619 } |
|
620 break; |
|
621 case EExitKill: |
|
622 case EExitTerminate: |
|
623 { |
|
624 buf.Append( EKilled ); |
|
625 } |
|
626 break; |
|
627 case EExitPanic: |
|
628 { |
|
629 buf.Append( EPanic ); |
|
630 } |
|
631 break; |
|
632 }; |
|
633 |
|
634 // name length |
|
635 buf.Append( processName.Length() ); |
|
636 |
|
637 // name |
|
638 buf.Append( processName ); |
|
639 |
|
640 process.Close(); |
|
641 |
|
642 TRAP( err, processListBuf->ExpandL( pos, buf.Length() ) ); |
|
643 if ( err ) |
|
644 { |
|
645 SendErrorMsg( err , KErrDescrNoMemory ); |
|
646 delete processListBuf; |
|
647 return; |
|
648 } |
|
649 processListBuf->Write( pos, buf, buf.Length() ); |
|
650 |
|
651 pos += buf.Length(); |
|
652 buf.Zero(); |
|
653 processIdDes.Zero(); |
|
654 numberOfEntries++; |
|
655 } |
|
656 |
|
657 // insert the number of entries in the beginning |
|
658 TBuf8<2> entries; |
|
659 entries.Append( ( TUint8* ) ( &numberOfEntries ), 2 ); |
|
660 processListBuf->ExpandL( 0, 2 ); |
|
661 processListBuf->Write( 0, entries, 2 ); |
|
662 |
|
663 SendMessageL( EOk, processListBuf->Ptr( 0 ) ); |
|
664 |
|
665 CleanupStack::PopAndDestroy( processListBuf ); |
|
666 |
|
667 HTI_LOG_FUNC_OUT( "CHtiAppServicePlugin::HandleListProcessesL" ); |
|
668 } |
|
669 |
|
670 TInt CHtiAppServicePlugin::OpenProcessL( RProcess& aProcess, |
|
671 const TDesC& aMatch ) |
|
672 { |
|
673 HTI_LOG_FUNC_IN( "CHtiAppServicePlugin::OpenProcessL" ); |
|
674 TFullName processName; |
|
675 TInt err = KErrNone; |
|
676 TFindProcess finder( aMatch ); |
|
677 |
|
678 err = finder.Next( processName ); |
|
679 if ( err == KErrNone ) |
|
680 { |
|
681 err = aProcess.Open( finder ); |
|
682 } |
|
683 |
|
684 HTI_LOG_FUNC_OUT( "CHtiAppServicePlugin::OpenProcessL" ); |
|
685 return err; |
|
686 } |
|
687 |
|
688 template<class T> T CHtiAppServicePlugin::Parse32( |
|
689 const TDesC8& a32int ) |
|
690 { |
|
691 //manually construct TUint or TInt32 |
|
692 return T( a32int[0] + ( a32int[1] << 8 ) + |
|
693 ( a32int[2] << 16) + ( a32int[3] << 24) ); |
|
694 } |
|
695 |
|
696 void CHtiAppServicePlugin::SendMessageL( TAppCommand aResponseCode, |
|
697 const TDesC8& aMsg ) |
|
698 { |
|
699 HTI_LOG_FORMAT( "SendMessage %d", aResponseCode ); |
|
700 HTI_LOG_FORMAT( "Message len %d", aMsg.Length() ); |
|
701 HBufC8* sendMsg = HBufC8::NewL( 1 + aMsg.Length() ); |
|
702 CleanupStack::PushL( sendMsg ); |
|
703 sendMsg->Des().Append( aResponseCode ); |
|
704 sendMsg->Des().Append( aMsg ); |
|
705 |
|
706 User::LeaveIfError( iDispatcher->DispatchOutgoingMessage( |
|
707 sendMsg, |
|
708 KAppServiceUid ) ); |
|
709 CleanupStack::Pop(); |
|
710 } |
|
711 |
|
712 inline TInt CHtiAppServicePlugin::SendErrorMsg( TInt anError, |
|
713 const TDesC8& aMsg ) |
|
714 { |
|
715 return iDispatcher->DispatchOutgoingErrorMessage( anError, |
|
716 aMsg, |
|
717 KAppServiceUid ); |
|
718 } |
|
719 |
|
720 |
|
721 // End of File |