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