|
1 /* |
|
2 * Copyright (c) 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: Implements CNcdPurchaseOptionImpl class |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "ncdpurchaseoptionimpl.h" |
|
20 #include "ncdserversubscription.h" |
|
21 #include "ncdserverpartofsubscription.h" |
|
22 #include "ncdserverupgrade.h" |
|
23 #include "ncdnodemetadataimpl.h" |
|
24 #include "catalogssession.h" |
|
25 #include "catalogsbasemessage.h" |
|
26 #include "ncdnodefunctionids.h" |
|
27 #include "catalogsconstants.h" |
|
28 #include "ncd_pp_download.h" |
|
29 #include "ncd_pp_purchaseoption.h" |
|
30 #include "ncd_pp_subscriptiondetails.h" |
|
31 #include "ncd_pp_descriptor.h" |
|
32 #include "ncd_pp_rights.h" |
|
33 #include "ncd_cp_query.h" |
|
34 #include "ncdutils.h" |
|
35 #include "catalogsutils.h" |
|
36 #include "catalogsdebug.h" |
|
37 |
|
38 |
|
39 CNcdPurchaseOptionImpl::CNcdPurchaseOptionImpl( |
|
40 NcdNodeClassIds::TNcdNodeClassId aClassId, |
|
41 const CNcdNodeMetaData& aParentMetaData ) |
|
42 : CCatalogsCommunicable(), |
|
43 iClassId( aClassId ), |
|
44 iParentMetaData( aParentMetaData ), |
|
45 iPrice( -1 ), |
|
46 iIsFree( EFalse ), |
|
47 iRequirePurchaseProcess( ETrue ) |
|
48 { |
|
49 } |
|
50 |
|
51 void CNcdPurchaseOptionImpl::ConstructL() |
|
52 { |
|
53 } |
|
54 |
|
55 CNcdPurchaseOptionImpl* CNcdPurchaseOptionImpl::NewL( |
|
56 const CNcdNodeMetaData& aParentMetaData ) |
|
57 { |
|
58 CNcdPurchaseOptionImpl* self = |
|
59 CNcdPurchaseOptionImpl::NewLC( aParentMetaData ); |
|
60 CleanupStack::Pop( self ); |
|
61 return self; |
|
62 } |
|
63 |
|
64 CNcdPurchaseOptionImpl* CNcdPurchaseOptionImpl::NewLC( |
|
65 const CNcdNodeMetaData& aParentMetaData ) |
|
66 { |
|
67 CNcdPurchaseOptionImpl* self = |
|
68 new( ELeave ) CNcdPurchaseOptionImpl( |
|
69 NcdNodeClassIds::ENcdItemNodeMetaDataClassId, |
|
70 aParentMetaData ); |
|
71 CleanupClosePushL( *self ); |
|
72 self->ConstructL(); |
|
73 return self; |
|
74 } |
|
75 |
|
76 |
|
77 CNcdPurchaseOptionImpl::~CNcdPurchaseOptionImpl() |
|
78 { |
|
79 DLTRACEIN(("")); |
|
80 |
|
81 ResetMemberVariables(); |
|
82 |
|
83 DLTRACEOUT(("")); |
|
84 } |
|
85 |
|
86 |
|
87 NcdNodeClassIds::TNcdNodeClassId CNcdPurchaseOptionImpl::ClassId() const |
|
88 { |
|
89 return iClassId; |
|
90 } |
|
91 |
|
92 |
|
93 // Internalization from the protocol |
|
94 |
|
95 void CNcdPurchaseOptionImpl::InternalizeL( |
|
96 const MNcdPreminetProtocolPurchaseOption& aOption ) |
|
97 { |
|
98 DLTRACEIN(("")); |
|
99 |
|
100 // Just to be sure, delete old values of member-variables. |
|
101 ResetMemberVariables(); |
|
102 |
|
103 DLTRACE(( _L("Internalizing purchaseoption from protocol.") )); |
|
104 |
|
105 iName = aOption.Name().AllocL(); |
|
106 |
|
107 DLTRACE(( _L("Purchaseoption name: %S."), iName )); |
|
108 |
|
109 iPriceText = aOption.PriceText().AllocL(); |
|
110 |
|
111 iPrice = aOption.Price(); |
|
112 iPriceCurrency = aOption.PriceCurrency().AllocL(); |
|
113 |
|
114 |
|
115 iIsFree = aOption.IsFree(); |
|
116 iPurchaseOptionId = aOption.Id().AllocL(); |
|
117 iRequirePurchaseProcess = aOption.RequirePurchaseProcess(); |
|
118 |
|
119 |
|
120 // Let's create subscription related aggregate classes |
|
121 InternalizeSubscriptionsInfoL( aOption ); |
|
122 |
|
123 |
|
124 // Let's internalize download details |
|
125 InternalizeDownloadDetailsL( aOption ); |
|
126 |
|
127 DLTRACEOUT(("")); |
|
128 } |
|
129 |
|
130 |
|
131 |
|
132 |
|
133 const CNcdNodeIdentifier& |
|
134 CNcdPurchaseOptionImpl::ParentMetaIdentifier() const |
|
135 { |
|
136 return iParentMetaData.Identifier(); |
|
137 } |
|
138 |
|
139 const CNcdServerSubscribableContent* |
|
140 CNcdPurchaseOptionImpl::ParentSubscribableContent() const |
|
141 { |
|
142 return iParentMetaData.SubscribableContent(); |
|
143 } |
|
144 |
|
145 const CNcdNodeIcon& CNcdPurchaseOptionImpl::ParentIconL() const |
|
146 { |
|
147 return iParentMetaData.IconL(); |
|
148 } |
|
149 |
|
150 |
|
151 const TDesC& CNcdPurchaseOptionImpl::PurchaseOptionName() const |
|
152 { |
|
153 // Not an optional element in protocol, no checkings |
|
154 // done against NULL pointer |
|
155 return *iName; |
|
156 } |
|
157 |
|
158 void CNcdPurchaseOptionImpl::SetIdL( const TDesC& aId ) |
|
159 { |
|
160 HBufC* newId = aId.AllocL(); |
|
161 delete iPurchaseOptionId; |
|
162 iPurchaseOptionId = newId; |
|
163 } |
|
164 |
|
165 const TDesC& CNcdPurchaseOptionImpl::Id() const |
|
166 { |
|
167 // Not an optional element in protocol, no checkings |
|
168 // done against NULL pointer |
|
169 return *iPurchaseOptionId; |
|
170 } |
|
171 MNcdPurchaseOption::TType CNcdPurchaseOptionImpl::PurchaseOptionType() const |
|
172 { |
|
173 return iType; |
|
174 } |
|
175 |
|
176 TBool CNcdPurchaseOptionImpl::IsFree() const |
|
177 { |
|
178 return iIsFree; |
|
179 } |
|
180 |
|
181 TBool CNcdPurchaseOptionImpl::RequirePurchaseProcess() const |
|
182 { |
|
183 return iRequirePurchaseProcess; |
|
184 } |
|
185 |
|
186 void CNcdPurchaseOptionImpl::SetPriceTextL( const TDesC& aPriceText ) |
|
187 { |
|
188 AssignDesL( iPriceText, aPriceText); |
|
189 } |
|
190 |
|
191 const TDesC& CNcdPurchaseOptionImpl::PriceText() const |
|
192 { |
|
193 return *iPriceText; |
|
194 } |
|
195 |
|
196 TInt CNcdPurchaseOptionImpl::DownloadInfoCount() const |
|
197 { |
|
198 return iDownloadInfo.Count(); |
|
199 } |
|
200 |
|
201 const CNcdPurchaseDownloadInfo& CNcdPurchaseOptionImpl::DownloadInfo( |
|
202 TInt aInfoIndex ) const |
|
203 { |
|
204 DASSERT( aInfoIndex >= 0 && aInfoIndex < iDownloadInfo.Count() ); |
|
205 return *iDownloadInfo[aInfoIndex]; |
|
206 } |
|
207 |
|
208 const CNcdServerSubscription* |
|
209 CNcdPurchaseOptionImpl::SubscriptionInfo() const |
|
210 { |
|
211 return iSubscription; |
|
212 } |
|
213 |
|
214 const CNcdServerPartOfSubscription* |
|
215 CNcdPurchaseOptionImpl::PartOfSubscriptionInfo() const |
|
216 { |
|
217 return iPartOfSubscription; |
|
218 } |
|
219 |
|
220 const CNcdServerUpgrade* CNcdPurchaseOptionImpl::UpgradeInfo() const |
|
221 { |
|
222 return iUpgrade; |
|
223 } |
|
224 |
|
225 void CNcdPurchaseOptionImpl::SetRecentlyUpdated( TBool aNewState ) |
|
226 { |
|
227 DLTRACEIN(("")); |
|
228 iRecentlyUpdated = aNewState; |
|
229 DLTRACEOUT(("")); |
|
230 } |
|
231 |
|
232 TBool CNcdPurchaseOptionImpl::RecentlyUpdated() const |
|
233 { |
|
234 DLTRACEIN(("")); |
|
235 DLTRACEOUT(("")); |
|
236 return iRecentlyUpdated; |
|
237 } |
|
238 |
|
239 |
|
240 // Internalization from and externalization to the database |
|
241 |
|
242 void CNcdPurchaseOptionImpl::ExternalizeL( RWriteStream& aStream ) |
|
243 { |
|
244 DLTRACEIN(("")); |
|
245 |
|
246 // Set all the membervariable values to the stream. So, |
|
247 // that the stream may be used later to create a new |
|
248 // object. |
|
249 |
|
250 ExternalizeDataForRequestL( aStream ); |
|
251 |
|
252 |
|
253 // download details are not internalized to proxy-side |
|
254 // so externalization of downloadinfo to database is |
|
255 // not done in ExternalizeDataForRequestL. |
|
256 // It has to be done here. |
|
257 TInt detailsCount( iDownloadInfo.Count() ); |
|
258 |
|
259 // First we write the amount of download details |
|
260 aStream.WriteInt32L( detailsCount ); |
|
261 |
|
262 // Then each details object |
|
263 TInt detailsIndexer( 0 ); |
|
264 while ( detailsIndexer < detailsCount ) |
|
265 { |
|
266 iDownloadInfo[detailsIndexer]->ExternalizeL( aStream ); |
|
267 ++detailsIndexer; |
|
268 } |
|
269 |
|
270 |
|
271 DLTRACEOUT(("")); |
|
272 } |
|
273 |
|
274 void CNcdPurchaseOptionImpl::InternalizeL( RReadStream& aStream ) |
|
275 { |
|
276 DLTRACEIN(("")); |
|
277 |
|
278 // If there happened to be something stored already |
|
279 // in this object, destroy it |
|
280 ResetMemberVariables(); |
|
281 |
|
282 aStream.ReadInt32L(); // Class id |
|
283 |
|
284 InternalizeDesL( iName, aStream ); |
|
285 DLINFO(( _L("Internalized name: %S"), iName )); |
|
286 |
|
287 InternalizeDesL( iPriceText, aStream ); |
|
288 |
|
289 iPrice = aStream.ReadReal32L(); |
|
290 InternalizeDesL( iPriceCurrency, aStream ); |
|
291 |
|
292 |
|
293 iIsFree = aStream.ReadInt32L(); |
|
294 |
|
295 InternalizeDesL( iPurchaseOptionId, aStream ); |
|
296 |
|
297 //InternalizeDesL( iPurchase, aStream ); |
|
298 iType = static_cast<MNcdPurchaseOption::TType>(aStream.ReadInt32L()); |
|
299 DLINFO(( "Internalized purchase option type: %d", iType )); |
|
300 |
|
301 iRequirePurchaseProcess = aStream.ReadInt32L(); |
|
302 |
|
303 |
|
304 // Let's internalize subscription related aggregate classes |
|
305 |
|
306 // Internalization of these could be moved into |
|
307 // the aggregate classes |
|
308 |
|
309 TBool subscriptionExists( aStream.ReadInt32L() ); |
|
310 if ( subscriptionExists ) |
|
311 { |
|
312 iSubscription = CNcdServerSubscription::NewL(); |
|
313 |
|
314 iSubscription->SetValidityDelta( aStream.ReadInt32L() ); |
|
315 iSubscription->SetValidityAutoUpdate( aStream.ReadInt32L() ); |
|
316 |
|
317 TReal32 tmpAmountOfCredits( aStream.ReadReal32L() ); |
|
318 iSubscription->SetAmountOfCredits( tmpAmountOfCredits ); |
|
319 |
|
320 HBufC* tmpAmountOfCreditsCurrency( NULL ); |
|
321 InternalizeDesL( tmpAmountOfCreditsCurrency, aStream ); |
|
322 iSubscription->SetAmountOfCreditsCurrency( |
|
323 tmpAmountOfCreditsCurrency ); |
|
324 |
|
325 iSubscription->SetNumberOfDownloads( aStream.ReadInt32L() ); |
|
326 } |
|
327 |
|
328 TBool partOfSubscriptionExists( aStream.ReadInt32L() ); |
|
329 if ( partOfSubscriptionExists ) |
|
330 { |
|
331 iPartOfSubscription = CNcdServerPartOfSubscription::NewL(); |
|
332 |
|
333 HBufC* tmpParentEntityId( NULL ); |
|
334 InternalizeDesL( tmpParentEntityId, aStream ); |
|
335 iPartOfSubscription->SetParentEntityId( tmpParentEntityId ); |
|
336 |
|
337 HBufC* tmpParentPurchaseOptionId( NULL ); |
|
338 InternalizeDesL( tmpParentPurchaseOptionId, aStream ); |
|
339 iPartOfSubscription->SetParentPurchaseOptionId( |
|
340 tmpParentPurchaseOptionId ); |
|
341 |
|
342 iPartOfSubscription->SetCreditPrice( aStream.ReadReal32L() ); |
|
343 } |
|
344 |
|
345 TBool upgradeExists( aStream.ReadInt32L() ); |
|
346 if ( upgradeExists ) |
|
347 { |
|
348 iUpgrade = CNcdServerUpgrade::NewL(); |
|
349 |
|
350 HBufC* tmpDependencyId( NULL ); |
|
351 InternalizeDesL( tmpDependencyId, aStream ); |
|
352 iUpgrade->SetDependencyId( tmpDependencyId ); |
|
353 |
|
354 iUpgrade->SetValidityDelta( aStream.ReadInt32L() ); |
|
355 |
|
356 TReal32 tmpAmountOfCredits( aStream.ReadReal32L() ); |
|
357 iUpgrade->SetAmountOfCredits( tmpAmountOfCredits ); |
|
358 |
|
359 iUpgrade->SetNumberOfDownloads( aStream.ReadInt32L() ); |
|
360 } |
|
361 |
|
362 |
|
363 |
|
364 // Next let's internalize download details |
|
365 |
|
366 // First read amount |
|
367 TInt detailsCount( aStream.ReadInt32L() ); |
|
368 |
|
369 // Then each details object |
|
370 TInt detailsIndexer( 0 ); |
|
371 while ( detailsIndexer < detailsCount ) |
|
372 { |
|
373 CNcdPurchaseDownloadInfo* tempInfo = |
|
374 CNcdPurchaseDownloadInfo::NewLC(); |
|
375 |
|
376 tempInfo->InternalizeL( aStream ); |
|
377 iDownloadInfo.AppendL( tempInfo ); |
|
378 CleanupStack::Pop( tempInfo ); |
|
379 |
|
380 ++detailsIndexer; |
|
381 } |
|
382 |
|
383 |
|
384 |
|
385 DLTRACEOUT(("")); |
|
386 } |
|
387 |
|
388 |
|
389 void CNcdPurchaseOptionImpl::ReceiveMessage( MCatalogsBaseMessage* aMessage, |
|
390 TInt aFunctionNumber ) |
|
391 { |
|
392 DLTRACEIN(("")); |
|
393 |
|
394 DASSERT( aMessage ); |
|
395 |
|
396 // Now, we can be sure that rest of the time iMessage exists. |
|
397 // This member variable is set for the CounterPartLost function. |
|
398 iMessage = aMessage; |
|
399 |
|
400 TInt trapError( KErrNone ); |
|
401 |
|
402 // Check which function is called by the proxy side object. |
|
403 // Function number are located in ncdnodefunctinoids.h file. |
|
404 switch( aFunctionNumber ) |
|
405 { |
|
406 case NcdNodeFunctionIds::ENcdInternalize: |
|
407 // Internalize the proxy side according to the data |
|
408 // of this object. |
|
409 TRAP( trapError, InternalizeRequestL( *aMessage ) ); |
|
410 break; |
|
411 |
|
412 case NcdNodeFunctionIds::ENcdRelease: |
|
413 // The proxy does not want to use this object anymore. |
|
414 // So, release the handle from the session. |
|
415 ReleaseRequest( *aMessage ); |
|
416 break; |
|
417 |
|
418 default: |
|
419 break; |
|
420 } |
|
421 |
|
422 if ( trapError != KErrNone ) |
|
423 { |
|
424 // Because something went wrong, the complete has not been |
|
425 // yet called for the message. |
|
426 // So, inform the client about the error if the |
|
427 // message is still available. |
|
428 aMessage->CompleteAndRelease( trapError ); |
|
429 } |
|
430 |
|
431 // Because the message should not be used after this, set it NULL. |
|
432 // So, CounterPartLost function will know that no messages are |
|
433 // waiting the response at the moment. |
|
434 iMessage = NULL; |
|
435 |
|
436 DLTRACEOUT(("")); |
|
437 } |
|
438 |
|
439 void CNcdPurchaseOptionImpl::CounterPartLost( const MCatalogsSession& aSession ) |
|
440 { |
|
441 // This function may be called whenever -- when the message is waiting |
|
442 // response or when the message does not exist. |
|
443 // iMessage may be NULL here, because in the end of the |
|
444 // ReceiveMessage it is set to NULL. The life time of the message |
|
445 // ends shortly after CompleteAndRelease is called. |
|
446 if ( iMessage != NULL ) |
|
447 { |
|
448 iMessage->CounterPartLost( aSession ); |
|
449 } |
|
450 } |
|
451 |
|
452 |
|
453 void CNcdPurchaseOptionImpl::InternalizeRequestL( MCatalogsBaseMessage& aMessage ) const |
|
454 { |
|
455 DLTRACEIN(("")); |
|
456 |
|
457 CBufBase* buf = CBufFlat::NewL( KBufExpandSize ); |
|
458 CleanupStack::PushL( buf ); |
|
459 |
|
460 RBufWriteStream stream( *buf ); |
|
461 CleanupClosePushL( stream ); |
|
462 |
|
463 |
|
464 // Include all the necessary node data to the stream |
|
465 ExternalizeDataForRequestL( stream ); |
|
466 |
|
467 |
|
468 // Commits data to the stream when closing. |
|
469 CleanupStack::PopAndDestroy( &stream ); |
|
470 |
|
471 |
|
472 // If this leaves, ReceiveMessge will complete the message. |
|
473 // NOTE: that here we expect that the buffer contains at least |
|
474 // some data. So, make sure taht ExternalizeDataForRequestL inserts |
|
475 // something to the buffer. |
|
476 aMessage.CompleteAndReleaseL( buf->Ptr( 0 ), KErrNone ); |
|
477 |
|
478 |
|
479 DLTRACE(("Deleting the buf")); |
|
480 CleanupStack::PopAndDestroy( buf ); |
|
481 |
|
482 DLTRACEOUT(("")); |
|
483 } |
|
484 |
|
485 |
|
486 void CNcdPurchaseOptionImpl::ExternalizeDataForRequestL( RWriteStream& aStream ) const |
|
487 { |
|
488 DLTRACEIN(("")); |
|
489 |
|
490 // First insert data that the creator of this class object will use to |
|
491 // create this class object. Class id informs what class object |
|
492 // will be created. |
|
493 aStream.WriteInt32L( ClassId() ); |
|
494 |
|
495 DLINFO(( _L("Externalizing name: %S"), iName )); |
|
496 |
|
497 ExternalizeDesL( *iName, aStream ); |
|
498 ExternalizeDesL( *iPriceText, aStream ); |
|
499 |
|
500 aStream.WriteReal32L( iPrice ); |
|
501 ExternalizeDesL( *iPriceCurrency, aStream ); |
|
502 |
|
503 aStream.WriteInt32L( iIsFree ); |
|
504 |
|
505 ExternalizeDesL( *iPurchaseOptionId, aStream ); |
|
506 |
|
507 //ExternalizeDesL( *iPurchase, aStream ); |
|
508 aStream.WriteInt32L( iType ); |
|
509 |
|
510 DLINFO(( "Externalizing purchase option type: %d", iType )); |
|
511 |
|
512 aStream.WriteInt32L( iRequirePurchaseProcess ); |
|
513 |
|
514 DLINFO(( "Externalizing require purchase process: %d", iRequirePurchaseProcess )); |
|
515 |
|
516 |
|
517 // Let's externalize subscription related aggregate classes |
|
518 |
|
519 // Externalization of these could be moved into |
|
520 // the aggregate classes |
|
521 |
|
522 if ( iSubscription != NULL ) |
|
523 { |
|
524 // indicate that subscription exists |
|
525 aStream.WriteInt32L( ETrue ); |
|
526 |
|
527 aStream.WriteInt32L( iSubscription->ValidityDelta() ); |
|
528 DLINFO(( "Externalized validitydelta: %d", |
|
529 iSubscription->ValidityDelta() )); |
|
530 |
|
531 aStream.WriteInt32L( iSubscription->ValidityAutoUpdate() ); |
|
532 DLINFO(( "Externalized validity auto update: %d", |
|
533 iSubscription->ValidityAutoUpdate() )); |
|
534 |
|
535 aStream.WriteReal32L( iSubscription->AmountOfCredits() ); |
|
536 DLINFO(( "Externalized amount of credits: %f.", |
|
537 iSubscription->AmountOfCredits() )); |
|
538 |
|
539 ExternalizeDesL( |
|
540 iSubscription->AmountOfCreditsCurrency(), |
|
541 aStream ); |
|
542 DLINFO(( _L("Externalized credits currency: %S"), |
|
543 &iSubscription->AmountOfCreditsCurrency() )); |
|
544 |
|
545 aStream.WriteInt32L( iSubscription->NumberOfDownloads() ); |
|
546 DLINFO(( _L("Externalized number of downloads: %d"), |
|
547 iSubscription->NumberOfDownloads() )); |
|
548 |
|
549 } |
|
550 else |
|
551 { |
|
552 // Does not exist |
|
553 aStream.WriteInt32L( EFalse ); |
|
554 DLINFO(( _L("Externalizing po impl: Subscription component did not exist.") )); |
|
555 } |
|
556 |
|
557 |
|
558 if ( iPartOfSubscription != NULL ) |
|
559 { |
|
560 // indicate that part of subscription exists |
|
561 aStream.WriteInt32L( ETrue ); |
|
562 |
|
563 DLINFO(( _L("Parent entity id: %S"), |
|
564 &iPartOfSubscription->ParentEntityId() )); |
|
565 DLINFO(( _L("Parent entity po id: %S"), |
|
566 &iPartOfSubscription->ParentPurchaseOptionId() )); |
|
567 |
|
568 ExternalizeDesL( |
|
569 iPartOfSubscription->ParentEntityId(), |
|
570 aStream ); |
|
571 ExternalizeDesL( |
|
572 iPartOfSubscription->ParentPurchaseOptionId(), |
|
573 aStream ); |
|
574 |
|
575 aStream.WriteReal32L( iPartOfSubscription->CreditPrice() ); |
|
576 |
|
577 DLINFO(( _L("Externalized part of subscription info") )); |
|
578 } |
|
579 else |
|
580 { |
|
581 // Does not exist |
|
582 aStream.WriteInt32L( EFalse ); |
|
583 DLINFO(( _L("Externalizing po impl: Part of subscription component did not exist.") )); |
|
584 } |
|
585 |
|
586 if ( iUpgrade != NULL ) |
|
587 { |
|
588 // indicate that upgrade exists |
|
589 aStream.WriteInt32L( ETrue ); |
|
590 |
|
591 ExternalizeDesL( iUpgrade->DependencyId(), aStream ); |
|
592 DLINFO(( _L("Upgrade dependency id: %S"), |
|
593 &iUpgrade->DependencyId() )); |
|
594 |
|
595 aStream.WriteInt32L( iUpgrade->ValidityDelta() ); |
|
596 aStream.WriteReal32L( iUpgrade->AmountOfCredits() ); |
|
597 aStream.WriteInt32L( iUpgrade->NumberOfDownloads() ); |
|
598 } |
|
599 else |
|
600 { |
|
601 // Does not exist |
|
602 aStream.WriteInt32L( EFalse ); |
|
603 DLINFO(( _L("Externalizing po impl: Upgrade component did not exist.") )); |
|
604 } |
|
605 |
|
606 DLTRACEOUT(("")); |
|
607 } |
|
608 |
|
609 void CNcdPurchaseOptionImpl::ReleaseRequest( MCatalogsBaseMessage& aMessage ) const |
|
610 { |
|
611 DLTRACEIN(("")); |
|
612 |
|
613 // Decrease the reference count for this object. |
|
614 // When the reference count reaches zero, this object will be destroyed |
|
615 // and removed from the session. |
|
616 MCatalogsSession& requestSession( aMessage.Session() ); |
|
617 TInt handle( aMessage.Handle() ); |
|
618 |
|
619 // Send complete information back to proxy. |
|
620 aMessage.CompleteAndRelease( KErrNone ); |
|
621 |
|
622 // Remove this object from the session. |
|
623 requestSession.RemoveObject( handle ); |
|
624 |
|
625 DLTRACEOUT(("")); |
|
626 } |
|
627 |
|
628 |
|
629 void CNcdPurchaseOptionImpl::InternalizeSubscriptionsInfoL( |
|
630 const MNcdPreminetProtocolPurchaseOption& aOption ) |
|
631 { |
|
632 |
|
633 DLTRACEIN(("")); |
|
634 |
|
635 TNcdPurchaseType purchase = aOption.Purchase(); |
|
636 |
|
637 // Conversion to type declared in the purchaseoption interface |
|
638 |
|
639 switch ( purchase ) |
|
640 { |
|
641 case ETypeNotSet: // Flow through, default is EContent |
|
642 case EContent: |
|
643 iType = MNcdPurchaseOption::EPurchase; |
|
644 break; |
|
645 case ESubscription: |
|
646 iType = MNcdPurchaseOption::ESubscription; |
|
647 break; |
|
648 case EPartOfSubscription: |
|
649 iType = MNcdPurchaseOption::ESubscriptionPurchase; |
|
650 break; |
|
651 case EUpgrade: |
|
652 iType = MNcdPurchaseOption::ESubscriptionUpgrade; |
|
653 break; |
|
654 default: |
|
655 DASSERT( false ); // unsupported type |
|
656 break; |
|
657 } |
|
658 |
|
659 DLTRACE(( _L("Purchaseoption impl, purchase option type: %d."), |
|
660 iType )); |
|
661 |
|
662 |
|
663 // Po cannot be a subscription and an upgrade at the same time |
|
664 // because they use same variables with different meaning |
|
665 if( purchase == EUpgrade ) |
|
666 { |
|
667 iUpgrade = CNcdServerUpgrade::NewL(); |
|
668 |
|
669 // If subscription upgrade the po that is upgraded. |
|
670 // Possibly also some other meaning? |
|
671 iUpgrade->SetDependencyId( aOption.DependencyId().AllocL() ); |
|
672 |
|
673 // Subscription upgrade stuff... |
|
674 iUpgrade->SetValidityDelta( aOption.SubscriptionDetails()->ValidityDelta() ); |
|
675 iUpgrade->SetAmountOfCredits( |
|
676 aOption.SubscriptionDetails()->AmountOfCredits() ); |
|
677 iUpgrade->SetNumberOfDownloads( |
|
678 aOption.SubscriptionDetails()->NumberOfDownloads() ); |
|
679 |
|
680 DLINFO(( "Purchaseoption impl, upgrade, amount of credits: %f.", |
|
681 iUpgrade->AmountOfCredits() )); |
|
682 DLINFO(( "Purchaseoption impl, upgrade, validitydelta: %d.", |
|
683 iUpgrade->ValidityDelta() )); |
|
684 DLINFO(( "Purchaseoption impl, upgrade, downloads: %d.", |
|
685 iUpgrade->NumberOfDownloads() )); |
|
686 |
|
687 } |
|
688 else if ( purchase == ESubscription ) |
|
689 { |
|
690 // check if we have a subscription |
|
691 |
|
692 iSubscription = CNcdServerSubscription::NewL(); |
|
693 |
|
694 iSubscription->SetValidityDelta( |
|
695 aOption.SubscriptionDetails()->ValidityDelta() ); |
|
696 iSubscription->SetValidityAutoUpdate( |
|
697 aOption.SubscriptionDetails()->ValidityAutoUpdate() ); |
|
698 iSubscription->SetAmountOfCredits( |
|
699 aOption.SubscriptionDetails()->AmountOfCredits() ); |
|
700 iSubscription->SetAmountOfCreditsCurrency( |
|
701 aOption.SubscriptionDetails()->AmountOfCreditsCurrency().AllocL() ); |
|
702 iSubscription->SetNumberOfDownloads( |
|
703 aOption.SubscriptionDetails()->NumberOfDownloads() ); |
|
704 |
|
705 DLINFO(( "Purchaseoption impl, subscription, amount of credits in protocol: %f.", |
|
706 aOption.SubscriptionDetails()->AmountOfCredits() )); |
|
707 DLINFO(( "Purchaseoption impl, subscription, amount of credits: %f.", |
|
708 iSubscription->AmountOfCredits() )); |
|
709 DLINFO(( "Purchaseoption impl, subscription, validitydelta: %d.", |
|
710 iSubscription->ValidityDelta() )); |
|
711 DLINFO(( "Purchaseoption impl, subscription, downloads: %d.", |
|
712 iSubscription->NumberOfDownloads() )); |
|
713 } |
|
714 |
|
715 // Still have to check if we have a part of subscription |
|
716 |
|
717 DLTRACE(( _L("Purchaseoption impl, Checking part of subscription info.") )); |
|
718 |
|
719 const TDesC& tmpParentSubscriptionEntityId = |
|
720 aOption.ParentSubscriptionEntityId(); |
|
721 |
|
722 DLTRACE(( _L("Purchaseoption impl, parent entity id: \"%S\"."), |
|
723 &tmpParentSubscriptionEntityId )); |
|
724 |
|
725 // According to protocol if we have a part of subscription then |
|
726 // parent subscription entity id is a mandatory field. |
|
727 if ( tmpParentSubscriptionEntityId != KNullDesC ) |
|
728 { |
|
729 iPartOfSubscription = CNcdServerPartOfSubscription::NewL(); |
|
730 |
|
731 iPartOfSubscription->SetParentEntityId( |
|
732 aOption.ParentSubscriptionEntityId().AllocL() ); |
|
733 iPartOfSubscription->SetParentPurchaseOptionId( |
|
734 aOption.ParentSubscriptionPurchaseOptionId().AllocL() ); |
|
735 iPartOfSubscription->SetCreditPrice( aOption.CreditPrice() ); |
|
736 |
|
737 |
|
738 DLINFO(( "Purchaseoption impl, part of subscription, credit price: %f.", |
|
739 iPartOfSubscription->CreditPrice() )); |
|
740 DLINFO(( _L("Purchaseoption impl, part of subscription, parent entity id: %S."), |
|
741 &iPartOfSubscription->ParentEntityId() )); |
|
742 DLINFO(( _L("Purchaseoption impl, part of subscription, parent po id: %S."), |
|
743 &iPartOfSubscription->ParentPurchaseOptionId() )); |
|
744 } |
|
745 |
|
746 DLTRACEOUT(("")); |
|
747 } |
|
748 |
|
749 |
|
750 |
|
751 void CNcdPurchaseOptionImpl::InternalizeDownloadDetailsL( |
|
752 const MNcdPreminetProtocolPurchaseOption& aOption ) |
|
753 { |
|
754 DLTRACEIN(("")); |
|
755 |
|
756 const TInt KDetailsCount( aOption.DownloadDetailsCount() ); |
|
757 TInt detailsIndexer( 0 ); |
|
758 |
|
759 DLTRACE(( _L("Purchaseoption download details amount: %d."), |
|
760 KDetailsCount )); |
|
761 |
|
762 while ( detailsIndexer < KDetailsCount ) |
|
763 { |
|
764 const MNcdPreminetProtocolDownload& tmpDownloadDetails = |
|
765 aOption.DownloadDetailsL( detailsIndexer ); |
|
766 |
|
767 CNcdPurchaseDownloadInfo* tempInfo = |
|
768 CNcdPurchaseDownloadInfo::NewLC(); |
|
769 |
|
770 TNcdDownloadTargetType tmpTarget = tmpDownloadDetails.Target(); |
|
771 // Conversion from TNcdDownloadTargetType to TContentUsage |
|
772 MNcdPurchaseDownloadInfo::TContentUsage tmpUsage = |
|
773 MNcdPurchaseDownloadInfo::EDownloadable; |
|
774 |
|
775 switch ( tmpTarget ) |
|
776 { |
|
777 case EDownloadTargetDownloadable: |
|
778 tmpUsage = MNcdPurchaseDownloadInfo::EDownloadable; |
|
779 break; |
|
780 case EDownloadTargetConsumable: |
|
781 tmpUsage = MNcdPurchaseDownloadInfo::EConsumable; |
|
782 break; |
|
783 default: |
|
784 DASSERT( false ); // unsupported type |
|
785 break; |
|
786 } |
|
787 tempInfo->SetContentUsage( tmpUsage ); |
|
788 |
|
789 tempInfo->SetContentUriL( tmpDownloadDetails.Uri() ); |
|
790 tempInfo->SetContentMimeTypeL( tmpDownloadDetails.Mime() ); |
|
791 tempInfo->SetContentSize( tmpDownloadDetails.Size() ); |
|
792 tempInfo->SetLaunchable( tmpDownloadDetails.Launchable() ); |
|
793 |
|
794 |
|
795 const MNcdPreminetProtocolDescriptor* descriptor = |
|
796 tmpDownloadDetails.Descriptor(); |
|
797 if ( descriptor != NULL ) |
|
798 { |
|
799 tempInfo->SetDescriptorTypeL( descriptor->Type() ); |
|
800 tempInfo->SetDescriptorNameL( descriptor->Name() ); |
|
801 tempInfo->SetDescriptorUriL( descriptor->Uri() ); |
|
802 tempInfo->SetDescriptorDataL( descriptor->Data() ); |
|
803 } |
|
804 |
|
805 |
|
806 const MNcdPreminetProtocolRights* rights = |
|
807 tmpDownloadDetails.Rights(); |
|
808 if ( rights != NULL ) |
|
809 { |
|
810 tempInfo->SetRightsUriL( rights->Uri() ); |
|
811 tempInfo->SetRightsTypeL( rights->Type() ); |
|
812 } |
|
813 |
|
814 tempInfo->SetContentValidityDelta( |
|
815 tmpDownloadDetails.ValidityDelta() ); |
|
816 |
|
817 iDownloadInfo.AppendL( tempInfo ); |
|
818 CleanupStack::Pop( tempInfo ); |
|
819 |
|
820 ++detailsIndexer; |
|
821 } |
|
822 |
|
823 DLTRACEOUT(("")); |
|
824 } |
|
825 |
|
826 |
|
827 void CNcdPurchaseOptionImpl::ResetMemberVariables() |
|
828 { |
|
829 // In all cases this state variable is in the beginning false |
|
830 // This has to be set especially by the user. |
|
831 iRecentlyUpdated = EFalse; |
|
832 |
|
833 delete iName; |
|
834 iName = NULL; |
|
835 delete iPriceText; |
|
836 iPriceText = NULL; |
|
837 |
|
838 iPrice = -1; |
|
839 delete iPriceCurrency; |
|
840 iPriceCurrency = NULL; |
|
841 |
|
842 iIsFree = EFalse; |
|
843 delete iPurchaseOptionId; |
|
844 iPurchaseOptionId = NULL; |
|
845 |
|
846 iType = MNcdPurchaseOption::EPurchase; |
|
847 iRequirePurchaseProcess = EFalse; |
|
848 |
|
849 iDownloadInfo.ResetAndDestroy(); |
|
850 |
|
851 delete iSubscription; |
|
852 iSubscription = NULL; |
|
853 delete iPartOfSubscription; |
|
854 iPartOfSubscription = NULL; |
|
855 delete iUpgrade; |
|
856 iUpgrade = NULL; |
|
857 } |