|
1 /* |
|
2 * Copyright (c) 2007 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: Part of SyncML Data Synchronization Plug In Adapter |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "changefinder.h" |
|
20 #include "logger.h" |
|
21 |
|
22 const TUint KSnapshotFormatVersion ( 0xf0000001 ); // format version |
|
23 // ----------------------------------------------------------------------------- |
|
24 // CChangeFinder::NewL |
|
25 // Static function to create CChangeFider object(s) |
|
26 // ----------------------------------------------------------------------------- |
|
27 CChangeFinder* CChangeFinder::NewL( MSmlSyncRelationship& aSyncRelationship, TKeyArrayFix aKey, |
|
28 TBool& aHasHistory, TInt aStreamUid ) |
|
29 { |
|
30 CChangeFinder* self = new (ELeave) CChangeFinder( aSyncRelationship, aKey, aStreamUid ); |
|
31 CleanupStack::PushL( self ); |
|
32 self->ConstructL( aHasHistory ); |
|
33 CleanupStack::Pop( self ); |
|
34 return self; |
|
35 } |
|
36 |
|
37 // ----------------------------------------------------------------------------- |
|
38 // CChangeFinder::CChangeFinder |
|
39 // Constructor for the class |
|
40 // ----------------------------------------------------------------------------- |
|
41 CChangeFinder::CChangeFinder( MSmlSyncRelationship& aSyncRelationship, TKeyArrayFix aKey, TInt aStreamUid ) : |
|
42 iSyncRelationship( aSyncRelationship ), |
|
43 iKey( aKey ), |
|
44 iStreamUid( aStreamUid ), |
|
45 iDataStoreUid( KErrNotFound ) |
|
46 { |
|
47 |
|
48 } |
|
49 |
|
50 // ----------------------------------------------------------------------------- |
|
51 // CChangeFinder::~CChangeFinder |
|
52 // Destructor for the class, closes the ChangeFinder and writes snapshot to stream |
|
53 // ----------------------------------------------------------------------------- |
|
54 CChangeFinder::~CChangeFinder() |
|
55 { |
|
56 LOGGER_ENTERFN( "CChangeFinder::~CChangeFinder" ); |
|
57 delete iOldSnapshot; |
|
58 delete iCurrentSnapshot; |
|
59 LOGGER_LEAVEFN( "CChangeFinder::~CChangeFinder" ); |
|
60 } |
|
61 |
|
62 // ----------------------------------------------------------------------------- |
|
63 // CChangeFinder::ConstructL |
|
64 // 2nd phase constructor for the class, reads snapshot from stream |
|
65 // ----------------------------------------------------------------------------- |
|
66 void CChangeFinder::ConstructL( TBool& aHasHistory ) |
|
67 { |
|
68 LOGGER_ENTERFN( "CChangeFinder::ConstructL" ); |
|
69 iOldSnapshot = new (ELeave) CSnapshotArray( KSnapshotGranularity ); |
|
70 iCurrentSnapshot = new (ELeave) CSnapshotArray( KSnapshotGranularity ); |
|
71 LOGGER_WRITE("CChangeFinder::ConstructL, CSnapshotArray:s created"); |
|
72 TUid uid = {iStreamUid}; |
|
73 |
|
74 aHasHistory = iSyncRelationship.IsStreamPresentL( uid ); |
|
75 |
|
76 if ( aHasHistory ) |
|
77 { |
|
78 LOGGER_WRITE("CChangeFinder::ConstructL, HasHistory"); |
|
79 // Open stream for reading |
|
80 RReadStream readStream; |
|
81 iSyncRelationship.OpenReadStreamLC( readStream, uid ); |
|
82 |
|
83 // Read used format version |
|
84 TUint formatVer = readStream.ReadUint32L(); |
|
85 if ( formatVer != KSnapshotFormatVersion ) |
|
86 { |
|
87 // Wrong version, do not try to import data |
|
88 LOGGER_WRITE("CChangeFinder::ConstructL, Wrong format version -> no history"); |
|
89 aHasHistory = EFalse; |
|
90 CleanupStack::PopAndDestroy( &readStream ); |
|
91 LOGGER_LEAVEFN("CChangeFinder::ConstructL"); |
|
92 return; |
|
93 } |
|
94 else |
|
95 { |
|
96 LOGGER_WRITE("CChangeFinder::ConstructL, format is OK"); |
|
97 } |
|
98 |
|
99 // Read item count |
|
100 TInt count = readStream.ReadUint32L(); |
|
101 |
|
102 // Read items |
|
103 for ( TInt i=0; i<count; i++ ) |
|
104 { |
|
105 TSnapshotItem item; |
|
106 item.InternalizeL( readStream ); |
|
107 iOldSnapshot->InsertIsqL( item, iKey ); |
|
108 } |
|
109 iOldSnapshot->Compress(); |
|
110 |
|
111 LOGGER_WRITE_1("iOldSnapshot done, iOldSnapshot->Count: %d", iOldSnapshot->Count() ); |
|
112 CleanupStack::PopAndDestroy( &readStream ); // readStream |
|
113 } |
|
114 else |
|
115 { |
|
116 LOGGER_WRITE("CChangeFinder::ConstructL, no sync history."); |
|
117 } |
|
118 |
|
119 LOGGER_LEAVEFN("CChangeFinder::ConstructL"); |
|
120 } |
|
121 |
|
122 // ----------------------------------------------------------------------------- |
|
123 // CChangeFinder::CloseL |
|
124 // Closes ChangeFinder object and writes snapshot to stream |
|
125 // ----------------------------------------------------------------------------- |
|
126 void CChangeFinder::CloseL() |
|
127 { |
|
128 LOGGER_ENTERFN( "CChangeFinder::CloseL" ); |
|
129 |
|
130 RWriteStream writeStream; |
|
131 |
|
132 TUid uid = {iStreamUid}; |
|
133 |
|
134 // Open write stream |
|
135 iSyncRelationship.OpenWriteStreamLC( writeStream, uid ); |
|
136 |
|
137 // Write used format version |
|
138 writeStream.WriteUint32L( KSnapshotFormatVersion ); |
|
139 |
|
140 // Write item count |
|
141 TInt count = iOldSnapshot->Count(); |
|
142 writeStream.WriteUint32L( count ); |
|
143 |
|
144 // Write items |
|
145 for ( TInt i = 0; i < count; i++ ) |
|
146 { |
|
147 const TSnapshotItem& item = iOldSnapshot->At( i ); |
|
148 item.ExternalizeL( writeStream ); |
|
149 } |
|
150 |
|
151 writeStream.CommitL(); |
|
152 CleanupStack::PopAndDestroy( &writeStream ); // writeStream |
|
153 |
|
154 LOGGER_LEAVEFN( "CChangeFinder::CloseL" ); |
|
155 } |
|
156 |
|
157 // ----------------------------------------------------------------------------- |
|
158 // CChangeFinder::ResetL |
|
159 // Resets synchronization history, all contetn is considered new after this call |
|
160 // ----------------------------------------------------------------------------- |
|
161 void CChangeFinder::ResetL() |
|
162 { |
|
163 LOGGER_ENTERFN( "CChangeFinder::ResetL" ); |
|
164 if ( iOldSnapshot ) |
|
165 { |
|
166 LOGGER_WRITE("iOldSnapshot->Reset()"); |
|
167 iOldSnapshot->Reset(); |
|
168 // Write 'null' data to file, |
|
169 // this removes change history from the file |
|
170 CloseL(); |
|
171 } |
|
172 LOGGER_LEAVEFN( "CChangeFinder::ResetL" ); |
|
173 } |
|
174 |
|
175 // ----------------------------------------------------------------------------- |
|
176 // CChangeFinder::FindChangedItemsL |
|
177 // Compares snapshots, finds changed items |
|
178 // ----------------------------------------------------------------------------- |
|
179 void CChangeFinder::FindChangedItemsL( CNSmlDataItemUidSet& aChangedUids ) |
|
180 { |
|
181 LOGGER_ENTERFN( "CChangeFinder::FindChangedItemsL" ); |
|
182 aChangedUids.Reset(); |
|
183 |
|
184 if ( !iCurrentSnapshot ) |
|
185 { |
|
186 LOGGER_WRITE( "CChangeFinder::FindChangedItemsL leaved, no current snapshot." ); |
|
187 User::Leave( KErrNotFound ); |
|
188 } |
|
189 |
|
190 if ( !iOldSnapshot ) |
|
191 { |
|
192 LOGGER_WRITE( "CChangeFinder::FindChangedItemsL leaved, no old snapshot." ); |
|
193 User::Leave( KErrNotFound ); |
|
194 } |
|
195 |
|
196 TInt index; |
|
197 TInt count = iCurrentSnapshot->Count(); |
|
198 LOGGER_WRITE_1( "CChangeFinder::FindChangedItemsL items on iCurrentSnapshot: %d", count ); |
|
199 for ( TInt i=0; i < count; i++ ) |
|
200 { |
|
201 const TSnapshotItem& currentItem = iCurrentSnapshot->At( i ); |
|
202 |
|
203 // Find this entry from the old snapshot |
|
204 if ( iOldSnapshot->FindIsq( currentItem, iKey, index ) == KErrNone) |
|
205 { |
|
206 // This is the old item |
|
207 TSnapshotItem& oldItem = iOldSnapshot->At( index ); |
|
208 if ( currentItem.Hash().Compare( oldItem.Hash() ) != 0 ) |
|
209 { |
|
210 // add to list |
|
211 User::LeaveIfError( aChangedUids.AddItem( currentItem.ItemId() ) ); |
|
212 } |
|
213 } |
|
214 } |
|
215 |
|
216 LOGGER_LEAVEFN( "CChangeFinder::FindChangedItemsL" ); |
|
217 } |
|
218 |
|
219 // ----------------------------------------------------------------------------- |
|
220 // CChangeFinder::FindDeletedItemsL |
|
221 // Compares snapshots, finds deleted items |
|
222 // ----------------------------------------------------------------------------- |
|
223 void CChangeFinder::FindDeletedItemsL( CNSmlDataItemUidSet& aDeletedUids ) |
|
224 { |
|
225 LOGGER_ENTERFN( "CChangeFinder::FindDeletedItemsL" ); |
|
226 aDeletedUids.Reset(); |
|
227 if ( !iOldSnapshot ) |
|
228 { |
|
229 LOGGER_LEAVEFN( "CChangeFinder::FindDeletedItemsL leaved, no old snapshot." ); |
|
230 User::Leave( KErrNotFound ); |
|
231 } |
|
232 |
|
233 TInt index; |
|
234 TInt count = iOldSnapshot->Count(); |
|
235 for ( TInt i=0; i < count; i++ ) |
|
236 { |
|
237 const TSnapshotItem& currentItem = iOldSnapshot->At( i ); |
|
238 |
|
239 // If there's no current snapshot, this definately is deleted item |
|
240 if ( !iCurrentSnapshot ) |
|
241 { |
|
242 User::LeaveIfError( aDeletedUids.AddItem( currentItem.ItemId() ) ); |
|
243 LOGGER_WRITE_1( "Item %d was deleted.", currentItem.ItemId() ); |
|
244 } |
|
245 // It is also new if it doesn't exist int the current snapshot. |
|
246 else if ( iCurrentSnapshot->FindIsq( currentItem, iKey, index ) != KErrNone ) |
|
247 { |
|
248 User::LeaveIfError( aDeletedUids.AddItem( currentItem.ItemId() ) ); |
|
249 LOGGER_WRITE_1( "Item %d was deleted.", currentItem.ItemId() ); |
|
250 } |
|
251 } |
|
252 |
|
253 LOGGER_LEAVEFN( "CChangeFinder::FindDeletedItemsL" ); |
|
254 } |
|
255 |
|
256 // ----------------------------------------------------------------------------- |
|
257 // CChangeFinder::FindNewItemsL |
|
258 // Compares snapshots, finds new items |
|
259 // ----------------------------------------------------------------------------- |
|
260 void CChangeFinder::FindNewItemsL( CNSmlDataItemUidSet& aNewUids ) |
|
261 { |
|
262 LOGGER_ENTERFN( "CChangeFinder::FindNewItemsL" ); |
|
263 aNewUids.Reset(); |
|
264 /*if ( !iCurrentSnapshot ) |
|
265 { |
|
266 LOGGER_WRITE( "CChangeFinder::FindNewItemsL leaved, no current snapshot." ); |
|
267 User::Leave( KErrNotFound ); |
|
268 }*/ |
|
269 |
|
270 TInt index; |
|
271 TInt count = iCurrentSnapshot->Count(); |
|
272 LOGGER_WRITE_1( "iCurrentSnapshot->Count(): %d", count ); |
|
273 LOGGER_WRITE_1( "iOldSnapshot->Count(): %d", iOldSnapshot->Count() ); |
|
274 for ( TInt i=0; i < count; i++ ) |
|
275 { |
|
276 const TSnapshotItem& currentItem = iCurrentSnapshot->At( i ); |
|
277 |
|
278 // If there's no old snapshot, all items are new |
|
279 if ( !iOldSnapshot ) |
|
280 { |
|
281 User::LeaveIfError( aNewUids.AddItem( currentItem.ItemId() ) ); |
|
282 LOGGER_WRITE_1( "!iOldSnapshot, Item %d was new.", currentItem.ItemId() ); |
|
283 } |
|
284 // It is also new if it doesn't exist int the old snapshot. |
|
285 else if ( iOldSnapshot->FindIsq( currentItem, iKey, index ) != KErrNone ) |
|
286 { |
|
287 User::LeaveIfError( aNewUids.AddItem( currentItem.ItemId() ) ); |
|
288 LOGGER_WRITE_1( "Item %d was new.", currentItem.ItemId() ); |
|
289 } |
|
290 } |
|
291 |
|
292 LOGGER_LEAVEFN( "CChangeFinder::FindNewItemsL" ); |
|
293 } |
|
294 |
|
295 // ----------------------------------------------------------------------------- |
|
296 // CChangeFinder::FindMovedItemsL |
|
297 // Compares snapshots, finds moved items |
|
298 // ----------------------------------------------------------------------------- |
|
299 void CChangeFinder::FindMovedItemsL( CNSmlDataItemUidSet& aMovedUids ) |
|
300 { |
|
301 LOGGER_ENTERFN( "CChangeFinder::FindMovedItemsL" ); |
|
302 aMovedUids.Reset(); |
|
303 if ( !iCurrentSnapshot ) |
|
304 { |
|
305 LOGGER_WRITE( "CChangeFinder::FindMovedItemsL leaved, no current snapshot." ); |
|
306 User::Leave( KErrNotFound ); |
|
307 } |
|
308 |
|
309 if ( !iOldSnapshot ) |
|
310 { |
|
311 LOGGER_WRITE( "CChangeFinder::FindMovedItemsL leaved, no old snapshot." ); |
|
312 User::Leave( KErrNotFound ); |
|
313 } |
|
314 |
|
315 TInt index; |
|
316 TInt count = iCurrentSnapshot->Count(); |
|
317 for ( TInt i=0; i < count; i++ ) |
|
318 { |
|
319 const TSnapshotItem& currentItem = iCurrentSnapshot->At( i ); |
|
320 |
|
321 // Find this entry from the old snapshot |
|
322 if(iOldSnapshot->FindIsq( currentItem, iKey, index ) == KErrNone) |
|
323 { |
|
324 // This is the old item |
|
325 TSnapshotItem& oldItem = iOldSnapshot->At( index ); |
|
326 |
|
327 // Report only moved items in which only parent id has been changed |
|
328 if ( oldItem.ParentId() != currentItem.ParentId() |
|
329 && currentItem.Hash().Compare( oldItem.Hash() ) == 0 ) |
|
330 { |
|
331 User::LeaveIfError( aMovedUids.AddItem( currentItem.ItemId() ) ); |
|
332 LOGGER_WRITE_1( "Item %d was moved.", currentItem.ItemId() ); |
|
333 } |
|
334 } |
|
335 } |
|
336 |
|
337 LOGGER_LEAVEFN( "CChangeFinder::FindMovedItemsL" ); |
|
338 } |
|
339 |
|
340 // ----------------------------------------------------------------------------- |
|
341 // CChangeFinder::ItemAddedL |
|
342 // Adds item to snapshot, this item is no longer considered new |
|
343 // ----------------------------------------------------------------------------- |
|
344 void CChangeFinder::ItemAddedL( const TSnapshotItem& aItem ) |
|
345 { |
|
346 LOGGER_ENTERFN( "CChangeFinder::ItemAddedL" ); |
|
347 |
|
348 // Add this to old snapshot, if there's no old snapshot it must be created |
|
349 if ( !iOldSnapshot ) |
|
350 { |
|
351 iOldSnapshot = new (ELeave) CSnapshotArray( KSnapshotGranularity ); |
|
352 } |
|
353 |
|
354 LOGGER_WRITE_1( "Adding item %d.", aItem.ItemId() ); |
|
355 |
|
356 iOldSnapshot->InsertIsqL( aItem, iKey ); |
|
357 iOldSnapshot->Compress(); |
|
358 |
|
359 LOGGER_LEAVEFN( "CChangeFinder::ItemAddedL" ); |
|
360 } |
|
361 |
|
362 // ----------------------------------------------------------------------------- |
|
363 // CChangeFinder::ItemDeletedL |
|
364 // Removes item to snapshot, this item is no longer considered deleted |
|
365 // ----------------------------------------------------------------------------- |
|
366 void CChangeFinder::ItemDeletedL( const TSnapshotItem& aItem ) |
|
367 { |
|
368 LOGGER_ENTERFN( "CChangeFinder::ItemDeletedL" ); |
|
369 |
|
370 LOGGER_WRITE_1( "deleting item %d.", aItem.ItemId() ); |
|
371 |
|
372 if ( !iOldSnapshot ) |
|
373 { |
|
374 LOGGER_WRITE( "CChangeFinder::ItemDeletedL leaved, no old snapshot." ); |
|
375 User::Leave( KErrNotFound ); |
|
376 } |
|
377 |
|
378 // Delete item from the old snapshot |
|
379 TInt index; |
|
380 if ( iOldSnapshot->FindIsq( aItem, iKey, index ) == KErrNone ) |
|
381 { |
|
382 iOldSnapshot->Delete( index ); |
|
383 } |
|
384 else // Skip, there wasn't such entry |
|
385 { |
|
386 LOGGER_WRITE( "iOldSnapshot->FindIsq, item was not found." ); |
|
387 } |
|
388 |
|
389 LOGGER_LEAVEFN( "CChangeFinder::ItemDeletedL" ); |
|
390 } |
|
391 |
|
392 // ----------------------------------------------------------------------------- |
|
393 // CChangeFinder::ItemUpdatedL |
|
394 // Updates item to snapshot, this item is no longer considered changed |
|
395 // ----------------------------------------------------------------------------- |
|
396 void CChangeFinder::ItemUpdatedL( const TSnapshotItem& aItem ) |
|
397 { |
|
398 LOGGER_ENTERFN( "CChangeFinder::ItemUpdatedL" ); |
|
399 |
|
400 LOGGER_WRITE_1( "Updating item %d.", aItem.ItemId() ); |
|
401 |
|
402 // There must be such entry in the snapshot after this |
|
403 // If there isn't old snapshot, we'll create it and add the item |
|
404 |
|
405 if ( !iOldSnapshot ) |
|
406 { |
|
407 iOldSnapshot = new (ELeave) CSnapshotArray( KSnapshotGranularity ); |
|
408 ItemAddedL( aItem ); |
|
409 } |
|
410 else |
|
411 { |
|
412 // Update item in the old snapshot |
|
413 TInt index; |
|
414 if ( iOldSnapshot->FindIsq( aItem, iKey, index ) == KErrNone ) |
|
415 { |
|
416 iOldSnapshot->At( index ) = aItem; |
|
417 } |
|
418 else |
|
419 { |
|
420 // There was old snapshot but no such item. Let's add it |
|
421 ItemAddedL( aItem ); |
|
422 } |
|
423 |
|
424 } |
|
425 |
|
426 LOGGER_LEAVEFN( "CChangeFinder::ItemUpdatedL" ); |
|
427 } |
|
428 |
|
429 // ----------------------------------------------------------------------------- |
|
430 // CChangeFinder::ItemMovedL |
|
431 // Moves item within snapshot, this item is no longer considered moved |
|
432 // ----------------------------------------------------------------------------- |
|
433 void CChangeFinder::ItemMovedL( const TSnapshotItem& aItem ) |
|
434 { |
|
435 LOGGER_ENTERFN( "CChangeFinder::ItemMovedL" ); |
|
436 |
|
437 LOGGER_WRITE_1( "Moving item %d.", aItem.ItemId() ); |
|
438 |
|
439 // There must be such entry in the snapshot after this |
|
440 // If there isn't old snapshot, we'll create it and add the item |
|
441 if ( !iOldSnapshot ) |
|
442 { |
|
443 iOldSnapshot = new (ELeave) CSnapshotArray( KSnapshotGranularity ); |
|
444 ItemAddedL( aItem ); |
|
445 } |
|
446 else |
|
447 { |
|
448 // Update item's parent in the old snapshot |
|
449 TInt index; |
|
450 if ( iOldSnapshot->FindIsq( aItem, iKey, index ) == KErrNone ) |
|
451 { |
|
452 iOldSnapshot->At(index) = aItem; |
|
453 } |
|
454 else |
|
455 { |
|
456 // There was old snapshot but no such item. Let's add it |
|
457 ItemAddedL( aItem ); |
|
458 } |
|
459 } |
|
460 |
|
461 LOGGER_LEAVEFN("CChangeFinder::ItemMovedL"); |
|
462 } |
|
463 |
|
464 // ----------------------------------------------------------------------------- |
|
465 // CChangeFinder::CommitChangesL |
|
466 // Commits current changes to snapshot |
|
467 // ----------------------------------------------------------------------------- |
|
468 void CChangeFinder::CommitChangesL() |
|
469 { |
|
470 LOGGER_ENTERFN( "CChangeFinder::CommitChangesL" ); |
|
471 |
|
472 if ( !iCurrentSnapshot ) |
|
473 { |
|
474 LOGGER_WRITE( "CChangeFinder::CommitChangesL leaved, current snapshot missing." ); |
|
475 User::Leave( KErrNotFound ); |
|
476 } |
|
477 |
|
478 if ( !iOldSnapshot ) |
|
479 { |
|
480 iOldSnapshot = new (ELeave) CSnapshotArray( KSnapshotGranularity ); |
|
481 } |
|
482 |
|
483 // Delete everything from the old snapshot |
|
484 iOldSnapshot->Reset(); |
|
485 |
|
486 // Loop through all the items in current snapshot |
|
487 TInt count = iCurrentSnapshot->Count(); |
|
488 |
|
489 // Copy everything from current to old snapshot |
|
490 for ( TInt i = 0; i < count; i++ ) |
|
491 { |
|
492 // Commit it to the old array. |
|
493 iOldSnapshot->InsertIsqL( iCurrentSnapshot->At( i ), iKey ); |
|
494 } |
|
495 LOGGER_LEAVEFN( "CChangeFinder::CommitChangesL" ); |
|
496 } |
|
497 |
|
498 // ----------------------------------------------------------------------------- |
|
499 // CChangeFinder::CommitChangesL |
|
500 // Commits current changes to snapshot, affects only a specified group of items |
|
501 // ----------------------------------------------------------------------------- |
|
502 void CChangeFinder::CommitChangesL( const MSmlDataItemUidSet& aUids ) |
|
503 { |
|
504 LOGGER_ENTERFN( "CChangeFinder::CommitChangesL" ); |
|
505 |
|
506 // This function commits changes from current snapshot to old snapshot |
|
507 // But commits only the entries in the parameter array |
|
508 if ( !iCurrentSnapshot ) |
|
509 { |
|
510 LOGGER_WRITE( "CChangeFinder::CommitChangesL leaved, current snapshot missing." ); |
|
511 User::Leave( KErrNotFound ); |
|
512 } |
|
513 |
|
514 if ( !iOldSnapshot ) |
|
515 { |
|
516 iOldSnapshot = new (ELeave) CSnapshotArray( KSnapshotGranularity ); |
|
517 } |
|
518 |
|
519 for ( TInt i = 0; i < aUids.ItemCount(); i++ ) |
|
520 { |
|
521 TSmlDbItemUid itemId = aUids.ItemAt( i ); |
|
522 TSnapshotItem temp( itemId ); |
|
523 TInt indexOld( -1 ); |
|
524 TInt indexNew( -1 ); |
|
525 if ( !iOldSnapshot->FindIsq( temp, iKey, indexOld) ) |
|
526 { |
|
527 if ( !iCurrentSnapshot->FindIsq(temp, iKey, indexNew) ) |
|
528 { |
|
529 // Replace, moved or softdeleted |
|
530 iOldSnapshot->At( indexOld ) = iCurrentSnapshot->At( indexNew ); |
|
531 } |
|
532 else |
|
533 { |
|
534 // Delete |
|
535 iOldSnapshot->Delete( indexOld ); |
|
536 } |
|
537 } |
|
538 else |
|
539 { |
|
540 // Add |
|
541 if ( !iCurrentSnapshot->FindIsq( temp, iKey, indexNew ) ) |
|
542 { |
|
543 iOldSnapshot->InsertIsqL( iCurrentSnapshot->At( indexNew ), iKey ); |
|
544 } |
|
545 } |
|
546 } |
|
547 LOGGER_LEAVEFN( "CChangeFinder::CommitChangesL" ); |
|
548 } |
|
549 |
|
550 // ----------------------------------------------------------------------------- |
|
551 // CChangeFinder::SetNewSnapshot |
|
552 // Sets new snapshot (to be compared against), ChangeFinder takes ownership |
|
553 // ----------------------------------------------------------------------------- |
|
554 void CChangeFinder::SetNewSnapshot( CSnapshotArray* aNewSnapshot ) |
|
555 { |
|
556 LOGGER_ENTERFN( "CChangeFinder::SetNewSnapshot" ); |
|
557 |
|
558 // Delete existing snapshot |
|
559 delete iCurrentSnapshot; |
|
560 |
|
561 // Set submitted snapshot as active |
|
562 iCurrentSnapshot = aNewSnapshot; |
|
563 LOGGER_LEAVEFN( "CChangeFinder::SetNewSnapshot" ); |
|
564 } |
|
565 |
|
566 // ----------------------------------------------------------------------------- |
|
567 // CChangeFinder::DataStoreUid |
|
568 // returns stored data store id number |
|
569 // ----------------------------------------------------------------------------- |
|
570 TInt64 CChangeFinder::DataStoreUid() const |
|
571 { |
|
572 LOGGER_ENTERFN( "CChangeFinder::DataStoreUid" ); |
|
573 LOGGER_LEAVEFN( "CChangeFinder::DataStoreUid" ); |
|
574 return iDataStoreUid; |
|
575 } |
|
576 |
|
577 // ----------------------------------------------------------------------------- |
|
578 // CChangeFinder::SetDataStoreUid |
|
579 // Sets data store id number |
|
580 // ----------------------------------------------------------------------------- |
|
581 void CChangeFinder::SetDataStoreUid( TInt64 aUid ) |
|
582 { |
|
583 LOGGER_ENTERFN( "CChangeFinder::SetDataStoreUid" ); |
|
584 iDataStoreUid = aUid; |
|
585 LOGGER_LEAVEFN( "CChangeFinder::SetDataStoreUid" ); |
|
586 } |