upnpavcontroller/upnpavcontrollerserver/src/upnpavcontrolpoint.cpp
branchIOP_Improvements
changeset 40 08b5eae9f9ff
child 44 97caed2372ca
equal deleted inserted replaced
39:6369bfd1b60d 40:08b5eae9f9ff
       
     1 /** @file
       
     2 * Copyright (c) 2005-2009 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:  CUpnpAVControlPoint
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "upnpavcontrolpoint.h"
       
    21 #include "upnpavcontrolpointobserver.h"
       
    22 
       
    23 #include <upnpdevice.h>
       
    24 
       
    25 _LIT( KComponentLogfile, "upnpavcontrollerserver.txt" );
       
    26 #include "upnplog.h"
       
    27 
       
    28 // -----------------------------------------------------------------------------
       
    29 // CUpnpAVControlPoint::NewL
       
    30 // Two-phased constructor.
       
    31 // -----------------------------------------------------------------------------
       
    32 //
       
    33 CUpnpAVControlPoint* CUpnpAVControlPoint::NewL(
       
    34             MUpnpAVControlPointObserver& aAVControlPointObserver )
       
    35     {
       
    36     CUpnpAVControlPoint* self = 
       
    37         new (ELeave) CUpnpAVControlPoint( aAVControlPointObserver );    
       
    38     CleanupStack::PushL( self );
       
    39     self->ConstructL();
       
    40     CleanupStack::Pop( self );
       
    41     return self;
       
    42     }
       
    43 
       
    44 // -----------------------------------------------------------------------------
       
    45 // CUpnpAVControlPoint::CUpnpAVControlPoint
       
    46 // C++ default constructor can NOT contain any code, that
       
    47 // might leave.
       
    48 // -----------------------------------------------------------------------------
       
    49 //
       
    50 CUpnpAVControlPoint::CUpnpAVControlPoint(
       
    51      MUpnpAVControlPointObserver& aAVControlPointObserver)
       
    52                 : CUpnpControlPoint(),
       
    53                   iAVControlPointObserver(aAVControlPointObserver)
       
    54     {
       
    55     }
       
    56 
       
    57 // -----------------------------------------------------------------------------
       
    58 // CUpnpStateUpdateHandler::ConstructL
       
    59 // Symbian 2nd phase constructor can leave.
       
    60 // -----------------------------------------------------------------------------
       
    61 //
       
    62 void CUpnpAVControlPoint::ConstructL( )
       
    63     {
       
    64     }
       
    65 
       
    66 // -----------------------------------------------------------------------------
       
    67 // CUpnpAVControlPoint::~CUpnpAVControlPoint
       
    68 // Destructor
       
    69 // -----------------------------------------------------------------------------
       
    70 //
       
    71 CUpnpAVControlPoint::~CUpnpAVControlPoint()
       
    72     {
       
    73     }
       
    74 
       
    75 // -----------------------------------------------------------------------------
       
    76 // CUpnpAVControlPoint::Service
       
    77 // This function returns a pointer to appropriate service instance.
       
    78 // (other items were commented in a header)
       
    79 // -----------------------------------------------------------------------------
       
    80 //
       
    81 CUpnpService* CUpnpAVControlPoint::Service( 
       
    82         const CUpnpDevice* aDevice,
       
    83         const TDesC8& aServiceType )
       
    84     {
       
    85     __ASSERT( aDevice, __FILE__, __LINE__ );
       
    86     
       
    87     // CUpnpDevice::ServiceList() is non-const method (for some reason). 
       
    88     CUpnpDevice* dev = const_cast<CUpnpDevice*>(aDevice);
       
    89     RPointerArray<CUpnpService>& services = dev->ServiceList();
       
    90     
       
    91     for( TInt i(0); i < services.Count(); i++ )
       
    92         {
       
    93         if( services[i]->ServiceType().Match( aServiceType )!= KErrNotFound )
       
    94             {
       
    95             return services[i];
       
    96             }
       
    97         }
       
    98     return NULL;
       
    99     }
       
   100 
       
   101 // -----------------------------------------------------------------------------
       
   102 // CUpnpAVControlPoint::CreateActionLC
       
   103 // Creates new action object.
       
   104 // (other items were commented in a header)
       
   105 // -----------------------------------------------------------------------------
       
   106 //
       
   107 CUpnpAction* CUpnpAVControlPoint::CreateActionLC( 
       
   108         const CUpnpDevice* aDevice, 
       
   109         const TDesC8& aServiceType,
       
   110         const TDesC8& aActionName )
       
   111     {
       
   112     // Tries to find CUpnpService from given device with given
       
   113     // service type.
       
   114     CUpnpService* service = Service( aDevice, aServiceType );
       
   115     if ( !service ) 
       
   116         {
       
   117         // Service not found.
       
   118         User::Leave( KErrUnknown );
       
   119         }
       
   120     
       
   121     // Creates the action with given action name.
       
   122     // Note! If service doesn't include action, it return NULL.
       
   123     // CUpnpService::CreateActionLC leaves only if creation of 
       
   124     // found action leaves.
       
   125     CUpnpAction* action = service->CreateActionLC( aActionName );
       
   126     if ( !action ) 
       
   127         {
       
   128         // Action not found.
       
   129         User::Leave( KErrGeneral );
       
   130         }
       
   131     
       
   132     return action;
       
   133     }
       
   134 
       
   135 // -----------------------------------------------------------------------------
       
   136 // CUpnpAVControlPoint::StartUpL
       
   137 // (other items were commented in a header)
       
   138 // -----------------------------------------------------------------------------
       
   139 //
       
   140 void CUpnpAVControlPoint::StartUpL()
       
   141     {
       
   142     //_LIT8( KMediaServer, "urn:schemas-upnp-org:device:MediaServer" );
       
   143     _LIT8( KMediaRenderer, "urn:schemas-upnp-org:device:MediaRenderer" );
       
   144 
       
   145     CDesC8ArrayFlat* targetDeviceTypes = new(ELeave) CDesC8ArrayFlat(1);
       
   146     CleanupStack::PushL( targetDeviceTypes );
       
   147     // We only have push use case, no need to ask stack to find media servers: 
       
   148     //targetDeviceTypes->AppendL( KMediaServer() );
       
   149     targetDeviceTypes->AppendL( KMediaRenderer() );    
       
   150     CUpnpControlPoint::ConstructL( *targetDeviceTypes );
       
   151     CleanupStack::Pop( targetDeviceTypes );
       
   152     targetDeviceTypes->Reset();
       
   153     delete targetDeviceTypes; 
       
   154     targetDeviceTypes = NULL;
       
   155 
       
   156     TPtrC8 devicePtr;
       
   157     devicePtr.Set( UpnpSSDP::KUPnPRootDevice );
       
   158     SearchL( devicePtr );
       
   159     }
       
   160 
       
   161 // -----------------------------------------------------------------------------
       
   162 // CUpnpAVControlPoint::DeviceDiscoveredL
       
   163 // This function implements an inteface and notifies an observer.
       
   164 // (other items were commented in a header)
       
   165 // -----------------------------------------------------------------------------
       
   166 //
       
   167 void CUpnpAVControlPoint::DeviceDiscoveredL( CUpnpDevice* aDevice )
       
   168     {
       
   169     iAVControlPointObserver.DeviceDiscoveredL( aDevice );
       
   170     }
       
   171 
       
   172 // -----------------------------------------------------------------------------
       
   173 // CUpnpAVControlPoint::DeviceDisappearedL
       
   174 // This function implements an inteface and notifies an observer.
       
   175 // (other items were commented in a header)
       
   176 // -----------------------------------------------------------------------------
       
   177 //
       
   178 void CUpnpAVControlPoint::DeviceDisappearedL( CUpnpDevice* aDevice )
       
   179     {    
       
   180     iAVControlPointObserver.DeviceDisappearedL(aDevice);
       
   181     }
       
   182 
       
   183 // -----------------------------------------------------------------------------
       
   184 // CUpnpAVControlPoint::ActionResponseReceivedL
       
   185 // This function ralizes an interface. Functionality is located in separate 
       
   186 // handler class.
       
   187 // (other items were commented in a header)
       
   188 // -----------------------------------------------------------------------------
       
   189 //
       
   190 void CUpnpAVControlPoint::ActionResponseReceivedL( CUpnpAction* aAction )
       
   191     {
       
   192     iAVControlPointObserver.ActionResponseL( aAction );
       
   193     }
       
   194 
       
   195 // -----------------------------------------------------------------------------
       
   196 // CUpnpAVControlPoint::StateUpdatedL
       
   197 // This function implements an inteface and forwards request 
       
   198 // to stateupdate handler.
       
   199 // (other items were commented in a header)
       
   200 // -----------------------------------------------------------------------------
       
   201 //
       
   202 void CUpnpAVControlPoint::StateUpdatedL( CUpnpService* aService )
       
   203     {
       
   204     iAVControlPointObserver.StateUpdatedL( aService );
       
   205     }
       
   206 
       
   207 // -----------------------------------------------------------------------------
       
   208 // CUpnpAVControlPoint::HttpResponseReceivedL
       
   209 // This function implements an inteface and notifies an observer.
       
   210 // (other items were commented in a header)
       
   211 // -----------------------------------------------------------------------------
       
   212 //
       
   213 void CUpnpAVControlPoint::HttpResponseReceivedL( 
       
   214         CUpnpHttpMessage* aMessage )
       
   215     {    
       
   216     iAVControlPointObserver.HttpResponseL( aMessage );
       
   217     }
       
   218 
       
   219 
       
   220 // -----------------------------------------------------------------------------
       
   221 // CUpnpAVControlPoint::NetworkEvent
       
   222 // -----------------------------------------------------------------------------
       
   223 //
       
   224 void CUpnpAVControlPoint::NetworkEvent( CUpnpNetworkEventBase* aEvent )
       
   225     {
       
   226     CUpnpControlPoint::NetworkEvent( aEvent );                
       
   227     TRAP_IGNORE( SearchL( UpnpSSDP::KUPnPRootDevice ) );
       
   228     }    
       
   229 
       
   230 //end of file