1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/userlibandfileserver/fileserver/sfat32/sl_leafdir_cache.h Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,188 @@
1.4 +// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of the License "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// f32\sfat32\inc\sl_leafdir_cache.h
1.18 +//
1.19 +//
1.20 +
1.21 +/**
1.22 + @file
1.23 + @internalTechnology
1.24 +*/
1.25 +
1.26 +#ifndef SL_LEAFDIR_CACHE_H
1.27 +#define SL_LEAFDIR_CACHE_H
1.28 +
1.29 +//---------------------------------------------------------------------------------------------------------------------------------
1.30 +
1.31 +class CLeafDirTree;
1.32 +
1.33 +/*
1.34 +A data structure to define the location of a direcotry
1.35 +*/
1.36 +class TLeafDirData
1.37 + {
1.38 +public:
1.39 + TLeafDirData();
1.40 + TLeafDirData(TUint aClusterNum);
1.41 + TLeafDirData(TUint aClusterNum, const TEntryPos& aMRUPos);
1.42 + inline TBool operator==(const TLeafDirData &aDirPos) const;
1.43 + inline TBool operator!=(const TLeafDirData &aDirPos) const;
1.44 +public:
1.45 + TUint iClusterNum;
1.46 + TEntryPos iMRUPos;
1.47 + };
1.48 +
1.49 +/*
1.50 +Class definition for the nodes of the leaf dir cache
1.51 +All cached direcotries are stored as nodes in a tree structure
1.52 +
1.53 +*/
1.54 +class CLeafDirTreeNode : public CBase
1.55 + {
1.56 +public:
1.57 + // Types of the nodes
1.58 + enum TLeafDirTreeNodeType
1.59 + {
1.60 + ERoot, // Represents the root node, i.e. the root path
1.61 + ELeaf, // Represents a pure 'leaf' nodes, no child
1.62 + ELeafIntermediary, // Represents a 'leaf' node, but has at least one child
1.63 + EPureIntermediary, // Represents a pure 'intermediary' node, which only exists to share the common path of other nodes
1.64 + };
1.65 +
1.66 + static CLeafDirTreeNode* NewL(CLeafDirTree* aOwnerTree, const TDesC& aPathName, const TLeafDirData& aDirPos, TLeafDirTreeNodeType aType);
1.67 + ~CLeafDirTreeNode();
1.68 + inline CLeafDirTreeNode* Parent();
1.69 + inline void SetParent(CLeafDirTreeNode* aNode);
1.70 + inline RPointerArray<CLeafDirTreeNode>& Children();
1.71 + void MakeItChildL(CLeafDirTreeNode* aNode);
1.72 + TInt RemoveChild(CLeafDirTreeNode* aNode);
1.73 + inline const TLeafDirData& LeafDirData() const;
1.74 + inline TUint32 StartClusterNum() const;
1.75 + inline void SetLeafDirData(const TLeafDirData& aLeafDirData);
1.76 + inline const TDesC& Path() const;
1.77 + void SetPathL(const TDesC& aPathData);
1.78 + void SetType(const CLeafDirTreeNode::TLeafDirTreeNodeType aType);
1.79 + inline TBool IsRoot() const;
1.80 + inline TBool IsLeaf();
1.81 + inline TBool IsLeafIntermediary();
1.82 + inline TBool IsPureIntermediary();
1.83 +
1.84 +private:
1.85 + void ConstructL(CLeafDirTree* aOwnerTree, const TDesC& aPathName);
1.86 + CLeafDirTreeNode(const TLeafDirData& aDirPos , TLeafDirTreeNodeType aType);
1.87 + CLeafDirTreeNode(const CLeafDirTreeNode& aLeafDirTreeNode);
1.88 + CLeafDirTreeNode* operator=(CLeafDirTreeNode& aLeafDirTreeNode);
1.89 +
1.90 +private:
1.91 + CLeafDirTree* iOwnerTree; // A pointer to the owner of this node.
1.92 + CLeafDirTreeNode* iParent; // The parent of this node
1.93 + RPointerArray<CLeafDirTreeNode> iChildren; // The children of this node
1.94 + RBuf iPath; // The path of the direcotry this node represents
1.95 + TLeafDirData iLeafDirData; // The position of the direcotry this node represents
1.96 + TLeafDirTreeNodeType iNodeType; // The type of the node
1.97 + };
1.98 +
1.99 +/*
1.100 +Class definition for the tree structure of the leaf dir cache
1.101 +All cached direcotries are stored as nodes in a tree structure
1.102 +
1.103 +*/
1.104 +class CLeafDirTree : public CBase
1.105 + {
1.106 +public:
1.107 + static CLeafDirTree* NewL(TUint32 aSize);
1.108 + ~CLeafDirTree();
1.109 +
1.110 +public:
1.111 + TInt Search(const TDesC& aPath, CLeafDirTreeNode*& aNodeFound, TLeafDirData& aDirPos);
1.112 + TInt DoSearch(const TDesC& aPath, CLeafDirTreeNode* aNodeToStart, CLeafDirTreeNode*& aNodeFound, TLeafDirData& aDirPos);
1.113 + void InsertL(const TDesC& aPath, const TLeafDirData& aDirPos, CLeafDirTreeNode*& aNodeInserted);
1.114 + void DoInsertL(CLeafDirTreeNode* aNodeToStart, const TDesC& aPath, const TLeafDirData& aDirPos, CLeafDirTreeNode*& aNodeInserted);
1.115 + void RemoveDirL(const TLeafDirData& aDirPos);
1.116 + void UpdateMRUPos(const TLeafDirData& aLeafDirData);
1.117 + void RemoveFromCacheL(CLeafDirTreeNode* aNodeToDelete);
1.118 + CLeafDirTreeNode* FindLeftestLeafNode(CLeafDirTreeNode* aNodeToStart) const;
1.119 + void DeleteSubTreeL(CLeafDirTreeNode* aNodeToStart);
1.120 + void Reset();
1.121 + CLeafDirTreeNode* LruNode();
1.122 + void AddOntoLruL(CLeafDirTreeNode* aNodeToAdd);
1.123 + TInt RemoveFromLru(CLeafDirTreeNode* aNodeToRemove);
1.124 + TInt MakeMostRecentlyUsed(CLeafDirTreeNode* aNodeUsed);
1.125 + inline TInt LruCount() const;
1.126 + void CheckLimitL();
1.127 +
1.128 + // For debugging & testing only
1.129 + #ifdef _DEBUG
1.130 + TInt ObjectCount() const {return iContainer.Count();};
1.131 + void AddToObjectContainerL(CLeafDirTreeNode* aNode);
1.132 + void RemoveFromObjectContainerL(CLeafDirTreeNode* aNode);
1.133 + void DumpTreeContentL() const;
1.134 + #endif //_DEBUG
1.135 +
1.136 +private:
1.137 + void ConstructL();
1.138 + CLeafDirTree(TUint32 aSize);
1.139 +
1.140 +private:
1.141 + CLeafDirTreeNode* iRoot; // The root node
1.142 + RPointerArray<CLeafDirTreeNode> iLruList; // The list containing all the LRU cached nodes
1.143 + TUint32 iSize; // The maximum number of items allowed to cache
1.144 +
1.145 + // For debugging & testing only
1.146 + #ifdef _DEBUG
1.147 + RPointerArray<CLeafDirTreeNode> iContainer; // The container containing all nodes
1.148 + #endif //_DEBUG
1.149 + };
1.150 +
1.151 +/*
1.152 +Class definition for leaf directory cache.
1.153 +Acting as an interface class for CFatMountCB to use.
1.154 +
1.155 +*/
1.156 +class CLeafDirCache : public CBase
1.157 + {
1.158 +public:
1.159 + static CLeafDirCache* NewL(TUint32 aLimit);
1.160 + ~CLeafDirCache();
1.161 + void Reset();
1.162 + TInt FindInCache(const TDesC& aLeafDirName, TLeafDirData& aDirPos) const;
1.163 + void AddToCacheL(const TDesC& aLeafDirName, const TLeafDirData& aDirPos);
1.164 + void RemoveDirL(const TLeafDirData& aDirPos);
1.165 + void UpdateMRUPos(const TLeafDirData& aLeafDirData);
1.166 + TInt CacheCount() const;
1.167 +
1.168 + // For debugging & testing only
1.169 + #ifdef _DEBUG
1.170 + void DumpCacheContentL() const;
1.171 + TInt NodeCount() const;
1.172 + #endif //_DEBUG
1.173 +
1.174 +private:
1.175 + CLeafDirCache(TUint32 aLimit);
1.176 + void ConstructL();
1.177 +
1.178 +private:
1.179 + TUint32 iSize; // The cache size
1.180 + CLeafDirTree* iTree; // The cache content, represented as a tree structure
1.181 + };
1.182 +
1.183 +//---------------------------------------------------------------------------------------------------------------------------------
1.184 +
1.185 +#include"sl_leafdir_cache.inl"
1.186 +
1.187 +#endif //SL_LEAFDIR_CACHE_H
1.188 +
1.189 +
1.190 +
1.191 +