userlibandfileserver/fileserver/sfat/sl_dir_cache.h
changeset 9 96e5fb8b040d
equal deleted inserted replaced
-1:000000000000 9:96e5fb8b040d
       
     1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of the License "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // f32\sfat32\inc\sl_dir_cache.h
       
    15 // 
       
    16 //
       
    17 
       
    18 /**
       
    19  @file
       
    20  @internalTechnology
       
    21 */
       
    22 
       
    23 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
       
    24 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
       
    25 //!!
       
    26 //!! WARNING!! DO NOT edit this file !! '\sfat' component is obsolete and is not being used. '\sfat32'replaces it
       
    27 //!!
       
    28 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
       
    29 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
       
    30 
       
    31 
       
    32 #ifndef SL_DIR_CACHE_H
       
    33 #define SL_DIR_CACHE_H
       
    34 
       
    35 #include "sf_memory_man.h"
       
    36 #include "sf_memory_client.h"
       
    37 #include "sl_cache.h"
       
    38 #include <e32hashtab.h>
       
    39 
       
    40 //---------------------------------------------------------------------------------------------------------------------------------
       
    41 class   CDynamicDirCache;
       
    42 
       
    43 
       
    44 /**
       
    45 The dynamic directory cache page class
       
    46 */
       
    47 class TDynamicDirCachePage
       
    48     {
       
    49 public:
       
    50     enum TPageType
       
    51         {
       
    52         EUnknown,
       
    53         ELocked,
       
    54         EUnlocked,
       
    55         EActivePage,
       
    56         };
       
    57 
       
    58 public:
       
    59     ~TDynamicDirCachePage();
       
    60     static TDynamicDirCachePage* NewL(CDynamicDirCache* aOwnerCache, TInt64 aStartMedPos, TUint8* aStartRamAddr);
       
    61     
       
    62     inline void SetLocked(TBool);
       
    63     inline TBool    IsLocked() const;
       
    64     inline TUint8*  StartPtr()  const;
       
    65     inline void     SetStartPtr(TUint8* aPtr);
       
    66     inline void SetValid(TBool aIsValid);
       
    67     inline TBool    IsValid()   const;
       
    68     inline void SetPageType(TPageType aType);
       
    69     inline TPageType PageType();
       
    70 
       
    71     inline TUint32  PageSizeInBytes() const;
       
    72     inline TUint32  PageSizeInSegs() const;
       
    73 
       
    74     inline void SetPos(TInt64 aPos);
       
    75     inline void ResetPos();
       
    76     inline TInt64   StartPos()  const;
       
    77 
       
    78     inline TUint8*  PtrInPage(TInt64 aPos) const;
       
    79     inline TBool    PosCachedInPage(TInt64 aPos) const;
       
    80 
       
    81     inline void Deque();
       
    82 
       
    83 private:
       
    84     // declared to disable copying and assignment
       
    85     TDynamicDirCachePage& operator=(const TDynamicDirCachePage&);
       
    86     TDynamicDirCachePage(const TDynamicDirCachePage&);
       
    87 
       
    88     // private constructor, as this class is not supposed to be created on stack
       
    89     TDynamicDirCachePage(CDynamicDirCache* aOwnerCache, TInt64 aStartMedPos, TUint8* aStartRamAddr);
       
    90 
       
    91 public:
       
    92     TDblQueLink         iLink;          ///< the embedded link object, see TCachePageList
       
    93     TInt64              iStartMedPos;   ///< the starting media address that this page caches
       
    94     TUint8*             iStartRamAddr;  ///< the starting ram address that thsi page lives
       
    95     CDynamicDirCache*   iOwnerCache;    ///< pointer to the cache that owns this page
       
    96     TBool               iValid  :1;     ///< flag to indicate the validity of the page content
       
    97     TBool               iLocked :1;     ///< flag to indicate if the page is locked or not
       
    98     TPageType           iType;          ///< page type, see TPageType
       
    99     };
       
   100 
       
   101 /**
       
   102 The lookup table entry class
       
   103 @see    CDynamicDirCache
       
   104 */
       
   105 class TLookupEntry
       
   106     {
       
   107     public:
       
   108         TLookupEntry(): iPos(0), iRange(0), iPage(NULL) {};
       
   109         TLookupEntry(TInt64 aPos, TUint32 aRange, TDynamicDirCachePage* aPage): iPos(aPos), iRange(aRange), iPage(aPage) {};
       
   110     public:
       
   111         TInt64                  iPos;
       
   112         TUint32                 iRange;
       
   113         TDynamicDirCachePage*   iPage;
       
   114     };
       
   115 
       
   116 //---------------------------------------------------------------------------------------------------------------------------------
       
   117 typedef TDblQue<TDynamicDirCachePage> TCachePageList;
       
   118 /**
       
   119 Dynamic directory cache.
       
   120 For now it is directly derived from MWTCacheInterface.
       
   121 Provides caching FAT directory data.
       
   122 */
       
   123 class CDynamicDirCache : public CBase, public MWTCacheInterface
       
   124     {
       
   125 public:
       
   126     ~CDynamicDirCache();
       
   127     static CDynamicDirCache* NewL(TFatDriveInterface& aDrive, TUint32 aMinPageNum, TUint32 aMaxPageNum, TUint32 aPageSizeLog2, const TDesC& aClientName);
       
   128 
       
   129     //-- overloads from the base class
       
   130     void    ReadL (TInt64 aPos, TInt aLength, TDes8& aDes);
       
   131     void    WriteL(TInt64 aPos, const TDesC8& aDes);
       
   132     void    InvalidateCache(void);
       
   133     void    InvalidateCachePage(TUint64 aPos);
       
   134 
       
   135     TUint32 PosCached(const TInt64& aPosToSearch, TInt64& aCachedPosStart);
       
   136     TUint32 CacheSizeInBytes()  const;
       
   137     TInt    Control(TUint32 aFunction, TUint32 aParam1, TAny* aParam2);
       
   138     void    SetCacheBasePos(TInt64 aBasePos);
       
   139     void    MakePageMRU(TInt64 aPos);
       
   140     TUint32 PageSizeInBytesLog2() const;
       
   141     
       
   142     TUint32 PageSizeInSegs() const;
       
   143 
       
   144     // Debugging functions
       
   145     void Dump();
       
   146     void Info() const;
       
   147 
       
   148 protected:
       
   149     CDynamicDirCache(TFatDriveInterface& aDrive, TUint32 aMinSizeInBytes, TUint32 aMaxSizeInBytes, TUint32 aPageSizeInBytesLog2);
       
   150     void ConstructL(const TDesC& aClientName);
       
   151 
       
   152     void ReadDataFromSinglePageL(TInt64 aPos, TInt aLength, TDes8& aDes);
       
   153     void WriteDataOntoSinglePageL(TInt64 aPos, const TUint8* aData, TUint32 aDataLen);
       
   154     TDynamicDirCachePage* FindPageByPos(TInt64 aPos);
       
   155     TDynamicDirCachePage* UpdateActivePageL(TInt64 aPos);
       
   156     TDynamicDirCachePage* AllocateAndLockNewPageL(TInt64 aStartMedPos);
       
   157     TUint8* LockPage(TDynamicDirCachePage* aPage);
       
   158     TInt    UnlockPage(TDynamicDirCachePage* aPage);
       
   159     TInt    DecommitPage(TDynamicDirCachePage* aPage);
       
   160     inline TInt64  CalcPageStartPos(TInt64 aPos) const;
       
   161     void CheckThresholds();
       
   162     inline TBool CacheIsFull() const;
       
   163     inline TUint32 MaxCacheSizeInPages() const;
       
   164     TInt DeQueue(TDynamicDirCachePage* aPage);
       
   165     TInt AddFirstOntoQueue(TDynamicDirCachePage* aPage, TDynamicDirCachePage::TPageType aType);
       
   166     TInt LookupTblRemove(TInt64 aPagePos);
       
   167     TInt LookupTblAdd(TDynamicDirCachePage* aPage);
       
   168     TDynamicDirCachePage* LookupTblFind(TInt64 aPos);
       
   169     TInt ResetPagePos(TDynamicDirCachePage* aPage);
       
   170     void MakePageLastLocked(TDynamicDirCachePage* aPage);
       
   171     
       
   172 private:
       
   173     TUint32             iPageSizeLog2;      ///< log2 value of cache pages size in bytes
       
   174     TUint32             iMinCacheSizeInBytes;   ///< minimum cache data size
       
   175     TUint32             iMaxCacheSizeInBytes;   ///< maximum cache data size
       
   176     TUint32             iMinSizeInPages;    ///< minimum cache page number
       
   177     TUint32             iMaxSizeInPages;    ///< maximum cache page number
       
   178     TUint32             iPageSizeInBytes;   ///< cache page size in bytes
       
   179     TInt64              iCacheBasePos;      ///< cache pages base position, used to align them at cluster size
       
   180 
       
   181     TFatDriveInterface& iDrive;             ///< reference to the driver for media access
       
   182     TUint32             iCacheDisabled : 1; ///< if not 0 the cache is disabled totally and all reads and writes go via TFatDriveInterface directly
       
   183 
       
   184     TDynamicDirCachePage*   iActivePage;    ///< a unique page in cache, used to read new page before make it MRU or have it replaced
       
   185     
       
   186     // data structures for LRU page list    
       
   187     TCachePageList  iLockedQ;               ///< the locked queue that manages all locked pages, limited by minimum page number
       
   188     TCachePageList  iUnlockedQ;             ///< the unlocked queue that manages all locked pages, limited by maximum page number - minimum page number
       
   189     TUint32         iLockedQCount;
       
   190     TUint32         iUnlockedQCount;
       
   191 
       
   192     // data structures for look up table
       
   193     THashFunction32<TLookupEntry>   iHashFunction;
       
   194     TIdentityRelation<TLookupEntry> iIdentityFunction;
       
   195     RHashSet<TLookupEntry>          iLookupTable;   ///< a lookup table that used to speed up page look up
       
   196 
       
   197     CCacheMemoryClient* iCacheMemoryClient; ///< interface to cache memory manager
       
   198     };
       
   199 
       
   200 #include"sl_dir_cache.inl"
       
   201 
       
   202 #endif //SL_DIR_CACHE_H
       
   203 
       
   204 
       
   205 
       
   206