48 // ----------------------------------------------------------------------------- |
47 // ----------------------------------------------------------------------------- |
49 // |
48 // |
50 CIAUpdateManager* CIAUpdateManager::NewLC( MIAUpdateObserver& aObserver ) |
49 CIAUpdateManager* CIAUpdateManager::NewLC( MIAUpdateObserver& aObserver ) |
51 { |
50 { |
52 IAUPDATE_TRACE("[IAUPDATE] CIAUpdateManager::NewLC() begin"); |
51 IAUPDATE_TRACE("[IAUPDATE] CIAUpdateManager::NewLC() begin"); |
53 CIAUpdateManager* self = new( ELeave ) CIAUpdateManager( aObserver ); |
52 CIAUpdateManager* self = new( ELeave ) CIAUpdateManager(); |
54 CleanupStack::PushL( self ); |
53 CleanupStack::PushL( self ); |
55 self->ConstructL(); |
54 self->ConstructL( aObserver ); |
56 IAUPDATE_TRACE("[IAUPDATE] CIAUpdateManager::NewLC() end"); |
55 IAUPDATE_TRACE("[IAUPDATE] CIAUpdateManager::NewLC() end"); |
57 return self; |
56 return self; |
58 } |
57 } |
59 |
58 |
60 // ----------------------------------------------------------------------------- |
59 // ----------------------------------------------------------------------------- |
61 // CIAUpdateManager::CIAUpdateManager |
60 // CIAUpdateManager::CIAUpdateManager |
62 // |
61 // |
63 // ----------------------------------------------------------------------------- |
62 // ----------------------------------------------------------------------------- |
64 // |
63 // |
65 CIAUpdateManager::CIAUpdateManager( MIAUpdateObserver& aObserver ) |
64 CIAUpdateManager::CIAUpdateManager() |
66 : CActive( CActive::EPriorityStandard ), |
|
67 iObserver( aObserver ), |
|
68 iUpdateType( EIAUpdateIdle ) |
|
69 { |
65 { |
70 IAUPDATE_TRACE("[IAUPDATE] CIAUpdateManager::CIAUpdateManager()"); |
66 IAUPDATE_TRACE("[IAUPDATE] CIAUpdateManager::CIAUpdateManager()"); |
71 iEikEnv = CEikonEnv::Static(); |
67 iEikEnv = CEikonEnv::Static(); |
72 } |
68 } |
73 |
69 |
74 // ----------------------------------------------------------------------------- |
70 // ----------------------------------------------------------------------------- |
75 // CIAUpdateManager::ConstructL() |
71 // CIAUpdateManager::ConstructL() |
76 // |
72 // |
77 // ----------------------------------------------------------------------------- |
73 // ----------------------------------------------------------------------------- |
78 // |
74 // |
79 void CIAUpdateManager::ConstructL() |
75 void CIAUpdateManager::ConstructL( MIAUpdateObserver& aObserver ) |
80 { |
76 { |
81 IAUPDATE_TRACE("[IAUPDATE] CIAUpdateManager::ConstructL() begin"); |
77 IAUPDATE_TRACE("[IAUPDATE] CIAUpdateManager::ConstructL() begin"); |
82 CActiveScheduler::Add( this ); |
78 iUpdateClient = new IAUpdateClient( aObserver ); |
|
79 if ( !iUpdateClient ) |
|
80 { |
|
81 User::Leave(KErrNoMemory); |
|
82 } |
83 if ( iEikEnv ) |
83 if ( iEikEnv ) |
84 { |
84 { |
85 iEikEnv->AddForegroundObserverL(*this); |
85 iEikEnv->AddForegroundObserverL(*this); |
86 } |
86 } |
87 IAUPDATE_TRACE("[IAUPDATE] CIAUpdateManager::ConstructL() end"); |
87 IAUPDATE_TRACE("[IAUPDATE] CIAUpdateManager::ConstructL() end"); |
112 // ----------------------------------------------------------------------------- |
109 // ----------------------------------------------------------------------------- |
113 // |
110 // |
114 void CIAUpdateManager::CheckUpdates( const CIAUpdateParameters& aUpdateParameters ) |
111 void CIAUpdateManager::CheckUpdates( const CIAUpdateParameters& aUpdateParameters ) |
115 { |
112 { |
116 IAUPDATE_TRACE("[IAUPDATE] CIAUpdateManager::CheckUpdates() begin"); |
113 IAUPDATE_TRACE("[IAUPDATE] CIAUpdateManager::CheckUpdates() begin"); |
117 if ( BusyCheck() ) |
114 |
118 { |
115 iUpdateClient->checkUpdates( aUpdateParameters ); |
119 // An operation is already going on. |
|
120 // Do not continue with this new operation. |
|
121 // Only, inform the observer with the error code. |
|
122 // Notice that the callback is called synchronously here |
|
123 // because there is no better way to do it. Asynchronous way |
|
124 // would be really cumbersome because this object is already active. |
|
125 // This error is users fault. Therefore we, could also panic here. |
|
126 Observer().CheckUpdatesComplete( KErrServerBusy, 0 ); |
|
127 return; |
|
128 } |
|
129 |
116 |
130 // Reset result values because we are starting a new operation. |
|
131 ResetResults(); |
|
132 |
|
133 // Set the update type. |
|
134 // So, we know later in RunL what operation was requested. |
|
135 SetUpdateType( EIAUpdateCheck ); |
|
136 |
|
137 TInt error( UpdateClient().Open( ETrue) ); |
|
138 if ( error == KErrNone ) |
|
139 { |
|
140 error = |
|
141 UpdateClient().CheckUpdates( aUpdateParameters, |
|
142 iSuccessCount, |
|
143 iStatus ); |
|
144 } |
|
145 |
|
146 if ( error == KErrNone ) |
|
147 { |
|
148 // Set this object active. |
|
149 // Because everything went ok, |
|
150 // the operation will be handled asynchronously |
|
151 // and the service provider will inform us when the operation |
|
152 // is finished. |
|
153 SetActive(); |
|
154 } |
|
155 else |
|
156 { |
|
157 // Because we are going to activate this active object, |
|
158 // set the status pending. |
|
159 iStatus = KRequestPending; |
|
160 |
|
161 // An error occurred above. |
|
162 // Therefore, the operation did not proceed any further. |
|
163 // Set this object active for asynchronous error handling. |
|
164 SetActive(); |
|
165 |
|
166 // Now, that everything is ready, just inform the active scheduler |
|
167 // that operation is finished. Pass the error code for the observer. |
|
168 TRequestStatus* status( &iStatus ); |
|
169 User::RequestComplete( status, error ); |
|
170 } |
|
171 IAUPDATE_TRACE("[IAUPDATE] CIAUpdateManager::CheckUpdates() end"); |
117 IAUPDATE_TRACE("[IAUPDATE] CIAUpdateManager::CheckUpdates() end"); |
172 } |
118 } |
173 |
119 |
174 // ----------------------------------------------------------------------------- |
120 // ----------------------------------------------------------------------------- |
175 // CIAUpdateManager::ShowUpdates |
121 // CIAUpdateManager::ShowUpdates |
177 // ----------------------------------------------------------------------------- |
123 // ----------------------------------------------------------------------------- |
178 // |
124 // |
179 void CIAUpdateManager::ShowUpdates( const CIAUpdateParameters& aUpdateParameters ) |
125 void CIAUpdateManager::ShowUpdates( const CIAUpdateParameters& aUpdateParameters ) |
180 { |
126 { |
181 IAUPDATE_TRACE("[IAUPDATE] CIAUpdateManager::ShowUpdates() begin"); |
127 IAUPDATE_TRACE("[IAUPDATE] CIAUpdateManager::ShowUpdates() begin"); |
182 if ( BusyCheck() ) |
128 iUpdateClient->showUpdates( aUpdateParameters ); |
183 { |
|
184 // An update operation is already going on. |
|
185 // Do not continue with this new operation. |
|
186 // Only, inform the observer with the error code. |
|
187 // Notice that the callback is called synchronously here |
|
188 // because there is no better way to do it. Asynchronous way |
|
189 // would be really cumbersome because this object is already active. |
|
190 // This error is users fault. Therefore we, could also panic here. |
|
191 Observer().UpdateComplete( KErrServerBusy, NULL ); |
|
192 return; |
|
193 } |
|
194 |
129 |
195 // Reset result values because we are starting a new operation. |
|
196 ResetResults(); |
|
197 |
|
198 // Set the update type. |
|
199 // So, we know later in RunL what operation was requested. |
|
200 SetUpdateType( EIAUpdateUpdate ); |
|
201 |
|
202 TInt error( UpdateClient().Open( EFalse ) ); |
|
203 if ( error == KErrNone ) |
|
204 { |
|
205 error = |
|
206 UpdateClient().ShowUpdates( aUpdateParameters, |
|
207 iSuccessCount, |
|
208 iFailCount, |
|
209 iCancelCount, |
|
210 iStatus ); |
|
211 } |
|
212 |
|
213 if ( error == KErrNone ) |
|
214 { |
|
215 // Set this object active. |
|
216 // Because everything went ok, |
|
217 // the operation will be handled asynchronously |
|
218 // and the service provider will inform us when the operation |
|
219 // is finished. |
|
220 SetActive(); |
|
221 } |
|
222 else |
|
223 { |
|
224 // Because we are going to activate this active object, |
|
225 // set the status pending. |
|
226 iStatus = KRequestPending; |
|
227 |
|
228 // An error occurred above. |
|
229 // Therefore, the operation did not proceed any further. |
|
230 // Set this object active for asynchronous error handling. |
|
231 SetActive(); |
|
232 |
|
233 // Now, that everything is ready, just inform the active scheduler |
|
234 // that operation is finished. Pass the error code for the observer. |
|
235 TRequestStatus* status( &iStatus ); |
|
236 User::RequestComplete( status, error ); |
|
237 } |
|
238 IAUPDATE_TRACE("[IAUPDATE] CIAUpdateManager::ShowUpdates() end"); |
130 IAUPDATE_TRACE("[IAUPDATE] CIAUpdateManager::ShowUpdates() end"); |
239 } |
131 } |
240 |
132 |
241 // ----------------------------------------------------------------------------- |
133 // ----------------------------------------------------------------------------- |
242 // CIAUpdateManager::Update |
134 // CIAUpdateManager::Update |
258 // ----------------------------------------------------------------------------- |
150 // ----------------------------------------------------------------------------- |
259 // |
151 // |
260 void CIAUpdateManager::UpdateQuery() |
152 void CIAUpdateManager::UpdateQuery() |
261 { |
153 { |
262 IAUPDATE_TRACE("[IAUPDATE] CIAUpdateManager::UpdateQuery() begin"); |
154 IAUPDATE_TRACE("[IAUPDATE] CIAUpdateManager::UpdateQuery() begin"); |
263 if ( BusyCheck() ) |
|
264 { |
|
265 // An update operation is already going on. |
|
266 // Do not continue with this new operation. |
|
267 // Only, inform the observer with the error code. |
|
268 // Notice that the callback is called synchronously here |
|
269 // because there is no better way to do it. Asynchronous way |
|
270 // would be really cumbersome because this object is already active. |
|
271 // This error is users fault. Therefore we, could also panic here. |
|
272 Observer().UpdateQueryComplete( KErrServerBusy, EFalse ); |
|
273 return; |
|
274 } |
|
275 |
|
276 // Reset result values because we are starting a new operation. |
|
277 ResetResults(); |
|
278 |
|
279 // Set the update type. |
|
280 // So, we know later in RunL what operation was requested. |
|
281 SetUpdateType( EIAUpdateQuery ); |
|
282 |
|
283 TInt error( UpdateClient().Open( EFalse ) ); |
|
284 if ( error == KErrNone ) |
|
285 { |
|
286 error = |
|
287 UpdateClient().UpdateQuery( iUpdateNow, iStatus ); |
|
288 } |
|
289 |
|
290 if ( error == KErrNone ) |
|
291 { |
|
292 // Set this object active. |
|
293 // Because everything went ok, |
|
294 // the operation will be handled asynchronously |
|
295 // and the service provider will inform us when the operation |
|
296 // is finished. |
|
297 SetActive(); |
|
298 } |
|
299 else |
|
300 { |
|
301 // Because we are going to activate this active object, |
|
302 // set the status pending. |
|
303 iStatus = KRequestPending; |
|
304 |
155 |
305 // An error occurred above. |
156 iUpdateClient->updateQuery(); |
306 // Therefore, the operation did not proceed any further. |
157 |
307 // Set this object active for asynchronous error handling. |
|
308 SetActive(); |
|
309 |
|
310 // Now, that everything is ready, just inform the active scheduler |
|
311 // that operation is finished. Pass the error code for the observer. |
|
312 TRequestStatus* status( &iStatus ); |
|
313 User::RequestComplete( status, error ); |
|
314 } |
|
315 IAUPDATE_TRACE("[IAUPDATE] CIAUpdateManager::UpdateQuery() end"); |
158 IAUPDATE_TRACE("[IAUPDATE] CIAUpdateManager::UpdateQuery() end"); |
316 } |
159 } |
317 |
160 |
318 // ----------------------------------------------------------------------------- |
|
319 // CIAUpdateManager::DoCancel |
|
320 // |
|
321 // ----------------------------------------------------------------------------- |
|
322 // |
|
323 void CIAUpdateManager::DoCancel() |
|
324 { |
|
325 IAUPDATE_TRACE("[IAUPDATE] CIAUpdateManager::DoCancel() begin"); |
|
326 UpdateClient().CancelAsyncRequest(); |
|
327 |
161 |
328 // Reset result values because we are starting a new operation. |
|
329 ResetResults(); |
|
330 IAUPDATE_TRACE("[IAUPDATE] CIAUpdateManager::DoCancel() end"); |
|
331 } |
|
332 |
|
333 // ----------------------------------------------------------------------------- |
|
334 // CIAUpdateManager::RunL |
|
335 // |
|
336 // ----------------------------------------------------------------------------- |
|
337 // |
|
338 void CIAUpdateManager::RunL() |
|
339 { |
|
340 IAUPDATE_TRACE("[IAUPDATE] CIAUpdateManager::RunL() begin"); |
|
341 // Update operation error code |
|
342 TInt errorCode( iStatus.Int() ); |
|
343 IAUPDATE_TRACE_1("[IAUPDATE] error code: %d", errorCode ); |
|
344 if ( errorCode == KErrServerTerminated ) |
|
345 { |
|
346 // Handle is released if server is terminated |
|
347 UpdateClient().Close(); |
|
348 } |
|
349 |
|
350 // Variables for operation and result information. |
|
351 TIAUpdateType updateType( UpdateType() ); |
|
352 IAUPDATE_TRACE_1("[IAUPDATE] update type: %d", updateType ); |
|
353 CIAUpdateResult* updateResult( NULL ); |
|
354 |
|
355 if ( updateType == EIAUpdateUpdate ) |
|
356 { |
|
357 // Update result object is required. |
|
358 // Notice that the ownership is transferred later. |
|
359 // So, this function does not need to delete updateResult object. |
|
360 TRAPD( trapError, updateResult = CIAUpdateResult::NewL() ); |
|
361 if ( updateResult ) |
|
362 { |
|
363 updateResult->SetSuccessCount( iSuccessCount ); |
|
364 updateResult->SetFailCount( iFailCount ); |
|
365 updateResult->SetCancelCount( iCancelCount ); |
|
366 } |
|
367 else |
|
368 { |
|
369 // Something went wrong when creating update result object. |
|
370 // Update the error code accordingly. |
|
371 errorCode = trapError; |
|
372 } |
|
373 // Let's assume that connection is not needed anymore |
|
374 UpdateClient().Close(); |
|
375 } |
|
376 |
|
377 |
|
378 // Inform that no operation is going on anymore. |
|
379 // This is required for busy check. |
|
380 SetUpdateType( EIAUpdateIdle ); |
|
381 |
|
382 // Use the update type of the ongoing operation to check what callback |
|
383 // function to call. |
|
384 switch ( updateType ) |
|
385 { |
|
386 case EIAUpdateCheck: |
|
387 if ( iSuccessCount == 0 ) |
|
388 { |
|
389 // Let's assume that connection is not needed anymore |
|
390 UpdateClient().Close(); |
|
391 } |
|
392 IAUPDATE_TRACE_1("[IAUPDATE] success count: %d", iSuccessCount ); |
|
393 Observer().CheckUpdatesComplete( errorCode, iSuccessCount ); |
|
394 break; |
|
395 |
|
396 case EIAUpdateUpdate: |
|
397 // Notice that ownership of result object is transferred here. |
|
398 IAUPDATE_TRACE_3("[IAUPDATE] success count: %d failed count: %d cancelled count: %d", iSuccessCount, iFailCount, iCancelCount ); |
|
399 Observer().UpdateComplete( errorCode, updateResult ); |
|
400 break; |
|
401 |
|
402 case EIAUpdateQuery: |
|
403 if ( !iUpdateNow ) |
|
404 { |
|
405 // Let's assume that connection is not needed anymore |
|
406 UpdateClient().Close(); |
|
407 } |
|
408 IAUPDATE_TRACE_1("[IAUPDATE] update now: %d", iUpdateNow ); |
|
409 Observer().UpdateQueryComplete( errorCode, iUpdateNow ); |
|
410 break; |
|
411 |
|
412 default: |
|
413 // Should not ever come here. |
|
414 break; |
|
415 } |
|
416 |
|
417 // Do not anything else than return after callback function is called because |
|
418 // this instance can be deleted by a client in a callback function |
|
419 // |
|
420 IAUPDATE_TRACE("[IAUPDATE] CIAUpdateManager::RunL() end"); |
|
421 } |
|
422 |
|
423 // ----------------------------------------------------------------------------- |
|
424 // CIAUpdateManager::ResetResults |
|
425 // |
|
426 // ----------------------------------------------------------------------------- |
|
427 // |
|
428 void CIAUpdateManager::ResetResults() |
|
429 { |
|
430 IAUPDATE_TRACE("[IAUPDATE] CIAUpdateManager::ResetResults() begin"); |
|
431 // Set the member variables to their default values. |
|
432 iSuccessCount = 0; |
|
433 iFailCount = 0; |
|
434 iCancelCount = 0; |
|
435 iUpdateNow = EFalse; |
|
436 IAUPDATE_TRACE("[IAUPDATE] CIAUpdateManager::ResetResults() end"); |
|
437 } |
|
438 |
|
439 // ----------------------------------------------------------------------------- |
|
440 // CIAUpdateManager::BusyCheck |
|
441 // |
|
442 // ----------------------------------------------------------------------------- |
|
443 // |
|
444 TBool CIAUpdateManager::BusyCheck() const |
|
445 { |
|
446 IAUPDATE_TRACE("[IAUPDATE] CIAUpdateManager::BusyCheck()"); |
|
447 if ( UpdateType() == EIAUpdateIdle ) |
|
448 { |
|
449 return EFalse; |
|
450 } |
|
451 else |
|
452 { |
|
453 return ETrue; |
|
454 } |
|
455 } |
|
456 |
|
457 // ----------------------------------------------------------------------------- |
|
458 // CIAUpdateManager::UpdateClient |
|
459 // |
|
460 // ----------------------------------------------------------------------------- |
|
461 // |
|
462 RIAUpdateClient& CIAUpdateManager::UpdateClient() |
|
463 { |
|
464 IAUPDATE_TRACE("[IAUPDATE] CIAUpdateManager::UpdateClient()"); |
|
465 return iUpdateClient; |
|
466 } |
|
467 |
|
468 // ----------------------------------------------------------------------------- |
|
469 // CIAUpdateManager::Observer |
|
470 // |
|
471 // ----------------------------------------------------------------------------- |
|
472 // |
|
473 MIAUpdateObserver& CIAUpdateManager::Observer() const |
|
474 { |
|
475 IAUPDATE_TRACE("[IAUPDATE] CIAUpdateManager::Observer()"); |
|
476 return iObserver; |
|
477 } |
|
478 |
|
479 // ----------------------------------------------------------------------------- |
|
480 // CIAUpdateManager::UpdateType |
|
481 // |
|
482 // ----------------------------------------------------------------------------- |
|
483 // |
|
484 CIAUpdateManager::TIAUpdateType CIAUpdateManager::UpdateType() const |
|
485 { |
|
486 IAUPDATE_TRACE("[IAUPDATE] CIAUpdateManager::UpdateType()"); |
|
487 return iUpdateType; |
|
488 } |
|
489 |
|
490 |
|
491 // ----------------------------------------------------------------------------- |
|
492 // CIAUpdateManager::SetUpdateType |
|
493 // |
|
494 // ----------------------------------------------------------------------------- |
|
495 // |
|
496 void CIAUpdateManager::SetUpdateType( CIAUpdateManager::TIAUpdateType aUpdateType ) |
|
497 { |
|
498 IAUPDATE_TRACE("[IAUPDATE] CIAUpdateManager::SetUpdateType() begin"); |
|
499 IAUPDATE_TRACE_1("[IAUPDATE] update type: %d", aUpdateType ); |
|
500 iUpdateType = aUpdateType; |
|
501 IAUPDATE_TRACE("[IAUPDATE] CIAUpdateManager::SetUpdateType() end"); |
|
502 } |
|
503 |
|
504 // ----------------------------------------------------------------------------- |
162 // ----------------------------------------------------------------------------- |
505 // CIAUpdateManager::HandleGainingForeground |
163 // CIAUpdateManager::HandleGainingForeground |
506 // iaupdate.exe is brought to foreground if visible request is ongoing |
164 // iaupdate.exe is brought to foreground if visible request is ongoing |
507 // ----------------------------------------------------------------------------- |
165 // ----------------------------------------------------------------------------- |
508 // |
166 // |
509 void CIAUpdateManager::HandleGainingForeground() |
167 void CIAUpdateManager::HandleGainingForeground() |
510 { |
168 { |
511 IAUPDATE_TRACE("[IAUPDATE] CIAUpdateManager::HandleGainingForeground() begin"); |
169 IAUPDATE_TRACE("[IAUPDATE] CIAUpdateManager::HandleGainingForeground() begin"); |
512 iUpdateClient.BroughtToForeground(); |
170 //iUpdateClient->broughtToForeground(); |
513 IAUPDATE_TRACE("[IAUPDATE] CIAUpdateManager::HandleGainingForeground() end"); |
171 IAUPDATE_TRACE("[IAUPDATE] CIAUpdateManager::HandleGainingForeground() end"); |
514 } |
172 } |
515 |
173 |
516 // ----------------------------------------------------------------------------- |
174 // ----------------------------------------------------------------------------- |
517 // CIAUpdateManager::HandleLosingForeground |
175 // CIAUpdateManager::HandleLosingForeground |