cmmanager/cmmgr/cmmserver/src/cmmcache.cpp
changeset 53 4af712113915
parent 46 95d45f234cf3
child 66 ed07dcc72692
equal deleted inserted replaced
47:cb7afde124a3 53:4af712113915
   123     iInstanceMapping = NULL;
   123     iInstanceMapping = NULL;
   124     iTrans = NULL;
   124     iTrans = NULL;
   125     iBearerPriorityCache = NULL;
   125     iBearerPriorityCache = NULL;
   126     iCurrentTemporaryId = KTemporaryIdCounterStart;
   126     iCurrentTemporaryId = KTemporaryIdCounterStart;
   127 
   127 
       
   128     iSnapTableId = 0;
       
   129     iSnapMetadataTableId = 0;
       
   130 
   128     OstTraceFunctionExit0( DUP1_CCMMCACHE_CCMMCACHE_EXIT );
   131     OstTraceFunctionExit0( DUP1_CCMMCACHE_CCMMCACHE_EXIT );
   129     }
   132     }
   130 
   133 
   131 // ---------------------------------------------------------------------------
   134 // ---------------------------------------------------------------------------
   132 // Second phase constructor.
   135 // Second phase constructor.
   141     iBearerPriorityCache = CCmmBearerPriorityCache::NewL(
   144     iBearerPriorityCache = CCmmBearerPriorityCache::NewL(
   142             iTrans,
   145             iTrans,
   143             iCmManagerImpl->TableId( ECmmDbBearerPriorityRecord ) );
   146             iCmManagerImpl->TableId( ECmmDbBearerPriorityRecord ) );
   144     iListenerManager = CCmmListenerManager::NewL( this );
   147     iListenerManager = CCmmListenerManager::NewL( this );
   145     iInstanceMapping = CCmmInstanceMapping::NewL( *this );
   148     iInstanceMapping = CCmmInstanceMapping::NewL( *this );
       
   149 
       
   150     // Create CommsDat listeners to detect changes to the database from external sources.
       
   151     RArray<TUint32> tableIdArray;
       
   152     CleanupClosePushL( tableIdArray );
       
   153 
       
   154     iSnapTableId = iCmManagerImpl->TableId( ECmmDbSnapRecord );
       
   155     iSnapMetadataTableId = iCmManagerImpl->TableId( ECmmDestMetadataRecord );
       
   156 
       
   157     // Instancemapping needs notifications on following tables.
       
   158     tableIdArray.Append( CommsDat::KCDTIdIAPRecord );
       
   159     tableIdArray.Append( CommsDat::KCDTIdVPNServiceRecord );
       
   160     tableIdArray.Append( iSnapTableId );
       
   161     tableIdArray.Append( iSnapMetadataTableId );
       
   162 
       
   163     // Destinations need notifications on following tables.
       
   164     tableIdArray.Append( CommsDat::KCDTIdNetworkRecord );
       
   165     tableIdArray.Append( CommsDat::KCDTIdAccessPointRecord );
       
   166     // Destination metadata table was already added.
       
   167 
       
   168     // Connection methods need notifications on following tables.
       
   169     TInt pluginCount( iPlugins->Count() );
       
   170     if ( pluginCount )
       
   171         {
       
   172         ( *iPlugins )[0]->GetGenericTableIdsToBeObservedL( tableIdArray );
       
   173         for( TInt i = 0; i < pluginCount; i++ )
       
   174             {
       
   175             ( *iPlugins )[i]->GetBearerTableIdsToBeObservedL( tableIdArray );
       
   176             }
       
   177         }
       
   178 
       
   179     for ( TInt i = 0; i < tableIdArray.Count(); i++ )
       
   180         {
       
   181         iListenerManager->AddListenerL( tableIdArray[i] );
       
   182         }
       
   183     CleanupStack::PopAndDestroy( &tableIdArray );
   146 
   184 
   147     OstTraceFunctionExit0( CCMMCACHE_CONSTRUCTL_EXIT );
   185     OstTraceFunctionExit0( CCMMCACHE_CONSTRUCTL_EXIT );
   148     }
   186     }
   149 
   187 
   150 // ---------------------------------------------------------------------------
   188 // ---------------------------------------------------------------------------
   268     // Check connection method ID.
   306     // Check connection method ID.
   269     TBool validAttributes( EFalse );
   307     TBool validAttributes( EFalse );
   270     if ( !aDestinationInstance )
   308     if ( !aDestinationInstance )
   271         {
   309         {
   272         // Check connection method exists in database.
   310         // Check connection method exists in database.
   273         validAttributes = iInstanceMapping->ValidConnMethodId( aConnMethodId ); // Embedded destinations not included.
   311         // Embedded destinations not included.
       
   312         validAttributes = iInstanceMapping->ValidConnMethodId( aConnMethodId );
   274         }
   313         }
   275     else
   314     else
   276         {
   315         {
   277         // Check connection method is inside the destination.
   316         // Check connection method is inside the destination.
   278         if ( aDestinationInstance->ValidConnMethodIdInDestinationIncludeEmbedded( aConnMethodId ) )
   317         if ( aDestinationInstance->
   279             {
   318                 ValidConnMethodIdInDestinationIncludeEmbedded( aConnMethodId ) )
   280             // Check connection method (can be embedded destination too) exists in database.
   319             {
       
   320             // Check connection method (can be embedded destination too)
       
   321             // exists in database.
   281             if ( iInstanceMapping->ValidConnMethodId( aConnMethodId ) ||
   322             if ( iInstanceMapping->ValidConnMethodId( aConnMethodId ) ||
   282                     iInstanceMapping->ValidDestinationId( aConnMethodId ) )
   323                     iInstanceMapping->ValidDestinationId( aConnMethodId ) )
   283                 {
   324                 {
   284                 validAttributes = ETrue;
   325                 validAttributes = ETrue;
   285                 }
   326                 }
   294 
   335 
   295     // Check if connection method is already opened in cache.
   336     // Check if connection method is already opened in cache.
   296     TInt index = FindConnMethodFromCache( aConnMethodId );
   337     TInt index = FindConnMethodFromCache( aConnMethodId );
   297     if ( index != KErrNotFound )
   338     if ( index != KErrNotFound )
   298         {
   339         {
       
   340         // Update data from commsdat if necessary.
       
   341         if ( iConnMethodArray[index]->GetRecordStatus() == ECmmRecordStatusExpired )
       
   342             {
       
   343             iConnMethodArray[index]->ReloadPluginDataIfNeededL();
       
   344             // CopyDataL() will set the internal state of aConnMethodInstance.
       
   345             }
       
   346 
   299         // Already open in cache. Copy the connection method data to session
   347         // Already open in cache. Copy the connection method data to session
   300         // instance.
   348         // instance.
   301         aConnMethodInstance.CopyDataL( iConnMethodArray[index] ); // Will increase reference counter.
   349         // Will increase reference counter.
       
   350         aConnMethodInstance.CopyDataL( iConnMethodArray[index] );
   302         }
   351         }
   303     else
   352     else
   304         {
   353         {
   305         // Not yet open in cache, open now.
   354         // Not yet open in cache, open now.
   306         OpenConnectionMethodInstanceL( aConnMethodInstance, aConnMethodId );
   355         OpenConnectionMethodInstanceL( aConnMethodInstance, aConnMethodId );
   337         {
   386         {
   338         OstTraceFunctionExit0( CCMMCACHE_REFRESHCONNMETHODL_EXIT );
   387         OstTraceFunctionExit0( CCMMCACHE_REFRESHCONNMETHODL_EXIT );
   339         return;
   388         return;
   340         }
   389         }
   341 
   390 
   342     iConnMethodArray[index]->RefreshConnMethodInstanceL( aConnMethodInstance );
   391     iConnMethodArray[index]->ReloadPluginDataIfNeededL();
       
   392     if ( iConnMethodArray[index]->GetStatus() == ECmmConnMethodStatusValid
       
   393             || iConnMethodArray[index]->GetStatus() == ECmmConnMethodStatusToBeDeleted )
       
   394         {
       
   395         iConnMethodArray[index]->GetPlugin()->GetPluginDataL( 
       
   396                 aConnMethodInstance.GetPluginDataInstance() );
       
   397         }
       
   398     // Internal state need to be set to the same state as after a successfull update.
       
   399     aConnMethodInstance.UpdateSuccessful();
   343 
   400 
   344     OstTraceFunctionExit0( DUP1_CCMMCACHE_REFRESHCONNMETHODL_EXIT );
   401     OstTraceFunctionExit0( DUP1_CCMMCACHE_REFRESHCONNMETHODL_EXIT );
   345     }
   402     }
   346 
   403 
   347 // ---------------------------------------------------------------------------
   404 // ---------------------------------------------------------------------------
   473 
   530 
   474     OstTraceFunctionExit0( CCMMCACHE_CREATECOPYOFCONNMETHODL_EXIT );
   531     OstTraceFunctionExit0( CCMMCACHE_CREATECOPYOFCONNMETHODL_EXIT );
   475     }
   532     }
   476 
   533 
   477 // ---------------------------------------------------------------------------
   534 // ---------------------------------------------------------------------------
   478 // Re-loads a destination record if needed and copies the latest version to
   535 // Reloads a destination record if needed and copies the latest version to
   479 // the session instance given as parameter.
   536 // the session instance given as parameter.
   480 // ---------------------------------------------------------------------------
   537 // ---------------------------------------------------------------------------
   481 //
   538 //
   482 void CCmmCache::LoadDestinationRecordL(
   539 void CCmmCache::LoadDestinationRecordL(
   483         CCmmDestinationInstance& aDestinationInstance,
   540         CCmmDestinationInstance& aDestinationInstance,
  1616 // has possibly changed, the cache will refresh that information immediately.
  1673 // has possibly changed, the cache will refresh that information immediately.
  1617 // For other database tables, the tables are flagged and will be refreshed when
  1674 // For other database tables, the tables are flagged and will be refreshed when
  1618 // needed.
  1675 // needed.
  1619 // ---------------------------------------------------------------------------
  1676 // ---------------------------------------------------------------------------
  1620 //
  1677 //
  1621 void CCmmCache::DbChangeDetected( const TUint32 aTableId )
  1678 void CCmmCache::DbChangeDetectedL( const TUint32 aTableId )
  1622     {
  1679     {
  1623     OstTraceFunctionEntry0( CCMMCACHE_DBCHANGEDETECTED_ENTRY );
  1680     OstTraceFunctionEntry0( CCMMCACHE_DBCHANGEDETECTED_ENTRY );
  1624 
  1681 
  1625     (void)aTableId; //TODO
  1682     if ( aTableId == iSnapMetadataTableId )
  1626     // Flag the table as: currently not up-to-date
  1683         {
       
  1684         for ( TInt i = 0; i < iDestinationArray.Count(); i++ )
       
  1685             {
       
  1686             iDestinationArray[i]->NotifyRecordChange( ECmmDestMetadataRecord );
       
  1687             }
       
  1688         }
       
  1689     else if ( aTableId == CommsDat::KCDTIdNetworkRecord )
       
  1690         {
       
  1691         // Affects destinations.
       
  1692         for ( TInt i = 0; i < iDestinationArray.Count(); i++ )
       
  1693             {
       
  1694             iDestinationArray[i]->NotifyRecordChange( ECmmDestNetworkRecord );
       
  1695             }
       
  1696         }
       
  1697     else if ( aTableId == CommsDat::KCDTIdAccessPointRecord )
       
  1698         {
       
  1699         // Affects destinations.
       
  1700         for ( TInt i = 0; i < iDestinationArray.Count(); i++ )
       
  1701             {
       
  1702             iDestinationArray[i]->NotifyRecordChange( ECmmDestApRecord );
       
  1703             }
       
  1704         }
       
  1705 
       
  1706     // Notify Connection Methods about the table changes in CommsDat.
       
  1707     NotifyPluginsForTableChangesL( aTableId );
       
  1708 
       
  1709     // Update instancemapping.
       
  1710     iInstanceMapping->RefreshL();
       
  1711 
  1627     OstTraceFunctionExit0( CCMMCACHE_DBCHANGEDETECTED_EXIT );
  1712     OstTraceFunctionExit0( CCMMCACHE_DBCHANGEDETECTED_EXIT );
       
  1713     }
       
  1714 
       
  1715 // ---------------------------------------------------------------------------
       
  1716 // Informs all the loaded iaps if something related to their tables
       
  1717 // changed in commsdat.
       
  1718 // ---------------------------------------------------------------------------
       
  1719 //
       
  1720 void CCmmCache::NotifyPluginsForTableChangesL( const TUint32 aTableId )
       
  1721     {
       
  1722     OstTraceFunctionEntry0( CCMMCACHE_NOTIFYPLUGINSFORTABLECHANGESL_ENTRY );
       
  1723 
       
  1724     if ( iConnMethodArray.Count() )
       
  1725         {
       
  1726         RArray<TUint32> tableIdArray;
       
  1727         CleanupClosePushL( tableIdArray );
       
  1728 
       
  1729         // Check if change concerns some table generic for all iaps
       
  1730         ( *iPlugins )[0]->GetGenericTableIdsToBeObservedL( tableIdArray );
       
  1731         TBool generic( EFalse );
       
  1732         for( TInt i = 0; i < tableIdArray.Count(); i++ )
       
  1733             {
       
  1734             if ( aTableId == tableIdArray[i] )
       
  1735                 {
       
  1736                 generic = ETrue;
       
  1737                 break;
       
  1738                 }
       
  1739             }
       
  1740 
       
  1741         if ( generic )
       
  1742             {
       
  1743             // generic-->Notify all iaps
       
  1744             for( TInt i = 0; i < iConnMethodArray.Count(); i++ )
       
  1745                 {
       
  1746                 iConnMethodArray[i]->NotifyRecordChange( aTableId );
       
  1747                 }
       
  1748             }
       
  1749         else
       
  1750             {
       
  1751             // Not generic: Check bearer specific tables
       
  1752             RArray<TUint32> affectedBearersArray;
       
  1753             CleanupClosePushL( affectedBearersArray );
       
  1754             for( TInt i = 0; i < iPlugins->Count(); i++ )
       
  1755                 {
       
  1756                 tableIdArray.Reset();
       
  1757                 ( *iPlugins )[i]->GetBearerTableIdsToBeObservedL( tableIdArray );
       
  1758                 TInt idCount = tableIdArray.Count();
       
  1759                 for( TInt j = 0; j < idCount; j++ )
       
  1760                     {
       
  1761                     if ( aTableId == tableIdArray[j] )
       
  1762                         {
       
  1763                         // Save the bearer type id which is affected
       
  1764                         affectedBearersArray.AppendL(
       
  1765                                 ( *iPlugins )[i]->GetBearerInfoIntL(
       
  1766                                         CMManager::ECmBearerType ) );
       
  1767                         }
       
  1768                     }
       
  1769                 }
       
  1770 
       
  1771             // Go through all the loaded iaps and notify all the iaps
       
  1772             // which have the same bearer type saved above
       
  1773             for( TInt i = 0; i < iConnMethodArray.Count(); i++ )
       
  1774                 {
       
  1775                 for( TInt j = 0; j < affectedBearersArray.Count(); j++ )
       
  1776                     {
       
  1777                     if ( iConnMethodArray[i]->GetBearerType() == affectedBearersArray[j] )
       
  1778                         {
       
  1779                         iConnMethodArray[i]->NotifyRecordChange( aTableId );
       
  1780                         break;
       
  1781                         }
       
  1782                     }
       
  1783                 }
       
  1784             CleanupStack::PopAndDestroy( &affectedBearersArray );
       
  1785             }
       
  1786         CleanupStack::PopAndDestroy( &tableIdArray );
       
  1787         }
       
  1788     OstTraceFunctionExit0( CCMMCACHE_NOTIFYPLUGINSFORTABLECHANGESL_EXIT );
  1628     }
  1789     }
  1629 
  1790 
  1630 // ---------------------------------------------------------------------------
  1791 // ---------------------------------------------------------------------------
  1631 // Tells the cache that an error has occured with a database listener. Any
  1792 // Tells the cache that an error has occured with a database listener. Any
  1632 // reads to this table need go through the database, since cache can't know if
  1793 // reads to this table need go through the database, since cache can't know if
  1637     {
  1798     {
  1638     OstTraceFunctionEntry0( CCMMCACHE_DBCHANGEERROR_ENTRY );
  1799     OstTraceFunctionEntry0( CCMMCACHE_DBCHANGEERROR_ENTRY );
  1639 
  1800 
  1640     (void)aTableId; //TODO
  1801     (void)aTableId; //TODO
  1641     // Flag the table as: permanently not up-to-date
  1802     // Flag the table as: permanently not up-to-date
       
  1803 
       
  1804     //TODO, How to do this?
       
  1805     // Implement some 'status locked' flags that are always checked before changing status back to 'loaded' after reading database?
       
  1806     // Or move record status info to CCmmCache-class?
       
  1807     // What about plugins?
       
  1808 	// Or just ignore errors with notifiers?
       
  1809 
       
  1810     // For now, just ignore errors.
       
  1811 
  1642     OstTraceFunctionExit0( CCMMCACHE_DBCHANGEERROR_EXIT );
  1812     OstTraceFunctionExit0( CCMMCACHE_DBCHANGEERROR_EXIT );
  1643     }
  1813     }
  1644 
  1814 
  1645 // ---------------------------------------------------------------------------
  1815 // ---------------------------------------------------------------------------
  1646 // Tells the cache that a hadle to a destination was closed. The cache will
  1816 // Tells the cache that a hadle to a destination was closed. The cache will
  2126     {
  2296     {
  2127     OstTraceFunctionEntry0( CCMMCACHE_OPENCONNECTIONMETHODINSTANCEL_ENTRY );
  2297     OstTraceFunctionEntry0( CCMMCACHE_OPENCONNECTIONMETHODINSTANCEL_ENTRY );
  2128 
  2298 
  2129     // Find out the connection method bearer type.
  2299     // Find out the connection method bearer type.
  2130     TUint32 bearerType( 0 );
  2300     TUint32 bearerType( 0 );
  2131     User::LeaveIfError( iInstanceMapping->GetConnMethodBearerType( aConnMethodId, bearerType ) );
  2301     User::LeaveIfError( iInstanceMapping->
       
  2302             GetConnMethodBearerType( aConnMethodId, bearerType ) );
  2132 
  2303 
  2133     // Check bearer type support and create plugin instance.
  2304     // Check bearer type support and create plugin instance.
  2134     CCmPluginBaseEng* plugin = NULL;
  2305     CCmPluginBaseEng* plugin = NULL;
  2135     for ( TInt i = 0; i < iPlugins->Count(); i++ )
  2306     for ( TInt i = 0; i < iPlugins->Count(); i++ )
  2136         {
  2307         {
  2137         if ( ( *iPlugins )[i]->GetBearerInfoIntL( CMManager::ECmBearerType ) == bearerType )
  2308         if ( ( *iPlugins )[i]->GetBearerInfoIntL(
       
  2309                 CMManager::ECmBearerType ) == bearerType )
  2138             {
  2310             {
  2139             TCmPluginInitParam pluginParams( Session() );
  2311             TCmPluginInitParam pluginParams( Session() );
  2140             plugin = ( *iPlugins )[i]->CreateInstanceL( pluginParams );
  2312             plugin = ( *iPlugins )[i]->CreateInstanceL( pluginParams );
  2141             CleanupStack::PushL( plugin );
  2313             CleanupStack::PushL( plugin );
  2142             plugin->LoadL( aConnMethodId );
  2314             plugin->LoadL( aConnMethodId );
  2179     // Check if connection method is already opened in cache.
  2351     // Check if connection method is already opened in cache.
  2180     TInt index = FindConnMethodFromCache( aCmId );
  2352     TInt index = FindConnMethodFromCache( aCmId );
  2181     if ( index != KErrNotFound )
  2353     if ( index != KErrNotFound )
  2182         {
  2354         {
  2183         // Already open in cache. Copy the connection method to session instance.
  2355         // Already open in cache. Copy the connection method to session instance.
  2184         cmInstance->CopyDataL( iConnMethodArray[index] ); // Will increase reference counter.
  2356         // Will increase reference counter.
       
  2357         cmInstance->CopyDataL( iConnMethodArray[index] );
  2185         }
  2358         }
  2186     else
  2359     else
  2187         {
  2360         {
  2188         OpenConnectionMethodInstanceL( *cmInstance, aCmId );
  2361         OpenConnectionMethodInstanceL( *cmInstance, aCmId );
  2189         }
  2362         }
  2213     // Check if connection method is already opened in cache.
  2386     // Check if connection method is already opened in cache.
  2214     TInt index = FindConnMethodFromCache( aCmId );
  2387     TInt index = FindConnMethodFromCache( aCmId );
  2215     if ( index != KErrNotFound )
  2388     if ( index != KErrNotFound )
  2216         {
  2389         {
  2217         // Already open in cache. Copy the connection method to session instance.
  2390         // Already open in cache. Copy the connection method to session instance.
  2218         cmInstance->CopyDataL( iConnMethodArray[index] ); // Will increase reference counter.
  2391         // Will increase reference counter.
       
  2392         cmInstance->CopyDataL( iConnMethodArray[index] );
  2219         }
  2393         }
  2220     else
  2394     else
  2221         {
  2395         {
  2222         OpenConnectionMethodInstanceL( *cmInstance, aCmId );
  2396         OpenConnectionMethodInstanceL( *cmInstance, aCmId );
  2223         }
  2397         }
  2247     // Check if connection method is already opened in cache.
  2421     // Check if connection method is already opened in cache.
  2248     TInt index = FindConnMethodFromCache( aCmId );
  2422     TInt index = FindConnMethodFromCache( aCmId );
  2249     if ( index != KErrNotFound )
  2423     if ( index != KErrNotFound )
  2250         {
  2424         {
  2251         // Already open in cache. Copy the connection method to session instance.
  2425         // Already open in cache. Copy the connection method to session instance.
  2252         cmInstance->CopyDataL( iConnMethodArray[index] ); // Will increase reference counter.
  2426         // Will increase reference counter.
       
  2427         cmInstance->CopyDataL( iConnMethodArray[index] );
  2253         }
  2428         }
  2254     else
  2429     else
  2255         {
  2430         {
  2256         OpenConnectionMethodInstanceL( *cmInstance, aCmId );
  2431         OpenConnectionMethodInstanceL( *cmInstance, aCmId );
  2257         }
  2432         }