63
|
1 |
/*
|
|
2 |
* Copyright (c) 2008 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: process monitor.
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
#include "hsprocessmonitor.h"
|
|
19 |
|
|
20 |
// ========================= MEMBER FUNCTIONS ==================================
|
|
21 |
|
|
22 |
// -----------------------------------------------------------------------------
|
|
23 |
// CHsProcessMonitor::NewL()
|
|
24 |
// Two-phased constructor
|
|
25 |
// -----------------------------------------------------------------------------
|
|
26 |
CHsProcessMonitor* CHsProcessMonitor::NewL( const TInt iProcessId,
|
|
27 |
MHsProcessMonitorObserver& aObserver )
|
|
28 |
{
|
|
29 |
CHsProcessMonitor* self = new ( ELeave ) CHsProcessMonitor( iProcessId,
|
|
30 |
aObserver );
|
|
31 |
CleanupStack::PushL( self );
|
|
32 |
self->ConstructL();
|
|
33 |
CleanupStack::Pop( self );
|
|
34 |
return self;
|
|
35 |
}
|
|
36 |
|
|
37 |
// -----------------------------------------------------------------------------
|
|
38 |
// CHsProcessMonitor::~CHsProcessMonitor()
|
|
39 |
// Destructor.
|
|
40 |
// -----------------------------------------------------------------------------
|
|
41 |
//
|
|
42 |
CHsProcessMonitor::~CHsProcessMonitor()
|
|
43 |
{
|
|
44 |
Cancel();
|
|
45 |
SecureProcessHandleAsClosed();
|
|
46 |
iProcessId = KErrNotFound;
|
|
47 |
}
|
|
48 |
|
|
49 |
// -----------------------------------------------------------------------------
|
|
50 |
// CHsProcessMonitor::AttachMonitor()
|
|
51 |
// Attach monitor
|
|
52 |
// -----------------------------------------------------------------------------
|
|
53 |
//
|
|
54 |
TInt CHsProcessMonitor::AttachMonitor()
|
|
55 |
{
|
|
56 |
SecureProcessHandleAsClosed();
|
|
57 |
|
|
58 |
TInt error = iProcess.Open( iProcessId, EOwnerProcess );
|
|
59 |
|
|
60 |
if( error == KErrNone )
|
|
61 |
{
|
|
62 |
iProcessHandleOpen = ETrue;
|
|
63 |
}
|
|
64 |
|
|
65 |
return error;
|
|
66 |
}
|
|
67 |
|
|
68 |
// -----------------------------------------------------------------------------
|
|
69 |
// CHsProcessMonitor::StartMonitor()
|
|
70 |
// Start monitor
|
|
71 |
// -----------------------------------------------------------------------------
|
|
72 |
//
|
|
73 |
TInt CHsProcessMonitor::StartMonitor()
|
|
74 |
{
|
|
75 |
TInt error = KErrNone;
|
|
76 |
|
|
77 |
if( !iProcessHandleOpen )
|
|
78 |
{
|
|
79 |
error = AttachMonitor();
|
|
80 |
}
|
|
81 |
|
|
82 |
if( error == KErrNone )
|
|
83 |
{
|
|
84 |
iProcess.Logon( iStatus );
|
|
85 |
SetActive();
|
|
86 |
}
|
|
87 |
|
|
88 |
return error;
|
|
89 |
}
|
|
90 |
|
|
91 |
// -----------------------------------------------------------------------------
|
|
92 |
// CHsProcessMonitor::CHsProcessMonitor()
|
|
93 |
// C++ default constructor can NOT contain any code, that might leave.
|
|
94 |
// -----------------------------------------------------------------------------
|
|
95 |
CHsProcessMonitor::CHsProcessMonitor( const TInt aProcessId,
|
|
96 |
MHsProcessMonitorObserver& aObserver ) :
|
|
97 |
CActive( EPriorityStandard ),
|
|
98 |
iProcessId( aProcessId ),
|
|
99 |
iObserver( aObserver ),
|
|
100 |
iProcessHandleOpen( EFalse )
|
|
101 |
{
|
|
102 |
CActiveScheduler::Add( this );
|
|
103 |
}
|
|
104 |
|
|
105 |
// -----------------------------------------------------------------------------
|
|
106 |
// CHsProcessMonitor::ConstructL()
|
|
107 |
// Symbian 2nd phase constructor can leave.
|
|
108 |
// -----------------------------------------------------------------------------
|
|
109 |
//
|
|
110 |
void CHsProcessMonitor::ConstructL()
|
|
111 |
{
|
|
112 |
}
|
|
113 |
|
|
114 |
// -----------------------------------------------------------------------------
|
|
115 |
// CHsProcessMonitor::RunL
|
|
116 |
// -----------------------------------------------------------------------------
|
|
117 |
//
|
|
118 |
void CHsProcessMonitor::RunL()
|
|
119 |
{
|
|
120 |
iProcess.LogonCancel( iStatus );
|
|
121 |
|
|
122 |
const TInt error = iStatus.Int();
|
|
123 |
|
|
124 |
if( error == KErrCancel )
|
|
125 |
{
|
|
126 |
}
|
|
127 |
else if( error == KErrNoMemory )
|
|
128 |
{
|
|
129 |
User::Leave( KErrNoMemory );
|
|
130 |
}
|
|
131 |
else
|
|
132 |
{
|
|
133 |
const TExitType exitType = iProcess.ExitType();
|
|
134 |
if( exitType == EExitPending )
|
|
135 |
{
|
|
136 |
User::LeaveIfError( StartMonitor() );
|
|
137 |
}
|
|
138 |
else
|
|
139 |
{
|
|
140 |
iObserver.ProcessEnded( exitType,
|
|
141 |
iProcess.ExitReason(),
|
|
142 |
iProcess.ExitCategory() );
|
|
143 |
}
|
|
144 |
}
|
|
145 |
}
|
|
146 |
|
|
147 |
// -----------------------------------------------------------------------------
|
|
148 |
// CHsProcessMonitor::DoCancel()
|
|
149 |
// From CActive.
|
|
150 |
// -----------------------------------------------------------------------------
|
|
151 |
//
|
|
152 |
void CHsProcessMonitor::DoCancel()
|
|
153 |
{
|
|
154 |
iProcess.LogonCancel( iStatus );
|
|
155 |
}
|
|
156 |
|
|
157 |
// -----------------------------------------------------------------------------
|
|
158 |
// CHsProcessMonitor::RunError()
|
|
159 |
// From CActive.
|
|
160 |
// -----------------------------------------------------------------------------
|
|
161 |
//
|
|
162 |
TInt CHsProcessMonitor::RunError( TInt aError )
|
|
163 |
{
|
|
164 |
iObserver.ProcessMonitoringError( aError );
|
|
165 |
|
|
166 |
// Observer will handle error. Return green light.
|
|
167 |
return KErrNone;
|
|
168 |
}
|
|
169 |
|
|
170 |
// -----------------------------------------------------------------------------
|
|
171 |
// CHsProcessMonitor::SecureProcessHandleAsClosed()
|
|
172 |
// Close process handle if open
|
|
173 |
// -----------------------------------------------------------------------------
|
|
174 |
//
|
|
175 |
void CHsProcessMonitor::SecureProcessHandleAsClosed()
|
|
176 |
{
|
|
177 |
if( iProcessHandleOpen )
|
|
178 |
{
|
|
179 |
iProcess.Close();
|
|
180 |
iProcessHandleOpen = EFalse;
|
|
181 |
}
|
|
182 |
}
|
|
183 |
|
|
184 |
// End of File
|