dlnasrv_exampleapp/src/exampleappengine_p.cpp
branchIOP_Improvements
changeset 40 08b5eae9f9ff
child 41 b4d83ea1d6e2
equal deleted inserted replaced
39:6369bfd1b60d 40:08b5eae9f9ff
       
     1 /*
       
     2 * Copyright (c) 2010 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:
       
    15 *
       
    16 */
       
    17 
       
    18 #include <es_sock.h>
       
    19 #include <es_enum.h>
       
    20 #include <upnpsettingsengine.h>
       
    21 #include <upnpavcontrollerfactory.h>
       
    22 #include <upnpavcontroller.h>
       
    23 #include <upnpavdevice.h>
       
    24 #include <upnpavdevicelist.h>
       
    25 #include <upnprenderingstatemachine.h>
       
    26 #include <upnpavrenderingsession.h>
       
    27 #include <upnpvolumestatemachine.h>
       
    28 #include <upnpitemresolverfactory.h>
       
    29 #include <upnpitemresolver.h>
       
    30 #include <upnpconnectionmonitor.h>
       
    31 
       
    32 #include "exampleappengine_p.h"
       
    33 #include "trace.h"
       
    34 
       
    35 /*!
       
    36     /class ExampleAppEnginePrivate
       
    37     /brief Implements interface to Symbian side DLNA APIs.
       
    38 */
       
    39 
       
    40 /*!
       
    41     C++ constructor.
       
    42 */
       
    43 ExampleAppEnginePrivate::ExampleAppEnginePrivate():
       
    44     q_ptr(0),
       
    45     mSettingsEngine(0),
       
    46     mAVRenderingSession(0),
       
    47     mRenderingStateMachine(0),
       
    48     mVolumeStateMachine(0),
       
    49     mAVController(0),
       
    50     mIap(0),
       
    51     mIapName(""),
       
    52     mDevices(0),
       
    53     mDevice(0),
       
    54     mPlaybackState(ExampleAppEngine::PlaybackStateStopped),
       
    55     mItemResolver(0)
       
    56 {
       
    57     FUNC_LOG    
       
    58 
       
    59     TRAP_IGNORE(mSettingsEngine = CUPnPSettingsEngine::NewL());
       
    60     
       
    61     TRAP_IGNORE(mDevices = CUpnpAVDeviceList::NewL());
       
    62     
       
    63     TRAP_IGNORE(mConnectionMonitor = CUPnPConnectionMonitor::NewL(0));
       
    64     mConnectionMonitor->SetObserver(*this);
       
    65 }
       
    66 
       
    67 /*!
       
    68     C++ destructor.
       
    69 */
       
    70 ExampleAppEnginePrivate::~ExampleAppEnginePrivate()
       
    71 {
       
    72     FUNC_LOG
       
    73     
       
    74     delete mItemResolver;
       
    75     
       
    76     delete mDevices;
       
    77     
       
    78     delete mSettingsEngine;
       
    79     
       
    80     if (mAVRenderingSession)
       
    81     {
       
    82         if (mAVController)
       
    83         {
       
    84             mAVController->StopRenderingSession(*mAVRenderingSession);
       
    85         }
       
    86     }
       
    87     
       
    88     delete mRenderingStateMachine;
       
    89     
       
    90     delete mVolumeStateMachine;
       
    91     
       
    92     if (mAVController)
       
    93     {
       
    94         mAVController->Release();
       
    95     }
       
    96     
       
    97     delete mConnectionMonitor;
       
    98 }
       
    99 
       
   100 /*!
       
   101     description
       
   102     
       
   103     /a
       
   104     /return
       
   105 */
       
   106 void ExampleAppEnginePrivate::construct()
       
   107 {
       
   108     FUNC_LOG
       
   109 
       
   110     resolveIapL();
       
   111     resolveIapNameL();
       
   112 }
       
   113 
       
   114 /*!
       
   115     description
       
   116     
       
   117     /a
       
   118     /return
       
   119 */
       
   120 int ExampleAppEnginePrivate::getConnectedIap() const
       
   121 {
       
   122     FUNC_LOG
       
   123     
       
   124     return mIap;
       
   125 }
       
   126 
       
   127 /*!
       
   128     description
       
   129     
       
   130     /a
       
   131     /return
       
   132 */
       
   133 QString ExampleAppEnginePrivate::getConnectedIapName() const
       
   134 {
       
   135     FUNC_LOG
       
   136     
       
   137     return mIapName;
       
   138 }
       
   139 
       
   140 /*!
       
   141     description
       
   142     
       
   143     /a
       
   144     /return
       
   145 */
       
   146 int ExampleAppEnginePrivate::getPlaybackState() const
       
   147 {
       
   148     FUNC_LOG
       
   149     
       
   150     return mPlaybackState;
       
   151 }
       
   152 
       
   153 /*!
       
   154     description
       
   155     
       
   156     /a
       
   157     /return
       
   158 */
       
   159 bool ExampleAppEnginePrivate::isSeekSupported() const
       
   160 {
       
   161     FUNC_LOG
       
   162 
       
   163     // TODO: return real value when seek is implemented
       
   164     
       
   165     return false;
       
   166 }
       
   167 
       
   168 /*!
       
   169     description
       
   170     
       
   171     /a
       
   172     /return
       
   173 */
       
   174 bool ExampleAppEnginePrivate::isPauseSupported() const
       
   175 {
       
   176     FUNC_LOG
       
   177     
       
   178     bool isSupported(false);
       
   179     
       
   180     if (mDevice)
       
   181     {
       
   182         isSupported = mDevice->PauseCapability();
       
   183     }
       
   184     
       
   185     return isSupported;
       
   186 }
       
   187 
       
   188 /*!
       
   189     description
       
   190     
       
   191     /a
       
   192     /return
       
   193 */
       
   194 void ExampleAppEnginePrivate::searchRenderingDevices()
       
   195 {
       
   196     FUNC_LOG
       
   197     
       
   198     if (mIap)
       
   199     {
       
   200         // first create av controller
       
   201         if (!mAVController)
       
   202         {
       
   203             TRAP_IGNORE(mAVController = UPnPAVControllerFactory::NewUPnPAVControllerL());
       
   204             if (!mAVController)
       
   205             {
       
   206                 return;
       
   207             }
       
   208             mAVController->SetDeviceObserver(*this);
       
   209         }
       
   210         
       
   211         // check if devices have been found
       
   212         TRAP_IGNORE(searchRenderingDevicesL());
       
   213     }    
       
   214 }
       
   215 
       
   216 /*!
       
   217     description
       
   218     
       
   219     /a
       
   220     /return
       
   221 */
       
   222 void ExampleAppEnginePrivate::prepareRenderingDevice(const QString &uuid)
       
   223 {
       
   224     FUNC_LOG
       
   225     
       
   226     TRAP_IGNORE(prepareRenderingDeviceL(uuid));    
       
   227 }
       
   228 
       
   229 /*!
       
   230     description
       
   231     
       
   232     /a
       
   233     /return
       
   234 */
       
   235 int ExampleAppEnginePrivate::initFile(const QString& file)
       
   236 {
       
   237     FUNC_LOG
       
   238     
       
   239     TRAPD(err, initFileL(file));
       
   240     
       
   241     return err;
       
   242 }
       
   243 
       
   244 /*!
       
   245     description
       
   246     
       
   247     /a
       
   248     /return
       
   249 */
       
   250 void ExampleAppEnginePrivate::play()
       
   251 {
       
   252     FUNC_LOG
       
   253 
       
   254     TRAP_IGNORE(playL());
       
   255 }
       
   256 
       
   257 /*!
       
   258     description
       
   259     
       
   260     /a
       
   261     /return
       
   262 */
       
   263 void ExampleAppEnginePrivate::pause()
       
   264 {
       
   265     FUNC_LOG
       
   266     
       
   267     TRAP_IGNORE(pauseL());
       
   268 }
       
   269 
       
   270 /*!
       
   271     description
       
   272     
       
   273     /a
       
   274     /return
       
   275 */
       
   276 void ExampleAppEnginePrivate::stop()
       
   277 {
       
   278     FUNC_LOG
       
   279     
       
   280     TRAP_IGNORE(stopL());
       
   281 }
       
   282 
       
   283 /*!
       
   284     description
       
   285     
       
   286     /a
       
   287     /return
       
   288 */
       
   289 void ExampleAppEnginePrivate::volumeUp()
       
   290 {
       
   291     FUNC_LOG
       
   292     
       
   293     // TODO: implement
       
   294 }
       
   295 
       
   296 /*!
       
   297     description
       
   298     
       
   299     /a
       
   300     /return
       
   301 */
       
   302 void ExampleAppEnginePrivate::volumeDown()
       
   303 {
       
   304     FUNC_LOG
       
   305     
       
   306     // TODO: implement
       
   307 }
       
   308 
       
   309 /*!
       
   310     description
       
   311     
       
   312     /a
       
   313     /return
       
   314 */
       
   315 void ExampleAppEnginePrivate::rew()
       
   316 {
       
   317     FUNC_LOG
       
   318     
       
   319     // TODO: implement
       
   320 }
       
   321 
       
   322 /*!
       
   323     description
       
   324     
       
   325     /a
       
   326     /return
       
   327 */
       
   328 void ExampleAppEnginePrivate::ff()
       
   329 {
       
   330     FUNC_LOG
       
   331     
       
   332     // TODO: implement
       
   333 }
       
   334 
       
   335 /*!
       
   336     description
       
   337     
       
   338     /a
       
   339     /return
       
   340 */
       
   341 void ExampleAppEnginePrivate::UPnPDeviceDiscovered(const CUpnpAVDevice& aDevice)
       
   342 {
       
   343     FUNC_LOG
       
   344     
       
   345     TRAP_IGNORE(upnpDeviceDiscoveredL(aDevice));
       
   346 }
       
   347 
       
   348 /*!
       
   349     description
       
   350     
       
   351     /a
       
   352     /return
       
   353 */
       
   354 void ExampleAppEnginePrivate::UPnPDeviceDisappeared(const CUpnpAVDevice& aDevice)
       
   355 {
       
   356     FUNC_LOG
       
   357 
       
   358     // search device from list
       
   359     CUpnpAVDevice *device(NULL);
       
   360     int count(mDevices->Count());
       
   361     int index(0);
       
   362     for (int i = 0; i < count; i++)
       
   363     {
       
   364         device = (*mDevices)[i];
       
   365         if (device->Uuid() == aDevice.Uuid())
       
   366         {
       
   367             index = i;
       
   368             break;
       
   369         }
       
   370         device = NULL;
       
   371     }
       
   372     
       
   373     // remove if device was found
       
   374     if (device)
       
   375     {
       
   376         mDevices->Remove(index);
       
   377         
       
   378         if (device->Uuid() == mDevice->Uuid())
       
   379         {
       
   380             stopRenderingSession();
       
   381         }
       
   382         
       
   383         QString name = asString8(device->FriendlyName());
       
   384         QString uuid = asString8(device->Uuid());        
       
   385         emit q_ptr->renderingDeviceDisappeared(name, uuid);
       
   386         
       
   387         delete device;
       
   388     }
       
   389 }
       
   390 
       
   391 /*!
       
   392     description
       
   393     
       
   394     /a
       
   395     /return
       
   396 */
       
   397 void ExampleAppEnginePrivate::WLANConnectionLost()
       
   398 {
       
   399     FUNC_LOG
       
   400 
       
   401     // no implementation required
       
   402 }
       
   403 
       
   404 /*!
       
   405     description
       
   406     
       
   407     /a
       
   408     /return
       
   409 */
       
   410 void ExampleAppEnginePrivate::VolumeResult(TInt aError,
       
   411     TInt aVolumeLevel,
       
   412     TBool aActionResponse)
       
   413 {
       
   414     FUNC_LOG
       
   415 
       
   416     if (mVolumeStateMachine)
       
   417     {
       
   418         mVolumeStateMachine->VolumeResult(aError, aVolumeLevel, aActionResponse);
       
   419     }
       
   420 }
       
   421 
       
   422 /*!
       
   423     description
       
   424     
       
   425     /a
       
   426     /return
       
   427 */
       
   428 void ExampleAppEnginePrivate::MuteResult(TInt aError,
       
   429     TBool aMute,
       
   430     TBool aActionResponse)
       
   431 {
       
   432     FUNC_LOG
       
   433 
       
   434     if (mVolumeStateMachine)
       
   435     {
       
   436         mVolumeStateMachine->MuteResult(aError, aMute, aActionResponse);
       
   437     }
       
   438 }
       
   439 
       
   440 /*!
       
   441     description
       
   442     
       
   443     /a
       
   444     /return
       
   445 */
       
   446 void ExampleAppEnginePrivate::InteractOperationComplete(TInt aError,
       
   447     TUPnPAVInteractOperation aOperation)
       
   448 {
       
   449     FUNC_LOG
       
   450 
       
   451     if (mRenderingStateMachine)
       
   452     {
       
   453         mRenderingStateMachine->InteractOperationComplete(aError, aOperation);
       
   454     }
       
   455 }
       
   456 
       
   457 /*!
       
   458     description
       
   459     
       
   460     /a
       
   461     /return
       
   462 */
       
   463 void ExampleAppEnginePrivate::PositionInfoResult(TInt aError,
       
   464     const TDesC8& aTrackPosition,
       
   465     const TDesC8& aTrackLength)
       
   466 {
       
   467     FUNC_LOG
       
   468 
       
   469     if (mRenderingStateMachine)
       
   470     {
       
   471         mRenderingStateMachine->PositionInfoResult(aError, aTrackPosition, aTrackLength);
       
   472     }
       
   473 }
       
   474 
       
   475 /*!
       
   476     description
       
   477     
       
   478     /a
       
   479     /return
       
   480 */
       
   481 void ExampleAppEnginePrivate::SetURIResult(TInt aError)
       
   482 {
       
   483     FUNC_LOG
       
   484 
       
   485     if (mRenderingStateMachine)
       
   486     {
       
   487         mRenderingStateMachine->SetURIResult(aError);
       
   488     }
       
   489 }
       
   490 
       
   491 /*!
       
   492     description
       
   493     
       
   494     /a
       
   495     /return
       
   496 */
       
   497 void ExampleAppEnginePrivate::SetNextURIResult(TInt aError)
       
   498 {
       
   499     FUNC_LOG
       
   500     
       
   501     if (mRenderingStateMachine)
       
   502     {
       
   503         mRenderingStateMachine->SetNextURIResult(aError);
       
   504     }
       
   505 }
       
   506 
       
   507 /*!
       
   508     description
       
   509     
       
   510     /a
       
   511     /return
       
   512 */
       
   513 void ExampleAppEnginePrivate::MediaRendererDisappeared(TUPnPDeviceDisconnectedReason /*aReason*/)
       
   514 {
       
   515     FUNC_LOG
       
   516     
       
   517     // TODO: implement
       
   518 }
       
   519 
       
   520 /*!
       
   521     description
       
   522     
       
   523     /a
       
   524     /return
       
   525 */
       
   526 void ExampleAppEnginePrivate::RendererSyncReady(TInt /*aError*/, Upnp::TState /*aState*/)
       
   527 {
       
   528     FUNC_LOG
       
   529     
       
   530     // TODO: implement
       
   531 }
       
   532 
       
   533 /*!
       
   534     description
       
   535     
       
   536     /a
       
   537     /return
       
   538 */
       
   539 void ExampleAppEnginePrivate::RenderingStateChanged(TInt aError,
       
   540     Upnp::TState aState,
       
   541     TBool /*aUserOriented*/,
       
   542     TInt /*aStateParam*/)
       
   543 {
       
   544     FUNC_LOG
       
   545 
       
   546     int state(ExampleAppEngine::PlaybackStateStopped);
       
   547     
       
   548     if (aError == KErrNone)
       
   549     {
       
   550         switch (aState)
       
   551         {
       
   552             case Upnp::EBuffering:
       
   553             {
       
   554                 state = ExampleAppEngine::PlaybackStateBuffering;
       
   555                 break;
       
   556             }
       
   557             case Upnp::EPlaying:
       
   558             {
       
   559                 state = ExampleAppEngine::PlaybackStatePlaying;
       
   560                 break;
       
   561             }
       
   562             case Upnp::EPaused:
       
   563             {
       
   564                 state = ExampleAppEngine::PlaybackStatePaused;
       
   565                 break;
       
   566             }
       
   567             default:
       
   568             {
       
   569                 // no actions, stopped state is used
       
   570                 break;
       
   571             }
       
   572         }
       
   573     }
       
   574     
       
   575     mPlaybackState = state;
       
   576     
       
   577     emit q_ptr->stateChanged(mPlaybackState);
       
   578 }
       
   579 
       
   580 /*!
       
   581     description
       
   582     
       
   583     /a
       
   584     /return
       
   585 */
       
   586 void ExampleAppEnginePrivate::PositionSync(TInt /*aError*/,
       
   587     Upnp::TPositionMode /*aMode*/,
       
   588     TInt /*aDuration*/,
       
   589     TInt /*aPosition*/)
       
   590 {
       
   591     FUNC_LOG
       
   592     
       
   593     // TODO: implement
       
   594 }
       
   595 
       
   596 /*!
       
   597     description
       
   598     
       
   599     /a
       
   600     /return
       
   601 */
       
   602 void ExampleAppEnginePrivate::VolumeSyncReady(TInt /*aError*/)
       
   603 {
       
   604     FUNC_LOG
       
   605     
       
   606     // TODO: implement
       
   607 }
       
   608 
       
   609 /*!
       
   610     description
       
   611     
       
   612     /a
       
   613     /return
       
   614 */
       
   615 void ExampleAppEnginePrivate::VolumeChanged(TInt /*aError*/,
       
   616     TInt /*aVolume*/,
       
   617     TBool /*aUserOriented*/)
       
   618 {
       
   619     FUNC_LOG
       
   620     
       
   621     // TODO: implement
       
   622 }
       
   623 
       
   624 /*!
       
   625     description
       
   626     
       
   627     /a
       
   628     /return
       
   629 */
       
   630 void ExampleAppEnginePrivate::MuteChanged(TInt /*aError*/,
       
   631     TBool /*aMuteState*/,
       
   632     TBool /*aUserOriented*/)
       
   633 {
       
   634     FUNC_LOG
       
   635     
       
   636     // TODO: implement
       
   637 }
       
   638 
       
   639 /*!
       
   640     description
       
   641     
       
   642     /a
       
   643     /return
       
   644 */
       
   645 void ExampleAppEnginePrivate::ResolveComplete(const MUPnPItemResolver& /*aResolver*/,
       
   646     TInt aError)
       
   647 {
       
   648     FUNC_LOG
       
   649     
       
   650     ERROR(aError, "Error while resolving an item");
       
   651     
       
   652     emit q_ptr->initComplete(aError);
       
   653 }
       
   654 
       
   655 /*!
       
   656     description
       
   657     
       
   658     /a
       
   659     /return
       
   660 */
       
   661 void ExampleAppEnginePrivate::ConnectionLost(TBool /*aUserOriented*/)
       
   662 {
       
   663     FUNC_LOG
       
   664 
       
   665     stopRenderingSession();
       
   666     
       
   667     mIap = 0;
       
   668     mIapName = "Not connected";
       
   669 
       
   670     emit q_ptr->iapUpdated(mIapName);
       
   671     emit q_ptr->iapUpdated(mIap);
       
   672 }
       
   673 
       
   674 /*!
       
   675     description
       
   676     
       
   677     /a
       
   678     /return
       
   679 */
       
   680 void ExampleAppEnginePrivate::ConnectionCreated(TInt /*aConnectionId*/)
       
   681 {
       
   682     FUNC_LOG
       
   683 
       
   684     TRAP_IGNORE(resolveIapL());
       
   685     TRAP_IGNORE(resolveIapNameL());
       
   686 
       
   687     emit q_ptr->iapUpdated(mIapName);
       
   688     emit q_ptr->iapUpdated(mIap);
       
   689 }
       
   690 
       
   691 /*!
       
   692     description
       
   693     
       
   694     /a
       
   695     /return
       
   696 */
       
   697 void ExampleAppEnginePrivate::searchRenderingDevicesL()
       
   698 {
       
   699     FUNC_LOG
       
   700     
       
   701     emit q_ptr->renderingDeviceSearchStarted();
       
   702 
       
   703     CUpnpAVDeviceList *deviceList = mAVController->GetMediaRenderersL();
       
   704     int count(deviceList->Count());
       
   705     for (int i = count - 1; i >= 0; i--)
       
   706     {
       
   707         CUpnpAVDevice *device = (*deviceList)[i];
       
   708         upnpDeviceDiscoveredL(*device);
       
   709     }
       
   710     delete deviceList;
       
   711 }
       
   712 
       
   713 /*!
       
   714     description
       
   715     
       
   716     /a
       
   717     /return
       
   718 */
       
   719 void ExampleAppEnginePrivate::upnpDeviceDiscoveredL(const CUpnpAVDevice& aDevice)
       
   720 {
       
   721     FUNC_LOG
       
   722 
       
   723     if (aDevice.DeviceType() == CUpnpAVDevice::EMediaRenderer)
       
   724     {
       
   725         CUpnpAVDevice *device(0);
       
   726         int count(mDevices->Count());
       
   727         for (int i = 0; i < count; i++)
       
   728         {
       
   729             device = (*mDevices)[i];
       
   730             if (device->Uuid() == aDevice.Uuid())
       
   731             {
       
   732                 // found
       
   733                 break;
       
   734             }
       
   735             device = 0;
       
   736         }
       
   737         
       
   738         if (!device)
       
   739         {
       
   740             // create new device
       
   741             device = CUpnpAVDevice::NewL(aDevice);
       
   742             mDevices->AppendDeviceL(*device);
       
   743             
       
   744             QString name = asString8(device->FriendlyName());
       
   745             QString uuid = asString8(device->Uuid());
       
   746 
       
   747             INFO_2("New rendering device found: Name = %s, Uuid = %s",
       
   748                 name.utf16(), uuid.utf16());
       
   749             
       
   750             emit q_ptr->renderingDeviceFound(name, uuid);
       
   751         }
       
   752     }
       
   753 }
       
   754 
       
   755 /*!
       
   756     description
       
   757     
       
   758     /a
       
   759     /return
       
   760 */
       
   761 void ExampleAppEnginePrivate::prepareRenderingDeviceL(const QString &uuid)
       
   762 {
       
   763     FUNC_LOG
       
   764     
       
   765     // get current uuid
       
   766     QString currentUuid;
       
   767     if (mDevice)
       
   768     {
       
   769         currentUuid = asString8(mDevice->Uuid());
       
   770     }
       
   771     
       
   772     // check if uuid is different than the requsted one
       
   773     if (currentUuid != uuid)
       
   774     {
       
   775         // search the rendering device
       
   776         CUpnpAVDevice *device = 0;
       
   777         int count(mDevices->Count());
       
   778         for (int i = 0; i < count; i++)
       
   779         {
       
   780             device = (*mDevices)[i];
       
   781             QString deviceUuid = asString8(device->Uuid());
       
   782             if (deviceUuid == uuid)
       
   783             {
       
   784                 // device found
       
   785                 break;
       
   786             }
       
   787             device = 0;
       
   788         }
       
   789         
       
   790         stopRenderingSession();
       
   791         
       
   792         mDevice = device;
       
   793         if (mDevice)
       
   794         {            
       
   795             startRenderingSessionL(*mDevice);
       
   796         }
       
   797     }
       
   798 }
       
   799 
       
   800 /*!
       
   801     description
       
   802     
       
   803     /a
       
   804     /return
       
   805 */
       
   806 void ExampleAppEnginePrivate::startRenderingSessionL(const CUpnpAVDevice &device)
       
   807 {
       
   808     FUNC_LOG
       
   809 
       
   810     // start new rendering session
       
   811     mAVRenderingSession = &mAVController->StartRenderingSessionL(device);
       
   812     mAVRenderingSession->SetObserver(*this);
       
   813     
       
   814     // start new rendering state machine
       
   815     mRenderingStateMachine = CUpnpRenderingStateMachine::NewL(*mAVRenderingSession);
       
   816     mRenderingStateMachine->SetObserver(*this);
       
   817     mRenderingStateMachine->SyncL();
       
   818     
       
   819     // start new volume state machine
       
   820     mVolumeStateMachine = CUpnpVolumeStateMachine::NewL(*mAVRenderingSession);
       
   821     mVolumeStateMachine->SetObserver(*this);
       
   822     mVolumeStateMachine->SyncL();
       
   823 }
       
   824 
       
   825 /*!
       
   826     description
       
   827     
       
   828     /a
       
   829     /return
       
   830 */
       
   831 void ExampleAppEnginePrivate::stopRenderingSession()
       
   832 {
       
   833     FUNC_LOG
       
   834     
       
   835     // stop ongoing playback
       
   836     if (mPlaybackState != ExampleAppEngine::PlaybackStateStopped)
       
   837     {
       
   838         stop();
       
   839         RenderingStateChanged(KErrNone, Upnp::EStopped, EFalse, 0);
       
   840     }
       
   841     
       
   842     // release rendering state machine
       
   843     delete mRenderingStateMachine;
       
   844     mRenderingStateMachine = 0;
       
   845     
       
   846     // release volume state machine
       
   847     delete mVolumeStateMachine;
       
   848     mVolumeStateMachine = 0;
       
   849 
       
   850     // stop and release rendering session
       
   851     if (mAVController && mAVRenderingSession)
       
   852     {
       
   853         mAVController->StopRenderingSession(*mAVRenderingSession);            
       
   854         mAVRenderingSession = 0;
       
   855     }
       
   856     
       
   857     mDevice = 0;
       
   858 }
       
   859 
       
   860 /*!
       
   861     description
       
   862     
       
   863     /a
       
   864     /return
       
   865 */
       
   866 void ExampleAppEnginePrivate::initFileL(const QString &file)
       
   867 {
       
   868     FUNC_LOG
       
   869     
       
   870     delete mItemResolver;
       
   871     mItemResolver = 0;
       
   872     
       
   873     if (mDevice)
       
   874     {
       
   875         TPtrC filePath(file.utf16(), file.length());
       
   876         TUPnPSelectDefaultResource selector;
       
   877         mItemResolver =
       
   878             UPnPItemResolverFactory::NewLocalItemResolverL(
       
   879                 filePath, *mAVController, selector);
       
   880         mItemResolver->ResolveL(*this, mDevice);
       
   881     }
       
   882     else
       
   883     {
       
   884         // rendering device has not been selected
       
   885         User::Leave(KErrNotReady);
       
   886     }
       
   887 }
       
   888 
       
   889 /*!
       
   890     description
       
   891     
       
   892     /a
       
   893     /return
       
   894 */
       
   895 bool ExampleAppEnginePrivate::isReadyForPlayback() const
       
   896 {
       
   897     FUNC_LOG
       
   898     
       
   899     bool isReady(false);
       
   900     
       
   901     if (mDevice &&           // device is selected
       
   902         mAVRenderingSession &&      // av rendering session is created
       
   903         mRenderingStateMachine &&   // rendering state machine is created
       
   904         mVolumeStateMachine)        // volume state machine is created
       
   905     {
       
   906         isReady = true;
       
   907     }
       
   908     
       
   909     return isReady;
       
   910 }
       
   911 
       
   912 /*!
       
   913     description
       
   914     
       
   915     /a
       
   916     /return
       
   917 */
       
   918 void ExampleAppEnginePrivate::playL()
       
   919 {
       
   920     FUNC_LOG
       
   921     
       
   922     if (isReadyForPlayback())
       
   923     {
       
   924         mRenderingStateMachine->CommandL(Upnp::EPlay, 0, &mItemResolver->Item());
       
   925     }
       
   926     else
       
   927     {
       
   928         User::Leave(KErrNotReady);
       
   929     }
       
   930 }
       
   931 
       
   932 /*!
       
   933     description
       
   934     
       
   935     /a
       
   936     /return
       
   937 */
       
   938 void ExampleAppEnginePrivate::pauseL()
       
   939 {
       
   940     FUNC_LOG
       
   941     
       
   942     if (isReadyForPlayback())
       
   943     {
       
   944         // double check that the rendering device supports pause capability
       
   945         if (mDevice->PauseCapability())
       
   946         {
       
   947             mRenderingStateMachine->CommandL(Upnp::EPause);
       
   948         }
       
   949         else
       
   950         {
       
   951             User::Leave(KErrNotSupported);
       
   952         }
       
   953     }
       
   954     else
       
   955     {
       
   956         User::Leave(KErrNotReady);
       
   957     }
       
   958 }
       
   959 
       
   960 /*!
       
   961     description
       
   962     
       
   963     /a
       
   964     /return
       
   965 */
       
   966 void ExampleAppEnginePrivate::stopL()
       
   967 {
       
   968     FUNC_LOG
       
   969     
       
   970     if (isReadyForPlayback())
       
   971     {
       
   972         mRenderingStateMachine->CommandL(Upnp::EStop);
       
   973     }
       
   974     else
       
   975     {
       
   976         User::Leave(KErrNotReady);
       
   977     }
       
   978 }
       
   979 
       
   980 /*!
       
   981     description
       
   982     
       
   983     /a
       
   984     /return
       
   985 */
       
   986 void ExampleAppEnginePrivate::resolveIapL()
       
   987 {
       
   988     FUNC_LOG
       
   989     
       
   990     // code below could be optimized so that connections to socket server
       
   991     // are only made once
       
   992     RSocketServ socketServ;
       
   993     int err = socketServ.Connect();
       
   994     if (err == KErrNone)
       
   995     {
       
   996         RConnection connection;
       
   997         err = connection.Open(socketServ);
       
   998         if (err == KErrNone)
       
   999         {
       
  1000             uint connectionCount(0);
       
  1001             err = connection.EnumerateConnections(connectionCount);
       
  1002             if (err == KErrNone &&
       
  1003             connectionCount == 1)
       
  1004             {
       
  1005                 // One active connection - find it and try using it
       
  1006                 TPckgBuf<TConnectionInfo> connectionInfo;
       
  1007                 for (int i = 1; i <= connectionCount; ++i)
       
  1008                 {
       
  1009                     if (connection.GetConnectionInfo(i, connectionInfo) == KErrNone)
       
  1010                     {
       
  1011                         // resolve iap id and name
       
  1012                         mIap = connectionInfo().iIapId;
       
  1013                     }
       
  1014                 }
       
  1015                 connection.Close();
       
  1016             }
       
  1017         }
       
  1018         socketServ.Close();
       
  1019     }
       
  1020     
       
  1021     mSettingsEngine->SetAccessPoint(mIap);
       
  1022 }
       
  1023 
       
  1024 /*!
       
  1025     description
       
  1026     
       
  1027     /a
       
  1028     /return
       
  1029 */
       
  1030 void ExampleAppEnginePrivate::resolveIapNameL()
       
  1031 {
       
  1032     FUNC_LOG
       
  1033     
       
  1034     HBufC* iapName(NULL);
       
  1035     TRAP_IGNORE(iapName = CUPnPSettingsEngine::GetCurrentIapNameL(mIap));
       
  1036     if (iapName)
       
  1037     {
       
  1038         mIapName = asString(*iapName);
       
  1039         delete iapName;
       
  1040     }
       
  1041 }
       
  1042 
       
  1043 /*!
       
  1044     description
       
  1045     
       
  1046     /a
       
  1047     /return
       
  1048 */
       
  1049 QString ExampleAppEnginePrivate::asString(const TDesC &desc) const
       
  1050 {
       
  1051     return QString::fromUtf16(desc.Ptr(), desc.Length());
       
  1052 }
       
  1053 
       
  1054 /*!
       
  1055     description
       
  1056     
       
  1057     /a
       
  1058     /return
       
  1059 */
       
  1060 QString ExampleAppEnginePrivate::asString8(const TDesC8 &desc) const
       
  1061 {
       
  1062     return QString::fromUtf8((char*)desc.Ptr(), desc.Length());
       
  1063 }
       
  1064 
       
  1065 // End of file