|
1 /* |
|
2 * Copyright (c) 2006-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: Implements CNcdServerReportManager class |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <e32err.h> |
|
20 #include <e32base.h> |
|
21 #include <s32mem.h> |
|
22 |
|
23 #include "ncdserverreportmanagerimpl.h" |
|
24 #include "ncdreportmanager.h" |
|
25 #include "ncdnodeidentifier.h" |
|
26 #include "ncdnodeimpl.h" |
|
27 #include "ncdnodemetadataimpl.h" |
|
28 #include "ncdproviderimpl.h" |
|
29 #include "ncdpurchasehistorydbimpl.h" |
|
30 #include "ncdpurchasehistoryutils.h" |
|
31 #include "ncdutils.h" |
|
32 #include "ncdnodefunctionids.h" |
|
33 #include "catalogssession.h" |
|
34 #include "catalogsbasemessage.h" |
|
35 #include "catalogscontext.h" |
|
36 #include "catalogsaccesspointmanager.h" |
|
37 #include "catalogshttpsession.h" |
|
38 #include "catalogsdebug.h" |
|
39 |
|
40 |
|
41 CNcdServerReportManager* CNcdServerReportManager::NewL( CNcdProvider& aProvider ) |
|
42 { |
|
43 CNcdServerReportManager* self = |
|
44 CNcdServerReportManager::NewLC( aProvider ); |
|
45 CleanupStack::Pop( self ); |
|
46 return self; |
|
47 } |
|
48 |
|
49 CNcdServerReportManager* CNcdServerReportManager::NewLC( CNcdProvider& aProvider ) |
|
50 { |
|
51 CNcdServerReportManager* self = |
|
52 new( ELeave ) CNcdServerReportManager( aProvider); |
|
53 CleanupClosePushL( *self ); |
|
54 self->ConstructL(); |
|
55 return self; |
|
56 } |
|
57 |
|
58 |
|
59 CNcdServerReportManager::CNcdServerReportManager( CNcdProvider& aProvider ) |
|
60 : CCatalogsCommunicable(), |
|
61 iProvider( aProvider ) |
|
62 { |
|
63 } |
|
64 |
|
65 |
|
66 void CNcdServerReportManager::ConstructL() |
|
67 { |
|
68 DLTRACEIN(("")); |
|
69 } |
|
70 |
|
71 |
|
72 CNcdServerReportManager::~CNcdServerReportManager() |
|
73 { |
|
74 DLTRACEIN(("")); |
|
75 } |
|
76 |
|
77 |
|
78 void CNcdServerReportManager::ReceiveMessage( MCatalogsBaseMessage* aMessage, |
|
79 TInt aFunctionNumber ) |
|
80 { |
|
81 DLTRACEIN(("handle: %d, function: %d", |
|
82 aMessage->Handle(), |
|
83 aFunctionNumber)); |
|
84 |
|
85 DASSERT( aMessage ); |
|
86 |
|
87 // Now, we can be sure that rest of the time iMessage exists. |
|
88 // This member variable is set for the CounterPartLost function. |
|
89 iMessage = aMessage; |
|
90 |
|
91 TInt trapError( KErrNone ); |
|
92 |
|
93 switch( aFunctionNumber ) |
|
94 { |
|
95 case NcdNodeFunctionIds::ENcdServerReportManagerSetReportingMethod: |
|
96 TRAP( trapError, SetReportingMethodRequestL( *aMessage ) ); |
|
97 break; |
|
98 |
|
99 case NcdNodeFunctionIds::ENcdServerReportManagerReportingMethod: |
|
100 TRAP( trapError, ReportingMethodRequestL( *aMessage ) ); |
|
101 break; |
|
102 |
|
103 case NcdNodeFunctionIds::ENcdServerReportManagerSetReportingStyle: |
|
104 TRAP( trapError, SetReportingStyleRequestL( *aMessage ) ); |
|
105 break; |
|
106 |
|
107 case NcdNodeFunctionIds::ENcdServerReportManagerReportingStyle: |
|
108 TRAP( trapError, ReportingStyleRequestL( *aMessage ) ); |
|
109 break; |
|
110 |
|
111 case NcdNodeFunctionIds::ENcdServerReportManagerNodeSetAsInstalled: |
|
112 TRAP( trapError, NodeSetAsInstalledRequestL( *aMessage ) ); |
|
113 break; |
|
114 |
|
115 case NcdNodeFunctionIds::ENcdRelease: |
|
116 ReleaseRequest( *aMessage ); |
|
117 break; |
|
118 |
|
119 default: |
|
120 DLERROR(("Unidentified function request")); |
|
121 DASSERT( EFalse ); |
|
122 break; |
|
123 } |
|
124 |
|
125 if ( trapError != KErrNone ) |
|
126 { |
|
127 // Because something went wrong the complete has not been |
|
128 // yet called for the message. |
|
129 // So, inform the client about the error. |
|
130 DLTRACEIN(("Complete with error message")); |
|
131 aMessage->CompleteAndRelease( trapError ); |
|
132 } |
|
133 |
|
134 // Because the message should not be used after this, set it NULL. |
|
135 // So, CounterPartLost function will know that no messages are |
|
136 // waiting the response at the moment. |
|
137 iMessage = NULL; |
|
138 |
|
139 DLTRACEOUT(("")); |
|
140 } |
|
141 |
|
142 |
|
143 void CNcdServerReportManager::CounterPartLost( const MCatalogsSession& aSession ) |
|
144 { |
|
145 // This function may be called whenever -- when the message is waiting |
|
146 // response or when the message does not exist. |
|
147 // iMessage may be NULL here, because in the end of the |
|
148 // ReceiveMessage it is set to NULL. The life time of the message |
|
149 // ends shortly after CompleteAndRelease is called. |
|
150 if ( iMessage != NULL ) |
|
151 { |
|
152 iMessage->CounterPartLost( aSession ); |
|
153 } |
|
154 } |
|
155 |
|
156 |
|
157 CNcdProvider& CNcdServerReportManager::Provider() |
|
158 { |
|
159 return iProvider; |
|
160 } |
|
161 |
|
162 |
|
163 CNcdReportManager& CNcdServerReportManager::ReportManagerL( MCatalogsBaseMessage& aMessage ) |
|
164 { |
|
165 // Get current context |
|
166 MCatalogsContext& context( aMessage.Session().Context() ); |
|
167 |
|
168 // All the clients have their own report manager. |
|
169 TNcdProviderContext providerContext; |
|
170 Provider().GetProviderContextL( context, providerContext ); |
|
171 CNcdReportManager& reportManager( *providerContext.iReportManager ); |
|
172 |
|
173 return reportManager; |
|
174 } |
|
175 |
|
176 |
|
177 void CNcdServerReportManager::SetReportingMethodRequestL( MCatalogsBaseMessage& aMessage ) |
|
178 { |
|
179 HBufC8* input = HBufC8::NewLC( aMessage.InputLength() ); |
|
180 TPtr8 inputPtr = input->Des(); |
|
181 aMessage.ReadInput( inputPtr ); |
|
182 RDesReadStream inputStream( *input ); |
|
183 CleanupClosePushL( inputStream ); |
|
184 |
|
185 MNcdServerReportManager::TReportingMethod method( |
|
186 static_cast<MNcdServerReportManager::TReportingMethod>( inputStream.ReadInt32L() ) ); |
|
187 |
|
188 CleanupStack::PopAndDestroy( &inputStream ); |
|
189 CleanupStack::PopAndDestroy( input ); |
|
190 |
|
191 ReportManagerL( aMessage ).SetReportingMethod( method ); |
|
192 |
|
193 // If this leaves, ReceiveMessge will complete the message. |
|
194 aMessage.CompleteAndRelease( KErrNone ); |
|
195 } |
|
196 |
|
197 |
|
198 void CNcdServerReportManager::ReportingMethodRequestL( MCatalogsBaseMessage& aMessage ) |
|
199 { |
|
200 TInt method( |
|
201 ReportManagerL( aMessage ).ReportingMethod() ); |
|
202 aMessage.CompleteAndReleaseL( method, KErrNone ); |
|
203 } |
|
204 |
|
205 |
|
206 void CNcdServerReportManager::SetReportingStyleRequestL( MCatalogsBaseMessage& aMessage ) |
|
207 { |
|
208 HBufC8* input = HBufC8::NewLC( aMessage.InputLength() ); |
|
209 TPtr8 inputPtr = input->Des(); |
|
210 aMessage.ReadInput( inputPtr ); |
|
211 RDesReadStream inputStream( *input ); |
|
212 CleanupClosePushL( inputStream ); |
|
213 |
|
214 MNcdServerReportManager::TReportingStyle style( |
|
215 static_cast<MNcdServerReportManager::TReportingStyle>( inputStream.ReadInt32L() ) ); |
|
216 |
|
217 CleanupStack::PopAndDestroy( &inputStream ); |
|
218 CleanupStack::PopAndDestroy( input ); |
|
219 |
|
220 ReportManagerL( aMessage ).SetReportingStyle( style ); |
|
221 |
|
222 // If this leaves, ReceiveMessge will complete the message. |
|
223 aMessage.CompleteAndRelease( KErrNone ); |
|
224 } |
|
225 |
|
226 |
|
227 void CNcdServerReportManager::ReportingStyleRequestL( MCatalogsBaseMessage& aMessage ) |
|
228 { |
|
229 TInt style( |
|
230 ReportManagerL( aMessage ).ReportingStyle() ); |
|
231 aMessage.CompleteAndReleaseL( style, KErrNone ); |
|
232 } |
|
233 |
|
234 |
|
235 void CNcdServerReportManager::NodeSetAsInstalledRequestL( MCatalogsBaseMessage& aMessage ) |
|
236 { |
|
237 HBufC8* input = HBufC8::NewLC( aMessage.InputLength() ); |
|
238 TPtr8 inputPtr = input->Des(); |
|
239 aMessage.ReadInput( inputPtr ); |
|
240 RDesReadStream inputStream( *input ); |
|
241 CleanupClosePushL( inputStream ); |
|
242 |
|
243 TInt errorCode( inputStream.ReadInt32L() ); |
|
244 CNcdNodeIdentifier* identifier( CNcdNodeIdentifier::NewLC( inputStream ) ); |
|
245 |
|
246 CNcdReportManager& reportManager( ReportManagerL( aMessage ) ); |
|
247 CNcdNode& node( Provider().NodeManager().NodeL( *identifier ) ); |
|
248 CNcdNodeMetaData& metaData( node.NodeMetaDataL() ); |
|
249 |
|
250 TNcdReportStatusInfo info( ENcdReportCreate, errorCode ); |
|
251 // Use the node identifier to identify the content in install report. |
|
252 // Node id uniquely identifies the node that contains contents |
|
253 // that will be installed. One node may contains multiple contents but |
|
254 // they are all thought as one bundle, in one operation. Also, notice that |
|
255 // multiple nodes can contain same metadata and same content. |
|
256 TNcdReportId reportId = |
|
257 reportManager.RegisterInstallL( |
|
258 identifier->NodeId(), |
|
259 metaData.Identifier(), |
|
260 info, |
|
261 metaData.Identifier().ServerUri(), |
|
262 metaData.Identifier().NodeNameSpace() ); |
|
263 |
|
264 // Set access point for report. |
|
265 UpdateInstallReportAccessPointL( aMessage.Session().Context().FamilyId(), |
|
266 reportId, |
|
267 node, |
|
268 metaData, |
|
269 reportManager, |
|
270 HttpSessionL( aMessage.Session().Context() ) ); |
|
271 |
|
272 // Set the final success information directly into the report instead of |
|
273 // reporting other install statuses here. |
|
274 TNcdReportStatus status( ENcdReportSuccess ); |
|
275 if ( errorCode == KErrNone ) |
|
276 { |
|
277 status = ENcdReportSuccess; |
|
278 } |
|
279 else if ( errorCode == KErrCancel ) |
|
280 { |
|
281 status = ENcdReportCancel; |
|
282 } |
|
283 else |
|
284 { |
|
285 status = ENcdReportFail; |
|
286 } |
|
287 |
|
288 // Create the status info object with the given info. |
|
289 info.iStatus = status; |
|
290 info.iErrorCode = errorCode; |
|
291 |
|
292 reportManager.ReportInstallStatusL( |
|
293 reportId, |
|
294 info ); |
|
295 |
|
296 CleanupStack::PopAndDestroy( identifier ); |
|
297 CleanupStack::PopAndDestroy( &inputStream ); |
|
298 CleanupStack::PopAndDestroy( input ); |
|
299 |
|
300 aMessage.CompleteAndRelease( KErrNone ); |
|
301 } |
|
302 |
|
303 |
|
304 void CNcdServerReportManager::ReleaseRequest( MCatalogsBaseMessage& aMessage ) const |
|
305 { |
|
306 DLTRACEIN(("")); |
|
307 |
|
308 // Decrease the reference count for this object. |
|
309 // When the reference count reaches zero, this object will be destroyed |
|
310 // and removed from the session. |
|
311 MCatalogsSession& requestSession( aMessage.Session() ); |
|
312 TInt handle( aMessage.Handle() ); |
|
313 aMessage.CompleteAndRelease( KErrNone ); |
|
314 requestSession.RemoveObject( handle ); |
|
315 |
|
316 DLTRACEOUT(("")); |
|
317 } |
|
318 |
|
319 |
|
320 void CNcdServerReportManager::UpdateInstallReportAccessPointL( const TUid& aClientUid, |
|
321 TInt aReportId, |
|
322 CNcdNode& aNode, |
|
323 CNcdNodeMetaData& aMetaData, |
|
324 CNcdReportManager& aReportManager, |
|
325 MCatalogsHttpSession& aHttpSession ) |
|
326 { |
|
327 DLTRACEIN(("")); |
|
328 |
|
329 CNcdPurchaseHistoryDb& db = Provider().NodeManager().PurchaseHistory(); |
|
330 |
|
331 CNcdPurchaseDetails* purchase = |
|
332 NcdPurchaseHistoryUtils::PurchaseDetailsLC( |
|
333 db, |
|
334 aClientUid, |
|
335 aMetaData.Identifier(), |
|
336 EFalse ); |
|
337 |
|
338 // Create origin identifier |
|
339 CNcdNodeIdentifier* originIdentifier = |
|
340 CNcdNodeIdentifier::NewL( |
|
341 aNode.Identifier().NodeNameSpace(), |
|
342 purchase->OriginNodeId(), |
|
343 aNode.Identifier().ClientUid() ); |
|
344 |
|
345 CleanupStack::PopAndDestroy( purchase ); |
|
346 |
|
347 CleanupStack::PushL( originIdentifier ); |
|
348 |
|
349 // Get report ap |
|
350 TUint32 apId( 0 ); |
|
351 |
|
352 TInt error = |
|
353 Provider().AccessPointManager().AccessPointIdL( |
|
354 *originIdentifier, |
|
355 MCatalogsAccessPointManager::EBrowse, |
|
356 aClientUid, |
|
357 apId ); |
|
358 |
|
359 TCatalogsConnectionMethod reportAp; |
|
360 if ( error == KErrNone ) |
|
361 { |
|
362 DLTRACE(( "Setting access point %d for reports", apId )) |
|
363 reportAp = |
|
364 TCatalogsConnectionMethod( |
|
365 apId, |
|
366 ECatalogsConnectionMethodTypeAccessPoint ); |
|
367 } |
|
368 |
|
369 if ( reportAp.iId == 0 ) |
|
370 { |
|
371 reportAp = aHttpSession.ConnectionManager().DefaultConnectionMethod(); |
|
372 } |
|
373 |
|
374 CleanupStack::PopAndDestroy( originIdentifier ); |
|
375 |
|
376 aReportManager.SetInstallReportAccessPoint( |
|
377 aReportId, |
|
378 reportAp ); |
|
379 } |
|
380 |
|
381 |
|
382 MCatalogsHttpSession& CNcdServerReportManager::HttpSessionL( MCatalogsContext& aContext ) |
|
383 { |
|
384 TNcdProviderContext providerContext; |
|
385 Provider().GetProviderContextL( aContext, providerContext ); |
|
386 return *providerContext.iHttpSession; |
|
387 } |
|
388 |