supl/locationomasuplprotocolhandler/protocolhandlerver2/src/epos_comasuplposstate.cpp
changeset 0 667063e416a2
equal deleted inserted replaced
-1:000000000000 0:667063e416a2
       
     1 /*
       
     2 * Copyright (c) 2002-2005 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:   Class for handling SUPL_POS message.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #include <bautils.h>
       
    21 #include <flogger.h>
       
    22 
       
    23 #include <lbs/epos_comasuplpossessionbase.h>
       
    24 #include <lbs/epos_comasuplpospayload.h>
       
    25 #include <lbs/epos_comasuplvelocity.h>
       
    26 #include <lbs/epos_comasuplinforequestlist.h>
       
    27 #include <lbs/epos_comasuplsetcapabilities.h>
       
    28 #include <lbs/epos_eomasuplposerrors.h>
       
    29 
       
    30 #include "epos_comasuplpos.h"
       
    31 #include "epos_comasuplposrequestor.h"
       
    32 #include "epos_comasuplposstate.h"
       
    33 #include "epos_omasuplconstants.h"
       
    34 #include "epos_comasupltrace.h"
       
    35 #include "epos_comasuplasnbase.h"
       
    36 
       
    37 _LIT(KTraceFileName,"SUPL_OMA_SESSION::EPos_COMASuplPosState.cpp");
       
    38 
       
    39 // ============================ MEMBER FUNCTIONS ===============================
       
    40 
       
    41 // -----------------------------------------------------------------------------
       
    42 // COMASuplPosState::COMASuplPosState
       
    43 // C++ constructor can NOT contain any code, that might leave.
       
    44 // -----------------------------------------------------------------------------
       
    45 //
       
    46 COMASuplPosState::COMASuplPosState(COMASuplPosSessionBase* aPOSSession,TInt aMsgTimeout,COMASuplSETCapabilities* aSETCapabilities,
       
    47 									COMASuplAsnHandlerBase* aOMASuplAsnHandlerBase):
       
    48 								  iPOSSession(aPOSSession),
       
    49 								  iSETCapabilities(aSETCapabilities),
       
    50 								  iOMASuplAsnHandlerBase(aOMASuplAsnHandlerBase)
       
    51     {
       
    52 			iMessageTimeOut = aMsgTimeout * KSecond; 
       
    53 			iCurrentState = ESUPL_POS;   
       
    54     }
       
    55 
       
    56 // -----------------------------------------------------------------------------
       
    57 // COMASuplPosState::~COMASuplPosState
       
    58 // -----------------------------------------------------------------------------
       
    59 //
       
    60 COMASuplPosState::~COMASuplPosState()
       
    61     {
       
    62 		delete iPOSRequestor;
       
    63 		delete iRemainingPospayload;
       
    64 		
       
    65 		if(iTrace)
       
    66 			iTrace->Trace(_L("COMASuplPosState::~COMASuplPosState..."), KTraceFileName, __LINE__); 							
       
    67     }
       
    68 
       
    69 // -----------------------------------------------------------------------------
       
    70 // COMASuplPosState::ConstructL
       
    71 // Symbian 2nd phase constructor can leave.
       
    72 // -----------------------------------------------------------------------------
       
    73 //
       
    74 void COMASuplPosState::ConstructL()
       
    75     {
       
    76     	COMASuplState::BaseConstructL();
       
    77     	iTrace->Trace(_L("COMASuplPosState::ConstructL..."), KTraceFileName, __LINE__); 
       
    78     								
       
    79 		if(iPOSSession)
       
    80 		{
       
    81 			iPOSRequestor = COMASuplPOSRequestor::NewL(this,iPOSSession);
       
    82 			iOMASuplPosPayLoad = COMASuplPosPayload::NewL();
       
    83 			iOMASuplVelocity = COMASuplVelocity::NewL();
       
    84 			
       
    85 			
       
    86 			iPOSRequestor->CreateListL();
       
    87 			iPOSRequestor->AppendInfoRequest(iOMASuplPosPayLoad);//ownership is towords iPOSRequestor
       
    88 			iPOSRequestor->AppendInfoRequest(iOMASuplVelocity);
       
    89 		}
       
    90 			iIsLastPosPayloadSegmented = EFalse;
       
    91 			iIsAnyPosPayloadFromPosInit = EFalse;
       
    92     }
       
    93 
       
    94 // -----------------------------------------------------------------------------
       
    95 // COMASuplPosState::NewL
       
    96 // Two-phased constructor.
       
    97 // -----------------------------------------------------------------------------
       
    98 //
       
    99 COMASuplPosState* COMASuplPosState::NewL(COMASuplPosSessionBase* aPOSSession,TInt aMsgTimeout,COMASuplSETCapabilities* aSETCapabilities,
       
   100 																				 COMASuplAsnHandlerBase* aOMASuplAsnHandlerBase)
       
   101     {
       
   102 	    COMASuplPosState* self =  new ( ELeave ) COMASuplPosState(aPOSSession,aMsgTimeout,aSETCapabilities,aOMASuplAsnHandlerBase);
       
   103 	    CleanupStack::PushL( self );
       
   104 	    self->ConstructL();
       
   105 	    CleanupStack::Pop(self);
       
   106 	    return self;
       
   107     }
       
   108 
       
   109 // -----------------------------------------------------------------------------
       
   110 // COMASuplPosState::GenerateMessage
       
   111 // Generates SUPL_POS message
       
   112 // (other items were commented in a header).
       
   113 // -----------------------------------------------------------------------------
       
   114 //
       
   115 TInt COMASuplPosState::GenerateMessageL() 
       
   116 	{
       
   117 		iTrace->Trace(_L("Start of COMASuplPosState::GenerateMessage"), KTraceFileName, __LINE__); 
       
   118 		TInt err = KErrNone;
       
   119 		iGenerationStatus = ETrue;
       
   120 		if(iPOSSession)
       
   121 		{
       
   122 			if(iIsLastPosPayloadSegmented)
       
   123 				{
       
   124 					OperationCompleteL(KErrNone);
       
   125 				}
       
   126 			else
       
   127 				{
       
   128 					iOMASuplPosPayLoad->SetStatus(KErrOMASuplParamNotSet);//Set this explicitly...so that one can set it again
       
   129 					err = iPOSRequestor->GetSuplInfoL();	
       
   130 				}	
       
   131 			
       
   132 			if(err != KErrNone)	
       
   133 				{
       
   134 					iGenerationStatus = EFalse;
       
   135 				}
       
   136 		}
       
   137 		
       
   138 		return err;
       
   139 	}
       
   140 	
       
   141 // -----------------------------------------------------------------------------
       
   142 // COMASuplPosState::EncodeMessageL
       
   143 // Encodes message ...returns encoded data
       
   144 // (other items were commented in a header).
       
   145 // -----------------------------------------------------------------------------
       
   146 //
       
   147 HBufC8* COMASuplPosState::EncodeMessageL(TOMASuplVersion& aSuplVersion,COMASuplSessionID* aSessionId,TInt& aError)
       
   148 { 
       
   149     iTrace->Trace(_L("Starting Encoding..."), KTraceFileName, __LINE__); 							
       
   150     COMASuplState::EncodeMessageL(aSuplVersion,aSessionId,aError);
       
   151 	HBufC8 *encodedBuffer = NULL;
       
   152 	TInt error;
       
   153 	aError = KErrNone;
       
   154 	iRequestError = KErrNone;
       
   155 	
       
   156 	
       
   157 	COMASuplAsnMessageBase* OMASuplMessageBase = iOMASuplAsnHandlerBase->CreateOMASuplMessageL(COMASuplAsnMessageBase::ESUPL_POS);
       
   158 	CleanupStack::PushL(OMASuplMessageBase);
       
   159 	COMASuplPos* OMASuplPos  =  static_cast<COMASuplPos*>(OMASuplMessageBase);
       
   160 	OMASuplPos->SetMessageBase(aSuplVersion,aSessionId); 
       
   161 	IterateSuplInfoListL(OMASuplPos,aError);
       
   162 
       
   163 	TRAPD(err,encodedBuffer = iOMASuplAsnHandlerBase->EncodeL(OMASuplPos,error));
       
   164 	CleanupStack::PopAndDestroy(OMASuplMessageBase);
       
   165 	
       
   166 	LogPosPayLoadData();
       
   167 	LogVelocity();
       
   168 	
       
   169 	if(aError == KErrNone || aError == KErrOMASuplLastPosMsg )				
       
   170 		{
       
   171 			if ( error == KErrNone && err == KErrNone )
       
   172 			{
       
   173 				iTrace->Trace(_L("Encoding Done..."), KTraceFileName, __LINE__); 							
       
   174 				aError = KErrNone;
       
   175 				return encodedBuffer;
       
   176 			}
       
   177 			else
       
   178 			{
       
   179 				iTrace->Trace(_L("Encoding Failed."), KTraceFileName, __LINE__); 
       
   180 				aError = error;	
       
   181 				delete encodedBuffer;
       
   182 			}
       
   183 			return NULL;
       
   184 		}
       
   185 	else
       
   186 		{
       
   187 			aError = KErrOMAManParamMissing;
       
   188 			iTrace->Trace(_L("POS failed to give manadatory ..."), KTraceFileName, __LINE__); 							
       
   189 			delete encodedBuffer; 
       
   190 			return NULL;
       
   191 		}		
       
   192 }
       
   193 
       
   194 // -----------------------------------------------------------------------------
       
   195 // COMASuplPosState::ProcessMessage
       
   196 // process message...
       
   197 // (other items were commented in a header).
       
   198 // -----------------------------------------------------------------------------
       
   199 //
       
   200 TInt COMASuplPosState::ProcessMessageL(COMASuplAsnMessageBase*  aDecodedMessage )
       
   201 {
       
   202 		iTrace->Trace(_L("COMASuplPosState::ProcessMessageL"), KTraceFileName, __LINE__); 
       
   203 				
       
   204 		COMASuplPos* OMASuplPos = static_cast <COMASuplPos*>(aDecodedMessage);
       
   205 		
       
   206 			//Retrieve the Pos Payload from Supl Pos Message
       
   207 			COMASuplPosPayload* OMASuplPosPayLoad = NULL;
       
   208 			OMASuplPosPayLoad  =  OMASuplPos->SuplPos(); 
       
   209 			
       
   210 			if(!CheckPOSPayloadType(OMASuplPosPayLoad)) // Check is POS method mismatch with SETCaps
       
   211 				{
       
   212 					iTrace->Trace(_L("COMASuplPosState::ProcessMessageL POS method Mismatched. "), KTraceFileName, __LINE__); 
       
   213 					return KErrSuplposMethodMismatch; 	
       
   214 				}
       
   215 			if(iPOSSession)
       
   216 				{
       
   217 					TRAP_IGNORE(iPOSSession->HandleSuplPosMessageL(OMASuplPosPayLoad));		
       
   218 					iTrace->Trace(_L("COMASuplPosState::ProcessMessageL...PosPayLoad sent to POS Msg Plugin..."), KTraceFileName, __LINE__); 
       
   219 				}
       
   220 			return KErrNone;
       
   221 }
       
   222 
       
   223 // -----------------------------------------------------------------------------
       
   224 // COMASuplPosState::CancelOperation
       
   225 // Cancels Operation...which will be depend on derived class implementation
       
   226 // (other items were commented in a header).
       
   227 // -----------------------------------------------------------------------------
       
   228 //
       
   229 void COMASuplPosState::CancelOperation() 
       
   230 	{ 
       
   231 		 COMASuplState::CancelOperation();
       
   232 		 if(iPOSRequestor)
       
   233 		 	{
       
   234 			 	iPOSRequestor->Cancel();
       
   235 		 	}
       
   236 		 iTrace->Trace(_L("COMASuplPosState::CancelOperation..."), KTraceFileName, __LINE__); 							
       
   237 	}	
       
   238 // -----------------------------------------------------------------------------
       
   239 // COMASuplPosState::StartTimer
       
   240 // StartTimer...starts the timer ... 
       
   241 // (other items were commented in a header).
       
   242 // -----------------------------------------------------------------------------
       
   243 //
       
   244 void COMASuplPosState::StartTimer()
       
   245 {
       
   246 	iTrace->Trace(_L("COMASuplPosState::StartTimer..."), KTraceFileName, __LINE__); 							
       
   247 	if(IsLastMessage() && !iIsLastPosPayloadSegmented)
       
   248 		{
       
   249 			iTrace->Trace(_L("Timer Started for POS"), KTraceFileName, __LINE__); 
       
   250 			COMASuplState::StartTimer();
       
   251 		}
       
   252 }
       
   253 
       
   254 // -----------------------------------------------------------------------------
       
   255 // COMASuplPosState::IsLastMessage
       
   256 // Is last message
       
   257 // (other items were commented in a header).
       
   258 // -----------------------------------------------------------------------------
       
   259 //
       
   260 TBool COMASuplPosState::IsLastMessage()
       
   261 {
       
   262 	iTrace->Trace(_L("COMASuplPosState::IsLastMessage"), KTraceFileName, __LINE__); 
       
   263 	if(iRequestError == KErrOMASuplLastPosMsg)
       
   264 		{
       
   265 			iTrace->Trace(_L("COMASuplPosState::IsLastMessage... Last Message from POS"), KTraceFileName, __LINE__); 
       
   266 			return ETrue;
       
   267 		}
       
   268 	else
       
   269 		{
       
   270 			iTrace->Trace(_L("COMASuplPosState::IsLastMessage...More data from POS Payload..."), KTraceFileName, __LINE__); 
       
   271 			return EFalse;
       
   272 		}
       
   273 }
       
   274 
       
   275 // -----------------------------------------------------------------------------
       
   276 // COMASuplPosState::OperationCompleteL
       
   277 // Gets control when any of the asynchronous requests are completed
       
   278 // (other items were commented in a header).
       
   279 // -----------------------------------------------------------------------------
       
   280 //
       
   281 void COMASuplPosState::OperationCompleteL(TInt aErrorCode)
       
   282 {
       
   283 	iGenerationStatus = EFalse;
       
   284 	PseudoSegmentationL();
       
   285 	if(iMsgStateObserver)
       
   286 		iMsgStateObserver->OperationCompleteL(aErrorCode);
       
   287 }
       
   288 
       
   289 // -----------------------------------------------------------------------------
       
   290 // COMASuplPosState::GetPositionComplete
       
   291 // No use
       
   292 // (other items were commented in a header).
       
   293 // -----------------------------------------------------------------------------
       
   294 //
       
   295 void COMASuplPosState::GetPositionCompleteL(TInt /*aError*/)
       
   296 {
       
   297 }
       
   298 
       
   299 // -----------------------------------------------------------------------------
       
   300 // COMASuplPosState::IterateSuplInfoListL
       
   301 // Interates thro' request list 
       
   302 // (other items were commented in a header).
       
   303 // -----------------------------------------------------------------------------
       
   304 //
       
   305 void COMASuplPosState::IterateSuplInfoListL(COMASuplPos* aOMASuplPos,TInt &aError)
       
   306 { 
       
   307 	iTrace->Trace(_L("COMASuplPosState::IterateSuplInfoList..."), KTraceFileName, __LINE__); 
       
   308 	COMASuplInfoRequestList* OMASuplInfoRequestList =  iPOSRequestor->GetOMASuplInfoRequestList();
       
   309 	
       
   310 	if(!OMASuplInfoRequestList) 
       
   311 		{
       
   312 			iTrace->Trace(_L("Failed to retrived list(RequestList).COMASuplPosState::FillSuplInfoList"), KTraceFileName, __LINE__); 		
       
   313 			aError = KErrCompletion;
       
   314 			return;	
       
   315 		}
       
   316 	
       
   317 	TInt NoOfElements = OMASuplInfoRequestList->GetCount();
       
   318 	
       
   319 	aError = KErrNone;
       
   320 	
       
   321 	for(TInt cnt = 0; cnt < NoOfElements; ++cnt)
       
   322 		{
       
   323 			COMASuplInfoRequest* info = OMASuplInfoRequestList->GetElement(cnt);
       
   324 			if(!info) 
       
   325 				{
       
   326 					iTrace->Trace(_L("Failed to retrive list(info).COMASuplPosState::IterateSuplInfoList"), KTraceFileName, __LINE__); 		
       
   327 					continue;
       
   328 				}
       
   329 				
       
   330 			TInt posError = info->Status();					
       
   331 			switch(info->Type())
       
   332 				{
       
   333 					case COMASuplInfoRequest::EOMASuplVelocity: 
       
   334 				 		{
       
   335 							if(posError == KErrNone)
       
   336 								{
       
   337 									if(iOMASuplVelocity)//Use velocity
       
   338 										{
       
   339 											COMASuplVelocity* OMASuplVelocity = static_cast <COMASuplVelocity *>(iOMASuplVelocity->CloneL());//Ownership transfer to callee
       
   340 											aOMASuplPos->SetVelocity(OMASuplVelocity);
       
   341 										}
       
   342 								}
       
   343 							break;	
       
   344 						}
       
   345 
       
   346 					case COMASuplInfoRequest::EOMASuplPosPayload: 
       
   347 						{
       
   348 							if( (posError == KErrNone || posError == KErrOMASuplLastPosMsg) && iOMASuplPosPayLoad)//Use PosPayload
       
   349 								{
       
   350 									COMASuplPosPayload* OMASuplPosPayload =static_cast <COMASuplPosPayload *>(iOMASuplPosPayLoad->CloneL());//Ownership transfer to callee
       
   351 									aOMASuplPos->SetSuplPos(OMASuplPosPayload);
       
   352 									if(posError == KErrOMASuplLastPosMsg)
       
   353 										{
       
   354 											iRequestError = KErrOMASuplLastPosMsg;
       
   355 										}
       
   356 								}
       
   357 							else
       
   358 								{
       
   359 									aError = posError;
       
   360 								}	
       
   361 							break;	
       
   362 						}
       
   363 				}
       
   364 		}
       
   365 		
       
   366 	iTrace->Trace(_L("Done...COMASuplPosState::IterateSuplInfoList"), KTraceFileName, __LINE__); 		
       
   367 }
       
   368 
       
   369 // -----------------------------------------------------------------------------
       
   370 // COMASuplPosState::IsGenerationInProgress()
       
   371 // returns status of generation of Message
       
   372 // (other items were commented in a header).
       
   373 // -----------------------------------------------------------------------------
       
   374 //
       
   375 TBool COMASuplPosState::IsGenerationInProgress()
       
   376 	{
       
   377 		return iGenerationStatus;
       
   378 	}
       
   379 	
       
   380 // -----------------------------------------------------------------------------
       
   381 // COMASuplPosState::CheckPOSPayloadType()
       
   382 // returns EFalse if there is mismatch in POS Payload type
       
   383 // (other items were commented in a header).
       
   384 // -----------------------------------------------------------------------------
       
   385 //
       
   386 TBool COMASuplPosState::CheckPOSPayloadType(const COMASuplPosPayload *aPosPayload)
       
   387 	{
       
   388 		if(!iSETCapabilities)	
       
   389 			{
       
   390 				return EFalse;		
       
   391 			}
       
   392 			
       
   393 			HBufC8* Payload = NULL;
       
   394 			COMASuplPosPayload::TOMASuplPosPayloadType ReceivedPayloadType;
       
   395 			aPosPayload->GetPosPayload(Payload,ReceivedPayloadType);
       
   396 			
       
   397 			TOMASuplPosTechnology posTech;
       
   398 			COMASuplSETCapabilities::TOMASuplPrefMethod prefMethod;
       
   399 			TOMASuplPosProtocol posProtocol;
       
   400 			iSETCapabilities->GetSETCapabilities(posTech,prefMethod, posProtocol);
       
   401 			
       
   402 			TBool SETtia801,SETRRLP,SETRRC;
       
   403 			posProtocol.GetPosProtocol(SETtia801,SETRRLP,SETRRC);
       
   404 			
       
   405 			if(ReceivedPayloadType == COMASuplPosPayload::ETIA801)
       
   406 				{
       
   407 					iTrace->Trace(_L("Received POS protocol method is TIA801 "), KTraceFileName, __LINE__); 		
       
   408 					return SETtia801;
       
   409 				}
       
   410 				
       
   411 			if(ReceivedPayloadType == COMASuplPosPayload::ERRLP)
       
   412 				{
       
   413 					iTrace->Trace(_L("Received POS protocol method is RRLP "), KTraceFileName, __LINE__); 		
       
   414 					return SETRRLP;
       
   415 				}
       
   416 				
       
   417 			if(ReceivedPayloadType == COMASuplPosPayload::ERRC)
       
   418 				{
       
   419 					iTrace->Trace(_L("Received POS protocol method is RRC "), KTraceFileName, __LINE__); 		
       
   420 					return SETRRC;
       
   421 				}
       
   422 				
       
   423 		return EFalse;
       
   424 	}
       
   425 	
       
   426 
       
   427 // -----------------------------------------------------------------------------
       
   428 // COMASuplPosState::IsSegmentationDone
       
   429 // Does the pseudo segmentation done...
       
   430 // (other items were commented in a header).
       
   431 // -----------------------------------------------------------------------------
       
   432 //
       
   433 TBool COMASuplPosState::IsSegmentationDone() const
       
   434 	{
       
   435 		return iIsLastPosPayloadSegmented;
       
   436 	}
       
   437 	
       
   438 // -----------------------------------------------------------------------------
       
   439 // COMASuplPosState::PseudoSegmentation
       
   440 // Does the pseudo segmentation.
       
   441 // (other items were commented in a header).
       
   442 // -----------------------------------------------------------------------------
       
   443 //
       
   444 void COMASuplPosState::PseudoSegmentationL()
       
   445 	{
       
   446 		TInt posPosPayLoadError = iOMASuplPosPayLoad->Status();					
       
   447 		if(posPosPayLoadError == KErrNone || posPosPayLoadError == KErrOMASuplLastPosMsg || !iIsAnyPosPayloadFromPosInit)
       
   448 			{
       
   449 				HBufC8* payLoad = NULL;
       
   450 				iOMASuplPosPayLoad->GetPosPayload(payLoad,iPosPayLoadType);
       
   451 			if(!iIsLastPosPayloadSegmented) // First time ..will hold data
       
   452 				{
       
   453 					if(payLoad)
       
   454 					{
       
   455 						TInt posPayloadLength = payLoad->Length();
       
   456 						TBuf<64> msg;
       
   457 						msg.Copy(_L("Received Pospayload having length : "));
       
   458 						msg.AppendNum(posPayloadLength);
       
   459 						iTrace->Trace(msg, KTraceFileName, __LINE__); 		
       
   460 						msg.Copy(_L("Logging Received POS Payload from POS Msg Plugin: "));
       
   461 						iTrace->Trace(msg, KTraceFileName, __LINE__); 		
       
   462 
       
   463 				    	LogPacket(payLoad->Des());
       
   464 						
       
   465 						if( posPayloadLength > KMaxPosPayloadLength )
       
   466 						{
       
   467 							delete iRemainingPospayload; 
       
   468 							posPayloadLength  = posPayloadLength - KMaxPosPayloadLength; // Length of remaining data
       
   469 							msg.Copy(_L("Remaining POS Payload after segmentation: "));
       
   470 							msg.AppendNumUC(posPayloadLength);
       
   471 							iTrace->Trace(msg, KTraceFileName, __LINE__); 		
       
   472 							iRemainingPospayload = HBufC8::NewL(posPayloadLength);  
       
   473 							iRemainingPospayload->Des().Copy(payLoad->Des().Mid(KMaxPosPayloadLength ));// Copy rest data
       
   474 							payLoad->Des().Copy(payLoad->Des().Left(KMaxPosPayloadLength));
       
   475 							iIsLastPosPayloadSegmented = ETrue;
       
   476 							
       
   477 								TInt len = payLoad->Length();
       
   478 								msg.Copy(_L("Segmentationed POS Payload data...: "));
       
   479 								msg.AppendNum(len);
       
   480 								iTrace->Trace(msg, KTraceFileName, __LINE__); 		
       
   481 								LogPacket(payLoad->Des());
       
   482 						}
       
   483 					}
       
   484 				}
       
   485 			else
       
   486 				{
       
   487 					iOMASuplVelocity->SetStatus(KErrOMASuplParamNotSet);//Set this explicitly...so that velocity will not be reconsider
       
   488 					TInt remainingPosPayloadLength = iRemainingPospayload->Length();
       
   489 					if( remainingPosPayloadLength > KMaxPosPayloadLength )
       
   490 						{
       
   491 							payLoad->Des().Copy(iRemainingPospayload->Des().Left(KMaxPosPayloadLength));
       
   492 							iRemainingPospayload->Des().Copy(iRemainingPospayload->Des().Mid(KMaxPosPayloadLength));// Copy rest data
       
   493 						}
       
   494 					else
       
   495 						{
       
   496 							payLoad->Des().Copy(iRemainingPospayload->Des());
       
   497 							iIsLastPosPayloadSegmented = EFalse;
       
   498 						}
       
   499 						
       
   500 						TInt len = payLoad->Length();
       
   501 						TBuf<64> msg;
       
   502 						msg.Copy(_L("Segmentationed POS Payload data...: "));
       
   503 						msg.AppendNum(len);
       
   504 						iTrace->Trace(msg, KTraceFileName, __LINE__); 		
       
   505 				}
       
   506 			}
       
   507 	}
       
   508 	
       
   509 // -----------------------------------------------------------------------------
       
   510 // COMASuplPosState::SetRemainingPosPayloadFromSuplPosInit
       
   511 // Sets remaining pos payload from SUPL_POS_INIT
       
   512 // (other items were commented in a header).
       
   513 // -----------------------------------------------------------------------------
       
   514 //
       
   515 void COMASuplPosState::SetRemainingPosPayloadFromSuplPosInitL(COMASuplPosPayload* aRemainingPospayload)	
       
   516 	{
       
   517 		if(aRemainingPospayload)
       
   518 			{
       
   519 				iIsAnyPosPayloadFromPosInit = ETrue;
       
   520 				iIsLastPosPayloadSegmented = ETrue;
       
   521 				
       
   522 				HBufC8* payLoad = NULL;
       
   523 				COMASuplPosPayload::TOMASuplPosPayloadType payLoadType;
       
   524 				aRemainingPospayload->GetPosPayload(payLoad,payLoadType);
       
   525 				
       
   526 				HBufC8* payLoadBuffer = HBufC8::NewL(payLoad->Length());
       
   527 				payLoadBuffer->Des().Copy(payLoad->Des());
       
   528 				iOMASuplPosPayLoad->SetPosPayload(payLoadBuffer,payLoadType); //Setting POS payload buffer
       
   529 				iOMASuplPosPayLoad->SetStatus(KErrNone);
       
   530 				
       
   531 				iRemainingPospayload = HBufC8::NewL(payLoad->Length());
       
   532 				iRemainingPospayload->Des().Copy(payLoad->Des());
       
   533 				delete aRemainingPospayload;
       
   534 			}
       
   535 	}
       
   536 	
       
   537 // -----------------------------------------------------------------------------
       
   538 // COMASuplPosState::LogPosPayLoadData
       
   539 // // Logs PosPayLoadData in epostrace file
       
   540 // (other items were commented in a header).
       
   541 // -----------------------------------------------------------------------------
       
   542 //
       
   543 void COMASuplPosState::LogPosPayLoadData()
       
   544 	{
       
   545 	
       
   546 #ifdef PRINT_MESSAGE 
       
   547 
       
   548 	if(iOMASuplPosPayLoad)
       
   549 		{
       
   550 		TInt posPosPayLoadError = iOMASuplPosPayLoad->Status();					
       
   551 		if(!(posPosPayLoadError == KErrNone || posPosPayLoadError == KErrOMASuplLastPosMsg  ))
       
   552 			{
       
   553 				iTrace->Trace(_L("No POS Payload data provided for SUPL_POS from PosMsgPlugin"), KTraceFileName, __LINE__);	
       
   554 				return;
       
   555 			}
       
   556 			
       
   557 		iTrace->Trace(_L("**************** Start of SUPL POS  PosPayLoad Data from PosMsgPlugin**********************"), KTraceFileName, __LINE__);
       
   558 		HBufC8* payLoad = NULL;
       
   559 		COMASuplPosPayload::TOMASuplPosPayloadType payLoadType;
       
   560 		
       
   561 		iOMASuplPosPayLoad->GetPosPayload(payLoad,payLoadType);
       
   562 		HBufC* payLoadBuffer = NULL; 
       
   563 		if(payLoad)
       
   564 			{
       
   565 			TInt err;	
       
   566 			TRAP(err,payLoadBuffer = HBufC::NewL(payLoad->Length()))	;
       
   567 			err = 0;
       
   568 			payLoadBuffer->Des().Copy(payLoad->Des());
       
   569 			}
       
   570 			
       
   571 		if(payLoadType == COMASuplPosPayload::ETIA801)
       
   572 			{
       
   573 			iTrace->Trace(_L("POS DATA Type - ETIA801 "), KTraceFileName, __LINE__);
       
   574 			if(payLoadBuffer && payLoad)
       
   575 			   iTrace->Trace(payLoadBuffer->Des(),KTraceFileName, __LINE__);
       
   576 			}
       
   577 		else if(payLoadType == COMASuplPosPayload::ERRLP)
       
   578 			{
       
   579 			iTrace->Trace(_L("POS DATA Type - ERRLP "), KTraceFileName, __LINE__);
       
   580 			}
       
   581 		else if(payLoadType == COMASuplPosPayload::ERRC)
       
   582 			{
       
   583 			iTrace->Trace(_L("POS DATA Type - ERRC "), KTraceFileName, __LINE__);
       
   584 			if(payLoadBuffer && payLoad )
       
   585 				iTrace->Trace(payLoadBuffer->Des(),KTraceFileName, __LINE__);		
       
   586 			}
       
   587 			
       
   588 		delete payLoadBuffer;
       
   589 		payLoadBuffer = NULL;
       
   590 		
       
   591 		iTrace->Trace(_L("**************** End of SUPL POS  PosPayLoad Data **********************"), KTraceFileName, __LINE__);
       
   592 		}
       
   593 #endif
       
   594 
       
   595 	}
       
   596 	
       
   597 // -----------------------------------------------------------------------------
       
   598 // COMASuplPosState::LogVelocity
       
   599 // Logs Velocity in epostrace file
       
   600 // (other items were commented in a header).
       
   601 // -----------------------------------------------------------------------------
       
   602 //
       
   603 void COMASuplPosState::LogVelocity()
       
   604 	{
       
   605 	
       
   606 #ifdef PRINT_MESSAGE 		
       
   607 	if(iOMASuplVelocity)
       
   608 		{
       
   609 		TInt posVelocityError = iOMASuplVelocity->Status();					
       
   610 		if(posVelocityError != KErrNone )
       
   611 			{
       
   612 				iTrace->Trace(_L("No Velocity Information provided for SUPL_POS "), KTraceFileName, __LINE__);	
       
   613 				return;
       
   614 			}
       
   615 			
       
   616 		iTrace->Trace(_L("Velocity Information for SUPL_POS "), KTraceFileName, __LINE__);		
       
   617 		TBuf<256> msg;
       
   618 		TOMASuplVelocityType velocityType = iOMASuplVelocity->VelType();
       
   619 		COMASuplHorizVelocity* horizVelocity = iOMASuplVelocity->Velocity();
       
   620 		TUint16 bearing;
       
   621 		TUint16 horSpeed;
       
   622 		switch(velocityType)	
       
   623 			{
       
   624 				case  EHorizVelocity:
       
   625 					{
       
   626 					iTrace->Trace(_L("Velocity Type : EHorizVelocity - Values "), KTraceFileName, __LINE__);
       
   627 					horizVelocity->GetHorizVel(bearing,horSpeed);
       
   628 					
       
   629 					msg.Append(_L("Bearing "));
       
   630 					msg.AppendNum(bearing);
       
   631 					msg.Append(_L("Horizontal Speed "));
       
   632 					msg.AppendNum(horSpeed);
       
   633 					iTrace->Trace(msg, KTraceFileName, __LINE__);
       
   634 					break;
       
   635 					}
       
   636 				case EHorizAndVertVelocity:
       
   637 					{
       
   638 					TUint8 verDirect;
       
   639 					TUint8 verSpeed;
       
   640 					COMASuplHorizAndVertVelocity* horizVertVel = (COMASuplHorizAndVertVelocity*)horizVelocity;
       
   641 					horizVertVel->GetHorizAndVertVel(bearing,horSpeed,verDirect,verSpeed);
       
   642 					
       
   643 					iTrace->Trace(_L("Velocity Type : EHorizVelocity - Values "), KTraceFileName, __LINE__);
       
   644 										
       
   645 					msg.Append(_L("Bearing "));
       
   646 					msg.AppendNum(bearing);
       
   647 					msg.Append(_L("Horizontal Speed "));
       
   648 					msg.AppendNum(horSpeed);
       
   649 					msg.Append(_L("Vertical Direction "));
       
   650 					msg.AppendNum(verDirect);
       
   651 					msg.Append(_L("Vertical Speed "));
       
   652 					msg.AppendNum(verSpeed);					
       
   653 					iTrace->Trace(msg, KTraceFileName, __LINE__);
       
   654 					
       
   655 					break;
       
   656 					}
       
   657 				case EHorizUncertVelocity: 
       
   658 					{
       
   659 					TUint8 uncertSpeed;
       
   660 					COMASuplHorizUncertVelocity* horizUncertVel = (COMASuplHorizUncertVelocity*)horizVelocity;
       
   661 	
       
   662 					horizUncertVel->GetHorizUncertVel(bearing,horSpeed,uncertSpeed);	
       
   663 					
       
   664 					iTrace->Trace(_L("Velocity Type : EHorizUncertVelocity - Values "), KTraceFileName, __LINE__);
       
   665 										
       
   666 					msg.Append(_L("Bearing "));
       
   667 					msg.AppendNum(bearing);
       
   668 					msg.Append(_L("Horizontal Speed "));
       
   669 					msg.AppendNum(horSpeed);
       
   670 					msg.Append(_L("Uncertainity Speed "));
       
   671 					msg.AppendNum(uncertSpeed);
       
   672 							
       
   673 					iTrace->Trace(msg, KTraceFileName, __LINE__);
       
   674 					
       
   675 					break;
       
   676 					}
       
   677 				case EHorizAndVertUncertVelocity:
       
   678 					{
       
   679 					TUint8  verDirect;
       
   680 					TUint8  verSpeed;
       
   681 					TUint8  horizUncertSpeed;
       
   682 					TUint8  vertUncertSpeed;
       
   683 										
       
   684 					COMASuplHorizAndVertUncertVelocity* horizVertUncertVel = (COMASuplHorizAndVertUncertVelocity*)horizVelocity;
       
   685 
       
   686 					horizVertUncertVel->GetHorizVertUncertVel(bearing,horSpeed,verDirect,verSpeed,
       
   687 																horizUncertSpeed,vertUncertSpeed);
       
   688 					
       
   689 					iTrace->Trace(_L("Velocity Type : EHorizAndVertUncertVelocity - Values "), KTraceFileName, __LINE__);
       
   690 										
       
   691 					msg.Append(_L("Bearing "));
       
   692 					msg.AppendNum(bearing);
       
   693 					msg.Append(_L("Horizontal Speed "));
       
   694 					msg.AppendNum(horSpeed);
       
   695 					msg.Append(_L("Vertical Direction "));
       
   696 					msg.AppendNum(verDirect);
       
   697 					msg.Append(_L("Vertical Speed "));
       
   698 					msg.AppendNum(verSpeed);					
       
   699 					msg.Append(_L("Horiz Uncertain Speed "));
       
   700 					msg.AppendNum(horizUncertSpeed);
       
   701 					msg.Append(_L("Vertical Uncertain Speed "));
       
   702 					msg.AppendNum(vertUncertSpeed);					
       
   703 					iTrace->Trace(msg, KTraceFileName, __LINE__);																					
       
   704 																
       
   705 				    break;																
       
   706 					}
       
   707 			}
       
   708 		}
       
   709 #endif
       
   710 		
       
   711 	}
       
   712 	
       
   713 void COMASuplPosState::LogPacket(const TDesC8& 
       
   714 #ifdef PRINT_MESSAGE
       
   715 aPacket
       
   716 #endif
       
   717 )
       
   718 {
       
   719 #ifdef PRINT_MESSAGE
       
   720 
       
   721 
       
   722 			RFileLogger  logger;
       
   723 			TInt err = logger.Connect();
       
   724 			if(err == KErrNone)
       
   725 				{
       
   726 					const TText* hdr1 = _S("Header");
       
   727 					const TText* mrg1 = _S("End");
       
   728 					logger.CreateLog(_L("epos"),_L("PayloadFromPOSPlugin.txt"),EFileLoggingModeAppend);
       
   729 					logger.HexDump(hdr1, mrg1, aPacket.Ptr(), aPacket.Length() );
       
   730 				}
       
   731 			logger.Close();
       
   732 #endif
       
   733 }
       
   734 
       
   735 	
       
   736 //  End of File