servicediscoveryandcontrol/pnp/test/upnp/upnpdescription/src/specversionparser.cpp
changeset 0 f5a58ecadc66
equal deleted inserted replaced
-1:000000000000 0:f5a58ecadc66
       
     1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include "specversionparser.h"
       
    17 #include "upnpdescriptionschema.h"
       
    18 #include <upnpdescriptionschema.h>
       
    19 
       
    20 CSpecVersionParser* CSpecVersionParser::NewL(CUPnPDeviceDescription* aDeviceDesc, const RStringPool& aStringPool)
       
    21 	{
       
    22 	CSpecVersionParser* self = new (ELeave) CSpecVersionParser(aDeviceDesc, aStringPool);
       
    23 	return self;
       
    24 	}
       
    25 
       
    26 CSpecVersionParser* CSpecVersionParser::NewL(CUPnPServiceDescription* aServiceDesc, const RStringPool& aStringPool)
       
    27 	{
       
    28 	CSpecVersionParser* self = new (ELeave) CSpecVersionParser(aServiceDesc, aStringPool);
       
    29 	return self;
       
    30 	}
       
    31 		
       
    32 CSpecVersionParser::CSpecVersionParser(CUPnPDeviceDescription* aDeviceDesc, const RStringPool& aStringPool) : iDeviceDesc(aDeviceDesc), iStringPool(aStringPool)
       
    33 	{
       
    34 	iType = CSpecVersionParser::EDeviceType; 
       
    35 	}
       
    36 
       
    37 CSpecVersionParser::CSpecVersionParser(CUPnPServiceDescription* aServiceDesc, const RStringPool& aStringPool) : iServiceDesc(aServiceDesc), iStringPool(aStringPool)
       
    38 	{
       
    39 	iType = CSpecVersionParser::EServiceType; 
       
    40 	}
       
    41 
       
    42 CSpecVersionParser::~CSpecVersionParser()
       
    43 	{
       
    44 	}
       
    45 
       
    46 void CSpecVersionParser::ParseStartElementL(const RTagInfo& aElement, const RAttributeArray& /*aAttributes*/)
       
    47 	{
       
    48 	iSiblingsCount++;
       
    49 	iString = iStringPool.OpenStringL(aElement.LocalName().DesC());
       
    50 	TInt tblIndex = iString.Index ( UPNPDESCRIPTIONXMLTAGS::Table );
       
    51 	switch( tblIndex )
       
    52 		{
       
    53 		case UPNPDESCRIPTIONXMLTAGS::ESpecVersion:
       
    54 			iFlags = ESpec;
       
    55 			break;
       
    56 		case UPNPDESCRIPTIONXMLTAGS::EMajorNumber:
       
    57 			iFlags = EMajorVersion;
       
    58 			break;
       
    59 		case UPNPDESCRIPTIONXMLTAGS::EMinorNumber:
       
    60 			iFlags = EMinorVersion;
       
    61 			break;
       
    62 		default:
       
    63 			User::Leave(KErrCorrupt);
       
    64 		}
       
    65 	
       
    66 	}
       
    67 		
       
    68 
       
    69 void CSpecVersionParser::ParseEndElementL(const RTagInfo& /*aElement*/)
       
    70 	{
       
    71 	iSiblingsCount--;
       
    72 	iString.Close();
       
    73 	}
       
    74 
       
    75 void CSpecVersionParser::ParseContentL(const TDesC8& aBytes)
       
    76 	{
       
    77 	switch(iFlags)
       
    78 		{
       
    79 		case EMajorVersion:
       
    80 		{
       
    81 		TInt majorNumber;
       
    82 		TLex8 data(aBytes);
       
    83 		data.Val(majorNumber);
       
    84 		if (iType == CSpecVersionParser::EServiceType)
       
    85 			iServiceDesc->SetMajorNumberL(majorNumber);
       
    86 		else
       
    87 			iDeviceDesc->SetMajorNumberL(majorNumber);
       
    88 		iFlags = 0;
       
    89 		break;
       
    90 		}
       
    91 	
       
    92 		case EMinorVersion:
       
    93 		{
       
    94 		TInt minorNumber;
       
    95 		TLex8 data(aBytes);
       
    96 		data.Val(minorNumber);
       
    97 		if (iType == CSpecVersionParser::EServiceType)
       
    98 			iServiceDesc->SetMinorNumberL(minorNumber);
       
    99 		else
       
   100 			iDeviceDesc->SetMinorNumberL(minorNumber);
       
   101 		iFlags = 0;			
       
   102 		break;
       
   103 		}
       
   104 		
       
   105 		default:
       
   106 		break;
       
   107 		}
       
   108 	}
       
   109