bluetooth/btstack/avdtp/avdtpDirectChannel.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 "direct" (!muxed) transport channel object
       
    15 // 
       
    16 //
       
    17 
       
    18 /**
       
    19  @file
       
    20  @internalComponent
       
    21 */
       
    22 #include <bluetooth/logger.h>
       
    23 #include "avdtpDirectChannel.h"
       
    24 #include "avdtpTransportSession.h"
       
    25 #include "avdtp.h"
       
    26 #include "avdtputil.h"
       
    27 
       
    28 #ifdef __FLOG_ACTIVE
       
    29 _LIT8(KLogComponent, LOG_COMPONENT_AVDTP);
       
    30 #endif
       
    31 
       
    32 CDirectChannel* CDirectChannel::NewL(CAvdtpProtocol& aProtocol,
       
    33 						 	   		 const TBTDevAddr& aRemoteDevice)
       
    34 	{
       
    35 	LOG_STATIC_FUNC
       
    36 	CDirectChannel* s = new (ELeave) CDirectChannel(aProtocol, aRemoteDevice);
       
    37 	return s;
       
    38 	}
       
    39 
       
    40 
       
    41 CDirectChannel::CDirectChannel(CAvdtpProtocol& aProtocol,
       
    42 							   const TBTDevAddr& aRemoteDevice)
       
    43 : CTransportChannel(aProtocol, aRemoteDevice)
       
    44 	{
       
    45 	LOG_FUNC
       
    46 	}
       
    47 		
       
    48 TInt CDirectChannel::AttachTransportSession(CUserPlaneTransportSession& aSession, TAvdtpTransportSessionType /*aType*/)
       
    49 	{
       
    50 	LOG_FUNC
       
    51 	__ASSERT_DEBUG(!iTransportSession, Panic(EAVDTPBadSessionAttachToTransportChannel));
       
    52 	// don't care about session type for direct channels
       
    53 	iTransportSession = &aSession;
       
    54 	return KErrNone;
       
    55 	}
       
    56 	
       
    57 TBool CDirectChannel::CouldAttachSession(const TAvdtpSockAddr& /*aAddr*/)
       
    58 	{
       
    59 	LOG_FUNC
       
    60 	// for this channel we can take iff no session
       
    61 	return (iTransportSession == NULL);
       
    62 	}
       
    63 
       
    64 TTCID CDirectChannel::TCID() const
       
    65 	{
       
    66 	LOG_FUNC
       
    67 	return KDirectChannelTCID;
       
    68 	}
       
    69 
       
    70 CServProviderBase* CDirectChannel::ObtainSAP()
       
    71 	{
       
    72 	CServProviderBase* sap = iLogicalChannel;
       
    73 	iLogicalChannel = NULL;
       
    74 	return sap;
       
    75 	}
       
    76 
       
    77 void CDirectChannel::TransportSessionBlocked(TAvdtpTransportSessionType /*aSession*/, TBool aBlocked)
       
    78 	{
       
    79 	LOG_FUNC
       
    80 	LOG1(_L("TransportSession blocked(%d"), aBlocked);
       
    81 	iTransportSessionBlocked = aBlocked;
       
    82 	}
       
    83 	
       
    84 /**
       
    85 Just pass down directly to logical channel
       
    86 No marshalling of other sessions to do, and no framing so just go
       
    87 but this is by invite only! should check for this (only debug)
       
    88 */
       
    89 TUint CDirectChannel::SendPacket(TTSID /*aTSID*/, RMBufChain& aPacket)
       
    90 	{
       
    91 	LOG_FUNC
       
    92 	LOG1(_L("Packet length = %d bytes"), aPacket.Length());
       
    93 	return iLogicalChannel ? iLogicalChannel->Write(aPacket,0) : 0;
       
    94 	}
       
    95 	
       
    96 	
       
    97 // from logical channel
       
    98 
       
    99 /**
       
   100 To reduce copying just forward indication on
       
   101 Also this leaves the AV Sap or Session to work out what is best strategy to get data
       
   102 */
       
   103 void CDirectChannel::NewData(TUint aCount)
       
   104 	{
       
   105 	LOG_FUNC
       
   106 	if (iTransportSession)
       
   107 		{
       
   108 		RMBufChain chain;
       
   109 		TInt err = KErrNone;
       
   110 		while (aCount--)
       
   111 			{
       
   112 			err = iLogicalChannel->GetData(chain,0,0);  //returns negative error code or the number of datagrams ( = 1 )
       
   113 			if (err > 0)
       
   114 				{
       
   115 				iTransportSession->NewData(chain);
       
   116 				}
       
   117 			}
       
   118 		}
       
   119 	}
       
   120 
       
   121 void CDirectChannel::CanSend()
       
   122 /**
       
   123 upcall from logical channel (l2cap)
       
   124 */
       
   125 	{
       
   126 	LOG_FUNC
       
   127 	iTransportSession->CanSend();
       
   128 	}
       
   129 
       
   130 #ifdef _DEBUG	
       
   131 void CDirectChannel::DetachTransportSession(CUserPlaneTransportSession& aSession, TAvdtpTransportSessionType /*aType */)
       
   132 #else
       
   133 void CDirectChannel::DetachTransportSession(CUserPlaneTransportSession& /*aSession*/, TAvdtpTransportSessionType /*aType */)
       
   134 #endif
       
   135 	{
       
   136 	LOG_FUNC
       
   137 	__ASSERT_DEBUG(&aSession == iTransportSession, Panic(EAVDTPBadSessionDetachFromTransportChannel));
       
   138 	iTransportSession = NULL;
       
   139 	// closing logical channel is async - we die on CanClose
       
   140 	// but we're invalid, so tell protocol
       
   141 	Protocol().TransportChannelClosing(*this);
       
   142 	CloseLogicalChannel();
       
   143 	}
       
   144 	
       
   145 void CDirectChannel::Disconnect()
       
   146 /**
       
   147 	upcall from logical channel (l2cap)
       
   148 */
       
   149 	{
       
   150 	LOG_FUNC
       
   151 	iLogicalChannel = NULL;
       
   152 	if (iTransportSession)
       
   153 		{
       
   154 		iTransportSession->ChannelError(KErrDisconnected);
       
   155 		}
       
   156 	}
       
   157 	
       
   158 void CDirectChannel::Error(TInt aError, TUint /*aOperationMask*/)
       
   159 /**
       
   160 	upcall from logical channel (l2cap)
       
   161 */
       
   162 	{
       
   163 	LOG_FUNC
       
   164 	if (iTransportSession)
       
   165 		{
       
   166 		iTransportSession->ChannelError(aError);
       
   167 		}
       
   168 	}
       
   169 	
       
   170