bluetooth/btstack/avdtp/avdtpTransportChannel.cpp
changeset 0 29b1cd4cb562
child 22 786b94c6f0a4
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 // Implements the avdtp transport channel base class
       
    15 // 
       
    16 //
       
    17 
       
    18 /**
       
    19  @file
       
    20  @internalComponent
       
    21 */
       
    22 
       
    23 #include <bluetooth/logger.h>
       
    24 #include "avdtpTransportChannel.h"
       
    25 #include "avdtpDirectChannel.h"
       
    26 #include "avdtpMuxChannel.h"
       
    27 #include "avdtp.h"
       
    28 
       
    29 #ifdef __FLOG_ACTIVE
       
    30 _LIT8(KLogComponent, LOG_COMPONENT_AVDTP);
       
    31 #endif
       
    32 
       
    33 CTransportChannel::CTransportChannel(CAvdtpProtocol& aProtocol,
       
    34 							  		 const TBTDevAddr& aRemoteDevice)
       
    35 	: iProtocol(aProtocol),
       
    36 	  iRemoteDevice(const_cast<TBTDevAddr&>(aRemoteDevice))
       
    37 	{
       
    38 	LOG_FUNC
       
    39 	}
       
    40 	
       
    41 CTransportChannel::~CTransportChannel()
       
    42 	{
       
    43 	LOG_FUNC
       
    44 	iProtocol.TransportChannelDown(*this);
       
    45 
       
    46 	if (iLogicalChannel)
       
    47 		{
       
    48 		iLogicalChannel->Shutdown(CServProviderBase::EImmediate);
       
    49 		delete iLogicalChannel;
       
    50 		}
       
    51 	}
       
    52 
       
    53 /*static*/ CTransportChannel* CTransportChannel::NewDirectChannelL(CAvdtpProtocol& aProtocol,
       
    54 							  const TBTDevAddr& aRemoteDevice)
       
    55 	{
       
    56 	LOG_STATIC_FUNC
       
    57 	return CDirectChannel::NewL(aProtocol, aRemoteDevice);
       
    58 	}
       
    59 
       
    60 
       
    61 /*static*/ CTransportChannel* CTransportChannel::NewMuxChannelL(CAvdtpProtocol& aProtocol,
       
    62 							  const TBTDevAddr& aRemoteDevice,
       
    63 							  TTCID aRemotelyAssignedTCID/*=KInvalidTCID*/)
       
    64 	{
       
    65 	LOG_STATIC_FUNC
       
    66 	return CMuxChannel::NewL(aProtocol, aRemoteDevice, aRemotelyAssignedTCID);
       
    67 	}
       
    68 
       
    69 TInt CTransportChannel::SetOption(TUint aLevel, TUint aName, const TDesC8 &aOption)
       
    70 	{
       
    71 	LOG_FUNC
       
    72 	return iLogicalChannel->SetOption(aLevel, aName, aOption);
       
    73 	}
       
    74 
       
    75 void CTransportChannel::CanClose(TDelete aDelete)
       
    76 	{
       
    77 	LOG_FUNC
       
    78 	switch (aDelete)
       
    79 		{
       
    80 		case EDelete:
       
    81 			delete iLogicalChannel;
       
    82 		// fallthrough
       
    83 		default:
       
    84 			iLogicalChannel = NULL;
       
    85 		}
       
    86 	delete this;
       
    87 	}
       
    88 	
       
    89 void CTransportChannel::LogicalChannelComplete(TLogicalChannelRecord aLogicalChannelRecord, TInt aErr)
       
    90 	{
       
    91 	LOG_FUNC
       
    92 	if (aErr)
       
    93 		{
       
    94 		// try to tell any sessions present...
       
    95 		static_cast<MSocketNotify*>(this)->Disconnect();		
       
    96 		}
       
    97 	else
       
    98 		{
       
    99 		// take ownership
       
   100 		iLogicalChannel = aLogicalChannelRecord.iLogicalChannelSAP;
       
   101 		iLogicalChannel->SetNotify(this);
       
   102 		// drain any data
       
   103 		if (aLogicalChannelRecord.iDataCount)
       
   104 			{
       
   105 			NewData(aLogicalChannelRecord.iDataCount);
       
   106 			
       
   107 			if (aLogicalChannelRecord.iEndOfData)
       
   108 				{
       
   109 				NewData(KNewDataEndofData);
       
   110 				}
       
   111 			}
       
   112 		}
       
   113 	}
       
   114 	
       
   115 void CTransportChannel::AllowServices(TAvdtpAdaptationServices aServices)
       
   116 	{
       
   117 	LOG_FUNC
       
   118 	// retained by base class - the derivee can choose whether to use it
       
   119 	iAllowedServices = aServices;
       
   120 	}
       
   121 
       
   122 
       
   123 void CTransportChannel::CloseLogicalChannel()
       
   124 	{
       
   125 	LOG_FUNC
       
   126 	if (iLogicalChannel)
       
   127 		{
       
   128 		iLogicalChannel->Shutdown(CServProviderBase::ENormal);
       
   129 		}
       
   130 	else CanClose();
       
   131 	}
       
   132 
       
   133 
       
   134 TInt CTransportChannel::MaxPacketSize(TInt& aMTU)
       
   135 	{
       
   136 	LOG_FUNC
       
   137 	// default is just whatever l2cap is
       
   138 	TInt ret = KErrNotReady;
       
   139 	if (iLogicalChannel)
       
   140 		{
       
   141 		TPckg<TInt> mtuPckg(aMTU);
       
   142 		ret = iLogicalChannel->GetOption(KSolBtL2CAP, KL2CAPOutboundMTUForBestPerformance, mtuPckg);
       
   143 		}
       
   144 	else
       
   145 		{
       
   146 		aMTU = 0;
       
   147 		}
       
   148 	return ret;
       
   149 	}
       
   150 	
       
   151 TInt CTransportChannel::MaxReceivePacketSize(TInt& aMRU)
       
   152 	{
       
   153 	LOG_FUNC
       
   154 	// default is just whatever l2cap is
       
   155 	TInt ret = KErrNotReady;
       
   156 	if (iLogicalChannel)
       
   157 		{
       
   158 		TPckg<TInt> mruPckg(aMRU);
       
   159 		ret = iLogicalChannel->GetOption(KSolBtL2CAP, KL2CAPInboundMTU, mruPckg);
       
   160 		}
       
   161 	else
       
   162 		{
       
   163 		aMRU = 0;
       
   164 		}
       
   165 	return ret;
       
   166 	}