
/*===========================================================================

FILE:      AEEBTSIO.h
 
SERVICES:  Bluetooth Serial Interafce
 
DESCRIPTION: This file provides defintions for the Serial Interface over Bluetooth.

PUBLIC CLASSES:  Not Applicable

INITIALIZATION AND SEQUENCING REQUIREMENTS:


        Copyright © 1999-2002 QUALCOMM Incorporated.
               All Rights Reserved.
            QUALCOMM Proprietary/GTDR
===========================================================================*/
#ifndef _AEEBTSIO_H_
#define _AEEBTSIO_H_

#include "AEE.h"
#include "AEESource.h"
#include "AEEBT.h"


#ifdef __cplusplus
extern "C" {
#endif
typedef struct tagAEEBTConnectionInfo
{
	boolean					bMaster;	// Device is Master or Slave
	AEEBTAddr				bdAddr;	// Target Device Address
	AEEBTRCServerChannel	btServerChannel;	// Target Device Server Channel
	uint16					uServiceClass;		// Service Class of the Device
	char					szServiceName[AEEBT_MAX_SERVICENAME_LEN];	// Service Name
}AEEBTConnectionInfo;

//
// uServiceClass and szServiceName are used if the the device is opened in Slave mode.
// It is not supported currently
//
// Bluetooth Serial IO Interface definitions
typedef struct IBTSIOPort IBTSIOPort;
AEEINTERFACE(IBTSIOPort) 
{
  INHERIT_ISource(IBTSIOPort);
  int32 (*Write)(IBTSIOPort *po, char *pcBuf, int32 cbBuf);
  void  (*Writeable)(IBTSIOPort *po, AEECallback *pcb);
  int32	(*GetLastError)(IBTSIOPort * po);
  int32	(*Open)(IBTSIOPort * po, AEEBTConnectionInfo* pConnectInfo);
  int32	(*GetState)(IBTSIOPort * po);

};

// BASE AEE INTERFACE
#define IBTSIOPORT_AddRef(p)                 AEEGETPVTBL((p),IBTSIOPort)->AddRef((p))
#define IBTSIOPORT_Release(p)                AEEGETPVTBL((p),IBTSIOPort)->Release((p))
#define IBTSIOPORT_QueryInterface(p,i,ppo)   AEEGETPVTBL((p),IBTSIOPort)->QueryInterface((p),(i),(ppo))

/*======================================================================= 

  INTERFACES   DOCUMENTATION
======================================================================= 


Interface Name: IBTSIOPORT

Description: 
    The IBTSIOPORT Interface functions are used to open, close , read and Write using 
	a serial interface over Bluetooth.

	FUNCTIONS in this Interface

	IBTSIOPORT_Open
	IBTSIOPORT_Read
	IBTSIOPORT_Write
	IBTSIOPORT_Readable
	IBTSIOPORT_Writeable
	IBTSIOPORT_GetState

USAGE:

	a. Open a Serial Port Using IBTSIOPORT_Open.
	b. Schedule a Writeable callback/ Readable Callback using Readble or Writeable.
	c. On a successfull of Connection Establishment, the Readable or Writeable Callbacks
	are scheduled. The User can read or write to the Serial port appropriately.
	d. Use the IBTSIOPORT_GetState to query the state of the Port
	e. Close the Port using IBTSIOPORT_Release.
===========================================================================*/

/*===========================================================================

Function:  IBTSIOPORT_Open

Description:

  This function opens the Serial port over Bluetooth

Prototype:

  int32 IBTSIOPORT_Open(IBTSIOPort*pme, AEEBT_ConnectionInfo* pConnectInfo,
				AEECallback *pcb)

Parameters:
	pConnectInfo : Connection Info for the BT Serial Port
	pcb : The Callback which is called when ever there is a state change in the Link. The Callback
	will be called only if the open succeeded.
Return Value:
	SUCCESS is successful
	EFAILED If the port is error


===========================================================================*/

/*===========================================================================

Function:  IBTSIOPORT_Read

Description:

  This function copies data from the receive buffer into the pcBuf[] buffer
  supplied by the caller. As much data as is available should be copied, never
  exceeding nLen bytes and never exceeding the number of bytes available in
  the receive buffer. Data copied into pcBuf[] should be removed from the
  receive buffer.

Prototype:

  int32 IBTSIOPORT_Read(IBTSIOPort*pme, char *pcBuf, int16 nLen)

Parameters:

Return Value:
  The number of bytes removed from the receive buffer.

  If the receive buffer is empty, no bytes should be copied and this function
  should return AEE_BT_WOULDBLOCK.

  AEE_BT_ERROR If the port is error
	
===========================================================================*/


/*===========================================================================

Function:  IBTSIOPORT_Readable

Description:

  This function schedules a read callback whenever the data is available. This function allows the
  user to schedule a asynchronous of a Function when ever data is available on the Port.
  Once the callback is executed, it is removed from the outstanding callback lists. The User should
  read as much as data i.e available and then schedule a callback again using this function.

Prototype:

  void IBTSIOPORT_Readable(IBTSIOPort*pme, AEECallback*)

Parameters:


Return Value:
 None


===========================================================================*/

/*===========================================================================
Function:  IBTSIOPORT_Write

Description:
 
  This should append nLen bytes from the specified buffer (pcBuf) onto the end
  of the transmit buffer. If the buffer cannot accomodate nLen bytes, as many
  bytes as can fit should be appended.

Prototype:

  int16 IBTSIOPORT_Write(IBTSIOPort*pme, const char *pcBuf, int16 nLen) 

Parameters:

Return Value:

  The number of bytes appended to the transmit buffer.

  If the receive buffer is full, no bytes should be copied and this function
  should return AEE_BT_WOULDBLOCK.

  AEE_BT_ERROR If the port is error

===========================================================================*/
/*===========================================================================

Function:  IBTSIOPORT_Writeable

Description:

  This function schedules a write callback when the bluetooth driver is ready to transmit

  This function schedules a write callback whenever the the drive can transmit data again.
  This function allows the   user to schedule a asynchronous of a Function when ever data 
  the port is ready to transmit.
  Once the callback is executed, it is removed from the outstanding callback lists. The User should
  write as much as data i.e available and then schedule a callback again using this function.

Prototype:

  void IBTSIOPORT_Writeable(IBTSIOPort*pme, AEECallback*)

Parameters:

Return Value:
 None


===========================================================================*/

/*===========================================================================

Function:  IBTSIOPORT_Open

Description:

  This function opens the Serial port over Bluetooth

Prototype:

  int32 IBTSIOPORT_Open(IBTSIOPort*pme, AEEBT_ConnectionInfo* pConnectInfo,
				AEECallback *pcb)

Parameters:
	pConnectInfo : Connection Info for the BT Serial Port
	pcb : The Callback which is called when ever there is a state change in the Link. The Callback
	will be called only if the open succeeded.
Return Value:
	SUCCESS is successful
	EFAILED If the port is error


===========================================================================*/


/*===========================================================================

Function:  IBTSIOPORT_Release

Description:

  This function closes the Serial port over Bluetooth if the reference goes to Zero

Prototype:

  uint32 IBTSIOPORT_Release(IBTSIOPort*pme)

Parameters:

Return Value:


===========================================================================*/

/*===========================================================================
Function:  AEEBTSIOPort_GetState

Description:
 
  Returns the Current State of the BT port

Prototype:

  int32	IBTSIOPORT_GetState(IBTSIOPort * po);

Parameters:

  IBTSIOPort * po: the port


Return Value:
	State of the BT Port.
	Return Value:
	AEEBT_ST_IDLE	 : Connection is IDLE
	AEEBT_ST_LISTENING : Connection is in Listen Mode
	AEEBT_ST_CONNECTING : Trying to Estanblish Connection
	AEEBT_ST_CONNECTED : Connected to a remote Device
	AEEBT_ST_CLOSED : Connection is closed.

===========================================================================*/

#define IBTSIOPORT_Read(p,pc,cb)             AEEGETPVTBL((p),IBTSIOPort)->Read((p),(pc),(cb))
#define IBTSIOPORT_Write(p,pc,cb)            AEEGETPVTBL((p),IBTSIOPort)->Write((p),(pc),(cb))
#define IBTSIOPORT_Readable(p,pcb)           AEEGETPVTBL((p),IBTSIOPort)->Readable((p),(pcb))
#define IBTSIOPORT_Writeable(p,pcb)          AEEGETPVTBL((p),IBTSIOPort)->Writeable((p),(pcb))
#define IBTSIOPORT_Open(p,pCntInfo)     AEEGETPVTBL((p),IBTSIOPort)->Open((p),pCntInfo)
#define IBTSIOPORT_GetState(p)				 AEEGETPVTBL((p),IBTSIOPort)->GetState((p))

#define IBTSIOPORT_GetLastError(p)  		  AEEGETPVTBL((p),IBTSIOPort)->(GetLastError)((p))


#define IBTSIOPORT_ReadableEx(p,pcb,pfn,pv)   CALLBACK_Init((pcb),(pfn),(pv)); \
											  IBTSIOPORT_Readable((p), (pcb))

#define IBTSIOPORT_WriteableEx(p,pcb,pfn,pv)  CALLBACK_Init((pcb),(pfn),(pv)); \
											  IBTSIOPORT_Writeable((p), (pcb))

#ifdef __cplusplus
}
#endif


#endif  //_AEEBTSIO_H_

