networkprotocolmodules/common/suplrrlpasn1/src/suplpospayload.cpp
branchRCL_3
changeset 52 29dbbeac905d
parent 39 a3482a8f15d8
child 53 419d6cfdb715
child 54 0c2046328c85
equal deleted inserted replaced
39:a3482a8f15d8 52:29dbbeac905d
     1 // Copyright (c) 2008-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 //
       
    15 
       
    16 /**
       
    17  @file
       
    18  @internalTechnology
       
    19  
       
    20 */
       
    21 
       
    22 #include "RRLP-Messages.h"
       
    23 #include "ULP.h"
       
    24 #include "suplpospayload.h"
       
    25 #include "supldevloggermacros.h" 
       
    26 #include "rrlputils.h"
       
    27 #include "rrlpmeasureposrequest.h"
       
    28 #include "rrlpassistancedata.h"
       
    29 #include "rrlpprotocolerror.h"
       
    30 #include "suplasn1error.h"
       
    31 
       
    32 /**
       
    33 Default Constructor
       
    34 */
       
    35 CSuplPosPayload::CSuplPosPayload(TSuplPosPayloadType aType, TBool aIsOutgoingMsg)
       
    36  : iMessageType(aType), iIsOutgoingMessage(aIsOutgoingMsg)
       
    37 	{
       
    38 	SUPLLOG(ELogP1, "CSuplPosPayload::CSuplPosPayload() Begin\n");
       
    39 	SUPLLOG(ELogP1, "CSuplPosPayload::CSuplPosPayload() End\n");
       
    40 	}
       
    41 
       
    42 /**
       
    43 Default Constructor
       
    44 */
       
    45 CSuplPosPayload::~CSuplPosPayload()
       
    46 	{
       
    47 	SUPLLOG(ELogP1, "CSuplPosPayload::~CSuplPosPayload() Begin\n");
       
    48 	SUPLLOG(ELogP1, "CSuplPosPayload::~CSuplPosPayload() End\n");
       
    49 	}
       
    50 	
       
    51 /** 
       
    52 EncodeToL()
       
    53 
       
    54 Encode a populated outgoing message 
       
    55 
       
    56 @param aBuf the destination buffer to encode to
       
    57 @return error indication, KErrNone otherwise
       
    58 */
       
    59 TInt CSuplPosPayload::EncodeToL(TPtr8& /*aBuf*/)
       
    60 	{
       
    61 	SUPLLOG(ELogP1, "CSuplPosPayload::~CSuplPosPayload() Begin\n");
       
    62 	SUPLLOG(ELogP1, "CSuplPosPayload::~CSuplPosPayload() End\n");
       
    63 	return KErrNotSupported;
       
    64 	}
       
    65 
       
    66 /**
       
    67 Prints the content payload data structure to the logger
       
    68 Default implementation logs nothing and should be overridden
       
    69 */
       
    70 void CSuplPosPayload::LogMessageContent()
       
    71 	{
       
    72 	SUPLLOG(ELogP1, "CSuplPosPayload::LogMessageContent() Begin\n");
       
    73 	SUPLLOG(ELogP1, "CSuplPosPayload::LogMessageContent() End\n");
       
    74 	}
       
    75 
       
    76 /** 
       
    77 MessageType()
       
    78 
       
    79 @return the positioning payload message type
       
    80 */
       
    81 EXPORT_C CSuplPosPayload::TSuplPosPayloadType CSuplPosPayload::MessageType()
       
    82 	{
       
    83 	SUPLLOG(ELogP1, "CSuplPosPayload::MessageType() Begin\n");
       
    84 	SUPLLOG2(ELogP1, "CSuplPosPayload::MessageType() End (iMessageType = %d)\n", iMessageType);
       
    85 	return iMessageType;
       
    86 	}
       
    87 	
       
    88 /**
       
    89  * DecodePosPayload
       
    90  * 
       
    91  * decodes a pospayload and returns a CSuplPosPayload* (eg CRrlpMeasurePositionRequest*) containing the decoded rrlp payload 
       
    92  * 
       
    93  * @param aPosPayload	an asn1-encoded rrlp pos payload. Caller takes ownership.
       
    94  * @param aError		any error encountered 
       
    95  */
       
    96 EXPORT_C CSuplPosPayload* CSuplPosPayload::DecodePosPayloadL(const HBufC8* aPosPayload, TInt& aError)
       
    97 	{
       
    98 	SUPLLOG(ELogP1, "CSuplPosPayload::DecodePosPayloadL() Begin\n");	
       
    99 	
       
   100 	CSuplPosPayload *decodedRrlpMsg = NULL;
       
   101 	
       
   102 	const ASN1T_PosPayLoad_rrlpPayload* posPayLoad = reinterpret_cast<const ASN1T_PosPayLoad_rrlpPayload*>(aPosPayload);
       
   103 	
       
   104 	// extract the RRLP payload and decode and compare...
       
   105 	TInt payloadLength  = posPayLoad->numocts;
       
   106 	const OSOCTET* payloadptr = &posPayLoad->data[0];
       
   107 
       
   108 	// Create the payload decode buffer
       
   109     // CleanupDeletePushL used for ASN1x_X classes rather than CleanupStack::PushL() to ensure 
       
   110 	// class destructors are called on PopAndDestroy. This is necessary to ensure ASN1Context 
       
   111 	// reference counter is decremented correctly and memory released.
       
   112 	ASN1Context* payloadContext = new (ELeave) ASN1Context;
       
   113 	CleanupDeletePushL(payloadContext);
       
   114 	ASN1PERDecodeBuffer* decodeBuffer = new (ELeave) ASN1PERDecodeBuffer (payloadptr, payloadLength, FALSE, payloadContext);
       
   115 	// construction of iDecodeBuffer successful, pop payloadContext off the cleanup stack
       
   116 	CleanupStack::Pop(payloadContext);	// now owned by decodeBuffer
       
   117 	CleanupDeletePushL(decodeBuffer);	
       
   118 	
       
   119 	// Create data and control objects to manage the decode		
       
   120 	ASN1T_PDU* payloadData  = new (ELeave) ASN1T_PDU();
       
   121 	CleanupDeletePushL(payloadData);	
       
   122 	ASN1C_PDU* payloadPdu   = new (ELeave) ASN1C_PDU(*decodeBuffer, *payloadData);
       
   123 	CleanupDeletePushL(payloadPdu);
       
   124 	
       
   125 	TInt stat = payloadPdu->Decode();
       
   126 
       
   127 	// return now if error encountered while decoding
       
   128 	if (stat != KErrNone)
       
   129 		{
       
   130 		aError = RrlpUtils::ProcessAsn1Error(stat);
       
   131 		CleanupStack::PopAndDestroy(payloadPdu);
       
   132 		CleanupStack::PopAndDestroy(payloadData);
       
   133 		CleanupStack::PopAndDestroy(decodeBuffer);
       
   134 		return NULL;	
       
   135 		}
       
   136 
       
   137 	// build payload content wrapper.
       
   138 	switch (payloadData->component.t)
       
   139 		{
       
   140 		case T_RRLP_Component_msrPositionReq:
       
   141 			{
       
   142 			decodedRrlpMsg = CRrlpMeasurePositionRequest::NewL();	
       
   143 			break;
       
   144 			}
       
   145 			
       
   146 		case T_RRLP_Component_assistanceData:
       
   147 			{
       
   148 			decodedRrlpMsg = CRrlpAssistanceData::NewL();
       
   149 			break;
       
   150 			}
       
   151 
       
   152 		case T_RRLP_Component_protocolError:
       
   153 			{
       
   154 			decodedRrlpMsg = CRrlpProtocolError::NewL(EFalse);
       
   155 			break;
       
   156 			}
       
   157 
       
   158 		case T_RRLP_Component_msrPositionRsp:
       
   159 		case T_RRLP_Component_assistanceDataAck:
       
   160 		default:
       
   161 			{
       
   162 			// unsupported message type
       
   163 			aError = ESuplAsn1ErrUnsupportedPosMessageType;
       
   164 			CleanupStack::PopAndDestroy(payloadPdu);
       
   165 			CleanupStack::PopAndDestroy(payloadData);
       
   166 			CleanupStack::PopAndDestroy(decodeBuffer);
       
   167 			return NULL;	
       
   168 			}
       
   169 		}
       
   170 	
       
   171 	CleanupStack::Pop(payloadPdu);
       
   172 	CleanupStack::Pop(payloadData);
       
   173 	CleanupStack::PopAndDestroy(decodeBuffer);
       
   174 	
       
   175 	// pass ownership of the decoded message content.
       
   176 	static_cast<CRrlpMessageBase*>(decodedRrlpMsg)->SetDecodedData(payloadData, payloadPdu);
       
   177 			
       
   178 	SUPLLOG(ELogP1, "CSuplPosPayload::DecodePosPayloadL() End\n");
       
   179 	
       
   180 	return decodedRrlpMsg;
       
   181 		
       
   182 	}