networkprotocolmodules/networkprotocolmodule/LbsProtocolModule/src/cnetlocstatehandler.cpp
changeset 36 b47902b73a93
parent 0 9cfd9a3ee49c
equal deleted inserted replaced
35:a2efdd544abf 36:b47902b73a93
       
     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 // This file provides the implementation of the class for
       
    15 // the Network Based Location protocol state handler
       
    16 // 
       
    17 //
       
    18 
       
    19 /**
       
    20  @file
       
    21  @internalTechnology
       
    22  @released
       
    23 */
       
    24 
       
    25 #include "cnetlocstatemachine.h"
       
    26 #include "cnetlocstatehandler.h"
       
    27 #include "lbsdevloggermacros.h"
       
    28 
       
    29 /** Static constructor.
       
    30 @param aMachine A reference to the parent state machine.
       
    31 @return A new instance of the CNetLocStateHandler class
       
    32 */  
       
    33 CNetLocStateHandler* CNetLocStateHandler::NewL(CStateMachineBase& aMachine)
       
    34 	{
       
    35 	CNetLocStateHandler* self = new (ELeave) CNetLocStateHandler(aMachine);
       
    36 	CleanupStack::PushL(self);
       
    37 	self->ConstructL();
       
    38 	CleanupStack::Pop(self);
       
    39 	return self;
       
    40 	}
       
    41 
       
    42 
       
    43 /** Standard constructor.
       
    44 @param aMachine A reference to the parent state machine.
       
    45 */  
       
    46 CNetLocStateHandler::CNetLocStateHandler(CStateMachineBase& aMachine)
       
    47 : CStateHandlerBase(aMachine)
       
    48 	{
       
    49 	}
       
    50 
       
    51 
       
    52 /** Standard destructor.
       
    53 */  
       
    54 CNetLocStateHandler::~CNetLocStateHandler()
       
    55 	{
       
    56 	}
       
    57 
       
    58 
       
    59 /** Private second-stage constructor.
       
    60 */  
       
    61 void CNetLocStateHandler::ConstructL()
       
    62 	{
       
    63 	}
       
    64 
       
    65 
       
    66 /** Initialise state attributes
       
    67 */
       
    68 void CNetLocStateHandler::Initialise()
       
    69 	{
       
    70 	}
       
    71 
       
    72 	
       
    73 /** Perform entry actions.
       
    74 This is called from the state machine to perform any actions
       
    75 associated with entering the current state.
       
    76 */  
       
    77 void CNetLocStateHandler::EntryActions()
       
    78 	{
       
    79 	CNetworkInterface::TNetworkError netError = CNetworkInterface::ENone;
       
    80 
       
    81 	// Retrieve current state and act accordingly
       
    82 	CNetLocStateMachine& netlocMachine = reinterpret_cast <CNetLocStateMachine&> (iMachine);
       
    83 	switch(netlocMachine.CurrentState())
       
    84 		{
       
    85 
       
    86 	case CNetLocStateMachine::EStateNull:
       
    87 		break;
       
    88 
       
    89 	case CNetLocStateMachine::EStateClientReqRecvd:
       
    90 		// No action required
       
    91 		break;
       
    92 
       
    93 	case CNetLocStateMachine::EStateNetSessStarted:
       
    94 		// Forward Network Based Location request to network
       
    95 		netError = netlocMachine.Observer().Network()->MoLrReq(KNullDesC());
       
    96 		// If this succeeded then start a timer for the anticipated response
       
    97 		if (CNetworkInterface::ENone == netError)
       
    98 			{
       
    99 			netlocMachine.StartNetLocReqTimer();
       
   100 			}
       
   101 		break;
       
   102 
       
   103 	case CNetLocStateMachine::EStateMeasureDataRecvd:
       
   104 		// No action required
       
   105 		break;
       
   106 
       
   107 	case CNetLocStateMachine::EStateNetBasedLocSent:
       
   108 		// Send network location to gateway
       
   109 		netlocMachine.Observer().Gateway()->NetworkLocationInd(
       
   110 							netlocMachine.SessionId(),
       
   111 							netlocMachine.ReferenceLoc());
       
   112 		break;
       
   113 
       
   114 	case CNetLocStateMachine::EStateLocReqByNet:
       
   115 		// Send location request to gateway
       
   116 		netlocMachine.Observer().Gateway()->LocationReq(
       
   117 							netlocMachine.SessionId(),
       
   118 							EFalse, // this is NOT emergency related
       
   119 							netlocMachine.LocReqType(),
       
   120 							netlocMachine.LocReqQuality(),
       
   121 							netlocMachine.PosMethod());
       
   122 		// Start a timer for the anticipated response
       
   123 		netlocMachine.StartLocRespTimer();
       
   124 		break;
       
   125 
       
   126 	case CNetLocStateMachine::EStateLocRespRecvd:
       
   127 		// No action required
       
   128 		break;
       
   129 
       
   130 	case CNetLocStateMachine::EStateLocSentToNet:
       
   131 		// Forward location response to network - but not if an error was reported
       
   132 		if (KErrNone == netlocMachine.LocRespReason())
       
   133 			{
       
   134 			netError = netlocMachine.Observer().Network()->LocationResp(netlocMachine.LocRespPosition());
       
   135 			}
       
   136 		break;
       
   137 
       
   138 	case CNetLocStateMachine::EStateClientSessToClose:
       
   139 		// No action required
       
   140 		break;
       
   141 
       
   142 	case CNetLocStateMachine::EStateNetSessToClose:
       
   143 		// If we had received a location request, but an error was reported then
       
   144 		// forward this location error to the network
       
   145 		if (netlocMachine.IsLocReqReceived() && (KErrNone != netlocMachine.LocRespReason()))
       
   146 			{
       
   147 			netError = netlocMachine.Observer().Network()->LocationResp(netlocMachine.LocRespReason());
       
   148 			}
       
   149 		break;
       
   150 
       
   151 	case CNetLocStateMachine::EStateSessionsClosed:
       
   152 		// No action required
       
   153 		break;
       
   154 
       
   155 	case CNetLocStateMachine::EStateCancelling:
       
   156 		// No action required
       
   157 		break;
       
   158 
       
   159 	default:
       
   160 		User::Panic(KProtocolModulePanic, EProtocolModuleNetLocState);
       
   161 		break;
       
   162 		}
       
   163 
       
   164 	// Handle any network-related error
       
   165 	if (CNetworkInterface::ENone != netError)
       
   166 		{
       
   167 		netlocMachine.Observer().NetworkErrorReported();
       
   168 		}
       
   169 
       
   170 	}
       
   171 	
       
   172 	
       
   173 /** Perform exit actions.
       
   174 This is called from the state machine to perform any actions
       
   175 associated with exiting from the current state.
       
   176 */  
       
   177 void CNetLocStateHandler::ExitActions()
       
   178 	{
       
   179 	CNetworkInterface::TNetworkError netError = CNetworkInterface::ENone;
       
   180 
       
   181 	// Retrieve current state and act accordingly
       
   182 	CNetLocStateMachine& netlocMachine = reinterpret_cast <CNetLocStateMachine&> (iMachine);
       
   183 	switch(netlocMachine.CurrentState())
       
   184 		{
       
   185 
       
   186 	case CNetLocStateMachine::EStateNull:
       
   187 		// no action required
       
   188 		break;
       
   189 
       
   190 	case CNetLocStateMachine::EStateClientReqRecvd:
       
   191 		// no action required
       
   192 		break;
       
   193 
       
   194 	case CNetLocStateMachine::EStateNetSessStarted:
       
   195 		// no action required
       
   196 		break;
       
   197 
       
   198 	case CNetLocStateMachine::EStateMeasureDataRecvd:
       
   199 		// no action required
       
   200 		break;
       
   201 
       
   202 	case CNetLocStateMachine::EStateNetBasedLocSent:
       
   203 		// no action required
       
   204 		break;
       
   205 
       
   206 	case CNetLocStateMachine::EStateLocReqByNet:
       
   207 		// no action required
       
   208 		break;
       
   209 
       
   210 	case CNetLocStateMachine::EStateLocRespRecvd:
       
   211 		// no action required
       
   212 		break;
       
   213 
       
   214 	case CNetLocStateMachine::EStateLocSentToNet:
       
   215 		// no action required
       
   216 		break;
       
   217 
       
   218 	case CNetLocStateMachine::EStateClientSessToClose:
       
   219 		// Send a session completion to the gateway
       
   220 		LBSLOG(ELogP2, "CNetLocStateHandler::ExitActions() Completing Session \n");
       
   221 		netlocMachine.Observer().Gateway()->SessionCompleteInd(
       
   222 							netlocMachine.SessionId(),netlocMachine.ClientCloseReason());
       
   223 		break;
       
   224 
       
   225 	case CNetLocStateMachine::EStateNetSessToClose:
       
   226 		// Forward session completion to network if network is okay
       
   227 		if (!netlocMachine.IsNetworkConnectionError())
       
   228 			{
       
   229 			netError = netlocMachine.Observer().Network()->MoLrCompleteInd(netlocMachine.NetworkCloseReason());
       
   230 			}
       
   231 		break;
       
   232 
       
   233 	case CNetLocStateMachine::EStateSessionsClosed:
       
   234 		// no action required
       
   235 		break;
       
   236 
       
   237 	case CNetLocStateMachine::EStateCancelling:
       
   238 		// no action required
       
   239 		break;
       
   240 
       
   241 	default:
       
   242 		User::Panic(KProtocolModulePanic, EProtocolModuleNetLocState);
       
   243 		break;
       
   244 		}
       
   245 
       
   246 	// Handle any network-related error
       
   247 	if (CNetworkInterface::ENone != netError)
       
   248 		{
       
   249 		netlocMachine.Observer().NetworkErrorReported();
       
   250 		}
       
   251 
       
   252 	}
       
   253 
       
   254