bearermanagement/mpm/src/mpmdatausagewatcher.cpp
changeset 20 9c97ad6591ae
parent 18 fcbbe021d614
child 44 a0c4ceac30d0
equal deleted inserted replaced
18:fcbbe021d614 20:9c97ad6591ae
    80 //
    80 //
    81 void CMpmDataUsageWatcher::StartL()
    81 void CMpmDataUsageWatcher::StartL()
    82     {
    82     {
    83     MPMLOGSTRING( "CMpmDataUsageWatcher::StartL" )
    83     MPMLOGSTRING( "CMpmDataUsageWatcher::StartL" )
    84 
    84 
    85     // Request notification
    85     // Get the initial data usage value from repository.
    86     User::LeaveIfError( iRepository->NotifyRequest( KCurrentCellularDataUsage,
    86     User::LeaveIfError( GetCurrentDataUsageValue() );
    87             iStatus ) );
       
    88     SetActive();
       
    89 
    87 
    90     // Get value from central repository
    88     // Request notifications.
    91     User::LeaveIfError( iRepository->Get( KCurrentCellularDataUsage,
    89     User::LeaveIfError( RequestNotifications() );
    92             iCellularDataUsage ) );
       
    93     }
    90     }
    94 
    91 
    95 // ---------------------------------------------------------------------------
    92 // ---------------------------------------------------------------------------
    96 // From class CActive.
    93 // From class CActive.
    97 // Event is received when there is a change in central repository key.
    94 // Event is received when there is a change in central repository key.
    99 //
    96 //
   100 void CMpmDataUsageWatcher::RunL()
    97 void CMpmDataUsageWatcher::RunL()
   101     {
    98     {
   102     MPMLOGSTRING( "CMpmDataUsageWatcher::RunL" )
    99     MPMLOGSTRING( "CMpmDataUsageWatcher::RunL" )
   103 
   100 
   104     User::LeaveIfError( iStatus.Int() );
   101     if ( iStatus.Int() < KErrNone )
       
   102         {
       
   103         MPMLOGSTRING2("Status: 0x%08X", iStatus.Int())
       
   104         iErrorCounter++;
       
   105         if ( iErrorCounter > KMpmDataUsageWatcherCenRepErrorThreshold )
       
   106             {
       
   107             MPMLOGSTRING2("Over %d consecutive errors, stopping notifications permanently.",
       
   108                     KMpmDataUsageWatcherCenRepErrorThreshold)
       
   109             return;
       
   110             }
       
   111         // Else: Error occured but counter not expired. Proceed.
       
   112         }
       
   113     else
       
   114         {
       
   115         // Notification is received ok => Reset the counter.
       
   116         iErrorCounter = 0;
   105 
   117 
   106     // Request new notification
   118         // Get the new Cellular data usage setting value from central repository.
   107     User::LeaveIfError( iRepository->NotifyRequest( KCurrentCellularDataUsage,
   119         TInt oldCellularDataUsage = iCellularDataUsage;
   108             iStatus ) );
       
   109     SetActive();
       
   110 
   120 
   111     TInt oldCellularDataUsage = iCellularDataUsage;
   121         if ( GetCurrentDataUsageValue() == KErrNone )
   112 
   122             {
   113     // Get the new value from central repository
   123             // Stop cellular connections if the setting changes into Disabled.
   114     User::LeaveIfError( iRepository->Get( KCurrentCellularDataUsage,
   124             if ( oldCellularDataUsage != ECmCellularDataUsageDisabled &&
   115             iCellularDataUsage ) );
   125                     iCellularDataUsage == ECmCellularDataUsageDisabled &&
       
   126                     iServer->RoamingWatcher()->RoamingStatus() != EMPMRoamingStatusUnknown )
       
   127                 {
       
   128                 iServer->StopCellularConns();
       
   129                 }
       
   130             }
       
   131         }
   116     
   132     
   117     // Stop cellular connections if the setting changes into Disabled
   133     RequestNotifications();
   118     if ( oldCellularDataUsage != ECmCellularDataUsageDisabled &&
       
   119          iCellularDataUsage == ECmCellularDataUsageDisabled &&
       
   120          iServer->RoamingWatcher()->RoamingStatus() != EMPMRoamingStatusUnknown )
       
   121         {
       
   122         iServer->StopCellularConns();
       
   123         }
       
   124     }
       
   125 
       
   126 // ---------------------------------------------------------------------------
       
   127 // From class CActive.
       
   128 // Nothing to do over here.
       
   129 // ---------------------------------------------------------------------------
       
   130 //
       
   131 TInt CMpmDataUsageWatcher::RunError( TInt /*aError*/ )
       
   132     {
       
   133     MPMLOGSTRING( "CMpmDataUsageWatcher::RunError" )
       
   134 
       
   135     return KErrNone;
       
   136     }
   134     }
   137 
   135 
   138 // ---------------------------------------------------------------------------
   136 // ---------------------------------------------------------------------------
   139 // From class CActive.
   137 // From class CActive.
   140 // Cancel outstanding request.
   138 // Cancel outstanding request.
   145     MPMLOGSTRING( "CMpmDataUsageWatcher::DoCancel" )
   143     MPMLOGSTRING( "CMpmDataUsageWatcher::DoCancel" )
   146 
   144 
   147     iRepository->NotifyCancel( KCurrentCellularDataUsage );
   145     iRepository->NotifyCancel( KCurrentCellularDataUsage );
   148     }
   146     }
   149 
   147 
       
   148 // ---------------------------------------------------------------------------
       
   149 // Request notifications.
       
   150 // ---------------------------------------------------------------------------
       
   151 //
       
   152 TInt CMpmDataUsageWatcher::RequestNotifications()
       
   153     {
       
   154     MPMLOGSTRING( "CMpmDataUsageWatcher::RequestNotifications" )
       
   155 
       
   156     TInt err = iRepository->NotifyRequest( KCurrentCellularDataUsage, iStatus );
       
   157         
       
   158     if ( err == KErrNone )
       
   159         {
       
   160         SetActive();
       
   161         }
       
   162     else
       
   163         {
       
   164         MPMLOGSTRING2( "CMpmDataUsageWatcher::RequestNotifications, ERROR: %d", err )
       
   165         }
       
   166     return err;
       
   167     }
       
   168 
       
   169 // ---------------------------------------------------------------------------
       
   170 // Get current repository key value.
       
   171 // ---------------------------------------------------------------------------
       
   172 //
       
   173 TInt CMpmDataUsageWatcher::GetCurrentDataUsageValue()
       
   174     {
       
   175     MPMLOGSTRING( "CMpmDataUsageWatcher::GetCurrentDataUsageValue" )
       
   176 
       
   177     TInt err = iRepository->Get( KCurrentCellularDataUsage, iCellularDataUsage );
       
   178         
       
   179     if ( err != KErrNone )
       
   180         {
       
   181         MPMLOGSTRING2( "CMpmDataUsageWatcher::GetCurrentDataUsageValue, ERROR: %d", err )
       
   182         }
       
   183     return err;
       
   184     }