upnp/upnpstack/serviceframework/src/upnprootcontenthandler.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 CUpnpRootContentHandler class
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 #include "upnprootcontenthandler.h"
       
    20 #include "upnpdevice.h"
       
    21 #include "upnpcontenthandlerscontroller.h"
       
    22 #include "upnpdevicetagcontenthandler.h"
       
    23 #include "upnpdeviceliterals.h"
       
    24 
       
    25 const TUint8 KReqiuredTagsBoundary(1); //first bit    //specVersion ignored now
       
    26 enum TFlagsPositions
       
    27     {
       
    28     EDevicePos = 0,
       
    29     //ESpecVersion, required but ignored for now...
       
    30     EURLBasePos //optional
       
    31     };
       
    32 
       
    33 // -----------------------------------------------------------------------------
       
    34 // CUpnpRootContentHandler::NewL
       
    35 // Two-phased constructor
       
    36 // -----------------------------------------------------------------------------
       
    37 //
       
    38 CUpnpRootContentHandler* CUpnpRootContentHandler::NewL(
       
    39     CUpnpContentHandlersController& aController, CUpnpDevice& aResultDevice,
       
    40     TParseType aParseType )
       
    41     {
       
    42     CUpnpRootContentHandler* rootContentHandler = 
       
    43         CUpnpRootContentHandler::NewLC( aController, aResultDevice, aParseType );
       
    44     CleanupStack::Pop( rootContentHandler );
       
    45     return rootContentHandler;
       
    46     }
       
    47 
       
    48 // -----------------------------------------------------------------------------
       
    49 // CUpnpRootContentHandler::NewLC
       
    50 // Two-phased constructor. Leaves teh object on the CleanupStack
       
    51 // -----------------------------------------------------------------------------
       
    52 //
       
    53 CUpnpRootContentHandler* CUpnpRootContentHandler::NewLC(
       
    54     CUpnpContentHandlersController& aController, CUpnpDevice& aResultDevice,
       
    55     TParseType aParseType )
       
    56     {
       
    57     CUpnpRootContentHandler* rootContentHandler = 
       
    58         new (ELeave) CUpnpRootContentHandler( aController, aResultDevice,
       
    59                 aParseType );
       
    60     CleanupStack::PushL( rootContentHandler );
       
    61     return rootContentHandler;
       
    62     }
       
    63 
       
    64 // -----------------------------------------------------------------------------
       
    65 // CUpnpRootContentHandler::~CUpnpRootContentHandler
       
    66 // Destructor of CUpnpRootContentHandler class 
       
    67 // -----------------------------------------------------------------------------
       
    68 //
       
    69 CUpnpRootContentHandler::~CUpnpRootContentHandler()
       
    70     {
       
    71     }
       
    72 
       
    73 // -----------------------------------------------------------------------------
       
    74 // CUpnpRootContentHandler::CUpnpRootContentHandler
       
    75 // Constructor
       
    76 // -----------------------------------------------------------------------------
       
    77 //
       
    78 CUpnpRootContentHandler::CUpnpRootContentHandler(
       
    79     CUpnpContentHandlersController& aController, CUpnpDevice& aResultDevice,
       
    80     TParseType aParseType ) :
       
    81     CUpnpContentHandler( aController ), iResultDevice( aResultDevice ),
       
    82             iCurrentState( EInitial ), iParseType( aParseType )
       
    83     {
       
    84     }
       
    85 
       
    86 // -----------------------------------------------------------------------------
       
    87 // CUpnpRootContentHandler::OnStartElementL
       
    88 // This method is a callback to indicate an element has been parsed.
       
    89 // -----------------------------------------------------------------------------
       
    90 //
       
    91 void CUpnpRootContentHandler::OnStartElementL( const RTagInfo& aElement,
       
    92     const RAttributeArray& /*aAttributes*/)
       
    93     {
       
    94     if ( EInitial == iCurrentState )
       
    95         {
       
    96         if ( aElement.LocalName().DesC().Compare( KUpnpDevice )==0 )
       
    97             {
       
    98             RepeatedTagCheckL( EDevicePos, iFoundTags );
       
    99             iController.SetCurrentContentHandlerL( CUpnpDeviceTagContentHandler::NewL(
       
   100                 iController, iResultDevice, iParseType ) );
       
   101             }
       
   102         else
       
   103             if ( aElement.LocalName().DesC().Compare( KUpnpURLBase )==0 )
       
   104                 {
       
   105                 //RepeatedTagCheckL( EURLBasePos, iFoundTags )  NIY
       
   106                 iCurrentState = EURLBase;
       
   107                 }
       
   108             else
       
   109                 {
       
   110                 SetIgnoreHandlerL();
       
   111                 }
       
   112         }
       
   113     else
       
   114         {
       
   115         ASSERT( EURLBase == iCurrentState );
       
   116         //User::Leave(KErrArgument)  //content="textonly"
       
   117         SetIgnoreHandlerL();
       
   118         }
       
   119     }
       
   120 
       
   121 // -----------------------------------------------------------------------------
       
   122 // CUpnpRootContentHandler::OnEndElementL
       
   123 // This method is a callback to indicate the end of the element has been reached.
       
   124 // -----------------------------------------------------------------------------
       
   125 //
       
   126 void CUpnpRootContentHandler::OnEndElementL( const RTagInfo& aElement )
       
   127     {
       
   128     switch ( iCurrentState )
       
   129         {
       
   130         case EInitial:
       
   131             ASSERT( aElement.LocalName().DesC().Compare( KUpnpDeviceRoot ) == 0 );
       
   132             if ( (iFoundTags.iFlags & KReqiuredTagsBoundary)
       
   133                     == KReqiuredTagsBoundary )
       
   134                 {
       
   135                 iController.SetPreviousContentHandler();
       
   136                 }
       
   137             else
       
   138                 {
       
   139                 User::Leave( KErrArgument ); //required tag not found
       
   140                 }
       
   141             break;
       
   142         default:
       
   143             iCurrentState = EInitial;
       
   144         }
       
   145     }
       
   146 
       
   147 // -----------------------------------------------------------------------------
       
   148 // CUpnpRootContentHandler::OnContentL
       
   149 // This method is a callback that sends the content of the element.
       
   150 // aErrorCode must be KErrNone, and that aBytes should contains complete
       
   151 // content (one chunk).
       
   152 // -----------------------------------------------------------------------------
       
   153 //
       
   154 void CUpnpRootContentHandler::OnContentL( const TDesC8& aBytes )
       
   155     {
       
   156     switch ( iCurrentState )
       
   157         {
       
   158         case EURLBase:
       
   159             iResultDevice.SetUrlBaseL( aBytes );
       
   160             break;
       
   161         default:
       
   162             //User::Leave(KErrArgument)  
       
   163             break;
       
   164         }
       
   165     }
       
   166 
       
   167 //  End of File