landmarks/locationlandmarks/server/inc/EPos_CPosLmLocalAccessSubsession.h
changeset 0 667063e416a2
equal deleted inserted replaced
-1:000000000000 0:667063e416a2
       
     1 /*
       
     2 * Copyright (c) 2002-2005 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: subsession class for operations related to local access.
       
    15 *
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 #ifndef CPOSLMLOCALACCESSSUBSESSION_H
       
    21 #define CPOSLMLOCALACCESSSUBSESSION_H
       
    22 
       
    23 #include <EPos_Landmarks.h>
       
    24 #include "EPos_CPosLmSubsessionBase.h"
       
    25 #include "EPos_PosLmServerCommon.h"
       
    26 #include "EPos_CPosLmNameIndex.h"
       
    27 
       
    28 class CPosLmEventHandler;
       
    29 class CPosLmLocalDbAccess;
       
    30 class CPosLmActiveCompacter;
       
    31 class CPosLmNameIndex;
       
    32 
       
    33 
       
    34 /**
       
    35 * This is a subsession class for operations related to local access.
       
    36 */
       
    37 class CPosLmLocalAccessSubsession : public CPosLmSubsessionBase
       
    38     {
       
    39 
       
    40     public: // Constructors and destructor
       
    41 
       
    42         /**
       
    43         * Two-phased constructor.
       
    44         *
       
    45         * @param[in] aLmServer Reference to the landmark server.
       
    46         */
       
    47         static CPosLmLocalAccessSubsession* NewLC( CPosLmServer* aServer );
       
    48 
       
    49         ~CPosLmLocalAccessSubsession();
       
    50 
       
    51     public: 
       
    52 
       
    53         /**
       
    54         * Checks if the db of this subsession matches the specified URI and if
       
    55         * so if the db has a write lock.
       
    56         *
       
    57         * @param[in] aUri The URI to compare with.
       
    58         * @return ETrue if the URI matches and this subsession has a write
       
    59         *   lock, otherwise EFalse.
       
    60         */
       
    61         TBool HasWriteLock( const TDesC& aUri );
       
    62 
       
    63         /**
       
    64         * Checks if the db of this subsession matches the specified URI and if
       
    65         * so if the db has any lock.
       
    66         *
       
    67         * @param[in] aUri The URI to compare with.
       
    68         * @return ETrue if the URI matches and this subsession has any lock,
       
    69         *   otherwise EFalse.
       
    70         */
       
    71         TBool HasAnyLock( const TDesC& aUri );
       
    72 
       
    73         /**
       
    74         * Handles an incoming operation event from the server. If the URI
       
    75         * matches the URI associated with this subsession, the event is
       
    76         * forwarded to the client, if it is listening for events.
       
    77         *
       
    78         * @param[in] aEvent The event.
       
    79         * @param[in] aUri A URI associated with the database from which the event
       
    80         *   was generated.
       
    81         * @param[in] aCheckUri ETrue if the URI should be checked. EFalse otherwise.
       
    82         */
       
    83         void HandleOperationEventL(
       
    84             TPosLmEvent aEvent,
       
    85             const TDesC& aUri,
       
    86             TBool aCheckUri );
       
    87 
       
    88         /**
       
    89         * Completes outstanding events in the event handler.
       
    90         *
       
    91         * @param[in] aError An error code to complete the request with.
       
    92         */
       
    93         void CompleteOutstandingEventRequest( TInt aError );
       
    94 
       
    95         /** Releases the write lock for an internal compact. */
       
    96         void ReleaseCompactLock();
       
    97 
       
    98     public: // Functions from base classes
       
    99 
       
   100         /** Handles the servicing of client requests to the server.
       
   101         * @param[in] aMessage The message containing the client request.
       
   102         */
       
   103         void ServiceL( const RMessage2& aMessage );
       
   104 
       
   105     private:
       
   106 
       
   107         /**
       
   108         * C++ default constructor.
       
   109         *
       
   110         * @param[in] aLmServer Reference to the landmark server.
       
   111         */
       
   112         CPosLmLocalAccessSubsession( CPosLmServer* aServer );
       
   113 
       
   114         void ConstructL();
       
   115 
       
   116         /**
       
   117         * Reads and stores the database URI sent from the client. The URI
       
   118         * shows which database the client is connected to. The message
       
   119         * is completed with KErrNone within this function.
       
   120         *
       
   121         * @param[in] aMessage Message containing the client request.
       
   122         */
       
   123         void RegisterUriL( const RMessage2& aMessage );
       
   124 
       
   125         void DatabaseLockL( const RMessage2& aMessage );
       
   126 
       
   127         void ForwardEventToAllSessionsL( const RMessage2& aMessage );
       
   128 
       
   129         void CreateDefaultDatabaseL( const RMessage2& aMessage );
       
   130 
       
   131         void HandleReadSortedLandmarksL( const RMessage2& aMessage );
       
   132         void GetSortedLandmarksL( 
       
   133             CPosLmNameIndex& aNameIndex,
       
   134             RWriteStream& aOut,
       
   135             TPosLmServerReadArrayParam& aParam,
       
   136             TInt aMaxSize );
       
   137         void GetSortedLandmarksReverseL( 
       
   138             CPosLmNameIndex& aNameIndex,
       
   139             RWriteStream& aOut,
       
   140             TPosLmServerReadArrayParam& aParam,
       
   141             TInt aMaxSize );
       
   142         TBool ExportIndexItemL( 
       
   143             const CPosLmNameIndex::CItem& aItem,
       
   144             RWriteStream& aOut,
       
   145             TInt& aLeftInBuffer,
       
   146             TPosLmServerReadArrayParam& aParam );
       
   147         
       
   148         void HandleReadSortedIdsL( const RMessage2& aMessage );
       
   149         
       
   150         void HandleUpdateLandmarkIndexL( const RMessage2& aMessage );
       
   151 
       
   152         void HandleLandmarksAddedOrUpdatedL( const RMessage2& aMessage );
       
   153         
       
   154         void HandleLandmarksRemovedL( const RMessage2& aMessage );
       
   155 
       
   156         void CheckDiskSizeL( const TDesC& aUri );
       
   157 
       
   158         void CompactIfNeededL();
       
   159         
       
   160         void HandleDataTransactionL( const RMessage2& aMessage );
       
   161         
       
   162         void HandleNameIndexStatusL( const RMessage2& aMessage );
       
   163         
       
   164         void HandleUseNameIndexL( const RMessage2& aMessage );
       
   165         
       
   166         /** Leaves, if index for this database is not loaded.
       
   167          *  To ensure that index is loaded, client has to register
       
   168          *  with EPosLmServerOpenNameIndex */
       
   169         void AssertIndexLoadedL();
       
   170 
       
   171     private:    // Data
       
   172 
       
   173         // Database URI associated with the client database.
       
   174         HBufC* iDbUri;
       
   175 
       
   176         CPosLmLocalDbAccess* iDbAccess;
       
   177 
       
   178         CPosLmEventHandler* iEventHandler;
       
   179 
       
   180         TBool iHasWriteLock;
       
   181 
       
   182         TInt iNoOfReadLocks;
       
   183 
       
   184         CPosLmActiveCompacter* iCompacter;
       
   185         
       
   186         TBool iUsingNameIndex;
       
   187     };
       
   188 
       
   189 #endif //CPOSLMLOCALACCESSSUBSESSION_H
       
   190