datasourcemodules/defaultpositioningmodule/src/epos_cposconstmanager.cpp
changeset 0 9cfd9a3ee49c
child 4 03e0f2627e7a
equal deleted inserted replaced
-1:000000000000 0:9cfd9a3ee49c
       
     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::EDeviceReady:
       
   136         case TPositionModuleStatus::EDeviceActive:
       
   137             return Min( 
       
   138                 KPosTimeshiftValueMultiplier*aTtnf.Int64(), 
       
   139                 iMaxTimeshiftInActiveOrReady );
       
   140         default:
       
   141             return Min( aTtff, iMaxTimeshiftNotInActiveOrReady );
       
   142         }
       
   143     }
       
   144             
       
   145 // ---------------------------------------------------------
       
   146 // CPosConstManager::GetUnusedTimeoutValue
       
   147 // ---------------------------------------------------------
       
   148 //
       
   149 TTimeIntervalMicroSeconds  CPosConstManager::GetUnusedTimeoutValue() const
       
   150     {
       
   151     return iPsyStateUnknownTimeout;
       
   152     }
       
   153     
       
   154 // ---------------------------------------------------------
       
   155 // CPosConstManager::GetExternalGpsCheckingTimeoutValue
       
   156 // ---------------------------------------------------------
       
   157 //
       
   158 TTimeIntervalMicroSeconds  CPosConstManager::GetExternalGpsCheckingTimeoutValue() const
       
   159     {
       
   160     return iExternalGpsCheckingTimeout;
       
   161     }
       
   162         
       
   163 // ---------------------------------------------------------
       
   164 // CPosConstManager::GetCleanupTimeoutValue
       
   165 // ---------------------------------------------------------
       
   166 //
       
   167 TTimeIntervalMicroSeconds CPosConstManager::GetCleanupTimeoutValue() const
       
   168     {
       
   169     return iCleanupTimeout;
       
   170     }
       
   171 
       
   172 // ---------------------------------------------------------
       
   173 // CPosConstManager::GetLastWorkingGpsPsyId
       
   174 // ---------------------------------------------------------
       
   175 //
       
   176 TPositionModuleId CPosConstManager::GetLastWorkingGpsPsyId()
       
   177     {
       
   178     if ( iLastWorkingGpsPsyId != KPositionNullModuleId )
       
   179         {
       
   180         return iLastWorkingGpsPsyId;
       
   181         }
       
   182         
       
   183     TPositionModuleId id = KPositionNullModuleId;
       
   184     TBuf< KPosMaximumLastWorkingGpsPsyUidStringLength > idBuf;
       
   185     TInt err = iRepository->Get( 
       
   186         KDefaultProxyLastWorkingGpsPsy,
       
   187         idBuf );
       
   188     TLex lex ( idBuf );
       
   189     lex.SkipSpace();
       
   190     TUint32 psyUid;
       
   191     if ( err == KErrNone )
       
   192         {
       
   193         err = lex.Val( psyUid , EHex );
       
   194         if ( err == KErrNone )
       
   195             {
       
   196             id = TUid::Uid( psyUid );
       
   197             }
       
   198         }
       
   199 
       
   200     TRACESTRING2( "GetLastWorkingGpsPsyId Id: %x", id)
       
   201 
       
   202     iLastWorkingGpsPsyId = KPositionNullModuleId;
       
   203     
       
   204     return id;
       
   205     }
       
   206         
       
   207 // ---------------------------------------------------------
       
   208 // CPosConstManager::SetLastWorkingGpsPsyId
       
   209 // ---------------------------------------------------------
       
   210 //
       
   211 void CPosConstManager::SetLastWorkingGpsPsyId( TPositionModuleId aId )
       
   212     {
       
   213     TRACESTRING2( "SetLastWorkingGpsPsyId Id: %x", aId)
       
   214 
       
   215     if ( aId == iLastWorkingGpsPsyId )
       
   216         {
       
   217         return;
       
   218         }
       
   219         
       
   220     iLastWorkingGpsPsyId = aId;
       
   221     
       
   222     TBuf< KPosMaximumLastWorkingGpsPsyUidStringLength > idBuf;
       
   223 
       
   224     idBuf.AppendNumFixedWidth( aId.iUid, EHex, KPosPsyUidWidth );
       
   225     iRepository->Set( 
       
   226         KDefaultProxyLastWorkingGpsPsy,
       
   227         idBuf ); //error ignored
       
   228     }
       
   229 
       
   230 //  End of File