richcallsettingsengine/rcse2/src/rcseregistrybase.cpp
branchRCL_3
changeset 22 d38647835c2e
equal deleted inserted replaced
21:f742655b05bf 22:d38647835c2e
       
     1 /*
       
     2 * Copyright (c) 2004-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:  Base for RCSE registry classes
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 //#include <cenrepdatabaseutil.h>
       
    20 //#include <cenrepdatabaseproperty.h>
       
    21 
       
    22 
       
    23 #include "rcseregistrybase.h"
       
    24 #include "rcsebackupobserver.h"
       
    25 #include "rcsedefaultdbnames.h"
       
    26 #include "rcseconstants.h"
       
    27 #include "rcsepanic.h"
       
    28 #include "rcseprivatecrkeys.h"
       
    29 #include "rcselogger.h"
       
    30 #include "rcsedbimporter.h"
       
    31 
       
    32 
       
    33 // ======== MEMBER FUNCTIONS ========
       
    34 
       
    35 // ---------------------------------------------------------------------------
       
    36 // Constructor
       
    37 // ---------------------------------------------------------------------------
       
    38 //
       
    39 CRCSERegistryBase::CRCSERegistryBase( TRCSERegistryType aType )
       
    40     : iType( aType )
       
    41     {
       
    42     }
       
    43 
       
    44 // ---------------------------------------------------------------------------
       
    45 // BaseConstructL
       
    46 // ---------------------------------------------------------------------------
       
    47 //
       
    48 void CRCSERegistryBase::BaseConstructL()
       
    49     {
       
    50     RCSELOGSTRING2( "CRCSERegistryBase::BaseConstructL(type=%d) - IN", iType );
       
    51     RCSELOGTHREAD();
       
    52 
       
    53     // Set proper table and mask
       
    54     switch ( iType )
       
    55         {
       
    56         case EVoIPProfile:
       
    57             {
       
    58             iCenRepDb = CCenRepDatabaseUtil::NewL( KCRUidRCSE,
       
    59                                                    KRCSEProfileTable,
       
    60                                                    KRCSEColIncrement,
       
    61                                                    KRCSEColumnMask,
       
    62                                                    KRCSEIdCounter,
       
    63                                                    KRCSEColumnCountVoIP );
       
    64             break;
       
    65             }
       
    66         case EAudioCodecSetting:
       
    67             {
       
    68             iCenRepDb = CCenRepDatabaseUtil::NewL( KCRUidRCSECodec,
       
    69                                                    KRCSECodecTable,
       
    70                                                    KRCSEColIncrement,
       
    71                                                    KRCSEColumnMask,
       
    72                                                    KRCSEIdCounter,
       
    73                                                    KRCSEColumnCountCodec );
       
    74 
       
    75             break;
       
    76             }
       
    77         default:
       
    78             {
       
    79             User::Leave( KErrNotSupported );
       
    80             }
       
    81         };
       
    82 
       
    83     iBackupObserver = CRCSEBackupObserver::NewL( *this );
       
    84 
       
    85     TInt err( 0 );
       
    86 
       
    87     // Check if Backup operation is running.
       
    88     if ( iBackupObserver->IsBackupOperationRunning() )
       
    89         {
       
    90         RCSELOGSTRING( "Backup active!" );
       
    91         iBackupActive = ETrue;
       
    92         }
       
    93 
       
    94     if ( !iBackupActive &&
       
    95          CRCSEDbImporter::ImportExists() &&
       
    96          !CRCSEDbImporter::IsImportRunning() )
       
    97         {
       
    98         TRAP( err, ImportSettingsL() );
       
    99         }
       
   100 
       
   101     RCSELOGSTRING( "CRCSERegistryBase::BaseConstructL() - OUT" );
       
   102     }
       
   103 
       
   104 // ---------------------------------------------------------------------------
       
   105 // Destructor
       
   106 // ---------------------------------------------------------------------------
       
   107 //
       
   108 CRCSERegistryBase::~CRCSERegistryBase()
       
   109     {
       
   110     RCSELOGSTRING2( 
       
   111         "CRCSERegistryBase::~CRCSERegistryBase(type=%d) - IN", iType );
       
   112     RCSELOGTHREAD();
       
   113 
       
   114     if ( iBackupObserver )
       
   115         {
       
   116         iBackupObserver->Cancel();
       
   117         delete iBackupObserver;
       
   118         iBackupObserver = NULL;
       
   119         }
       
   120 
       
   121 
       
   122     delete iCenRepDb;
       
   123 
       
   124     RCSELOGSTRING( "CRCSERegistryBase::~CRCSERegistryBase() - OUT" );
       
   125     }
       
   126 
       
   127 // ---------------------------------------------------------------------------
       
   128 // From class MRCSEBackupObserver.
       
   129 // Handle backup events.
       
   130 // ---------------------------------------------------------------------------
       
   131 //
       
   132 void CRCSERegistryBase::HandleBackupOperationEventL()
       
   133 	{
       
   134 	RCSELOGSTRING( "CRCSERegistryBase::HandleBackupOperationEventL() - IN" );
       
   135     RCSELOGTHREAD();
       
   136 
       
   137 	if ( iBackupObserver->IsBackupOperationRunning() )
       
   138         {
       
   139         RCSELOGSTRING( "Backup active!" );
       
   140         iBackupActive = ETrue;
       
   141         }
       
   142     else
       
   143         {
       
   144         RCSELOGSTRING( "Backup not active!" );
       
   145         iBackupActive = EFalse;
       
   146 		}
       
   147 
       
   148     RCSELOGSTRING( "CRCSERegistryBase::HandleBackupOperationEventL() - OUT" );
       
   149 	}
       
   150 
       
   151 // -----------------------------------------------------------------------------
       
   152 // CRCSERegistryBase::BeginL
       
   153 // Prepares read/write operation.
       
   154 // -----------------------------------------------------------------------------
       
   155 //
       
   156 void CRCSERegistryBase::BeginL()
       
   157     {
       
   158     RCSELOGSTRING( "CRCSERegistryBase::BeginL() - IN" );
       
   159     RCSELOGTHREAD();
       
   160 
       
   161     if ( iBackupActive )
       
   162         {
       
   163         User::Leave( KErrNotReady );
       
   164         }
       
   165 
       
   166     else 
       
   167         {
       
   168         RCSELOGSTRING( "Begin transaction" );
       
   169 
       
   170         // Begin transaction. Method leaves 2 items in cleanup stack
       
   171         // and they will be removed in CommitTransaction
       
   172         iCenRepDb->BeginTransactionL(); 
       
   173         }
       
   174 
       
   175     RCSELOGSTRING( "CRCSERegistryBase::BeginL() - OUT" );
       
   176     }
       
   177 
       
   178 // -----------------------------------------------------------------------------
       
   179 // CRCSERegistryBase::EndL
       
   180 // Finalize performed operation
       
   181 // -----------------------------------------------------------------------------
       
   182 //
       
   183 void CRCSERegistryBase::EndL()
       
   184     {
       
   185     RCSELOGSTRING( "CRCSERegistryBase::EndL() - IN" );
       
   186     RCSELOGTHREAD();
       
   187 
       
   188     User::LeaveIfError( iCenRepDb->CommitTransaction() );
       
   189 
       
   190     RCSELOGSTRING( "CRCSERegistryBase::EndL() - OUT" );
       
   191     }
       
   192 
       
   193 // -----------------------------------------------------------------------------
       
   194 // CRCSERegistryBase::ToDes
       
   195 // Converts TInt32 to descriptor.
       
   196 // -----------------------------------------------------------------------------
       
   197 //
       
   198 TDesC& CRCSERegistryBase::ToDes( TInt32 aFrom, TDes& aTo )
       
   199     {
       
   200     aTo.Zero();
       
   201     aTo.AppendNum( aFrom );
       
   202     return aTo;
       
   203     }
       
   204 
       
   205 // -----------------------------------------------------------------------------
       
   206 // CRCSERegistryBase::ToDes
       
   207 // Converts TUint32 to descriptor.
       
   208 // -----------------------------------------------------------------------------
       
   209 //
       
   210 TDesC& CRCSERegistryBase::ToDes( TUint32 aFrom, TDes& aTo )
       
   211     {
       
   212     aTo.Zero();
       
   213     aTo.AppendNum( aFrom );
       
   214     return aTo;
       
   215     }
       
   216 
       
   217 // -----------------------------------------------------------------------------
       
   218 // CRCSERegistryBase::ToDes
       
   219 // Converts descriptor to TInt32.
       
   220 // -----------------------------------------------------------------------------
       
   221 //
       
   222 TInt32 CRCSERegistryBase::ToTInt32L( const TDesC& aFrom )
       
   223     {
       
   224     TInt32 value;
       
   225     TLex16 convert( aFrom );
       
   226     User::LeaveIfError( convert.Val( value ) );
       
   227     return value;
       
   228     }
       
   229 
       
   230 // -----------------------------------------------------------------------------
       
   231 // CRCSERegistryBase::ToDes
       
   232 // Converts descriptor to TUint32.
       
   233 // -----------------------------------------------------------------------------
       
   234 //
       
   235 TUint32 CRCSERegistryBase::ToTUint32L( const TDesC& aFrom)
       
   236     {
       
   237     TUint32 value;
       
   238     TLex16 convert( aFrom );
       
   239     User::LeaveIfError( convert.Val( value, EDecimal ) );
       
   240     return value;
       
   241     }
       
   242 
       
   243 // -----------------------------------------------------------------------------
       
   244 // CRCSERegistryBase::ImportSettingsL
       
   245 // Import settings from db files and store to cenrep.
       
   246 // -----------------------------------------------------------------------------
       
   247 //
       
   248 void CRCSERegistryBase::ImportSettingsL()
       
   249     {
       
   250     RCSELOGSTRING( "CRCSERegistryBase::ImportSettingsL() - IN" );
       
   251     RCSELOGTHREAD();
       
   252 
       
   253     CRCSEDbImporter* importer = CRCSEDbImporter::NewLC();
       
   254     importer->ImportAndStoreL();
       
   255     CleanupStack::PopAndDestroy( importer );
       
   256 
       
   257     RCSELOGSTRING( "CRCSERegistryBase::ImportSettingsL() - OUT" );
       
   258     }
       
   259 
       
   260 // -----------------------------------------------------------------------------
       
   261 // CRCSERegistryBase::CreatePropertyL
       
   262 // Create a new property and appends it to given property array
       
   263 // -----------------------------------------------------------------------------
       
   264 //
       
   265 void CRCSERegistryBase::CreatePropertyL( 
       
   266     TUint aPropertyName, 
       
   267     const TDesC& aPropertyValue, 
       
   268     RIpAppPropArray& aPropertyArray )
       
   269     {
       
   270     CCenRepDatabaseProperty* property = CCenRepDatabaseProperty::NewLC();
       
   271     property->SetName( aPropertyName );
       
   272     User::LeaveIfError( property->SetValue( aPropertyValue ) );
       
   273     aPropertyArray.AppendL( property );
       
   274     CleanupStack::Pop( property );
       
   275     }
       
   276 
       
   277 // -----------------------------------------------------------------------------
       
   278 // CRCSERegistryBase::GetPropertyValueL
       
   279 // Gets value of requested property from array
       
   280 // -----------------------------------------------------------------------------
       
   281 //
       
   282 void CRCSERegistryBase::GetPropertyValueL( 
       
   283     TUint aPropertyName, 
       
   284     TDes& aPropertyValue, 
       
   285     RIpAppPropArray& aPropertyArray )
       
   286     {
       
   287     aPropertyValue.Zero();
       
   288 
       
   289     const TInt count( aPropertyArray.Count() );
       
   290     for ( TInt i( 0 ); i < count; i++ )
       
   291         {
       
   292         if ( aPropertyArray[i]->GetName() == aPropertyName )
       
   293             {
       
   294             aPropertyValue = aPropertyArray[i]->GetDesValue();
       
   295             //delete aPropertyArray[i];
       
   296             //aPropertyArray.Remove( i );
       
   297             i = count; // Stop the loop
       
   298             }
       
   299         }
       
   300     }
       
   301 
       
   302 // -----------------------------------------------------------------------------
       
   303 // CRCSERegistryBase::FindIdsByValueL
       
   304 // Search entries that have this property and requested value.
       
   305 // -----------------------------------------------------------------------------
       
   306 //
       
   307 void CRCSERegistryBase::FindIdsByValueL( 
       
   308     TUint aPropertyName, 
       
   309     const TDesC& aPropertyValue, 
       
   310     RArray<TUint32>& aIdArray )
       
   311     {    
       
   312     RArray<TInt> allEntries;
       
   313     CleanupClosePushL( allEntries );
       
   314 
       
   315     iCenRepDb->FindEntryIdsL( allEntries );
       
   316     
       
   317     CCenRepDatabaseProperty* property = CCenRepDatabaseProperty::NewLC();
       
   318     
       
   319     const TInt allCount( allEntries.Count() );
       
   320     
       
   321     for ( TInt i( 0 ); i < allCount; i++ )
       
   322         {        
       
   323         TInt err = iCenRepDb->FindPropertyL( allEntries[i], aPropertyName,
       
   324                 *property );
       
   325         
       
   326         if ( KErrNoMemory == err )
       
   327             {
       
   328             User::Leave( err );
       
   329             }
       
   330         
       
   331         if ( KErrNone == err )
       
   332             {            
       
   333             // If properties match, add id to the id array.
       
   334             if ( !property->GetDesValue().Compare( aPropertyValue ) )
       
   335                 {                
       
   336                 aIdArray.AppendL( allEntries[i] );
       
   337                 }
       
   338             }
       
   339         }
       
   340     
       
   341     CleanupStack::PopAndDestroy( property );
       
   342     CleanupStack::PopAndDestroy( &allEntries );
       
   343     }
       
   344 
       
   345 // -----------------------------------------------------------------------------
       
   346 // CRCSERegistryBase::FindAllIdsL
       
   347 // Search all ids of entries from cenrep db.
       
   348 // -----------------------------------------------------------------------------
       
   349 //
       
   350 void CRCSERegistryBase::FindAllIdsL( RArray<TUint32>& aIdArray )
       
   351     {
       
   352     CleanupClosePushL( aIdArray );
       
   353     aIdArray.Reset();
       
   354 
       
   355     RArray<TInt> ids;
       
   356     CleanupClosePushL( ids );
       
   357 
       
   358     iCenRepDb->FindEntryIdsL( ids );
       
   359 
       
   360     // TInt to TUint
       
   361     const TInt count( ids.Count() );
       
   362     for ( TInt i( 0 ); i < count; i++ )
       
   363         {
       
   364         aIdArray.AppendL( ids[ i ] );
       
   365         }
       
   366 
       
   367     CleanupStack::PopAndDestroy( &ids );
       
   368     CleanupStack::Pop( &aIdArray );
       
   369     }
       
   370 
       
   371 // -----------------------------------------------------------------------------
       
   372 // CRCSERegistryBase::CleanupDbPropArray
       
   373 // Custom cleanup for cenrep db property array.
       
   374 // -----------------------------------------------------------------------------
       
   375 //
       
   376 void CRCSERegistryBase::CleanupDbPropArray( TAny* aPointer )
       
   377 	{
       
   378 	RIpAppPropArray* array = static_cast<RIpAppPropArray*>( aPointer );
       
   379 	array->ResetAndDestroy();
       
   380 	}
       
   381 
       
   382