datasourcemodules/defaultpositioningmodule/src/epos_cposconstmanager.cpp
changeset 36 b47902b73a93
child 49 5f20f71a57a3
equal deleted inserted replaced
35:a2efdd544abf 36:b47902b73a93
       
     1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include <centralrepository.h>
       
    20 
       
    21 #include "epos_cposconstmanager.h"
       
    22 #include "epos_cpossingletonmanager.h"
       
    23 #include "epos_defaultproxyprivatecrkeys.h"
       
    24 #include "epos_defaultproxycommon.h"
       
    25 
       
    26 
       
    27 //Define the const for calculating the timeshift value
       
    28 const TInt KPosTimeshiftValueMultiplier = 2;
       
    29 
       
    30 //Maximum length of last working GPS PSY UID in CenRep
       
    31 const TInt KPosMaximumLastWorkingGpsPsyUidStringLength = 24;
       
    32 
       
    33 //The width of each PSY uid in the PSY list
       
    34 const TInt KPosPsyUidWidth = 8;
       
    35 
       
    36 
       
    37 // ================= MEMBER FUNCTIONS =======================
       
    38 
       
    39 // C++ default constructor can NOT contain any code, that
       
    40 // might leave.
       
    41 //
       
    42 CPosConstManager::CPosConstManager()
       
    43     {
       
    44     iLastWorkingGpsPsyId = KPositionNullModuleId;
       
    45     }
       
    46 
       
    47 // EPOC default constructor can leave.
       
    48 void CPosConstManager::ConstructL()
       
    49     {
       
    50     //Central repository
       
    51     iRepository = CRepository::NewL( KCRUidDefaultProxyConfiguration );
       
    52     
       
    53     //Get constant value
       
    54     User::LeaveIfError( iRepository->Get(
       
    55         KDefaultProxyTimeshiftInActiveOrReady, 
       
    56         iMaxTimeshiftInActiveOrReady ) );
       
    57         
       
    58     User::LeaveIfError( iRepository->Get(
       
    59         KDefaultProxyTimeshiftNotInActiveOrReady,
       
    60         iMaxTimeshiftNotInActiveOrReady ) );
       
    61         
       
    62     User::LeaveIfError( iRepository->Get(
       
    63         KDefaultProxyPsyStateUnknownTimeout, 
       
    64         iPsyStateUnknownTimeout ) );
       
    65         
       
    66     User::LeaveIfError( iRepository->Get(
       
    67         KDefaultProxyExternalGPSCheckingTimeout, 
       
    68         iExternalGpsCheckingTimeout ) );
       
    69         
       
    70     User::LeaveIfError( iRepository->Get(
       
    71         KDefaultProxyCleanupTimeout, 
       
    72         iCleanupTimeout ) );
       
    73     
       
    74     }
       
    75 
       
    76 // ---------------------------------------------------------
       
    77 // CPosConstManager::GetIntanceL
       
    78 // ---------------------------------------------------------
       
    79 //
       
    80 CPosConstManager* CPosConstManager::GetInstanceL()
       
    81     {
       
    82     CPosConstManager* self = reinterpret_cast < CPosConstManager* > 
       
    83         ( CPosSingletonManager::GetObject( 
       
    84             EPosSigletonObjectConstManagerId ) );
       
    85         
       
    86     if ( !self )
       
    87         {
       
    88         //Construct a new object and store it to CPosSingletonManager
       
    89         self = new ( ELeave ) CPosConstManager;
       
    90         CleanupStack::PushL(self);
       
    91         self->ConstructL();
       
    92         CPosSingletonManager::SetObjectL(
       
    93             self,
       
    94             EPosSigletonObjectConstManagerId );
       
    95         CleanupStack::Pop(self);
       
    96         }
       
    97         
       
    98     self->iRefCount++;
       
    99     
       
   100     return self;
       
   101     }
       
   102 
       
   103 // Destructor
       
   104 CPosConstManager::~CPosConstManager()
       
   105     {
       
   106     delete iRepository;
       
   107     }
       
   108 
       
   109 // ---------------------------------------------------------
       
   110 // CPosConstManager::ReleaseInstance
       
   111 // ---------------------------------------------------------
       
   112 //
       
   113 void CPosConstManager::ReleaseInstance()
       
   114     {
       
   115     iRefCount--;
       
   116     if ( iRefCount == 0 )
       
   117         {
       
   118         //We shall delete the instance
       
   119         CPosSingletonManager::ReleaseObject(
       
   120             EPosSigletonObjectConstManagerId );
       
   121         }
       
   122     }
       
   123 
       
   124 // ---------------------------------------------------------
       
   125 // CPosConstManager::GetTimeshiftValue
       
   126 // ---------------------------------------------------------
       
   127 //
       
   128 TTimeIntervalMicroSeconds CPosConstManager::GetTimeshiftValue( 
       
   129             TTimeIntervalMicroSeconds aTtff, 
       
   130             TTimeIntervalMicroSeconds aTtnf, 
       
   131             TPositionModuleStatus::TDeviceStatus aDeviceStatus )
       
   132     {
       
   133     switch ( aDeviceStatus )
       
   134         {
       
   135         case TPositionModuleStatus::EDeviceActive:
       
   136             return Min( 
       
   137                 KPosTimeshiftValueMultiplier*aTtnf.Int64(), 
       
   138                 iMaxTimeshiftInActiveOrReady );
       
   139         default:
       
   140             return Min( aTtff, iMaxTimeshiftNotInActiveOrReady );
       
   141         }
       
   142     }
       
   143             
       
   144 // ---------------------------------------------------------
       
   145 // CPosConstManager::GetUnusedTimeoutValue
       
   146 // ---------------------------------------------------------
       
   147 //
       
   148 TTimeIntervalMicroSeconds  CPosConstManager::GetUnusedTimeoutValue() const
       
   149     {
       
   150     return iPsyStateUnknownTimeout;
       
   151     }
       
   152     
       
   153 // ---------------------------------------------------------
       
   154 // CPosConstManager::GetExternalGpsCheckingTimeoutValue
       
   155 // ---------------------------------------------------------
       
   156 //
       
   157 TTimeIntervalMicroSeconds  CPosConstManager::GetExternalGpsCheckingTimeoutValue() const
       
   158     {
       
   159     return iExternalGpsCheckingTimeout;
       
   160     }
       
   161         
       
   162 // ---------------------------------------------------------
       
   163 // CPosConstManager::GetCleanupTimeoutValue
       
   164 // ---------------------------------------------------------
       
   165 //
       
   166 TTimeIntervalMicroSeconds CPosConstManager::GetCleanupTimeoutValue() const
       
   167     {
       
   168     return iCleanupTimeout;
       
   169     }
       
   170 
       
   171 // ---------------------------------------------------------
       
   172 // CPosConstManager::GetLastWorkingGpsPsyId
       
   173 // ---------------------------------------------------------
       
   174 //
       
   175 TPositionModuleId CPosConstManager::GetLastWorkingGpsPsyId()
       
   176     {
       
   177     if ( iLastWorkingGpsPsyId != KPositionNullModuleId )
       
   178         {
       
   179         return iLastWorkingGpsPsyId;
       
   180         }
       
   181         
       
   182     TPositionModuleId id = KPositionNullModuleId;
       
   183     TBuf< KPosMaximumLastWorkingGpsPsyUidStringLength > idBuf;
       
   184     TInt err = iRepository->Get( 
       
   185         KDefaultProxyLastWorkingGpsPsy,
       
   186         idBuf );
       
   187     TLex lex ( idBuf );
       
   188     lex.SkipSpace();
       
   189     TUint32 psyUid;
       
   190     if ( err == KErrNone )
       
   191         {
       
   192         err = lex.Val( psyUid , EHex );
       
   193         if ( err == KErrNone )
       
   194             {
       
   195             id = TUid::Uid( psyUid );
       
   196             }
       
   197         }
       
   198 
       
   199     TRACESTRING2( "GetLastWorkingGpsPsyId Id: %x", id)
       
   200 
       
   201     iLastWorkingGpsPsyId = KPositionNullModuleId;
       
   202     
       
   203     return id;
       
   204     }
       
   205         
       
   206 // ---------------------------------------------------------
       
   207 // CPosConstManager::SetLastWorkingGpsPsyId
       
   208 // ---------------------------------------------------------
       
   209 //
       
   210 void CPosConstManager::SetLastWorkingGpsPsyId( TPositionModuleId aId )
       
   211     {
       
   212     TRACESTRING2( "SetLastWorkingGpsPsyId Id: %x", aId)
       
   213 
       
   214     if ( aId == iLastWorkingGpsPsyId )
       
   215         {
       
   216         return;
       
   217         }
       
   218         
       
   219     iLastWorkingGpsPsyId = aId;
       
   220     
       
   221     TBuf< KPosMaximumLastWorkingGpsPsyUidStringLength > idBuf;
       
   222 
       
   223     idBuf.AppendNumFixedWidth( aId.iUid, EHex, KPosPsyUidWidth );
       
   224     iRepository->Set( 
       
   225         KDefaultProxyLastWorkingGpsPsy,
       
   226         idBuf ); //error ignored
       
   227     }
       
   228 
       
   229 //  End of File