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