sl@0: // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // CSPTxt2Bin class sl@0: // sl@0: // sl@0: sl@0: #include "cn_main.h" sl@0: #include "cn_util.h" sl@0: #include "cn_txt2bin.h" sl@0: #include "SC_TextIn.h" sl@0: #include "SC_StrmOut.h" sl@0: sl@0: using namespace DBSC; sl@0: sl@0: /** sl@0: CSPTxt2Bin::RunL() implements pure virtual CCmdProcessor::RunL(). sl@0: It opens the input text policy file and creates in-memory presentation of the sl@0: policies found there. Then it stores the policies in a binary policy file, sl@0: which may be used then by the DBMS server. sl@0: CSPTxt2Bin::RunL() uses CPDTextLoader class to load policies for the text policy file sl@0: and TPDStreamPersister class to store them in a binary policy file. sl@0: @leave System-wide error codes in case of failure sl@0: @see CCmdProcessor::RunL() sl@0: @see CPDTextLoader sl@0: @see TPDStreamPersister sl@0: */ sl@0: void CSPTxt2Bin::RunL() sl@0: { sl@0: CPDTextLoader* textLoader = CPDTextLoader::NewLC(iFs, iCmdLinePrm.iTxtFile); sl@0: sl@0: #ifdef __DBDUMP__ sl@0: TBuf dumpFileName; sl@0: dumpFileName = iCmdLinePrm.iTxtFile; sl@0: _LIT(KExt, "D"); sl@0: dumpFileName += KExt; sl@0: (void)iFs.Delete(dumpFileName); sl@0: #endif//__DBDUMP__ sl@0: sl@0: TUid domainUid = TSPConvUtil::UidFromFileNameL(iCmdLinePrm.iBinFile); sl@0: CPolicyDomain* policyDomain = CPolicyDomain::NewLC(domainUid, *textLoader); sl@0: sl@0: #ifdef __DBDUMP__ sl@0: RFile dumpFile; sl@0: CleanupClosePushL(dumpFile); sl@0: __LEAVE_IF_ERROR(dumpFile.Replace(iFs, dumpFileName, EFileWrite)); sl@0: policyDomain->Dump(dumpFile); sl@0: CleanupStack::PopAndDestroy(&dumpFile); sl@0: #endif//__DBDUMP__ sl@0: sl@0: RFileWriteStream streamOut; sl@0: CleanupClosePushL(streamOut); sl@0: __LEAVE_IF_ERROR(streamOut.Replace(iFs, iCmdLinePrm.iBinFile, EFileWrite)); sl@0: TPDStreamPersister streamPersister(streamOut); sl@0: policyDomain->ExternalizeL(streamPersister); sl@0: CleanupStack::PopAndDestroy(&streamOut); sl@0: sl@0: CleanupStack::PopAndDestroy(policyDomain); sl@0: CleanupStack::PopAndDestroy(textLoader); sl@0: } sl@0: sl@0: /** sl@0: */ sl@0: inline CSPTxt2Bin::CSPTxt2Bin(RFs& aFs, const TCmdLinePrm& aCmdLinePrm) : sl@0: CCmdProcessor(aFs, aCmdLinePrm) sl@0: { sl@0: } sl@0: sl@0: /** sl@0: */ sl@0: CSPTxt2Bin::~CSPTxt2Bin() sl@0: { sl@0: } sl@0: sl@0: /** sl@0: Standard phase-one CSPTxt2Bin factory method. sl@0: @param aFs File server session sl@0: @param aCmdLinePrm Parsed command line arguments: requested action, input and output file paths sl@0: @return A pointer to successfully created CSPTxt2Bin instance. sl@0: @leave KErrNoMemory - not enough memory sl@0: @leave KErrNotFound - input file not found sl@0: */ sl@0: CSPTxt2Bin* CSPTxt2Bin::NewLC(RFs& aFs, const TCmdLinePrm& aCmdLinePrm) sl@0: { sl@0: __ASSERT(aCmdLinePrm.iAction == TCmdLinePrm::ETxt2Bin); sl@0: CSPTxt2Bin* self = new (ELeave) CSPTxt2Bin(aFs, aCmdLinePrm); sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(); sl@0: return self; sl@0: } sl@0: sl@0: /** sl@0: Standard phase-two CSPTxt2Bin construction method. sl@0: */ sl@0: void CSPTxt2Bin::ConstructL() sl@0: { sl@0: if(!TSPConvUtil::FileExists(iFs, iCmdLinePrm.iTxtFile)) sl@0: { sl@0: _LIT(KText, "Text file \"%S\" not found\n"); sl@0: TSPConvUtil::Print(KText, iCmdLinePrm.iTxtFile); sl@0: __LEAVE(KErrNotFound); sl@0: } sl@0: }