bluetoothmgmt/bluetoothclientlib/avlib/avdtpCapabilities.cpp
changeset 0 29b1cd4cb562
equal deleted inserted replaced
-1:000000000000 0:29b1cd4cb562
       
     1 // Copyright (c) 2003-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  @publishedPartner
       
    19 */
       
    20 
       
    21 #include <bluetoothav.h>
       
    22 #include "gavdpinterface.h" // for mux capability
       
    23 
       
    24 /**TAvdtpServiceCapability() is for Symbian use only
       
    25 @internalTechnology
       
    26 */
       
    27 EXPORT_C TAvdtpServiceCapability::TAvdtpServiceCapability(TAvdtpServiceCategory aCategory, TInt aLOSC/*=KMaxTInt*/)
       
    28 : iLOSC(aLOSC), iCategory(aCategory)
       
    29 /*
       
    30 	Base class c'tor
       
    31 */
       
    32 	{
       
    33 	}
       
    34 
       
    35 /**Returns the category
       
    36 @see TAvdtpServiceCategory
       
    37 */
       
    38 EXPORT_C TAvdtpServiceCategory TAvdtpServiceCapability::Category() const
       
    39 	{
       
    40 	return iCategory;
       
    41 	}
       
    42 
       
    43 EXPORT_C /*virtual*/ void TAvdtpServiceCapability::Parse(const TDesC8&)
       
    44 	{
       
    45 	//This is the base implementation which is NULL as some caps
       
    46 	//just have their header.
       
    47 	}
       
    48 
       
    49 /**AllocFromPDUL() is for Symbian use only
       
    50 @internalTechnology
       
    51 */
       
    52 EXPORT_C /*static*/ TAvdtpServiceCapability* TAvdtpServiceCapability::AllocFromPDUL(TAvdtpServiceCategory aCat,
       
    53 																					const TDesC8& aDes)
       
    54 	{
       
    55 	TAvdtpServiceCapability* res=NULL;
       
    56 
       
    57 	switch (aCat)
       
    58 		{
       
    59 		case EServiceCategoryMediaTransport:
       
    60 			{
       
    61 			res = new (ELeave) TAvdtpMediaTransportCapabilities;
       
    62 			}
       
    63 			break;
       
    64 		case EServiceCategoryReporting:
       
    65 			{
       
    66 			res = new (ELeave) TAvdtpReportingCapabilities;
       
    67 			}
       
    68 			break;
       
    69 		case EServiceCategoryRecovery:
       
    70 			{
       
    71 			res = new (ELeave) TAvdtpRecoveryCapabilities;
       
    72 			}
       
    73 			break;
       
    74 		case EServiceCategoryContentProtection:
       
    75 			{
       
    76 			res = new (ELeave) TAvdtpContentProtectionCapabilities;
       
    77 			}
       
    78 			break;
       
    79 		case EServiceCategoryHeaderCompression:
       
    80 			{
       
    81 			res = new (ELeave) TAvdtpHeaderCompressionCapabilities;	
       
    82 			}
       
    83 			break;
       
    84 		case EServiceCategoryMultiplexing:
       
    85 			{
       
    86 			res = new (ELeave) TAvdtpMultiplexingCapability;
       
    87 			}
       
    88 			break;
       
    89 		case EServiceCategoryMediaCodec:
       
    90 			{
       
    91 			res = TAvdtpMediaCodecCapabilities::AllocCodecFromPDUL(aDes);
       
    92 			}
       
    93 			break;
       
    94 		default:
       
    95 			{
       
    96 			User::Leave(KErrNotSupported);
       
    97 			}
       
    98 		}
       
    99 	
       
   100 	if (res)
       
   101 		{
       
   102 		// got a class into which it can parse itself from the protocol
       
   103 		res->Parse(aDes); //non leaving
       
   104 		}
       
   105 	
       
   106 	return res;
       
   107 	}
       
   108 
       
   109 	
       
   110 /**AllocFromPckgL() is for Symbian use only
       
   111 @internalTechnology
       
   112 */
       
   113 EXPORT_C /*static*/ TAvdtpServiceCapability* TAvdtpServiceCapability::AllocFromPckgL(const TDesC8& aPackagedCap)
       
   114 	{
       
   115 	TInt len = aPackagedCap.Length();
       
   116 	TAny* buf = User::AllocL(len);
       
   117 	Mem::Copy(buf, aPackagedCap.Ptr(), len);
       
   118 	return reinterpret_cast<TAvdtpServiceCapability*>(buf);
       
   119 	}
       
   120 	
       
   121 	
       
   122 TInt TAvdtpServiceCapability::AddHeader(RBuf8& aBuffer) const
       
   123 /*
       
   124 	Small helper to factor growing of buffer, and addition of a header
       
   125 */
       
   126 	{
       
   127 	// check to see if variable LOSC capabilities have updated LOSC
       
   128 	__ASSERT_ALWAYS(iLOSC!=KMaxTInt, User::Invariant());
       
   129 	
       
   130 	TInt err = aBuffer.ReAlloc(aBuffer.Length()+iLOSC+KAvdtpServiceCapabilitiesHeaderLen);
       
   131 
       
   132 	if (err==KErrNone)
       
   133 		{
       
   134 		aBuffer.Append(iCategory);
       
   135 		aBuffer.Append(iLOSC);
       
   136 		}
       
   137 	
       
   138 	return err;
       
   139 	}
       
   140