From 8919ea86c80001be7e826f5363f1b7548c7a8091 Mon Sep 17 00:00:00 2001 From: Denis Shienkov Date: Fri, 26 Jun 2015 16:40:44 +0300 Subject: Improve the processing of errors Sometimes the error string would contain a wrong description which did not correspond to the system error code. The reason was qt_error_string() being called too late, when the system error might have already been overwritten. The error processing is now in QSPP::getSystemError(), which returns both the error code and the error description as soon as possible. * Now the QSPP::getSystemError() returns the new class QSerialPortErrorInfo which contains all necessary fields. * The new method QSPP::setError() which accepts the QSerialPortErrorInfo as input parameter is used. * The old private method QSP::setError() is removed, because it is not used anywhere. Change-Id: Ia7e4d617b863e2131175c52812cdf426ed963795 Reviewed-by: Sergey Belyashov Reviewed-by: Oswald Buddenhagen Reviewed-by: Denis Shienkov --- src/serialport/qserialport_p.h | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'src/serialport/qserialport_p.h') diff --git a/src/serialport/qserialport_p.h b/src/serialport/qserialport_p.h index a39bc22..571b0de 100644 --- a/src/serialport/qserialport_p.h +++ b/src/serialport/qserialport_p.h @@ -106,6 +106,19 @@ class QSocketNotifier; QString serialPortLockFilePath(const QString &portName); #endif +class QSerialPortErrorInfo +{ +public: + explicit QSerialPortErrorInfo(QSerialPort::SerialPortError errorCode = QSerialPort::UnknownError, + const QString &errorString = QString()) + : errorCode(errorCode) + , errorString(errorString) + { + } + QSerialPort::SerialPortError errorCode; + QString errorString; +}; + class QSerialPortPrivate : public QIODevicePrivate { Q_DECLARE_PUBLIC(QSerialPort) @@ -144,7 +157,9 @@ public: bool setFlowControl(QSerialPort::FlowControl flowControl); bool setDataErrorPolicy(QSerialPort::DataErrorPolicy policy); - QSerialPort::SerialPortError decodeSystemError(int systemErrorCode = -1) const; + QSerialPortErrorInfo getSystemError(int systemErrorCode = -1) const; + + void setError(const QSerialPortErrorInfo &errorInfo); qint64 writeData(const char *data, qint64 maxSize); @@ -237,11 +252,11 @@ public: bool initialize(QIODevice::OpenMode mode); bool updateTermios(); - QSerialPort::SerialPortError setBaudRate_helper(qint32 baudRate, + QSerialPortErrorInfo setBaudRate_helper(qint32 baudRate, QSerialPort::Directions directions); - QSerialPort::SerialPortError setCustomBaudRate(qint32 baudRate, + QSerialPortErrorInfo setCustomBaudRate(qint32 baudRate, QSerialPort::Directions directions); - QSerialPort::SerialPortError setStandardBaudRate(qint32 baudRate, + QSerialPortErrorInfo setStandardBaudRate(qint32 baudRate, QSerialPort::Directions directions); bool isReadNotificationEnabled() const; -- cgit v1.2.1