locationsystemui/locationsysui/possettings/possettingsengine/src/possettingsengineprivate.cpp
branchRCL_3
changeset 44 2b4ea9893b66
equal deleted inserted replaced
42:02ba3f1733c6 44:2b4ea9893b66
       
     1 /*
       
     2 * Copyright (c) 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:  Implementation of positioning settings engine private class. 
       
    15 *
       
    16 */
       
    17 
       
    18 #include "possettingsengineprivate.h"
       
    19 #include "possettingsengine.h"
       
    20 #include <qglobal.h>
       
    21 #include <EPos_CSuplSettings.h>
       
    22 #include <lbtcommon.h>
       
    23 #include <EPos_CPosModules.h>
       
    24 #include <EPos_CPosModuleIdList.h>
       
    25 #include <EPos_CPosModuleUpdate.h>
       
    26 
       
    27 // AGPS psy module UID
       
    28 const TUid KAGPSPsyModuleID =
       
    29     {
       
    30     0x101fe98c
       
    31     };
       
    32 // NPP Psy module UID
       
    33 const TUid KNPPPsyModuleID =
       
    34     {
       
    35     0x10206915
       
    36     };
       
    37 
       
    38 //---------------------------------------------------------------------
       
    39 // PosSettingsEnginePrivate::PosSettingsEnginePrivate()
       
    40 // (other items were commented in a header).
       
    41 //---------------------------------------------------------------------
       
    42 PosSettingsEnginePrivate::PosSettingsEnginePrivate( 
       
    43                                       PositionTechnologyChangeObserver& 
       
    44                                       posTechChangeObserver):
       
    45                                       mPosTechChangeObserver(
       
    46                                       posTechChangeObserver )
       
    47     {
       
    48     // Open session to LBT server.
       
    49     int error = mLbtServer.Connect();
       
    50     if( error != KErrNone )
       
    51         {
       
    52         throw( error );
       
    53         }
       
    54     //Open subsession to LBT server.
       
    55     error = mLbtManager.Open( mLbtServer );
       
    56     if( error != KErrNone )
       
    57         {
       
    58         throw( error );
       
    59         }
       
    60     QT_TRAP_THROWING( mSuplSettings = CSuplSettings::NewL();
       
    61                       mPosModules = CPosModules::OpenL();
       
    62                 
       
    63                       populatePsyModuleInfoListL();
       
    64                       // Get back ground position status
       
    65                       GetBackGroundPositioingStateL();
       
    66                       // Register for settings change.
       
    67                       mPosModules->SetObserverL( *this )
       
    68                     );
       
    69     }
       
    70 
       
    71 
       
    72 //---------------------------------------------------------------------
       
    73 // PosSettingsEnginePrivate::~PosSettingsEnginePrivate()
       
    74 // (other items were commented in a header).
       
    75 //---------------------------------------------------------------------
       
    76 PosSettingsEnginePrivate::~PosSettingsEnginePrivate()
       
    77     {
       
    78     mLbtManager.Close();
       
    79     mLbtServer.Close();
       
    80     delete mSuplSettings;
       
    81     mSuplSettings = NULL;
       
    82     // remove observer
       
    83     mPosModules->RemoveObserver();
       
    84     delete mPosModules;
       
    85     mPosModules = NULL;
       
    86     
       
    87     mPsyModuleInfoList.Close();
       
    88     }
       
    89 
       
    90 
       
    91 //---------------------------------------------------------------------
       
    92 // PosSettingsEnginePrivate::isPositionTechnologyAvailable()
       
    93 // (other items were commented in a header).
       
    94 //---------------------------------------------------------------------
       
    95 bool PosSettingsEnginePrivate::isPositionTechnologyAvailable( 
       
    96                                        PositionTechnology posTechnology )
       
    97     {
       
    98     // Iterate through the PSY list to find the specified position 
       
    99     // technology.
       
   100     TInt cnt = mPsyModuleInfoList.Count();
       
   101     for( TInt i=0;i<cnt;++i )
       
   102         {
       
   103         if( mPsyModuleInfoList[i].mPosTech == posTechnology )
       
   104             {
       
   105             return true;
       
   106             }
       
   107         }
       
   108     return false;
       
   109     }
       
   110 
       
   111 //---------------------------------------------------------------------
       
   112 // PosSettingsEnginePrivate::setPositionTypeState()
       
   113 // (other items were commented in a header).
       
   114 //---------------------------------------------------------------------
       
   115 int PosSettingsEnginePrivate::setPositionTechnologyState( 
       
   116                                       State posTechnologyState,
       
   117                                       PositionTechnology posTechnology )
       
   118     {
       
   119     // If the specified position technology is unavailable, return error.
       
   120     if( !isPositionTechnologyAvailable( posTechnology ) )
       
   121         {
       
   122         return KErrNotFound;
       
   123         }
       
   124     
       
   125     int error = KErrNone;
       
   126     TRAP( error,setPositionTechnologyStateL( posTechnologyState,posTechnology ) );
       
   127     return error;
       
   128     }
       
   129 
       
   130 //---------------------------------------------------------------------
       
   131 // PosSettingsEnginePrivate::isPositionTechnologyEnabled()
       
   132 // (other items were commented in a header).
       
   133 //---------------------------------------------------------------------
       
   134 bool PosSettingsEnginePrivate::isPositionTechnologyEnabled( 
       
   135                                        PositionTechnology posTechnology )
       
   136     {
       
   137     // Iterate through the PSY info list to find specified position 
       
   138     // technology and its corresponding state.
       
   139     TInt cnt = mPsyModuleInfoList.Count();
       
   140     for( TInt i=0;i<cnt;++i )
       
   141         {
       
   142         if( mPsyModuleInfoList[i].mPosTech == posTechnology && 
       
   143             mPsyModuleInfoList[i].mState == StateEnable )
       
   144             {
       
   145             return true;
       
   146             }
       
   147         }
       
   148     return false;
       
   149     }
       
   150                                          
       
   151 //---------------------------------------------------------------------
       
   152 // PosSettingsEnginePrivate::setBackGroundPositioningState()
       
   153 // (other items were commented in a header).
       
   154 //---------------------------------------------------------------------
       
   155 int PosSettingsEnginePrivate::setBackGroundPositioningState( 
       
   156                                              State backGroundPosState )
       
   157     {    
       
   158     // Check if any of the position technology are available.
       
   159     if( !mPsyModuleInfoList.Count() )
       
   160         {
       
   161         return KErrNotSupported;
       
   162         }
       
   163     int error = KErrNone;
       
   164     // Change the state of back ground positioning only if its current
       
   165     // state is different from the requested state.
       
   166     if( backGroundPosState != mBackGroundPositioningState )
       
   167         {
       
   168         TRAP( error,setBackGroundPositioningStateL( backGroundPosState ) );
       
   169         }
       
   170     return error;
       
   171     }
       
   172 
       
   173 //---------------------------------------------------------------------
       
   174 // PosSettingsEnginePrivate::isBackGroundPositioningEnabled()
       
   175 // (other items were commented in a header).
       
   176 //---------------------------------------------------------------------
       
   177 bool PosSettingsEnginePrivate::isBackGroundPositioningEnabled()
       
   178     {
       
   179     if( mBackGroundPositioningState == StateEnable )
       
   180         {
       
   181         return true;
       
   182         }
       
   183     return false;
       
   184     }
       
   185 
       
   186 //---------------------------------------------------------------------
       
   187 // PosSettingsEnginePrivate::HandleSettingsChangeL()
       
   188 // (other items were commented in a header).
       
   189 //---------------------------------------------------------------------
       
   190 void PosSettingsEnginePrivate::HandleSettingsChangeL( 
       
   191                                        TPosModulesEvent aEvent )
       
   192     {    
       
   193     // Reset the module info list and repopulate again.
       
   194     mPsyModuleInfoList.Reset();
       
   195     populatePsyModuleInfoListL();
       
   196     
       
   197     if( aEvent.iType == EPosModulesEventModuleInstalled || aEvent.iType == EPosModulesEventModuleRemoved
       
   198     	|| aEvent.iType == EPosModulesEventVisibilityChanged ) 
       
   199         {       
       
   200     	mPosTechChangeObserver.handlePositionTechnologyChange();
       
   201     	}
       
   202     }
       
   203 
       
   204 //---------------------------------------------------------------------
       
   205 // PosSettingsEnginePrivate::setPositionTechnologyStateL()
       
   206 // (other items were commented in a header).
       
   207 //---------------------------------------------------------------------
       
   208 void PosSettingsEnginePrivate::setPositionTechnologyStateL( 
       
   209                                         State posTechnologyState,
       
   210                                         PositionTechnology posTechnology )
       
   211     {
       
   212     CPosModuleUpdate* updateParams = CPosModuleUpdate::NewLC();
       
   213     
       
   214     if( posTechnologyState == StateEnable )
       
   215         {
       
   216         updateParams->SetUpdateAvailability( ETrue );
       
   217         }
       
   218     else
       
   219         {
       
   220         updateParams->SetUpdateAvailability( EFalse );
       
   221         }
       
   222     TInt cnt = mPsyModuleInfoList.Count();    
       
   223     for( TInt i=0;i<cnt;++i )
       
   224         {
       
   225         // Change the state only if position technology of PSY matches
       
   226         // with the position technology specified and if the state of 
       
   227         // the PSY is different from the requested state.
       
   228         if( mPsyModuleInfoList[i].mPosTech == posTechnology &&
       
   229             mPsyModuleInfoList[i].mState != posTechnologyState )
       
   230             {
       
   231             mPosModules->UpdateModuleL( mPsyModuleInfoList[i].mPsyModuleId, 
       
   232                                         *updateParams );
       
   233             mPsyModuleInfoList[i].mState = posTechnologyState;
       
   234             }
       
   235         }
       
   236     CleanupStack::PopAndDestroy( updateParams );
       
   237     }
       
   238 
       
   239 //---------------------------------------------------------------------
       
   240 // PosSettingsEnginePrivate::setBackGroundPositioningStateL()
       
   241 // (other items were commented in a header).
       
   242 //---------------------------------------------------------------------
       
   243 void PosSettingsEnginePrivate::setBackGroundPositioningStateL( 
       
   244                                            State backGroundPosState )
       
   245     {
       
   246     if( backGroundPosState == StateEnable )
       
   247         {
       
   248         mLbtManager.SetTriggeringMechanismStateL( 
       
   249                      ETriggeringMechanismOn );
       
   250         User::LeaveIfError( mSuplSettings->SetSuplTriggeredServiceStatus( 
       
   251                                 CSuplSettings::ESuplTriggerOn  ) );
       
   252         mBackGroundPositioningState = StateEnable;
       
   253         }
       
   254     else
       
   255         {
       
   256         mLbtManager.SetTriggeringMechanismStateL( 
       
   257                      ETriggeringMechanismOff );
       
   258         User::LeaveIfError( mSuplSettings->SetSuplTriggeredServiceStatus( 
       
   259                                 CSuplSettings::ESuplTriggerOff ) );
       
   260         mBackGroundPositioningState = StateDisable;
       
   261         }
       
   262     }
       
   263 
       
   264 //---------------------------------------------------------------------
       
   265 // PosSettingsEnginePrivate::populatePsyModuleInfoListL()
       
   266 // (other items were commented in a header).
       
   267 //---------------------------------------------------------------------
       
   268 void PosSettingsEnginePrivate::populatePsyModuleInfoListL()
       
   269     {
       
   270     TBool agpsState = EFalse;
       
   271     TBool nppState = EFalse;
       
   272     CPosModuleIdList* idList = mPosModules->ModuleIdListLC();
       
   273     TInt cnt = idList->Count();
       
   274     for ( TInt i = 0; i < cnt; ++i )
       
   275         {
       
   276         TPositionModuleInfo moduleInfo;
       
   277         mPosModules->GetModuleInfoL( (*idList)[i], moduleInfo );
       
   278         
       
   279         // Psy module info hold the information regarding PSY that are
       
   280         // essential for our operation.
       
   281         PsyModuleInfo psyModuleInfo;
       
   282         
       
   283         // Set the module Id.
       
   284         psyModuleInfo.mPsyModuleId = moduleInfo.ModuleId();
       
   285         
       
   286         // Set position technology type.
       
   287         if( moduleInfo.TechnologyType() == TPositionModuleInfo::ETechnologyTerminal ||
       
   288             moduleInfo.TechnologyType() == TPositionModuleInfo::ETechnologyAssisted )
       
   289             {
       
   290             psyModuleInfo.mPosTech = PositionTechnologyGps;
       
   291             }
       
   292         else if ( moduleInfo.TechnologyType() == TPositionModuleInfo::ETechnologyNetwork )
       
   293             {
       
   294             psyModuleInfo.mPosTech = PositionTechnologyNetwork;
       
   295             }
       
   296         
       
   297         // Set state of Psy.
       
   298         if( moduleInfo.IsAvailable() )
       
   299             {
       
   300             psyModuleInfo.mState = StateEnable;
       
   301             // capture the state of the agps psy module
       
   302             if (moduleInfo.ModuleId() == KAGPSPsyModuleID)
       
   303                 {
       
   304                 agpsState = ETrue;
       
   305                 }
       
   306             // capture the state of npp psy module
       
   307             if (moduleInfo.ModuleId() == KNPPPsyModuleID)
       
   308                 {
       
   309                 nppState = ETrue;
       
   310                 }
       
   311 
       
   312             }
       
   313         else 
       
   314             {
       
   315             psyModuleInfo.mState = StateDisable;
       
   316             // capture the state of the agps psy module
       
   317             if (moduleInfo.ModuleId() == KAGPSPsyModuleID)
       
   318                 {
       
   319                 agpsState = EFalse;
       
   320                 }
       
   321             // capture the state of npp psy module
       
   322             if (moduleInfo.ModuleId() == KNPPPsyModuleID)
       
   323                 {
       
   324                 nppState = EFalse;
       
   325                 }
       
   326             }
       
   327         
       
   328         mPsyModuleInfoList.AppendL( psyModuleInfo );
       
   329         }
       
   330     // Check if the state of both agps & npp psy are disabled then turn off the supl trigger status
       
   331     // else turn it back on again even if either is enabled
       
   332     if (!agpsState && !nppState)
       
   333         {
       
   334         User::LeaveIfError(mSuplSettings->SetSuplTriggeredServiceStatus(
       
   335                 CSuplSettings::ESuplTriggerOff));
       
   336         }
       
   337     else
       
   338         {
       
   339         User::LeaveIfError(mSuplSettings->SetSuplTriggeredServiceStatus(
       
   340                 CSuplSettings::ESuplTriggerOn));
       
   341         }
       
   342 
       
   343     CleanupStack::PopAndDestroy(idList);
       
   344     }
       
   345 
       
   346 
       
   347 //---------------------------------------------------------------------
       
   348 // PosSettingsEnginePrivate::GetBackGroundPositioingStateL()
       
   349 // (other items were commented in a header).
       
   350 //---------------------------------------------------------------------
       
   351 void PosSettingsEnginePrivate::GetBackGroundPositioingStateL()
       
   352     {
       
   353     // Get the SUPL service status.
       
   354     CSuplSettings::TSuplTriggerStatus suplTriggerStatus;
       
   355     User::LeaveIfError( mSuplSettings->GetSuplTriggeredServiceStatus( 
       
   356                         suplTriggerStatus ) );
       
   357     
       
   358     // Get LBT service status.
       
   359     TLbtTriggeringSystemManagementSettings triggeringSystemSettings;
       
   360     mLbtManager.GetTriggeringSystemSettingsL( triggeringSystemSettings );
       
   361     
       
   362     // Back ground positioning state is considered to be enabled only 
       
   363     // if both LBT and SUPL services are enabled.
       
   364     if( suplTriggerStatus == CSuplSettings::ESuplTriggerOn && 
       
   365         triggeringSystemSettings.TriggeringMechanismState() ==
       
   366         ETriggeringMechanismOn )
       
   367         {
       
   368         mBackGroundPositioningState = StateEnable;
       
   369         }
       
   370     else
       
   371         {
       
   372         mBackGroundPositioningState = StateDisable;
       
   373         } 
       
   374     }
       
   375 
       
   376 // End of file