|
1 /* |
|
2 * Copyright (c) 2004-2006 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: Central repository proxy. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "CVtEngCRObserverItem.h" |
|
22 #include "CVtEngCRProxy.h" |
|
23 #include "MVtEngCRSettingObserver.h" |
|
24 #include <cvtlogger.h> |
|
25 |
|
26 // CONSTANTS |
|
27 |
|
28 const TInt KVtEngCRProxyObsGranularity = 5; |
|
29 |
|
30 // ============================ MEMBER FUNCTIONS =============================== |
|
31 |
|
32 // ----------------------------------------------------------------------------- |
|
33 // CVtEngCRProxy::CVtEngCRProxy |
|
34 // C++ default constructor can NOT contain any code, that |
|
35 // might leave. |
|
36 // ----------------------------------------------------------------------------- |
|
37 // |
|
38 CVtEngCRProxy::CVtEngCRProxy() : iObserverItems( KVtEngCRProxyObsGranularity ) |
|
39 { |
|
40 } |
|
41 |
|
42 // ----------------------------------------------------------------------------- |
|
43 // CVtEngCRProxy::NewL |
|
44 // Two-phased constructor. |
|
45 // ----------------------------------------------------------------------------- |
|
46 // |
|
47 CVtEngCRProxy* CVtEngCRProxy::NewL( ) |
|
48 { |
|
49 __VTPRINTENTER( "CRProxy.NewL" ) |
|
50 CVtEngCRProxy* self = new( ELeave ) CVtEngCRProxy; |
|
51 __VTPRINTEXIT( "CRProxy.NewL" ) |
|
52 return self; |
|
53 } |
|
54 |
|
55 // ----------------------------------------------------------------------------- |
|
56 // CVtEngCRProxy::~CVtEngCRProxy |
|
57 // Destructor. |
|
58 // ----------------------------------------------------------------------------- |
|
59 // |
|
60 CVtEngCRProxy::~CVtEngCRProxy() |
|
61 { |
|
62 __VTPRINTENTER( "CRProxy.~" ) |
|
63 RemoveAllObservers(); |
|
64 RemoveSessions(); |
|
65 __VTPRINTEXIT( "CRProxy.~" ) |
|
66 } |
|
67 |
|
68 // ----------------------------------------------------------------------------- |
|
69 // CVtEngCRProxy::FindItem |
|
70 // Finds observer item. |
|
71 // ----------------------------------------------------------------------------- |
|
72 // |
|
73 CVtEngCRObserverItem* CVtEngCRProxy::FindItem( |
|
74 const TUid& aUid, |
|
75 const TUint32 aKey, |
|
76 TInt& aIndex ) const |
|
77 { |
|
78 TInt count( iObserverItems.Count() ); |
|
79 CVtEngCRObserverItem* item = NULL; |
|
80 TBool found( EFalse ); |
|
81 while ( count-- && !found ) |
|
82 { |
|
83 item = iObserverItems[ count ]; |
|
84 if ( item->Offer( aUid, aKey ) ) |
|
85 { |
|
86 aIndex = count; |
|
87 found = ETrue; |
|
88 } |
|
89 } |
|
90 |
|
91 // Just NULL the item if not found |
|
92 if ( !found ) |
|
93 { |
|
94 item = NULL; |
|
95 } |
|
96 return item; |
|
97 } |
|
98 |
|
99 // ----------------------------------------------------------------------------- |
|
100 // CVtEngCRProxy::FindItem |
|
101 // Finds observer item. |
|
102 // ----------------------------------------------------------------------------- |
|
103 // |
|
104 CVtEngCRObserverItem* CVtEngCRProxy::FindItem( |
|
105 const TUint32 aKey, TInt& aIndex ) const |
|
106 { |
|
107 TInt count( iObserverItems.Count() ); |
|
108 CVtEngCRObserverItem* item = NULL; |
|
109 if ( aIndex < 0 ) |
|
110 { |
|
111 return NULL; |
|
112 } |
|
113 |
|
114 for ( ; aIndex < count; aIndex++ ) |
|
115 { |
|
116 item = iObserverItems[ aIndex ]; |
|
117 if ( item->Offer( aKey ) ) |
|
118 { |
|
119 break; |
|
120 } |
|
121 } |
|
122 return item; |
|
123 } |
|
124 |
|
125 // ----------------------------------------------------------------------------- |
|
126 // CVtEngCRProxy::RemoveInterested |
|
127 // Removes a cent rep listener. |
|
128 // ----------------------------------------------------------------------------- |
|
129 // |
|
130 void CVtEngCRProxy::RemoveInterested( CVtEngCRObserverItem& aObserver ) |
|
131 { |
|
132 __VTPRINTENTER( "CRProxy.RemoveInterested" ) |
|
133 TInt index ( 0 ); |
|
134 CVtEngCRObserverItem* item = FindItem( aObserver.Uid(), |
|
135 aObserver.Key(), index ); |
|
136 if ( !item ) |
|
137 { |
|
138 // Should not be possible. |
|
139 __VTPRINTEXITR( "CRProxy.RemoveInterested %d", 0 ) |
|
140 return; |
|
141 } |
|
142 |
|
143 delete item; |
|
144 iObserverItems.Remove( index ); |
|
145 __VTPRINTEXITR( "CRProxy.RemoveInterested %d", 1 ) |
|
146 } |
|
147 |
|
148 // ----------------------------------------------------------------------------- |
|
149 // CVtEngCRProxy::NewCRSessionL |
|
150 // New Central repository-uid pairing. |
|
151 // ----------------------------------------------------------------------------- |
|
152 // |
|
153 CVtEngCRProxy::CCRSession* CVtEngCRProxy::NewCRSessionL( TUid aUid ) |
|
154 { |
|
155 __VTPRINTENTER( "CRProxy.NewCRSessionL" ) |
|
156 CRepository* crSession = CRepository::NewL( aUid ); |
|
157 CleanupStack::PushL( crSession ); |
|
158 CCRSession* csSession = new ( ELeave ) CCRSession; |
|
159 csSession->iSession = crSession; |
|
160 csSession->iUid = aUid; |
|
161 CleanupStack::Pop( crSession ); |
|
162 __VTPRINTEXIT( "CRProxy.NewCRSessionL" ) |
|
163 return csSession; |
|
164 } |
|
165 |
|
166 // ----------------------------------------------------------------------------- |
|
167 // CVtEngCRProxy::RegisterInterested |
|
168 // New Central repository listener. |
|
169 // ----------------------------------------------------------------------------- |
|
170 // |
|
171 void CVtEngCRProxy::RegisterInterestedL( CVtEngCRObserverItem* aObserver ) |
|
172 { |
|
173 __VTPRINTENTER( "CRProxy.RegisterInterestedL" ) |
|
174 CRepository* crSession = MapUidToCR( aObserver->Uid() ); |
|
175 CCRSession* csSession = NULL; |
|
176 if( !crSession ) |
|
177 { |
|
178 csSession = NewCRSessionL( aObserver->Uid() ); |
|
179 CleanupStack::PushL( csSession ); |
|
180 crSession = csSession->iSession; |
|
181 iCRSessions.AppendL( csSession ); |
|
182 CleanupStack::Pop( csSession ); |
|
183 } |
|
184 |
|
185 CCenRepNotifyHandler* notifier = |
|
186 CCenRepNotifyHandler::NewL( *aObserver, *crSession, |
|
187 aObserver->Type(), aObserver->Key() ); |
|
188 //notifier ownership transfered |
|
189 aObserver->SetCenRepNotifier( notifier ); |
|
190 notifier->StartListeningL(); |
|
191 iObserverItems.AppendL ( aObserver ); |
|
192 __VTPRINTEXIT( "CRProxy.RegisterInterestedL" ) |
|
193 } |
|
194 |
|
195 // ----------------------------------------------------------------------------- |
|
196 // CVtEngCRProxy::MapUidToCR |
|
197 // Maps a given UID to a Central repository session. |
|
198 // ----------------------------------------------------------------------------- |
|
199 // |
|
200 CRepository* CVtEngCRProxy::MapUidToCR( const TUid aUid ) |
|
201 { |
|
202 __VTPRINTENTER( "CRProxy.Map" ) |
|
203 CCRSession* csSession = NULL; |
|
204 TBool found( EFalse ); |
|
205 TInt count( iCRSessions.Count() ); |
|
206 for ( TInt i = 0 ; i < count; i++ ) |
|
207 { |
|
208 csSession = iCRSessions[ i ]; |
|
209 if ( csSession->iUid == aUid ) |
|
210 { |
|
211 i = count; // break loop |
|
212 found = ETrue; |
|
213 } |
|
214 } |
|
215 CRepository* session = NULL; |
|
216 // Only return something when found. |
|
217 if ( found ) |
|
218 { |
|
219 session = csSession->iSession; |
|
220 } |
|
221 __VTPRINTEXITR( "CRProxy.Map %d", (TInt) session ) |
|
222 return session; |
|
223 } |
|
224 |
|
225 // ----------------------------------------------------------------------------- |
|
226 // CVtEngCRProxy::RemoveAllObservers |
|
227 // All observers off they go. |
|
228 // ----------------------------------------------------------------------------- |
|
229 // |
|
230 void CVtEngCRProxy::RemoveAllObservers() |
|
231 { |
|
232 __VTPRINTENTER( "CRProxy.RemoveAll" ) |
|
233 iObserverItems.ResetAndDestroy(); |
|
234 iObserverItems.Close(); |
|
235 __VTPRINTEXIT( "CRProxy.RemoveAll" ) |
|
236 } |
|
237 |
|
238 // ----------------------------------------------------------------------------- |
|
239 // CVtEngCRProxy::RemoveSessions |
|
240 // Removes all Central repository sessions. |
|
241 // ----------------------------------------------------------------------------- |
|
242 // |
|
243 void CVtEngCRProxy::RemoveSessions() |
|
244 { |
|
245 __VTPRINTENTER( "CRProxy.RemoveAllS" ) |
|
246 iCRSessions.ResetAndDestroy(); |
|
247 iCRSessions.Close(); |
|
248 __VTPRINTEXIT( "CRProxy.RemoveAllS" ) |
|
249 } |
|
250 |
|
251 // ----------------------------------------------------------------------------- |
|
252 // CVtEngCRProxy::GetSession |
|
253 // Gets an existing or a new Central repository session for a UID. |
|
254 // ----------------------------------------------------------------------------- |
|
255 // |
|
256 TInt CVtEngCRProxy::GetSessionL( const TUid aUid, CRepository*& crSession ) |
|
257 { |
|
258 TInt err( KErrNone ); |
|
259 crSession = MapUidToCR( aUid ); |
|
260 if ( !crSession ) |
|
261 { |
|
262 CCRSession* session = NULL; |
|
263 session = NewCRSessionL( aUid ); |
|
264 if ( session ) |
|
265 { |
|
266 CleanupStack::PushL( session ); |
|
267 iCRSessions.AppendL( session ); |
|
268 CleanupStack::Pop( session ); |
|
269 crSession = session->iSession; |
|
270 } |
|
271 else |
|
272 { |
|
273 err = KErrNotFound; |
|
274 } |
|
275 } |
|
276 return err; |
|
277 } |
|
278 |
|
279 // ----------------------------------------------------------------------------- |
|
280 // CVtEngCRProxy::Get |
|
281 // Gets integer value. |
|
282 // ----------------------------------------------------------------------------- |
|
283 // |
|
284 TInt CVtEngCRProxy::Get( const TUid aUid, const TUint32 aId, TInt& aVal ) |
|
285 { |
|
286 __VTPRINTENTER( "CRProxy.GetInt" ) |
|
287 __VTPRINT3( DEBUG_GEN, "UID=%d,key=%d", aUid.iUid, (TInt) aId ); |
|
288 |
|
289 CRepository* crSession = NULL; |
|
290 TRAPD( err, GetSessionL( aUid, crSession ) ); |
|
291 if ( err == KErrNone ) |
|
292 { |
|
293 err = crSession->Get( aId, aVal ); |
|
294 } |
|
295 __VTPRINTEXITR( "CRProxy.GetInt %d", err ) |
|
296 return err; |
|
297 } |
|
298 |
|
299 // ----------------------------------------------------------------------------- |
|
300 // CVtEngCRProxy::Get |
|
301 // Gets real value. |
|
302 // ----------------------------------------------------------------------------- |
|
303 // |
|
304 TInt CVtEngCRProxy::Get( const TUid aUid, const TUint32 aId, TReal& aVal ) |
|
305 { |
|
306 __VTPRINTENTER( "CRProxy.GetReal" ) |
|
307 __VTPRINT3( DEBUG_GEN, "UID=%d,key=%d", aUid.iUid, (TInt) aId ); |
|
308 CRepository* crSession = NULL; |
|
309 TRAPD( err, GetSessionL( aUid, crSession ) ); |
|
310 if ( err == KErrNone ) |
|
311 { |
|
312 err = crSession->Get( aId, aVal ); |
|
313 } |
|
314 __VTPRINTEXITR( "CRProxy.GetR %d", err ) |
|
315 return err; |
|
316 } |
|
317 |
|
318 // ----------------------------------------------------------------------------- |
|
319 // CVtEngCRProxy::Get |
|
320 // Gets binary value. |
|
321 // ----------------------------------------------------------------------------- |
|
322 // |
|
323 TInt CVtEngCRProxy::Get( const TUid aUid, const TUint32 aId, TDes8& aVal ) |
|
324 { |
|
325 __VTPRINTENTER( "CRProxy.GetD8" ) |
|
326 __VTPRINT3( DEBUG_GEN, "UID=%d,key=%d", aUid.iUid, (TInt) aId ); |
|
327 CRepository* crSession = NULL; |
|
328 TRAPD( err, GetSessionL( aUid, crSession ) ); |
|
329 if ( err == KErrNone ) |
|
330 { |
|
331 err = crSession->Get( aId, aVal ); |
|
332 } |
|
333 __VTPRINTEXITR( "CRProxy.GetD8 %d", err ) |
|
334 return err; |
|
335 } |
|
336 |
|
337 // ----------------------------------------------------------------------------- |
|
338 // CVtEngCRProxy::Get |
|
339 // Gets string value. |
|
340 // ----------------------------------------------------------------------------- |
|
341 // |
|
342 TInt CVtEngCRProxy::Get( const TUid aUid, const TUint32 aId, TDes16& aVal ) |
|
343 { |
|
344 __VTPRINTENTER( "CRProxy.GetD16" ) |
|
345 __VTPRINT3( DEBUG_GEN, "UID=%d,key=%d", aUid.iUid, (TInt) aId ); |
|
346 CRepository* crSession = NULL; |
|
347 TRAPD( err, GetSessionL( aUid, crSession ) ); |
|
348 if ( err == KErrNone ) |
|
349 { |
|
350 err = crSession->Get( aId, aVal ); |
|
351 } |
|
352 __VTPRINTEXITR( "CRProxy.GetD16 %d", err ) |
|
353 return err; |
|
354 } |
|
355 |
|
356 // ----------------------------------------------------------------------------- |
|
357 // CVtEngCRProxy::Set |
|
358 // Sets integer value to Central Repository. |
|
359 // ----------------------------------------------------------------------------- |
|
360 // |
|
361 TInt CVtEngCRProxy::Set( const TUid aUid, const TUint32 aId, TInt aVal ) |
|
362 { |
|
363 __VTPRINTENTER( "CRProxy.SetInt" ) |
|
364 CRepository* crSession = NULL; |
|
365 TRAPD( err, GetSessionL( aUid, crSession ) ); |
|
366 if ( err == KErrNone ) |
|
367 { |
|
368 err = crSession->Set( aId, aVal ); |
|
369 } |
|
370 __VTPRINTEXITR( "CRProxy.SetInt %d", err ) |
|
371 return err; |
|
372 } |
|
373 |
|
374 // ----------------------------------------------------------------------------- |
|
375 // CVtEngCRProxy::Set |
|
376 // Sets real value to Central Repository. |
|
377 // ----------------------------------------------------------------------------- |
|
378 // |
|
379 TInt CVtEngCRProxy::Set( const TUid aUid, const TUint32 aId, const TReal& aVal ) |
|
380 { |
|
381 __VTPRINTENTER( "CRProxy.SetR" ) |
|
382 CRepository* crSession = NULL; |
|
383 TRAPD( err, GetSessionL( aUid, crSession ) ); |
|
384 if ( err == KErrNone ) |
|
385 { |
|
386 err = crSession->Set( aId, aVal ); |
|
387 } |
|
388 __VTPRINTEXITR( "CRProxy.SetR %d", err ) |
|
389 return err; |
|
390 } |
|
391 |
|
392 // ----------------------------------------------------------------------------- |
|
393 // CVtEngCRProxy::Set |
|
394 // Sets binary value to Central Repository. |
|
395 // ----------------------------------------------------------------------------- |
|
396 // |
|
397 TInt CVtEngCRProxy::Set( const TUid aUid, const TUint32 aId, const TDesC8& aVal ) |
|
398 { |
|
399 __VTPRINTENTER( "CRProxy.SetD8" ) |
|
400 CRepository* crSession = NULL; |
|
401 TRAPD( err, GetSessionL( aUid, crSession ) ); |
|
402 if ( err == KErrNone ) |
|
403 { |
|
404 err = crSession->Set( aId, aVal ); |
|
405 } |
|
406 __VTPRINTEXITR( "CRProxy.SetD8 %d", err ) |
|
407 return err; |
|
408 } |
|
409 |
|
410 // ----------------------------------------------------------------------------- |
|
411 // CVtEngCRProxy::Set |
|
412 // Sets string value to Central Repository. |
|
413 // ----------------------------------------------------------------------------- |
|
414 // |
|
415 TInt CVtEngCRProxy::Set( |
|
416 const TUid aUid, const TUint32 aId, const TDesC16& aVal ) |
|
417 { |
|
418 __VTPRINTENTER( "CRProxy.SetD16" ) |
|
419 CRepository* crSession = NULL; |
|
420 TRAPD( err, GetSessionL( aUid, crSession ) ); |
|
421 if ( err == KErrNone ) |
|
422 { |
|
423 err = crSession->Set( aId, aVal ); |
|
424 } |
|
425 __VTPRINTEXITR( "CRProxy.SetD16 %d", err ) |
|
426 return err; |
|
427 } |
|
428 |
|
429 // ----------------------------------------------------------------------------- |
|
430 // CVtEngCRProxy::CCRSession::~CCRSession |
|
431 // Destructor. |
|
432 // ----------------------------------------------------------------------------- |
|
433 // |
|
434 CVtEngCRProxy::CCRSession::~CCRSession() |
|
435 { |
|
436 __VTPRINTENTER( "CRProxy.~" ) |
|
437 delete iSession; |
|
438 __VTPRINTEXIT( "CRProxy.~" ) |
|
439 } |
|
440 |
|
441 // end of file |