upnpavcontroller/upnpavcontrollerclient/src/upnpavrenderingsessionimpl.cpp
changeset 0 7f85d04be362
equal deleted inserted replaced
-1:000000000000 0:7f85d04be362
       
     1 /*
       
     2 * Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:      implements a session towards a renderer
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 
       
    23 // INCLUDES
       
    24 // upnp stack api
       
    25 #include <upnpitem.h>
       
    26 #include <upnpobjectlist.h>
       
    27 
       
    28 // upnpframework / avcontroller api
       
    29 #include "upnpavdevice.h"
       
    30 #include "upnpavcontrollerglobals.h"
       
    31 #include "upnpavrenderingsessionobserver.h"
       
    32 
       
    33 // avcontroller internal
       
    34 #include "upnpaveventactive.h"
       
    35 #include "upnpavcontrollerclient.h"
       
    36 #include "upnpavdeviceactive.h"
       
    37 #include "upnpavrenderingactive.h"
       
    38 #include "upnpavrenderingsessionimpl.h"
       
    39 
       
    40 _LIT( KComponentLogfile, "upnpavcontrollerclient.txt");
       
    41 #include "upnplog.h"
       
    42 
       
    43 // ======== MEMBER FUNCTIONS ========
       
    44 
       
    45 // --------------------------------------------------------------------------
       
    46 // CUPnPAVRenderingSessionImpl::CUPnPAVRenderingSessionImpl
       
    47 // See upnpavrenderingsessionimpl.h
       
    48 // --------------------------------------------------------------------------
       
    49 CUPnPAVRenderingSessionImpl* CUPnPAVRenderingSessionImpl::NewL( 
       
    50                                             RUPnPAVControllerClient& aServer, 
       
    51                                             const CUpnpAVDevice& aDevice )
       
    52     {
       
    53     CUPnPAVRenderingSessionImpl* self = 
       
    54                         new (ELeave) CUPnPAVRenderingSessionImpl( aServer );
       
    55     CleanupStack::PushL( self );
       
    56     self->iDevice = CUpnpAVDevice::NewL( aDevice );
       
    57     self->ConstructL();
       
    58     CleanupStack::Pop( self );
       
    59     return self;
       
    60     }
       
    61 
       
    62 // --------------------------------------------------------------------------
       
    63 // CUPnPAVRenderingSessionImpl::CUPnPAVRenderingSessionImpl
       
    64 // See upnpavrenderingsessionimpl.h
       
    65 // --------------------------------------------------------------------------
       
    66 CUPnPAVRenderingSessionImpl::CUPnPAVRenderingSessionImpl( 
       
    67                                         RUPnPAVControllerClient& aServer ):
       
    68     iServer( aServer ),
       
    69     iBufferPtr( 0, 0 ),
       
    70     iAlive( ETrue )
       
    71     {
       
    72     }
       
    73 
       
    74 // --------------------------------------------------------------------------
       
    75 // CUPnPAVRenderingSessionImpl::~CUPnPAVRenderingSessionImpl
       
    76 // See upnpavrenderingsessionimpl.h
       
    77 // --------------------------------------------------------------------------
       
    78 CUPnPAVRenderingSessionImpl::~CUPnPAVRenderingSessionImpl()
       
    79     {
       
    80     __LOG( "CUPnPAVRenderingSessionImpl::~CUPnPAVRenderingSessionImpl" );
       
    81     
       
    82     delete iDevice;
       
    83     delete iEventActive;
       
    84     delete iCommandActive;
       
    85     delete iSettingActive;
       
    86     delete iDeviceActive;
       
    87     delete iBuffer; 
       
    88 
       
    89     iServer.DestroyRenderingSession( (TInt)this );
       
    90     }
       
    91 
       
    92 // --------------------------------------------------------------------------
       
    93 // CUPnPAVRenderingSessionImpl::ConstructL
       
    94 // See upnpavrenderingsessionimpl.h
       
    95 // --------------------------------------------------------------------------
       
    96 void CUPnPAVRenderingSessionImpl::ConstructL()
       
    97     {
       
    98     __LOG( "CUPnPAVRenderingSessionImpl::ConstructL" );
       
    99     
       
   100     iBuffer = iDevice->Uuid().AllocL();
       
   101     iBufferPtr.Set( iBuffer->Des() );
       
   102     User::LeaveIfError( iServer.CreateRenderingSession( (TInt)this , 
       
   103                                                         iBufferPtr ) );
       
   104     iEventActive = CUPnPAVEventActive::NewL( iServer, *this );
       
   105     iCommandActive = CUPnPAVRenderingActive::NewL( iServer, (TInt)this );
       
   106     iSettingActive = CUPnPAVRenderingActive::NewL( iServer, (TInt)this );
       
   107     iDeviceActive = CUPnPAVDeviceActive::NewL( iServer, *this );
       
   108     iDeviceActive->StartListening( (TInt)this );
       
   109     }
       
   110 
       
   111 // --------------------------------------------------------------------------
       
   112 // CUPnPAVRenderingSessionImpl::SetObserver
       
   113 // See upnpavrenderingsessionimpl.h
       
   114 // --------------------------------------------------------------------------
       
   115 void CUPnPAVRenderingSessionImpl::SetObserver( 
       
   116                                  MUPnPAVRenderingSessionObserver& aObserver )
       
   117     {
       
   118     // Set the observer and make an async request to the server to receive
       
   119     // device callbacks
       
   120     __ASSERTD( !iObserver, __FILE__, __LINE__ );
       
   121 
       
   122     iEventActive->StartListeningEvents( (TInt)this );        
       
   123         
       
   124     iObserver = &aObserver;
       
   125     iCommandActive->SetObserver( aObserver );
       
   126     iSettingActive->SetObserver( aObserver );
       
   127     }
       
   128 
       
   129 // --------------------------------------------------------------------------
       
   130 // CUPnPAVRenderingSessionImpl::Observer
       
   131 // See upnpavrenderingsessionimpl.h
       
   132 // --------------------------------------------------------------------------
       
   133 MUPnPAVRenderingSessionObserver* CUPnPAVRenderingSessionImpl::Observer() const
       
   134     {
       
   135     return iObserver;
       
   136     }
       
   137 
       
   138 // --------------------------------------------------------------------------
       
   139 // CUPnPAVRenderingSessionImpl::RemoveObserver
       
   140 // See upnpavrenderingsessionimpl.h
       
   141 // --------------------------------------------------------------------------
       
   142 void CUPnPAVRenderingSessionImpl::RemoveObserver()
       
   143     {
       
   144     iObserver = NULL;
       
   145     iCommandActive->RemoveObserver();
       
   146     iSettingActive->RemoveObserver();    
       
   147     iEventActive->Cancel();
       
   148     }
       
   149 
       
   150 // --------------------------------------------------------------------------
       
   151 // CUPnPAVRenderingSessionImpl::Device
       
   152 // See upnpavrenderingsessionimpl.h
       
   153 // --------------------------------------------------------------------------
       
   154 const CUpnpAVDevice& CUPnPAVRenderingSessionImpl::Device() const
       
   155     {
       
   156     return *iDevice;
       
   157     }
       
   158 
       
   159 // --------------------------------------------------------------------------
       
   160 // CUPnPAVRenderingSessionImpl::ReserveLocalMSServicesL
       
   161 // See upnpavrenderingsessionimpl.h
       
   162 // --------------------------------------------------------------------------
       
   163 void CUPnPAVRenderingSessionImpl::ReserveLocalMSServicesL()
       
   164     {  
       
   165     ResetL();
       
   166     
       
   167     iCommandActive->ReserveLocalMSServicesL();       
       
   168     }
       
   169 
       
   170 // --------------------------------------------------------------------------
       
   171 // CUPnPAVRenderingSessionImpl::CancelReserveLocalMSServicesL
       
   172 // See upnpavrenderingsessionimpl.h
       
   173 // --------------------------------------------------------------------------
       
   174 void CUPnPAVRenderingSessionImpl::CancelReserveLocalMSServicesL()
       
   175     {
       
   176     ResetL();
       
   177     
       
   178     iCommandActive->CancelReserveLocalMSServicesL();  
       
   179     }
       
   180 
       
   181 // --------------------------------------------------------------------------
       
   182 // CUPnPAVRenderingSessionImpl::ReleaseLocalMSServicesL
       
   183 // See upnpavrenderingsessionimpl.h
       
   184 // --------------------------------------------------------------------------
       
   185 void CUPnPAVRenderingSessionImpl::ReleaseLocalMSServicesL()
       
   186     {  
       
   187     ResetL();
       
   188     
       
   189     iCommandActive->ReleaseLocalMSServicesL();
       
   190     }
       
   191 
       
   192 // --------------------------------------------------------------------------
       
   193 // CUPnPAVRenderingSessionImpl::SetURIL
       
   194 // See upnpavrenderingsessionimpl.h
       
   195 // --------------------------------------------------------------------------
       
   196 void CUPnPAVRenderingSessionImpl::SetURIL( const TDesC8& aURI,
       
   197     const CUpnpItem& aItem )
       
   198     {
       
   199     ResetL();
       
   200     
       
   201     iCommandActive->SetURIL( aURI, aItem );
       
   202     }
       
   203 
       
   204 // --------------------------------------------------------------------------
       
   205 // CUPnPAVRenderingSessionImpl::SetNextURIL
       
   206 // See upnpavrenderingsessionimpl.h
       
   207 // --------------------------------------------------------------------------
       
   208 void CUPnPAVRenderingSessionImpl::SetNextURIL( const TDesC8& aURI,
       
   209     const CUpnpItem& aItem )    
       
   210     {
       
   211     ResetL();
       
   212     
       
   213     iCommandActive->SetNextURIL( aURI, aItem );     
       
   214     }
       
   215 
       
   216 
       
   217 // --------------------------------------------------------------------------
       
   218 // CUPnPAVRenderingSessionImpl::PlayL
       
   219 // See upnpavrenderingsessionimpl.h
       
   220 // --------------------------------------------------------------------------
       
   221 void CUPnPAVRenderingSessionImpl::PlayL()
       
   222     {
       
   223     ResetL();
       
   224     
       
   225     iCommandActive->PlayL();
       
   226     }
       
   227 
       
   228 // --------------------------------------------------------------------------
       
   229 // CUPnPAVRenderingSessionImpl::StopL
       
   230 // See upnpavrenderingsessionimpl.h
       
   231 // --------------------------------------------------------------------------
       
   232 void CUPnPAVRenderingSessionImpl::StopL()
       
   233     {
       
   234     ResetL();
       
   235     
       
   236     iCommandActive->StopL(); 
       
   237     }
       
   238 
       
   239 // --------------------------------------------------------------------------
       
   240 // CUPnPAVRenderingSessionImpl::PauseL
       
   241 // See upnpavrenderingsessionimpl.h
       
   242 // --------------------------------------------------------------------------
       
   243 void CUPnPAVRenderingSessionImpl::PauseL()
       
   244     {
       
   245     ResetL();
       
   246     
       
   247     iCommandActive->PauseL();   
       
   248     }
       
   249 
       
   250 // --------------------------------------------------------------------------
       
   251 // CUPnPAVRenderingSessionImpl::SetVolumeL
       
   252 // See upnpavrenderingsessionimpl.h
       
   253 // --------------------------------------------------------------------------
       
   254 void CUPnPAVRenderingSessionImpl::SetVolumeL( TInt aVolumeLevel )
       
   255     {
       
   256     ResetL();
       
   257     
       
   258     iSettingActive->SetVolumeL( aVolumeLevel );
       
   259     }
       
   260 
       
   261 // --------------------------------------------------------------------------
       
   262 // CUPnPAVRenderingSessionImpl::GetVolumeL
       
   263 // See upnpavrenderingsessionimpl.h
       
   264 // --------------------------------------------------------------------------
       
   265 void CUPnPAVRenderingSessionImpl::GetVolumeL()
       
   266     {
       
   267     ResetL();
       
   268     
       
   269     iSettingActive->GetVolumeL();
       
   270     }
       
   271 
       
   272 // --------------------------------------------------------------------------
       
   273 // CUPnPAVRenderingSessionImpl::SetMuteL
       
   274 // See upnpavrenderingsessionimpl.h
       
   275 // --------------------------------------------------------------------------
       
   276 void CUPnPAVRenderingSessionImpl::SetMuteL( TBool aMute )
       
   277     {
       
   278     ResetL();
       
   279     
       
   280     iSettingActive->SetMuteL( aMute );
       
   281     }
       
   282 
       
   283 // --------------------------------------------------------------------------
       
   284 // CUPnPAVRenderingSessionImpl::GetMuteL
       
   285 // See upnpavrenderingsessionimpl.h
       
   286 // --------------------------------------------------------------------------
       
   287 void CUPnPAVRenderingSessionImpl::GetMuteL()
       
   288     {
       
   289     ResetL();
       
   290     
       
   291     iSettingActive->GetMuteL();           
       
   292     }
       
   293 
       
   294 // --------------------------------------------------------------------------
       
   295 // CUPnPAVRenderingSessionImpl::GetPositionInfoL
       
   296 // See upnpavrenderingsessionimpl.h
       
   297 // --------------------------------------------------------------------------
       
   298 void CUPnPAVRenderingSessionImpl::GetPositionInfoL()
       
   299     {
       
   300     ResetL();
       
   301     
       
   302     iSettingActive->GetPositionInfoL();               
       
   303     }
       
   304 
       
   305 // --------------------------------------------------------------------------
       
   306 // CUPnPAVRenderingSessionImpl::UPnPDeviceDiscovered
       
   307 // See upnpavrenderingsessionimpl.h
       
   308 // --------------------------------------------------------------------------
       
   309 void CUPnPAVRenderingSessionImpl::UPnPDeviceDiscovered( 
       
   310                                         const CUpnpAVDevice& /*aDevice*/ )
       
   311     {
       
   312     // No implementation needed
       
   313     }
       
   314 
       
   315 // --------------------------------------------------------------------------
       
   316 // CUPnPAVRenderingSessionImpl::UPnPDeviceDisappeared
       
   317 // See upnpavrenderingsessionimpl.h
       
   318 // --------------------------------------------------------------------------
       
   319 void CUPnPAVRenderingSessionImpl::UPnPDeviceDisappeared( 
       
   320                                         const CUpnpAVDevice& /*aDevice*/ )
       
   321     {
       
   322     __LOG( "CUPnPAVRenderingSessionImpl::UPnPDeviceDisappeared" );
       
   323     
       
   324     iAlive = EFalse;
       
   325     if( iObserver )
       
   326         {
       
   327         iObserver->MediaRendererDisappeared(
       
   328             MUPnPAVSessionObserverBase::EDisconnected );
       
   329         }
       
   330     }
       
   331 
       
   332 // --------------------------------------------------------------------------
       
   333 // CUPnPAVRenderingSessionImpl::WLANConnectionLost
       
   334 // See upnpavrenderingsessionimpl.h
       
   335 // --------------------------------------------------------------------------
       
   336 void CUPnPAVRenderingSessionImpl::WLANConnectionLost()
       
   337     {
       
   338     __LOG( "CUPnPAVRenderingSessionImpl::WLANConnectionLost" );
       
   339     
       
   340     iAlive = EFalse;
       
   341     if( iObserver )    
       
   342         {
       
   343         iObserver->MediaRendererDisappeared(
       
   344             MUPnPAVSessionObserverBase::EWLANLost );
       
   345         }
       
   346     
       
   347     }
       
   348 
       
   349 // --------------------------------------------------------------------------
       
   350 // CUPnPAVRenderingSessionImpl::EventReceived
       
   351 // See upnpavrenderingsessionimpl.h
       
   352 // --------------------------------------------------------------------------
       
   353 void CUPnPAVRenderingSessionImpl::EventReceived( TInt aError,
       
   354     TUnsolicitedEventC aEvent )
       
   355     {
       
   356     if( iObserver )
       
   357         {
       
   358         switch( aEvent.iEvent )
       
   359             {
       
   360             case EPlay:
       
   361                 {
       
   362                 iObserver->InteractOperationComplete( aError,
       
   363                     EUPnPAVPlayUser );
       
   364                 break;
       
   365                 }
       
   366             case EPause:
       
   367                 {
       
   368                 iObserver->InteractOperationComplete( aError,
       
   369                     EUPnPAVPauseUser );                
       
   370                 break;
       
   371                 }
       
   372             case EStop:
       
   373                 {
       
   374                 iObserver->InteractOperationComplete( aError,
       
   375                     EUPnPAVStopUser );                
       
   376                 break;
       
   377                 }
       
   378             case EVolume:
       
   379                 {
       
   380                 iObserver->VolumeResult( aError, aEvent.iValue, EFalse );
       
   381                 break;
       
   382                 }
       
   383             case EMute:
       
   384                 {
       
   385                 iObserver->MuteResult( aError, (TBool)aEvent.iValue,
       
   386                     EFalse );
       
   387                 break;
       
   388                 }
       
   389             default:
       
   390                 {
       
   391                 __PANICD( __FILE__, __LINE__ );
       
   392                 break;
       
   393                 }    
       
   394             }
       
   395         }
       
   396     }
       
   397 
       
   398 // --------------------------------------------------------------------------
       
   399 // CUPnPAVRenderingSessionImpl::ResetL
       
   400 // See upnpavrenderingsessionimpl.h
       
   401 // --------------------------------------------------------------------------
       
   402 void CUPnPAVRenderingSessionImpl::ResetL()
       
   403     {
       
   404     __LOG( "CUPnPAVRenderingSessionImpl::ResetL" );
       
   405     
       
   406     if( !iAlive )
       
   407         {
       
   408         __LOG( "ResetL - disconnected, leave " );
       
   409         User::Leave( KErrDisconnected );        
       
   410         }
       
   411 
       
   412     delete iBuffer; iBuffer = NULL;
       
   413     }
       
   414 
       
   415 // end of file