|
1 /* |
|
2 * Copyright (c) 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "cradiorepositoryentity.h" |
|
19 #include "cradiorepositorymanager.h" |
|
20 #include "cradiorepositorymanagerimp.h" |
|
21 #include "radioengineutils.h" |
|
22 |
|
23 const TInt KVRRepositoryObserverArrayGranularity = 2; |
|
24 |
|
25 // ======== LOCAL FUNCTIONS ======== |
|
26 |
|
27 // --------------------------------------------------------------------------- |
|
28 // Panics the application. |
|
29 // --------------------------------------------------------------------------- |
|
30 // |
|
31 void Panic( TInt aReason ) |
|
32 { |
|
33 _LIT( category, "CRadioRepositoryManagerImp" ); |
|
34 User::Panic( category, aReason ); |
|
35 } |
|
36 |
|
37 // ======== MEMBER FUNCTIONS ======== |
|
38 |
|
39 // --------------------------------------------------------------------------- |
|
40 // |
|
41 // --------------------------------------------------------------------------- |
|
42 // |
|
43 CRadioRepositoryManagerImp* CRadioRepositoryManagerImp::NewL( TInt aGranularity ) |
|
44 { |
|
45 CRadioRepositoryManagerImp* self = new ( ELeave ) CRadioRepositoryManagerImp( aGranularity ); |
|
46 CleanupStack::PushL( self ); |
|
47 self->ConstructL(); |
|
48 CleanupStack::Pop( self ); |
|
49 return self; |
|
50 } |
|
51 |
|
52 // --------------------------------------------------------------------------- |
|
53 // |
|
54 // --------------------------------------------------------------------------- |
|
55 // |
|
56 void CRadioRepositoryManagerImp::ConstructL() |
|
57 { |
|
58 RadioEngineUtils::InitializeL(); |
|
59 CheckRepositoryKeysL(); |
|
60 } |
|
61 |
|
62 // --------------------------------------------------------------------------- |
|
63 // |
|
64 // --------------------------------------------------------------------------- |
|
65 // |
|
66 CRadioRepositoryManagerImp::CRadioRepositoryManagerImp( TInt aGranularity ) |
|
67 : iObservers( KVRRepositoryObserverArrayGranularity ) |
|
68 , iEntities( aGranularity ) |
|
69 , iEnableSave( ETrue ) |
|
70 { |
|
71 } |
|
72 |
|
73 // --------------------------------------------------------------------------- |
|
74 // |
|
75 // --------------------------------------------------------------------------- |
|
76 // |
|
77 CRadioRepositoryManagerImp::~CRadioRepositoryManagerImp() |
|
78 { |
|
79 iObservers.Close(); |
|
80 iEntities.ResetAndDestroy(); |
|
81 RadioEngineUtils::Release(); |
|
82 } |
|
83 |
|
84 // --------------------------------------------------------------------------- |
|
85 // Adds observer |
|
86 // --------------------------------------------------------------------------- |
|
87 // |
|
88 void CRadioRepositoryManagerImp::AddObserverL( MRadioRepositoryEntityObserver* aObserver ) |
|
89 { |
|
90 iObservers.AppendL( aObserver ); |
|
91 } |
|
92 |
|
93 // --------------------------------------------------------------------------- |
|
94 // Removes observer |
|
95 // --------------------------------------------------------------------------- |
|
96 // |
|
97 void CRadioRepositoryManagerImp::RemoveObserver( MRadioRepositoryEntityObserver* aObserver ) |
|
98 { |
|
99 TInt objectIndex = iObservers.Find( aObserver ); |
|
100 |
|
101 if ( objectIndex != KErrNotFound ) |
|
102 { |
|
103 iObservers.Remove( objectIndex ); |
|
104 } |
|
105 } |
|
106 |
|
107 // --------------------------------------------------------------------------- |
|
108 // Enables or disables the saving of entities. |
|
109 // --------------------------------------------------------------------------- |
|
110 // |
|
111 void CRadioRepositoryManagerImp::EnableSave( TBool aEnable ) |
|
112 { |
|
113 iEnableSave = aEnable; |
|
114 } |
|
115 |
|
116 // --------------------------------------------------------------------------- |
|
117 // Adds an entity. |
|
118 // --------------------------------------------------------------------------- |
|
119 // |
|
120 void CRadioRepositoryManagerImp::AddEntityL( const TUid& aUid, TUint32 aKey, TRadioEntityType aType ) |
|
121 { |
|
122 CRadioRepositoryEntityBase* entity = NULL; |
|
123 |
|
124 switch ( aType ) |
|
125 { |
|
126 case ERadioEntityInt: |
|
127 entity = CRadioRepositoryEntity<TInt>::NewL( aUid, aKey, *this ); |
|
128 break; |
|
129 case ERadioEntityReal: |
|
130 entity = CRadioRepositoryEntity<TReal>::NewL( aUid, aKey, *this ); |
|
131 break; |
|
132 case ERadioEntityDes8: |
|
133 entity = CRadioRepositoryEntity<TRadioEntityBuf8>::NewL( aUid, aKey, *this ); |
|
134 break; |
|
135 case ERadioEntityDes16: |
|
136 entity = CRadioRepositoryEntity<TRadioEntityBuf16>::NewL( aUid, aKey, *this ); |
|
137 break; |
|
138 default: |
|
139 User::Leave( KErrNotSupported ); |
|
140 break; |
|
141 } |
|
142 |
|
143 CleanupStack::PushL( entity ); |
|
144 iEntities.AppendL( entity ); |
|
145 CleanupStack::Pop( entity ); |
|
146 } |
|
147 |
|
148 // --------------------------------------------------------------------------- |
|
149 // Removes an entity. |
|
150 // --------------------------------------------------------------------------- |
|
151 // |
|
152 void CRadioRepositoryManagerImp::RemoveEntity( const TUid& aUid, TUint32 aKey ) |
|
153 { |
|
154 TInt idx = EntityIndex( aUid, aKey ); |
|
155 |
|
156 if ( idx >= 0 ) |
|
157 { |
|
158 CRadioRepositoryEntityBase* entity = iEntities[idx]; |
|
159 iEntities.Remove( idx ); |
|
160 iEntities.GranularCompress(); |
|
161 delete entity; |
|
162 } |
|
163 } |
|
164 |
|
165 // --------------------------------------------------------------------------- |
|
166 // Sets an entity's value. |
|
167 // --------------------------------------------------------------------------- |
|
168 // |
|
169 TInt CRadioRepositoryManagerImp::SetEntityValue( const TUid& aUid, TUint32 aKey, TInt aValue ) |
|
170 { |
|
171 return DoSetEntityValue<TInt>( aUid, aKey, aValue ); |
|
172 } |
|
173 |
|
174 // --------------------------------------------------------------------------- |
|
175 // Sets an entity's value. |
|
176 // --------------------------------------------------------------------------- |
|
177 // |
|
178 TInt CRadioRepositoryManagerImp::SetEntityValue( const TUid& aUid, TUint32 aKey, const TReal& aValue ) |
|
179 { |
|
180 return DoSetEntityValue<TReal>( aUid, aKey, aValue ); |
|
181 } |
|
182 |
|
183 // --------------------------------------------------------------------------- |
|
184 // Sets an entity's value. |
|
185 // --------------------------------------------------------------------------- |
|
186 // |
|
187 TInt CRadioRepositoryManagerImp::SetEntityValue( const TUid& aUid, TUint32 aKey, const TDesC8& aValue ) |
|
188 { |
|
189 return DoSetEntityValue<TRadioEntityBuf8>( aUid, aKey, aValue ); |
|
190 } |
|
191 |
|
192 // --------------------------------------------------------------------------- |
|
193 // Sets an entity's value. |
|
194 // --------------------------------------------------------------------------- |
|
195 // |
|
196 TInt CRadioRepositoryManagerImp::SetEntityValue( const TUid& aUid, TUint32 aKey, const TDesC16& aValue ) |
|
197 { |
|
198 return DoSetEntityValue<TRadioEntityBuf16>( aUid, aKey, aValue ); |
|
199 } |
|
200 |
|
201 // --------------------------------------------------------------------------- |
|
202 // Returns an entity's value. |
|
203 // --------------------------------------------------------------------------- |
|
204 // |
|
205 TInt CRadioRepositoryManagerImp::EntityValueInt( const TUid& aUid, TUint32 aKey ) const |
|
206 { |
|
207 return DoEntityValue<TInt>( aUid, aKey ); |
|
208 } |
|
209 |
|
210 // --------------------------------------------------------------------------- |
|
211 // Returns an entity's value. |
|
212 // --------------------------------------------------------------------------- |
|
213 // |
|
214 const TReal& CRadioRepositoryManagerImp::EntityValueReal( const TUid& aUid, TUint32 aKey ) const |
|
215 { |
|
216 return DoEntityValue<TReal>( aUid, aKey ); |
|
217 } |
|
218 |
|
219 // --------------------------------------------------------------------------- |
|
220 // Returns an entity's value. |
|
221 // --------------------------------------------------------------------------- |
|
222 // |
|
223 const TDesC8& CRadioRepositoryManagerImp::EntityValueDes8( const TUid& aUid, TUint32 aKey ) const |
|
224 { |
|
225 return DoEntityValue<TDesC8>( aUid, aKey ); |
|
226 } |
|
227 |
|
228 // --------------------------------------------------------------------------- |
|
229 // Returns an entity's value. |
|
230 // --------------------------------------------------------------------------- |
|
231 // |
|
232 const TDesC16& CRadioRepositoryManagerImp::EntityValueDes16( const TUid& aUid, TUint32 aKey ) const |
|
233 { |
|
234 return DoEntityValue<TDesC16>( aUid, aKey ); |
|
235 } |
|
236 |
|
237 // --------------------------------------------------------------------------- |
|
238 // Sets the value of a repository key. |
|
239 // --------------------------------------------------------------------------- |
|
240 // |
|
241 void CRadioRepositoryManagerImp::SetRepositoryValueL( const TUid& aUid, TUint32 aKey, TInt aValue ) |
|
242 { |
|
243 DoSetRepositoryValueL( aUid, aKey, aValue ); |
|
244 } |
|
245 |
|
246 // --------------------------------------------------------------------------- |
|
247 // Sets the value of a repository key. |
|
248 // --------------------------------------------------------------------------- |
|
249 // |
|
250 void CRadioRepositoryManagerImp::SetRepositoryValueL( const TUid& aUid, TUint32 aKey, const TReal& aValue ) |
|
251 { |
|
252 DoSetRepositoryValueL( aUid, aKey, aValue ); |
|
253 } |
|
254 |
|
255 // --------------------------------------------------------------------------- |
|
256 // Sets the value of a repository key. |
|
257 // --------------------------------------------------------------------------- |
|
258 // |
|
259 void CRadioRepositoryManagerImp::SetRepositoryValueL( const TUid& aUid, TUint32 aKey, const TDesC8& aValue ) |
|
260 { |
|
261 DoSetRepositoryValueL( aUid, aKey, aValue ); |
|
262 } |
|
263 |
|
264 // --------------------------------------------------------------------------- |
|
265 // Sets the value of a repository key. |
|
266 // --------------------------------------------------------------------------- |
|
267 // |
|
268 void CRadioRepositoryManagerImp::SetRepositoryValueL( const TUid& aUid, TUint32 aKey, const TDesC16& aValue ) |
|
269 { |
|
270 DoSetRepositoryValueL( aUid, aKey, aValue ); |
|
271 } |
|
272 |
|
273 // --------------------------------------------------------------------------- |
|
274 // Gets the value of a repository key. |
|
275 // --------------------------------------------------------------------------- |
|
276 // |
|
277 void CRadioRepositoryManagerImp::GetRepositoryValueL( const TUid& aUid, TUint32 aKey, TInt& aValue ) |
|
278 { |
|
279 DoGetRepositoryValueL( aUid, aKey, aValue ); |
|
280 } |
|
281 |
|
282 // --------------------------------------------------------------------------- |
|
283 // Gets the value of a repository key. |
|
284 // --------------------------------------------------------------------------- |
|
285 // |
|
286 void CRadioRepositoryManagerImp::GetRepositoryValueL( const TUid& aUid, TUint32 aKey, TReal& aValue ) |
|
287 { |
|
288 DoGetRepositoryValueL( aUid, aKey, aValue ); |
|
289 } |
|
290 |
|
291 // --------------------------------------------------------------------------- |
|
292 // Gets the value of a repository key. |
|
293 // --------------------------------------------------------------------------- |
|
294 // |
|
295 void CRadioRepositoryManagerImp::GetRepositoryValueL( const TUid& aUid, TUint32 aKey, TDes8& aValue ) |
|
296 { |
|
297 DoGetRepositoryValueL( aUid, aKey, aValue ); |
|
298 } |
|
299 |
|
300 // --------------------------------------------------------------------------- |
|
301 // Gets the value of a repository key. |
|
302 // --------------------------------------------------------------------------- |
|
303 // |
|
304 void CRadioRepositoryManagerImp::GetRepositoryValueL( const TUid& aUid, TUint32 aKey, TDes16& aValue ) |
|
305 { |
|
306 DoGetRepositoryValueL( aUid, aKey, aValue ); |
|
307 } |
|
308 |
|
309 // --------------------------------------------------------------------------- |
|
310 // Sets an entity's value. |
|
311 // --------------------------------------------------------------------------- |
|
312 // |
|
313 template <typename T> |
|
314 TInt CRadioRepositoryManagerImp::DoSetEntityValue( const TUid& aUid, TUint32 aKey, const T& aValue ) |
|
315 { |
|
316 TInt idx = EntityIndex( aUid, aKey ); |
|
317 |
|
318 // If the entity could not be found, panic the application. |
|
319 __ASSERT_ALWAYS( idx >= 0, ::Panic( KErrArgument ) ); |
|
320 |
|
321 return static_cast<CRadioRepositoryEntity<T>*>( iEntities[idx] )->SetValue( aValue, iEnableSave ); |
|
322 } |
|
323 |
|
324 // --------------------------------------------------------------------------- |
|
325 // Returns an entity's value. |
|
326 // --------------------------------------------------------------------------- |
|
327 // |
|
328 template <typename T> |
|
329 const T& CRadioRepositoryManagerImp::DoEntityValue( const TUid& aUid, TUint32 aKey ) const |
|
330 { |
|
331 TInt idx = EntityIndex( aUid, aKey ); |
|
332 |
|
333 // If the entity could not be found, panic the application. |
|
334 __ASSERT_ALWAYS( idx >= 0, ::Panic( KErrArgument ) ); |
|
335 |
|
336 return static_cast<CRadioRepositoryEntity<T>*>( iEntities[idx] )->Value(); |
|
337 } |
|
338 |
|
339 // --------------------------------------------------------------------------- |
|
340 // Sets a key's value in the repository. |
|
341 // --------------------------------------------------------------------------- |
|
342 // |
|
343 template <typename T> |
|
344 void CRadioRepositoryManagerImp::DoSetRepositoryValueL( const TUid& aUid, TUint32 aKey, const T& aValue ) |
|
345 { |
|
346 CRepository* repository = CRepository::NewLC( aUid ); |
|
347 User::LeaveIfError( repository->Set( aKey, aValue ) ); |
|
348 CleanupStack::PopAndDestroy( repository ); |
|
349 } |
|
350 |
|
351 // --------------------------------------------------------------------------- |
|
352 // Returns a key's value in the repository. |
|
353 // --------------------------------------------------------------------------- |
|
354 // |
|
355 template <typename T> |
|
356 void CRadioRepositoryManagerImp::DoGetRepositoryValueL( const TUid& aUid, TUint32 aKey, T& aValue ) |
|
357 { |
|
358 CRepository* repository = CRepository::NewLC( aUid ); |
|
359 User::LeaveIfError( repository->Get( aKey, aValue ) ); |
|
360 CleanupStack::PopAndDestroy( repository ); |
|
361 } |
|
362 |
|
363 // --------------------------------------------------------------------------- |
|
364 // Returns the entity's index that matches the supplied arguments. |
|
365 // --------------------------------------------------------------------------- |
|
366 // |
|
367 TInt CRadioRepositoryManagerImp::EntityIndex( const TUid& aUid, TUint32 aKey ) const |
|
368 { |
|
369 TInt idx = KErrNotFound; |
|
370 |
|
371 for ( TInt i = 0; i < iEntities.Count(); i++ ) |
|
372 { |
|
373 CRadioRepositoryEntityBase* entity = iEntities[i]; |
|
374 if ( entity->Uid() == aUid && entity->Key() == aKey ) |
|
375 { |
|
376 idx = i; |
|
377 break; |
|
378 } |
|
379 } |
|
380 |
|
381 return idx; |
|
382 } |
|
383 |
|
384 // --------------------------------------------------------------------------- |
|
385 // SIS installation does not update central repository, this checks that the new keys are in the repository. |
|
386 // --------------------------------------------------------------------------- |
|
387 // |
|
388 void CRadioRepositoryManagerImp::CheckRepositoryKeysL() |
|
389 { |
|
390 // After adding a new cenrep key to radiointernalcrkeys.h, add it also here with a default value |
|
391 /* |
|
392 CRepository* repository = CRepository::NewLC( KVRCRUid ); |
|
393 |
|
394 TInt ret = repository->Create( KVRCRNewValue, TInt( 123 ) ); |
|
395 if ( ret != KErrAlreadyExists ) |
|
396 { |
|
397 User::LeaveIfError( ret ); |
|
398 } |
|
399 |
|
400 CleanupStack::PopAndDestroy( repository ); |
|
401 */ |
|
402 } |
|
403 |
|
404 // --------------------------------------------------------------------------- |
|
405 // Forwards the repository value changes |
|
406 // --------------------------------------------------------------------------- |
|
407 // |
|
408 void CRadioRepositoryManagerImp::HandleRepositoryValueChangeL( const TUid& aUid, |
|
409 TUint32 aKey, TInt aValue, TInt aError ) |
|
410 { |
|
411 for ( TInt i = 0; i < iObservers.Count(); i++ ) |
|
412 { |
|
413 iObservers[i]->HandleRepositoryValueChangeL( aUid, aKey, aValue, aError ); |
|
414 } |
|
415 } |
|
416 |
|
417 // --------------------------------------------------------------------------- |
|
418 // Forwards the repository value changes |
|
419 // --------------------------------------------------------------------------- |
|
420 // |
|
421 void CRadioRepositoryManagerImp::HandleRepositoryValueChangeL( const TUid& aUid, |
|
422 TUint32 aKey, const TReal& aValue, TInt aError ) |
|
423 { |
|
424 for ( TInt i = 0; i < iObservers.Count(); i++ ) |
|
425 { |
|
426 iObservers[i]->HandleRepositoryValueChangeL( aUid, aKey, aValue, aError ); |
|
427 } |
|
428 } |
|
429 |
|
430 // --------------------------------------------------------------------------- |
|
431 // Forwards the repository value changes |
|
432 // --------------------------------------------------------------------------- |
|
433 // |
|
434 void CRadioRepositoryManagerImp::HandleRepositoryValueChangeL( const TUid& aUid, |
|
435 TUint32 aKey, const TDesC8& aValue, TInt aError ) |
|
436 { |
|
437 for ( TInt i = 0; i < iObservers.Count(); i++ ) |
|
438 { |
|
439 iObservers[i]->HandleRepositoryValueChangeL( aUid, aKey, aValue, aError ); |
|
440 } |
|
441 } |
|
442 |
|
443 // --------------------------------------------------------------------------- |
|
444 // Forwards the repository value changes |
|
445 // --------------------------------------------------------------------------- |
|
446 // |
|
447 void CRadioRepositoryManagerImp::HandleRepositoryValueChangeL( const TUid& aUid, |
|
448 TUint32 aKey, const TDesC16& aValue, TInt aError ) |
|
449 { |
|
450 for ( TInt i = 0; i < iObservers.Count(); i++ ) |
|
451 { |
|
452 iObservers[i]->HandleRepositoryValueChangeL( aUid, aKey, aValue, aError ); |
|
453 } |
|
454 } |