networkprotocolmodules/networkprotocolmodule/LbsProtocolModule/inc/cx3pstatemachine.h
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 defines the class for the X3P protocol state machine.
       
    15 // 
       
    16 //
       
    17 
       
    18 /**
       
    19  @file
       
    20  @internalComponent
       
    21  @test
       
    22 */
       
    23 
       
    24 #ifndef __CX3PSTATEMACHINE_H__
       
    25 #define __CX3PSTATEMACHINE_H__
       
    26 
       
    27 #include "cstatemachinebase.h"
       
    28 
       
    29 
       
    30 /** Maximum size of X3P destination string
       
    31 */
       
    32 #define KMaxSizeX3pDestination 64
       
    33 
       
    34 
       
    35 /** X3P protocol state machine.
       
    36 This class manages the X3P protocol procedure and is employed when the protocol
       
    37 module is required to handle interactions to transmit the mobile location 
       
    38 to a third party.
       
    39 
       
    40 The class implements the pure virtual methods defined by CStateMachineBase.
       
    41 @see CStateMachineBase
       
    42 
       
    43 The class also implements a timer observer interface defined by MLbsCallbackTimerObserver
       
    44 @see MLbsCallbackTimerObserver
       
    45 */
       
    46 NONSHARABLE_CLASS(CX3pStateMachine) : public CStateMachineBase, public MLbsCallbackTimerObserver
       
    47 	{
       
    48 public:
       
    49 
       
    50 	/** X3P specific states
       
    51 	These are specific to X3P and identify the current state within the
       
    52 	X3P self locate protocol procedure.
       
    53 	*/
       
    54 	enum TX3pState
       
    55 		{
       
    56 		/** Not valid */
       
    57 		EStateNull,
       
    58 		/** LBS Cient X3P request has been received */
       
    59 		EStateClientReqRecvd,
       
    60 		/** Network X3P session has started */
       
    61 		EStateNetSessStarted,
       
    62 		/** Measurement control data received from the network */
       
    63 		EStateMeasureDataRecvd,
       
    64 		/** Network reference location sent to LBS */
       
    65 		EStateNetBasedLocSent,
       
    66 		/** Network location request sent to LBS */
       
    67 		EStateLocReqByNet,
       
    68 		/** Location response received from LBS */
       
    69 		EStateLocRespRecvd,
       
    70 		/** Location response sent to network */
       
    71 		EStateLocSentToNet,
       
    72 		/** Network X3P session about to close */
       
    73 		EStateNetSessToClose,
       
    74 		/** Network provided location sent to LBS */
       
    75 		EStateNetResultSent,
       
    76 		/** LBS client X3P session about to close */
       
    77 		EStateClientSessToClose,
       
    78 		/** Network and LBS sessions closed */
       
    79 		EStateSessionsClosed,
       
    80 		/** Protocol procedure is to be cancelled */
       
    81 		EStateCancelling
       
    82 		};
       
    83 
       
    84 	/** Request identifiers used when a request is queued.
       
    85 	*/
       
    86 	enum TX3pQueue
       
    87 		{
       
    88 		/** Location response received from LBS */
       
    89 		EQueueLocResponse		 = 100,
       
    90 		/** Measurement control received from network */
       
    91 		EQueueMeasurementControl = 200,
       
    92 		/** Network result received from network */
       
    93 		EQueueNetworkResult		 = 300,
       
    94 		};
       
    95 
       
    96 public:
       
    97 
       
    98 	static CX3pStateMachine* NewL(MStateMachineObserver& aObserver);
       
    99 	virtual ~CX3pStateMachine();
       
   100 	
       
   101 	CX3pStateMachine::TX3pState CurrentState();
       
   102 	
       
   103 	void StartX3pReqTimer();
       
   104 	void StartLocRespTimer();
       
   105 	void StartFacResultTimer();
       
   106 	
       
   107 	const TDesC& Destination() const;
       
   108 
       
   109 	const TPositionInfoBase& NetResultLoc() const;
       
   110 	
       
   111 	void X3pReq(const TLbsNetSessionId& aNewSessionId, const TDesC& aDest);
       
   112 	void QueueX3pReq(const TLbsNetSessionId& aNewSessionId, const TDesC& aDest);
       
   113 	void SessionResult(TInt aResult, const TPositionInfoBase* aPosInfo);
       
   114     void ResponseSent();
       
   115 
       
   116 	void SetStillCancelling(TBool aValue);
       
   117 
       
   118 	// CStateMachineBase derived methods
       
   119 
       
   120 	void MeasurementControlInd(const TPositionInfoBase& aPosInfo,
       
   121 							const TLbsNetPosRequestQuality& aQuality,
       
   122 							const TLbsNetPosRequestMethod& aPosMethod);
       
   123 	void MeasurementControlErrorInd(TInt aReason);
       
   124 	void NetworkErrorInd();
       
   125 	TInt ClientCloseReason() const;
       
   126 
       
   127 	// CStateMachineBase pure virtual methods
       
   128 	void StartQueuedMachine();
       
   129 	void PreStateTransition();
       
   130 	void StateTransition();
       
   131 	void PostStateTransition();
       
   132 	void CancelProcedure();
       
   133 	void DoQueuedRequest(TInt aRequest);
       
   134 
       
   135 	void LocationResp(TInt aReason, const TPositionInfoBase& aPosInfo);
       
   136 	void MeasurementControlTimeout();
       
   137 
       
   138 	// MLbsCallbackTimerObserver methods
       
   139 	
       
   140 	void OnTimerEventL(TInt aTimerId);
       
   141 	TInt OnTimerError(TInt aTimerId, TInt aError);
       
   142 	
       
   143 protected:
       
   144 
       
   145 	CX3pStateMachine(MStateMachineObserver& aObserver);
       
   146 	
       
   147 private:
       
   148 	
       
   149 	void ConstructL();
       
   150 	void InitialiseProcedure();
       
   151 	void CompleteProcedure();
       
   152 
       
   153 	void StoreDestination(const TDesC& aDest);
       
   154 	void QueueDestination(const TDesC& aDest);
       
   155 
       
   156 	void StoreNetResultLoc(const TPositionInfoBase& aPosInfo);
       
   157 
       
   158 protected:
       
   159 	
       
   160 	/** Current X3P state
       
   161 	*/
       
   162 	TX3pState iCurrentState;
       
   163 	
       
   164 	/** Timer for X3P requests issued to network.
       
   165 	*/
       
   166 	CLbsCallbackTimer* iX3pReqIssuedTimer;
       
   167 	
       
   168 	/** Timer for Facility result expected from network
       
   169 	*/
       
   170 	CLbsCallbackTimer* iFacResultTimer;
       
   171 	
       
   172 	/** Timer for Location response expected by network
       
   173 	*/
       
   174 	CLbsCallbackTimer* iLocRespTimer;
       
   175 
       
   176 	/** Flag to indicate if network result location is available
       
   177 	*/
       
   178 	TBool iIsNetResultLocAvailable;
       
   179 	
       
   180 	/** Network Result Position info.
       
   181 	*/
       
   182 	TPositionInfo iNetResultPosInfo;
       
   183 
       
   184 private:
       
   185 
       
   186 	/** Destination for this transmit request
       
   187 	*/
       
   188 	TBuf<KMaxSizeX3pDestination> iDestination;
       
   189 
       
   190 	/** Destination for a queued transmit request
       
   191 	*/
       
   192 	TBuf<KMaxSizeX3pDestination> iQueueDestination;
       
   193 
       
   194 	/** Indicates that certain queued state changes should not take place
       
   195 	*/
       
   196 	TBool iStillCancelling;
       
   197 
       
   198 	};
       
   199 
       
   200 #endif // __CX3PSTATEMACHINE_H__
       
   201