bluetoothengine/headsetsimulator/core/inc/RemoteControl/hsremotecontrolserver.h
branchheadsetsimulator
changeset 60 90dbfc0435e3
equal deleted inserted replaced
59:02103bf20ee5 60:90dbfc0435e3
       
     1 /*
       
     2  * Component Name: Headset Simulator
       
     3  * Author: Comarch S.A.
       
     4  * Version: 1.0
       
     5  * Copyright (c) 2010 Comarch S.A.
       
     6  *  
       
     7  * This Software is submitted by Comarch S.A. to Symbian Foundation Limited on 
       
     8  * the basis of the Member Contribution Agreement entered between Comarch S.A. 
       
     9  * and Symbian Foundation Limited on 5th June 2009 (“Agreement”) and may be 
       
    10  * used only in accordance with the terms and conditions of the Agreement. 
       
    11  * Any other usage, duplication or redistribution of this Software is not 
       
    12  * allowed without written permission of Comarch S.A.
       
    13  * 
       
    14  */
       
    15 
       
    16 #ifndef HSREMOTECONTROLSERVER_H
       
    17 #define HSREMOTECONTROLSERVER_H
       
    18 
       
    19 #include <bt_sock.h> 
       
    20 #include <e32base.h>
       
    21 #include <es_sock.h>
       
    22 #include <btsdp.h>
       
    23 #include <hsclientobservers.h>
       
    24 
       
    25 class CHsCore;
       
    26 class CHsRemoteControlDataHandler;
       
    27 
       
    28 /**  
       
    29  * The id used for advertising and discovering the remote control service. 
       
    30  */
       
    31 const TUint32 KHsRemoteControlServiceID = 0xfabc234f;
       
    32 
       
    33 /** Avalaible service state */
       
    34 const TInt KServicAvailable = 0xFF;
       
    35 
       
    36 /** Unavalaible service state */
       
    37 const TInt KServiceUnavailable = 0x00;
       
    38 
       
    39 /** Buffer size */
       
    40 const TInt KHsRemoteControlBufferSize = 256;
       
    41 
       
    42 /** The number of connections allowed in the queue */
       
    43 const TInt KHsSizeOfListenQueue = 5;
       
    44 
       
    45 /** Useful constants */
       
    46 _LIT(KHsRFComm,"RFCOMM");
       
    47 _LIT(KServiceName, "HSControlServer");
       
    48 _LIT(KServiceDesc, "HSControlServer");
       
    49 
       
    50 /** Buffer for remote control */
       
    51 typedef TBuf8 <KHsRemoteControlBufferSize> THsRemoteControlBuffer;
       
    52 
       
    53 /**
       
    54  * @brief Server for remote control requests
       
    55  */
       
    56 class CHsControlServer : public CBase, public MBluetoothSocketNotifier
       
    57 {
       
    58 
       
    59 public:
       
    60 
       
    61     /**
       
    62      * Two-phased constructor.
       
    63      * 
       
    64      * @param aSocketServ sesion to socket server
       
    65      * @param aHsCore pointer to CHsCore
       
    66      * @return class instance
       
    67      */
       
    68     static CHsControlServer* NewL( RSocketServ& aSocketServ, CHsCore* aHsCore );
       
    69 
       
    70     /**
       
    71      * Two-phased constructor.
       
    72      * 
       
    73      * @param aSocketServ session to socket server
       
    74      * @param aHsCore pointer to CHsCore
       
    75      * @return class instance
       
    76      */
       
    77     static CHsControlServer* NewLC( RSocketServ& aSocketServ, 
       
    78             CHsCore* aHsCore );
       
    79 
       
    80     /**
       
    81      * Destructor.
       
    82      */
       
    83     ~CHsControlServer();
       
    84 
       
    85 public:
       
    86 
       
    87     /**
       
    88      * Turns on server for remote control
       
    89      */
       
    90     void StartRemoteControlServerL();
       
    91 
       
    92     /**
       
    93      * Stops remote control server. Cancels receiving and sending data, destroys
       
    94      * all CBluetoothSockets
       
    95      */
       
    96     void CancelListen();
       
    97 
       
    98     /**
       
    99      * Setter for observer
       
   100      * 
       
   101      * @param aConnectionObserver observer
       
   102      */
       
   103     void SetConnectionObserver(
       
   104             MRemoteControllerConnectionObserver &aConnectionObserver );
       
   105 
       
   106 private:
       
   107 
       
   108     /**
       
   109      * Constructor for performing 1st stage construction
       
   110      * 
       
   111      * @param aSocketServ sesion to socket server
       
   112      * @param aHsCore pointer to CHsCore
       
   113      */
       
   114     CHsControlServer( RSocketServ& aSocketServ, CHsCore* aHsCore );
       
   115 
       
   116     /**
       
   117      * Default constructor for performing 2nd stage construction
       
   118      */
       
   119     void ConstructL();
       
   120 
       
   121 private:
       
   122     /**
       
   123      * Sends data to client.
       
   124      * 
       
   125      * @param aData message to be send
       
   126      *  
       
   127      * @return error code
       
   128      */
       
   129     TInt Send( const TDesC8& aData );
       
   130 
       
   131     /**
       
   132      * Receives data from listening socket.
       
   133      */
       
   134     void Receive();
       
   135 
       
   136     /**
       
   137      * Registers service in SDP database
       
   138      *  
       
   139      * @param aChannel port number
       
   140      * @return error code. KErrNone if success
       
   141      */
       
   142     void RegisterSdpL( TInt aChannel );
       
   143 
       
   144     /**
       
   145      * Updates availability of service registered in SDP database
       
   146      * 
       
   147      * @param aAvailable service availability
       
   148      */
       
   149     void UpdateAvailabilityL( TBool aAvailable );
       
   150 
       
   151     /**
       
   152      * Deletes service record from SDP database
       
   153      */
       
   154     void DeleteRecordSdp();
       
   155 
       
   156     /**
       
   157      * Handles incoming remote control request
       
   158      * 
       
   159      * @param aRequest 8-bit desciptor containing request
       
   160      */
       
   161     void HandleRequestL( TDes8& aRequest );
       
   162 
       
   163     /**
       
   164      * Retrieves 'HsTurnOn' command's data needed for HS's initialization
       
   165      * 
       
   166      * @param aParams command's data
       
   167      * @param aPluginCod Cod plugin's name
       
   168      * @param aPluginSdp Sdp plugin's name
       
   169      * @param aPluginName profile plugin's name
       
   170      */
       
   171     void RetrieveStartupParamsL( const TDesC8& aParams, RBuf8& aPluginCod,
       
   172             RBuf8& aPluginSdp, RBuf8& aPluginProfile );
       
   173 
       
   174 private:
       
   175     //Methods inherited from MBluetoothSocketNotifier
       
   176 
       
   177     void HandleConnectCompleteL( TInt aErr );
       
   178 
       
   179     void HandleAcceptCompleteL( TInt aErr );
       
   180 
       
   181     void HandleShutdownCompleteL( TInt aErr );
       
   182 
       
   183     void HandleSendCompleteL( TInt aErr );
       
   184 
       
   185     void HandleReceiveCompleteL( TInt aErr );
       
   186 
       
   187     void HandleIoctlCompleteL( TInt aErr );
       
   188 
       
   189     void HandleActivateBasebandEventNotifierCompleteL( TInt aErr,
       
   190             TBTBasebandEventNotification& aEventNotification );
       
   191 
       
   192 private:
       
   193 
       
   194     /** States of the Remote control server */
       
   195     enum THsRemoteControlState
       
   196     {
       
   197         /** Not initialized */
       
   198         ENone = 1,
       
   199         /** Connection attempt ongoing */
       
   200         EConnecting,
       
   201         /** Ready for clients */
       
   202         EWaiting
       
   203     };
       
   204 
       
   205     /** Current state */
       
   206     THsRemoteControlState iState;
       
   207 
       
   208     /** Listening status */
       
   209     TBool iInitialized;
       
   210 
       
   211     /** Server port */
       
   212     TInt iServerPort;
       
   213 
       
   214     /** Service record state */
       
   215     TInt iRecordState;
       
   216 
       
   217     /** Data length */
       
   218     TSockXfrLength iDataLength;
       
   219 
       
   220     /** Holds received data */
       
   221     THsRemoteControlBuffer iReceiveDataBuffer;
       
   222 
       
   223     /** Used for buffering data */
       
   224     THsRemoteControlBuffer iTempDataBuffer;
       
   225 
       
   226     /** Holds data to be send */
       
   227     THsRemoteControlBuffer iSendDataBuffer;
       
   228 
       
   229     /** Service record */
       
   230     TSdpServRecordHandle iSdpRecordHandle;
       
   231 
       
   232     /** Service discovery database session */
       
   233     RSdp iSdpServer;
       
   234 
       
   235     /** Service discovery database subsession */
       
   236     RSdpDatabase iSdpDB;
       
   237 
       
   238     /** Creates subsession to socket server */
       
   239     RSocketServ &iSocketServ;
       
   240 
       
   241     /** Socket for listening for new connections */
       
   242     CBluetoothSocket *iListenSocket;
       
   243 
       
   244     /** Socket */
       
   245     CBluetoothSocket *iSocket;
       
   246 
       
   247     /** Pointer to CHsCore */
       
   248     CHsCore *iHsCore;
       
   249 
       
   250     /** Pointer to CHsRemoteControlDataHandler */
       
   251     CHsRemoteControlDataHandler* iDataHandler;
       
   252 
       
   253     /** Pointer to observer */
       
   254     MRemoteControllerConnectionObserver *iConnectionObserver;
       
   255 
       
   256 };
       
   257 
       
   258 #endif // HSREMOTECONTROLSERVER_H