bluetoothengine/headsetsimulator/core/inc/Server/hsaudioserver.h
branchheadsetsimulator
changeset 60 90dbfc0435e3
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/bluetoothengine/headsetsimulator/core/inc/Server/hsaudioserver.h	Wed Sep 15 15:59:44 2010 +0200
@@ -0,0 +1,155 @@
+/*
+ * 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 HSAUDIOSERVER_H_
+#define HSAUDIOSERVER_H_
+
+#include <e32std.h>
+#include <bt_sock.h>
+
+/** Buffer size */
+const TInt KHsSynchronousBufferLength = 128;
+
+/**
+ * @brief Server for SCO connections
+ */
+class CHsAudioServer : public CBase, public MBluetoothSynchronousLinkNotifier
+{
+public:
+    /**
+     * Two-phase constructor
+     * @param aSocketServ socket server session
+     * @param aPullAudio denotes if audio should be pulled
+     * @return instance of class
+     */
+    static CHsAudioServer* NewL( RSocketServ& aSocketServ, TBool aPullAudio );
+
+    /**
+     * Two-phase constructor
+     * @param aSocketServ socket server session
+     * @param aPullAudio denotes if audio should be pulled
+     * @return instance of class
+     */
+    static CHsAudioServer* NewLC( RSocketServ& aSocketServ, TBool aPullAudio );
+
+    /**
+     * Destructor
+     */
+    ~CHsAudioServer();
+
+public:
+
+    /**
+     * Prepares audio server for incoming connections
+     */
+    void ListenL();
+
+    /**
+     * Connects audio server to the specified device
+     * 
+     * @param aAddr device's bluetooth address
+     */
+    void ConnectL( const TBTDevAddr &aAddr );
+
+    /**
+     * Closes current connections and prepares the server for the new one
+     */
+    void Disconnect();
+
+    /**
+     * Turns off audio server
+     */
+    void Shutdown();
+
+    /**
+     * Method allows to accept \ reject SCO connection establishment 
+     * 
+     * @param aPullAudio ETrue if SCO connection is supposed to be accepted 
+     */
+    void SetPullAudio( TBool aPullAudio );
+
+    /**
+     * Checks if client is connected
+     * 
+     * @return ETrue if client connected
+     */
+    TBool IsConnected();
+
+    /**
+     * Checks if server is ready for incoming requests
+     * 
+     * @return ETrue if server is ready
+     */
+    TBool IsListen();
+
+private:
+
+    /**
+     * Constructor for performing 1st stage construction
+     * 
+     * @param aSocketServ socket server session
+     * @param aPullAudio denotes if audio should be pulled
+     */
+    CHsAudioServer( RSocketServ& aSocketServ, TBool aPullAudio );
+
+    /**
+     * Constructor for performing 2nd stage construction
+     */
+    void ConstructL();
+
+private:
+    // Methods derived from MBluetoothSynchronousLinkNotifier
+
+    void HandleSetupConnectionCompleteL( TInt aErr );
+
+    void HandleDisconnectionCompleteL( TInt aErr );
+
+    void HandleAcceptConnectionCompleteL( TInt aErr );
+
+    void HandleSendCompleteL( TInt aErr );
+
+    void HandleReceiveCompleteL( TInt aErr );
+
+private:
+
+    /** Session of socket server */
+    RSocketServ& iSServ;
+
+    /** SCO socket */
+    CBluetoothSynchronousLink* iSCOSocket;
+
+    /** Buffer for received data */
+    TBuf8 <KHsSynchronousBufferLength> iReceiveBuffer;
+
+    /** Buffer for data to be send */
+    TBuf8 <KHsSynchronousBufferLength> iSendBuffer;
+
+    /** Types of accepted SCO packets */
+    TBTSyncPackets iAcceptedPackets;
+
+    /** DevAddr of connected device */
+    TBTDevAddr iAddr;
+
+    /** Denotes if server is ready for incoming connections */
+    TBool iListening;
+
+    /** Denotes if client is connected */
+    TBool iConnected;
+
+    /** Denotes if audio should be transferred */
+    TBool iPullAudio;
+};
+
+#endif /* HSAUDIOSERVER_H_ */