locationmgmt/networklocationmgr/src/lbsnetlocmanresponsehandler.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 // Component
       
    16 // 
       
    17 //
       
    18 
       
    19 #include "lbsnetlocmanresponsehandler.h"
       
    20 #include "lbsnetlocmanlogic.h"
       
    21 #include "lbsdevloggermacros.h"
       
    22 #include "LbsNetworkLocateLogEvent.h"
       
    23 
       
    24 
       
    25 const TInt KLbsLogQueueSize = 10;
       
    26 
       
    27 //****************************************************************
       
    28 // Class CNetLocManResponseHandler
       
    29 //****************************************************************
       
    30 /** Static constructor.
       
    31 @param aNetLocMan A reference to the parent class
       
    32 @released
       
    33 @internalComponent
       
    34 */
       
    35 CNetLocManResponseHandler* CNetLocManResponseHandler::NewL(CNetLocManLogic& aNetLocMan)
       
    36 	{
       
    37 	CNetLocManResponseHandler* self = new(ELeave) CNetLocManResponseHandler (aNetLocMan);
       
    38 
       
    39 	CleanupStack::PushL(self);
       
    40 
       
    41 	self->ConstructL();
       
    42 	CleanupStack::Pop();
       
    43 
       
    44 	return self;
       
    45 	}
       
    46 	
       
    47 	
       
    48 /** Constructor.
       
    49 @param aNetLocMan A reference to the parent class
       
    50 @released
       
    51 @internalComponent
       
    52 */
       
    53 CNetLocManResponseHandler::CNetLocManResponseHandler(CNetLocManLogic& aNetLocMan) : 
       
    54 CActive(CActive::EPriorityStandard), iNetLocMan(aNetLocMan)
       
    55 	{
       
    56 
       
    57 	}
       
    58 
       
    59 
       
    60 /** 
       
    61 @see CActive::DoCancel
       
    62 @released
       
    63 @internalComponent
       
    64 */
       
    65 void CNetLocManResponseHandler::DoCancel()
       
    66 	{
       
    67 // cancel async request
       
    68 iPositionUpdate.CancelNotifyNetworkLocationUpdate();
       
    69 iCompletionHandler->Cancel();
       
    70 	}
       
    71 
       
    72 
       
    73 /** Second phase constructor.
       
    74 @released
       
    75 @internalComponent
       
    76 */
       
    77 void CNetLocManResponseHandler::ConstructL()
       
    78 	{
       
    79 	iPositionUpdate.OpenL(RLbsNetworkPositionUpdates::ENetworkPositionReference);
       
    80 iCompletionHandler = CNetLocManCompletionHandler::NewL(this);
       
    81 	
       
    82 	iLogger.Open(KLbsLogQueueSize);
       
    83 	
       
    84 	CActiveScheduler::Add(this);
       
    85 	}
       
    86 
       
    87 
       
    88 /** Destructor
       
    89 @released
       
    90 @internalComponent
       
    91 */
       
    92 CNetLocManResponseHandler::~CNetLocManResponseHandler()
       
    93 	{
       
    94 	Cancel();
       
    95 delete iCompletionHandler;
       
    96 	iPositionUpdate.Close();
       
    97 	iLogger.Close();
       
    98 	}
       
    99  
       
   100 
       
   101 /** 
       
   102 @see CActive::RunError
       
   103 @param aError An error code
       
   104 @released
       
   105 @internalComponent
       
   106 */
       
   107 TInt CNetLocManResponseHandler::RunError(TInt aError)
       
   108 	{
       
   109 	// handle RunL leaving - in our case we do nothing 
       
   110 	// as this means we have had encountered a program inconsistency
       
   111 	// By doing nothing here  causes the main manager thread to exit
       
   112 	// and the Lbs root process resolves any issues - by stopping and restarting
       
   113 	// lbs components
       
   114  	return aError;
       
   115 	}	
       
   116 
       
   117 
       
   118 /** Subscribe to the location update response property
       
   119 @released
       
   120 @internalComponent
       
   121 */
       
   122 void CNetLocManResponseHandler::StartGettingRequests()
       
   123 	{
       
   124 	LBSLOG(ELogP2, "CNetLocManResponseHandler::StartGettingRequests:");
       
   125 	Cancel();
       
   126 	// subscribe to property from Network Gateway -> Network Location Manager
       
   127 	iPositionUpdate.NotifyNetworkLocationUpdate(iStatus);
       
   128 	SetActive();	
       
   129 	}
       
   130 
       
   131 void CNetLocManResponseHandler::OnSessionComplete(TInt aStatus, 
       
   132 							const TLbsNetSessionIdInt& aSessionId)
       
   133 	{
       
   134 	TLbsNetSessionIdInt sessionIdRequ;
       
   135 	iNetLocMan.GetSessionId(sessionIdRequ);
       
   136 	// Only action it if it relates to the current session Id
       
   137 	if(aSessionId == sessionIdRequ)
       
   138 		{
       
   139 		// The position info is probably unnecessary (it's eitehr invalid or the 
       
   140 		// client already has it), but pass it on anyway in case the client
       
   141 		// is interested.
       
   142 		TPositionCourseInfo posInfo;
       
   143 		TTime targetTime;
       
   144 		TTime actualTime;
       
   145 		TLbsNetSessionIdInt sessionId;
       
   146 		iPositionUpdate.GetPositionInfo(sessionId, posInfo, targetTime, actualTime);
       
   147 	
       
   148 		ReportPosUpdate(aStatus, aSessionId.SessionOwner(), posInfo, 0);
       
   149 		}
       
   150 	}
       
   151 
       
   152 void CNetLocManResponseHandler::ReportPosUpdate(TInt aStatus, TUid aSessionOwner, 
       
   153 											TPositionInfo& aPosInfo, TTime aTargetTime)
       
   154 	{
       
   155 	/** LBSLOGGER - Start Logging */
       
   156 	// -------------------------------------------------------------------------
       
   157 	CLbsNetworkLocateLogEvent* event = NULL;
       
   158 	TRAPD(logErr, event = CLbsNetworkLocateLogEvent::NewL(aSessionOwner, NULL));
       
   159 	if (logErr == KErrNone)
       
   160 		{
       
   161 		event->SetPositionInfo(&aPosInfo);
       
   162 		// -------------------------------------------------------------------------
       
   163 		if (KErrNone == aStatus)
       
   164 			{
       
   165 			event->SetRequestOutcome(ELbsRequestOutcomeSuccess);
       
   166 			}
       
   167 		else
       
   168 			{
       
   169 			event->SetRequestOutcome(ELbsRequestOutcomeFail);
       
   170 			}
       
   171 		iLogger.AddEvent(*event);
       
   172 		delete event;
       
   173 		}
       
   174 		// -------------------------------------------------------------------------
       
   175 		/** LBSLOGGER - End Logging */
       
   176 
       
   177 		// deliver location info to NetLocManager
       
   178 		LBSLOG(ELogP2, "CNetLocManResponseHandler::ReportPosUpdate: passing position update to Net Loc Manager");
       
   179 		iNetLocMan.UpdateLocation(aStatus, aPosInfo, aTargetTime);
       
   180 
       
   181 	}
       
   182 
       
   183 /** Handle responses from the NetworkGateway
       
   184 This function handles the incomming location responses from the
       
   185 NetworkGateway, and pass them on to the LocServer, provided that
       
   186 the session id match.
       
   187 @see CActive::RunL
       
   188 @released
       
   189 @internalComponent
       
   190 */
       
   191 void CNetLocManResponseHandler::RunL()
       
   192 	{
       
   193 	TInt status = iStatus.Int();
       
   194 	TPositionCourseInfo posInfo;
       
   195 
       
   196 	switch (status)
       
   197 		{
       
   198 		case KErrNone:
       
   199 			{
       
   200 
       
   201 			TLbsNetSessionIdInt sessionIdRequ;
       
   202 			iNetLocMan.GetSessionId(sessionIdRequ);
       
   203 			StartGettingRequests();			
       
   204 			
       
   205 			TTime targetTime;
       
   206 			TTime actualTime;
       
   207 			TLbsNetSessionIdInt sessionId;
       
   208 			TInt error = iPositionUpdate.GetPositionInfo(sessionId, posInfo, targetTime, actualTime);
       
   209 
       
   210 			LBSLOG3(ELogP2, "CNetLocManResponseHandler::RunL() Sessionid %d, %d", sessionId, sessionIdRequ);
       
   211 			// Only pass on the update if it relates to a request issued through 
       
   212 			// the Net Loc Manager
       
   213 			if(sessionId == sessionIdRequ)
       
   214 				{
       
   215 				ReportPosUpdate(error, sessionId.SessionOwner(), posInfo, targetTime);
       
   216 				}
       
   217 			break;
       
   218 			}
       
   219 		default:
       
   220 			{
       
   221 			User::LeaveIfError(status);
       
   222 			break;
       
   223 			}
       
   224 		}
       
   225 	}