bluetoothengine/btsap/inc/BTSapSocketHandler.h
changeset 0 f63038272f30
equal deleted inserted replaced
-1:000000000000 0:f63038272f30
       
     1 /*
       
     2 * Copyright (c) 2004 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *	  This class handles data exchange via SAP Socketection initiated by a client
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 #ifndef BT_SAP_SOCKET_HANDLER_H
       
    21 #define BT_SAP_SOCKET_HANDLER_H
       
    22 
       
    23 //	INCLUDES
       
    24 #include <e32base.h>
       
    25 #include <btsdp.h>
       
    26 
       
    27 #include "BTSapMessage.h" // KMaxMsgSize
       
    28 #include "BTSapSniffHandler.h"
       
    29 
       
    30 enum TBTSapSocketState
       
    31 	{
       
    32 	EBTSapSocketStateListen,
       
    33 	EBTSapSocketStateRecv,
       
    34 	EBTSapSocketStateSend,
       
    35 	EBTSapSocketStateCheckSecurity,
       
    36 	EBTSapSocketStateRecvWrong
       
    37 	};
       
    38 
       
    39 // FORWARD DECLARATIONS
       
    40 class CBTEngDiscovery;
       
    41 class CBTSapServerState;
       
    42 class CBTSapRequestHandler;
       
    43 class CBTSapSecurityHandler;
       
    44 class TBTDevAddr;
       
    45 
       
    46 // CLASS DECLARATION
       
    47 
       
    48 /**
       
    49 * SAP Bluetooth socket connection handler class.
       
    50 */
       
    51 class CBTSapSocketHandler : public CActive
       
    52 	{
       
    53 private:
       
    54 
       
    55 	class TState
       
    56 		{
       
    57 	public:
       
    58 		TState(RSocket& aSocket);
       
    59 		virtual void Enter(TRequestStatus& aStatus) = 0;
       
    60 		virtual TBTSapSocketState Complete(TInt aReason = KErrNone) = 0;
       
    61 		virtual void Cancel() = 0;
       
    62 
       
    63 	protected:
       
    64 		RSocket& iSocket;
       
    65 		};
       
    66 
       
    67 	class TStateListen : public TState
       
    68 		{
       
    69 	public:
       
    70 		TStateListen(RSocketServ& aSockServ, RSocket& aSocket,	 RSocket& aListener, TUint aChannel);
       
    71 		void Enter(TRequestStatus& aStatus);
       
    72 		TBTSapSocketState Complete(TInt aReason);
       
    73 		void Cancel();
       
    74 
       
    75 	private:
       
    76 		RSocketServ& iSockServ;
       
    77 		RSocket& iListener;
       
    78 		TUint& iChannel;
       
    79 		};
       
    80 
       
    81 	class TStateRecv : public TState
       
    82 		{
       
    83 	public:
       
    84 		TStateRecv(RSocket& aSocket, CBTSapRequestHandler& aRequestHandler, CBTSapSniffHandler** aSniffHandler);
       
    85 		void Enter(TRequestStatus& aStatus);
       
    86 		TBTSapSocketState Complete(TInt aReason);
       
    87 		void Cancel();
       
    88 
       
    89 	private:
       
    90 		TBuf8<KMaxMsgSize> iRequestData;
       
    91 		TSockXfrLength iSockXfrLength;
       
    92 		CBTSapRequestHandler& iRequestHandler;
       
    93         CBTSapSniffHandler** iSniffHandler;
       
    94 		};
       
    95 
       
    96 	class TStateSend : public TState
       
    97 		{
       
    98 	public:
       
    99 		TStateSend(RSocket& aSocket);
       
   100 		void Enter(TRequestStatus& aStatus);
       
   101 		TBTSapSocketState Complete(TInt aReason);
       
   102 		void Cancel();
       
   103 		void SetResponseData(const TDesC8& aResponseData);
       
   104 
       
   105 	private:
       
   106 		TBuf8<KMaxMsgSize> iResponseData;
       
   107 		};
       
   108 
       
   109 	class TStateCheckSecurity : public TState
       
   110 		{
       
   111 	public:
       
   112 		TStateCheckSecurity(RSocket& aSocket, CBTSapSecurityHandler*& aSecurityHandler);
       
   113 		void Enter(TRequestStatus& aStatus);
       
   114 		TBTSapSocketState Complete(TInt aReason);
       
   115 		void Cancel();
       
   116 
       
   117 	private:
       
   118 		CBTSapSecurityHandler*& iSecurityHandler;
       
   119 		};
       
   120 
       
   121 public:
       
   122 	
       
   123 	// Constructors
       
   124 	static CBTSapSocketHandler* NewL(CBTSapServerState& aServerState, CBTSapRequestHandler& aRequestHandler);
       
   125 	
       
   126 	// Destructor
       
   127 	~CBTSapSocketHandler();
       
   128 		
       
   129 private:	 // From CActive
       
   130    
       
   131 	/**
       
   132 	* DoCancel() has to be implemented by all the classes deriving CActive.
       
   133 	* Request cancellation routine.
       
   134 	* @param none
       
   135 	* @return none 
       
   136 	*/
       
   137 	void DoCancel();
       
   138 	
       
   139 	/**
       
   140 	* RunL is called by framework after request is being completed.
       
   141 	* @param nones
       
   142 	* @return none 
       
   143 	*/
       
   144 	void RunL();
       
   145 
       
   146 public:	   
       
   147 	
       
   148 	/**
       
   149 	* Listen for incoming SAP socket connection
       
   150 	* @param	None
       
   151 	* @return	None.
       
   152 	*/		  
       
   153 	void Listen();
       
   154 	
       
   155 	/**
       
   156 	* Send response message back to the SAP client
       
   157 	* @return	None.
       
   158 	*/	  
       
   159 	void Send(const TDes8& aResponseData);
       
   160 
       
   161 	TInt GetRemoteBTAddress(TBTDevAddr& aBTDevAddr);
       
   162 
       
   163     TBool IsSapConnected();
       
   164 
       
   165 private:
       
   166 
       
   167 	// Two-phase constructor
       
   168 	void ConstructL();
       
   169 
       
   170 	// Default constructor
       
   171 	CBTSapSocketHandler(CBTSapServerState& aServerState, CBTSapRequestHandler& aRequestHandler);
       
   172 
       
   173 	void RegisterBTSapServiceL();
       
   174 
       
   175 	void UnregisterBTSapServiceL();
       
   176 
       
   177 private:
       
   178 
       
   179 	void ChangeState();
       
   180 
       
   181 private:
       
   182 
       
   183 	CBTSapServerState& iServerState;
       
   184 	CBTSapSecurityHandler* iSecurityHandler;
       
   185 
       
   186 	TSdpServRecordHandle iSdpHandle; // Registering handle 
       
   187 	CBTEngDiscovery* iBtDiscovery; // Bluetooth engine
       
   188 	RSocketServ iSockServ; // Socket server
       
   189 	RSocket iSocket; // Data socket 
       
   190 	RSocket iListener; // Listenning socket for incoming connection
       
   191 	TUint iChannel; // Local BT channel
       
   192 
       
   193 	TStateListen iStateListen;
       
   194 	TStateRecv iStateRecv;
       
   195 	TStateSend iStateSend;
       
   196 	TStateCheckSecurity iStateCheckSecurity;
       
   197 	RPointerArray <TState> iStateArray;
       
   198 	TBTSapSocketState iCurrentState;
       
   199 	TBTSapSocketState iNextState;
       
   200 
       
   201     CBTSapSniffHandler* iSniffHandler;
       
   202 	};
       
   203 
       
   204 #endif		// BT_SAP_SOCKET_HANDLER_H	 
       
   205 			
       
   206 // End of File