os/kernelhwsrv/userlibandfileserver/fileserver/sfat/sl_leafdir_cache.h
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     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_leafdir_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_LEAFDIR_CACHE_H
    33 #define SL_LEAFDIR_CACHE_H
    34 
    35 //---------------------------------------------------------------------------------------------------------------------------------
    36 
    37 class CLeafDirTree;
    38 
    39 /*
    40 A data structure to define the location of a direcotry 
    41 */
    42 class TLeafDirData
    43     {
    44 public:
    45     TLeafDirData();
    46     TLeafDirData(TUint aClusterNum);
    47     TLeafDirData(TUint aClusterNum, const TEntryPos& aMRUPos);
    48     inline TBool operator==(const TLeafDirData &aDirPos) const;
    49     inline TBool operator!=(const TLeafDirData &aDirPos) const;
    50 public:
    51     TUint       iClusterNum;
    52     TEntryPos   iMRUPos;
    53     };
    54 
    55 /*
    56 Class definition for the nodes of the leaf dir cache
    57 All cached direcotries are stored as nodes in a tree structure
    58  
    59 */
    60 class CLeafDirTreeNode : public CBase
    61     {
    62 public:
    63     // Types of the nodes
    64     enum  TLeafDirTreeNodeType
    65         {
    66         ERoot,              // Represents the root node, i.e. the root path
    67         ELeaf,              // Represents a pure 'leaf' nodes, no child
    68         ELeafIntermediary,  // Represents a 'leaf' node, but has at least one child
    69         EPureIntermediary,  // Represents a pure 'intermediary' node, which only exists to share the common path of other nodes
    70         };
    71 
    72     static CLeafDirTreeNode* NewL(CLeafDirTree* aOwnerTree, const TDesC& aPathName, const TLeafDirData& aDirPos, TLeafDirTreeNodeType aType);
    73     ~CLeafDirTreeNode();
    74     inline CLeafDirTreeNode* Parent();
    75     inline void SetParent(CLeafDirTreeNode* aNode);
    76     inline RPointerArray<CLeafDirTreeNode>& Children();
    77     void MakeItChildL(CLeafDirTreeNode* aNode);
    78     TInt RemoveChild(CLeafDirTreeNode* aNode);
    79     inline const TLeafDirData& LeafDirData() const;
    80     inline TUint32 StartClusterNum() const;
    81     inline void SetLeafDirData(const TLeafDirData& aLeafDirData);
    82     inline const TDesC& Path() const;
    83     void SetPathL(const TDesC& aPathData);
    84     void SetType(const CLeafDirTreeNode::TLeafDirTreeNodeType aType);
    85     inline TBool IsRoot() const;
    86     inline TBool IsLeaf();
    87     inline TBool IsLeafIntermediary();
    88     inline TBool IsPureIntermediary();
    89 
    90 private:
    91     void ConstructL(CLeafDirTree* aOwnerTree, const TDesC& aPathName);
    92     CLeafDirTreeNode(const TLeafDirData& aDirPos , TLeafDirTreeNodeType aType);
    93     CLeafDirTreeNode(const CLeafDirTreeNode& aLeafDirTreeNode);
    94     CLeafDirTreeNode* operator=(CLeafDirTreeNode& aLeafDirTreeNode);
    95 
    96 private:
    97     CLeafDirTree* iOwnerTree;                   // A pointer to the owner of this node.
    98     CLeafDirTreeNode* iParent;                  // The parent of this node 
    99     RPointerArray<CLeafDirTreeNode> iChildren;  // The children of this node
   100     RBuf iPath;                                 // The path of the direcotry this node represents
   101     TLeafDirData iLeafDirData;                  // The position of the direcotry this node represents
   102     TLeafDirTreeNodeType iNodeType;             // The type of the node
   103     };
   104 
   105 /*
   106 Class definition for the tree structure of the leaf dir cache
   107 All cached direcotries are stored as nodes in a tree structure
   108 
   109 */
   110 class CLeafDirTree : public CBase
   111     {
   112 public:
   113     static CLeafDirTree* NewL(TUint32 aSize);
   114     ~CLeafDirTree();
   115 
   116 public:
   117     TInt Search(const TDesC& aPath, CLeafDirTreeNode*& aNodeFound, TLeafDirData& aDirPos); 
   118     TInt DoSearch(const TDesC& aPath, CLeafDirTreeNode* aNodeToStart, CLeafDirTreeNode*& aNodeFound, TLeafDirData& aDirPos);
   119     void InsertL(const TDesC& aPath, const TLeafDirData& aDirPos, CLeafDirTreeNode*& aNodeInserted);
   120     void DoInsertL(CLeafDirTreeNode* aNodeToStart, const TDesC& aPath, const TLeafDirData& aDirPos, CLeafDirTreeNode*& aNodeInserted);
   121     void RemoveDirL(const TLeafDirData& aDirPos);
   122     void UpdateMRUPos(const TLeafDirData& aLeafDirData);
   123     void RemoveFromCacheL(CLeafDirTreeNode* aNodeToDelete);
   124     CLeafDirTreeNode* FindLeftestLeafNode(CLeafDirTreeNode* aNodeToStart) const;
   125     void DeleteSubTreeL(CLeafDirTreeNode* aNodeToStart);
   126     void Reset();
   127     CLeafDirTreeNode* LruNode();
   128     void AddOntoLruL(CLeafDirTreeNode* aNodeToAdd);
   129     TInt RemoveFromLru(CLeafDirTreeNode* aNodeToRemove);
   130     TInt MakeMostRecentlyUsed(CLeafDirTreeNode* aNodeUsed);
   131     inline TInt LruCount() const;
   132     void CheckLimitL();
   133     
   134     // For debugging & testing only
   135     #ifdef _DEBUG
   136         TInt ObjectCount() const {return iContainer.Count();};
   137         void AddToObjectContainerL(CLeafDirTreeNode* aNode);
   138         void RemoveFromObjectContainerL(CLeafDirTreeNode* aNode);
   139         void DumpTreeContentL() const;
   140     #endif  //_DEBUG
   141 
   142 private:
   143     void ConstructL();
   144     CLeafDirTree(TUint32 aSize);
   145 
   146 private:
   147     CLeafDirTreeNode* iRoot;                    // The root node
   148     RPointerArray<CLeafDirTreeNode> iLruList;   // The list containing all the LRU cached nodes
   149     TUint32 iSize;                              // The maximum number of items allowed to cache 
   150 
   151     // For debugging & testing only
   152     #ifdef _DEBUG
   153         RPointerArray<CLeafDirTreeNode> iContainer; // The container containing all nodes
   154     #endif  //_DEBUG
   155     };
   156 
   157 /*
   158 Class definition for leaf directory cache.
   159 Acting as an interface class for CFatMountCB to use.
   160 
   161 */
   162 class CLeafDirCache : public CBase
   163     {
   164 public: 
   165     static CLeafDirCache* NewL(TUint32 aLimit);
   166     ~CLeafDirCache();
   167     void Reset();
   168     TInt FindInCache(const TDesC& aLeafDirName, TLeafDirData& aDirPos) const; 
   169     void AddToCacheL(const TDesC& aLeafDirName, const TLeafDirData& aDirPos);
   170     void RemoveDirL(const TLeafDirData& aDirPos); 
   171     void UpdateMRUPos(const TLeafDirData& aLeafDirData);
   172     TInt CacheCount() const;
   173 
   174     // For debugging & testing only
   175     #ifdef _DEBUG
   176         void DumpCacheContentL() const;
   177         TInt NodeCount() const;
   178     #endif  //_DEBUG
   179 
   180 private:
   181     CLeafDirCache(TUint32 aLimit);
   182     void ConstructL();
   183 
   184 private:
   185     TUint32 iSize;          // The cache size
   186     CLeafDirTree* iTree;    // The cache content, represented as a tree structure
   187     };
   188 
   189 //---------------------------------------------------------------------------------------------------------------------------------
   190 
   191 #include"sl_leafdir_cache.inl"
   192 
   193 #endif //SL_LEAFDIR_CACHE_H
   194 
   195 
   196 
   197