upnp/upnpstack/serviceframework/src/upnpiconcontenthandler.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 CUpnpIconContentHandler class
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 #include "upnpiconcontenthandler.h"
       
    20 #include "upnpcontenthandlerscontroller.h"
       
    21 #include "upnpicon.h"
       
    22 #include "upnpdeviceliterals.h"
       
    23 
       
    24 //const TUint8 KReqiuredTagsBoundary(31) //first five bits
       
    25 enum TFlagsPositions
       
    26     {
       
    27     EMimetypePos = 0,
       
    28     EWidthPos,
       
    29     EHeightPos,
       
    30     EDepthPos,
       
    31     EUrlPos //all required
       
    32     };
       
    33 
       
    34 // -----------------------------------------------------------------------------
       
    35 // CUpnpIconContentHandler::NewL
       
    36 // Two-phased constructor
       
    37 // -----------------------------------------------------------------------------
       
    38 //
       
    39 CUpnpIconContentHandler* CUpnpIconContentHandler::NewL(
       
    40     CUpnpContentHandlersController& aController, CUpnpIcon& aResultIcon )
       
    41     {
       
    42     CUpnpIconContentHandler* iconContentHandler = 
       
    43         CUpnpIconContentHandler::NewLC( aController, aResultIcon );
       
    44     CleanupStack::Pop( iconContentHandler );
       
    45     return iconContentHandler;
       
    46     }
       
    47 
       
    48 // -----------------------------------------------------------------------------
       
    49 // CUpnpIconContentHandler::NewLC
       
    50 // Two-phased constructor. Leaves teh object on the CleanupStack
       
    51 // -----------------------------------------------------------------------------
       
    52 //
       
    53 CUpnpIconContentHandler* CUpnpIconContentHandler::NewLC(
       
    54     CUpnpContentHandlersController& aController, CUpnpIcon& aResultIcon )
       
    55     {
       
    56     CUpnpIconContentHandler* iconContentHandler = 
       
    57         new (ELeave) CUpnpIconContentHandler( aController, aResultIcon );
       
    58     CleanupStack::PushL( iconContentHandler );
       
    59     return iconContentHandler;
       
    60     }
       
    61 
       
    62 // -----------------------------------------------------------------------------
       
    63 // CUpnpIconContentHandler::~CUpnpIconContentHandler
       
    64 // Destructor of CUpnpIconContentHandler class 
       
    65 // -----------------------------------------------------------------------------
       
    66 //
       
    67 CUpnpIconContentHandler::~CUpnpIconContentHandler()
       
    68     {
       
    69     }
       
    70 
       
    71 // -----------------------------------------------------------------------------
       
    72 // CUpnpIconContentHandler::CUpnpIconContentHandler
       
    73 // Constructor
       
    74 // -----------------------------------------------------------------------------
       
    75 //
       
    76 CUpnpIconContentHandler::CUpnpIconContentHandler(
       
    77     CUpnpContentHandlersController& aController, CUpnpIcon& aResultIcon ) :
       
    78     CUpnpContentHandler( aController ), iResultIcon( aResultIcon ),
       
    79             iCurrentState( EInitial )
       
    80     {
       
    81     }
       
    82 
       
    83 // -----------------------------------------------------------------------------
       
    84 // CUpnpIconContentHandler::OnStartElementL
       
    85 // This method is a callback to indicate an element has been parsed.
       
    86 // -----------------------------------------------------------------------------
       
    87 //
       
    88 void CUpnpIconContentHandler::OnStartElementL( const RTagInfo& aElement,
       
    89     const RAttributeArray& /*aAttributes*/)
       
    90     {
       
    91     if ( EInitial == iCurrentState  )
       
    92         {
       
    93         const TDesC8& elementName(aElement.LocalName().DesC() );
       
    94         if ( elementName.Compare( KUpnpMimetype ) == 0 )
       
    95             {
       
    96             //            RepeatedTagCheckL( EMimetypePos, iFoundTags ) NIY
       
    97             iCurrentState = EMimeType;
       
    98             }
       
    99         else if ( elementName.Compare( KUpnpWidth ) == 0 )
       
   100             {
       
   101             //            RepeatedTagCheckL( EWidthPos, iFoundTags )    NIY
       
   102             iCurrentState = EWidth;
       
   103             }
       
   104         else if ( elementName.Compare( KUpnpHeight ) == 0 )
       
   105             {
       
   106             //            RepeatedTagCheckL( EHeightPos, iFoundTags )   NIY
       
   107             iCurrentState = EHeight;
       
   108             }
       
   109         else if ( elementName.Compare( KUpnpDepth ) == 0 )
       
   110             {
       
   111             //            RepeatedTagCheckL( EDepthPos, iFoundTags )    NIY
       
   112             iCurrentState = EDepth;
       
   113             }
       
   114         else if ( elementName.Compare( KUpnpUrl ) == 0 )
       
   115             {
       
   116             //            RepeatedTagCheckL( EUrlPos, iFoundTags )      NIY
       
   117             iCurrentState = EUrl;
       
   118             }
       
   119         else
       
   120             {
       
   121             SetIgnoreHandlerL();
       
   122             }
       
   123         }
       
   124     else
       
   125         {
       
   126         //User::Leave( KErrArgument )    
       
   127         SetIgnoreHandlerL();
       
   128         }
       
   129     }
       
   130 
       
   131 // -----------------------------------------------------------------------------
       
   132 // CUpnpIconContentHandler::OnEndElementL
       
   133 // This method is a callback to indicate the end of the element has been reached.
       
   134 // -----------------------------------------------------------------------------
       
   135 //
       
   136 void CUpnpIconContentHandler::OnEndElementL( const RTagInfo& aElement )
       
   137     {
       
   138     switch ( iCurrentState )
       
   139         {
       
   140         case EInitial:
       
   141             ASSERT( aElement.LocalName().DesC().Compare( KUpnpIcon )==0 );
       
   142             //if ( (iFoundTags.iFlags & KReqiuredTagsBoundary) == 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 // CUpnpIconContentHandler::OnContentL
       
   158 // This method is a callback that sends the content of the element.
       
   159 // -----------------------------------------------------------------------------
       
   160 //
       
   161 void CUpnpIconContentHandler::OnContentL( const TDesC8& aBytes )
       
   162     {
       
   163     switch ( iCurrentState )
       
   164         {
       
   165         case EMimeType:
       
   166             iResultIcon.SetMimeTypeL( aBytes );
       
   167             break;
       
   168         case EWidth:
       
   169             iResultIcon.SetWidthL( ParseIntL( aBytes ) );
       
   170             break;
       
   171         case EHeight:
       
   172             iResultIcon.SetHeightL( ParseIntL( aBytes ) );
       
   173             break;
       
   174         case EDepth:
       
   175             iResultIcon.SetDepthL( ParseIntL( aBytes ) );
       
   176             break;
       
   177         case EUrl:
       
   178             iResultIcon.SetUrlL( aBytes );
       
   179             break;
       
   180         default:
       
   181             ASSERT( EInitial == iCurrentState );
       
   182             //User::Leave(KErrArgument) 
       
   183             break;
       
   184         }
       
   185     }
       
   186 
       
   187 // -----------------------------------------------------------------------------
       
   188 // CUpnpIconContentHandler::ParseIntL
       
   189 // Parses and returns int value stored in descriptor, or leaves with KErrArgument
       
   190 // if parsing failes.
       
   191 // -----------------------------------------------------------------------------
       
   192 //
       
   193 TInt CUpnpIconContentHandler::ParseIntL( const TDesC8& aToParse )
       
   194     {
       
   195     TLex8 val(aToParse);
       
   196     TInt ret(0);
       
   197     TInt err = val.Val( ret );
       
   198     //    if ( err )
       
   199     //        {
       
   200     //        User::Leave( KErrArgument ) no error checking for now
       
   201     //        }
       
   202     return ret;
       
   203     }
       
   204 
       
   205 //  End of File