bluetoothengine/headsetsimulator/remotecontroller/inc/hsremotecontroller.h
branchheadsetsimulator
changeset 60 90dbfc0435e3
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/bluetoothengine/headsetsimulator/remotecontroller/inc/hsremotecontroller.h	Wed Sep 15 15:59:44 2010 +0200
@@ -0,0 +1,346 @@
+/*
+ * 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 HSREMOTECONTROLLER_H
+#define HSREMOTECONTROLLER_H
+
+#include <e32base.h>
+#include <bttypes.h> 
+#include <bt_sock.h>
+#include <UTF.H>
+#include <hsrcbttoolsobserver.h>
+#include <hsremoterequest.h>
+
+_LIT(KHSRemoteControllerNotConnectedPanicMsg,
+        "Not connected to Headset Simulator");
+
+class CHsRCBTManager;
+
+/** Length of the remote request data */
+const TInt KHsRemoteControlDataLength = 1024;
+
+/** Buffer for remote control */
+typedef TBuf8 <KHsRemoteControlDataLength> THsRemoteControlBuffer;
+
+/**
+ * @brief Interface for handling Headset Simulator Remote Controller's status
+ */
+class MHsRCObserver
+{
+
+public:
+    /**
+     * Informs about connection with Headset Simulator
+     * 
+     * @param aErr error value. If aErr == KErrNone connection is established, 
+     * otherwise not. 
+     */
+    virtual void HandleConnectedToHs( TInt aErr ) = 0;
+
+    /**
+     * Informs about released connection with Headset Simulator
+     */
+    virtual void HandleDisconnectedFromHs( TInt aErr ) = 0;
+
+    /**
+     * Informs that connection with Headset Simulator is being established 
+     */
+    virtual void HandleConnectingToHs() = 0;
+
+    /**
+     * Informs that remote request was sent
+     * @param aType THsRemoteControlCommandType
+     */
+    virtual void HandleRequestSent( THsRemoteControlCommandType aType ) = 0;
+};
+
+/**
+ * @brief Class responsible for remote control of Headset Simulator
+ */
+class CHsRemoteController : public CBase, public MBluetoothSocketNotifier,
+        public MHsRCBTManagerObserver
+{
+public:
+    /**
+     * Two-phase constructor
+     * @param aObserver pointer to MHsRCObserver
+     * @return instance of class
+     */
+    IMPORT_C static CHsRemoteController* NewL( MHsRCObserver* aObserver );
+
+    /**
+     * Two-phase constructor
+     * @param aObserver pointer to MHsRCObserver
+     * @return instance of class
+     */
+    IMPORT_C static CHsRemoteController* NewLC( MHsRCObserver* aObserver );
+
+    /**
+     * Destructor
+     */
+    IMPORT_C ~CHsRemoteController();
+
+public:
+
+    /**
+     * Connects Headset Simulator by its bluetooth address
+     * 
+     * When request completes notification is sent to 
+     * MHsRCObserver::HandleConnectedToHs()
+     * 
+     * @param aDevAddr Headset Simulator's bluetooth address
+     * @param aService Headset Simulator's Remote Control service TUUID
+     * 
+     * @leave KErrInUse if connection with Headset Simulator is already 
+     *        established 
+     */
+    IMPORT_C void ConnectHsDevAddrL( const TBTDevAddr& aDevAddr,
+            const TUUID& aService );
+
+    /**
+     * Connects Headset Simulator by its bluetooth name
+     * 
+     * When request completes notification is sent to 
+     * MHsRCObserver::HandleConnectedToHs()
+     * 
+     * @param aHsName Headset Simulator's bluetooth name
+     * @param aService Headset Simulator's Remote Control service TUUID
+     * 
+     * @leave KErrInUse if connection with Headset Simulator is 
+     *        already established
+     */
+    IMPORT_C void ConnectHsDevNameL( const TDesC& aHsName,
+            const TUUID& aService );
+
+    /**
+     * Cancels attempt of connection with Headset Simulator
+     */
+    IMPORT_C void CancelConnectingToHs();
+
+    /**
+     * Disconnects from Headset Simulator
+     *
+     * When request completes notification is sent to 
+     * MHsRCObserver::HandleDisconnectedFromHs()
+     */
+    IMPORT_C void DisconnectFromHs();
+
+    //remote requests
+
+    /**
+     * Requests turning HS on (i.e. start providing headset service)
+     * 
+     * @pre Established connection with Headset Simulator
+     * @param aPluginCod CoD plugin's name
+     * @param aPluginSdp SDP plugin's name
+     * @param aPluginProfile Profile plugin's name
+     */
+    IMPORT_C void ReqTurnOnHs( const TDesC& aPluginCod,
+            const TDesC& aPluginSdp, const TDesC& aPluginProfile );
+
+    /**
+     * Requests turning HS off (i.e. stop providing headset service)
+     * 
+     * @pre Established connection with Headset Simulator
+     */
+    IMPORT_C void ReqTurnOffHs();
+    
+    /**
+     * Requests connection establishment between Headset Simulator and AG 
+     * with specified bluetooth address. Address should be lower-case.
+     * 
+     * @pre Established connection with Headset Simulator
+     * 
+     * @param aDevAddr AG's bluetooth device address
+     */
+    IMPORT_C void ReqConnectWithDevAddr( const TBTDevAddr& aDevAddr );
+
+    /**
+     * Requests connection establishment between Headset Simulator and AG 
+     * with specified bluetooth name
+     * 
+     * @pre Established connection with Headset Simulator 
+     * 
+     * @param aDevName AG's bluetooth device name
+     */
+    IMPORT_C void ReqConnectWithDevName( const TDesC& aDevName );
+
+    /**
+     * Requests connection establishment between Headset Simulator and 
+     * last-connected AG
+     * 
+     * @pre Established connection with Headset Simulator 
+     */
+    IMPORT_C void ReqConnectWithLastConnected();
+
+    /**
+     * Requests accept incoming call on AG
+     * 
+     * @pre Established connection with Headset Simulator 
+     */
+    IMPORT_C void ReqAcceptCall();
+
+    /**
+     * Requests call release on AG
+     * 
+     * @pre Established connection with Headset Simulator 
+     */
+    IMPORT_C void ReqReleaseCall();
+
+    /**
+     * Requests setting AG's microphone gain
+     * 
+     * @pre Established connection with Headset Simulator
+     * 
+     * @param aValue text-value 
+     */
+    IMPORT_C void ReqSetMicGain( const TDesC& aValue );
+
+    /**
+     * Requests setting AG's speaker volume
+     * 
+     * @pre Established connection with Headset Simulator
+     * 
+     * @param aValue text-value 
+     */
+    IMPORT_C void ReqSetSpeakerVolume( const TDesC& aValue );
+
+    /**
+     * Requests sending any AT command
+     * 
+     * @pre Established connection with Headset Simulator
+     * 
+     * @param aValue text-value 
+     */
+    IMPORT_C void ReqSendAnyAt( const TDesC& aValue );
+
+    /**
+     * Requests disconnection of AG from Headset Simulator
+     * 
+     * @pre Established connection with Headset Simulator
+     */
+    IMPORT_C void ReqDisconnectAG();
+
+private:
+    /**
+     * Constructor for performing 1st stage construction
+     * 
+     * @param aObserver pointer to MHsRCObserver
+     */
+    CHsRemoteController( MHsRCObserver* aObserver );
+
+    /**
+     * Constructor for performing 2nd stage construction
+     */
+    void ConstructL();
+
+private:
+    /**
+     * Sends request to Headset Simulator
+     * 
+     * @param aCommandType type of command
+     * @param aData additional data send within request
+     */
+    void SendRequest( const THsRemoteControlCommandType aCommandType,
+            const TDesC& aData = KNullDesC );
+
+    /**
+     * Sends data (THsRCCommand as a descriptor) to remote bluetooth device
+     * 
+     * @param aData data to be send
+     * @return error value
+     */
+    TInt Send( const TDesC8& aData );
+
+    /**
+     *  Receives data from remote bluetooth device
+     */
+    void Receive();
+
+    /**
+     * Connects with Headset Simulator's Remote Control server
+     * 
+     * @param aAddr Headset Simulator's bluetooth address
+     * @param aPort Headset Simulator's remote controls's server port
+     * 
+     * @return error value
+     */
+    TInt ConnectRemoteControlServer( const TBTDevAddr &aAddr, const TInt aPort );
+
+    /**
+     * Creates component responsible for handling bluetooth 
+     * 
+     * @return error value
+     */
+    TInt CreateBTManager();
+
+private:
+    //Methods inherited 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:
+    //Methods inherited from MHsRCBTManagerObserver
+
+    void HandleDesiredDevFound( const TDesC& aDevName,
+            const TBTDevAddr& aDevAddr, const TInt aPort );
+
+    void HandleDesiredDevNotFound( TInt aErr );
+
+private:
+
+    /** received data */
+    THsRemoteControlBuffer iReceiveDataBuffer;
+
+    /** data to be sent */
+    THsRemoteControlBuffer iSendDataBuffer;
+
+    /** buffered data */
+    THsRemoteControlBuffer iTempDataBuffer;
+
+    /** data length */
+    TSockXfrLength iDataLength;
+
+    /** instance of socket server */
+    RSocketServ iSocketServ;
+
+    /** denotes if connection with Headset Simulator is established */
+    TBool iConnected;
+
+    /** pointer to CHsRCBTManager, owned */
+    CHsRCBTManager* iBTManager;
+
+    /** pointer to CBluetoothSocket, owned */
+    CBluetoothSocket* iSocket;
+
+    /** pointer to MHsRCObserver, not owned */
+    MHsRCObserver* iObserver;
+
+};
+
+#endif // HSREMOTECONTROLLER_H