|
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 CNcdNodeuriContent class |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "ncdnodeuricontentimpl.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_download.h" |
|
26 #include "ncd_cp_query.h" |
|
27 #include "catalogsutils.h" |
|
28 #include "catalogsdebug.h" |
|
29 #include "ncdpurchasedetails.h" |
|
30 #include "ncdutils.h" |
|
31 |
|
32 |
|
33 CNcdNodeUriContent::CNcdNodeUriContent( NcdNodeClassIds::TNcdNodeClassId aClassId ) |
|
34 : CCatalogsCommunicable(), |
|
35 iClassId( aClassId ), |
|
36 iValidityDelta( -1 ) |
|
37 { |
|
38 } |
|
39 |
|
40 void CNcdNodeUriContent::ConstructL() |
|
41 { |
|
42 iUriContent = KNullDesC().AllocL(); |
|
43 } |
|
44 |
|
45 |
|
46 CNcdNodeUriContent* CNcdNodeUriContent::NewL() |
|
47 { |
|
48 CNcdNodeUriContent* self = |
|
49 CNcdNodeUriContent::NewLC(); |
|
50 CleanupStack::Pop( self ); |
|
51 return self; |
|
52 } |
|
53 |
|
54 CNcdNodeUriContent* CNcdNodeUriContent::NewLC() |
|
55 { |
|
56 CNcdNodeUriContent* self = |
|
57 new( ELeave ) CNcdNodeUriContent( |
|
58 NcdNodeClassIds::ENcdNodeUriContentClassId ); |
|
59 CleanupClosePushL( *self ); |
|
60 self->ConstructL(); |
|
61 return self; |
|
62 } |
|
63 |
|
64 |
|
65 CNcdNodeUriContent::~CNcdNodeUriContent() |
|
66 { |
|
67 DLTRACEIN(("")); |
|
68 |
|
69 delete iUriContent; |
|
70 iUriContent = NULL; |
|
71 |
|
72 DLTRACEOUT(("")); |
|
73 } |
|
74 |
|
75 NcdNodeClassIds::TNcdNodeClassId CNcdNodeUriContent::ClassId() const |
|
76 { |
|
77 return iClassId; |
|
78 } |
|
79 |
|
80 |
|
81 // --------------------------------------------------------------------------- |
|
82 // Internalization from purchase details |
|
83 // --------------------------------------------------------------------------- |
|
84 // |
|
85 TBool CNcdNodeUriContent::InternalizeL( const MNcdPurchaseDetails& aDetails ) |
|
86 { |
|
87 DLTRACEIN(("this-ptr: %X", this)); |
|
88 |
|
89 TArray<MNcdPurchaseDownloadInfo*> dlInfo ( aDetails.DownloadInfoL() ); |
|
90 |
|
91 TInt index = KErrNotFound; |
|
92 for ( TInt i = 0; i < dlInfo.Count(); ++i ) |
|
93 { |
|
94 if ( dlInfo[i]->ContentUsage() == MNcdPurchaseDownloadInfo::EConsumable ) |
|
95 { |
|
96 DLINFO(("Download in index %d is consumable!", i)); |
|
97 index = i; |
|
98 // Only one uri is supported so break immediately as we |
|
99 // come across it |
|
100 break; |
|
101 } |
|
102 } |
|
103 |
|
104 // Leaves if index is still KErrNotFound, positive indices don't leave |
|
105 if ( index == KErrNotFound ) |
|
106 { |
|
107 return EFalse; |
|
108 } |
|
109 |
|
110 DLTRACE(("Copying content URI")); |
|
111 HBufC* uri = dlInfo[index]->ContentUri().AllocL(); |
|
112 delete iUriContent; |
|
113 iUriContent = uri; |
|
114 iValidityDelta = dlInfo[index]->ContentValidityDelta(); |
|
115 DLTRACEOUT(( _L("Content URI: %S"), iUriContent )); |
|
116 |
|
117 return ETrue; |
|
118 } |
|
119 |
|
120 |
|
121 // Internalization from and externalization to the database |
|
122 |
|
123 void CNcdNodeUriContent::ExternalizeL( RWriteStream& aStream ) |
|
124 { |
|
125 DLTRACEIN(("")); |
|
126 |
|
127 aStream.WriteInt32L( ClassId() ); |
|
128 |
|
129 ExternalizeDesL( *iUriContent, aStream ); |
|
130 |
|
131 aStream.WriteInt32L( iValidityDelta ); |
|
132 |
|
133 DLTRACEOUT(("")); |
|
134 } |
|
135 |
|
136 |
|
137 void CNcdNodeUriContent::InternalizeL( RReadStream& aStream ) |
|
138 { |
|
139 DLTRACEIN(("")); |
|
140 |
|
141 // Read the class id first because it is set to the stream in internalize |
|
142 // function and it is not read from the stream anywhere else. |
|
143 TInt classId( aStream.ReadInt32L() ); |
|
144 if ( classId != ClassId() ) |
|
145 { |
|
146 DLTRACE(("Wrong class id")); |
|
147 DASSERT( EFalse ); |
|
148 // Leave because the stream does not match this class object |
|
149 User::Leave( KErrCorrupt ); |
|
150 } |
|
151 |
|
152 InternalizeDesL( iUriContent, aStream ); |
|
153 |
|
154 iValidityDelta = aStream.ReadInt32L(); |
|
155 |
|
156 DLTRACEOUT(("")); |
|
157 } |
|
158 |
|
159 |
|
160 |
|
161 // --------------------------------------------------------------------------- |
|
162 // URI getter |
|
163 // --------------------------------------------------------------------------- |
|
164 // |
|
165 const TDesC& CNcdNodeUriContent::Uri() const |
|
166 { |
|
167 DASSERT( iUriContent ); |
|
168 DLTRACEIN(( _L("%S"), iUriContent )); |
|
169 return *iUriContent; |
|
170 } |
|
171 |
|
172 |
|
173 void CNcdNodeUriContent::ReceiveMessage( MCatalogsBaseMessage* aMessage, |
|
174 TInt aFunctionNumber ) |
|
175 { |
|
176 DLTRACEIN(("")); |
|
177 |
|
178 DASSERT( aMessage ); |
|
179 |
|
180 // Now, we can be sure that rest of the time iMessage exists. |
|
181 // This member variable is set for the CounterPartLost function. |
|
182 iMessage = aMessage; |
|
183 |
|
184 TInt trapError( KErrNone ); |
|
185 |
|
186 // Check which function is called by the proxy side object. |
|
187 // Function number are located in ncdnodefunctinoids.h file. |
|
188 switch( aFunctionNumber ) |
|
189 { |
|
190 case NcdNodeFunctionIds::ENcdInternalize: |
|
191 // Internalize the proxy side according to the data |
|
192 // of this object. |
|
193 TRAP( trapError, InternalizeRequestL( *aMessage ) ); |
|
194 break; |
|
195 |
|
196 case NcdNodeFunctionIds::ENcdRelease: |
|
197 // The proxy does not want to use this object anymore. |
|
198 // So, release the handle from the session. |
|
199 ReleaseRequest( *aMessage ); |
|
200 break; |
|
201 |
|
202 default: |
|
203 DLERROR(("Unidentified function request")); |
|
204 DASSERT( EFalse ); |
|
205 break; |
|
206 } |
|
207 |
|
208 if ( trapError != KErrNone ) |
|
209 { |
|
210 // Because something went wrong, the complete has not been |
|
211 // yet called for the message. |
|
212 // So, inform the client about the error if the |
|
213 // message is still available. |
|
214 aMessage->CompleteAndRelease( trapError ); |
|
215 } |
|
216 |
|
217 // Because the message should not be used after this, set it NULL. |
|
218 // So, CounterPartLost function will know that no messages are |
|
219 // waiting the response at the moment. |
|
220 iMessage = NULL; |
|
221 |
|
222 DLTRACEOUT(("")); |
|
223 } |
|
224 |
|
225 void CNcdNodeUriContent::CounterPartLost( const MCatalogsSession& aSession ) |
|
226 { |
|
227 // This function may be called whenever -- when the message is waiting |
|
228 // response or when the message does not exist. |
|
229 // iMessage may be NULL here, because in the end of the |
|
230 // ReceiveMessage it is set to NULL. The life time of the message |
|
231 // ends shortly after CompleteAndRelease is called. |
|
232 if ( iMessage != NULL ) |
|
233 { |
|
234 iMessage->CounterPartLost( aSession ); |
|
235 } |
|
236 } |
|
237 |
|
238 |
|
239 void CNcdNodeUriContent::InternalizeRequestL( MCatalogsBaseMessage& aMessage ) |
|
240 { |
|
241 DLTRACEIN(("")); |
|
242 |
|
243 CBufBase* buf = CBufFlat::NewL( KBufExpandSize ); |
|
244 CleanupStack::PushL( buf ); |
|
245 |
|
246 RBufWriteStream stream( *buf ); |
|
247 CleanupClosePushL( stream ); |
|
248 |
|
249 |
|
250 // Include all the necessary node data to the stream |
|
251 ExternalizeDataForRequestL( stream ); |
|
252 |
|
253 |
|
254 // Commits data to the stream when closing. |
|
255 CleanupStack::PopAndDestroy( &stream ); |
|
256 |
|
257 |
|
258 // If this leaves, ReceiveMessage will complete the message. |
|
259 // NOTE: that here we expect that the buffer contains at least |
|
260 // some data. So, make sure that ExternalizeDataForRequestL inserts |
|
261 // something to the buffer. |
|
262 aMessage.CompleteAndReleaseL( buf->Ptr( 0 ), KErrNone ); |
|
263 |
|
264 |
|
265 DLTRACE(("Deleting the buf")); |
|
266 CleanupStack::PopAndDestroy( buf ); |
|
267 |
|
268 DLTRACEOUT(("")); |
|
269 } |
|
270 |
|
271 |
|
272 void CNcdNodeUriContent::ExternalizeDataForRequestL( RWriteStream& aStream ) |
|
273 { |
|
274 DLTRACEIN(("")); |
|
275 |
|
276 ExternalizeL( aStream ); |
|
277 |
|
278 DLTRACEOUT(("")); |
|
279 } |
|
280 |
|
281 void CNcdNodeUriContent::ReleaseRequest( MCatalogsBaseMessage& aMessage ) const |
|
282 { |
|
283 DLTRACEIN(("")); |
|
284 |
|
285 // Decrease the reference count for this object. |
|
286 // When the reference count reaches zero, this object will be destroyed |
|
287 // and removed from the session. |
|
288 MCatalogsSession& requestSession( aMessage.Session() ); |
|
289 TInt handle( aMessage.Handle() ); |
|
290 |
|
291 // Send complete information back to proxy. |
|
292 aMessage.CompleteAndRelease( KErrNone ); |
|
293 |
|
294 // Remove this object from the session. |
|
295 requestSession.RemoveObject( handle ); |
|
296 |
|
297 DLTRACEOUT(("")); |
|
298 } |
|
299 |
|
300 |