/*
* Component Name: Headset Simulator
* Author: Comarch S.A.
* Version: 1.0
* Copyright (c) 2010 Comarch S.A.
*
* This Software is submitted by Comarch S.A. to Symbian Foundation Limited on
* the basis of the Member Contribution Agreement entered between Comarch S.A.
* and Symbian Foundation Limited on 5th June 2009 (“Agreement”) and may be
* used only in accordance with the terms and conditions of the Agreement.
* Any other usage, duplication or redistribution of this Software is not
* allowed without written permission of Comarch S.A.
*
*/
#ifndef HSCLIENT_H_
#define HSCLIENT_H_
#include <bt_sock.h>
class MHsClientObserver;
class MHsClientStateNotifier;
/** Length of AG's receive and send data buffer */
const TInt32 KHsClientBufferLength = 0x800;
/** Buffer for communication with AG */
typedef TBuf8 <KHsClientBufferLength> THsClientBuffer;
/**
* @brief Class represents AG client.
*/
class CHsClient : public CBase, public MBluetoothSocketNotifier
{
public:
/**
* Two-phase constructor
*
* @param aClient socket which AG is connected
* @param aClientStateNotifier pointer to AG state observer
* @param aClientDisconnectNotifier pointer to AG disconnection observer
* @return instance of class
*/
static CHsClient* NewL( CBluetoothSocket* aClient,
MHsClientStateNotifier* aClientStateNotifier = NULL,
MHsClientObserver* aClientDisconnectNotifier = NULL );
/**
* Two-phase constructor
*
* @param aClient socket which AG is connected
* @param aClientStateNotifier pointer to AG state observer
* @param aClientDisconnectNotifier pointer to AG disconnection observer
* @return instance of class
*/
static CHsClient* NewLC( CBluetoothSocket* aClient,
MHsClientStateNotifier* aClientStateNotifier = NULL,
MHsClientObserver* aClientDisconnectNotifier = NULL );
/**
* Destructor
*/
~CHsClient();
public:
/**
* Sends data to AG.
*
* @pre AG client is connected
*
* @param aData data to be send
*/
void Send( const TDesC8& aData );
/**
* Sets observer of AG's disconnection.
*
* @param aNotifier reference to MHsClientObserver
*/
void SetClientDisconnectNotfier( MHsClientObserver& aNotifier );
/**
* Sets observer of AG's states.
*
* @param aNotifier reference to MHsClientStateNotifier
*/
void SetClientStateNotfier( MHsClientStateNotifier& aNotifier );
/**
* Returns pointer to AG's states observer.
*/
MHsClientStateNotifier* GetClientStateNotifer();
private:
/**
* Constructor for performing 1st stage construction
*
* @param aClient socket which AG is connected
* @param aClientStateNotifier pointer to AG state observer
* @param aClientDisconnectNotifier pointer to AG disconnection observer
*/
CHsClient( CBluetoothSocket& aClient,
MHsClientStateNotifier* aClientStateNotifier = NULL,
MHsClientObserver* aClientDisconnectNotifier = NULL );
/**
* Constructor for performing 2nd stage construction
*/
void ConstructL();
private:
/**
* Receives data from AG.
*
* @param aData received data buffer
*
* @leave KErrNoMemory if AG socket is NULL
* @leave KErrDisconnected if AG is not connected
*/
void RawRecvL( TDes8& aData );
/**
* Sends data to AG.
*
* @param aData data to be send
*
* @leave KErrNoMemory if AG socket is NULL
* @leave KErrDisconnected if AG is not connected
* @leave KErrWrite if parameter is empty
*/
void RawSendL( const TDesC8& aData );
/**
* Sends data to AG with double buffering and init receiving when there
* is no data to be send.
*
* @param aData data to be send
*/
void BufferedProcessL( const TDesC8& aData = KNullDesC8 );
/**
* Swaps sending buffers.
*/
void SwapBuffers();
private:
//Methods derived from MBluetoothSocketNotifier
void HandleConnectCompleteL( TInt aErr );
void HandleAcceptCompleteL( TInt aErr );
void HandleShutdownCompleteL( TInt aErr );
void HandleSendCompleteL( TInt aErr );
void HandleReceiveCompleteL( TInt aErr );
void HandleIoctlCompleteL( TInt aErr );
void HandleActivateBasebandEventNotifierCompleteL( TInt aErr,
TBTBasebandEventNotification& aEventNotification );
private:
/** AG client state enum */
enum THsClientState
{
/** Idle state */
EIdle = 0,
/** Sending state */
ESending,
/** Receiving state */
EReceiving
};
/** AG client's state */
THsClientState iState;
/** Bluetooth information receive flags */
TInt iReceiveFlag;
/** Bluetooth information send flags */
TInt iSendFlag;
/** Denotes if AG is connected */
TBool iConnected;
/** Length indicating how much data was read */
TSockXfrLength iReceiveMessageLength;
/** Receive data buffer */
THsClientBuffer iReceiveMessageBuffer;
/** Send data buffer */
THsClientBuffer iSendBuf;
/** Temporary send data buffer */
THsClientBuffer iTempSendBuf;
/** Bluetooth socket */
CBluetoothSocket* iSocket;
/** Pointer to MHsClientStateNotifier. Not owned */
MHsClientStateNotifier* iStateNotifier;
/** Pointer to MHsClientObserver. Not owned */
MHsClientObserver* iClientObserver;
};
#endif /* HSCLIENT_H_ */