|
1 /* |
|
2 * Copyright (c) 2005 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: DS notepad mods fetcher |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 |
|
21 #include <s32strm.h> |
|
22 #include <nsmlsnapshotitem.h> |
|
23 #include <nsmlchangefinder.h> |
|
24 |
|
25 #include "NSmlNotepadModsFetcher.h" |
|
26 #include "nsmlnotepadDatabase.h" |
|
27 |
|
28 #include "nsmlnotepadlogging.h" |
|
29 |
|
30 const TInt KNullId=-1; |
|
31 |
|
32 // ------------------------------------------------------------------------------------------------ |
|
33 // CNSmlNotepadModsFetcher::NewL |
|
34 // ------------------------------------------------------------------------------------------------ |
|
35 // |
|
36 CNSmlNotepadModsFetcher* CNSmlNotepadModsFetcher::NewL( TBool& aSnapshotRegistered, |
|
37 CNSmlNotepadDatabase* aNpdDb, |
|
38 TKeyArrayFix& aKey, |
|
39 CNSmlChangeFinder& aChangeFinder ) |
|
40 { |
|
41 _NOTEPAD_DBG_FILE("CNSmlNotepadModsFetcher::NewL(): begin"); |
|
42 CNSmlNotepadModsFetcher* self = NewLC(aSnapshotRegistered,aNpdDb,aKey,aChangeFinder); |
|
43 CleanupStack::Pop(self); |
|
44 _NOTEPAD_DBG_FILE("CNSmlNotepadModsFetcher::NewL(): end"); |
|
45 return self; |
|
46 } |
|
47 |
|
48 // ------------------------------------------------------------------------------------------------ |
|
49 // CNSmlNotepadModsFetcher::NewLC |
|
50 // ------------------------------------------------------------------------------------------------ |
|
51 // |
|
52 CNSmlNotepadModsFetcher* CNSmlNotepadModsFetcher::NewLC( TBool& aSnapshotRegistered, |
|
53 CNSmlNotepadDatabase* aNpdDb, |
|
54 TKeyArrayFix& aKey, |
|
55 CNSmlChangeFinder& aChangeFinder ) |
|
56 { |
|
57 _NOTEPAD_DBG_FILE("CNSmlNotepadModsFetcher::NewLC(): begin"); |
|
58 CNSmlNotepadModsFetcher* self = new (ELeave) CNSmlNotepadModsFetcher(aSnapshotRegistered,aNpdDb,aKey,aChangeFinder); |
|
59 CleanupStack::PushL( self ); |
|
60 self->ConstructL(); |
|
61 _NOTEPAD_DBG_FILE("CNSmlNotepadDataProvider::NewLC(): end"); |
|
62 return self; |
|
63 } |
|
64 // ------------------------------------------------------------------------------------------------ |
|
65 // CNSmlNotepadModsFetcher::CNSmlNotepadModsFetcher |
|
66 // ------------------------------------------------------------------------------------------------ |
|
67 // |
|
68 CNSmlNotepadModsFetcher::CNSmlNotepadModsFetcher( TBool& aSnapshotRegistered, |
|
69 CNSmlNotepadDatabase* aNpdDb, |
|
70 TKeyArrayFix& aKey, |
|
71 CNSmlChangeFinder& aChangeFinder ) : |
|
72 CActive( EPriorityLow ), iSnapshotRegistered( aSnapshotRegistered ), iNpdDb( aNpdDb ), iKey( aKey ), iChangeFinder( aChangeFinder ) |
|
73 { |
|
74 _NOTEPAD_DBG_FILE("CNSmlNotepadModsFetcher::CNSmlNotepadModsFetcher(): begin"); |
|
75 CActiveScheduler::Add( this ); |
|
76 iBeginning = ETrue; |
|
77 _NOTEPAD_DBG_FILE("CNSmlNotepadModsFetcher::CNSmlNotepadModsFetcher(): end"); |
|
78 } |
|
79 // ------------------------------------------------------------------------------------------------ |
|
80 // CNSmlNotepadModsFetcher::ConstructL |
|
81 // ------------------------------------------------------------------------------------------------ |
|
82 // |
|
83 void CNSmlNotepadModsFetcher::ConstructL() |
|
84 { |
|
85 _NOTEPAD_DBG_FILE("CNSmlNotepadModsFetcher::ConstructL: begin"); |
|
86 iSnapshot = new (ELeave) CArrayFixSeg<TNSmlSnapshotItem>(KNSmlSnapshotSmallSize); |
|
87 _NOTEPAD_DBG_FILE("CNSmlNotepadModsFetcher::ConstructL: end"); |
|
88 } |
|
89 // ------------------------------------------------------------------------------------------------ |
|
90 // CNSmlNotepadModsFetcher::~CNSmlNotepadModsFetcher |
|
91 // ------------------------------------------------------------------------------------------------ |
|
92 // |
|
93 CNSmlNotepadModsFetcher::~CNSmlNotepadModsFetcher() |
|
94 { |
|
95 _NOTEPAD_DBG_FILE("CNSmlNotepadModsFetcher::~CNSmlNotepadModsFetcher(): begin"); |
|
96 if(IsActive()) |
|
97 Cancel(); |
|
98 if(iSnapshot) |
|
99 { |
|
100 iSnapshot->Reset(); |
|
101 delete iSnapshot; |
|
102 iSnapshot=NULL; |
|
103 } |
|
104 _NOTEPAD_DBG_FILE("CNSmlNotepadModsFetcher::~CNSmlNotepadModsFetcher(): end"); |
|
105 } |
|
106 |
|
107 // ------------------------------------------------------------------------------------------------ |
|
108 // CNSmlNotepadModsFetcher::FetchModificationsL |
|
109 // ------------------------------------------------------------------------------------------------ |
|
110 // |
|
111 TInt CNSmlNotepadModsFetcher::FetchModificationsL( TRequestStatus& aStatus ) |
|
112 { |
|
113 _NOTEPAD_DBG_FILE("CNSmlNotepadModsFetcher::FetchModificationsL(): begin"); |
|
114 iCallerStatus = &aStatus; |
|
115 *iCallerStatus = KRequestPending; |
|
116 if(!iSnapshot) |
|
117 { |
|
118 iSnapshot = new (ELeave) CArrayFixSeg<TNSmlSnapshotItem>( KNSmlSnapshotSize ); |
|
119 } |
|
120 SetActive(); |
|
121 TRequestStatus* status = &iStatus; |
|
122 User::RequestComplete( status, KErrNone ); |
|
123 _NOTEPAD_DBG_FILE("CNSmlNotepadModsFetcher::FetchModificationsL(): end"); |
|
124 return KErrNone; |
|
125 } |
|
126 |
|
127 // ------------------------------------------------------------------------------------------------ |
|
128 // CNSmlNotepadModsFetcher::Reset() |
|
129 // ------------------------------------------------------------------------------------------------ |
|
130 // |
|
131 void CNSmlNotepadModsFetcher::Reset() |
|
132 { |
|
133 iBeginning = ETrue; |
|
134 } |
|
135 |
|
136 |
|
137 // ------------------------------------------------------------------------------------------------ |
|
138 // CNSmlNotepadModsFetcher::FetchNextChunkL |
|
139 // ------------------------------------------------------------------------------------------------ |
|
140 // |
|
141 void CNSmlNotepadModsFetcher::FetchNextChunkL() |
|
142 { |
|
143 _NOTEPAD_DBG_FILE("CNSmlNotepadModsFetcher::RunL(): end"); |
|
144 if ( iSnapshotRegistered ) |
|
145 { |
|
146 |
|
147 _NOTEPAD_DBG_FILE("CNSmlNotepadModsFetcher::FetchNextChunkL: if snapshotregistered"); |
|
148 iEnd = ETrue; |
|
149 } |
|
150 |
|
151 else |
|
152 { |
|
153 iEnd = EFalse; |
|
154 TInt id; |
|
155 |
|
156 if ( iBeginning ) |
|
157 { |
|
158 |
|
159 _NOTEPAD_DBG_FILE("CNSmlNotepadModsFetcher::FetchNextChunkL: callinf firstl"); |
|
160 id = iNpdDb->FirstL(); |
|
161 iBeginning = EFalse; |
|
162 } |
|
163 else |
|
164 { |
|
165 |
|
166 _NOTEPAD_DBG_FILE("CNSmlNotepadModsFetcher::FetchNextChunkL: calling nextl"); |
|
167 id = iNpdDb->NextL(); |
|
168 } |
|
169 if ( id == KNullId ) |
|
170 { |
|
171 |
|
172 _NOTEPAD_DBG_FILE("CNSmlNotepadModsFetcher::FetchNextChunkL: invalid id"); |
|
173 iEnd = ETrue; |
|
174 } |
|
175 else |
|
176 { |
|
177 |
|
178 _NOTEPAD_DBG_FILE("CNSmlNotepadModsFetcher::FetchNextChunkL: reading item from db"); |
|
179 CNpdItem* item = CNpdItem::NewLC(); |
|
180 TInt err; |
|
181 TRAP(err,iNpdDb->GetNoteL( id,*item )); |
|
182 if( err == KErrNone ) |
|
183 { |
|
184 |
|
185 _NOTEPAD_DBG_FILE("CNSmlNotepadModsFetcher::FetchNextChunkL: item read successful"); |
|
186 TNSmlSnapshotItem snap( item->Key() ); |
|
187 snap.SetLastChangedDate( item->LastModified() ); |
|
188 iSnapshot->InsertIsqL( snap, iKey ); |
|
189 iCurrentSnapshotCounter++; |
|
190 if ( iCurrentSnapshotCounter > KNSmlSnapshotItemCount ) |
|
191 { |
|
192 iSnapshot->Compress(); |
|
193 iCurrentSnapshotCounter = 0; |
|
194 } |
|
195 } |
|
196 CleanupStack::PopAndDestroy(item); // item |
|
197 } |
|
198 |
|
199 if ( iEnd ) |
|
200 { |
|
201 |
|
202 _NOTEPAD_DBG_FILE("CNSmlNotepadModsFetcher::FetchNextChunkL: end item"); |
|
203 iChangeFinder.SetNewSnapshot( iSnapshot ); // changefinder takes ownership |
|
204 iSnapshot = NULL; |
|
205 iSnapshotRegistered = ETrue; |
|
206 } |
|
207 } |
|
208 if ( iEnd ) |
|
209 { |
|
210 User::RequestComplete( iCallerStatus, KErrNone ); // CNSmlContactsModsFetcher |
|
211 } |
|
212 _NOTEPAD_DBG_FILE("CNSmlNotepadModsFetcher::FetchNextChunkL: end"); |
|
213 } |
|
214 // ------------------------------------------------------------------------------------------------ |
|
215 // CNSmlNotepadModsFetcher::RunL |
|
216 // ------------------------------------------------------------------------------------------------ |
|
217 // |
|
218 void CNSmlNotepadModsFetcher::RunL() |
|
219 { |
|
220 _NOTEPAD_DBG_FILE("CNSmlNotepadModsFetcher::RunL(): begin"); |
|
221 FetchNextChunkL(); |
|
222 if ( !iEnd ) |
|
223 { |
|
224 SetActive(); |
|
225 TRequestStatus* status = &iStatus; |
|
226 User::RequestComplete( status, KErrNone ); |
|
227 } |
|
228 _NOTEPAD_DBG_FILE("CNSmlNotepadModsFetcher::RunL(): end"); |
|
229 } |
|
230 |
|
231 // ------------------------------------------------------------------------------------------------ |
|
232 // CNSmlNotepadModsFetcher::DoCancel |
|
233 // ------------------------------------------------------------------------------------------------ |
|
234 // |
|
235 void CNSmlNotepadModsFetcher::DoCancel() |
|
236 { |
|
237 _NOTEPAD_DBG_FILE("CNSmlNotepadModsFetcher::DoCancel(): begin"); |
|
238 User::RequestComplete( iCallerStatus, KErrCancel ); |
|
239 iEnd = ETrue; |
|
240 _NOTEPAD_DBG_FILE("CNSmlNotepadModsFetcher::DoCancel(): end"); |
|
241 } |
|
242 |
|
243 // End of File |