diff -r 0aa8cc770c8a -r 4a793f564d72 mtpdataproviders/mtppictbridgedp/pictbridgeengine/src/dpstransaction.cpp --- a/mtpdataproviders/mtppictbridgedp/pictbridgeengine/src/dpstransaction.cpp Tue Aug 31 16:03:15 2010 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,455 +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 creates and parses dps operations. -* -*/ - - -#include -#include -#include -#include -#include "dpstransaction.h" -#include "dpsscriptsender.h" -#include "dpsdefs.h" -#include "dpsxmlparser.h" -#include "dpsxmlgenerator.h" -#include "dpsconst.h" -#include "dpsfile.h" -#include "dpsstatemachine.h" -#include "dpsscriptreceiver.h" -#include "pictbridge.h" -#include -#include "dpsparam.h" -#include "dpsoperation.h" -#include "dpsxmlstring.h" - -#ifdef _DEBUG -# define IF_DEBUG(t) {RDebug::t;} -#else -# define IF_DEBUG(t) -#endif - -const TInt KPathLength = 3; -const TInt KPercentagePosition = 3; -const TInt KPercentage = 100; -// --------------------------------------------------------------------------- -// -// --------------------------------------------------------------------------- -// -CDpsTransaction* CDpsTransaction::NewL(CDpsStateMachine* aOperator) - { - IF_DEBUG(Print(_L("CDpsTransaction::NewL"))); - CDpsTransaction* self = new(ELeave) CDpsTransaction(aOperator); - CleanupStack::PushL(self); - self->ConstructL(); - CleanupStack::Pop(); - return self; - } - -// --------------------------------------------------------------------------- -// -// --------------------------------------------------------------------------- -// -CDpsTransaction::CDpsTransaction(CDpsStateMachine* aOperator) : - iOperator(aOperator), iReply(EFalse) - { - IF_DEBUG(Print(_L("CDpsTransaction::Ctor"))); - } - -// --------------------------------------------------------------------------- -// -// --------------------------------------------------------------------------- -// -void CDpsTransaction::ConstructL() - { - IF_DEBUG(Print(_L(">>>CDpsTransaction::ConstructL"))); - iFile = CDpsFile::NewL(); - iXmlGen = CDpsXmlGenerator::NewL(iOperator->DpsEngine()); - iXmlPar = CDpsXmlParser::NewL(iOperator->DpsEngine()); - IF_DEBUG(Print(_L("<<>>~CDpsTransaction"))); - delete iXmlPar; - iXmlPar = NULL; - - delete iXmlGen; - iXmlGen = NULL; - - delete iFile; - iFile = NULL; - - IF_DEBUG(Print(_L("<<<~CDpsTransaction"))); - } - -// --------------------------------------------------------------------------- -// -// --------------------------------------------------------------------------- -// -void CDpsTransaction::CreateRequestL(TMDpsOperation* aOperation) - { - IF_DEBUG(Print(_L(">>>CDpsTransaction::CreateRequest "))); - IF_DEBUG(Print(_L(" the request is %d"), aOperation->iOperation)); - TDpsArgArray args; - TDpsEleArray elements; - TDpsAttribute attrib = 0; - CleanupClosePushL(args); - CleanupClosePushL(elements); - RFileWriteStream writer; - writer.PushL(); - TFileName defaultPath = iOperator->DpsEngine()->DpsFolder(); - defaultPath.Append(KDpsDeviceRequestFileName); - User::LeaveIfError(writer.Replace(iFile->FileSession(), defaultPath, - EFileWrite)); - IF_DEBUG(Print(_L("*** file created "))); - User::LeaveIfError(aOperation->FillReqArgs(args, elements, attrib, this)); - aOperation->CreateReqScriptL(args, elements, attrib, writer, this); - writer.CommitL(); - writer.Pop(); - writer.Release(); - User::LeaveIfError(iOperator->ScriptSender()->SendScript(EFalse)); - CleanupStack::PopAndDestroy(&elements); - CleanupStack::PopAndDestroy(&args); - IF_DEBUG(Print(_L("<<>>CDpsTransaction::Filter size %d"), size)); - - for (TInt i = 0; i < size; ) - { - // removes any unprintalbe char between two XML attributes, e.g. - // between > and < - if (aScript[i] >= KSOH && aScript[i] <= KSpace && aScript[i -1] == '>') - { - aScript.Delete(i, 1); - size--; - } - else - { - i++; - } - } - IF_DEBUG(Print(_L("<<>>CDpsTransaction::ParseScript"))); - iReply = aReply; - TInt size; - iFile->FileSizeL(iOperator->ScriptReceiver()->FileNameAndPath(), size); - HBufC8* script = HBufC8::NewLC(size); - TPtr8 ptr_script = script->Des(); - iFile->GetContentL(iOperator->ScriptReceiver()->FileNameAndPath(), - ptr_script); - Filter(ptr_script); - iXmlPar->Reset(); - CParser* parser = CParser::NewLC(KDpsXmlMimeType, *iXmlPar); - Xml::ParseL(*parser, ptr_script); - TDpsArgArray args; iXmlPar->GetParameters(args); - -#ifdef _DEBUG - //print what we get now - TBuf print; - for (TInt i = 0; i < args.Count(); i++) - { - print.Copy(args[i].iContent); - IF_DEBUG(Print(_L("element %d content %S"), - args[i].iElement, &print)); - } -#endif - - if (aReply) - { - TMDpsOperation* op = iOperator->MOperation(); - User::LeaveIfError(op->FillRepArgs(args, this)); - iXmlPar->SetOperationResult(op->iResult); - } - else - { - TDpsResult result; - result.iMajorCode = EDpsResultOk; - result.iMinorCode = EDpsResultNone; - if (iXmlPar->IsEvent()) - { - TDpsEvent event = iXmlPar->Event(); - iOperator->SetEvent(event); - if (event == EDpsEvtNotifyJobStatus) - { - User::LeaveIfError(iOperator->DpsEngine()->Event()-> - iJobEvent.FillRepArgs(args, this)); - } - else - { - User::LeaveIfError(iOperator->DpsEngine()->Event()-> - iPrinterEvent.FillRepArgs(args, this)); - } - CreateEventReplyL(event, result); - } - else - { - // the request from the host is only this one: - // GetFileID and used by DPOF printing - TDpsOperation ope = iXmlPar->Operation(); - iOperator->SetOperation(ope); - if (iOperator->Operation() != EDpsOpGetFileID) - { - User::Leave(KErrNotSupported); - } - CreateRequestReplyL(args, result); - } - } - CleanupStack::PopAndDestroy(parser); - CleanupStack::PopAndDestroy(script); - IF_DEBUG(Print(_L("<<>>CDpsTransaction::HandleHostRequestError %d"), aErr)); - TDpsResult result; - // here we need to map the aErr to Dps standard error - switch (aErr) - { - case KErrNotSupported: - result.iMajorCode = EDpsResultNotRecognized; - result.iMinorCode = EDpsResultNone; - break; - - case KErrArgument: - result.iMajorCode = EDpsResultNotSupported; - result.iMinorCode = EDpsResultillegalParam; - break; - - default: - IF_DEBUG(Print(_L("unknown err"))); - return; - } - TRAP_IGNORE(CreateEventReplyL(iXmlPar->Event(), result)); - - IF_DEBUG(Print(_L("<<>>CDpsTransaction::CreateReply"))); - IF_DEBUG(Print(_L - (" the operation reply is %d"), iOperator->Operation())); - IF_DEBUG(Print(_L("\t the event reply is %d"), iOperator->Event())); - RFileWriteStream writer; - writer.PushL(); - TFileName defaultPath = iOperator->DpsEngine()->DpsFolder(); - defaultPath.Append(KDpsDeviceResponseFileName); - User::LeaveIfError(writer.Replace(iFile->FileSession(), defaultPath, - EFileWrite)); - IF_DEBUG(Print(_L("*** file created "))); - iXmlGen->CreateResultScriptL(aEvent, writer, aResult); - writer.CommitL(); - writer.Pop(); - writer.Release(); - User::LeaveIfError(iOperator->ScriptSender()->SendScript(ETrue)); - IF_DEBUG(Print(_L("<<>>CDpsTransaction::CreateRequestReply"))); - TInt count = aArgs.Count(); - TInt basePathId; - TBuf8 filePath; - TLex8 converter; - - for (TInt i = 0; i < count; i++) - { - switch (aArgs[i].iElement) - { - case EDpsArgBasePathID: - converter.Assign(aArgs[i].iContent); - User::LeaveIfError(converter.Val(basePathId)); - break; - - case EDpsArgFilePath: - filePath.Copy(aArgs[i].iContent); - break; - - default: - __IF_DEBUG(Print(_L("***wrong args"))); - User::Leave(KErrArgument); - break; - } - TUint32 fileId; - - SubstitutePath(filePath); - TBuf file; - file.Copy(filePath); - User::LeaveIfError(iOperator->DpsEngine()-> - Ptp().GetObjectHandleByName(file, fileId)); - TDpsArg arg; - arg.iElement = EDpsArgFileID; - arg.iContent.AppendNumFixedWidth(fileId, EHex, KFullWordWidth); - RFileWriteStream writer; - writer.PushL(); - TFileName defaultPath = iOperator->DpsEngine()->DpsFolder(); - defaultPath.Append(KDpsDeviceResponseFileName); - User::LeaveIfError(writer.Replace(iFile->FileSession(), defaultPath, - EFileWrite)); - IF_DEBUG(Print(_L("*** file created "))); - iXmlGen->CreateReplyScriptL(EDpsOpGetFileID, writer, aResult, arg); - User::LeaveIfError(iOperator->ScriptSender()->SendScript(ETrue)); - writer.CommitL(); - writer.Pop(); - writer.Release(); - } - IF_DEBUG(Print(_L("<<>>CDpsTransaction::SubstitutePath %S"), &aPath)); - TInt size = aPath.Size(); - for (TInt i = 0; i < size; i++) - { - if (aPath[i] == KSlash) - { - aPath[i] = KBackSlash; - } - } - TBuf driveEWide = PathInfo::MemoryCardRootPath(); - TBuf8 driveENarrow; - driveENarrow.Copy(driveEWide); - aPath.Replace(0, KPathLength - 1, driveENarrow); - IF_DEBUG(Print(_L("<<