htiui/HtiCommPlugins/HtiBtCommPlugin/BtEngine/src/sdpattributeparser.cpp
changeset 0 d6fe6244b863
child 3 2703485a934c
equal deleted inserted replaced
-1:000000000000 0:d6fe6244b863
       
     1 /*
       
     2 * Copyright (c) 2009 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:  Reads selected parts of SDP attribute values.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <bt_sock.h>
       
    21 
       
    22 #include "SdpAttributeParser.h"
       
    23 #include "SdpAttributeParser.pan"
       
    24 #include "SdpAttributeNotifier.h"
       
    25 
       
    26 // ============================ MEMBER FUNCTIONS ==============================
       
    27 
       
    28 // ----------------------------------------------------------------------------
       
    29 // TSdpAttributeParser::TSdpAttributeParser()
       
    30 // Construct a TSdpAttributeParser.
       
    31 // ----------------------------------------------------------------------------
       
    32 //
       
    33 
       
    34 TSdpAttributeParser::TSdpAttributeParser(
       
    35     TSdpAttributeList& aNodeList,
       
    36     MSdpAttributeNotifier& aObserver
       
    37 )
       
    38 :   iObserver( aObserver ),
       
    39     iNodeList( aNodeList ),
       
    40     iCurrentNodeIndex( 0 )
       
    41     {
       
    42     // no implementation required
       
    43     }
       
    44 
       
    45 // ----------------------------------------------------------------------------
       
    46 // TSdpAttributeParser::HasFinished()
       
    47 // Check if parsing processed the whole list.
       
    48 // ----------------------------------------------------------------------------
       
    49 //
       
    50 TBool TSdpAttributeParser::HasFinished() const
       
    51     {
       
    52     return CurrentNode().iCommand == EFinished;
       
    53     }
       
    54 
       
    55 // ----------------------------------------------------------------------------
       
    56 // TSdpAttributeParser::VisitAttributeValueL()
       
    57 // Process a data element.
       
    58 // ----------------------------------------------------------------------------
       
    59 //
       
    60 void TSdpAttributeParser::VisitAttributeValueL( CSdpAttrValue& aValue,
       
    61                                                 TSdpElementType aType )
       
    62     {
       
    63     switch ( CurrentNode().iCommand )
       
    64         {
       
    65         case ECheckType:
       
    66             CheckTypeL( aType );
       
    67             break;
       
    68 
       
    69         case ECheckValue:
       
    70             CheckTypeL( aType );
       
    71             CheckValueL( aValue );
       
    72             break;
       
    73 
       
    74         case ECheckEnd:
       
    75             User::Leave( KErrGeneral ); //list element contains too many items
       
    76             break;
       
    77 
       
    78         case ESkip:
       
    79             break;  // no checking required
       
    80 
       
    81         case EReadValue:
       
    82             CheckTypeL( aType );
       
    83             ReadValueL( aValue );
       
    84             break;
       
    85 
       
    86         case EFinished:
       
    87             User::Leave( KErrGeneral ); // element is after
       
    88             return;                     // value should have ended
       
    89 
       
    90         default:
       
    91             Panic( ESdpAttributeParserInvalidCommand );
       
    92         }
       
    93 
       
    94     AdvanceL();
       
    95     }
       
    96 
       
    97 // ----------------------------------------------------------------------------
       
    98 // TSdpAttributeParser::StartListL()
       
    99 // Process the start of a data element list.
       
   100 // ----------------------------------------------------------------------------
       
   101 //
       
   102 void TSdpAttributeParser::StartListL( CSdpAttrValueList& /*aList*/ )
       
   103     {
       
   104     // no checks done here
       
   105     }
       
   106 
       
   107 // ----------------------------------------------------------------------------
       
   108 // TSdpAttributeParser::EndListL()
       
   109 // Process the end of a data element list.
       
   110 // ----------------------------------------------------------------------------
       
   111 //
       
   112 void TSdpAttributeParser::EndListL()
       
   113     {
       
   114     // check we are at the end of a list
       
   115     if ( CurrentNode().iCommand != ECheckEnd )
       
   116         {
       
   117         User::Leave( KErrGeneral );
       
   118         }
       
   119 
       
   120     AdvanceL();
       
   121     }
       
   122 
       
   123 // ----------------------------------------------------------------------------
       
   124 // TSdpAttributeParser::CheckTypeL()
       
   125 // Check the type of the current node is the same as the specified type.
       
   126 // ----------------------------------------------------------------------------
       
   127 //
       
   128 void TSdpAttributeParser::CheckTypeL( TSdpElementType aElementType ) const
       
   129     {
       
   130     if ( CurrentNode().iType != aElementType )
       
   131         {
       
   132         User::Leave( KErrGeneral );
       
   133         }
       
   134     }
       
   135 
       
   136 // ----------------------------------------------------------------------------
       
   137 // TSdpAttributeParser::CheckValueL()
       
   138 // Check the value of the current node is the same as the specified type.
       
   139 // ----------------------------------------------------------------------------
       
   140 //
       
   141 void TSdpAttributeParser::CheckValueL( CSdpAttrValue& aValue ) const
       
   142     {
       
   143     switch ( aValue.Type() )
       
   144         {
       
   145         case ETypeNil:
       
   146             Panic( ESdpAttributeParserNoValue );
       
   147             break;
       
   148 
       
   149         case ETypeUint:
       
   150             if ( aValue.Uint() != ( TUint )CurrentNode().iValue )
       
   151                 {
       
   152                 User::Leave( KErrArgument );
       
   153                 }
       
   154             break;
       
   155 
       
   156         case ETypeInt:
       
   157             if ( aValue.Int() != CurrentNode().iValue )
       
   158                 {
       
   159                 User::Leave( KErrArgument );
       
   160                 }
       
   161             break;
       
   162 
       
   163         case ETypeBoolean:
       
   164             if ( aValue.Bool() != CurrentNode().iValue )
       
   165                 {
       
   166                 User::Leave( KErrArgument );
       
   167                 }
       
   168             break;
       
   169 
       
   170         case ETypeUUID:
       
   171             if ( aValue.UUID() != TUUID( CurrentNode().iValue ) )
       
   172                 {
       
   173                 User::Leave( KErrArgument );
       
   174                 }
       
   175             break;
       
   176 
       
   177         // these are lists, so have to check contents
       
   178         case ETypeDES:
       
   179         case ETypeDEA:
       
   180             Panic( ESdpAttributeParserValueIsList );
       
   181             break;
       
   182 
       
   183         // these aren't supported - use EReadValue and leave on error
       
   184         //case ETypeString:
       
   185         //case ETypeURL:
       
   186         //case ETypeEncoded:
       
   187         default:
       
   188             Panic( ESdpAttributeParserValueTypeUnsupported );
       
   189             break;
       
   190         }
       
   191     }
       
   192 
       
   193 // ----------------------------------------------------------------------------
       
   194 // TSdpAttributeParser::ReadValueL()
       
   195 // Pass the data element value to the observer.
       
   196 // ----------------------------------------------------------------------------
       
   197 //
       
   198 void TSdpAttributeParser::ReadValueL( CSdpAttrValue& aValue ) const
       
   199     {
       
   200     iObserver.FoundElementL( CurrentNode().iValue, aValue );
       
   201     }
       
   202 
       
   203 // ----------------------------------------------------------------------------
       
   204 // TSdpAttributeParser::CurrentNode()
       
   205 // Get the current node.
       
   206 // ----------------------------------------------------------------------------
       
   207 //
       
   208 const TSdpAttributeParser::SSdpAttributeNode& TSdpAttributeParser
       
   209 ::CurrentNode() const
       
   210     {
       
   211     return  iNodeList[iCurrentNodeIndex];
       
   212     }
       
   213 
       
   214 // ----------------------------------------------------------------------------
       
   215 // TSdpAttributeParser::AdvanceL()
       
   216 // Advance to the next node.
       
   217 // ----------------------------------------------------------------------------
       
   218 //
       
   219 void TSdpAttributeParser::AdvanceL()
       
   220     {
       
   221     // check not at end
       
   222     if ( CurrentNode().iCommand == EFinished )
       
   223         {
       
   224         User::Leave( KErrEof );
       
   225         }
       
   226 
       
   227     // move to the next item
       
   228     ++iCurrentNodeIndex;
       
   229     }
       
   230 
       
   231 // End of File