testconns/statapi/device/source/statapi/inc/stat_bt.h
changeset 4 b8d1455fddc0
equal deleted inserted replaced
2:73b88125830c 4:b8d1455fddc0
       
     1 /*
       
     2 * Copyright (c) 2005-2009 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 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 /********************************************************************************
       
    21  *
       
    22  * Stat Bletooth Transport
       
    23  *
       
    24  *******************************************************************************/
       
    25 #ifndef __STATBT_H__
       
    26 #define __STATBT_H__
       
    27 
       
    28 /********************************************************************************
       
    29  *
       
    30  * System Includes
       
    31  *
       
    32  *******************************************************************************/
       
    33 #include <es_sock.h>
       
    34 
       
    35 #include <btmanclient.h>
       
    36 #include <btsdp.h>
       
    37 #include <bt_sock.h>
       
    38 #include <btextnotifiers.h>
       
    39 
       
    40 /********************************************************************************
       
    41  *
       
    42  * Local Includes
       
    43  *
       
    44  *******************************************************************************/
       
    45 #include "stat_interfaces.h"
       
    46 
       
    47 /********************************************************************************
       
    48  *
       
    49  * Definitions
       
    50  *
       
    51  *******************************************************************************/
       
    52 const TUint KStatBTHeaderSize	= 8;
       
    53 const TUint KLittleStatBTListenQueue = 1;
       
    54 const TUint KLittleStatBTPort = 3;
       
    55 
       
    56 /********************************************************************************
       
    57  *
       
    58  * CStatTransportBT - Top-level of the transport. Creates and waits on the 
       
    59  * listening socket. When a new data socket is created it creates the reader
       
    60  * and writer passing the socket to them. After that, the object simply routes
       
    61  * read/write calls/cancels to the appopriate objects.
       
    62  *
       
    63  *******************************************************************************/
       
    64 class CStatTransportBT : public CActive, public MStatNetwork
       
    65 {
       
    66 public:
       
    67 	// construction
       
    68 	static CStatTransportBT *NewL( void );
       
    69 	CStatTransportBT();
       
    70 	~CStatTransportBT();
       
    71 
       
    72 	// from MStatNetwork
       
    73 	TInt GetPacketSize();
       
    74 	TInt InitialiseL( MNotifyStatTransport *iTransport );
       
    75 	TInt ConnectL( TDesC *aRemoteHost );
       
    76 	TInt RequestSend( TDesC8 *aCommandData, const TUint aDataLength );
       
    77 	TInt RequestReceive( TUint aByteCount );
       
    78 	TInt Disconnect( void );
       
    79 	TInt Release( void );
       
    80 	TText8 *Error( void );
       
    81 	TUint NtoHl( TUint aValue ) const;
       
    82 	TUint HtoNl( TUint aValue ) const;
       
    83 	TBool PadPacket( TUint size ) const;
       
    84 
       
    85 	// from CActive 
       
    86 	void RunL( void );
       
    87 	void DoCancel();
       
    88 
       
    89 private:
       
    90 	void ConstructL( void );
       
    91 	
       
    92 	TInt RegWithSDPDatabaseL( void );
       
    93 	TInt StartSocketL( void );
       
    94 	void HandleAsyncDisconnect( void );
       
    95 
       
    96 public:
       
    97 	enum TStatTransportBTStatus { EIdle, EError, EInitialised, EConnectingSockets, EConnected, 
       
    98 								EConnectingRegisterMgr, EConnectingRegisterSDP, 
       
    99 								EDisconnectingData, EDisconnectingListen, 
       
   100 								EDisconnected, EDisconnectingUnregister };
       
   101 
       
   102 private:
       
   103 	TStatTransportBTStatus iBTTransportStatus;
       
   104 	TStatTransportBTStatus iBTTransportDisconnectStatusBeforeUnregister;
       
   105 	TReadWriteStatus iRWStatus;
       
   106 	MNotifyStatTransport *iTransport;
       
   107 	TInt iMaxPacketSize;
       
   108 
       
   109 	HBufC8 *iRecvBuffer;
       
   110 	TPtr8 *iRecvBufferPtr;
       
   111 
       
   112  	RSocket iListenSocket;
       
   113 	RSocket iDataSocket;
       
   114  	RSocketServ iSocketServ;
       
   115  	HBufC8 *iWrCommandData;
       
   116  	TUint iPort;							//	Assigned port number
       
   117 
       
   118  	TBTServiceSecurity iServiceSecurity;	//Service security object
       
   119  
       
   120  
       
   121  	RSdp iSdpSession;					//Service Discovery Session
       
   122  	RSdpDatabase iSdpDatabaseSession;	//Subsession to the SDP through which service record and their attributes can be added, deleted, and updated.
       
   123  	TSdpServRecordHandle iRecHandle;		//Session record handle
       
   124 };
       
   125 
       
   126 inline TUint CStatTransportBT::NtoHl( TUint aValue ) const
       
   127 {
       
   128 	return ( aValue );
       
   129 }
       
   130 
       
   131 inline TUint CStatTransportBT::HtoNl( TUint aValue ) const
       
   132 {
       
   133 	return ( aValue );
       
   134 }
       
   135 
       
   136 inline TBool CStatTransportBT::PadPacket( TUint ) const
       
   137 {
       
   138 	return ( EFalse );
       
   139 }
       
   140 
       
   141 #endif // __STATBT_H__