sl@0
|
1 |
// Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
//
|
sl@0
|
15 |
|
sl@0
|
16 |
#include <pdrport.h>
|
sl@0
|
17 |
#include "printerport.h"
|
sl@0
|
18 |
|
sl@0
|
19 |
_LIT(KPdrStoreECUART,"ECUART");
|
sl@0
|
20 |
|
sl@0
|
21 |
EXPORT_C CFilePrinterPort* CFilePrinterPort::NewL(const TDesC& aFileName)
|
sl@0
|
22 |
{
|
sl@0
|
23 |
CFilePrinterPort* fileprinterport = new(ELeave) CFilePrinterPort(aFileName);
|
sl@0
|
24 |
CleanupStack::PushL(fileprinterport);
|
sl@0
|
25 |
fileprinterport->ConstructL();
|
sl@0
|
26 |
CleanupStack::Pop();
|
sl@0
|
27 |
return fileprinterport;
|
sl@0
|
28 |
}
|
sl@0
|
29 |
|
sl@0
|
30 |
EXPORT_C CFilePrinterPort::~CFilePrinterPort()
|
sl@0
|
31 |
{
|
sl@0
|
32 |
iFile.Close();
|
sl@0
|
33 |
if (iCancelled)
|
sl@0
|
34 |
iFs.Delete(iFileName); // ignore error
|
sl@0
|
35 |
iFs.Close();
|
sl@0
|
36 |
}
|
sl@0
|
37 |
/** Implementation of the pure virtual function inherited from CPrinterPort.
|
sl@0
|
38 |
|
sl@0
|
39 |
Writes data asynchronously to the concrete file printer port.
|
sl@0
|
40 |
|
sl@0
|
41 |
@param aBuf A descriptor containing the data to be written to the file printer port.
|
sl@0
|
42 |
@param aRequestStatus A reference to the request status object.
|
sl@0
|
43 |
On completion contains KErrNone if the data is successfully written to
|
sl@0
|
44 |
this file printer port, otherwise if the request is cancelled, this should
|
sl@0
|
45 |
be set to KErrCancel.
|
sl@0
|
46 |
*/
|
sl@0
|
47 |
void CFilePrinterPort::WriteRequest(const TDesC8& aBuf, TRequestStatus& aRequestStatus)
|
sl@0
|
48 |
{
|
sl@0
|
49 |
// iFile.Write(aBuf,aRequestStatus); //!! real code with fixed F32
|
sl@0
|
50 |
//
|
sl@0
|
51 |
TRequestStatus* pStatus=&aRequestStatus; // F32 bug workaround code
|
sl@0
|
52 |
User::RequestComplete(pStatus, iFile.Write(aBuf)); // F32 bug workaround code
|
sl@0
|
53 |
}
|
sl@0
|
54 |
|
sl@0
|
55 |
void CFilePrinterPort::Cancel()
|
sl@0
|
56 |
{
|
sl@0
|
57 |
iCancelled = ETrue;
|
sl@0
|
58 |
}
|
sl@0
|
59 |
|
sl@0
|
60 |
void CFilePrinterPort::ConstructL()
|
sl@0
|
61 |
{
|
sl@0
|
62 |
User::LeaveIfError(iFs.Connect());
|
sl@0
|
63 |
User::LeaveIfError(iFile.Replace(iFs, iFileName,EFileStream|EFileWrite));
|
sl@0
|
64 |
}
|
sl@0
|
65 |
|
sl@0
|
66 |
CFilePrinterPort::CFilePrinterPort(const TDesC& aFileName)
|
sl@0
|
67 |
: iFileName(aFileName)
|
sl@0
|
68 |
{
|
sl@0
|
69 |
}
|
sl@0
|
70 |
|
sl@0
|
71 |
EXPORT_C TOutputHandshake::TOutputHandshake()
|
sl@0
|
72 |
: iXonXoff(EFalse),
|
sl@0
|
73 |
iCts(ETrue),
|
sl@0
|
74 |
iDsr(ETrue),
|
sl@0
|
75 |
iDcd(EFalse)
|
sl@0
|
76 |
{
|
sl@0
|
77 |
}
|
sl@0
|
78 |
|
sl@0
|
79 |
EXPORT_C void TOutputHandshake::InternalizeL(RReadStream& aStream)
|
sl@0
|
80 |
{
|
sl@0
|
81 |
iXonXoff = aStream.ReadInt8L();
|
sl@0
|
82 |
iCts = aStream.ReadInt8L();
|
sl@0
|
83 |
iDsr = aStream.ReadInt8L();
|
sl@0
|
84 |
iDcd = aStream.ReadInt8L();
|
sl@0
|
85 |
}
|
sl@0
|
86 |
|
sl@0
|
87 |
EXPORT_C void TOutputHandshake::ExternalizeL(RWriteStream& aStream) const
|
sl@0
|
88 |
{
|
sl@0
|
89 |
aStream.WriteInt8L(iXonXoff);
|
sl@0
|
90 |
aStream.WriteInt8L(iCts);
|
sl@0
|
91 |
aStream.WriteInt8L(iDsr);
|
sl@0
|
92 |
aStream.WriteInt8L(iDcd);
|
sl@0
|
93 |
}
|
sl@0
|
94 |
|
sl@0
|
95 |
EXPORT_C TSerialPrinterPortConfig::TSerialPrinterPortConfig()
|
sl@0
|
96 |
: iRate(EBps9600),
|
sl@0
|
97 |
iDataBits(EData8),
|
sl@0
|
98 |
iStopBits(EStop1),
|
sl@0
|
99 |
iParity(EParityNone),
|
sl@0
|
100 |
iIgnoreParity(EFalse),
|
sl@0
|
101 |
iHandshake()
|
sl@0
|
102 |
{
|
sl@0
|
103 |
}
|
sl@0
|
104 |
|
sl@0
|
105 |
EXPORT_C void TSerialPrinterPortConfig::InternalizeL(RReadStream& aStream)
|
sl@0
|
106 |
{
|
sl@0
|
107 |
iRate = (TBps) aStream.ReadInt8L();
|
sl@0
|
108 |
iDataBits = (TDataBits) aStream.ReadInt8L();
|
sl@0
|
109 |
iStopBits = (TStopBits) aStream.ReadInt8L();
|
sl@0
|
110 |
iParity = (TParity) aStream.ReadInt8L();
|
sl@0
|
111 |
iIgnoreParity = aStream.ReadInt8L();
|
sl@0
|
112 |
iHandshake.InternalizeL(aStream);
|
sl@0
|
113 |
}
|
sl@0
|
114 |
|
sl@0
|
115 |
EXPORT_C void TSerialPrinterPortConfig::ExternalizeL(RWriteStream& aStream) const
|
sl@0
|
116 |
{
|
sl@0
|
117 |
aStream.WriteInt8L(iRate);
|
sl@0
|
118 |
aStream.WriteInt8L(iDataBits);
|
sl@0
|
119 |
aStream.WriteInt8L(iStopBits);
|
sl@0
|
120 |
aStream.WriteInt8L(iParity);
|
sl@0
|
121 |
aStream.WriteInt8L(iIgnoreParity);
|
sl@0
|
122 |
iHandshake.ExternalizeL(aStream);
|
sl@0
|
123 |
}
|
sl@0
|
124 |
|
sl@0
|
125 |
EXPORT_C CCommPrinterPort* CCommPrinterPort::NewL(const TDesC& aCsyName, const TDesC& aPortName, const TSerialPrinterPortConfig& aConfig, const TFifo aFifo)
|
sl@0
|
126 |
{
|
sl@0
|
127 |
CCommPrinterPort* commprinterport = new(ELeave) CCommPrinterPort;
|
sl@0
|
128 |
CleanupStack::PushL(commprinterport);
|
sl@0
|
129 |
commprinterport->ConstructL(aCsyName, aPortName, aConfig, aFifo);
|
sl@0
|
130 |
CleanupStack::Pop();
|
sl@0
|
131 |
return commprinterport;
|
sl@0
|
132 |
}
|
sl@0
|
133 |
|
sl@0
|
134 |
EXPORT_C CCommPrinterPort::~CCommPrinterPort()
|
sl@0
|
135 |
{
|
sl@0
|
136 |
iComm.Close();
|
sl@0
|
137 |
iCommServ.Close();
|
sl@0
|
138 |
}
|
sl@0
|
139 |
|
sl@0
|
140 |
EXPORT_C void CCommPrinterPort::WriteRequest(const TDesC8& aBuf, TRequestStatus& aRequestStatus)
|
sl@0
|
141 |
{
|
sl@0
|
142 |
iComm.Write(aRequestStatus, 20000000, aBuf); // Times out after 20 seconds
|
sl@0
|
143 |
}
|
sl@0
|
144 |
|
sl@0
|
145 |
EXPORT_C void CCommPrinterPort::Cancel()
|
sl@0
|
146 |
{
|
sl@0
|
147 |
iComm.WriteCancel();
|
sl@0
|
148 |
}
|
sl@0
|
149 |
|
sl@0
|
150 |
EXPORT_C void CCommPrinterPort::ConstructL(const TDesC& aCsyName, const TDesC& aPortName, const TSerialPrinterPortConfig& aConfig, const TFifo aFifo)
|
sl@0
|
151 |
{
|
sl@0
|
152 |
User::LeaveIfError(iCommServ.Connect());
|
sl@0
|
153 |
User::LeaveIfError(iCommServ.LoadCommModule(aCsyName));
|
sl@0
|
154 |
User::LeaveIfError(iComm.Open(iCommServ, aPortName, ECommExclusive));
|
sl@0
|
155 |
|
sl@0
|
156 |
TCommConfig config;
|
sl@0
|
157 |
iComm.Config(config);
|
sl@0
|
158 |
config().iRate = aConfig.iRate;
|
sl@0
|
159 |
config().iDataBits = aConfig.iDataBits;
|
sl@0
|
160 |
config().iStopBits = aConfig.iStopBits;
|
sl@0
|
161 |
config().iParityErrorChar = STATIC_CAST(TText8, aConfig.iParity);
|
sl@0
|
162 |
if (aConfig.iIgnoreParity)
|
sl@0
|
163 |
config().iParityErrorChar = KConfigParityErrorIgnore;
|
sl@0
|
164 |
TUint handshake = 0;
|
sl@0
|
165 |
if (aConfig.iHandshake.iXonXoff)
|
sl@0
|
166 |
handshake = handshake | KConfigObeyXoff;
|
sl@0
|
167 |
if (aConfig.iHandshake.iCts)
|
sl@0
|
168 |
handshake = handshake | KConfigObeyCTS;
|
sl@0
|
169 |
if (aConfig.iHandshake.iDsr)
|
sl@0
|
170 |
handshake = handshake | KConfigObeyDSR;
|
sl@0
|
171 |
if (aConfig.iHandshake.iDcd)
|
sl@0
|
172 |
handshake = handshake | KConfigObeyDCD;
|
sl@0
|
173 |
config().iHandshake = handshake;
|
sl@0
|
174 |
config().iFifo = aFifo;
|
sl@0
|
175 |
User::LeaveIfError(iComm.SetConfig(config));
|
sl@0
|
176 |
}
|
sl@0
|
177 |
|
sl@0
|
178 |
EXPORT_C CCommPrinterPort::CCommPrinterPort()
|
sl@0
|
179 |
: CPrinterPort(),
|
sl@0
|
180 |
iCommServ(),
|
sl@0
|
181 |
iComm()
|
sl@0
|
182 |
{
|
sl@0
|
183 |
}
|
sl@0
|
184 |
|
sl@0
|
185 |
EXPORT_C CSerialPrinterPort* CSerialPrinterPort::NewL(const TDesC& aPortName, const TSerialPrinterPortConfig& aConfig)
|
sl@0
|
186 |
{
|
sl@0
|
187 |
CSerialPrinterPort* serialprinterport=new(ELeave) CSerialPrinterPort(aConfig);
|
sl@0
|
188 |
CleanupStack::PushL(serialprinterport);
|
sl@0
|
189 |
serialprinterport->ConstructL(aPortName);
|
sl@0
|
190 |
CleanupStack::Pop();
|
sl@0
|
191 |
return serialprinterport;
|
sl@0
|
192 |
}
|
sl@0
|
193 |
|
sl@0
|
194 |
EXPORT_C CSerialPrinterPort::~CSerialPrinterPort()
|
sl@0
|
195 |
{
|
sl@0
|
196 |
}
|
sl@0
|
197 |
|
sl@0
|
198 |
EXPORT_C TSerialPrinterPortConfig CSerialPrinterPort::Config()
|
sl@0
|
199 |
{
|
sl@0
|
200 |
return iConfig;
|
sl@0
|
201 |
}
|
sl@0
|
202 |
|
sl@0
|
203 |
void CSerialPrinterPort::ConstructL(const TDesC& aPortName)
|
sl@0
|
204 |
{
|
sl@0
|
205 |
CCommPrinterPort::ConstructL(KPdrStoreECUART, aPortName, iConfig);
|
sl@0
|
206 |
}
|
sl@0
|
207 |
|
sl@0
|
208 |
CSerialPrinterPort::CSerialPrinterPort(const TSerialPrinterPortConfig& aConfig)
|
sl@0
|
209 |
: CCommPrinterPort(),
|
sl@0
|
210 |
iConfig(aConfig)
|
sl@0
|
211 |
{
|
sl@0
|
212 |
}
|
sl@0
|
213 |
|
sl@0
|
214 |
EXPORT_C CParallelPrinterPort* CParallelPrinterPort::NewL(const TDesC& aPortName)
|
sl@0
|
215 |
{
|
sl@0
|
216 |
CParallelPrinterPort* parallelprinterport = new(ELeave) CParallelPrinterPort;
|
sl@0
|
217 |
CleanupStack::PushL(parallelprinterport);
|
sl@0
|
218 |
parallelprinterport->ConstructL(aPortName);
|
sl@0
|
219 |
CleanupStack::Pop();
|
sl@0
|
220 |
return parallelprinterport;
|
sl@0
|
221 |
}
|
sl@0
|
222 |
|
sl@0
|
223 |
EXPORT_C CParallelPrinterPort::~CParallelPrinterPort()
|
sl@0
|
224 |
{
|
sl@0
|
225 |
}
|
sl@0
|
226 |
|
sl@0
|
227 |
void CParallelPrinterPort::ConstructL(const TDesC& aPortName)
|
sl@0
|
228 |
{
|
sl@0
|
229 |
TSerialPrinterPortConfig config;
|
sl@0
|
230 |
config.iRate = EBps19200;
|
sl@0
|
231 |
config.iHandshake.iXonXoff = ETrue;
|
sl@0
|
232 |
config.iHandshake.iCts = EFalse;
|
sl@0
|
233 |
config.iHandshake.iDsr = ETrue;
|
sl@0
|
234 |
config.iHandshake.iDcd = ETrue;
|
sl@0
|
235 |
CCommPrinterPort::ConstructL(KPdrStoreECUART, aPortName, config, EFifoDisable);
|
sl@0
|
236 |
|
sl@0
|
237 |
TRequestStatus stat;
|
sl@0
|
238 |
iComm.Write(stat, 10, TPtrC8(NULL, 0));
|
sl@0
|
239 |
User::WaitForRequest(stat);
|
sl@0
|
240 |
|
sl@0
|
241 |
TCommConfig buf;
|
sl@0
|
242 |
iComm.Config(buf);
|
sl@0
|
243 |
buf().iHandshake |= (KConfigFailDSR | KConfigFailDCD);
|
sl@0
|
244 |
User::LeaveIfError(iComm.SetConfig(buf));
|
sl@0
|
245 |
}
|
sl@0
|
246 |
|
sl@0
|
247 |
CParallelPrinterPort::CParallelPrinterPort()
|
sl@0
|
248 |
: CCommPrinterPort()
|
sl@0
|
249 |
{
|
sl@0
|
250 |
}
|
sl@0
|
251 |
|
sl@0
|
252 |
EXPORT_C CIrdaPrinterPort* CIrdaPrinterPort::NewL()
|
sl@0
|
253 |
{
|
sl@0
|
254 |
CIrdaPrinterPort* irdaprinterport = new(ELeave) CIrdaPrinterPort;
|
sl@0
|
255 |
CleanupStack::PushL(irdaprinterport);
|
sl@0
|
256 |
irdaprinterport->ConstructL();
|
sl@0
|
257 |
CleanupStack::Pop();
|
sl@0
|
258 |
return irdaprinterport;
|
sl@0
|
259 |
}
|
sl@0
|
260 |
|
sl@0
|
261 |
EXPORT_C CIrdaPrinterPort::~CIrdaPrinterPort()
|
sl@0
|
262 |
{
|
sl@0
|
263 |
}
|
sl@0
|
264 |
|
sl@0
|
265 |
void CIrdaPrinterPort::ConstructL()
|
sl@0
|
266 |
{
|
sl@0
|
267 |
TSerialPrinterPortConfig config;
|
sl@0
|
268 |
_LIT(KPdrStoreIRCOMM,"IRCOMM");
|
sl@0
|
269 |
_LIT(KPdrStoreIRCOMM0,"IrCOMM::0");
|
sl@0
|
270 |
CCommPrinterPort::ConstructL(KPdrStoreIRCOMM, KPdrStoreIRCOMM0, config, EFifoDisable);
|
sl@0
|
271 |
}
|
sl@0
|
272 |
|
sl@0
|
273 |
CIrdaPrinterPort::CIrdaPrinterPort()
|
sl@0
|
274 |
: CCommPrinterPort()
|
sl@0
|
275 |
{
|
sl@0
|
276 |
}
|
sl@0
|
277 |
|
sl@0
|
278 |
EXPORT_C CEpocConnectPort* CEpocConnectPort::NewL()
|
sl@0
|
279 |
{
|
sl@0
|
280 |
CEpocConnectPort* epocconnectport = new(ELeave) CEpocConnectPort;
|
sl@0
|
281 |
CleanupStack::PushL(epocconnectport);
|
sl@0
|
282 |
epocconnectport->ConstructL();
|
sl@0
|
283 |
CleanupStack::Pop();
|
sl@0
|
284 |
return epocconnectport;
|
sl@0
|
285 |
}
|
sl@0
|
286 |
|
sl@0
|
287 |
EXPORT_C CEpocConnectPort::~CEpocConnectPort()
|
sl@0
|
288 |
{
|
sl@0
|
289 |
}
|
sl@0
|
290 |
|
sl@0
|
291 |
void CEpocConnectPort::ConstructL()
|
sl@0
|
292 |
{
|
sl@0
|
293 |
TSerialPrinterPortConfig config;
|
sl@0
|
294 |
_LIT(KPdrStorePLPLPT,"PLPLPT");
|
sl@0
|
295 |
_LIT(KPdrStorePLPLPT0,"PLPLPT::0");
|
sl@0
|
296 |
CCommPrinterPort::ConstructL(KPdrStorePLPLPT, KPdrStorePLPLPT0, config, EFifoDisable);
|
sl@0
|
297 |
}
|
sl@0
|
298 |
|
sl@0
|
299 |
CEpocConnectPort::CEpocConnectPort()
|
sl@0
|
300 |
: CCommPrinterPort()
|
sl@0
|
301 |
{
|
sl@0
|
302 |
}
|
sl@0
|
303 |
|
sl@0
|
304 |
|