cmmanager/cmmgr/cmmserver/src/cmmanagerimpl.cpp
changeset 20 9c97ad6591ae
child 27 489cf6208544
equal deleted inserted replaced
18:fcbbe021d614 20:9c97ad6591ae
       
     1 /*
       
     2 * Copyright (c) 2006-2010 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 * Implementation of CCmManagerImpl.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 #include <cmpluginbaseeng.h>
       
    21 #include <featmgr.h>
       
    22 #include <cmpluginembdestinationdef.h> // KUidEmbeddedDestination
       
    23 
       
    24 #include "cmmanagerimpl.h"
       
    25 #include "cmmtransactionhandler.h"
       
    26 #include "cmmcache.h"
       
    27 
       
    28 #include "OstTraceDefinitions.h"
       
    29 #ifdef OST_TRACE_COMPILER_IN_USE
       
    30 #include "cmmanagerimplTraces.h"
       
    31 #endif
       
    32 
       
    33 const TInt KPluginGranularity = 3;
       
    34 
       
    35 
       
    36 //-----------------------------------------------------------------------------
       
    37 //  CCmManagerImpl::NewL()
       
    38 //-----------------------------------------------------------------------------
       
    39 //
       
    40 CCmManagerImpl* CCmManagerImpl::NewL()
       
    41     {
       
    42     OstTraceFunctionEntry0( CCMMANAGERIMPL_NEWL_ENTRY );
       
    43 
       
    44     CCmManagerImpl* self = new( ELeave ) CCmManagerImpl();
       
    45     CleanupStack::PushL( self );
       
    46     self->ConstructL();
       
    47     CleanupStack::Pop( self );
       
    48 
       
    49     OstTraceFunctionExit0( CCMMANAGERIMPL_NEWL_EXIT );
       
    50     return self;
       
    51     }
       
    52 
       
    53 //-----------------------------------------------------------------------------
       
    54 //  CCmManagerImpl::CCmManagerImpl()
       
    55 //-----------------------------------------------------------------------------
       
    56 //
       
    57 CCmManagerImpl::~CCmManagerImpl()
       
    58     {
       
    59     OstTraceFunctionEntry0( DUP1_CCMMANAGERIMPL_CCMMANAGERIMPL_ENTRY );
       
    60 
       
    61     delete iCache;
       
    62 
       
    63     if ( iPlugins )
       
    64         {
       
    65         iPlugins->ResetAndDestroy();
       
    66         delete iPlugins;
       
    67         }
       
    68 
       
    69     delete iTrans;
       
    70 
       
    71     if ( iIsFeatureManagerInitialised )
       
    72         {
       
    73         FeatureManager::UnInitializeLib();
       
    74         }
       
    75 
       
    76     REComSession::FinalClose();
       
    77 
       
    78     OstTraceFunctionExit0( DUP1_CCMMANAGERIMPL_CCMMANAGERIMPL_EXIT );
       
    79     }
       
    80 
       
    81 //-----------------------------------------------------------------------------
       
    82 //  CCmManagerImpl::CCmManagerImpl()
       
    83 //-----------------------------------------------------------------------------
       
    84 //
       
    85 CCmManagerImpl::CCmManagerImpl()
       
    86     {
       
    87     OstTraceFunctionEntry0( CCMMANAGERIMPL_CCMMANAGERIMPL_ENTRY );
       
    88 
       
    89     iCache = NULL;
       
    90     iPlugins = NULL;
       
    91     iTrans = NULL;
       
    92     iSnapTableId = 0;
       
    93     iBearerPriorityTableId = 0;
       
    94     iDestMetadataTableId = 0;
       
    95     iDefConnTableId = 0;
       
    96     iIsFeatureManagerInitialised = EFalse;
       
    97     iWLanSupport = ETrue;
       
    98 
       
    99     OstTraceFunctionExit0( CCMMANAGERIMPL_CCMMANAGERIMPL_EXIT );
       
   100     }
       
   101 
       
   102 //-----------------------------------------------------------------------------
       
   103 //  CCmManagerImpl::ConstructL()
       
   104 //-----------------------------------------------------------------------------
       
   105 //
       
   106 void CCmManagerImpl::ConstructL()
       
   107     {
       
   108     OstTraceFunctionEntry0( CCMMANAGERIMPL_CONSTRUCTL_ENTRY );
       
   109 
       
   110     FeatureManager::InitializeLibL();
       
   111     iIsFeatureManagerInitialised = ETrue;
       
   112     iWLanSupport = FeatureManager::FeatureSupported( KFeatureIdProtocolWlan );
       
   113 
       
   114     CommsDat::CMDBSession* db = CommsDat::CMDBSession::NewLC( KCDVersion1_2 );
       
   115     iTrans = CCmmTransactionHandler::NewL( *db ); // Ownership of db transferred.
       
   116     CleanupStack::Pop( db );
       
   117 
       
   118     CheckTablesL();
       
   119     BuildPluginArrayL();
       
   120 
       
   121     iCache = CCmmCache::NewL( this, iPlugins );
       
   122 
       
   123     OstTraceFunctionExit0( CCMMANAGERIMPL_CONSTRUCTL_EXIT );
       
   124     }
       
   125 
       
   126 // -----------------------------------------------------------------------------
       
   127 // CCmManagerImpl::CheckTablesL()
       
   128 // -----------------------------------------------------------------------------
       
   129 //
       
   130 void CCmManagerImpl::CheckTablesL()
       
   131     {
       
   132     OstTraceFunctionEntry0( CCMMANAGERIMPL_CHECKTABLESL_ENTRY );
       
   133 
       
   134     TInt err( 0 );
       
   135 
       
   136     TRAP( err, iSnapTableId = CCDDataMobilitySelectionPolicyRecord::TableIdL( iTrans->Session() ));
       
   137     if ( err == KErrNotFound )
       
   138         {
       
   139         iSnapTableId = CCDDataMobilitySelectionPolicyRecord::CreateTableL( iTrans->Session() );
       
   140         }
       
   141     else
       
   142         {
       
   143         User::LeaveIfError( err );
       
   144         }
       
   145 
       
   146     TRAP( err, iBearerPriorityTableId =
       
   147             CCDGlobalBearerTypePriorizationRecord::TableIdL( iTrans->Session() ) );
       
   148     if ( err == KErrNotFound )
       
   149         {
       
   150         iBearerPriorityTableId =
       
   151                CCDGlobalBearerTypePriorizationRecord::CreateTableL( iTrans->Session() );
       
   152         }
       
   153     else
       
   154         {
       
   155         User::LeaveIfError( err );
       
   156         }
       
   157 
       
   158     TRAP( err, iDestMetadataTableId = CCDSNAPMetadataRecord::TableIdL( iTrans->Session() ) );
       
   159     if ( err == KErrNotFound )
       
   160         {
       
   161         iDestMetadataTableId = CCDSNAPMetadataRecord::CreateTableL( iTrans->Session() );
       
   162         }
       
   163     else
       
   164         {
       
   165         User::LeaveIfError( err );
       
   166         }
       
   167 
       
   168     TRAP( err, iDefConnTableId = CCDDefConnRecord::TableIdL( iTrans->Session() ) );
       
   169     if ( err == KErrNotFound )
       
   170         {
       
   171         iDefConnTableId = CCDDefConnRecord::CreateTableL( iTrans->Session() );
       
   172         }
       
   173     else
       
   174         {
       
   175         User::LeaveIfError( err );
       
   176         }
       
   177 
       
   178     OstTraceFunctionExit0( CCMMANAGERIMPL_CHECKTABLESL_EXIT );
       
   179     }
       
   180 
       
   181 //-----------------------------------------------------------------------------
       
   182 // Return an array containing the supported bearer types (embedded destination
       
   183 // excluded).
       
   184 //-----------------------------------------------------------------------------
       
   185 //
       
   186 void CCmManagerImpl::SupportedBearersL( RArray<TUint32>& aArray ) const
       
   187     {
       
   188     OstTraceFunctionEntry0( CCMMANAGERIMPL_SUPPORTEDBEARERSL_ENTRY );
       
   189 
       
   190     aArray.Reset();
       
   191     for ( TInt i = 0; i < iPlugins->Count(); i++ )
       
   192         {
       
   193         TUint32 bearerType( (*iPlugins)[i]->GetBearerInfoIntL( CMManager::ECmBearerType ) );
       
   194         if ( KUidEmbeddedDestination != bearerType )
       
   195             {
       
   196             aArray.AppendL( bearerType );
       
   197             }
       
   198         }
       
   199     OstTraceFunctionExit0( CCMMANAGERIMPL_SUPPORTEDBEARERSL_EXIT );
       
   200     }
       
   201 
       
   202 //-----------------------------------------------------------------------------
       
   203 // Return the requested table ID.
       
   204 //-----------------------------------------------------------------------------
       
   205 //
       
   206 CommsDat::TMDBElementId CCmManagerImpl::TableId( TCmmDbRecords aRecord )
       
   207     {
       
   208     CommsDat::TMDBElementId tableId( 0 );
       
   209     switch ( aRecord )
       
   210         {
       
   211         case ECmmDestNetworkRecord:
       
   212             tableId = CommsDat::KCDTIdNetworkRecord;
       
   213             break;
       
   214         case ECmmDestApRecord:
       
   215             tableId = CommsDat::KCDTIdAccessPointRecord;
       
   216             break;
       
   217         case ECmmDestMetadataRecord:
       
   218             tableId = iDestMetadataTableId;
       
   219             break;
       
   220         case ECmmDbSnapRecord:
       
   221             tableId = iSnapTableId;
       
   222             break;
       
   223         case ECmmDbBearerPriorityRecord:
       
   224             tableId = iBearerPriorityTableId;
       
   225             break;
       
   226         case ECmmDbDefConnRecord:
       
   227             tableId = iDefConnTableId;
       
   228             break;
       
   229         default:
       
   230             break;
       
   231         }
       
   232     return tableId;
       
   233     }
       
   234 
       
   235 // -----------------------------------------------------------------------------
       
   236 // Get a handle to the database cache manager.
       
   237 // -----------------------------------------------------------------------------
       
   238 //
       
   239 CCmmCache& CCmManagerImpl::Cache()
       
   240     {
       
   241     return *iCache;
       
   242     }
       
   243 
       
   244 //-----------------------------------------------------------------------------
       
   245 // Get a handle to the database transaction handler.
       
   246 //-----------------------------------------------------------------------------
       
   247 //
       
   248 CCmmTransactionHandler* CCmManagerImpl::GetTransactionHandler()
       
   249     {
       
   250     return iTrans;
       
   251     }
       
   252 
       
   253 //-----------------------------------------------------------------------------
       
   254 // Get a handle to database session.
       
   255 //-----------------------------------------------------------------------------
       
   256 //
       
   257 CommsDat::CMDBSession& CCmManagerImpl::Session() const
       
   258     {
       
   259     OstTraceFunctionEntry0( CCMMANAGERIMPL_SESSION_ENTRY );
       
   260     return iTrans->Session();
       
   261     }
       
   262 
       
   263 // ---------------------------------------------------------------------------
       
   264 // Return true is WLAN is supported on phone.
       
   265 // ---------------------------------------------------------------------------
       
   266 //
       
   267 TBool CCmManagerImpl::WlanSupported() const
       
   268     {
       
   269     OstTraceFunctionEntry0( CCMMANAGERIMPL_WLANSUPPORTED_ENTRY );
       
   270     OstTraceFunctionExit0( CCMMANAGERIMPL_WLANSUPPORTED_EXIT );
       
   271     return iWLanSupport;
       
   272     }
       
   273 
       
   274 // -----------------------------------------------------------------------------
       
   275 // CCmManagerImpl::BuildPluginArrayL()
       
   276 // -----------------------------------------------------------------------------
       
   277 //
       
   278 void CCmManagerImpl::BuildPluginArrayL()
       
   279     {
       
   280     OstTraceFunctionEntry0( CCMMANAGERIMPL_BUILDPLUGINARRAYL_ENTRY );
       
   281 
       
   282     iPlugins = new( ELeave ) CArrayPtrFlat<const CCmPluginBaseEng>( KPluginGranularity );
       
   283 
       
   284     // Get a list of all the bearer types.
       
   285     RPointerArray<CImplementationInformation> implArray;
       
   286     CmmCleanupResetAndDestroyPushL( implArray );
       
   287     REComSession::ListImplementationsL( TUid::Uid( KCMPluginInterfaceUid ), implArray );
       
   288 
       
   289     CCmPluginBaseEng* plugin = NULL;
       
   290     for ( TInt i = 0; i < implArray.Count(); i++ )
       
   291         {
       
   292         TCmPluginInitParam params( iTrans->Session() );
       
   293 
       
   294         // This is the Util implementation.
       
   295         // Trap it to be able to work even if there's a faulty plugin installed
       
   296         // in the phone.
       
   297         TRAPD( err, plugin = STATIC_CAST( CCmPluginBaseEng*, REComSession::CreateImplementationL(
       
   298                 ( implArray )[i]->ImplementationUid(),
       
   299                 _FOFF( CCmPluginBaseEng, iDtor_ID_Key ),
       
   300                 ( TAny* )&params ) ) );
       
   301 
       
   302         if ( !err )
       
   303             {
       
   304             CleanupStack::PushL( plugin );
       
   305 
       
   306             TBool inserted( EFalse );
       
   307             //TODO, Implement plugin sorting by priority later.
       
   308             /*
       
   309             TInt defaultPriority( KDataMobilitySelectionPolicyPriorityWildCard );
       
   310 
       
   311             // No UI priority -> wildcard
       
   312             TRAP_IGNORE( defaultPriority = plugin->GetIntAttributeL( ECmDefaultUiPriority ) );
       
   313 
       
   314             for ( TInt j( 0 ); j < iPlugins->Count(); ++j )
       
   315                 {
       
   316                 if ( defaultPriority > (*iPlugins)[j]->GetIntAttributeL( ECmDefaultUiPriority ) )
       
   317                     {
       
   318                     continue;
       
   319                     }
       
   320                 else if ( defaultPriority == (*iPlugins)[j]->GetIntAttributeL( ECmDefaultUiPriority ) )
       
   321                     {
       
   322                     if ( plugin->GetIntAttributeL( ECmExtensionLevel ) >
       
   323                         (*iPlugins)[j]->GetIntAttributeL( ECmExtensionLevel ) )
       
   324                         {
       
   325                         iPlugins->InsertL( j, plugin );
       
   326                         inserted = ETrue;
       
   327                         break;
       
   328                         }
       
   329                     }
       
   330                 else
       
   331                     {
       
   332                     iPlugins->InsertL( j, plugin );
       
   333                     inserted = ETrue;
       
   334                     break;
       
   335                     }
       
   336                 }*/
       
   337 
       
   338             if ( !inserted )
       
   339                 {
       
   340                 iPlugins->AppendL( plugin );
       
   341                 }
       
   342             CleanupStack::Pop( plugin );
       
   343             }
       
   344         }
       
   345 
       
   346     CleanupStack::PopAndDestroy( &implArray );
       
   347 
       
   348     OstTraceFunctionExit0( CCMMANAGERIMPL_BUILDPLUGINARRAYL_EXIT );
       
   349     }
       
   350 
       
   351 // Enf of file