24
|
1 |
// Copyright (c) 2003-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 |
// NetDial Script reader
|
|
15 |
//
|
|
16 |
//
|
|
17 |
|
|
18 |
/**
|
|
19 |
@file Scrread.cpp
|
|
20 |
*/
|
|
21 |
|
|
22 |
#include "SSCRREAD.H"
|
|
23 |
#include "ND_STD.H"
|
|
24 |
#include "SLOGGER.H"
|
|
25 |
|
|
26 |
// TLinePosition definitions
|
|
27 |
|
|
28 |
TLinePosition::TLinePosition(TInt aLineCount,TInt aLineStart,TInt aLineLength,TInt aOffset)
|
|
29 |
: iLineCount(aLineCount), iLineStart(aLineStart), iLineLength(aLineLength), iOffset(aOffset)
|
|
30 |
/**
|
|
31 |
Constructor for TLinePosition.
|
|
32 |
|
|
33 |
@param aLineCount is line count.
|
|
34 |
@param aLineStart is line start.
|
|
35 |
@param aLineLength is line length.
|
|
36 |
@param aOffset is line offset.
|
|
37 |
*/
|
|
38 |
{}
|
|
39 |
|
|
40 |
TLinePosition& TLinePosition::operator=(const TLinePosition& aLinePosition)
|
|
41 |
/**
|
|
42 |
TLinePosition =-operator.
|
|
43 |
|
|
44 |
@param aLinePosition a reference to line position for comparison.
|
|
45 |
*/
|
|
46 |
{
|
|
47 |
iLineCount=aLinePosition.iLineCount;
|
|
48 |
iLineStart=aLinePosition.iLineStart;
|
|
49 |
iLineLength=aLinePosition.iLineLength;
|
|
50 |
iOffset=aLinePosition.iOffset;
|
|
51 |
return (*this);
|
|
52 |
}
|
|
53 |
|
|
54 |
void TLinePosition::Reset()
|
|
55 |
/**
|
|
56 |
Reset.
|
|
57 |
*/
|
|
58 |
{
|
|
59 |
iLineCount=0;
|
|
60 |
iLineStart=0;
|
|
61 |
iLineLength=0;
|
|
62 |
iOffset=0;
|
|
63 |
}
|
|
64 |
|
|
65 |
// TScriptStatus definitions
|
|
66 |
|
|
67 |
TScriptStatus::TScriptStatus(TInt& aOffset,TPtrC& aLine,TBool& aSkip,TBool& aSkipModeToggleReq)
|
|
68 |
: iOffset(aOffset), iLine(aLine), iSkip(aSkip), iSkipModeToggleReq(aSkipModeToggleReq)
|
|
69 |
/**
|
|
70 |
Constructor for TScriptStatus.
|
|
71 |
|
|
72 |
@param aOffset a reference to script offset.
|
|
73 |
@param aLine a reference to script line.
|
|
74 |
@param aSkip a reference to skip
|
|
75 |
@param aSkipModeToggleReq a reference to skip mode toggle.
|
|
76 |
*/
|
|
77 |
{}
|
|
78 |
|
|
79 |
TScriptStatus::TScriptStatus(const TScriptStatus& aStatus)
|
|
80 |
: iOffset(aStatus.iOffset), iLine(aStatus.iLine), iSkip(aStatus.iSkip), iSkipModeToggleReq(aStatus.iSkipModeToggleReq)
|
|
81 |
/**
|
|
82 |
Constructor for TScriptStatus.
|
|
83 |
|
|
84 |
@param aStatus a reference to script status.
|
|
85 |
*/
|
|
86 |
{}
|
|
87 |
|
|
88 |
// CScriptReader (NetDial Script Reader) definitions
|
|
89 |
|
|
90 |
CScriptReader* CScriptReader::NewL(TInt aBufferSize)
|
|
91 |
/**
|
|
92 |
2 phased constructor for CScriptReader, first phase.
|
|
93 |
|
|
94 |
@param aBufferSize is buffer size for script reader.
|
|
95 |
@exception Leaves if ConstructL() leaves, or not enough memory is available.
|
|
96 |
@return a new CScriptReader object.
|
|
97 |
*/
|
|
98 |
{
|
|
99 |
CScriptReader* p=new(ELeave) CScriptReader();
|
|
100 |
CleanupStack::PushL(p);
|
|
101 |
p->ConstructL(aBufferSize);
|
|
102 |
CleanupStack::Pop();
|
|
103 |
return p;
|
|
104 |
}
|
|
105 |
|
|
106 |
CScriptReader::CScriptReader()
|
|
107 |
: iScript(NULL,0), iCurrentPosition()
|
|
108 |
/**
|
|
109 |
Constructor for CScriptReader, used in the first phase of construction.
|
|
110 |
*/
|
|
111 |
{}
|
|
112 |
|
|
113 |
void CScriptReader::ConstructL(TInt aBufferSize)
|
|
114 |
/**
|
|
115 |
Instantiate member variables.
|
|
116 |
|
|
117 |
@param aBufferSize is buffer size for script reader.
|
|
118 |
*/
|
|
119 |
{
|
|
120 |
__FLOG_STMT(_LIT8(logString,"Script:\tCreating Buffer Of Size %d");)
|
|
121 |
__FLOG_STATIC1(KNetDialLogFolder(),KNetDialLogFile(),TRefByValue<const TDesC8>(logString()),aBufferSize);
|
|
122 |
iScriptBuffer=HBufC::NewL(aBufferSize);
|
|
123 |
TPtr temp=iScriptBuffer->Des();
|
|
124 |
iScript.Set(temp);
|
|
125 |
iLoggingOn=ETrue;
|
|
126 |
}
|
|
127 |
|
|
128 |
CScriptReader::~CScriptReader()
|
|
129 |
/**
|
|
130 |
Destructor.
|
|
131 |
Delete members.
|
|
132 |
*/
|
|
133 |
{
|
|
134 |
delete iScriptBuffer;
|
|
135 |
}
|
|
136 |
|
|
137 |
void CScriptReader::SetScript(const TDesC& aScript)
|
|
138 |
/**
|
|
139 |
Set script and reset buffers.
|
|
140 |
@param aScript a reference to used script.
|
|
141 |
*/
|
|
142 |
{
|
|
143 |
iScript.Copy(aScript);
|
|
144 |
iCurrentPosition.Reset();
|
|
145 |
iScriptSet=ETrue;
|
|
146 |
iSkip=EFalse;
|
|
147 |
}
|
|
148 |
|
|
149 |
TBool CScriptReader::IsScriptSet() const
|
|
150 |
/**
|
|
151 |
Set script and reset buffers.
|
|
152 |
|
|
153 |
@return iScriptSet flag.
|
|
154 |
*/
|
|
155 |
{
|
|
156 |
return iScriptSet;
|
|
157 |
}
|
|
158 |
|
|
159 |
TScriptStatus CScriptReader::ScriptStatus()
|
|
160 |
/**
|
|
161 |
Set script and reset buffers.
|
|
162 |
|
|
163 |
@return TScriptStatus.
|
|
164 |
*/
|
|
165 |
{
|
|
166 |
return TScriptStatus(iCurrentPosition.iOffset,iCurrentLine,iSkip,iSkipModeToggleReq);
|
|
167 |
}
|
|
168 |
|
|
169 |
TInt CScriptReader::GetNextLine()
|
|
170 |
/**
|
|
171 |
Get next line.
|
|
172 |
|
|
173 |
@return current line from GetCurrentLine().
|
|
174 |
*/
|
|
175 |
{
|
|
176 |
iCurrentPosition.iLineStart+=iCurrentPosition.iLineLength; // adjust to the start of the next line
|
|
177 |
return GetCurrentLine();
|
|
178 |
}
|
|
179 |
|
|
180 |
TInt CScriptReader::GetCurrentLine()
|
|
181 |
/**
|
|
182 |
Get current line.
|
|
183 |
|
|
184 |
@return current line.
|
|
185 |
*/
|
|
186 |
{
|
|
187 |
TInt activeLen=iScript.Length()-iCurrentPosition.iLineStart; // length of the script which is still unread
|
|
188 |
if (activeLen==0)
|
|
189 |
return KErrScriptCompleted;
|
|
190 |
|
|
191 |
TPtrC activeDes;
|
|
192 |
activeDes.Set(iScript.Right(activeLen));
|
|
193 |
|
|
194 |
TBool isLastLineWithoutReturn=EFalse;
|
|
195 |
TInt posCR=activeDes.Locate(KCarriageReturn);
|
|
196 |
TInt posLF=activeDes.Locate(KLineFeed);
|
|
197 |
if(posCR==KErrNotFound && posLF==KErrNotFound)
|
|
198 |
isLastLineWithoutReturn=ETrue;
|
|
199 |
|
|
200 |
if (isLastLineWithoutReturn)
|
|
201 |
iCurrentPosition.iLineLength=activeDes.Length();
|
|
202 |
else
|
|
203 |
{
|
|
204 |
if (posCR==KErrNotFound)
|
|
205 |
posCR = KMaxTInt;
|
|
206 |
if (posLF==KErrNotFound)
|
|
207 |
posLF = KMaxTInt;
|
|
208 |
TInt pos = Min(posCR,posLF);
|
|
209 |
iCurrentPosition.iLineLength=pos+1;
|
|
210 |
}
|
|
211 |
|
|
212 |
iCurrentLine.Set(activeDes.Left(iCurrentPosition.iLineLength)); // for script status
|
|
213 |
iCurrentPosition.iOffset=0;
|
|
214 |
iCurrentPosition.iLineCount++;
|
|
215 |
if (iLoggingOn)
|
|
216 |
{
|
|
217 |
TBuf<KLogBufferSize> line;
|
|
218 |
line.Copy(activeDes.Left(Min(KLogBufferSize,iCurrentPosition.iLineLength)));
|
|
219 |
if (iSkip)
|
|
220 |
{
|
|
221 |
__FLOG_STMT(_LIT(logString1,"Script Line #%d:\t[Skip] : %S");)
|
|
222 |
__FLOG_STATIC2(KNetDialLogFolder(),KNetDialLogFile(),TRefByValue<const TDesC>(logString1()),iCurrentPosition.iLineCount,&line);
|
|
223 |
}
|
|
224 |
else
|
|
225 |
{
|
|
226 |
__FLOG_STMT(_LIT(logString2,"Script Line #%d:\t%S");)
|
|
227 |
__FLOG_STATIC2(KNetDialLogFolder(),KNetDialLogFile(),TRefByValue<const TDesC>(logString2()),iCurrentPosition.iLineCount,&line);
|
|
228 |
}
|
|
229 |
}
|
|
230 |
return KErrNone;
|
|
231 |
}
|
|
232 |
|
|
233 |
void CScriptReader::CurrentPos(TLinePosition& aPosition,TInt aOffset)
|
|
234 |
/**
|
|
235 |
Get the current position and change the offset to aOffset.
|
|
236 |
|
|
237 |
@param aPosition a reference to line position.
|
|
238 |
@param aOffset is offset.
|
|
239 |
*/
|
|
240 |
{
|
|
241 |
aPosition=iCurrentPosition;
|
|
242 |
aPosition.iOffset=aOffset;
|
|
243 |
}
|
|
244 |
|
|
245 |
void CScriptReader::SetCurrentPos(TLinePosition aPosition)
|
|
246 |
/**
|
|
247 |
Set current position to aPos and aLine
|
|
248 |
|
|
249 |
@param aPosition is line position.
|
|
250 |
*/
|
|
251 |
{
|
|
252 |
iCurrentPosition=aPosition;
|
|
253 |
}
|
|
254 |
|
|
255 |
TInt CScriptReader::Reset()
|
|
256 |
/**
|
|
257 |
Reset counters and flags
|
|
258 |
*/
|
|
259 |
{
|
|
260 |
iLoggingOn=ETrue;
|
|
261 |
iCurrentPosition.Reset();
|
|
262 |
TInt ret=GetCurrentLine();
|
|
263 |
__ASSERT_DEBUG(!iScriptSet || ret==KErrNone, User::Invariant());
|
|
264 |
GetCurrentLine();
|
|
265 |
iSkip=EFalse;
|
|
266 |
iSkipModeToggleReq=EFalse;
|
|
267 |
return ret;
|
|
268 |
}
|