locationrequestmgmt/networkrequesthandler/src/privacyandlocationrequesthandler.cpp
changeset 27 aadfb18aaac1
parent 0 9cfd9a3ee49c
child 49 5f20f71a57a3
--- a/locationrequestmgmt/networkrequesthandler/src/privacyandlocationrequesthandler.cpp	Mon May 03 13:50:32 2010 +0300
+++ b/locationrequestmgmt/networkrequesthandler/src/privacyandlocationrequesthandler.cpp	Fri May 14 17:16:36 2010 +0300
@@ -15,6 +15,12 @@
 
 #include <e32std.h>
 #include <e32property.h>
+#include <centralrepository.h>
+
+#ifdef SYMBIAN_FEATURE_MANAGER
+    #include <featdiscovery.h>
+    #include <featureuids.h>
+#endif
 
 // LBS-specific
 #include <lbs.h>
@@ -25,6 +31,8 @@
 #include "nrhpanic.h"
 #include "lbsdevloggermacros.h"
 #include "lbsqualityprofile.h"
+#include "lbsrootcenrepdefs.h"
+#include "lbspositioningstatusprops.h"
 
 #include "privacyandlocationrequesthandler.h"
 
@@ -93,6 +101,10 @@
 	
 	iFsmArray.ResetAndDestroy();
 
+    // force the count of active network initiated positioning sessions to 0
+	// this supports the pre-APE centric architecture wherein the NRH is
+	// destroyed on completion of network initiated positioning. 
+    RProperty::Set(iPosStatusCategory, KLbsNiPositioningStatusKey, 0);
 
 	delete iEmergencyFsm;
     delete iAgpsInterface;
@@ -161,6 +173,20 @@
 		}
 	LBSLOG2(ELogP3, "Using KLbsSpecialFeatureIntermediateFutileUpdate = %d", specialFeature);
 	iSpecialFeatureIntermediateFutileUpdate = (specialFeature == CLbsAdmin::ESpecialFeatureOn) ? ETrue : EFalse;
+	
+#ifdef SYMBIAN_FEATURE_MANAGER
+    iLocationManagementSupported = CFeatureDiscovery::IsFeatureSupportedL(NFeature::KLocationManagement);
+#else
+    __ASSERT_ALWAYS(EFalse, User::Invariant()); // Would happen on older versions of symbian OS if this code ever backported
+#endif    
+    
+    // Get the CategoryUid from the cenrep file owned by LbsRoot for accessing Positioning Status P&S Keys
+    CRepository* rep = CRepository::NewLC(KLbsCenRepUid);
+    TInt posStatusCategory;
+    err = rep->Get(KNiPositioningStatusAPIKey, posStatusCategory);
+    User::LeaveIfError(err);
+    CleanupStack::PopAndDestroy(rep);
+    iPosStatusCategory = TUid::Uid(posStatusCategory);
 	}
 
 
@@ -685,6 +711,36 @@
 	{
 	return iNetRegStatus;
 	}
+
+// increments the P&S key tracking mobile terminated positioning requests
+void CPrivacyAndLocationHandler::IncrementPositioningStatus()
+    {
+    TInt count;     
+    RProperty::Get(iPosStatusCategory, KLbsNiPositioningStatusKey, count);
+    RProperty::Set(iPosStatusCategory, KLbsNiPositioningStatusKey, count+1);
+    }
+
+// decrements the P&S key tracking mobile terminated positioning requests
+// if location management is supported. In the alternative architecture,
+// the NRH is not aware of the positioning session's progress, but is 
+// transient. Therefore the positioning status is set to zero in the 
+// class destructor.
+void CPrivacyAndLocationHandler::DecrementPositioningStatus()
+    {
+    if (iLocationManagementSupported)
+        {
+        TInt count;     
+        RProperty::Get(iPosStatusCategory, KLbsNiPositioningStatusKey, count);
+        if(count>0)
+            {
+            RProperty::Set(iPosStatusCategory, KLbsNiPositioningStatusKey, count-1);
+            }
+        else
+            {
+            LBSLOG_ERR(ELogP3, "CPrivacyAndLocationHandler::DecrementPositioningStatus() - Incorrect Positioning Status count\n");
+            }
+        }
+    }
 	
 
 /**
@@ -915,7 +971,7 @@
 	if(aSessionId == iFsm->SessionId())
 		{
 		iFsm->ExitData().SetExitData(TPrivLocStateExitData::EExitSessionComplete, aReason);
-		iFsm->ChangeState(CLbsPrivLocFsm::EStateIdle, aSessionId);	            
+		iFsm->ChangeState(CLbsPrivLocFsm::EStateIdle, aSessionId);
 		}		
 	}
 
@@ -1054,6 +1110,17 @@
 	return iFsm->PrivLocHandler().NetworkRegistrationStatus();
 	}
 
+/*
+ * increments the network initiated positioning status count
+ * and remembers that it has done
+ */
+void CLbsPrivLocStateBase::IncrementPositioningStatus()
+    {
+    iFsm->PrivLocHandler().IncrementPositioningStatus();
+    iFsm->WasPositioningStatusIncremented() = ETrue;
+    }
+
+
 // ----------------------------------------------------------------------------- 
 // 
 // ----------------------- Class CLbsPrivLocIdleState --------------------
@@ -1129,7 +1196,7 @@
         // The request relates to a rejected privacy request
         // or a request for this session which has already been answered. 
         // In either case, it should be refused. The message is sent to the
-        // network gateway as apart of exit from the state, but we want to 
+        // network gateway as a part of exit from the state, but we want to 
         // remain in Idle state.
         iFsm->ExitData().SetExitData(TPrivLocStateExitData::EExitCancelledByPrivacyController, KErrAccessDenied);
         iFsm->ChangeState(CLbsPrivLocFsm::EStateIdle, aSessionId);
@@ -1183,6 +1250,7 @@
 				const TLbsNetPosRequestPrivacyInt& aNetPosRequestPrivacy)
 	{
 	iFsm->SessionType() = aSessionType;
+	iFsm->ExternalRequestType() = aExternalRequestInfo.RequestType();
 	iFsm->ExitData().SetExitData(TPrivLocStateExitData::EExitPrivacyRequestReceived, KErrNone);
 	TPrivLocWaitPrivResponseParams privacyRequestParams(	aSessionId, 
 													aSessionType,
@@ -1292,7 +1360,7 @@
 					}
 				}		
 				
-			// For MtLrs the Protcol module should not
+			// For MtLrs the Protocol module should not
 			// send a REF position until after we have sent the Priv response to the PM 
 	            
 			// Inform network of the privacy response for normal privacy requests.
@@ -1366,6 +1434,13 @@
 			// Tell the AGPS handler that we are going to start a location request soon.
 			AgpsInterface()->PreStartPositioning(iFsm->SessionId(), iFsm->IsEmergency());
 			
+			// Set the Positioning Status for the UI indicator.
+			// Not done for silent requests.
+			if (iFsm->ExternalRequestType() < TLbsExternalRequestInfo::ERequestSingleShotSilent)
+			    {
+                IncrementPositioningStatus();
+			    }
+			
 			if(iFsm->LocReqReceived())
 				{				
 				TPrivLocWaitLocationUpdateParams updateRequestParams(iFsm->SessionId(),
@@ -2487,7 +2562,8 @@
 	iRefPosProcessed(EFalse),
 	iLocReqReceived(EFalse),
 	iReqCancelled(EFalse),
-	iWasPrivacyResponseReceivedStateExited(EFalse)
+	iWasPrivacyResponseReceivedStateExited(EFalse),
+	iPositioningStatusIncremented(EFalse)
 	{	
 	}
 	
@@ -2612,6 +2688,14 @@
 	{
 	LBSLOG3(ELogP3, "FSM(%d) OnSessionComplete reason=%d",iSessionId.SessionNum(),aReason);
 	iCurrentState->OnSessionComplete(aSessionId, aReason);
+	
+    // update the positioning status. Note this is updated only if it was previously
+    // incremented as a result of this session.
+    if (WasPositioningStatusIncremented())
+        {
+        PrivLocHandler().DecrementPositioningStatus();
+        WasPositioningStatusIncremented() = EFalse;
+        }
 	}
 
 // -----------------------------------------------------------------------------