|
1 // Copyright (c) 2004-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 // CSPTxt2Bin class |
|
15 // |
|
16 // |
|
17 |
|
18 #include "cn_main.h" |
|
19 #include "cn_util.h" |
|
20 #include "cn_txt2bin.h" |
|
21 #include "SC_TextIn.h" |
|
22 #include "SC_StrmOut.h" |
|
23 |
|
24 using namespace DBSC; |
|
25 |
|
26 /** |
|
27 CSPTxt2Bin::RunL() implements pure virtual CCmdProcessor::RunL(). |
|
28 It opens the input text policy file and creates in-memory presentation of the |
|
29 policies found there. Then it stores the policies in a binary policy file, |
|
30 which may be used then by the DBMS server. |
|
31 CSPTxt2Bin::RunL() uses CPDTextLoader class to load policies for the text policy file |
|
32 and TPDStreamPersister class to store them in a binary policy file. |
|
33 @leave System-wide error codes in case of failure |
|
34 @see CCmdProcessor::RunL() |
|
35 @see CPDTextLoader |
|
36 @see TPDStreamPersister |
|
37 */ |
|
38 void CSPTxt2Bin::RunL() |
|
39 { |
|
40 CPDTextLoader* textLoader = CPDTextLoader::NewLC(iFs, iCmdLinePrm.iTxtFile); |
|
41 |
|
42 #ifdef __DBDUMP__ |
|
43 TBuf<KMaxFileName> dumpFileName; |
|
44 dumpFileName = iCmdLinePrm.iTxtFile; |
|
45 _LIT(KExt, "D"); |
|
46 dumpFileName += KExt; |
|
47 (void)iFs.Delete(dumpFileName); |
|
48 #endif//__DBDUMP__ |
|
49 |
|
50 TUid domainUid = TSPConvUtil::UidFromFileNameL(iCmdLinePrm.iBinFile); |
|
51 CPolicyDomain* policyDomain = CPolicyDomain::NewLC(domainUid, *textLoader); |
|
52 |
|
53 #ifdef __DBDUMP__ |
|
54 RFile dumpFile; |
|
55 CleanupClosePushL(dumpFile); |
|
56 __LEAVE_IF_ERROR(dumpFile.Replace(iFs, dumpFileName, EFileWrite)); |
|
57 policyDomain->Dump(dumpFile); |
|
58 CleanupStack::PopAndDestroy(&dumpFile); |
|
59 #endif//__DBDUMP__ |
|
60 |
|
61 RFileWriteStream streamOut; |
|
62 CleanupClosePushL(streamOut); |
|
63 __LEAVE_IF_ERROR(streamOut.Replace(iFs, iCmdLinePrm.iBinFile, EFileWrite)); |
|
64 TPDStreamPersister streamPersister(streamOut); |
|
65 policyDomain->ExternalizeL(streamPersister); |
|
66 CleanupStack::PopAndDestroy(&streamOut); |
|
67 |
|
68 CleanupStack::PopAndDestroy(policyDomain); |
|
69 CleanupStack::PopAndDestroy(textLoader); |
|
70 } |
|
71 |
|
72 /** |
|
73 */ |
|
74 inline CSPTxt2Bin::CSPTxt2Bin(RFs& aFs, const TCmdLinePrm& aCmdLinePrm) : |
|
75 CCmdProcessor(aFs, aCmdLinePrm) |
|
76 { |
|
77 } |
|
78 |
|
79 /** |
|
80 */ |
|
81 CSPTxt2Bin::~CSPTxt2Bin() |
|
82 { |
|
83 } |
|
84 |
|
85 /** |
|
86 Standard phase-one CSPTxt2Bin factory method. |
|
87 @param aFs File server session |
|
88 @param aCmdLinePrm Parsed command line arguments: requested action, input and output file paths |
|
89 @return A pointer to successfully created CSPTxt2Bin instance. |
|
90 @leave KErrNoMemory - not enough memory |
|
91 @leave KErrNotFound - input file not found |
|
92 */ |
|
93 CSPTxt2Bin* CSPTxt2Bin::NewLC(RFs& aFs, const TCmdLinePrm& aCmdLinePrm) |
|
94 { |
|
95 __ASSERT(aCmdLinePrm.iAction == TCmdLinePrm::ETxt2Bin); |
|
96 CSPTxt2Bin* self = new (ELeave) CSPTxt2Bin(aFs, aCmdLinePrm); |
|
97 CleanupStack::PushL(self); |
|
98 self->ConstructL(); |
|
99 return self; |
|
100 } |
|
101 |
|
102 /** |
|
103 Standard phase-two CSPTxt2Bin construction method. |
|
104 */ |
|
105 void CSPTxt2Bin::ConstructL() |
|
106 { |
|
107 if(!TSPConvUtil::FileExists(iFs, iCmdLinePrm.iTxtFile)) |
|
108 { |
|
109 _LIT(KText, "Text file \"%S\" not found\n"); |
|
110 TSPConvUtil::Print(KText, iCmdLinePrm.iTxtFile); |
|
111 __LEAVE(KErrNotFound); |
|
112 } |
|
113 } |