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