|
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 CNcdFileDownloadOperationProxy |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <s32strm.h> |
|
20 #include "ncdfiledownloadoperationproxy.h" |
|
21 #include "ncdfiledownloadoperationobserver.h" |
|
22 #include "catalogsdebug.h" |
|
23 #include "ncddownloadoperationstates.h" |
|
24 #include "ncdoperationproxyremovehandler.h" |
|
25 #include "catalogsclientserver.h" |
|
26 #include "catalogsutils.h" |
|
27 #include "ncdnodeproxy.h" |
|
28 |
|
29 |
|
30 // ======== MEMBER FUNCTIONS ======== |
|
31 |
|
32 // --------------------------------------------------------------------------- |
|
33 // NewL |
|
34 // --------------------------------------------------------------------------- |
|
35 // |
|
36 CNcdFileDownloadOperationProxy* CNcdFileDownloadOperationProxy::NewL( |
|
37 MCatalogsClientServer& aSession, |
|
38 TInt aHandle, |
|
39 MNcdOperationProxyRemoveHandler* aRemoveHandler, |
|
40 CNcdNodeProxy* aNode, |
|
41 CNcdNodeManagerProxy* aNodeManager, |
|
42 const TDesC& aTargetFilename, |
|
43 MNcdFileDownloadOperationObserver* aObserver, |
|
44 TNcdDownloadDataType aDataType ) |
|
45 { |
|
46 CNcdFileDownloadOperationProxy* self = |
|
47 CNcdFileDownloadOperationProxy::NewLC( |
|
48 aSession, |
|
49 aHandle, |
|
50 aRemoveHandler, |
|
51 aNode, |
|
52 aNodeManager, |
|
53 aTargetFilename, |
|
54 aObserver, |
|
55 aDataType ); |
|
56 CleanupStack::Pop( self ); |
|
57 return self; |
|
58 } |
|
59 |
|
60 |
|
61 // --------------------------------------------------------------------------- |
|
62 // NewLC |
|
63 // --------------------------------------------------------------------------- |
|
64 // |
|
65 CNcdFileDownloadOperationProxy* CNcdFileDownloadOperationProxy::NewLC( |
|
66 MCatalogsClientServer& aSession, |
|
67 TInt aHandle, |
|
68 MNcdOperationProxyRemoveHandler* aRemoveHandler, |
|
69 CNcdNodeProxy* aNode, |
|
70 CNcdNodeManagerProxy* aNodeManager, |
|
71 const TDesC& aTargetFilename, |
|
72 MNcdFileDownloadOperationObserver* aObserver, |
|
73 TNcdDownloadDataType aDataType ) |
|
74 { |
|
75 CNcdFileDownloadOperationProxy* self = |
|
76 new( ELeave ) CNcdFileDownloadOperationProxy( aDataType ); |
|
77 |
|
78 self->AddRef(); |
|
79 CleanupReleasePushL( *self ); |
|
80 self->ConstructL( aSession, aHandle, aRemoveHandler, |
|
81 aNode, aNodeManager, aObserver, aTargetFilename ); |
|
82 return self; |
|
83 } |
|
84 |
|
85 |
|
86 // --------------------------------------------------------------------------- |
|
87 // From MNcdFileDownloadOperation |
|
88 // |
|
89 // --------------------------------------------------------------------------- |
|
90 // |
|
91 const TDesC& CNcdFileDownloadOperationProxy::TargetFileName() const |
|
92 { |
|
93 DASSERT( iTargetFilename ); |
|
94 return *iTargetFilename; |
|
95 } |
|
96 |
|
97 |
|
98 // --------------------------------------------------------------------------- |
|
99 // From MNcdFileDownloadOperation |
|
100 // |
|
101 // --------------------------------------------------------------------------- |
|
102 // |
|
103 void CNcdFileDownloadOperationProxy::PauseL() |
|
104 { |
|
105 DLTRACEIN( ( "" ) ); |
|
106 HBufC8* data = NULL; |
|
107 |
|
108 TState state = OperationStateL(); |
|
109 // Check that the operation is in a resumable state |
|
110 if ( state == EStateCancelled ) |
|
111 { |
|
112 DLERROR(("Cannot resume! Operation has been cancelled. Leaving")); |
|
113 User::Leave( KErrCancel ); |
|
114 } |
|
115 |
|
116 // Operation must be running for pause to work |
|
117 if ( state != EStateRunning || iIsPaused ) |
|
118 { |
|
119 DLTRACEOUT(("Operation complete or other unresumable state")); |
|
120 return; |
|
121 } |
|
122 |
|
123 ClientServerSession().SendSyncAlloc( ENCDOperationFunctionPause, |
|
124 KNullDesC8(), |
|
125 data, |
|
126 Handle(), |
|
127 0 ); |
|
128 |
|
129 if ( data ) |
|
130 { |
|
131 DLTRACE(("Received progress information")); |
|
132 |
|
133 RDesReadStream stream( *data ); |
|
134 CleanupStack::PushL( data ); |
|
135 CleanupClosePushL( stream ); |
|
136 |
|
137 // Just read completionId from the stream |
|
138 stream.ReadInt32L(); |
|
139 |
|
140 TNcdSendableProgress progress; |
|
141 // Read progress info |
|
142 progress.InternalizeL( stream ); |
|
143 |
|
144 // Update paused state |
|
145 iIsPaused = ( progress.iState == ENcdDownloadPaused ); |
|
146 |
|
147 CleanupStack::PopAndDestroy( 2, data ); // stream, data |
|
148 } |
|
149 |
|
150 SetState( EStateRunning ); |
|
151 DLTRACEOUT( ( "IsPaused: %d", iIsPaused ) ); |
|
152 } |
|
153 |
|
154 |
|
155 // --------------------------------------------------------------------------- |
|
156 // From MNcdFileDownloadOperation |
|
157 // |
|
158 // --------------------------------------------------------------------------- |
|
159 // |
|
160 void CNcdFileDownloadOperationProxy::ResumeL() |
|
161 { |
|
162 DLTRACEIN(( "" )); |
|
163 HBufC8* data = NULL; |
|
164 TState state = OperationStateL(); |
|
165 |
|
166 // Check that the operation is in a resumable state |
|
167 if ( state == EStateCancelled ) |
|
168 { |
|
169 DLERROR(("Cannot resume! Operation has been cancelled. Leaving")); |
|
170 User::Leave( KErrCancel ); |
|
171 } |
|
172 |
|
173 if ( ( state != EStateStopped && state != EStateRunning ) || !iIsPaused ) |
|
174 { |
|
175 DLTRACEOUT(("Operation complete or other unresumable state")); |
|
176 return; |
|
177 } |
|
178 |
|
179 ClientServerSession().SendSyncAlloc( ENCDOperationFunctionResume, |
|
180 KNullDesC8(), |
|
181 data, |
|
182 Handle(), |
|
183 0 ); |
|
184 |
|
185 if ( data ) |
|
186 { |
|
187 DLTRACE(("Received progress information")); |
|
188 RDesReadStream stream( *data ); |
|
189 CleanupStack::PushL( data ); |
|
190 CleanupClosePushL( stream ); |
|
191 |
|
192 // Just read the completionId from the stream |
|
193 stream.ReadInt32L(); |
|
194 |
|
195 TNcdSendableProgress progress; |
|
196 // Read progress info |
|
197 |
|
198 progress.InternalizeL( stream ); |
|
199 // Update paused-state |
|
200 iIsPaused = ( progress.iState == ENcdDownloadPaused ); |
|
201 |
|
202 DLTRACE(("Sending continue message")); |
|
203 if ( progress.iState == KNcdDownloadContinueMessageRequired ) |
|
204 { |
|
205 SendContinueMessageL(); |
|
206 } |
|
207 |
|
208 CleanupStack::PopAndDestroy( 2, data ); // stream, data |
|
209 } |
|
210 |
|
211 SetState( EStateRunning ); |
|
212 DLTRACEOUT(( "" )); |
|
213 |
|
214 } |
|
215 |
|
216 |
|
217 // --------------------------------------------------------------------------- |
|
218 // From MNcdFileDownloadOperation |
|
219 // |
|
220 // --------------------------------------------------------------------------- |
|
221 // |
|
222 TBool CNcdFileDownloadOperationProxy::IsPaused() |
|
223 { |
|
224 return iIsPaused; |
|
225 } |
|
226 |
|
227 |
|
228 // --------------------------------------------------------------------------- |
|
229 // |
|
230 // --------------------------------------------------------------------------- |
|
231 // |
|
232 TBool CNcdFileDownloadOperationProxy::IsPausableL() |
|
233 { |
|
234 DLTRACEIN(("")); |
|
235 TInt data = KErrNone; |
|
236 User::LeaveIfError( ClientServerSession().SendSync( |
|
237 ENCDOperationFunctionGetData, |
|
238 KNullDesC8(), |
|
239 data, |
|
240 Handle() ) ); |
|
241 |
|
242 DLTRACEOUT(("pausable: %d", data == KNcdDownloadIsPausable )); |
|
243 return data == KNcdDownloadIsPausable; |
|
244 } |
|
245 |
|
246 |
|
247 // --------------------------------------------------------------------------- |
|
248 // Download type getter |
|
249 // --------------------------------------------------------------------------- |
|
250 // |
|
251 TNcdDownloadDataType CNcdFileDownloadOperationProxy::DownloadDataType() const |
|
252 { |
|
253 return iDataType; |
|
254 } |
|
255 |
|
256 |
|
257 // --------------------------------------------------------------------------- |
|
258 // From MNcdOperation |
|
259 // Operation type getter |
|
260 // --------------------------------------------------------------------------- |
|
261 // |
|
262 TNcdInterfaceId CNcdFileDownloadOperationProxy::OperationType() const |
|
263 { |
|
264 return static_cast<TNcdInterfaceId>( |
|
265 MNcdFileDownloadOperation::KInterfaceUid ); |
|
266 } |
|
267 |
|
268 |
|
269 // --------------------------------------------------------------------------- |
|
270 // Constructor |
|
271 // --------------------------------------------------------------------------- |
|
272 // |
|
273 CNcdFileDownloadOperationProxy::CNcdFileDownloadOperationProxy( |
|
274 TNcdDownloadDataType aDataType ) |
|
275 : CNcdOperation< MNcdFileDownloadOperation >( NULL ), iIsPaused( EFalse ), |
|
276 iDataType( aDataType ) |
|
277 { |
|
278 } |
|
279 |
|
280 |
|
281 |
|
282 // --------------------------------------------------------------------------- |
|
283 // Destructor |
|
284 // --------------------------------------------------------------------------- |
|
285 // |
|
286 CNcdFileDownloadOperationProxy::~CNcdFileDownloadOperationProxy() |
|
287 { |
|
288 DLTRACEIN( ( "" ) ); |
|
289 delete iTargetFilename; |
|
290 DASSERT( iRemoveHandler ); |
|
291 if ( iRemoveHandler ) |
|
292 { |
|
293 DLTRACE(("Removing proxy from remove handler")); |
|
294 iRemoveHandler->RemoveOperationProxy( *this ); |
|
295 } |
|
296 |
|
297 DLTRACEOUT( ( "" ) ); |
|
298 } |
|
299 |
|
300 |
|
301 // --------------------------------------------------------------------------- |
|
302 // ConstructL |
|
303 // --------------------------------------------------------------------------- |
|
304 // |
|
305 void CNcdFileDownloadOperationProxy::ConstructL( MCatalogsClientServer& aSession, |
|
306 TInt aHandle, |
|
307 MNcdOperationProxyRemoveHandler* aRemoveHandler, |
|
308 CNcdNodeProxy* aNode, |
|
309 CNcdNodeManagerProxy* aNodeManager, |
|
310 MNcdFileDownloadOperationObserver* aObserver, |
|
311 const TDesC& aTargetFilename ) |
|
312 { |
|
313 DLTRACEIN( ( "" ) ); |
|
314 CNcdBaseOperationProxy::ConstructL( aSession, aHandle, aRemoveHandler, |
|
315 aNode, aNodeManager ); |
|
316 iObserver = aObserver; |
|
317 iTargetFilename = aTargetFilename.AllocL(); |
|
318 |
|
319 // Initialize the operation if necessary. Initialization mechanism is used |
|
320 // here to transfer the targetfilename to serverside unless it is |
|
321 // transferred in node id |
|
322 if ( aNode ) |
|
323 { |
|
324 InitializeOperationL(); |
|
325 } |
|
326 DLTRACEOUT( ( "" ) ); |
|
327 } |
|
328 |
|
329 |
|
330 // --------------------------------------------------------------------------- |
|
331 // Handle progress callback |
|
332 // --------------------------------------------------------------------------- |
|
333 // |
|
334 void CNcdFileDownloadOperationProxy::ProgressCallback() |
|
335 { |
|
336 DLTRACEIN( ( "" ) ); |
|
337 if ( iObserver ) |
|
338 { |
|
339 |
|
340 TNcdSendableProgress& sendableProgress( SendableProgress() ); |
|
341 TNcdProgress progress( sendableProgress.iProgress, |
|
342 sendableProgress.iMaxProgress ); |
|
343 |
|
344 iObserver->FileDownloadProgress( *this, progress ); |
|
345 } |
|
346 DLTRACEOUT( ( "" ) ); |
|
347 } |
|
348 |
|
349 |
|
350 // --------------------------------------------------------------------------- |
|
351 // Handle query received callback |
|
352 // --------------------------------------------------------------------------- |
|
353 // |
|
354 void CNcdFileDownloadOperationProxy::QueryReceivedCallback( CNcdQuery* /*aQuery*/ ) |
|
355 { |
|
356 DLTRACEIN( ( "" ) ); |
|
357 DLTRACEOUT( ( "" ) ); |
|
358 } |
|
359 |
|
360 |
|
361 // --------------------------------------------------------------------------- |
|
362 // Handle operation complete |
|
363 // --------------------------------------------------------------------------- |
|
364 // |
|
365 void CNcdFileDownloadOperationProxy::CompleteCallback( TInt aError ) |
|
366 { |
|
367 AddRef(); |
|
368 DLTRACEIN( ( "Error: %d", aError ) ); |
|
369 iIsPaused = EFalse; |
|
370 |
|
371 if ( iObserver ) |
|
372 { |
|
373 iObserver->OperationComplete( *this, aError ); |
|
374 } |
|
375 |
|
376 Release(); |
|
377 DLTRACEOUT( ( "" ) ); |
|
378 } |
|
379 |
|
380 |
|
381 // --------------------------------------------------------------------------- |
|
382 // Create initialization data sent to the server-side |
|
383 // --------------------------------------------------------------------------- |
|
384 // |
|
385 HBufC8* CNcdFileDownloadOperationProxy::CreateInitializationBufferL() |
|
386 { |
|
387 DLTRACEIN( ( "" ) ); |
|
388 DASSERT( iTargetFilename ); |
|
389 |
|
390 HBufC8* buf = HBufC8::NewLC( 2 * KMaxPath ); |
|
391 |
|
392 TPtr8 ptr( buf->Des() ); |
|
393 RDesWriteStream stream( ptr ); |
|
394 CleanupClosePushL( stream ); |
|
395 ExternalizeDesL( *iTargetFilename, stream ); |
|
396 CleanupStack::PopAndDestroy( &stream ); |
|
397 CleanupStack::Pop( buf ); |
|
398 return buf; |
|
399 } |
|
400 |
|
401 |
|
402 // --------------------------------------------------------------------------- |
|
403 // Handle initialization callback |
|
404 // --------------------------------------------------------------------------- |
|
405 // |
|
406 void CNcdFileDownloadOperationProxy::InitializationCallback( |
|
407 RReadStream& /* aReadStream */, TInt /* aDataLength */ ) |
|
408 { |
|
409 DLTRACEIN( ( "" ) ); |
|
410 } |
|
411 |
|
412 |
|
413 |