|
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: Harvester utility implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <e32base.h> |
|
20 #include <f32file.h> |
|
21 #include <mpxharvesterserverdefs.h> |
|
22 #include <mpxcmn.h> |
|
23 |
|
24 #include <mpxmedia.h> |
|
25 #include <mpxmediageneraldefs.h> |
|
26 #include <mpxcollectionpath.h> |
|
27 #include <mpxlog.h> |
|
28 #include "mpxharvesterutilityobserver.h" |
|
29 #include "mpxharvesterutilityimp.h" |
|
30 |
|
31 |
|
32 const TInt KMaxPlaylistExtensionLength = 10; |
|
33 |
|
34 // ======== MEMBER FUNCTIONS ======== |
|
35 |
|
36 // --------------------------------------------------------------------------- |
|
37 // Private Constructor |
|
38 // --------------------------------------------------------------------------- |
|
39 // |
|
40 CMPXHarvesterUtilityImp::CMPXHarvesterUtilityImp() : CActive( EPriorityNormal ), |
|
41 iCurAsyncOp( EHvsServerOpCount ) |
|
42 { |
|
43 CActiveScheduler::Add( this ); |
|
44 } |
|
45 |
|
46 |
|
47 // --------------------------------------------------------------------------- |
|
48 // 2nd-Phased Constructor |
|
49 // --------------------------------------------------------------------------- |
|
50 // |
|
51 void CMPXHarvesterUtilityImp::ConstructL() |
|
52 { |
|
53 TInt err = iSession.Connect(KMPXHarvesterServerName, |
|
54 KMPXHarvesterServerImg, |
|
55 TVersion(KMPXHarvesterServerMajorVersionNumber, |
|
56 KMPXHarvesterServerMinorVersionNumber, |
|
57 KMPXHarvesterServerBuildVersionNumber)); |
|
58 User::LeaveIfError( err ); |
|
59 } |
|
60 |
|
61 // --------------------------------------------------------------------------- |
|
62 // Two-Phased Constructor |
|
63 // --------------------------------------------------------------------------- |
|
64 // |
|
65 CMPXHarvesterUtilityImp* CMPXHarvesterUtilityImp::NewL() |
|
66 { |
|
67 CMPXHarvesterUtilityImp* self = new( ELeave ) CMPXHarvesterUtilityImp(); |
|
68 CleanupStack::PushL( self ); |
|
69 self->ConstructL(); |
|
70 CleanupStack::Pop( self ); |
|
71 return self; |
|
72 } |
|
73 |
|
74 // --------------------------------------------------------------------------- |
|
75 // Virtual Destructor |
|
76 // --------------------------------------------------------------------------- |
|
77 // |
|
78 CMPXHarvesterUtilityImp::~CMPXHarvesterUtilityImp() |
|
79 { |
|
80 Cancel(); |
|
81 |
|
82 delete iBuffer; |
|
83 iSession.Close(); |
|
84 delete iCurTask; |
|
85 delete iFile; |
|
86 } |
|
87 |
|
88 // --------------------------------------------------------------------------- |
|
89 // Scan Function |
|
90 // --------------------------------------------------------------------------- |
|
91 // |
|
92 void CMPXHarvesterUtilityImp::ScanL() |
|
93 { |
|
94 iSession.SendReceiveL( EHvsServerScan ); |
|
95 } |
|
96 |
|
97 // --------------------------------------------------------------------------- |
|
98 // Cancel Scan Function |
|
99 // --------------------------------------------------------------------------- |
|
100 // |
|
101 void CMPXHarvesterUtilityImp::CancelScanL() |
|
102 { |
|
103 iSession.SendReceiveL( EHvsServerCancelScan ); |
|
104 } |
|
105 |
|
106 // --------------------------------------------------------------------------- |
|
107 // Shut down the server function |
|
108 // --------------------------------------------------------------------------- |
|
109 // |
|
110 void CMPXHarvesterUtilityImp::ShutdownL() |
|
111 { |
|
112 iSession.SendReceiveL( EHvsServerShutdown ); |
|
113 } |
|
114 |
|
115 // --------------------------------------------------------------------------- |
|
116 // Add a song to the harvester |
|
117 // --------------------------------------------------------------------------- |
|
118 // |
|
119 void CMPXHarvesterUtilityImp::AddFileL( const TDesC& aFilePath, |
|
120 MMPXHarvesterUtilityObserver* aObs ) |
|
121 { |
|
122 ASSERT( !iCurTask ); |
|
123 HBufC* path = aFilePath.AllocLC(); |
|
124 iCurTask = new(ELeave) CHvsUtilityTask( NULL, path, |
|
125 NULL, NULL ); |
|
126 CleanupStack::Pop( path ); |
|
127 iSession.SendReceive( EHvsServerAddFile, TIpcArgs( &iCurTask->Arg2() ), iStatus ); |
|
128 |
|
129 // Set Async op |
|
130 iCurAsyncOp = EHvsServerAddFile; |
|
131 iObserver = aObs; |
|
132 SetActive(); |
|
133 } |
|
134 |
|
135 // --------------------------------------------------------------------------- |
|
136 // Add a song to the harvester |
|
137 // --------------------------------------------------------------------------- |
|
138 // |
|
139 TInt CMPXHarvesterUtilityImp::AddFileL( CMPXMedia*& aProperty ) |
|
140 { |
|
141 CBufBase* buf( NULL ); |
|
142 CreateBufferL<CMPXMedia>( *aProperty, buf ); |
|
143 CleanupStack::PushL( buf ); |
|
144 TPtr8 p = buf->Ptr(0); |
|
145 TInt r = iSession.SendReceiveL( EHvsServerAddFileMedia, TIpcArgs( &p ) ); |
|
146 CleanupStack::PopAndDestroy( buf ); |
|
147 return r; |
|
148 } |
|
149 |
|
150 // --------------------------------------------------------------------------- |
|
151 // Remove a song from the harvester |
|
152 // --------------------------------------------------------------------------- |
|
153 // |
|
154 TInt CMPXHarvesterUtilityImp::RemoveFileL( const TDesC& aFilePath ) |
|
155 { |
|
156 TPckgBuf<TInt> del(EFalse); |
|
157 return iSession.SendReceiveL( EHvsServerRemoveFile, TIpcArgs( &aFilePath, |
|
158 &del ) ); |
|
159 } |
|
160 |
|
161 // --------------------------------------------------------------------------- |
|
162 // Remove multiple songs from the harvester |
|
163 // --------------------------------------------------------------------------- |
|
164 // |
|
165 void CMPXHarvesterUtilityImp::RemoveFilesL( const MDesCArray& aArray ) |
|
166 { |
|
167 CBufBase* buf( NULL ); |
|
168 MPXUser::CreateBufferL( &aArray, buf ); |
|
169 CleanupStack::PushL( buf ); |
|
170 // IPC args |
|
171 TPtr8 p=buf->Ptr(0); |
|
172 TPckgBuf<TInt> del(EFalse); |
|
173 iSession.SendReceiveL( EHvsServerRemoveFiles, |
|
174 TIpcArgs( &p, &del ) ); |
|
175 CleanupStack::PopAndDestroy( buf ); |
|
176 } |
|
177 |
|
178 // --------------------------------------------------------------------------- |
|
179 // Remove all songs from the harvester |
|
180 // --------------------------------------------------------------------------- |
|
181 // |
|
182 void CMPXHarvesterUtilityImp::RemoveAllFilesL() |
|
183 { |
|
184 iSession.SendReceiveL( EHvsServerRemoveAllFiles ); |
|
185 } |
|
186 |
|
187 // --------------------------------------------------------------------------- |
|
188 // Recreate the harvester database |
|
189 // --------------------------------------------------------------------------- |
|
190 // |
|
191 void CMPXHarvesterUtilityImp::RecreateDatabasesL() |
|
192 { |
|
193 iSession.SendReceiveL( EHvsServerReCreateDB ); |
|
194 } |
|
195 |
|
196 // --------------------------------------------------------------------------- |
|
197 // Remove a song and delete it from the file system |
|
198 // --------------------------------------------------------------------------- |
|
199 // |
|
200 void CMPXHarvesterUtilityImp::DeleteFileL( const TDesC& aFilePath, |
|
201 MMPXHarvesterUtilityObserver* aObs ) |
|
202 { |
|
203 ASSERT( !iCurTask ); |
|
204 |
|
205 HBufC* path = aFilePath.AllocLC(); |
|
206 iCurTask = new(ELeave) CHvsUtilityTask( NULL, path, |
|
207 NULL, ETrue ); |
|
208 CleanupStack::Pop( path ); |
|
209 |
|
210 iSession.SendReceive( EHvsServerRemoveFile, TIpcArgs( &iCurTask->Arg2(), |
|
211 &iCurTask->Arg4() ), iStatus ); |
|
212 |
|
213 // Set Async op |
|
214 iCurAsyncOp = EHvsServerRemoveFile; |
|
215 iObserver = aObs; |
|
216 SetActive(); |
|
217 } |
|
218 |
|
219 // --------------------------------------------------------------------------- |
|
220 // Remove and delete a list of files from the file system |
|
221 // --------------------------------------------------------------------------- |
|
222 // |
|
223 void CMPXHarvesterUtilityImp::DeleteFilesL( const MDesCArray& aArray, |
|
224 MMPXHarvesterUtilityObserver* aObs ) |
|
225 { |
|
226 ASSERT( !iCurTask ); |
|
227 |
|
228 CBufBase* buf( NULL ); |
|
229 MPXUser::CreateBufferL( &aArray, buf ); |
|
230 CleanupStack::PushL( buf ); |
|
231 iCurTask = new(ELeave) CHvsUtilityTask( buf, NULL, |
|
232 NULL, ETrue ); |
|
233 CleanupStack::Pop( buf ); |
|
234 |
|
235 iSession.SendReceive( EHvsServerRemoveFiles, |
|
236 TIpcArgs( &iCurTask->Arg1(), &iCurTask->Arg4() ), iStatus ); |
|
237 // Set Async op |
|
238 iCurAsyncOp = EHvsServerRemoveFiles; |
|
239 iObserver = aObs; |
|
240 SetActive(); |
|
241 } |
|
242 |
|
243 // --------------------------------------------------------------------------- |
|
244 // Remove and delete a list of files from the file system |
|
245 // --------------------------------------------------------------------------- |
|
246 // |
|
247 void CMPXHarvesterUtilityImp::DeleteFilesL( const MDesCArray& aArray ) |
|
248 { |
|
249 DeleteFilesL( aArray, ETrue ); |
|
250 } |
|
251 |
|
252 // --------------------------------------------------------------------------- |
|
253 // Remove and delete a list of files from the file system |
|
254 // --------------------------------------------------------------------------- |
|
255 // |
|
256 void CMPXHarvesterUtilityImp::DeleteFilesL( const MDesCArray& aArray, TBool aEndTransaction ) |
|
257 { |
|
258 CBufBase* buf( NULL ); |
|
259 MPXUser::CreateBufferL( &aArray, buf ); |
|
260 CleanupStack::PushL( buf ); |
|
261 // IPC args |
|
262 TPtr8 p=buf->Ptr(0); |
|
263 TPckgBuf<TInt> del(ETrue); |
|
264 TPckgBuf<TInt> transaction(aEndTransaction); |
|
265 iSession.SendReceiveL( EHvsServerRemoveFiles, |
|
266 TIpcArgs( &p, &del , &transaction ) ); |
|
267 CleanupStack::PopAndDestroy( buf ); |
|
268 } |
|
269 |
|
270 // --------------------------------------------------------------------------- |
|
271 // Close the database transaction |
|
272 // --------------------------------------------------------------------------- |
|
273 // |
|
274 void CMPXHarvesterUtilityImp::CloseTransactionL() |
|
275 { |
|
276 iSession.SendReceiveL( EHvsServerCloseTransaction ); |
|
277 } |
|
278 |
|
279 // --------------------------------------------------------------------------- |
|
280 // Remove and delete a file from the file system |
|
281 // --------------------------------------------------------------------------- |
|
282 // |
|
283 void CMPXHarvesterUtilityImp::UpdateFileL( CMPXMedia*& aProperty ) |
|
284 { |
|
285 TMPXAttribute att( KMPXMediaIdGeneral, EMPXMediaGeneralUri ); |
|
286 const TDesC& filepath = aProperty->ValueText( att ); |
|
287 |
|
288 att = TMPXAttribute( KMPXMediaIdGeneral, EMPXMediaGeneralCollectionId ); |
|
289 const TUid& collection = aProperty->ValueTObjectL<TUid>( att ); |
|
290 |
|
291 TPckgBuf<TInt> arg2( collection.iUid ); |
|
292 iSession.SendReceiveL( EHvsServerUpdateFile, TIpcArgs(&filepath, &arg2) ); |
|
293 } |
|
294 |
|
295 // --------------------------------------------------------------------------- |
|
296 // Rename file for the media |
|
297 // --------------------------------------------------------------------------- |
|
298 // |
|
299 HBufC* CMPXHarvesterUtilityImp::RenameFileLC( const CMPXMedia& aMedia ) |
|
300 { |
|
301 TMPXGeneralCategory category = |
|
302 aMedia.ValueTObjectL<TMPXGeneralCategory>( |
|
303 TMPXAttribute(KMPXMediaIdGeneral,EMPXMediaGeneralCategory)); |
|
304 if ( category != EMPXPlaylist ) |
|
305 { |
|
306 User::Leave( KErrNotSupported ); |
|
307 } |
|
308 |
|
309 const TDesC& title = |
|
310 aMedia.ValueText( |
|
311 TMPXAttribute( KMPXMediaIdGeneral, EMPXMediaGeneralTitle ) ); |
|
312 |
|
313 const TDesC& oldPath = |
|
314 aMedia.ValueText( |
|
315 TMPXAttribute( KMPXMediaIdGeneral, EMPXMediaGeneralUri ) ); |
|
316 |
|
317 // determine the new file path from the existing file path and the given title |
|
318 TParsePtrC parser( oldPath ); |
|
319 HBufC* newPath = HBufC::NewLC( parser.DriveAndPath().Length() + |
|
320 title.Length() + parser.Ext().Length() ); |
|
321 TPtr ptr = newPath->Des(); |
|
322 ptr.Append( parser.DriveAndPath() ); |
|
323 ptr.Append( title ); |
|
324 ptr.Append( parser.Ext() ); |
|
325 |
|
326 // get collection Id |
|
327 const TUid& collection = |
|
328 aMedia.ValueTObjectL<TUid>(TMPXAttribute(KMPXMediaIdGeneral,EMPXMediaGeneralCollectionId)); |
|
329 |
|
330 RenameFileL(oldPath, *newPath, collection.iUid); |
|
331 |
|
332 return newPath; |
|
333 } |
|
334 |
|
335 // --------------------------------------------------------------------------- |
|
336 // Rename file |
|
337 // --------------------------------------------------------------------------- |
|
338 // |
|
339 void CMPXHarvesterUtilityImp::RenameFileL( const TDesC& aOldUri, |
|
340 const TDesC& aNewUri, |
|
341 TInt aCollection ) |
|
342 { |
|
343 TPckgBuf<TInt> collectionId( aCollection ); |
|
344 |
|
345 iSession.SendReceiveL( EHvsServerRenameFile, TIpcArgs(&aOldUri, &aNewUri, &collectionId) ); |
|
346 } |
|
347 |
|
348 // --------------------------------------------------------------------------- |
|
349 // Find the collection ID for a file |
|
350 // --------------------------------------------------------------------------- |
|
351 // |
|
352 TInt CMPXHarvesterUtilityImp::FindCollectionIdL( const TDesC& aFile ) |
|
353 { |
|
354 return iSession.SendReceiveL( EHvsServerFindColID, TIpcArgs(&aFile) ); |
|
355 } |
|
356 |
|
357 // --------------------------------------------------------------------------- |
|
358 // Query the required attributes for tracks for the specified playlist type |
|
359 // --------------------------------------------------------------------------- |
|
360 // |
|
361 void CMPXHarvesterUtilityImp::RequiredAttributesL(TInt aPlaylistType, |
|
362 RArray<TMPXAttribute>& aRequiredAttributes) |
|
363 { |
|
364 TPckgBuf<TInt> playlistType( aPlaylistType ); |
|
365 |
|
366 TInt size = iSession.SendReceiveL( EHvsServerReqAttr, TIpcArgs( &playlistType) ); |
|
367 |
|
368 // Transfer results from server |
|
369 // lint doesn't understand the template ::CreateBuffer |
|
370 // |
|
371 ::TransferBufferFromServerL( iSession, EHvsServerGetBuffer, size, iBuffer ); |
|
372 ::CreateFromBufferL<TMPXAttribute>( *iBuffer, aRequiredAttributes ); //lint !e1024 !e1703 !e1514 !e64 |
|
373 } |
|
374 |
|
375 // --------------------------------------------------------------------------- |
|
376 // Query the optional attributes for tracks for the specified playlist type |
|
377 // --------------------------------------------------------------------------- |
|
378 // |
|
379 void CMPXHarvesterUtilityImp::OptionalAttributesL(TInt aPlaylistType, |
|
380 RArray<TMPXAttribute>& aOptionalAttributes) |
|
381 { |
|
382 TPckgBuf<TInt> playlistType( aPlaylistType ); |
|
383 |
|
384 TInt size = iSession.SendReceiveL( EHvsServerOptAttr, TIpcArgs( &playlistType) ); |
|
385 |
|
386 // Transfer results from server |
|
387 // |
|
388 ::TransferBufferFromServerL( iSession, EHvsServerGetBuffer, size, iBuffer ); |
|
389 ::CreateFromBufferL<TMPXAttribute>( *iBuffer, aOptionalAttributes ); //lint !e1024 !e1703 !e1514 !e64 |
|
390 } |
|
391 |
|
392 // --------------------------------------------------------------------------- |
|
393 // Queries about the playlist file extension of the currently selected playlist |
|
394 // plugin |
|
395 // --------------------------------------------------------------------------- |
|
396 HBufC* CMPXHarvesterUtilityImp::PlaylistFileExtensionLC(TInt aPlaylistType) |
|
397 { |
|
398 TPckgBuf<TInt> playlistType( aPlaylistType ); |
|
399 |
|
400 HBufC* fileExtension = HBufC::NewLC(KMaxPlaylistExtensionLength); |
|
401 TPtr extension = fileExtension->Des(); |
|
402 |
|
403 User::LeaveIfError( |
|
404 iSession.SendReceiveL( EHvsServerPlaylistFileExt, TIpcArgs(&playlistType, &extension))); |
|
405 |
|
406 return fileExtension; |
|
407 } |
|
408 |
|
409 // --------------------------------------------------------------------------- |
|
410 // Determines if the given file is a playlist |
|
411 // --------------------------------------------------------------------------- |
|
412 // |
|
413 TBool CMPXHarvesterUtilityImp::IsPlaylistL( const TDesC& aUri ) |
|
414 { |
|
415 return iSession.SendReceiveL( EHvsServerIsPlaylist, TIpcArgs(&aUri) ); |
|
416 } |
|
417 |
|
418 // --------------------------------------------------------------------------- |
|
419 // Tells the harvester to poll for system events |
|
420 // --------------------------------------------------------------------------- |
|
421 // |
|
422 void CMPXHarvesterUtilityImp::CheckForSystemEventsL() |
|
423 { |
|
424 User::LeaveIfError( iSession.SendReceiveL( EHvsServerCheckSystemEvent ) ); |
|
425 } |
|
426 |
|
427 |
|
428 // --------------------------------------------------------------------------- |
|
429 // Closes the harvester utility |
|
430 // --------------------------------------------------------------------------- |
|
431 // |
|
432 void CMPXHarvesterUtilityImp::Close() |
|
433 { |
|
434 delete this; |
|
435 } |
|
436 |
|
437 // --------------------------------------------------------------------------- |
|
438 // Get a media object for the file |
|
439 // --------------------------------------------------------------------------- |
|
440 // |
|
441 void CMPXHarvesterUtilityImp::GetMediaForFileL( const TDesC& aFilePath, |
|
442 MMPXHarvesterUtilityObserver* aObs ) |
|
443 { |
|
444 ASSERT( !iCurTask ); |
|
445 HBufC* path = aFilePath.AllocLC(); |
|
446 iCurTask = new(ELeave) CHvsUtilityTask( NULL, path, |
|
447 NULL, NULL ); |
|
448 CleanupStack::Pop( path ); |
|
449 iSession.SendReceive( EHvsServerGetMedia, TIpcArgs( &iCurTask->Arg2() ), iStatus ); |
|
450 |
|
451 // Set Async op |
|
452 iCurAsyncOp = EHvsServerGetMedia; |
|
453 iObserver = aObs; |
|
454 SetActive(); |
|
455 } |
|
456 |
|
457 // --------------------------------------------------------------------------- |
|
458 // Get a collection ID for the file |
|
459 // --------------------------------------------------------------------------- |
|
460 // |
|
461 TInt CMPXHarvesterUtilityImp::GetColUidForFileL( const TDesC& aFilePath ) |
|
462 { |
|
463 return iSession.SendReceiveL( EHvsServerGetColUid, TIpcArgs(&aFilePath) ); |
|
464 } |
|
465 |
|
466 // --------------------------------------------------------------------------- |
|
467 // Export a playlist to a file |
|
468 // --------------------------------------------------------------------------- |
|
469 // |
|
470 void CMPXHarvesterUtilityImp::ExportPlaylistL( const CMPXMedia& aProp, |
|
471 const TDesC& aPath, |
|
472 TInt aPlaylistType, |
|
473 MMPXHarvesterUtilityObserver* aObs ) |
|
474 { |
|
475 if( iCurAsyncOp != EHvsServerOpCount ) |
|
476 { |
|
477 User::Leave( KErrNotReady ); |
|
478 } |
|
479 |
|
480 // Construct the IPC Args |
|
481 CBufBase* buf( NULL ); |
|
482 CreateBufferL<CMPXMedia>( aProp, buf ); |
|
483 CleanupStack::PushL( buf ); |
|
484 HBufC* path = aPath.AllocLC(); |
|
485 CMPXMedia* copy = CMPXMedia::NewL( aProp ); |
|
486 CleanupStack::PushL( copy ); |
|
487 iCurTask = new(ELeave) CHvsUtilityTask( buf, path, |
|
488 NULL, aPlaylistType, copy ); // ownership xfer |
|
489 CleanupStack::Pop( 3, buf ); |
|
490 |
|
491 // Send the IPC |
|
492 // |
|
493 iSession.SendReceive( EHvsServerExportPlaylist, |
|
494 TIpcArgs( &iCurTask->Arg1(), &iCurTask->Arg2(), |
|
495 &iCurTask->Arg4() ), |
|
496 iStatus ); |
|
497 |
|
498 iCurAsyncOp = EHvsServerExportPlaylist; |
|
499 iObserver = aObs; |
|
500 SetActive(); |
|
501 } |
|
502 |
|
503 // --------------------------------------------------------------------------- |
|
504 // Import a playlist from a file |
|
505 // --------------------------------------------------------------------------- |
|
506 // |
|
507 void CMPXHarvesterUtilityImp::ImportPlaylistL( const TDesC& aFilename, |
|
508 MMPXHarvesterUtilityObserver* aObs ) |
|
509 { |
|
510 if( iCurAsyncOp != EHvsServerOpCount ) |
|
511 { |
|
512 User::Leave( KErrNotReady ); |
|
513 } |
|
514 |
|
515 HBufC* file = aFilename.AllocL(); |
|
516 iCurTask = new(ELeave) CHvsUtilityTask( NULL, file ); |
|
517 iSession.SendReceive( EHvsServerImportPlaylist, |
|
518 TIpcArgs( &iCurTask->Arg2() ), |
|
519 iStatus ); |
|
520 |
|
521 iCurAsyncOp = EHvsServerImportPlaylist; |
|
522 iObserver = aObs; |
|
523 SetActive(); |
|
524 } |
|
525 |
|
526 // --------------------------------------------------------------------------- |
|
527 // Import a file, async |
|
528 // --------------------------------------------------------------------------- |
|
529 // |
|
530 void CMPXHarvesterUtilityImp::ImportFileL( const TDesC& aFilename, |
|
531 MMPXHarvesterUtilityObserver* aObs ) |
|
532 { |
|
533 if( iCurAsyncOp != EHvsServerOpCount ) |
|
534 { |
|
535 User::Leave( KErrNotReady ); |
|
536 } |
|
537 if( iFile != NULL ) |
|
538 { |
|
539 delete iFile; |
|
540 iFile = NULL; |
|
541 } |
|
542 iFile = aFilename.AllocL(); |
|
543 HBufC* file = aFilename.AllocL(); |
|
544 iCurTask = new(ELeave) CHvsUtilityTask( NULL, file ); |
|
545 iSession.SendReceive( EHvsServerImportFile, |
|
546 TIpcArgs( iFile ), |
|
547 iStatus ); |
|
548 |
|
549 iCurAsyncOp = EHvsServerImportFile; |
|
550 iObserver = aObs; |
|
551 SetActive(); |
|
552 } |
|
553 |
|
554 // --------------------------------------------------------------------------- |
|
555 // RunL() from CActive |
|
556 // --------------------------------------------------------------------------- |
|
557 // |
|
558 void CMPXHarvesterUtilityImp::RunL() |
|
559 { |
|
560 // Try again in case server is down for IAD |
|
561 if (iStatus == KErrDied || iStatus == KErrServerTerminated) |
|
562 { |
|
563 MPX_DEBUG1("-->CMPXHarvesterUtilityImp::RunL Reconnecting session for IAD"); |
|
564 |
|
565 // attempt to bring the server back up |
|
566 if (iSession.Reconnect() != KErrNone) |
|
567 { |
|
568 MPX_DEBUG1("-->CMPXHarvesterUtilityImp::RunL Reconnect Failed"); |
|
569 } |
|
570 } |
|
571 |
|
572 // Clear status needs to be here because user can launch a second |
|
573 // async op within the callback! |
|
574 // |
|
575 delete iCurTask; |
|
576 iCurTask = NULL; |
|
577 |
|
578 // Cache these variables as locals because they need to be used |
|
579 // |
|
580 MMPXHarvesterUtilityObserver* curObserver = iObserver; |
|
581 iObserver = NULL; |
|
582 TInt curTask = iCurAsyncOp; |
|
583 iCurAsyncOp = EHvsServerOpCount; |
|
584 |
|
585 |
|
586 switch( curTask ) |
|
587 { |
|
588 case EHvsServerAddFile: |
|
589 { |
|
590 TInt size = iStatus.Int(); |
|
591 CMPXMedia* prop( NULL ); |
|
592 if( size > 0 ) |
|
593 { |
|
594 ::TransferBufferFromServerL(iSession, EHvsServerGetBuffer, |
|
595 size, iBuffer); |
|
596 ::NewFromBufferL<CMPXMedia>( *iBuffer, prop ); |
|
597 delete iBuffer; |
|
598 iBuffer = NULL; |
|
599 } |
|
600 curObserver->HandleFileAddCompletedL( prop, size<0?size:KErrNone ) ; |
|
601 break; |
|
602 } |
|
603 case EHvsServerRemoveFile: |
|
604 case EHvsServerRemoveFiles: // deliberate fall through |
|
605 { |
|
606 TInt err( iStatus.Int() ); |
|
607 curObserver->HandleDeleteCompletedL( err>0?KErrNone:err ); |
|
608 break; |
|
609 } |
|
610 case EHvsServerExportPlaylist: |
|
611 { |
|
612 TInt size = iStatus.Int(); |
|
613 CMPXMedia* prop( NULL ); |
|
614 if( size > 0 ) |
|
615 { |
|
616 ::TransferBufferFromServerL(iSession, EHvsServerGetBuffer, |
|
617 size, iBuffer); |
|
618 ::NewFromBufferL<CMPXMedia>( *iBuffer, prop ); |
|
619 delete iBuffer; |
|
620 iBuffer = NULL; |
|
621 } |
|
622 // observer takes ownership of prop |
|
623 curObserver->HandlePlaylistExportCompletedL( prop, size<0?size:KErrNone ); |
|
624 break; |
|
625 } |
|
626 case EHvsServerImportPlaylist: |
|
627 { |
|
628 TInt size = iStatus.Int(); |
|
629 CMPXMedia* prop(NULL); |
|
630 if( size > 0 ) |
|
631 { |
|
632 ::TransferBufferFromServerL(iSession, EHvsServerGetBuffer, |
|
633 size, iBuffer); |
|
634 ::NewFromBufferL<CMPXMedia>( *iBuffer, prop ); |
|
635 delete iBuffer; |
|
636 iBuffer = NULL; |
|
637 } |
|
638 curObserver->HandlePlaylistImportCompletedL( prop, |
|
639 size<0?size:KErrNone ); |
|
640 break; |
|
641 } |
|
642 case EHvsServerImportFile: |
|
643 { |
|
644 TInt size = iStatus.Int(); |
|
645 CMPXMedia* prop(NULL); |
|
646 if( size > 0 ) |
|
647 { |
|
648 ::TransferBufferFromServerL(iSession, EHvsServerGetBuffer, |
|
649 size, iBuffer); |
|
650 ::NewFromBufferL<CMPXMedia>( *iBuffer, prop ); |
|
651 delete iBuffer; |
|
652 iBuffer = NULL; |
|
653 } |
|
654 curObserver->HandleFileImportCompletedL( prop, size<0?size:KErrNone ); |
|
655 break; |
|
656 } |
|
657 case EHvsServerGetMedia: |
|
658 { |
|
659 TInt size = iStatus.Int(); |
|
660 CMPXMedia* prop( NULL ); |
|
661 if( size > 0 ) |
|
662 { |
|
663 ::TransferBufferFromServerL(iSession, EHvsServerGetBuffer, |
|
664 size, iBuffer); |
|
665 ::NewFromBufferL<CMPXMedia>( *iBuffer, prop ); |
|
666 delete iBuffer; |
|
667 iBuffer = NULL; |
|
668 } |
|
669 curObserver->HandleFileGetMediaCompletedL( prop, size<0?size:KErrNone ) ; |
|
670 break; |
|
671 } |
|
672 default: |
|
673 { |
|
674 ASSERT(0); |
|
675 } |
|
676 } |
|
677 } |
|
678 |
|
679 // --------------------------------------------------------------------------- |
|
680 // Cancels the current async op |
|
681 // --------------------------------------------------------------------------- |
|
682 // |
|
683 void CMPXHarvesterUtilityImp::DoCancel() |
|
684 { |
|
685 // Do Nothing |
|
686 } |
|
687 |
|
688 // ---------------------------------------------------------------------------- |
|
689 // Handles a leave occurring in the request completion event handler RunL() |
|
690 // ---------------------------------------------------------------------------- |
|
691 // |
|
692 TInt CMPXHarvesterUtilityImp::RunError(TInt aError) |
|
693 { |
|
694 MPX_DEBUG2("CMPXHarvesterUtilityImp::RunError(%d)", aError ); |
|
695 (void) aError; |
|
696 return KErrNone; |
|
697 } |
|
698 |
|
699 // --------------------------------------------------------------------------- |
|
700 // Utility class to cache async requests |
|
701 // --------------------------------------------------------------------------- |
|
702 // |
|
703 CMPXHarvesterUtilityImp::CHvsUtilityTask::CHvsUtilityTask( CBufBase* arg1, |
|
704 HBufC* arg2, |
|
705 HBufC* arg3, |
|
706 TInt arg4, |
|
707 CMPXMedia* arg5 ) |
|
708 { |
|
709 iArg1 = arg1; |
|
710 iArg2 = arg2; |
|
711 iArg3 = arg3; |
|
712 iArg4 = TPckgBuf<TInt>(arg4); |
|
713 iArg5 = arg5; |
|
714 |
|
715 if( iArg1 ) |
|
716 { |
|
717 iPtr1.Set(iArg1->Ptr(0)); |
|
718 } |
|
719 if( iArg2 ) |
|
720 { |
|
721 iPtr2.Set(iArg2->Des()); |
|
722 } |
|
723 if( iArg3 ) |
|
724 { |
|
725 iPtr3.Set(iArg3->Des()); |
|
726 } |
|
727 } |
|
728 |
|
729 // --------------------------------------------------------------------------- |
|
730 // Default destructor |
|
731 // --------------------------------------------------------------------------- |
|
732 // |
|
733 CMPXHarvesterUtilityImp::CHvsUtilityTask::~CHvsUtilityTask() |
|
734 { |
|
735 delete iArg1; |
|
736 delete iArg2; |
|
737 delete iArg3; |
|
738 delete iArg5; |
|
739 } |
|
740 |
|
741 // --------------------------------------------------------------------------- |
|
742 // Access each argument |
|
743 // --------------------------------------------------------------------------- |
|
744 // |
|
745 const TDesC8& CMPXHarvesterUtilityImp::CHvsUtilityTask::Arg1() |
|
746 { |
|
747 return iPtr1; |
|
748 } |
|
749 |
|
750 // --------------------------------------------------------------------------- |
|
751 // Access each argument |
|
752 // --------------------------------------------------------------------------- |
|
753 // |
|
754 const TDesC& CMPXHarvesterUtilityImp::CHvsUtilityTask::Arg2() |
|
755 { |
|
756 return iPtr2; |
|
757 } |
|
758 |
|
759 // --------------------------------------------------------------------------- |
|
760 // Access each argument |
|
761 // --------------------------------------------------------------------------- |
|
762 // |
|
763 const TDesC& CMPXHarvesterUtilityImp::CHvsUtilityTask::Arg3() |
|
764 { |
|
765 return iPtr3; |
|
766 } |
|
767 |
|
768 // --------------------------------------------------------------------------- |
|
769 // Access each argument |
|
770 // --------------------------------------------------------------------------- |
|
771 // |
|
772 const TDesC8& CMPXHarvesterUtilityImp::CHvsUtilityTask::Arg4() |
|
773 { |
|
774 return iArg4; |
|
775 } |
|
776 |
|
777 // --------------------------------------------------------------------------- |
|
778 // Access each argument |
|
779 // --------------------------------------------------------------------------- |
|
780 // |
|
781 const CMPXMedia& CMPXHarvesterUtilityImp::CHvsUtilityTask::Arg5() |
|
782 { |
|
783 return *iArg5; |
|
784 } |
|
785 |
|
786 // END OF FILE |