|
1 /* |
|
2 * Copyright (c) 2002-2008 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: Control for accessory related settings. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "AccSrvSettingsHandler.h" |
|
21 #include "AccSrvConnectionController.h" |
|
22 #include "acc_debug.h" |
|
23 #include <AccessoryTypes.h> |
|
24 #include <e32property.h> |
|
25 #include <centralrepository.h> |
|
26 #include <hwrmdomainpskeys.h> |
|
27 #include <AccSettingsDomainCRKeys.h> |
|
28 #include <f32file.h> |
|
29 #include <hwrmlight.h> |
|
30 |
|
31 // EXTERNAL DATA STRUCTURES |
|
32 |
|
33 // EXTERNAL FUNCTION PROTOTYPES |
|
34 |
|
35 // CONSTANTS |
|
36 const TInt KAccSettingIdLength = 4; // "int:" or "boo:" or "des:" |
|
37 const TInt KAccSettingMaxLength = KAccSettingIdLength + KMaxAccModeSetting; |
|
38 // Max size in bytes for hwdevices.ini file |
|
39 const TInt KHWDevicesFileMaxSize = 4; |
|
40 // Maximum number of supported accessory modes |
|
41 const TInt KMaxAccessoryMode = 4096; |
|
42 // Maximum number of supported settings for each accessory mode |
|
43 const TInt KMaxAccessorySetting = 4096; |
|
44 // First bit reserved for accessory mode when counting is started from right |
|
45 const TInt KAccessoryModeStartBit = 20; |
|
46 // First bit reserved for accessory mode setting when counting is started from |
|
47 // right |
|
48 const TInt KAccessoryModeSettingStartBit = 8; |
|
49 |
|
50 // MACROS |
|
51 |
|
52 // LOCAL CONSTANTS AND MACROS |
|
53 _LIT( KAccSettingInteger, "int:" ); |
|
54 _LIT( KAccSettingBoolean, "boo:" ); |
|
55 _LIT( KAccSettingDescriptor, "des:" ); |
|
56 // File that stores supported HW devices |
|
57 _LIT( KHWDevicesFile, "c:\\private\\1020504A\\hwdevices.ini" ); |
|
58 |
|
59 // MODULE DATA STRUCTURES |
|
60 |
|
61 // LOCAL FUNCTION PROTOTYPES |
|
62 |
|
63 // FORWARD DECLARATIONS |
|
64 |
|
65 // ============================= LOCAL FUNCTIONS ================================ |
|
66 |
|
67 // ============================= MEMBER FUNCTIONS =============================== |
|
68 |
|
69 // ----------------------------------------------------------------------------- |
|
70 // CAccSrvSettingsHandler::CAccSrvSettingsHandler |
|
71 // C++ default constructor can NOT contain any code, that |
|
72 // might leave. |
|
73 // ----------------------------------------------------------------------------- |
|
74 // |
|
75 CAccSrvSettingsHandler::CAccSrvSettingsHandler( CAccSrvConnectionController* aConCtrl, |
|
76 CAccSrvServerModel& aModel ) |
|
77 : iConCtrl( aConCtrl ), |
|
78 iModel( aModel ), |
|
79 iLightsOn( EAccSettingsLightsNotSet ) |
|
80 { |
|
81 COM_TRACE_( "[AccFW:AccServer] CAccSrvSettingsHandler::CAccSrvSettingsHandler()" ); |
|
82 |
|
83 COM_TRACE_( "[AccFW:AccServer] CAccSrvSettingsHandler::CAccSrvSettingsHandler - return" ); |
|
84 } |
|
85 |
|
86 // ----------------------------------------------------------------------------- |
|
87 // CAccSrvSettingsHandler::ConstructL |
|
88 // Symbian 2nd phase constructor can leave. |
|
89 // ----------------------------------------------------------------------------- |
|
90 // |
|
91 void CAccSrvSettingsHandler::ConstructL() |
|
92 { |
|
93 COM_TRACE_( "[AccFW:AccServer] CAccSrvSettingsHandler::ConstructL()" ); |
|
94 |
|
95 // Update settings in model according to CR |
|
96 TInt retval( KErrNone ); |
|
97 TInt hwDevices( 0 ); |
|
98 |
|
99 retval = RProperty::Define( KPSUidHWRM, |
|
100 KHWRMAccessoryVibraBlocked, |
|
101 RProperty::EInt, |
|
102 KNoCapability, |
|
103 KWriteDeviceDataPolicy); |
|
104 |
|
105 if( retval != KErrAlreadyExists ) |
|
106 { |
|
107 User::LeaveIfError( retval ); |
|
108 } |
|
109 |
|
110 CRepository* repository = CRepository::NewLC( KCRUidAccServer ); |
|
111 User::LeaveIfError( repository->Get( KAccServerHWDevices, hwDevices ) ); |
|
112 iModel.SetDeviceType( static_cast<TUint32>( hwDevices ) ); |
|
113 CleanupStack::PopAndDestroy( repository ); |
|
114 |
|
115 COM_TRACE_( "[AccFW:AccServer] CAccSrvSettingsHandler::ConstructL - return void" ); |
|
116 } |
|
117 |
|
118 // ----------------------------------------------------------------------------- |
|
119 // CAccSrvSettingsHandler::NewL |
|
120 // Two-phased constructor. |
|
121 // ----------------------------------------------------------------------------- |
|
122 // |
|
123 CAccSrvSettingsHandler* CAccSrvSettingsHandler::NewL( |
|
124 CAccSrvConnectionController* aConCtrl, |
|
125 CAccSrvServerModel& aModel ) |
|
126 { |
|
127 COM_TRACE_( "[AccFW:AccServer] CAccSrvSettingsHandler::NewL()" ); |
|
128 |
|
129 CAccSrvSettingsHandler* self = new( ELeave ) CAccSrvSettingsHandler( |
|
130 aConCtrl, |
|
131 aModel ); |
|
132 CleanupStack::PushL( self ); |
|
133 self->ConstructL(); |
|
134 CleanupStack::Pop( self ); |
|
135 |
|
136 COM_TRACE_( "[AccFW:AccServer] CAccSrvSettingsHandler::NewL - return self" ); |
|
137 return self; |
|
138 } |
|
139 |
|
140 // Destructor |
|
141 CAccSrvSettingsHandler::~CAccSrvSettingsHandler() |
|
142 { |
|
143 COM_TRACE_( "[AccFW:AccServer] CAccSrvSettingsHandler::~CAccSrvSettingsHandler()" ); |
|
144 delete iLightsApi; |
|
145 COM_TRACE_( "[AccFW:AccServer] CAccSrvSettingsHandler::~CAccSrvSettingsHandler - return" ); |
|
146 } |
|
147 |
|
148 // ----------------------------------------------------------------------------- |
|
149 // CAccSrvSettingsHandler::ConnectionStatusChangedL |
|
150 // Accessory settings may change when connection status changes. This method |
|
151 // updates settings according connection status and user given settings. |
|
152 // (other items were commented in a header). |
|
153 // ----------------------------------------------------------------------------- |
|
154 // |
|
155 void CAccSrvSettingsHandler::ConnectionStatusChangedL( |
|
156 TAccPolGenericIDArray& aArray ) |
|
157 { |
|
158 COM_TRACE_( "[AccFW:AccServer] CAccSrvSettingsHandler::ConnectionStatusChangedL()" ); |
|
159 |
|
160 TAccPolGenericID genericId; |
|
161 TBool vibraAllowed( ETrue ); |
|
162 |
|
163 // Any accessories connected |
|
164 if( aArray.Count() > 0 ) |
|
165 { |
|
166 // get generic id of last connected accessory |
|
167 genericId = aArray.GetGenericIDL( 0 ); |
|
168 // check if vibra is really allowed |
|
169 GetVibraAllowed( genericId, vibraAllowed ); |
|
170 } |
|
171 |
|
172 // Get current vibra status |
|
173 TInt vibraBlocked( 0 ); |
|
174 RProperty::Get( KPSUidHWRM, KHWRMAccessoryVibraBlocked, vibraBlocked ); |
|
175 |
|
176 // Set vibra on/off, if needed |
|
177 if( !vibraAllowed && vibraBlocked == 0 ) |
|
178 { |
|
179 // accessory that doesn't support vibra was connected -> set vibra of |
|
180 COM_TRACE_( "[AccFW:AccServer] CAccSrvSettingsHandlerConnectionStatusChangedL() - Vibra PS Key = VibraOff" ); |
|
181 |
|
182 RProperty::Set( KPSUidHWRM, |
|
183 KHWRMAccessoryVibraBlocked, |
|
184 1 ); |
|
185 } |
|
186 else if( vibraAllowed && vibraBlocked == 1 ) |
|
187 { |
|
188 // accessory that doesn't support vibra was disconnected -> set vibra on |
|
189 COM_TRACE_( "[AccFW:AccServer] CAccSrvSettingsHandlerConnectionStatusChangedL() - Vibra PS Key = VibraOn" ); |
|
190 |
|
191 RProperty::Set( KPSUidHWRM, |
|
192 KHWRMAccessoryVibraBlocked, |
|
193 0 ); |
|
194 } |
|
195 |
|
196 TBool setLights( EFalse ); |
|
197 |
|
198 // Accessory connected |
|
199 if( aArray.Count() > 0 ) |
|
200 { |
|
201 // check if lights should be put on |
|
202 GetLightsAllowedL( genericId, setLights ); |
|
203 |
|
204 // Need to set lights on |
|
205 if( setLights ) |
|
206 { |
|
207 // accessory with lights on setting connected -> set lights on |
|
208 COM_TRACE_( "[AccFW:AccServer] CAccSrvSettingsHandler::ConnectionStatusChangedL() - Set lights on" ); |
|
209 |
|
210 if( !iLightsApi ) |
|
211 { |
|
212 iLightsApi = CHWRMLight::NewL(); |
|
213 } |
|
214 |
|
215 iLightsApi->ReserveLightL( CHWRMLight::ESystemTarget, ETrue, ETrue ); |
|
216 iLightsApi->LightOnL( CHWRMLight::ESystemTarget ); |
|
217 |
|
218 iLightsOn = EAccSettingsLightsOn; |
|
219 } |
|
220 } |
|
221 else if( iLightsOn == EAccSettingsLightsOn ) |
|
222 { |
|
223 // accessory with lights on setting disconnected -> set lights off |
|
224 COM_TRACE_( "[AccFW:AccServer] CAccSrvSettingsHandler::ConnectionStatusChangedL() - Set lights off" ); |
|
225 |
|
226 iLightsApi->ReleaseLight( CHWRMLight::ESystemTarget ); |
|
227 |
|
228 delete iLightsApi; |
|
229 iLightsApi = NULL; |
|
230 |
|
231 iLightsOn = EAccSettingsLightsOff; |
|
232 } |
|
233 |
|
234 COM_TRACE_( "[AccFW:AccServer] CAccSrvSettingsHandler::ConnectionStatusChangedL() - return void" ); |
|
235 } |
|
236 |
|
237 // ----------------------------------------------------------------------------- |
|
238 // CAccSrvSettingsHandler::GetSupportedHWDevicesL |
|
239 // |
|
240 // (other items were commented in a header). |
|
241 // ----------------------------------------------------------------------------- |
|
242 // |
|
243 TUint32 CAccSrvSettingsHandler::GetSupportedHWDevicesL() const |
|
244 { |
|
245 COM_TRACE_( "[AccFW:AccServer] CAccSrvSettingsHandler::GetSupportedHWDevicesL()" ); |
|
246 |
|
247 TUint32 settings( 0 ); |
|
248 |
|
249 // Read supported HW devices from file |
|
250 RFs session; |
|
251 RFile file; |
|
252 HBufC8* buf = HBufC8::NewL( KHWDevicesFileMaxSize ); |
|
253 CleanupStack::PushL( buf ); |
|
254 |
|
255 TPtr8 ptrBuf( buf->Des() ); |
|
256 User::LeaveIfError( session.Connect() ); |
|
257 User::LeaveIfError( file.Open( session, KHWDevicesFile, EFileRead ) ); |
|
258 file.Read( ptrBuf ); |
|
259 file.Close(); |
|
260 session.Close(); |
|
261 |
|
262 TLex8 l( ptrBuf ); |
|
263 TInt32 temp; |
|
264 l.Val( temp ); |
|
265 settings = static_cast< TUint32 >( temp ); |
|
266 |
|
267 CleanupStack::Pop( buf ); |
|
268 |
|
269 COM_TRACE_1( "[AccFW:AccServer] CAccSrvSettingsHandler::GetSupportedHWDevicesL() - return %d", settings ); |
|
270 |
|
271 return settings; |
|
272 } |
|
273 |
|
274 // ----------------------------------------------------------------------------- |
|
275 // CAccSrvSettingsHandler::SetHWDeviceSettingsL |
|
276 // |
|
277 // (other items were commented in a header). |
|
278 // ----------------------------------------------------------------------------- |
|
279 // |
|
280 void CAccSrvSettingsHandler::SetHWDeviceSettingsL( TUint32 aSettings, |
|
281 TBool aEnable, |
|
282 TBool aForce ) const |
|
283 { |
|
284 COM_TRACE_3( "[AccFW:AccServer] CAccSrvSettingsHandler::SetHWDeviceSettingsL( %d, %d, %d )", aSettings, aEnable, aForce ); |
|
285 |
|
286 // Valid settings |
|
287 TUint32 settings = ResolveNewSettingsL( aSettings, aEnable, aForce ); |
|
288 |
|
289 // Update model |
|
290 iModel.SetDeviceType( settings ); |
|
291 |
|
292 // Update setting to CR |
|
293 CRepository* repository = CRepository::NewL( KCRUidAccServer ); |
|
294 TInt crSettings = static_cast<TInt>( settings ); |
|
295 repository->Set( KAccServerHWDevices, crSettings ); |
|
296 delete repository; |
|
297 repository = NULL; |
|
298 |
|
299 COM_TRACE_( "[AccFW:AccServer] CAccSrvSettingsHandler::SetHWDeviceSettingsL() - return" ); |
|
300 } |
|
301 |
|
302 // ----------------------------------------------------------------------------- |
|
303 // CAccSrvSettingsHandler::GetHWDeviceSettings |
|
304 // |
|
305 // (other items were commented in a header). |
|
306 // ----------------------------------------------------------------------------- |
|
307 // |
|
308 TUint32 CAccSrvSettingsHandler::GetHWDeviceSettings() const |
|
309 { |
|
310 COM_TRACE_( "[AccFW:AccServer] CAccSrvSettingsHandler::GetHWDeviceSettings()" ); |
|
311 |
|
312 TUint32 settings = iModel.DeviceType(); |
|
313 |
|
314 COM_TRACE_1( "[AccFW:AccServer] CAccSrvSettingsHandler::SetHWDeviceSettings() - return %d", settings ); |
|
315 return settings; |
|
316 } |
|
317 |
|
318 // ----------------------------------------------------------------------------- |
|
319 // CAccSrvSettingsHandler::SetAccessoryModeSettingL |
|
320 // |
|
321 // (other items were commented in a header). |
|
322 // ----------------------------------------------------------------------------- |
|
323 // |
|
324 void CAccSrvSettingsHandler::SetAccessoryModeSettingL( |
|
325 const TAccMode aAccMode, |
|
326 const TAccModeSetting& aSetting ) const |
|
327 { |
|
328 COM_TRACE_( "[AccFW:AccServer] CAccSrvSettingsHandler::SetAccessoryModeSettingL()" ); |
|
329 |
|
330 CRepository* repository = CRepository::NewL( KCRUidAccServer ); |
|
331 CleanupStack::PushL( repository ); |
|
332 |
|
333 // Static or dynamic setting |
|
334 if( StaticKey( aSetting.Id() ) ) |
|
335 { |
|
336 // write INT setting to CR |
|
337 TUint32 key = static_cast<TUint32>( aSetting.Id() ); |
|
338 TInt setting( 0 ); |
|
339 aSetting.GetTInt( setting ); |
|
340 User::LeaveIfError( repository->Set( key, setting ) ); |
|
341 } |
|
342 else |
|
343 { |
|
344 // write DESCRIPTOR setting to CR |
|
345 TUint32 key = CreateCRKeyL( aAccMode, aSetting.Id() ); |
|
346 HBufC* setting = CodeSettingL( aSetting ); |
|
347 CleanupStack::PushL( setting ); |
|
348 User::LeaveIfError( repository->Set( key, *setting ) ); |
|
349 CleanupStack::PopAndDestroy( setting ); |
|
350 } |
|
351 |
|
352 CleanupStack::PopAndDestroy( repository ); |
|
353 |
|
354 COM_TRACE_( "[AccFW:AccServer] CAccSrvSettingsHandler::SetAccessoryModeSettingL() - return" ); |
|
355 } |
|
356 |
|
357 // ----------------------------------------------------------------------------- |
|
358 // CAccSrvSettingsHandler::GetAccessoryModeSettingL |
|
359 // |
|
360 // (other items were commented in a header). |
|
361 // ----------------------------------------------------------------------------- |
|
362 // |
|
363 void CAccSrvSettingsHandler::GetAccessoryModeSettingL( |
|
364 const TAccMode aAccMode, |
|
365 TAccModeSetting& aSetting ) const |
|
366 { |
|
367 COM_TRACE_1( "[AccFW:AccServer] CAccSrvSettingsHandler::GetAccessoryModeSettingL() AccMode=%d", aAccMode ); |
|
368 |
|
369 CRepository* repository = CRepository::NewL( KCRUidAccServer ); |
|
370 CleanupStack::PushL( repository ); |
|
371 |
|
372 // static / dynamic key |
|
373 if( StaticKey( aSetting.Id() ) ) |
|
374 { |
|
375 // read INT setting from CR |
|
376 TUint32 key = static_cast<TUint32>( aSetting.Id() ); |
|
377 TInt setting( 0 ); |
|
378 User::LeaveIfError( repository->Get( key, setting ) ); |
|
379 aSetting.SetTInt( setting ); |
|
380 } |
|
381 else |
|
382 { |
|
383 // read DESCRIPTOR setting from CR |
|
384 TUint32 key = CreateCRKeyL( aAccMode, aSetting.Id() ); |
|
385 TBuf16< KAccSettingMaxLength > setting; |
|
386 User::LeaveIfError( repository->Get( key, setting ) ); |
|
387 DecodeSettingL( setting, aSetting ); |
|
388 } |
|
389 |
|
390 CleanupStack::PopAndDestroy( repository ); |
|
391 |
|
392 COM_TRACE_( "[AccFW:AccServer] CAccSrvSettingsHandler::GetAccessoryModeSettingL() - return" ); |
|
393 } |
|
394 |
|
395 // ----------------------------------------------------------------------------- |
|
396 // CAccSrvSettingsHandler::SetAccessoryModeSettingsL |
|
397 // |
|
398 // (other items were commented in a header). |
|
399 // ----------------------------------------------------------------------------- |
|
400 // |
|
401 void CAccSrvSettingsHandler::SetAccessoryModeSettingsL( |
|
402 const TAccMode aAccMode, |
|
403 const TAccModeSettingArray& aArray ) const |
|
404 { |
|
405 COM_TRACE_1( "[AccFW:AccServer] CAccSrvSettingsHandler::SetAccessoryModeSettingsL(aAccMode=%d)", aAccMode ); |
|
406 |
|
407 for(TInt i=0; i<aArray.GetArraySize(); ++i ) |
|
408 { |
|
409 TAccModeSetting setting; |
|
410 aArray.GetSetting( i, setting ); |
|
411 SetAccessoryModeSettingL( aAccMode, setting ); |
|
412 } |
|
413 |
|
414 COM_TRACE_( "[AccFW:AccServer] CAccSrvSettingsHandler::SetAccessoryModeSettingsL() - return" ); |
|
415 } |
|
416 |
|
417 // ----------------------------------------------------------------------------- |
|
418 // CAccSrvSettingsHandler::GetAccessoryModeSettingsL |
|
419 // |
|
420 // (other items were commented in a header). |
|
421 // ----------------------------------------------------------------------------- |
|
422 // |
|
423 void CAccSrvSettingsHandler::GetAccessoryModeSettingsL( |
|
424 const TAccMode aAccMode, |
|
425 TAccModeSettingArray& aArray ) const |
|
426 { |
|
427 COM_TRACE_1( "[AccFW:AccServer] CAccSrvSettingsHandler::GetAccessoryModeSettingsL(aAccMode=%d)", aAccMode ); |
|
428 |
|
429 // Creation of partialKey and mask below has to be line with logic in |
|
430 // CAccSrvSettingsHandler::CreateCRKeyL() method. |
|
431 |
|
432 TUint32 mode = static_cast< TUint32 >( const_cast< TAccMode& >( aAccMode ) ); |
|
433 if( mode >= KMaxAccessoryMode ) |
|
434 { |
|
435 // mode value is out of range |
|
436 COM_TRACE_1( "[AccFW:AccServer] CAccSrvSettingsHandler::GetAccessoryModeSettingsL() aAccMode=%d is out of range", aAccMode ); |
|
437 User::Leave( KErrArgument ); |
|
438 } |
|
439 |
|
440 // reset possible items in an array |
|
441 aArray.Reset(); |
|
442 |
|
443 CRepository* repository = CRepository::NewL( KCRUidAccServer ); |
|
444 CleanupStack::PushL( repository ); |
|
445 |
|
446 // search accessory mode specific dynamic settings |
|
447 RArray< TUint32 > foundKeys; |
|
448 CleanupClosePushL( foundKeys ); |
|
449 TUint32 partialKey = mode << KAccessoryModeStartBit; |
|
450 TUint32 mask( 0xfff00000 ); |
|
451 repository->FindL( partialKey, mask, foundKeys ); |
|
452 |
|
453 RArray< TUint32 > array; |
|
454 CleanupClosePushL( array ); |
|
455 GetStaticKeys( aAccMode, array ); |
|
456 TAccModeSetting setting; |
|
457 |
|
458 // get mode related static settings for client |
|
459 for ( TInt i=0; i<array.Count(); ++i ) |
|
460 { |
|
461 TInt intSetting( 0 ); |
|
462 User::LeaveIfError( repository->Get( array[i], intSetting ) ); |
|
463 setting.SetId( array[i] ); |
|
464 setting.SetTInt( intSetting ); // sets type & value |
|
465 aArray.AddSetting( setting ); |
|
466 } |
|
467 |
|
468 // get mode related dynamic settings |
|
469 for ( TInt i=0; i<foundKeys.Count(); ++i ) |
|
470 { |
|
471 TUint32 key = foundKeys[i]; |
|
472 TBuf16< KAccSettingMaxLength > desSetting; |
|
473 User::LeaveIfError( repository->Get( key, desSetting ) ); |
|
474 // setting id is stored key's to hexadecimal numbers marked with X: |
|
475 // 0x000XXX00 |
|
476 TUint32 temp = key & 0x000fff00; |
|
477 TUint32 id = temp >> KAccessoryModeSettingStartBit; |
|
478 setting.SetId( id ); |
|
479 DecodeSettingL( desSetting, setting ); // sets type & value |
|
480 aArray.AddSetting( setting ); |
|
481 } |
|
482 |
|
483 CleanupStack::PopAndDestroy( &array );//array.Close() is called; |
|
484 CleanupStack::PopAndDestroy( &foundKeys );//foundKeys.Close() is called; |
|
485 CleanupStack::PopAndDestroy( repository ); |
|
486 |
|
487 COM_TRACE_( "[AccFW:AccServer] CAccSrvSettingsHandler::GetAccessoryModeSettingsL() - return" ); |
|
488 } |
|
489 |
|
490 // ----------------------------------------------------------------------------- |
|
491 // CAccSrvSettingsHandler::ResolveNewSettingsL |
|
492 // Note: This method assumes that only ONE HW DEVICE setting is ACTIVE AT THE |
|
493 // TIME. If API method RAccessorySettings::SetHWDeviceSettingsL( |
|
494 // TUint32 aSettings, |
|
495 // TBool aEnable, |
|
496 // TBool aForce ) |
|
497 // |
|
498 // starts to support several active settings at the same time, this method |
|
499 // has to be modified. |
|
500 // (other items were commented in a header). |
|
501 // ----------------------------------------------------------------------------- |
|
502 // |
|
503 TUint32 CAccSrvSettingsHandler::ResolveNewSettingsL( TUint32 aSettings, |
|
504 TBool aEnable, |
|
505 TBool /*aForce*/ ) const |
|
506 { |
|
507 COM_TRACE_2( "[AccFW:AccServer] CAccSrvSettingsHandler::ResolveNewSettingsL( %d, %d )", aSettings, aEnable ); |
|
508 |
|
509 TUint32 settings( 0 ); |
|
510 |
|
511 // Clear all settings |
|
512 if( aSettings == KASNoDevice || !aEnable ) |
|
513 { |
|
514 COM_TRACE_1( "[AccFW:AccServer] CAccSrvSettingsHandler::ResolveNewSettingsL() - return %d", settings ); |
|
515 return settings; |
|
516 } |
|
517 |
|
518 // Set new setting |
|
519 switch ( aSettings ) |
|
520 { |
|
521 case KASTTY: |
|
522 case KASLoopset: |
|
523 case KASHeadset: |
|
524 case KASHeadphones: |
|
525 case KASLineOut: |
|
526 case KASTVOut: |
|
527 case KASMusicStand: |
|
528 settings = aSettings; |
|
529 break; |
|
530 |
|
531 default: |
|
532 // Only one setting supported at the moment |
|
533 settings = aSettings; |
|
534 break; |
|
535 } |
|
536 |
|
537 COM_TRACE_1( "[AccFW:AccServer] CAccSrvSettingsHandler::ResolveNewSettingsL() - return %d", settings ); |
|
538 return settings; |
|
539 } |
|
540 |
|
541 // ----------------------------------------------------------------------------- |
|
542 // CAccSrvSettingsHandler::GetVibraAllowedL |
|
543 // |
|
544 // (other items were commented in a header). |
|
545 // ----------------------------------------------------------------------------- |
|
546 // |
|
547 void CAccSrvSettingsHandler::GetVibraAllowed( TAccPolGenericID& aId, |
|
548 TBool& aVibra ) const |
|
549 { |
|
550 COM_TRACE_( "[AccFW:AccServer] CAccSrvSettingsHandler::GetVibraAllowed()" ); |
|
551 |
|
552 aVibra = ETrue; |
|
553 |
|
554 // Critical accessory (wired car kit, music stand connected ) |
|
555 if ( aId.DeviceTypeCaps( KDTCarKit ) && aId.PhysicalConnectionCaps( KPCWired ) || |
|
556 aId.DeviceTypeCaps( KDTOffice ) && aId.PhysicalConnectionCaps( KPCWired ) ) |
|
557 { |
|
558 aVibra = EFalse; |
|
559 } |
|
560 |
|
561 COM_TRACE_1( "[AccFW:AccServer] CAccSrvSettingsHandler::GetVibraAllowed() - return aVibra = %d", aVibra ); |
|
562 } |
|
563 |
|
564 // ----------------------------------------------------------------------------- |
|
565 // CAccSrvSettingsHandler::GetLightsAllowedL |
|
566 // Returns aLights = ETrue, if lights are set on for connected accessory. |
|
567 // Returns aLights = EFalse, if lights are not set for connected accessory. |
|
568 // (other items were commented in a header). |
|
569 // ----------------------------------------------------------------------------- |
|
570 // |
|
571 void CAccSrvSettingsHandler::GetLightsAllowedL( TAccPolGenericID& aId, |
|
572 TBool& aLights ) const |
|
573 { |
|
574 COM_TRACE_( "[AccFW:AccServer] CAccSrvSettingsHandler::GetLightsAllowedL()" ); |
|
575 |
|
576 TUint32 key( 0 ); |
|
577 |
|
578 // Select CR key |
|
579 if ( aId.DeviceTypeCaps( KDTHeadset ) && |
|
580 aId.PhysicalConnectionCaps( KPCWired ) ) |
|
581 { |
|
582 key = KAccServerWiredHSLights; |
|
583 } |
|
584 else if ( aId.DeviceTypeCaps( KDTHeadset ) && |
|
585 aId.PhysicalConnectionCaps( KPCBluetooth ) ) |
|
586 { |
|
587 key = KAccServerWirelessHSLights; |
|
588 } |
|
589 else if ( aId.DeviceTypeCaps( KDTCarKit ) && |
|
590 aId.PhysicalConnectionCaps( KPCWired ) ) |
|
591 { |
|
592 key = KAccServerWiredCarKitLights; |
|
593 } |
|
594 else if ( aId.DeviceTypeCaps( KDTCarKit ) && |
|
595 aId.PhysicalConnectionCaps( KPCBluetooth ) ) |
|
596 { |
|
597 key = KAccServerWirelessCarKitLights; |
|
598 } |
|
599 else if ( aId.DeviceTypeCaps( KDTTTY ) && |
|
600 aId.PhysicalConnectionCaps( KPCWired ) ) |
|
601 { |
|
602 key = KAccServerTextDeviceLights; |
|
603 } |
|
604 else if ( aId.DeviceTypeCaps( KDTLoopset ) && |
|
605 aId.PhysicalConnectionCaps( KPCWired ) ) |
|
606 { |
|
607 key = KAccServerLoopsetLights; |
|
608 } |
|
609 else if ( aId.DeviceTypeCaps( KDTOffice ) && |
|
610 aId.PhysicalConnectionCaps( KPCWired ) ) |
|
611 { |
|
612 key = KAccServerMusicStandLights; |
|
613 } |
|
614 |
|
615 // Get light setting from CR |
|
616 TInt setLights( 0 ); |
|
617 |
|
618 if ( key ) |
|
619 { |
|
620 // If key is selected, get lights status from CenRep |
|
621 CRepository* repository = CRepository::NewL( KCRUidAccServer ); |
|
622 CleanupStack::PushL( repository ); |
|
623 User::LeaveIfError( repository->Get( key, setLights ) ); |
|
624 CleanupStack::PopAndDestroy( repository ); |
|
625 } |
|
626 else |
|
627 { |
|
628 // Key not set, no need to get value from CenRep (it'll leave anyway) |
|
629 // This is the case at least with AV_Connector (TV-Out) |
|
630 } |
|
631 |
|
632 aLights = static_cast<TBool>( setLights ); |
|
633 |
|
634 COM_TRACE_1( "[AccFW:AccServer] CAccSrvSettingsHandler::GetLightsAllowedL() - return aLights = %d", aLights ); |
|
635 } |
|
636 |
|
637 // ----------------------------------------------------------------------------- |
|
638 // CAccSrvSettingsHandler::CreateCRKeyL |
|
639 // |
|
640 // CR key has to be uniq TUint32 value. It's used to set/get a single accessory |
|
641 // setting. |
|
642 |
|
643 // Key value range from 0x00100000 to 0xFFFFFF00 has been reserved for any |
|
644 // accessory related setting that doesn't have influence to Accessory Server |
|
645 // behaviour but needs to be stored permanently. |
|
646 // |
|
647 // Key value created by this method consists as follows: |
|
648 // |
|
649 // 1. accessory mode is stored to hexadecimal numbers marked with X: 0xXXX00000 |
|
650 // 2. setting id is stored to hexadecimal numbers marked with X: 0x000XXX00 |
|
651 // |
|
652 // Thus, Accessory Server can store dynamically 4096 accessory modes and for |
|
653 // each mode 4096 settings. |
|
654 // |
|
655 // (2 least significant hexadecimal numbers have been reserved for keys that |
|
656 // have an influence to Accessory Server behaviour like KAccServerHWDevices |
|
657 // key. Thus, Accessory Server can store 256 settings this kind of settings.) |
|
658 // |
|
659 // (other items were commented in a header). |
|
660 // ----------------------------------------------------------------------------- |
|
661 // |
|
662 TUint32 CAccSrvSettingsHandler::CreateCRKeyL( |
|
663 const TAccMode aAccMode, |
|
664 const TInt aId ) const |
|
665 { |
|
666 COM_TRACE_2( "[AccFW:AccServer] CAccSrvSettingsHandler::CreateCRKeyL(%d,%d)", aAccMode, aId ); |
|
667 |
|
668 TUint32 key( 0 ); |
|
669 |
|
670 // create first part of key from accessory mode |
|
671 TUint32 mode = static_cast< TUint32 >( const_cast< TAccMode& >( aAccMode ) ); |
|
672 if( mode >= KMaxAccessoryMode ) |
|
673 { |
|
674 // mode value is out of range |
|
675 COM_TRACE_1( "[AccFW:AccServer] CAccSrvSettingsHandler::CreateCRKeyL() aAccMode=%d is out of range", aAccMode ); |
|
676 User::Leave( KErrArgument ); |
|
677 } |
|
678 |
|
679 TUint32 keyPart1 = mode << KAccessoryModeStartBit; |
|
680 |
|
681 // Create second part of key from id |
|
682 TUint32 id = static_cast< TUint32 >( const_cast< TInt& >( aId ) ); |
|
683 if( id >= KMaxAccessorySetting ) |
|
684 { |
|
685 // id value is out of range |
|
686 COM_TRACE_1( "[AccFW:AccServer] CAccSrvSettingsHandler::CreateCRKeyL() aId=%d is out of range", aId ); |
|
687 User::Leave( KErrArgument ); |
|
688 } |
|
689 |
|
690 TUint32 keyPart2 = id << KAccessoryModeSettingStartBit; |
|
691 |
|
692 key = keyPart1 + keyPart2; |
|
693 COM_TRACE_1( "[AccFW:AccServer] CAccSrvSettingsHandler::CreateCRKeyL() returns key=%d", key ); |
|
694 |
|
695 return key; |
|
696 } |
|
697 |
|
698 // ----------------------------------------------------------------------------- |
|
699 // CAccSrvSettingsHandler::CodeSettingL |
|
700 // |
|
701 // This method is used to convert setting in client format to (TAccModeSetting) |
|
702 // dynamic format that used to store setting to CR. |
|
703 // |
|
704 // Dynamic settings are stored to descriptor that has following structure: |
|
705 // xxx:yyy where |
|
706 // |
|
707 // xxx tells variable type of a setting. Possible values are "des" for |
|
708 // descriptor, "int" for integer and "boo" for boolean. Variable is stored to |
|
709 // 3 characters. |
|
710 // |
|
711 // ":" separates variable type information from it's value. Separation character |
|
712 // takes one character. |
|
713 // |
|
714 // yyy stores value of a setting. For setting has been reserved 256 characters. |
|
715 // |
|
716 // (other items were commented in a header). |
|
717 // ----------------------------------------------------------------------------- |
|
718 // |
|
719 HBufC* CAccSrvSettingsHandler::CodeSettingL( const TAccModeSetting& aSetting ) const |
|
720 { |
|
721 HBufC* data = HBufC::NewL( KAccSettingMaxLength ); |
|
722 |
|
723 // store variable type and value to data |
|
724 switch ( aSetting.Type() ) |
|
725 { |
|
726 case EAccModeSettingInt: |
|
727 { |
|
728 TInt value( 0 ); |
|
729 aSetting.GetTInt( value ); |
|
730 TBuf< KAccSettingMaxLength > temp; |
|
731 temp.Num( value ); |
|
732 data->Des().Copy( KAccSettingInteger ); |
|
733 data->Des().Append( temp ); |
|
734 } |
|
735 break; |
|
736 |
|
737 case EAccModeSettingBool: |
|
738 { |
|
739 TBool value( EFalse ); |
|
740 aSetting.GetTBool( value ); |
|
741 TBuf< 1 > temp; |
|
742 if ( value ) |
|
743 { |
|
744 _LIT( KTrue, "1" ); |
|
745 temp.Append( KTrue ); |
|
746 } |
|
747 else |
|
748 { |
|
749 _LIT( KFalse, "0" ); |
|
750 temp.Append( KFalse ); |
|
751 } |
|
752 data->Des().Copy( KAccSettingBoolean ); |
|
753 data->Des().Append( temp ); |
|
754 } |
|
755 break; |
|
756 |
|
757 case EAccModeSettingDes: |
|
758 { |
|
759 TBuf< KAccSettingMaxLength > value; |
|
760 aSetting.GetTDes( value ); |
|
761 data->Des().Copy( KAccSettingDescriptor ); |
|
762 data->Des().Append( value ); |
|
763 } |
|
764 break; |
|
765 |
|
766 default: |
|
767 { |
|
768 COM_TRACE_( "[AccFW:AccServer] CAccSrvSettingsHandler::CodeSettingL() value was not set !" ); |
|
769 delete data; |
|
770 data = NULL; |
|
771 User::Leave( KErrNotFound ); |
|
772 } |
|
773 break; |
|
774 } |
|
775 |
|
776 COM_TRACE_1( "[AccFW:AccServer] CAccSrvSettingsHandler:.CodeSettingL() returns %d", data ); |
|
777 return data; |
|
778 } |
|
779 |
|
780 // ----------------------------------------------------------------------------- |
|
781 // CAccSrvSettingsHandler::DecodeSettingL |
|
782 // |
|
783 // This method is used to convert dynamically stored setting to format |
|
784 // (TAccModeSetting) that client understands. |
|
785 // |
|
786 // Dynamic settings are stored to descriptor that has following structure: |
|
787 // xxx:yyy where |
|
788 // |
|
789 // xxx tells variable type of a setting. Possible values are "des" for |
|
790 // descriptor, "int" for integer and "boo" for boolean. Variable is stored to |
|
791 // 3 characters. |
|
792 // |
|
793 // ":" separates variable type information from it's value. Separation character |
|
794 // takes one character. |
|
795 // |
|
796 // yyy stores value of a setting. For setting has been reserved 256 characters. |
|
797 // |
|
798 // (other items were commented in a header). |
|
799 // ----------------------------------------------------------------------------- |
|
800 // |
|
801 void CAccSrvSettingsHandler::DecodeSettingL( const TDesC& aIn, TAccModeSetting& aOut ) const |
|
802 { |
|
803 COM_TRACE_( "[AccFW:AccServer] CAccSrvSettingsHandler::DecodeSettingL()" ); |
|
804 |
|
805 TAccModeSettingType type( EAccModeSettingNotSet ); |
|
806 |
|
807 // check variable type |
|
808 if( aIn.Find( KAccSettingInteger ) == 0 ) |
|
809 { |
|
810 type = EAccModeSettingInt; |
|
811 } |
|
812 else if( aIn.Find( KAccSettingBoolean ) == 0 ) |
|
813 { |
|
814 type = EAccModeSettingBool; |
|
815 } |
|
816 else if( aIn.Find( KAccSettingDescriptor ) == 0 ) |
|
817 { |
|
818 type = EAccModeSettingDes; |
|
819 } |
|
820 |
|
821 // get data out |
|
822 HBufC* data = HBufC::NewL( aIn.Length() - KAccSettingIdLength ); |
|
823 data->Des().Copy( aIn.Mid( KAccSettingIdLength ) ); |
|
824 |
|
825 // store value for client |
|
826 switch ( type ) |
|
827 { |
|
828 case EAccModeSettingInt: |
|
829 { |
|
830 TLex temp( *data ); |
|
831 TInt value( 0 ); |
|
832 temp.Val( value ); |
|
833 aOut.SetTInt( value ); |
|
834 } |
|
835 break; |
|
836 |
|
837 case EAccModeSettingBool: |
|
838 { |
|
839 TLex temp( *data ); |
|
840 TInt value( 0 ); |
|
841 temp.Val( value ); |
|
842 aOut.SetTBool( static_cast< TBool >( value ) ); |
|
843 } |
|
844 break; |
|
845 |
|
846 case EAccModeSettingDes: |
|
847 { |
|
848 aOut.SetTDes( *data ); |
|
849 } |
|
850 break; |
|
851 |
|
852 default: |
|
853 { |
|
854 COM_TRACE_( "[AccFW:AccServer] CAccSrvSettingsHandler::DecodeSettingL() value was not set !" ); |
|
855 delete data; |
|
856 User::Leave( KErrNotFound ); |
|
857 } |
|
858 break; |
|
859 } |
|
860 |
|
861 delete data; |
|
862 COM_TRACE_( "[AccFW:AccServer] CAccSrvSettingsHandler::DecodeSettingL() return" ); |
|
863 } |
|
864 |
|
865 // ----------------------------------------------------------------------------- |
|
866 // CAccSrvSettingsHandler::StaticKey |
|
867 // |
|
868 // Returns ETrue, if id is static key. Settings stored with static key have some |
|
869 // influence to Accessory Server's behaviour. |
|
870 // (other items were commented in a header). |
|
871 // ----------------------------------------------------------------------------- |
|
872 // |
|
873 TBool CAccSrvSettingsHandler::StaticKey( const TInt id ) const |
|
874 { |
|
875 COM_TRACE_1( "[AccFW:AccServer] CAccSrvSettingsHandler::StaticKey(%d)", id ); |
|
876 |
|
877 TBool identified( EFalse ); |
|
878 |
|
879 switch ( id ) |
|
880 { |
|
881 case KAccServerWiredHSLights: |
|
882 case KAccServerWirelessHSLights: |
|
883 case KAccServerWiredCarKitLights: |
|
884 case KAccServerWirelessCarKitLights: |
|
885 case KAccServerTextDeviceLights: |
|
886 case KAccServerLoopsetLights: |
|
887 case KAccServerMusicStandLights: |
|
888 case KAccServerSyncStandLights: |
|
889 identified = ETrue; |
|
890 break; |
|
891 |
|
892 default: |
|
893 break; |
|
894 } |
|
895 |
|
896 COM_TRACE_1( "[AccFW:AccServer] CAccSrvSettingsHandler::StaticKey() returns %d", identified ); |
|
897 return identified; |
|
898 } |
|
899 |
|
900 // ----------------------------------------------------------------------------- |
|
901 // CAccSrvSettingsHandler::GetStaticKeys |
|
902 // |
|
903 // (other items were commented in a header). |
|
904 // ----------------------------------------------------------------------------- |
|
905 // |
|
906 void CAccSrvSettingsHandler::GetStaticKeys( |
|
907 const TAccMode aAccMode, |
|
908 RArray< TUint32 >& aArray ) const |
|
909 { |
|
910 COM_TRACE_1( "[AccFW:AccServer] CAccSrvSettingsHandler::GetStaticKeys(%d)", aAccMode ); |
|
911 |
|
912 switch( aAccMode ) |
|
913 { |
|
914 case EAccModeWiredHeadset: |
|
915 aArray.Append( KAccServerWiredHSLights ); |
|
916 break; |
|
917 case EAccModeWirelessHeadset: |
|
918 aArray.Append( KAccServerWirelessHSLights ); |
|
919 break; |
|
920 case EAccModeWiredCarKit: |
|
921 aArray.Append( KAccServerWiredCarKitLights ); |
|
922 break; |
|
923 case EAccModeWirelessCarKit: |
|
924 aArray.Append( KAccServerWirelessCarKitLights ); |
|
925 break; |
|
926 case EAccModeTextDevice: |
|
927 aArray.Append( KAccServerTextDeviceLights ); |
|
928 break; |
|
929 case EAccModeLoopset: |
|
930 aArray.Append( KAccServerLoopsetLights ); |
|
931 break; |
|
932 case EAccModeMusicStand: |
|
933 aArray.Append( KAccServerMusicStandLights ); |
|
934 break; |
|
935 default: // mode is not supported |
|
936 break; |
|
937 } |
|
938 |
|
939 COM_TRACE_( "[AccFW:AccServer] CAccSrvSettingsHandler::GetStaticKeys() returns" ); |
|
940 } |
|
941 |
|
942 // ========================== OTHER EXPORTED FUNCTIONS ========================= |
|
943 |
|
944 // End of File |