bluetoothappprofiles/avrcp/remconbeareravrcp/src/browsingframe.cpp
changeset 70 f5508c13dfe0
parent 67 16e4b9007960
child 71 083fd884d7dd
equal deleted inserted replaced
67:16e4b9007960 70:f5508c13dfe0
     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 #include "browsingframe.h"
       
    17 
       
    18 
       
    19 /** Verifies the length of a frame is correct.  Checking:
       
    20 1) Header is present
       
    21 2) Data length indicated is present
       
    22 
       
    23 This does not semantically check that the data expected for
       
    24 the PDU ID is present.
       
    25 
       
    26 @param aFrame The frame to verify
       
    27 @leave KErrCorrupt if the length of the frame is incorrect
       
    28 */
       
    29 void AvrcpBrowsing::BrowsingFrame::VerifyFrameL(const TDesC8& aFrame)
       
    30 	{
       
    31 	if((aFrame.Length() < AvrcpBrowsing::KHeaderLength) ||
       
    32 	  (aFrame.Length() < (AvrcpBrowsing::KHeaderLength + ParamLength(aFrame))))
       
    33 		{
       
    34 		User::Leave(KErrCorrupt);
       
    35 		}
       
    36 	}
       
    37 
       
    38 
       
    39 /** Retreives the PDU ID from this frame.
       
    40 
       
    41 @pre The integrity of the frame must have been verified (@see 
       
    42 	 BrowsingFrame::VerifyFrameL) as the length is not checked
       
    43 	 before retrieving the PDU ID.
       
    44 @param aFrame The frame to retrieve the PDU ID for.
       
    45 @return The PDU ID of aFrame
       
    46 */
       
    47 AvrcpBrowsing::TPduId AvrcpBrowsing::BrowsingFrame::PduId(const TDesC8& aFrame)
       
    48 	{
       
    49 	return aFrame[0];
       
    50 	}
       
    51 
       
    52 /** Retreives the parameter length from this frame.
       
    53 
       
    54 @pre The integrity of the frame must have been verified (@see 
       
    55 	 BrowsingFrame::VerifyFrameL) as the length is not checked
       
    56 	 before retrieving the parameter length.
       
    57 @param aFrame The frame to retrieve the parameter length for.
       
    58 @return The parameter length of aFrame
       
    59 */
       
    60 TInt AvrcpBrowsing::BrowsingFrame::ParamLength(const TDesC8& aFrame)
       
    61 	{
       
    62 	TInt paramLength = 0;
       
    63 	paramLength += aFrame[2];
       
    64 	paramLength += ((TUint)aFrame[1]) << 8;
       
    65 	
       
    66 	return paramLength;
       
    67 	}
       
    68 
       
    69 /** Retreives the payload from this frame.
       
    70 
       
    71 @pre The integrity of the frame must have been verified (@see 
       
    72 	 BrowsingFrame::VerifyFrameL) as the length is not checked
       
    73 	 before retrieving the payload.
       
    74 @param aFrame The frame to retrieve the payload for.
       
    75 @param aPayload On return the payload of aFrame
       
    76 */
       
    77 void AvrcpBrowsing::BrowsingFrame::Payload(const TDesC8& aFrame, TPtrC8& aPayload)
       
    78 	{
       
    79 	aPayload.Set(aFrame.Mid(AvrcpBrowsing::KHeaderLength, AvrcpBrowsing::BrowsingFrame::ParamLength(aFrame)));
       
    80 	}
       
    81