bluetooth/btstack/avdtp/avdtpStream.h
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 // Defines the avdtp stream.  The stream appears when the SEPs have been configured
       
    15 // 
       
    16 //
       
    17 
       
    18 /**
       
    19  @file
       
    20  @internalComponent
       
    21 */
       
    22 
       
    23 #ifndef AVDTPSTREAM_H
       
    24 #define AVDTPSTREAM_H
       
    25 
       
    26 #include <bluetoothav.h>
       
    27 
       
    28 #include "bt.h"
       
    29 #include "avdtpTransportSession.h"
       
    30 #include "avdtpTransportChannel.h"
       
    31 #include "avdtpLogicalChannelFactory.h"
       
    32 #include "avdtpServiceInterface.h"
       
    33 #include "avdtpSEPCache.h"
       
    34 #include "avdtpAllocators.h"
       
    35 #include "avdtputil.h"
       
    36 
       
    37 // when rationalising logging, will not need this to get FLOG_ACTIVE MACRO in this header
       
    38 #include <comms-infras/commsdebugutility.h>
       
    39 
       
    40 class CAVStream;
       
    41 class CSignallingSession;
       
    42 class CTransportSession;
       
    43 class CUserPlaneTransportSession;
       
    44 class CAvdtpSAP;
       
    45 class CAvdtpProtocol;
       
    46 class TAVStreamState;
       
    47 class CAVStreamStateFactory;
       
    48 class CLocalSEP;
       
    49 class CWatchdogTimer;
       
    50 
       
    51 #ifdef _OOM_TEST
       
    52 const TInt KAvdtpLogicalChannelsWatchdogTimeout = 50000; 
       
    53 #else
       
    54 const TInt KAvdtpLogicalChannelsWatchdogTimeout = 30000000; //30s	
       
    55 #endif
       
    56 
       
    57 /**
       
    58 Interface for upcalls from stream to signalling session
       
    59 */
       
    60 class MAvdtpStreamNotify
       
    61 	{
       
    62 public:
       
    63 	virtual void StreamStarted(TSEID aLocalSEID) =0;
       
    64 	virtual void StreamSuspended(TSEID aLocalSEID) =0;
       
    65 	virtual void StreamAccepted(TSEID aLocalSEID, TSEID aRemoteSEID, TBool aWithReporting, TBool aWithRecovery) =0;
       
    66 	virtual void StreamConfigured(TSEID aLocalSEID, TInt aError, TAvdtpServiceCategory aFailedCategory) =0;
       
    67 	virtual void StreamInitiatedServiceFailed(const CAVStream& aStream, TInt aError) =0;
       
    68 	virtual void StreamReadyForStartIndication(const TAvdtpTransactionLabel aLabel, const TSEID aSeid) =0;
       
    69 	};
       
    70 
       
    71 #ifdef __FLOG_ACTIVE
       
    72 #define STATENAME(statename) iName = _L(statename);
       
    73 #else
       
    74 #define STATENAME(statename)
       
    75 #endif
       
    76 
       
    77 NONSHARABLE_CLASS(TPendingStreamDetails)
       
    78 	{
       
    79 public:
       
    80 	TPendingStreamDetails()
       
    81 		{
       
    82 		Reset();
       
    83 		};
       
    84 		
       
    85 	void Reset() 
       
    86 		{
       
    87 		iLocalSEP = NULL;
       
    88 		iStreamNotify = NULL;
       
    89 		iRemoteSEID.Reset();
       
    90 		};
       
    91 		
       
    92 	CLocalSEP* iLocalSEP; //non-owned
       
    93 	MAvdtpStreamNotify* iStreamNotify; // non-owned
       
    94 	TSEID iRemoteSEID;
       
    95 	TBool iRequireReporting;
       
    96 	TBool iRequireRecovery;
       
    97 	};
       
    98 
       
    99 /**
       
   100 	This class knows which SAPs constitute 1 stream
       
   101 	SAPs can therefore use this to propagate important matters
       
   102 	e.g. Coordinating sends to MUX? Flushing?
       
   103 	
       
   104 	Instances of this class appear during the signalling phase
       
   105 	When endpoints have been discovered, the GC will Select a SEP
       
   106 	which will cause a CAVStream to be instantiated.
       
   107 	
       
   108 	The stream then needs to be told of the capabilities that have been selected
       
   109 	If remote supports MUX then we always choose to use that
       
   110 	
       
   111 	Once the stream is told it knows how many sessions will be required.
       
   112 	
       
   113 */
       
   114 
       
   115 NONSHARABLE_CLASS(CAVStream) : public CBase, public XLogicalChannelFactoryClient,
       
   116 								public XAvdtpSignalReceiver
       
   117 	{
       
   118 friend class CAvdtpProtocol;
       
   119 friend class CWatchdogTimer;
       
   120 friend class CSignallingSession;
       
   121 friend class TAVStreamState;
       
   122 friend class TAVStreamStateIdle;
       
   123 friend class TAVStreamStateOpening;
       
   124 friend class TAVStreamStateReleasing;
       
   125 friend class TAVStreamStateAborting;
       
   126 friend class TAVStreamStateCreatingLogicalChannels;
       
   127 friend class TAVStreamStateWaitingForLogicalChannels;
       
   128 friend class TAVStreamStateOpen;
       
   129 friend class TAVStreamStateReady;
       
   130 friend class TAVStreamStateWaitForSessions;
       
   131 friend class TAVStreamStateStreaming;
       
   132 friend class TAVStreamStateConfiguring;
       
   133 friend class TAVStreamStateConfigured;
       
   134 friend class TAVStreamStateINTConfigured;
       
   135 friend class TAVStreamStateACPConfigured;
       
   136 friend class TAVStreamStateReconfiguring;
       
   137 friend class TAVStreamStateStarting;
       
   138 friend class TAVStreamStateSuspending;
       
   139 friend class TAVStreamStateWaitForSessionsStartReceived;
       
   140 
       
   141 public:
       
   142 	static CAVStream* NewL(const TAvdtpSockAddr& aAddr,
       
   143 					 MAvdtpStreamNotify& aStreamNotify,
       
   144 					 CAvdtpProtocol& aProtocol,
       
   145 					 CLocalSEP& aLocalSEP);
       
   146 	~CAVStream();
       
   147 	void NotifyUserPlaneTransportSessionsError(CUserPlaneTransportSession* aErroredSession, TInt aError);
       
   148 	void LocalSEPDestroyed(const CLocalSEP& aTerminator);
       
   149 	
       
   150 	TInt AddSession(TAvdtpTransportSessionType aType,
       
   151 					CUserPlaneTransportSession& aSession,
       
   152 					CTransportChannel*& aTransportChannel);
       
   153 	void DropSession(TAvdtpTransportSessionType aType, CUserPlaneTransportSession& aSession);
       
   154 	void ClearSession(CUserPlaneTransportSession& aSession);
       
   155 
       
   156 	inline TSEID LocalSEID() const;
       
   157 	inline TSEID RemoteSEID() const;
       
   158 	inline TBTDevAddr DeviceAddress() const;
       
   159 	void CanMuxFrag(TBool& aCanMux, TBool& aCanFrag) const;	
       
   160 	TBool CheckConfigured(TAvdtpServiceCategory aCategory) const;
       
   161 	void GetTSID(RTSID& aTSID, TAvdtpTransportSessionType aSessionType);
       
   162 	TBool MultiplexingConfigured() const;
       
   163 	
       
   164 // INT stuff
       
   165 	void SetConfigurationL(RBuf8& aPacketBuffer,
       
   166 							CSignallingChannel& aSignallingChannel,
       
   167 							TBool aReportingConfigured,
       
   168 							TBool aRecoveryConfigured);
       
   169 	TInt Start();
       
   170 	TInt Suspend();
       
   171 	
       
   172 // ACP stuff
       
   173 	void Configured();
       
   174 	void AwaitLogicalChannelsL();
       
   175 	void Started();
       
   176 	void Suspended();
       
   177 	TBool IsStreaming() const;
       
   178 	TInt StartIndication(TAvdtpTransactionLabel aLabel, TSEID aSeid);
       
   179 	TBool IsHostEncryptionKeyRefreshPrevented();
       
   180 	
       
   181 private:
       
   182 	CAVStream(const TAvdtpSockAddr& aAddr,
       
   183 				MAvdtpStreamNotify& aStreamNotify,
       
   184 				CAvdtpProtocol& aProtocol,
       
   185 				CLocalSEP& aLocalSEP);
       
   186 	void ConstructL();
       
   187 
       
   188 private:
       
   189 	void LogicalChannelFactoryRequestComplete(TLogicalChannelFactoryTicket aTicket, TInt aResult);
       
   190 	void BindLogicalAndTransportChannels(TLogicalChannelFactoryTicket aTicket, TInt aError);
       
   191 	void TransportChannelsReady();
       
   192 	TAvdtpMultiplexingCapability* CreateMuxCapabilityL(TBool aRequireReporting, TBool aRequireRecovery, CSignallingChannel& aIDProvider);
       
   193 	void DeallocateUnclaimedTransportSessionIDs();
       
   194 // signalling channel callbacks
       
   195 	virtual void OpenConfirm(TInt aResult, TSEID aSEID);
       
   196 	virtual void ReleaseConfirm(TInt aResult, TSEID aSEID);
       
   197 	virtual void StartConfirm(TInt aResult, TSEID aRemoteSEID);
       
   198 	virtual void SuspendConfirm(TInt aResult, TSEID aRemoteSEID);
       
   199 	virtual void SetConfigConfirm(TInt aResult, TSEID aRemoteSEID, TAvdtpServiceCategory aFailedCategory);
       
   200 	virtual void ReconfigConfirm(TInt aResult, TSEID aRemoteSEID, TAvdtpServiceCategory aFailedCategory);
       
   201 	virtual void AbortConfirm(TSEID aRemoteSEID);
       
   202 	void ReadyForStartIndication();
       
   203 	void Release();		// initiate release proceedings, eg SEP has been destroyed
       
   204 	void Released();	// release proceedings completed
       
   205 	// the watchdog guards against failed creation/reception of transport channels
       
   206 	void StartWatchdog();
       
   207 	void StopWatchdog();
       
   208 	void WatchdogFired();
       
   209 	void TryToAndThenPreventHostEncryptionKeyRefresh();
       
   210 	void AllowHostEncryptionKeyRefresh();
       
   211 	
       
   212 private:
       
   213 	NONSHARABLE_STRUCT(TStartDetails)
       
   214 		{
       
   215 	public:
       
   216 		TAvdtpTransactionLabel 	iLabel;
       
   217 		TSEID iSeid;
       
   218 		};
       
   219 
       
   220 private:
       
   221 	CAvdtpProtocol&		iProtocol;
       
   222 
       
   223 	MAvdtpStreamNotify& iStreamNotify;
       
   224 
       
   225 	TTransportBinding	iMediaBinding;
       
   226 	TTransportBinding	iReportingBinding;
       
   227 	TTransportBinding	iRecoveryBinding;
       
   228 	
       
   229 	TFixedArray<RTSID, 3>	iMuxedTSIDs; // fixed to make easier to access by sessiontype
       
   230 
       
   231 	TAvdtpSockAddr		iRemoteAddress;	// devaddr and RemoteSEID
       
   232 	CLocalSEP*			iLocalSEP;		// NULL if the SEP is destroyed and we need to Release
       
   233 
       
   234 	TInt				iNumSessionsRequired; // the number that constitute this stream
       
   235 	// iNumSessions is used to determine when transportchannels should be activated/shutdown
       
   236 	const TAVStreamState*		iState;		// non-owned
       
   237 
       
   238 	TLogicalChannelFactoryTicket iFactoryJob;
       
   239 	
       
   240 	CWatchdogTimer*		iWatchdogTimer;
       
   241 	TStartDetails	iStartDetails;
       
   242 	TThreadPriority iOriginalESockBTPriority;
       
   243 	TBool			iNotifiedACLStreamActive;
       
   244 	TDblQueLink			iProtocolQLink;
       
   245 	//First try to refresh the encrption key and then prevent it from refreshing in future untill
       
   246 	//we allow it later. This is done so that we do not (or forced by controller) refresh the encryption key 
       
   247 	//in the middle of streaming audio data. 
       
   248 	MBluetoothControlPlaneToken*	iTryToAndThenPreventHostEncryptionKeyRefreshToken;
       
   249 	};
       
   250 	
       
   251 
       
   252 NONSHARABLE_CLASS(CWatchdogTimer) : public CTimer
       
   253 	{
       
   254 public:
       
   255 	static CWatchdogTimer* NewL(CAVStream& aObserver);
       
   256 private:
       
   257 	CWatchdogTimer(CAVStream& aObserver);
       
   258 	void RunL();
       
   259 	void ConstructL();
       
   260 private:
       
   261 	CAVStream& iObserver;
       
   262 	};
       
   263 
       
   264 NONSHARABLE_CLASS(CAVStreamStateFactory) : public CBase
       
   265 	{
       
   266 public:
       
   267 	static CAVStreamStateFactory* NewL();
       
   268 	enum TAVStreamStates
       
   269 		{
       
   270 		EStreamStateIdle,
       
   271 		EStreamStateConfiguring,
       
   272 		EStreamStateINTConfigured,
       
   273 		EStreamStateACPConfigured,
       
   274 		EStreamStateOpening,
       
   275 		EStreamStateWaitForSessions,
       
   276 		EStreamStateOpen, // AVDTP Open transaction performed
       
   277 		EStreamStateReady, // all logical channels in place
       
   278 		EStreamStateReleasing,
       
   279 		EStreamStateAborting,
       
   280 		EStreamStateStreaming,
       
   281 		EStreamStateWaitingForLogicalChannels,
       
   282 		EStreamStateCreatingLogicalChannels,
       
   283 		EStreamStateSuspending,
       
   284 		EStreamStateStarting,
       
   285 		EStreamStateReconfiguring,
       
   286 		EStreamStateWaitForSessionsStartReceived,
       
   287 	// *** keep next one last ***
       
   288 		EStreamMaxState,
       
   289 		};
       
   290 	const TAVStreamState& GetState(TAVStreamStates aState) const;
       
   291 	TInt StateIndex(const TAVStreamState* aState) const;
       
   292 	~CAVStreamStateFactory();
       
   293 private:
       
   294 	void ConstructL();
       
   295 	TFixedArray<TAVStreamState*, EStreamMaxState> iStates;
       
   296 	};
       
   297 	
       
   298 NONSHARABLE_CLASS(TAVStreamState)
       
   299 	{
       
   300 public:
       
   301 	virtual void Release(CAVStream& aStream) const;
       
   302 	virtual void LogicalChannelsAvailable(CAVStream& aStream, TLogicalChannelFactoryTicket aTicket, TInt aErr) const;
       
   303 	virtual TInt AddSession(CAVStream& aStream, 
       
   304 							TAvdtpTransportSessionType aType,
       
   305 							CUserPlaneTransportSession& aSession,
       
   306 							CTransportChannel*& aTransportChannel) const;
       
   307 	virtual void DropSession(CAVStream& aStream, TAvdtpTransportSessionType aType,
       
   308 							 CUserPlaneTransportSession& aSession) const;
       
   309 	
       
   310 // INT stuff
       
   311 	virtual void SetConfigurationL(CAVStream& aStream, 
       
   312 									RBuf8& aPacketBuffer,
       
   313 									CSignallingChannel& aSignallingChannel,
       
   314 									TBool aReportingConfigured,
       
   315 									TBool aRecoveryConfigured) const;
       
   316 
       
   317 	// forwarded from service_interface
       
   318 	virtual void SetConfigConfirm(CAVStream& aStream, TInt aResult, TSEID aRemoteSEID, TAvdtpServiceCategory aFailedCategory) const;
       
   319 	virtual void ReconfigConfirm(CAVStream& aStream, TInt aResult, 
       
   320 									TSEID aRemoteSEID, TAvdtpServiceCategory aFailedCategory) const;
       
   321 	virtual void StartConfirm(CAVStream& aStream, TInt aResult, TSEID aRemoteSEID) const;
       
   322 	virtual void SuspendConfirm(CAVStream& aStream, TInt aResult, TSEID aRemoteSEID) const;
       
   323 	virtual void OpenConfirm(CAVStream& aStream, TInt aResult, TSEID aSEID) const;
       
   324 	virtual void ReleaseConfirm(CAVStream& aStream, TInt aResult, TSEID aSEID) const;
       
   325 	virtual void AbortConfirm(CAVStream& aStream, TSEID aRemoteSEID) const;
       
   326 	virtual TInt Start(CAVStream& aStream) const;
       
   327 	virtual TInt Suspend(CAVStream& aStream) const;
       
   328 
       
   329 // ACP stuff
       
   330 	virtual void Configured(CAVStream& aStream) const;
       
   331 	virtual void AwaitLogicalChannelsL(CAVStream& aStream) const;
       
   332 	virtual TBool IsStreaming(const CAVStream& aStream) const;
       
   333 	virtual TInt StartReceived(CAVStream& aStream) const;
       
   334 	virtual void Started(CAVStream& aStream) const;
       
   335 	virtual void Suspended(CAVStream& aStream) const;
       
   336 
       
   337 	virtual void Enter(CAVStream& aStream) const;
       
   338 	virtual void Exit(CAVStream& aStream) const;
       
   339 	virtual void WatchdogFired(CAVStream& aStream) const;
       
   340 
       
   341 protected:
       
   342 	TAVStreamState(CAVStreamStateFactory& aFactory);
       
   343 	void ChangeState(CAVStream& aContext, CAVStreamStateFactory::TAVStreamStates aState) const;
       
   344 	void PanicInState(TAvdtpPanic aPanic) const;
       
   345 protected:
       
   346 	CAVStreamStateFactory&	iFactory;
       
   347 #ifdef __FLOG_ACTIVE
       
   348 	TBuf<32>				iName;
       
   349 #endif
       
   350 	};
       
   351 
       
   352 /**
       
   353 State when:
       
   354 Stream object initially created (either INT or ACP)
       
   355 Or after configured: reason is that the remote may have got a GetConfig
       
   356 and been happy with configuration, so no need for it to configure
       
   357 */ 
       
   358 NONSHARABLE_CLASS(TAVStreamStateIdle) : public TAVStreamState
       
   359 	{
       
   360 public:
       
   361 	TAVStreamStateIdle(CAVStreamStateFactory& aFactory);
       
   362 	
       
   363 	virtual void SetConfigurationL(CAVStream& aStream, 
       
   364 							RBuf8& aPacketBuffer,
       
   365 							CSignallingChannel& aSignallingChannel,
       
   366 							TBool aReportingConfigured,
       
   367 							TBool aRecoveryConfigured) const;
       
   368 	virtual void Configured(CAVStream& aStream) const;
       
   369 	virtual void Enter(CAVStream& aStream) const;
       
   370 private:
       
   371 	};
       
   372 
       
   373 NONSHARABLE_CLASS(TAVStreamStateConfiguring) : public TAVStreamStateIdle
       
   374 	{
       
   375 public:
       
   376 	TAVStreamStateConfiguring(CAVStreamStateFactory& aFactory);
       
   377 	virtual void SetConfigConfirm(CAVStream& aStram, TInt aResult, TSEID aRemoteSEID, TAvdtpServiceCategory aFailedCategory) const;
       
   378 	virtual void Enter(CAVStream& aStream) const;
       
   379 	};
       
   380 
       
   381 /*
       
   382 Abstract state to get common Release event for INT and ACPConfigured states
       
   383 Since abstract, this isn't added as a state in the state factory
       
   384 */
       
   385 NONSHARABLE_CLASS(TAVStreamStateConfigured) : public TAVStreamStateIdle
       
   386 	{
       
   387 public:
       
   388 	virtual void Release(CAVStream& aStream) const;	
       
   389 	virtual void Enter(CAVStream& aStream) const;
       
   390 protected:
       
   391 	TAVStreamStateConfigured(CAVStreamStateFactory& aFactory);	
       
   392 	};
       
   393 	
       
   394 NONSHARABLE_CLASS(TAVStreamStateINTConfigured) : public TAVStreamStateConfigured
       
   395 	{
       
   396 public:
       
   397 	TAVStreamStateINTConfigured(CAVStreamStateFactory& aFactory);
       
   398 	virtual TInt AddSession(CAVStream& aStream,
       
   399 					TAvdtpTransportSessionType aType,
       
   400 					CUserPlaneTransportSession& aSession,
       
   401 					CTransportChannel*& aChannel) const;
       
   402 	virtual void DropSession(CAVStream& aStream, TAvdtpTransportSessionType aType,
       
   403 					 CUserPlaneTransportSession& aSession) const;
       
   404 	virtual void SetConfigurationL(CAVStream& aStream, 
       
   405 									RBuf8& aPacketBuffer,
       
   406 									CSignallingChannel& aSignallingChannel,
       
   407 									TBool aReportingConfigured,
       
   408 									TBool aRecoveryConfigured) const;
       
   409 	virtual void Enter(CAVStream& aStream) const;
       
   410 private:
       
   411 	void TryToOpen(CAVStream& aStream) const;
       
   412 	};
       
   413 
       
   414 NONSHARABLE_CLASS(TAVStreamStateACPConfigured) : public TAVStreamStateConfigured
       
   415 	{
       
   416 public:
       
   417 	TAVStreamStateACPConfigured(CAVStreamStateFactory& aFactory);
       
   418 	virtual void AwaitLogicalChannelsL(CAVStream& aStream) const;
       
   419 	TInt AddSession(CAVStream& aStream, 
       
   420 							TAvdtpTransportSessionType aType,
       
   421 							CUserPlaneTransportSession& aSession,
       
   422 							CTransportChannel*& aTransportChannel) const;
       
   423 	virtual void Enter(CAVStream& aStream) const;
       
   424 private:
       
   425 	void TryToOpen(CAVStream& aStream) const;
       
   426 	void DoAwaitDirectChannelsL(CAVStream& aStream,
       
   427 								TBool aRequireReporting,
       
   428 								TBool aRequireRecovery) const;
       
   429 	void DoAwaitMuxedChannelsL(CAVStream& aStream,
       
   430 							    TAvdtpMultiplexingCapabilityHelper& aHelper,
       
   431 								TBool aRequireReporting,
       
   432 								TBool aRequireRecovery) const;
       
   433 	};
       
   434 	
       
   435 NONSHARABLE_CLASS(TAVStreamStateWaitForSessions) : public TAVStreamStateIdle
       
   436 	{
       
   437 public:
       
   438 	TAVStreamStateWaitForSessions(CAVStreamStateFactory& aFactory);
       
   439 	
       
   440 	virtual TInt AddSession(CAVStream& aStream,
       
   441 					TAvdtpTransportSessionType aType,
       
   442 					CUserPlaneTransportSession& aSession,
       
   443 					CTransportChannel*& aChannel) const;
       
   444 				
       
   445 	virtual TInt StartReceived(CAVStream& aStream) const;
       
   446 	virtual void Enter(CAVStream& aStream) const;
       
   447 	};
       
   448 
       
   449 NONSHARABLE_CLASS(TAVStreamStateWaitForSessionsStartReceived) : public TAVStreamStateWaitForSessions
       
   450 	{
       
   451 public:
       
   452 	TAVStreamStateWaitForSessionsStartReceived(CAVStreamStateFactory& aFactory);
       
   453 	
       
   454 	virtual TInt AddSession(CAVStream& aStream,
       
   455 					TAvdtpTransportSessionType aType,
       
   456 					CUserPlaneTransportSession& aSession,
       
   457 					CTransportChannel*& aChannel) const;
       
   458 	
       
   459 	virtual TInt StartReceived(CAVStream& aStream) const;
       
   460 	virtual void Enter(CAVStream& aStream) const;
       
   461 	};
       
   462 	
       
   463 NONSHARABLE_CLASS(TAVStreamStateOpening) : public TAVStreamStateIdle
       
   464 	{
       
   465 public:
       
   466 	TAVStreamStateOpening(CAVStreamStateFactory& aFactory);
       
   467 	virtual void OpenConfirm(CAVStream& aStream, TInt aResult, TSEID aRemoteSEID) const;
       
   468 	virtual void DropSession(CAVStream& aStream, TAvdtpTransportSessionType aType, CUserPlaneTransportSession& aSession) const;
       
   469 	virtual void Enter(CAVStream& aStream) const;
       
   470 	};
       
   471 	
       
   472 	
       
   473 NONSHARABLE_CLASS(TAVStreamStateOpen) : public TAVStreamStateIdle
       
   474 	{
       
   475 public:
       
   476 	TAVStreamStateOpen(CAVStreamStateFactory& aFactory);
       
   477 	virtual void Release(CAVStream& aStream) const;
       
   478 	virtual void DropSession(CAVStream& aStream, TAvdtpTransportSessionType aType, CUserPlaneTransportSession& aSession) const;
       
   479 	virtual void Enter(CAVStream& aStream) const;
       
   480 private:
       
   481 	void DoRelease(CAVStream& aStream) const;	
       
   482 	};
       
   483 
       
   484 /**
       
   485 Ready state is 'GAVDP Open' + Transport channels connected.
       
   486 This state is required to make up for the big difference between having got an error-free
       
   487 AVDTP Open response (thus "open") and the successful subsequent transport channel connection, and session attachment
       
   488 which once complete means we are open, ready for moving to streaming, or reconfiguring
       
   489 */
       
   490 NONSHARABLE_CLASS(TAVStreamStateReady) : public TAVStreamStateOpen
       
   491 	{
       
   492 public:
       
   493 	TAVStreamStateReady(CAVStreamStateFactory& aFactory);
       
   494 	virtual TInt AddSession(CAVStream& aStream,
       
   495 			TAvdtpTransportSessionType aType,
       
   496 			CUserPlaneTransportSession& aSession,
       
   497 			CTransportChannel*& aChannel) const;
       
   498 	// next pertains to reconfiguration
       
   499 	void SetConfigurationL(CAVStream& aStream, 
       
   500 									RBuf8& aPacketBuffer,
       
   501 									CSignallingChannel& aSignallingChannel,
       
   502 									TBool aReportingConfigured,
       
   503 									TBool aRecoveryConfigured) const;
       
   504 	virtual TInt StartReceived(CAVStream& aStream) const;
       
   505 	virtual TInt Start(CAVStream& aStream) const;
       
   506 	virtual void Started(CAVStream& aStream) const;
       
   507 	virtual void Enter(CAVStream& aStream) const;
       
   508 	};
       
   509 
       
   510 /**
       
   511 Waiting for Logical Channels happens after we have got a AVDTP Open and sent Response
       
   512 */
       
   513 NONSHARABLE_CLASS(TAVStreamStateWaitingForLogicalChannels) : public TAVStreamStateOpen
       
   514 	{
       
   515 public:
       
   516 	TAVStreamStateWaitingForLogicalChannels(CAVStreamStateFactory& aFactory);
       
   517 	virtual void Enter(CAVStream& aStream) const;
       
   518 	virtual void LogicalChannelsAvailable(CAVStream& aStream, TLogicalChannelFactoryTicket aTicket, TInt aErr) const;
       
   519 	virtual void Exit(CAVStream& aStream) const;
       
   520 	virtual void WatchdogFired(CAVStream& aStream) const;
       
   521 	virtual void DropSession(CAVStream& aStream, TAvdtpTransportSessionType aType, CUserPlaneTransportSession& aSession) const;
       
   522 	};
       
   523 	
       
   524 /**
       
   525 Creating Logical Channels happens after we have got a AVDTP Open Response back
       
   526 */
       
   527 NONSHARABLE_CLASS(TAVStreamStateCreatingLogicalChannels) : public TAVStreamStateOpen
       
   528 	{
       
   529 public:
       
   530 	TAVStreamStateCreatingLogicalChannels(CAVStreamStateFactory& aFactory);
       
   531 	virtual void LogicalChannelsAvailable(CAVStream& aStream, TLogicalChannelFactoryTicket aTicket, TInt aErr) const;
       
   532 	virtual void Enter(CAVStream& aStream) const;
       
   533 	};
       
   534 
       
   535 NONSHARABLE_CLASS(TAVStreamStateReconfiguring) : public TAVStreamStateReady
       
   536 	{
       
   537 public:
       
   538 	TAVStreamStateReconfiguring(CAVStreamStateFactory& aFactory);
       
   539 	virtual void ReconfigConfirm(CAVStream& aStram, TInt aResult, TSEID aRemoteSEID, TAvdtpServiceCategory aFailedCategory) const;
       
   540 	virtual void Enter(CAVStream& aStream) const;
       
   541 	};
       
   542 
       
   543 NONSHARABLE_CLASS(TAVStreamStateReleasing) : public TAVStreamStateReady
       
   544 	{
       
   545 public:
       
   546 	TAVStreamStateReleasing(CAVStreamStateFactory& aFactory);
       
   547 	virtual void Release(CAVStream& aStream) const;
       
   548 	virtual void ReleaseConfirm(CAVStream& aStream, TInt aResult, TSEID aSEID) const;
       
   549 	virtual void DropSession(CAVStream& aStream, TAvdtpTransportSessionType aType, CUserPlaneTransportSession& aSession) const;
       
   550 	virtual void Enter(CAVStream& aStream) const;
       
   551 	};
       
   552 
       
   553 /*
       
   554 Rarely entered state - required to gracefully release a Configured, but UnOpened, stream
       
   555 **/
       
   556 NONSHARABLE_CLASS(TAVStreamStateAborting) : public TAVStreamStateReady
       
   557 	{
       
   558 public:
       
   559 	TAVStreamStateAborting(CAVStreamStateFactory& aFactory);
       
   560 	virtual void Release(CAVStream& aStream) const;
       
   561 	virtual void AbortConfirm(CAVStream& aStream, TSEID aRemoteSEID) const;
       
   562 	virtual void Enter(CAVStream& aStream) const;
       
   563 	};
       
   564 
       
   565 	
       
   566 NONSHARABLE_CLASS(TAVStreamStateStarting) : public TAVStreamStateReady
       
   567 	{
       
   568 public:
       
   569 	TAVStreamStateStarting(CAVStreamStateFactory& aFactory);
       
   570 	virtual void StartConfirm(CAVStream& aStream, TInt aResult, TSEID aSEID) const;
       
   571 	virtual TInt StartReceived(CAVStream& aStream) const;
       
   572 	virtual void Enter(CAVStream& aStream) const;
       
   573 	};
       
   574 	
       
   575 NONSHARABLE_CLASS(TAVStreamStateStreaming) : public TAVStreamStateReady
       
   576 	{
       
   577 public:
       
   578 	TAVStreamStateStreaming(CAVStreamStateFactory& aFactory);
       
   579 	virtual TInt Suspend(CAVStream& aStream) const;
       
   580 	virtual TBool IsStreaming(const CAVStream& aStream) const;
       
   581 	virtual void Suspended(CAVStream& aStream) const;
       
   582 	virtual TInt Start(CAVStream& aStream) const;
       
   583 	virtual void Enter(CAVStream& aStream) const;
       
   584 	virtual void Exit(CAVStream& aStream) const;
       
   585 	virtual TInt StartReceived(CAVStream& aStream) const;
       
   586 	};
       
   587 
       
   588 NONSHARABLE_CLASS(TAVStreamStateSuspending) : public TAVStreamStateReady
       
   589 	{
       
   590 public:
       
   591 	TAVStreamStateSuspending(CAVStreamStateFactory& aFactory);
       
   592 	virtual void SuspendConfirm(CAVStream& aStream, TInt aResult, TSEID aRemoteSEID) const;
       
   593 	virtual void Suspended(CAVStream& aStream) const;
       
   594 	virtual void Enter(CAVStream& aStream) const;
       
   595 	};
       
   596 
       
   597 inline TBTDevAddr CAVStream::DeviceAddress() const
       
   598 	{
       
   599 	return iRemoteAddress.BTAddr();
       
   600 	}
       
   601 	
       
   602 inline TSEID CAVStream::RemoteSEID() const
       
   603 	{
       
   604 #ifdef _DEBUG
       
   605 	TSEID seid = iRemoteAddress.SEID();
       
   606 	__ASSERT_DEBUG(!seid.IsLocal(), Panic(EAvdtpSEIDHasWrongDomain));
       
   607 	return seid;
       
   608 #else
       
   609 	return iRemoteAddress.SEID();
       
   610 #endif
       
   611 	}
       
   612 
       
   613 #include "avdtpLocalSEP.h"
       
   614 		
       
   615 inline TSEID CAVStream::LocalSEID() const
       
   616 	{
       
   617 #ifdef _DEBUG
       
   618 	TSEID seid = iLocalSEP->SEID();
       
   619 	__ASSERT_DEBUG(seid.IsLocal(), Panic(EAvdtpSEIDHasWrongDomain));
       
   620 	return seid;
       
   621 #else
       
   622 	return iLocalSEP->SEID();
       
   623 #endif
       
   624 	}
       
   625 
       
   626 #endif //AVDTPSTREAM_H