|
1 /* |
|
2 * Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Server-side sub-session of Accessory BT Control |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "AccSrvSubBTControl.h" |
|
22 #include "acc_debug.h" |
|
23 #include "AccPolGenericIDArray.h" |
|
24 #include "AccPolGenericIDArrayAccessor.h" |
|
25 #include "AccSrvServerModel.h" |
|
26 #include "AccPolGenericIDAccessor.h" |
|
27 #include "AccPolicyDB.h" |
|
28 #include "AccPolAccessoryPolicy.h" |
|
29 #include "AccPolCapabilityStorage.h" |
|
30 |
|
31 // EXTERNAL DATA STRUCTURES |
|
32 |
|
33 // EXTERNAL FUNCTION PROTOTYPES |
|
34 |
|
35 // CONSTANTS |
|
36 |
|
37 // MACROS |
|
38 |
|
39 // LOCAL CONSTANTS AND MACROS |
|
40 |
|
41 // MODULE DATA STRUCTURES |
|
42 |
|
43 // LOCAL FUNCTION PROTOTYPES |
|
44 |
|
45 // FORWARD DECLARATIONS |
|
46 |
|
47 // ============================= LOCAL FUNCTIONS =============================== |
|
48 |
|
49 // ============================ MEMBER FUNCTIONS =============================== |
|
50 |
|
51 // ----------------------------------------------------------------------------- |
|
52 // CAccSrvSubBTControl::CAccSrvSubBTControl |
|
53 // C++ default constructor can NOT contain any code, that |
|
54 // might leave. |
|
55 // ----------------------------------------------------------------------------- |
|
56 // |
|
57 CAccSrvSubBTControl::CAccSrvSubBTControl( |
|
58 CASYProxyAPI* aProxy, |
|
59 CAccSrvConnectionController* aConnectionController, |
|
60 CAccSrvServerModel* aServerModel ) |
|
61 : CAccSrvSubControl ( aProxy, aConnectionController,aServerModel ), |
|
62 iAudioLinkOpenCancelFlagResetCalledTwice( EFalse ), |
|
63 iAudioLinkCloseCancelFlagResetCalledTwice( EFalse ) |
|
64 { |
|
65 COM_TRACE_2( "[AccFW:AccServer] CAccSrvSubBTControl::CAccSrvSubBTControl(0x%x, 0x%x)", aProxy, &aConnectionController ); |
|
66 |
|
67 COM_TRACE_( "[AccFW:AccServer] CAccSrvSubBTControl::CAccSrvSubBTControl - return void" ); |
|
68 } |
|
69 // ----------------------------------------------------------------------------- |
|
70 // CAccSrvSubBTControl::ConstructL |
|
71 // Symbian 2nd phase constructor can leave. |
|
72 // ----------------------------------------------------------------------------- |
|
73 // |
|
74 void CAccSrvSubBTControl::ConstructL() |
|
75 { |
|
76 COM_TRACE_( "[AccFW:AccServer] CAccSrvSubBTControl::ConstructL()" ); |
|
77 |
|
78 CAccSrvSubControl::ConstructL(); |
|
79 |
|
80 COM_TRACE_( "[AccFW:AccServer] CAccSrvSubBTControl::ConstructL- return void" ); |
|
81 } |
|
82 |
|
83 // ----------------------------------------------------------------------------- |
|
84 // CAccSrvSubBTControl::NewL |
|
85 // Two-phased constructor. |
|
86 // ----------------------------------------------------------------------------- |
|
87 // |
|
88 |
|
89 CAccSrvSubBTControl* CAccSrvSubBTControl::NewL( |
|
90 CASYProxyAPI* aProxy, |
|
91 CAccSrvConnectionController* aConnectionController, |
|
92 CAccSrvServerModel* aServerModel ) |
|
93 { |
|
94 COM_TRACE_2( "[AccFW:AccServer] CAccSrvSubBTControl::NewL(0x%x, 0x%x)", aProxy, &aConnectionController ); |
|
95 |
|
96 __ASSERT_ALWAYS( aProxy, User::Leave( KErrArgument ) ); |
|
97 CAccSrvSubBTControl* self = new (ELeave) CAccSrvSubBTControl( aProxy, |
|
98 aConnectionController, |
|
99 aServerModel ); |
|
100 |
|
101 CleanupStack::PushL( self ); |
|
102 self->ConstructL(); |
|
103 CleanupStack::Pop( self ); |
|
104 |
|
105 COM_TRACE_1( "[AccFW:AccServer] CAccSrvSubBTControl::NewL - return 0x%x", self ); |
|
106 |
|
107 return self; |
|
108 } |
|
109 |
|
110 // Destructor |
|
111 CAccSrvSubBTControl::~CAccSrvSubBTControl() |
|
112 { |
|
113 COM_TRACE_( "[AccFW:AccServer] CAccSrvSubBTControl::~CAccSrvSubBTControl()" ); |
|
114 |
|
115 RMessage2 dummy; |
|
116 |
|
117 CAccSrvSubBTControl::CancelConnectAccessory( dummy );//For iConnectBluetoothAccessoryMsg |
|
118 CAccSrvSubBTControl::CancelNotifyBluetoothAudioLinkCloseReq( dummy );//For iNotifyBluetoothAudioLinkCloseReqMsg |
|
119 CAccSrvSubBTControl::CancelNotifyBluetoothAudioLinkOpenReq( dummy );//For iNotifyBluetoothAudioLinkOpenReqMsg |
|
120 |
|
121 if ( iServerModel ) |
|
122 { |
|
123 iServerModel->SetAudioLinkOpenCancelled( EFalse ); |
|
124 iServerModel->SetAudioLinkCloseCancelled( EFalse ); |
|
125 } |
|
126 |
|
127 COM_TRACE_( "[AccFW:AccServer] CAccSrvSubBTControl::~CAccSrvSubBTControl - return" ); |
|
128 } |
|
129 |
|
130 // ----------------------------------------------------------------------------- |
|
131 // CAccSrvSubBTControl::BluetoothConnectAccessoryL |
|
132 // ----------------------------------------------------------------------------- |
|
133 // |
|
134 void CAccSrvSubBTControl::BluetoothConnectAccessoryL( const RMessage2& aMessage ) |
|
135 { |
|
136 COM_TRACE_( "[AccFW:AccServer] CAccSrvSubBTControl::BluetoothConnectAccessoryL()" ); |
|
137 |
|
138 TBTDevAddr BTDevAddr; |
|
139 TPckg<TBTDevAddr> BTDevAddrPckg( BTDevAddr ); |
|
140 TUint callerThreadID( 0 ); |
|
141 TPckg<TUint> callerThreadIDPckg( callerThreadID ); |
|
142 TBuf8<KGIDIntMaxLength> GIDIntEmpty( KNullDesC8 ); |
|
143 |
|
144 aMessage.ReadL( KAccServParamPosFirst, BTDevAddrPckg ); |
|
145 aMessage.ReadL( KAccServParamPosSecond, callerThreadIDPckg ); |
|
146 |
|
147 // A new GenericID for connection made without GenericID. |
|
148 // Rest of it is filled after supported profiles has been queried from BT-ASY |
|
149 // (see CAccSrvConnectionHandler::ResolveGenericIDL() ). |
|
150 TAccPolGenericID genericID; |
|
151 TAccPolGenericIDAccessor::SetDeviceAddress( genericID, |
|
152 MakeTUint64( BTDevAddr ) ); |
|
153 TAccPolGenericIDAccessor::SetFeatureAttributeL( genericID, |
|
154 KAccPolPCPhysicalConnection, |
|
155 KPCBluetooth ); |
|
156 |
|
157 iServerModel->CapabilityStorage().GenerateUniqueId( genericID ); |
|
158 iServerModel->CapabilityStorage().NewCapabilityListL( genericID ); |
|
159 |
|
160 // Pass handling to Connection Controller. |
|
161 // If Leave occurs, aMessage is completed with error code. |
|
162 iConnectionController->HandleConnectL( genericID, callerThreadID, EFalse, EFalse ); |
|
163 |
|
164 // Add this subsession to "ConnectAccessory"-queue for later i completion |
|
165 iConnectionController->NotificationQueue().RegisterControlMessage( EConnectAccessory, |
|
166 this ); |
|
167 iConnectBluetoothAccessoryMsg = aMessage;//Store RMessage2 for future completion |
|
168 |
|
169 COM_TRACE_( "[AccFW:AccServer] CAccSrvSubBTControl::BluetoothConnectAccessoryL - return void" ); |
|
170 } |
|
171 |
|
172 // ----------------------------------------------------------------------------- |
|
173 // CAccSrvSubBTControl::BluetoothDisconnectAccessoryL |
|
174 // ----------------------------------------------------------------------------- |
|
175 // |
|
176 void CAccSrvSubBTControl::BluetoothDisconnectAccessoryL( const RMessage2& aMessage ) |
|
177 { |
|
178 COM_TRACE_( "[AccFW:AccServer] CAccSrvSubBTControl::BluetoothDisconnectAccessoryL()" ); |
|
179 |
|
180 TInt index( KErrNotFound ); |
|
181 TAccPolGenericID genericId; |
|
182 TAccPolGenericIDArray genericIdArray; |
|
183 TBTDevAddr BTDevAddr; |
|
184 TPckg<TBTDevAddr> BTDevAddrPckg( BTDevAddr ); |
|
185 |
|
186 aMessage.ReadL( KAccServParamPosFirst, BTDevAddrPckg ); |
|
187 |
|
188 //Find the GenericID in question |
|
189 iServerModel->CurrentConnectionStatusL( genericIdArray );//Fill the array |
|
190 index = TAccPolGenericIDArrayAccessor::FindWithDeviceAddressL( |
|
191 genericIdArray, |
|
192 MakeTUint64( BTDevAddr ) ); |
|
193 |
|
194 if ( index < 0 ) |
|
195 { |
|
196 User::Leave( KErrArgument ); |
|
197 } |
|
198 |
|
199 //Pass handling to Connection Controller |
|
200 iConnectionController->HandleDisconnectL( genericIdArray.GetGenericIDL( index ) ); |
|
201 |
|
202 Write( aMessage, KAccSrvDisconnectBTAccessoryBit ); |
|
203 |
|
204 COM_TRACE_( "[AccFW:AccServer] CAccSrvSubBTControl::BluetoothDisconnectAccessoryL - return void" ); |
|
205 } |
|
206 |
|
207 // ----------------------------------------------------------------------------- |
|
208 // CAccSrvSubBTControl::BluetoothAudioLinkOpenRespL |
|
209 // ----------------------------------------------------------------------------- |
|
210 // |
|
211 void CAccSrvSubBTControl::BluetoothAudioLinkOpenRespL( const RMessage2& aMessage ) |
|
212 { |
|
213 COM_TRACE_( "[AccFW:AccServer] CAccSrvSubBTControl::BluetoothAudioLinkOpenRespL()" ); |
|
214 |
|
215 TInt index( KErrNotFound ); |
|
216 TInt uniqueID( KErrNotFound ); |
|
217 TBTDevAddr BTDevAddr; |
|
218 TPckg<TBTDevAddr> BTDevAddrPckg( BTDevAddr ); |
|
219 TInt response( 0 ); |
|
220 TPckg<TInt> responsePckg( response ); |
|
221 |
|
222 aMessage.ReadL( KAccServParamPosFirst, BTDevAddrPckg ); |
|
223 aMessage.ReadL( KAccServParamPosSecond, responsePckg ); |
|
224 |
|
225 //Find the GenericID in question |
|
226 index = iServerModel->FindWithDeviceAddressL( |
|
227 MakeTUint64( BTDevAddr ), |
|
228 uniqueID /*Unique DB id of the found accessory*/ ); |
|
229 |
|
230 if ( index < 0 ) |
|
231 { |
|
232 User::Leave( KErrArgument ); |
|
233 } |
|
234 |
|
235 if ( iServerModel->AudioLinkOpenCancelled() ) |
|
236 { |
|
237 //AccessoryAudioLinkOpen() request was cancelled before this response was received. |
|
238 //This response can be completed with error code. |
|
239 ResetAudioLinkOpenCancelFlag( response ); |
|
240 User::Leave( KErrCancel ); |
|
241 } |
|
242 else |
|
243 { |
|
244 iConnectionController->NotificationQueue().CompleteControlMessageL( |
|
245 EAccessoryAudioLinkOpen, response, uniqueID ); |
|
246 } |
|
247 |
|
248 COM_TRACE_( "[AccFW:AccServer] CAccSrvSubBTControl::BluetoothAudioLinkOpenRespL - return void" ); |
|
249 } |
|
250 |
|
251 // ----------------------------------------------------------------------------- |
|
252 // CAccSrvSubBTControl::BluetoothAudioLinkCloseRespL |
|
253 // ----------------------------------------------------------------------------- |
|
254 // |
|
255 void CAccSrvSubBTControl::BluetoothAudioLinkCloseRespL( const RMessage2& aMessage ) |
|
256 { |
|
257 COM_TRACE_( "[AccFW:AccServer] CAccSrvSubBTControl::BluetoothAudioLinkCloseRespL()" ); |
|
258 |
|
259 TInt index( KErrNotFound ); |
|
260 TInt uniqueID( KErrNotFound ); |
|
261 TBTDevAddr BTDevAddr; |
|
262 TPckg<TBTDevAddr> BTDevAddrPckg( BTDevAddr ); |
|
263 TInt response( 0 ); |
|
264 TPckg<TInt> responsePckg( response ); |
|
265 |
|
266 aMessage.ReadL( KAccServParamPosFirst, BTDevAddrPckg ); |
|
267 aMessage.ReadL( KAccServParamPosSecond, responsePckg ); |
|
268 |
|
269 //Find the GenericID in question |
|
270 index = iServerModel->FindWithDeviceAddressL( |
|
271 MakeTUint64( BTDevAddr ), |
|
272 uniqueID /*Unique DB id of the found accessory*/ ); |
|
273 |
|
274 if ( index < 0 ) |
|
275 { |
|
276 User::Leave( KErrArgument ); |
|
277 } |
|
278 |
|
279 if ( iServerModel->AudioLinkCloseCancelled() ) |
|
280 { |
|
281 //AccessoryAudioLinkClose() request was cancelled before this response was received. |
|
282 //This response can be completed with error code. |
|
283 ResetAudioLinkCloseCancelFlag( response ); |
|
284 User::Leave( KErrCancel ); |
|
285 } |
|
286 else |
|
287 { |
|
288 iConnectionController->NotificationQueue().CompleteControlMessageL( |
|
289 EAccessoryAudioLinkClose, response, uniqueID ); |
|
290 } |
|
291 |
|
292 COM_TRACE_( "[AccFW:AccServer] CAccSrvSubBTControl::BluetoothAudioLinkCloseRespL - return void" ); |
|
293 } |
|
294 |
|
295 // ----------------------------------------------------------------------------- |
|
296 // CAccSrvSubBTControl::BluetoothAudioLinkOpenedNotifyL |
|
297 // ----------------------------------------------------------------------------- |
|
298 // |
|
299 void CAccSrvSubBTControl::BluetoothAudioLinkOpenedNotifyL( const RMessage2& aMessage ) |
|
300 { |
|
301 COM_TRACE_( "[AccFW:AccServer] CAccSrvSubBTControl::BluetoothAudioLinkOpenedNotifyL()" ); |
|
302 |
|
303 TInt index( KErrNotFound ); |
|
304 TInt uniqueID( KErrNotFound ); |
|
305 TInt currentAccessoryModeUniqueID = iServerModel->UniqueID();//Preferred audio output status is assigned for this uniqueID |
|
306 TBTDevAddr BTDevAddr; |
|
307 TPckg<TBTDevAddr> BTDevAddrPckg( BTDevAddr ); |
|
308 TAccAudioType audioType( EAccMonoAudio ); // Initialization value |
|
309 TAccSrvAudioTypePckg audioTypePckg( audioType ); |
|
310 |
|
311 aMessage.ReadL( KAccServParamPosFirst, BTDevAddrPckg ); |
|
312 aMessage.ReadL( KAccServParamPosSecond, audioTypePckg ); |
|
313 |
|
314 //Find the GenericID in question |
|
315 index = iServerModel->FindWithDeviceAddressL( |
|
316 MakeTUint64( BTDevAddr ), |
|
317 uniqueID /*Unique id of the found accessory*/ ); |
|
318 if ( index < 0 ) |
|
319 { |
|
320 User::Leave( KErrArgument ); |
|
321 } |
|
322 |
|
323 |
|
324 if ( iServerModel->AudioLinkOpenCancelled() ) |
|
325 { |
|
326 //AccessoryAudioLinkOpen() request was cancelled before this response was received. |
|
327 //This response can be completed with error code. |
|
328 ResetAudioLinkOpenCancelFlag( KErrNone ); |
|
329 User::Leave( KErrCancel ); |
|
330 } |
|
331 else |
|
332 { |
|
333 iServerModel->SetAudioType( audioType );//Notice, This works for single client (Server model can store only one value) |
|
334 iConnectionController->NotificationQueue().CompleteControlMessageL( |
|
335 EAccessoryAudioLinkOpened, KErrNone, uniqueID ); |
|
336 } |
|
337 |
|
338 COM_TRACE_( "[AccFW:AccServer] CAccSrvSubBTControl::BluetoothAudioLinkOpenedNotifyL - return void" ); |
|
339 } |
|
340 |
|
341 // ----------------------------------------------------------------------------- |
|
342 // CAccSrvSubBTControl::BluetoothAudioLinkClosedNotify |
|
343 // ----------------------------------------------------------------------------- |
|
344 // |
|
345 void CAccSrvSubBTControl::BluetoothAudioLinkClosedNotifyL( const RMessage2& aMessage ) |
|
346 { |
|
347 COM_TRACE_( "[AccFW:AccServer] CAccSrvSubBTControl::BluetoothAudioLinkClosedNotifyL()" ); |
|
348 |
|
349 TInt index( KErrNotFound ); |
|
350 TInt uniqueID( KErrNotFound ); |
|
351 TBTDevAddr BTDevAddr; |
|
352 TPckg<TBTDevAddr> BTDevAddrPckg( BTDevAddr ); |
|
353 TAccAudioType audioType( EAccMonoAudio ); // Initialization value |
|
354 TAccSrvAudioTypePckg audioTypePckg( audioType ); |
|
355 |
|
356 aMessage.ReadL( KAccServParamPosFirst, BTDevAddrPckg ); |
|
357 aMessage.ReadL( KAccServParamPosSecond, audioTypePckg ); |
|
358 |
|
359 //Find the GenericID in question |
|
360 index = iServerModel->FindWithDeviceAddressL( |
|
361 MakeTUint64( BTDevAddr ), |
|
362 uniqueID /*Unique id of the found accessory*/ ); |
|
363 |
|
364 if ( index < 0 ) |
|
365 { |
|
366 User::Leave( KErrArgument ); |
|
367 } |
|
368 |
|
369 if ( iServerModel->AudioLinkCloseCancelled() ) |
|
370 { |
|
371 //AccessoryAudioLinkClose() request was cancelled before this response was received. |
|
372 //This response can be completed with error code. |
|
373 ResetAudioLinkCloseCancelFlag( KErrNone ); |
|
374 User::Leave( KErrCancel ); |
|
375 } |
|
376 else |
|
377 { |
|
378 iServerModel->SetAudioType( audioType );//Notice, This works for single client (Server model can store only one value) |
|
379 iConnectionController->NotificationQueue().CompleteControlMessageL( |
|
380 EAccessoryAudioLinkClosed, KErrNone, uniqueID ); |
|
381 } |
|
382 |
|
383 COM_TRACE_( "[AccFW:AccServer] CAccSrvSubBTControl::BluetoothAudioLinkClosedNotifyL - return void" ); |
|
384 } |
|
385 |
|
386 // ----------------------------------------------------------------------------- |
|
387 // CAccSrvSubBTControl::NotifyBluetoothAudioLinkOpenReqL |
|
388 // ----------------------------------------------------------------------------- |
|
389 // |
|
390 void CAccSrvSubBTControl::NotifyBluetoothAudioLinkOpenReqL( |
|
391 const RMessage2& aMessage ) |
|
392 { |
|
393 COM_TRACE_( "[AccFW:AccServer] CAccSrvSubBTControl::NotifyBluetoothAudioLinkOpenReqL()" ); |
|
394 |
|
395 iNotifyBluetoothAudioLinkOpenReqMsg = aMessage;//Store RMessage2 for future completion |
|
396 |
|
397 iConnectionController->NotificationQueue().RegisterControlMessage( |
|
398 EBluetoothAudioLinkOpenReq, this ); |
|
399 |
|
400 if ( iServerModel->BluetoothAudioLinkOpenReqPostponed() ) |
|
401 { |
|
402 //Complete notification immediately if audio link open is still in progress |
|
403 if ( !iServerModel->AudioLinkOpenCancelled() && |
|
404 iConnectionController->NotificationQueue().ControlMessagesWaiting( EAccessoryAudioLinkOpen ) > 0 ) |
|
405 { |
|
406 TInt uniqueID( KErrNotFound ); |
|
407 TBTDevAddr BTDevAddr; |
|
408 TPckg<TBTDevAddr> BTDevAddrPckg( BTDevAddr ); |
|
409 |
|
410 aMessage.ReadL( KAccServParamPosFirst, BTDevAddrPckg ); |
|
411 iServerModel->FindWithDeviceAddressL( MakeTUint64( BTDevAddr ), uniqueID ); |
|
412 iConnectionController->NotificationQueue().CompleteControlMessageL( |
|
413 EBluetoothAudioLinkOpenReq, KErrNone, uniqueID ); |
|
414 } |
|
415 } |
|
416 iServerModel->SetBluetoothAudioLinkOpenReqPostponed( EFalse );//Postpone is not needed anymore |
|
417 |
|
418 COM_TRACE_( "[AccFW:AccServer] CAccSrvSubBTControl::NotifyBluetoothAudioLinkOpenReqL - return void" ); |
|
419 } |
|
420 |
|
421 // ----------------------------------------------------------------------------- |
|
422 // CAccSrvSubBTControl::NotifyBluetoothAudioLinkCloseReqL |
|
423 // ----------------------------------------------------------------------------- |
|
424 // |
|
425 void CAccSrvSubBTControl::NotifyBluetoothAudioLinkCloseReqL( |
|
426 const RMessage2& aMessage ) |
|
427 { |
|
428 COM_TRACE_( "[AccFW:AccServer] CAccSrvSubBTControl::NotifyBluetoothAudioLinkCloseReqL()" ); |
|
429 |
|
430 iNotifyBluetoothAudioLinkCloseReqMsg = aMessage;//Store RMessage2 for future completion |
|
431 |
|
432 iConnectionController->NotificationQueue().RegisterControlMessage( |
|
433 EBluetoothAudioLinkCloseReq, this ); |
|
434 |
|
435 COM_TRACE_( "[AccFW:AccServer] CAccSrvSubBTControl::NotifyBluetoothAudioLinkCloseReqL - return void" ); |
|
436 } |
|
437 |
|
438 // ----------------------------------------------------------------------------- |
|
439 // CAccSrvSubBTControl::NotifyBTAccessoryValueChangedTBoolL |
|
440 // ----------------------------------------------------------------------------- |
|
441 // |
|
442 void CAccSrvSubBTControl::NotifyBTAccessoryValueChangedTBoolL( |
|
443 const RMessage2& aMessage ) |
|
444 { |
|
445 COM_TRACE_( "[AccFW:AccServer] CAccSrvSubBTControl::NotifyBTAccessoryValueChangedTBoolL()" ); |
|
446 |
|
447 TInt index( KErrNotFound ); |
|
448 TAccPolGenericIDArray genericIdArray; |
|
449 TAccPolGenericID genericID; |
|
450 TBTDevAddr BTDevAddr; |
|
451 TPckg<TBTDevAddr> BTDevAddrPckg( BTDevAddr ); |
|
452 TAccPolNameRecord nameRecord; |
|
453 TAccSrvNameRecordPckg nameRecordPckg( nameRecord ); |
|
454 TAccSrvValueTypeTBoolPckgBuf valuePckgBuf; |
|
455 |
|
456 aMessage.ReadL( KAccServParamPosFirst, BTDevAddrPckg ); |
|
457 aMessage.ReadL( KAccServParamPosSecond, nameRecordPckg ); |
|
458 aMessage.ReadL( KAccServParamPosThird, valuePckgBuf ); |
|
459 |
|
460 //Find the GenericID in question |
|
461 iServerModel->CurrentConnectionStatusL( genericIdArray );//Fill the array |
|
462 index = TAccPolGenericIDArrayAccessor::FindWithDeviceAddressL( |
|
463 genericIdArray, |
|
464 MakeTUint64( BTDevAddr ) ); |
|
465 if ( index < 0 ) |
|
466 { |
|
467 User::Leave( KErrArgument ); |
|
468 } |
|
469 genericID = genericIdArray.GetGenericIDL( index ); |
|
470 |
|
471 //Check is the capability assigned for this accessory |
|
472 TUint32 name; |
|
473 nameRecord.GetName( name ); |
|
474 |
|
475 CCapValue * value = iServerModel->CapabilityStorage().GetCapability( genericID, name ); |
|
476 |
|
477 if ( !value ) |
|
478 { |
|
479 User::Leave( KErrArgument ); |
|
480 } |
|
481 |
|
482 //Store a new value |
|
483 value->SetValueL( valuePckgBuf().iValue ); |
|
484 |
|
485 //Store Value Data for AccessoryValueChanged notification |
|
486 TAccValueTypeTInt dummyTIntValue = { 0 }; |
|
487 TAccValueTypeObject dummyObjectValue( TPtr8( NULL, 0, 0 ) ); |
|
488 iServerModel->SetValueData( genericID, |
|
489 nameRecord, |
|
490 dummyTIntValue, /*Not used*/ |
|
491 valuePckgBuf(), |
|
492 dummyObjectValue/*Not used*/ ); |
|
493 |
|
494 //complete possible pending notifications about change of accessory value |
|
495 iConnectionController->NotificationQueue().CompleteControlMessageL( |
|
496 EAccessoryValueChangedTBool, KErrNone, genericID.UniqueID() ); |
|
497 |
|
498 //Update Connection status and Accessory mode (if changed) |
|
499 iConnectionController->HandleConnectionChangeValidationL( genericID ); |
|
500 |
|
501 COM_TRACE_( "[AccFW:AccServer] CAccSrvSubBTControl::NotifyBTAccessoryValueChangedTBoolL - return void" ); |
|
502 } |
|
503 |
|
504 // ----------------------------------------------------------------------------- |
|
505 // CAccSrvSubBTControl::NotifyBTAccessoryValueChangedTIntL |
|
506 // ----------------------------------------------------------------------------- |
|
507 // |
|
508 void CAccSrvSubBTControl::NotifyBTAccessoryValueChangedTIntL( |
|
509 const RMessage2& aMessage ) |
|
510 { |
|
511 COM_TRACE_( "[AccFW:AccServer] CAccSrvSubBTControl::NotifyBTAccessoryValueChangedTIntL()" ); |
|
512 |
|
513 TInt index( KErrNotFound ); |
|
514 TAccPolGenericIDArray genericIdArray; |
|
515 TAccPolGenericID genericID; |
|
516 TBTDevAddr BTDevAddr; |
|
517 TPckg<TBTDevAddr> BTDevAddrPckg( BTDevAddr ); |
|
518 TAccPolNameRecord nameRecord; |
|
519 TAccSrvNameRecordPckg nameRecordPckg( nameRecord ); |
|
520 TAccSrvValueTypeTIntPckgBuf valuePckgBuf; |
|
521 |
|
522 aMessage.ReadL( KAccServParamPosFirst, BTDevAddrPckg ); |
|
523 aMessage.ReadL( KAccServParamPosSecond, nameRecordPckg ); |
|
524 aMessage.ReadL( KAccServParamPosThird, valuePckgBuf ); |
|
525 |
|
526 //Find the GenericID in question |
|
527 iServerModel->CurrentConnectionStatusL( genericIdArray );//Fill the array |
|
528 index = TAccPolGenericIDArrayAccessor::FindWithDeviceAddressL( |
|
529 genericIdArray, |
|
530 MakeTUint64( BTDevAddr ) ); |
|
531 if ( index < 0 ) |
|
532 { |
|
533 User::Leave( KErrArgument ); |
|
534 } |
|
535 genericID = genericIdArray.GetGenericIDL( index ); |
|
536 |
|
537 //Check is the capability assigned for this accessory |
|
538 TUint32 name; |
|
539 nameRecord.GetName( name ); |
|
540 |
|
541 CCapValue * value = iServerModel->CapabilityStorage().GetCapability( genericID, name ); |
|
542 |
|
543 if ( !value ) |
|
544 { |
|
545 User::Leave( KErrArgument ); |
|
546 } |
|
547 |
|
548 //Store a new value |
|
549 value->SetValueL( valuePckgBuf().iValue ); |
|
550 |
|
551 //Store Value Data for AccessoryValueChanged notification |
|
552 TAccValueTypeTBool dummyTBoolValue = { 0 }; |
|
553 TAccValueTypeObject dummyObjectValue( TPtr8( NULL, 0, 0 ) ); |
|
554 iServerModel->SetValueData( genericID, |
|
555 nameRecord, |
|
556 valuePckgBuf(), |
|
557 dummyTBoolValue /*Not used*/, |
|
558 dummyObjectValue/*Not used*/); |
|
559 |
|
560 //complete possible pending notifications about change of accessory value |
|
561 iConnectionController->NotificationQueue().CompleteControlMessageL( |
|
562 EAccessoryValueChangedTInt, KErrNone, genericID.UniqueID() ); |
|
563 |
|
564 //Update Connection status and Accessory mode (if changed) |
|
565 iConnectionController->HandleConnectionChangeValidationL( genericID ); |
|
566 |
|
567 COM_TRACE_( "[AccFW:AccServer] CAccSrvSubBTControl::NotifyBTAccessoryValueChangedTIntL - return void" ); |
|
568 } |
|
569 |
|
570 // ----------------------------------------------------------------------------- |
|
571 // CAccSrvSubBTControl::CancelNotifyBluetoothAudioLinkOpenReq |
|
572 // ----------------------------------------------------------------------------- |
|
573 // |
|
574 void CAccSrvSubBTControl::CancelNotifyBluetoothAudioLinkOpenReq( |
|
575 const RMessage2& /*aMessage*/ ) |
|
576 { |
|
577 COM_TRACE_( "[AccFW:AccServer] CAccSrvSubBTControl::CancelNotifyBluetoothAudioLinkOpenReq()" ); |
|
578 |
|
579 // If request is Null, there is nothing to cancel |
|
580 if ( !iNotifyBluetoothAudioLinkOpenReqMsg.IsNull() ) |
|
581 { |
|
582 iConnectionController->NotificationQueue().CancelControlMessage( |
|
583 EBluetoothAudioLinkOpenReq, this ); |
|
584 Write( iNotifyBluetoothAudioLinkOpenReqMsg, KAccSrvNotifyBluetoothAudioLinkOpenReqBit ); |
|
585 iNotifyBluetoothAudioLinkOpenReqMsg.Complete( KErrCancel ); |
|
586 } |
|
587 |
|
588 COM_TRACE_( "[AccFW:AccServer] CAccSrvSubBTControl::CancelNotifyBluetoothAudioLinkOpenReq - return void" ); |
|
589 } |
|
590 |
|
591 // ----------------------------------------------------------------------------- |
|
592 // CAccSrvSubBTControl::CancelNotifyBluetoothAudioLinkCloseReq |
|
593 // ----------------------------------------------------------------------------- |
|
594 // |
|
595 void CAccSrvSubBTControl::CancelNotifyBluetoothAudioLinkCloseReq( |
|
596 const RMessage2& /*aMessage*/ ) |
|
597 { |
|
598 COM_TRACE_( "[AccFW:AccServer] CAccSrvSubBTControl::CancelNotifyBluetoothAudioLinkCloseReq()" ); |
|
599 |
|
600 // If request is Null, there is nothing to cancel |
|
601 if ( !iNotifyBluetoothAudioLinkCloseReqMsg.IsNull() ) |
|
602 { |
|
603 iConnectionController->NotificationQueue().CancelControlMessage( |
|
604 EBluetoothAudioLinkCloseReq, this ); |
|
605 Write( iNotifyBluetoothAudioLinkCloseReqMsg, KAccSrvNotifyBluetoothAudioLinkCloseReqBit ); |
|
606 iNotifyBluetoothAudioLinkCloseReqMsg.Complete( KErrCancel ); |
|
607 } |
|
608 |
|
609 COM_TRACE_( "[AccFW:AccServer] CAccSrvSubBTControl::CancelNotifyBluetoothAudioLinkCloseReq - return void" ); |
|
610 } |
|
611 |
|
612 // ----------------------------------------------------------------------------- |
|
613 // CAccSrvSubBTControl::CancelConnectAccessory |
|
614 // |
|
615 // ----------------------------------------------------------------------------- |
|
616 // |
|
617 void CAccSrvSubBTControl::CancelConnectAccessory( const RMessage2& /*aMessage*/) |
|
618 { |
|
619 COM_TRACE_( "[AccFW:AccServer] CAccSrvSubBTControl::CancelConnectAccessory()" ); |
|
620 |
|
621 // If request is Null, there is nothing to cancel |
|
622 if ( !iConnectBluetoothAccessoryMsg.IsNull() ) |
|
623 { |
|
624 iConnectionController->NotificationQueue().CancelControlMessage( EConnectAccessory, |
|
625 this); |
|
626 |
|
627 //Read the accessory in question |
|
628 TBTDevAddr BTDevAddr; |
|
629 TPckg<TBTDevAddr> BTDevAddrPckg( BTDevAddr ); |
|
630 TInt err = iConnectBluetoothAccessoryMsg.Read( 0, BTDevAddrPckg ); |
|
631 |
|
632 if ( KErrNone == err ) |
|
633 { |
|
634 TRAP( err, iServerModel->SetCancelledConnectAccessoryL( MakeTUint64( BTDevAddr ) ) ); |
|
635 Write( iConnectBluetoothAccessoryMsg, KAccSrvConnectBTAccessoryBit ); |
|
636 iConnectBluetoothAccessoryMsg.Complete( KErrCancel ); |
|
637 } |
|
638 else |
|
639 { |
|
640 TRACE_ASSERT_ALWAYS; |
|
641 } |
|
642 } |
|
643 |
|
644 COM_TRACE_( "[AccFW:AccServer] CAccSrvSubBTControl::CancelConnectAccessory - return void" ); |
|
645 } |
|
646 |
|
647 // ----------------------------------------------------------------------------- |
|
648 // CAccSrvSubBTControl::CancelDisconnectAccessory |
|
649 // |
|
650 // ----------------------------------------------------------------------------- |
|
651 // |
|
652 void CAccSrvSubBTControl::CancelDisconnectAccessory( const RMessage2& /*aMessage*/) |
|
653 { |
|
654 COM_TRACE_( "[AccFW:AccServer] CAccSrvSubBTControl::CancelDisconnectAccessory()" ); |
|
655 |
|
656 // Current implementation doesn't support DisconnectAccessory() cancel |
|
657 // i.e. DisconnectAccessory() is processed before cancel can be processed. |
|
658 |
|
659 COM_TRACE_( "[AccFW:AccServer] CAccSrvSubBTControl::CancelDisconnectAccessory - return void" ); |
|
660 } |
|
661 |
|
662 // ----------------------------------------------------------------------------- |
|
663 // CAccSrvSubBTControl::DispatchMessageL |
|
664 // Handles client request. If request is not handled here, it is passed to |
|
665 // parent class for handling |
|
666 // ----------------------------------------------------------------------------- |
|
667 // |
|
668 void CAccSrvSubBTControl::DispatchMessageL( const RMessage2& aMessage ) |
|
669 { |
|
670 COM_TRACE_( "[AccFW:AccServer] CAccSrvSubBTControl::DispatchMessageL()" ); |
|
671 |
|
672 TInt function = aMessage.Function(); |
|
673 |
|
674 switch ( function ) |
|
675 { |
|
676 case EAccSrvBluetoothConnectAccessory: |
|
677 { |
|
678 BluetoothConnectAccessoryL( aMessage ); |
|
679 break; |
|
680 } |
|
681 case EAccSrvBluetoothDisconnectAccessory: |
|
682 { |
|
683 BluetoothDisconnectAccessoryL( aMessage ); |
|
684 break; |
|
685 } |
|
686 case EAccSrvBluetoothAudioLinkOpenResp: |
|
687 { |
|
688 BluetoothAudioLinkOpenRespL( aMessage ); |
|
689 break; |
|
690 } |
|
691 case EAccSrvBluetoothAudioLinkCloseResp: |
|
692 { |
|
693 BluetoothAudioLinkCloseRespL( aMessage ); |
|
694 break; |
|
695 } |
|
696 case EAccSrvBluetoothAudioLinkOpenedNotify: |
|
697 { |
|
698 BluetoothAudioLinkOpenedNotifyL( aMessage ); |
|
699 break; |
|
700 } |
|
701 case EAccSrvBluetoothAudioLinkClosedNotify: |
|
702 { |
|
703 BluetoothAudioLinkClosedNotifyL( aMessage ); |
|
704 break; |
|
705 } |
|
706 case EAccSrvNotifyBluetoothAudioLinkOpenReq: |
|
707 { |
|
708 NotifyBluetoothAudioLinkOpenReqL( aMessage ); |
|
709 break; |
|
710 } |
|
711 case EAccSrvNotifyBluetoothAudioLinkCloseReq: |
|
712 { |
|
713 NotifyBluetoothAudioLinkCloseReqL( aMessage ); |
|
714 break; |
|
715 } |
|
716 case EAccSrvBTAccessoryValueChangedTBoolNotify: |
|
717 { |
|
718 NotifyBTAccessoryValueChangedTBoolL( aMessage ); |
|
719 break; |
|
720 } |
|
721 case EAccSrvBTAccessoryValueChangedTIntNotify: |
|
722 { |
|
723 NotifyBTAccessoryValueChangedTIntL( aMessage ); |
|
724 break; |
|
725 } |
|
726 case EAccSrvCancelNotifyBluetoothAudioLinkOpenReq: |
|
727 { |
|
728 CancelNotifyBluetoothAudioLinkOpenReq( aMessage ); |
|
729 break; |
|
730 } |
|
731 case EAccSrvCancelNotifyBluetoothAudioLinkCloseReq: |
|
732 { |
|
733 CancelNotifyBluetoothAudioLinkCloseReq( aMessage ); |
|
734 break; |
|
735 } |
|
736 case EAccSrvCancelConnectAccessory: |
|
737 { |
|
738 CancelConnectAccessory( aMessage ); |
|
739 break; |
|
740 } |
|
741 case EAccSrvCancelDisconnectAccessory: |
|
742 { |
|
743 CancelDisconnectAccessory( aMessage ); |
|
744 break; |
|
745 } |
|
746 default: |
|
747 { |
|
748 // Not handled here, pass to base class |
|
749 CAccSrvSubControl::DispatchMessageL( aMessage ); |
|
750 break; |
|
751 } |
|
752 } // switch( function ) |
|
753 |
|
754 COM_TRACE_( "[AccFW:AccServer] CAccSrvSubBTControl::DispatchMessageL - return void" ); |
|
755 } |
|
756 |
|
757 // ----------------------------------------------------------------------------- |
|
758 // CAccSrvSubBTControl::CompleteMessageL |
|
759 // ----------------------------------------------------------------------------- |
|
760 // |
|
761 TBool CAccSrvSubBTControl::CompleteMessageL( TMsgID aMsgID, |
|
762 TInt aErrorCode, |
|
763 TInt aUniqueID ) |
|
764 { |
|
765 COM_TRACE_2( "[AccFW:AccServer] CAccSrvSubBTControl::CompleteMessageL(MsgID=%d Err=%d)", aMsgID, aErrorCode ); |
|
766 |
|
767 TBool messageConsumption( EFalse );// Return value tells should this subsession be removed from the queue |
|
768 |
|
769 switch ( aMsgID ) |
|
770 { |
|
771 case EConnectAccessory: |
|
772 { |
|
773 //Complete outstanding ConnectAccessory request for BT |
|
774 if ( !iConnectBluetoothAccessoryMsg.IsNull() ) |
|
775 { |
|
776 Write( iConnectBluetoothAccessoryMsg, KAccSrvConnectBTAccessoryBit ); |
|
777 iConnectBluetoothAccessoryMsg.Complete( aErrorCode ); |
|
778 messageConsumption = ETrue; |
|
779 } |
|
780 } |
|
781 break; |
|
782 case EBluetoothAudioLinkOpenReq: |
|
783 { |
|
784 //Complete outstanding AccessoryAudioLinkOpen request |
|
785 COM_TRACE_1( "[AccFW:AccServer] CAccSrvSubBTControl::CompleteMessageL - AudioLinkOpenReq AudioType=%d)", iServerModel->AudioType() ); |
|
786 |
|
787 TAccPolGenericID genericID; |
|
788 iServerModel->FindWithUniqueIDL( aUniqueID, genericID ); |
|
789 TBTDevAddr BTDevAddr( genericID.DeviceAddress() ); |
|
790 TPckg<TBTDevAddr> BTDevAddrPackage( BTDevAddr ); |
|
791 iNotifyBluetoothAudioLinkOpenReqMsg.WriteL( KAccServParamPosFirst, BTDevAddrPackage ); |
|
792 |
|
793 TAccSrvAudioTypePckg audioTypePackage( iServerModel->AudioType() );//Notice, This works for single client (Server model can store only one value) |
|
794 iNotifyBluetoothAudioLinkOpenReqMsg.WriteL( KAccServParamPosSecond, audioTypePackage ); |
|
795 Write( iNotifyBluetoothAudioLinkOpenReqMsg, |
|
796 KAccSrvNotifyBluetoothAudioLinkOpenReqBit ); |
|
797 |
|
798 iNotifyBluetoothAudioLinkOpenReqMsg.Complete( aErrorCode ); |
|
799 messageConsumption = ETrue; |
|
800 } |
|
801 break; |
|
802 |
|
803 case EBluetoothAudioLinkCloseReq: |
|
804 { |
|
805 //Complete outstanding AccessoryAudioLinkOpen request |
|
806 COM_TRACE_1( "[AccFW:AccServer] CAccSrvSubBTControl::CompleteMessageL - AudioLinkCloseReq AudioType=%d)", iServerModel->AudioType() ); |
|
807 |
|
808 TAccPolGenericID genericID; |
|
809 iServerModel->FindWithUniqueIDL( aUniqueID, genericID ); |
|
810 TBTDevAddr BTDevAddr( genericID.DeviceAddress() ); |
|
811 TPckg<TBTDevAddr> BTDevAddrPackage( BTDevAddr ); |
|
812 iNotifyBluetoothAudioLinkCloseReqMsg.WriteL( KAccServParamPosFirst, BTDevAddrPackage ); |
|
813 |
|
814 TAccSrvAudioTypePckg audioTypePackage( iServerModel->AudioType() );//Notice, This works for single client (Server model can store only one value) |
|
815 iNotifyBluetoothAudioLinkCloseReqMsg.WriteL( KAccServParamPosSecond, audioTypePackage ); |
|
816 Write( iNotifyBluetoothAudioLinkCloseReqMsg, |
|
817 KAccSrvNotifyBluetoothAudioLinkCloseReqBit ); |
|
818 |
|
819 iNotifyBluetoothAudioLinkCloseReqMsg.Complete( aErrorCode ); |
|
820 messageConsumption = ETrue; |
|
821 } |
|
822 break; |
|
823 |
|
824 default: |
|
825 { |
|
826 //Pass handling to parent class |
|
827 messageConsumption = CAccSrvSubControl::CompleteMessageL( aMsgID, |
|
828 aErrorCode, |
|
829 aUniqueID ); |
|
830 } |
|
831 } |
|
832 |
|
833 COM_TRACE_1( "[AccFW:AccServer] CAccSrvSubBTControl::CompleteMessageL - return 0x%x", messageConsumption ); |
|
834 |
|
835 return messageConsumption; |
|
836 } |
|
837 |
|
838 // ----------------------------------------------------------------------------- |
|
839 // CAccSrvSubBTControl::ResetAudioLinkOpenCancelFlag |
|
840 // ----------------------------------------------------------------------------- |
|
841 // |
|
842 void CAccSrvSubBTControl::ResetAudioLinkOpenCancelFlag( TInt aResponse ) |
|
843 { |
|
844 COM_TRACE_1( "[AccFW:AccServer] CAccSrvSubBTControl::ResetAudioLinkOpenCancelFlag(response=%d)", aResponse ); |
|
845 |
|
846 if ( iAudioLinkOpenCancelFlagResetCalledTwice || ( KErrNone != aResponse ) ) |
|
847 { |
|
848 COM_TRACE_( "[AccFW:AccServer] CAccSrvSubBTControl::ResetAudioLinkOpenCancelFlag - second call" ); |
|
849 iServerModel->SetAudioLinkOpenCancelled( EFalse ); |
|
850 iAudioLinkOpenCancelFlagResetCalledTwice = EFalse; |
|
851 } |
|
852 else |
|
853 { |
|
854 iAudioLinkOpenCancelFlagResetCalledTwice = ETrue; |
|
855 } |
|
856 |
|
857 COM_TRACE_( "[AccFW:AccServer] CAccSrvSubBTControl::ResetAudioLinkOpenCancelFlag - return void" ); |
|
858 } |
|
859 |
|
860 // ----------------------------------------------------------------------------- |
|
861 // CAccSrvSubBTControl::ResetAudioLinkCloseCancelFlag |
|
862 // ----------------------------------------------------------------------------- |
|
863 // |
|
864 void CAccSrvSubBTControl::ResetAudioLinkCloseCancelFlag( TInt aResponse ) |
|
865 { |
|
866 COM_TRACE_1( "[AccFW:AccServer] CAccSrvSubBTControl::ResetAudioLinkCloseCancelFlag(response=%d)", aResponse ); |
|
867 |
|
868 if ( iAudioLinkCloseCancelFlagResetCalledTwice || ( KErrNone != aResponse ) ) |
|
869 { |
|
870 COM_TRACE_( "[AccFW:AccServer] CAccSrvSubBTControl::ResetAudioLinkCloseCancelFlag - second call" ); |
|
871 iServerModel->SetAudioLinkCloseCancelled( EFalse ); |
|
872 iAudioLinkCloseCancelFlagResetCalledTwice = EFalse; |
|
873 } |
|
874 else |
|
875 { |
|
876 iAudioLinkCloseCancelFlagResetCalledTwice = ETrue; |
|
877 } |
|
878 |
|
879 COM_TRACE_( "[AccFW:AccServer] CAccSrvSubBTControl::ResetAudioLinkCloseCancelFlag - return void" ); |
|
880 } |
|
881 |
|
882 // ----------------------------------------------------------------------------- |
|
883 // CAccSrvSubBTControl::MakeTUint64 |
|
884 // ----------------------------------------------------------------------------- |
|
885 // |
|
886 TUint64 CAccSrvSubBTControl::MakeTUint64( const TBTDevAddr& aBTDevAddr ) |
|
887 { |
|
888 #ifdef _DEBUG |
|
889 TBuf<12> bdaddrbuf; |
|
890 aBTDevAddr.GetReadable( bdaddrbuf ); |
|
891 COM_TRACE_1( "[AccFW:AccServer] CAccSrvSubBTControl::MakeTUint64(%S)", &bdaddrbuf ); |
|
892 #endif |
|
893 |
|
894 TUint32 bTDevAddrHigh( 0 ); |
|
895 TUint32 bTDevAddrLow( 0 ); |
|
896 |
|
897 bTDevAddrHigh += aBTDevAddr[1]<<(0*8); |
|
898 bTDevAddrHigh += aBTDevAddr[0]<<(1*8); |
|
899 //bTDevAddrHigh += 0<<(2*8)//The size of a bluetooth device address in bytes is 6 (KBTDevAddrSize) |
|
900 //bTDevAddrHigh += 0<<(3*8)//The size of a bluetooth device address in bytes is 6 (KBTDevAddrSize) |
|
901 |
|
902 bTDevAddrLow += aBTDevAddr[5]<<(0*8); |
|
903 bTDevAddrLow += aBTDevAddr[4]<<(1*8); |
|
904 bTDevAddrLow += aBTDevAddr[3]<<(2*8); |
|
905 bTDevAddrLow += aBTDevAddr[2]<<(3*8); |
|
906 |
|
907 COM_TRACE_2( "[AccFW:AccServer] CAccSrvSubBTControl::MakeTUint64 - return (h:0x%x, l:0x%x)", bTDevAddrHigh, bTDevAddrLow ); |
|
908 |
|
909 return MAKE_TUINT64 (bTDevAddrHigh, bTDevAddrLow); |
|
910 } |
|
911 |
|
912 // ========================== OTHER EXPORTED FUNCTIONS ========================= |
|
913 |
|
914 // End of File |