|
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: Implements CNcdNodeDbManager class |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "ncdnodedbmanager.h" |
|
20 |
|
21 #include <e32err.h> |
|
22 #include <s32mem.h> |
|
23 #include <badesca.h> |
|
24 |
|
25 #include "ncdnodeidentifier.h" |
|
26 #include "ncdnodeidentifiereditor.h" |
|
27 #include "catalogsutils.h" |
|
28 #include "ncdstoragemanager.h" |
|
29 #include "ncdstoragebase.h" |
|
30 #include "ncdstorage.h" |
|
31 #include "ncdfilestorage.h" |
|
32 #include "ncddatabasestorage.h" |
|
33 #include "ncdproviderdefines.h" |
|
34 #include "ncdstorageclient.h" |
|
35 #include "ncdstorageitem.h" |
|
36 #include "catalogsconstants.h" |
|
37 #include "ncdnodeidentifierutils.h" |
|
38 |
|
39 #include "catalogsdebug.h" |
|
40 |
|
41 CNcdNodeDbManager::CNcdNodeDbManager( |
|
42 MNcdStorageManager& aStorageManager ) |
|
43 : CBase(), |
|
44 iStorageManager( aStorageManager ) |
|
45 { |
|
46 DLTRACEIN(("")); |
|
47 |
|
48 DLTRACEOUT(("")); |
|
49 } |
|
50 |
|
51 void CNcdNodeDbManager::ConstructL() |
|
52 { |
|
53 DLTRACEIN(("")); |
|
54 |
|
55 DLTRACEOUT(("")); |
|
56 } |
|
57 |
|
58 CNcdNodeDbManager* CNcdNodeDbManager::NewL( |
|
59 MNcdStorageManager& aStorageManager ) |
|
60 { |
|
61 CNcdNodeDbManager* self = |
|
62 CNcdNodeDbManager::NewLC( aStorageManager ); |
|
63 CleanupStack::Pop( self ); |
|
64 return self; |
|
65 } |
|
66 |
|
67 CNcdNodeDbManager* CNcdNodeDbManager::NewLC( |
|
68 MNcdStorageManager& aStorageManager ) |
|
69 { |
|
70 CNcdNodeDbManager* self = |
|
71 new( ELeave ) CNcdNodeDbManager( aStorageManager ); |
|
72 CleanupStack::PushL( self ); |
|
73 self->ConstructL(); |
|
74 return self; |
|
75 } |
|
76 |
|
77 |
|
78 CNcdNodeDbManager::~CNcdNodeDbManager() |
|
79 { |
|
80 DLTRACEIN(("")); |
|
81 |
|
82 // Do not delete storage manager here because it is not owned |
|
83 // by this class object. |
|
84 DLTRACEOUT(("")); |
|
85 } |
|
86 |
|
87 |
|
88 |
|
89 // Database info functions |
|
90 |
|
91 // --------------------------------------------------------------------------- |
|
92 // StorageSizeL |
|
93 // --------------------------------------------------------------------------- |
|
94 // |
|
95 TInt CNcdNodeDbManager::StorageSizeL( const TUid& aClientUid, |
|
96 const MDesCArray& aSkipNamespaces ) |
|
97 { |
|
98 DLTRACEIN(("")); |
|
99 DPROFILING_BEGIN( x ); |
|
100 TInt size( 0 ); |
|
101 |
|
102 // Get the namespaces from the storage of the given client and insert |
|
103 // the namespace array to the cleanup stack. Notice that the array items |
|
104 // are deleted when the array is deleted. |
|
105 MNcdStorageClient& client = iStorageManager.StorageClientL( aClientUid.Name() ); |
|
106 MDesCArray* namespaces = client.NamespacesLC(); |
|
107 |
|
108 // Temporary variables for the loop |
|
109 TPtrC clientNamespace; |
|
110 TBool doNotSkip( ETrue ); |
|
111 |
|
112 // Start to remove all the possible namespaces from the client. |
|
113 for ( TInt i = 0; i < namespaces->MdcaCount(); ++i ) |
|
114 { |
|
115 doNotSkip = ETrue; |
|
116 clientNamespace.Set( namespaces->MdcaPoint( i ) ); |
|
117 |
|
118 // Check if this namespace should be skipped because its content |
|
119 // is not wanted to be part of the size info. |
|
120 for ( TInt j = 0; j < aSkipNamespaces.MdcaCount(); ++j ) |
|
121 { |
|
122 if ( clientNamespace == aSkipNamespaces.MdcaPoint( j ) ) |
|
123 { |
|
124 DLINFO(("Skip namespace")); |
|
125 // This namespace should be skipped. |
|
126 doNotSkip = EFalse; |
|
127 break; |
|
128 } |
|
129 } |
|
130 if ( doNotSkip ) |
|
131 { |
|
132 DLINFO(("Add namespace size")); |
|
133 // This size increase should not be skipped. So, add the size to the total. |
|
134 // Storage will contains the data of the client identified by its UID |
|
135 // The identifier id can be empty when creating storage. Only, |
|
136 // namespace and uid are actually used. |
|
137 CNcdNodeIdentifier* storageIdentifier = |
|
138 CNcdNodeIdentifier::NewLC( clientNamespace, KNullDesC, aClientUid ); |
|
139 MNcdStorage& storage = StorageL( *storageIdentifier ); |
|
140 CleanupStack::PopAndDestroy( storageIdentifier ); |
|
141 |
|
142 size += storage.SizeL(); |
|
143 } |
|
144 } |
|
145 |
|
146 CleanupStack::PopAndDestroy( namespaces ); |
|
147 DPROFILING_END( x ); |
|
148 DLTRACEOUT(("Storage size: %d", size)); |
|
149 |
|
150 return size; |
|
151 } |
|
152 |
|
153 |
|
154 // Database read functions |
|
155 |
|
156 // --------------------------------------------------------------------------- |
|
157 // ReadFromDatabaseL |
|
158 // --------------------------------------------------------------------------- |
|
159 // |
|
160 HBufC8* CNcdNodeDbManager::ReadDataFromDatabaseL( |
|
161 const CNcdNodeIdentifier& aIdentifier, |
|
162 const NcdNodeClassIds::TNcdNodeClassType aClassType ) |
|
163 { |
|
164 DLTRACEIN(("")); |
|
165 |
|
166 HBufC8* ret( ReadDataFromDatabaseLC( aIdentifier, |
|
167 aClassType ) ); |
|
168 if ( ret != NULL ) |
|
169 { |
|
170 CleanupStack::Pop( ret ); |
|
171 } |
|
172 |
|
173 DLTRACEOUT(("")); |
|
174 return ret; |
|
175 } |
|
176 |
|
177 // --------------------------------------------------------------------------- |
|
178 // ReadFromDatabaseLC |
|
179 // --------------------------------------------------------------------------- |
|
180 // |
|
181 HBufC8* CNcdNodeDbManager::ReadDataFromDatabaseLC( |
|
182 const CNcdNodeIdentifier& aIdentifier, |
|
183 const NcdNodeClassIds::TNcdNodeClassType aClassType ) |
|
184 { |
|
185 DLTRACEIN(("")); |
|
186 DPROFILING_BEGIN( x ); |
|
187 DASSERT( !aIdentifier.ContainsEmptyFields() ); |
|
188 |
|
189 // Storage will contains the data of the client identified by its UID |
|
190 MNcdStorage& storage = StorageL( aIdentifier ); |
|
191 |
|
192 // NOTE: this creates the database if it does not already exist. |
|
193 MNcdDatabaseStorage& database = |
|
194 storage.DatabaseStorageL( NcdProviderDefines::KDefaultDatabaseUid ); |
|
195 |
|
196 // Get the storage item from which the node is loaded |
|
197 // Note: database has the ownership of the item |
|
198 MNcdStorageItem* item = |
|
199 database.StorageItemL( aIdentifier.NodeId(), |
|
200 aClassType ); |
|
201 |
|
202 DLINFO(("Get data")); |
|
203 HBufC8* data = item->GetDataLC(); |
|
204 |
|
205 DLTRACEOUT(("Returning data, length: %d", data->Length())); |
|
206 DPROFILING_END( x ); |
|
207 return data; |
|
208 } |
|
209 |
|
210 |
|
211 // --------------------------------------------------------------------------- |
|
212 // StartStorageLoadActionL |
|
213 // --------------------------------------------------------------------------- |
|
214 // |
|
215 void CNcdNodeDbManager::StartStorageLoadActionL( |
|
216 const CNcdNodeIdentifier& aIdentifier, |
|
217 MNcdStorageDataItem& aDataItem, |
|
218 const NcdNodeClassIds::TNcdNodeClassType aClassType ) |
|
219 { |
|
220 DLTRACEIN(("")); |
|
221 DPROFILING_BEGIN( x ); |
|
222 if( aIdentifier.ContainsEmptyFields() ) |
|
223 { |
|
224 DLERROR(("Empty identifier fields given")); |
|
225 |
|
226 // For debugging purposes |
|
227 DASSERT( EFalse ); |
|
228 |
|
229 User::Leave( KErrArgument ); |
|
230 } |
|
231 |
|
232 // Here we will get the data from the storage according |
|
233 // to the namespace and data id information. Also, class id |
|
234 // is used to define the type of the data that is searched. |
|
235 |
|
236 // The type of the data should be gotten from the first four bytes (TInt32) |
|
237 // of the stream when the Internalize function of the data item is called |
|
238 // from the storage handler. |
|
239 |
|
240 // Storage will contains the data of the client identified by its UID |
|
241 MNcdStorage& storage = StorageL( aIdentifier ); |
|
242 |
|
243 // NOTE: If db does not already exist, |
|
244 // this creates one into the storage. |
|
245 MNcdDatabaseStorage& database = |
|
246 storage.DatabaseStorageL( NcdProviderDefines::KDefaultDatabaseUid ); |
|
247 |
|
248 // Ensure the node exists in the database |
|
249 |
|
250 if( !database.ItemExistsInStorageL( aIdentifier.NodeId(), |
|
251 aClassType ) ) |
|
252 { |
|
253 DLINFO(("Data was not in namespace")); |
|
254 User::Leave( KErrNotFound ); |
|
255 } |
|
256 |
|
257 // Get the storage item from which the node is loaded |
|
258 // Note: database has the ownership of the item |
|
259 MNcdStorageItem* item = |
|
260 database.StorageItemL( aIdentifier.NodeId(), |
|
261 aClassType ); |
|
262 |
|
263 // Get data from database by using aDataItem as the target so that |
|
264 // internalize will be called for it |
|
265 item->SetDataItem( &aDataItem ); |
|
266 |
|
267 // Read node data -> calls InternalizeL of aDataItem |
|
268 item->ReadDataL(); |
|
269 DPROFILING_END( x ); |
|
270 DLTRACEOUT(("Item IsOpen: %d", item->IsOpen() )); |
|
271 } |
|
272 |
|
273 |
|
274 // --------------------------------------------------------------------------- |
|
275 // GetAllClientItemIdentifiersL |
|
276 // --------------------------------------------------------------------------- |
|
277 // |
|
278 void CNcdNodeDbManager::GetAllClientItemIdentifiersL( |
|
279 RPointerArray<CNcdNodeIdentifier>& aItemIdentifiers, |
|
280 const TUid& aClientUid, |
|
281 const MDesCArray& aSkipNamespaces, |
|
282 const RArray<NcdNodeClassIds::TNcdNodeClassType>& aAcceptClassTypes ) |
|
283 { |
|
284 DLTRACEIN(("")); |
|
285 DPROFILING_BEGIN( x ); |
|
286 // This temporary array is used for the items that are gotten from |
|
287 // the storages. |
|
288 // Insert it into the cleanup stack to be sure that the array is closed |
|
289 // if leave occurs.No need to worry about deleting array items here. |
|
290 // They are owned by the storage. |
|
291 RPointerArray<MNcdStorageItem> tmpItemArray; |
|
292 CleanupClosePushL( tmpItemArray ); |
|
293 |
|
294 // Get all the namespaces of the client. Notice that the namespaces are |
|
295 // deleted from the array when the array is deleted. |
|
296 MNcdStorageClient& client = |
|
297 iStorageManager.StorageClientL( aClientUid.Name() ); |
|
298 MDesCArray* namespaces = client.NamespacesLC(); |
|
299 |
|
300 // Temporary variables that are used in the loops. |
|
301 TPtrC clientNamespace; |
|
302 TBool doNotSkip( ETrue ); |
|
303 MNcdStorageItem* tmpItem( NULL ); |
|
304 CNcdNodeIdentifier* tmpItemIdentifier( NULL ); |
|
305 |
|
306 // Start to remove all the possible namespaces from the client. |
|
307 for ( TInt i = 0; i < namespaces->MdcaCount(); ++i ) |
|
308 { |
|
309 doNotSkip = ETrue; |
|
310 clientNamespace.Set( namespaces->MdcaPoint( i ) ); |
|
311 |
|
312 // Check if this namespace should be skipped. |
|
313 for ( TInt j = 0; j < aSkipNamespaces.MdcaCount(); ++j ) |
|
314 { |
|
315 if ( clientNamespace == aSkipNamespaces.MdcaPoint( j ) ) |
|
316 { |
|
317 DLINFO(("Skip namespace")); |
|
318 // This namespace should be skipped |
|
319 doNotSkip = EFalse; |
|
320 break; |
|
321 } |
|
322 } |
|
323 |
|
324 if ( doNotSkip ) |
|
325 { |
|
326 DLINFO(("Did not skip namespace")); |
|
327 // This namespace should not be skipped. So, do your thing. |
|
328 |
|
329 // Storage will contains the data of the client identified by its UID |
|
330 // The identifier id can be empty when creating storage. Only, |
|
331 // namespace and uid are actually used. |
|
332 CNcdNodeIdentifier* storageIdentifier = |
|
333 CNcdNodeIdentifier::NewLC( clientNamespace, KNullDesC, aClientUid ); |
|
334 MNcdStorage& storage = StorageL( *storageIdentifier ); |
|
335 CleanupStack::PopAndDestroy( storageIdentifier ); |
|
336 |
|
337 // NOTE: If db does not already exist, |
|
338 // this creates one into the storage. |
|
339 MNcdDatabaseStorage& database = |
|
340 storage.DatabaseStorageL( NcdProviderDefines::KDefaultDatabaseUid ); |
|
341 |
|
342 // Now get all the items from the db storage. |
|
343 // Notice that the tmpItemArray will not own the items, but they |
|
344 // are owned by the database. |
|
345 database.StorageItemsL( tmpItemArray ); |
|
346 |
|
347 DLINFO(("tmpItemArrayCount: %d", tmpItemArray.Count())); |
|
348 TInt count = tmpItemArray.Count(); |
|
349 while ( count-- ) |
|
350 { |
|
351 // Move the item info from tmpItemArray into the return array. |
|
352 tmpItem = tmpItemArray [ count ]; |
|
353 for ( TInt m = 0; m < aAcceptClassTypes.Count(); ++m ) |
|
354 { |
|
355 if ( tmpItem->Type() == aAcceptClassTypes[ m ] ) |
|
356 { |
|
357 tmpItemIdentifier = |
|
358 CNcdNodeIdentifier::NewLC( clientNamespace, |
|
359 tmpItem->Uid(), |
|
360 aClientUid ); |
|
361 |
|
362 aItemIdentifiers.AppendL( tmpItemIdentifier ); |
|
363 |
|
364 CleanupStack::Pop( tmpItemIdentifier ); |
|
365 |
|
366 tmpItemIdentifier = NULL; |
|
367 break; |
|
368 } |
|
369 } |
|
370 // Notice that the item array does not own the |
|
371 // items. So, do not delete them but only remove them |
|
372 // from the array. |
|
373 tmpItemArray.Remove( count ); |
|
374 } |
|
375 } |
|
376 } |
|
377 |
|
378 // Deletes the array and its items |
|
379 CleanupStack::PopAndDestroy( namespaces ); |
|
380 |
|
381 // Closes the array but does not delete items because the items |
|
382 // are not owned by this array. |
|
383 CleanupStack::PopAndDestroy( &tmpItemArray ); |
|
384 DPROFILING_END( x ); |
|
385 DLTRACEOUT(("Items load ok.")); |
|
386 } |
|
387 |
|
388 |
|
389 |
|
390 // Database write functions |
|
391 |
|
392 // --------------------------------------------------------------------------- |
|
393 // SaveDataIntoDatabaseL |
|
394 // --------------------------------------------------------------------------- |
|
395 // |
|
396 void CNcdNodeDbManager::SaveDataIntoDatabaseL( |
|
397 const CNcdNodeIdentifier& aIdentifier, |
|
398 MNcdStorageDataItem& aDataItem, |
|
399 const NcdNodeClassIds::TNcdNodeClassType aClassType ) |
|
400 { |
|
401 DLTRACEIN(("")); |
|
402 DPROFILING_BEGIN( x ); |
|
403 if( aIdentifier.ContainsEmptyFields() ) |
|
404 { |
|
405 DLERROR(("Empty identifier fields given")); |
|
406 |
|
407 // For debugging purposes |
|
408 DASSERT( EFalse ); |
|
409 |
|
410 User::Leave( KErrArgument ); |
|
411 } |
|
412 |
|
413 // Storage will contains the data of the client identified by its UID |
|
414 MNcdStorage& storage = StorageL( aIdentifier ); |
|
415 |
|
416 // NOTE: If db does not already exist, |
|
417 // this creates one into the storage. |
|
418 MNcdDatabaseStorage& database = |
|
419 storage.DatabaseStorageL( NcdProviderDefines::KDefaultDatabaseUid ); |
|
420 |
|
421 // Get/create the storage item where the data is saved |
|
422 // Note: database has the ownership of the item |
|
423 MNcdStorageItem* storageItem = |
|
424 database.StorageItemL( aIdentifier.NodeId(), |
|
425 aClassType ); |
|
426 |
|
427 // Here call the storage functions that will handle |
|
428 // the saving of the data |
|
429 |
|
430 // Save new item to database |
|
431 storageItem->SetDataItem( &aDataItem ); |
|
432 storageItem->OpenL(); |
|
433 |
|
434 // Calls ExternalizeL for data item |
|
435 storageItem->WriteDataL(); |
|
436 |
|
437 // Save the data to the database. |
|
438 // The data object implements MNcdStorageDataItem interface. |
|
439 // So, the externalize function will insert the data to the stream |
|
440 // that the database handler will save to the database. |
|
441 storageItem->SaveL(); |
|
442 DPROFILING_END( x ); |
|
443 DLTRACEOUT(("")); |
|
444 } |
|
445 |
|
446 |
|
447 |
|
448 // Database remove functions |
|
449 |
|
450 // --------------------------------------------------------------------------- |
|
451 // RemoveDataFromDatabaseL |
|
452 // --------------------------------------------------------------------------- |
|
453 // |
|
454 void CNcdNodeDbManager::RemoveDataFromDatabaseL( |
|
455 const CNcdNodeIdentifier& aIdentifier, |
|
456 const NcdNodeClassIds::TNcdNodeClassType aClassType ) |
|
457 { |
|
458 DLTRACEIN(("")); |
|
459 DPROFILING_BEGIN( x ); |
|
460 if( aIdentifier.ContainsEmptyFields() ) |
|
461 { |
|
462 DLERROR(("Empty identifier fields given")); |
|
463 DASSERT( EFalse ); |
|
464 User::Leave( KErrArgument ); |
|
465 } |
|
466 |
|
467 // Storage will contains the data of the client identified by its UID |
|
468 MNcdStorage& storage = StorageL( aIdentifier ); |
|
469 |
|
470 // NOTE: If db does not already exist, |
|
471 // this creates one into the storage. |
|
472 MNcdDatabaseStorage& database = |
|
473 storage.DatabaseStorageL( NcdProviderDefines::KDefaultDatabaseUid ); |
|
474 |
|
475 // Get/create the storage item where the data is saved |
|
476 // Note: database has the ownership of the item. |
|
477 MNcdStorageItem* storageItem = |
|
478 database.StorageItemL( aIdentifier.NodeId(), aClassType ); |
|
479 |
|
480 // Remove the item from the storage |
|
481 storageItem->RemoveFromStorageL(); |
|
482 |
|
483 // Make the removing happen. |
|
484 database.CommitL(); |
|
485 DPROFILING_END( x ); |
|
486 DLTRACEOUT(("")); |
|
487 } |
|
488 |
|
489 |
|
490 // --------------------------------------------------------------------------- |
|
491 // RemoveDataFromDatabaseL |
|
492 // --------------------------------------------------------------------------- |
|
493 // |
|
494 void CNcdNodeDbManager::RemoveDataFromDatabaseL( |
|
495 const RPointerArray<CNcdNodeIdentifier>& aIdentifiers, |
|
496 const RArray<NcdNodeClassIds::TNcdNodeClassType>& aClassTypes, |
|
497 TBool aCompact ) |
|
498 { |
|
499 DLTRACEIN(("")); |
|
500 DPROFILING_BEGIN( x ); |
|
501 CNcdNodeIdentifier* identifier( NULL ); |
|
502 |
|
503 TPtrC currentNamespace; |
|
504 TInt i = 0; |
|
505 const TInt count = aIdentifiers.Count(); |
|
506 const TInt classCount = aClassTypes.Count(); |
|
507 while( i < count ) |
|
508 { |
|
509 identifier = aIdentifiers[ i ]; |
|
510 if( identifier == NULL |
|
511 || identifier->ContainsEmptyFields() ) |
|
512 { |
|
513 DLERROR(("NULL identifier or empty identifier fields given")); |
|
514 DASSERT( EFalse ); |
|
515 User::Leave( KErrArgument ); |
|
516 } |
|
517 |
|
518 currentNamespace.Set( identifier->NodeNameSpace() ); |
|
519 // Storage will contains the data of the client identified by its UID |
|
520 MNcdStorage& storage = StorageL( *identifier ); |
|
521 |
|
522 // NOTE: If db does not already exist, |
|
523 // this creates one into the storage. |
|
524 MNcdDatabaseStorage& database = |
|
525 storage.DatabaseStorageL( NcdProviderDefines::KDefaultDatabaseUid ); |
|
526 |
|
527 for ( ; i < count && |
|
528 currentNamespace == aIdentifiers[ i ]->NodeNameSpace(); ++i ) |
|
529 { |
|
530 identifier = aIdentifiers[ i ]; |
|
531 for ( TInt j = 0; j < classCount; ++j ) |
|
532 { |
|
533 // Get/create the storage item where the data is saved |
|
534 // Note: database has the ownership of the item. |
|
535 MNcdStorageItem* storageItem = |
|
536 database.StorageItemL( identifier->NodeId(), aClassTypes[ j ] ); |
|
537 |
|
538 // Remove the item from the storage |
|
539 storageItem->RemoveFromStorageL(); |
|
540 } |
|
541 } |
|
542 |
|
543 // Commit & compact or just commit |
|
544 if ( aCompact ) |
|
545 { |
|
546 database.Compact(); |
|
547 } |
|
548 else |
|
549 { |
|
550 database.CommitL(); |
|
551 } |
|
552 } |
|
553 DPROFILING_END( x ); |
|
554 DLTRACEOUT(("")); |
|
555 } |
|
556 |
|
557 |
|
558 // --------------------------------------------------------------------------- |
|
559 // RemoveDataFromDatabaseL |
|
560 // --------------------------------------------------------------------------- |
|
561 // |
|
562 void CNcdNodeDbManager::RemoveDataFromDatabaseL( |
|
563 const CNcdNodeIdentifier& aNodeIdentifier, |
|
564 const RArray<RNcdDatabaseItems>& aDoNotRemoveItems ) |
|
565 { |
|
566 DLTRACEIN(("")); |
|
567 DPROFILING_BEGIN( x ); |
|
568 // Storage will contain the data of the client identified by its UID |
|
569 // and node's namespace |
|
570 MNcdStorage& storage = StorageL( aNodeIdentifier ); |
|
571 |
|
572 // NOTE: If db does not already exist, |
|
573 // this creates one into the storage. |
|
574 MNcdDatabaseStorage& database = |
|
575 storage.DatabaseStorageL( NcdProviderDefines::KDefaultDatabaseUid ); |
|
576 |
|
577 DLTRACE(("Removing from database")); |
|
578 // commits and compacts data |
|
579 database.RemoveItemsL( aDoNotRemoveItems ); |
|
580 DPROFILING_END( x ); |
|
581 } |
|
582 |
|
583 |
|
584 // --------------------------------------------------------------------------- |
|
585 // ClearClientL |
|
586 // --------------------------------------------------------------------------- |
|
587 // |
|
588 void CNcdNodeDbManager::ClearClientL( const TUid& aClientUid, |
|
589 const MDesCArray& aSkipNamespaces ) |
|
590 { |
|
591 DLTRACEIN(("")); |
|
592 DPROFILING_BEGIN( x ); |
|
593 // Get the namespaces of the given client. |
|
594 // The namespaces are inserted into the array. Notice that the items in array |
|
595 // are deleted when the array is deleted. |
|
596 MNcdStorageClient& client = iStorageManager.StorageClientL( aClientUid.Name() ); |
|
597 MDesCArray* namespaces = client.NamespacesLC(); |
|
598 |
|
599 // Temporary variables for the array. |
|
600 TPtrC clientNamespace; |
|
601 TBool doNotSkip( ETrue ); |
|
602 |
|
603 // Start to remove all the possible namespaces from the client. |
|
604 for ( TInt i = 0; i < namespaces->MdcaCount(); ++i ) |
|
605 { |
|
606 doNotSkip = ETrue; |
|
607 clientNamespace.Set( namespaces->MdcaPoint( i ) ); |
|
608 |
|
609 // Check if this namespace should be skipped. |
|
610 for ( TInt j = 0; j < aSkipNamespaces.MdcaCount(); ++j ) |
|
611 { |
|
612 if ( clientNamespace == aSkipNamespaces.MdcaPoint( j ) ) |
|
613 { |
|
614 DLINFO(("Skip namespace")); |
|
615 // This namespace should be skipped and not removed. |
|
616 doNotSkip = EFalse; |
|
617 break; |
|
618 } |
|
619 } |
|
620 if ( doNotSkip ) |
|
621 { |
|
622 DLINFO((_L("Remove namespace: %S"), |
|
623 &clientNamespace)); |
|
624 // This removal should not be skipped. So, remove. |
|
625 client.RemoveStorageL( clientNamespace ); |
|
626 } |
|
627 } |
|
628 |
|
629 CleanupStack::PopAndDestroy( namespaces ); |
|
630 DPROFILING_END( x ); |
|
631 DLTRACEOUT(("Client cleared")); |
|
632 } |
|
633 |
|
634 |
|
635 // Misc functions |
|
636 |
|
637 // --------------------------------------------------------------------------- |
|
638 // StorageL |
|
639 // --------------------------------------------------------------------------- |
|
640 // |
|
641 MNcdStorage& CNcdNodeDbManager::StorageL( |
|
642 const CNcdNodeIdentifier& aIdentifier ) const |
|
643 { |
|
644 DLTRACEIN(("")); |
|
645 DPROFILING_BEGIN( x ); |
|
646 // This function needs the namespace and uid information. |
|
647 // So, check them. Id can be empty because it is not used here. |
|
648 if( aIdentifier.NodeNameSpace() == KNullDesC |
|
649 || aIdentifier.ClientUid() == TUid::Null() ) |
|
650 { |
|
651 DLERROR(("Empty ns or uid fields given")); |
|
652 |
|
653 User::Leave( KErrArgument ); |
|
654 } |
|
655 |
|
656 DLINFO(("Identifier was not empty")); |
|
657 |
|
658 return iStorageManager.CreateOrGetStorageL( |
|
659 aIdentifier.ClientUid().Name(), |
|
660 aIdentifier.NodeNameSpace() ); |
|
661 } |
|
662 |