satengine/SatServer/Engine/src/CSatApnHandler.cpp
branchRCL_3
changeset 8 ba42c4bd84dd
parent 5 7237db0d9fca
child 18 594d59766373
--- a/satengine/SatServer/Engine/src/CSatApnHandler.cpp	Wed Mar 31 22:34:38 2010 +0300
+++ b/satengine/SatServer/Engine/src/CSatApnHandler.cpp	Wed Apr 14 16:32:24 2010 +0300
@@ -22,6 +22,8 @@
 #include <cmconnectionmethodext.h>
 #include <cmconnectionmethoddef.h>
 #include <cmpluginpacketdatadef.h>
+#include <cmdestination.h>
+#include <cmmanagerdef.h>
 
 #include    "MSatUtils.h"
 #include    "CSatApnHandler.h"
@@ -386,4 +388,74 @@
     return formatApnName;
     }
 
+// -----------------------------------------------------------------------------
+// CSatApnHandler::FindDefaultApL
+// -----------------------------------------------------------------------------
+//
+TUint32 CSatApnHandler::FindDefaultApL(
+        const RPacketContext::TProtocolType& aPdpType )
+    {
+    LOG( SIMPLE, "SATENGINE: CSatApnHandler::FindDefaultApL calling" );
+    TUint32 defaultIap( 0 );
+    TInt pdpType;
+    TBool isFound( EFalse );
+
+    // create a network destination
+    RCmDestination des;
+    RCmConnectionMethod cm;
+
+    // Create CMManager Session
+    RCmManager cmManager;
+    cmManager.OpenL();
+    CleanupClosePushL( cmManager );
+
+    // Get the Connection Method list from the open CMManager session
+    RArray<TUint32> array = RArray<TUint32>( KSatCMGranularity );
+    CleanupClosePushL( array );
+
+    // list all available destinations' id
+    cmManager.AllDestinationsL( array );
+    for( TInt i = 0; ( i < array.Count() ) && !isFound; ++i )
+        {
+        des = cmManager.DestinationL( array[i] );
+        CleanupClosePushL( des );
+
+        if ( CMManager::ESnapPurposeInternet ==
+        des.MetadataL( CMManager::ESnapMetadataPurpose ) )
+            {
+            LOG( SIMPLE, "SATENGINE: CSatApnHandler::FindDefaultApL \
+            the fixed destination is identified as 'Internet'" );
+            for( TInt j = 0; ( j < des.ConnectionMethodCount() ) &&
+            !isFound; ++j )
+                {
+                cm = des.ConnectionMethodL( j );
+                CleanupClosePushL( cm );
+                pdpType = cm.GetIntAttributeL(
+                        CMManager::EPacketDataPDPType );
+                LOG2( SIMPLE, "SATENGINE: CSatApnHandler::FindDefaultApL \
+                        current protocol type is %d", pdpType )
+                if ( pdpType == aPdpType )
+                    {
+                    defaultIap = cm.GetIntAttributeL( CMManager::ECmIapId );
+                    isFound  = ETrue;
+                    LOG2( SIMPLE, "SATENGINE: CSatApnHandler::FindDefaultApL \
+                            default iap had been found %d", defaultIap )
+                    }
+                CleanupStack::PopAndDestroy( &cm );
+                }
+            }
+        CleanupStack::PopAndDestroy( &des );
+        }
+    CleanupStack::PopAndDestroy( &array );
+    CleanupStack::PopAndDestroy( &cmManager );
+
+    if ( !isFound )
+        {
+        LOG( SIMPLE, "SATENGINE: CSatApnHandler: default AP not found" );
+        User::Leave( KErrNotFound );
+        }
+
+    LOG( SIMPLE, "SATENGINE: CSatApnHandler::FindDefaultApL exit" )
+    return defaultIap;
+    }
 //  End of File