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