|
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 HSCLIENT_H_ |
|
17 #define HSCLIENT_H_ |
|
18 |
|
19 #include <bt_sock.h> |
|
20 |
|
21 class MHsClientObserver; |
|
22 class MHsClientStateNotifier; |
|
23 |
|
24 /** Length of AG's receive and send data buffer */ |
|
25 const TInt32 KHsClientBufferLength = 0x800; |
|
26 |
|
27 /** Buffer for communication with AG */ |
|
28 typedef TBuf8 <KHsClientBufferLength> THsClientBuffer; |
|
29 |
|
30 /** |
|
31 * @brief Class represents AG client. |
|
32 */ |
|
33 class CHsClient : public CBase, public MBluetoothSocketNotifier |
|
34 { |
|
35 public: |
|
36 |
|
37 /** |
|
38 * Two-phase constructor |
|
39 * |
|
40 * @param aClient socket which AG is connected |
|
41 * @param aClientStateNotifier pointer to AG state observer |
|
42 * @param aClientDisconnectNotifier pointer to AG disconnection observer |
|
43 * @return instance of class |
|
44 */ |
|
45 static CHsClient* NewL( CBluetoothSocket* aClient, |
|
46 MHsClientStateNotifier* aClientStateNotifier = NULL, |
|
47 MHsClientObserver* aClientDisconnectNotifier = NULL ); |
|
48 |
|
49 /** |
|
50 * Two-phase constructor |
|
51 * |
|
52 * @param aClient socket which AG is connected |
|
53 * @param aClientStateNotifier pointer to AG state observer |
|
54 * @param aClientDisconnectNotifier pointer to AG disconnection observer |
|
55 * @return instance of class |
|
56 */ |
|
57 static CHsClient* NewLC( CBluetoothSocket* aClient, |
|
58 MHsClientStateNotifier* aClientStateNotifier = NULL, |
|
59 MHsClientObserver* aClientDisconnectNotifier = NULL ); |
|
60 |
|
61 /** |
|
62 * Destructor |
|
63 */ |
|
64 ~CHsClient(); |
|
65 |
|
66 public: |
|
67 /** |
|
68 * Sends data to AG. |
|
69 * |
|
70 * @pre AG client is connected |
|
71 * |
|
72 * @param aData data to be send |
|
73 */ |
|
74 void Send( const TDesC8& aData ); |
|
75 |
|
76 /** |
|
77 * Sets observer of AG's disconnection. |
|
78 * |
|
79 * @param aNotifier reference to MHsClientObserver |
|
80 */ |
|
81 void SetClientDisconnectNotfier( MHsClientObserver& aNotifier ); |
|
82 |
|
83 /** |
|
84 * Sets observer of AG's states. |
|
85 * |
|
86 * @param aNotifier reference to MHsClientStateNotifier |
|
87 */ |
|
88 void SetClientStateNotfier( MHsClientStateNotifier& aNotifier ); |
|
89 |
|
90 /** |
|
91 * Returns pointer to AG's states observer. |
|
92 */ |
|
93 MHsClientStateNotifier* GetClientStateNotifer(); |
|
94 |
|
95 private: |
|
96 /** |
|
97 * Constructor for performing 1st stage construction |
|
98 * |
|
99 * @param aClient socket which AG is connected |
|
100 * @param aClientStateNotifier pointer to AG state observer |
|
101 * @param aClientDisconnectNotifier pointer to AG disconnection observer |
|
102 */ |
|
103 CHsClient( CBluetoothSocket& aClient, |
|
104 MHsClientStateNotifier* aClientStateNotifier = NULL, |
|
105 MHsClientObserver* aClientDisconnectNotifier = NULL ); |
|
106 |
|
107 /** |
|
108 * Constructor for performing 2nd stage construction |
|
109 */ |
|
110 void ConstructL(); |
|
111 |
|
112 private: |
|
113 |
|
114 /** |
|
115 * Receives data from AG. |
|
116 * |
|
117 * @param aData received data buffer |
|
118 * |
|
119 * @leave KErrNoMemory if AG socket is NULL |
|
120 * @leave KErrDisconnected if AG is not connected |
|
121 */ |
|
122 void RawRecvL( TDes8& aData ); |
|
123 |
|
124 /** |
|
125 * Sends data to AG. |
|
126 * |
|
127 * @param aData data to be send |
|
128 * |
|
129 * @leave KErrNoMemory if AG socket is NULL |
|
130 * @leave KErrDisconnected if AG is not connected |
|
131 * @leave KErrWrite if parameter is empty |
|
132 */ |
|
133 void RawSendL( const TDesC8& aData ); |
|
134 |
|
135 /** |
|
136 * Sends data to AG with double buffering and init receiving when there |
|
137 * is no data to be send. |
|
138 * |
|
139 * @param aData data to be send |
|
140 */ |
|
141 void BufferedProcessL( const TDesC8& aData = KNullDesC8 ); |
|
142 |
|
143 /** |
|
144 * Swaps sending buffers. |
|
145 */ |
|
146 void SwapBuffers(); |
|
147 |
|
148 private: |
|
149 //Methods derived from MBluetoothSocketNotifier |
|
150 void HandleConnectCompleteL( TInt aErr ); |
|
151 |
|
152 void HandleAcceptCompleteL( TInt aErr ); |
|
153 |
|
154 void HandleShutdownCompleteL( TInt aErr ); |
|
155 |
|
156 void HandleSendCompleteL( TInt aErr ); |
|
157 |
|
158 void HandleReceiveCompleteL( TInt aErr ); |
|
159 |
|
160 void HandleIoctlCompleteL( TInt aErr ); |
|
161 |
|
162 void HandleActivateBasebandEventNotifierCompleteL( TInt aErr, |
|
163 TBTBasebandEventNotification& aEventNotification ); |
|
164 |
|
165 private: |
|
166 |
|
167 /** AG client state enum */ |
|
168 enum THsClientState |
|
169 { |
|
170 /** Idle state */ |
|
171 EIdle = 0, |
|
172 /** Sending state */ |
|
173 ESending, |
|
174 /** Receiving state */ |
|
175 EReceiving |
|
176 }; |
|
177 |
|
178 /** AG client's state */ |
|
179 THsClientState iState; |
|
180 |
|
181 /** Bluetooth information receive flags */ |
|
182 TInt iReceiveFlag; |
|
183 |
|
184 /** Bluetooth information send flags */ |
|
185 TInt iSendFlag; |
|
186 |
|
187 /** Denotes if AG is connected */ |
|
188 TBool iConnected; |
|
189 |
|
190 /** Length indicating how much data was read */ |
|
191 TSockXfrLength iReceiveMessageLength; |
|
192 |
|
193 /** Receive data buffer */ |
|
194 THsClientBuffer iReceiveMessageBuffer; |
|
195 |
|
196 /** Send data buffer */ |
|
197 THsClientBuffer iSendBuf; |
|
198 |
|
199 /** Temporary send data buffer */ |
|
200 THsClientBuffer iTempSendBuf; |
|
201 |
|
202 /** Bluetooth socket */ |
|
203 CBluetoothSocket* iSocket; |
|
204 |
|
205 /** Pointer to MHsClientStateNotifier. Not owned */ |
|
206 MHsClientStateNotifier* iStateNotifier; |
|
207 |
|
208 /** Pointer to MHsClientObserver. Not owned */ |
|
209 MHsClientObserver* iClientObserver; |
|
210 }; |
|
211 |
|
212 #endif /* HSCLIENT_H_ */ |