datasourcemodules/bluetoothgpspositioningmodule/btgpspsy/src/Settings/BTGPSSettingManager.cpp
changeset 36 b47902b73a93
parent 0 9cfd9a3ee49c
equal deleted inserted replaced
35:a2efdd544abf 36:b47902b73a93
       
     1 // Copyright (c) 2005-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 <e32std.h>
       
    20 #include <bt_sock.h>
       
    21 #include "BtGpsPsyPrivatePSKeys.h"
       
    22 #include "BtGpsPsyPrivateCRKeys.h"
       
    23 #include "BTGPSSettingManager.h"
       
    24 #include "BTGPSSettingsListener.h"
       
    25 #include "BTGPSLogging.h"
       
    26 
       
    27 // CONSTANTS
       
    28 
       
    29 // BT GPS PSY specific setting partial Id 
       
    30 const TUint32 KBTGPSPSYSpecificSettingsPartialId = 0x10000000;
       
    31 
       
    32 // BT GPS PSY specific setting mask
       
    33 const TUint32 KBTGPSPSYSpecificSettingsMask = 0xF0000000;
       
    34 
       
    35 
       
    36 // MACROS
       
    37 
       
    38 
       
    39 // ============================ MEMBER FUNCTIONS ===============================
       
    40 
       
    41 
       
    42 // -----------------------------------------------------------------------------
       
    43 // CBTGPSSettingManager::NewL
       
    44 // -----------------------------------------------------------------------------
       
    45 CBTGPSSettingManager* CBTGPSSettingManager::NewL()
       
    46     {
       
    47     CBTGPSSettingManager* self = new (ELeave) CBTGPSSettingManager();
       
    48     CleanupStack::PushL(self);
       
    49     self->ConstructL();
       
    50     CleanupStack::Pop();
       
    51     return self;
       
    52     }
       
    53 
       
    54 // -----------------------------------------------------------------------------
       
    55 // CBTGPSSettingManager::~CBTGPSSettingManager
       
    56 // -----------------------------------------------------------------------------
       
    57 CBTGPSSettingManager::~CBTGPSSettingManager()
       
    58     {
       
    59     //Set setting to unload status. All erros are ignored in destruction
       
    60     iEvents.Set(KPsUidBluetoothGpsPsy, KBluetoothGpsPsyState,           EPSYNotLoaded); 
       
    61 	iEvents.Set(KPsUidBluetoothGpsPsy, KBluetoothGpsPsyBatteryLevel,    KErrNotFound); 
       
    62 	iEvents.Set(KPsUidBluetoothGpsPsy, KBluetoothGpsPsyBatteryState,    EBatteryStateNA); 
       
    63 	iEvents.Set(KPsUidBluetoothGpsPsy, KBluetoothGpsPsyExtAntennaState, EExtAntennaNA); 
       
    64 	iEvents.Set(KPsUidBluetoothGpsPsy, KBluetoothGpsPsyExtPowerState,   EExtPowerNA); 
       
    65 	iEvents.Set(KPsUidBluetoothGpsPsy, KBluetoothGpsPsyVersion,         KNullDesC); 
       
    66 	iEvents.Set(KPsUidBluetoothGpsPsy, KBluetoothGpsPsyBtHwVersion,     KNullDesC); 
       
    67 	iEvents.Set(KPsUidBluetoothGpsPsy, KBluetoothGpsPsyBtSwVersion,     KNullDesC); 
       
    68 	iEvents.Set(KPsUidBluetoothGpsPsy, KBluetoothGpsPsyGpsHwVersion,    KNullDesC); 
       
    69 	iEvents.Set(KPsUidBluetoothGpsPsy, KBluetoothGpsPsyGpsSwVersion,    KNullDesC);
       
    70 	
       
    71 	iEvents.Close();
       
    72 	
       
    73 	Cancel();
       
    74 	
       
    75 	delete iSettings;
       
    76 	
       
    77 	iListenerArray.Reset();
       
    78 	iListenerArray.Close();
       
    79     }
       
    80 
       
    81 // -----------------------------------------------------------------------------
       
    82 // CBTGPSSettingManager::ConstructL
       
    83 // -----------------------------------------------------------------------------
       
    84 void CBTGPSSettingManager::ConstructL()
       
    85     {
       
    86 	TRACESTRING("CBTGPSSettingManager::ConstructL()")
       
    87 
       
    88     TInt err(KErrNone);
       
    89 
       
    90 	//Define P&S events
       
    91 	TSecurityPolicy readPolicy(ECapabilityReadDeviceData);
       
    92 	TSecurityPolicy writePolicy(ECapabilityWriteDeviceData);	
       
    93 	err |= iEvents.Define(KPsUidBluetoothGpsPsy, KBluetoothGpsPsyState,            RProperty::EInt, readPolicy, writePolicy); 
       
    94 	err |= iEvents.Define(KPsUidBluetoothGpsPsy, KBluetoothGpsPsyBatteryLevel,     RProperty::EInt, readPolicy, writePolicy); 
       
    95 	err |= iEvents.Define(KPsUidBluetoothGpsPsy, KBluetoothGpsPsyBatteryState,     RProperty::EInt, readPolicy, writePolicy); 
       
    96 	err |= iEvents.Define(KPsUidBluetoothGpsPsy, KBluetoothGpsPsyExtAntennaState,  RProperty::EInt, readPolicy, writePolicy); 
       
    97 	err |= iEvents.Define(KPsUidBluetoothGpsPsy, KBluetoothGpsPsyExtPowerState,    RProperty::EInt, readPolicy, writePolicy); 
       
    98 	err |= iEvents.Define(KPsUidBluetoothGpsPsy, KBluetoothGpsPsyVersion,          RProperty::EByteArray, readPolicy, writePolicy); 
       
    99 	err |= iEvents.Define(KPsUidBluetoothGpsPsy, KBluetoothGpsPsyBtHwVersion,      RProperty::EByteArray, readPolicy, writePolicy); 
       
   100 	err |= iEvents.Define(KPsUidBluetoothGpsPsy, KBluetoothGpsPsyBtSwVersion,      RProperty::EByteArray, readPolicy, writePolicy); 
       
   101 	err |= iEvents.Define(KPsUidBluetoothGpsPsy, KBluetoothGpsPsyGpsHwVersion,     RProperty::EByteArray, readPolicy, writePolicy); 
       
   102 	err |= iEvents.Define(KPsUidBluetoothGpsPsy, KBluetoothGpsPsyGpsSwVersion,     RProperty::EByteArray, readPolicy, writePolicy); 
       
   103 
       
   104 	if(err!=KErrAlreadyExists)
       
   105 	    {
       
   106 	    User::LeaveIfError(err);
       
   107 	    }
       
   108 	
       
   109     err = KErrNone;
       
   110     
       
   111     err |= iEvents.Set(KPsUidBluetoothGpsPsy, KBluetoothGpsPsyState,            EPSYLoaded); 
       
   112 	err |= iEvents.Set(KPsUidBluetoothGpsPsy, KBluetoothGpsPsyBatteryLevel,     KErrNotFound); 
       
   113 	err |= iEvents.Set(KPsUidBluetoothGpsPsy, KBluetoothGpsPsyBatteryState,     EBatteryStateNA); 
       
   114 	err |= iEvents.Set(KPsUidBluetoothGpsPsy, KBluetoothGpsPsyExtAntennaState,  EExtAntennaNA); 
       
   115 	err |= iEvents.Set(KPsUidBluetoothGpsPsy, KBluetoothGpsPsyExtPowerState,    EExtPowerNA); 
       
   116 	err |= iEvents.Set(KPsUidBluetoothGpsPsy, KBluetoothGpsPsyVersion,          KNullDesC); 
       
   117 	err |= iEvents.Set(KPsUidBluetoothGpsPsy, KBluetoothGpsPsyBtHwVersion,      KNullDesC); 
       
   118 	err |= iEvents.Set(KPsUidBluetoothGpsPsy, KBluetoothGpsPsyBtSwVersion,      KNullDesC); 
       
   119 	err |= iEvents.Set(KPsUidBluetoothGpsPsy, KBluetoothGpsPsyGpsHwVersion,     KNullDesC); 
       
   120 	err |= iEvents.Set(KPsUidBluetoothGpsPsy, KBluetoothGpsPsyGpsSwVersion,     KNullDesC); 
       
   121 	
       
   122 	User::LeaveIfError(err);
       
   123 	
       
   124     //Construct Central Repositary Setting
       
   125     iSettings = CRepository::NewL(KCRUidBtGpsPsy );
       
   126     iSettings->NotifyRequest(
       
   127         KBTGPSPSYSpecificSettingsPartialId, 
       
   128         KBTGPSPSYSpecificSettingsMask,
       
   129         iStatus);
       
   130     SetActive();
       
   131     
       
   132     }
       
   133 
       
   134 // -----------------------------------------------------------------------------
       
   135 // CBTGPSSettingManager::CBTGPSSettingManager
       
   136 // C++ default constructor can NOT contain any code, that
       
   137 // might leave.
       
   138 // -----------------------------------------------------------------------------
       
   139 CBTGPSSettingManager::CBTGPSSettingManager() :
       
   140     CActive(EPriorityStandard)
       
   141     {
       
   142     CActiveScheduler::Add(this);
       
   143     }
       
   144     
       
   145 // -----------------------------------------------------------------------------
       
   146 // CBTGPSSettingManager::UpdatePsyState
       
   147 // Updates the client for new BT GPS PSY values.
       
   148 // -----------------------------------------------------------------------------
       
   149 TInt CBTGPSSettingManager::UpdatePsyState(const TBTGPSPSYState aStatus)
       
   150     {
       
   151     TInt err = KErrNone;
       
   152     TRACESTRING28("CBTGPSSettingManager::UpdateBTGPSPSYStatus: %d", aStatus)
       
   153 	err = iEvents.Set(KPsUidBluetoothGpsPsy, KBluetoothGpsPsyState, aStatus);
       
   154 	if( aStatus != EPSYLoadedAndPNOKSupportedBTGPSUsed )
       
   155 		{
       
   156 		err |= iEvents.Set(KPsUidBluetoothGpsPsy, KBluetoothGpsPsyBatteryLevel,     KErrNotFound); 
       
   157 	    err |= iEvents.Set(KPsUidBluetoothGpsPsy, KBluetoothGpsPsyBatteryState,     EBatteryStateNA); 
       
   158 	    err |= iEvents.Set(KPsUidBluetoothGpsPsy, KBluetoothGpsPsyExtAntennaState,  EExtAntennaNA); 
       
   159 	    err |= iEvents.Set(KPsUidBluetoothGpsPsy, KBluetoothGpsPsyExtPowerState,    EExtPowerNA); 
       
   160 	    err |= iEvents.Set(KPsUidBluetoothGpsPsy, KBluetoothGpsPsyVersion,          KNullDesC); 
       
   161     	err |= iEvents.Set(KPsUidBluetoothGpsPsy, KBluetoothGpsPsyBtHwVersion,      KNullDesC); 
       
   162     	err |= iEvents.Set(KPsUidBluetoothGpsPsy, KBluetoothGpsPsyBtSwVersion,      KNullDesC); 
       
   163     	err |= iEvents.Set(KPsUidBluetoothGpsPsy, KBluetoothGpsPsyGpsHwVersion,     KNullDesC); 
       
   164     	err |= iEvents.Set(KPsUidBluetoothGpsPsy, KBluetoothGpsPsyGpsSwVersion,     KNullDesC); 
       
   165 		}
       
   166     return err;
       
   167     }
       
   168 
       
   169 // -----------------------------------------------------------------------------
       
   170 // CBTGPSSettingManager::UpdateDeviceStatus
       
   171 // Updates the client information file for the new status event values 
       
   172 // (batterylevel ext. antenna and ext. power state).
       
   173 // -----------------------------------------------------------------------------     
       
   174 TInt CBTGPSSettingManager::UpdateDeviceStatus(
       
   175         const TInt aBatteryLevel, 
       
   176         const TBTGPSExtPowerState aExtPowerState, 
       
   177         const TBTGPSExtAntennaState aExtAntennaState,
       
   178         const TBTGPSBatteryState aBatteryState )
       
   179     {
       
   180     TRACESTRING("CBTGPSSettingManager::UpdateStatus")
       
   181     
       
   182     TInt err = KErrNone;
       
   183     err |= iEvents.Set(KPsUidBluetoothGpsPsy, KBluetoothGpsPsyBatteryLevel,     aBatteryLevel); 
       
   184 	err |= iEvents.Set(KPsUidBluetoothGpsPsy, KBluetoothGpsPsyBatteryState,     aBatteryState); 
       
   185 	err |= iEvents.Set(KPsUidBluetoothGpsPsy, KBluetoothGpsPsyExtAntennaState,  aExtAntennaState); 
       
   186 	err |= iEvents.Set(KPsUidBluetoothGpsPsy, KBluetoothGpsPsyExtPowerState,    aExtPowerState); 
       
   187 	
       
   188 	return err;
       
   189     }
       
   190     
       
   191 // -----------------------------------------------------------------------------
       
   192 // CBTGPSSettingManager::UpdateVersions
       
   193 // Updates the client information file for the new version (device, BT HW, BT SW,
       
   194 // GPS HW and GPS SW) information.
       
   195 // ----------------------------------------------------------------------------- 
       
   196 TInt CBTGPSSettingManager::UpdateVersions(
       
   197         const TDesC8& aID, 
       
   198         const TDesC8& aBTHW, 
       
   199         const TDesC8& aBTSW, 
       
   200         const TDesC8& aGPSHW, 
       
   201         const TDesC8& aGPSSW)
       
   202     {
       
   203     TInt err = KErrNone;
       
   204     
       
   205     TRACESTRING("CBTGPSSettingManager::UpdateVersions")  
       
   206 	TRACETEXT(aID) 
       
   207 	TRACETEXT(aBTHW)
       
   208 	TRACETEXT(aBTSW)
       
   209 	TRACETEXT(aGPSHW)
       
   210 	TRACETEXT(aGPSSW)
       
   211 	
       
   212 	err |= iEvents.Set(KPsUidBluetoothGpsPsy, KBluetoothGpsPsyVersion,          aID); 
       
   213 	err |= iEvents.Set(KPsUidBluetoothGpsPsy, KBluetoothGpsPsyBtHwVersion,      aBTHW);
       
   214 	err |= iEvents.Set(KPsUidBluetoothGpsPsy, KBluetoothGpsPsyBtSwVersion,      aBTSW);
       
   215 	err |= iEvents.Set(KPsUidBluetoothGpsPsy, KBluetoothGpsPsyGpsHwVersion,     aGPSHW);
       
   216 	err |= iEvents.Set(KPsUidBluetoothGpsPsy, KBluetoothGpsPsyGpsSwVersion,     aGPSSW);
       
   217 	
       
   218 	return err;
       
   219     }
       
   220     
       
   221 // -----------------------------------------------------------------------------
       
   222 // CBTGPSSettingManager::GetNightModeSetting
       
   223 // ----------------------------------------------------------------------------- 
       
   224 TInt CBTGPSSettingManager::GetNightModeSetting(TBTGPSSettingsApi::TNightModeState& aStatus)
       
   225     {
       
   226     TInt err = KErrNone;
       
   227     TInt nightMode = KErrNotFound;
       
   228     err |= iSettings->Get(KBluetoothGpsPsyNightModeState, nightMode);
       
   229     switch(nightMode)
       
   230         {
       
   231         case TBTGPSSettingsApi::ENightModeOn:
       
   232         case TBTGPSSettingsApi::ENightModeOff:
       
   233             {
       
   234             aStatus = (TBTGPSSettingsApi::TNightModeState) nightMode;
       
   235             break;
       
   236             }
       
   237         default:
       
   238             return KErrCorrupt;
       
   239         }
       
   240     return err;
       
   241     }
       
   242 
       
   243 // -----------------------------------------------------------------------------
       
   244 // CBTGPSSettingManager::GetBTDeviceInfo
       
   245 // ----------------------------------------------------------------------------- 
       
   246 TInt CBTGPSSettingManager::GetBTDeviceInfo(TInt& aValid, TBTSockAddr& aAddress )
       
   247     {
       
   248     TRACESTRING("CBTGPSSettingManager::GetBTDeviceInfo")
       
   249 
       
   250     TInt err = KErrNone;
       
   251     err |=  iSettings->Get( KBluetoothGpsPsyDeviceAddressValidity, aValid );
       
   252     TBuf<KMaxSockAddrSize> addressBuffer;
       
   253     err |= iSettings->Get( KBluetoothGpsPsyDeviceAddress, addressBuffer );
       
   254     aAddress.Copy(addressBuffer);
       
   255     
       
   256     TRACESTRING2("err=%d", err)
       
   257     TRACESTRING2("validity=%d", aValid)
       
   258     TRACESTRING28("Address=%S", &aAddress)
       
   259 
       
   260     return err;
       
   261     }
       
   262 
       
   263 // -----------------------------------------------------------------------------
       
   264 // CBTGPSSettingManager::UpdateBTDeviceInfo
       
   265 // ----------------------------------------------------------------------------- 
       
   266 TInt CBTGPSSettingManager::UpdateBTDeviceInfo(TInt aValid, const TBTSockAddr& aAddress)
       
   267     {
       
   268     TInt err = KErrNone;
       
   269     err |= iSettings->Set(KBluetoothGpsPsyDeviceAddressValidity, aValid);
       
   270     
       
   271     TBuf<KMaxSockAddrSize> addressBuffer;
       
   272     addressBuffer.Copy(aAddress);
       
   273     err |= iSettings->Set(KBluetoothGpsPsyDeviceAddress , addressBuffer);
       
   274     
       
   275     return err;
       
   276     }
       
   277     
       
   278 // -----------------------------------------------------------------------------
       
   279 // CBTGPSSettingManager::ResetEventStatuses
       
   280 // ----------------------------------------------------------------------------- 
       
   281 void CBTGPSSettingManager::ResetEventStatuses()
       
   282     {
       
   283     //Reset status events in P&S. All errors are ignored.
       
   284     iEvents.Set(KPsUidBluetoothGpsPsy, KBluetoothGpsPsyState,            EPSYLoaded); 
       
   285     iEvents.Set(KPsUidBluetoothGpsPsy, KBluetoothGpsPsyBatteryLevel,     KErrNotFound); 
       
   286 	iEvents.Set(KPsUidBluetoothGpsPsy, KBluetoothGpsPsyBatteryState,     EBatteryStateNA); 
       
   287 	iEvents.Set(KPsUidBluetoothGpsPsy, KBluetoothGpsPsyExtAntennaState,  EExtAntennaNA); 
       
   288 	iEvents.Set(KPsUidBluetoothGpsPsy, KBluetoothGpsPsyExtPowerState,    EExtPowerNA); 
       
   289 	iEvents.Set(KPsUidBluetoothGpsPsy, KBluetoothGpsPsyVersion,          KNullDesC); 
       
   290     iEvents.Set(KPsUidBluetoothGpsPsy, KBluetoothGpsPsyBtHwVersion,      KNullDesC); 
       
   291     iEvents.Set(KPsUidBluetoothGpsPsy, KBluetoothGpsPsyBtSwVersion,      KNullDesC); 
       
   292     iEvents.Set(KPsUidBluetoothGpsPsy, KBluetoothGpsPsyGpsHwVersion,     KNullDesC); 
       
   293     iEvents.Set(KPsUidBluetoothGpsPsy, KBluetoothGpsPsyGpsSwVersion,     KNullDesC); 
       
   294     }	
       
   295 	
       
   296 // -----------------------------------------------------------------------------
       
   297 // CBTGPSSettingManager::HandleSettingsChangeL
       
   298 // Callback function from MPosSettingsObserver. The Positioning Plug-in API
       
   299 // uses this to inform changes in the observable file.
       
   300 // ----------------------------------------------------------------------------- 
       
   301 void CBTGPSSettingManager::HandleSettingsChange()
       
   302 	{
       
   303 	TRACESTRING("CBTGPSSettingManager::HandleSettingsChange start ...")
       
   304 	
       
   305 	//Get night mode status
       
   306 	TInt nightMode;
       
   307 	iSettings->Get( KBluetoothGpsPsyNightModeState, nightMode );
       
   308 	
       
   309 	//Inform listeners on night mode setting change.
       
   310     TInt count = iListenerArray.Count();
       
   311     for(TInt i=count-1; i>=0; i--)
       
   312         {
       
   313         iListenerArray[i]->HandleNightModeChange(
       
   314             (TBTGPSSettingsApi::TNightModeState)nightMode);
       
   315         }
       
   316 	
       
   317 	//no change event notifies for dialog status setting change.
       
   318     TRACESTRING("CBTGPSSettingManager::HandleSettingsChange end")
       
   319 	}
       
   320 	
       
   321 // -----------------------------------------------------------------------------
       
   322 // CBTGPSSettingManager::RunL
       
   323 // ----------------------------------------------------------------------------- 
       
   324 void CBTGPSSettingManager::RunL()
       
   325     {
       
   326 	TRACESTRING2("CBTGPSSettingManager::RunL start ....%d", iStatus.Int())
       
   327     //Issue request right after. Otherwise we may miss some change notification
       
   328     iSettings->NotifyRequest(
       
   329         KBTGPSPSYSpecificSettingsPartialId, 
       
   330         KBTGPSPSYSpecificSettingsMask,
       
   331         iStatus);
       
   332     SetActive();
       
   333     
       
   334     HandleSettingsChange();
       
   335 	TRACESTRING("CBTGPSSettingManager::RunL end")
       
   336     }
       
   337 
       
   338 // -----------------------------------------------------------------------------
       
   339 // CBTGPSSettingManager::DoCancel
       
   340 // ----------------------------------------------------------------------------- 
       
   341 void CBTGPSSettingManager::DoCancel()
       
   342     {
       
   343     if(iSettings!=NULL)
       
   344         {
       
   345         iSettings->NotifyCancelAll();
       
   346         }
       
   347     }
       
   348 
       
   349 // -----------------------------------------------------------------------------
       
   350 // CBTGPSSettingManager::AddListenerL
       
   351 // ----------------------------------------------------------------------------- 
       
   352 void CBTGPSSettingManager::AddListenerL(MBTGPSSettingsListener& aListener)
       
   353     {
       
   354     User::LeaveIfError(iListenerArray.Append(&aListener));
       
   355     }
       
   356         
       
   357 // -----------------------------------------------------------------------------
       
   358 // CBTGPSSettingManager::RemoveListener
       
   359 // ----------------------------------------------------------------------------- 
       
   360 void CBTGPSSettingManager::RemoveListener(MBTGPSSettingsListener& aListener)
       
   361     {
       
   362     TInt index = iListenerArray.Find(&aListener);
       
   363     if(index!=KErrNone)
       
   364         {
       
   365         iListenerArray.Remove(index);
       
   366         }
       
   367     }
       
   368 
       
   369 
       
   370 
       
   371 //  End of File