--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/bluetoothengine/headsetsimulator/core/inc/Server/hsserver.h Wed Sep 15 15:59:44 2010 +0200
@@ -0,0 +1,164 @@
+/*
+ * 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 HSSERVER_H
+#define HSSERVER_H
+
+#include <bt_sock.h>
+#include <bttypes.h>
+
+class CBluetoothSocket;
+class RSocketServ;
+class MHsAcceptNewClientObserver;
+
+/** The number of connections allowed in the queue */
+const TUint KListenQueueSize = 10;
+
+/** Buffer size */
+const TInt KMaxTHSConnectionBufferSize = 1024;
+
+/**
+ * @brief Server that listens and handles physical link connection with AG device.
+ */
+class CHsServer : public CBase, public MBluetoothSocketNotifier
+{
+public:
+
+ /**
+ * Two-phased constructor.
+ * @param aSocketServ session of socket server
+ * @return instance of class
+ */
+ static CHsServer* NewL( RSocketServ &aSocketServ );
+
+ /**
+ * Two-phased constructor.
+ * @param aSocketServ session of socket server
+ * @return instance of class
+ */
+ static CHsServer* NewLC( RSocketServ &aSocketServ );
+
+ /**
+ * Destructor
+ */
+ ~CHsServer();
+
+public:
+
+ /**
+ * Turns on server. Method listens (RFCOMM protocol) and accepts ongoing
+ * connections. Server gets the first free port number in system.
+ *
+ * @return KErrNone if successful,
+ * KErrAlreadyExists if server is already running,
+ * otherwise one of the system-wide error codes
+ */
+ TInt Listen();
+
+ /**
+ * Returns server listening status.
+ *
+ * @return ETrue if server listens, otherwise EFalse
+ */
+ TBool IsReady();
+
+ /**
+ * Shutdowns server. Cancels receiving and sending data, disconnects
+ * clients and destroys all bluetooth sockets.
+ */
+ void Shutdown();
+
+ /**
+ * Sets new client observer.
+ *
+ * @param aNewClientObserv reference to observer
+ */
+ void SetNewClientObserver( MHsAcceptNewClientObserver &aNewClientObserv );
+
+ /**
+ * Returns listening server port.
+ *
+ * @return port number
+ */
+ TInt GetPort();
+
+ /**
+ * Connects to AG client's socket.
+ *
+ * @param aAddr socket address
+ *
+ * @leave KErrInUse if the device is already being used
+ */
+ void GetSocketAndTryToConnectL( const TBTSockAddr &aAddr );
+
+protected:
+
+private:
+ /**
+ * Constructor for performing 1st stage construction
+ *
+ * @param aSocketServ session of socket server
+ */
+ CHsServer( RSocketServ &aSocketServ );
+
+ /**
+ * Constructor for performing 2nd stage construction
+ */
+ void ConstructL();
+
+private:
+ //Methods inhertited 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:
+
+ /** Listening status */
+ TBool iListen;
+
+ /** Server port */
+ TInt iPort;
+
+ /** Service security */
+ TBTServiceSecurity iServerSecurity;
+
+ /** Session of socket server */
+ RSocketServ &iSServ;
+
+ /** Socket for listening for new connections */
+ CBluetoothSocket *iSocketServer;
+
+ /** Client socket */
+ CBluetoothSocket *iBlankSocket;
+
+ /** Second client socket */
+ CBluetoothSocket *iBlankSocket2;
+
+ /** Pointer to observer */
+ MHsAcceptNewClientObserver *iNewClientObserver;
+};
+
+#endif // HSSERVER_H