upnp/upnpstack/serviceframework/src/upnpstatevariablecontenthandler.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 CUpnpActionContentHandler class
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 #include "upnpstatevariablecontenthandler.h"
       
    20 #include "upnpcontenthandlerscontroller.h"
       
    21 #include "upnpignorecontenthandler.h"
       
    22 #include "upnpallowedvaluerangecontenthandler.h"
       
    23 #include "upnpallowedvaluelistcontenthandler.h"
       
    24 #include "upnpstatevariable.h"
       
    25 #include "upnpserviceliterals.h"
       
    26 
       
    27 const TUint8 KReqiuredTagsBoundary(3); //first two bits
       
    28 enum TFlagsPositions
       
    29     {
       
    30     ENamePos = 0,
       
    31     EDataTypePos,
       
    32     EDefaultValuePos, //optional
       
    33     EAllowedValuePos //optional, AllowedValueList or AllowedValueRange
       
    34     };
       
    35 
       
    36 // -----------------------------------------------------------------------------
       
    37 // CUpnpStateVariableContentHandler::NewL
       
    38 // Two-phased constructor
       
    39 // -----------------------------------------------------------------------------
       
    40 //
       
    41 CUpnpStateVariableContentHandler* CUpnpStateVariableContentHandler::NewL(
       
    42     CUpnpContentHandlersController& aController,
       
    43     CUpnpStateVariable& aResultStateVariable )
       
    44     {
       
    45     CUpnpStateVariableContentHandler* actionContentHandler = 
       
    46         CUpnpStateVariableContentHandler::NewLC( aController, aResultStateVariable );
       
    47     CleanupStack::Pop( actionContentHandler );
       
    48     return actionContentHandler;
       
    49     }
       
    50 
       
    51 // -----------------------------------------------------------------------------
       
    52 // CUpnpStateVariableContentHandler::NewLC
       
    53 // Two-phased constructor. Leaves teh object on the CleanupStack
       
    54 // -----------------------------------------------------------------------------
       
    55 //
       
    56 CUpnpStateVariableContentHandler* CUpnpStateVariableContentHandler::NewLC(
       
    57     CUpnpContentHandlersController& aController,
       
    58     CUpnpStateVariable& aResultStateVariable )
       
    59     {
       
    60     CUpnpStateVariableContentHandler* actionContentHandler = 
       
    61         new (ELeave) CUpnpStateVariableContentHandler( aController, 
       
    62             aResultStateVariable );
       
    63     CleanupStack::PushL( actionContentHandler );
       
    64     return actionContentHandler;
       
    65     }
       
    66 
       
    67 // -----------------------------------------------------------------------------
       
    68 // CUpnpStateVariableContentHandler::~CUpnpStateVariableContentHandler
       
    69 // Destructor of CUpnpStateVariableContentHandler class 
       
    70 // -----------------------------------------------------------------------------
       
    71 //
       
    72 CUpnpStateVariableContentHandler::~CUpnpStateVariableContentHandler()
       
    73     {
       
    74     }
       
    75 
       
    76 // -----------------------------------------------------------------------------
       
    77 // CUpnpStateVariableContentHandler::CUpnpStateVariableContentHandler
       
    78 // Constructor
       
    79 // -----------------------------------------------------------------------------
       
    80 //
       
    81 CUpnpStateVariableContentHandler::CUpnpStateVariableContentHandler(
       
    82     CUpnpContentHandlersController& aController,
       
    83     CUpnpStateVariable& aResultStateVariable ) :
       
    84         CUpnpContentHandler( aController ),
       
    85         iResultStateVariable( aResultStateVariable ),
       
    86         iCurrentState( EInitial )
       
    87     {
       
    88     }
       
    89 
       
    90 // -----------------------------------------------------------------------------
       
    91 // CUpnpStateVariableContentHandler::OnStartElementL
       
    92 // This method is a callback to indicate an element has been parsed.
       
    93 // -----------------------------------------------------------------------------
       
    94 //
       
    95 void CUpnpStateVariableContentHandler::OnStartElementL(
       
    96     const RTagInfo& aElement, const RAttributeArray& /*aAttributes*/ )
       
    97     {
       
    98     if ( iCurrentState == EInitial )
       
    99         {
       
   100         const TDesC8& elementName( aElement.LocalName().DesC() );
       
   101         if ( elementName.Compare( KUpnpName ) == 0 )
       
   102             {
       
   103             RepeatedTagCheckL( ENamePos, iFoundTags );
       
   104             iCurrentState = EName;
       
   105             }
       
   106         else if ( elementName.Compare( KUpnpDataType ) == 0 )
       
   107             {
       
   108             RepeatedTagCheckL( EDataTypePos, iFoundTags );
       
   109             iCurrentState = EDataType;
       
   110             }
       
   111         else if ( elementName.Compare( KUpnpDefaultValue ) == 0 )
       
   112             {
       
   113             RepeatedTagCheckL( EDefaultValuePos, iFoundTags );
       
   114             iCurrentState = EDefaultValue;
       
   115             }
       
   116         else if ( elementName.Compare( KUpnpAllowedValueList ) == 0 )
       
   117             {
       
   118             RepeatedTagCheckL( EAllowedValuePos, iFoundTags );
       
   119             iController.SetCurrentContentHandlerL( 
       
   120                 CUpnpAllowedValueListContentHandler::NewL(
       
   121                     iController, iResultStateVariable ) );
       
   122             }
       
   123         else if ( elementName.Compare( KUpnpAllowedValueRange ) == 0 )
       
   124             {
       
   125             RepeatedTagCheckL( EAllowedValuePos, iFoundTags );
       
   126             iController.SetCurrentContentHandlerL( 
       
   127                 CUpnpAllowedValueRangeContentHandler::NewL(
       
   128                     iController, iResultStateVariable ) );
       
   129             }
       
   130         else
       
   131             {
       
   132             iController.SetCurrentContentHandlerL( 
       
   133                 CUpnpIgnoreContentHandler::NewL( iController ) );
       
   134             }
       
   135         }
       
   136     else
       
   137         {
       
   138         //User::Leave( KErrArgument ) //content="textOnly" not checked now
       
   139         iController.SetCurrentContentHandlerL( 
       
   140             CUpnpIgnoreContentHandler::NewL( iController ) );
       
   141         }
       
   142     }
       
   143 
       
   144 // -----------------------------------------------------------------------------
       
   145 // CUpnpStateVariableContentHandler::OnEndElementL
       
   146 // This method is a callback to indicate the end of the element has been reached.
       
   147 // -----------------------------------------------------------------------------
       
   148 //
       
   149 void CUpnpStateVariableContentHandler::OnEndElementL( const RTagInfo& aElement )
       
   150     {
       
   151     switch ( iCurrentState )
       
   152         {
       
   153         case EInitial:
       
   154             ASSERT( aElement.LocalName().DesC().Compare(KUpnpStateVariable)==0 );
       
   155             if ( (iFoundTags.iFlags & KReqiuredTagsBoundary) == 
       
   156                     KReqiuredTagsBoundary )
       
   157                 {
       
   158                 iController.SetPreviousContentHandler();
       
   159                 }
       
   160             else
       
   161                 {
       
   162                 //User::Leave( KErrArgument ) //required tag not found                    
       
   163                 iController.SetPreviousContentHandler();
       
   164                 }
       
   165             break;
       
   166         default:
       
   167             iCurrentState = EInitial;
       
   168         }
       
   169     }
       
   170 
       
   171 // -----------------------------------------------------------------------------
       
   172 // CUpnpStateVariableContentHandler::OnContentL
       
   173 // This method is a callback that sends the content of the element.
       
   174 // aErrorCode must be KErrNone, and that aBytes should contains complete
       
   175 // content (one chunk).
       
   176 // -----------------------------------------------------------------------------
       
   177 //
       
   178 void CUpnpStateVariableContentHandler::OnContentL( const TDesC8& aBytes )
       
   179     {
       
   180     switch ( iCurrentState )
       
   181         {
       
   182         case EName:
       
   183             iResultStateVariable.SetNameL( aBytes );
       
   184             break;
       
   185         case EDataType:
       
   186             iResultStateVariable.SetTypeL( aBytes );
       
   187             break;
       
   188         case EDefaultValue:
       
   189             iResultStateVariable.SetDefaultValueL( aBytes );
       
   190             break;
       
   191         default:
       
   192             //User::Leave( KErrArgument ) //eltOnly not checked now
       
   193             break;
       
   194         }
       
   195     }
       
   196 
       
   197 //  End of File