|
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 fetching data without caching it permanently |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "rsfwfetchdatastatemachine.h" |
|
20 #include "rsfwfileentry.h" |
|
21 #include "rsfwfiletable.h" |
|
22 #include "rsfwinterface.h" |
|
23 #include "rsfwvolumetable.h" |
|
24 #include "rsfwvolume.h" |
|
25 #include "rsfwrfeserver.h" |
|
26 #include "mdebug.h" |
|
27 #include "rsfwfileengine.h" |
|
28 |
|
29 |
|
30 // ---------------------------------------------------------------------------- |
|
31 // CRsfwFetchDataStateMachine::CRsfwFetchDataStateMachine |
|
32 // ---------------------------------------------------------------------------- |
|
33 // |
|
34 CRsfwFetchDataStateMachine::CRsfwFetchDataStateMachine() |
|
35 { |
|
36 } |
|
37 |
|
38 // ---------------------------------------------------------------------------- |
|
39 // CRsfwFetchDataStateMachine::CompleteRequestL |
|
40 // ---------------------------------------------------------------------------- |
|
41 // |
|
42 CRsfwRfeStateMachine::TState* |
|
43 CRsfwFetchDataStateMachine::CompleteRequestL(TInt aError) |
|
44 { |
|
45 TRfeFetchDataOutArgs* outArgs = |
|
46 static_cast<TRfeFetchDataOutArgs*>(iOutArgs); |
|
47 if(!aError) |
|
48 { |
|
49 outArgs->iTempPath.Copy(*iCacheName); |
|
50 } |
|
51 |
|
52 CompleteAndDestroyState()->SetErrorCode(aError); |
|
53 return CompleteAndDestroyState(); |
|
54 } |
|
55 |
|
56 // ---------------------------------------------------------------------------- |
|
57 // CRsfwFetchDataStateMachine::TFetchDataState::TFetchDataState |
|
58 // ---------------------------------------------------------------------------- |
|
59 // |
|
60 CRsfwFetchDataStateMachine::TFetchDataState::TFetchDataState( |
|
61 CRsfwFetchDataStateMachine* aParent) |
|
62 : iOperation(aParent) |
|
63 { |
|
64 } |
|
65 |
|
66 // ---------------------------------------------------------------------------- |
|
67 // CRsfwFetchDataStateMachine::TFetchDataState::EnterL |
|
68 // ---------------------------------------------------------------------------- |
|
69 // |
|
70 void CRsfwFetchDataStateMachine::TFetchDataState::EnterL() |
|
71 { |
|
72 TInt err = KErrNone; |
|
73 TRfeFetchDataInArgs* inArgs = |
|
74 static_cast<TRfeFetchDataInArgs*>(iOperation->iInArgs); |
|
75 TRfeFetchDataOutArgs* outArgs = |
|
76 static_cast<TRfeFetchDataOutArgs*>(iOperation->iOutArgs); |
|
77 TInt firstByte = inArgs->iFirstByte; |
|
78 TInt lastByte = inArgs->iLastByte; |
|
79 |
|
80 |
|
81 TCachingMode cachingMode = |
|
82 iOperation->Node()->iFileTable->Volume()->iVolumeTable->iCachingMode; |
|
83 |
|
84 if (iOperation->Node()) |
|
85 { |
|
86 DEBUGSTRING(("Fetch without caching fid %d, bytes %d - %d", |
|
87 iOperation->Node()->Fid().iNodeId, |
|
88 firstByte, |
|
89 lastByte)); |
|
90 |
|
91 if (cachingMode == EWholeFileCaching) |
|
92 { |
|
93 outArgs->iUseTempPath = EFalse; |
|
94 // in this mode we always fetch the whole file to the normal cache |
|
95 iOperation->iCacheName = iOperation->Node()->CacheFileName(); |
|
96 iOperation->iLength = iOperation->Node()->Size() - |
|
97 iOperation->Node()->iCachedSize + |
|
98 1; |
|
99 TUint transactionId = iOperation-> |
|
100 FileEngine()->FetchAndCacheL(*iOperation->Node(), |
|
101 iOperation->Node()->iCachedSize, |
|
102 &iOperation->iLength, |
|
103 &(iOperation->iDirEnts), |
|
104 iOperation); |
|
105 // transactionId = 0 means syncronous non-cancellable operation |
|
106 if (transactionId > 0) |
|
107 { |
|
108 iOperation->iTransactionId = transactionId; |
|
109 } |
|
110 } |
|
111 else |
|
112 { |
|
113 // reset and use the temporary cache file... |
|
114 outArgs->iUseTempPath = ETrue; |
|
115 TParse parser; |
|
116 parser.Set(*iOperation->Node()->CacheFileName(), NULL, NULL); |
|
117 HBufC* tempPath = HBufC::NewLC(KMaxPath); |
|
118 TPtr tempfile = tempPath->Des(); |
|
119 tempfile.Append(parser.DriveAndPath()); |
|
120 tempfile.Append(KTempFileName); |
|
121 iOperation->iCacheName = iOperation->Node()->CacheFileName(); |
|
122 // This much will be added to the cache by this fetch |
|
123 iOperation->iLength =lastByte - firstByte + 1; |
|
124 if (!iOperation-> |
|
125 Node()-> |
|
126 iFileTable-> |
|
127 Volume()-> |
|
128 iVolumeTable->EnsureCacheCanBeAddedL(iOperation->iLength)) |
|
129 { |
|
130 User::Leave(KErrDiskFull); |
|
131 } |
|
132 RFile f; |
|
133 err = f.Replace(CRsfwRfeServer::Env()->iFs, |
|
134 *tempPath, |
|
135 EFileShareAny | EFileWrite); |
|
136 if (err == KErrNone) |
|
137 { |
|
138 f.Close(); |
|
139 HBufC* fullName = |
|
140 iOperation->FileEngine()->FullNameLC(*iOperation->Node()); |
|
141 TUint transactionId = iOperation->FileEngine()->RemoteAccessL()-> |
|
142 GetFileL(*fullName, |
|
143 *tempPath, |
|
144 firstByte, |
|
145 &iOperation->iLength, |
|
146 KRemoteAccessOptionGetToStartOfFile, |
|
147 iOperation); |
|
148 // transactionId = 0 means syncronous non-cancellable operation |
|
149 if (transactionId > 0) |
|
150 { |
|
151 iOperation->iTransactionId = transactionId; |
|
152 } |
|
153 CleanupStack::PopAndDestroy(fullName); |
|
154 } |
|
155 CleanupStack::PopAndDestroy(tempPath); |
|
156 } |
|
157 } |
|
158 } |
|
159 |
|
160 // ---------------------------------------------------------------------------- |
|
161 // CRsfwFetchDataStateMachine::TFetchDataState::CompleteL |
|
162 // ---------------------------------------------------------------------------- |
|
163 // |
|
164 CRsfwFetchDataStateMachine::TState* |
|
165 CRsfwFetchDataStateMachine::TFetchDataState::CompleteL() |
|
166 { |
|
167 return iOperation->CompleteRequestL(KErrNone); |
|
168 } |
|
169 |
|
170 // ---------------------------------------------------------------------------- |
|
171 // CRsfwFetchDataStateMachine::TFetchDataState::ErrorL |
|
172 // ---------------------------------------------------------------------------- |
|
173 // |
|
174 CRsfwFetchDataStateMachine::TState* |
|
175 CRsfwFetchDataStateMachine::TFetchDataState::ErrorL(TInt aCode) |
|
176 { |
|
177 return iOperation->CompleteRequestL(aCode); |
|
178 } |
|
179 |
|
180 |