tsrc/centralrepositorystub/src/centralrepositorystub.cpp
changeset 22 496ad160a278
equal deleted inserted replaced
15:ccd8e69b5392 22:496ad160a278
       
     1 /*
       
     2 * Copyright (c) 2005 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 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "mussettingskeys.h"
       
    20 #include "centralrepository.h"
       
    21 #include "e32property.h"
       
    22 #include <badesca.h>
       
    23 
       
    24 /// CenRep UIDs and keys
       
    25 const TUid KCRUidSIPClientResolverConfig = { 0x10282EE7 };
       
    26 
       
    27 const TUid KCRUidInCallVolume = {0x102828B1};
       
    28 const TUint32 KTelIncallEarVolume                           = 0x00000001;
       
    29 const TUint32 KTelIncallLoudspeakerVolume                   = 0x00000002;
       
    30 
       
    31 
       
    32 // Values for static variables
       
    33 MusSettingsKeys::TOperatorVariant CRepository::iOperatorVariant =
       
    34             MusSettingsKeys::EStandard;
       
    35 TBool CRepository::iEmulateSawfishRepository = EFalse;
       
    36 HBufC8* CRepository::iStaticAvcConfigKeys = NULL;
       
    37 TBool CRepository::iStaticWriteAvcKeysToStaticData = EFalse;
       
    38 TInt CRepository::iForceFailWithCode = KErrNone;
       
    39 TInt CRepository::iStaticEncoderUid = 0;
       
    40 CRepository::TCenRepStubKeyValueEntry CRepository::iGlobalKeyVals[ KCenRepStubGlobalKeyValueMaxLen ];
       
    41 TInt CRepository::iGlobalKeyValsTop = 0;
       
    42 
       
    43 
       
    44 // -----------------------------------------------------------------------------
       
    45 //
       
    46 // -----------------------------------------------------------------------------
       
    47 //
       
    48 EXPORT_C CRepository* CRepository::NewL( TUid aRepositoryUid )
       
    49     {
       
    50     CRepository* self = CRepository::NewLC( aRepositoryUid );
       
    51     CleanupStack::Pop( self );
       
    52     return self;
       
    53     }
       
    54     
       
    55     
       
    56 // -----------------------------------------------------------------------------
       
    57 //
       
    58 // -----------------------------------------------------------------------------
       
    59 // 
       
    60 EXPORT_C CRepository* CRepository::NewLC( TUid aRepositoryUid )
       
    61     {
       
    62     CRepository* self = new (ELeave) CRepository( aRepositoryUid );
       
    63     CleanupStack::PushL( self );
       
    64 
       
    65     // This UID cannot be used in normal variant
       
    66     if ( aRepositoryUid == KCRUidSIPClientResolverConfig &&
       
    67          !iEmulateSawfishRepository )
       
    68         {
       
    69         User::Leave( KErrNotFound );
       
    70         }
       
    71     
       
    72     // Add a few keys
       
    73     if ( self->iRepositoryUid == KCRUidInCallVolume )
       
    74         {
       
    75         User::LeaveIfError( self->Set ( KTelIncallEarVolume, 4 ) );
       
    76         User::LeaveIfError( self->Set ( KTelIncallLoudspeakerVolume, 4 ) );
       
    77         }
       
    78     else if ( self->iRepositoryUid == MusSettingsKeys::KRepositoryUid )
       
    79         {
       
    80         // Set default values for numeric values which are not handled by static
       
    81         // variables
       
    82         User::LeaveIfError( 
       
    83                 self->Set ( MusSettingsKeys::KActivation,
       
    84                             MusSettingsKeys::EAlwaysActive ) );
       
    85         User::LeaveIfError( 
       
    86                 self->Set ( MusSettingsKeys::KAuditoryNotification,
       
    87                             MusSettingsKeys::EAuditoryNotificationOff ) );
       
    88         User::LeaveIfError( 
       
    89                 self->Set ( MusSettingsKeys::KPopupNotification,
       
    90                             MusSettingsKeys::EPopupNotificationOff ) );
       
    91         User::LeaveIfError( 
       
    92                 self->Set ( MusSettingsKeys::KPopupNotificationType,
       
    93                             MusSettingsKeys::ENotificationTypeQueryUser ) );
       
    94         User::LeaveIfError( 
       
    95                 self->Set ( MusSettingsKeys::KEdgeDtmSupport,
       
    96                             MusSettingsKeys::EDtmModeNotAllowed ) );
       
    97         User::LeaveIfError( 
       
    98                 self->Set ( MusSettingsKeys::KForceInternetSignaling,
       
    99                             MusSettingsKeys::EFollowProfileConfiguration ) );
       
   100         User::LeaveIfError( 
       
   101                 self->Set ( MusSettingsKeys::KAutoRecord,
       
   102                             MusSettingsKeys::EAutoRecordOn ) );       
       
   103         User::LeaveIfError( 
       
   104                 self->Set ( MusSettingsKeys::KSipProfileId,
       
   105                             0 /*default profile*/ ) );                    
       
   106     
       
   107         User::LeaveIfError( 
       
   108                 self->Set ( MusSettingsKeys::KUiOrientation,
       
   109                             MusSettingsKeys::EPortrait ) );                    
       
   110         User::LeaveIfError( 
       
   111                 self->Set ( MusSettingsKeys::KCapabilityQuery,
       
   112                             MusSettingsKeys::ENoOptions ) );
       
   113         
       
   114         // No variation keys defined                         
       
   115         }
       
   116     
       
   117     self->iDesC8Values = new (ELeave) CDesC8ArrayFlat( 1 );        
       
   118 
       
   119     return self;
       
   120     }
       
   121 
       
   122 
       
   123 // -----------------------------------------------------------------------------
       
   124 //
       
   125 // -----------------------------------------------------------------------------
       
   126 //
       
   127 EXPORT_C CRepository::~CRepository()
       
   128     {
       
   129     iKeys.Close();
       
   130     iValues.Close();
       
   131     iDesC8Keys.Close();
       
   132     delete iDesC8Values;   
       
   133     }
       
   134 
       
   135 
       
   136 // -----------------------------------------------------------------------------
       
   137 //
       
   138 // -----------------------------------------------------------------------------
       
   139 //
       
   140 EXPORT_C TInt CRepository::Create(TUint32 /*aKey*/, TInt /*aValue*/ )
       
   141     {
       
   142     return KErrNotSupported;
       
   143     }
       
   144 
       
   145 
       
   146 // -----------------------------------------------------------------------------
       
   147 //
       
   148 // -----------------------------------------------------------------------------
       
   149 //
       
   150 EXPORT_C TInt CRepository::Create(TUint32 /*aKey*/, const TDesC8& /*aValue*/)
       
   151     {
       
   152     return KErrNotSupported;
       
   153     }
       
   154 
       
   155 
       
   156 // -----------------------------------------------------------------------------
       
   157 //
       
   158 // -----------------------------------------------------------------------------
       
   159 //
       
   160 EXPORT_C TInt CRepository::Delete( TUint32 /*aPartialKey*/, 
       
   161                                    TUint32 /*aMask*/, 
       
   162                                    TUint32& /*aErrorKey*/ ) 
       
   163     {
       
   164     return KErrNotSupported;
       
   165     }
       
   166      
       
   167 
       
   168 // -----------------------------------------------------------------------------
       
   169 //
       
   170 // -----------------------------------------------------------------------------
       
   171 //
       
   172 EXPORT_C TInt CRepository::Get(TUint32 aKey, TInt& aValue)
       
   173     {
       
   174     // fail simulation
       
   175     if ( iForceFailWithCode != KErrNone )
       
   176         {
       
   177         TInt returnValue = iForceFailWithCode;
       
   178         iForceFailWithCode = KErrNone;
       
   179         return returnValue;
       
   180         }
       
   181     
       
   182     // Setting of encoding device
       
   183     if ( iRepositoryUid == MusSettingsKeys::KRepositoryUid &&
       
   184          aKey == MusSettingsKeys::KEncodingDevice )
       
   185         {
       
   186         aValue = CRepository::iStaticEncoderUid;
       
   187         return KErrNone;
       
   188         }
       
   189             
       
   190     if ( iRepositoryUid == MusSettingsKeys::KRepositoryUid &&
       
   191         aKey == MusSettingsKeys::KOperatorVariant )
       
   192         {
       
   193         aValue = CRepository::iOperatorVariant;
       
   194         return KErrNone;
       
   195         }
       
   196 
       
   197     TInt err = RProperty::Get( MusSettingsKeys::KRepositoryUid, aKey, aValue );
       
   198     if ( err != KErrNone )
       
   199         {
       
   200         for ( TInt i = 0; i < iKeys.Count(); ++i )
       
   201             {
       
   202             if ( iKeys[i] == aKey )
       
   203                 {
       
   204                 aValue = iValues[i];
       
   205                 return KErrNone;
       
   206                 }
       
   207             }
       
   208         }
       
   209     if ( iGlobalKeyValsTop >= 0 && iGlobalKeyValsTop < KCenRepStubGlobalKeyValueMaxLen )
       
   210         {
       
   211         for ( TInt i = 0; i < iGlobalKeyValsTop; i++ )
       
   212             {
       
   213             if ( iGlobalKeyVals[ i ].iKey == aKey )
       
   214                 {
       
   215                 aValue = CRepository::iGlobalKeyVals[ i ].iVal;
       
   216                 return KErrNone;
       
   217                 }
       
   218             }
       
   219         }
       
   220     return err;
       
   221     }
       
   222 
       
   223 // -----------------------------------------------------------------------------
       
   224 //
       
   225 // -----------------------------------------------------------------------------
       
   226 //
       
   227 EXPORT_C TInt CRepository::Get(TUint32 aKey, TDes8& aValue )
       
   228     {
       
   229     // fail simulation
       
   230     if ( iForceFailWithCode != KErrNone )
       
   231         {
       
   232         TInt returnValue = iForceFailWithCode;
       
   233         iForceFailWithCode = KErrNone;
       
   234         return returnValue;
       
   235         }
       
   236     
       
   237     if ( aKey == MusSettingsKeys::KEncoderConfigurationInfo &&
       
   238          iStaticAvcConfigKeys )
       
   239         {
       
   240         // Use static data instead of member data
       
   241         aValue.Copy( *iStaticAvcConfigKeys );
       
   242         return KErrNone;
       
   243         }
       
   244         
       
   245     for ( TInt i = 0; i < iDesC8Keys.Count(); ++i )
       
   246         {
       
   247         if ( iDesC8Keys[i] == aKey )
       
   248             {
       
   249             TPtrC8 value = iDesC8Values->MdcaPoint( i ); 
       
   250             aValue.Copy( value );
       
   251             return KErrNone;
       
   252             }
       
   253         }
       
   254         
       
   255     return KErrNotFound;
       
   256     }
       
   257     
       
   258 
       
   259 // -----------------------------------------------------------------------------
       
   260 //
       
   261 // -----------------------------------------------------------------------------
       
   262 //	
       
   263 EXPORT_C TInt CRepository::Set( TUint32 aKey, const TDesC8& aValue )
       
   264     {
       
   265     TBool error( EFalse );
       
   266     
       
   267     // fail simulation
       
   268     if ( iForceFailWithCode != KErrNone )
       
   269         {
       
   270         error = iForceFailWithCode;
       
   271         iForceFailWithCode = KErrNone;
       
   272         return error;
       
   273         }
       
   274         
       
   275     TBool keyFound( EFalse );
       
   276     
       
   277     // Replace possibly existing value
       
   278     for ( TInt i = 0; i < iDesC8Keys.Count(); ++i )
       
   279         {
       
   280         if ( iDesC8Keys[i] == aKey )
       
   281             {
       
   282             iDesC8Values->Delete( i );
       
   283             iDesC8Values->Compress();
       
   284             TRAP( error, iDesC8Values->InsertL( i, aValue ) );
       
   285             if ( error != KErrNone )
       
   286                 {
       
   287                 return error;
       
   288                 }
       
   289                 
       
   290             keyFound = ETrue;
       
   291             }
       
   292         }
       
   293     
       
   294     // If no existing value, add new one
       
   295     if ( !keyFound )
       
   296         {
       
   297         error = iDesC8Keys.Append( aKey );
       
   298         if ( error == KErrNone )
       
   299             {
       
   300             TRAP( error, iDesC8Values->AppendL( aValue ) )
       
   301             }
       
   302         }
       
   303     
       
   304     if ( iStaticWriteAvcKeysToStaticData &&
       
   305          aKey == MusSettingsKeys::KEncoderConfigurationInfo )
       
   306         {
       
   307         // Write also to static data
       
   308         TRAP( error, SetStubAvcConfigKeysL( aValue ) );
       
   309         }
       
   310         
       
   311     return error;
       
   312     }
       
   313 	
       
   314   
       
   315 // -----------------------------------------------------------------------------
       
   316 //
       
   317 // -----------------------------------------------------------------------------
       
   318 //
       
   319 EXPORT_C TInt CRepository::Get(TUint32 aKey, TDes& aValue)
       
   320     {
       
   321     // fail simulation
       
   322     if ( iForceFailWithCode != KErrNone )
       
   323         {
       
   324         TInt returnValue = iForceFailWithCode;
       
   325         iForceFailWithCode = KErrNone;
       
   326         return returnValue;
       
   327         }
       
   328 
       
   329     _LIT( KSampleValue, "\\data\\videos\\");
       
   330     TInt err = RProperty::Get( MusSettingsKeys::KRepositoryUid, aKey, aValue );
       
   331     if ( err != KErrNone )
       
   332         {
       
   333         aValue.Append( KSampleValue() );
       
   334         }
       
   335     return KErrNone;
       
   336     }
       
   337 
       
   338 
       
   339 // -----------------------------------------------------------------------------
       
   340 //
       
   341 // -----------------------------------------------------------------------------
       
   342 //
       
   343 EXPORT_C TInt CRepository::Set(TUint32 /*aKey*/, const TDesC& /*aValue*/)
       
   344     {
       
   345     return KErrNotSupported;
       
   346     }
       
   347 
       
   348 
       
   349 // -----------------------------------------------------------------------------
       
   350 //
       
   351 // -----------------------------------------------------------------------------
       
   352 //
       
   353 EXPORT_C TInt CRepository::Set(TUint32 aKey, TInt aValue)
       
   354     {
       
   355     // fail simulation
       
   356     if ( iForceFailWithCode != KErrNone )
       
   357         {
       
   358         TInt returnValue = iForceFailWithCode;
       
   359         iForceFailWithCode = KErrNone;
       
   360         return returnValue;
       
   361         }
       
   362     
       
   363     // Setting of encoding device
       
   364     if ( iRepositoryUid == MusSettingsKeys::KRepositoryUid &&
       
   365          aKey == MusSettingsKeys::KEncodingDevice )
       
   366         {
       
   367         CRepository::iStaticEncoderUid = aValue;
       
   368         return KErrNone;
       
   369         }
       
   370     
       
   371     // Setting of operator variant value
       
   372     if ( iRepositoryUid == MusSettingsKeys::KRepositoryUid &&
       
   373          aKey == MusSettingsKeys::KOperatorVariant )
       
   374         {
       
   375         CRepository::iOperatorVariant =
       
   376                 ( MusSettingsKeys::TOperatorVariant ) aValue;
       
   377         return KErrNone;
       
   378         }
       
   379 
       
   380     RProperty::Set( MusSettingsKeys::KRepositoryUid, aKey, aValue );
       
   381 
       
   382     // Setting of any other value
       
   383     for ( TInt i = 0; i < iKeys.Count(); ++i )
       
   384         {
       
   385         if ( iKeys[i] == aKey )
       
   386             {
       
   387             iValues[i] = aValue;
       
   388             return KErrNone;
       
   389             }
       
   390         }
       
   391     
       
   392     // No wise error handling implemented
       
   393     TInt error = iKeys.Append( aKey );
       
   394     if ( error == KErrNone )
       
   395         {
       
   396         error = iValues.Append( aValue );
       
   397         }
       
   398         
       
   399     return error;
       
   400     }
       
   401 
       
   402 
       
   403 // -----------------------------------------------------------------------------
       
   404 //
       
   405 // -----------------------------------------------------------------------------
       
   406 //
       
   407 EXPORT_C TInt CRepository::FindL( TUint32 /*aPartialKey*/, 
       
   408                                   TUint32 /*aMask*/,
       
   409 		                          RArray<TUint32>& /*aFoundKeys*/ )
       
   410     {
       
   411     User::Leave( KErrNotSupported ); 
       
   412     return KErrNotSupported;
       
   413     }
       
   414     
       
   415 
       
   416 // -----------------------------------------------------------------------------
       
   417 //
       
   418 // -----------------------------------------------------------------------------
       
   419 //
       
   420 EXPORT_C TInt CRepository::FindEqL( TUint32 /*aPartialKey*/, 
       
   421                                     TUint32 /*aMask*/,
       
   422 		                            const TDesC8& /*aValue*/, 
       
   423 		                            RArray<TUint32>& /*aFoundKeys*/ )
       
   424     {
       
   425     User::Leave( KErrNotSupported ); 
       
   426     return KErrNotSupported;
       
   427     }
       
   428     
       
   429 
       
   430 // -----------------------------------------------------------------------------
       
   431 //
       
   432 // -----------------------------------------------------------------------------
       
   433 //
       
   434 EXPORT_C TInt CRepository::StartTransaction( TTransactionMode /*aMode*/ )
       
   435     {
       
   436     return KErrNotSupported;
       
   437     }
       
   438     
       
   439     
       
   440 /// -----------------------------------------------------------------------------
       
   441 //
       
   442 // -----------------------------------------------------------------------------
       
   443 //
       
   444 EXPORT_C TInt CRepository::CommitTransaction(TUint32& /*aKeyInfo*/)
       
   445     {
       
   446     return KErrNotSupported;
       
   447     }
       
   448        
       
   449 
       
   450 
       
   451 // ------- Functions that are not present in real CRepository but are ----------
       
   452 // ------- defined here exclusively for stubbing purposes             ----------  
       
   453     
       
   454 // -----------------------------------------------------------------------------
       
   455 //
       
   456 // -----------------------------------------------------------------------------
       
   457 //
       
   458 void CRepository::ResetKeysAndValues()
       
   459     {
       
   460     iKeys.Reset();
       
   461     iValues.Reset();
       
   462 
       
   463     iDesC8Keys.Reset();
       
   464     iDesC8Values->Reset();
       
   465     
       
   466     iEmulateSawfishRepository = EFalse;
       
   467 
       
   468     delete iStaticAvcConfigKeys;
       
   469     iStaticAvcConfigKeys = NULL;    
       
   470     }
       
   471 
       
   472 
       
   473 // -----------------------------------------------------------------------------
       
   474 //
       
   475 // -----------------------------------------------------------------------------
       
   476 //
       
   477 void CRepository::SetStubAvcConfigKeysL( const TDesC8& aConfigKeys )
       
   478     {
       
   479     HBufC8* newConfigKeys = aConfigKeys.AllocL();
       
   480     CRepository::DeleteStubAvcConfigKeys();
       
   481     iStaticAvcConfigKeys = newConfigKeys; 
       
   482     }
       
   483 
       
   484 // -----------------------------------------------------------------------------
       
   485 //
       
   486 // -----------------------------------------------------------------------------
       
   487 //
       
   488 
       
   489 void CRepository::DeleteStubAvcConfigKeys()
       
   490     {
       
   491     delete iStaticAvcConfigKeys;
       
   492     iStaticAvcConfigKeys = NULL;
       
   493     }
       
   494 
       
   495 void CRepository::ResetStubGlobal()
       
   496     {
       
   497     iGlobalKeyValsTop = 0;
       
   498     }
       
   499 
       
   500 TInt CRepository::SetStubGlobal(TUint32 aKey, TInt aValue)
       
   501     {
       
   502     for ( TInt i = 0; i < iGlobalKeyValsTop; i++ )
       
   503         {
       
   504         if ( iGlobalKeyVals[ i ].iKey == aKey )
       
   505             {
       
   506             iGlobalKeyVals[ i ].iVal = aValue;
       
   507             return KErrNone;
       
   508             }
       
   509         }
       
   510     
       
   511     if ( iGlobalKeyValsTop >= KCenRepStubGlobalKeyValueMaxLen )
       
   512         {
       
   513         return KErrNoMemory;
       
   514         }
       
   515     iGlobalKeyVals[ iGlobalKeyValsTop ].iKey = aKey;
       
   516     iGlobalKeyVals[ iGlobalKeyValsTop ].iVal = aValue;
       
   517     iGlobalKeyValsTop++;
       
   518     return KErrNone;
       
   519     }
       
   520 // -----------------------------------------------------------------------------
       
   521 //
       
   522 // -----------------------------------------------------------------------------
       
   523 //
       
   524 CRepository::CRepository( TUid aRepositoryUid )
       
   525     :iRepositoryUid( aRepositoryUid )
       
   526     {
       
   527     
       
   528     }    
       
   529 
       
   530