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 Serial IO Functions
|
|
15 |
//
|
|
16 |
//
|
|
17 |
|
|
18 |
/**
|
|
19 |
@file Sio.cpp
|
|
20 |
*/
|
|
21 |
|
|
22 |
#include "SSCREXEC.H"
|
|
23 |
#include "SIO.H"
|
|
24 |
#include "SLOGGER.H"
|
|
25 |
#include <networking/bca.h>
|
|
26 |
|
|
27 |
const TInt KChatterPriority=0;
|
|
28 |
const TInt KCommReadPriority=10;
|
|
29 |
const TInt KCommWritePriority=20;
|
|
30 |
const TInt KChatBufferSize=64;
|
|
31 |
const TInt KWriteTimeOutSec=6;
|
|
32 |
const TInt KOneSecInMicroSecs=1000000;
|
|
33 |
const TInt KPreSendPauseTimeMicroSec=200000;
|
|
34 |
const TInt KClockTick=15500;
|
|
35 |
const TReal KTRealOneSecInMicroSecs=1E6;
|
|
36 |
|
|
37 |
// CScriptIO definitions
|
|
38 |
CScriptIO* CScriptIO::NewL(CScriptExecutor* aScriptExecutor, const TDesC& aCommsChannel)
|
|
39 |
|
|
40 |
/**
|
|
41 |
2 phased constructor for CScriptIO, first phase.
|
|
42 |
|
|
43 |
@param aScriptExecutor a pointer to script executor.
|
|
44 |
@param aCommPort a reference to COMM port.
|
|
45 |
@exception Leaves if ConstructL() leaves, or not enough memory is available.
|
|
46 |
@return a new CScriptIO object.
|
|
47 |
*/
|
|
48 |
{
|
|
49 |
CScriptIO* c=new(ELeave) CScriptIO(aScriptExecutor);
|
|
50 |
CleanupStack::PushL(c);
|
|
51 |
c->ConstructL(aCommsChannel);
|
|
52 |
CleanupStack::Pop();
|
|
53 |
return c;
|
|
54 |
}
|
|
55 |
|
|
56 |
CScriptIO::CScriptIO(CScriptExecutor* aScriptExecutor)
|
|
57 |
: iScriptExecutor(aScriptExecutor)
|
|
58 |
/**
|
|
59 |
Constructor for CSetCommand, used in the first phase of construction.
|
|
60 |
|
|
61 |
@param aScriptExecutor a pointer to script executor.
|
|
62 |
@param aCommPort a reference to COMM port.
|
|
63 |
*/
|
|
64 |
{}
|
|
65 |
|
|
66 |
void CScriptIO::ConstructL(const TDesC& aCommsChannel)
|
|
67 |
/**
|
|
68 |
Instantiates member variables.
|
|
69 |
*/
|
|
70 |
{
|
|
71 |
CommConstructL(KCommReadPriority,KCommWritePriority);
|
|
72 |
iChat=CCommChatter::NewL(this,KChatterPriority,KChatBufferSize);
|
|
73 |
iPreSendPause=CPreSendPause::NewL(this);
|
|
74 |
iExcessData.Set(NULL,0);
|
|
75 |
|
|
76 |
iCommsChannel.CreateL(aCommsChannel);
|
|
77 |
iCommsChannel.Copy(aCommsChannel);
|
|
78 |
}
|
|
79 |
|
|
80 |
void CScriptIO::CreateChannel(TRequestStatus& aStatus)
|
|
81 |
{
|
|
82 |
ASSERT(iCreateAndShutdownStatus == NULL);
|
|
83 |
__FLOG_STATIC1(KNetDialLogFolder(),KNetDialLogFile(),_L("Script:\tOpening Comm Port '%S'"), &iCommsChannel);
|
|
84 |
|
|
85 |
iCommClosed = EFalse;
|
|
86 |
TInt err = CommOpen(iCommsChannel);
|
|
87 |
if (err != KErrNone)
|
|
88 |
{
|
|
89 |
__FLOG_STATIC1(KNetDialLogFolder(),KNetDialLogFile(),_L("Script: Error %d opening Comm Port"), err);
|
|
90 |
TRequestStatus* stat = &aStatus;
|
|
91 |
User::RequestComplete(stat, err);
|
|
92 |
}
|
|
93 |
iCreateAndShutdownStatus = &aStatus;
|
|
94 |
}
|
|
95 |
|
|
96 |
void CScriptIO::CancelCreateChannel()
|
|
97 |
{
|
|
98 |
__FLOG_STMT(_LIT8(logString,"Script:\tCancelCreateChannel()");)
|
|
99 |
__FLOG_STATIC(KNetDialLogFolder(),KNetDialLogFile(),logString());
|
|
100 |
CommCancel();
|
|
101 |
}
|
|
102 |
|
|
103 |
void CScriptIO::InitializeComplete()
|
|
104 |
{
|
|
105 |
__FLOG_STMT(_LIT8(logString,"Script:\tInitializeComplete()");)
|
|
106 |
__FLOG_STATIC(KNetDialLogFolder(),KNetDialLogFile(),logString());
|
|
107 |
ASSERT(iCreateAndShutdownStatus);
|
|
108 |
User::RequestComplete(iCreateAndShutdownStatus, KErrNone);
|
|
109 |
iCreateAndShutdownStatus = NULL;
|
|
110 |
}
|
|
111 |
|
|
112 |
void CScriptIO::ShutdownComplete(TInt aError)
|
|
113 |
{
|
|
114 |
__FLOG_STMT(_LIT8(logString,"Script:\tShutdownComplete(aError %d)");)
|
|
115 |
__FLOG_STATIC1(KNetDialLogFolder(),KNetDialLogFile(),logString(), aError);
|
|
116 |
|
|
117 |
ASSERT(iCreateAndShutdownStatus);
|
|
118 |
if (iCreateError != KErrNone) //The creation error is probably more interesting than a bad shutdown error
|
|
119 |
{
|
|
120 |
aError = iCreateError;
|
|
121 |
}
|
|
122 |
User::RequestComplete(iCreateAndShutdownStatus, aError);
|
|
123 |
iCreateAndShutdownStatus = NULL;
|
|
124 |
iCreateError = KErrNone;
|
|
125 |
iCommClosed = ETrue;
|
|
126 |
}
|
|
127 |
|
|
128 |
void CScriptIO::ConfigurePort(TRequestStatus& aStatus, const TCommConfig& aConfiguration)
|
|
129 |
/**
|
|
130 |
Configures COMM port.
|
|
131 |
|
|
132 |
@return error value from RComm::SetConfig() request.
|
|
133 |
*/
|
|
134 |
{
|
|
135 |
using namespace BasebandChannelAdaptation;
|
|
136 |
iConfig() = aConfiguration;
|
|
137 |
iBca->Ioctl(aStatus, KBcaOptLevelExtSerial, KSerialSetConfig, iConfig);
|
|
138 |
}
|
|
139 |
|
|
140 |
void CScriptIO::CancelConfigurePort()
|
|
141 |
/**
|
|
142 |
Cancel Configuration of COMM port.
|
|
143 |
*/
|
|
144 |
{
|
|
145 |
iBca->CancelIoctl();
|
|
146 |
}
|
|
147 |
|
|
148 |
void CScriptIO::ShutdownChannel(TRequestStatus& aStatus)
|
|
149 |
{
|
|
150 |
ASSERT(iCreateAndShutdownStatus == NULL);
|
|
151 |
iCreateAndShutdownStatus = &aStatus;
|
|
152 |
Stop(KErrNone);
|
|
153 |
}
|
|
154 |
|
|
155 |
void CScriptIO::Stop(TInt aError)
|
|
156 |
/**
|
|
157 |
Upcall from CScriptBcaControl class indicating an error was encountered. Clean up and close BCA.
|
|
158 |
|
|
159 |
@param aError System wide error code.
|
|
160 |
*/
|
|
161 |
{
|
|
162 |
__FLOG_STMT(_LIT8(logString,"Script:\tStop(aError %d)");)
|
|
163 |
__FLOG_STATIC1(KNetDialLogFolder(),KNetDialLogFile(),logString(), aError);
|
|
164 |
|
|
165 |
iCreateError = aError;
|
|
166 |
delete iChat;
|
|
167 |
iChat = NULL;
|
|
168 |
delete iPreSendPause;
|
|
169 |
iPreSendPause = NULL;
|
|
170 |
CommClose();
|
|
171 |
}
|
|
172 |
|
|
173 |
CScriptIO::~CScriptIO()
|
|
174 |
/**
|
|
175 |
Destructor.
|
|
176 |
Deletes iChat.
|
|
177 |
Deletes iPreSendPause.
|
|
178 |
Calls CommDelete().
|
|
179 |
*/
|
|
180 |
{
|
|
181 |
iCommsChannel.Close();
|
|
182 |
delete iChat;
|
|
183 |
delete iPreSendPause;
|
|
184 |
CommDelete();
|
|
185 |
}
|
|
186 |
|
|
187 |
|
|
188 |
void CScriptIO::Start()
|
|
189 |
/**
|
|
190 |
Starts write.
|
|
191 |
*/
|
|
192 |
{
|
|
193 |
CommWriteReady();
|
|
194 |
iWritePending=ETrue;
|
|
195 |
iChat->StartTimer(KWriteTimeOutSec*KOneSecInMicroSecs);
|
|
196 |
}
|
|
197 |
|
|
198 |
void CScriptIO::CommReadComplete(TInt aStatus)
|
|
199 |
/**
|
|
200 |
Reads completely - stops timer and if no error checks string against the desired string
|
|
201 |
*/
|
|
202 |
{
|
|
203 |
__FLOG_STMT(_LIT8(logString1,"Script:\tRead Complete");)
|
|
204 |
__FLOG_STATIC(KNetDialLogFolder(),KNetDialLogFile(),logString1());
|
|
205 |
if(aStatus==KErrCommsLineFail)
|
|
206 |
{
|
|
207 |
__FLOG_STMT(_LIT8(logString2,"Script:\tComms Error %d");)
|
|
208 |
__FLOG_STATIC1(KNetDialLogFolder(),KNetDialLogFile(),TRefByValue<const TDesC8>(logString2()),aStatus);
|
|
209 |
iChat->StopTimer();
|
|
210 |
iReadPending=EFalse;
|
|
211 |
TRAPD(ret,iScriptExecutor->CompletedReadL(KErrCommsLineFail));
|
|
212 |
if (KErrNone != ret)
|
|
213 |
{
|
|
214 |
__FLOG_STMT(_LIT8(logString6,"Script:\tCompleteReadL Failure");)
|
|
215 |
__FLOG_STATIC(KNetDialLogFolder(),KNetDialLogFile(),logString6());
|
|
216 |
}
|
|
217 |
return;
|
|
218 |
}
|
|
219 |
|
|
220 |
__ASSERT_ALWAYS(iReadPending,NetDialPanic(EIllegalReadComplete));
|
|
221 |
iReadPending=EFalse;
|
|
222 |
|
|
223 |
|
|
224 |
if (aStatus==KErrCommsFrame)
|
|
225 |
{
|
|
226 |
__FLOG_STMT(_LIT(logString3,"Script:\tComms Error %d");)
|
|
227 |
__FLOG_STATIC1(KNetDialLogFolder(),KNetDialLogFile(),TRefByValue<const TDesC>(logString3()),aStatus);
|
|
228 |
User::After(KClockTick); // wait for a clock tick and continue
|
|
229 |
aStatus=KErrNone;
|
|
230 |
}
|
|
231 |
|
|
232 |
else if (aStatus!=KErrNone)
|
|
233 |
{
|
|
234 |
TRAPD(ret,iScriptExecutor->CompletedReadL(aStatus));
|
|
235 |
if (KErrNone != ret)
|
|
236 |
{
|
|
237 |
__FLOG_STMT(_LIT8(logString7,"Script:\tCompleteReadL Failure");)
|
|
238 |
__FLOG_STATIC(KNetDialLogFolder(),KNetDialLogFile(),logString7());
|
|
239 |
}
|
|
240 |
return;
|
|
241 |
}
|
|
242 |
|
|
243 |
#ifdef __FLOG_ACTIVE
|
|
244 |
_LIT(logString4,"Rx:\t%S");
|
|
245 |
TBuf16<KLogBufferSize> temp;
|
|
246 |
temp.Copy(iRxBuffer.Left(Min(iRxBuffer.Length(),KLogBufferSize)));
|
|
247 |
__FLOG_STATIC1(KNetDialLogFolder(),KNetDialLogFile(),TRefByValue<const TDesC>(logString4()),&temp);
|
|
248 |
#endif
|
|
249 |
|
|
250 |
if (iScriptExecutor->RequestUsePct())
|
|
251 |
{
|
|
252 |
TInt err=iScriptExecutor->WritePct(iRxBuffer);
|
|
253 |
if (err!=KErrNone)
|
|
254 |
{
|
|
255 |
TRAPD(ret,iScriptExecutor->CompletedReadL(err));
|
|
256 |
if (KErrNone != ret)
|
|
257 |
{
|
|
258 |
__FLOG_STMT(_LIT8(logString8,"Script:\tCompleteReadL Failure");)
|
|
259 |
__FLOG_STATIC(KNetDialLogFolder(),KNetDialLogFile(),logString8());
|
|
260 |
}
|
|
261 |
return;
|
|
262 |
}
|
|
263 |
}
|
|
264 |
|
|
265 |
if (!iScriptExecutor->ReadPctPending())
|
|
266 |
{
|
|
267 |
for (iRxBufOffset=0; iRxBufOffset<iRxBuffer.Length(); iRxBufOffset++)
|
|
268 |
{
|
|
269 |
iChat->AddChar(iRxBuffer[iRxBufOffset]);
|
|
270 |
if(iStringFound!=-1)
|
|
271 |
{
|
|
272 |
iExcessData.Set(iRxBuffer.Right(iRxBuffer.Length()-iRxBufOffset-1));
|
|
273 |
#ifdef __FLOG_ACTIVE
|
|
274 |
_LIT(logString5,"Script:\tExcess data buffer set to: %S");
|
|
275 |
TBuf16<KLogBufferSize> temp;
|
|
276 |
temp.Copy(iExcessData.Left(Min(iExcessData.Length(),KLogBufferSize)));
|
|
277 |
__FLOG_STATIC1(KNetDialLogFolder(),KNetDialLogFile(),TRefByValue<const TDesC>(logString5()),&temp);
|
|
278 |
#endif
|
|
279 |
break;
|
|
280 |
}
|
|
281 |
}
|
|
282 |
}
|
|
283 |
else
|
|
284 |
iStringFound=KErrNotFound;
|
|
285 |
|
|
286 |
if(iStringFound!=KErrNotFound)
|
|
287 |
{
|
|
288 |
iChat->StopTimer();
|
|
289 |
TRAPD(ret,iScriptExecutor->CompletedReadL(aStatus,iStringFound));
|
|
290 |
if (KErrNone != ret)
|
|
291 |
{
|
|
292 |
__FLOG_STMT(_LIT8(logString9,"Script:\tCompleteReadL Failure");)
|
|
293 |
__FLOG_STATIC(KNetDialLogFolder(),KNetDialLogFile(),logString9());
|
|
294 |
}
|
|
295 |
}
|
|
296 |
else
|
|
297 |
{
|
|
298 |
iReadPending=ETrue;
|
|
299 |
CommReadOneOrMore(iRxBuffer);
|
|
300 |
}
|
|
301 |
}
|
|
302 |
|
|
303 |
void CScriptIO::CommWriteComplete(TInt aStatus)
|
|
304 |
/**
|
|
305 |
Writes completely - stops timer
|
|
306 |
*/
|
|
307 |
{
|
|
308 |
__FLOG_STMT(_LIT8(logString,"Script:\tWrite Complete");)
|
|
309 |
__FLOG_STATIC(KNetDialLogFolder(),KNetDialLogFile(),logString());
|
|
310 |
iChat->StopTimer();
|
|
311 |
if(aStatus==KErrCommsLineFail)
|
|
312 |
{
|
|
313 |
__FLOG_STMT(_LIT8(logString2,"Script:\tComms Error %d");)
|
|
314 |
__FLOG_STATIC1(KNetDialLogFolder(),KNetDialLogFile(),logString2(),aStatus);
|
|
315 |
iWritePending=EFalse;
|
|
316 |
iScriptExecutor->CompletedWrite(KErrCommsLineFail);
|
|
317 |
return;
|
|
318 |
}
|
|
319 |
__ASSERT_ALWAYS(iWritePending,NetDialPanic(EIllegalWriteComplete));
|
|
320 |
iWritePending=EFalse;
|
|
321 |
if(aStatus==KErrCommsFrame) // ignore Comms Frame Error
|
|
322 |
aStatus=KErrNone;
|
|
323 |
iScriptExecutor->CompletedWrite(aStatus);
|
|
324 |
}
|
|
325 |
|
|
326 |
void CScriptIO::ChatStringMatch(TInt aIndex)
|
|
327 |
/**
|
|
328 |
Logs matching string found and sets iStringFound to aIndex.
|
|
329 |
*/
|
|
330 |
{
|
|
331 |
__FLOG_STMT(_LIT8(logString,"Script:\tMatching String Found %d");)
|
|
332 |
__FLOG_STATIC1(KNetDialLogFolder(),KNetDialLogFile(),TRefByValue<const TDesC8>(logString()),aIndex);
|
|
333 |
iStringFound=aIndex;
|
|
334 |
}
|
|
335 |
|
|
336 |
void CScriptIO::ChatTimeout()
|
|
337 |
/**
|
|
338 |
Timeout has occurred without while read/write pending. Calls executor with error.
|
|
339 |
*/
|
|
340 |
{
|
|
341 |
CommCancel();
|
|
342 |
if(iWritePending)
|
|
343 |
{
|
|
344 |
__FLOG_STMT(_LIT8(logString1,"Script:\tWrite Chat Time Out");)
|
|
345 |
__FLOG_STATIC(KNetDialLogFolder(),KNetDialLogFile(),logString1());
|
|
346 |
iWritePending=EFalse;
|
|
347 |
iScriptExecutor->CompletedWrite(KErrTimedOut);
|
|
348 |
}
|
|
349 |
else if(iReadPending)
|
|
350 |
{
|
|
351 |
__FLOG_STMT(_LIT8(logString2,"Script:\tRead Chat Time Out");)
|
|
352 |
__FLOG_STATIC(KNetDialLogFolder(),KNetDialLogFile(),logString2());
|
|
353 |
iReadPending=EFalse;
|
|
354 |
TRAPD(ret,iScriptExecutor->CompletedReadL(KErrTimedOut));
|
|
355 |
if (KErrNone != ret)
|
|
356 |
{
|
|
357 |
__FLOG_STMT(_LIT8(logString3,"Script:\tCompleteReadL Failure");)
|
|
358 |
__FLOG_STATIC(KNetDialLogFolder(),KNetDialLogFile(),logString3());
|
|
359 |
}
|
|
360 |
}
|
|
361 |
else
|
|
362 |
NetDialPanic(EIllegalTimeOutComplete);
|
|
363 |
}
|
|
364 |
|
|
365 |
void CScriptIO::Read(CLabelSearchArray* aSearchArray, const TReal& aTimeOut)
|
|
366 |
/**
|
|
367 |
Read from port.
|
|
368 |
*/
|
|
369 |
{
|
|
370 |
__ASSERT_ALWAYS(aSearchArray!=NULL, NetDialPanic(ENullSearchArray));
|
|
371 |
|
|
372 |
iExcessData.Set(NULL,0); // clear excess data buffer
|
|
373 |
|
|
374 |
for(TInt i=0; i<aSearchArray->Count(); i++)
|
|
375 |
{
|
|
376 |
iChat->AddString((*aSearchArray)[i]->ChatString());
|
|
377 |
}
|
|
378 |
iReadPending=ETrue;
|
|
379 |
iStringFound=KErrNotFound;
|
|
380 |
//
|
|
381 |
TReal realTimeInterval=aTimeOut*KTRealOneSecInMicroSecs;
|
|
382 |
TInt timeInterval=TInt(realTimeInterval);
|
|
383 |
if (realTimeInterval>TReal(timeInterval))
|
|
384 |
timeInterval++;
|
|
385 |
__FLOG_STMT(_LIT8(logString,"Script:\tRead Pending In %d Microseconds");)
|
|
386 |
__FLOG_STATIC1(KNetDialLogFolder(),KNetDialLogFile(),logString(),timeInterval);
|
|
387 |
//
|
|
388 |
iChat->StartTimer(timeInterval);
|
|
389 |
CommReadOneOrMore(iRxBuffer);
|
|
390 |
iRxBufOffset=0;
|
|
391 |
}
|
|
392 |
|
|
393 |
void CScriptIO::ReadEcho()
|
|
394 |
/**
|
|
395 |
Reads echo.
|
|
396 |
*/
|
|
397 |
{
|
|
398 |
__FLOG_STMT(_LIT8(logString,"Script:\tRead Echo");)
|
|
399 |
__FLOG_STATIC(KNetDialLogFolder(),KNetDialLogFile(),logString());
|
|
400 |
iExcessData.Set(NULL,0); // clear excess data buffer
|
|
401 |
|
|
402 |
iReadPending=ETrue;
|
|
403 |
iChat->StartTimer(KMaxTInt);
|
|
404 |
CommReadOneOrMore(iRxBuffer);
|
|
405 |
iRxBufOffset=0;
|
|
406 |
}
|
|
407 |
|
|
408 |
void CScriptIO::Write(const TDesC8& aString)
|
|
409 |
/**
|
|
410 |
Writes to port - start pre-send pause, when it completes, will start write.
|
|
411 |
*/
|
|
412 |
{
|
|
413 |
if (aString.Length()>KTxBufferSize)
|
|
414 |
iTxBuffer.Copy(aString.Left(KTxBufferSize));
|
|
415 |
else
|
|
416 |
iTxBuffer.Copy(aString);
|
|
417 |
__ASSERT_ALWAYS(!iWritePending, NetDialPanic(EIllegalWritePending));
|
|
418 |
iWritePending=ETrue;
|
|
419 |
iPreSendPause->Start();
|
|
420 |
}
|
|
421 |
|
|
422 |
void CScriptIO::PreSendPauseCompleted()
|
|
423 |
/**
|
|
424 |
PreSend pause is finished, can now do write.
|
|
425 |
*/
|
|
426 |
{
|
|
427 |
#ifdef __FLOG_ACTIVE
|
|
428 |
_LIT(logString,"Tx:\t%S");
|
|
429 |
TBuf16<KLogBufferSize> temp;
|
|
430 |
temp.Copy(iTxBuffer.Left(Min(iTxBuffer.Length(),KLogBufferSize)));
|
|
431 |
__FLOG_STATIC1(KNetDialLogFolder(),KNetDialLogFile(),TRefByValue<const TDesC>(logString()),&temp);
|
|
432 |
#endif
|
|
433 |
CommWrite(iTxBuffer);
|
|
434 |
iChat->StartTimer(KWriteTimeOutSec*KOneSecInMicroSecs);
|
|
435 |
}
|
|
436 |
|
|
437 |
TBool CScriptIO::RWPending()
|
|
438 |
/**
|
|
439 |
Returns true if a read or write is pending.
|
|
440 |
*/
|
|
441 |
{
|
|
442 |
return (iWritePending)||(iReadPending);
|
|
443 |
}
|
|
444 |
|
|
445 |
TInt CScriptIO::GetExcessData(TDes8& aBuffer)
|
|
446 |
/**
|
|
447 |
Gets excess data.
|
|
448 |
*/
|
|
449 |
{
|
|
450 |
TInt len=aBuffer.Length();
|
|
451 |
if(iExcessData.Length()>len)
|
|
452 |
aBuffer.Copy(iExcessData.Right(len));
|
|
453 |
else
|
|
454 |
aBuffer.Copy(iExcessData);
|
|
455 |
return KErrNone;
|
|
456 |
}
|
|
457 |
|
|
458 |
void CScriptIO::Disconnect()
|
|
459 |
/**
|
|
460 |
Disconnection - resets handshaking and closes comm port.
|
|
461 |
*/
|
|
462 |
{
|
|
463 |
Cancel();
|
|
464 |
/* TCommConfig cbuf;
|
|
465 |
TCommConfigV01 &cfg=cbuf();
|
|
466 |
iCommPort.Config(cbuf);
|
|
467 |
cfg.iHandshake = KConfigFreeRTS | KConfigFreeDTR;
|
|
468 |
iCommPort.SetConfig(cbuf); // ignore return value
|
|
469 |
iCommPort.SetSignalsToSpace(KSignalRTS | KSignalDTR);
|
|
470 |
*/
|
|
471 |
// Don't issue a CommClose() if we have already issued it before.
|
|
472 |
if (!iCommClosed)
|
|
473 |
{
|
|
474 |
CommClose();
|
|
475 |
}
|
|
476 |
}
|
|
477 |
|
|
478 |
void CScriptIO::ReConfigureAndCancelPort(TRequestStatus& aStatus)
|
|
479 |
/**
|
|
480 |
Cancels and reconfigures Comm Port to allow RTS and DTR to be subsequently dropped (see also DropSignals()).
|
|
481 |
|
|
482 |
@param aStatus TRequestStatus to complete once Comm Port is configured.
|
|
483 |
*/
|
|
484 |
{
|
|
485 |
using namespace BasebandChannelAdaptation;
|
|
486 |
|
|
487 |
Cancel();
|
|
488 |
|
|
489 |
// Someone has (presumably accidentally) defined Ioctls KSerialConfig and KSerialSetConfig as
|
|
490 |
// requiring a package buffer within a package buffer, hence the use of "()()".
|
|
491 |
iConfig()().iHandshake = KConfigFreeRTS | KConfigFreeDTR;
|
|
492 |
|
|
493 |
iBca->Ioctl(aStatus, KBcaOptLevelExtSerial, KSerialSetConfig, iConfig);
|
|
494 |
}
|
|
495 |
|
|
496 |
void CScriptIO::DropSignals(TRequestStatus& aStatus)
|
|
497 |
/**
|
|
498 |
Drop RTS and DTR. Occurs once ReConfigureAndCancelPort() has released the signals.
|
|
499 |
|
|
500 |
@param aStatus TRequestStatus to complete once signals have been dropped.
|
|
501 |
*/
|
|
502 |
{
|
|
503 |
SetControlLines(&aStatus, 0, KSignalRTS | KSignalDTR);
|
|
504 |
}
|
|
505 |
|
|
506 |
void CScriptIO::Cancel()
|
|
507 |
/**
|
|
508 |
Cancel - cancels timers and read/write
|
|
509 |
*/
|
|
510 |
{
|
|
511 |
|
|
512 |
CommCancel();
|
|
513 |
if (iPreSendPause)
|
|
514 |
{
|
|
515 |
iPreSendPause->Cancel();
|
|
516 |
}
|
|
517 |
iReadPending=EFalse;
|
|
518 |
iWritePending=EFalse;
|
|
519 |
iExcessData.Set(NULL,0);
|
|
520 |
if (iChat)
|
|
521 |
{
|
|
522 |
iChat->StopTimer();
|
|
523 |
iChat->DeleteAllAndStop();
|
|
524 |
}
|
|
525 |
}
|
|
526 |
|
|
527 |
|
|
528 |
void CScriptIO::ReadEchoCancel()
|
|
529 |
/**
|
|
530 |
Cancel read - cancels timers and read
|
|
531 |
*/
|
|
532 |
{
|
|
533 |
|
|
534 |
CommReadCancel();
|
|
535 |
iReadPending=EFalse;
|
|
536 |
iExcessData.Set(NULL,0);
|
|
537 |
iChat->StopTimer();
|
|
538 |
}
|
|
539 |
|
|
540 |
void CScriptIO::DropDTR(TRequestStatus* aStatusPtr)
|
|
541 |
/**
|
|
542 |
Drop DTR.
|
|
543 |
*/
|
|
544 |
{
|
|
545 |
Cancel();
|
|
546 |
SetControlLines(aStatusPtr, 0, KSignalDTR);
|
|
547 |
}
|
|
548 |
|
|
549 |
|
|
550 |
void CScriptIO::RaiseDTR(TRequestStatus* aStatusPtr)
|
|
551 |
/**
|
|
552 |
Raide DTR.
|
|
553 |
*/
|
|
554 |
{
|
|
555 |
Cancel();
|
|
556 |
SetControlLines(aStatusPtr, KSignalDTR, 0);
|
|
557 |
}
|
|
558 |
|
|
559 |
void CScriptIO::SetControlLines(TRequestStatus* aStatusPtr, TUint aSetMask, TUint aClearMask)
|
|
560 |
/**
|
|
561 |
Issue request to BCA to alter control lines.
|
|
562 |
*/
|
|
563 |
{
|
|
564 |
using namespace BasebandChannelAdaptation;
|
|
565 |
TPckgBuf<TSerialSetControlLines> lines;
|
|
566 |
lines().iSetMask = aSetMask;
|
|
567 |
lines().iClearMask = aClearMask;
|
|
568 |
if (aStatusPtr == NULL)
|
|
569 |
{
|
|
570 |
// During conversion from RComm to BCA, synchronous behaviour was allowed in this particular circumstance.
|
|
571 |
// This is to avoid wholesale changes to the CSD Agent to accomodate rarely (if ever) traversed
|
|
572 |
// code paths. The original RComm based code would previously issue a synchronous RComm::SetSignals()
|
|
573 |
// call at this point, so the synchronous behaviour here is no worse than before.
|
|
574 |
TRequestStatus status;
|
|
575 |
iBca->Ioctl(status, KBcaOptLevelExtSerial, KSerialSetControlLines, lines);
|
|
576 |
User::WaitForRequest(status);
|
|
577 |
}
|
|
578 |
else
|
|
579 |
{
|
|
580 |
iBca->Ioctl(*aStatusPtr, KBcaOptLevelExtSerial, KSerialSetControlLines, lines);
|
|
581 |
}
|
|
582 |
}
|
|
583 |
|
|
584 |
const TDesC& CScriptIO::BcaStack()
|
|
585 |
{
|
|
586 |
ASSERT(iScriptExecutor);
|
|
587 |
return iScriptExecutor->BcaStack();
|
|
588 |
}
|
|
589 |
|
|
590 |
TInt CScriptIO::IapId()
|
|
591 |
{
|
|
592 |
ASSERT(iScriptExecutor);
|
|
593 |
return iScriptExecutor->IapId();
|
|
594 |
}
|
|
595 |
|
|
596 |
// CPreSendPause definitions
|
|
597 |
|
|
598 |
CPreSendPause* CPreSendPause::NewL(CScriptIO* aNotifier)
|
|
599 |
/**
|
|
600 |
2 phased constructor for CPreSendPause, first phase.
|
|
601 |
|
|
602 |
@param aNotifier a pointer to script IO notifier.
|
|
603 |
@exception Leaves if ConstructL() leaves, or not enough memory is available.
|
|
604 |
@return a new CPreSendPause object.
|
|
605 |
*/
|
|
606 |
{
|
|
607 |
CPreSendPause* p=new(ELeave) CPreSendPause(aNotifier);
|
|
608 |
CleanupStack::PushL(p);
|
|
609 |
p->ConstructL(); // CTimer::ConstructL()
|
|
610 |
CleanupStack::Pop();
|
|
611 |
return p;
|
|
612 |
}
|
|
613 |
|
|
614 |
CPreSendPause::CPreSendPause(CScriptIO* aNotifier)
|
|
615 |
: CTimer(EPriorityStandard), iNotifier(aNotifier)
|
|
616 |
/**
|
|
617 |
Constructor for CScriptCharacterConverter, used in the first phase of construction.
|
|
618 |
*/
|
|
619 |
{
|
|
620 |
CActiveScheduler::Add(this);
|
|
621 |
}
|
|
622 |
|
|
623 |
void CPreSendPause::Start()
|
|
624 |
/**
|
|
625 |
Starts timer.
|
|
626 |
*/
|
|
627 |
{
|
|
628 |
After(KPreSendPauseTimeMicroSec);
|
|
629 |
}
|
|
630 |
|
|
631 |
void CPreSendPause::RunL()
|
|
632 |
/**
|
|
633 |
Notifies script IO that pause complete.
|
|
634 |
*/
|
|
635 |
{
|
|
636 |
iNotifier->PreSendPauseCompleted();
|
|
637 |
}
|