bluetooth/btsdp/database/EncoderVisitor.cpp
changeset 0 29b1cd4cb562
equal deleted inserted replaced
-1:000000000000 0:29b1cd4cb562
       
     1 // Copyright (c) 2000-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  @internalTechnology
       
    18  @released
       
    19 */
       
    20 
       
    21 #include "EncoderVisitor.h"
       
    22 #include <btsdp.h>
       
    23 #include "DataEncoder.h"
       
    24 #include "SDPDatabase.h"
       
    25 #include "sdputil.h"
       
    26 
       
    27 /** Creates a new CAttrEncoderVisitor and leaves it on the cleanup stack.
       
    28 
       
    29 @param aEncoder a TElementEncoder to be used by this CAttrEncoderVisitor.
       
    30 @return A new CAttrEncoderVisitor.
       
    31 */
       
    32 EXPORT_C CAttrEncoderVisitor *CAttrEncoderVisitor::NewLC(TElementEncoder aEncoder)
       
    33 	{
       
    34 	CAttrEncoderVisitor *self = new(ELeave) CAttrEncoderVisitor(aEncoder);
       
    35 	CleanupStack::PushL(self);
       
    36 	self->ConstructL();
       
    37 	return self;
       
    38 	}
       
    39 
       
    40 /** Creates a new CAttrEncoderVisitor.
       
    41 
       
    42 @param aEncoder a TElementEncoder to be used by this CAttrEncoderVisitor.
       
    43 @return A new CAttrEncoderVisitor.
       
    44 */
       
    45 EXPORT_C CAttrEncoderVisitor *CAttrEncoderVisitor::NewL(TElementEncoder aEncoder)
       
    46 	{
       
    47 	CAttrEncoderVisitor *self = CAttrEncoderVisitor::NewLC(aEncoder);
       
    48 	CleanupStack::Pop();
       
    49 	return self;
       
    50 	}
       
    51 
       
    52 CAttrEncoderVisitor::CAttrEncoderVisitor(TElementEncoder aEncoder)
       
    53 	: iEncoder(aEncoder)
       
    54 	{
       
    55 	}
       
    56 
       
    57 void CAttrEncoderVisitor::ConstructL()
       
    58 	{
       
    59 	}
       
    60 
       
    61 CAttrEncoderVisitor::~CAttrEncoderVisitor()
       
    62 	{
       
    63 	}
       
    64 
       
    65 /**
       
    66 Encode attribute in aSrcAttr into buffer supplied in the encoder.
       
    67 
       
    68 @param aEncoder A TElementEncoder with a buffer large enough to contain the 
       
    69 				encoded value.
       
    70 @leave ESdpUnexpectedAttributeValueType If the attribute is of an unknown type.
       
    71 @leave Positive value equal to the number of bytes of the encoded value which 
       
    72 	   did not fit in the write buffer of the TElementEncoder which is provided 
       
    73 	   as aEncoder.  To calculate the size of write buffer needed  use the 
       
    74 	   TElementEncoder::EncodedSize function.
       
    75 @see TElementEncoder::EncodedSize
       
    76 */
       
    77 EXPORT_C void CAttrEncoderVisitor::EncodeAttributeL(TElementEncoder aEncoder, CSdpAttrValue &aSrcAttr)
       
    78 	{
       
    79 	CAttrEncoderVisitor *self = CAttrEncoderVisitor::NewLC(aEncoder);
       
    80 	aSrcAttr.AcceptVisitorL(*self);
       
    81 	CleanupStack::PopAndDestroy();
       
    82 	}
       
    83 
       
    84 /**
       
    85 Encode attribute in aSrcAttr into buffer supplied at construction.
       
    86 
       
    87 @leave ESdpUnexpectedAttributeValueType If the attribute is of an unknown type.
       
    88 @leave Positive value equal to the number of bytes of the encoded value which 
       
    89 	   did not fit in the write buffer of the TElementEncoder.  This was provided 
       
    90 	   at construction.  To calculate the size of write buffer needed  use the 
       
    91 	   TElementEncoder::EncodedSize function.
       
    92 @see TElementEncoder::EncodedSize
       
    93 */
       
    94 EXPORT_C void CAttrEncoderVisitor::EncodeAttributeL(CSdpAttrValue &aSrcAttr)
       
    95 	{
       
    96 	aSrcAttr.AcceptVisitorL(*this);
       
    97 	}
       
    98 
       
    99 
       
   100 void CAttrEncoderVisitor::VisitAttributeL(CSdpAttr &aAttribute)
       
   101 	{
       
   102 	iEncoder.WriteUint(aAttribute.AttributeID(), sizeof(TSdpAttributeID));
       
   103 	}
       
   104 
       
   105 void CAttrEncoderVisitor::VisitAttributeValueL(CSdpAttrValue &aValue, TSdpElementType aType)
       
   106 	{
       
   107 	TUint rem=0;
       
   108 	switch(aType)
       
   109 		{
       
   110 	case ETypeNil:
       
   111 		rem = iEncoder.WriteNil();
       
   112 		break;
       
   113 	case ETypeUint:
       
   114 	case ETypeInt:
       
   115 	case ETypeUUID:
       
   116 	case ETypeString:
       
   117 	case ETypeURL:
       
   118 		rem = iEncoder.WriteElement(aType, aValue.Des());
       
   119 		break;
       
   120 	case ETypeBoolean:
       
   121 		rem = iEncoder.WriteBoolean(aValue.Bool());
       
   122 		break;
       
   123 	case ETypeDES:
       
   124 		rem = iEncoder.WriteDES(aValue.DataSize());
       
   125 		break;
       
   126 	case ETypeDEA:
       
   127 		rem = iEncoder.WriteDEA(aValue.DataSize());
       
   128 		break;
       
   129 	case ETypeEncoded:
       
   130 		rem= iEncoder.WriteDesc(aValue.Des());
       
   131 		break;
       
   132 	default:
       
   133 		User::Leave(ESdpUnexpectedAttributeValueType);
       
   134 		}
       
   135 
       
   136 
       
   137 	if (rem)
       
   138 		User::Leave(rem);
       
   139 	}
       
   140 
       
   141 void CAttrEncoderVisitor::StartListL(CSdpAttrValueList &/*aList*/)
       
   142 	{
       
   143 	}
       
   144 
       
   145 void CAttrEncoderVisitor::EndListL()
       
   146 	{
       
   147 	}
       
   148 
       
   149 
       
   150 
       
   151