S60 3rd Edition SDK for Symbian OS
Example Applications Guide

ChatSdpAttributeParser.cpp

00001 /*
00002 * ==============================================================================
00003 *  Name        : ChatSdpAttributeParser.cpp
00004 *  Part of     : Chat
00005 *  Interface   : 
00006 *  Description : 
00007 *  Version     : 
00008 *
00009 *  Copyright (c) 2005-2006 Nokia Corporation.
00010 *  This material, including documentation and any related 
00011 *  computer programs, is protected by copyright controlled by 
00012 *  Nokia Corporation.
00013 * ==============================================================================
00014 */
00015 
00016 // INCLUDE FILES
00017 #include <bt_sock.h>
00018 
00019 #include "ChatSdpAttributeParser.h"
00020 #include "ChatSdpAttributeParser.pan"
00021 #include "ChatSdpAttributeNotifier.h"
00022 
00023 // ============================ MEMBER FUNCTIONS ==============================
00024 
00025 // ----------------------------------------------------------------------------
00026 // TChatSdpAttributeParser::TChatSdpAttributeParser()
00027 // Construct a TChatSdpAttributeParser.
00028 // ----------------------------------------------------------------------------
00029 //
00030 TChatSdpAttributeParser::TChatSdpAttributeParser(
00031     RArray<TChatSdpAttributeParser::TChatSdpAttributeNode>& aNodeList,
00032     MChatSdpAttributeNotifier& aObserver ) : 
00033     iObserver( aObserver ),
00034     iNodeList( aNodeList ),
00035     iCurrentNodeIndex( 0 )
00036     {
00037     iCurrentNode = iNodeList[iCurrentNodeIndex];
00038     }
00039 
00040 // ----------------------------------------------------------------------------
00041 // TChatSdpAttributeParser::~TChatSdpAttributeParser()
00042 // Destructor.
00043 // ----------------------------------------------------------------------------
00044 //
00045 TChatSdpAttributeParser::~TChatSdpAttributeParser()
00046         {
00047         // No implementation needed     
00048         }
00049         
00050 // ----------------------------------------------------------------------------
00051 // TChatSdpAttributeParser::HasFinished()
00052 // Check if parsing processed the whole list.
00053 // ----------------------------------------------------------------------------
00054 //
00055 TBool TChatSdpAttributeParser::HasFinished() const
00056     {
00057     return ( iCurrentNode.Command() == EFinished );
00058     }
00059 
00060 // ----------------------------------------------------------------------------
00061 // TChatSdpAttributeParser::VisitAttributeValueL()
00062 // Process a data element.
00063 // ----------------------------------------------------------------------------
00064 //
00065 void TChatSdpAttributeParser::VisitAttributeValueL( CSdpAttrValue& aValue, 
00066     TSdpElementType aType )
00067     {
00068     switch ( iCurrentNode.Command() )
00069         {
00070         case ECheckType:
00071             CheckTypeL( aType );
00072             break;
00073 
00074         case ECheckValue:
00075             CheckTypeL( aType );
00076             CheckValueL( aValue );
00077             break;
00078 
00079         case ECheckEnd:
00080             User::Leave( KErrTooBig ); //list element contains too many items
00081             break;
00082 
00083         case ESkip:
00084             break;  // no checking required
00085 
00086         case EReadValue:
00087             CheckTypeL( aType );
00088             ReadValueL( aValue );
00089             break;
00090 
00091         case EFinished:
00092             User::Leave( KErrEof ); // element is after 
00093             return;                     // value should have ended
00094 
00095         default:
00096             Panic( EChatSdpAttributeParserInvalidCommand );
00097         }
00098 
00099     AdvanceL();
00100     }
00101 
00102 // ----------------------------------------------------------------------------
00103 // TChatSdpAttributeParser::StartListL()
00104 // Process the start of a data element list.
00105 // ----------------------------------------------------------------------------
00106 //
00107 void TChatSdpAttributeParser::StartListL( CSdpAttrValueList& /*aList*/ )
00108     {
00109     // no checks done here
00110     }
00111 
00112 // ----------------------------------------------------------------------------
00113 // TChatSdpAttributeParser::EndListL()
00114 // Process the end of a data element list.
00115 // ----------------------------------------------------------------------------
00116 //
00117 void TChatSdpAttributeParser::EndListL()
00118     {
00119     // check we are at the end of a list
00120     if ( iCurrentNode.Command() != ECheckEnd )
00121         {
00122         User::Leave( KErrGeneral );
00123         }
00124 
00125     AdvanceL();
00126     }
00127 
00128 // ----------------------------------------------------------------------------
00129 // TChatSdpAttributeParser::CheckTypeL()
00130 // Check the type of the current node is the same as the specified type.
00131 // ----------------------------------------------------------------------------
00132 //
00133 void TChatSdpAttributeParser::CheckTypeL( TSdpElementType aElementType ) const
00134     {
00135     if ( iCurrentNode.Type() != aElementType )
00136         {
00137         User::Leave( KErrGeneral );
00138         }
00139     }
00140 
00141 // ----------------------------------------------------------------------------
00142 // TChatSdpAttributeParser::CheckValueL()
00143 // Check the value of the current node is the same as the specified type.
00144 // ----------------------------------------------------------------------------
00145 //
00146 void TChatSdpAttributeParser::CheckValueL( CSdpAttrValue& aValue ) const
00147     {
00148     switch ( aValue.Type() )
00149         {
00150         case ETypeNil:
00151             Panic( EChatSdpAttributeParserNoValue );
00152             break;
00153 
00154         case ETypeUint:
00155             if ( aValue.Uint() != ( TUint ) iCurrentNode.Value() )
00156                 {
00157                 User::Leave( KErrArgument );
00158                 }
00159             break;
00160 
00161         case ETypeInt:
00162             if ( aValue.Int() != iCurrentNode.Value() )
00163                 {
00164                 User::Leave( KErrArgument );
00165                 }
00166             break;
00167 
00168         case ETypeBoolean:
00169             if ( aValue.Bool() != iCurrentNode.Value() )
00170                 {
00171                 User::Leave( KErrArgument );
00172                 }
00173             break;
00174 
00175         case ETypeUUID:
00176             if ( aValue.UUID() != TUUID( iCurrentNode.Value() ) )
00177                 {
00178                 User::Leave( KErrArgument );
00179                 }
00180             break;
00181 
00182         case ETypeDES:
00183         case ETypeDEA:
00184             Panic( EChatSdpAttributeParserValueIsList );
00185             break;
00186 
00187         default:
00188             Panic( EChatSdpAttributeParserValueTypeUnsupported );
00189             break;
00190         }
00191     }
00192 
00193 // ----------------------------------------------------------------------------
00194 // TChatSdpAttributeParser::ReadValueL()
00195 // Pass the data element value to the observer.
00196 // ----------------------------------------------------------------------------
00197 //
00198 void TChatSdpAttributeParser::ReadValueL( CSdpAttrValue& aValue ) const
00199     {
00200     iObserver.FoundElementL( iCurrentNode.Value(), aValue );
00201     }
00202 
00203 // ----------------------------------------------------------------------------
00204 // TChatSdpAttributeParser::AdvanceL()
00205 // Advance to the next node.
00206 // ----------------------------------------------------------------------------
00207 //
00208 void TChatSdpAttributeParser::AdvanceL()
00209     {
00210     // check not at end
00211     if ( iCurrentNode.Command() == EFinished )
00212         {
00213         User::Leave( KErrEof );
00214         }
00215 
00216     // move to the next item
00217     iCurrentNode = iNodeList[++iCurrentNodeIndex];
00218     }
00219 
00220 // ----------------------------------------------------------------------------
00221 // TChatSdpAttributeParser::TChatSdpAttributeNode::TChatSdpAttributeNode()
00222 // constructor.
00223 // ----------------------------------------------------------------------------
00224 //
00225 TChatSdpAttributeParser::TChatSdpAttributeNode::TChatSdpAttributeNode()
00226   {
00227   // no implementation needed
00228   }
00229             
00230 // ----------------------------------------------------------------------------
00231 // TChatSdpAttributeParser::TChatSdpAttributeNode::~TChatSdpAttributeNode()
00232 // destructor.
00233 // ----------------------------------------------------------------------------
00234 //
00235 TChatSdpAttributeParser::TChatSdpAttributeNode::~TChatSdpAttributeNode()
00236   {
00237     // no implementation needed
00238     }
00239 
00240 // ----------------------------------------------------------------------------
00241 // TChatSdpAttributeParser::TChatSdpAttributeNode::SetCommand( TNodeCommand aCommand )
00242 // set iCommand member variable.
00243 // ----------------------------------------------------------------------------
00244 //            
00245 void TChatSdpAttributeParser::TChatSdpAttributeNode::SetCommand( TNodeCommand aCommand )
00246     {
00247     iCommand = aCommand;
00248     }
00249 
00250 // ----------------------------------------------------------------------------
00251 // TChatSdpAttributeParser::TChatSdpAttributeNode::SetType( TChatSdpElementType aType )
00252 // set iType member variable.
00253 // ----------------------------------------------------------------------------
00254 //          
00255 void TChatSdpAttributeParser::TChatSdpAttributeNode::SetType( TSdpElementType aType )
00256     {
00257     iType = aType;
00258     }
00259 
00260 // ----------------------------------------------------------------------------
00261 // void TChatSdpAttributeParser::TChatSdpAttributeNode::SetValue( TInt aValue )
00262 // set iValue member variable.
00263 // ----------------------------------------------------------------------------
00264 //          
00265 void TChatSdpAttributeParser::TChatSdpAttributeNode::SetValue( TInt aValue )
00266     {
00267     iValue = aValue;
00268     }
00269 
00270 // ----------------------------------------------------------------------------
00271 // TChatSdpAttributeParser::TChatSdpAttributeNode::Command()
00272 // get iCommand member variable value.
00273 // ----------------------------------------------------------------------------
00274 //            
00275 TChatSdpAttributeParser::TNodeCommand TChatSdpAttributeParser::TChatSdpAttributeNode::Command() const
00276     {
00277     return iCommand;
00278     }
00279 
00280 // ----------------------------------------------------------------------------
00281 // TChatSdpAttributeParser::TChatSdpAttributeNode::Type()
00282 // get iType member variable value.
00283 // ----------------------------------------------------------------------------
00284 //            
00285 TSdpElementType TChatSdpAttributeParser::TChatSdpAttributeNode::Type() const
00286     {
00287     return iType;
00288     }
00289 
00290 // ----------------------------------------------------------------------------
00291 // TChatSdpAttributeParser::TChatSdpAttributeNode::Value()
00292 // get iValue member variable value.
00293 // ----------------------------------------------------------------------------
00294 //            
00295 TInt TChatSdpAttributeParser::TChatSdpAttributeNode::Value() const
00296     {
00297     return iValue;
00298     }   
00299             
00300 
00301 // End of File

© Nokia 2006

Back to top