|
1 /* |
|
2 * Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 /** |
|
20 @file |
|
21 @released |
|
22 @internalTechnology |
|
23 */ |
|
24 |
|
25 #ifndef __INTEGRITYTREE_H__ |
|
26 #define __INTEGRITYTREE_H__ |
|
27 |
|
28 #include <e32base.h> |
|
29 #include <f32file.h> |
|
30 #include "integrityservicesevent.h" |
|
31 #include "integrityservices.h" |
|
32 |
|
33 namespace Swi |
|
34 { |
|
35 |
|
36 class CIntegrityTreeNode; |
|
37 class CIntegrityTreeLeaf; |
|
38 |
|
39 typedef void(* TTreeWalkFunctionL)(const TDesC& aPath, CIntegrityTreeLeaf* aLeaf, RFs& aFs, RLoader& aLoader, CFileMan& aFileMan); |
|
40 |
|
41 class CIntegrityTreeLeaf : public CBase |
|
42 { |
|
43 public: |
|
44 /** |
|
45 * Constructs a file tree leaf, and places it on the cleanup stack |
|
46 * |
|
47 * @param aFileName The filename for this leaf node |
|
48 * @param aType The type of this leaf |
|
49 * @param aOwningJournal A reference to the filename of the owning journal |
|
50 * @return A fully constructed tree leaf |
|
51 */ |
|
52 static CIntegrityTreeLeaf* NewLC(const TDesC& aFileName, TIntegrityServicesEvent aType, |
|
53 const TDesC& aOwningJournal); |
|
54 |
|
55 /** |
|
56 * Sets the peer node if applicable. This is used for leaves that |
|
57 * naturally form pairs, for example a removed file and its backup. |
|
58 * |
|
59 * @param aPeer The leaf's peer. |
|
60 * |
|
61 */ |
|
62 |
|
63 void SetPeer(CIntegrityTreeLeaf* aPeer); |
|
64 |
|
65 /** |
|
66 * Returns the leaf's peer, or null if none was set |
|
67 * |
|
68 * @return The leaf's peer node if available |
|
69 * |
|
70 */ |
|
71 |
|
72 CIntegrityTreeLeaf* Peer(); |
|
73 |
|
74 /** |
|
75 * Returns the type of this leaf. |
|
76 * |
|
77 * @return This leaf's type |
|
78 */ |
|
79 |
|
80 TIntegrityServicesEvent Type(); |
|
81 |
|
82 /** |
|
83 * Returns the file name for this leaf |
|
84 * |
|
85 * @return The file name for this leaf |
|
86 */ |
|
87 |
|
88 const TDesC& Name(); |
|
89 |
|
90 /** |
|
91 * Returns the name of the journal file that owns this leaf |
|
92 * |
|
93 * @return The associated journal file name |
|
94 */ |
|
95 |
|
96 const TDesC& Journal(); |
|
97 |
|
98 ~CIntegrityTreeLeaf(); |
|
99 private: |
|
100 CIntegrityTreeLeaf(TIntegrityServicesEvent aType, const TDesC& aOwningJournal); |
|
101 void ConstructL(const TDesC& aFileName); |
|
102 |
|
103 private: |
|
104 HBufC* iFileName; |
|
105 TIntegrityServicesEvent iType; |
|
106 CIntegrityTreeLeaf* iPeer; |
|
107 |
|
108 const TDesC& iOwningJournal; |
|
109 |
|
110 }; |
|
111 |
|
112 class CIntegrityTreeNode : public CBase |
|
113 { |
|
114 public: |
|
115 /** |
|
116 * Constructs a file tree node, and places it on the cleanup stack |
|
117 * |
|
118 * @param aDirectoryName The name of the directory this node represents |
|
119 * @return A fully constructed tree node |
|
120 */ |
|
121 |
|
122 static CIntegrityTreeNode* NewL(const TDesC& aDirectoryName); |
|
123 |
|
124 /** |
|
125 * Constructs a file tree node |
|
126 * |
|
127 * @param aDirectoryName The name of the directory this node represents |
|
128 * @return A fully constructed tree node |
|
129 */ |
|
130 |
|
131 static CIntegrityTreeNode* NewLC(const TDesC& aDirectoryName); |
|
132 |
|
133 /** |
|
134 * Returns the name of the directory this node represents |
|
135 * |
|
136 * @return The name of this directory |
|
137 */ |
|
138 |
|
139 const TDesC& Name(); |
|
140 |
|
141 /** |
|
142 * Adds a leaf node to this tree structure, adding intermediate (directory) nodes along |
|
143 * the way as appropriate. |
|
144 * |
|
145 * @param aFileName The fully qualified file name of the node to add |
|
146 * @param aType The type of the node to add |
|
147 * @param aOwningJournal The file name of the journal that owns this node |
|
148 * @return The leaf node added. |
|
149 * |
|
150 */ |
|
151 |
|
152 CIntegrityTreeLeaf* AddNodeL(const TDesC& aFileName, TIntegrityServicesEvent aType, const TDesC& aOwningJournal); |
|
153 |
|
154 /** |
|
155 * Finds a node in the tree if it exists. |
|
156 * |
|
157 * @param aFileName The file name to find |
|
158 * @param aType The type of node to find |
|
159 * @return KErrNone if found, otherwise one of the system wide error codes |
|
160 */ |
|
161 |
|
162 TInt FindNode(const TDesC& aFileName, TIntegrityServicesEvent aType); |
|
163 |
|
164 /** |
|
165 * Applies a function to every applicable node in the tree |
|
166 * |
|
167 * @param aFunc The function to apply |
|
168 * @param aTypeFilter The type of node to apply the function to |
|
169 * @param aFs A connected file server session |
|
170 * @param aLoader reference to the RLoader server session |
|
171 * @param aFileMan A constructed CFileMan object |
|
172 * @param aIntegrityServices The parent class for this journal, used exclusively for testing |
|
173 * @param aFailType The type of failure to induce if required. Used exclusively in testing. |
|
174 * |
|
175 */ |
|
176 |
|
177 void WalkTreeL(TTreeWalkFunctionL aFunc, TIntegrityServicesEvent aTypeFilter, |
|
178 RFs& aFs, RLoader& aLoader, CFileMan& aFileMan, |
|
179 CIntegrityServices& aIntegrityServices, CIntegrityServices::TFailType aFailType); |
|
180 |
|
181 ~CIntegrityTreeNode(); |
|
182 protected: |
|
183 CIntegrityTreeLeaf* DoAddNodeL(TDes& aFileName, TIntegrityServicesEvent aType, const TDesC& aOwningJournal); |
|
184 TInt DoFindNode(TDes& aFileName, TIntegrityServicesEvent aType); |
|
185 void DoWalkTreeL(TDes& aPath, TTreeWalkFunctionL aFunc, TIntegrityServicesEvent aTypeFilter, |
|
186 RFs& aFs, RLoader& aLoader, CFileMan& aFileMan, |
|
187 CIntegrityServices& aIntegrityServices, CIntegrityServices::TFailType aFailType); |
|
188 |
|
189 private: |
|
190 CIntegrityTreeNode(); |
|
191 void ConstructL(const TDesC& aDirectoryName); |
|
192 |
|
193 private: |
|
194 HBufC* iDirName; |
|
195 RPointerArray<CIntegrityTreeNode> iDirectories; |
|
196 RPointerArray<CIntegrityTreeLeaf> iFiles; |
|
197 |
|
198 friend class Swi::CIntegrityServices; |
|
199 }; |
|
200 |
|
201 } // namespace Swi |
|
202 |
|
203 #endif /* __INTEGRITYTREE_H__ */ |