|
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: Contains CNcdSubscriptionProxy class implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "ncdsubscriptionproxy.h" |
|
20 #include "ncdoperationimpl.h" |
|
21 #include "ncddownloadoperationproxy.h" |
|
22 #include "ncdoperationmanagerproxy.h" |
|
23 #include "ncdoperationdatatypes.h" |
|
24 #include "catalogsclientserver.h" |
|
25 #include "ncdnodeidentifier.h" |
|
26 #include "ncdnodefunctionids.h" |
|
27 #include "ncdnodeclassids.h" |
|
28 #include "catalogsinterfaceidentifier.h" |
|
29 #include "catalogsutils.h" |
|
30 #include "ncdsubscriptionoperationproxy.h" |
|
31 #include "ncdsubscriptiongroupproxy.h" |
|
32 #include "ncdnodemanagerproxy.h" |
|
33 #include "ncdnodeproxy.h" |
|
34 #include "ncderrors.h" |
|
35 |
|
36 #include "catalogsdebug.h" |
|
37 |
|
38 // ======== PUBLIC MEMBER FUNCTIONS ======== |
|
39 |
|
40 CNcdSubscriptionProxy::CNcdSubscriptionProxy( |
|
41 MCatalogsClientServer& aSession, |
|
42 TInt aHandle, |
|
43 CNcdOperationManagerProxy& aOperationManager, |
|
44 CNcdNodeManagerProxy& aNodeManager, |
|
45 CNcdSubscriptionGroupProxy& aParentGroup ) |
|
46 : CNcdInterfaceBaseProxy( aSession, aHandle, NULL ), |
|
47 iOperationManager( aOperationManager ), |
|
48 iNodeManager( aNodeManager ), |
|
49 iObsolete( EFalse ), |
|
50 iParentGroup( aParentGroup ) |
|
51 { |
|
52 } |
|
53 |
|
54 |
|
55 void CNcdSubscriptionProxy::ConstructL() |
|
56 { |
|
57 // Register the interface |
|
58 MNcdSubscription* interface( this ); |
|
59 AddInterfaceL( |
|
60 CCatalogsInterfaceIdentifier::NewL( interface, this, |
|
61 MNcdSubscription::KInterfaceUid ) ); |
|
62 |
|
63 // Is it ok if internalization fails here? |
|
64 // Earlier comment: Do not let the internalization leave here. |
|
65 // This object may be reinternalized later. |
|
66 InternalizeL(); |
|
67 } |
|
68 |
|
69 |
|
70 CNcdSubscriptionProxy* CNcdSubscriptionProxy::NewL( |
|
71 MCatalogsClientServer& aSession, |
|
72 TInt aHandle, |
|
73 CNcdOperationManagerProxy& aOperationManager, |
|
74 CNcdNodeManagerProxy& aNodeManager, |
|
75 CNcdSubscriptionGroupProxy& aParentGroup ) |
|
76 { |
|
77 CNcdSubscriptionProxy* self = |
|
78 CNcdSubscriptionProxy::NewLC( aSession, |
|
79 aHandle, |
|
80 aOperationManager, |
|
81 aNodeManager, |
|
82 aParentGroup ); |
|
83 CleanupStack::Pop( self ); |
|
84 return self; |
|
85 } |
|
86 |
|
87 CNcdSubscriptionProxy* CNcdSubscriptionProxy::NewLC( |
|
88 MCatalogsClientServer& aSession, |
|
89 TInt aHandle, |
|
90 CNcdOperationManagerProxy& aOperationManager, |
|
91 CNcdNodeManagerProxy& aNodeManager, |
|
92 CNcdSubscriptionGroupProxy& aParentGroup ) |
|
93 { |
|
94 CNcdSubscriptionProxy* self = |
|
95 new( ELeave ) CNcdSubscriptionProxy( aSession, |
|
96 aHandle, |
|
97 aOperationManager, |
|
98 aNodeManager, |
|
99 aParentGroup ); |
|
100 // Using PushL because the object does not have any references yet |
|
101 CleanupStack::PushL( self ); |
|
102 self->ConstructL(); |
|
103 return self; |
|
104 } |
|
105 |
|
106 |
|
107 CNcdSubscriptionProxy::~CNcdSubscriptionProxy() |
|
108 { |
|
109 // Remove interfaces implemented by this class from the interface list. |
|
110 // So, the interface list is up to date when this class object is deleted. |
|
111 RemoveInterface( MNcdSubscription::KInterfaceUid ); |
|
112 |
|
113 ResetSubscriptionVariables(); |
|
114 } |
|
115 |
|
116 |
|
117 void CNcdSubscriptionProxy::InternalizeL() |
|
118 { |
|
119 DLTRACEIN(("")); |
|
120 |
|
121 HBufC8* data( NULL ); |
|
122 |
|
123 // Because we do not know the exact size of the data, use |
|
124 // the alloc method, which creates the buffer of the right size |
|
125 // and sets the pointer to point to the created buffer. |
|
126 // Get all the data that is necessary to internalize this object |
|
127 // from the server side. |
|
128 User::LeaveIfError( |
|
129 ClientServerSession(). |
|
130 SendSyncAlloc( NcdNodeFunctionIds::ENcdInternalize, |
|
131 KNullDesC8, |
|
132 data, |
|
133 Handle(), |
|
134 0 ) ); |
|
135 |
|
136 if ( data == NULL ) |
|
137 { |
|
138 DLERROR(("")); |
|
139 User::Leave( KErrNotFound ); |
|
140 } |
|
141 |
|
142 CleanupStack::PushL( data ); |
|
143 |
|
144 // Read the data from the stream and insert it to the memeber variables |
|
145 RDesReadStream stream( *data ); |
|
146 CleanupClosePushL( stream ); |
|
147 |
|
148 InternalizeDataL( stream ); |
|
149 |
|
150 // Closes the stream |
|
151 CleanupStack::PopAndDestroy( &stream ); |
|
152 CleanupStack::PopAndDestroy( data ); |
|
153 |
|
154 DLTRACEOUT(("")); |
|
155 } |
|
156 |
|
157 |
|
158 void CNcdSubscriptionProxy::SetObsolete() |
|
159 { |
|
160 iObsolete = ETrue; |
|
161 } |
|
162 |
|
163 TDesC& CNcdSubscriptionProxy::PurchaseOptionId() const |
|
164 { |
|
165 return *iPurchaseOptionId; |
|
166 } |
|
167 |
|
168 |
|
169 // MNcdSubscription functions |
|
170 |
|
171 |
|
172 const TDesC& CNcdSubscriptionProxy::Name() const |
|
173 { |
|
174 if ( iName == NULL ) |
|
175 { |
|
176 return KNullDesC; |
|
177 } |
|
178 |
|
179 return *iName; |
|
180 } |
|
181 |
|
182 HBufC8* CNcdSubscriptionProxy::IconL() const |
|
183 { |
|
184 DLTRACEIN(("")); |
|
185 if ( IsObsolete() ) |
|
186 { |
|
187 User::Leave( KNcdErrorObsolete ); |
|
188 } |
|
189 |
|
190 return iParentGroup.IconL(); |
|
191 } |
|
192 |
|
193 MNcdSubscription::TStatus CNcdSubscriptionProxy::SubscriptionStatus() const |
|
194 { |
|
195 DLTRACEIN(( _L("Subscription name: %S, subscription poId: %S"), |
|
196 &(Name()), |
|
197 &(PurchaseOptionId()) )); |
|
198 |
|
199 if ( iExpiredOn && *iExpiredOn != KNullDesC ) |
|
200 { |
|
201 DLINFO(( _L("ExpiredOn: %S"), iExpiredOn )); |
|
202 DLTRACEOUT(("Subscription expired.")); |
|
203 return MNcdSubscription::ESubscriptionExpired; |
|
204 } |
|
205 |
|
206 if ( iSubscriptionType == MNcdSubscription::EPeriodic || |
|
207 ( iSubscriptionType == MNcdSubscription::EAutomaticContinous |
|
208 && iCancelled ) ) |
|
209 { |
|
210 if ( iValidityTimeSet ) |
|
211 { |
|
212 TTime now; |
|
213 now.HomeTime(); |
|
214 |
|
215 if ( now > iValidUntil ) |
|
216 { |
|
217 DLTRACEOUT(("Subscription expired.")); |
|
218 return MNcdSubscription::ESubscriptionExpired; |
|
219 } |
|
220 } |
|
221 |
|
222 if ( iCreditLimitSet ) |
|
223 { |
|
224 // This simple compare is deemed to be enough as no |
|
225 // complicated operations are done on the TReal numbers |
|
226 if ( iCreditsLeft <= 0 ) |
|
227 { |
|
228 DLTRACEOUT(("Subscription expired.")); |
|
229 return MNcdSubscription::ESubscriptionExpired; |
|
230 } |
|
231 } |
|
232 |
|
233 if ( iDownloadLimitSet ) |
|
234 { |
|
235 if ( iDownloadsLeft <= 0 ) |
|
236 { |
|
237 DLTRACEOUT(("Subscription expired.")); |
|
238 return MNcdSubscription::ESubscriptionExpired; |
|
239 } |
|
240 } |
|
241 } |
|
242 |
|
243 |
|
244 // If we get here the subscription is not expired. Because |
|
245 // subscription like this is created when it is bought, |
|
246 // it cannot be in ENotSubscribed state. So the only alternative |
|
247 // left is ESubscriptionActive. |
|
248 DLTRACEOUT(("Subscription active.")); |
|
249 return MNcdSubscription::ESubscriptionActive; |
|
250 } |
|
251 |
|
252 TBool CNcdSubscriptionProxy::IsObsolete() const |
|
253 { |
|
254 return iObsolete; |
|
255 } |
|
256 |
|
257 TBool CNcdSubscriptionProxy::Unsubscribed() const |
|
258 { |
|
259 return iCancelled; |
|
260 } |
|
261 |
|
262 MNcdSubscriptionOperation* CNcdSubscriptionProxy::UnsubscribeL( |
|
263 MNcdSubscriptionOperationObserver& aObserver ) |
|
264 { |
|
265 DLTRACEIN(("")); |
|
266 |
|
267 if ( IsObsolete() ) |
|
268 { |
|
269 User::Leave( KNcdErrorObsolete ); |
|
270 } |
|
271 |
|
272 CNcdSubscriptionOperationProxy* operation( NULL ); |
|
273 |
|
274 operation = |
|
275 iOperationManager.CreateSubscriptionUnsubscribeOperationL( |
|
276 PurchaseOptionId(), |
|
277 iParentGroup.EntityId(), |
|
278 iParentGroup.Namespace(), |
|
279 iParentGroup.ServerUri(), |
|
280 aObserver ); |
|
281 |
|
282 DLTRACEOUT(("")); |
|
283 |
|
284 return operation; |
|
285 } |
|
286 |
|
287 MNcdSubscription::TType CNcdSubscriptionProxy::SubscriptionType() const |
|
288 { |
|
289 return iSubscriptionType; |
|
290 } |
|
291 |
|
292 TBool CNcdSubscriptionProxy::ValidityTime( TTime& aValidUntil ) const |
|
293 { |
|
294 if ( !iValidityTimeSet ) |
|
295 { |
|
296 return EFalse; |
|
297 } |
|
298 aValidUntil = iValidUntil; |
|
299 |
|
300 return ETrue; |
|
301 } |
|
302 |
|
303 TBool CNcdSubscriptionProxy::CreditLimit( TReal& aCreditsLeft, |
|
304 TReal& aTotalCredits ) const |
|
305 { |
|
306 if ( !iCreditLimitSet ) |
|
307 { |
|
308 return EFalse; |
|
309 } |
|
310 aCreditsLeft = iCreditsLeft; |
|
311 aTotalCredits = iTotalCredits; |
|
312 |
|
313 return ETrue; |
|
314 } |
|
315 |
|
316 TBool CNcdSubscriptionProxy::DownloadLimit( TInt& aDownloadsLeft, |
|
317 TInt& aTotalDownloads) const |
|
318 { |
|
319 if ( !iDownloadLimitSet ) |
|
320 { |
|
321 return EFalse; |
|
322 } |
|
323 aDownloadsLeft = iDownloadsLeft; |
|
324 aTotalDownloads = iTotalDownloads; |
|
325 |
|
326 return ETrue; |
|
327 } |
|
328 |
|
329 MNcdNode* CNcdSubscriptionProxy::OriginNodeL() const |
|
330 { |
|
331 DLTRACEIN(("")); |
|
332 |
|
333 if ( IsObsolete() ) |
|
334 { |
|
335 User::Leave( KNcdErrorObsolete ); |
|
336 } |
|
337 |
|
338 const CNcdNodeIdentifier& groupIdentifier = iParentGroup.Identifier(); |
|
339 |
|
340 // Notice that this function takes the metadataidentifier as a parameter. |
|
341 MNcdNode* subscriptionNode = |
|
342 &iNodeManager.CreateTemporaryOrSupplierNodeL( groupIdentifier ); |
|
343 |
|
344 // Increase also the reference counter by one here. |
|
345 // So, the root ref count is at least one when the user |
|
346 // gets it. |
|
347 if ( subscriptionNode != NULL ) |
|
348 { |
|
349 subscriptionNode->AddRef(); |
|
350 } |
|
351 |
|
352 DLTRACEOUT(("")); |
|
353 return subscriptionNode; |
|
354 } |
|
355 |
|
356 const TDesC& CNcdSubscriptionProxy::OriginPurchaseOptionId() const |
|
357 { |
|
358 return PurchaseOptionId(); |
|
359 } |
|
360 |
|
361 |
|
362 |
|
363 // Other functions |
|
364 |
|
365 CNcdOperationManagerProxy& CNcdSubscriptionProxy::OperationManager() const |
|
366 { |
|
367 return iOperationManager; |
|
368 } |
|
369 |
|
370 |
|
371 |
|
372 void CNcdSubscriptionProxy::InternalizeDataL( RReadStream& aStream ) |
|
373 { |
|
374 DLTRACEIN(("Internalizing subscription proxy")); |
|
375 |
|
376 ResetSubscriptionVariables(); |
|
377 |
|
378 InternalizeDesL( iName, aStream ); |
|
379 DLINFO(( _L("Subscription proxy, name: %S"), iName )); |
|
380 InternalizeDesL( iExpiredOn, aStream ); |
|
381 |
|
382 iCancelled = aStream.ReadInt32L(); |
|
383 |
|
384 iSubscriptionType = |
|
385 static_cast<MNcdSubscription::TType>(aStream.ReadInt32L()); |
|
386 |
|
387 iValidityTimeSet = aStream.ReadInt32L(); |
|
388 DLINFO(( "Subscription proxy, validitytimeset: %d", iValidityTimeSet )); |
|
389 TInt64 intValidUntil( -1 ); |
|
390 aStream >> intValidUntil; |
|
391 iValidUntil = intValidUntil; |
|
392 TInt totalValidityDelta = aStream.ReadInt32L(); // Not needed here |
|
393 DLINFO(( "Subscription proxy, validitydelta: %d", totalValidityDelta )); |
|
394 |
|
395 iCreditLimitSet = aStream.ReadInt32L(); |
|
396 iCreditsLeft = aStream.ReadReal32L(); |
|
397 DLINFO(( "Subscription proxy, credits left: %f", iCreditsLeft )); |
|
398 iTotalCredits = aStream.ReadReal32L(); |
|
399 DLINFO(( "Subscription proxy, total credits: %f", iTotalCredits )); |
|
400 |
|
401 iDownloadLimitSet = aStream.ReadInt32L(); |
|
402 iDownloadsLeft = aStream.ReadInt32L(); |
|
403 DLINFO(( "Subscription proxy, downloads left: %d", iDownloadsLeft )); |
|
404 iTotalDownloads = aStream.ReadInt32L(); |
|
405 DLINFO(( "Subscription proxy, total downloads: %d", iTotalDownloads )); |
|
406 |
|
407 InternalizeDesL( iPurchaseOptionId, aStream ); |
|
408 |
|
409 DLINFO(( _L("Subscription proxy, purchaseoptionid: %S"), |
|
410 iPurchaseOptionId )); |
|
411 |
|
412 DLTRACEOUT(("")); |
|
413 } |
|
414 |
|
415 |
|
416 void CNcdSubscriptionProxy::ResetSubscriptionVariables() |
|
417 { |
|
418 delete iName; |
|
419 iName = NULL; |
|
420 |
|
421 delete iExpiredOn; |
|
422 iExpiredOn = NULL; |
|
423 |
|
424 iCancelled = EFalse; |
|
425 |
|
426 iSubscriptionType = MNcdSubscription::EPeriodic; |
|
427 |
|
428 iValidityTimeSet = EFalse; |
|
429 iValidUntil = -1; |
|
430 |
|
431 iCreditLimitSet = EFalse; |
|
432 iCreditsLeft = -1; |
|
433 iTotalCredits = -1; |
|
434 |
|
435 iDownloadLimitSet = EFalse; |
|
436 iDownloadsLeft = -1; |
|
437 iTotalDownloads = -1; |
|
438 |
|
439 delete iPurchaseOptionId; |
|
440 iPurchaseOptionId = NULL; |
|
441 |
|
442 } |