PECengine/StorageManager2/ServerSrc/CPEngStorageFolder.cpp
changeset 0 094583676ce7
equal deleted inserted replaced
-1:000000000000 0:094583676ce7
       
     1 /*
       
     2 * Copyright (c) 2002 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:  One Storage folder management
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include    <e32std.h>
       
    22 
       
    23 #include <f32file.h>
       
    24 
       
    25 #include    "CPEngStorageFolder.h"
       
    26 #include    "PEngInternalGlobalConsts.h"
       
    27 
       
    28 // Data entries
       
    29 #include    "CPEngDataEntry.h"
       
    30 
       
    31 // Request Handlers
       
    32 #include    "CPEngRequestHandler.h"
       
    33 #include    "CPEngHandlerListenSIDs.h"
       
    34 
       
    35 #include    "CPEngSessionSlotState.h"
       
    36 #include    "CPEngSessionSlotId.h"
       
    37 
       
    38 // Clients message
       
    39 #include    "RPEngMessage.h"
       
    40 
       
    41 // Storages globals
       
    42 #include    "PEngStorageGlobals.h"
       
    43 
       
    44 // Hash tools
       
    45 #include    "PEngHashTool.h"
       
    46 
       
    47 #include    "TPEngStorageServerBTreeKeys.h"
       
    48 
       
    49 //  Debug prints
       
    50 #include    "PresenceDebugPrint.h"
       
    51 
       
    52 
       
    53 // ============================ MEMBER FUNCTIONS ===============================
       
    54 
       
    55 // -----------------------------------------------------------------------------
       
    56 // CPEngStorageFolder::CPEngStorageFolder
       
    57 // C++ default constructor can NOT contain any code, that
       
    58 // might leave.
       
    59 // -----------------------------------------------------------------------------
       
    60 //
       
    61 CPEngStorageFolder::CPEngStorageFolder(
       
    62     RFs& aFs,
       
    63     const TDesC& aTempFolder,
       
    64     RBuf16& aCommBuff )
       
    65         : iFs( aFs ),
       
    66         iTempFolder( aTempFolder ),
       
    67         iBuffer( aCommBuff ),
       
    68         iDataEntryTree( EBtreeSecure )
       
    69     {
       
    70 
       
    71     }
       
    72 
       
    73 
       
    74 // -----------------------------------------------------------------------------
       
    75 // CPEngStorageFolder::ConstructL
       
    76 // Symbian 2nd phase constructor can leave.
       
    77 // -----------------------------------------------------------------------------
       
    78 //
       
    79 void CPEngStorageFolder::ConstructL( )
       
    80     {
       
    81     iObservers = CObjectCon::NewL();
       
    82     // we need to put some number to the CObjectCon::iUniqueID so it takes ownerships
       
    83     iObservers->iUniqueID = reinterpret_cast<TInt>( this );
       
    84 
       
    85     iPool = CMemPagePool::NewL();
       
    86     iDataEntryTree.Connect( iPool, &iDataEntryTreeKey );
       
    87     //client must track if the tree is connected or not, if it is not connected,
       
    88     //you MUST NOT call for example ResetL, because it panics!!
       
    89     iTreeConnected = ETrue;
       
    90     }
       
    91 
       
    92 
       
    93 // -----------------------------------------------------------------------------
       
    94 // CPEngStorageFolder::NewL
       
    95 // Two-phased constructor.
       
    96 // -----------------------------------------------------------------------------
       
    97 //
       
    98 CPEngStorageFolder* CPEngStorageFolder::NewL(
       
    99     RFs& aFs,
       
   100     const TDesC& aTempFolder,
       
   101     RBuf16& aCommBuff )
       
   102     {
       
   103     CPEngStorageFolder* self = NewLC( aFs,
       
   104                                       aTempFolder,
       
   105                                       aCommBuff );
       
   106     CleanupStack::Pop(); // self
       
   107     return self;
       
   108     }
       
   109 
       
   110 
       
   111 // -----------------------------------------------------------------------------
       
   112 // CPEngStorageFolder::NewLC
       
   113 // Two-phased constructor.
       
   114 // -----------------------------------------------------------------------------
       
   115 //
       
   116 CPEngStorageFolder* CPEngStorageFolder::NewLC(
       
   117     RFs& aFs,
       
   118     const TDesC& aTempFolder,
       
   119     RBuf16& aCommBuff )
       
   120     {
       
   121     CPEngStorageFolder* self = new( ELeave ) CPEngStorageFolder(
       
   122         aFs,
       
   123         aTempFolder,
       
   124         aCommBuff );
       
   125     CleanupClosePushL( *self );
       
   126     self->ConstructL( );
       
   127     return self;
       
   128     }
       
   129 
       
   130 
       
   131 // Destructor
       
   132 CPEngStorageFolder::~CPEngStorageFolder()
       
   133     {
       
   134     // clean tree, ignore error, since thread will be closed anyway
       
   135     TRAP_IGNORE( CleanTreeFromAllEntriesL() );
       
   136 
       
   137     delete iSessionState;
       
   138     delete iPool;
       
   139 
       
   140     if ( iObservers )
       
   141         {
       
   142         for ( TInt x( iObservers->Count() - 1 ) ; x >= 0  ; --x )
       
   143             {
       
   144             ( *iObservers )[ x ]->Close();
       
   145             }
       
   146         }
       
   147 
       
   148     delete iObservers;
       
   149     delete iSessionFolder;
       
   150 
       
   151 
       
   152 #if _BullseyeCoverage
       
   153     cov_write();
       
   154 #endif
       
   155     }
       
   156 
       
   157 
       
   158 
       
   159 // =============================================================================
       
   160 // =============== Functions from CObject base class ===========================
       
   161 // =============================================================================
       
   162 
       
   163 
       
   164 // -----------------------------------------------------------------------------
       
   165 // CPEngStorageFolder::Close()
       
   166 // -----------------------------------------------------------------------------
       
   167 //
       
   168 void CPEngStorageFolder::Close ()
       
   169     {
       
   170     if ( iSessionState->SessionSlotState() == EPEngNWPresenceSessionClosed )
       
   171         {
       
   172         CObject::Close();
       
   173         }
       
   174     else
       
   175         {
       
   176         Dec();
       
   177         }
       
   178     }
       
   179 
       
   180 
       
   181 // =============================================================================
       
   182 // =============== Functions from MPEngStorageFolder ===========================
       
   183 // =============================================================================
       
   184 // -----------------------------------------------------------------------------
       
   185 
       
   186 // -----------------------------------------------------------------------------
       
   187 // CPEngStorageFolder::DataEntryL()
       
   188 // -----------------------------------------------------------------------------
       
   189 //
       
   190 CPEngDataEntry* CPEngStorageFolder::DataEntryL(
       
   191     const TDesC& aSId )
       
   192     {
       
   193     TBtreePos pos;
       
   194     if ( !iTreeConnected )
       
   195         {
       
   196         User::Leave( KErrNotReady );
       
   197         }
       
   198 
       
   199     CPEngDataEntry* entry = CheckBufferedDataEntries( aSId );
       
   200     if ( entry )
       
   201         {
       
   202         return entry;
       
   203         }
       
   204 
       
   205     if ( !iDataEntryTree.FindL( pos, const_cast<TDesC*> ( &aSId ) ) )
       
   206         {
       
   207         return NULL;
       
   208         }
       
   209     else
       
   210         {
       
   211         iDataEntryTree.ExtractAtL( pos, entry );
       
   212         }
       
   213     AddBufferedDataEntry( entry );
       
   214     return entry;
       
   215     }
       
   216 
       
   217 
       
   218 // =============================================================================
       
   219 // =============== New Public Functions/ Server used ===========================
       
   220 // =============================================================================
       
   221 
       
   222 
       
   223 // -----------------------------------------------------------------------------
       
   224 // CPEngStorageFolder::SessionSlotState()
       
   225 // -----------------------------------------------------------------------------
       
   226 //
       
   227 CPEngSessionSlotState& CPEngStorageFolder::SessionSlotState()
       
   228     {
       
   229     return *iSessionState;
       
   230     }
       
   231 
       
   232 
       
   233 // -----------------------------------------------------------------------------
       
   234 // CPEngStorageFolder::SetSessionSlotState()
       
   235 // -----------------------------------------------------------------------------
       
   236 //
       
   237 void CPEngStorageFolder::SetSessionSlotState( CPEngSessionSlotState& aState )
       
   238     {
       
   239     delete iSessionState;
       
   240     iSessionState = &aState;
       
   241     }
       
   242 
       
   243 
       
   244 
       
   245 // -----------------------------------------------------------------------------
       
   246 // CPEngStorageFolder::SetSessionFolder()
       
   247 // -----------------------------------------------------------------------------
       
   248 //
       
   249 void CPEngStorageFolder::SetSessionFolder( HBufC& aFolder )
       
   250     {
       
   251     delete iSessionFolder;
       
   252     iSessionFolder = &aFolder;
       
   253     }
       
   254 
       
   255 
       
   256 
       
   257 // -----------------------------------------------------------------------------
       
   258 // CPEngStorageFolder::CommiteStateUpdate()
       
   259 // -----------------------------------------------------------------------------
       
   260 //
       
   261 void CPEngStorageFolder::CommiteStateUpdate()
       
   262     {
       
   263     if ( iSessionState->SessionSlotState() != EPEngNWPresenceSessionClosed )
       
   264         {
       
   265         // nothing to do, session is active
       
   266         return;
       
   267         }
       
   268     // session is closed, check reference count and clean cached data
       
   269     // inform all observers about change
       
   270     NofifyAllAboutAll();
       
   271     if ( 0 == AccessCount() )
       
   272         {
       
   273         delete this;
       
   274         }
       
   275     else
       
   276         {
       
   277         TRAP_IGNORE( CleanTreeFromAllEntriesL() );
       
   278         }
       
   279     }
       
   280 
       
   281 // =============================================================================
       
   282 // =============== New public Functions / Store Engine =========================
       
   283 // =============================================================================
       
   284 
       
   285 
       
   286 // -----------------------------------------------------------------------------
       
   287 // CPEngStorageFolder::WriteStoreEntry()
       
   288 // -----------------------------------------------------------------------------
       
   289 //
       
   290 const CPEngDataEntry* CPEngStorageFolder::WriteStoreEntryL(
       
   291     const RPEngMessage& aMessage,
       
   292     TBool aNotifyActive,
       
   293     TUint32 aSessionId,
       
   294     TInt aSubSessionId )
       
   295     {
       
   296     PENG_DP( D_PENG_LIT( "CPEngStorageFolder::WriteStoreEntryL()" ) );
       
   297     // Etrue, that it should be created if it does not exists
       
   298     TBtreePos pos;
       
   299     CPEngDataEntry* storeEntry = GetStoreEntryL( aMessage, ETrue, pos );
       
   300     HBufC8* clientData = aMessage.ReadOneDescriptor8LC( KMessageSlot2 );
       
   301 
       
   302     return storeEntry->SetDataLX( clientData,
       
   303                                   static_cast<TPEngStorageType>( aMessage.Int1() ),
       
   304                                   aNotifyActive,
       
   305                                   aSessionId,
       
   306                                   aSubSessionId );
       
   307     }
       
   308 
       
   309 
       
   310 
       
   311 // -----------------------------------------------------------------------------
       
   312 // CPEngStorageFolder::ReadStoreEntry()
       
   313 // -----------------------------------------------------------------------------
       
   314 //
       
   315 void CPEngStorageFolder::ReadStoreEntryL(
       
   316     const RPEngMessage& aMessage )
       
   317     {
       
   318     PENG_DP( D_PENG_LIT( "CPEngStorageFolder::ReadStoreEntryL()" ) );
       
   319 
       
   320     // get store entry
       
   321     // do not create if does not exists
       
   322     TBtreePos pos;
       
   323     CPEngDataEntry* storeEntry = GetStoreEntryL( aMessage, EFalse, pos );
       
   324 
       
   325     storeEntry->AssertStorageTypeL( static_cast<TPEngStorageType>( aMessage.Int1() ) );
       
   326 
       
   327     //  write data to the client side, trap error
       
   328     //  if not enough space on client side
       
   329     TInt e ( aMessage.WriteOneDescriptor( KMessageSlot2, storeEntry->DataL() ) );
       
   330     if ( e == KErrOverflow )
       
   331         {
       
   332         // complete message with the length
       
   333         aMessage.Complete( storeEntry->DataL().Length() );
       
   334         // return so message is not completed twice
       
   335         return;
       
   336         }
       
   337 
       
   338     // leave if any error
       
   339     User::LeaveIfError( e );
       
   340     }
       
   341 
       
   342 
       
   343 
       
   344 // -----------------------------------------------------------------------------
       
   345 // CPEngStorageFolder::GetStoryLength()
       
   346 // -----------------------------------------------------------------------------
       
   347 //
       
   348 void CPEngStorageFolder::GetStoreEntryLengthL(
       
   349     const RPEngMessage& aMessage )
       
   350     {
       
   351     // do not create story entry if it does not exist
       
   352     TBtreePos pos;
       
   353     aMessage.Complete( GetStoreEntryL( aMessage, EFalse, pos )->DataL().Length() );
       
   354     }
       
   355 
       
   356 
       
   357 
       
   358 // -----------------------------------------------------------------------------
       
   359 // CPEngStorageFolder::RemoveStoreEntry()
       
   360 // -----------------------------------------------------------------------------
       
   361 //
       
   362 void CPEngStorageFolder::RemoveStoreEntryL(
       
   363     const RPEngMessage& aMessage )
       
   364     {
       
   365     // load if exists, do not create
       
   366     TBtreePos pos;
       
   367     // we actually need position from tree, so true search
       
   368     CPEngDataEntry* storeEntry = GetStoreEntryL( aMessage, EFalse, pos, ETrue );
       
   369     storeEntry->DeleteStoreEntry();
       
   370     // remove store entry from tree
       
   371     iDataEntryTree.DeleteAtL( pos );
       
   372     // removed from tree, not delete instance
       
   373     delete storeEntry;
       
   374     // remove buffered pointers of deleted store entry
       
   375     if ( iBuffDataEntry0 == iBuffDataEntry1 )
       
   376         {
       
   377         iBuffDataEntry1 = NULL;
       
   378         }
       
   379     if ( iBuffDataEntry0 == iBuffDataEntry2 )
       
   380         {
       
   381         iBuffDataEntry2 = NULL;
       
   382         }
       
   383     iBuffDataEntry0 = NULL;
       
   384     }
       
   385 
       
   386 
       
   387 
       
   388 // -----------------------------------------------------------------------------
       
   389 // CPEngStorageFolder::LockStoreEntry()
       
   390 // -----------------------------------------------------------------------------
       
   391 //
       
   392 void CPEngStorageFolder::LockStoreEntryL(
       
   393     const RPEngMessage& aMessage,
       
   394     TUint32 aSessionId,
       
   395     TInt aSubSessionId )
       
   396     {
       
   397     // load if exists, or create if does not exists
       
   398     TBtreePos pos;
       
   399     TInt priorityInt( aMessage.Int2() );
       
   400     TBool createEntry = priorityInt & KLockEntryCreateMask;
       
   401     CPEngDataEntry* storeEntry = GetStoreEntryL( aMessage, createEntry, pos );
       
   402     priorityInt &= ~KLockEntryCreateMask;
       
   403     TPengStorageLockPriority priority (
       
   404         static_cast<TPengStorageLockPriority> ( priorityInt ) );
       
   405 
       
   406     aMessage.Complete( storeEntry->IncreaseLockCountL( aSessionId,
       
   407                                                        aSubSessionId,
       
   408                                                        priority ) );
       
   409     }
       
   410 
       
   411 
       
   412 
       
   413 // -----------------------------------------------------------------------------
       
   414 // CPEngStorageFolder::UnlockStoreEntry()
       
   415 // -----------------------------------------------------------------------------
       
   416 //
       
   417 const CPEngDataEntry* CPEngStorageFolder::UnlockStoreEntryL(
       
   418     const RPEngMessage& aMessage,
       
   419     TBool aNotifyActive,
       
   420     TUint32 aSessionId,
       
   421     TInt aSubSessionId )
       
   422     {
       
   423     // load if exists, do not create if does not exists
       
   424     TBtreePos pos;
       
   425     CPEngDataEntry* storeEntry = GetStoreEntryL( aMessage, EFalse, pos );
       
   426 
       
   427     // check current lock count, so we avoid hasty notifications
       
   428     if ( !storeEntry->LockCount() )
       
   429         {
       
   430         // item is not locked at all, complete with zero
       
   431         aMessage.Complete( 0 );
       
   432         return NULL;
       
   433         }
       
   434 
       
   435     // release lock by one
       
   436     CPEngDataEntry* notifEntry = NULL;
       
   437     TInt lockCount( storeEntry->DecreaseLockCountL( aNotifyActive,
       
   438                                                     aSessionId,
       
   439                                                     aSubSessionId,
       
   440                                                     notifEntry ) );
       
   441     aMessage.Complete( lockCount );
       
   442     return NULL;
       
   443     }
       
   444 
       
   445 
       
   446 
       
   447 // -----------------------------------------------------------------------------
       
   448 // CPEngStorageFolder::IsStoreEntryLocked()
       
   449 // -----------------------------------------------------------------------------
       
   450 //
       
   451 void CPEngStorageFolder::IsStoreEntryLockedL(
       
   452     const RPEngMessage& aMessage )
       
   453     {
       
   454     TBtreePos pos;
       
   455     CPEngDataEntry* volatile storeEntry = NULL;
       
   456     TRAPD( e, storeEntry = GetStoreEntryL( aMessage, EFalse, pos ) );
       
   457     if ( e == KErrNotFound )
       
   458         {
       
   459         // if does not exists in store, also not locked
       
   460         aMessage.Complete( KErrNone );
       
   461         return;
       
   462         }
       
   463     // other error leave
       
   464     User::LeaveIfError( e );
       
   465     aMessage.Complete( storeEntry->LockStatus(
       
   466                            static_cast<TPengStorageLockPriority>( aMessage.Int2() ) ) );
       
   467     }
       
   468 
       
   469 
       
   470 
       
   471 // =============================================================================
       
   472 // =============== New public Functions / Notify Engine ========================
       
   473 // =============================================================================
       
   474 
       
   475 
       
   476 // -----------------------------------------------------------------------------
       
   477 // CPEngStorageFolder::StartListenSIDsChanges()
       
   478 // -----------------------------------------------------------------------------
       
   479 //
       
   480 void CPEngStorageFolder::ListenSIDsChangesL(
       
   481     const RPEngMessage& aMessage,
       
   482     TUint32 aSessionId,
       
   483     TInt aSubSessionId )
       
   484     {
       
   485     CPEngRequestHandler* reqHandler = FindRequestHandler( aSessionId, aSubSessionId,
       
   486                                                           EFolderSubSessListenSIDsChanges );
       
   487     if ( reqHandler )
       
   488         {
       
   489         // this handler already exists, not allowed by multiple
       
   490         User::Leave( KErrAlreadyExists );
       
   491         }
       
   492 
       
   493     // create new handler
       
   494     reqHandler = CPEngHandlerListenSIDs::NewLC( *this,
       
   495                                                 aMessage,
       
   496                                                 aSessionId,
       
   497                                                 aSubSessionId );
       
   498     // store new handler
       
   499     iObservers->AddL( reqHandler );
       
   500     CleanupStack::Pop(); // newHandler
       
   501     }
       
   502 
       
   503 
       
   504 
       
   505 // -----------------------------------------------------------------------------
       
   506 // CPEngStorageFolder::UpdateListenSIDsScout()
       
   507 // -----------------------------------------------------------------------------
       
   508 //
       
   509 void CPEngStorageFolder::UpdateListenSIDsScoutL(
       
   510     const RPEngMessage& aMessage,
       
   511     TUint32 aSessionId,
       
   512     TInt aSubSessionId )
       
   513     {
       
   514     CPEngRequestHandler* reqHandler = FindRequestHandler( aSessionId, aSubSessionId,
       
   515                                                           static_cast<TPEngStorageServerMessages> ( aMessage.Int0() ) );
       
   516     if ( !reqHandler )
       
   517         {
       
   518         // there is not such a request to be reloaded
       
   519         User::Leave( KErrArgument );
       
   520         }
       
   521     reqHandler->ReloadScoutWithNewMessageL( aMessage );
       
   522     }
       
   523 
       
   524 void CPEngStorageFolder::FetchChangedIdsIndexesL(
       
   525     const RPEngMessage& aMessage,
       
   526     TUint32 aSessionId,
       
   527     TInt aSubSessionId )
       
   528     {
       
   529     CPEngRequestHandler* reqHandler = FindRequestHandler( aSessionId, aSubSessionId,
       
   530                                                           static_cast<TPEngStorageServerMessages> ( aMessage.Int0() ) );
       
   531     if ( !reqHandler )
       
   532         {
       
   533         // there is not such a request to be reloaded
       
   534         User::Leave( KErrArgument );
       
   535         }
       
   536     reqHandler->ReloadScoutWithNewMessageL( aMessage );
       
   537     }
       
   538 
       
   539 
       
   540 
       
   541 // -----------------------------------------------------------------------------
       
   542 // CPEngStorageFolder::ReloadAsyncScout()
       
   543 // -----------------------------------------------------------------------------
       
   544 //
       
   545 void CPEngStorageFolder::ReloadAsyncScoutL(
       
   546     const RPEngMessage& aMessage,
       
   547     TUint32 aSessionId,
       
   548     TInt aSubSessionId )
       
   549     {
       
   550     CPEngRequestHandler* reqHandler = FindRequestHandler( aSessionId, aSubSessionId,
       
   551                                                           static_cast<TPEngStorageServerMessages> ( aMessage.Int0() ) );
       
   552     if ( !reqHandler )
       
   553         {
       
   554         // there is not such a request to be reloaded
       
   555         User::Leave( KErrArgument );
       
   556         }
       
   557     reqHandler->ReloadScoutWithNewMessageL( aMessage );
       
   558     }
       
   559 
       
   560 
       
   561 
       
   562 // -----------------------------------------------------------------------------
       
   563 // CPEngStorageFolder::CancelSubSessionScouts()
       
   564 // -----------------------------------------------------------------------------
       
   565 //
       
   566 void CPEngStorageFolder::CancelSubSessionRequests(
       
   567     TUint32 aSessionId,
       
   568     TInt aSubSessionId )
       
   569     {
       
   570     for ( TInt x( iObservers->Count() - 1 ) ; x >= 0 ; --x )
       
   571         {
       
   572         CPEngRequestHandler* reqHandler =
       
   573             static_cast<CPEngRequestHandler*>( ( *iObservers )[ x ] );
       
   574         if (
       
   575             ( reqHandler->SessionId() == aSessionId )
       
   576             &&
       
   577             ( reqHandler->SubSessionId() == aSubSessionId )
       
   578         )
       
   579             {
       
   580             reqHandler->CancelRequestD();
       
   581             }
       
   582         }
       
   583     }
       
   584 
       
   585 
       
   586 
       
   587 // -----------------------------------------------------------------------------
       
   588 // CPEngStorageFolder::CancelRequest()
       
   589 // -----------------------------------------------------------------------------
       
   590 //
       
   591 void CPEngStorageFolder::CancelRequest(
       
   592     const RPEngMessage& aMessage,
       
   593     TUint32  aSessionId,
       
   594     TInt aSubSessionId )
       
   595     {
       
   596     CPEngRequestHandler* reqHandler = FindRequestHandler( aSessionId, aSubSessionId,
       
   597                                                           static_cast<TPEngStorageServerMessages> ( aMessage.Int0() ) );
       
   598     // ignore if such a request does not exists
       
   599     if ( reqHandler )
       
   600         {
       
   601         reqHandler->CancelRequestD();
       
   602         }
       
   603     }
       
   604 
       
   605 
       
   606 
       
   607 // -----------------------------------------------------------------------------
       
   608 // CPEngStorageFolder::NotifyChangedStorageIdL()
       
   609 // -----------------------------------------------------------------------------
       
   610 //
       
   611 const CPEngDataEntry* CPEngStorageFolder::NotifyChangedStorageIdL(
       
   612     const RPEngMessage& aMessage,
       
   613     TBool aNotifyActive )
       
   614     {
       
   615     // find entry
       
   616     TBtreePos pos;
       
   617     CPEngDataEntry* storeEntry = GetStoreEntryL( aMessage, ETrue, pos );
       
   618 
       
   619     if ( aNotifyActive )
       
   620         {
       
   621         // better to go through array from end
       
   622         for ( TInt x( iObservers->Count() - 1 ) ; x >= 0 ; --x )
       
   623             {
       
   624             static_cast<CPEngHandlerListenSIDs*>
       
   625             ( ( *iObservers )[ x ] )->EntryUpdated( *storeEntry );
       
   626             }
       
   627         storeEntry = NULL;
       
   628         }
       
   629 
       
   630     //In other cases let the caller to do the notification delayed
       
   631     return storeEntry;
       
   632     }
       
   633 
       
   634 
       
   635 
       
   636 // -----------------------------------------------------------------------------
       
   637 // CPEngStorageFolder::NotifySIDChanges()
       
   638 // -----------------------------------------------------------------------------
       
   639 //
       
   640 void CPEngStorageFolder::NotifySIDChanges(
       
   641     const RPointerArray<CPEngDataEntry>& aEntries )
       
   642     {
       
   643     // better to go through array from end
       
   644     for ( TInt x( iObservers->Count() - 1 ) ; x >= 0 ; --x )
       
   645         {
       
   646         static_cast<CPEngHandlerListenSIDs*>
       
   647         ( ( *iObservers )[ x ] )->NotifyChangedSIDs( aEntries ) ;
       
   648         }
       
   649     }
       
   650 
       
   651 
       
   652 // =============================================================================
       
   653 // =============== New private Functions of the class ==========================
       
   654 // =============================================================================
       
   655 
       
   656 
       
   657 // -----------------------------------------------------------------------------
       
   658 // CPEngStorageFolder::FindRequestHandler()
       
   659 // Find Request Handler
       
   660 // (other items were commented in a header).
       
   661 // -----------------------------------------------------------------------------
       
   662 //
       
   663 CPEngRequestHandler* CPEngStorageFolder::FindRequestHandler(
       
   664     TUint32 aSessionId,
       
   665     TInt aSubSession,
       
   666     TPEngStorageServerMessages aFunction )
       
   667     {
       
   668     TInt count( iObservers->Count() );
       
   669     for ( TInt x( 0 ) ; x < count ; x++ )
       
   670         {
       
   671         CPEngRequestHandler* reqHandler = static_cast<CPEngRequestHandler*>( ( *iObservers )[ x ] );
       
   672         if ( ( reqHandler->SessionId() == aSessionId )
       
   673              && ( reqHandler->SubSessionId() == aSubSession )
       
   674              && ( reqHandler->RequestFunction() == aFunction ) )
       
   675             {
       
   676             return reqHandler;
       
   677             }
       
   678         }
       
   679     return NULL;
       
   680     }
       
   681 
       
   682 
       
   683 
       
   684 // -----------------------------------------------------------------------------
       
   685 // CPEngStorageFolder::GetStoreEntryL()
       
   686 // Get Store Entry instance
       
   687 // (other items were commented in a header).
       
   688 // -----------------------------------------------------------------------------
       
   689 //
       
   690 CPEngDataEntry* CPEngStorageFolder::GetStoreEntryL(
       
   691     const RPEngMessage& aMessage,
       
   692     TBool aCreateIfNotPressent,
       
   693     TBtreePos& aPos,
       
   694     TBool aTrueSearch /* = EFalse */ )
       
   695     {
       
   696     // read Store ID and type from message
       
   697     aMessage.ReadOneDescriptorL( KMessageSlot0, iBuffer );
       
   698     PENG_DP( D_PENG_LIT( "CPEngStorageFolder::GetStoreEntryL():%S" ), &iBuffer );
       
   699 
       
   700     if ( !iTreeConnected )
       
   701         {
       
   702         User::Leave( KErrNotReady );
       
   703         }
       
   704 
       
   705     CPEngDataEntry* entry = NULL;
       
   706     if ( !aTrueSearch )
       
   707         {
       
   708         entry = CheckBufferedDataEntries( iBuffer );
       
   709         }
       
   710 
       
   711     if ( entry )
       
   712         {
       
   713         return entry;
       
   714         }
       
   715 
       
   716     if ( !iDataEntryTree.FindL( aPos, &iBuffer ) )
       
   717         {
       
   718         // not in the tree, try to load it, it will be also added to the tree
       
   719         entry = LoadStoreEntryL( iBuffer, aCreateIfNotPressent, aPos, aMessage );
       
   720         }
       
   721     else
       
   722         {
       
   723         iDataEntryTree.ExtractAtL( aPos, entry );
       
   724         }
       
   725     AddBufferedDataEntry( entry );
       
   726     return entry;
       
   727     }
       
   728 
       
   729 
       
   730 
       
   731 // -----------------------------------------------------------------------------
       
   732 // CPEngStorageFolder::LoadStoreEntryL()
       
   733 // Load Store Entry from disc if it exists
       
   734 // (other items were commented in a header).
       
   735 // -----------------------------------------------------------------------------
       
   736 //
       
   737 CPEngDataEntry* CPEngStorageFolder::LoadStoreEntryL(
       
   738     TDesC& aKey,
       
   739     TBool aCreateIfNotPressent,
       
   740     TBtreePos& aPos,
       
   741     const RPEngMessage& aMessage )
       
   742     {
       
   743     // add it into the tree if entry will be created
       
   744     TPEngStorageType type( static_cast<TPEngStorageType>( aMessage.Int1() ) );
       
   745 
       
   746     CPEngDataEntry* entry = CPEngDataEntry::NewLC(
       
   747                                 iFs,
       
   748                                 iTempFolder,
       
   749                                 aKey,
       
   750                                 type );
       
   751 
       
   752     HBufC* path = NULL;
       
   753     if ( type & EPEngStorageBasicPermanent )
       
   754         {
       
   755         // create Hashed path for the file
       
   756         path = PEngHashTool::HashDescriptorL( aKey );
       
   757         CleanupStack::PushL( path );
       
   758 
       
   759         path = path->ReAllocL( path->Length() +
       
   760                                iSessionFolder->Length() );
       
   761 
       
   762         CleanupStack::Pop(); // new pointer was received, old buffer deleted
       
   763         // folder delimiter was already there
       
   764         path->Des().Insert( 0, *iSessionFolder );
       
   765         entry->SetHashedPath( path );
       
   766         }
       
   767 
       
   768     if ( !( entry->InitializeStoreEntryL() || aCreateIfNotPressent ) )
       
   769         {
       
   770         User::Leave( KErrNotFound );
       
   771         }
       
   772 
       
   773     // add entry to the tree
       
   774     if ( !iDataEntryTree.InsertL( aPos, entry ) )
       
   775         {
       
   776         User::Leave( KErrGeneral );
       
   777         }
       
   778 
       
   779     // notify SIDs observers about new added entry
       
   780     // better to go through array from end
       
   781     for ( TInt x( iObservers->Count() - 1 ) ; x >= 0 ; --x )
       
   782         {
       
   783         static_cast<CPEngHandlerListenSIDs*>
       
   784         ( ( *iObservers )[ x ] )->EntryCreatedL( *entry );
       
   785         }
       
   786 
       
   787     CleanupStack::Pop( entry );
       
   788 
       
   789     return entry;
       
   790     }
       
   791 
       
   792 // -----------------------------------------------------------------------------
       
   793 // CPEngStorageFolder::NofifyAllAboutAll()
       
   794 // Notify observer that all observer SIds changed
       
   795 // (other items were commented in a header).
       
   796 // -----------------------------------------------------------------------------
       
   797 //
       
   798 void CPEngStorageFolder::NofifyAllAboutAll()
       
   799     {
       
   800     // better to go through array from end
       
   801     for ( TInt x( iObservers->Count() - 1 ) ; x >= 0 ; --x )
       
   802         {
       
   803         static_cast<CPEngHandlerListenSIDs*>
       
   804         ( ( *iObservers )[ x ] )->NotifyAllSIdsChanged();
       
   805         }
       
   806     }
       
   807 
       
   808 // -----------------------------------------------------------------------------
       
   809 // CPEngStorageFolder::NofifyAllAboutAll()
       
   810 // Look in buffered data entries for data entry with desired key
       
   811 // -----------------------------------------------------------------------------
       
   812 //
       
   813 CPEngDataEntry* CPEngStorageFolder::CheckBufferedDataEntries(
       
   814     const TDesC& aKey )
       
   815     {
       
   816     if ( iBuffDataEntry0 && KErrNone == iBuffDataEntry0->Key().CompareF( aKey ) )
       
   817         {
       
   818         PENG_DP( D_PENG_LIT(
       
   819                      "CPEngStorageFolder::CheckBufferedDataEntries(0) Search skipped:%S" ),
       
   820                  &aKey );
       
   821         return iBuffDataEntry0;
       
   822         }
       
   823 
       
   824     if ( iBuffDataEntry1 && KErrNone == iBuffDataEntry1->Key().CompareF( aKey ) )
       
   825         {
       
   826         PENG_DP( D_PENG_LIT(
       
   827                      "CPEngStorageFolder::CheckBufferedDataEntries(1) Search skipped:%S" ),
       
   828                  &aKey );
       
   829         CPEngDataEntry* entry = iBuffDataEntry1;
       
   830         iBuffDataEntry1 = iBuffDataEntry0;
       
   831         iBuffDataEntry0 = entry;
       
   832         return entry;
       
   833         }
       
   834 
       
   835     if ( iBuffDataEntry2 && KErrNone == iBuffDataEntry2->Key().CompareF( aKey ) )
       
   836         {
       
   837         PENG_DP( D_PENG_LIT(
       
   838                      "CPEngStorageFolder::CheckBufferedDataEntries(2) Search skipped:%S" ),
       
   839                  &aKey );
       
   840         AddBufferedDataEntry( iBuffDataEntry2 );
       
   841         return iBuffDataEntry0;
       
   842         }
       
   843     return NULL;
       
   844     }
       
   845 
       
   846 // -----------------------------------------------------------------------------
       
   847 // CPEngStorageFolder::AddBufferedDataEntry()
       
   848 // Add buffered data entry pointer
       
   849 // -----------------------------------------------------------------------------
       
   850 //
       
   851 void CPEngStorageFolder::AddBufferedDataEntry(
       
   852     CPEngDataEntry* aDataEntry )
       
   853     {
       
   854     iBuffDataEntry2 = iBuffDataEntry1;
       
   855     iBuffDataEntry1 = iBuffDataEntry0;
       
   856     iBuffDataEntry0 = aDataEntry;
       
   857     }
       
   858 
       
   859 
       
   860 // -----------------------------------------------------------------------------
       
   861 // CPEngStorageFolder::CleanTreeFromAllEntriesL()
       
   862 // Clean B tree from all entries
       
   863 // (other items were commented in a header).
       
   864 // -----------------------------------------------------------------------------
       
   865 //
       
   866 void CPEngStorageFolder::CleanTreeFromAllEntriesL()
       
   867     {
       
   868     if ( !iTreeConnected )
       
   869         {
       
   870         User::Leave( KErrNotReady );
       
   871         }
       
   872     TBtreeMark pos;
       
   873     TBool b = iDataEntryTree.ResetL( pos );
       
   874     iBuffDataEntry0 = NULL;
       
   875     iBuffDataEntry1 = NULL;
       
   876     iBuffDataEntry2 = NULL;
       
   877     while ( b )
       
   878         {
       
   879         CPEngDataEntry* entry;
       
   880         iDataEntryTree.ExtractAtL( pos, entry );
       
   881         if ( entry )
       
   882             {
       
   883             delete entry;
       
   884             }
       
   885         b = iDataEntryTree.NextL( pos );
       
   886         }
       
   887     iDataEntryTree.ClearL();
       
   888     }
       
   889 
       
   890 
       
   891 //  End of File