|
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 CNcdNodeContentInfo class |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "ncdnodecontentinfoimpl.h" |
|
20 #include "catalogssession.h" |
|
21 #include "catalogsbasemessage.h" |
|
22 #include "ncdnodefunctionids.h" |
|
23 #include "ncdnodeclassids.h" |
|
24 #include "catalogsconstants.h" |
|
25 #include "ncd_pp_dataentity.h" |
|
26 #include "ncd_pp_dataentitycontent.h" |
|
27 #include "ncd_cp_query.h" |
|
28 #include "ncditempurpose.h" |
|
29 #include "catalogsutils.h" |
|
30 #include "ncderrors.h" |
|
31 #include "ncdproviderutils.h" |
|
32 #include "ncdinstallationservice.h" |
|
33 #include "ncdpurchasedetails.h" |
|
34 |
|
35 #include "catalogsdebug.h" |
|
36 |
|
37 CNcdNodeContentInfo::CNcdNodeContentInfo( NcdNodeClassIds::TNcdNodeClassId aClassId ) |
|
38 : CNcdCommunicable(), |
|
39 iClassId( aClassId ) |
|
40 { |
|
41 } |
|
42 |
|
43 void CNcdNodeContentInfo::ConstructL() |
|
44 { |
|
45 iMimeType = KNullDesC().AllocL(); |
|
46 iVersion = KNullDesC().AllocL(); |
|
47 |
|
48 } |
|
49 |
|
50 |
|
51 CNcdNodeContentInfo* CNcdNodeContentInfo::NewL() |
|
52 { |
|
53 CNcdNodeContentInfo* self = |
|
54 CNcdNodeContentInfo::NewLC(); |
|
55 CleanupStack::Pop( self ); |
|
56 return self; |
|
57 } |
|
58 |
|
59 CNcdNodeContentInfo* CNcdNodeContentInfo::NewLC() |
|
60 { |
|
61 CNcdNodeContentInfo* self = |
|
62 new( ELeave ) CNcdNodeContentInfo( |
|
63 NcdNodeClassIds::ENcdNodeContentInfoClassId ); |
|
64 CleanupClosePushL( *self ); |
|
65 self->ConstructL(); |
|
66 return self; |
|
67 } |
|
68 |
|
69 |
|
70 CNcdNodeContentInfo::~CNcdNodeContentInfo() |
|
71 { |
|
72 DLTRACEIN(("")); |
|
73 |
|
74 delete iMimeType; |
|
75 iMimeType = NULL; |
|
76 |
|
77 delete iVersion; |
|
78 iVersion = NULL; |
|
79 |
|
80 DLTRACEOUT(("")); |
|
81 } |
|
82 |
|
83 NcdNodeClassIds::TNcdNodeClassId CNcdNodeContentInfo::ClassId() const |
|
84 { |
|
85 return iClassId; |
|
86 } |
|
87 |
|
88 TUint CNcdNodeContentInfo::Purpose() const |
|
89 { |
|
90 return iPurpose; |
|
91 } |
|
92 |
|
93 const TDesC& CNcdNodeContentInfo::MimeType() const |
|
94 { |
|
95 return *iMimeType; |
|
96 } |
|
97 |
|
98 const TUid& CNcdNodeContentInfo::Uid() const |
|
99 { |
|
100 return iUid; |
|
101 } |
|
102 |
|
103 const TDesC& CNcdNodeContentInfo::Version() const |
|
104 { |
|
105 return *iVersion; |
|
106 } |
|
107 |
|
108 TInt CNcdNodeContentInfo::TotalContentSize() const |
|
109 { |
|
110 return iSize; |
|
111 } |
|
112 |
|
113 |
|
114 // Internalization from the protocol |
|
115 |
|
116 void CNcdNodeContentInfo::InternalizeL( |
|
117 MNcdPreminetProtocolDataEntity& aData ) |
|
118 { |
|
119 DLTRACEIN(("")); |
|
120 |
|
121 if ( ! aData.DownloadableContent() ) |
|
122 { |
|
123 DLERROR(("No content data present")); |
|
124 // Content info should not be internalized if there is no content info |
|
125 // available. |
|
126 DASSERT( EFalse ); |
|
127 // Content data not present. |
|
128 User::Leave( KErrNotFound ); |
|
129 } |
|
130 |
|
131 iPurpose = 0; |
|
132 |
|
133 delete iMimeType; |
|
134 iMimeType = NULL; |
|
135 |
|
136 iUid = TUid::Null(); |
|
137 |
|
138 delete iVersion; |
|
139 iVersion = NULL; |
|
140 |
|
141 // Construct purpose. |
|
142 TInt purposeCount = aData.DownloadableContent()->ContentPurposeCount(); |
|
143 for ( TInt i = 0; i < purposeCount; i++ ) |
|
144 { |
|
145 const TDesC& purpose = |
|
146 aData.DownloadableContent()->ContentPurposeL( i ); |
|
147 |
|
148 // Notice that the content purpose does not need to be case insensitive. |
|
149 // According to the specification the purposes should be given in all |
|
150 // lower case characters. So, the Compare function should be used here, |
|
151 // which is much faster than using of CompareF function. |
|
152 if ( purpose.Compare( KNcdContentPurposeMusic ) == 0 ) |
|
153 { |
|
154 iPurpose |= ENcdItemPurposeMusic; |
|
155 } |
|
156 else if ( purpose.Compare( KNcdContentPurposeRingtone ) == 0 ) |
|
157 { |
|
158 iPurpose |= ENcdItemPurposeRingtone; |
|
159 } |
|
160 else if ( purpose.Compare( KNcdContentPurposeWallpaper ) == 0 ) |
|
161 { |
|
162 iPurpose |= ENcdItemPurposeWallpaper; |
|
163 } |
|
164 else if ( purpose.Compare( KNcdContentPurposeVideo ) == 0 ) |
|
165 { |
|
166 iPurpose |= ENcdItemPurposeVideo; |
|
167 } |
|
168 else if ( purpose.Compare( KNcdContentPurposeTheme ) == 0 ) |
|
169 { |
|
170 iPurpose |= ENcdItemPurposeTheme; |
|
171 } |
|
172 else if ( purpose.Compare( KNcdContentPurposeApplication ) == 0 ) |
|
173 { |
|
174 iPurpose |= ENcdItemPurposeApplication; |
|
175 } |
|
176 else if ( purpose.Compare( KNcdContentPurposeHtmlPage ) == 0 ) |
|
177 { |
|
178 iPurpose |= ENcdItemPurposeHtmlPage; |
|
179 } |
|
180 else if ( purpose.Compare( KNcdContentPurposeGame ) == 0 ) |
|
181 { |
|
182 iPurpose |= ENcdItemPurposeGame; |
|
183 } |
|
184 else if ( purpose.Compare( KNcdContentPurposeScreensaver ) == 0 ) |
|
185 { |
|
186 iPurpose |= ENcdItemPurposeScreensaver; |
|
187 } |
|
188 else if ( purpose.Compare( KNcdContentPurposeStream ) == 0 ) |
|
189 { |
|
190 iPurpose |= ENcdItemPurposeStream; |
|
191 } |
|
192 else |
|
193 { |
|
194 iPurpose |= ENcdItemPurposeUnknown; |
|
195 } |
|
196 } |
|
197 |
|
198 iMimeType = aData.DownloadableContent()->Mime().AllocL(); |
|
199 |
|
200 if ( iPurpose & ENcdItemPurposeApplication ) |
|
201 { |
|
202 TInt uid = 0; |
|
203 TRAPD( err, uid = DesHexToIntL( aData.DownloadableContent()->Id() ) ); |
|
204 if( err != KErrNone ) |
|
205 { |
|
206 DLERROR(( _L("DownloadableContent()->Id() was not valid hex, using ZERO: %S"), |
|
207 &aData.DownloadableContent()->Id() )); |
|
208 iUid.iUid = 0; |
|
209 } |
|
210 else |
|
211 { |
|
212 iUid.iUid = uid; |
|
213 } |
|
214 } |
|
215 |
|
216 iVersion = aData.DownloadableContent()->Version().AllocL(); |
|
217 iSize = aData.DownloadableContent()->Size(); |
|
218 |
|
219 DLTRACEOUT(("")); |
|
220 } |
|
221 |
|
222 |
|
223 // Internalization from and externalization to the database |
|
224 |
|
225 void CNcdNodeContentInfo::ExternalizeL( RWriteStream& aStream ) |
|
226 { |
|
227 DLTRACEIN(("")); |
|
228 |
|
229 aStream.WriteInt32L( ClassId() ); |
|
230 |
|
231 aStream.WriteUint16L( iPurpose ); |
|
232 ExternalizeDesL( *iMimeType, aStream ); |
|
233 aStream.WriteInt32L( iUid.iUid ); |
|
234 ExternalizeDesL( *iVersion, aStream ); |
|
235 aStream.WriteInt32L( iSize ); |
|
236 |
|
237 DLTRACEOUT(("")); |
|
238 } |
|
239 |
|
240 |
|
241 void CNcdNodeContentInfo::InternalizeL( RReadStream& aStream ) |
|
242 { |
|
243 DLTRACEIN(("")); |
|
244 |
|
245 // Read the class id first because it is set to the stream in internalize |
|
246 // function and it is not read from the stream anywhere else. |
|
247 TInt classId( aStream.ReadInt32L() ); |
|
248 if ( classId != ClassId() ) |
|
249 { |
|
250 DLTRACE(("Wrong class id")); |
|
251 DASSERT( EFalse ); |
|
252 // Leave because the stream does not match this class object |
|
253 User::Leave( KErrCorrupt ); |
|
254 } |
|
255 |
|
256 iPurpose = aStream.ReadUint16L(); |
|
257 InternalizeDesL( iMimeType, aStream ); |
|
258 iUid.iUid = aStream.ReadInt32L(); |
|
259 InternalizeDesL( iVersion, aStream ); |
|
260 iSize = aStream.ReadInt32L(); |
|
261 |
|
262 DLTRACEOUT(("")); |
|
263 } |
|
264 |
|
265 |
|
266 void CNcdNodeContentInfo::InternalizeL( const MNcdPurchaseDetails& aDetails ) |
|
267 { |
|
268 DLTRACEIN(("")); |
|
269 iPurpose = aDetails.ItemPurpose(); |
|
270 iSize = aDetails.TotalContentSize(); |
|
271 iUid.iUid = aDetails.AttributeInt32( |
|
272 MNcdPurchaseDetails::EPurchaseAttributeContentUid ); |
|
273 AssignDesL( iVersion, aDetails.Version() ); |
|
274 AssignDesL( iMimeType, aDetails.AttributeString( |
|
275 MNcdPurchaseDetails::EPurchaseAttributeContentMimeType ) ); |
|
276 } |
|
277 |
|
278 |
|
279 void CNcdNodeContentInfo::ReceiveMessage( MCatalogsBaseMessage* aMessage, |
|
280 TInt aFunctionNumber ) |
|
281 { |
|
282 DLTRACEIN(("")); |
|
283 |
|
284 DASSERT( aMessage ); |
|
285 |
|
286 // Now, we can be sure that rest of the time iMessage exists. |
|
287 // This member variable is set for the CounterPartLost function. |
|
288 iMessage = aMessage; |
|
289 |
|
290 TInt trapError( KErrNone ); |
|
291 |
|
292 // Check which function is called by the proxy side object. |
|
293 // Function number are located in ncdnodefunctinoids.h file. |
|
294 switch( aFunctionNumber ) |
|
295 { |
|
296 case NcdNodeFunctionIds::ENcdInternalize: |
|
297 // Internalize the proxy side according to the data |
|
298 // of this object. |
|
299 TRAP( trapError, InternalizeRequestL( *aMessage ) ); |
|
300 break; |
|
301 |
|
302 case NcdNodeFunctionIds::ENcdRelease: |
|
303 // The proxy does not want to use this object anymore. |
|
304 // So, release the handle from the session. |
|
305 ReleaseRequest( *aMessage ); |
|
306 break; |
|
307 |
|
308 default: |
|
309 DLERROR(("Unidentified function request")); |
|
310 DASSERT( EFalse ); |
|
311 break; |
|
312 } |
|
313 |
|
314 if ( trapError != KErrNone ) |
|
315 { |
|
316 // Because something went wrong, the complete has not been |
|
317 // yet called for the message. |
|
318 // So, inform the client about the error if the |
|
319 // message is still available. |
|
320 aMessage->CompleteAndRelease( trapError ); |
|
321 } |
|
322 |
|
323 // Because the message should not be used after this, set it NULL. |
|
324 // So, CounterPartLost function will know that no messages are |
|
325 // waiting the response at the moment. |
|
326 iMessage = NULL; |
|
327 |
|
328 DLTRACEOUT(("")); |
|
329 } |
|
330 |
|
331 void CNcdNodeContentInfo::CounterPartLost( const MCatalogsSession& aSession ) |
|
332 { |
|
333 // This function may be called whenever -- when the message is waiting |
|
334 // response or when the message does not exist. |
|
335 // iMessage may be NULL here, because in the end of the |
|
336 // ReceiveMessage it is set to NULL. The life time of the message |
|
337 // ends shortly after CompleteAndRelease is called. |
|
338 if ( iMessage != NULL ) |
|
339 { |
|
340 iMessage->CounterPartLost( aSession ); |
|
341 } |
|
342 } |
|
343 |
|
344 |
|
345 void CNcdNodeContentInfo::InternalizeRequestL( MCatalogsBaseMessage& aMessage ) |
|
346 { |
|
347 DLTRACEIN(("")); |
|
348 |
|
349 CBufBase* buf = CBufFlat::NewL( KBufExpandSize ); |
|
350 CleanupStack::PushL( buf ); |
|
351 |
|
352 RBufWriteStream stream( *buf ); |
|
353 CleanupClosePushL( stream ); |
|
354 |
|
355 |
|
356 // Include all the necessary node data to the stream |
|
357 ExternalizeDataForRequestL( stream ); |
|
358 |
|
359 |
|
360 // Commits data to the stream when closing. |
|
361 CleanupStack::PopAndDestroy( &stream ); |
|
362 |
|
363 |
|
364 // If this leaves, ReceiveMessage will complete the message. |
|
365 // NOTE: that here we expect that the buffer contains at least |
|
366 // some data. So, make sure that ExternalizeDataForRequestL inserts |
|
367 // something to the buffer. |
|
368 aMessage.CompleteAndReleaseL( buf->Ptr( 0 ), KErrNone ); |
|
369 |
|
370 |
|
371 DLTRACE(("Deleting the buf")); |
|
372 CleanupStack::PopAndDestroy( buf ); |
|
373 |
|
374 DLTRACEOUT(("")); |
|
375 } |
|
376 |
|
377 |
|
378 void CNcdNodeContentInfo::ExternalizeDataForRequestL( RWriteStream& aStream ) |
|
379 { |
|
380 DLTRACEIN(("")); |
|
381 |
|
382 if ( IsObsolete() ) |
|
383 { |
|
384 DLINFO(("Set as obsolete. This means that server has removed the object.")); |
|
385 User::Leave( KNcdErrorObsolete ); |
|
386 } |
|
387 |
|
388 ExternalizeL( aStream ); |
|
389 |
|
390 DLTRACEOUT(("")); |
|
391 } |
|
392 |
|
393 void CNcdNodeContentInfo::ReleaseRequest( MCatalogsBaseMessage& aMessage ) const |
|
394 { |
|
395 DLTRACEIN(("")); |
|
396 |
|
397 // Decrease the reference count for this object. |
|
398 // When the reference count reaches zero, this object will be destroyed |
|
399 // and removed from the session. |
|
400 MCatalogsSession& requestSession( aMessage.Session() ); |
|
401 TInt handle( aMessage.Handle() ); |
|
402 |
|
403 // Send complete information back to proxy. |
|
404 aMessage.CompleteAndRelease( KErrNone ); |
|
405 |
|
406 // Remove this object from the session. |
|
407 requestSession.RemoveObject( handle ); |
|
408 |
|
409 DLTRACEOUT(("")); |
|
410 } |
|
411 |
|
412 |