locationmgmt/networklocationmgr/src/lbsnetlocmanlogic.cpp
changeset 0 9cfd9a3ee49c
equal deleted inserted replaced
-1:000000000000 0:9cfd9a3ee49c
       
     1 // Copyright (c) 2006-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 // Includes
       
    15 // System
       
    16 // 
       
    17 //
       
    18 
       
    19 #include <e32cons.h>
       
    20 
       
    21 // Lbs
       
    22 #include "lbsdevloggermacros.h"
       
    23 
       
    24 // Component
       
    25 #include "lbsnetlocmanlogic.h"
       
    26 
       
    27 
       
    28 //****************************************************************
       
    29 // Class CNetLocManLogic
       
    30 //****************************************************************
       
    31 /** Static constructor.
       
    32 @released
       
    33 @internalComponent
       
    34 */
       
    35 CNetLocManLogic* CNetLocManLogic::NewL()
       
    36 	{
       
    37 	
       
    38 	
       
    39 	CNetLocManLogic* self = new(ELeave) CNetLocManLogic;
       
    40 	CleanupStack::PushL(self);
       
    41 	self->ConstructL();
       
    42 	
       
    43 	CleanupStack::Pop(self);
       
    44 	return self;
       
    45 	};
       
    46 
       
    47 
       
    48 /** Constructor.
       
    49 @released
       
    50 @internalComponent
       
    51 */
       
    52 CNetLocManLogic::CNetLocManLogic()
       
    53 	{
       
    54 	}
       
    55 
       
    56 
       
    57 /** Second phase constructor.
       
    58 @released
       
    59 @internalComponent
       
    60 */
       
    61 void CNetLocManLogic::ConstructL()
       
    62 	{
       
    63 	
       
    64 	
       
    65 	iCurrentId.SetSessionOwner(KLbsNetLocManagerUid);
       
    66 	iCurrentId.SetSessionNum(0);
       
    67 	
       
    68 	// create the monitor to handle the close down request signal from root process
       
    69 	iCloseDownRequestDetector = CLbsCloseDownRequestDetector::NewL(this, KLbsNetLocManagerUid);
       
    70 	
       
    71 	// open the property for position update and module status
       
    72 	iPositionUpdates.OpenL(KLbsNetLocManagerUid);
       
    73 
       
    74 	// Set the initial device status, network location manager can only be EDeviceReady or EDeviceActive
       
    75 	iModuleStatus.OpenL(KLbsNetLocManagerUid);
       
    76 	iPreviousReportedModuleStatus.SetDeviceStatus(TPositionModuleStatus::EDeviceReady);
       
    77 	iPreviousReportedModuleStatus.SetDataQualityStatus(TPositionModuleStatus::EDataQualityNormal);
       
    78 	TPositionModuleStatusEventBase::TModuleEvent occurredEventsSinceLastSet = 
       
    79 		TPositionModuleStatusEventBase::EEventDeviceStatus | TPositionModuleStatusEventBase::EEventDataQualityStatus;
       
    80 	iModuleStatus.SetModuleStatus(&iPreviousReportedModuleStatus,sizeof(iPreviousReportedModuleStatus),occurredEventsSinceLastSet);
       
    81 
       
    82 	const RLbsPositionUpdateRequests::TChannelIdentifer KChannelIdentifierLS = 
       
    83 		{
       
    84 			{KLbsNetLocManagerUidValue},{KLbsLocServerUidValue}
       
    85 		};
       
    86 
       
    87 	// create netloc request handler and start the active object
       
    88 	iLocSvrLocationRequestHandler = CNetLocManRequestHandler::NewL(KChannelIdentifierLS, *this); 
       
    89 	iLocSvrLocationRequestHandler->StartGettingRequests();
       
    90 
       
    91 	// create netloc response handler and start the active object
       
    92 	iNetLocationResponseHandler = CNetLocManResponseHandler::NewL(*this); 
       
    93 	iNetLocationResponseHandler->StartGettingRequests();
       
    94 	}
       
    95 
       
    96 
       
    97 /** Destructor.
       
    98 @released
       
    99 @internalComponent
       
   100 */
       
   101 CNetLocManLogic::~CNetLocManLogic()
       
   102 	{
       
   103 	
       
   104 	delete iNetLocationResponseHandler;
       
   105 	iNetLocationResponseHandler = NULL;
       
   106 	
       
   107 	delete iLocSvrLocationRequestHandler;
       
   108 	iLocSvrLocationRequestHandler = NULL;
       
   109 
       
   110 	delete iCloseDownRequestDetector;
       
   111 	iCloseDownRequestDetector = NULL;
       
   112 	}
       
   113 
       
   114 
       
   115 
       
   116 /** Process version
       
   117 @released
       
   118 @internalComponent
       
   119 */
       
   120 TVersion CNetLocManLogic::Version()
       
   121 	{
       
   122 	return TVersion(1,0,0);
       
   123 	}
       
   124 
       
   125 
       
   126 /** Retrieve the current session id for the component
       
   127 @param aSessionId A session id to return current id through
       
   128 @released
       
   129 @internalComponent
       
   130 */
       
   131 void CNetLocManLogic::GetSessionId(TLbsNetSessionIdInt& aSessionId)
       
   132 	{
       
   133 	aSessionId = iCurrentId;
       
   134 	}
       
   135 
       
   136 
       
   137 /** Increment the current session
       
   138 @released
       
   139 @internalComponent
       
   140 */
       
   141 void CNetLocManLogic::IncrementSessionId()
       
   142 	{
       
   143 	iCurrentId.IncrSession();
       
   144 	}
       
   145 	
       
   146 	
       
   147 /** Publish a position on the position request bus
       
   148 This function is called from the response handler when it has
       
   149 received a response from the NetworkGateway. If aStatus is different
       
   150 from KErrNone an error has ocurred and the NetworkGateway has not
       
   151 a valid position to the response handler and the information passed
       
   152 in the other parameters is therefore disregarded. In any other case
       
   153 the position info received is published.
       
   154 @param aStatus An errorcode
       
   155 @param aPosInfoArray A position array
       
   156 @param aTargetTime The position target time
       
   157 @see CNetLocManResponseHandler::RunL
       
   158 @released
       
   159 @internalComponent
       
   160 */
       
   161 void CNetLocManLogic::UpdateLocation(TInt aStatus, TPositionInfoBase& aPosition, 
       
   162 										 const TTime& aTargetTime)
       
   163 	{
       
   164 	// Module Id and update type
       
   165 	TPositionModuleId id = {KLbsNetLocManagerUidValue};
       
   166 	TPositionModuleInfo::TTechnologyType type = TPositionModuleInfo::ETechnologyNetwork;
       
   167 	
       
   168 	aPosition.SetModuleId(id);
       
   169 	aPosition.SetUpdateType(EPositionUpdateGeneral);
       
   170 	aPosition.SetPositionMode(type);
       
   171 	aPosition.SetPositionModeReason(EPositionModeReasonNone);
       
   172 
       
   173 	TInt size = aPosition.PositionClassSize();
       
   174 	if ((aStatus == KErrServerBusy) || (aStatus == KErrPositionHighPriorityReceive))
       
   175 		{
       
   176 		iPositionUpdates.SetPositionInfo(aStatus, ETrue, &aPosition,size,0, 0);
       
   177 		}
       
   178 	else if (aStatus != KErrNone)
       
   179 		{
       
   180 		iPositionUpdates.SetPositionInfo(aStatus, EFalse, &aPosition,size,0, 0);		
       
   181 		}
       
   182 	
       
   183 	else
       
   184 		{ 
       
   185 		TTime timeNow;
       
   186 		timeNow.UniversalTime();
       
   187 
       
   188 		// always publish new update regardless
       
   189 		TInt size = aPosition.PositionClassSize();
       
   190 		iPositionUpdates.SetPositionInfo(aStatus, EFalse, &aPosition,size,aTargetTime, timeNow);
       
   191 		}
       
   192 	// Request has been dealt with... We can say we're 'ready' again.
       
   193 	UpdateDeviceStatus(TPositionModuleStatus::EDeviceReady);
       
   194 	}
       
   195 
       
   196 
       
   197 /** Process close down callback
       
   198 @see MLbsCloseDownObserver
       
   199 @released
       
   200 @internalComponent
       
   201 */
       
   202 void CNetLocManLogic::OnProcessCloseDown()
       
   203 	{
       
   204 	iLocSvrLocationRequestHandler->Cancel();
       
   205 	iNetLocationResponseHandler->Cancel();
       
   206 	CActiveScheduler::Stop();
       
   207 	}
       
   208 	
       
   209 void CNetLocManLogic::UpdateDeviceStatus(TPositionModuleStatus::TDeviceStatus aDeviceStatus)
       
   210 	{
       
   211 	iPreviousReportedModuleStatus.SetDeviceStatus(aDeviceStatus);
       
   212 	TPositionModuleStatusEventBase::TModuleEvent occurredEventsSinceLastSet = 
       
   213 		TPositionModuleStatusEventBase::EEventDeviceStatus;
       
   214 	iModuleStatus.SetModuleStatus(&iPreviousReportedModuleStatus,sizeof(TPositionModuleStatus),occurredEventsSinceLastSet);
       
   215 	}
       
   216