1 /* |
|
2 * Copyright (c) 2005-2007 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: Implementation of the class CUPnPAiwEngine. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 // System |
|
21 #include <bautils.h> |
|
22 #include <AknWaitDialog.h> |
|
23 #include <aknnotewrappers.h> |
|
24 #include <StringLoader.h> |
|
25 #include <utf.h> |
|
26 |
|
27 // Upnp stack |
|
28 #include <upnpitem.h> |
|
29 |
|
30 // avcontroller api |
|
31 #include "upnpavcontroller.h" |
|
32 #include "upnpavcontrollerfactory.h" |
|
33 #include "upnpavrenderingsession.h" |
|
34 #include "upnpavsessionbase.h" |
|
35 #include "upnpavdevice.h" |
|
36 |
|
37 // avcontroller / avcontroller helper api |
|
38 #include "upnpitemresolver.h" |
|
39 #include "upnpitemresolverfactory.h" |
|
40 #include "upnpitemutility.h" |
|
41 #include "upnpresourceselector.h" |
|
42 |
|
43 // upnpframework internal api's |
|
44 #include "upnpfiletransferengine.h" // Upnp Fw / UpnpFileTransferEngine |
|
45 #include "upnpcommonutils.h" // Upnp Fw / UpnpUtilities |
|
46 |
|
47 // aiw engine internal |
|
48 #include <upnpaiwengineresources.rsg> // Upnp Fw / UpnpAiwEngine |
|
49 #include "upnpaiwengine.h" // Upnp Fw / UpnpAiwEngine |
|
50 #include "upnpaiwtimer.h" // Upnp Fw / UpnpAiwEngine |
|
51 |
|
52 // logging |
|
53 _LIT( KComponentLogfile, "upnpaiwengine.log" ); |
|
54 #include "upnplog.h" |
|
55 |
|
56 const TInt KSlash = 92; |
|
57 const TInt KDot = 46; |
|
58 |
|
59 // CONSTANTS |
|
60 _LIT( KResFileName, "\\resource\\upnpaiwengineresources.rsc" ); |
|
61 const TInt KAiwTimerIntervalInSeconds = 1; |
|
62 |
|
63 // -------------------------------------------------------------------------- |
|
64 // CUPnPAiwEngine::NewL |
|
65 // NewL. |
|
66 // -------------------------------------------------------------------------- |
|
67 // |
|
68 EXPORT_C CUPnPAiwEngine* CUPnPAiwEngine::NewL() |
|
69 { |
|
70 __LOG( "[UpnpAiwEngine]\t CUPnPAiwEngine::NewL" ); |
|
71 |
|
72 CUPnPAiwEngine* self = NULL; |
|
73 |
|
74 // If this is the first time we are getting the instance of this |
|
75 // singleton class, create the instance and store it into the |
|
76 // Thread Local Storage |
|
77 if( !Dll::Tls() ) |
|
78 { |
|
79 self = new (ELeave) CUPnPAiwEngine; |
|
80 |
|
81 CleanupStack::PushL( self ); |
|
82 self->ConstructL(); |
|
83 CleanupStack::Pop( self ); |
|
84 |
|
85 TInt err = Dll::SetTls( static_cast<TAny*>( self ) ); |
|
86 if( err != KErrNone ) |
|
87 { |
|
88 delete self; |
|
89 self = NULL; |
|
90 } |
|
91 else |
|
92 { |
|
93 // Initialise the user counter to zero |
|
94 self->InitialiseUserCounter(); |
|
95 } |
|
96 } |
|
97 else |
|
98 { |
|
99 self = static_cast<CUPnPAiwEngine*>( Dll::Tls() ); |
|
100 } |
|
101 |
|
102 // Increase number of users by one |
|
103 self->IncreaseUserCounter(); |
|
104 return self; |
|
105 } |
|
106 |
|
107 // -------------------------------------------------------------------------- |
|
108 // CUPnPAiwEngine::ReleaseInstance |
|
109 // Releases the instance. |
|
110 // -------------------------------------------------------------------------- |
|
111 // |
|
112 EXPORT_C void CUPnPAiwEngine::ReleaseInstance() |
|
113 { |
|
114 __LOG( "[UpnpAiwEngine]\t CUPnPAiwEngine::ReleaseInstance" ); |
|
115 |
|
116 CUPnPAiwEngine* instance = NULL; |
|
117 |
|
118 // Get the instance from the TLS if there is an instance |
|
119 if( Dll::Tls() ) |
|
120 { |
|
121 instance = static_cast<CUPnPAiwEngine*>( Dll::Tls() ); |
|
122 } |
|
123 |
|
124 // If there still were an instance in the TLS |
|
125 if( instance ) |
|
126 { |
|
127 |
|
128 // Decrease the number of instance |
|
129 instance->DecreaseUserCounter(); |
|
130 |
|
131 // If the instance count is now 0, empty the TLS |
|
132 if( instance->UserCounter() <= 0 ) |
|
133 { |
|
134 // Empty the TLS |
|
135 TInt err = Dll::SetTls( NULL ); |
|
136 if( err ) |
|
137 { |
|
138 // ignore |
|
139 } |
|
140 |
|
141 // Delete the instance |
|
142 delete instance; |
|
143 instance = NULL; |
|
144 } |
|
145 } |
|
146 } |
|
147 |
|
148 // -------------------------------------------------------------------------- |
|
149 // Constructor |
|
150 // -------------------------------------------------------------------------- |
|
151 // |
|
152 CUPnPAiwEngine::CUPnPAiwEngine() |
|
153 { |
|
154 __LOG( "[UpnpAiwEngine]\t CUPnPAiwEngine::CUPnPAiwEngine" ); |
|
155 |
|
156 iRenderingSessionInUse = EFalse; |
|
157 iVideoPlay = EFalse; |
|
158 iFileName = NULL; |
|
159 iVideoPlayCancel = EFalse; |
|
160 iVideoPlayWait = EFalse; |
|
161 } |
|
162 |
|
163 // -------------------------------------------------------------------------- |
|
164 // Destructor |
|
165 // -------------------------------------------------------------------------- |
|
166 // |
|
167 CUPnPAiwEngine::~CUPnPAiwEngine() |
|
168 { |
|
169 __LOG( "[UpnpAiwEngine]\t CUPnPAiwEngine::~CUPnPAiwEngine" ); |
|
170 // Delete resolvers |
|
171 // Delete for resolvers is done using temporary variables so that we can |
|
172 // first nullify the members and then delete the actual objects. |
|
173 // This is because local resolver deletion uses active scheduler loops |
|
174 // and therefore other asynchronous events may orrur. So we may end |
|
175 // up here in Cleanup again, during the resolver is being deleted. |
|
176 // if deletion is done the conventional way, the objects get deleted |
|
177 // twice, which is not what we want. :-) |
|
178 MUPnPItemResolver* tempResolver = iResolver; |
|
179 iResolver = NULL; |
|
180 delete tempResolver; |
|
181 StopTimer(); |
|
182 |
|
183 // If wait note is shown, finish it |
|
184 if (iWaitNoteDialog) |
|
185 { |
|
186 TRAP_IGNORE( iWaitNoteDialog->ProcessFinishedL() ); |
|
187 } |
|
188 |
|
189 if (iRenderingSession && iAVController) |
|
190 { |
|
191 TRAP_IGNORE( iAVController->StopRenderingSession( |
|
192 *iRenderingSession ) ); |
|
193 iRenderingSession = NULL; |
|
194 } |
|
195 |
|
196 delete iCommonUI; |
|
197 |
|
198 // Delete the UPnP AV Controller |
|
199 delete iAVController; |
|
200 delete iFileName; |
|
201 |
|
202 // Un-load resource file |
|
203 if (iResFileOffset) |
|
204 { |
|
205 CEikonEnv::Static()->DeleteResourceFile(iResFileOffset); |
|
206 iResFileOffset = 0; |
|
207 } |
|
208 } |
|
209 |
|
210 // -------------------------------------------------------------------------- |
|
211 // CUPnPAiwEngine::ConstructL |
|
212 // Second phase constructor |
|
213 // -------------------------------------------------------------------------- |
|
214 // |
|
215 void CUPnPAiwEngine::ConstructL() |
|
216 { |
|
217 __LOG( "[UpnpAiwEngine]\t CUPnPAiwEngine::ConstructL" ); |
|
218 |
|
219 iCoeEnv = CEikonEnv::Static(); |
|
220 RFs& fileSession = iCoeEnv->FsSession(); |
|
221 |
|
222 // Load resource file |
|
223 TFileName rscFileName(KResFileName); |
|
224 TFileName dllName; |
|
225 Dll::FileName(dllName); |
|
226 TBuf<2> drive = dllName.Left(2); // Drive letter followed by ':' |
|
227 rscFileName.Insert( 0, drive); |
|
228 |
|
229 // Get the exact filename of the resource file |
|
230 BaflUtils::NearestLanguageFile(fileSession, rscFileName); |
|
231 |
|
232 // Check if the resource file exists or not |
|
233 if ( !BaflUtils::FileExists(fileSession, rscFileName) ) |
|
234 { |
|
235 __LOG( "[UpnpAiwEngine]\t CUPnPAiwEngine, resource file does not \ |
|
236 exist!" ); |
|
237 User::Leave(KErrNotFound); |
|
238 } |
|
239 |
|
240 if (iCoeEnv) |
|
241 { |
|
242 // Read the resource file offset |
|
243 iResFileOffset = iCoeEnv->AddResourceFileL(rscFileName); |
|
244 } |
|
245 |
|
246 // Set initial state of the connection to the UPnPAVController |
|
247 iCommonUI = CUPnPCommonUI::NewL(); |
|
248 iAVController = NULL; |
|
249 iRenderingSession = NULL; |
|
250 iEngineState = EUPnPEngineNotConnected; |
|
251 } |
|
252 |
|
253 // -------------------------------------------------------------------------- |
|
254 // CUPnPAiwEngine::SetEngineObserver |
|
255 // Sets the observer instance. |
|
256 // -------------------------------------------------------------------------- |
|
257 // |
|
258 EXPORT_C void CUPnPAiwEngine::SetEngineObserver( |
|
259 MUPnPAiwEngineObserver* aObserver ) |
|
260 { |
|
261 __LOG( "[UpnpAiwEngine]\t CUPnPAiwEngine::SetEngineObserver" ); |
|
262 |
|
263 if( aObserver ) |
|
264 { |
|
265 iObserver = aObserver; |
|
266 } |
|
267 } |
|
268 |
|
269 // -------------------------------------------------------------------------- |
|
270 // CUPnPAiwEngine::RemoveEngineObserver |
|
271 // Sets the observer instance. |
|
272 // -------------------------------------------------------------------------- |
|
273 // |
|
274 EXPORT_C void CUPnPAiwEngine::RemoveEngineObserver() |
|
275 { |
|
276 __LOG( "[UpnpAiwEngine]\t CUPnPAiwEngine::RemoveEngineObserver" ); |
|
277 |
|
278 iObserver = NULL; |
|
279 } |
|
280 |
|
281 // -------------------------------------------------------------------------- |
|
282 // CUPnPAiwEngine::EngineState |
|
283 // Gets the state of the UPnP AIW Engine. |
|
284 // -------------------------------------------------------------------------- |
|
285 // |
|
286 EXPORT_C TUPnPEngineState CUPnPAiwEngine::EngineState() |
|
287 { |
|
288 __LOG( "[UpnpAiwEngine]\t CUPnPAiwEngine::EngineState" ); |
|
289 |
|
290 return iEngineState; |
|
291 } |
|
292 |
|
293 // -------------------------------------------------------------------------- |
|
294 // CUPnPAiwEngine::OpenExternalMediaL |
|
295 // Opens the External media UI. |
|
296 // -------------------------------------------------------------------------- |
|
297 // |
|
298 EXPORT_C void CUPnPAiwEngine::OpenExternalMediaL() |
|
299 { |
|
300 __LOG( "[UpnpAiwEngine]\t CUPnPAiwEngine::OpenExternalMediaL" ); |
|
301 |
|
302 TInt status = KErrNone; |
|
303 |
|
304 if( !iAVController && |
|
305 iEngineState == EUPnPEngineNotConnected ) |
|
306 { |
|
307 TRAP( status, |
|
308 iAVController = |
|
309 UPnPAVControllerFactory::NewUPnPAVControllerL() ); |
|
310 |
|
311 if( status == KErrNone && |
|
312 iAVController ) |
|
313 { |
|
314 // Update engine state |
|
315 iEngineState = EUPnPEngineBrowsingHomeNetwork; |
|
316 TInt leaveCode = KErrNone; |
|
317 |
|
318 TRAP( leaveCode, |
|
319 status = iCommonUI->ExecuteDeviceDialogL( *iAVController ) ); |
|
320 |
|
321 // Handle status and leave codes |
|
322 if( leaveCode != KErrNone && |
|
323 status == KErrNone ) |
|
324 { |
|
325 status = leaveCode; |
|
326 } |
|
327 |
|
328 // Clean up and return the engine state |
|
329 delete iAVController; |
|
330 iAVController = NULL; |
|
331 iEngineState = EUPnPEngineNotConnected; |
|
332 } |
|
333 else // If the instantiation of UpnpAvController fails |
|
334 |
|
335 { |
|
336 TRAP_IGNORE( ShowConnectionErrorL() ); |
|
337 status = KErrCouldNotConnect; |
|
338 } |
|
339 } |
|
340 else // If the UpnpAvController is already instantiated |
|
341 |
|
342 { |
|
343 status = KErrInUse; |
|
344 } |
|
345 |
|
346 if( status != KErrNone ) |
|
347 { |
|
348 User::Leave( status ); |
|
349 } |
|
350 } |
|
351 |
|
352 // -------------------------------------------------------------------------- |
|
353 // CUPnPAiwEngine::EnableExternalL |
|
354 // Enables the showing of local media files on a remote renderer device. |
|
355 // -------------------------------------------------------------------------- |
|
356 // |
|
357 EXPORT_C void CUPnPAiwEngine::EnableExternalL() |
|
358 { |
|
359 __LOG( "[UpnpAiwEngine]\t CUPnPAiwEngine::EnableExternalL" ); |
|
360 |
|
361 TInt status = KErrNone; |
|
362 |
|
363 if( !iAVController && |
|
364 iEngineState == EUPnPEngineNotConnected ) |
|
365 { |
|
366 TRAP( status, |
|
367 iAVController = |
|
368 UPnPAVControllerFactory::NewUPnPAVControllerL() ); |
|
369 |
|
370 if( status == KErrNone && |
|
371 iAVController ) |
|
372 { |
|
373 iAVController->SetDeviceObserver( *this ); |
|
374 TRAP( status, StartRenderingSessionL( |
|
375 EUPnPAiwEngineTargetDeviceWithImageSupport ) ); |
|
376 |
|
377 // If the rendering session was created successfully |
|
378 if( status == KErrNone && |
|
379 iRenderingSession ) |
|
380 { |
|
381 // Start local file sharing |
|
382 TRAP( status, |
|
383 StartLocalFileSharingL( iRenderingSession ) ); |
|
384 { |
|
385 // If the file sharing failed to start, undo the enable |
|
386 // external by calling disable external. |
|
387 if( status != KErrNone ) |
|
388 { |
|
389 DisableExternal(); |
|
390 } |
|
391 } |
|
392 } |
|
393 else |
|
394 { |
|
395 delete iAVController; |
|
396 iAVController = NULL; |
|
397 iEngineState = EUPnPEngineNotConnected; |
|
398 } |
|
399 } |
|
400 else // If the instantiation of UpnpAvController fails |
|
401 |
|
402 { |
|
403 TRAP_IGNORE( ShowConnectionErrorL() ); |
|
404 status = KErrCouldNotConnect; |
|
405 } |
|
406 } |
|
407 else |
|
408 { |
|
409 status = KErrInUse; |
|
410 } |
|
411 |
|
412 if( status != KErrNone ) |
|
413 { |
|
414 User::Leave( status ); |
|
415 } |
|
416 } |
|
417 |
|
418 // -------------------------------------------------------------------------- |
|
419 // CUPnPAiwEngine::DisableExternal |
|
420 // Disables the showing of local media files on a remote renderer device. |
|
421 // -------------------------------------------------------------------------- |
|
422 // |
|
423 EXPORT_C void CUPnPAiwEngine::DisableExternal() |
|
424 { |
|
425 __LOG( "[UpnpAiwEngine]\t CUPnPAiwEngine::DisableExternal" ); |
|
426 |
|
427 if( iAVController ) |
|
428 { |
|
429 if( iRenderingSession ) |
|
430 { |
|
431 // If STOP action is required, use the timer to delay the |
|
432 // destruction (give some time for AvController to send the STOP |
|
433 // action message) |
|
434 if( iEngineState == EUPnPEngineActive ) |
|
435 { |
|
436 TRAP_IGNORE( iRenderingSession->StopL() ); |
|
437 StartTimer(); |
|
438 } |
|
439 else |
|
440 { |
|
441 // Stop local file sharing |
|
442 TRAP_IGNORE( iRenderingSession->ReleaseLocalMSServicesL() ); |
|
443 |
|
444 // Stop the rendering session |
|
445 TRAP_IGNORE( iAVController->StopRenderingSession( |
|
446 *iRenderingSession ) ); |
|
447 iRenderingSession = NULL; |
|
448 } |
|
449 } |
|
450 |
|
451 // Delete the UPnP AV Controller |
|
452 delete iAVController; |
|
453 iAVController = NULL; |
|
454 } |
|
455 |
|
456 // Update engine state |
|
457 iRenderingSessionInUse = EFalse; |
|
458 iEngineState = EUPnPEngineNotConnected; |
|
459 } |
|
460 |
|
461 // -------------------------------------------------------------------------- |
|
462 // CUPnPAiwEngine::PlayL |
|
463 // Plays (sends for rendering) local media file using the selected |
|
464 // UPnP Media renderer. |
|
465 // -------------------------------------------------------------------------- |
|
466 // |
|
467 EXPORT_C void CUPnPAiwEngine::PlayL( const TDesC& aFileName ) |
|
468 { |
|
469 __LOG( "[UpnpAiwEngine]\t CUPnPAiwEngine::PlayL" ); |
|
470 |
|
471 TInt status = KErrNone; |
|
472 |
|
473 if( aFileName != KNullDesC ) |
|
474 { |
|
475 |
|
476 if( iAVController && |
|
477 iRenderingSession && |
|
478 ( iEngineState == EUPnPEngineConnected || |
|
479 iEngineState == EUPnPEngineActive ) ) |
|
480 { |
|
481 |
|
482 // Check the file type |
|
483 TUPnPItemType fileType = ETypeOther; |
|
484 TRAPD( mimeError, |
|
485 fileType = UPnPCommonUtils::ResolveFileTypeL( |
|
486 aFileName ) ); |
|
487 if( mimeError == KErrNone ) |
|
488 { |
|
489 if( fileType == ETypeAudio ) |
|
490 { |
|
491 status = KErrNotSupported; |
|
492 if( iObserver ) |
|
493 { |
|
494 iObserver->PlayCompleteL( status ); |
|
495 } |
|
496 __LOG( "[UpnpAiwEngine]\t CUPnPAiwEngine, \ |
|
497 audio files not supported!" ); |
|
498 } |
|
499 else if ( fileType == ETypeVideo ) |
|
500 { |
|
501 if( iRenderingSessionInUse ) |
|
502 { |
|
503 //if the previous operation not finished |
|
504 delete iFileName; iFileName = NULL; |
|
505 iFileName = aFileName.AllocL(); |
|
506 iVideoPlayWait = ETrue; |
|
507 } |
|
508 else |
|
509 { |
|
510 TRAP( status, StartVideoPlayL( aFileName ) ); |
|
511 } |
|
512 } |
|
513 else if ( fileType == ETypeImage ) |
|
514 { |
|
515 if( !iVideoPlay ) //if no video is being played |
|
516 |
|
517 { |
|
518 if( iRenderingSessionInUse ) |
|
519 { |
|
520 //if the previous operation not finished |
|
521 iVideoPlayWait = EFalse; |
|
522 __LOG( "[UpnpAiwEngine]\t CUPnPAiwEngine, \ |
|
523 iRenderingSessionInUse: ETrue" ); |
|
524 delete iFileName; |
|
525 iFileName = NULL; |
|
526 iFileName = aFileName.AllocL(); |
|
527 } |
|
528 else |
|
529 { |
|
530 __LOG( "[UpnpAiwEngine]\t CUPnPAiwEngine, \ |
|
531 iRenderingSessionInUse: EFalse" ); |
|
532 TRAP( status , CreateUpnpItemAndSetUriL( aFileName ) ); |
|
533 if( KErrNone == status ) |
|
534 { |
|
535 iRenderingSessionInUse = ETrue; |
|
536 } |
|
537 else |
|
538 { |
|
539 // Failed, notify MG, the image playing is |
|
540 // complete |
|
541 if( iObserver ) |
|
542 { |
|
543 iObserver->PlayCompleteL( status ); |
|
544 } |
|
545 } |
|
546 } |
|
547 } |
|
548 else |
|
549 { |
|
550 //notify MG, the music playing is complete |
|
551 if( iObserver ) |
|
552 { |
|
553 iObserver->PlayCompleteL( status ); |
|
554 } |
|
555 } |
|
556 |
|
557 } |
|
558 else // Unsupported file |
|
559 |
|
560 { |
|
561 status = KErrNotSupported; |
|
562 } |
|
563 } |
|
564 else // Failed to resolve MIME type |
|
565 |
|
566 { |
|
567 status = KErrArgument; |
|
568 } |
|
569 } |
|
570 else // Rendering session not available (Enable External not done) |
|
571 |
|
572 { |
|
573 status = KErrNotReady; |
|
574 } |
|
575 } |
|
576 else |
|
577 { |
|
578 status = KErrArgument; |
|
579 } |
|
580 |
|
581 if( status != KErrNone ) |
|
582 { |
|
583 User::Leave( status ); |
|
584 } |
|
585 } |
|
586 |
|
587 // -------------------------------------------------------------------------- |
|
588 // CUPnPAiwEngine::CopyToExternalL |
|
589 // Copies local files to a remote media server. |
|
590 // -------------------------------------------------------------------------- |
|
591 // |
|
592 EXPORT_C void CUPnPAiwEngine::CopyToExternalL( |
|
593 RPointerArray<TDesC>& aFileNames ) |
|
594 { |
|
595 __LOG( "[UpnpAiwEngine]\t CUPnPAiwEngine::CopyToExternalL" ); |
|
596 |
|
597 // Check parameters |
|
598 if( aFileNames.Count() <= 0 ) |
|
599 { |
|
600 User::Leave( KErrArgument ); |
|
601 } |
|
602 |
|
603 // Check engine state |
|
604 if( iAVController ) |
|
605 { |
|
606 User::Leave( KErrInUse ); |
|
607 } |
|
608 |
|
609 // Create UPnPAVController |
|
610 TRAPD( avControllerError, |
|
611 iAVController = UPnPAVControllerFactory::NewUPnPAVControllerL() ); |
|
612 if( avControllerError != KErrNone ) |
|
613 { |
|
614 TRAP_IGNORE( ShowConnectionErrorL() ); |
|
615 User::Leave( KErrCouldNotConnect ); |
|
616 } |
|
617 |
|
618 // Update engine state |
|
619 iEngineState = EUPnPEngineConnected; |
|
620 |
|
621 // Do the transfer |
|
622 TRAPD( transferError, |
|
623 TransferToExternalL( EAiwEngineCopy, aFileNames, KNullDesC ) ); |
|
624 |
|
625 // Clean up |
|
626 delete iAVController; |
|
627 iAVController = NULL; |
|
628 |
|
629 // Update engine state |
|
630 iEngineState = EUPnPEngineNotConnected; |
|
631 |
|
632 if( transferError != KErrNone ) |
|
633 { |
|
634 User::Leave( transferError ); |
|
635 } |
|
636 } |
|
637 |
|
638 // -------------------------------------------------------------------------- |
|
639 // CUPnPAiwEngine::CopyToExternalL |
|
640 // Copies local files to a remote media server. |
|
641 // -------------------------------------------------------------------------- |
|
642 // |
|
643 EXPORT_C void CUPnPAiwEngine::CopyPlaylistToExternalL( |
|
644 const TDesC& aPlaylistName, |
|
645 RPointerArray<TDesC>& aFileNames ) |
|
646 { |
|
647 __LOG( "[UpnpAiwEngine]\t CUPnPAiwEngine::CopyPlaylistToExternalL" ); |
|
648 |
|
649 // Check parameters |
|
650 if( aFileNames.Count() <= 0 || |
|
651 aPlaylistName == KNullDesC ) |
|
652 { |
|
653 User::Leave( KErrArgument ); |
|
654 } |
|
655 |
|
656 // Check engine state |
|
657 if( iAVController ) |
|
658 { |
|
659 User::Leave( KErrInUse ); |
|
660 } |
|
661 |
|
662 // Create UPnPAVController |
|
663 TRAPD( avControllerError, |
|
664 iAVController = UPnPAVControllerFactory::NewUPnPAVControllerL() ); |
|
665 if( avControllerError != KErrNone ) |
|
666 { |
|
667 TRAP_IGNORE( ShowConnectionErrorL() ); |
|
668 User::Leave( KErrCouldNotConnect ); |
|
669 } |
|
670 |
|
671 // Update engine state |
|
672 iEngineState = EUPnPEngineConnected; |
|
673 |
|
674 // Do the transfer |
|
675 TRAPD( transferError, |
|
676 TransferToExternalL( EAiwEngineCopyPlaylist, |
|
677 aFileNames, |
|
678 aPlaylistName ) ); |
|
679 |
|
680 // Clean up |
|
681 delete iAVController; |
|
682 iAVController = NULL; |
|
683 |
|
684 // Update engine state |
|
685 iEngineState = EUPnPEngineNotConnected; |
|
686 |
|
687 if( transferError != KErrNone ) |
|
688 { |
|
689 User::Leave( transferError ); |
|
690 } |
|
691 } |
|
692 |
|
693 // -------------------------------------------------------------------------- |
|
694 // CUPnPAiwEngine::MoveToExternalL |
|
695 // Moves local files to a remote media server. |
|
696 // -------------------------------------------------------------------------- |
|
697 // |
|
698 EXPORT_C void CUPnPAiwEngine::MoveToExternalL( |
|
699 RPointerArray<TDesC>& aFileNames ) |
|
700 { |
|
701 __LOG( "[UpnpAiwEngine]\t CUPnPAiwEngine::MoveToExternalL" ); |
|
702 |
|
703 // Check parameters |
|
704 if( aFileNames.Count() <= 0 ) |
|
705 { |
|
706 User::Leave( KErrArgument ); |
|
707 } |
|
708 |
|
709 // Check engine state |
|
710 if( iAVController ) |
|
711 { |
|
712 User::Leave( KErrInUse ); |
|
713 } |
|
714 |
|
715 // Create UPnPAVController |
|
716 TRAPD( avControllerError, |
|
717 iAVController = UPnPAVControllerFactory::NewUPnPAVControllerL() ); |
|
718 if( avControllerError != KErrNone ) |
|
719 { |
|
720 TRAP_IGNORE( ShowConnectionErrorL() ); |
|
721 User::Leave( KErrCouldNotConnect ); |
|
722 } |
|
723 |
|
724 // Update engine state |
|
725 iEngineState = EUPnPEngineConnected; |
|
726 |
|
727 // Do the transfer |
|
728 TRAPD( transferError, |
|
729 TransferToExternalL( EAiwEngineMove, aFileNames, KNullDesC ) ); |
|
730 |
|
731 // Clean up |
|
732 delete iAVController; |
|
733 iAVController = NULL; |
|
734 |
|
735 // Update engine state |
|
736 iEngineState = EUPnPEngineNotConnected; |
|
737 |
|
738 if( transferError != KErrNone ) |
|
739 { |
|
740 User::Leave( transferError ); |
|
741 } |
|
742 } |
|
743 |
|
744 // -------------------------------------------------------------------------- |
|
745 // CUPnPAiwEngine::TransferToExternalL |
|
746 // Transfers (copies/moves) local files/playlists to a remote media server. |
|
747 // -------------------------------------------------------------------------- |
|
748 // |
|
749 void CUPnPAiwEngine::TransferToExternalL(TUPnPAiwEngineTransferMode aMode, |
|
750 RPointerArray<TDesC>& aFilePaths, const TDesC& aPlaylistName) |
|
751 { |
|
752 __LOG( "[UpnpAiwEngine]\t CUPnPAiwEngine::TransferToExternalL" ); |
|
753 |
|
754 // Parameters were already checked |
|
755 |
|
756 // Select the target server device |
|
757 // Title should be according to ui spec. |
|
758 TUPnPDialogTitle title = EUPnPCopyToTitle; |
|
759 if (aMode == EAiwEngineMove) |
|
760 { |
|
761 title = EUPnPMoveToTitle; |
|
762 } |
|
763 CUpnpAVDevice* targetDevice = SelectDeviceL( |
|
764 EUPnPSearchServerDevicesWithCopyCapability, title); |
|
765 |
|
766 CleanupStack::PushL(targetDevice); |
|
767 |
|
768 // Create a browsing session |
|
769 TInt status = KErrNone; |
|
770 MUPnPAVBrowsingSession* browsingSession= NULL; |
|
771 TRAP( status, browsingSession = |
|
772 &iAVController->StartBrowsingSessionL( *targetDevice ) ); |
|
773 |
|
774 if (status == KErrNone && browsingSession) |
|
775 { |
|
776 // Create a file transfer engine instance |
|
777 CUpnpFileTransferEngine* ftEngine= NULL; |
|
778 TRAP( status, |
|
779 ftEngine = CUpnpFileTransferEngine::NewL( browsingSession ) ); |
|
780 if ( status == KErrNone && ftEngine ) |
|
781 { |
|
782 CleanupStack::PushL( ftEngine ); |
|
783 |
|
784 // Update engine state |
|
785 iEngineState = EUPnPEngineActive; |
|
786 |
|
787 // Number of files in the array. |
|
788 TInt count = aFilePaths.Count(); |
|
789 |
|
790 // Do the copy/move |
|
791 if ( aMode == EAiwEngineMove ) |
|
792 { |
|
793 TRAP( status, ftEngine->MoveLocalFilesToRemoteServerL( |
|
794 &aFilePaths ) ); |
|
795 } |
|
796 else if ( aMode == EAiwEngineCopyPlaylist) |
|
797 { |
|
798 TRAP( status, ftEngine->CopyLocalPlaylistToRemoteServerL( |
|
799 aPlaylistName, |
|
800 &aFilePaths ) ); |
|
801 } |
|
802 else |
|
803 { |
|
804 TRAP( status, ftEngine->CopyLocalFilesToRemoteServerL( |
|
805 &aFilePaths ) ); |
|
806 } |
|
807 |
|
808 // Clean up |
|
809 // aFilePaths is not updates until ftEngine is deleted! |
|
810 CleanupStack::PopAndDestroy( ftEngine ); |
|
811 ftEngine = NULL; |
|
812 |
|
813 // Update engine state |
|
814 if ( status == KErrNone ) |
|
815 { |
|
816 iEngineState = EUPnPEngineConnected; |
|
817 |
|
818 // Shows proper info note. |
|
819 // |
|
820 // Calculate number of transferred files based on original |
|
821 // file count and items remaining in aFilePaths |
|
822 // (those were NOT transferred) |
|
823 ShowTransferInfoNoteL( |
|
824 aMode, |
|
825 count - aFilePaths.Count(), |
|
826 *targetDevice ); |
|
827 } |
|
828 else if (KErrSessionClosed == status || KErrCouldNotConnect == status |
|
829 || KErrDisconnected == status ) |
|
830 { |
|
831 iEngineState = EUPnPEngineConnectionLost; |
|
832 if ( aMode != EAiwEngineMove ) |
|
833 { |
|
834 ShowConnectionLostCopyErrorL(); |
|
835 } |
|
836 else |
|
837 { |
|
838 ShowConnectionErrorL(); |
|
839 } |
|
840 } |
|
841 else if ( KErrNotFound == status ) |
|
842 { |
|
843 ShowTransferInfoNoteL ( |
|
844 aMode, |
|
845 0, |
|
846 *targetDevice ); |
|
847 } |
|
848 else |
|
849 { |
|
850 iEngineState = EUPnPEngineConnected; |
|
851 } |
|
852 } |
|
853 |
|
854 // Stop browsing session |
|
855 iAVController->StopBrowsingSession( *browsingSession ); |
|
856 } |
|
857 |
|
858 // Clean up |
|
859 CleanupStack::PopAndDestroy( targetDevice ); |
|
860 targetDevice = NULL; |
|
861 |
|
862 // Get the titles (of the files that failed to be transfered) from |
|
863 // the item array and store them in the file name array. |
|
864 TChar slash( KSlash ); |
|
865 TChar dot( KDot ); |
|
866 TInt fileCount = aFilePaths.Count(); |
|
867 RPointerArray<TDesC16> fileTitles; |
|
868 for ( TInt index = 0; index < fileCount; index++ ) |
|
869 { |
|
870 TInt offset1 = aFilePaths[index]->LocateReverse( slash ); |
|
871 TInt offset2 = aFilePaths[index]->LocateReverse( dot ); |
|
872 |
|
873 HBufC16* fileTitle= NULL; |
|
874 |
|
875 if ( KErrNotFound != offset1 && KErrNotFound != offset2 && |
|
876 offset2 > ( offset1 + 1 ) ) |
|
877 { |
|
878 |
|
879 fileTitle = aFilePaths[index]-> |
|
880 Mid( ( offset1 + 1 ), ( offset2 - offset1 - 1 ) ).Alloc(); |
|
881 |
|
882 } |
|
883 if (fileTitle) |
|
884 { |
|
885 fileTitles.AppendL(fileTitle); |
|
886 } |
|
887 } |
|
888 aFilePaths.ResetAndDestroy(); |
|
889 for (TInt index = 0; index < fileTitles.Count(); index++) |
|
890 { |
|
891 aFilePaths.AppendL(fileTitles[index]); |
|
892 } |
|
893 |
|
894 fileTitles.Reset(); |
|
895 fileTitles.Close(); |
|
896 |
|
897 if (status != KErrNone) |
|
898 { |
|
899 User::Leave(status); |
|
900 } |
|
901 } |
|
902 |
|
903 // -------------------------------------------------------------------------- |
|
904 // CUPnPAiwEngine::StartRenderingSessionL |
|
905 // Starts a rendering session with UpnpAvController. Queries the target |
|
906 // rendering device. |
|
907 // -------------------------------------------------------------------------- |
|
908 // |
|
909 void CUPnPAiwEngine::StartRenderingSessionL(TUPnPAiwEngineDeviceType aType) |
|
910 { |
|
911 __LOG( "[UpnpAiwEngine]\t CUPnPAiwEngine::StartRenderingSessionL" ); |
|
912 |
|
913 TInt status = KErrNone; |
|
914 |
|
915 if (iAVController) |
|
916 { |
|
917 if ( !iRenderingSession) |
|
918 { |
|
919 CUpnpAVDevice* tempDevice = CUpnpAVDevice::NewL(); |
|
920 CleanupStack::PushL(tempDevice); |
|
921 |
|
922 // Launch the device selection dialog |
|
923 |
|
924 if (aType == EUPnPAiwEngineTargetDeviceWithAudioSupport) |
|
925 { |
|
926 status = iCommonUI->SelectDeviceL( *iAVController, |
|
927 *tempDevice, |
|
928 EUPnPSearchRenderingDevicesWithAudioCapability, |
|
929 EUPnPSelectDeviceTitle); |
|
930 } |
|
931 else |
|
932 if (aType |
|
933 == EUPnPAiwEngineTargetDeviceWithImageAndVideoSupport) |
|
934 { |
|
935 status = iCommonUI->SelectDeviceL( *iAVController, |
|
936 *tempDevice, |
|
937 EUPnPSearchRenderingDevicesWithVideoCapability, |
|
938 EUPnPSelectDeviceTitle); |
|
939 } |
|
940 else |
|
941 if (aType == EUPnPAiwEngineTargetDeviceWithImageSupport) |
|
942 { |
|
943 status |
|
944 = iCommonUI->SelectDeviceL( |
|
945 *iAVController, |
|
946 *tempDevice, |
|
947 EUPnPSearchRenderingDevicesWithImageCapability, |
|
948 EUPnPSelectDeviceTitle); |
|
949 } |
|
950 else |
|
951 { |
|
952 status = KErrNotSupported; |
|
953 } |
|
954 |
|
955 if (status == KErrNone) |
|
956 { |
|
957 // Create a rendering session and register to observe the |
|
958 // callbacks |
|
959 __LOG( "[UpnpAiwEngine]\t CUPnPAiwEngine, \ |
|
960 creating rendering session." ); |
|
961 iRenderingSession |
|
962 = &(iAVController->StartRenderingSessionL( *tempDevice) ); |
|
963 iRenderingSession->SetObserver( *this); |
|
964 __LOG( "[UpnpAiwEngine]\t CUPnPAiwEngine, \ |
|
965 rendering session created." ); |
|
966 |
|
967 // Update the engine state |
|
968 iEngineState = EUPnPEngineConnected; |
|
969 } |
|
970 |
|
971 // Clean up |
|
972 CleanupStack::PopAndDestroy(tempDevice); |
|
973 tempDevice = NULL; |
|
974 } |
|
975 else |
|
976 { |
|
977 status = KErrInUse; |
|
978 } |
|
979 } |
|
980 else |
|
981 { |
|
982 status = KErrNotReady; |
|
983 } |
|
984 |
|
985 if (status != KErrNone) |
|
986 { |
|
987 User::Leave(status); |
|
988 } |
|
989 } |
|
990 |
|
991 // -------------------------------------------------------------------------- |
|
992 // CUPnPAiwEngine::InteractOperationComplete |
|
993 // UPnP AV Controller calls this method to indicate that the requested |
|
994 // interaction operation (play, stop, etc.) is complete. |
|
995 // -------------------------------------------------------------------------- |
|
996 // |
|
997 void CUPnPAiwEngine::InteractOperationComplete(TInt aError, |
|
998 TUPnPAVInteractOperation aOperation) |
|
999 { |
|
1000 __LOG( "[UpnpAiwEngine]\t CUPnPAiwEngine::InteractOperationComplete" ); |
|
1001 |
|
1002 if (iObserver && !iVideoPlayCancel) |
|
1003 { |
|
1004 // If the play operation is complete (stop) or the play fails, do |
|
1005 // the call back |
|
1006 if (aOperation == EUPnPAVPlay || aOperation == EUPnPAVPlayUser |
|
1007 || aOperation == EUPnPAVStop || aOperation == EUPnPAVStopUser) |
|
1008 { |
|
1009 iEngineState = EUPnPEngineConnected; |
|
1010 TRAP_IGNORE( iObserver->PlayCompleteL( aError ) ); |
|
1011 } |
|
1012 } |
|
1013 if (aOperation == EUPnPAVPlay || aOperation == EUPnPAVStop) |
|
1014 { |
|
1015 iRenderingSessionInUse = EFalse; |
|
1016 if (iFileName) // If there is a pending item |
|
1017 { |
|
1018 __LOG( "[UpnpAiwEngine]\t CUPnPAiwEngine, pending item" ); |
|
1019 TRAP_IGNORE( InitPlayL() ); |
|
1020 delete iFileName; |
|
1021 iFileName = NULL; |
|
1022 iVideoPlayCancel = EFalse; // No need to send StopL |
|
1023 } |
|
1024 else |
|
1025 { |
|
1026 __LOG( "[UpnpAiwEngine]\t CUPnPAiwEngine, no pending item" ); |
|
1027 |
|
1028 if (iVideoPlayCancel) |
|
1029 { |
|
1030 __LOG( "[UpnpAiwEngine]\t CUPnPAiwEngine, stop previous \ |
|
1031 video item," ); |
|
1032 iRenderingSessionInUse = ETrue; |
|
1033 TRAP_IGNORE( iRenderingSession->StopL() ); |
|
1034 iVideoPlayCancel = EFalse; //StopL sent |
|
1035 } |
|
1036 } |
|
1037 } |
|
1038 } |
|
1039 |
|
1040 // -------------------------------------------------------------------------- |
|
1041 // CUPnPAiwEngine::SetURIResult |
|
1042 // UPnP AV Controller calls this method to indicate that ... |
|
1043 // -------------------------------------------------------------------------- |
|
1044 // |
|
1045 void CUPnPAiwEngine::SetURIResult(TInt aError) |
|
1046 { |
|
1047 __LOG( "[UpnpAiwEngine]\t CUPnPAiwEngine::SetURIResult" ); |
|
1048 |
|
1049 iRenderingSessionInUse = EFalse; |
|
1050 if (aError != KErrNone && iObserver && !iVideoPlayCancel) |
|
1051 { |
|
1052 TRAP_IGNORE( iObserver->PlayCompleteL( aError ) ); |
|
1053 } |
|
1054 else |
|
1055 if ( !iRenderingSession) |
|
1056 { |
|
1057 if (iObserver) |
|
1058 { |
|
1059 TRAP_IGNORE( iObserver->PlayCompleteL( KErrNotReady ) ); |
|
1060 } |
|
1061 } |
|
1062 |
|
1063 if (iFileName) //if there is a pending item |
|
1064 { |
|
1065 __LOG( "[UpnpAiwEngine]\t CUPnPAiwEngine, pending item" ); |
|
1066 TRAP_IGNORE( InitPlayL() ); |
|
1067 delete iFileName; |
|
1068 iFileName = NULL; |
|
1069 iVideoPlayCancel = EFalse; //no need to send StopL |
|
1070 } |
|
1071 else |
|
1072 if ( !iVideoPlayCancel) |
|
1073 { |
|
1074 __LOG( "[UpnpAiwEngine]\t CUPnPAiwEngine, no pending item" ); |
|
1075 __LOG( "[UpnpAiwEngine]\t CUPnPAiwEngine, no cancellation from \ |
|
1076 video play" ); |
|
1077 TRAP( aError, iRenderingSession->PlayL() ); |
|
1078 //if play failed, send the result right way |
|
1079 if (aError && iObserver) |
|
1080 { |
|
1081 TRAP_IGNORE( iObserver->PlayCompleteL( aError ) ); |
|
1082 } |
|
1083 else |
|
1084 if (KErrNone == aError) |
|
1085 { |
|
1086 iRenderingSessionInUse = ETrue; |
|
1087 } |
|
1088 } |
|
1089 else |
|
1090 if (iVideoPlayCancel) |
|
1091 { |
|
1092 __LOG( "[UpnpAiwEngine]\t CUPnPAiwEngine, no pending item" ); |
|
1093 __LOG( "[UpnpAiwEngine]\t CUPnPAiwEngine, stop previous \ |
|
1094 video item" ); |
|
1095 TRAP_IGNORE( iRenderingSession->StopL() ); |
|
1096 iRenderingSessionInUse = ETrue; |
|
1097 iVideoPlayCancel = EFalse; //StopL sent |
|
1098 } |
|
1099 } |
|
1100 |
|
1101 // -------------------------------------------------------------------------- |
|
1102 // CUPnPAiwEngine::ReleaseUpnpResourceL |
|
1103 // Release Upnp resouces |
|
1104 // -------------------------------------------------------------------------- |
|
1105 // |
|
1106 void CUPnPAiwEngine::ReleaseUpnpResourceL() |
|
1107 { |
|
1108 __LOG( "[UpnpAiwEngine]\t CUPnPAiwEngine::ReleaseUpnpResourceL" ); |
|
1109 |
|
1110 // Inform the client about the connection lost |
|
1111 if (iObserver) |
|
1112 { |
|
1113 iObserver->ConnectionLostL(); |
|
1114 } |
|
1115 |
|
1116 // Stop the rendering session |
|
1117 if ( iRenderingSession && iAVController ) |
|
1118 { |
|
1119 //iRenderingSession->ReleaseLocalMSServicesL(); |
|
1120 iRenderingSession->RemoveObserver(); |
|
1121 iAVController->StopRenderingSession( *iRenderingSession); |
|
1122 iRenderingSession = NULL; |
|
1123 } |
|
1124 |
|
1125 // Disconnect UPnPAVController |
|
1126 delete iAVController; |
|
1127 iAVController = NULL; |
|
1128 |
|
1129 iRenderingSessionInUse = EFalse; |
|
1130 // Update engine state |
|
1131 iEngineState = /*EUPnPEngineConnectionLost;*/EUPnPEngineNotConnected; |
|
1132 } |
|
1133 |
|
1134 // -------------------------------------------------------------------------- |
|
1135 // CUPnPAiwEngine::WLANConnectionLost |
|
1136 // UPnP AV Controller calls this method to indicate that ... |
|
1137 // -------------------------------------------------------------------------- |
|
1138 // |
|
1139 void CUPnPAiwEngine::WLANConnectionLost() |
|
1140 { |
|
1141 __LOG( "[UpnpAiwEngine]\t CUPnPAiwEngine::WLANConnectionLost" ); |
|
1142 |
|
1143 iFileSharingError = KErrDisconnected; |
|
1144 if ( iFileSharingActivationWaitNote ) |
|
1145 { |
|
1146 TRAP_IGNORE( iFileSharingActivationWaitNote->ProcessFinishedL() ); |
|
1147 } |
|
1148 TRAP_IGNORE( iCommonUI->DismissDialogL( KErrDisconnected ) ); |
|
1149 TRAP_IGNORE( ReleaseUpnpResourceL() ); |
|
1150 } |
|
1151 |
|
1152 // -------------------------------------------------------------------------- |
|
1153 // CUPnPAiwEngine::MediaRendererDisappeared |
|
1154 // Notifies that the Media Renderer we have a session with has disappeared. |
|
1155 // Session is now unusable and must be closed. |
|
1156 // -------------------------------------------------------------------------- |
|
1157 // |
|
1158 void CUPnPAiwEngine::MediaRendererDisappeared( |
|
1159 TUPnPDeviceDisconnectedReason aReason) |
|
1160 { |
|
1161 __LOG( "[UpnpAiwEngine]\t CUPnPAiwEngine::MediaRendererDisappeared" ); |
|
1162 |
|
1163 if (EDisconnected == aReason) |
|
1164 { |
|
1165 TRAP_IGNORE( ShowConnectionErrorL() ); |
|
1166 TRAP_IGNORE( ReleaseUpnpResourceL() ); |
|
1167 } |
|
1168 |
|
1169 } |
|
1170 |
|
1171 // -------------------------------------------------------------------------- |
|
1172 // CUPnPAiwEngine::InitialiseUserCounter |
|
1173 // Sets the initial value of the user counter to zero. |
|
1174 // -------------------------------------------------------------------------- |
|
1175 // |
|
1176 void CUPnPAiwEngine::InitialiseUserCounter() |
|
1177 { |
|
1178 iNumberOfUsers = 0; |
|
1179 } |
|
1180 |
|
1181 // -------------------------------------------------------------------------- |
|
1182 // CUPnPAiwEngine::IncreaseUserCounter |
|
1183 // Increases the value of the user counter by one. |
|
1184 // -------------------------------------------------------------------------- |
|
1185 // |
|
1186 void CUPnPAiwEngine::IncreaseUserCounter() |
|
1187 { |
|
1188 iNumberOfUsers++; |
|
1189 } |
|
1190 |
|
1191 // -------------------------------------------------------------------------- |
|
1192 // CUPnPAiwEngine::DecreaseUserCounter |
|
1193 // Decreases the value of the user counter by one. |
|
1194 // -------------------------------------------------------------------------- |
|
1195 // |
|
1196 void CUPnPAiwEngine::DecreaseUserCounter() |
|
1197 { |
|
1198 iNumberOfUsers--; |
|
1199 } |
|
1200 |
|
1201 // -------------------------------------------------------------------------- |
|
1202 // CUPnPAiwEngine::UserCounter |
|
1203 // Gets the value of the user counter. |
|
1204 // -------------------------------------------------------------------------- |
|
1205 // |
|
1206 TInt CUPnPAiwEngine::UserCounter() const |
|
1207 { |
|
1208 return iNumberOfUsers; |
|
1209 } |
|
1210 |
|
1211 // -------------------------------------------------------------------------- |
|
1212 // CUPnPAiwEngine::StartTimer() |
|
1213 // -------------------------------------------------------------------------- |
|
1214 // |
|
1215 void CUPnPAiwEngine::StartTimer() |
|
1216 { |
|
1217 // Stop the timer |
|
1218 StopTimer(); |
|
1219 |
|
1220 // Start the timer |
|
1221 __LOG( "[UpnpAiwEngine]\t CUPnPAiwEngine, starting timer" ); |
|
1222 TRAPD( err, |
|
1223 iUPnPAiwTimer = CUPnPAiwTimer::NewL( KAiwTimerIntervalInSeconds, |
|
1224 this ) ) |
|
1225 ; |
|
1226 if (err) |
|
1227 { |
|
1228 __LOG( "[UpnpAiwEngine]\t CUPnPAiwEngine, timer start failed!" ); |
|
1229 } |
|
1230 } |
|
1231 |
|
1232 // -------------------------------------------------------------------------- |
|
1233 // CUPnPAiwEngine::StopTimer() |
|
1234 // -------------------------------------------------------------------------- |
|
1235 // |
|
1236 void CUPnPAiwEngine::StopTimer() |
|
1237 { |
|
1238 // Stop the timer if it is running |
|
1239 if (iUPnPAiwTimer) |
|
1240 { |
|
1241 __LOG( "[UpnpAiwEngine]\t CUPnPAiwEngine, stopping timer" ); |
|
1242 delete iUPnPAiwTimer; |
|
1243 iUPnPAiwTimer = NULL; |
|
1244 } |
|
1245 } |
|
1246 |
|
1247 // -------------------------------------------------------------------------- |
|
1248 // CUPnPAiwEngine::TimerCallback |
|
1249 // Callback method for the UPnPAiWTimer. |
|
1250 // -------------------------------------------------------------------------- |
|
1251 // |
|
1252 EXPORT_C void CUPnPAiwEngine::TimerCallback() |
|
1253 { |
|
1254 StopTimer(); |
|
1255 if( iAVController ) |
|
1256 { |
|
1257 if( iRenderingSession ) |
|
1258 { |
|
1259 // Stop local file sharing |
|
1260 TRAP_IGNORE( iRenderingSession->ReleaseLocalMSServicesL() ); |
|
1261 |
|
1262 // Stop the rendering session |
|
1263 TRAP_IGNORE( iAVController->StopRenderingSession( |
|
1264 *iRenderingSession ) ); |
|
1265 iRenderingSession = NULL; |
|
1266 } |
|
1267 |
|
1268 // Disconnect UPnPAVController |
|
1269 delete iAVController; |
|
1270 iAVController = NULL; |
|
1271 |
|
1272 // Update engine state |
|
1273 iEngineState = EUPnPEngineNotConnected; |
|
1274 } |
|
1275 } |
|
1276 |
|
1277 // -------------------------------------------------------------------------- |
|
1278 // CUPnPAiwEngine::ShowConnectionErrorL() |
|
1279 // -------------------------------------------------------------------------- |
|
1280 // |
|
1281 EXPORT_C void CUPnPAiwEngine::ShowConnectionErrorL() |
|
1282 { |
|
1283 iCommonUI->DisplayConnectionErrorNoteL(); |
|
1284 } |
|
1285 |
|
1286 // -------------------------------------------------------------------------- |
|
1287 // CUPnPAiwEngine::ShowConnectionLostCopyErrorL() |
|
1288 // -------------------------------------------------------------------------- |
|
1289 // |
|
1290 void CUPnPAiwEngine::ShowConnectionLostCopyErrorL() |
|
1291 { |
|
1292 __LOG( "[UpnpAiwEngine]\t CUPnPAiwEngine::ShowConnectionLostErrorL" ); |
|
1293 iCommonUI->DisplayConnectionLostCopyErrorNoteL(); |
|
1294 } |
|
1295 |
|
1296 // -------------------------------------------------------------------------- |
|
1297 // CUPnPAiwEngine::ShowTransferInfoNoteL |
|
1298 // Show correct info note after file transfer is completed. |
|
1299 // -------------------------------------------------------------------------- |
|
1300 // |
|
1301 void CUPnPAiwEngine::ShowTransferInfoNoteL( |
|
1302 TUPnPAiwEngineTransferMode aMode, |
|
1303 TInt aCount, |
|
1304 const CUpnpAVDevice& aServerName ) const |
|
1305 { |
|
1306 __LOG( "[UpnpAiwEngine]\t CUPnPAiwEngine::ShowTransferInfoNoteL" ); |
|
1307 |
|
1308 // Converts device name into unicode string. |
|
1309 HBufC* deviceString = CnvUtfConverter::ConvertToUnicodeFromUtf8L( |
|
1310 aServerName.FriendlyName() ); |
|
1311 CleanupStack::PushL( deviceString ); |
|
1312 |
|
1313 HBufC* infoText= NULL; |
|
1314 if ( aCount == 1 ) |
|
1315 { |
|
1316 if ( aMode == EAiwEngineMove ) |
|
1317 { |
|
1318 // File moved. |
|
1319 infoText = StringLoader::LoadLC( |
|
1320 R_AIW_INFO_MOVE_EXT_ONE_TEXT, |
|
1321 *deviceString ); |
|
1322 } |
|
1323 else |
|
1324 { |
|
1325 // File copied. |
|
1326 infoText = StringLoader::LoadLC( |
|
1327 R_AIW_INFO_COPY_EXT_ONE_TEXT, |
|
1328 *deviceString ); |
|
1329 } |
|
1330 } |
|
1331 else |
|
1332 { |
|
1333 if ( aMode == EAiwEngineMove ) |
|
1334 { |
|
1335 // Files moved. |
|
1336 infoText = StringLoader::LoadLC( |
|
1337 R_AIW_INFO_MOVE_EXT_MANY_TEXT, |
|
1338 *deviceString, |
|
1339 aCount); |
|
1340 } |
|
1341 else |
|
1342 { |
|
1343 // Files copied. |
|
1344 infoText = StringLoader::LoadLC( |
|
1345 R_AIW_INFO_COPY_EXT_MANY_TEXT, |
|
1346 *deviceString, |
|
1347 aCount ); |
|
1348 } |
|
1349 } |
|
1350 |
|
1351 // Shows the dialog. |
|
1352 CAknInformationNote* infoNote = |
|
1353 new ( ELeave ) CAknInformationNote( ETrue ); |
|
1354 infoNote->ExecuteLD( *infoText ); |
|
1355 |
|
1356 CleanupStack::PopAndDestroy( infoText ); |
|
1357 CleanupStack::PopAndDestroy( deviceString ); |
|
1358 } |
|
1359 |
|
1360 // -------------------------------------------------------------------------- |
|
1361 // CUPnPAiwEngine::ReserveLocalMSServicesCompleted |
|
1362 // Notifies that the Media Server startup has completed. |
|
1363 // -------------------------------------------------------------------------- |
|
1364 // |
|
1365 void CUPnPAiwEngine::ReserveLocalMSServicesCompleted(TInt aError) |
|
1366 { |
|
1367 __LOG( "[UpnpAiwEngine]\t CUPnPAiwEngine::\ |
|
1368 ReserveLocalMSServicesCompleted" ); |
|
1369 |
|
1370 iFileSharingError = aError; |
|
1371 if (aError == KErrNone) |
|
1372 { |
|
1373 iLocalFileSharingActivated = ETrue; |
|
1374 } |
|
1375 if (iFileSharingActivationWaitNote) |
|
1376 { |
|
1377 TRAP_IGNORE( iFileSharingActivationWaitNote->ProcessFinishedL() ); |
|
1378 } |
|
1379 } |
|
1380 |
|
1381 // -------------------------------------------------------------------------- |
|
1382 // CUPnPAiwEngine::StartLocalFileSharingL |
|
1383 // Waits for local media server file sharing activation (or user cancel). |
|
1384 // -------------------------------------------------------------------------- |
|
1385 void CUPnPAiwEngine::StartLocalFileSharingL(MUPnPAVSessionBase *aSession) |
|
1386 { |
|
1387 __LOG( "[UpnpAiwEngine]\t CUPnPAiwEngine::StartLocalFileSharingL" ); |
|
1388 |
|
1389 // Leave if the parameter is not valid |
|
1390 if ( !aSession) |
|
1391 { |
|
1392 User::Leave(KErrArgument); |
|
1393 } |
|
1394 |
|
1395 // Initialize the sharing error variable |
|
1396 iFileSharingError = KErrNone; |
|
1397 iLocalFileSharingActivated = EFalse; |
|
1398 |
|
1399 // Start the local media server |
|
1400 aSession->ReserveLocalMSServicesL(); |
|
1401 |
|
1402 // Instantiate and launch the wait note until the sharing is |
|
1403 // enabled of user cancels the operation |
|
1404 if ( !iLocalFileSharingActivated && iFileSharingError == KErrNone) |
|
1405 { |
|
1406 // Instantiate and launch the wait note until the sharing is |
|
1407 // enabled of user cancels the operation |
|
1408 iFileSharingActivationWaitNote = new(ELeave)CAknWaitDialog( |
|
1409 ( REINTERPRET_CAST( CEikDialog**, |
|
1410 &iFileSharingActivationWaitNote ) ), ETrue ); |
|
1411 iFileSharingActivationWaitNote->SetCallback( this); |
|
1412 TRAPD( fileSharingActivationError, |
|
1413 iFileSharingActivationWaitNote->ExecuteLD( |
|
1414 R_AIW_ENABLE_SHARING_WAIT_NOTE ) ) |
|
1415 ; |
|
1416 |
|
1417 // Cancel sharing activation is user pressed cancel |
|
1418 if (iFileSharingError == KErrCancel) |
|
1419 { |
|
1420 TRAP_IGNORE( aSession->CancelReserveLocalMSServicesL() ); |
|
1421 } |
|
1422 |
|
1423 // If sharing failed, and the user did not cancel the operations, |
|
1424 // forward the leave code. |
|
1425 if (fileSharingActivationError != KErrNone && iFileSharingError |
|
1426 != KErrCancel) |
|
1427 { |
|
1428 iFileSharingError = fileSharingActivationError; |
|
1429 } |
|
1430 } |
|
1431 |
|
1432 if (iFileSharingError != KErrNone) |
|
1433 { |
|
1434 User::Leave(iFileSharingError); |
|
1435 } |
|
1436 } |
|
1437 |
|
1438 // -------------------------------------------------------------------------- |
|
1439 // CUPnPAiwEngine::DialogDismissedL |
|
1440 // ProgressDialog call back method. Get's called when a dialog is |
|
1441 // dismissed. |
|
1442 // -------------------------------------------------------------------------- |
|
1443 // |
|
1444 void CUPnPAiwEngine::DialogDismissedL(TInt aButtonId) |
|
1445 { |
|
1446 if (aButtonId == EAknSoftkeyCancel) |
|
1447 { |
|
1448 __LOG( "[UpnpAiwEngine]\t CUPnPAiwEngine, user cancelled the file \ |
|
1449 sharing activation" ); |
|
1450 iFileSharingError = KErrCancel; |
|
1451 } |
|
1452 } |
|
1453 |
|
1454 // -------------------------------------------------------------------------- |
|
1455 // CUPnPAiwEngine::DialogDismissedL |
|
1456 // Method for selecting a device. |
|
1457 // -------------------------------------------------------------------------- |
|
1458 // |
|
1459 CUpnpAVDevice* CUPnPAiwEngine::SelectDeviceL( |
|
1460 TUPnPDeviceTypesToSearch aDeviceType, TUPnPDialogTitle aDlgTitle) |
|
1461 { |
|
1462 __LOG( "[UpnpAiwEngine]\t CUPnPAiwEngine::SelectDeviceL" ); |
|
1463 |
|
1464 CUpnpAVDevice* device= NULL; |
|
1465 |
|
1466 // Leave if the engine is not in right state |
|
1467 if ( !iAVController) |
|
1468 { |
|
1469 User::Leave(KErrNotReady); |
|
1470 } |
|
1471 else |
|
1472 { |
|
1473 // Create new UpnpAvDevice instance |
|
1474 device = CUpnpAVDevice::NewL(); |
|
1475 CleanupStack::PushL(device); |
|
1476 |
|
1477 // Do the device selection |
|
1478 TInt ret = iCommonUI->SelectDeviceL( *iAVController, *device, |
|
1479 aDeviceType, aDlgTitle); |
|
1480 |
|
1481 if (ret != KErrNone) |
|
1482 { |
|
1483 CleanupStack::PopAndDestroy(device); |
|
1484 device = NULL; |
|
1485 User::Leave(ret); |
|
1486 } |
|
1487 CleanupStack::Pop(device); // Will be returned from the method |
|
1488 } |
|
1489 |
|
1490 return device; |
|
1491 } |
|
1492 |
|
1493 // -------------------------------------------------------------------------- |
|
1494 // CUPnPAiwEngine::StarVideoPlayL |
|
1495 // Method for Playing a local video |
|
1496 // -------------------------------------------------------------------------- |
|
1497 // |
|
1498 void CUPnPAiwEngine::StartVideoPlayL(const TDesC& aFileName) |
|
1499 { |
|
1500 __LOG( "[UpnpAiwEngine]\t CUPnPAiwEngine::StartVideoPlayL" ); |
|
1501 |
|
1502 //check if selected renderer supports playing video |
|
1503 TInt status = KErrNone; |
|
1504 if (iRenderingSession->Device().VideoCapability() ) |
|
1505 { |
|
1506 // Launch the video player dialog to render the |
|
1507 // item on the selected rendering device. |
|
1508 MUPnPItemResolver* resolver = CreateResolverLC( aFileName ); |
|
1509 |
|
1510 // Update engine state |
|
1511 iEngineState = EUPnPEngineActive; |
|
1512 iRenderingSessionInUse = ETrue; |
|
1513 iVideoPlay = ETrue; |
|
1514 |
|
1515 status = iCommonUI->ExecuteVideoPlayerL( *iRenderingSession, |
|
1516 resolver->Item() ); |
|
1517 iVideoPlay = EFalse; |
|
1518 iRenderingSessionInUse = EFalse; |
|
1519 |
|
1520 if (KErrSessionClosed == status || KErrDisconnected == status) |
|
1521 { |
|
1522 if (KErrSessionClosed == status) |
|
1523 { |
|
1524 ReleaseUpnpResourceL(); |
|
1525 } |
|
1526 } |
|
1527 else |
|
1528 { |
|
1529 // Re-register to observe the rendering |
|
1530 // session and update engine state |
|
1531 iRenderingSession->RemoveObserver(); |
|
1532 iRenderingSession->SetObserver( *this); |
|
1533 iEngineState = EUPnPEngineConnected; |
|
1534 } |
|
1535 |
|
1536 //notify MG, the video playing is complete |
|
1537 if (iObserver) |
|
1538 { |
|
1539 iObserver->PlayCompleteL(status); |
|
1540 } |
|
1541 |
|
1542 if (KErrCancel == status) |
|
1543 { |
|
1544 TRAP_IGNORE( iRenderingSession->StopL() ); |
|
1545 iRenderingSessionInUse = ETrue; |
|
1546 iVideoPlayCancel = ETrue; |
|
1547 } |
|
1548 |
|
1549 CleanupStack::PopAndDestroy(); // resolver |
|
1550 } |
|
1551 else //if not |
|
1552 { |
|
1553 status = KErrNotSupported; |
|
1554 } |
|
1555 } |
|
1556 |
|
1557 // -------------------------------------------------------------------------- |
|
1558 // CUPnPAiwEngine::InitPlayL |
|
1559 // Method for Playing a local file |
|
1560 // -------------------------------------------------------------------------- |
|
1561 // |
|
1562 void CUPnPAiwEngine::InitPlayL() |
|
1563 { |
|
1564 __LOG( "[UpnpAiwEngine]\t CUPnPAiwEngine::InitPlayL" ); |
|
1565 |
|
1566 //if pending an item |
|
1567 TInt error = KErrNone; |
|
1568 |
|
1569 if (iVideoPlay || iVideoPlayWait) |
|
1570 { |
|
1571 __LOG( "[UpnpAiwEngine]\t CUPnPAiwEngine, start video play" ); |
|
1572 TRAP_IGNORE( StartVideoPlayL( *iFileName ) ); |
|
1573 iVideoPlayWait = EFalse; |
|
1574 } |
|
1575 else |
|
1576 { |
|
1577 __LOG( "[UpnpAiwEngine]\t CUPnPAiwEngine, start image play" ); |
|
1578 TRAP( error , CreateUpnpItemAndSetUriL( *iFileName ) ); |
|
1579 if (KErrNone == error) |
|
1580 { |
|
1581 iRenderingSessionInUse = ETrue; |
|
1582 } |
|
1583 else |
|
1584 { |
|
1585 iObserver->PlayCompleteL(error); |
|
1586 } |
|
1587 } |
|
1588 } |
|
1589 |
|
1590 // -------------------------------------------------------------------------- |
|
1591 // CUPnPAiwEngine::Wait |
|
1592 // -------------------------------------------------------------------------- |
|
1593 // |
|
1594 void CUPnPAiwEngine::Wait() |
|
1595 { |
|
1596 StopWait(); |
|
1597 iWait.Start(); |
|
1598 } |
|
1599 |
|
1600 // -------------------------------------------------------------------------- |
|
1601 // CUPnPAiwEngine::StopWait |
|
1602 // -------------------------------------------------------------------------- |
|
1603 // |
|
1604 void CUPnPAiwEngine::StopWait() |
|
1605 { |
|
1606 if (iWait.IsStarted() ) |
|
1607 { |
|
1608 if (iWait.CanStopNow() ) |
|
1609 { |
|
1610 iWait.AsyncStop(); |
|
1611 } |
|
1612 } |
|
1613 } |
|
1614 |
|
1615 // -------------------------------------------------------------------------- |
|
1616 // CUPnPAiwEngine::CreateUpnpItemAndSetUriL |
|
1617 // -------------------------------------------------------------------------- |
|
1618 // |
|
1619 void CUPnPAiwEngine::CreateUpnpItemAndSetUriL(const TDesC& aFileName) |
|
1620 { |
|
1621 __LOG( "[UpnpAiwEngine]\t CUPnPAiwEngine::CreateUpnpItemAndSetUriL" ); |
|
1622 |
|
1623 // Creates resolver to iResolver member variable. |
|
1624 MUPnPItemResolver* resolver = CreateResolverLC( aFileName ); |
|
1625 |
|
1626 // Sets uri. |
|
1627 const CUpnpElement& element = UPnPItemUtility::ResourceFromItemL( |
|
1628 iResolver->Item() ); |
|
1629 iRenderingSession->SetURIL( element.Value(), iResolver->Item() ); |
|
1630 |
|
1631 // Cleanup |
|
1632 CleanupStack::PopAndDestroy(); // resolver |
|
1633 |
|
1634 __LOG( "[UpnpAiwEngine]\t CUPnPAiwEngine::CreateUpnpItemAndSetUriL -END" ); |
|
1635 } |
|
1636 |
|
1637 // -------------------------------------------------------------------------- |
|
1638 // CUPnPAiwEngine::ResolveComplete |
|
1639 // -------------------------------------------------------------------------- |
|
1640 // |
|
1641 void CUPnPAiwEngine::ResolveComplete( |
|
1642 const MUPnPItemResolver& /*aResolver*/, |
|
1643 TInt aError ) |
|
1644 { |
|
1645 __LOG( "[UpnpAiwEngine]\t CUPnPAiwEngine::ResolveComplete" ); |
|
1646 |
|
1647 iResolveResult = aError; |
|
1648 StopWait(); |
|
1649 |
|
1650 __LOG( "[UpnpAiwEngine]\t CUPnPAiwEngine::ResolveComplete -END" ); |
|
1651 } |
|
1652 |
|
1653 // -------------------------------------------------------------------------- |
|
1654 // CUPnPAiwEngine::CreateResolverLC |
|
1655 // -------------------------------------------------------------------------- |
|
1656 // |
|
1657 MUPnPItemResolver* CUPnPAiwEngine::CreateResolverLC( const TDesC& aFilePath ) |
|
1658 { |
|
1659 __LOG( "[UpnpAiwEngine]\t CUPnPAiwEngine::CreateResolverLC" ); |
|
1660 |
|
1661 // If member variable exists, resolving operation is ongoing. |
|
1662 if ( iResolver ) |
|
1663 { |
|
1664 User::Leave( KErrInUse ); |
|
1665 } |
|
1666 |
|
1667 // Creates resolver |
|
1668 TUPnPSelectDefaultResource selector; |
|
1669 iResolver = UPnPItemResolverFactory::NewLocalItemResolverL( |
|
1670 aFilePath, |
|
1671 *iAVController, |
|
1672 selector ); |
|
1673 CleanupStack::PushL( TCleanupItem( CleanupResolver, this ) ); |
|
1674 |
|
1675 // Starts async resolver. |
|
1676 iResolveResult = KErrNone; |
|
1677 iResolver->ResolveL( *this ); |
|
1678 Wait(); |
|
1679 |
|
1680 // If error occured, resolves it in here. It will cleanup resolver. |
|
1681 User::LeaveIfError( iResolveResult ); |
|
1682 |
|
1683 __LOG( "[UpnpAiwEngine]\t CUPnPAiwEngine::CreateResolverLC -END" ); |
|
1684 |
|
1685 return iResolver; |
|
1686 } |
|
1687 |
|
1688 // -------------------------------------------------------------------------- |
|
1689 // CUPnPAiwEngine::CleanupResolver |
|
1690 // Static method to cleanup resolver object. |
|
1691 // -------------------------------------------------------------------------- |
|
1692 // |
|
1693 void CUPnPAiwEngine::CleanupResolver( TAny* aAiwEngine ) |
|
1694 { |
|
1695 __LOG( "[UpnpAiwEngine]\t CUPnPAiwEngine::CleanupResolver" ); |
|
1696 |
|
1697 CUPnPAiwEngine* aiwEngine = reinterpret_cast<CUPnPAiwEngine*>( aAiwEngine ); |
|
1698 if ( aiwEngine ) |
|
1699 { |
|
1700 MUPnPItemResolver* tempResolver = aiwEngine->iResolver; |
|
1701 aiwEngine->iResolver = NULL; |
|
1702 delete tempResolver; |
|
1703 __LOG( "[UpnpAiwEngine]\t\t Resolver cleaned up." ); |
|
1704 } |
|
1705 |
|
1706 __LOG( "[UpnpAiwEngine]\t CUPnPAiwEngine::CleanupResolver -END" ); |
|
1707 } |
|
1708 |
|
1709 // End of file |
|