|
1 /* |
|
2 * Copyright (c) 2002-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: Monitor for browser termination |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <etelsat.h> |
|
21 #include <apgtask.h> |
|
22 #include <DocumentHandler.h> //KWmlcHandler |
|
23 #include "CSatBrowserThreadMonitor.h" |
|
24 #include "csatbrowserwsmonitor.h" |
|
25 #include "SatLog.h" |
|
26 |
|
27 // ======== MEMBER FUNCTIONS ======== |
|
28 |
|
29 // ----------------------------------------------------------------------------- |
|
30 // CSatBrowserWSMonitor::CSatBrowserWSMonitor |
|
31 // C++ default constructor can NOT contain any code, that |
|
32 // might leave. |
|
33 // ----------------------------------------------------------------------------- |
|
34 // |
|
35 CSatBrowserWSMonitor::CSatBrowserWSMonitor() : |
|
36 CActive( CActive::EPriorityStandard ) |
|
37 { |
|
38 LOG( SIMPLE, |
|
39 "SATEVENTMONITORS: CSatBrowserWSMonitor::CSatBrowserWSMonitor calling" ) |
|
40 |
|
41 CActiveScheduler::Add( this ); |
|
42 |
|
43 LOG( SIMPLE, |
|
44 "SATEVENTMONITORS: CSatBrowserWSMonitor::CSatBrowserWSMonitor exiting" ) |
|
45 } |
|
46 |
|
47 // Destructor |
|
48 CSatBrowserWSMonitor::~CSatBrowserWSMonitor() |
|
49 { |
|
50 LOG( SIMPLE, |
|
51 "SATEVENTMONITORS: CSatBrowserWSMonitor::~CSatBrowserWSMonitor calling" ) |
|
52 |
|
53 // Cancel any outstanding requests. |
|
54 Cancel(); |
|
55 |
|
56 if ( iThreadMonitor ) |
|
57 { |
|
58 iThreadMonitor->DoCancelMonitor(); |
|
59 delete iThreadMonitor; |
|
60 iThreadMonitor = NULL; |
|
61 } |
|
62 |
|
63 iObserver = NULL; |
|
64 |
|
65 iWg.Close(); |
|
66 iWsSession.Close(); |
|
67 |
|
68 LOG( SIMPLE, |
|
69 "SATEVENTMONITORS: CSatBrowserWSMonitor::~CSatBrowserWSMonitor exiting" ) |
|
70 } |
|
71 |
|
72 // ----------------------------------------------------------------------------- |
|
73 // CSatBrowserWSMonitor::NewL |
|
74 // Two-phased constructor. |
|
75 // ----------------------------------------------------------------------------- |
|
76 // |
|
77 CSatBrowserWSMonitor* CSatBrowserWSMonitor::NewL() |
|
78 { |
|
79 LOG( SIMPLE, |
|
80 "SATEVENTMONITORS: CSatBrowserWSMonitor::NewL calling" ) |
|
81 |
|
82 CSatBrowserWSMonitor* self = |
|
83 new ( ELeave ) CSatBrowserWSMonitor(); |
|
84 CleanupStack::PushL( self ); |
|
85 self->ConstructL(); |
|
86 CleanupStack::Pop( /*self*/ ); |
|
87 |
|
88 LOG( SIMPLE, |
|
89 "SATEVENTMONITORS: CSatBrowserWSMonitor::NewL exiting" ) |
|
90 return self; |
|
91 } |
|
92 |
|
93 // ----------------------------------------------------------------------------- |
|
94 // CSatBrowserWSMonitor::ConstructL |
|
95 // Symbian 2nd phase constructor can leave. |
|
96 // ----------------------------------------------------------------------------- |
|
97 // |
|
98 void CSatBrowserWSMonitor::ConstructL() |
|
99 { |
|
100 LOG( SIMPLE, |
|
101 "SATEVENTMONITORS: CSatBrowserWSMonitor::ConstructL calling" ) |
|
102 // Window session is created when event is requested |
|
103 LOG( SIMPLE, |
|
104 "SATEVENTMONITORS: CSatBrowserWSMonitor::ConstructL exiting" ) |
|
105 } |
|
106 |
|
107 // ----------------------------------------------------------------------------- |
|
108 // CSatBrowserWSMonitor::DoCancelMonitor |
|
109 // ----------------------------------------------------------------------------- |
|
110 // |
|
111 void CSatBrowserWSMonitor::DoCancelMonitor() |
|
112 { |
|
113 LOG( SIMPLE, "SATEVENTMONITORS: CSatBrowserWSMonitor::\ |
|
114 DoCancelMonitor calling" ) |
|
115 |
|
116 Cancel(); |
|
117 |
|
118 LOG( SIMPLE, "SATEVENTMONITORS: CSatBrowserWSMonitor::\ |
|
119 DoCancelMonitor exiting" ) |
|
120 } |
|
121 |
|
122 // ----------------------------------------------------------------------------- |
|
123 // CSatBrowserWSMonitor::StartMonitor |
|
124 // ----------------------------------------------------------------------------- |
|
125 // |
|
126 TInt CSatBrowserWSMonitor::StartMonitor( |
|
127 MSatBrowserWSObserver* aObserver ) |
|
128 { |
|
129 LOG( SIMPLE, |
|
130 "SATEVENTMONITORS: CSatBrowserWSMonitor::StartMonitor calling" ) |
|
131 TInt err( KErrNone ); |
|
132 |
|
133 if ( !iWGCreated ) |
|
134 { |
|
135 // First time called, create needed services |
|
136 LOG( SIMPLE,"SATEVENTMONITORS: CSatBrowserWSMonitor::StartMonitor \ |
|
137 connect to WsSession " ) |
|
138 err = iWsSession.Connect(); |
|
139 if ( KErrNone == err ) |
|
140 { |
|
141 // Creates a window group |
|
142 TRAP( err, CreateWGL() ); |
|
143 } |
|
144 } |
|
145 |
|
146 iObserver = aObserver; |
|
147 |
|
148 if ( !err ) |
|
149 { |
|
150 // All fine, start monitoring |
|
151 Start(); |
|
152 } |
|
153 |
|
154 LOG2( SIMPLE, |
|
155 "SATEVENTMONITORS: CSatBrowserWSMonitor::StartMonitor exiting err=%d",\ |
|
156 err ) |
|
157 |
|
158 return err; |
|
159 } |
|
160 |
|
161 // ----------------------------------------------------------------------------- |
|
162 // CSatBrowserWSMonitor::Start |
|
163 // ----------------------------------------------------------------------------- |
|
164 // |
|
165 void CSatBrowserWSMonitor::Start() |
|
166 { |
|
167 LOG( SIMPLE, "SATEVENTMONITORS: CSatBrowserWSMonitor::Start calling" ) |
|
168 |
|
169 Cancel(); |
|
170 |
|
171 // It migth be null already |
|
172 if ( iThreadMonitor ) |
|
173 { |
|
174 LOG( SIMPLE, |
|
175 "SATEVENTMONITORS: CSatBrowserWSMonitor::Start iThreadMonitor true" ) |
|
176 delete iThreadMonitor; |
|
177 iThreadMonitor = NULL; |
|
178 } |
|
179 |
|
180 iWsSession.EventReady( &iStatus ); |
|
181 SetActive(); |
|
182 |
|
183 LOG( SIMPLE, "SATEVENTMONITORS: CSatBrowserWSMonitor::Start exiting" ) |
|
184 } |
|
185 |
|
186 // ----------------------------------------------------------------------------- |
|
187 // CSatBrowserWSMonitor::RunL |
|
188 // Checks is the WML Browser launched and creates browser thread monitor to |
|
189 // monitor browsers thread death. |
|
190 // ----------------------------------------------------------------------------- |
|
191 // |
|
192 void CSatBrowserWSMonitor::RunL() |
|
193 { |
|
194 LOG( SIMPLE, |
|
195 "SATEVENTMONITORS: CSatBrowserWSMonitor::RunL calling" ) |
|
196 |
|
197 // Get the status of this object. |
|
198 const TInt errCode( iStatus.Int() ); |
|
199 LOG2( SIMPLE, |
|
200 "SATEVENTMONITORS: CSatBrowserWSMonitor::RunL errCode: %d", |
|
201 errCode ) |
|
202 if ( KErrNone == errCode ) |
|
203 { |
|
204 // UID Code for WML Browser in S60. |
|
205 const TUid uidWmlBrowser( TUid::Uid( KWmlcHandler ) ); |
|
206 TWsEvent event; |
|
207 iWsSession.GetEvent( event ); |
|
208 TApaTaskList taskList( iWsSession ); |
|
209 |
|
210 if ( taskList.FindApp( uidWmlBrowser ).Exists() ) |
|
211 { |
|
212 LOG( SIMPLE, |
|
213 "SATEVENTMONITORS: CSatBrowserWSMonitor::RunL task exists" ) |
|
214 const TApaTask task = taskList.FindApp( uidWmlBrowser ); |
|
215 const TThreadId threadID = task.ThreadId(); |
|
216 RThread thread; |
|
217 User::LeaveIfError ( thread.Open( threadID, EOwnerProcess ) ); |
|
218 |
|
219 // Create Browser thread monitor. |
|
220 iThreadMonitor = CSatBrowserThreadMonitor::NewL( thread ); |
|
221 |
|
222 // Call the active object to monitor for this threads death. |
|
223 iThreadMonitor->StartMonitor( this ); |
|
224 } |
|
225 else |
|
226 { |
|
227 LOG( SIMPLE, |
|
228 "SATEVENTMONITORS: CSatBrowserWSMonitor::RunL start" ) |
|
229 // Renew the request. |
|
230 Start(); |
|
231 } |
|
232 } |
|
233 else if ( KErrCancel != errCode ) |
|
234 { |
|
235 // Renew the request. |
|
236 Start(); |
|
237 } |
|
238 else |
|
239 { |
|
240 LOG( SIMPLE, |
|
241 "SATEVENTMONITORS: CSatBrowserWSMonitor::RunL cancelled" ) |
|
242 } |
|
243 |
|
244 LOG( SIMPLE, |
|
245 "SATEVENTMONITORS: CSatBrowserWSMonitor::RunL exiting" ) |
|
246 } |
|
247 |
|
248 // ----------------------------------------------------------------------------- |
|
249 // CSatBrowserWSMonitor::DoCancel |
|
250 // ----------------------------------------------------------------------------- |
|
251 // |
|
252 void CSatBrowserWSMonitor::DoCancel() |
|
253 { |
|
254 LOG( SIMPLE, |
|
255 "SATEVENTMONITORS: CSatBrowserWSMonitor::DoCancel calling" ) |
|
256 |
|
257 if ( iThreadMonitor ) |
|
258 { |
|
259 LOG( SIMPLE, |
|
260 "SATEVENTMONITORS: CSatBrowserWSMonitor::DoCancel iThreadMonitor true" ) |
|
261 iThreadMonitor->DoCancelMonitor(); |
|
262 } |
|
263 |
|
264 // Cancel the outstanding request. |
|
265 iWsSession.EventReadyCancel(); |
|
266 |
|
267 LOG( SIMPLE, |
|
268 "SATEVENTMONITORS: CSatBrowserWSMonitor::DoCancel exiting" ) |
|
269 } |
|
270 |
|
271 // ----------------------------------------------------------------------------- |
|
272 // CSatBrowserWSMonitor::NotifyBrowserTerminated |
|
273 // Sends event download notification to SAT Engine. |
|
274 // ----------------------------------------------------------------------------- |
|
275 // |
|
276 void CSatBrowserWSMonitor::NotifyBrowserTerminated( |
|
277 const RSat::TBrowserTerminationCause aCause ) |
|
278 { |
|
279 LOG( SIMPLE, "SATEVENTMONITORS: CSatBrowserWSMonitor::\ |
|
280 NotifyBrowserTerminated calling" ) |
|
281 |
|
282 // Notify termination to observer. |
|
283 iObserver->NotifyBrowserTerminated( aCause ); |
|
284 |
|
285 LOG( SIMPLE, "SATEVENTMONITORS: CSatBrowserWSMonitor::\ |
|
286 NotifyBrowserTerminated exiting" ) |
|
287 } |
|
288 |
|
289 // ----------------------------------------------------------------------------- |
|
290 // CSatBrowserWSMonitor::CreateWGL |
|
291 // Creates a window group and hides it form the UI. |
|
292 // ----------------------------------------------------------------------------- |
|
293 // |
|
294 void CSatBrowserWSMonitor::CreateWGL() |
|
295 { |
|
296 LOG( SIMPLE, |
|
297 "SATEVENTMONITORS: CSatBrowserWSMonitor::CreateWGL calling" ) |
|
298 |
|
299 // -1 means the window will never be visible. |
|
300 const TInt KWindowGroupPriority( -1 ); |
|
301 |
|
302 RWindowGroup wg( iWsSession ); |
|
303 // Make a handle from the address of window group obj. |
|
304 User::LeaveIfError( wg.Construct( reinterpret_cast<TUint32>( &wg ) ) ); |
|
305 // Enable group changed events. |
|
306 User::LeaveIfError( wg.EnableGroupChangeEvents() ); |
|
307 |
|
308 // Get the ordinal pos of this window group. |
|
309 const TInt ordPos( wg.OrdinalPosition() ); |
|
310 // Set SAT so its never shown in the UI. |
|
311 wg.SetOrdinalPosition( ordPos , KWindowGroupPriority ); |
|
312 |
|
313 // Needs to be a member variable. Must be closed in destructor. |
|
314 // Otherwise can't monitor what has been opened. |
|
315 iWg = wg; |
|
316 |
|
317 // Set SAT Server hidden now. |
|
318 iWsSession.Flush(); |
|
319 iWGCreated = ETrue; |
|
320 LOG( SIMPLE, |
|
321 "SATEVENTMONITORS: CSatBrowserWSMonitor::CreateWGL exiting" ) |
|
322 } |
|
323 |
|
324 // End of file |