|
1 /* |
|
2 * Copyright (c) 2010 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 #include "CProcessMonitor.h" |
|
20 |
|
21 CProcessMonitor::CProcessMonitor() |
|
22 : CActive( EPriorityNormal ), |
|
23 iObserver( NULL ), |
|
24 iProcess(), |
|
25 iProcessName() |
|
26 { |
|
27 CActiveScheduler::Add(this); |
|
28 } |
|
29 |
|
30 CProcessMonitor::~CProcessMonitor() |
|
31 { |
|
32 Cancel(); |
|
33 Cleanup(); |
|
34 } |
|
35 |
|
36 void CProcessMonitor::Cleanup() |
|
37 { |
|
38 iObserver = 0; |
|
39 delete iProcessName; |
|
40 iProcessName = 0; |
|
41 iProcess.Close(); |
|
42 } |
|
43 |
|
44 const TDesC& CProcessMonitor::ProcessName() |
|
45 { |
|
46 if ( iProcessName ) |
|
47 { |
|
48 return *iProcessName; |
|
49 } |
|
50 else |
|
51 { |
|
52 return KNullDesC; |
|
53 } |
|
54 } |
|
55 |
|
56 void CProcessMonitor::StartL( MProcessMonitorObserver& aObserver, |
|
57 const TDesC& aProcessName ) |
|
58 { |
|
59 iObserver = &aObserver; |
|
60 delete iProcessName; |
|
61 iProcessName = aProcessName.AllocL(); |
|
62 |
|
63 TBuf<256> match; |
|
64 match.Append( _L("*") ); |
|
65 match.Append( aProcessName ); |
|
66 match.Append( _L("*") ); |
|
67 |
|
68 TFindProcess find( match ); |
|
69 TFullName name; |
|
70 User::LeaveIfError( find.Next( name ) ); |
|
71 User::LeaveIfError( iProcess.Open( find ) ); |
|
72 |
|
73 iProcess.Logon( iStatus ); |
|
74 SetActive(); |
|
75 } |
|
76 |
|
77 void CProcessMonitor::DoCancel() |
|
78 { |
|
79 iProcess.LogonCancel( iStatus ); |
|
80 Cleanup(); |
|
81 } |
|
82 |
|
83 void CProcessMonitor::RunL() |
|
84 { |
|
85 if ( iStatus >= 0 ) |
|
86 { |
|
87 TRAP_IGNORE |
|
88 ( |
|
89 iObserver->ProcessFinished( *this, |
|
90 iProcess.ExitType(), |
|
91 iProcess.ExitCategory(), |
|
92 iProcess.ExitReason() ); |
|
93 ); |
|
94 } |
|
95 else |
|
96 { |
|
97 iObserver->Failed( *this, iStatus.Int() ); |
|
98 } |
|
99 |
|
100 Cleanup(); |
|
101 } |
|
102 |