|
1 /* |
|
2 * Copyright (c) 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "ncddbstoragemanager.h" |
|
20 |
|
21 #include "ncdstoragebase.h" |
|
22 #include "ncdstoragepanics.pan" |
|
23 |
|
24 #include "catalogsdebug.h" |
|
25 |
|
26 #include <f32file.h> |
|
27 #include <bautils.h> |
|
28 |
|
29 // --------------------------------------------------------------------------- |
|
30 // |
|
31 // --------------------------------------------------------------------------- |
|
32 // |
|
33 CNcdDbStorageManager* CNcdDbStorageManager::NewLC( |
|
34 RFs& aFs, |
|
35 const TDesC& aStorageUid, |
|
36 const TDesC& aStorageFolder, |
|
37 const TDesC& aStorageName ) |
|
38 { |
|
39 CNcdDbStorageManager* manager = new (ELeave) CNcdDbStorageManager; |
|
40 CleanupStack::PushL( manager ); |
|
41 manager->ConstructL( aFs, aStorageUid, aStorageFolder, aStorageName ); |
|
42 return manager; |
|
43 } |
|
44 |
|
45 |
|
46 |
|
47 // --------------------------------------------------------------------------- |
|
48 // |
|
49 // --------------------------------------------------------------------------- |
|
50 // |
|
51 CNcdDbStorageManager::~CNcdDbStorageManager() |
|
52 { |
|
53 DLTRACEIN(("this-ptr: %X", this)); |
|
54 delete iStorage; |
|
55 delete iData; |
|
56 } |
|
57 |
|
58 |
|
59 // --------------------------------------------------------------------------- |
|
60 // |
|
61 // --------------------------------------------------------------------------- |
|
62 // |
|
63 CNcdDbStorageManager::CNcdDbStorageManager() : |
|
64 iLocallyOpenCount( 0 ), |
|
65 iForceOpen( EFalse ) |
|
66 { |
|
67 DLTRACEIN(( "this-ptr: %X", this )); |
|
68 } |
|
69 |
|
70 |
|
71 // --------------------------------------------------------------------------- |
|
72 // |
|
73 // --------------------------------------------------------------------------- |
|
74 // |
|
75 void CNcdDbStorageManager::ConstructL( |
|
76 RFs& aFs, |
|
77 const TDesC& aStorageUid, |
|
78 const TDesC& aStorageFolder, const TDesC& aStorageName ) |
|
79 { |
|
80 DLTRACEIN(("")); |
|
81 iStorage = CNcdStorageBase::NewL( aFs, aStorageUid, aStorageFolder, |
|
82 aStorageName ); |
|
83 |
|
84 DLTRACE(("CNcdStorageBase created")); |
|
85 iStorage->SetListener( this ); |
|
86 |
|
87 User::LeaveIfError( iStorage->Open() ); |
|
88 |
|
89 // Create data object |
|
90 iData = new (ELeave) CNcdDbStorageManagerData( this ); |
|
91 |
|
92 DLTRACEOUT( ("") ); |
|
93 } |
|
94 |
|
95 |
|
96 // --------------------------------------------------------------------------- |
|
97 // |
|
98 // --------------------------------------------------------------------------- |
|
99 // |
|
100 MNcdStorageItem* CNcdDbStorageManager::StorageItemL( const TDesC& aUid, |
|
101 TInt aType ) |
|
102 { |
|
103 return (MNcdStorageItem*)iStorage->StorageItemL( aUid, aType ); |
|
104 } |
|
105 |
|
106 |
|
107 // --------------------------------------------------------------------------- |
|
108 // |
|
109 // --------------------------------------------------------------------------- |
|
110 // |
|
111 void CNcdDbStorageManager::StorageItemsL( |
|
112 RPointerArray<MNcdStorageItem>& aItems ) |
|
113 { |
|
114 iStorage->StorageItemsL( aItems ); |
|
115 } |
|
116 |
|
117 |
|
118 // --------------------------------------------------------------------------- |
|
119 // |
|
120 // --------------------------------------------------------------------------- |
|
121 // |
|
122 void CNcdDbStorageManager::RemoveItemsL( |
|
123 const RArray<RNcdDatabaseItems>& aDoNotRemoveItems ) |
|
124 { |
|
125 iStorage->RemoveItemsL( aDoNotRemoveItems ); |
|
126 } |
|
127 |
|
128 |
|
129 // --------------------------------------------------------------------------- |
|
130 // |
|
131 // --------------------------------------------------------------------------- |
|
132 // |
|
133 void CNcdDbStorageManager::Begin() |
|
134 { |
|
135 iForceOpen = ETrue; |
|
136 iData->StorageOpened(); |
|
137 } |
|
138 |
|
139 // --------------------------------------------------------------------------- |
|
140 // |
|
141 // --------------------------------------------------------------------------- |
|
142 // |
|
143 void CNcdDbStorageManager::CommitL() |
|
144 { |
|
145 DLTRACEIN(("")); |
|
146 iForceOpen = EFalse; |
|
147 iData->StorageClosedL(); |
|
148 } |
|
149 |
|
150 // --------------------------------------------------------------------------- |
|
151 // |
|
152 // --------------------------------------------------------------------------- |
|
153 // |
|
154 void CNcdDbStorageManager::Rollback() |
|
155 { |
|
156 iForceOpen = EFalse; |
|
157 iData->Rollback(); |
|
158 } |
|
159 |
|
160 // --------------------------------------------------------------------------- |
|
161 // |
|
162 // --------------------------------------------------------------------------- |
|
163 // |
|
164 TBool CNcdDbStorageManager::ItemExistsInStorageL( |
|
165 MNcdStorageItem& aStorageItem ) |
|
166 { |
|
167 return ItemExistsInStorageL( aStorageItem.Uid(), aStorageItem.Type() ); |
|
168 } |
|
169 |
|
170 |
|
171 // --------------------------------------------------------------------------- |
|
172 // |
|
173 // --------------------------------------------------------------------------- |
|
174 // |
|
175 TBool CNcdDbStorageManager::ItemExistsInStorageL( const TDesC& aUid, |
|
176 TInt aType ) |
|
177 { |
|
178 return iStorage->ItemExistsInStorageL( aUid, aType ); |
|
179 } |
|
180 |
|
181 // --------------------------------------------------------------------------- |
|
182 // |
|
183 // --------------------------------------------------------------------------- |
|
184 // |
|
185 MNcdDatabaseStorage::TNcdDatabaseSize CNcdDbStorageManager::Size() const |
|
186 { |
|
187 return iStorage->Size(); |
|
188 } |
|
189 |
|
190 |
|
191 // --------------------------------------------------------------------------- |
|
192 // Compact |
|
193 // --------------------------------------------------------------------------- |
|
194 // |
|
195 void CNcdDbStorageManager::Compact() |
|
196 { |
|
197 DLTRACEIN(("")); |
|
198 CommitCachedItems(); |
|
199 iStorage->Compact(); |
|
200 } |
|
201 |
|
202 |
|
203 // --------------------------------------------------------------------------- |
|
204 // |
|
205 // --------------------------------------------------------------------------- |
|
206 // |
|
207 void CNcdDbStorageManager::CacheOpened() |
|
208 { |
|
209 DLTRACEIN(("this: %x", this)); |
|
210 iLocallyOpenCount++; |
|
211 iData->StorageOpened(); |
|
212 } |
|
213 |
|
214 // --------------------------------------------------------------------------- |
|
215 // |
|
216 // --------------------------------------------------------------------------- |
|
217 // |
|
218 void CNcdDbStorageManager::CacheReadyL() |
|
219 { |
|
220 DLTRACEIN(("this: %x", this)); |
|
221 iLocallyOpenCount--; |
|
222 iData->StorageClosedL(); |
|
223 |
|
224 DLTRACEOUT(("")); |
|
225 } |
|
226 |
|
227 // --------------------------------------------------------------------------- |
|
228 // |
|
229 // --------------------------------------------------------------------------- |
|
230 // |
|
231 TInt CNcdDbStorageManager::CommitCachedItems() |
|
232 { |
|
233 DLTRACEIN(("this: %x", this)); |
|
234 iForceOpen = EFalse; |
|
235 |
|
236 TInt err = iStorage->Commit(); |
|
237 |
|
238 if( err == KErrNone ) |
|
239 { |
|
240 iLocallyOpenCount = 0; |
|
241 } |
|
242 DLTRACEOUT(("err: %d", err)); |
|
243 return err; |
|
244 } |
|
245 |
|
246 |
|
247 // --------------------------------------------------------------------------- |
|
248 // |
|
249 // --------------------------------------------------------------------------- |
|
250 // |
|
251 void CNcdDbStorageManager::NotifyRollback() |
|
252 { |
|
253 iLocallyOpenCount--; |
|
254 iData->Rollback(); |
|
255 } |
|
256 |
|
257 |
|
258 // --------------------------------------------------------------------------- |
|
259 // |
|
260 // --------------------------------------------------------------------------- |
|
261 // |
|
262 void CNcdDbStorageManager::RollbackItems() |
|
263 { |
|
264 iLocallyOpenCount = 0; |
|
265 iForceOpen = EFalse; |
|
266 |
|
267 iStorage->Rollback(); |
|
268 |
|
269 } |
|
270 |
|
271 |
|
272 // --------------------------------------------------------------------------- |
|
273 // |
|
274 // --------------------------------------------------------------------------- |
|
275 // |
|
276 CNcdDbStorageManager::CNcdDbStorageManagerData::CNcdDbStorageManagerData( |
|
277 CNcdDbStorageManager* aRoot ) : |
|
278 iRoot( aRoot ), |
|
279 iOpenStorages( 0 ) |
|
280 { |
|
281 } |
|
282 |
|
283 // --------------------------------------------------------------------------- |
|
284 // |
|
285 // --------------------------------------------------------------------------- |
|
286 // |
|
287 CNcdDbStorageManager::CNcdDbStorageManagerData::~CNcdDbStorageManagerData() |
|
288 { |
|
289 } |
|
290 |
|
291 |
|
292 // --------------------------------------------------------------------------- |
|
293 // |
|
294 // --------------------------------------------------------------------------- |
|
295 // |
|
296 void CNcdDbStorageManager::CNcdDbStorageManagerData::StorageOpened() |
|
297 { |
|
298 DLTRACEIN(("this: %x, open storages: %d", this, iOpenStorages + 1 )); |
|
299 iOpenStorages++; |
|
300 } |
|
301 |
|
302 |
|
303 // --------------------------------------------------------------------------- |
|
304 // |
|
305 // --------------------------------------------------------------------------- |
|
306 // |
|
307 void CNcdDbStorageManager::CNcdDbStorageManagerData::StorageClosedL() |
|
308 { |
|
309 DLTRACEIN(("OpenStorages: %d", iOpenStorages)); |
|
310 if ( iOpenStorages != 0 ) |
|
311 { |
|
312 iOpenStorages--; |
|
313 } |
|
314 else |
|
315 { |
|
316 DLTRACE(("All storages were already closed by tried to close one again")); |
|
317 } |
|
318 |
|
319 if( iOpenStorages == 0 ) |
|
320 { |
|
321 DLTRACE(("Committing cached items")); |
|
322 TInt err = iRoot->CommitCachedItems(); |
|
323 DLINFO(( "Commit error: %d", err )); |
|
324 User::LeaveIfError( err ); |
|
325 } |
|
326 |
|
327 DLTRACEOUT(("")); |
|
328 } |
|
329 |
|
330 |
|
331 // --------------------------------------------------------------------------- |
|
332 // |
|
333 // --------------------------------------------------------------------------- |
|
334 // |
|
335 TInt CNcdDbStorageManager::CNcdDbStorageManagerData::OpenStorages() |
|
336 { |
|
337 DLTRACEIN(( "this: %x, open storages: %d", this, iOpenStorages )); |
|
338 return iOpenStorages; |
|
339 } |
|
340 |
|
341 // --------------------------------------------------------------------------- |
|
342 // |
|
343 // --------------------------------------------------------------------------- |
|
344 // |
|
345 void CNcdDbStorageManager::CNcdDbStorageManagerData::Rollback() |
|
346 { |
|
347 if( iOpenStorages > 0 ) |
|
348 { |
|
349 iRoot->RollbackItems(); |
|
350 iOpenStorages = 0; |
|
351 } |
|
352 } |
|
353 |
|
354 |
|
355 // --------------------------------------------------------------------------- |
|
356 // UID getter |
|
357 // --------------------------------------------------------------------------- |
|
358 // |
|
359 const TDesC& CNcdDbStorageManager::Uid() const |
|
360 { |
|
361 return iStorage->Uid(); |
|
362 } |
|
363 |
|
364 |