ncdengine/provider/storage/src/ncdstoragebase.cpp
changeset 4 32704c33136d
equal deleted inserted replaced
-1:000000000000 4:32704c33136d
       
     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 "ncdstoragebase.h"
       
    20 
       
    21 #include <s32buf.h>
       
    22 
       
    23 #include "ncddatabasestorageimpl.h"
       
    24 #include "ncdstoragedataitem.h"
       
    25 #include "ncdstoragepanics.pan"
       
    26 #include "catalogsutils.h"
       
    27 
       
    28 #include "catalogsdebug.h"
       
    29 
       
    30 
       
    31 // ---------------------------------------------------------------------------
       
    32 // 
       
    33 // ---------------------------------------------------------------------------
       
    34 //
       
    35 CNcdStorageBase::~CNcdStorageBase()
       
    36     {
       
    37     DLTRACEIN(( "" ));
       
    38     delete iUid;
       
    39     delete iStorageFolder;
       
    40     delete iName;
       
    41     iOpenItems.Reset();
       
    42     iRemovedItems.Reset();
       
    43     iItems.ResetAndDestroy();
       
    44     }
       
    45 
       
    46 
       
    47 // ---------------------------------------------------------------------------
       
    48 // 
       
    49 // ---------------------------------------------------------------------------
       
    50 //
       
    51 CNcdStorageBase::CNcdStorageBase( HBufC* aUid, HBufC* aStorageFolder, 
       
    52         HBufC* aName ) :
       
    53     iUid( aUid ),
       
    54     iStorageFolder( aStorageFolder ),
       
    55     iName( aName ),
       
    56     iOpen( EFalse ),
       
    57     iListener( NULL )
       
    58     {
       
    59     }
       
    60 
       
    61 
       
    62 // ---------------------------------------------------------------------------
       
    63 // 
       
    64 // ---------------------------------------------------------------------------
       
    65 //
       
    66 CNcdStorageBase* CNcdStorageBase::NewL(
       
    67     RFs& aFs,
       
    68     const TDesC& aUid,
       
    69     const TDesC& aStorageFolder,
       
    70     const TDesC& aStorageName )
       
    71     {
       
    72     DLTRACE( ( _L("Path: %S"), &aStorageFolder ) );
       
    73     CNcdStorageBase* storage = 
       
    74         storage = CNcdDatabaseStorage::NewL( 
       
    75             aFs, aUid, aStorageFolder, 
       
    76             aStorageName ); 
       
    77 
       
    78     return storage;
       
    79     }
       
    80 
       
    81 
       
    82 // ---------------------------------------------------------------------------
       
    83 // 
       
    84 // ---------------------------------------------------------------------------
       
    85 //
       
    86 const TDesC& CNcdStorageBase::Uid() const
       
    87     {
       
    88     DASSERT( iUid );
       
    89     DLTRACE( ( _L("Uid: %S"), iUid ) );
       
    90     
       
    91     return *iUid;
       
    92     }
       
    93 
       
    94 // ---------------------------------------------------------------------------
       
    95 // 
       
    96 // ---------------------------------------------------------------------------
       
    97 //
       
    98 const TDesC& CNcdStorageBase::StorageFolder() const
       
    99     {
       
   100     DASSERT( iStorageFolder );
       
   101     return *iStorageFolder;
       
   102     }
       
   103 
       
   104 // ---------------------------------------------------------------------------
       
   105 // 
       
   106 // ---------------------------------------------------------------------------
       
   107 //
       
   108 const TDesC& CNcdStorageBase::Name() const
       
   109     {
       
   110     DASSERT( iName );
       
   111     return *iName;
       
   112     }
       
   113 
       
   114 
       
   115 // ---------------------------------------------------------------------------
       
   116 // 
       
   117 // ---------------------------------------------------------------------------
       
   118 //
       
   119 TInt CNcdStorageBase::Open()
       
   120     {
       
   121     DLTRACEIN(("this: %x", this));
       
   122     if( IsOpen() )
       
   123         {
       
   124         User::Panic( KNcdStoragePanic, ENcdStoragePanicAlreadyOpen );
       
   125         }
       
   126     
       
   127     TRAPD( err, DoOpenL() );
       
   128 
       
   129     if( err == KErrNone )
       
   130         {
       
   131         iOpen = ETrue;
       
   132         }
       
   133 
       
   134     return err;
       
   135     }
       
   136 
       
   137 
       
   138 // ---------------------------------------------------------------------------
       
   139 // 
       
   140 // ---------------------------------------------------------------------------
       
   141 //
       
   142 void CNcdStorageBase::Close()
       
   143     {
       
   144     DLTRACEIN(("this: %x", this));
       
   145     if( IsOpen() )
       
   146         {
       
   147         DoClose();
       
   148         iOpen = EFalse;
       
   149         }
       
   150 
       
   151     }
       
   152 
       
   153 
       
   154 // ---------------------------------------------------------------------------
       
   155 // 
       
   156 // ---------------------------------------------------------------------------
       
   157 //
       
   158 TBool CNcdStorageBase::IsOpen() const
       
   159     {
       
   160     return iOpen;
       
   161     }
       
   162 
       
   163 
       
   164 // ---------------------------------------------------------------------------
       
   165 // 
       
   166 // ---------------------------------------------------------------------------
       
   167 //
       
   168 CNcdStorageItem* CNcdStorageBase::StorageItemL( const TDesC& aUid, TInt aType )
       
   169     {
       
   170     DLTRACEIN( (_L("aUid: %S, aType: %d"), &aUid, aType ) );
       
   171     DPROFILING_BEGIN( x );
       
   172     CNcdStorageItem* item = FindStorageItem( aUid, aType );
       
   173 
       
   174     if ( !item )
       
   175         {
       
   176         TRAPD( err,
       
   177             {
       
   178             // Create item
       
   179             item = CreateStorageItemLC( aUid, aType );            
       
   180 
       
   181             // Store item to array
       
   182             iItems.InsertInAddressOrderL( item );
       
   183             DLTRACE(("Items: %d", iItems.Count() ));
       
   184             CleanupStack::Pop( item );
       
   185             });
       
   186 
       
   187         if( err == KErrNone )
       
   188             {
       
   189             iListener->CacheOpened();
       
   190             TRAP( err, iListener->CacheReadyL() );
       
   191             }
       
   192 
       
   193         if( err != KErrNone )
       
   194             {
       
   195             if( !ItemsOpen() )
       
   196                 {
       
   197                 DoRollback();
       
   198                 }
       
   199 
       
   200             User::Leave( err );
       
   201             }
       
   202         }
       
   203 
       
   204     DPROFILING_END( x );
       
   205     DLTRACEOUT((""));
       
   206     return item;
       
   207     }
       
   208 
       
   209 
       
   210 // ---------------------------------------------------------------------------
       
   211 // 
       
   212 // ---------------------------------------------------------------------------
       
   213 //
       
   214 void CNcdStorageBase::StorageItemsL( RPointerArray<MNcdStorageItem>& aItems )
       
   215     {
       
   216     RPointerArray<CNcdStorageItemIdentifier> items;
       
   217     CleanupResetAndDestroyPushL( items );
       
   218 
       
   219     // Get storage item identifiers from storage
       
   220     GetAllItemsFromStorageL( items );
       
   221 
       
   222     // Get storage items
       
   223     TInt count = items.Count();
       
   224     aItems.ReserveL( aItems.Count() + count );
       
   225     
       
   226     for( TInt i = 0; i < count; i++ )
       
   227         {
       
   228         aItems.AppendL( StorageItemL( items[i]->Id(), items[i]->Type() ) );
       
   229         }
       
   230 
       
   231     CleanupStack::PopAndDestroy( &items );    
       
   232     }
       
   233 
       
   234 
       
   235 // ---------------------------------------------------------------------------
       
   236 // 
       
   237 // ---------------------------------------------------------------------------
       
   238 //
       
   239 void CNcdStorageBase::RemoveItemsL( 
       
   240     const RArray<RNcdDatabaseItems>& aDoNotRemoveItems )
       
   241     {
       
   242     DLTRACEIN((""));
       
   243     DoRemoveItemsL( aDoNotRemoveItems );
       
   244     
       
   245     // reset arrays so that removed items are not left hanging aroung
       
   246     iOpenItems.Reset();
       
   247     iRemovedItems.Reset();
       
   248     iItems.ResetAndDestroy();
       
   249     }
       
   250 
       
   251 
       
   252 
       
   253 // ---------------------------------------------------------------------------
       
   254 // 
       
   255 // ---------------------------------------------------------------------------
       
   256 //
       
   257 void CNcdStorageBase::OpenItemL( CNcdStorageItem* aItem )
       
   258     {
       
   259     DLTRACEIN(("this: %x", this));
       
   260     iOpenItems.ReserveL( iOpenItems.Count() + 1 );
       
   261 
       
   262     DoOpenItemL( aItem );
       
   263 
       
   264     // Same item can't be opened multiple times (CNcdStorageItem::OpenL)
       
   265     // so we don't have to worry about adding it many times to the open item
       
   266     // array. Also we can't run out of memory because we already reserved 
       
   267     // memory for the item so we can ignore the error
       
   268     iOpenItems.InsertInAddressOrder( aItem );
       
   269     
       
   270     if( iListener && iOpenItems.Count() == 1 )
       
   271         {
       
   272         iListener->CacheOpened();
       
   273         }
       
   274     }
       
   275 
       
   276 
       
   277 // ---------------------------------------------------------------------------
       
   278 // 
       
   279 // ---------------------------------------------------------------------------
       
   280 //
       
   281 void CNcdStorageBase::SaveItemL( CNcdStorageItem* aItem )
       
   282     {
       
   283     DLTRACEIN(("this: %x", this));
       
   284     TInt index = iOpenItems.FindInAddressOrder( aItem );
       
   285 
       
   286     if( index < 0 )
       
   287         {
       
   288         User::Panic( KNcdStoragePanic, ENcdStoragePanicItemNotOpen );
       
   289         }
       
   290 
       
   291     iOpenItems.Remove( index );
       
   292 
       
   293     if( iListener && iOpenItems.Count() == 0 )
       
   294         {
       
   295         iListener->CacheReadyL();
       
   296         }
       
   297     }
       
   298 
       
   299 
       
   300 // ---------------------------------------------------------------------------
       
   301 // 
       
   302 // ---------------------------------------------------------------------------
       
   303 //
       
   304 void CNcdStorageBase::RollbackItems()
       
   305     {
       
   306     DLTRACEIN((""));
       
   307     Rollback();
       
   308 
       
   309     iListener->NotifyRollback();
       
   310     }
       
   311 
       
   312 
       
   313 // ---------------------------------------------------------------------------
       
   314 // 
       
   315 // ---------------------------------------------------------------------------
       
   316 //
       
   317 TInt CNcdStorageBase::Commit()
       
   318     {
       
   319     DLTRACEIN((""));
       
   320     TInt err = DoCommit();
       
   321 
       
   322     if( err == KErrNone )
       
   323         {
       
   324         TInt count = iRemovedItems.Count();
       
   325         TInt index = 0;
       
   326         for( TInt i = 0; i < count; i++ )
       
   327             {
       
   328             index = iItems.FindInAddressOrder( iRemovedItems[i] );
       
   329             if( index >= 0 )
       
   330                 {
       
   331                 iItems.Remove( index );
       
   332                 }
       
   333             DLTRACE(("Items: %d", iItems.Count() ));
       
   334             delete iRemovedItems[i];
       
   335             iRemovedItems[i] = NULL;
       
   336             }
       
   337         }
       
   338 
       
   339     iRemovedItems.Reset();    
       
   340     return err;
       
   341     }
       
   342 
       
   343 
       
   344 // ---------------------------------------------------------------------------
       
   345 // 
       
   346 // ---------------------------------------------------------------------------
       
   347 //
       
   348 void CNcdStorageBase::RemoveItemL( CNcdStorageItem* aItem )
       
   349     {
       
   350     DLTRACEIN(("this: %x", this));
       
   351     TInt insertError( iRemovedItems.InsertInAddressOrder( aItem ) );
       
   352     if ( insertError == KErrAlreadyExists )
       
   353         {
       
   354         DLINFO(("Remove item was already in the array."));
       
   355         return;
       
   356         }
       
   357     User::LeaveIfError( insertError );
       
   358 
       
   359     TRAPD( err, DoRemoveItemL( aItem ) );
       
   360 
       
   361     if( err != KErrNone )
       
   362         {
       
   363         TInt index = iRemovedItems.FindInAddressOrder( aItem );
       
   364         if( index >= 0 )
       
   365             {
       
   366             iRemovedItems.Remove( index );
       
   367             }
       
   368         DLERROR(("Error: %d occurred when removing", err));
       
   369         User::Leave( err );
       
   370         }
       
   371     }
       
   372 
       
   373 // ---------------------------------------------------------------------------
       
   374 // 
       
   375 // ---------------------------------------------------------------------------
       
   376 //
       
   377 void CNcdStorageBase::Rollback()
       
   378     {
       
   379     DoRollback();
       
   380 
       
   381     TInt count = iOpenItems.Count();
       
   382     for( TInt i = 0; i < count; i++ )
       
   383         {
       
   384         iOpenItems[i]->SetOpen( EFalse );
       
   385         }
       
   386 
       
   387     iOpenItems.Reset();
       
   388     iRemovedItems.Reset();
       
   389     }
       
   390 
       
   391 
       
   392 // ---------------------------------------------------------------------------
       
   393 // 
       
   394 // ---------------------------------------------------------------------------
       
   395 //
       
   396 void CNcdStorageBase::ReadDataL( CNcdStorageItem* aItem, 
       
   397     MNcdStorageDataItem& aDataItem )
       
   398     {
       
   399     DoReadDataL( aItem, aDataItem );
       
   400     }
       
   401 
       
   402 
       
   403 // ---------------------------------------------------------------------------
       
   404 // 
       
   405 // ---------------------------------------------------------------------------
       
   406 //
       
   407 void CNcdStorageBase::WriteDataL( CNcdStorageItem* aItem, 
       
   408     MNcdStorageDataItem& aDataItem )
       
   409     {
       
   410     DoWriteDataL( aItem, aDataItem );
       
   411     }
       
   412 
       
   413 
       
   414 // ---------------------------------------------------------------------------
       
   415 // 
       
   416 // ---------------------------------------------------------------------------
       
   417 //
       
   418 TBool CNcdStorageBase::ItemsOpen() const
       
   419     {
       
   420     DLTRACEIN(("this: %x, items open: %d", this, iOpenItems.Count() ));
       
   421     return ( iOpenItems.Count() > 0 );
       
   422     }
       
   423 
       
   424 
       
   425 // ---------------------------------------------------------------------------
       
   426 // 
       
   427 // ---------------------------------------------------------------------------
       
   428 //
       
   429 HBufC8* CNcdStorageBase::GetDataL( CNcdStorageItem* aItem )
       
   430     {
       
   431     return DoGetDataL( aItem );
       
   432     }
       
   433 
       
   434 
       
   435 // ---------------------------------------------------------------------------
       
   436 // 
       
   437 // ---------------------------------------------------------------------------
       
   438 //
       
   439 CNcdStorageItem* CNcdStorageBase::FindStorageItem( const TDesC& aUid, 
       
   440     TInt aType )
       
   441     {
       
   442     TInt count = iItems.Count();
       
   443     CNcdStorageItem* item = NULL;
       
   444 
       
   445     for( TInt i = 0; i < count; i++ )
       
   446         {
       
   447         item = iItems[i];
       
   448 
       
   449         if( item->Type() == aType && 
       
   450             item->Uid().Compare( aUid ) == 0 )
       
   451             {
       
   452             return item;
       
   453             }
       
   454         }    
       
   455         
       
   456     return NULL;
       
   457     }
       
   458 
       
   459 
       
   460 // ---------------------------------------------------------------------------
       
   461 // 
       
   462 // ---------------------------------------------------------------------------
       
   463 //
       
   464 void CNcdStorageBase::SetListener( CNcdStorageBaseListener* aListener )
       
   465     {
       
   466     iListener = aListener;
       
   467     }
       
   468 
       
   469 
       
   470 // ---------------------------------------------------------------------------
       
   471 // 
       
   472 // ---------------------------------------------------------------------------
       
   473 //
       
   474 TBool CNcdStorageBase::ItemExistsInStorageL( const TDesC& aUid, TInt aType )
       
   475     {
       
   476     return ItemExistsL( aUid, aType );
       
   477     }
       
   478 
       
   479 
       
   480 // ---------------------------------------------------------------------------
       
   481 // 
       
   482 // ---------------------------------------------------------------------------
       
   483 //
       
   484 HBufC8* CNcdStorageBase::GetAllDataLC( RReadStream& aStream )
       
   485     {
       
   486     MStreamBuf* streamBuf = aStream.Source();
       
   487     TInt size = streamBuf->SizeL();
       
   488 
       
   489     HBufC8* dataBuffer = HBufC8::NewLC( size );
       
   490     TPtr8 data = dataBuffer->Des();
       
   491 
       
   492     aStream.ReadL( data, size );
       
   493 
       
   494     return dataBuffer;
       
   495     }
       
   496 
       
   497 
       
   498 // ---------------------------------------------------------------------------
       
   499 // 
       
   500 // ---------------------------------------------------------------------------
       
   501 //
       
   502 HBufC8* CNcdStorageBase::GetAllDataL( RReadStream& aStream )
       
   503     {
       
   504     HBufC8* dataBuffer = GetAllDataLC( aStream );
       
   505     CleanupStack::Pop( dataBuffer );    
       
   506     return dataBuffer;
       
   507     }
       
   508 
       
   509 
       
   510 
       
   511 // ********************************
       
   512 //         CNcdStorageItem
       
   513 // ********************************
       
   514 
       
   515 
       
   516 // ---------------------------------------------------------------------------
       
   517 // 
       
   518 // ---------------------------------------------------------------------------
       
   519 //
       
   520 CNcdStorageItem* CNcdStorageItem::NewL( CNcdStorageBase* aStorage, 
       
   521     const TDesC& aUid, TInt aType )
       
   522     {
       
   523     CNcdStorageItem* item = new (ELeave) CNcdStorageItem( aStorage );
       
   524     CleanupStack::PushL( item );
       
   525     item->ConstructL( aUid, aType );
       
   526     CleanupStack::Pop( item );
       
   527     return item;
       
   528     }
       
   529 
       
   530 
       
   531 // ---------------------------------------------------------------------------
       
   532 // 
       
   533 // ---------------------------------------------------------------------------
       
   534 //
       
   535 CNcdStorageItem::~CNcdStorageItem()
       
   536     {
       
   537     DLTRACEIN((""));
       
   538     delete iIdentifier;
       
   539     }
       
   540 
       
   541 
       
   542 // ---------------------------------------------------------------------------
       
   543 // 
       
   544 // ---------------------------------------------------------------------------
       
   545 //
       
   546 CNcdStorageItem::CNcdStorageItem( CNcdStorageBase* aStorage ) :
       
   547     iStorage( aStorage ),
       
   548     iOpen( EFalse )
       
   549     {
       
   550     }
       
   551 
       
   552 
       
   553 // ---------------------------------------------------------------------------
       
   554 // 
       
   555 // ---------------------------------------------------------------------------
       
   556 //
       
   557 void CNcdStorageItem::ConstructL( const TDesC& aUid, TInt aType  )
       
   558     {
       
   559     DLTRACEIN(("this: %x", this));
       
   560     iIdentifier = CNcdStorageItemIdentifier::NewL( aUid, aType );
       
   561     }
       
   562 
       
   563 
       
   564 // ---------------------------------------------------------------------------
       
   565 // 
       
   566 // ---------------------------------------------------------------------------
       
   567 //
       
   568 void CNcdStorageItem::SetOpen( TBool aOpen )
       
   569     {
       
   570     iOpen = aOpen;
       
   571     }
       
   572 
       
   573 
       
   574 // ---------------------------------------------------------------------------
       
   575 // 
       
   576 // ---------------------------------------------------------------------------
       
   577 //
       
   578 TBool CNcdStorageItem::IsOpen() const
       
   579     {
       
   580     return iOpen;
       
   581     }
       
   582 
       
   583 
       
   584 // ---------------------------------------------------------------------------
       
   585 // 
       
   586 // ---------------------------------------------------------------------------
       
   587 //
       
   588 const TDesC& CNcdStorageItem::Uid() const
       
   589     {
       
   590     return iIdentifier->Id();
       
   591     }
       
   592 
       
   593 
       
   594 // ---------------------------------------------------------------------------
       
   595 // 
       
   596 // ---------------------------------------------------------------------------
       
   597 //
       
   598 TInt CNcdStorageItem::Type() const
       
   599     {
       
   600     return iIdentifier->Type();
       
   601     }
       
   602 
       
   603 
       
   604 // ---------------------------------------------------------------------------
       
   605 // 
       
   606 // ---------------------------------------------------------------------------
       
   607 //
       
   608 void CNcdStorageItem::OpenL()
       
   609     {
       
   610     DLTRACEIN(("this: %x", this));
       
   611     if( iOpen )
       
   612         {
       
   613         User::Panic( KNcdStoragePanic, ENcdStoragePanicItemAlreadyOpen );
       
   614         }
       
   615 
       
   616     iStorage->OpenItemL( this );
       
   617     iOpen = ETrue;
       
   618     DLTRACEOUT(("Opened %x", this));
       
   619     }
       
   620 
       
   621 
       
   622 // ---------------------------------------------------------------------------
       
   623 // 
       
   624 // ---------------------------------------------------------------------------
       
   625 //
       
   626 void CNcdStorageItem::SaveL()
       
   627     {
       
   628     DLTRACEIN(("this: %x", this));
       
   629     if( !iOpen )
       
   630         {
       
   631         User::Panic( KNcdStoragePanic, ENcdStoragePanicItemNotOpen );
       
   632         }
       
   633 
       
   634     TRAPD( err, iStorage->SaveItemL( this ) );
       
   635     if( err != KErrNone )
       
   636         {
       
   637         Rollback();
       
   638         User::Leave( err );
       
   639         }
       
   640     iOpen = EFalse;
       
   641     DLTRACEOUT(("closed: %x", this));
       
   642     }
       
   643 
       
   644 
       
   645 // ---------------------------------------------------------------------------
       
   646 // 
       
   647 // ---------------------------------------------------------------------------
       
   648 //
       
   649 void CNcdStorageItem::Rollback()
       
   650     {
       
   651     DLTRACEIN(("this: %x", this));
       
   652     if( iOpen )
       
   653         {
       
   654         iOpen = EFalse;
       
   655         iStorage->RollbackItems();
       
   656         }
       
   657     }
       
   658 
       
   659 
       
   660 // ---------------------------------------------------------------------------
       
   661 // 
       
   662 // ---------------------------------------------------------------------------
       
   663 //
       
   664 void CNcdStorageItem::RemoveFromStorageL()
       
   665     {
       
   666     DLTRACEIN(("this: %x", this));
       
   667     if( iOpen )
       
   668         {
       
   669         User::Panic( KNcdStoragePanic, ENcdStoragePanicItemAlreadyOpen );
       
   670         }
       
   671 
       
   672     iStorage->RemoveItemL( this );
       
   673     }
       
   674 
       
   675 
       
   676 // ---------------------------------------------------------------------------
       
   677 // 
       
   678 // ---------------------------------------------------------------------------
       
   679 //
       
   680 void CNcdStorageItem::SetDataItem( MNcdStorageDataItem* aDataItem )
       
   681     {
       
   682     iDataItem = aDataItem;
       
   683     }
       
   684 
       
   685 
       
   686 // ---------------------------------------------------------------------------
       
   687 // 
       
   688 // ---------------------------------------------------------------------------
       
   689 //
       
   690 void CNcdStorageItem::ReadDataL()
       
   691     {
       
   692     iStorage->ReadDataL( this, *iDataItem );
       
   693     }
       
   694 
       
   695 
       
   696 // ---------------------------------------------------------------------------
       
   697 // 
       
   698 // ---------------------------------------------------------------------------
       
   699 //
       
   700 void CNcdStorageItem::WriteDataL()
       
   701     {
       
   702     DLTRACEIN(("this: %x", this));
       
   703     if( iOpen )
       
   704         {
       
   705         TRAPD( err, iStorage->WriteDataL( this, *iDataItem ) );
       
   706         if ( err != KErrNone ) 
       
   707             {
       
   708             Rollback();
       
   709             User::Leave( err );
       
   710             }
       
   711         }
       
   712     else
       
   713         {
       
   714         User::Panic( KNcdStoragePanic, ENcdStoragePanicItemNotOpen );
       
   715         }
       
   716     }
       
   717 
       
   718 
       
   719 // ---------------------------------------------------------------------------
       
   720 // 
       
   721 // ---------------------------------------------------------------------------
       
   722 //
       
   723 HBufC8* CNcdStorageItem::GetDataLC()
       
   724     {
       
   725     HBufC8* data = iStorage->GetDataL( this );
       
   726     CleanupStack::PushL( data );
       
   727     return data;
       
   728     }
       
   729 
       
   730 
       
   731 // ********************************
       
   732 //     CNcdStorageItemIdentifier
       
   733 // ********************************
       
   734 
       
   735 // ---------------------------------------------------------------------------
       
   736 // 
       
   737 // ---------------------------------------------------------------------------
       
   738 //
       
   739 CNcdStorageItemIdentifier* CNcdStorageItemIdentifier::NewLC( 
       
   740     const TDesC8& aId, TInt aType )
       
   741     {
       
   742     CNcdStorageItemIdentifier* identifier = new (ELeave) 
       
   743         CNcdStorageItemIdentifier( aType );
       
   744     CleanupStack::PushL( identifier );
       
   745     identifier->ConstructL( aId );
       
   746     return identifier;
       
   747     }
       
   748 
       
   749 
       
   750 // ---------------------------------------------------------------------------
       
   751 // 
       
   752 // ---------------------------------------------------------------------------
       
   753 //
       
   754 CNcdStorageItemIdentifier* CNcdStorageItemIdentifier::NewL( 
       
   755     const TDesC16& aId, TInt aType )
       
   756     {
       
   757     CNcdStorageItemIdentifier* identifier = 
       
   758         CNcdStorageItemIdentifier::NewLC( aId, aType );
       
   759     CleanupStack::Pop( identifier );
       
   760     return identifier;
       
   761     }
       
   762 
       
   763 
       
   764 // ---------------------------------------------------------------------------
       
   765 // 
       
   766 // ---------------------------------------------------------------------------
       
   767 //
       
   768 CNcdStorageItemIdentifier* CNcdStorageItemIdentifier::NewLC( 
       
   769     const TDesC16& aId, TInt aType )
       
   770     {
       
   771     CNcdStorageItemIdentifier* identifier = new (ELeave) 
       
   772         CNcdStorageItemIdentifier( aType );
       
   773     CleanupStack::PushL( identifier );
       
   774     identifier->ConstructL( aId );
       
   775     return identifier;
       
   776     }
       
   777 
       
   778 
       
   779 // ---------------------------------------------------------------------------
       
   780 // 
       
   781 // ---------------------------------------------------------------------------
       
   782 //
       
   783 CNcdStorageItemIdentifier::CNcdStorageItemIdentifier( TInt aType ) :
       
   784     iType( aType )
       
   785     {
       
   786     }
       
   787 
       
   788 
       
   789 // ---------------------------------------------------------------------------
       
   790 // 
       
   791 // ---------------------------------------------------------------------------
       
   792 //
       
   793 CNcdStorageItemIdentifier::~CNcdStorageItemIdentifier()
       
   794     {
       
   795     delete iId;
       
   796     }
       
   797 
       
   798 
       
   799 // ---------------------------------------------------------------------------
       
   800 // 
       
   801 // ---------------------------------------------------------------------------
       
   802 //
       
   803 const TDesC& CNcdStorageItemIdentifier::Id() const
       
   804     {
       
   805     return *iId;
       
   806     }
       
   807 
       
   808 
       
   809 // ---------------------------------------------------------------------------
       
   810 // 
       
   811 // ---------------------------------------------------------------------------
       
   812 //
       
   813 TInt CNcdStorageItemIdentifier::Type() const
       
   814     {
       
   815     return iType;
       
   816     }
       
   817 
       
   818 
       
   819 // ---------------------------------------------------------------------------
       
   820 // 
       
   821 // ---------------------------------------------------------------------------
       
   822 //
       
   823 void CNcdStorageItemIdentifier::ConstructL( const TDesC16& aId )
       
   824     {
       
   825     iId = aId.AllocL();
       
   826     }
       
   827 
       
   828 
       
   829 void CNcdStorageItemIdentifier::ConstructL( const TDesC8& aId )
       
   830     {  
       
   831     TInt length = aId.Length();
       
   832 
       
   833     if( length % 2 != 0 )
       
   834       {
       
   835       User::Panic( KNcdStoragePanic, ENcdStoragePanicIdDescAlign );
       
   836       }
       
   837 
       
   838     iId = HBufC16::NewL( length / 2 );
       
   839     iId->Des().Copy( (const TUint16*)aId.Ptr(), length / 2 );
       
   840     }