|
1 /* |
|
2 * Copyright (c) 2005-2006 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 "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: State machine for getting attributes of a file |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "rsfwgetattributesstatemachine.h" |
|
20 #include "rsfwopenbypathstatemachine.h" |
|
21 #include "rsfwinterface.h" |
|
22 #include "rsfwrferequest.h" |
|
23 #include "rsfwrfeoperation.h" |
|
24 #include "rsfwfileentry.h" |
|
25 #include "rsfwfileengine.h" |
|
26 #include "mdebug.h" |
|
27 #include "rsfwdirentattr.h" |
|
28 #include "rsfwvolumetable.h" |
|
29 |
|
30 // ---------------------------------------------------------------------------- |
|
31 // CRsfwGetAttributesStateMachine::CRsfwGetAttributesStateMachine |
|
32 // ---------------------------------------------------------------------------- |
|
33 // |
|
34 CRsfwGetAttributesStateMachine::CRsfwGetAttributesStateMachine() |
|
35 { |
|
36 } |
|
37 |
|
38 // ---------------------------------------------------------------------------- |
|
39 // CRsfwGetAttributesStateMachine::CompleteRequestL |
|
40 // ---------------------------------------------------------------------------- |
|
41 // |
|
42 CRsfwRfeStateMachine::TState* CRsfwGetAttributesStateMachine::CompleteRequestL(TInt aError) |
|
43 { |
|
44 TRfeGetAttrOutArgs* outArgs = static_cast<TRfeGetAttrOutArgs*>(iOutArgs); |
|
45 |
|
46 if (!aError) |
|
47 { |
|
48 outArgs->iAttr.iAtt = Node()->Att(); |
|
49 outArgs->iAttr.iSize = Node()->Size(); |
|
50 outArgs->iAttr.iModified = Node()->Modified(); |
|
51 } |
|
52 |
|
53 CompleteAndDestroyState()->SetErrorCode(aError); |
|
54 return CompleteAndDestroyState(); |
|
55 } |
|
56 |
|
57 // ---------------------------------------------------------------------------- |
|
58 // CRsfwGetAttributesStateMachine::TRefreshAttributesState::TRefreshAttributesState |
|
59 // ---------------------------------------------------------------------------- |
|
60 // |
|
61 CRsfwGetAttributesStateMachine:: |
|
62 TRefreshAttributesState:: |
|
63 TRefreshAttributesState(CRsfwAttributeRefreshingStateMachine* aParent) |
|
64 : iOperation(aParent) |
|
65 { |
|
66 } |
|
67 |
|
68 // ---------------------------------------------------------------------------- |
|
69 // CRsfwGetAttributesStateMachine::TRefreshAttributesState::EnterL |
|
70 // ---------------------------------------------------------------------------- |
|
71 // |
|
72 void CRsfwGetAttributesStateMachine::TRefreshAttributesState::EnterL() |
|
73 { |
|
74 DEBUGSTRING(("CRsfwGetAttributesStateMachine::TRefreshAttributesState::EnterL")); |
|
75 TInt err = KErrNone; |
|
76 |
|
77 if (iOperation->Node()) |
|
78 { |
|
79 DEBUGSTRING(("getting attributes of fid %d", |
|
80 iOperation->Node()->Fid().iNodeId)); |
|
81 |
|
82 // as the entry is "needed" move it to the back of metadata LRU list |
|
83 iOperation->Volumes()->MoveToTheBackOfMetadataLRUPriorityListL(iOperation->Node()); |
|
84 |
|
85 if (!(iOperation->FileEngine()->UseCachedAttributes(*iOperation->Node()))) |
|
86 { |
|
87 // If we find the file entry and |
|
88 // the time window to use cached attributes has passed. |
|
89 // Store the old attributes |
|
90 delete iOperation->iDirEntAttrOld; |
|
91 iOperation->iDirEntAttrOld = NULL; |
|
92 iOperation->iDirEntAttrOld = CRsfwDirEntAttr::NewL(); |
|
93 iOperation->Node()->GetAttributesL(*iOperation->iDirEntAttrOld); |
|
94 if (!iOperation->FileEngine()->WriteDisconnected()) |
|
95 { |
|
96 iOperation->FileEngine()->GetAttributesL( |
|
97 *(iOperation->Node()), |
|
98 iOperation->iDirEntAttr, |
|
99 iOperation->Node()->Type(), |
|
100 iOperation); |
|
101 } |
|
102 else |
|
103 { |
|
104 iOperation->HandleRemoteAccessResponse(0, KUpdateNotRequired); |
|
105 } |
|
106 if (err) |
|
107 { |
|
108 User::Leave(err); |
|
109 } |
|
110 } |
|
111 else |
|
112 { |
|
113 // use cached attributes |
|
114 iOperation->HandleRemoteAccessResponse(0, KUpdateNotRequired); |
|
115 } |
|
116 } |
|
117 else |
|
118 { |
|
119 User::Leave(KErrPathNotFound); |
|
120 } |
|
121 } |
|
122 |
|
123 // ---------------------------------------------------------------------------- |
|
124 // CRsfwGetAttributesStateMachine::TRefreshAttributesState::CompleteL |
|
125 // ---------------------------------------------------------------------------- |
|
126 // |
|
127 CRsfwGetAttributesStateMachine::TState* |
|
128 CRsfwGetAttributesStateMachine::TRefreshAttributesState::CompleteL() |
|
129 { |
|
130 |
|
131 DEBUGSTRING(("TRefreshAttributesState::CompleteL for fid %d", |
|
132 iOperation->Node()->Fid().iNodeId)); |
|
133 |
|
134 // from CRsfwFileEngine::UpdateAttributes() |
|
135 iOperation->Node()->SetAttributesL(*iOperation->iDirEntAttr, ETrue); |
|
136 |
|
137 if (iOperation->Node()->IsOpenedForWriting()) |
|
138 { |
|
139 iOperation->Node()->iUseCachedData = ETrue; |
|
140 } |
|
141 else if (iOperation->FileEngine()->DataChanged(*iOperation->iDirEntAttrOld, |
|
142 *iOperation->iDirEntAttr)) |
|
143 { |
|
144 // discard the old cache file |
|
145 // this will also call SetCached(EFalse) etc... |
|
146 iOperation->Node()->RemoveCacheFile(); |
|
147 } |
|
148 |
|
149 DEBUGSTRING(("Attributes: attr=0x%x, size=%d, time=", |
|
150 iOperation->Node()->Att(), |
|
151 iOperation->Node()->Size())); |
|
152 DEBUGTIME((iOperation->Node()->Modified())); |
|
153 |
|
154 // from CRsfwFileEngine::UpdateFileAttributes/UpdateDirAttributes |
|
155 return CompleteOurRequestL(KErrNone); |
|
156 } |
|
157 |
|
158 // ---------------------------------------------------------------------------- |
|
159 // CRsfwGetAttributesStateMachine::TRefreshAttributesState::ErrorL |
|
160 // ---------------------------------------------------------------------------- |
|
161 // |
|
162 CRsfwGetAttributesStateMachine::TState* |
|
163 CRsfwGetAttributesStateMachine::TRefreshAttributesState::ErrorL(TInt aCode) |
|
164 { |
|
165 DEBUGSTRING(("CRsfwGetAttributesStateMachine::TRefreshAttributesState::ErrorL %d", aCode)); |
|
166 if (aCode == KUpdateNotRequired) |
|
167 { |
|
168 // note that we should NOT set iUseCachedData to ETrue here |
|
169 // (if it is false, only after fetch it should be set to true |
|
170 // , or openbypath if we are writing to the file) |
|
171 aCode = KErrNone; |
|
172 |
|
173 DEBUGSTRING(("update was not required")); |
|
174 |
|
175 DEBUGSTRING(("Attributes: attr=0x%x, size=%d, time=", |
|
176 iOperation->Node()->Att(), |
|
177 iOperation->Node()->Size())); |
|
178 DEBUGTIME((iOperation->Node()->Modified())); |
|
179 |
|
180 } |
|
181 else |
|
182 { |
|
183 // from CRsfwFileEngine::UpdateAttributes() |
|
184 if (!(iOperation->Node()->IsOpenedForWriting())) |
|
185 { |
|
186 // "iOperation->Node()" has been removed from the server?? |
|
187 // : remove FEP here |
|
188 iOperation->Node()->RemoveCacheFile(); |
|
189 } |
|
190 } |
|
191 return CompleteOurRequestL(aCode); |
|
192 } |
|
193 |
|
194 // ---------------------------------------------------------------------------- |
|
195 // CRsfwGetAttributesStateMachine::TRefreshAttributesState::CompleteOurRequestL |
|
196 // ---------------------------------------------------------------------------- |
|
197 // |
|
198 CRsfwGetAttributesStateMachine::TState* |
|
199 CRsfwGetAttributesStateMachine::TRefreshAttributesState::CompleteOurRequestL(TInt aCode) |
|
200 { |
|
201 if (iOperation->Request()->Operation()->Function() == EGetAttr) |
|
202 { |
|
203 // we are running in GetAttr() |
|
204 return iOperation->CompleteRequestL(aCode); |
|
205 } |
|
206 else if (iOperation->Request()->Operation()->Function() == EOpenByPath) |
|
207 { |
|
208 // we are running in OpenByPath() |
|
209 if (aCode == KErrNone) |
|
210 { |
|
211 return new (ELeave) CRsfwOpenByPathStateMachine::TRequestOpenModeState( |
|
212 (CRsfwOpenByPathStateMachine *)iOperation); |
|
213 } |
|
214 else |
|
215 { |
|
216 // attributes expired, refrshing them failed, do not open the file |
|
217 return iOperation->CompleteRequestL(aCode); |
|
218 } |
|
219 } |
|
220 else |
|
221 { |
|
222 return NULL; |
|
223 } |
|
224 } |
|
225 |
|
226 |