1 /* |
|
2 * Copyright (c) 2002-2007 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: Monitors browser's thread death. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <etelsat.h> |
|
21 #include <e32std.h> |
|
22 #include "msatbrowserthreadobserver.h" |
|
23 #include "CSatBrowserThreadMonitor.h" |
|
24 #include "SatLog.h" |
|
25 |
|
26 |
|
27 // ================= MEMBER FUNCTIONS ========================================== |
|
28 |
|
29 // ----------------------------------------------------------------------------- |
|
30 // CSatBrowserThreadMonitor::CSatBrowserThreadMonitor |
|
31 // The class constructor |
|
32 // ----------------------------------------------------------------------------- |
|
33 // |
|
34 CSatBrowserThreadMonitor::CSatBrowserThreadMonitor( |
|
35 const RThread& aThread ) : |
|
36 CActive( EPriorityStandard ), |
|
37 iThread( aThread ) |
|
38 { |
|
39 LOG( SIMPLE, |
|
40 "SATEVENTMONITORS: CSatBrowserThreadMonitor::CSatBrowserThreadMonitor \ |
|
41 calling" ) |
|
42 |
|
43 CActiveScheduler::Add( this ); |
|
44 |
|
45 LOG( SIMPLE, |
|
46 "SATEVENTMONITORS: CSatBrowserThreadMonitor::CSatBrowserThreadMonitor \ |
|
47 exiting" ) |
|
48 } |
|
49 |
|
50 // ----------------------------------------------------------------------------- |
|
51 // CSatSBrowserTerminationMonitor::NewL |
|
52 // Two-phased constructor |
|
53 // ----------------------------------------------------------------------------- |
|
54 // |
|
55 CSatBrowserThreadMonitor* CSatBrowserThreadMonitor::NewL( |
|
56 const RThread& aThread ) |
|
57 { |
|
58 LOG( SIMPLE, "SATEVENTMONITORS: CSatBrowserThreadMonitor::NewL calling" ) |
|
59 |
|
60 CSatBrowserThreadMonitor* self = |
|
61 new( ELeave )CSatBrowserThreadMonitor( aThread ); |
|
62 |
|
63 LOG( SIMPLE, "SATEVENTMONITORS: CSatBrowserThreadMonitor::NewL exiting" ) |
|
64 return self; |
|
65 } |
|
66 |
|
67 // ----------------------------------------------------------------------------- |
|
68 // CSatBrowserThreadMonitor::~CSatBrowserThreadMonitor |
|
69 // Destructor |
|
70 // ----------------------------------------------------------------------------- |
|
71 // |
|
72 CSatBrowserThreadMonitor::~CSatBrowserThreadMonitor() |
|
73 { |
|
74 LOG( SIMPLE, "SATEVENTMONITORS: CSatBrowserThreadMonitor::\ |
|
75 ~CSatBrowserThreadMonitor calling" ) |
|
76 |
|
77 // Cancel any outstanding requests. |
|
78 Cancel(); |
|
79 iThread.Close(); |
|
80 |
|
81 iObserver = NULL; |
|
82 |
|
83 LOG( SIMPLE, "SATEVENTMONITORS: CSatBrowserThreadMonitor::\ |
|
84 ~CSatBrowserThreadMonitor exiting" ) |
|
85 } |
|
86 |
|
87 // ----------------------------------------------------------------------------- |
|
88 // CSatBrowserThreadMonitor::StartMonitor |
|
89 // Starts the handler. |
|
90 // ----------------------------------------------------------------------------- |
|
91 // |
|
92 void CSatBrowserThreadMonitor::StartMonitor( |
|
93 MSatBrowserThreadObserver* aObserver ) |
|
94 { |
|
95 LOG( SIMPLE, |
|
96 "SATEVENTMONITORS: CSatBrowserThreadMonitor::StartMonitor calling" ) |
|
97 |
|
98 iObserver = aObserver; |
|
99 |
|
100 Start(); |
|
101 |
|
102 LOG( SIMPLE, |
|
103 "SATEVENTMONITORS: CSatBrowserThreadMonitor::StartMonitor exiting" ) |
|
104 } |
|
105 |
|
106 // ----------------------------------------------------------------------------- |
|
107 // CSatBrowserThreadMonitor::Start |
|
108 // Starts the handler. |
|
109 // ----------------------------------------------------------------------------- |
|
110 // |
|
111 void CSatBrowserThreadMonitor::Start() |
|
112 { |
|
113 LOG( SIMPLE, "SATEVENTMONITORS: CSatBrowserThreadMonitor::Start calling" ) |
|
114 |
|
115 // Just in case. |
|
116 Cancel(); |
|
117 |
|
118 // Monitor changes only in Browser Thread. |
|
119 iThread.Logon( iStatus ); |
|
120 SetActive(); |
|
121 |
|
122 LOG( SIMPLE, "SATEVENTMONITORS: CSatBrowserThreadMonitor::Start exiting" ) |
|
123 } |
|
124 |
|
125 // ----------------------------------------------------------------------------- |
|
126 // CSatBrowserThreadMonitor::DoCancelMonitor |
|
127 // ----------------------------------------------------------------------------- |
|
128 // |
|
129 void CSatBrowserThreadMonitor::DoCancelMonitor() |
|
130 { |
|
131 LOG( SIMPLE, "SATEVENTMONITORS: CSatBrowserThreadMonitor::\ |
|
132 DoCancelMonitor calling" ) |
|
133 |
|
134 Cancel(); |
|
135 |
|
136 LOG( SIMPLE, "SATEVENTMONITORS: CSatBrowserThreadMonitor::\ |
|
137 DoCancelMonitor exiting" ) |
|
138 } |
|
139 |
|
140 // ----------------------------------------------------------------------------- |
|
141 // CSatBrowserThreadMonitor::RunL |
|
142 // Handles the command. |
|
143 // ----------------------------------------------------------------------------- |
|
144 // |
|
145 void CSatBrowserThreadMonitor::RunL() |
|
146 { |
|
147 LOG( SIMPLE, "SATEVENTMONITORS: CSatBrowserThreadMonitor::RunL calling" ) |
|
148 |
|
149 const TExitType exitType( iThread.ExitType() ); |
|
150 |
|
151 // Check whether the thread is alive. |
|
152 if ( EExitPending == exitType ) |
|
153 { |
|
154 LOG( SIMPLE, "SATEVENTMONITORS: CSatBrowserThreadMonitor::RunL() | \ |
|
155 iThread.ExitType = EExitPending , renew the request" ) |
|
156 // Renew the request. |
|
157 Start(); |
|
158 } |
|
159 // Thread has exited |
|
160 else |
|
161 { |
|
162 LOG2( SIMPLE, "SATEVENTMONITORS: CSatBrowserThreadMonitor::RunL() | \ |
|
163 Thread has exited with exit code %i", exitType ) |
|
164 |
|
165 // Why did the browser exit. |
|
166 RSat::TBrowserTerminationCause cause( ExitCause() ); |
|
167 |
|
168 // Call the event monitor with the cause of the thread termination. |
|
169 iObserver->NotifyBrowserTerminated( cause ); |
|
170 } |
|
171 LOG( SIMPLE, "SATEVENTMONITORS: CSatBrowserThreadMonitor::RunL exiting" ) |
|
172 } |
|
173 |
|
174 // ----------------------------------------------------------------------------- |
|
175 // CSatBrowserThreadMonitor::DoCancel |
|
176 // Cancels the pending request. |
|
177 // ----------------------------------------------------------------------------- |
|
178 // |
|
179 void CSatBrowserThreadMonitor::DoCancel() |
|
180 { |
|
181 LOG( SIMPLE, |
|
182 "SATEVENTMONITORS: CSatBrowserThreadMonitor::DoCancel calling" ) |
|
183 |
|
184 // No longer monitor this thread. |
|
185 iThread.LogonCancel( iStatus ); |
|
186 |
|
187 LOG( SIMPLE, |
|
188 "SATEVENTMONITORS: CSatBrowserThreadMonitor::DoCancel exiting" ) |
|
189 } |
|
190 |
|
191 // ----------------------------------------------------------------------------- |
|
192 // CSatBrowserThreadMonitor::ExitCause |
|
193 // Why did the application close. |
|
194 // ----------------------------------------------------------------------------- |
|
195 // |
|
196 RSat::TBrowserTerminationCause CSatBrowserThreadMonitor::ExitCause() const |
|
197 { |
|
198 LOG( SIMPLE, |
|
199 "SATEVENTMONITORS: CSatBrowserThreadMonitor::ExitCause calling" ) |
|
200 |
|
201 TExitType exitType = iThread.ExitType(); |
|
202 RSat::TBrowserTerminationCause terminationCause; |
|
203 LOG2( SIMPLE, |
|
204 "SATEVENTMONITORS: CSatBrowserThreadMonitor::ExitCause exitType: %d", |
|
205 exitType ) |
|
206 switch ( exitType ) |
|
207 { |
|
208 // The thread has ended as a result of a kill. |
|
209 // i.e. Kill() has been called on the RThread. |
|
210 case EExitKill: |
|
211 { |
|
212 terminationCause = RSat::EUserTermination; |
|
213 break; |
|
214 } |
|
215 |
|
216 // The thread has been panicked. |
|
217 case EExitPanic: |
|
218 { |
|
219 terminationCause = RSat::EErrorTermination; |
|
220 break; |
|
221 } |
|
222 |
|
223 // The thread ended for unknown reasons. |
|
224 default: |
|
225 { |
|
226 terminationCause = RSat::EUnknownCause; |
|
227 break; |
|
228 } |
|
229 } |
|
230 |
|
231 LOG2( SIMPLE, "SATEVENTMONITORS: CSatBrowserThreadMonitor::\ |
|
232 ExitCause exiting with value: %d", terminationCause ) |
|
233 return terminationCause; |
|
234 } |
|
235 |
|
236 // End of File |
|