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