simpleengine/siputils/src/simplesettings.cpp
changeset 0 c8caa15ef882
child 12 e6a66db4e9d0
equal deleted inserted replaced
-1:000000000000 0:c8caa15ef882
       
     1 /*
       
     2 * Copyright (c) 2006 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:    SIMPLE engine settings
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include <e32std.h>
       
    23 #include <e32base.h>
       
    24 #include <centralrepository.h>
       
    25 #include <pressettingsapi.h>
       
    26 #include "simpleenginedomaincrkeys.h"
       
    27 #include "simpleengineprivatecrkeys.h"
       
    28 
       
    29 #ifdef _DEBUG
       
    30 #include <bautils.h>
       
    31 #include "simpledebugutils.h"
       
    32 #endif
       
    33 
       
    34 #include "simplesettings.h"
       
    35 
       
    36 #ifdef _DEBUG
       
    37 _LIT ( KSimpleIniFile, "\\system\\data\\simple.ini");
       
    38 _LIT8 ( KSimpleExpiryPuhlish, "expiry_publish");
       
    39 _LIT8 ( KSimpleExpiryWatcher, "expiry_watcher");
       
    40 _LIT8 ( KSimpleExpiryWinfo, "expiry_winfo");
       
    41 _LIT8 ( KSimpleExpiryAPI, "expiry_api");
       
    42 _LIT8 ( KSimpleObjLimit, "obj_limit");
       
    43 _LIT8 ( KSimpleThrottle, "throttle");
       
    44 _LIT8 ( KSimpleMaxSubs, "max_subs");
       
    45 #endif
       
    46 
       
    47 /** default API expiry time */
       
    48 const TInt KMyDefaultAPIExpiry = 60;
       
    49 /** default SIP refresh expiry time */
       
    50 const TInt KMyDefaultSIPExpiry = 43200;
       
    51 /** default OTA settings value */
       
    52 const TInt KOTASettingsDefault = 0;
       
    53 
       
    54 // ================= MEMBER FUNCTIONS =======================
       
    55 
       
    56 
       
    57 
       
    58 
       
    59 //**********************************
       
    60 // TSimpleSettings
       
    61 //**********************************
       
    62 
       
    63 // ---------------------------------------------------------
       
    64 // TSimpleSettings::TSimpleSettings
       
    65 // ---------------------------------------------------------
       
    66 //
       
    67 TSimpleSettings::TSimpleSettings( )
       
    68     :
       
    69     iExpiryPuhlish( KMyDefaultSIPExpiry ),
       
    70     iExpiryWatcher( KMyDefaultSIPExpiry ),
       
    71     iExpiryWinfo( KMyDefaultSIPExpiry ),
       
    72     iExpiryApi( KMyDefaultAPIExpiry ),
       
    73     iObjLimit(KOTASettingsDefault),
       
    74     iThrottle(KOTASettingsDefault),
       
    75     iMaxSubscriptions(KOTASettingsDefault),
       
    76     iSipProfileId(KOTASettingsDefault)
       
    77     {}
       
    78 
       
    79 TUint TSimpleSettings::ExpiryPuhlish()
       
    80     {
       
    81     return iExpiryPuhlish;
       
    82     }
       
    83 
       
    84 TUint TSimpleSettings::ExpiryWatcher()
       
    85     {
       
    86     return iExpiryWatcher;
       
    87     }
       
    88 
       
    89 TUint TSimpleSettings::ExpiryWinfo()
       
    90     {
       
    91     return iExpiryWinfo;
       
    92     }
       
    93 
       
    94 TUint TSimpleSettings::ExpiryApi()
       
    95     {
       
    96     return iExpiryApi;
       
    97     }
       
    98 
       
    99 TInt TSimpleSettings::ObjLimit()
       
   100     {
       
   101     return iObjLimit;
       
   102     }
       
   103 
       
   104 TInt TSimpleSettings::Throttle()
       
   105     {
       
   106     return iThrottle;
       
   107     }
       
   108 
       
   109 TInt TSimpleSettings::MaxSubscriptions()
       
   110     {
       
   111     return iMaxSubscriptions;
       
   112     }
       
   113 
       
   114 TInt TSimpleSettings::SipProfileId()
       
   115     {
       
   116     return iSipProfileId;
       
   117     }
       
   118 
       
   119 // ---------------------------------------------------------
       
   120 // TSimpleSettings::ReadCentRepSettings
       
   121 // ---------------------------------------------------------
       
   122 //
       
   123 void TSimpleSettings::ReadCentRepSettings( )
       
   124     {
       
   125     // Read Central Repository settings
       
   126     CRepository* repository = NULL;
       
   127     TRAP_IGNORE( repository = CRepository::NewL( KCRUIDSimpleVariation ));
       
   128     if ( repository )
       
   129         {
       
   130         //TRAP_IGNORE( iExpiryPuhlish = GetCenRepIntValueL(
       
   131         //    repository, KSimplePublishRefresh ));
       
   132         TRAP_IGNORE( iExpiryWatcher = GetCenRepIntValueL(
       
   133             repository, KSimpleSubscribeRefresh ));
       
   134         TRAP_IGNORE( iExpiryWinfo = GetCenRepIntValueL(
       
   135             repository, KSimpleSubscribeWinfoRefresh ));
       
   136         TRAP_IGNORE( iExpiryApi = GetCenRepIntValueL(
       
   137             repository, KSimpleExpiryTime));
       
   138         delete repository;
       
   139         repository = NULL;
       
   140 #ifdef _DEBUG
       
   141 #ifdef __WINS__
       
   142         TSimpleLogger::Log(_L("CentRep iExpiryPuhlish=%d iExpiryWatcher=%d iExpiryWinfo=%d iExpiryAPI=%d"),
       
   143         iExpiryPuhlish, iExpiryWatcher, iExpiryWinfo, iExpiryApi);
       
   144 #endif
       
   145 #endif
       
   146         }
       
   147     }
       
   148 
       
   149 // ---------------------------------------------------------
       
   150 // TSimpleSettings::ReadOTASettings
       
   151 // ---------------------------------------------------------
       
   152 //
       
   153 void TSimpleSettings::ReadOTASettingsL( TInt aSetId )
       
   154     {
       
   155     // Read OTA settings using PresSettingsApi
       
   156 
       
   157     TPresSettingsSet set;
       
   158     TInt error( KErrNone );
       
   159     error = PresSettingsApi::SettingsSetL( aSetId, set );
       
   160     User::LeaveIfError( error );
       
   161 
       
   162     // convert -1 values (undefined) to default values
       
   163     iObjLimit = set.iObjectSize > KOTASettingsDefault ?
       
   164         set.iObjectSize : KOTASettingsDefault;
       
   165     iMaxSubscriptions = set.iMaxSubscriptions > KOTASettingsDefault ?
       
   166         set.iMaxSubscriptions : KOTASettingsDefault;
       
   167     iThrottle = set.iPublicationInt > KOTASettingsDefault ?
       
   168         set.iPublicationInt : KOTASettingsDefault;
       
   169     iSipProfileId = set.iSipProfile > KOTASettingsDefault ?
       
   170         set.iSipProfile : KOTASettingsDefault;
       
   171 
       
   172 #ifdef _DEBUG
       
   173 #ifdef __WINS__
       
   174         TSimpleLogger::Log(_L("OTAsettings iObjLimit=%d iThrottle=%d iMaxSubs=%d iSip=%d"),
       
   175         iObjLimit, iThrottle, iMaxSubscriptions, iSipProfileId );
       
   176 #endif
       
   177 #endif
       
   178 
       
   179     }
       
   180 
       
   181 // ---------------------------------------------------------
       
   182 // TSimpleSettings:GetCenRepIntValueL
       
   183 // ---------------------------------------------------------
       
   184 //
       
   185 TInt TSimpleSettings::GetCenRepIntValueL(
       
   186     CRepository* aRepository,
       
   187     TUint32 aId )
       
   188     {
       
   189     TInt value( 0 );
       
   190     User::LeaveIfError( aRepository->Get( aId, value ) );
       
   191     return value;
       
   192     }
       
   193 
       
   194 // ---------------------------------------------------------
       
   195 // TSimpleSettings::ReadIniFileL
       
   196 // ---------------------------------------------------------
       
   197 //
       
   198 #ifdef _DEBUG
       
   199 
       
   200 void TSimpleSettings::ReadIniFileL( RFs&  aFs )
       
   201     {
       
   202     // Set few values without reading them from ini file
       
   203     CSimpleSettingFile* configFile = CSimpleSettingFile::NewL( aFs );
       
   204     CleanupStack::PushL( configFile );  // *****
       
   205     // Search current drive
       
   206     TFileName path;
       
   207     Dll::FileName( path );
       
   208     TDriveName drive( TParsePtrC( path ).Drive( ) );
       
   209 
       
   210     // In emulator we try to find from c drive
       
   211     // in hardware we try to find from current drive and then from RAM.
       
   212 #ifdef __WINS__
       
   213     TFileName fileN( KSimpleIniFile);
       
   214 #else
       
   215     TFileName fileN( drive );
       
   216     fileN.Append( KSimpleIniFile );
       
   217 #endif
       
   218 
       
   219     TInt err = 0;
       
   220 
       
   221     // Open temporary config file
       
   222     TRAP( err, configFile->OpenL( fileN ));
       
   223     if ( err && drive.CompareF( _L("c:") ))
       
   224         {
       
   225         err = KErrNone;
       
   226         fileN = _L("c:");
       
   227         fileN.Append( KSimpleIniFile );
       
   228         TRAP( err, configFile->OpenL( fileN ));
       
   229         }
       
   230     if ( err )
       
   231         {
       
   232         err = KErrNone;
       
   233         TSimpleLogger::Log(_L("Config file not found ***"));
       
   234         User::Leave( KErrNotFound );
       
   235         }
       
   236     else
       
   237         {
       
   238         TSimpleLogger::Log(_L("Config file found ***"));
       
   239         }
       
   240 
       
   241     TUint32 myUint = 0;
       
   242     TPtrC8 myPtr;
       
   243     TBuf<8> myBuffer;
       
   244 
       
   245     // read expiry times
       
   246     TRAP( err, myPtr.Set( configFile->KeyValueL(KSimpleExpiryPuhlish)));
       
   247     if ( !err )
       
   248         {
       
   249         myBuffer.Copy( myPtr );
       
   250         TLex lex;
       
   251         lex.Assign( myBuffer );
       
   252         lex.Val(myUint, EDecimal);
       
   253         iExpiryPuhlish = (TInt) myUint;
       
   254         }
       
   255 
       
   256     TRAP( err, myPtr.Set( configFile->KeyValueL(KSimpleExpiryWatcher)));
       
   257     if ( !err )
       
   258         {
       
   259         myBuffer.Copy( myPtr );
       
   260         TLex lex;
       
   261         lex.Assign( myBuffer );
       
   262         lex.Val(myUint, EDecimal);
       
   263         iExpiryWatcher = (TInt) myUint;
       
   264         }
       
   265 
       
   266     TRAP( err, myPtr.Set( configFile->KeyValueL(KSimpleExpiryWinfo)));
       
   267     if ( !err )
       
   268         {
       
   269         myBuffer.Copy( myPtr );
       
   270         TLex lex;
       
   271         lex.Assign( myBuffer );
       
   272         lex.Val(myUint, EDecimal);
       
   273         iExpiryWinfo = (TInt) myUint;
       
   274         }
       
   275 
       
   276     TRAP( err, myPtr.Set( configFile->KeyValueL(KSimpleExpiryAPI)));
       
   277     if ( !err )
       
   278         {
       
   279         myBuffer.Copy( myPtr );
       
   280         TLex lex;
       
   281         lex.Assign( myBuffer );
       
   282         lex.Val(myUint, EDecimal);
       
   283         iExpiryApi = (TInt) myUint;
       
   284         }
       
   285 
       
   286     TRAP( err, myPtr.Set( configFile->KeyValueL(KSimpleObjLimit)));
       
   287     if ( !err )
       
   288         {
       
   289         myBuffer.Copy( myPtr );
       
   290         TLex lex;
       
   291         lex.Assign( myBuffer );
       
   292         lex.Val(myUint, EDecimal);
       
   293         iObjLimit = (TInt) myUint;
       
   294         }
       
   295 
       
   296     TRAP( err, myPtr.Set( configFile->KeyValueL(KSimpleThrottle)));
       
   297     if ( !err )
       
   298         {
       
   299         myBuffer.Copy( myPtr );
       
   300         TLex lex;
       
   301         lex.Assign( myBuffer );
       
   302         lex.Val(myUint, EDecimal);
       
   303         iThrottle = (TInt) myUint;
       
   304         }
       
   305 
       
   306     TRAP( err, myPtr.Set( configFile->KeyValueL(KSimpleMaxSubs)));
       
   307     if ( !err )
       
   308         {
       
   309         myBuffer.Copy( myPtr );
       
   310         TLex lex;
       
   311         lex.Assign( myBuffer );
       
   312         lex.Val(myUint, EDecimal);
       
   313         iMaxSubscriptions = (TInt) myUint;
       
   314         }
       
   315     CleanupStack::PopAndDestroy(configFile);
       
   316 
       
   317     // debug logging
       
   318     TSimpleLogger::Log(_L("ReadFile iExpiryPuhlish=%d iExpiryWatcher=%d iExpiryWinfo=%d iExpiryAPI=%d"),
       
   319     iExpiryPuhlish, iExpiryWatcher, iExpiryWinfo, iExpiryApi);
       
   320     TSimpleLogger::Log(_L("ReadFile iObjLimit=%d iThrottle=%d iMaxSubs=%d"),
       
   321     iObjLimit, iThrottle, iMaxSubscriptions );
       
   322     }
       
   323 
       
   324 #endif // _DEBUG
       
   325 
       
   326 
       
   327 //  End of File
       
   328