os/graphics/printingservices/printerdriversupport/src/PDRPORT.CPP
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/graphics/printingservices/printerdriversupport/src/PDRPORT.CPP	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,304 @@
     1.4 +// Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +//
    1.18 +
    1.19 +#include <pdrport.h>
    1.20 +#include "printerport.h"
    1.21 +
    1.22 +_LIT(KPdrStoreECUART,"ECUART");
    1.23 +
    1.24 +EXPORT_C CFilePrinterPort* CFilePrinterPort::NewL(const TDesC& aFileName)
    1.25 +	{
    1.26 +	CFilePrinterPort* fileprinterport = new(ELeave) CFilePrinterPort(aFileName);
    1.27 +	CleanupStack::PushL(fileprinterport);
    1.28 +	fileprinterport->ConstructL();
    1.29 +	CleanupStack::Pop();
    1.30 +	return fileprinterport;
    1.31 +	}
    1.32 +
    1.33 +EXPORT_C CFilePrinterPort::~CFilePrinterPort()
    1.34 +	{
    1.35 +	iFile.Close();
    1.36 +	if (iCancelled)
    1.37 +		iFs.Delete(iFileName);  // ignore error
    1.38 +	iFs.Close();
    1.39 +	}
    1.40 +/** Implementation of the pure virtual function inherited from CPrinterPort.
    1.41 +
    1.42 +Writes data asynchronously to the concrete file printer port.
    1.43 +     
    1.44 +@param aBuf 	      A descriptor containing the data to be written to the file printer port. 
    1.45 +@param aRequestStatus A reference to the request status object. 
    1.46 +	   				  On completion contains KErrNone if the data is successfully written to 
    1.47 +	   				  this file printer port, otherwise if the request is cancelled, this should 
    1.48 +	   				  be set to KErrCancel.
    1.49 +*/
    1.50 +void CFilePrinterPort::WriteRequest(const TDesC8& aBuf, TRequestStatus& aRequestStatus)
    1.51 +	{
    1.52 +//	iFile.Write(aBuf,aRequestStatus); //!! real code with fixed F32
    1.53 +//
    1.54 +	TRequestStatus* pStatus=&aRequestStatus;			// F32 bug workaround code
    1.55 +	User::RequestComplete(pStatus, iFile.Write(aBuf));	// F32 bug workaround code 
    1.56 +	}
    1.57 +
    1.58 +void CFilePrinterPort::Cancel()
    1.59 +	{
    1.60 +	iCancelled = ETrue;
    1.61 +	}
    1.62 +
    1.63 +void CFilePrinterPort::ConstructL()
    1.64 +	{
    1.65 +	User::LeaveIfError(iFs.Connect());
    1.66 +	User::LeaveIfError(iFile.Replace(iFs, iFileName,EFileStream|EFileWrite));
    1.67 +	}
    1.68 +
    1.69 +CFilePrinterPort::CFilePrinterPort(const TDesC& aFileName)
    1.70 +:	iFileName(aFileName)
    1.71 +	{
    1.72 +	}
    1.73 +
    1.74 +EXPORT_C TOutputHandshake::TOutputHandshake()
    1.75 +:	iXonXoff(EFalse),
    1.76 +	iCts(ETrue),
    1.77 +	iDsr(ETrue),
    1.78 +	iDcd(EFalse)
    1.79 +	{
    1.80 +	}
    1.81 +
    1.82 +EXPORT_C void TOutputHandshake::InternalizeL(RReadStream& aStream)
    1.83 +	{
    1.84 +	iXonXoff = aStream.ReadInt8L();
    1.85 +	iCts = aStream.ReadInt8L();
    1.86 +	iDsr = aStream.ReadInt8L();
    1.87 +	iDcd = aStream.ReadInt8L();
    1.88 +	}
    1.89 +
    1.90 +EXPORT_C void TOutputHandshake::ExternalizeL(RWriteStream& aStream) const
    1.91 +	{
    1.92 +	aStream.WriteInt8L(iXonXoff);
    1.93 +	aStream.WriteInt8L(iCts);
    1.94 +	aStream.WriteInt8L(iDsr);
    1.95 +	aStream.WriteInt8L(iDcd);
    1.96 +	}
    1.97 +
    1.98 +EXPORT_C TSerialPrinterPortConfig::TSerialPrinterPortConfig()
    1.99 +:	iRate(EBps9600),
   1.100 +	iDataBits(EData8),
   1.101 +	iStopBits(EStop1),
   1.102 +	iParity(EParityNone),
   1.103 +	iIgnoreParity(EFalse),
   1.104 +	iHandshake()
   1.105 +	{
   1.106 +	}
   1.107 +
   1.108 +EXPORT_C void TSerialPrinterPortConfig::InternalizeL(RReadStream& aStream)
   1.109 +	{
   1.110 +	iRate = (TBps) aStream.ReadInt8L();
   1.111 +	iDataBits = (TDataBits) aStream.ReadInt8L();
   1.112 +	iStopBits = (TStopBits) aStream.ReadInt8L();
   1.113 +	iParity = (TParity) aStream.ReadInt8L();
   1.114 +	iIgnoreParity = aStream.ReadInt8L();
   1.115 +	iHandshake.InternalizeL(aStream);
   1.116 +	}
   1.117 +
   1.118 +EXPORT_C void TSerialPrinterPortConfig::ExternalizeL(RWriteStream& aStream) const
   1.119 +	{
   1.120 +	aStream.WriteInt8L(iRate);
   1.121 +	aStream.WriteInt8L(iDataBits);
   1.122 +	aStream.WriteInt8L(iStopBits);
   1.123 +	aStream.WriteInt8L(iParity);
   1.124 +	aStream.WriteInt8L(iIgnoreParity);
   1.125 +	iHandshake.ExternalizeL(aStream);
   1.126 +	}
   1.127 +
   1.128 +EXPORT_C CCommPrinterPort* CCommPrinterPort::NewL(const TDesC& aCsyName, const TDesC& aPortName, const TSerialPrinterPortConfig& aConfig, const TFifo aFifo)
   1.129 +	{
   1.130 +	CCommPrinterPort* commprinterport = new(ELeave) CCommPrinterPort;
   1.131 +	CleanupStack::PushL(commprinterport);
   1.132 +	commprinterport->ConstructL(aCsyName, aPortName, aConfig, aFifo);
   1.133 +	CleanupStack::Pop();
   1.134 +	return commprinterport;
   1.135 +	}
   1.136 +
   1.137 +EXPORT_C CCommPrinterPort::~CCommPrinterPort()
   1.138 +	{
   1.139 +	iComm.Close();
   1.140 +	iCommServ.Close();
   1.141 +	}
   1.142 +
   1.143 +EXPORT_C void CCommPrinterPort::WriteRequest(const TDesC8& aBuf, TRequestStatus& aRequestStatus)
   1.144 +	{
   1.145 +	iComm.Write(aRequestStatus, 20000000, aBuf);  // Times out after 20 seconds
   1.146 +	}
   1.147 +
   1.148 +EXPORT_C void CCommPrinterPort::Cancel()
   1.149 +	{
   1.150 +	iComm.WriteCancel();
   1.151 +	}
   1.152 +
   1.153 +EXPORT_C void CCommPrinterPort::ConstructL(const TDesC& aCsyName, const TDesC& aPortName, const TSerialPrinterPortConfig& aConfig, const TFifo aFifo)
   1.154 +	{
   1.155 +	User::LeaveIfError(iCommServ.Connect());
   1.156 +	User::LeaveIfError(iCommServ.LoadCommModule(aCsyName)); 
   1.157 +	User::LeaveIfError(iComm.Open(iCommServ, aPortName, ECommExclusive));
   1.158 +
   1.159 +	TCommConfig config;
   1.160 +	iComm.Config(config);
   1.161 +	config().iRate = aConfig.iRate;
   1.162 +	config().iDataBits = aConfig.iDataBits;
   1.163 +	config().iStopBits = aConfig.iStopBits;
   1.164 +	config().iParityErrorChar = STATIC_CAST(TText8, aConfig.iParity);
   1.165 +	if (aConfig.iIgnoreParity)
   1.166 +		config().iParityErrorChar = KConfigParityErrorIgnore;
   1.167 +	TUint handshake = 0;
   1.168 +	if (aConfig.iHandshake.iXonXoff)
   1.169 +		handshake = handshake | KConfigObeyXoff;
   1.170 +	if (aConfig.iHandshake.iCts)
   1.171 +		handshake = handshake | KConfigObeyCTS;
   1.172 +	if (aConfig.iHandshake.iDsr)
   1.173 +		handshake = handshake | KConfigObeyDSR;
   1.174 +	if (aConfig.iHandshake.iDcd)
   1.175 +		handshake = handshake | KConfigObeyDCD;
   1.176 +	config().iHandshake = handshake;
   1.177 +	config().iFifo = aFifo;
   1.178 +	User::LeaveIfError(iComm.SetConfig(config));
   1.179 +	}
   1.180 +
   1.181 +EXPORT_C CCommPrinterPort::CCommPrinterPort()
   1.182 +:	CPrinterPort(),
   1.183 +	iCommServ(),
   1.184 +	iComm()
   1.185 +	{
   1.186 +	}
   1.187 +
   1.188 +EXPORT_C CSerialPrinterPort* CSerialPrinterPort::NewL(const TDesC& aPortName, const TSerialPrinterPortConfig& aConfig)
   1.189 +	{
   1.190 +	CSerialPrinterPort* serialprinterport=new(ELeave) CSerialPrinterPort(aConfig);
   1.191 +	CleanupStack::PushL(serialprinterport);
   1.192 +	serialprinterport->ConstructL(aPortName);
   1.193 +	CleanupStack::Pop();
   1.194 +	return serialprinterport;
   1.195 +	}
   1.196 +
   1.197 +EXPORT_C CSerialPrinterPort::~CSerialPrinterPort()
   1.198 +	{
   1.199 +	}
   1.200 +
   1.201 +EXPORT_C TSerialPrinterPortConfig CSerialPrinterPort::Config()
   1.202 +	{
   1.203 +	return iConfig;
   1.204 +	}
   1.205 +
   1.206 +void CSerialPrinterPort::ConstructL(const TDesC& aPortName)
   1.207 +	{
   1.208 +	CCommPrinterPort::ConstructL(KPdrStoreECUART, aPortName, iConfig);
   1.209 +	}
   1.210 +
   1.211 +CSerialPrinterPort::CSerialPrinterPort(const TSerialPrinterPortConfig& aConfig)
   1.212 +:	CCommPrinterPort(),
   1.213 +	iConfig(aConfig)
   1.214 +	{
   1.215 +	}
   1.216 +
   1.217 +EXPORT_C CParallelPrinterPort* CParallelPrinterPort::NewL(const TDesC& aPortName)
   1.218 +	{
   1.219 +	CParallelPrinterPort* parallelprinterport = new(ELeave) CParallelPrinterPort;
   1.220 +	CleanupStack::PushL(parallelprinterport);
   1.221 +	parallelprinterport->ConstructL(aPortName);
   1.222 +	CleanupStack::Pop();
   1.223 +	return parallelprinterport;
   1.224 +	}
   1.225 +
   1.226 +EXPORT_C CParallelPrinterPort::~CParallelPrinterPort()
   1.227 +	{
   1.228 +	}
   1.229 +
   1.230 +void CParallelPrinterPort::ConstructL(const TDesC& aPortName)
   1.231 +	{
   1.232 +	TSerialPrinterPortConfig config;
   1.233 +	config.iRate = EBps19200;
   1.234 +	config.iHandshake.iXonXoff = ETrue;
   1.235 +	config.iHandshake.iCts = EFalse;
   1.236 +	config.iHandshake.iDsr = ETrue;
   1.237 +	config.iHandshake.iDcd = ETrue;
   1.238 +	CCommPrinterPort::ConstructL(KPdrStoreECUART, aPortName, config, EFifoDisable);
   1.239 +
   1.240 +	TRequestStatus stat;
   1.241 +	iComm.Write(stat, 10, TPtrC8(NULL, 0));
   1.242 +	User::WaitForRequest(stat);
   1.243 +
   1.244 +	TCommConfig buf;
   1.245 +	iComm.Config(buf);
   1.246 +	buf().iHandshake |= (KConfigFailDSR | KConfigFailDCD);
   1.247 +	User::LeaveIfError(iComm.SetConfig(buf));
   1.248 +	}
   1.249 +
   1.250 +CParallelPrinterPort::CParallelPrinterPort()
   1.251 +:	CCommPrinterPort()
   1.252 +	{
   1.253 +	}
   1.254 +
   1.255 +EXPORT_C CIrdaPrinterPort* CIrdaPrinterPort::NewL()
   1.256 +	{
   1.257 +	CIrdaPrinterPort* irdaprinterport = new(ELeave) CIrdaPrinterPort;
   1.258 +	CleanupStack::PushL(irdaprinterport);
   1.259 +	irdaprinterport->ConstructL();
   1.260 +	CleanupStack::Pop();
   1.261 +	return irdaprinterport;
   1.262 +	}
   1.263 +
   1.264 +EXPORT_C CIrdaPrinterPort::~CIrdaPrinterPort()
   1.265 +	{
   1.266 +	}
   1.267 +
   1.268 +void CIrdaPrinterPort::ConstructL()
   1.269 +	{
   1.270 +	TSerialPrinterPortConfig config;
   1.271 +	_LIT(KPdrStoreIRCOMM,"IRCOMM");
   1.272 +	_LIT(KPdrStoreIRCOMM0,"IrCOMM::0");
   1.273 +	CCommPrinterPort::ConstructL(KPdrStoreIRCOMM, KPdrStoreIRCOMM0, config, EFifoDisable);
   1.274 +	}
   1.275 +
   1.276 +CIrdaPrinterPort::CIrdaPrinterPort()
   1.277 +:	CCommPrinterPort()
   1.278 +	{
   1.279 +	}
   1.280 +
   1.281 +EXPORT_C CEpocConnectPort* CEpocConnectPort::NewL()
   1.282 +	{
   1.283 +	CEpocConnectPort* epocconnectport = new(ELeave) CEpocConnectPort;
   1.284 +	CleanupStack::PushL(epocconnectport);
   1.285 +	epocconnectport->ConstructL();
   1.286 +	CleanupStack::Pop();
   1.287 +	return epocconnectport;
   1.288 +	}
   1.289 +
   1.290 +EXPORT_C CEpocConnectPort::~CEpocConnectPort()
   1.291 +	{
   1.292 +	}
   1.293 +
   1.294 +void CEpocConnectPort::ConstructL()
   1.295 +	{
   1.296 +	TSerialPrinterPortConfig config;
   1.297 +	_LIT(KPdrStorePLPLPT,"PLPLPT");
   1.298 +	_LIT(KPdrStorePLPLPT0,"PLPLPT::0");
   1.299 +	CCommPrinterPort::ConstructL(KPdrStorePLPLPT, KPdrStorePLPLPT0, config, EFifoDisable);
   1.300 +	}
   1.301 +
   1.302 +CEpocConnectPort::CEpocConnectPort()
   1.303 +:	CCommPrinterPort()
   1.304 +	{
   1.305 +	}
   1.306 +
   1.307 +