bearermanagement/mpm/src/mpmdatausagewatcher.cpp
branchRCL_3
changeset 17 c14618f9de99
parent 12 ea6e024ea6f9
child 55 fc7b30ed2058
--- a/bearermanagement/mpm/src/mpmdatausagewatcher.cpp	Wed Mar 31 22:15:10 2010 +0300
+++ b/bearermanagement/mpm/src/mpmdatausagewatcher.cpp	Wed Apr 14 16:22:04 2010 +0300
@@ -82,14 +82,11 @@
     {
     MPMLOGSTRING( "CMpmDataUsageWatcher::StartL" )
 
-    // Request notification
-    User::LeaveIfError( iRepository->NotifyRequest( KCurrentCellularDataUsage,
-            iStatus ) );
-    SetActive();
+    // Get the initial data usage value from repository.
+    User::LeaveIfError( GetCurrentDataUsageValue() );
 
-    // Get value from central repository
-    User::LeaveIfError( iRepository->Get( KCurrentCellularDataUsage,
-            iCellularDataUsage ) );
+    // Request notifications.
+    User::LeaveIfError( RequestNotifications() );
     }
 
 // ---------------------------------------------------------------------------
@@ -101,38 +98,39 @@
     {
     MPMLOGSTRING( "CMpmDataUsageWatcher::RunL" )
 
-    User::LeaveIfError( iStatus.Int() );
+    if ( iStatus.Int() < KErrNone )
+        {
+        MPMLOGSTRING2("Status: 0x%08X", iStatus.Int())
+        iErrorCounter++;
+        if ( iErrorCounter > KMpmDataUsageWatcherCenRepErrorThreshold )
+            {
+            MPMLOGSTRING2("Over %d consecutive errors, stopping notifications permanently.",
+                    KMpmDataUsageWatcherCenRepErrorThreshold)
+            return;
+            }
+        // Else: Error occured but counter not expired. Proceed.
+        }
+    else
+        {
+        // Notification is received ok => Reset the counter.
+        iErrorCounter = 0;
 
-    // Request new notification
-    User::LeaveIfError( iRepository->NotifyRequest( KCurrentCellularDataUsage,
-            iStatus ) );
-    SetActive();
+        // Get the new Cellular data usage setting value from central repository.
+        TInt oldCellularDataUsage = iCellularDataUsage;
 
-    TInt oldCellularDataUsage = iCellularDataUsage;
-
-    // Get the new value from central repository
-    User::LeaveIfError( iRepository->Get( KCurrentCellularDataUsage,
-            iCellularDataUsage ) );
+        if ( GetCurrentDataUsageValue() == KErrNone )
+            {
+            // Stop cellular connections if the setting changes into Disabled.
+            if ( oldCellularDataUsage != ECmCellularDataUsageDisabled &&
+                    iCellularDataUsage == ECmCellularDataUsageDisabled &&
+                    iServer->RoamingWatcher()->RoamingStatus() != EMPMRoamingStatusUnknown )
+                {
+                iServer->StopCellularConns();
+                }
+            }
+        }
     
-    // Stop cellular connections if the setting changes into Disabled
-    if ( oldCellularDataUsage != ECmCellularDataUsageDisabled &&
-         iCellularDataUsage == ECmCellularDataUsageDisabled &&
-         iServer->RoamingWatcher()->RoamingStatus() != EMPMRoamingStatusUnknown )
-        {
-        iServer->StopCellularConns();
-        }
-    }
-
-// ---------------------------------------------------------------------------
-// From class CActive.
-// Nothing to do over here.
-// ---------------------------------------------------------------------------
-//
-TInt CMpmDataUsageWatcher::RunError( TInt /*aError*/ )
-    {
-    MPMLOGSTRING( "CMpmDataUsageWatcher::RunError" )
-
-    return KErrNone;
+    RequestNotifications();
     }
 
 // ---------------------------------------------------------------------------
@@ -147,3 +145,40 @@
     iRepository->NotifyCancel( KCurrentCellularDataUsage );
     }
 
+// ---------------------------------------------------------------------------
+// Request notifications.
+// ---------------------------------------------------------------------------
+//
+TInt CMpmDataUsageWatcher::RequestNotifications()
+    {
+    MPMLOGSTRING( "CMpmDataUsageWatcher::RequestNotifications" )
+
+    TInt err = iRepository->NotifyRequest( KCurrentCellularDataUsage, iStatus );
+        
+    if ( err == KErrNone )
+        {
+        SetActive();
+        }
+    else
+        {
+        MPMLOGSTRING2( "CMpmDataUsageWatcher::RequestNotifications, ERROR: %d", err )
+        }
+    return err;
+    }
+
+// ---------------------------------------------------------------------------
+// Get current repository key value.
+// ---------------------------------------------------------------------------
+//
+TInt CMpmDataUsageWatcher::GetCurrentDataUsageValue()
+    {
+    MPMLOGSTRING( "CMpmDataUsageWatcher::GetCurrentDataUsageValue" )
+
+    TInt err = iRepository->Get( KCurrentCellularDataUsage, iCellularDataUsage );
+        
+    if ( err != KErrNone )
+        {
+        MPMLOGSTRING2( "CMpmDataUsageWatcher::GetCurrentDataUsageValue, ERROR: %d", err )
+        }
+    return err;
+    }