upnp/upnpstack/serviceframework/src/upnpdevicecontenthandler.cpp
changeset 0 f5a58ecadc66
equal deleted inserted replaced
-1:000000000000 0:f5a58ecadc66
       
     1 /** @file
       
     2 * Copyright (c) 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:  Implements the CUpnpDeviceContentHandler class
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 #include "upnpdevicecontenthandler.h"
       
    20 #include "upnpdevice.h"
       
    21 #include "upnpdeviceimplementation.h"
       
    22 #include "upnpsilentdeviceimplementation.h"
       
    23 #include "upnpcontenthandlerscontroller.h"
       
    24 #include "upnprootcontenthandler.h"
       
    25 #include "upnpdeviceliterals.h"
       
    26 
       
    27 // -----------------------------------------------------------------------------
       
    28 // CUpnpDeviceContentHandler::NewL
       
    29 // Two-phased constructor that will parse CUpnpDevice object. If aResultDevice 
       
    30 // is NULL the result object will be created during the parsing, and will be 
       
    31 // owned by this CUpnpDeviceContentHandler.
       
    32 // Otherwise result will be parsed to existing aResultDevice object
       
    33 // -----------------------------------------------------------------------------
       
    34 //
       
    35 CUpnpDeviceContentHandler* CUpnpDeviceContentHandler::NewL(
       
    36     CUpnpContentHandlersController& aController, CUpnpDevice* aResultDevice )
       
    37     {
       
    38     CUpnpDeviceContentHandler* deviceContentHandler = 
       
    39         CUpnpDeviceContentHandler::NewLC( aController, aResultDevice );
       
    40     CleanupStack::Pop( deviceContentHandler );
       
    41     return deviceContentHandler;
       
    42     }
       
    43 
       
    44 // -----------------------------------------------------------------------------
       
    45 // CUpnpDeviceContentHandler::NewLC
       
    46 // Two-phased constructor that will parse CUpnpDevice object. If aResultDevice 
       
    47 // is NULL the result object will be created during the parsing, and will be 
       
    48 // owned by this CUpnpDeviceContentHandler.
       
    49 // Otherwise result will be parsed to existing aResultDevice object.
       
    50 // Leaves the object on the CleanupStack
       
    51 // -----------------------------------------------------------------------------
       
    52 //
       
    53 CUpnpDeviceContentHandler* CUpnpDeviceContentHandler::NewLC(
       
    54     CUpnpContentHandlersController& aController, CUpnpDevice* aResultDevice )
       
    55     {
       
    56     CUpnpDeviceContentHandler* deviceContentHandler = 
       
    57         new (ELeave) CUpnpDeviceContentHandler( aController, aResultDevice );
       
    58     CleanupStack::PushL( deviceContentHandler );
       
    59     return deviceContentHandler;
       
    60     }
       
    61 
       
    62 // -----------------------------------------------------------------------------
       
    63 // CUpnpDeviceContentHandler::NewL
       
    64 // Two-phased constructor that will parse CUpnpDeviceImplementation object. If 
       
    65 // aResultDeviceImpl is NULL the result object will be created during the parsing, 
       
    66 // and will be owned by this CUpnpDeviceContentHandler.
       
    67 // Otherwise result will be parsed to existing aResultDevice object.
       
    68 // -----------------------------------------------------------------------------
       
    69 //
       
    70 CUpnpDeviceContentHandler* CUpnpDeviceContentHandler::NewL(
       
    71     CUpnpContentHandlersController& aController,
       
    72     CUpnpDeviceImplementation* aResultDeviceImpl )
       
    73     {
       
    74     CUpnpDeviceContentHandler* deviceContentHandler = 
       
    75         CUpnpDeviceContentHandler::NewLC( aController, aResultDeviceImpl );
       
    76     CleanupStack::Pop( deviceContentHandler );
       
    77     return deviceContentHandler;
       
    78     }
       
    79 
       
    80 // -----------------------------------------------------------------------------
       
    81 // CUpnpDeviceContentHandler::NewLC
       
    82 // Two-phased constructor that will parse CUpnpDeviceImplementation object. If 
       
    83 // aResultDeviceImpl is NULL the result object will be created during the parsing, 
       
    84 // and will be owned by this CUpnpDeviceContentHandler.
       
    85 // Otherwise result will be parsed to existing aResultDevice object.
       
    86 // Leaves the object on the CleanupStack
       
    87 // -----------------------------------------------------------------------------
       
    88 //
       
    89 CUpnpDeviceContentHandler* CUpnpDeviceContentHandler::NewLC(
       
    90     CUpnpContentHandlersController& aController,
       
    91     CUpnpDeviceImplementation* aResultDeviceImpl )
       
    92     {
       
    93     CUpnpDeviceContentHandler* deviceContentHandler = 
       
    94         new (ELeave) CUpnpDeviceContentHandler( aController, aResultDeviceImpl );
       
    95     CleanupStack::PushL( deviceContentHandler );
       
    96     return deviceContentHandler;
       
    97     }
       
    98 
       
    99 
       
   100 // -----------------------------------------------------------------------------
       
   101 // CUpnpDeviceContentHandler::NewL
       
   102 // Two-phased constructor that will parse CUpnpSilentDeviceImplementation object. If 
       
   103 // aResultSilentDeviceImpl is NULL the result object will be created during the parsing, 
       
   104 // and will be owned by this CUpnpDeviceContentHandler.
       
   105 // Otherwise result will be parsed to existing aResultDevice object.
       
   106 // -----------------------------------------------------------------------------
       
   107 //
       
   108 CUpnpDeviceContentHandler* CUpnpDeviceContentHandler::NewL(
       
   109     CUpnpContentHandlersController& aController,
       
   110     CUpnpSilentDeviceImplementation* aResultSilentDeviceImpl )
       
   111     {
       
   112     CUpnpDeviceContentHandler* deviceContentHandler = 
       
   113         CUpnpDeviceContentHandler::NewLC( aController, aResultSilentDeviceImpl );
       
   114     CleanupStack::Pop( deviceContentHandler );
       
   115     return deviceContentHandler;
       
   116     }
       
   117 
       
   118 // -----------------------------------------------------------------------------
       
   119 // CUpnpDeviceContentHandler::NewLC
       
   120 // Two-phased constructor that will parse CUpnpSilentDeviceImplementation object. If 
       
   121 // aResultDeviceImpl is NULL the result object will be created during the parsing, 
       
   122 // and will be owned by this CUpnpDeviceContentHandler.
       
   123 // Otherwise result will be parsed to existing aResultDevice object.
       
   124 // Leaves the object on the CleanupStack
       
   125 // -----------------------------------------------------------------------------
       
   126 //
       
   127 CUpnpDeviceContentHandler* CUpnpDeviceContentHandler::NewLC(
       
   128     CUpnpContentHandlersController& aController,
       
   129     CUpnpSilentDeviceImplementation* aResultSilentDeviceImpl )
       
   130     {
       
   131     CUpnpDeviceContentHandler* deviceContentHandler = 
       
   132         new (ELeave) CUpnpDeviceContentHandler( aController, aResultSilentDeviceImpl );
       
   133     CleanupStack::PushL( deviceContentHandler );
       
   134     return deviceContentHandler;
       
   135     }
       
   136     
       
   137 // -----------------------------------------------------------------------------
       
   138 // CUpnpDeviceContentHandler::~CUpnpDeviceContentHandler
       
   139 // Destructor of CUpnpDeviceContentHandler class 
       
   140 // -----------------------------------------------------------------------------
       
   141 //
       
   142 CUpnpDeviceContentHandler::~CUpnpDeviceContentHandler()
       
   143     {
       
   144     if ( iIsDeviceOwned )
       
   145         {
       
   146         ASSERT( ( EDevice == iParseType && NULL == iResultDeviceImpl && NULL == iResultSilentDeviceImpl ) ||
       
   147                 ( EDeviceImpl == iParseType && NULL == iResultDevice && NULL == iResultSilentDeviceImpl ) ||  
       
   148                ( ESilentDeviceImpl == iParseType && NULL == iResultDevice && NULL == iResultDeviceImpl ) );
       
   149         //check if object is in legal state (class invariants)
       
   150         delete iResultDevice;
       
   151         delete iResultDeviceImpl;
       
   152         delete iResultSilentDeviceImpl;
       
   153         }
       
   154     }
       
   155 
       
   156 // -----------------------------------------------------------------------------
       
   157 // CUpnpDeviceContentHandler::CUpnpDeviceContentHandler
       
   158 // Constructor that will parse CUpnpDevice object. If aResultDevice is NULL
       
   159 // the result object will be created during the parsing, and will be owned by
       
   160 // this CUpnpDeviceContentHandler.
       
   161 // Otherwise result will be parsed to existing aResultDevice object
       
   162 // -----------------------------------------------------------------------------
       
   163 //
       
   164 CUpnpDeviceContentHandler::CUpnpDeviceContentHandler(
       
   165     CUpnpContentHandlersController& aController, CUpnpDevice* aResultDevice ) :
       
   166     CUpnpContentHandler( aController ), iResultDevice( aResultDevice ),
       
   167             iIsDeviceOwned( NULL == aResultDevice), iParseType( EDevice )
       
   168     {
       
   169     }
       
   170 
       
   171 // -----------------------------------------------------------------------------
       
   172 // CUpnpDeviceContentHandler::CUpnpDeviceContentHandler
       
   173 // Constructor that will parse CUpnpDeviceImplementation object. 
       
   174 // If aResultDeviceImpl is NULL the result object will be created during the 
       
   175 // parsing, and will be owned by this CUpnpDeviceContentHandler.
       
   176 // Otherwise result will be parsed to existing aResultDeviceImpl object
       
   177 // -----------------------------------------------------------------------------
       
   178 //
       
   179 CUpnpDeviceContentHandler::CUpnpDeviceContentHandler(
       
   180     CUpnpContentHandlersController& aController,
       
   181     CUpnpDeviceImplementation* aResultDeviceImpl ) :
       
   182     CUpnpContentHandler( aController ), iResultDeviceImpl( aResultDeviceImpl ),
       
   183             iIsDeviceOwned( NULL == aResultDeviceImpl),
       
   184             iParseType( EDeviceImpl )
       
   185     {
       
   186     }
       
   187     
       
   188 // -----------------------------------------------------------------------------
       
   189 // CUpnpDeviceContentHandler::CUpnpDeviceContentHandler
       
   190 // Constructor that will parse CUpnpSilentDeviceImplementation object. 
       
   191 // If aResultSilentDeviceImpl is NULL the result object will be created during the 
       
   192 // parsing, and will be owned by this CUpnpDeviceContentHandler.
       
   193 // Otherwise result will be parsed to existing aResultDeviceImpl object
       
   194 // -----------------------------------------------------------------------------
       
   195 //
       
   196 CUpnpDeviceContentHandler::CUpnpDeviceContentHandler(
       
   197     CUpnpContentHandlersController& aController,
       
   198     CUpnpSilentDeviceImplementation* aResultSilentDeviceImpl ) :
       
   199     CUpnpContentHandler( aController ), iResultSilentDeviceImpl( aResultSilentDeviceImpl ),
       
   200             iIsDeviceOwned( NULL == aResultSilentDeviceImpl ),
       
   201             iParseType( ESilentDeviceImpl )
       
   202     {
       
   203     }    
       
   204 
       
   205 // -----------------------------------------------------------------------------
       
   206 // CUpnpDeviceContentHandler::OnStartElementL
       
   207 // This method is a callback to indicate an element has been parsed.
       
   208 // -----------------------------------------------------------------------------
       
   209 //
       
   210 void CUpnpDeviceContentHandler::OnStartElementL( const RTagInfo& aElement,
       
   211     const RAttributeArray& /*aAttributes*/)
       
   212     {
       
   213     if ( aElement.LocalName().DesC().Compare( KUpnpDeviceRoot )==0 )
       
   214         {
       
   215         CUpnpRootContentHandler* rootCH = NULL;
       
   216         if ( iIsDeviceOwned )
       
   217             {
       
   218             switch ( iParseType )
       
   219                 {
       
   220                 case EDeviceImpl:
       
   221                     delete iResultDeviceImpl;
       
   222                     iResultDeviceImpl = NULL;
       
   223                     iResultDeviceImpl = new (ELeave) CUpnpDeviceImplementation();
       
   224                     break;
       
   225                 case ESilentDeviceImpl:
       
   226                     delete iResultSilentDeviceImpl;
       
   227                     iResultSilentDeviceImpl = NULL;
       
   228                     iResultSilentDeviceImpl = new (ELeave) CUpnpSilentDeviceImplementation();
       
   229                     break;
       
   230                 case EDevice:
       
   231                     delete iResultDevice;
       
   232                     iResultDevice = NULL;
       
   233                     iResultDevice = new (ELeave) CUpnpDevice();
       
   234                     break;
       
   235                 default:
       
   236                     _LIT( KPanicString, "CUpnpDeviceContentHandler::OnStartElementL" );
       
   237                     User::Panic( KPanicString, 1 );  
       
   238                 }
       
   239             }
       
   240         if ( iParseType == EDeviceImpl )
       
   241             {
       
   242             rootCH = CUpnpRootContentHandler::NewL( iController,
       
   243                 *iResultDeviceImpl, EDeviceImpl );
       
   244             }
       
   245         else if ( iParseType == ESilentDeviceImpl )    
       
   246             {
       
   247             rootCH = CUpnpRootContentHandler::NewL( iController,
       
   248                 *iResultSilentDeviceImpl, ESilentDeviceImpl );
       
   249             }
       
   250         else
       
   251             {
       
   252             rootCH = CUpnpRootContentHandler::NewL( iController,
       
   253                 *iResultDevice, EDevice );
       
   254             }
       
   255         iController.SetCurrentContentHandlerL( rootCH );
       
   256         }
       
   257     else
       
   258         {
       
   259         User::Leave( KErrArgument ); //wrong root node
       
   260         }
       
   261     }
       
   262 
       
   263 // -----------------------------------------------------------------------------
       
   264 // CUpnpDeviceContentHandler::OnEndElementL
       
   265 // This method is a callback to indicate the end of the element has been reached.
       
   266 // -----------------------------------------------------------------------------
       
   267 //
       
   268 void CUpnpDeviceContentHandler::OnEndElementL( const RTagInfo& /*aElement*/)
       
   269     {
       
   270     }
       
   271 
       
   272 // -----------------------------------------------------------------------------
       
   273 // CUpnpServiceContentHandler::OnContentL
       
   274 // This method is a callback that sends the content of the element.
       
   275 // -----------------------------------------------------------------------------
       
   276 //
       
   277 void CUpnpDeviceContentHandler::OnContentL( const TDesC8& /*aBytes*/)
       
   278     {
       
   279     }
       
   280 
       
   281 // -----------------------------------------------------------------------------
       
   282 // CUpnpDeviceContentHandler::GetResultDevice
       
   283 // Returns parsed CUpnpDevice object, and pass ownership to the caller.
       
   284 // One shouldn't call this method if CUpnpDeviceContentHandler doesn't have
       
   285 // ownership CUpnpDevice object.
       
   286 // @see GetResultDevice( CUpnpDeviceImplementation*& aResultDeviceImpl )
       
   287 // -----------------------------------------------------------------------------
       
   288 //
       
   289 void CUpnpDeviceContentHandler::GetResultDevice( CUpnpDevice*& aResultDevice )
       
   290     {
       
   291     ASSERT( iIsDeviceOwned && iParseType==EDevice );
       
   292     aResultDevice = iResultDevice;
       
   293     iIsDeviceOwned = EFalse;
       
   294     iResultDevice = NULL;
       
   295     }
       
   296 
       
   297 // -----------------------------------------------------------------------------
       
   298 // CUpnpDeviceContentHandler::GetResultDevice
       
   299 // Returns parsed CUpnpDeviceImplementation object, and pass ownership to the caller.
       
   300 // One shouldn't call this method if CUpnpDeviceContentHandler doesn't have
       
   301 // ownership CUpnpDeviceImplementation object.
       
   302 // @see GetResultDevice( CUpnpDevice*& aResultDeviceImpl )
       
   303 // -----------------------------------------------------------------------------
       
   304 //
       
   305 void CUpnpDeviceContentHandler::GetResultDevice(
       
   306     CUpnpDeviceImplementation*& aResultDeviceImpl )
       
   307     {
       
   308     ASSERT( iIsDeviceOwned && iParseType==EDeviceImpl );
       
   309     aResultDeviceImpl = iResultDeviceImpl;
       
   310     iIsDeviceOwned = EFalse;
       
   311     iResultDeviceImpl = NULL;
       
   312     }
       
   313     
       
   314 // -----------------------------------------------------------------------------
       
   315 // CUpnpDeviceContentHandler::GetResultDevice
       
   316 // Returns parsed CUpnpSilentDeviceImplementation object, and pass ownership to the caller.
       
   317 // One shouldn't call this method if CUpnpDeviceContentHandler doesn't have
       
   318 // ownership CUpnpSilentDeviceImplementation object.
       
   319 // @see GetResultDevice( CUpnpDevice*& aResultSilentDeviceImpl )
       
   320 // -----------------------------------------------------------------------------
       
   321 //
       
   322 void CUpnpDeviceContentHandler::GetResultDevice(
       
   323     CUpnpSilentDeviceImplementation*& aResultSilentDeviceImpl )
       
   324     {
       
   325     ASSERT( iIsDeviceOwned && iParseType==ESilentDeviceImpl );
       
   326     aResultSilentDeviceImpl = iResultSilentDeviceImpl;
       
   327     iIsDeviceOwned = EFalse;
       
   328     iResultSilentDeviceImpl = NULL;
       
   329     }
       
   330 
       
   331 //  End of File