|
1 /* |
|
2 * Copyright (c) 2005 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: Implementation of class CFotaSaver. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 |
|
21 #include "FotaSaver.h" |
|
22 #include "CodLogger.h" |
|
23 #include "CodError.h" |
|
24 #include "CodPanic.h" |
|
25 #include "CodData.h" |
|
26 |
|
27 // ================= MEMBER FUNCTIONS ======================= |
|
28 |
|
29 // --------------------------------------------------------- |
|
30 // CFotaSaver::NewL() |
|
31 // --------------------------------------------------------- |
|
32 // |
|
33 CFotaSaver* CFotaSaver::NewL( const TDesC8& aType, TInt aPkgId ) |
|
34 { |
|
35 CFotaSaver* saver = new (ELeave) CFotaSaver( aType, aPkgId ); |
|
36 CleanupStack::PushL( saver ); |
|
37 saver->ConstructL(); |
|
38 CleanupStack::Pop( saver ); |
|
39 return saver; |
|
40 } |
|
41 |
|
42 // --------------------------------------------------------- |
|
43 // CFotaSaver::~CFotaSaver() |
|
44 // --------------------------------------------------------- |
|
45 // |
|
46 CFotaSaver::~CFotaSaver() |
|
47 { |
|
48 CLOG(( ECodEng, 2, _L("-> CFotaSaver::~CFotaSaver") )); |
|
49 |
|
50 iEng.Close(); |
|
51 // iStore not closed (owned by the Engine). |
|
52 CLOG(( ECodEng, 2, _L("<- CFotaSaver::~CFotaSaver") )); |
|
53 } |
|
54 |
|
55 // --------------------------------------------------------- |
|
56 // CFotaSaver::OpenStoreL() |
|
57 // --------------------------------------------------------- |
|
58 // |
|
59 void CFotaSaver::OpenStoreL() |
|
60 { |
|
61 CLOG(( ECodEng, 2, _L("-> CFotaSaver::OpenStoreL") )); |
|
62 __ASSERT_DEBUG( iState == EInit, CodPanic( ECodInternal ) ); |
|
63 |
|
64 TInt err(KErrNone); |
|
65 |
|
66 if (!iEng.Handle() ) |
|
67 { |
|
68 TRAP( err, iEng.OpenL() ); |
|
69 } |
|
70 if ( !err && !iStore ) |
|
71 { |
|
72 err = iEng.OpenUpdatePackageStore( iPkgId, iStore ); |
|
73 } |
|
74 |
|
75 iSize = 0; |
|
76 iState = EStoreOpen; |
|
77 CLOG(( ECodEng, 2, _L("<- CFotaSaver::OpenStoreL") )); |
|
78 } |
|
79 |
|
80 // --------------------------------------------------------- |
|
81 // CFotaSaver::AppendData() |
|
82 // --------------------------------------------------------- |
|
83 // |
|
84 TInt CFotaSaver::AppendData( const TDesC8& aData ) |
|
85 { |
|
86 CLOG(( EHttpLoad, 2, \ |
|
87 _L("-> CFotaSaver::AppendData (%d) bytes"), aData.Length() )); |
|
88 __ASSERT_DEBUG( iState == EStoreOpen, CodPanic( ECodInternal ) ); |
|
89 TInt err = CheckMaxSize( aData.Size() ); |
|
90 if ( !err && iStore ) |
|
91 { |
|
92 TRAP( err, iStore->WriteL( aData ) ); |
|
93 } |
|
94 if ( !err ) |
|
95 { |
|
96 iSize += aData.Length(); |
|
97 } |
|
98 CLOG(( EHttpLoad, 2, _L("<- CFotaSaver::AppendData returns (%d)"), err )); |
|
99 return err; |
|
100 } |
|
101 |
|
102 // --------------------------------------------------------- |
|
103 // CFotaSaver::CloseStore() |
|
104 // --------------------------------------------------------- |
|
105 // |
|
106 void CFotaSaver::CloseStore() |
|
107 { |
|
108 CLOG(( ECodEng, 2, _L("CFotaSaver::CloseStore") )); |
|
109 // Nothing to do, iStore is owned by FOTA Engine. |
|
110 iState = EStoreClosed; |
|
111 } |
|
112 |
|
113 // --------------------------------------------------------- |
|
114 // CFotaSaver::CheckResponseAttributesL() |
|
115 // --------------------------------------------------------- |
|
116 // |
|
117 void CFotaSaver::CheckResponseAttributesL( const CCodData& aData ) |
|
118 { |
|
119 CLOG(( ECodEng, 2, _L("-> CFotaSaver::CheckResponseAttributesL") )); |
|
120 __ASSERT_DEBUG( iState == EStoreClosed, CodPanic( ECodInternal ) ); |
|
121 #ifdef __TEST_COD_LOG |
|
122 TPtrC8 mime( iType.Des8() ); |
|
123 CLOG(( ECodEng, 4, _L8(" MIME==<%S>, size(%d)"), &mime, iSize )); |
|
124 #endif /* def __TEST_COD_LOG */ |
|
125 |
|
126 if ( !iSize ) |
|
127 { |
|
128 CLOG(( ECodEng, 4, _L(" 0 bytes data") )); |
|
129 User::Leave( KErrCodAttributeMismatch ); |
|
130 } |
|
131 |
|
132 // Compare content MIME type against descriptor. |
|
133 |
|
134 // Size is not checked, no exact match is required. Quote form spec: |
|
135 // "The storage size and the execution size are dependent on the |
|
136 // environment and may be different from the value of the size attribute. |
|
137 // The transport size may also be different, if compression or some |
|
138 // packaging format is used." |
|
139 // |
|
140 // There is a safety upper bound on the transaction size, that is already |
|
141 // applied. See SetMaxSize(). |
|
142 |
|
143 if( iType != TDataType( (*aData[aData.ActiveDownload()]).Type() ) ) |
|
144 { |
|
145 CLOG(( ECodEng, 4, _L(" content-type mismatch") )); |
|
146 User::Leave( KErrCodAttributeMismatch ); |
|
147 } |
|
148 |
|
149 iState = ERespChecked; |
|
150 CLOG(( ECodEng, 2, _L("<- CFotaSaver::CheckResponseAttributesL (match)") )); |
|
151 } |
|
152 |
|
153 // --------------------------------------------------------- |
|
154 // CFotaSaver::InstallL() |
|
155 // --------------------------------------------------------- |
|
156 // |
|
157 void CFotaSaver::InstallL( TRequestStatus* aStatus, const TDesC& /*aName*/, const TBool /*aAttached*/ ) |
|
158 { |
|
159 CLOG(( ECodEng, 2, _L("CFotaSaver::InstallL") )); |
|
160 __ASSERT_DEBUG( iState == ERespChecked, CodPanic( ECodInternal ) ); |
|
161 // Do nothing. Update package is already in place. |
|
162 *aStatus = KRequestPending; |
|
163 User::RequestComplete( aStatus, KErrNone ); |
|
164 |
|
165 iState = EInstalled; |
|
166 } |
|
167 |
|
168 // --------------------------------------------------------- |
|
169 // CFotaSaver::CancelInstall() |
|
170 // --------------------------------------------------------- |
|
171 // |
|
172 void CFotaSaver::CancelInstall() |
|
173 { |
|
174 CLOG(( ECodEng, 2, _L("CFotaSaver::CancelInstall") )); |
|
175 // Do nothing, saving is completed already (not async). |
|
176 } |
|
177 |
|
178 // --------------------------------------------------------- |
|
179 // CFotaSaver::ReleaseContent() |
|
180 // --------------------------------------------------------- |
|
181 // |
|
182 void CFotaSaver::ReleaseContent( TFileName& aFname, TUid& aHandler ) |
|
183 { |
|
184 CLOG(( ECodEng, 2, _L("-> CFotaSaver::ReleaseContent") )); |
|
185 __ASSERT_DEBUG( iState == EInstalled, CodPanic( ECodInternal ) ); |
|
186 if ( iStore ) |
|
187 { |
|
188 iEng.UpdatePackageDownloadComplete( iPkgId ); |
|
189 } |
|
190 aFname = KNullDesC; |
|
191 aHandler = KNullUid; // TODO get UID of handler app (DeviceManager)? |
|
192 iEng.Close(); |
|
193 iStore = NULL; // Store not closed (owned by the Engine). |
|
194 iState = EInit; |
|
195 CLOG(( ECodEng, 2, _L("<- CFotaSaver::ReleaseContent") )); |
|
196 } |
|
197 |
|
198 // --------------------------------------------------------- |
|
199 // CFotaSaver::ReleaseFileName() |
|
200 // --------------------------------------------------------- |
|
201 // |
|
202 void CFotaSaver::ReleaseFileName( TFileName& /*aFname*/) |
|
203 { |
|
204 } |
|
205 |
|
206 // --------------------------------------------------------- |
|
207 // CFotaSaver::Cleanup() |
|
208 // --------------------------------------------------------- |
|
209 // |
|
210 void CFotaSaver::Cleanup( TBool aDeleteFile) |
|
211 { |
|
212 CLOG(( ECodEng, 2, _L("-> CFotaSaver::Cleanup") )); |
|
213 |
|
214 if( iEng.Handle() ) |
|
215 { |
|
216 iEng.UpdatePackageDownloadComplete( iPkgId ); |
|
217 if( aDeleteFile ) |
|
218 { |
|
219 iEng.DeleteUpdatePackage( iPkgId ); |
|
220 } |
|
221 iEng.Close(); // Close without committing to clean up. |
|
222 } |
|
223 iStore = NULL; // Store not closed (owned by the Engine). |
|
224 iState = EInit; |
|
225 CLOG(( ECodEng, 2, _L("<- CFotaSaver::Cleanup") )); |
|
226 } |
|
227 |
|
228 // --------------------------------------------------------- |
|
229 // CFotaSaver::CFotaSaver() |
|
230 // --------------------------------------------------------- |
|
231 // |
|
232 CFotaSaver::CFotaSaver( const TDesC8& aType, TInt aPkgId ) |
|
233 : CCodSaver( aType ), |
|
234 iPkgId( aPkgId ) |
|
235 { |
|
236 CLOG(( ECodEng, 2, _L("*** CFotaSaver::CFotaSaver") )); |
|
237 } |
|
238 |
|
239 // --------------------------------------------------------- |
|
240 // CFotaSaver::DownloadedFileSize() |
|
241 // --------------------------------------------------------- |
|
242 // |
|
243 TInt CFotaSaver::DownloadedFileSize() |
|
244 { |
|
245 // check how many bytes are already persisted |
|
246 TInt DownloadedSize(0); |
|
247 TInt completeSize (0); |
|
248 |
|
249 //Get the downloaded size from Fota Server |
|
250 TInt err = iEng.GetDownloadUpdatePackageSize( iPkgId, DownloadedSize, completeSize ); |
|
251 |
|
252 if(err != KErrNone) |
|
253 return err; |
|
254 |
|
255 return DownloadedSize; |
|
256 } |
|
257 |
|
258 // --------------------------------------------------------- |
|
259 // CFotaSaver::ResetL() |
|
260 // --------------------------------------------------------- |
|
261 // |
|
262 void CFotaSaver::ResetL() |
|
263 { |
|
264 iEng.UpdatePackageDownloadComplete( iPkgId ); |
|
265 |
|
266 TInt error = iEng.DeleteUpdatePackage( iPkgId ); |
|
267 User::LeaveIfError(error); |
|
268 |
|
269 error = iEng.OpenUpdatePackageStore( iPkgId, iStore ); |
|
270 User::LeaveIfError(error); |
|
271 } |