PECengine/StorageManager2/ServerSrc/CPEngStorageSubSession.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:  Sub-session class of the Storage Server
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include    <e32std.h>
       
    22 #include	"CPEngStorageSubSession.h"
       
    23 #include	"PEngStorageServerCommon.h"
       
    24 
       
    25 #include	"CPEngStorageFolder.h"
       
    26 #include	"MPEngStorageServer.h"
       
    27 #include	"RPEngMessage.h"
       
    28 
       
    29 
       
    30 // ============================ MEMBER FUNCTIONS ===============================
       
    31 
       
    32 // -----------------------------------------------------------------------------
       
    33 // CPEngStorageSubSession::CPEngStorageSubSession
       
    34 // C++ default constructor can NOT contain any code, that might leave.
       
    35 // -----------------------------------------------------------------------------
       
    36 //
       
    37 CPEngStorageSubSession::CPEngStorageSubSession( TInt32 aSessionId )
       
    38         : iBufferedNotif( 10 ), // 10 as value to grow array
       
    39         iSessionId( aSessionId )
       
    40     {
       
    41     }
       
    42 
       
    43 
       
    44 // -----------------------------------------------------------------------------
       
    45 // CPEngStorageSubSession::ConstructL
       
    46 // Symbian 2nd phase constructor can leave.
       
    47 // -----------------------------------------------------------------------------
       
    48 //
       
    49 void CPEngStorageSubSession::ConstructL(
       
    50     MPEngStorageServer& aServer,
       
    51     const RPEngMessage& aMessage )
       
    52     {
       
    53     iStorageFolder = aServer.StorageFolderL( aMessage );
       
    54     }
       
    55 
       
    56 
       
    57 // -----------------------------------------------------------------------------
       
    58 // CPEngStorageSubSession::NewL
       
    59 // Two-phased constructor.
       
    60 // -----------------------------------------------------------------------------
       
    61 //
       
    62 CPEngStorageSubSession* CPEngStorageSubSession::NewL(
       
    63     MPEngStorageServer& aServer,
       
    64     const RPEngMessage& aMessage,
       
    65     TInt32 aSessionId )
       
    66     {
       
    67     CPEngStorageSubSession* self = NewLC( aServer, aMessage, aSessionId );
       
    68 
       
    69     CleanupStack::Pop(); // self
       
    70 
       
    71     return self;
       
    72     }
       
    73 
       
    74 
       
    75 // -----------------------------------------------------------------------------
       
    76 // CPEngStorageSubSession::NewLC
       
    77 // Two-phased constructor.
       
    78 // -----------------------------------------------------------------------------
       
    79 //
       
    80 CPEngStorageSubSession* CPEngStorageSubSession::NewLC(
       
    81     MPEngStorageServer& aServer,
       
    82     const RPEngMessage& aMessage,
       
    83     TInt32 aSessionId )
       
    84     {
       
    85     CPEngStorageSubSession* self = new( ELeave ) CPEngStorageSubSession( aSessionId );
       
    86 
       
    87     CleanupClosePushL( *self );
       
    88     self->ConstructL( aServer, aMessage );
       
    89     return self;
       
    90     }
       
    91 
       
    92 
       
    93 // Destructor
       
    94 CPEngStorageSubSession::~CPEngStorageSubSession()
       
    95     {
       
    96     iBufferedNotif.Reset();
       
    97     // decrease count of the storage Folder
       
    98     if ( iStorageFolder )
       
    99         {
       
   100         iStorageFolder->CancelSubSessionRequests( iSessionId, iHandle );
       
   101         iStorageFolder->Close();
       
   102         }
       
   103     }
       
   104 
       
   105 
       
   106 
       
   107 // =============================================================================
       
   108 // =============== Functions from base class ===================================
       
   109 // =============================================================================
       
   110 
       
   111 
       
   112 // -----------------------------------------------------------------------------
       
   113 // CPEngStorageSubSession::DisplayName()
       
   114 // -----------------------------------------------------------------------------
       
   115 //
       
   116 TBool CPEngStorageSubSession::DispatchMessageL(
       
   117     const RPEngMessage& aMessage,
       
   118     TInt aRequest )
       
   119     {
       
   120     TBool completeMessage( ETrue );
       
   121     switch ( aRequest )
       
   122         {
       
   123             /*********************************************************************/
       
   124             /*  Asynchronous Requests Management                                 */
       
   125             /*********************************************************************/
       
   126 
       
   127             // Cancel Asynchronous request Request
       
   128         case EFolderSubSessCancelRequest:
       
   129             {
       
   130             iStorageFolder->CancelRequest( aMessage,
       
   131                                            iSessionId,
       
   132                                            iHandle );
       
   133             break;
       
   134             }
       
   135 
       
   136         // Reload Asynchronous Scout on the Server side
       
   137         case EFolderSubSessReloadAsynchronousScout:
       
   138             {
       
   139             iStorageFolder->ReloadAsyncScoutL( aMessage,
       
   140                                                iSessionId,
       
   141                                                iHandle );
       
   142             completeMessage = EFalse;
       
   143             break;
       
   144             }
       
   145 
       
   146         /*********************************************************************/
       
   147         /*  Store Entry management                                           */
       
   148         /*********************************************************************/
       
   149 
       
   150         // Write store entry
       
   151         case EFolderSubSessWriteEntry:
       
   152             {
       
   153             const CPEngDataEntry* entry = iStorageFolder->WriteStoreEntryL(
       
   154                                               aMessage,
       
   155                                               !iBufferingActiveCounter,
       
   156                                               iSessionId,
       
   157                                               iHandle );
       
   158             if ( entry )
       
   159                 {
       
   160                 TInt err( iBufferedNotif.InsertInAddressOrder( entry ) );
       
   161                 err = err == KErrAlreadyExists ? KErrNone : err;
       
   162                 User::LeaveIfError( err );
       
   163                 }
       
   164             break;
       
   165             }
       
   166 
       
   167         // Read store Entry
       
   168         case EFolderSubSessReadEntry:
       
   169             {
       
   170             iStorageFolder->ReadStoreEntryL( aMessage );
       
   171             break;
       
   172             }
       
   173 
       
   174         // Get Entry size
       
   175         case EFolderSubSessGetEntryLength:
       
   176             {
       
   177             iStorageFolder->GetStoreEntryLengthL( aMessage );
       
   178             break;
       
   179             }
       
   180 
       
   181         // Remove Store entry from the storage
       
   182         case EFolderSubSessRemoveEntry:
       
   183             {
       
   184             iStorageFolder->RemoveStoreEntryL( aMessage );
       
   185             break;
       
   186             }
       
   187 
       
   188         // Lock Store Entry
       
   189         case EFolderSubSessLockEntry:
       
   190             {
       
   191             iStorageFolder->LockStoreEntryL( aMessage,
       
   192                                              iSessionId,
       
   193                                              iHandle );
       
   194             completeMessage = EFalse;
       
   195             break;
       
   196             }
       
   197 
       
   198         // Unlock the Store entry
       
   199         case EFolderSubSessUnlockEntry:
       
   200             {
       
   201             // check if it is needed to buffer notification
       
   202             const CPEngDataEntry* entry =
       
   203                 iStorageFolder->UnlockStoreEntryL(
       
   204                     aMessage,
       
   205                     !iBufferingActiveCounter,
       
   206                     iSessionId,
       
   207                     iHandle );
       
   208             if ( entry )
       
   209                 {
       
   210                 TInt err( iBufferedNotif.InsertInAddressOrder( entry ) );
       
   211                 err = err == KErrAlreadyExists ? KErrNone : err;
       
   212                 User::LeaveIfError( err );
       
   213                 }
       
   214             completeMessage = EFalse;
       
   215             break;
       
   216             }
       
   217 
       
   218         // Is Store entry locked
       
   219         case EFolderSubSessIsEntryLocked:
       
   220             {
       
   221             iStorageFolder->IsStoreEntryLockedL( aMessage );
       
   222             completeMessage = EFalse;
       
   223             break;
       
   224             }
       
   225 
       
   226         // Suspend notification to the client
       
   227         case EFolderSubSessSuspendNotification:
       
   228             {
       
   229             iBufferingActiveCounter += aMessage.Int0();
       
   230             aMessage.Complete( iBufferingActiveCounter );
       
   231             completeMessage = EFalse;
       
   232             break;
       
   233             }
       
   234 
       
   235         // Resume notification to the client
       
   236         case EFolderSubSessResumeNotification:
       
   237             {
       
   238             ResumeSIDsNotification( aMessage.Int0() );
       
   239             aMessage.Complete( iBufferingActiveCounter );
       
   240             completeMessage = EFalse;
       
   241             break;
       
   242             }
       
   243 
       
   244         /*********************************************************************/
       
   245         /*   Storage ID changes notify management                            */
       
   246         /*********************************************************************/
       
   247 
       
   248         // Synchronous Request to register for notification
       
   249         case EFolderSubSessListenSIDsChanges:
       
   250             {
       
   251             iStorageFolder->ListenSIDsChangesL( aMessage,
       
   252                                                 iSessionId,
       
   253                                                 iHandle );
       
   254             break;
       
   255             }
       
   256 
       
   257         // Synchronous Request to update set of SIDs client
       
   258         case EFolderSubSessUpdateListenSIDsScout:
       
   259             {
       
   260             iStorageFolder->UpdateListenSIDsScoutL( aMessage,
       
   261                                                     iSessionId,
       
   262                                                     iHandle );
       
   263             break;
       
   264             }
       
   265 
       
   266         // Fetch indexes of changed SIds
       
   267         case EFolderSubSessFetchChangedSIDsIndexes:
       
   268             {
       
   269             iStorageFolder->FetchChangedIdsIndexesL( aMessage,
       
   270                                                      iSessionId,
       
   271                                                      iHandle );
       
   272             break;
       
   273             }
       
   274 
       
   275         // Synchronous Request to force notify Store Entry change
       
   276         case EFolderSubSessNotifyChangedSIDs:
       
   277             {
       
   278             // check if it is needed to buffer notification
       
   279             const CPEngDataEntry* entry =
       
   280                 iStorageFolder->NotifyChangedStorageIdL(
       
   281                     aMessage,
       
   282                     !iBufferingActiveCounter );
       
   283             if ( entry )
       
   284                 {
       
   285                 TInt err( iBufferedNotif.InsertInAddressOrder( entry ) );
       
   286                 err = err == KErrAlreadyExists ? KErrNone : err;
       
   287                 User::LeaveIfError( err );
       
   288                 }
       
   289 
       
   290             break;
       
   291             }
       
   292 
       
   293         default:
       
   294             {
       
   295             PanicClient( aMessage, ESSBadRequest );
       
   296             break;
       
   297             }
       
   298         }
       
   299     // check if message can be completed
       
   300     completeMessage &= aMessage.MessageValid();
       
   301     return completeMessage;
       
   302     }
       
   303 
       
   304 // -----------------------------------------------------------------------------
       
   305 // CPEngStorageSubSession::SetSubSesionHandle()
       
   306 // -----------------------------------------------------------------------------
       
   307 //
       
   308 void CPEngStorageSubSession::SetSubSesionHandle(
       
   309     TInt aHandle )
       
   310     {
       
   311     iHandle = aHandle;
       
   312     }
       
   313 
       
   314 
       
   315 // =============================================================================
       
   316 // =============== Private Functions from base class ===========================
       
   317 // =============================================================================
       
   318 
       
   319 // -----------------------------------------------------------------------------
       
   320 // CPEngStorageSubSession::PanicClient()
       
   321 // Panic client
       
   322 // (other items were commented in a header).
       
   323 // -----------------------------------------------------------------------------
       
   324 //
       
   325 void CPEngStorageSubSession::PanicClient(
       
   326     const RPEngMessage& aMessage,
       
   327     const TInt aPanic ) const
       
   328     {
       
   329     aMessage.Panic( KStorageSessionName, aPanic );
       
   330     }
       
   331 
       
   332 
       
   333 // -----------------------------------------------------------------------------
       
   334 // CPEngStorageSubSession::ResumeSIDsNotificationL()
       
   335 // Resume Notification of the SIDs
       
   336 // (other items were commented in a header).
       
   337 // -----------------------------------------------------------------------------
       
   338 //
       
   339 void CPEngStorageSubSession::ResumeSIDsNotification(
       
   340     TInt aCount )
       
   341     {
       
   342     iBufferingActiveCounter -= aCount;
       
   343     if ( iBufferingActiveCounter <= KErrNone )
       
   344         {
       
   345         // notify buffered SIDs
       
   346         iBufferingActiveCounter = KErrNone;
       
   347         iStorageFolder->NotifySIDChanges( iBufferedNotif );
       
   348         iBufferedNotif.Reset();
       
   349         }
       
   350     }
       
   351 
       
   352 //  End of File