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