bluetooth/gavdp/inc/gavdpInternal.h
changeset 0 29b1cd4cb562
child 22 786b94c6f0a4
equal deleted inserted replaced
-1:000000000000 0:29b1cd4cb562
       
     1 // Copyright (c) 2004-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 #ifndef _GAVDPINTERNAL_H
       
    17 #define _GAVDPINTERNAL_H
       
    18 
       
    19 #include <gavdp.h>
       
    20 #include "gavdpinterface.h"
       
    21 #include "e32debug.h"
       
    22 
       
    23 class CGavdpHelper;
       
    24 
       
    25 NONSHARABLE_CLASS(CGavdp) : public CBase
       
    26 {
       
    27 friend class CGavdpHelper;
       
    28 friend class CGavdpDiscover;
       
    29 friend class CGavdpStart;
       
    30 friend class CGavdpGetCaps;
       
    31 friend class CGavdpAbort;
       
    32 friend class CGavdpSuspend;
       
    33 friend class CGavdpSelectSEP;
       
    34 friend class CGavdpConnector;
       
    35 //friend class CGavdpPassiveSignallingConnector;
       
    36 friend class CGavdpIndicator;
       
    37 friend class CGavdpUPlaneConnector;
       
    38 
       
    39 public:
       
    40 	static CGavdp* NewL(MGavdpUser& aServiceUser, RSocketServ& aSocketServer, RGavdp& aHandle);
       
    41 	~CGavdp();
       
    42 
       
    43 	TInt Listen();
       
    44 
       
    45 	void Cancel();
       
    46 	
       
    47 	void Connect(const TBTDevAddr& aRemoteAddr);
       
    48 	void DiscoverRemoteSEPs();
       
    49 	void GetRemoteSEPCapabilities(TSEID aSEID, const TAvdtpServiceCategories& aInterestedCategories);
       
    50 
       
    51 	TInt RegisterSEP(TAvdtpSEPInfo& aInfo); // SEID will be written back
       
    52 
       
    53 	TInt BeginConfiguringRemoteSEP(TSEID aRemoteSEID, TSEID aLocalSEID);
       
    54 	TInt BeginConfiguringLocalSEP(TSEID aSEID);
       
    55 	TInt AddSEPCapability(const TAvdtpServiceCapability& aCapability);
       
    56 	void CommitSEPConfiguration();
       
    57 	
       
    58 	void StartStream(TSEID aSEID);
       
    59 	void SuspendStream(TSEID aSEID);
       
    60 	void AbortStream(TSEID aSEID);
       
    61 	
       
    62 	void SendSecurityControl(TSEID aSEID, const TDesC8& aSecurityData);
       
    63 	
       
    64 	TInt CreateBearerSockets(TSEID aSEID);
       
    65 
       
    66 	inline RSocket&	AvdtpRequester(); // not available for use outside DLL because we define the inline in the cpp
       
    67 	inline RSocket&	AvdtpIndicator(); // not available for use outside DLL because we define the inline in the cpp
       
    68 	inline RSocketServ& AvdtpSession(); // not available for use outside DLL because we define the inline in the cpp
       
    69 	
       
    70 	TInt Shutdown();
       
    71 private:
       
    72 	CGavdp(MGavdpUser& aServiceUser, RSocketServ& aSocketServer, RGavdp& aHandle);
       
    73 	void ConstructL();	
       
    74 	void ConstructSocketsAndHelpersL();
       
    75 	void DeAllocSocketsAndHelpers();
       
    76 	void SendResponse(TInternalAvdtpAirIndication aIndication,
       
    77 					  TInt aResult,
       
    78 					  const TAny* aResponseData=NULL,
       
    79 					  TInt aResponseDataLen=0);
       
    80 	void ServiceComplete(TInt aResult); // cleans up helpers and shift RGavdp statemachine
       
    81 	void BindSignallingL(const TBTDevAddr& aRemoteAddr);
       
    82 	void BindBearersL(TSEID aSEID, TBool aRequireReporting, TBool aRequireRecovery);
       
    83 	inline TBool CheckSEID(TSEID aSEID);
       
    84 	void Error(TInt aError);
       
    85 	void FatalError();
       
    86 private:
       
    87 	enum TGavdpState
       
    88 		{
       
    89 		EIdle,
       
    90 		EConfiguringLocalSEP,
       
    91 		EConfiguringRemoteSEP,
       
    92 		EListening,
       
    93 		EConnecting,
       
    94 		EConnected,
       
    95 		};
       
    96 private:
       
    97 	RSocketServ		iSocketServer;
       
    98 	RSocket			iAvdtpRequester;
       
    99 	RSocket			iAvdtpIndicator;
       
   100 	CGavdpHelper*	iRequesterHelper;
       
   101 	CGavdpHelper*	iIndicatorHelper;
       
   102 	TGavdpState		iState;
       
   103 	RSocketServ&	iClientSocketServer;
       
   104 	MGavdpUser&		iServiceUser;
       
   105 	TInt			iNumSEPsRegistered;
       
   106 	RGavdp&			iHandle;
       
   107 	};
       
   108 
       
   109 /**
       
   110 Faults - GAVDP itself has failed
       
   111 **/	
       
   112 enum TGavdpFault
       
   113 	{
       
   114 	EGavdpHelperTryingToUseNullGavdp,
       
   115 	EGavdpUnexpectedAvdtpError,
       
   116 	EGavdpHelperCompletingBadly,
       
   117 	};
       
   118 	
       
   119 static void Panic(TGavdpPanic aPanic)
       
   120 // Panic client due to programming error.
       
   121 	{
       
   122 	_LIT(KGavdpPanicName, "GAVDP Usage error");
       
   123 	RDebug::Print(_L("%S panic=%d"), &KGavdpPanicName, aPanic);
       
   124 	User::Panic(KGavdpPanicName, aPanic);
       
   125 	}
       
   126 
       
   127 static void Fault(TGavdpFault aFault)
       
   128 // Panic due to GAVDP fault
       
   129 	{
       
   130 	_LIT(KGavdpFaultName, "GAVDP fault");
       
   131 	User::Panic(KGavdpFaultName, aFault);
       
   132 	}
       
   133 
       
   134 
       
   135 NONSHARABLE_CLASS(CGavdpHelper) : public CActive
       
   136 	{
       
   137 public:
       
   138 	virtual void Begin() =0;
       
   139 protected:
       
   140 	CGavdpHelper(CGavdp& aGavdp, MGavdpUser& aUser);
       
   141 	TInt RunError(TInt aError);
       
   142 	inline RSocket& AvdtpRequester();
       
   143 	inline RSocket& AvdtpIndicator();
       
   144 	inline RSocketServ& AvdtpSession();
       
   145 	void CheckFailedL();
       
   146 	void DetachFromGavdp(TInt aError);
       
   147 	inline CGavdp& Gavdp(); // not const because of return
       
   148 	inline MGavdpUser& User(); // not const because of return
       
   149 private:
       
   150 	CGavdp*			iGavdp;	// NULL once helper s free-running
       
   151 	MGavdpUser&		iUser;
       
   152 	};
       
   153 	
       
   154 /**
       
   155 Helper that enables indications to be raised by AVDTP
       
   156 As a current imlpementation, this constantly queues ioctls
       
   157 (AVDTP assists by queing them too)
       
   158 @internalComponent
       
   159 */
       
   160 NONSHARABLE_CLASS(CGavdpIndicator) : public CGavdpHelper
       
   161 	{
       
   162 public:
       
   163 	static CGavdpIndicator* NewL(CGavdp& aGavdp, MGavdpUser& aUser);
       
   164 	virtual void Begin();
       
   165 	~CGavdpIndicator();
       
   166 private:
       
   167 	CGavdpIndicator(CGavdp& aGavdp, MGavdpUser& aUser);
       
   168 	void RunL();
       
   169 	TInt RunError(TInt aError);
       
   170 	void DoCancel();
       
   171 	void CheckClientResult(TInt aResult);
       
   172 private:
       
   173 	TBuf8<KAvdtpMaxInternalIndicationSize> iIndication;
       
   174 	};
       
   175 	
       
   176 	
       
   177 NONSHARABLE_CLASS(CGavdpDiscover) : public CGavdpHelper
       
   178 	{
       
   179 public:
       
   180 	static CGavdpDiscover* NewL(CGavdp& aGavdp, MGavdpUser& aUser);
       
   181 	virtual void Begin();
       
   182 	~CGavdpDiscover();
       
   183 private:
       
   184 	CGavdpDiscover(CGavdp& aGavdp, MGavdpUser& aUser);
       
   185 	void RunL();
       
   186 	void DoCancel();
       
   187 private:
       
   188 	TPckgBuf<TAvdtpInternalDiscoverConfirm>	iConfirm;
       
   189 	};
       
   190 	
       
   191 
       
   192 NONSHARABLE_CLASS(CGavdpGetCaps) : public CGavdpHelper
       
   193 	{
       
   194 public:
       
   195 	static CGavdpGetCaps* NewL(CGavdp& aGavdp,
       
   196 				 			  MGavdpUser& aUser,
       
   197 				 			  TSEID aSEID,
       
   198 				 			  TAvdtpServiceCategories aInterestingCategories);
       
   199 	virtual void Begin();
       
   200 	~CGavdpGetCaps();
       
   201 private:
       
   202 	CGavdpGetCaps(CGavdp& aGavdp, MGavdpUser& aUser,
       
   203 					TSEID aSEID, TAvdtpServiceCategories aInterestingCategories);
       
   204 	void ConstructL();
       
   205 	void RunL();
       
   206 	void DoCancel();
       
   207 private:
       
   208 	HBufC8*					iSEPCapBuf; // general input and output from socket, hence not typed
       
   209 	TPtr8					iSEPCapPtr;
       
   210 	TSEID					iSEID;
       
   211 	TAvdtpServiceCategories iInteresting;
       
   212 	};
       
   213 	
       
   214 
       
   215 NONSHARABLE_CLASS(CGavdpAbort) : public CGavdpHelper
       
   216 	{
       
   217 public:
       
   218 	static CGavdpAbort* NewL(CGavdp& aGavdp, MGavdpUser& aUser, TSEID aSEID);
       
   219 	
       
   220 	virtual void Begin();
       
   221 	~CGavdpAbort();
       
   222 private:
       
   223 	CGavdpAbort(CGavdp& aGavdp, MGavdpUser& aUser, TSEID aSEID);
       
   224 	void RunL();
       
   225 	void DoCancel();
       
   226 private:
       
   227 	TPckgBuf<TSEID> iSEID;
       
   228 	};
       
   229 
       
   230 
       
   231 NONSHARABLE_CLASS(CGavdpStart) : public CGavdpHelper
       
   232 	{
       
   233 public:
       
   234 	static CGavdpStart* NewL(CGavdp& aGavdp,
       
   235 					  		  MGavdpUser& aUser,
       
   236 					  		  TSEID aSeid);
       
   237 					  		   			  
       
   238 	virtual void Begin();
       
   239 	~CGavdpStart();
       
   240 private:
       
   241 	CGavdpStart(CGavdp& aGavdp, MGavdpUser& aUser, TSEID aSeid);
       
   242 	void RunL();
       
   243 	void DoCancel();
       
   244 private:			
       
   245 	TPckgBuf<TSEID>	iSeidPckg;
       
   246 	};
       
   247 
       
   248 
       
   249 NONSHARABLE_CLASS(CGavdpSuspend) : public CGavdpHelper
       
   250 	{
       
   251 public:
       
   252 	static CGavdpSuspend* NewL(CGavdp& aGavdp,
       
   253 					  			  MGavdpUser& aUser,
       
   254 					  			  TSEID aSeid);
       
   255 					  		   			  
       
   256 	virtual void Begin();
       
   257 	~CGavdpSuspend();
       
   258 private:
       
   259 	CGavdpSuspend(CGavdp& aGavdp, MGavdpUser& aUser, TSEID aSeid);
       
   260 	void RunL();
       
   261 	void DoCancel();
       
   262 private:			
       
   263 	TPckgBuf<TSEID>	iSeidPckg;
       
   264 	};
       
   265 
       
   266 NONSHARABLE_CLASS(CGavdpSecurityControl) : public CGavdpHelper
       
   267 	{
       
   268 public:
       
   269 	static CGavdpSecurityControl* NewL(CGavdp& aGavdp,
       
   270 					  		  MGavdpUser& aUser,
       
   271 					  		  TSEID aSeid,
       
   272 					  		  const TDesC8& aSecurityControl);
       
   273 					  		   			  
       
   274 	virtual void Begin();
       
   275 	~CGavdpSecurityControl();
       
   276 private:
       
   277 	CGavdpSecurityControl(CGavdp& aGavdp, MGavdpUser& aUser, TSEID aSeid,
       
   278 					  		  const TDesC8& aSecurityControl);
       
   279 	void RunL();
       
   280 	void DoCancel();
       
   281 private:			
       
   282 	TPckgBuf<TAvdtpInternalSendSecurityControl>	iSecurityControlPckgBuf;
       
   283 	};
       
   284 
       
   285 NONSHARABLE_CLASS(CGavdpSelectSEP) : public CGavdpHelper
       
   286 	{
       
   287 public:
       
   288 	static CGavdpSelectSEP* NewL(CGavdp& aGavdp, MGavdpUser& aUser);
       
   289 	
       
   290 	virtual void Begin();
       
   291 	~CGavdpSelectSEP();
       
   292 private:
       
   293 	CGavdpSelectSEP(CGavdp& aGavdp, MGavdpUser& aUser);
       
   294 	void RunL();
       
   295 	void DoCancel();
       
   296 private:
       
   297 	TPckgBuf<TAvdtpConfigReject> iRejDataBuf; // in case we get rejected by peer
       
   298 	};
       
   299 
       
   300 
       
   301 NONSHARABLE_CLASS(CGavdpConnector) : public CGavdpHelper
       
   302 	{
       
   303 public:
       
   304 	static CGavdpConnector* NewL(CGavdp& aGavdp, MGavdpUser& aUser, const TBTDevAddr& aAddr);
       
   305 	
       
   306 	virtual void Begin();
       
   307 	~CGavdpConnector();
       
   308 private:
       
   309 	CGavdpConnector(CGavdp& aGavdp, MGavdpUser& aUser, const TBTDevAddr& aAddr);
       
   310 	void RunL();
       
   311 	void DoCancel();
       
   312 private:
       
   313 	TAvdtpSockAddr	iSocketAddress;
       
   314 	};
       
   315 
       
   316 class CGavdpUPlaneConnector;
       
   317 
       
   318 NONSHARABLE_CLASS(CSocketConnector) : public CActive
       
   319 	{
       
   320 public:
       
   321 	static CSocketConnector* NewL(CGavdpUPlaneConnector& aParent,
       
   322 									RSocketServ& aSocketServer,
       
   323 									const TAvdtpSockAddr& aSockAddr);
       
   324 	inline RSocket& Socket(); // return type => non-const method
       
   325 	inline const TAvdtpSockAddr& Address() const;
       
   326 	virtual void RunL();
       
   327 	virtual void DoCancel();
       
   328 	~CSocketConnector();
       
   329 	void Begin();
       
   330 private:
       
   331 	CSocketConnector(CGavdpUPlaneConnector& aParent,
       
   332 									RSocketServ& aSocketServer,
       
   333 									const TAvdtpSockAddr& aSockAddr);
       
   334 	void ConstructL();
       
   335 private:
       
   336 	CGavdpUPlaneConnector& iParent;
       
   337 	RSocket iSocket;
       
   338 	RSocketServ& iSocketServer;
       
   339 	TAvdtpSockAddr iSockAddr;
       
   340 	};
       
   341 	
       
   342 inline RSocket& CSocketConnector::Socket()
       
   343 	{
       
   344 	return iSocket;
       
   345 	}
       
   346 	
       
   347 inline const TAvdtpSockAddr& CSocketConnector::Address() const
       
   348 	{
       
   349 	return iSockAddr;
       
   350 	}
       
   351 
       
   352 	
       
   353 NONSHARABLE_CLASS(CGavdpUPlaneConnector) : public CGavdpHelper
       
   354 	{
       
   355 public:
       
   356 	static CGavdpUPlaneConnector* NewL(CGavdp& aGavdp, MGavdpUser& aUser,
       
   357 								 	   const TAvdtpSockAddr& aAddr,
       
   358 									   TBool aRequireReporting,
       
   359 									   TBool aRequireRecovery,
       
   360 						  			   RSocketServ& aClientSession);
       
   361 	
       
   362 	virtual void Begin();
       
   363 	void ConnectComplete(TInt aErr);
       
   364 	~CGavdpUPlaneConnector();
       
   365 private:
       
   366 	CGavdpUPlaneConnector(CGavdp& aGavdp,
       
   367 						  MGavdpUser& aUser,
       
   368 						  const TAvdtpSockAddr& aAddr,
       
   369 						  TBool aRequireReporting,
       
   370 						  TBool aRequireRecovery,
       
   371 						  RSocketServ& aClientSession);
       
   372 	void RunL();
       
   373 	void DoConnectComplete(TInt aErr);
       
   374 	void DoCancel();
       
   375 	void AllBearersReadyL();
       
   376 	void ConstructL(TBool aRequireReporting, TBool aRequireRecovery);
       
   377 private:
       
   378 	TFixedArray<CSocketConnector*,ENumStreamTypes> iSocketConnectors;
       
   379 	RSocketServ&	iClientSession;
       
   380 	TInt			iNumBearersRequired;
       
   381 	TAvdtpSockAddr	iAddress; // just has remote BT Addr and SEID
       
   382 	};
       
   383 	
       
   384 inline RSocket& CGavdp::AvdtpRequester()
       
   385 	{
       
   386 	return iAvdtpRequester;
       
   387 	}
       
   388 
       
   389 inline RSocket& CGavdp::AvdtpIndicator()
       
   390 	{
       
   391 	return iAvdtpIndicator;
       
   392 	}
       
   393 	
       
   394 inline RSocketServ& CGavdp::AvdtpSession()
       
   395 	{
       
   396 	return iSocketServer;
       
   397 	}
       
   398 
       
   399 inline RSocket& CGavdpHelper::AvdtpRequester()
       
   400 	{
       
   401 	return Gavdp().AvdtpRequester();
       
   402 	}
       
   403 
       
   404 inline RSocket& CGavdpHelper::AvdtpIndicator()
       
   405 	{
       
   406 	return Gavdp().AvdtpIndicator();
       
   407 	}
       
   408 	
       
   409 inline RSocketServ& CGavdpHelper::AvdtpSession()
       
   410 	{
       
   411 	return Gavdp().AvdtpSession();
       
   412 	}
       
   413 		
       
   414 inline CGavdp& CGavdpHelper::Gavdp()
       
   415 	{
       
   416 	// free running helpers cannot interact with GAVDP
       
   417 	__ASSERT_ALWAYS(iGavdp, Fault(EGavdpHelperTryingToUseNullGavdp));
       
   418 	return *iGavdp;
       
   419 	}
       
   420 	
       
   421 #endif // _GAVDPINTERNAL_H
       
   422