networkprotocolmodules/networkprotocolmodule/LbsProtocolModule/src/cmtlrstatehandler.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 // This file provides the implementation of the class for
       
    15 // the MT-LR protocol state handler
       
    16 // 
       
    17 //
       
    18 
       
    19 /**
       
    20  @file
       
    21  @internalTechnology
       
    22  @released
       
    23 */
       
    24 
       
    25 #include "cmtlrstatemachine.h"
       
    26 #include "cmtlrstatehandler.h"
       
    27 
       
    28 
       
    29 /** Static constructor.
       
    30 @param aMachine A reference to the parent state machine.
       
    31 @return A new instance of the CMtLrStateHandler class
       
    32 */  
       
    33 CMtLrStateHandler* CMtLrStateHandler::NewL(CStateMachineBase& aMachine)
       
    34 	{
       
    35 	CMtLrStateHandler* self = new (ELeave) CMtLrStateHandler(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 CMtLrStateHandler::CMtLrStateHandler(CStateMachineBase& aMachine)
       
    47 : CStateHandlerBase(aMachine)
       
    48 	{
       
    49 	}
       
    50 
       
    51 
       
    52 /** Standard destructor.
       
    53 */  
       
    54 CMtLrStateHandler::~CMtLrStateHandler()
       
    55 	{
       
    56 	}
       
    57 
       
    58 
       
    59 /** Private second-stage constructor.
       
    60 */  
       
    61 void CMtLrStateHandler::ConstructL()
       
    62 	{
       
    63 	}
       
    64 
       
    65 
       
    66 /** Initialise state attributes
       
    67 */
       
    68 void CMtLrStateHandler::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 CMtLrStateHandler::EntryActions()
       
    78 	{
       
    79 	CNetworkInterface::TNetworkError netError = CNetworkInterface::ENone;
       
    80 
       
    81 	// Retrieve current state and act accordingly
       
    82 	CMtLrStateMachine& mtlrMachine = reinterpret_cast <CMtLrStateMachine&> (iMachine);
       
    83 	switch(mtlrMachine.CurrentState())
       
    84 		{
       
    85 
       
    86 	case CMtLrStateMachine::EStateNull:
       
    87 		// No action required
       
    88 		break;
       
    89 
       
    90 	case CMtLrStateMachine::EStateNetReqRecvd:
       
    91 		// No action required
       
    92 		break;
       
    93 
       
    94 	case CMtLrStateMachine::EStatePrivacySessStarted:
       
    95 		// Forward request to gateway
       
    96 		mtlrMachine.Observer().Gateway()->PrivacyReq(
       
    97 										mtlrMachine.SessionId(),
       
    98 										mtlrMachine.IsEmergency(),
       
    99 										mtlrMachine.PrivacyReq(),
       
   100 										mtlrMachine.PrivacyReqInfo());
       
   101 		break;
       
   102 
       
   103 	case CMtLrStateMachine::EStatePrivacyRespRecvd:
       
   104 		// Forward response to network
       
   105 		mtlrMachine.Observer().Network()->MtLrResp(mtlrMachine.PrivacyResponseValue());
       
   106 		break;
       
   107 
       
   108 	case CMtLrStateMachine::EStatePrivacyRespRecvdAfterMeasure:
       
   109 		// Forward response to network
       
   110 		mtlrMachine.Observer().Network()->MtLrResp(mtlrMachine.PrivacyResponseValue());
       
   111 		break;
       
   112 
       
   113 	case CMtLrStateMachine::EStatePrivacyReject:
       
   114 		// no action required
       
   115 		break;
       
   116 
       
   117 	case CMtLrStateMachine::EStatePrivacyRejectAfterMeasure:
       
   118 		// no action required
       
   119 		break;
       
   120 
       
   121 	case CMtLrStateMachine::EStateMeasureDataRecvd:
       
   122 		// No action required
       
   123 		break;
       
   124 
       
   125 	case CMtLrStateMachine::EStateNetBasedLocSent:
       
   126 		// Send network location to gateway
       
   127 		mtlrMachine.Observer().Gateway()->NetworkLocationInd(
       
   128 							mtlrMachine.SessionId(),
       
   129 							mtlrMachine.ReferenceLoc());
       
   130 		break;
       
   131 
       
   132 	case CMtLrStateMachine::EStateLocReqByNet:
       
   133 		// Send location request to gateway
       
   134 		mtlrMachine.Observer().Gateway()->LocationReq(
       
   135 							mtlrMachine.SessionId(),
       
   136 							mtlrMachine.IsEmergency(),
       
   137 							mtlrMachine.LocReqType(),
       
   138 							mtlrMachine.LocReqQuality(),
       
   139 							mtlrMachine.PosMethod());
       
   140 		// Start a timer for the anticipated response
       
   141 		mtlrMachine.StartLocRespTimer();
       
   142 		break;
       
   143 
       
   144 	case CMtLrStateMachine::EStateLocRespRecvd:
       
   145 		// No action required
       
   146 		break;
       
   147 
       
   148 	case CMtLrStateMachine::EStateLocSentToNet:
       
   149 		// If a location response does not indicate an error then forward it to network
       
   150 		if (KErrNone == mtlrMachine.LocRespReason())
       
   151 			{
       
   152 			netError = mtlrMachine.Observer().Network()->LocationResp(mtlrMachine.LocRespPosition());
       
   153 			}
       
   154 		break;
       
   155 
       
   156 	case CMtLrStateMachine::EStateClientSessToCloseWaitMeasure:
       
   157 		// Send session completion data to gateway
       
   158 		mtlrMachine.Observer().Gateway()->SessionCompleteInd(mtlrMachine.SessionId(), 
       
   159 															mtlrMachine.ClientCloseReason());
       
   160 		break;
       
   161 
       
   162 	case CMtLrStateMachine::EStateClientSessToCloseAfterMeasure:
       
   163 		// Send session completion data to gateway
       
   164 		mtlrMachine.Observer().Gateway()->SessionCompleteInd(mtlrMachine.SessionId(), 
       
   165 															mtlrMachine.ClientCloseReason());
       
   166 		break;
       
   167 
       
   168 	case CMtLrStateMachine::EStateClientSessToCloseWaitLocResp:
       
   169 		// Send session completion data to gateway
       
   170 		mtlrMachine.Observer().Gateway()->SessionCompleteInd(mtlrMachine.SessionId(), 
       
   171 															mtlrMachine.ClientCloseReason());
       
   172 		break;
       
   173 
       
   174 	case CMtLrStateMachine::EStateSessionsClosed:
       
   175 		// If a location response error has been reported then forward it to network
       
   176 		if (KErrNone != mtlrMachine.LocRespReason())
       
   177 			{
       
   178 			netError = mtlrMachine.Observer().Network()->LocationResp(mtlrMachine.LocRespReason());
       
   179 			}
       
   180 		break;
       
   181 
       
   182 	case CMtLrStateMachine::EStateCancelling:
       
   183 		// Is privacy response handled yet?
       
   184 		if (!mtlrMachine.IsPrivacyResponseHandled())
       
   185 			{
       
   186 			mtlrMachine.Observer().Network()->MtLrResp(mtlrMachine.PrivacyResponseValue());
       
   187 			}
       
   188 		break;
       
   189 
       
   190 	default:
       
   191 		User::Panic(KProtocolModulePanic, EProtocolModuleMtLrState);
       
   192 		break;
       
   193 		}
       
   194 
       
   195 	// Handle network-related error
       
   196 	if (CNetworkInterface::ENone != netError)
       
   197 		{
       
   198 		mtlrMachine.Observer().NetworkErrorReported();
       
   199 		}
       
   200 
       
   201 	}
       
   202 	
       
   203 	
       
   204 /** Perform exit actions.
       
   205 This is called from the state machine to perform any actions
       
   206 associated with exiting from the current state.
       
   207 */  
       
   208 void CMtLrStateHandler::ExitActions()
       
   209 	{
       
   210 	CNetworkInterface::TNetworkError netError = CNetworkInterface::ENone;
       
   211 
       
   212 	// Retrieve current state and act accordingly
       
   213 	CMtLrStateMachine& mtlrMachine = reinterpret_cast <CMtLrStateMachine&> (iMachine);
       
   214 	switch(mtlrMachine.CurrentState())
       
   215 		{
       
   216 
       
   217 	case CMtLrStateMachine::EStateNull:
       
   218 		// no action required
       
   219 		break;
       
   220 
       
   221 	case CMtLrStateMachine::EStateNetReqRecvd:
       
   222 		// no action required
       
   223 		break;
       
   224 
       
   225 	case CMtLrStateMachine::EStatePrivacySessStarted:
       
   226 		break;
       
   227 
       
   228 	case CMtLrStateMachine::EStatePrivacyRespRecvd:
       
   229 		// no action required
       
   230 		break;
       
   231 
       
   232 	case CMtLrStateMachine::EStatePrivacyRespRecvdAfterMeasure:
       
   233 		// no action required
       
   234 		break;
       
   235 
       
   236 	case CMtLrStateMachine::EStatePrivacyReject:
       
   237 		// no action required
       
   238 		break;
       
   239 
       
   240 	case CMtLrStateMachine::EStatePrivacyRejectAfterMeasure:
       
   241 		// no action required
       
   242 		break;
       
   243 
       
   244 	case CMtLrStateMachine::EStateMeasureDataRecvd:
       
   245 		// no action required
       
   246 		break;
       
   247 
       
   248 	case CMtLrStateMachine::EStateNetBasedLocSent:
       
   249 		// no action required
       
   250 		break;
       
   251 
       
   252 	case CMtLrStateMachine::EStateLocReqByNet:
       
   253 		// no action required
       
   254 		break;
       
   255 
       
   256 	case CMtLrStateMachine::EStateLocRespRecvd:
       
   257 		// no action required
       
   258 		break;
       
   259 
       
   260 	case CMtLrStateMachine::EStateLocSentToNet:
       
   261 		// no action required
       
   262 		break;
       
   263 
       
   264 	case CMtLrStateMachine::EStateClientSessToCloseWaitMeasure:
       
   265 		// no action required
       
   266 		break;
       
   267 
       
   268 	case CMtLrStateMachine::EStateClientSessToCloseAfterMeasure:
       
   269 		// no action required
       
   270 		break;
       
   271 
       
   272 	case CMtLrStateMachine::EStateClientSessToCloseWaitLocResp:
       
   273 		// no action required
       
   274 		break;
       
   275 
       
   276 	case CMtLrStateMachine::EStateSessionsClosed:
       
   277 		// no action required
       
   278 		break;
       
   279 
       
   280 	case CMtLrStateMachine::EStateCancelling:
       
   281 		// no action required
       
   282 		break;
       
   283 
       
   284 	default:
       
   285 		User::Panic(KProtocolModulePanic, EProtocolModuleMtLrState);
       
   286 		break;
       
   287 		}
       
   288 
       
   289 	// Handle network-related error
       
   290 	// this function is stubbed for future expansion
       
   291 	// coverity [dead_error_condition]
       
   292 	if (CNetworkInterface::ENone != netError)
       
   293 		{
       
   294 		// coverity [dead_error_line]
       
   295 		mtlrMachine.Observer().NetworkErrorReported();
       
   296 		}
       
   297 
       
   298 
       
   299 	}
       
   300 
       
   301