|
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 HSREMOTECONTROLLER_H |
|
17 #define HSREMOTECONTROLLER_H |
|
18 |
|
19 #include <e32base.h> |
|
20 #include <bttypes.h> |
|
21 #include <bt_sock.h> |
|
22 #include <UTF.H> |
|
23 #include <hsrcbttoolsobserver.h> |
|
24 #include <hsremoterequest.h> |
|
25 |
|
26 _LIT(KHSRemoteControllerNotConnectedPanicMsg, |
|
27 "Not connected to Headset Simulator"); |
|
28 |
|
29 class CHsRCBTManager; |
|
30 |
|
31 /** Length of the remote request data */ |
|
32 const TInt KHsRemoteControlDataLength = 1024; |
|
33 |
|
34 /** Buffer for remote control */ |
|
35 typedef TBuf8 <KHsRemoteControlDataLength> THsRemoteControlBuffer; |
|
36 |
|
37 /** |
|
38 * @brief Interface for handling Headset Simulator Remote Controller's status |
|
39 */ |
|
40 class MHsRCObserver |
|
41 { |
|
42 |
|
43 public: |
|
44 /** |
|
45 * Informs about connection with Headset Simulator |
|
46 * |
|
47 * @param aErr error value. If aErr == KErrNone connection is established, |
|
48 * otherwise not. |
|
49 */ |
|
50 virtual void HandleConnectedToHs( TInt aErr ) = 0; |
|
51 |
|
52 /** |
|
53 * Informs about released connection with Headset Simulator |
|
54 */ |
|
55 virtual void HandleDisconnectedFromHs( TInt aErr ) = 0; |
|
56 |
|
57 /** |
|
58 * Informs that connection with Headset Simulator is being established |
|
59 */ |
|
60 virtual void HandleConnectingToHs() = 0; |
|
61 |
|
62 /** |
|
63 * Informs that remote request was sent |
|
64 * @param aType THsRemoteControlCommandType |
|
65 */ |
|
66 virtual void HandleRequestSent( THsRemoteControlCommandType aType ) = 0; |
|
67 }; |
|
68 |
|
69 /** |
|
70 * @brief Class responsible for remote control of Headset Simulator |
|
71 */ |
|
72 class CHsRemoteController : public CBase, public MBluetoothSocketNotifier, |
|
73 public MHsRCBTManagerObserver |
|
74 { |
|
75 public: |
|
76 /** |
|
77 * Two-phase constructor |
|
78 * @param aObserver pointer to MHsRCObserver |
|
79 * @return instance of class |
|
80 */ |
|
81 IMPORT_C static CHsRemoteController* NewL( MHsRCObserver* aObserver ); |
|
82 |
|
83 /** |
|
84 * Two-phase constructor |
|
85 * @param aObserver pointer to MHsRCObserver |
|
86 * @return instance of class |
|
87 */ |
|
88 IMPORT_C static CHsRemoteController* NewLC( MHsRCObserver* aObserver ); |
|
89 |
|
90 /** |
|
91 * Destructor |
|
92 */ |
|
93 IMPORT_C ~CHsRemoteController(); |
|
94 |
|
95 public: |
|
96 |
|
97 /** |
|
98 * Connects Headset Simulator by its bluetooth address |
|
99 * |
|
100 * When request completes notification is sent to |
|
101 * MHsRCObserver::HandleConnectedToHs() |
|
102 * |
|
103 * @param aDevAddr Headset Simulator's bluetooth address |
|
104 * @param aService Headset Simulator's Remote Control service TUUID |
|
105 * |
|
106 * @leave KErrInUse if connection with Headset Simulator is already |
|
107 * established |
|
108 */ |
|
109 IMPORT_C void ConnectHsDevAddrL( const TBTDevAddr& aDevAddr, |
|
110 const TUUID& aService ); |
|
111 |
|
112 /** |
|
113 * Connects Headset Simulator by its bluetooth name |
|
114 * |
|
115 * When request completes notification is sent to |
|
116 * MHsRCObserver::HandleConnectedToHs() |
|
117 * |
|
118 * @param aHsName Headset Simulator's bluetooth name |
|
119 * @param aService Headset Simulator's Remote Control service TUUID |
|
120 * |
|
121 * @leave KErrInUse if connection with Headset Simulator is |
|
122 * already established |
|
123 */ |
|
124 IMPORT_C void ConnectHsDevNameL( const TDesC& aHsName, |
|
125 const TUUID& aService ); |
|
126 |
|
127 /** |
|
128 * Cancels attempt of connection with Headset Simulator |
|
129 */ |
|
130 IMPORT_C void CancelConnectingToHs(); |
|
131 |
|
132 /** |
|
133 * Disconnects from Headset Simulator |
|
134 * |
|
135 * When request completes notification is sent to |
|
136 * MHsRCObserver::HandleDisconnectedFromHs() |
|
137 */ |
|
138 IMPORT_C void DisconnectFromHs(); |
|
139 |
|
140 //remote requests |
|
141 |
|
142 /** |
|
143 * Requests turning HS on (i.e. start providing headset service) |
|
144 * |
|
145 * @pre Established connection with Headset Simulator |
|
146 * @param aPluginCod CoD plugin's name |
|
147 * @param aPluginSdp SDP plugin's name |
|
148 * @param aPluginProfile Profile plugin's name |
|
149 */ |
|
150 IMPORT_C void ReqTurnOnHs( const TDesC& aPluginCod, |
|
151 const TDesC& aPluginSdp, const TDesC& aPluginProfile ); |
|
152 |
|
153 /** |
|
154 * Requests turning HS off (i.e. stop providing headset service) |
|
155 * |
|
156 * @pre Established connection with Headset Simulator |
|
157 */ |
|
158 IMPORT_C void ReqTurnOffHs(); |
|
159 |
|
160 /** |
|
161 * Requests connection establishment between Headset Simulator and AG |
|
162 * with specified bluetooth address. Address should be lower-case. |
|
163 * |
|
164 * @pre Established connection with Headset Simulator |
|
165 * |
|
166 * @param aDevAddr AG's bluetooth device address |
|
167 */ |
|
168 IMPORT_C void ReqConnectWithDevAddr( const TBTDevAddr& aDevAddr ); |
|
169 |
|
170 /** |
|
171 * Requests connection establishment between Headset Simulator and AG |
|
172 * with specified bluetooth name |
|
173 * |
|
174 * @pre Established connection with Headset Simulator |
|
175 * |
|
176 * @param aDevName AG's bluetooth device name |
|
177 */ |
|
178 IMPORT_C void ReqConnectWithDevName( const TDesC& aDevName ); |
|
179 |
|
180 /** |
|
181 * Requests connection establishment between Headset Simulator and |
|
182 * last-connected AG |
|
183 * |
|
184 * @pre Established connection with Headset Simulator |
|
185 */ |
|
186 IMPORT_C void ReqConnectWithLastConnected(); |
|
187 |
|
188 /** |
|
189 * Requests accept incoming call on AG |
|
190 * |
|
191 * @pre Established connection with Headset Simulator |
|
192 */ |
|
193 IMPORT_C void ReqAcceptCall(); |
|
194 |
|
195 /** |
|
196 * Requests call release on AG |
|
197 * |
|
198 * @pre Established connection with Headset Simulator |
|
199 */ |
|
200 IMPORT_C void ReqReleaseCall(); |
|
201 |
|
202 /** |
|
203 * Requests setting AG's microphone gain |
|
204 * |
|
205 * @pre Established connection with Headset Simulator |
|
206 * |
|
207 * @param aValue text-value |
|
208 */ |
|
209 IMPORT_C void ReqSetMicGain( const TDesC& aValue ); |
|
210 |
|
211 /** |
|
212 * Requests setting AG's speaker volume |
|
213 * |
|
214 * @pre Established connection with Headset Simulator |
|
215 * |
|
216 * @param aValue text-value |
|
217 */ |
|
218 IMPORT_C void ReqSetSpeakerVolume( const TDesC& aValue ); |
|
219 |
|
220 /** |
|
221 * Requests sending any AT command |
|
222 * |
|
223 * @pre Established connection with Headset Simulator |
|
224 * |
|
225 * @param aValue text-value |
|
226 */ |
|
227 IMPORT_C void ReqSendAnyAt( const TDesC& aValue ); |
|
228 |
|
229 /** |
|
230 * Requests disconnection of AG from Headset Simulator |
|
231 * |
|
232 * @pre Established connection with Headset Simulator |
|
233 */ |
|
234 IMPORT_C void ReqDisconnectAG(); |
|
235 |
|
236 private: |
|
237 /** |
|
238 * Constructor for performing 1st stage construction |
|
239 * |
|
240 * @param aObserver pointer to MHsRCObserver |
|
241 */ |
|
242 CHsRemoteController( MHsRCObserver* aObserver ); |
|
243 |
|
244 /** |
|
245 * Constructor for performing 2nd stage construction |
|
246 */ |
|
247 void ConstructL(); |
|
248 |
|
249 private: |
|
250 /** |
|
251 * Sends request to Headset Simulator |
|
252 * |
|
253 * @param aCommandType type of command |
|
254 * @param aData additional data send within request |
|
255 */ |
|
256 void SendRequest( const THsRemoteControlCommandType aCommandType, |
|
257 const TDesC& aData = KNullDesC ); |
|
258 |
|
259 /** |
|
260 * Sends data (THsRCCommand as a descriptor) to remote bluetooth device |
|
261 * |
|
262 * @param aData data to be send |
|
263 * @return error value |
|
264 */ |
|
265 TInt Send( const TDesC8& aData ); |
|
266 |
|
267 /** |
|
268 * Receives data from remote bluetooth device |
|
269 */ |
|
270 void Receive(); |
|
271 |
|
272 /** |
|
273 * Connects with Headset Simulator's Remote Control server |
|
274 * |
|
275 * @param aAddr Headset Simulator's bluetooth address |
|
276 * @param aPort Headset Simulator's remote controls's server port |
|
277 * |
|
278 * @return error value |
|
279 */ |
|
280 TInt ConnectRemoteControlServer( const TBTDevAddr &aAddr, const TInt aPort ); |
|
281 |
|
282 /** |
|
283 * Creates component responsible for handling bluetooth |
|
284 * |
|
285 * @return error value |
|
286 */ |
|
287 TInt CreateBTManager(); |
|
288 |
|
289 private: |
|
290 //Methods inherited from MBluetoothSocketNotifier |
|
291 |
|
292 void HandleConnectCompleteL( TInt aErr ); |
|
293 |
|
294 void HandleAcceptCompleteL( TInt aErr ); |
|
295 |
|
296 void HandleShutdownCompleteL( TInt aErr ); |
|
297 |
|
298 void HandleSendCompleteL( TInt aErr ); |
|
299 |
|
300 void HandleReceiveCompleteL( TInt aErr ); |
|
301 |
|
302 void HandleIoctlCompleteL( TInt aErr ); |
|
303 |
|
304 void HandleActivateBasebandEventNotifierCompleteL( TInt aErr, |
|
305 TBTBasebandEventNotification& aEventNotification ); |
|
306 |
|
307 private: |
|
308 //Methods inherited from MHsRCBTManagerObserver |
|
309 |
|
310 void HandleDesiredDevFound( const TDesC& aDevName, |
|
311 const TBTDevAddr& aDevAddr, const TInt aPort ); |
|
312 |
|
313 void HandleDesiredDevNotFound( TInt aErr ); |
|
314 |
|
315 private: |
|
316 |
|
317 /** received data */ |
|
318 THsRemoteControlBuffer iReceiveDataBuffer; |
|
319 |
|
320 /** data to be sent */ |
|
321 THsRemoteControlBuffer iSendDataBuffer; |
|
322 |
|
323 /** buffered data */ |
|
324 THsRemoteControlBuffer iTempDataBuffer; |
|
325 |
|
326 /** data length */ |
|
327 TSockXfrLength iDataLength; |
|
328 |
|
329 /** instance of socket server */ |
|
330 RSocketServ iSocketServ; |
|
331 |
|
332 /** denotes if connection with Headset Simulator is established */ |
|
333 TBool iConnected; |
|
334 |
|
335 /** pointer to CHsRCBTManager, owned */ |
|
336 CHsRCBTManager* iBTManager; |
|
337 |
|
338 /** pointer to CBluetoothSocket, owned */ |
|
339 CBluetoothSocket* iSocket; |
|
340 |
|
341 /** pointer to MHsRCObserver, not owned */ |
|
342 MHsRCObserver* iObserver; |
|
343 |
|
344 }; |
|
345 |
|
346 #endif // HSREMOTECONTROLLER_H |