diff -r 0aa8cc770c8a -r 4a793f564d72 mtpdataproviders/mtppictbridgedp/pictbridgeengine/src/dpsxmlparser.cpp --- a/mtpdataproviders/mtppictbridgedp/pictbridgeengine/src/dpsxmlparser.cpp Tue Aug 31 16:03:15 2010 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,445 +0,0 @@ -/* -* Copyright (c) 2006, 2007 Nokia Corporation and/or its subsidiary(-ies). -* All rights reserved. -* This component and the accompanying materials are made available -* under the terms of "Eclipse Public License v1.0" -* which accompanies this distribution, and is available -* at the URL "http://www.eclipse.org/legal/epl-v10.html". -* -* Initial Contributors: -* Nokia Corporation - initial contribution. -* -* Contributors: -* -* Description: This class parses the dps xml script. -* -*/ - - -#include -#include "dpsxmlparser.h" -#include "dpsconst.h" -#include "pictbridge.h" -#include "dpsxmlstring.h" - -#ifdef _DEBUG -# define IF_DEBUG(t) {RDebug::t;} -# define PRINT_DES(t)\ - {TBuf _buf; _buf.Copy(t);RDebug::Print(_L("---%S"), &_buf);} -#else -# define IF_DEBUG(t) -# define PRINT_DES(t) -#endif - -// --------------------------------------------------------------------------- -// -// --------------------------------------------------------------------------- -// -CDpsXmlParser* CDpsXmlParser::NewL(CDpsEngine* aEngine) - { - IF_DEBUG(Print(_L("CDpsXmlParser::NewL"))); - CDpsXmlParser* self = new (ELeave) CDpsXmlParser(aEngine); - return self; - } - -// --------------------------------------------------------------------------- -// -// --------------------------------------------------------------------------- -// -CDpsXmlParser::~CDpsXmlParser() - { - IF_DEBUG(Print(_L(">>>~CDpsXmlParser"))); - iDpsArgs.Close(); - __IF_DEBUG(Print(_L("<<<~CDpsXmlParser"))); - } - -// --------------------------------------------------------------------------- -// -// --------------------------------------------------------------------------- -// -CDpsXmlParser::CDpsXmlParser(CDpsEngine* aEngine) : iEngine(aEngine) - { - IF_DEBUG(Print(_L(">>>CDpsXmlParser::Ctor"))); - Reset(); - IF_DEBUG(Print(_L("<<>>CDpsXmlParser::OnStartDocumentL"))); - if (aErrorCode != KErrNone) - { - IF_DEBUG(Print(_L("---, error code is %d"), aErrorCode)); - User::Leave(aErrorCode); - } - IF_DEBUG(Print(_L("<<>>CDpsXmlParser::OnEndDocumentL"))); - if (aErrorCode != KErrNone) - { - IF_DEBUG(Print(_L("---, error code is %d"), aErrorCode)); - User::Leave(aErrorCode); - } - - IF_DEBUG(Print(_L("<<>>CDpsXmlParser::OnStartElementL"))); - - if (aErrCode != KErrNone) - { - IF_DEBUG(Print(_L("---, error code is %d"), aErrCode)); - User::Leave(aErrCode); - } - if (aAttributes.Count() > 1) - { - IF_DEBUG(Print(_L("---cannot have more than one attribute!"))); - User::Leave(KErrArgument); - } - - // Gets the name of the tag - const TDesC8& name = aElement.LocalName().DesC(); - - IF_DEBUG(Print(_L("---Start"))); PRINT_DES(name); - - //Checks the element - // this is the first layer - if (!name.Compare(KDpsXml)) - { - iAction = EDpsXmlStart; - } - // this is the second layer - else if (!name.Compare(KDpsXmlOutput)) - { - iAction = EDpsXmlOutput; - } - else if (!name.Compare(KDpsXmlInput)) - { - // operation and event cannot be distiguised here - iAction = EDpsXmlInput; - } - // this is the third layer - else if (iAction == EDpsXmlOutput && !name.Compare(KDpsXmlResult)) - { - // output must be result - iAction = EDpsXmlResult; - } - else if (iAction == EDpsXmlInput && - (!name.Compare(iEngine->DpsParameters()->iDpsEventStrings[0]) || - !name.Compare(iEngine->DpsParameters()->iDpsEventStrings[1]))) - { - if (!name.Compare(iEngine->DpsParameters()->iDpsEventStrings[0])) - { - iDpsEvent = EDpsEvtNotifyJobStatus; - } - else - { - iDpsEvent = EDpsEvtNotifyDeviceStatus; - } - iAction = EDpsXmlEvent; - } - else if (iAction == EDpsXmlInput || iAction == EDpsXmlResult) - { - iAction = EDpsXmlOperation; - for (TInt i= 0; i < EDpsOpMax-1; i++) //i=0 as AppendL() method adds item on first free position in array - { - if (!name.Compare(iEngine->DpsParameters()->iDpsOperationStrings[i])) - { - IF_DEBUG(Print(_L("---found the operation"))); - PRINT_DES(name); - iDpsOperation = (TDpsOperation)(i+1);// i+1 to by pass first operation EDpsOpEmpty in enum which is not added to array - break; - } - } - } - - // below is the fourth layer, e.g. the argument list/element. there - // could be many arugments, but only one element - else if (iAction == EDpsXmlOperation || iAction == EDpsXmlEvent) - { - // only element in output is capability - if (!name.Compare(iEngine->DpsParameters()->iDpsElementStrings[0])) - { - IF_DEBUG(Print(_L("---the element is"))); - PRINT_DES(name); - iElement = EDpsCapability; - } - else - { - for (TInt i = 0; i < EDpsArgMax; i++) - { - if (!name.Compare(iEngine->DpsParameters()->iDpsArgStrings[i])) - { - IF_DEBUG(Print(_L("---the argument is "))); - PRINT_DES(name); - TDpsArg arg; - arg.iElement = (TDpsArgument)i; - arg.iContent.Copy(_L("")); - iDpsArgs.Append(arg); - break; - } - } - } - - } - else - { - // something wrong - IF_DEBUG(Print(_L("--- non-PB element! %S"), &name)); - User::Leave(KErrNotSupported); - } - if (aAttributes.Count() == 1) - { - ParseAttributesL(aAttributes, name); - } - IF_DEBUG(Print(_L("<<> KShiftLength; - CleanupStack::PopAndDestroy(value); - IF_DEBUG(Print(_L("--- attribte value %x"), result)); - - } - -// --------------------------------------------------------------------------- -// -// --------------------------------------------------------------------------- -// -void CDpsXmlParser::OnEndElementL(const RTagInfo& aElement, - TInt aErrorCode) - { - IF_DEBUG(Print(_L(">>>CDpsXmlParser::OnEndElementL"))); - - if (aErrorCode != KErrNone) - { - IF_DEBUG(Print(_L("--- error code is %d"), aErrorCode)); - User::Leave(aErrorCode); - } - - // Get the name of the tag - const TDesC8& name = aElement.LocalName().DesC(); - PRINT_DES(name); - IF_DEBUG(Print(_L("<<>>CDpsXmlParser::OnContentL content is"))); - PRINT_DES(aBytes); - - if (aErrorCode != KErrNone) - { - IF_DEBUG(Print(_L("--- error code %d"), aErrorCode)); - User::Leave(aErrorCode); - } - if (aBytes[0] >= KSOH && aBytes[0] <= KSpace) - { - IF_DEBUG(Print(_L("the unprintable char %d"), aBytes[0])); - return; - } - // parses the result - if (iAction == EDpsXmlResult) - { - TUint32 value; - TLex8 converter(aBytes); - TInt error = converter.Val(value, EHex); - if (error != KErrNone) - { - IF_DEBUG(Print(_L("--- convert error %d"), error)); - User::Leave(error); - } - IF_DEBUG(Print(_L("--- result %x"), value)); - // we have got the result - iDpsResult.iMajorCode = - static_cast(value >> KShiftLength); - iDpsResult.iMinorCode = - static_cast(value & KDpsMinorMask); - } - // gets the argument - else if (iAction == EDpsXmlOperation || iAction == EDpsXmlEvent) - { - iDpsArgs[iDpsArgs.Count() - 1].iContent.Copy(aBytes); - } - IF_DEBUG(Print(_L("<<>>CDpsXmlParser::OnStartPrefixMappingL"))); - if (aErrorCode != KErrNone) - { - IF_DEBUG(Print(_L("--- error code %d"), aErrorCode)); - User::Leave(aErrorCode); - } - IF_DEBUG(Print(_L("<<>>CDpsXmlParser::OnEndPrefixMappingL"))); - if (aErrorCode != KErrNone) - { - IF_DEBUG(Print(_L("--- error code %d"), aErrorCode)); - User::Leave(aErrorCode); - } - IF_DEBUG(Print(_L("<<>>CDpsXmlParser::OnIgnorableWhiteSpaceL"))); - if (aErrorCode != KErrNone) - { - IF_DEBUG(Print(_L("---error code %d"), aErrorCode)); - User::Leave(aErrorCode); - } - IF_DEBUG(Print(_L("<<>>CDpsXmlParser::OnSkippedEntityL"))); - if (aErrorCode != KErrNone) - { - IF_DEBUG(Print(_L("--- error code %d"), aErrorCode)); - User::Leave(aErrorCode); - } - IF_DEBUG(Print(_L("<<>>CDpsXmlParser::OnProcessingInstructionL"))); - if (aErrorCode != KErrNone) - { - IF_DEBUG(Print(_L("--- error code %d"), aErrorCode)); - User::Leave(aErrorCode); - } - IF_DEBUG(Print(_L("<<>>CDpsXmlParser::OnError()"))); - if (aErrorCode != KErrNone) - { - IF_DEBUG(Print(_L("---error code %d"), aErrorCode)); - } - IF_DEBUG(Print(_L("<<(this) : 0; - } - -// --------------------------------------------------------------------------- -// -// --------------------------------------------------------------------------- -// -void CDpsXmlParser::Reset() - { - iDpsArgs.Reset(); - iAction = EDpsXmlEmpty; - iDpsEvent = EDpsEvtEmpty; - iDpsOperation = EDpsOpEmpty; - iElement = EDpsEleEmpty; - iAttrib = 0; - } -