|
1 /* |
|
2 * Copyright (c) 2004 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 the License "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 * Implementation of class RFavouritesDb |
|
16 * |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 // INCLUDE FILES |
|
22 |
|
23 #include <s32std.h> |
|
24 #include "FavouritesDb.h" |
|
25 #include "FavouritesMsg.h" |
|
26 #include "FavouritesBuf.h" |
|
27 #include "FavouritesFilter.h" |
|
28 #include "FavouritesItemImpl.h" |
|
29 #include "FavouritesItemList.h" |
|
30 #include "FavouritesItemData.h" |
|
31 #include "FavouritesUtil.h" |
|
32 #include "UidMap.h" |
|
33 #include "FavouritesLogger.h" |
|
34 #include <rfsApMapper.h> |
|
35 |
|
36 // CONSTANTS |
|
37 |
|
38 /// Granularity of AP map in RFS. |
|
39 LOCAL_D const TInt KApMapGranularity = 4; |
|
40 |
|
41 // ================= MEMBER FUNCTIONS ======================= |
|
42 |
|
43 // --------------------------------------------------------- |
|
44 // RFavouritesDb::Open |
|
45 // --------------------------------------------------------- |
|
46 // |
|
47 EXPORT_C TInt RFavouritesDb::Open |
|
48 ( RFavouritesSession& aSess, const TDesC& aName ) |
|
49 { |
|
50 __ASSERT_DEBUG( !iHandle, FavouritesPanic( EFavouritesAlreadyOpen ) ); |
|
51 TInt ret = aSess.SendReceive( EFavengOpenDatabase, TIpcArgs( &aName ) ); |
|
52 if ( ret > 0 ) |
|
53 { |
|
54 iSess = aSess; |
|
55 iHandle = ret; |
|
56 ret = KErrNone; |
|
57 } |
|
58 return ret; |
|
59 } |
|
60 |
|
61 // --------------------------------------------------------- |
|
62 // RFavouritesDb::Version |
|
63 // --------------------------------------------------------- |
|
64 // |
|
65 EXPORT_C TVersion RFavouritesDb::Version() const |
|
66 { |
|
67 return RFavouritesSession::Version(); |
|
68 } |
|
69 |
|
70 // --------------------------------------------------------- |
|
71 // RFavouritesDb::IsDamaged |
|
72 // --------------------------------------------------------- |
|
73 // |
|
74 EXPORT_C TInt RFavouritesDb::IsDamaged( TBool& aIsDamaged ) |
|
75 { |
|
76 TInt ret = SendReceive( EFavengIsDamaged ); |
|
77 if ( ret >= 0 ) |
|
78 { |
|
79 aIsDamaged = ret; |
|
80 ret = KErrNone; |
|
81 } |
|
82 return ret; |
|
83 } |
|
84 |
|
85 // --------------------------------------------------------- |
|
86 // RFavouritesDb::Recover |
|
87 // --------------------------------------------------------- |
|
88 // |
|
89 EXPORT_C TInt RFavouritesDb::Recover() |
|
90 { |
|
91 return SendReceive( EFavengRecover ); |
|
92 } |
|
93 |
|
94 // --------------------------------------------------------- |
|
95 // RFavouritesDb::Compact |
|
96 // --------------------------------------------------------- |
|
97 // |
|
98 EXPORT_C TInt RFavouritesDb::Compact() |
|
99 { |
|
100 return SendReceive( EFavengCompact ); |
|
101 } |
|
102 |
|
103 // --------------------------------------------------------- |
|
104 // RFavouritesDb::Size |
|
105 // --------------------------------------------------------- |
|
106 // |
|
107 EXPORT_C TInt RFavouritesDb::Size( RDbDatabase::TSize& aSize ) const |
|
108 { |
|
109 TPckg<RDbDatabase::TSize> size( aSize ); |
|
110 return SendReceive( EFavengSize, TIpcArgs( &size ) ); |
|
111 } |
|
112 |
|
113 // --------------------------------------------------------- |
|
114 // RFavouritesDb::UpdateStats |
|
115 // --------------------------------------------------------- |
|
116 // |
|
117 EXPORT_C TInt RFavouritesDb::UpdateStats() |
|
118 { |
|
119 return SendReceive( EFavengUpdateStats ); |
|
120 } |
|
121 |
|
122 // --------------------------------------------------------- |
|
123 // RFavouritesDb::Begin |
|
124 // --------------------------------------------------------- |
|
125 // |
|
126 EXPORT_C TInt RFavouritesDb::Begin( TBool aWrite /*=EFalse*/ ) |
|
127 { |
|
128 return SendReceive( EFavengBegin, TIpcArgs( aWrite ) ); |
|
129 } |
|
130 |
|
131 // --------------------------------------------------------- |
|
132 // RFavouritesDb::Commit |
|
133 // --------------------------------------------------------- |
|
134 // |
|
135 EXPORT_C TInt RFavouritesDb::Commit() |
|
136 { |
|
137 return SendReceive( EFavengCommit ); |
|
138 } |
|
139 |
|
140 // --------------------------------------------------------- |
|
141 // RFavouritesDb::Rollback |
|
142 // --------------------------------------------------------- |
|
143 // |
|
144 EXPORT_C void RFavouritesDb::Rollback() |
|
145 { |
|
146 (void) SendReceive( EFavengRollback ); |
|
147 } |
|
148 |
|
149 // --------------------------------------------------------- |
|
150 // RFavouritesDb::CleanupRollbackPushL |
|
151 // --------------------------------------------------------- |
|
152 // |
|
153 EXPORT_C void RFavouritesDb::CleanupRollbackPushL() |
|
154 { |
|
155 CleanupStack::PushL( TCleanupItem( StaticRollback, this ) ); |
|
156 } |
|
157 |
|
158 // --------------------------------------------------------- |
|
159 // RFavouritesDb::Get |
|
160 // --------------------------------------------------------- |
|
161 // |
|
162 EXPORT_C TInt RFavouritesDb::Get( TInt aUid, CFavouritesItem& aItem ) |
|
163 { |
|
164 TInt err; |
|
165 |
|
166 // Special items which are creted in memory dynamically, |
|
167 // are filled up here at the client side. |
|
168 if( aUid <= KFavouritesStartPageUid ) |
|
169 { |
|
170 switch( aUid ) |
|
171 { |
|
172 case KFavouritesStartPageUid: |
|
173 { |
|
174 aItem.iImpl->SetUid( KFavouritesStartPageUid ); |
|
175 return KErrNone; |
|
176 } |
|
177 case KFavouritesAdaptiveItemsFolderUid: |
|
178 { |
|
179 aItem.iImpl->SetUid( KFavouritesAdaptiveItemsFolderUid ); |
|
180 aItem.SetType( CFavouritesItem::EFolder ); |
|
181 aItem.SetParentFolder( KFavouritesRootUid ); |
|
182 return KErrNone; |
|
183 } |
|
184 case KFavouritesRSSItemUid: |
|
185 { |
|
186 aItem.iImpl->SetUid( KFavouritesRSSItemUid ); |
|
187 aItem.SetParentFolder( KFavouritesRootUid ); |
|
188 return KErrNone; |
|
189 } |
|
190 case KFavouritesSavedDeckItemUid: |
|
191 { |
|
192 aItem.iImpl->SetUid( KFavouritesSavedDeckItemUid ); |
|
193 aItem.SetType( CFavouritesItem::EFolder ); |
|
194 aItem.SetParentFolder( KFavouritesRootUid ); |
|
195 return KErrNone; |
|
196 } |
|
197 default: |
|
198 { |
|
199 break; |
|
200 } |
|
201 } |
|
202 } |
|
203 |
|
204 // Other UIDs are handled at the server side. |
|
205 RFavouritesBuf buf; |
|
206 TIpcArgs args( aUid ); |
|
207 err = buf.Open( *this, EFavengGet, args ); |
|
208 if( !err ) |
|
209 { |
|
210 RReadStream stream( &buf ); |
|
211 TRAP( err, aItem.InternalizeL( stream ) ); |
|
212 buf.Close(); |
|
213 } |
|
214 return err; |
|
215 } |
|
216 |
|
217 // --------------------------------------------------------- |
|
218 // RFavouritesDb::GetAll |
|
219 // --------------------------------------------------------- |
|
220 // |
|
221 EXPORT_C TInt RFavouritesDb::GetAll |
|
222 ( |
|
223 CFavouritesItemList& aItemList, |
|
224 TInt aParentFolderFilter /*=KFavouritesNullUid*/, |
|
225 CFavouritesItem::TType aTypeFilter /*=CFavouritesItem::ENone*/, |
|
226 const TDesC* aNameFilter /*=NULL*/, |
|
227 TInt32 aContextIdFilter /*=KFavouritesNullContextId*/ |
|
228 ) |
|
229 { |
|
230 RFavouritesBuf buf; |
|
231 TFavouritesFilter filter |
|
232 ( aParentFolderFilter, aTypeFilter, aNameFilter, aContextIdFilter ); |
|
233 TPckg<TFavouritesFilter> filterPckg( filter ); |
|
234 TIpcArgs args( &filterPckg ); |
|
235 TInt err = buf.Open( *this, EFavengGetAll, args ); |
|
236 if( !err ) |
|
237 { |
|
238 RReadStream stream( &buf ); |
|
239 TRAP( err, aItemList.InternalizeL( stream ) ); |
|
240 buf.Close(); |
|
241 } |
|
242 return err; |
|
243 } |
|
244 |
|
245 // --------------------------------------------------------- |
|
246 // RFavouritesDb::PreferredUid |
|
247 // --------------------------------------------------------- |
|
248 // |
|
249 EXPORT_C TInt RFavouritesDb::PreferredUid( TInt aFolder, TInt& aPreferredUid ) |
|
250 { |
|
251 TPckg<TInt> prefUid( aPreferredUid ); |
|
252 return SendReceive( EFavengPreferredUid, TIpcArgs( aFolder, &prefUid ) ); |
|
253 } |
|
254 |
|
255 // --------------------------------------------------------- |
|
256 // RFavouritesDb::GetUids |
|
257 // --------------------------------------------------------- |
|
258 // |
|
259 EXPORT_C TInt RFavouritesDb::GetUids |
|
260 ( |
|
261 CArrayFix<TInt>& aUids, |
|
262 TInt aParentFolderFilter /*=KFavouritesNullUid*/, |
|
263 CFavouritesItem::TType aTypeFilter /*=CFavouritesItem::ENone*/, |
|
264 const TDesC* aNameFilter /*=NULL*/, |
|
265 TInt32 aContextIdFilter /*=KFavouritesNullContextId*/ |
|
266 ) |
|
267 { |
|
268 RFavouritesBuf buf; |
|
269 TFavouritesFilter filter |
|
270 ( aParentFolderFilter, aTypeFilter, aNameFilter, aContextIdFilter ); |
|
271 TPckg<TFavouritesFilter> filterPckg( filter ); |
|
272 TIpcArgs args( &filterPckg ); |
|
273 TInt err = buf.Open( *this, EFavengGetUids, args ); |
|
274 if( !err ) |
|
275 { |
|
276 RReadStream stream( &buf ); |
|
277 TRAP( err, FavouritesUtil::InternalizeL( aUids, stream ) ); |
|
278 buf.Close(); |
|
279 } |
|
280 return err; |
|
281 } |
|
282 |
|
283 // --------------------------------------------------------- |
|
284 // RFavouritesDb::Delete |
|
285 // --------------------------------------------------------- |
|
286 // |
|
287 EXPORT_C TInt RFavouritesDb::Delete( TInt aUid ) |
|
288 { |
|
289 return SendReceive( EFavengDelete, TIpcArgs( aUid ) ); |
|
290 } |
|
291 |
|
292 // --------------------------------------------------------- |
|
293 // RFavouritesDb::Update |
|
294 // --------------------------------------------------------- |
|
295 // |
|
296 EXPORT_C TInt RFavouritesDb::Update |
|
297 ( CFavouritesItem& aItem, TInt aUid, TBool aAutoRename ) |
|
298 { |
|
299 RFavouritesBuf buf; |
|
300 TInt err = buf.Open( iSess ); |
|
301 if ( !err ) |
|
302 { |
|
303 RWriteStream stream( &buf ); |
|
304 TRAP( err, aItem.ExternalizeL( stream ) ); |
|
305 if ( !err ) |
|
306 { |
|
307 TRAP( err, stream.CommitL() ); |
|
308 if ( !err ) |
|
309 { |
|
310 err = SendReceive( EFavengUpdate, TIpcArgs |
|
311 ( buf.Handle(), aUid, aAutoRename ) ); |
|
312 if ( !err ) |
|
313 { |
|
314 RReadStream readStream( &buf ); |
|
315 TRAP( err, aItem.iImpl->InternalizeUpdateDeltaL |
|
316 ( readStream ) ); |
|
317 } |
|
318 } |
|
319 } |
|
320 buf.Close(); |
|
321 } |
|
322 return err; |
|
323 } |
|
324 |
|
325 // --------------------------------------------------------- |
|
326 // RFavouritesDb::Add |
|
327 // --------------------------------------------------------- |
|
328 // |
|
329 EXPORT_C TInt RFavouritesDb::Add( CFavouritesItem& aItem, TBool aAutoRename ) |
|
330 { |
|
331 RFavouritesBuf buf; |
|
332 TInt err = buf.Open( iSess ); |
|
333 if ( !err ) |
|
334 { |
|
335 RWriteStream stream( &buf ); |
|
336 TRAP( err, aItem.ExternalizeL( stream ) ); |
|
337 if ( !err ) |
|
338 { |
|
339 TRAP( err, stream.CommitL() ); |
|
340 if ( !err ) |
|
341 { |
|
342 err = SendReceive( EFavengAdd, TIpcArgs |
|
343 ( buf.Handle(), aAutoRename ) ); |
|
344 if ( !err ) |
|
345 { |
|
346 RReadStream readStream( &buf ); |
|
347 TRAP( err, aItem.iImpl->InternalizeUpdateDeltaL |
|
348 ( readStream ) ); |
|
349 } |
|
350 } |
|
351 } |
|
352 buf.Close(); |
|
353 } |
|
354 return err; |
|
355 } |
|
356 |
|
357 // --------------------------------------------------------- |
|
358 // RFavouritesDb::SetHomepage |
|
359 // --------------------------------------------------------- |
|
360 // |
|
361 EXPORT_C TInt RFavouritesDb::SetHomepage( CFavouritesItem& aItem ) |
|
362 { |
|
363 return SetSpecialItem( aItem, KFavouritesHomepageUid ); |
|
364 } |
|
365 |
|
366 // --------------------------------------------------------- |
|
367 // RFavouritesDb::SetLastVisited |
|
368 // --------------------------------------------------------- |
|
369 // |
|
370 EXPORT_C TInt RFavouritesDb::SetLastVisited( CFavouritesItem& aItem ) |
|
371 { |
|
372 return SetSpecialItem( aItem, KFavouritesLastVisitedUid ); |
|
373 } |
|
374 |
|
375 // --------------------------------------------------------- |
|
376 // RFavouritesDb::SetFactoryItem |
|
377 // --------------------------------------------------------- |
|
378 // |
|
379 EXPORT_C TInt RFavouritesDb::SetFactoryItem( TInt aUid, TBool aFactoryItem ) |
|
380 { |
|
381 return SendReceive |
|
382 ( EFavengSetFactoryItem, TIpcArgs( aUid, aFactoryItem ) ); |
|
383 } |
|
384 |
|
385 // --------------------------------------------------------- |
|
386 // RFavouritesDb::SetReadOnly |
|
387 // --------------------------------------------------------- |
|
388 // |
|
389 EXPORT_C TInt RFavouritesDb::SetReadOnly( TInt aUid, TBool aReadOnly ) |
|
390 { |
|
391 return SendReceive( EFavengSetReadOnly, TIpcArgs( aUid, aReadOnly ) ); |
|
392 } |
|
393 |
|
394 // --------------------------------------------------------- |
|
395 // RFavouritesDb::SetModified |
|
396 // --------------------------------------------------------- |
|
397 // |
|
398 EXPORT_C TInt RFavouritesDb::SetModified( TInt aUid, TTime aModified ) |
|
399 { |
|
400 return SendReceive( EFavengSetModified, TIpcArgs |
|
401 ( aUid, I64HIGH( aModified.Int64() ), I64LOW( aModified.Int64() ) ) ); |
|
402 } |
|
403 |
|
404 // --------------------------------------------------------- |
|
405 // RFavouritesDb::SetPreferredUid |
|
406 // --------------------------------------------------------- |
|
407 // |
|
408 EXPORT_C TInt RFavouritesDb::SetPreferredUid( TInt aFolder, TInt aUid ) |
|
409 { |
|
410 return SendReceive( EFavengSetPreferredUid, TIpcArgs( aFolder, aUid ) ); |
|
411 } |
|
412 |
|
413 // --------------------------------------------------------- |
|
414 // RFavouritesDb::ItemExists |
|
415 // --------------------------------------------------------- |
|
416 // |
|
417 EXPORT_C TInt RFavouritesDb::ItemExists( TInt aUid, TBool& aItemExists ) |
|
418 { |
|
419 TInt ret = SendReceive( EFavengItemExists, TIpcArgs( aUid ) ); |
|
420 if ( ret >= 0 ) |
|
421 { |
|
422 aItemExists = ret; |
|
423 ret = KErrNone; |
|
424 } |
|
425 return ret; |
|
426 } |
|
427 |
|
428 // --------------------------------------------------------- |
|
429 // RFavouritesDb::FolderExists |
|
430 // --------------------------------------------------------- |
|
431 // |
|
432 EXPORT_C TInt RFavouritesDb::FolderExists( TInt aFolder, TBool& aFolderExists ) |
|
433 { |
|
434 TInt ret = SendReceive( EFavengFolderExists, TIpcArgs( aFolder ) ); |
|
435 if ( ret >= 0 ) |
|
436 { |
|
437 aFolderExists = ret; |
|
438 ret = KErrNone; |
|
439 } |
|
440 return ret; |
|
441 } |
|
442 |
|
443 // --------------------------------------------------------- |
|
444 // RFavouritesDb::Count |
|
445 // --------------------------------------------------------- |
|
446 // |
|
447 EXPORT_C TInt RFavouritesDb::Count |
|
448 ( |
|
449 TInt& aCount, |
|
450 TInt aParentFolderFilter /*=KFavouritesNullUid*/, |
|
451 CFavouritesItem::TType aTypeFilter /*=CFavouritesItem::ENone*/, |
|
452 const TDesC* aNameFilter /*=NULL*/, |
|
453 TInt32 aContextIdFilter /*=KFavouritesNullContextId*/ |
|
454 ) |
|
455 { |
|
456 TFavouritesFilter filter |
|
457 ( aParentFolderFilter, aTypeFilter, aNameFilter, aContextIdFilter ); |
|
458 TPckg<TFavouritesFilter> filterPckg( filter ); |
|
459 TInt ret = SendReceive( EFavengCount, TIpcArgs( &filterPckg ) ); |
|
460 if ( ret >= 0 ) |
|
461 { |
|
462 aCount = ret; |
|
463 ret = KErrNone; |
|
464 } |
|
465 return ret; |
|
466 } |
|
467 |
|
468 // --------------------------------------------------------- |
|
469 // RFavouritesDb::SetData |
|
470 // --------------------------------------------------------- |
|
471 // |
|
472 EXPORT_C TInt RFavouritesDb::SetData |
|
473 ( TInt aUid, const MFavouritesItemData& aData ) |
|
474 { |
|
475 return SetData( EFavengSetData, aUid, aData ); |
|
476 } |
|
477 |
|
478 // --------------------------------------------------------- |
|
479 // RFavouritesDb::GetData |
|
480 // --------------------------------------------------------- |
|
481 // |
|
482 EXPORT_C TInt RFavouritesDb::GetData( TInt aUid, MFavouritesItemData& aData ) |
|
483 { |
|
484 return GetData( EFavengGetData, aUid, aData ); |
|
485 } |
|
486 |
|
487 // --------------------------------------------------------- |
|
488 // RFavouritesDb::SetBrowserData |
|
489 // --------------------------------------------------------- |
|
490 // |
|
491 EXPORT_C TInt RFavouritesDb::SetBrowserData |
|
492 ( TInt aUid, const MFavouritesItemData& aData ) |
|
493 { |
|
494 return SetData( EFavengSetBrowserData, aUid, aData ); |
|
495 } |
|
496 |
|
497 // --------------------------------------------------------- |
|
498 // RFavouritesDb::GetBrowserData |
|
499 // --------------------------------------------------------- |
|
500 // |
|
501 EXPORT_C TInt RFavouritesDb::GetBrowserData |
|
502 ( TInt aUid, MFavouritesItemData& aData ) |
|
503 { |
|
504 return GetData( EFavengGetBrowserData, aUid, aData ); |
|
505 } |
|
506 |
|
507 // --------------------------------------------------------- |
|
508 // RFavouritesDb::MakeUniqueName |
|
509 // --------------------------------------------------------- |
|
510 // |
|
511 EXPORT_C TInt RFavouritesDb::MakeUniqueName( TDes& aName, TInt aFolder ) |
|
512 { |
|
513 __ASSERT_ALWAYS( aName.MaxLength() >= Min\ |
|
514 ( aName.Length() + KFavouritesMaxPostfix, KFavouritesMaxName ), \ |
|
515 FavouritesPanic( EFavouritesBufferTooSmall ) ); |
|
516 TInt ret = SendReceive( EFavengMakeUniqueName, |
|
517 TIpcArgs( &aName, aName.Length(), aFolder ) ); |
|
518 if ( ret >= 0 ) |
|
519 { |
|
520 __ASSERT_DEBUG( aName.MaxLength() >= ret, \ |
|
521 FavouritesPanic( EFavouritesInternal ) ); |
|
522 aName.SetLength( ret ); |
|
523 ret = KErrNone; |
|
524 } |
|
525 return ret; |
|
526 } |
|
527 |
|
528 // --------------------------------------------------------- |
|
529 // RFavouritesDb::MakeUniqueName |
|
530 // --------------------------------------------------------- |
|
531 // |
|
532 EXPORT_C TInt RFavouritesDb::MakeUniqueName( CFavouritesItem& aItem ) |
|
533 { |
|
534 TBuf<KFavouritesMaxName> name = aItem.Name(); |
|
535 TInt err = MakeUniqueName( name, aItem.ParentFolder() ); |
|
536 if ( !err ) |
|
537 { |
|
538 TRAP( err, aItem.SetNameL( name ) ); |
|
539 } |
|
540 return err; |
|
541 } |
|
542 |
|
543 // --------------------------------------------------------- |
|
544 // RFavouritesDb::CreateStartPageItemL |
|
545 // --------------------------------------------------------- |
|
546 // |
|
547 EXPORT_C CFavouritesItem* RFavouritesDb::CreateStartPageItemL() |
|
548 { |
|
549 CFavouritesItem* item = CFavouritesItem::NewL(); |
|
550 item->iImpl->SetUid( KFavouritesStartPageUid ); |
|
551 return item; |
|
552 } |
|
553 |
|
554 // --------------------------------------------------------- |
|
555 // RFavouritesDb::CreateAdaptiveItemsFolder |
|
556 // --------------------------------------------------------- |
|
557 // |
|
558 EXPORT_C CFavouritesItem* RFavouritesDb::CreateAdaptiveItemsFolderL() |
|
559 { |
|
560 CFavouritesItem* item = CFavouritesItem::NewL(); |
|
561 item->iImpl->SetUid( KFavouritesAdaptiveItemsFolderUid ); |
|
562 item->SetType( CFavouritesItem::EFolder ); |
|
563 item->SetParentFolder( KFavouritesRootUid ); |
|
564 return item; |
|
565 } |
|
566 |
|
567 // --------------------------------------------------------- |
|
568 // RFavouritesDb::DeleteFile |
|
569 // --------------------------------------------------------- |
|
570 // |
|
571 EXPORT_C TInt RFavouritesDb::DeleteFile( TInt aUid ) |
|
572 { |
|
573 return SendReceive( EFavengFileDelete, TIpcArgs( aUid ) ); |
|
574 } |
|
575 |
|
576 |
|
577 |
|
578 // --------------------------------------------------------- |
|
579 // RFavouritesDb::RestoreFactorySettingsL |
|
580 // --------------------------------------------------------- |
|
581 // |
|
582 EXPORT_C void RFavouritesDb::RestoreFactorySettingsL |
|
583 ( const TDesC& aName, const TDesC& aReferenceDbPath, MRfsApMapper& aApMapper ) |
|
584 { |
|
585 FLOG(( _L("rstore:FavouritesDb.cpp RFavouritesDb::RestoreFactorySettingsL with param") )); |
|
586 |
|
587 RFavouritesSession sess; |
|
588 RFavouritesDb db; |
|
589 User::LeaveIfError( sess.Connect() ); |
|
590 CleanupClosePushL<RFavouritesSession>( sess ); |
|
591 User::LeaveIfError( db.Open( sess, aName ) ); |
|
592 CleanupClosePushL<RFavouritesDb>( db ); |
|
593 db.DoRestoreFactorySettingsL( aReferenceDbPath, aApMapper ); |
|
594 CleanupStack::PopAndDestroy( 2 ); // Close db, close session |
|
595 } |
|
596 |
|
597 // --------------------------------------------------------- |
|
598 // RFavouritesDb::SetSpecialItem |
|
599 // --------------------------------------------------------- |
|
600 // |
|
601 TInt RFavouritesDb::SetSpecialItem( CFavouritesItem& aItem, TInt aUid ) |
|
602 { |
|
603 RFavouritesBuf buf; |
|
604 TInt err = buf.Open( iSess ); |
|
605 if ( !err ) |
|
606 { |
|
607 RWriteStream stream( &buf ); |
|
608 TRAP( err, aItem.ExternalizeL( stream ) ); |
|
609 if ( !err ) |
|
610 { |
|
611 TRAP( err, stream.CommitL() ); |
|
612 if ( !err ) |
|
613 { |
|
614 err = SendReceive( EFavengSetSpecialItem, TIpcArgs |
|
615 ( buf.Handle(), aUid ) ); |
|
616 if ( !err ) |
|
617 { |
|
618 RReadStream readStream( &buf ); |
|
619 TRAP( err, aItem.iImpl->InternalizeUpdateDeltaL |
|
620 ( readStream ) ); |
|
621 } |
|
622 } |
|
623 } |
|
624 buf.Close(); |
|
625 } |
|
626 return err; |
|
627 } |
|
628 |
|
629 // --------------------------------------------------------- |
|
630 // RFavouritesDb::SetData |
|
631 // --------------------------------------------------------- |
|
632 // |
|
633 TInt RFavouritesDb::SetData |
|
634 ( TInt aFunction, TInt aUid, const MFavouritesItemData& aData ) |
|
635 { |
|
636 RFavouritesBuf buf; |
|
637 TInt err = buf.Open( iSess ); |
|
638 if ( !err ) |
|
639 { |
|
640 RWriteStream stream( &buf ); |
|
641 TRAP( err, aData.ExternalizeL( stream ) ); |
|
642 if ( !err ) |
|
643 { |
|
644 TRAP( err, stream.CommitL() ); |
|
645 if ( !err ) |
|
646 { |
|
647 err = SendReceive( aFunction, TIpcArgs |
|
648 ( buf.Handle(), aUid ) ); |
|
649 } |
|
650 } |
|
651 buf.Close(); |
|
652 } |
|
653 return err; |
|
654 } |
|
655 |
|
656 // --------------------------------------------------------- |
|
657 // RFavouritesDb::GetData |
|
658 // --------------------------------------------------------- |
|
659 // |
|
660 TInt RFavouritesDb::GetData |
|
661 ( TInt aFunction, TInt aUid, MFavouritesItemData& aData ) |
|
662 { |
|
663 RFavouritesBuf buf; |
|
664 TIpcArgs args( aUid ); |
|
665 TInt err = buf.Open( *this, aFunction, args ); |
|
666 if( !err ) |
|
667 { |
|
668 RReadStream stream( &buf ); |
|
669 TRAP( err, aData.InternalizeL( stream ) ); |
|
670 buf.Close(); |
|
671 } |
|
672 return err; |
|
673 } |
|
674 |
|
675 // --------------------------------------------------------- |
|
676 // RFavouritesDb::DoRestoreFactorySettingsL |
|
677 // --------------------------------------------------------- |
|
678 // |
|
679 void RFavouritesDb::DoRestoreFactorySettingsL |
|
680 ( const TDesC& aReferenceDbPath, MRfsApMapper& aApMapper ) |
|
681 { |
|
682 // Start transaction. |
|
683 // As AP mapping functionality is an M class, it cannot be sent over to |
|
684 // the server. Because of this, RFS is split into two phases (RFS of |
|
685 // items and mapping AP-s). Therefore, the transaction has to be made here |
|
686 // on client side. |
|
687 User::LeaveIfError( Begin( /*aWrite=*/ ETrue ) ); |
|
688 CleanupRollbackPushL(); |
|
689 |
|
690 // Step 1: do the restore and collect AP-s to be mapped. |
|
691 RFavouritesBuf buf; |
|
692 TIpcArgs args( &aReferenceDbPath, aReferenceDbPath.Length() ); |
|
693 User::LeaveIfError |
|
694 ( buf.Open( *this, EFavengRestoreFactorySettings, args ) ); |
|
695 CleanupClosePushL<RFavouritesBuf>( buf ); |
|
696 CUidMap* apMap = new (ELeave) CUidMap( KApMapGranularity ); |
|
697 CleanupStack::PushL( apMap ); |
|
698 RReadStream rs( &buf ); |
|
699 apMap->InternalizeL( rs ); |
|
700 |
|
701 // Step 2: map AP-s. (Omitted if there are no AP-s to map). |
|
702 if ( apMap->Count() ) |
|
703 { |
|
704 // Do the mapping. |
|
705 TUint srcAp; |
|
706 TUint tgtAp; |
|
707 for ( TInt i = 0; i < apMap->Count(); i++ ) |
|
708 { |
|
709 srcAp = STATIC_CAST( TUint, apMap->At( i ).iUid2 ); |
|
710 if ( aApMapper.MapAccessPoint( srcAp, tgtAp ) ) |
|
711 { |
|
712 apMap->At( i ).iUid2 = STATIC_CAST( TInt, tgtAp ); |
|
713 } |
|
714 } |
|
715 |
|
716 // Send back mapped AP-s. Reusing existing buffer. |
|
717 RWriteStream ws( &buf ); |
|
718 apMap->ExternalizeL( ws ); |
|
719 ws.CommitL(); |
|
720 User::LeaveIfError( SendReceive |
|
721 ( EFavengSetAccessPoints, TIpcArgs( buf.Handle() ) ) ); |
|
722 } |
|
723 CleanupStack::PopAndDestroy( 2 ); // apMap, close buf. |
|
724 |
|
725 // Commit changes. |
|
726 User::LeaveIfError( Commit() ); |
|
727 CleanupStack::Pop(); // Pop the rollback. |
|
728 } |
|
729 |
|
730 // --------------------------------------------------------- |
|
731 // RFavouritesDb::StaticRollback |
|
732 // --------------------------------------------------------- |
|
733 // |
|
734 void RFavouritesDb::StaticRollback( TAny* aPtr ) |
|
735 { |
|
736 STATIC_CAST( RFavouritesDb*, aPtr )->Rollback(); |
|
737 } |
|
738 |
|
739 // End of File |