|
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 HSCORE_H |
|
17 #define HSCORE_H |
|
18 |
|
19 #include <es_sock.h> |
|
20 #include <btdevice.h> |
|
21 #include <bttypes.h> |
|
22 #include <hsobserver.h> |
|
23 #include <hsclientobservers.h> |
|
24 |
|
25 class CHsProfileManager; |
|
26 class CHsControlServer; |
|
27 class CHsServer; |
|
28 class CHsClientManager; |
|
29 class CHsBTManager; |
|
30 class CHsAudioServer; |
|
31 |
|
32 /** Index of AG to which data should be send */ |
|
33 const TInt KHsClientSendNumber = 0; |
|
34 |
|
35 /** Length of plugin identificator data */ |
|
36 const TInt KHsIdentificationFieldBufSize = 128; |
|
37 |
|
38 /** Length of command data */ |
|
39 const TInt32 KHsBufferLength = 0x800; |
|
40 |
|
41 /** Headset property Uid */ |
|
42 const TUid KHSProperty = |
|
43 { |
|
44 0x1000008d |
|
45 }; |
|
46 |
|
47 /** Length of last-connected device bluetooth address */ |
|
48 const TInt KLastDevAddrLength = KBTDevAddrSize * 2; |
|
49 |
|
50 /** Headset property key enum */ |
|
51 enum THSPropertyKey |
|
52 { |
|
53 /** Last-connected AG*/ |
|
54 ELastDevice |
|
55 }; |
|
56 |
|
57 /** Bluetooth friendly name of device */ |
|
58 typedef TBuf <KMaxFriendlyNameLen> TBTFriendlyName; |
|
59 |
|
60 /** Data buffer from profile to be send to client */ |
|
61 typedef TBuf8 <KHsBufferLength> TBufferFromProfileToClient; |
|
62 |
|
63 /** |
|
64 * @brief Class responsible for main functionality of Headset Simulator. |
|
65 */ |
|
66 class CHsCore : public CBase, public MHsClientStateNotifier, |
|
67 public MHsAcceptNewClientObserver, public MHsBTManagerObserver, |
|
68 public MRemoteControllerConnectionObserver |
|
69 { |
|
70 public: |
|
71 /** |
|
72 * Two-phase constructor |
|
73 * @param aService service UUID |
|
74 * @return instance of class |
|
75 */ |
|
76 IMPORT_C static CHsCore* NewL( const TUUID &aService ); |
|
77 |
|
78 /** |
|
79 * Two-phase constructor |
|
80 * @param aService service UUID |
|
81 * @return instance of class |
|
82 */ |
|
83 IMPORT_C static CHsCore* NewLC( const TUUID &aService ); |
|
84 |
|
85 /** |
|
86 * Destructor |
|
87 */ |
|
88 IMPORT_C ~CHsCore(); |
|
89 |
|
90 public: |
|
91 /** |
|
92 * Starts simulation of Headset. |
|
93 * Turns bluetooth on and sets local name, starts Headset server, loads |
|
94 * CoD, Sdp and profile plugins. |
|
95 * |
|
96 * @param aCoDUid Class of Device Uid |
|
97 * @param aSdpUid Sdp Uid |
|
98 * @param aProfileUid profile Uid |
|
99 * @param aBTName bluetooth name |
|
100 */ |
|
101 IMPORT_C void StartSimulationL( const TUid &aCoDUid, const TUid &aSdpUid, |
|
102 const TUid &aProfileUid, const TDesC &aBTName = KNullDesC ); |
|
103 |
|
104 /** |
|
105 * Starts simulation of Headset. |
|
106 * Turns bluetooth on and sets local name, starts Headset server, loads |
|
107 * CoD, Sdp and profile plugins. |
|
108 * |
|
109 * @param aCoDUid Class of Device Uid as descriptor |
|
110 * @param aSdpUid Sdp Uid as descriptor |
|
111 * @param aProfileUid profile Uid as descriptor |
|
112 * @param aBTName bluetooth name |
|
113 */ |
|
114 IMPORT_C void StartSimulationL( const TDesC8 &aCoDUid, |
|
115 const TDesC8 &aSdpUid, const TDesC8 &aProfileUid, |
|
116 const TDesC &aBTName = KNullDesC ); |
|
117 |
|
118 /** |
|
119 * Stops simulation of Headset. |
|
120 * Disconnects from AGs, Remote Controller, restores initial bluetooth |
|
121 * settings. |
|
122 */ |
|
123 IMPORT_C void StopSimulation(); |
|
124 |
|
125 /** |
|
126 * Connects AG by its bluetooth name. |
|
127 * |
|
128 * When request completes with success notification is sent to |
|
129 * MHsObserver::HandleConnectedToClient(), otherwise to |
|
130 * MHsObserver::HandleUnableToConnectClient(). |
|
131 * |
|
132 * @param aName AG's bluetooth name |
|
133 */ |
|
134 IMPORT_C void ConnectWithName( const TDesC &aName ); |
|
135 |
|
136 /** |
|
137 * Connects AG by its bluetooth address. |
|
138 * |
|
139 * When request completes with success notification is sent to |
|
140 * MHsObserver::HandleConnectedToClient(), otherwise to |
|
141 * MHsObserver::HandleUnableToConnectClient(). |
|
142 * |
|
143 * @param aDevAddress AG's bluetooth address |
|
144 */ |
|
145 IMPORT_C void ConnectWithDevAddress( const TDesC &aDevAddress ); |
|
146 |
|
147 /** |
|
148 * Connects last-connected AG. |
|
149 * |
|
150 * When request completes with success notification is sent to |
|
151 * MHsObserver::HandleConnectedToClient(), otherwise to |
|
152 * MHsObserver::HandleUnableToConnectClient(). |
|
153 * |
|
154 * @pre Invocation of this method must be after at least one call of |
|
155 * ConnectWithName or ConnectWithDevAddress which saves connection |
|
156 * parameters. |
|
157 */ |
|
158 IMPORT_C void ConnectWithLastConnectedL(); |
|
159 |
|
160 /** |
|
161 * Cancels attempt of connection with AG. |
|
162 */ |
|
163 IMPORT_C void CancelConnecting(); |
|
164 |
|
165 /** |
|
166 * Disconnects from AGs. |
|
167 * |
|
168 * When request completes notification is sent to |
|
169 * MHsObserver::HandleDisconnectedFromClient(). |
|
170 */ |
|
171 IMPORT_C void DisconnectClients(); |
|
172 |
|
173 /** |
|
174 * Sends command to AG. Data is handled by profile manager before. |
|
175 * |
|
176 * @param aData data to be handled and response send |
|
177 * @param aNumber specifies to which AG response command should be send |
|
178 * @return KErrNone if successful, otherwise one of the system-wide |
|
179 * error codes |
|
180 */ |
|
181 IMPORT_C TInt Send( const TDesC8 &aData, |
|
182 TInt aNumber = KHsClientSendNumber ); |
|
183 |
|
184 /** |
|
185 * Sets observer of Headset actions. |
|
186 * |
|
187 * @param aObserver reference to MHsObserver |
|
188 */ |
|
189 IMPORT_C void SetObserver( MHsObserver &aObserver ); |
|
190 |
|
191 /** |
|
192 * Accepts incoming call. If call is not pending, nothing happens. |
|
193 * |
|
194 * @return error value |
|
195 */ |
|
196 IMPORT_C TInt AcceptIncomingCall(); |
|
197 |
|
198 /** |
|
199 * Releases ongoing call. If call does not exist, nothing happens. |
|
200 * |
|
201 * @return error value |
|
202 */ |
|
203 IMPORT_C TInt ReleaseOngoingCall(); |
|
204 |
|
205 private: |
|
206 /** |
|
207 * Constructor for performing 1st stage construction |
|
208 * |
|
209 * @param aService service UUID |
|
210 */ |
|
211 CHsCore( const TUUID &aService ); |
|
212 |
|
213 /** |
|
214 * Constructor for performing 2nd stage construction |
|
215 */ |
|
216 void ConstructL(); |
|
217 |
|
218 private: |
|
219 |
|
220 /** |
|
221 * Simulation initialization. Starts bluetooth with optionally |
|
222 * specified name and server |
|
223 * |
|
224 * @param aBTName bluetooth name |
|
225 */ |
|
226 void InitializeSimulationL( const TDesC &aBTName = KNullDesC ); |
|
227 |
|
228 /** |
|
229 * Registers Headset property. |
|
230 */ |
|
231 void RegisterProperty(); |
|
232 |
|
233 /** |
|
234 * Creates Headset components. |
|
235 * |
|
236 * @leave system-wide error codes if any component's creation fails. |
|
237 */ |
|
238 void CreateComponentsL(); |
|
239 |
|
240 /** |
|
241 * Destroys Headset components. |
|
242 */ |
|
243 void DestroyComponents(); |
|
244 |
|
245 /** |
|
246 * Creates Headset server. |
|
247 * |
|
248 * @return KErrNone if successful, otherwise one of the system-wide |
|
249 * error codes |
|
250 */ |
|
251 TInt CreateHSServer(); |
|
252 |
|
253 /** |
|
254 * Starts Headset server. |
|
255 * |
|
256 * @return KErrNone if successful, otherwise one of the system-wide |
|
257 * error codes |
|
258 */ |
|
259 TInt StartHSServer(); |
|
260 |
|
261 /** |
|
262 * Stops Headset server. |
|
263 */ |
|
264 void StopHSServer(); |
|
265 |
|
266 /** |
|
267 * Destroys Headset server. |
|
268 */ |
|
269 void DestroyHSServer(); |
|
270 |
|
271 /** |
|
272 * Creates audio server. |
|
273 * |
|
274 * @return KErrNone if successful, otherwise one of the system-wide |
|
275 * error code |
|
276 */ |
|
277 TInt CreateAudioServer( TBool aPullAudio = EFalse ); |
|
278 |
|
279 /** |
|
280 * Starts audio server. |
|
281 * |
|
282 * @param aPullAudio denotes if SCO should be accepted |
|
283 * @return KErrNone if successful, otherwise one of the system-wide |
|
284 * error code |
|
285 * |
|
286 */ |
|
287 TInt StartAudioServer( TBool aPullAudio = EFalse ); |
|
288 |
|
289 /** |
|
290 * Stops audio server. |
|
291 */ |
|
292 void StopAudioServer(); |
|
293 |
|
294 /** |
|
295 * Destroys audio server. |
|
296 */ |
|
297 void DestroyAudioServer(); |
|
298 |
|
299 /** |
|
300 * Creates AG clients manager. |
|
301 * |
|
302 * @return KErrNone if successful, otherwise one of the system-wide |
|
303 * error codes |
|
304 */ |
|
305 TInt CreateClientManager(); |
|
306 |
|
307 /** |
|
308 * Destroys AG clients manager. |
|
309 */ |
|
310 void DestroyClientManager(); |
|
311 |
|
312 /** |
|
313 * Creates plugin manager. |
|
314 * |
|
315 * @return KErrNone if successful, otherwise one of the system-wide |
|
316 * error codes |
|
317 */ |
|
318 TInt CreatePluginManager(); |
|
319 |
|
320 /** |
|
321 * Destroys plugin manager. |
|
322 */ |
|
323 void DestroyPluginManager(); |
|
324 |
|
325 /** |
|
326 * Creates bluetooth manager. |
|
327 * |
|
328 * @return KErrNone if successful, otherwise one of the system-wide |
|
329 * error codes |
|
330 */ |
|
331 TInt CreateBTManager(); |
|
332 |
|
333 /** |
|
334 * Destroys bluetooth manager. |
|
335 */ |
|
336 void DestroyBTManager(); |
|
337 |
|
338 /** |
|
339 * Creates Remote Control server. |
|
340 * |
|
341 * @return KErrNone if successful, otherwise one of the system-wide |
|
342 * error codes |
|
343 */ |
|
344 TInt CreateControlServer(); |
|
345 |
|
346 /** |
|
347 * Destroys Remote Control server. |
|
348 */ |
|
349 void DestroyControlServer(); |
|
350 |
|
351 /** |
|
352 * Sets Headset bluetooth friendly name. |
|
353 * |
|
354 * @param aBTName bluetooth name |
|
355 */ |
|
356 void SetBTName( const TBTFriendlyName &aBTName ); |
|
357 |
|
358 /** |
|
359 * Gets last-connected AG's bluetooth address. |
|
360 * |
|
361 * @param aBTDevAddr on return, the value of bluetooth address |
|
362 * @return KErrNone if successful, otherwise one of the system-wide |
|
363 * error codes |
|
364 */ |
|
365 TInt GetLastConnected( TBTDevAddr &aBTDevAddr ); |
|
366 |
|
367 /** |
|
368 * Saves connection parameter - bluetooth address of last-connected AG. |
|
369 * |
|
370 * @param aSocket socket which AG is connected |
|
371 * @return KErrNone if successful, otherwise one of the system-wide |
|
372 * error codes |
|
373 */ |
|
374 TInt SaveClient( CBluetoothSocket* aSocket ); |
|
375 |
|
376 /** |
|
377 * Sets listening Headset server port to be used in settings of Sdp record. |
|
378 */ |
|
379 void SetSdpRecordServicePortFromServer(); |
|
380 |
|
381 /** |
|
382 * Loads profile. |
|
383 * |
|
384 * @param aProfileName profile name |
|
385 * @pre CoD and Sdp plugins loaded. |
|
386 */ |
|
387 void LoadProfileL( const TDesC8 &aProfileName ); |
|
388 |
|
389 /** |
|
390 * Loads profile. |
|
391 * |
|
392 * @param aProfileUid profile Uid |
|
393 * @pre CoD and Sdp plugins loaded. |
|
394 */ |
|
395 void LoadProfileL( const TUid &aProfileUid ); |
|
396 |
|
397 /** |
|
398 * Loads Sdp. |
|
399 * |
|
400 * @param aSdpName Sdp name |
|
401 */ |
|
402 void LoadSdpL( const TDesC8 &aSdpName ); |
|
403 |
|
404 /** |
|
405 * Loads Sdp. |
|
406 * |
|
407 * @param aSdpUid Sdp Uid |
|
408 */ |
|
409 void LoadSdpL( const TUid &aSdpUid ); |
|
410 |
|
411 /** |
|
412 * Loads CoD plugin |
|
413 * |
|
414 * @param aCodName CoD name |
|
415 */ |
|
416 void LoadCodL( const TDesC8 &aCoDName ); |
|
417 |
|
418 /** |
|
419 * Loads CoD plugin |
|
420 * |
|
421 * @param aCodUid CoD Uid |
|
422 */ |
|
423 void LoadCodL( const TUid &aCoDUid ); |
|
424 |
|
425 private: |
|
426 //Methods inherited from MHsClientStateNotifier |
|
427 void HandleClientConnectL( TInt aErr ); |
|
428 |
|
429 void HandleClientDisconnectL( TInt aErr ); |
|
430 |
|
431 void HandleClientReceiveCompleteL( const TDesC8 &aData, TInt aErr ); |
|
432 |
|
433 void HandleClientSendCompleteL( TInt aErr ); |
|
434 |
|
435 void HandleClientOtherProblemL( TInt aErr ); |
|
436 |
|
437 private: |
|
438 //Methods inherited from MHsAcceptNewClientObserver |
|
439 void HandleNewClientL( CBluetoothSocket *aClientSocket, TInt aErr ); |
|
440 |
|
441 private: |
|
442 //Methods inherited from MHsBTManagerObserver |
|
443 void HandleDesiredDeviceFound( const TDesC &aDevName, |
|
444 const TBTDevAddr &aDevAddr, const TInt aPort ); |
|
445 |
|
446 void HandleDesiredDeviceNotFound( TInt aErr ); |
|
447 |
|
448 void HandleSdpQueryError( TInt aErr ); |
|
449 |
|
450 void HandleServiceNotFound( TInt aErr ); |
|
451 |
|
452 void HandlePortNotFound( TInt aErr ); |
|
453 |
|
454 private: |
|
455 //Methods inherited from MRemoteControllerConnectionObserver |
|
456 void HandleRemoteControllerConnected( TInt aErr ); |
|
457 |
|
458 void HandleRemoteControllerDisconnected( TInt aErr ); |
|
459 |
|
460 private: |
|
461 |
|
462 /** Plugin types */ |
|
463 enum TPluginType |
|
464 { |
|
465 /** CoD plugin */ |
|
466 ECoDPlugin, |
|
467 /** Sdp plugin */ |
|
468 ESdpPlugin, |
|
469 /** Profile plugin */ |
|
470 EProfilePlugin, |
|
471 /** Number of plugins */ |
|
472 EEnd, |
|
473 }; |
|
474 |
|
475 /** Service UUID */ |
|
476 TUUID iService; |
|
477 |
|
478 /** Bluetooth friendly name of device */ |
|
479 TBTFriendlyName iBTFriendlyName; |
|
480 |
|
481 /** Data buffer from profile to be send to AG */ |
|
482 TBufferFromProfileToClient iBufferFromProfileToClient; |
|
483 |
|
484 /** Session of socket server */ |
|
485 RSocketServ iSocketServ; |
|
486 |
|
487 /** Pointer to CHsServer. Owned */ |
|
488 CHsServer* iHSServer; |
|
489 |
|
490 /** Pointer to CHsAudioServer. Owned */ |
|
491 CHsAudioServer* iAudioServer; |
|
492 |
|
493 /** Pointer to CHsControlServer. Owned */ |
|
494 CHsControlServer *iHSControlServer; |
|
495 |
|
496 /** Pointer to CHsClientManager. Owned */ |
|
497 CHsClientManager *iHSClientManager; |
|
498 |
|
499 /** Pointer to CHsProfileManager. Owned */ |
|
500 CHsProfileManager *iHSProfileManager; |
|
501 |
|
502 /** Pointer to CHsBTManager. Owned */ |
|
503 CHsBTManager *iHsBTManager; |
|
504 |
|
505 /** Pointer to MHsObserver. Not owned */ |
|
506 MHsObserver *iObserver; |
|
507 |
|
508 }; |
|
509 |
|
510 #endif // HSCORE_H |