bluetooth/btstack/common/IncomingConnListener.h
author Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Thu, 19 Aug 2010 11:01:00 +0300
branchRCL_3
changeset 22 786b94c6f0a4
parent 0 29b1cd4cb562
permissions -rw-r--r--
Revision: 201031 Kit: 201033

// Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies).
// All rights reserved.
// This component and the accompanying materials are made available
// under the terms of "Eclipse Public License v1.0"
// which accompanies this distribution, and is available
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
//
// Initial Contributors:
// Nokia Corporation - initial contribution.
//
// Contributors:
//
// Description:
// Provides functionality to a layer n protocol to listen on layer n-1
// 
//

#ifndef INCOMINGCONNLISTENER_H
#define INCOMINGCONNLISTENER_H

#include <es_prot.h>

class CBluetoothProtocolBase;
class CBluetoothSAP;

NONSHARABLE_CLASS(CIncomingConnectionListener) : public CBase, public MSocketNotify
	{
public:
	//	NB. NewL takes immediate ownership of aNewSAP
	static CIncomingConnectionListener* NewL(CBluetoothProtocolBase& aProtocol, CServProviderBase* aNewSAP, TUint aPort, TUint aQueSize, TUid aUid);
	static CIncomingConnectionListener* NewL(CBluetoothProtocolBase& aProtocol, CServProviderBase* aNewSAP, const TBTSockAddr& aCompleteSockAddr, TUint aQueSize);
	~CIncomingConnectionListener();

	//  For passing SetOptions down the stack
	TInt SetOption(const TUint aLevel, TUint aName, TDesC8& aOption);
	
	//  For sending Ioctls down the stack
	void Ioctl(const CBluetoothSAP& aSAP, TUint aLevel, TUint aName, TDes8* aOption);
	void CancelIoctl(const CBluetoothSAP& aSAP);

	// for Preauthorising devices - typical use is for combined profiles in one use-case
	// eg headet connects (in unknown order) to AVCTP and AVDTP
	// each protocol uses control plane message to inform the other that a
	// device is preauthorised for remaining connections
	void SetPreauthorisation(TUint aProtocolLevel,
								const TBTDevAddr& aPreauthoriseAddress,
								TBool aSetPreauthorisation);
	TBool IsPreauthorised(TUint aProtocolLevel, const TBTDevAddr& aRemoteAddress);

	//	From MSocketNotify
	virtual void NewData(TUint aCount);
	virtual void CanSend();

	virtual void ConnectComplete();
	virtual void ConnectComplete(const TDesC8& aConnectData);
    virtual void ConnectComplete(CServProviderBase& aSSP);
	virtual void ConnectComplete(CServProviderBase& aSSP,const TDesC8& aConnectData);
	
	virtual void CanClose(TDelete aDelete=EDelete);
	virtual void CanClose(const TDesC8& aDisconnectData,TDelete aDelete=EDelete);

	virtual void Error(TInt aError,TUint aOperationMask=EErrorAllOperations);
	
	virtual void Disconnect(void);
	virtual void Disconnect(TDesC8& aDisconnectData);
	virtual void IoctlComplete(TDesC8 *aBuf);

	virtual void NoBearer(const TDesC8& /*aConnectionParams*/) {};
	virtual void Bearer(const TDesC8& /*aConnectionInf*/) {};

private:	
	//	Construction
	CIncomingConnectionListener(CBluetoothProtocolBase& aProtocol, CServProviderBase* aNewSAP);
	void ConstructL(const TBTSockAddr& aCompletedSockAddr, TUint aQueSize);

	void ClearIoctl();

	TUint					iIoctlLevel;
	TUint					iIoctlName;
	CBluetoothProtocolBase&	iProtocol;
	CServProviderBase*		iListeningSAP;
	CBluetoothSAP*			iRequestingSAP;	// the SAP asking for the Muxless Ioctl
	};

enum TListenerPanic
	{
	EListenerNullSAPForListening,
	EListenerSAPTwoIoctls,
	EListenerUnexpectedEvent,
	EListenerInvalidSAPIoctlCancel,
	};

void Panic(TListenerPanic aPanic);

#endif