sl@0: // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: #include sl@0: #include "printerport.h" sl@0: sl@0: _LIT(KPdrStoreECUART,"ECUART"); sl@0: sl@0: EXPORT_C CFilePrinterPort* CFilePrinterPort::NewL(const TDesC& aFileName) sl@0: { sl@0: CFilePrinterPort* fileprinterport = new(ELeave) CFilePrinterPort(aFileName); sl@0: CleanupStack::PushL(fileprinterport); sl@0: fileprinterport->ConstructL(); sl@0: CleanupStack::Pop(); sl@0: return fileprinterport; sl@0: } sl@0: sl@0: EXPORT_C CFilePrinterPort::~CFilePrinterPort() sl@0: { sl@0: iFile.Close(); sl@0: if (iCancelled) sl@0: iFs.Delete(iFileName); // ignore error sl@0: iFs.Close(); sl@0: } sl@0: /** Implementation of the pure virtual function inherited from CPrinterPort. sl@0: sl@0: Writes data asynchronously to the concrete file printer port. sl@0: sl@0: @param aBuf A descriptor containing the data to be written to the file printer port. sl@0: @param aRequestStatus A reference to the request status object. sl@0: On completion contains KErrNone if the data is successfully written to sl@0: this file printer port, otherwise if the request is cancelled, this should sl@0: be set to KErrCancel. sl@0: */ sl@0: void CFilePrinterPort::WriteRequest(const TDesC8& aBuf, TRequestStatus& aRequestStatus) sl@0: { sl@0: // iFile.Write(aBuf,aRequestStatus); //!! real code with fixed F32 sl@0: // sl@0: TRequestStatus* pStatus=&aRequestStatus; // F32 bug workaround code sl@0: User::RequestComplete(pStatus, iFile.Write(aBuf)); // F32 bug workaround code sl@0: } sl@0: sl@0: void CFilePrinterPort::Cancel() sl@0: { sl@0: iCancelled = ETrue; sl@0: } sl@0: sl@0: void CFilePrinterPort::ConstructL() sl@0: { sl@0: User::LeaveIfError(iFs.Connect()); sl@0: User::LeaveIfError(iFile.Replace(iFs, iFileName,EFileStream|EFileWrite)); sl@0: } sl@0: sl@0: CFilePrinterPort::CFilePrinterPort(const TDesC& aFileName) sl@0: : iFileName(aFileName) sl@0: { sl@0: } sl@0: sl@0: EXPORT_C TOutputHandshake::TOutputHandshake() sl@0: : iXonXoff(EFalse), sl@0: iCts(ETrue), sl@0: iDsr(ETrue), sl@0: iDcd(EFalse) sl@0: { sl@0: } sl@0: sl@0: EXPORT_C void TOutputHandshake::InternalizeL(RReadStream& aStream) sl@0: { sl@0: iXonXoff = aStream.ReadInt8L(); sl@0: iCts = aStream.ReadInt8L(); sl@0: iDsr = aStream.ReadInt8L(); sl@0: iDcd = aStream.ReadInt8L(); sl@0: } sl@0: sl@0: EXPORT_C void TOutputHandshake::ExternalizeL(RWriteStream& aStream) const sl@0: { sl@0: aStream.WriteInt8L(iXonXoff); sl@0: aStream.WriteInt8L(iCts); sl@0: aStream.WriteInt8L(iDsr); sl@0: aStream.WriteInt8L(iDcd); sl@0: } sl@0: sl@0: EXPORT_C TSerialPrinterPortConfig::TSerialPrinterPortConfig() sl@0: : iRate(EBps9600), sl@0: iDataBits(EData8), sl@0: iStopBits(EStop1), sl@0: iParity(EParityNone), sl@0: iIgnoreParity(EFalse), sl@0: iHandshake() sl@0: { sl@0: } sl@0: sl@0: EXPORT_C void TSerialPrinterPortConfig::InternalizeL(RReadStream& aStream) sl@0: { sl@0: iRate = (TBps) aStream.ReadInt8L(); sl@0: iDataBits = (TDataBits) aStream.ReadInt8L(); sl@0: iStopBits = (TStopBits) aStream.ReadInt8L(); sl@0: iParity = (TParity) aStream.ReadInt8L(); sl@0: iIgnoreParity = aStream.ReadInt8L(); sl@0: iHandshake.InternalizeL(aStream); sl@0: } sl@0: sl@0: EXPORT_C void TSerialPrinterPortConfig::ExternalizeL(RWriteStream& aStream) const sl@0: { sl@0: aStream.WriteInt8L(iRate); sl@0: aStream.WriteInt8L(iDataBits); sl@0: aStream.WriteInt8L(iStopBits); sl@0: aStream.WriteInt8L(iParity); sl@0: aStream.WriteInt8L(iIgnoreParity); sl@0: iHandshake.ExternalizeL(aStream); sl@0: } sl@0: sl@0: EXPORT_C CCommPrinterPort* CCommPrinterPort::NewL(const TDesC& aCsyName, const TDesC& aPortName, const TSerialPrinterPortConfig& aConfig, const TFifo aFifo) sl@0: { sl@0: CCommPrinterPort* commprinterport = new(ELeave) CCommPrinterPort; sl@0: CleanupStack::PushL(commprinterport); sl@0: commprinterport->ConstructL(aCsyName, aPortName, aConfig, aFifo); sl@0: CleanupStack::Pop(); sl@0: return commprinterport; sl@0: } sl@0: sl@0: EXPORT_C CCommPrinterPort::~CCommPrinterPort() sl@0: { sl@0: iComm.Close(); sl@0: iCommServ.Close(); sl@0: } sl@0: sl@0: EXPORT_C void CCommPrinterPort::WriteRequest(const TDesC8& aBuf, TRequestStatus& aRequestStatus) sl@0: { sl@0: iComm.Write(aRequestStatus, 20000000, aBuf); // Times out after 20 seconds sl@0: } sl@0: sl@0: EXPORT_C void CCommPrinterPort::Cancel() sl@0: { sl@0: iComm.WriteCancel(); sl@0: } sl@0: sl@0: EXPORT_C void CCommPrinterPort::ConstructL(const TDesC& aCsyName, const TDesC& aPortName, const TSerialPrinterPortConfig& aConfig, const TFifo aFifo) sl@0: { sl@0: User::LeaveIfError(iCommServ.Connect()); sl@0: User::LeaveIfError(iCommServ.LoadCommModule(aCsyName)); sl@0: User::LeaveIfError(iComm.Open(iCommServ, aPortName, ECommExclusive)); sl@0: sl@0: TCommConfig config; sl@0: iComm.Config(config); sl@0: config().iRate = aConfig.iRate; sl@0: config().iDataBits = aConfig.iDataBits; sl@0: config().iStopBits = aConfig.iStopBits; sl@0: config().iParityErrorChar = STATIC_CAST(TText8, aConfig.iParity); sl@0: if (aConfig.iIgnoreParity) sl@0: config().iParityErrorChar = KConfigParityErrorIgnore; sl@0: TUint handshake = 0; sl@0: if (aConfig.iHandshake.iXonXoff) sl@0: handshake = handshake | KConfigObeyXoff; sl@0: if (aConfig.iHandshake.iCts) sl@0: handshake = handshake | KConfigObeyCTS; sl@0: if (aConfig.iHandshake.iDsr) sl@0: handshake = handshake | KConfigObeyDSR; sl@0: if (aConfig.iHandshake.iDcd) sl@0: handshake = handshake | KConfigObeyDCD; sl@0: config().iHandshake = handshake; sl@0: config().iFifo = aFifo; sl@0: User::LeaveIfError(iComm.SetConfig(config)); sl@0: } sl@0: sl@0: EXPORT_C CCommPrinterPort::CCommPrinterPort() sl@0: : CPrinterPort(), sl@0: iCommServ(), sl@0: iComm() sl@0: { sl@0: } sl@0: sl@0: EXPORT_C CSerialPrinterPort* CSerialPrinterPort::NewL(const TDesC& aPortName, const TSerialPrinterPortConfig& aConfig) sl@0: { sl@0: CSerialPrinterPort* serialprinterport=new(ELeave) CSerialPrinterPort(aConfig); sl@0: CleanupStack::PushL(serialprinterport); sl@0: serialprinterport->ConstructL(aPortName); sl@0: CleanupStack::Pop(); sl@0: return serialprinterport; sl@0: } sl@0: sl@0: EXPORT_C CSerialPrinterPort::~CSerialPrinterPort() sl@0: { sl@0: } sl@0: sl@0: EXPORT_C TSerialPrinterPortConfig CSerialPrinterPort::Config() sl@0: { sl@0: return iConfig; sl@0: } sl@0: sl@0: void CSerialPrinterPort::ConstructL(const TDesC& aPortName) sl@0: { sl@0: CCommPrinterPort::ConstructL(KPdrStoreECUART, aPortName, iConfig); sl@0: } sl@0: sl@0: CSerialPrinterPort::CSerialPrinterPort(const TSerialPrinterPortConfig& aConfig) sl@0: : CCommPrinterPort(), sl@0: iConfig(aConfig) sl@0: { sl@0: } sl@0: sl@0: EXPORT_C CParallelPrinterPort* CParallelPrinterPort::NewL(const TDesC& aPortName) sl@0: { sl@0: CParallelPrinterPort* parallelprinterport = new(ELeave) CParallelPrinterPort; sl@0: CleanupStack::PushL(parallelprinterport); sl@0: parallelprinterport->ConstructL(aPortName); sl@0: CleanupStack::Pop(); sl@0: return parallelprinterport; sl@0: } sl@0: sl@0: EXPORT_C CParallelPrinterPort::~CParallelPrinterPort() sl@0: { sl@0: } sl@0: sl@0: void CParallelPrinterPort::ConstructL(const TDesC& aPortName) sl@0: { sl@0: TSerialPrinterPortConfig config; sl@0: config.iRate = EBps19200; sl@0: config.iHandshake.iXonXoff = ETrue; sl@0: config.iHandshake.iCts = EFalse; sl@0: config.iHandshake.iDsr = ETrue; sl@0: config.iHandshake.iDcd = ETrue; sl@0: CCommPrinterPort::ConstructL(KPdrStoreECUART, aPortName, config, EFifoDisable); sl@0: sl@0: TRequestStatus stat; sl@0: iComm.Write(stat, 10, TPtrC8(NULL, 0)); sl@0: User::WaitForRequest(stat); sl@0: sl@0: TCommConfig buf; sl@0: iComm.Config(buf); sl@0: buf().iHandshake |= (KConfigFailDSR | KConfigFailDCD); sl@0: User::LeaveIfError(iComm.SetConfig(buf)); sl@0: } sl@0: sl@0: CParallelPrinterPort::CParallelPrinterPort() sl@0: : CCommPrinterPort() sl@0: { sl@0: } sl@0: sl@0: EXPORT_C CIrdaPrinterPort* CIrdaPrinterPort::NewL() sl@0: { sl@0: CIrdaPrinterPort* irdaprinterport = new(ELeave) CIrdaPrinterPort; sl@0: CleanupStack::PushL(irdaprinterport); sl@0: irdaprinterport->ConstructL(); sl@0: CleanupStack::Pop(); sl@0: return irdaprinterport; sl@0: } sl@0: sl@0: EXPORT_C CIrdaPrinterPort::~CIrdaPrinterPort() sl@0: { sl@0: } sl@0: sl@0: void CIrdaPrinterPort::ConstructL() sl@0: { sl@0: TSerialPrinterPortConfig config; sl@0: _LIT(KPdrStoreIRCOMM,"IRCOMM"); sl@0: _LIT(KPdrStoreIRCOMM0,"IrCOMM::0"); sl@0: CCommPrinterPort::ConstructL(KPdrStoreIRCOMM, KPdrStoreIRCOMM0, config, EFifoDisable); sl@0: } sl@0: sl@0: CIrdaPrinterPort::CIrdaPrinterPort() sl@0: : CCommPrinterPort() sl@0: { sl@0: } sl@0: sl@0: EXPORT_C CEpocConnectPort* CEpocConnectPort::NewL() sl@0: { sl@0: CEpocConnectPort* epocconnectport = new(ELeave) CEpocConnectPort; sl@0: CleanupStack::PushL(epocconnectport); sl@0: epocconnectport->ConstructL(); sl@0: CleanupStack::Pop(); sl@0: return epocconnectport; sl@0: } sl@0: sl@0: EXPORT_C CEpocConnectPort::~CEpocConnectPort() sl@0: { sl@0: } sl@0: sl@0: void CEpocConnectPort::ConstructL() sl@0: { sl@0: TSerialPrinterPortConfig config; sl@0: _LIT(KPdrStorePLPLPT,"PLPLPT"); sl@0: _LIT(KPdrStorePLPLPT0,"PLPLPT::0"); sl@0: CCommPrinterPort::ConstructL(KPdrStorePLPLPT, KPdrStorePLPLPT0, config, EFifoDisable); sl@0: } sl@0: sl@0: CEpocConnectPort::CEpocConnectPort() sl@0: : CCommPrinterPort() sl@0: { sl@0: } sl@0: sl@0: