realtimenetprots/sipfw/ProfileAgent/ApnManager/src/sipapnconfigurationhandler.cpp
branchRCL_3
changeset 13 822e1f077722
parent 6 43c4dec3cb1f
child 15 2cdd984ec527
--- a/realtimenetprots/sipfw/ProfileAgent/ApnManager/src/sipapnconfigurationhandler.cpp	Tue May 25 13:04:58 2010 +0300
+++ b/realtimenetprots/sipfw/ProfileAgent/ApnManager/src/sipapnconfigurationhandler.cpp	Wed Jun 09 10:04:26 2010 +0300
@@ -19,6 +19,8 @@
 #include <commsdattypesv1_1.h>
 #include <commdb.h>
 #include <commsdat.h>
+#include <cmgenconnsettings.h>
+#include <cmmanagerkeys.h>
 #include "sipapnconfigurationhandler.h"
 #include "SipProfileLog.h"
 
@@ -58,17 +60,15 @@
 	{
 	PROFILE_DEBUG1( 
 	        "CSIPApnConfigurationHandler::~CSIPApnConfigurationHandler()" )
-	
+	        
 	Cancel();
 	iConnection.Close();
 	iSocketSrv.Close();
-	
 	delete iApnProposal;
 	delete iCurrentApn;
-	
     delete iPrimaryApn;
     delete iSecondaryApn;
-    
+    delete iRepository;
 	delete iCommsDatabase;
 	
 	PROFILE_DEBUG1( 
@@ -105,7 +105,7 @@
         return;
         }
     
-    iMonitoringRetryCount = 0;
+    iDBMonitoringRetryCount = 0;
     
     ChangeApnIfNotInUseL( aAllowAsync );
         
@@ -285,6 +285,11 @@
     PROFILE_DEBUG3( 
             "CSIPApnConfigurationHandler::RunError() err", aError );
     
+    if(iCellularDataBlocked)
+        {
+        AllowCellularDataUsage();
+        }
+    
     if ( aError != KErrNoMemory && aError != KErrNone )
         {
         iObserver.ApnChanged( *iApnProposal, iIapId, aError );
@@ -307,7 +312,8 @@
 	CActiveScheduler::Add( this );
 	iIapId = aIapId;
 	iIsFailed = EFalse;
-	iIsFatalFailure = EFalse; 
+	iIsFatalFailure = EFalse;
+	iCellularDataBlocked = EFalse;
 	}
 
 // -----------------------------------------------------------------------------
@@ -320,7 +326,7 @@
 	        "CSIPApnConfigurationHandler::ConstructL()" )
 	
 	User::LeaveIfError( iSocketSrv.Connect() );
-	
+	iRepository = CRepository::NewL( KCRUidCmManager );
 	PROFILE_DEBUG1( 
 	        "CSIPApnConfigurationHandler::ConstructL() exit" )
 	}
@@ -426,7 +432,7 @@
 // CSIPApnConfigurationHandler::WatchDatabaseStatusChangeL
 // -----------------------------------------------------------------------------
 //	
-void CSIPApnConfigurationHandler::WatchDatabaseStatusChangeL( TUint32 aIapId )
+void CSIPApnConfigurationHandler::WatchDatabaseStatusChangeL()
     {
     PROFILE_DEBUG1( 
             "CSIPApnConfigurationHandler::WatchDatabaseStatusChangeL()" )
@@ -436,22 +442,26 @@
     if ( !iCommsDatabase )
         {
         PROFILE_DEBUG1( 
-                "CSIPApnConfigurationHandler::   create commsdb" )
+                "CSIPApnConfigurationHandler::WatchDatabaseStatusChangeL create commsdb" )
         iCommsDatabase = CCommsDatabase::NewL();
         }
     
     PROFILE_DEBUG1( 
-            "CSIPApnConfigurationHandler::   request notification" )
+            "CSIPApnConfigurationHandler::WatchDatabaseStatusChangeL request notification" )
     
     // Start monitoring for db events, there will be lots of them pouring in
     // as there's no filtering feature. We are interested only in
     // unlocked events.    
+
+    if(iDBMonitoringRetryCount > KDBMaxRetryCount)
+        {
+        PROFILE_DEBUG1("CSIPApnConfigurationHandler::WatchDatabaseStatusChangeL max retries reached!" )       
+        User::Leave( KErrAbort );
+        }
+    
     User::LeaveIfError( iCommsDatabase->RequestNotification( iStatus ) );
-    
     SetActive();
-    
-    iIapId = aIapId;
-        
+          
     SetMonitoringState( EMonitoringDatabase );
     
     PROFILE_DEBUG1( 
@@ -542,7 +552,7 @@
         
             __ASSERT_ALWAYS( aAllowAsync, User::Leave( KErrInUse ) );
         
-            WatchDatabaseStatusChangeL( iIapId );
+            WatchDatabaseStatusChangeL();
             }
         else 
             {
@@ -570,8 +580,12 @@
     
    	using namespace CommsDat;
 	
-	CMDBSession* db = CMDBSession::NewL( CMDBSession::LatestVersion() );
+	CMDBSession* db = CMDBSession::NewL( KCDVersion1_1 );
     CleanupStack::PushL( db );
+    
+	db->OpenTransactionL();
+    CleanupStack::PushL(TCleanupItem(RollBackDBTransaction, db));
+    
     // Set attributes so that also protected iaps can be accessed
     db->SetAttributeMask( ECDHidden | ECDProtectedWrite ); 
 
@@ -647,9 +661,19 @@
     db->ClearAttributeMask( ECDHidden | ECDProtectedWrite );
     
     CleanupStack::PopAndDestroy( iapRecord );
+    
+    db->CommitTransactionL();
+    
+	CleanupStack::Pop(); //cleanup item
+	
     CleanupStack::PopAndDestroy( db );
     
-    SendApnChangedNotificationL( aApn );
+    if (iCellularDataBlocked)
+        {
+        AllowCellularDataUsage();
+        }  
+    
+    SendApnChangedNotificationL( aApn );        
     
     PROFILE_DEBUG1( 
             "CSIPApnConfigurationHandler::ChangeApnL(), exit" )
@@ -701,10 +725,10 @@
 void CSIPApnConfigurationHandler::ConnectionMonitoringCompletedL( TInt aError )
     {
 	PROFILE_DEBUG3( 
-	        "CSIPApnConfigurationHandler::   progress.err",
+	        "CSIPApnConfigurationHandler::ConnectionMonitoringCompletedL   progress.err",
 	        iProgress().iError );
 	PROFILE_DEBUG3( 
-	        "CSIPApnConfigurationHandler::   progress.stage",
+	        "CSIPApnConfigurationHandler::ConnectionMonitoringCompletedL   progress.stage",
 	        iProgress().iStage );
 	                
     if ( !aError )
@@ -748,30 +772,19 @@
         {
         // Changing may be now possible, if not, db notifications or connection
         // monitoring is re-enabled inside following method
+        PROFILE_DEBUG1("DatabaseMonitoringCompletedL::DatabaseMonitoringCompletedL BlockCellularDataUsageL" );
+        BlockCellularDataUsageL();
         apnChanged = ChangeApnIfNotInUseL();
         }
     else
         {
-        WatchDatabaseStatusChangeL( iIapId );
+        iDBMonitoringRetryCount++;
+        WatchDatabaseStatusChangeL();        
         }
     
-    // Have some safety limit for monitoring as it's not guaranteed that
-    // db lock is ever released -> avoid unnecessary battery consumption    
-    if ( !apnChanged )
+    if(apnChanged)
         {
-        iMonitoringRetryCount++;
-        PROFILE_DEBUG3( 
-                "DatabaseMonitoringCompletedL::   retrycount",
-                iMonitoringRetryCount );
-        
-        if ( iMonitoringRetryCount > KSecondaryApnMaxRetryCount )
-            {
-            PROFILE_DEBUG1( 
-                "CSIPApnConfigurationHandler::   max retries reached!" )
-            Cancel();
-            
-            User::Leave( KErrAbort );
-            }
+        iDBMonitoringRetryCount = 0;
         }
     }
 
@@ -902,4 +915,40 @@
         }
     }
 
+// -----------------------------------------------------------------------------
+// CSIPApnConfigurationHandler::BlockCellularDataUsageL
+// -----------------------------------------------------------------------------
+//
+void CSIPApnConfigurationHandler::BlockCellularDataUsageL()
+    {
+    PROFILE_DEBUG1("DatabaseMonitoringCompletedL::BlockCellularDataUsageL Enter" );
+    //Current Usage Status;
+    iRepository->Get( KCurrentCellularDataUsage, iCurrentUsageStatus );
+    iRepository->Set( KCurrentCellularDataUsage, ECmCellularDataUsageDisabled );
+    iCellularDataBlocked = ETrue;
+    PROFILE_DEBUG1("DatabaseMonitoringCompletedL::BlockCellularDataUsageL Exit" );
+    }
+// -----------------------------------------------------------------------------
+// CSIPApnConfigurationHandler::AllowCellularDataUsage
+// -----------------------------------------------------------------------------
+//
+void CSIPApnConfigurationHandler::AllowCellularDataUsage()
+    {
+    PROFILE_DEBUG1("DatabaseMonitoringCompletedL::AllowCellularDataUsage Enter" );
+    iRepository->Set( KCurrentCellularDataUsage, iCurrentUsageStatus );
+    iDBMonitoringRetryCount = 0;
+    iCellularDataBlocked = EFalse;
+    PROFILE_DEBUG1("DatabaseMonitoringCompletedL::AllowCellularDataUsage Exit" );
+    }
+
+// -----------------------------------------------------------------------------
+// CSIPApnConfigurationHandler::RollBackDBTransaction
+// -----------------------------------------------------------------------------
+//
+void CSIPApnConfigurationHandler::RollBackDBTransaction(TAny* aDb)
+    {
+    CMDBSession* db = static_cast<CMDBSession*>(aDb);
+    TRAP_IGNORE(db->RollbackTransactionL());
+    }
+
 // End of file