|
1 // Copyright (c) 2001-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 // Reads lines from script using idle tick for each. Parse into tokens, pass to command object. |
|
15 // |
|
16 // |
|
17 |
|
18 #include "script.h" |
|
19 #include "command.h" |
|
20 |
|
21 #include <e32cons.h> |
|
22 #include <unifiedcertstore.h> |
|
23 |
|
24 CTOCSPScript* CTOCSPScript::NewLC(CTOCSPLogger& aLog, |
|
25 CTOCSPResult& aResult, |
|
26 const TDesC& aInputFileName, |
|
27 TInt aTransaction) |
|
28 { |
|
29 CTOCSPScript* self = new (ELeave) CTOCSPScript(aLog); |
|
30 CleanupStack::PushL(self); |
|
31 self->ConstructL(aInputFileName, aResult, aTransaction); |
|
32 return self; |
|
33 } |
|
34 |
|
35 |
|
36 CTOCSPScript* CTOCSPScript::NewL(CTOCSPLogger& aLog, |
|
37 CTOCSPResult& aResult, |
|
38 const TDesC& aInputFileName, |
|
39 TInt aTransaction) |
|
40 { |
|
41 CTOCSPScript* self = NewLC(aLog, aResult, aInputFileName, aTransaction); |
|
42 CleanupStack::Pop(self); |
|
43 return self; |
|
44 } |
|
45 //******************************************************************** |
|
46 CTOCSPScript* CTOCSPScript::NewL(CTOCSPLogger& aLog, |
|
47 CTOCSPResult& aResult, |
|
48 TInt aTransaction) |
|
49 { |
|
50 CTOCSPScript* self = NewLC(aLog, aResult, aTransaction); |
|
51 CleanupStack::Pop(self); |
|
52 return self; |
|
53 } |
|
54 |
|
55 CTOCSPScript* CTOCSPScript::NewLC(CTOCSPLogger& aLog, |
|
56 CTOCSPResult& aResult, |
|
57 TInt aTransaction) |
|
58 { |
|
59 CTOCSPScript* self = new (ELeave) CTOCSPScript(aLog); |
|
60 CleanupStack::PushL(self); |
|
61 self->ConstructL(aResult, aTransaction); |
|
62 return self; |
|
63 } |
|
64 |
|
65 void CTOCSPScript::ConstructL(CTOCSPResult& aResult, TInt aTransaction) |
|
66 { |
|
67 CActiveScheduler::Add(this); |
|
68 |
|
69 iCommand = CTOCSPCommand::NewL(iLog, aResult, aTransaction); |
|
70 |
|
71 } |
|
72 |
|
73 //********************************************************************* |
|
74 |
|
75 CTOCSPScript::CTOCSPScript(CTOCSPLogger& aLog) : |
|
76 CActive(EPriorityNormal), |
|
77 iLog(aLog) |
|
78 { |
|
79 } |
|
80 |
|
81 |
|
82 void CTOCSPScript::ConstructL(const TDesC& aInputFileName, CTOCSPResult& aResult, TInt aTransaction) |
|
83 { |
|
84 CActiveScheduler::Add(this); |
|
85 |
|
86 iCommand = CTOCSPCommand::NewL(iLog, aResult, aTransaction); |
|
87 |
|
88 User::LeaveIfError(iFs.Connect()); |
|
89 TInt err = iFile.Open(iFs, aInputFileName, EFileRead | EFileShareAny); |
|
90 if (err != KErrNone) |
|
91 { |
|
92 iLog.LogL(_L("Error while opening ")); |
|
93 iLog.LogL(aInputFileName); |
|
94 iLog.NewLineL(); |
|
95 User::Leave(err); |
|
96 } |
|
97 iLineReader.Set(iFile); |
|
98 } |
|
99 |
|
100 |
|
101 CTOCSPScript::~CTOCSPScript() |
|
102 { |
|
103 Cancel(); |
|
104 iFile.Close(); |
|
105 iFs.Close(); |
|
106 |
|
107 delete iCommand; |
|
108 } |
|
109 |
|
110 |
|
111 void CTOCSPScript::RunTestL(TRequestStatus& aStatus) |
|
112 { |
|
113 iClientRequestStatus = &aStatus; |
|
114 aStatus = KRequestPending; |
|
115 ReadLineL(); |
|
116 } |
|
117 |
|
118 |
|
119 TInt CTOCSPScript::TransactionCount() |
|
120 { |
|
121 return iCommand->CurrentTransaction(); |
|
122 } |
|
123 |
|
124 |
|
125 void CTOCSPScript::RunL() |
|
126 { |
|
127 User::LeaveIfError(iStatus.Int()); |
|
128 ReadLineL(); |
|
129 } |
|
130 |
|
131 |
|
132 void CTOCSPScript::DoCancel() |
|
133 { |
|
134 iCommand->Cancel(); |
|
135 } |
|
136 |
|
137 |
|
138 TInt CTOCSPScript::RunError(TInt aError) |
|
139 { |
|
140 User::RequestComplete(iClientRequestStatus, aError); |
|
141 return KErrNone; |
|
142 } |
|
143 |
|
144 |
|
145 |
|
146 // void CTOCSPScript::ReadLineL()f- |
|
147 //reads in from the TDes |
|
148 void CTOCSPScript::ReadLineL() |
|
149 { |
|
150 TInt error = iLineReader.Read(iLine); |
|
151 |
|
152 if (error == KErrNone) |
|
153 { |
|
154 ++iLinesProcessed; |
|
155 TBool carryOn = iCommand->ProcessCommand(iLine, iStatus); |
|
156 |
|
157 if (carryOn) |
|
158 { |
|
159 SetActive(); |
|
160 } |
|
161 else |
|
162 { |
|
163 User::RequestComplete(iClientRequestStatus, KErrNone); |
|
164 } |
|
165 } |
|
166 else if (error == KErrEof) |
|
167 { |
|
168 User::RequestComplete(iClientRequestStatus, KErrNone); |
|
169 } |
|
170 else |
|
171 { |
|
172 User::Leave(error); |
|
173 } |
|
174 } |
|
175 |
|
176 |
|
177 void CTOCSPScript::SetVerbose(TBool aVerbose) |
|
178 { |
|
179 iCommand->SetVerbose(aVerbose); |
|
180 } |
|
181 |
|
182 |
|
183 TInt CTOCSPScript::LinesProcessed() const |
|
184 { |
|
185 return iLinesProcessed; |
|
186 } |
|
187 |
|
188 const TDesC& CTOCSPScript::LastLine() const |
|
189 { |
|
190 return iLine; |
|
191 } |