cmmanager/cmmgr/cmmserver/src/cmmcache.cpp
changeset 27 489cf6208544
parent 23 7ec726f93df1
child 32 5c4486441ae6
child 46 95d45f234cf3
equal deleted inserted replaced
23:7ec726f93df1 27:489cf6208544
   399         User::Leave( KErrArgument );
   399         User::Leave( KErrArgument );
   400         }
   400         }
   401 
   401 
   402 
   402 
   403     // Store the connection method into cache.
   403     // Store the connection method into cache.
   404     CCmmConnMethodStruct* connMethodStruct = CCmmConnMethodStruct::NewLC( connMethodId ); // Use connMethodId here, so ID is either a real ID or a temporary ID.
   404     // Use connMethodId here, so ID is either a real ID or a temporary ID.
       
   405     CCmmConnMethodStruct* connMethodStruct = CCmmConnMethodStruct::NewL( connMethodId );
   405     connMethodStruct->SetPlugin( plugin, aBearerType, ECmmConnMethodStatusNotSaved );
   406     connMethodStruct->SetPlugin( plugin, aBearerType, ECmmConnMethodStatusNotSaved );
       
   407     CleanupStack::Pop( plugin );
       
   408     CleanupStack::PushL( connMethodStruct );
   406     iConnMethodArray.AppendL( connMethodStruct );
   409     iConnMethodArray.AppendL( connMethodStruct );
   407     CleanupStack::Pop( connMethodStruct );
   410     CleanupStack::Pop( connMethodStruct );
   408     CleanupStack::Pop( plugin ); //TODO, pop after SetPlugin()-call?
       
   409 
   411 
   410     // Copy the connection method data to session instance.
   412     // Copy the connection method data to session instance.
   411     aConnMethodInstance.CopyDataL( connMethodStruct ); // Will increase reference counter.
   413     aConnMethodInstance.CopyDataL( connMethodStruct ); // Will increase reference counter.
   412 
   414 
   413 
   415 
   414     if ( aDestinationInstance )
   416     if ( aDestinationInstance )
   415         {
   417         {
   416         // Add connection method to destination.
   418         // Add connection method to destination.
   417         aDestinationInstance->AddConnMethodL( aConnMethodInstance );
   419         aDestinationInstance->AddConnMethodL( aConnMethodInstance );
   418         }
   420         }
       
   421 
   419     OstTraceFunctionExit0( CCMMCACHE_CREATECONNMETHODL_EXIT );
   422     OstTraceFunctionExit0( CCMMCACHE_CREATECONNMETHODL_EXIT );
   420     }
   423     }
   421 
   424 
   422 // ---------------------------------------------------------------------------
   425 // ---------------------------------------------------------------------------
   423 // Creates a new connection method into cache as a copy of an existing
   426 // Creates a new connection method into cache as a copy of an existing
   443     if ( !plugin )
   446     if ( !plugin )
   444         {
   447         {
   445         User::Leave( KErrNotFound );
   448         User::Leave( KErrNotFound );
   446         }
   449         }
   447 
   450 
   448     CCmPluginBaseEng* pluginCopy = plugin->CreateCopyL( aConnMethodInstance.GetPluginDataInstance() );
   451     CCmPluginBaseEng* pluginCopy =
       
   452             plugin->CreateCopyL( aConnMethodInstance.GetPluginDataInstance() );
   449     CleanupStack::PushL( pluginCopy );
   453     CleanupStack::PushL( pluginCopy );
   450 
   454 
   451     // Store the connection method into cache.
   455     // Store the connection method into cache.
   452     CCmmConnMethodStruct* connMethodStruct = CCmmConnMethodStruct::NewLC( NextFreeTemporaryId() );
   456     CCmmConnMethodStruct* connMethodStruct =
   453     connMethodStruct->SetPlugin( pluginCopy, aConnMethodInstance.GetBearerType(), ECmmConnMethodStatusNotSaved );
   457             CCmmConnMethodStruct::NewL( NextFreeTemporaryId() );
       
   458     connMethodStruct->SetPlugin(
       
   459             pluginCopy,
       
   460             aConnMethodInstance.GetBearerType(),
       
   461             ECmmConnMethodStatusNotSaved );
       
   462     CleanupStack::Pop( pluginCopy );
       
   463     CleanupStack::PushL( connMethodStruct );
   454     iConnMethodArray.AppendL( connMethodStruct );
   464     iConnMethodArray.AppendL( connMethodStruct );
   455     CleanupStack::Pop( connMethodStruct );
   465     CleanupStack::Pop( connMethodStruct );
   456     CleanupStack::Pop( pluginCopy ); //TODO, pop after SetPlugin()-call?
       
   457 
   466 
   458     // Copy the connection method data to session instance.
   467     // Copy the connection method data to session instance.
   459     aNewConnMethodInstance.CopyDataL( connMethodStruct ); // Will increase reference counter.
   468     aNewConnMethodInstance.CopyDataL( connMethodStruct ); // Will increase reference counter.
   460 
   469 
   461     OstTraceFunctionExit0( CCMMCACHE_CREATECOPYOFCONNMETHODL_EXIT );
   470     OstTraceFunctionExit0( CCMMCACHE_CREATECOPYOFCONNMETHODL_EXIT );
  2101         {
  2110         {
  2102         User::Leave( KErrNotSupported );
  2111         User::Leave( KErrNotSupported );
  2103         }
  2112         }
  2104 
  2113 
  2105     // Store the connection method into cache.
  2114     // Store the connection method into cache.
  2106     CCmmConnMethodStruct* connMethodStruct = CCmmConnMethodStruct::NewLC( aConnMethodId );
  2115     CCmmConnMethodStruct* connMethodStruct = CCmmConnMethodStruct::NewL( aConnMethodId );
  2107     connMethodStruct->SetPlugin( plugin, bearerType, ECmmConnMethodStatusValid );
  2116     connMethodStruct->SetPlugin( plugin, bearerType, ECmmConnMethodStatusValid );
       
  2117     CleanupStack::Pop( plugin );
       
  2118     CleanupStack::PushL( connMethodStruct );
  2108     iConnMethodArray.AppendL( connMethodStruct );
  2119     iConnMethodArray.AppendL( connMethodStruct );
  2109     CleanupStack::Pop( connMethodStruct );
  2120     CleanupStack::Pop( connMethodStruct );
  2110     CleanupStack::Pop( plugin ); //TODO, pop after SetPlugin()-call?
       
  2111 
  2121 
  2112     // Copy the connection method data to session instance.
  2122     // Copy the connection method data to session instance.
  2113     aConnMethodInstance.CopyDataL( connMethodStruct ); // Will increase reference counter.
  2123     aConnMethodInstance.CopyDataL( connMethodStruct ); // Will increase reference counter.
  2114 
  2124 
  2115     OstTraceFunctionExit0( CCMMCACHE_OPENCONNECTIONMETHODINSTANCEL_EXIT );
  2125     OstTraceFunctionExit0( CCMMCACHE_OPENCONNECTIONMETHODINSTANCEL_EXIT );
  2873 // ---------------------------------------------------------------------------
  2883 // ---------------------------------------------------------------------------
  2874 //
  2884 //
  2875 void CCmmCache::CheckIfConnMethodReferencesCanBeRemovedL(
  2885 void CCmmCache::CheckIfConnMethodReferencesCanBeRemovedL(
  2876         const CCmmConnMethodInstance& aConnMethodInstance )
  2886         const CCmmConnMethodInstance& aConnMethodInstance )
  2877     {
  2887     {
       
  2888     OstTraceFunctionEntry0( CCMMCACHE_CHECKIFCONNMETHODREFERENCESCANBEREMOVEDL_ENTRY );
       
  2889 
  2878     TUint32 connMethodId( aConnMethodInstance.GetId() );
  2890     TUint32 connMethodId( aConnMethodInstance.GetId() );
  2879 
  2891 
  2880     // Check that connection method exists in database.
  2892     // Check that connection method exists in database.
  2881     if ( !iInstanceMapping->ValidConnMethodId( connMethodId ) )
  2893     if ( !iInstanceMapping->ValidConnMethodId( connMethodId ) )
  2882         {
  2894         {
  2886     // Can't remove an embedded destination this way.
  2898     // Can't remove an embedded destination this way.
  2887     if ( aConnMethodInstance.IsEmbeddedDestination() )
  2899     if ( aConnMethodInstance.IsEmbeddedDestination() )
  2888         {
  2900         {
  2889         User::Leave( KErrArgument );
  2901         User::Leave( KErrArgument );
  2890         }
  2902         }
  2891 
       
  2892     //TODO, what if protected?
       
  2893 
  2903 
  2894     // Iterate all destinations in database and check if possible reference can
  2904     // Iterate all destinations in database and check if possible reference can
  2895     // be removed.
  2905     // be removed.
  2896     RArray<TUint32> dbDestinations;
  2906     RArray<TUint32> dbDestinations;
  2897     CleanupClosePushL( dbDestinations );
  2907     CleanupClosePushL( dbDestinations );
  2908     // Can't remove a connection method that is in use.
  2918     // Can't remove a connection method that is in use.
  2909     if ( CheckIfCmConnected( connMethodId ) )
  2919     if ( CheckIfCmConnected( connMethodId ) )
  2910         {
  2920         {
  2911         User::Leave( KErrInUse );
  2921         User::Leave( KErrInUse );
  2912         }
  2922         }
       
  2923 
       
  2924     OstTraceFunctionExit0( CCMMCACHE_CHECKIFCONNMETHODREFERENCESCANBEREMOVEDL_EXIT );
       
  2925     }
       
  2926 
       
  2927 // ---------------------------------------------------------------------------
       
  2928 // Check if the given connection method can have all references removed and
       
  2929 // made into an uncategorized connection method. //TODO, fix comment, this looks like copy&paste from above
       
  2930 // ---------------------------------------------------------------------------
       
  2931 //
       
  2932 void CCmmCache::CheckIfConnMethodBelongsToProtectedDestinationL(
       
  2933         const CCmmConnMethodInstance& aConnMethodInstance,
       
  2934         TBool& aBelongsToProtectedDestination )
       
  2935     {
       
  2936     OstTraceFunctionEntry0( CCMMCACHE_CHECKIFCONNMETHODBELONGSTOPROTECTEDDESTINATIONL_ENTRY );
       
  2937 
       
  2938     TUint32 connMethodId( aConnMethodInstance.GetId() );
       
  2939 
       
  2940     // Check that connection method exists in database.
       
  2941     if ( !iInstanceMapping->ValidConnMethodId( connMethodId ) )
       
  2942         {
       
  2943         User::Leave( KErrNotFound );
       
  2944         }
       
  2945 
       
  2946     aBelongsToProtectedDestination = EFalse;
       
  2947     // Get destinations which have references to connection method passed as parameter.
       
  2948     RArray<TUint32> dbDestinations;
       
  2949     CleanupClosePushL( dbDestinations );
       
  2950     iInstanceMapping->DestinationsContainingConnMethodL( connMethodId, dbDestinations );
       
  2951     TUint32 metadata( 0 );
       
  2952     for ( TInt i = 0; i < dbDestinations.Count(); i++ )
       
  2953         {
       
  2954         // Check if any of destinations is protected.
       
  2955         metadata = iInstanceMapping->DestinationMetadata( dbDestinations[i] );
       
  2956         TUint32 protlevel = ( metadata & KDestProtectionLevelMask ) >> KBitsToShiftDestProtectionLevel;
       
  2957         if ( protlevel == CMManager::EProtLevel1 || protlevel == CMManager::EProtLevel3 )
       
  2958             {
       
  2959             aBelongsToProtectedDestination = ETrue;
       
  2960             break;
       
  2961             }
       
  2962         }
       
  2963     CleanupStack::PopAndDestroy( &dbDestinations );
       
  2964 
       
  2965     OstTraceFunctionExit0( CCMMCACHE_CHECKIFCONNMETHODBELONGSTOPROTECTEDDESTINATIONL_EXIT );
  2913     }
  2966     }
  2914 
  2967 
  2915 // ---------------------------------------------------------------------------
  2968 // ---------------------------------------------------------------------------
  2916 // Check if the given connection method can be deleted.
  2969 // Check if the given connection method can be deleted.
  2917 // ---------------------------------------------------------------------------
  2970 // ---------------------------------------------------------------------------
  2918 //
  2971 //
  2919 void CCmmCache::CheckIfConnMethodCanBeDeletedL(
  2972 void CCmmCache::CheckIfConnMethodCanBeDeletedL(
  2920         const CCmmConnMethodInstance& aConnMethodInstance )
  2973         const CCmmConnMethodInstance& aConnMethodInstance )
  2921     {
  2974     {
       
  2975     OstTraceFunctionEntry0( CCMMCACHE_CHECKIFCONNMETHODCANBEDELETEDL_ENTRY );
       
  2976 
  2922     TUint32 connMethodId( aConnMethodInstance.GetId() );
  2977     TUint32 connMethodId( aConnMethodInstance.GetId() );
  2923 
  2978 
  2924     // Find connection method from cache.
  2979     // Find connection method from cache.
  2925     TInt index = FindConnMethodFromCache( connMethodId );
  2980     TInt index = FindConnMethodFromCache( connMethodId );
  2926     if ( index == KErrNotFound )
  2981     if ( index == KErrNotFound )
  2959     // Check that no virtual IAP points to this connection method.
  3014     // Check that no virtual IAP points to this connection method.
  2960     if ( iInstanceMapping->ConnMethodPointedToByVirtualIap( connMethodId ) )
  3015     if ( iInstanceMapping->ConnMethodPointedToByVirtualIap( connMethodId ) )
  2961         {
  3016         {
  2962         User::Leave( KErrLocked );
  3017         User::Leave( KErrLocked );
  2963         }
  3018         }
       
  3019 
       
  3020     OstTraceFunctionExit0( CCMMCACHE_CHECKIFCONNMETHODCANBEDELETEDL_EXIT );
  2964     }
  3021     }
  2965 
  3022 
  2966 // ---------------------------------------------------------------------------
  3023 // ---------------------------------------------------------------------------
  2967 // Check if the given destination can be deleted.
  3024 // Check if the given destination can be deleted.
  2968 // ---------------------------------------------------------------------------
  3025 // ---------------------------------------------------------------------------
  2969 //
  3026 //
  2970 void CCmmCache::CheckIfDestinationCanBeDeletedL(
  3027 void CCmmCache::CheckIfDestinationCanBeDeletedL(
  2971         const CCmmDestinationInstance& aDestinationInstance )
  3028         const CCmmDestinationInstance& aDestinationInstance )
  2972     {
  3029     {
       
  3030     OstTraceFunctionEntry0( CCMMCACHE_CHECKIFDESTINATIONCANBEDELETEDL_ENTRY );
       
  3031 
  2973     TUint32 destinationId( aDestinationInstance.GetId() );
  3032     TUint32 destinationId( aDestinationInstance.GetId() );
  2974 
  3033 
  2975     // Find destination from cache.
  3034     // Find destination from cache.
  2976     TInt index = FindDestinationFromCache( destinationId );
  3035     TInt index = FindDestinationFromCache( destinationId );
  2977     if ( index == KErrNotFound )
  3036     if ( index == KErrNotFound )
  3017     // Check if any of the connection methods in this destination are currently in use.
  3076     // Check if any of the connection methods in this destination are currently in use.
  3018     if ( DestinationConnectedL( destinationId ) )
  3077     if ( DestinationConnectedL( destinationId ) )
  3019         {
  3078         {
  3020         User::Leave( KErrInUse );
  3079         User::Leave( KErrInUse );
  3021         }
  3080         }
       
  3081 
       
  3082     OstTraceFunctionExit0( CCMMCACHE_CHECKIFDESTINATIONCANBEDELETEDL_EXIT );
  3022     }
  3083     }
  3023 
  3084 
  3024 // ---------------------------------------------------------------------------
  3085 // ---------------------------------------------------------------------------
  3025 // Return the requested table ID.
  3086 // Return the requested table ID.
  3026 // ---------------------------------------------------------------------------
  3087 // ---------------------------------------------------------------------------
  3033 // ---------------------------------------------------------------------------
  3094 // ---------------------------------------------------------------------------
  3034 // Initiate the deletion of given destination if none of the connection
  3095 // Initiate the deletion of given destination if none of the connection
  3035 // methods inside it are connected.
  3096 // methods inside it are connected.
  3036 // ---------------------------------------------------------------------------
  3097 // ---------------------------------------------------------------------------
  3037 //
  3098 //
  3038 void CCmmCache::DeleteDestinationForcedL( CCmmDestinationInstance& aDestinationInstance ) //TODO, OST
  3099 void CCmmCache::DeleteDestinationForcedL( CCmmDestinationInstance& aDestinationInstance )
  3039     {
  3100     {
  3040     //TODO
  3101     OstTraceFunctionEntry0( CCMMCACHE_DELETEDESTINATIONFORCEDL_ENTRY );
       
  3102 
  3041     if ( !DestinationConnectedL( 0, &aDestinationInstance ) )
  3103     if ( !DestinationConnectedL( 0, &aDestinationInstance ) )
  3042         {
  3104         {
  3043         DeleteDestinationL( aDestinationInstance, ETrue );
  3105         DeleteDestinationL( aDestinationInstance, ETrue );
  3044         }
  3106         }
       
  3107 
       
  3108     OstTraceFunctionExit0( CCMMCACHE_DELETEDESTINATIONFORCEDL_EXIT );
  3045     }
  3109     }
  3046 
  3110 
  3047 // End of file
  3111 // End of file