|
1 /* |
|
2 * Copyright (c) 2007-2008 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: CNcdReportInstall implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "ncdreportinstall.h" |
|
20 |
|
21 #include "ncdreportmanager.h" |
|
22 #include "catalogsdebug.h" |
|
23 #include "ncdpanics.h" |
|
24 #include "ncdnodeidentifier.h" |
|
25 #include "catalogsutils.h" |
|
26 #include "catalogsconstants.h" |
|
27 #include "ncdrequestinstallation.h" |
|
28 #include "ncdprotocol.h" |
|
29 #include "catalogshttpoperation.h" |
|
30 #include "catalogshttpconfig.h" |
|
31 #include "ncdrequestgenerator.h" |
|
32 #include "ncdproviderutils.h" |
|
33 #include "ncdgeneralmanager.h" |
|
34 |
|
35 |
|
36 // --------------------------------------------------------------------------- |
|
37 // |
|
38 // --------------------------------------------------------------------------- |
|
39 CNcdReportInstall* CNcdReportInstall::NewLC( |
|
40 CNcdReportManager& aReportManager, |
|
41 const TDesC& aContentIdentifier, |
|
42 const CNcdNodeIdentifier& aMetadataId, |
|
43 const TNcdReportStatusInfo& aStatus, |
|
44 const TDesC& aReportUri, |
|
45 const TDesC& aReportNamespace ) |
|
46 { |
|
47 CNcdReportInstall* self = new( ELeave ) CNcdReportInstall( |
|
48 aStatus, aReportManager ); |
|
49 CleanupStack::PushL( self ); |
|
50 self->ConstructL( |
|
51 aContentIdentifier, |
|
52 aMetadataId, |
|
53 aReportUri, |
|
54 aReportNamespace ); |
|
55 return self; |
|
56 } |
|
57 |
|
58 |
|
59 // --------------------------------------------------------------------------- |
|
60 // Create new CNcdReportInstall from the given stream |
|
61 // --------------------------------------------------------------------------- |
|
62 CNcdReportInstall* CNcdReportInstall::NewLC( |
|
63 CNcdReportManager& aReportManager, |
|
64 RReadStream& aStream ) |
|
65 { |
|
66 TNcdReportStatusInfo tmpStatus; |
|
67 CNcdReportInstall* self = new( ELeave ) CNcdReportInstall( |
|
68 tmpStatus, aReportManager ); |
|
69 CleanupStack::PushL( self ); |
|
70 self->InternalizeL( aStream ); |
|
71 return self; |
|
72 } |
|
73 |
|
74 |
|
75 |
|
76 // --------------------------------------------------------------------------- |
|
77 // |
|
78 // --------------------------------------------------------------------------- |
|
79 CNcdReportInstall::~CNcdReportInstall() |
|
80 { |
|
81 DLTRACEIN(("")); |
|
82 } |
|
83 |
|
84 |
|
85 // --------------------------------------------------------------------------- |
|
86 // Overridden SetStatus |
|
87 // --------------------------------------------------------------------------- |
|
88 TInt CNcdReportInstall::SetStatus( const TNcdReportStatusInfo& aStatus ) |
|
89 { |
|
90 DLTRACEIN(("")); |
|
91 TInt err( CNcdReport::SetStatus( aStatus ) ); |
|
92 |
|
93 DLTRACEOUT(("err: %d", err)); |
|
94 return err; |
|
95 } |
|
96 |
|
97 |
|
98 // --------------------------------------------------------------------------- |
|
99 // |
|
100 // --------------------------------------------------------------------------- |
|
101 TBool CNcdReportInstall::CanBundle() const |
|
102 { |
|
103 return ETrue; |
|
104 } |
|
105 |
|
106 |
|
107 // --------------------------------------------------------------------------- |
|
108 // |
|
109 // --------------------------------------------------------------------------- |
|
110 void CNcdReportInstall::AddReportDataL( |
|
111 CNcdRequestInstallation& aRequest ) const |
|
112 { |
|
113 DLTRACEIN(("")); |
|
114 aRequest.AddInstallDetailsL( |
|
115 MetadataId().NodeId(), |
|
116 // convert status to actual status code |
|
117 ReportStatusToInstallReportStatus( Status() ) ); |
|
118 } |
|
119 |
|
120 |
|
121 // --------------------------------------------------------------------------- |
|
122 // |
|
123 // --------------------------------------------------------------------------- |
|
124 TBool CNcdReportInstall::IsSendable() const |
|
125 { |
|
126 DLTRACEIN(("")); |
|
127 TInt value = ReportStatusToInstallReportStatus( Status() ); |
|
128 |
|
129 // Can send if status code is good and it's not being sent already. |
|
130 // Notice, that for now same constants are used here as in download report. |
|
131 return value != KNcdDownloadReportNotSupported && |
|
132 !ReportTransaction() && |
|
133 Attributes().AttributeInt32( |
|
134 ENcdReportAttributeSendable ); |
|
135 } |
|
136 |
|
137 |
|
138 // --------------------------------------------------------------------------- |
|
139 // |
|
140 // --------------------------------------------------------------------------- |
|
141 TBool CNcdReportInstall::CanBeRemoved() const |
|
142 { |
|
143 DLTRACEIN(("")); |
|
144 return Status().iStatus >= ENcdReportCancel && |
|
145 Status().iStatus == Attributes().AttributeInt32( |
|
146 ENcdReportAttributeLatestSentReport ); |
|
147 } |
|
148 |
|
149 |
|
150 // --------------------------------------------------------------------------- |
|
151 // |
|
152 // --------------------------------------------------------------------------- |
|
153 HBufC8* CNcdReportInstall::CreateReportL() const |
|
154 { |
|
155 DLTRACEIN(("")); |
|
156 CNcdRequestInstallation* report = |
|
157 NcdRequestGenerator::CreateInstallationReportRequestLC(); |
|
158 |
|
159 report->SetNamespaceL( Attributes().AttributeString16( |
|
160 ENcdReportAttributeReportNamespace ) ); |
|
161 |
|
162 AddReportDataL( *report ); |
|
163 |
|
164 HBufC8* data = |
|
165 ReportManager().GeneralManager().ProtocolManager().ProcessPreminetRequestL( |
|
166 ReportManager().Context(), |
|
167 *report, |
|
168 Attributes().AttributeString16( |
|
169 ENcdReportAttributeReportUri ), |
|
170 ETrue ); |
|
171 |
|
172 |
|
173 CleanupStack::PopAndDestroy( report ); |
|
174 return data; |
|
175 } |
|
176 |
|
177 |
|
178 // --------------------------------------------------------------------------- |
|
179 // |
|
180 // --------------------------------------------------------------------------- |
|
181 void CNcdReportInstall::UpdateTransactionConfigL( |
|
182 MCatalogsHttpOperation& aTransaction ) |
|
183 { |
|
184 DLTRACEIN(("")); |
|
185 aTransaction.Config().SetConnectionMethod( ConnectionMethod() ); |
|
186 aTransaction.Config().SetPriority( ECatalogsPriorityLow ); |
|
187 aTransaction.SetContentTypeL( KMimeTypeXml ); |
|
188 } |
|
189 |
|
190 |
|
191 // --------------------------------------------------------------------------- |
|
192 // Returns ETrue if the status cannot change anymore |
|
193 // --------------------------------------------------------------------------- |
|
194 TBool CNcdReportInstall::StatusIsFinal() const |
|
195 { |
|
196 DLTRACEIN(("")); |
|
197 return IsOneOf( |
|
198 Status().iStatus, |
|
199 ENcdReportCancel, |
|
200 ENcdReportFail, |
|
201 ENcdReportSuccess ); |
|
202 } |
|
203 |
|
204 |
|
205 // --------------------------------------------------------------------------- |
|
206 // PRIVATE METHODS |
|
207 // --------------------------------------------------------------------------- |
|
208 |
|
209 |
|
210 // --------------------------------------------------------------------------- |
|
211 // Constructor |
|
212 // --------------------------------------------------------------------------- |
|
213 CNcdReportInstall::CNcdReportInstall( |
|
214 const TNcdReportStatusInfo& aStatus, |
|
215 CNcdReportManager& aReportManager ) |
|
216 : CNcdReport( ENcdReportInstall, aReportManager, aStatus ) |
|
217 { |
|
218 } |
|
219 |
|
220 |
|
221 // --------------------------------------------------------------------------- |
|
222 // ConstructL |
|
223 // --------------------------------------------------------------------------- |
|
224 void CNcdReportInstall::ConstructL( |
|
225 const TDesC& aContentIdentifier, |
|
226 const CNcdNodeIdentifier& aMetadataId, |
|
227 const TDesC& aReportUri, |
|
228 const TDesC& aReportNamespace ) |
|
229 { |
|
230 DLTRACEIN(("")); |
|
231 BaseConstructL( aMetadataId ); |
|
232 |
|
233 if ( !aReportUri.Length() || |
|
234 !aReportNamespace.Length() ) |
|
235 { |
|
236 DLERROR(("Either URI, report URI or report namespace is empty")); |
|
237 User::Leave( KErrArgument ); |
|
238 } |
|
239 |
|
240 Attributes().SetAttributeL( |
|
241 ENcdReportAttributeGenericId, |
|
242 aContentIdentifier ); |
|
243 |
|
244 Attributes().SetAttributeL( |
|
245 ENcdReportAttributeReportUri, |
|
246 aReportUri ); |
|
247 |
|
248 Attributes().SetAttributeL( |
|
249 ENcdReportAttributeReportNamespace, |
|
250 aReportNamespace ); |
|
251 |
|
252 DLTRACEOUT(("")); |
|
253 } |
|
254 |
|
255 |
|
256 // --------------------------------------------------------------------------- |
|
257 // |
|
258 // --------------------------------------------------------------------------- |
|
259 TInt CNcdReportInstall::ReportStatusToInstallReportStatus( |
|
260 const TNcdReportStatusInfo& aStatus ) const |
|
261 { |
|
262 DLTRACEIN(( "aStatus: %d", aStatus.iStatus )); |
|
263 |
|
264 TInt status = 0; |
|
265 |
|
266 if ( ReportManager().ReportingStyle() |
|
267 == MNcdServerReportManager::EReportingStyleS60 ) |
|
268 { |
|
269 // Return the S60 error code. |
|
270 status = aStatus.iErrorCode; |
|
271 } |
|
272 else |
|
273 { |
|
274 // For now, use the same values as with the download. |
|
275 // If these are defined more accurately, then change them. |
|
276 switch ( aStatus.iStatus ) |
|
277 { |
|
278 case ENcdReportCancel: |
|
279 { |
|
280 status = KNcdDownloadReportCancel; |
|
281 break; |
|
282 } |
|
283 |
|
284 case ENcdReportFail: |
|
285 { |
|
286 status = KNcdDownloadReportFail; |
|
287 break; |
|
288 } |
|
289 |
|
290 case ENcdReportSuccess: |
|
291 { |
|
292 status = KNcdDownloadReportSuccess; |
|
293 break; |
|
294 } |
|
295 |
|
296 // Unsupported cases |
|
297 case ENcdReportNone: |
|
298 case ENcdReportCreate: |
|
299 case ENcdReportStart: |
|
300 case ENcdReportPause: |
|
301 case ENcdReportResume: |
|
302 { |
|
303 DLTRACE(("Status not supported for install reporting")); |
|
304 status = KNcdDownloadReportNotSupported; |
|
305 break; |
|
306 } |
|
307 |
|
308 default: |
|
309 { |
|
310 NCD_ASSERT_ALWAYS( 0, ENcdPanicIndexOutOfRange ); |
|
311 break; |
|
312 } |
|
313 } |
|
314 } |
|
315 |
|
316 DLTRACEOUT(("Install report status: %d", status)); |
|
317 return status; |
|
318 } |