wvuing/wvuieng/EngSrc/CCARequestMapper.cpp
changeset 0 094583676ce7
equal deleted inserted replaced
-1:000000000000 0:094583676ce7
       
     1 /*
       
     2 * Copyright (c) 2002-2005 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:  This is the storage of asynchronous imps requests.
       
    15 *
       
    16 */
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include "CCARequestMapper.h"			// Own header
       
    20 #include "CCARequest.h"
       
    21 #include "ChatDebugPrint.h"
       
    22 #include "PrivateEngineDefinitions.h"
       
    23 
       
    24 #include "MCABackgroundTask.h"
       
    25 #include "MCABackgroundObserver.h"
       
    26 #include "CCABackgroundTask.h"
       
    27 
       
    28 #include <e32base.h>
       
    29 // ============================ MEMBER FUNCTIONS ===============================
       
    30 
       
    31 // -----------------------------------------------------------------------------
       
    32 // CCARequestMapper::NewL
       
    33 // Two-phased constructor.
       
    34 // -----------------------------------------------------------------------------
       
    35 //
       
    36 CCARequestMapper* CCARequestMapper::NewL()
       
    37     {
       
    38     CCARequestMapper* self = new( ELeave ) CCARequestMapper;
       
    39 
       
    40     return self;
       
    41     }
       
    42 
       
    43 // -----------------------------------------------------------------------------
       
    44 // CCARequestMapper::~CCARequestMapper
       
    45 // Destructor
       
    46 // (other items were commented in a header).
       
    47 // -----------------------------------------------------------------------------
       
    48 //
       
    49 CCARequestMapper::~CCARequestMapper()
       
    50     {
       
    51     CHAT_DP( D_CHAT_LIT( "RequestMapper destroying (%d requests pending)." ),
       
    52              iRequestArray.Count() );
       
    53 
       
    54     iRequestArray.ResetAndDestroy();
       
    55     iRequestArray.Close();
       
    56 
       
    57     iBackgroundTasks.ResetAndDestroy();
       
    58     iBackgroundTasks.Close();
       
    59     iBackgroundObservers.Reset();
       
    60     iBackgroundObservers.Close();
       
    61     iBackGroundTaskObserver.Reset();
       
    62     }
       
    63 
       
    64 // -----------------------------------------------------------------------------
       
    65 // CCARequestMapper::RegisterBackgroundTask
       
    66 //
       
    67 // (other items were commented in a header).
       
    68 // -----------------------------------------------------------------------------
       
    69 //
       
    70 TInt CCARequestMapper::RegisterBackgroundTask(
       
    71     MCABackgroundTask* aBackgroundTask
       
    72     , TCABackgroundTasks aTaskID
       
    73     , TInt aSubTasks
       
    74 )
       
    75     {
       
    76     if ( !aBackgroundTask )
       
    77         {
       
    78         return KErrArgument;
       
    79         }
       
    80 
       
    81     TInt err( KErrNone );
       
    82     TRAPD( leave, err = RegisterBackgroundTaskL(
       
    83                             aBackgroundTask
       
    84                             , aTaskID
       
    85                             , aSubTasks
       
    86                         ) );
       
    87     switch ( leave )
       
    88         {
       
    89         case KErrNone:
       
    90             {
       
    91             return err;
       
    92             }
       
    93         case KErrNoMemory: // flowtrough
       
    94         case KErrDiskFull:
       
    95             {
       
    96             CActiveScheduler::Current()->Error( leave );
       
    97             return leave;
       
    98             }
       
    99         default:
       
   100             {
       
   101             return leave;
       
   102             }
       
   103         }
       
   104     }
       
   105 
       
   106 // -----------------------------------------------------------------------------
       
   107 // CCARequestMapper::RegisterBackgroundObserver
       
   108 //
       
   109 // (other items were commented in a header).
       
   110 // -----------------------------------------------------------------------------
       
   111 //
       
   112 TInt CCARequestMapper::RegisterBackgroundObserver(
       
   113     MCABackgroundObserver* aBackgroundObserver
       
   114     , TInt aTaskMask
       
   115     , TInt aEventMask
       
   116 )
       
   117     {
       
   118     CHAT_DP( D_CHAT_LIT(
       
   119                  "RequestMapper::RegisterBackgroundObserverL new observer %d %d" ),
       
   120              aTaskMask, aEventMask );
       
   121 
       
   122     TIdentityRelation<TBackgroundNotifier>
       
   123     identity( TBackgroundNotifier::Identity );
       
   124 
       
   125 
       
   126     TInt position ( iBackgroundObservers.Find( TBackgroundNotifier(
       
   127                                                    aBackgroundObserver ), identity ) );
       
   128 
       
   129     TInt err( KErrNone );
       
   130     if ( position == KErrNotFound )
       
   131         {
       
   132         err = iBackgroundObservers.Append( TBackgroundNotifier(
       
   133                                                aBackgroundObserver
       
   134                                                , aTaskMask
       
   135                                                , aEventMask
       
   136                                            ) );
       
   137         }
       
   138     else
       
   139         {
       
   140         iBackgroundObservers[ position ].iTaskMask = aTaskMask;
       
   141 
       
   142         iBackgroundObservers[ position ].iEventMask = aEventMask;
       
   143 
       
   144         }
       
   145 
       
   146     return err;
       
   147     }
       
   148 
       
   149 // -----------------------------------------------------------------------------
       
   150 // CCARequestMapper::BackgroundTaskStatus
       
   151 //
       
   152 // (other items were commented in a header).
       
   153 // -----------------------------------------------------------------------------
       
   154 //
       
   155 TInt CCARequestMapper::BackgroundTaskStatus(
       
   156     TCABackgroundTasks aTaskID
       
   157 )
       
   158     {
       
   159     CHAT_DP( D_CHAT_LIT( "CCARequestMapper::BackgroundTaskStatus() task %d" ),
       
   160              aTaskID );
       
   161 
       
   162     const TInt limit( iBackgroundTasks.Count() );
       
   163     for ( TInt i( 0 ); i < limit; i++ )
       
   164         {
       
   165         CCABackgroundTask* task = iBackgroundTasks[ i ];
       
   166 
       
   167         if ( task->TaskId() == aTaskID )
       
   168             {
       
   169             CHAT_DP( D_CHAT_LIT( "CCARequestMapper::BackgroundTaskStatus() task \
       
   170                                  %d status:%d" )
       
   171                      , aTaskID, task->TaskState() );
       
   172             return task->TaskState();
       
   173             }
       
   174         }
       
   175     return KErrNotFound;
       
   176     }
       
   177 
       
   178 // -----------------------------------------------------------------------------
       
   179 // CCARequestMapper::UnRegisterBackgroundObserver
       
   180 //
       
   181 // (other items were commented in a header).
       
   182 // -----------------------------------------------------------------------------
       
   183 //
       
   184 TInt CCARequestMapper::UnRegisterBackgroundObserver(
       
   185     MCABackgroundObserver* aBackgroundObserver
       
   186 )
       
   187     {
       
   188     CHAT_DP_TXT( "RequestMapper::UnRegisterBackgroundObserver" );
       
   189 
       
   190     TIdentityRelation<TBackgroundNotifier>
       
   191     identity( TBackgroundNotifier::Identity );
       
   192 
       
   193     TInt position ( iBackgroundObservers.Find( TBackgroundNotifier(
       
   194                                                    aBackgroundObserver )
       
   195                                                , identity ) );
       
   196 
       
   197     if ( position == KErrNotFound )
       
   198         {
       
   199         return position;
       
   200         }
       
   201     else
       
   202         {
       
   203         iBackgroundObservers.Remove( position );
       
   204         return KErrNone;
       
   205         }
       
   206     }
       
   207 
       
   208 // -----------------------------------------------------------------------------
       
   209 // CCARequestMapper::HandleBackgroundTask
       
   210 //
       
   211 // (other items were commented in a header).
       
   212 // -----------------------------------------------------------------------------
       
   213 //
       
   214 TInt CCARequestMapper::HandleBackgroundTask(
       
   215     MCABackgroundInterface::TCABackgroundTasks aTask )
       
   216     {
       
   217 
       
   218     TInt position( KErrNotFound );
       
   219 
       
   220     TInt limit( iBackgroundTasks.Count() );
       
   221     TInt index( 0 );
       
   222 
       
   223     while ( index < limit && position == KErrNotFound )
       
   224         {
       
   225         if ( iBackgroundTasks[ index ]->TaskId() == aTask )
       
   226             {
       
   227             position = index;
       
   228             }
       
   229         index++;
       
   230         }
       
   231 
       
   232     __ASSERT_ALWAYS( position != KErrNotFound , User::Panic(
       
   233                          KCAEnginePanicCategory, EBackgroundTaskNotFound ) );
       
   234 
       
   235     if ( iBackgroundTasks[ position ]->TaskState() &
       
   236          (
       
   237              MCABackgroundInterface::ECancelled |
       
   238              MCABackgroundInterface::EUnknown
       
   239          ) )
       
   240         {
       
   241         //task cancelled nothing to do
       
   242 
       
   243         return EFalse;
       
   244         }
       
   245     NotifyBackgroundObservers(
       
   246         position,
       
   247         EStarting,
       
   248         iBackgroundTasks[ position ]->SubTasks()
       
   249     );
       
   250     TRAPD( leave , iBackgroundTasks[ position ]->ExecuteTaskL() );
       
   251     CHAT_DP( D_CHAT_LIT( "CCARequestMapper::HandleBackgroundTask() task %d, \
       
   252 	                      subtask %d left with %d" ),
       
   253              aTask, 0, leave );
       
   254     if ( leave )
       
   255         {
       
   256         NotifyBackgroundObservers(
       
   257             position,
       
   258             MCABackgroundInterface::EFailed,
       
   259             iBackgroundTasks[ position ]->SubTasks(),
       
   260             leave
       
   261         );
       
   262         }
       
   263     else
       
   264         {
       
   265         NotifyBackgroundObservers(
       
   266             position,
       
   267             MCABackgroundInterface::ECompleted,
       
   268             iBackgroundTasks[ position ]->SubTasks()
       
   269         );
       
   270         }
       
   271 
       
   272     NotifyBackgroundTaskObservers();
       
   273 
       
   274     return iBackgroundTasks[ position ]->More();
       
   275     }
       
   276 
       
   277 // -----------------------------------------------------------------------------
       
   278 // CCARequestMapper::HandleNetworkStateChange
       
   279 //
       
   280 // (other items were commented in a header).
       
   281 // -----------------------------------------------------------------------------
       
   282 //
       
   283 void CCARequestMapper::HandleNetworkStateChange( TNetworkState aState )
       
   284     {
       
   285     CHAT_DP( D_CHAT_LIT( "CCARequestMapper::HandleNetworkStateChange state %d" ),
       
   286              aState );
       
   287     if ( aState != ELoggedIn )
       
   288         {
       
   289         //Cancelling all penging request
       
   290         CancelAllRequests();
       
   291 
       
   292         //Cancelling all background task
       
   293         TInt limit( iBackgroundTasks.Count() );
       
   294         for ( TInt i( 0 ); i < limit; i++ )
       
   295             {
       
   296             CCABackgroundTask* task = iBackgroundTasks[ i ];
       
   297             task->Cancel();
       
   298 
       
   299             if ( task->TaskState() & ( MCABackgroundInterface::EIdleStarted
       
   300                                        | MCABackgroundInterface::EStarting
       
   301                                        | MCABackgroundInterface::EWaiting ) )
       
   302                 {
       
   303                 NotifyBackgroundObservers(
       
   304                     i
       
   305                     , MCABackgroundInterface::EUnknown
       
   306                     , task->SubTasks()
       
   307                 );
       
   308                 }
       
   309             }
       
   310         }
       
   311     }
       
   312 
       
   313 // -----------------------------------------------------------------------------
       
   314 // CCARequestMapper::CreateRequestL
       
   315 //
       
   316 // (other items were commented in a header).
       
   317 // -----------------------------------------------------------------------------
       
   318 //
       
   319 CCARequest* CCARequestMapper::CreateRequestL( TInt aOpId,
       
   320                                               TBool aWait,
       
   321                                               TBool aDestroyAfterComplete,
       
   322                                               TCallBack aCallBack )
       
   323     {
       
   324     CHAT_DP( D_CHAT_LIT( "RequestMapper::CreateRequestL (OpId: %d, Wait: %d, \
       
   325 	                      aDestroyAfterComplete: %d, aCallBack: %d)" ),
       
   326              aOpId, aWait, aDestroyAfterComplete, aCallBack.iFunction );
       
   327 
       
   328     CCARequest* request = CCARequest::NewL( aOpId,
       
   329                                             aDestroyAfterComplete,
       
   330                                             aCallBack );
       
   331     request->SetRequestMapper( this );
       
   332 
       
   333     TInt err( iRequestArray.Append( request ) );
       
   334 
       
   335     if ( err != KErrNone )
       
   336         {
       
   337         CHAT_DP( D_CHAT_LIT( "RequestMapper::CreateRequestL failed with \
       
   338 		                      error code %d!!!" ), err );
       
   339         delete request;
       
   340         User::Leave( err );
       
   341         }
       
   342 
       
   343     if ( aWait )
       
   344         {
       
   345         CHAT_DP( D_CHAT_LIT( "Wait starting...request type is %d" ),
       
   346                  request->RequestType() );
       
   347 
       
   348         request->StartWait();
       
   349         }
       
   350 
       
   351     return request;
       
   352     }
       
   353 
       
   354 // -----------------------------------------------------------------------------
       
   355 // CCARequestMapper::FindRequest
       
   356 //
       
   357 // (other items were commented in a header).
       
   358 // -----------------------------------------------------------------------------
       
   359 //
       
   360 const CCARequest* CCARequestMapper::FindRequest( TInt aOpId )
       
   361     {
       
   362     return DoFindRequest( aOpId );
       
   363     }
       
   364 
       
   365 // -----------------------------------------------------------------------------
       
   366 // CCARequestMapper::RemoveRequest
       
   367 //
       
   368 // (other items were commented in a header).
       
   369 // -----------------------------------------------------------------------------
       
   370 //
       
   371 void CCARequestMapper::RemoveRequest( CCARequest* aRequest )
       
   372     {
       
   373     TInt index( iRequestArray.Find( aRequest ) );
       
   374     CHAT_DP( D_CHAT_LIT( "RequestMapper::RemoveRequest (Index: %d)" ), index );
       
   375 
       
   376     if ( index != KErrNotFound )
       
   377         {
       
   378         delete aRequest;
       
   379         iRequestArray.Remove( index );
       
   380         }
       
   381     }
       
   382 
       
   383 // -----------------------------------------------------------------------------
       
   384 // CCARequestMapper::RemoveRequestAndLeaveIfErrorL
       
   385 //
       
   386 // (other items were commented in a header).
       
   387 // -----------------------------------------------------------------------------
       
   388 //
       
   389 void CCARequestMapper::RemoveRequestAndLeaveIfErrorL( CCARequest* aRequest )
       
   390     {
       
   391     if ( aRequest )
       
   392         {
       
   393         TInt errorCode( aRequest->ErrorCode() );
       
   394         RemoveRequest( aRequest );
       
   395 
       
   396         User::LeaveIfError( errorCode );
       
   397         }
       
   398     }
       
   399 
       
   400 // -----------------------------------------------------------------------------
       
   401 // CCARequestMapper::HandleRequest
       
   402 //
       
   403 // (other items were commented in a header).
       
   404 // -----------------------------------------------------------------------------
       
   405 //
       
   406 void CCARequestMapper::HandleRequest( TInt aOpId, TInt aErrorCode )
       
   407     {
       
   408     CHAT_DP( D_CHAT_LIT( "RequestMapper::HandleRequest (OpId: %d, Error: %d)" ),
       
   409              aOpId, aErrorCode );
       
   410 
       
   411     CCARequest* request = DoFindRequest( aOpId );
       
   412 
       
   413     //signal OOM
       
   414     if ( aErrorCode == KErrNoMemory || aErrorCode == KErrDiskFull )
       
   415         {
       
   416         CActiveScheduler::Current()->Error( aErrorCode );
       
   417         }
       
   418 
       
   419     // If we have the request...
       
   420     if ( request )
       
   421         {
       
   422         // Set error code
       
   423         request->SetErrorCode( aErrorCode );
       
   424         // Call callback function if one is defined
       
   425         request->ExecuteCallBackFunction();
       
   426         // Stop wait if needed
       
   427         request->StopWaitIfNeeded();
       
   428         // Destroy object if marked so
       
   429         if ( request->DestroyAfterComplete() )
       
   430             {
       
   431             RemoveRequest( request );
       
   432             }
       
   433         }
       
   434     CHAT_DP_TXT( "RequestMapper::HandleRequest over" );
       
   435     }
       
   436 
       
   437 // -----------------------------------------------------------------------------
       
   438 // CCARequestMapper::CancelAllRequests
       
   439 //
       
   440 // (other items were commented in a header).
       
   441 // -----------------------------------------------------------------------------
       
   442 //
       
   443 void CCARequestMapper::CancelAllRequests()
       
   444     {
       
   445     CHAT_DP( D_CHAT_LIT( "RequestMapper::CancelAllRequests (%d)" ),
       
   446              iRequestArray.Count() );
       
   447 
       
   448     CCARequest* request = NULL;
       
   449 
       
   450     for ( TInt i( 0 ); i < iRequestArray.Count(); ++i )
       
   451         {
       
   452         request = iRequestArray[i];
       
   453         request->SetErrorCode( EOperationCancelled );
       
   454         request->StopWaitIfNeeded();
       
   455         }
       
   456 
       
   457     }
       
   458 
       
   459 // -----------------------------------------------------------------------------
       
   460 // CCARequestMapper::WaitCount
       
   461 //
       
   462 // (other items were commented in a header).
       
   463 // -----------------------------------------------------------------------------
       
   464 //
       
   465 TInt CCARequestMapper::WaitCount()
       
   466     {
       
   467     return iWaitCount;
       
   468     }
       
   469 
       
   470 // -----------------------------------------------------------------------------
       
   471 // CCARequestMapper::ReportWaitStart
       
   472 //
       
   473 // (other items were commented in a header).
       
   474 // -----------------------------------------------------------------------------
       
   475 //
       
   476 void CCARequestMapper::ReportWaitStart()
       
   477     {
       
   478     iWaitCount++;
       
   479     }
       
   480 
       
   481 // -----------------------------------------------------------------------------
       
   482 // CCARequestMapper::ReportWaitStop
       
   483 //
       
   484 // (other items were commented in a header).
       
   485 // -----------------------------------------------------------------------------
       
   486 //
       
   487 void CCARequestMapper::ReportWaitStop()
       
   488     {
       
   489     iWaitCount--;
       
   490     }
       
   491 
       
   492 // -----------------------------------------------------------------------------
       
   493 // CCARequestMapper::CCARequestMapper
       
   494 // C++ default constructor can NOT contain any code, that
       
   495 // might leave.
       
   496 // -----------------------------------------------------------------------------
       
   497 //
       
   498 CCARequestMapper::CCARequestMapper()
       
   499     {
       
   500     }
       
   501 
       
   502 // -----------------------------------------------------------------------------
       
   503 // CCARequestMapper::DoFindRequest
       
   504 //
       
   505 // (other items were commented in a header).
       
   506 // -----------------------------------------------------------------------------
       
   507 //
       
   508 CCARequest* CCARequestMapper::DoFindRequest( TInt aOpId )
       
   509     {
       
   510     CHAT_DP_TXT( "CCARequestMapper::DoFindRequest" );
       
   511     TInt indexCount( iRequestArray.Count() );
       
   512 
       
   513     for ( TInt index( 0 ); index < indexCount; index ++ )
       
   514         {
       
   515         if ( iRequestArray[index]->IdMatches( aOpId ) )
       
   516             {
       
   517             CHAT_DP_TXT( "CCARequestMapper::DoFindRequest over +" );
       
   518             return iRequestArray[index];
       
   519             }
       
   520         }
       
   521     CHAT_DP_TXT( "CCARequestMapper::DoFindRequest over -" );
       
   522     return NULL;
       
   523     }
       
   524 
       
   525 // -----------------------------------------------------------------------------
       
   526 // CCARequestMapper::NotifyBackgroundObservers
       
   527 //
       
   528 // (other items were commented in a header).
       
   529 // -----------------------------------------------------------------------------
       
   530 //
       
   531 void CCARequestMapper::NotifyBackgroundObservers(
       
   532     TInt aTaskPosition,
       
   533     TCABackgroundStatus aStatus,
       
   534     TInt aSubTaskNumber,
       
   535     TInt aLeaveCode
       
   536 )
       
   537     {
       
   538     CHAT_DP( D_CHAT_LIT( "CCARequestMapper::NotifyBackgroundObservers() \
       
   539 	                      %d %d %d %d" ),
       
   540              aTaskPosition, aStatus, aSubTaskNumber, aLeaveCode );
       
   541 
       
   542     TInt limit( iBackgroundObservers.Count() );
       
   543     CCABackgroundTask* task = iBackgroundTasks[ aTaskPosition ];
       
   544     task->SetTaskState( aStatus );
       
   545 
       
   546     for ( TInt i( 0 ); i < limit; i++ )
       
   547         {
       
   548         if ( ( task->TaskId() & iBackgroundObservers[ i ].iTaskMask ) &&
       
   549              ( aStatus & iBackgroundObservers[ i ].iEventMask ) )
       
   550             {
       
   551             iBackgroundObservers[ i ].iObserver->HandleBackgroundEvent(
       
   552                 task->TaskId()
       
   553                 , aStatus
       
   554                 , aSubTaskNumber
       
   555                 , aLeaveCode
       
   556             );
       
   557             }
       
   558         }
       
   559     }
       
   560 
       
   561 // -----------------------------------------------------------------------------
       
   562 // CCARequestMapper::RegisterBackgroundTaskL
       
   563 //
       
   564 // (other items were commented in a header).
       
   565 // -----------------------------------------------------------------------------
       
   566 //
       
   567 TInt CCARequestMapper::RegisterBackgroundTaskL(
       
   568     MCABackgroundTask* aBackgroundTask
       
   569     , TCABackgroundTasks aTaskID
       
   570     , TInt aSubTasks
       
   571 )
       
   572     {
       
   573 
       
   574     CCABackgroundTask* newTask = CCABackgroundTask::NewLC(
       
   575                                      this
       
   576                                      , aBackgroundTask
       
   577                                      , aTaskID
       
   578                                      , aSubTasks
       
   579                                  );
       
   580     TIdentityRelation<CCABackgroundTask>
       
   581     identity( CCABackgroundTask::Identity );
       
   582 
       
   583     TInt position ( iBackgroundTasks.Find( newTask, identity ) );
       
   584 
       
   585     if ( position != KErrNotFound )
       
   586         {
       
   587         CCABackgroundTask* toRemove = iBackgroundTasks[ position ];
       
   588         iBackgroundTasks.Remove( position );
       
   589         delete toRemove;
       
   590         }
       
   591 
       
   592     TInt err( KErrNone );
       
   593     err = iBackgroundTasks.Append( newTask );
       
   594     if ( err )
       
   595         {
       
   596         CleanupStack::PopAndDestroy( newTask );
       
   597         return err;
       
   598         }
       
   599     else
       
   600         {
       
   601         CleanupStack::Pop( newTask );
       
   602         }
       
   603 
       
   604     position = iBackgroundTasks.Count() - 1;
       
   605 
       
   606     newTask->Start();
       
   607 
       
   608     newTask->SetTaskState( MCABackgroundInterface::EIdleStarted );
       
   609 
       
   610     NotifyBackgroundObservers(
       
   611         position,
       
   612         EIdleStarted,
       
   613         newTask->SubTasks()
       
   614     );
       
   615     return err; //KErrNone
       
   616     }
       
   617 
       
   618 // -----------------------------------------------------------------------------
       
   619 // TBackgroundNotifier::TBackgroundNotifier
       
   620 // constructor
       
   621 // (other items were commented in a header).
       
   622 // -----------------------------------------------------------------------------
       
   623 //
       
   624 TBackgroundNotifier::TBackgroundNotifier( MCABackgroundObserver* aObserver
       
   625                                           , TInt aTaskMask
       
   626                                           , TInt aEventMask
       
   627                                         ) :
       
   628         iObserver( aObserver )
       
   629         , iTaskMask( aTaskMask )
       
   630         , iEventMask( aEventMask )
       
   631     {
       
   632     }
       
   633 
       
   634 // -----------------------------------------------------------------------------
       
   635 // TBackgroundNotifier::Identity
       
   636 //
       
   637 // (other items were commented in a header).
       
   638 // -----------------------------------------------------------------------------
       
   639 //
       
   640 TBool TBackgroundNotifier::Identity( const TBackgroundNotifier& aA
       
   641                                      , const TBackgroundNotifier& aB
       
   642                                    )
       
   643     {
       
   644     return ( aA.iObserver == aB.iObserver );
       
   645     }
       
   646 
       
   647 
       
   648 // -----------------------------------------------------------------------------
       
   649 // TBackgroundNotifier::IsBackgroundTaskPending
       
   650 //
       
   651 // (other items were commented in a header).
       
   652 // -----------------------------------------------------------------------------
       
   653 TBool CCARequestMapper::IsBackgroundTaskPending()
       
   654     {
       
   655     const TInt limit( iBackgroundTasks.Count() );
       
   656 
       
   657     for ( TInt i( 0 ); i < limit; i++ )
       
   658         {
       
   659         CCABackgroundTask* task = iBackgroundTasks[ i ];
       
   660 
       
   661         if ( task->TaskId() == EGroupFetch )
       
   662             {
       
   663 
       
   664             MCABackgroundInterface::TCABackgroundStatus taskState = task->TaskState();
       
   665 
       
   666             if ( taskState == EIdleStarted || taskState == EStarting || taskState == EWaiting )
       
   667                 {
       
   668 
       
   669                 return ETrue;
       
   670                 }
       
   671             }
       
   672         }
       
   673     return EFalse;
       
   674     }
       
   675 
       
   676 // ---------------------------------------------------------
       
   677 // CCAEngine::RegisterGroupSyncObserver()
       
   678 // ---------------------------------------------------------
       
   679 //
       
   680 void CCARequestMapper::RegisterBackGroundTaskObserver( MCABackGroundTaskObserver* aObserver )
       
   681     {
       
   682     ASSERT( aObserver );
       
   683     TInt status( iBackGroundTaskObserver.Find( aObserver ) );
       
   684     if ( status == KErrNotFound )
       
   685         {
       
   686         status = iBackGroundTaskObserver.Append( aObserver ) ;
       
   687         }
       
   688     }
       
   689 
       
   690 // ---------------------------------------------------------
       
   691 // CCAEngine::UnRegisterGroupSyncObserver()
       
   692 // ---------------------------------------------------------
       
   693 //
       
   694 void CCARequestMapper::UnRegisterBackGroundTaskObserver( MCABackGroundTaskObserver* aObserver )
       
   695     {
       
   696     ASSERT( aObserver );
       
   697     const TInt status( iBackGroundTaskObserver.Find( aObserver ) );
       
   698     if ( status != KErrNotFound )
       
   699         {
       
   700         iBackGroundTaskObserver.Remove( status );
       
   701         iBackGroundTaskObserver.Compress();
       
   702         }
       
   703     }
       
   704 
       
   705 // ---------------------------------------------------------
       
   706 // CCAEngine::NotifyGroupSyncObservers()
       
   707 // ---------------------------------------------------------
       
   708 //
       
   709 void CCARequestMapper::NotifyBackgroundTaskObservers()
       
   710     {
       
   711     TInt count = iBackGroundTaskObserver.Count();
       
   712 
       
   713     for ( TInt i = 0; i < count; i++ )
       
   714         {
       
   715         TRAP_IGNORE ( iBackGroundTaskObserver[i]->HandleBackGroundTaskCompleteL( IsBackgroundTaskPending() ) );
       
   716         }
       
   717     }
       
   718 
       
   719 //  End of File