summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Shienkov <denis.shienkov@gmail.com>2015-07-08 18:26:08 +0300
committerDenis Shienkov <denis.shienkov@gmail.com>2015-07-10 09:34:47 +0000
commit3a3942f085e5aee712ccb2f80c41615e9a086c74 (patch)
tree4e90fb52a3839f5b4a19660c58608b9ed0b86a23
parent198e75ad7e2c829fb6ca393ad6deb492efb2ef0e (diff)
downloadqtserialport-3a3942f085e5aee712ccb2f80c41615e9a086c74.tar.gz
Give custom descriptions to errors which had none before
(cherry-picked from a2758cf594dd08a21037873f64f72166a353aa29) Change-Id: Ic083cbd58e4e775ede0cdf610f61407003834207 Reviewed-by: Denis Shienkov <denis.shienkov@gmail.com>
-rw-r--r--src/serialport/qserialport.cpp22
-rw-r--r--src/serialport/qserialport_unix.cpp21
-rw-r--r--src/serialport/qserialport_win.cpp14
-rw-r--r--src/serialport/qserialport_wince.cpp22
4 files changed, 37 insertions, 42 deletions
diff --git a/src/serialport/qserialport.cpp b/src/serialport/qserialport.cpp
index c8216c1..8a1b02a 100644
--- a/src/serialport/qserialport.cpp
+++ b/src/serialport/qserialport.cpp
@@ -518,14 +518,14 @@ bool QSerialPort::open(OpenMode mode)
Q_D(QSerialPort);
if (isOpen()) {
- d->setError(QSerialPortErrorInfo(QSerialPort::OpenError));
+ d->setError(QSerialPortErrorInfo(QSerialPort::OpenError, tr("Device is already open")));
return false;
}
// Define while not supported modes.
static const OpenMode unsupportedModes = Append | Truncate | Text | Unbuffered;
if ((mode & unsupportedModes) || mode == NotOpen) {
- d->setError(QSerialPortErrorInfo(QSerialPort::UnsupportedOperationError));
+ d->setError(QSerialPortErrorInfo(QSerialPort::UnsupportedOperationError, tr("Unsupported open mode")));
return false;
}
@@ -558,7 +558,7 @@ void QSerialPort::close()
{
Q_D(QSerialPort);
if (!isOpen()) {
- d->setError(QSerialPortErrorInfo(QSerialPort::NotOpenError));
+ d->setError(QSerialPortErrorInfo(QSerialPort::NotOpenError, tr("Device is not open")));
return;
}
@@ -869,7 +869,7 @@ bool QSerialPort::setDataTerminalReady(bool set)
Q_D(QSerialPort);
if (!isOpen()) {
- d->setError(QSerialPortErrorInfo(QSerialPort::NotOpenError));
+ d->setError(QSerialPortErrorInfo(QSerialPort::NotOpenError, tr("Device is not open")));
qWarning("%s: device not open", Q_FUNC_INFO);
return false;
}
@@ -916,7 +916,7 @@ bool QSerialPort::setRequestToSend(bool set)
Q_D(QSerialPort);
if (!isOpen()) {
- d->setError(QSerialPortErrorInfo(QSerialPort::NotOpenError));
+ d->setError(QSerialPortErrorInfo(QSerialPort::NotOpenError, tr("Device is not open")));
qWarning("%s: device not open", Q_FUNC_INFO);
return false;
}
@@ -966,7 +966,7 @@ QSerialPort::PinoutSignals QSerialPort::pinoutSignals()
Q_D(QSerialPort);
if (!isOpen()) {
- d->setError(QSerialPortErrorInfo(QSerialPort::NotOpenError));
+ d->setError(QSerialPortErrorInfo(QSerialPort::NotOpenError, tr("Device is not open")));
qWarning("%s: device not open", Q_FUNC_INFO);
return QSerialPort::NoSignal;
}
@@ -996,7 +996,7 @@ bool QSerialPort::flush()
Q_D(QSerialPort);
if (!isOpen()) {
- d->setError(QSerialPortErrorInfo(QSerialPort::NotOpenError));
+ d->setError(QSerialPortErrorInfo(QSerialPort::NotOpenError, tr("Device is not open")));
qWarning("%s: device not open", Q_FUNC_INFO);
return false;
}
@@ -1018,7 +1018,7 @@ bool QSerialPort::clear(Directions directions)
Q_D(QSerialPort);
if (!isOpen()) {
- d->setError(QSerialPortErrorInfo(QSerialPort::NotOpenError));
+ d->setError(QSerialPortErrorInfo(QSerialPort::NotOpenError, tr("Device is not open")));
qWarning("%s: device not open", Q_FUNC_INFO);
return false;
}
@@ -1080,7 +1080,7 @@ bool QSerialPort::setDataErrorPolicy(DataErrorPolicy policy)
Q_D(QSerialPort);
if (!isOpen()) {
- d->setError(QSerialPortErrorInfo(QSerialPort::NotOpenError));
+ d->setError(QSerialPortErrorInfo(QSerialPort::NotOpenError, tr("Device is not open")));
qWarning("%s: device not open", Q_FUNC_INFO);
return false;
}
@@ -1305,7 +1305,7 @@ bool QSerialPort::sendBreak(int duration)
Q_D(QSerialPort);
if (!isOpen()) {
- d->setError(QSerialPortErrorInfo(QSerialPort::NotOpenError));
+ d->setError(QSerialPortErrorInfo(QSerialPort::NotOpenError, tr("Device is not open")));
qWarning("%s: device not open", Q_FUNC_INFO);
return false;
}
@@ -1334,7 +1334,7 @@ bool QSerialPort::setBreakEnabled(bool set)
Q_D(QSerialPort);
if (!isOpen()) {
- d->setError(QSerialPortErrorInfo(QSerialPort::NotOpenError));
+ d->setError(QSerialPortErrorInfo(QSerialPort::NotOpenError, tr("Device is not open")));
qWarning("%s: device not open", Q_FUNC_INFO);
return false;
}
diff --git a/src/serialport/qserialport_unix.cpp b/src/serialport/qserialport_unix.cpp
index e6e0604..8a0dd49 100644
--- a/src/serialport/qserialport_unix.cpp
+++ b/src/serialport/qserialport_unix.cpp
@@ -174,14 +174,14 @@ bool QSerialPortPrivate::open(QIODevice::OpenMode mode)
bool isLockFileEmpty = lockFilePath.isEmpty();
if (isLockFileEmpty) {
qWarning("Failed to create a lock file for opening the device");
- setError(QSerialPortErrorInfo(QSerialPort::PermissionError));
+ setError(QSerialPortErrorInfo(QSerialPort::PermissionError, QSerialPort::tr("Permission error while creating lock file")));
return false;
}
QScopedPointer<QLockFile> newLockFileScopedPointer(new QLockFile(lockFilePath));
if (!newLockFileScopedPointer->tryLock()) {
- setError(QSerialPortErrorInfo(QSerialPort::PermissionError));
+ setError(QSerialPortErrorInfo(QSerialPort::PermissionError, QSerialPort::tr("Permission error while locking the device")));
return false;
}
@@ -488,7 +488,7 @@ QSerialPortPrivate::setCustomBaudRate(qint32 baudRate, QSerialPort::Directions d
currentSerialInfo.custom_divisor = currentSerialInfo.baud_base / baudRate;
if (currentSerialInfo.custom_divisor == 0)
- return QSerialPortErrorInfo(QSerialPort::UnsupportedOperationError);
+ return QSerialPortErrorInfo(QSerialPort::UnsupportedOperationError, QSerialPort::tr("No suitable custom baud rate divisor"));
if (currentSerialInfo.custom_divisor * baudRate != currentSerialInfo.baud_base) {
qWarning("Baud rate of serial port %s is set to %d instead of %d: divisor %f unsupported",
@@ -517,7 +517,7 @@ QSerialPortPrivate::setCustomBaudRate(qint32 baudRate, QSerialPort::Directions d
return QSerialPortErrorInfo(QSerialPort::NoError);
#endif
- return QSerialPortErrorInfo(QSerialPort::UnsupportedOperationError);
+ return QSerialPortErrorInfo(QSerialPort::UnsupportedOperationError, QSerialPort::tr("Custom baud rate is not supported"));
}
#elif defined (Q_OS_QNX)
@@ -548,7 +548,7 @@ QSerialPortPrivate::setCustomBaudRate(qint32 baudRate, QSerialPort::Directions d
bool QSerialPortPrivate::setBaudRate(qint32 baudRate, QSerialPort::Directions directions)
{
if (baudRate <= 0) {
- setError(QSerialPortErrorInfo(QSerialPort::UnsupportedOperationError));
+ setError(QSerialPortErrorInfo(QSerialPort::UnsupportedOperationError, QSerialPort::tr("Invalid baud rate value")));
return false;
}
@@ -975,7 +975,7 @@ bool QSerialPortPrivate::waitForReadOrWrite(bool *selectForRead, bool *selectFor
return false;
}
if (ret == 0) {
- setError(QSerialPortErrorInfo(QSerialPort::TimeoutError));
+ setError(QSerialPortErrorInfo(QSerialPort::TimeoutError, QSerialPort::tr("Operation timed out")));
return false;
}
@@ -1108,13 +1108,12 @@ qint64 QSerialPortPrivate::readPerChar(char *data, qint64 maxSize)
case QSerialPort::SkipPolicy:
continue; //ignore received character
case QSerialPort::StopReceivingPolicy: {
- QSerialPortErrorInfo error;
if (parity != QSerialPort::NoParity)
- error.errorCode = QSerialPort::ParityError;
+ setError(QSerialPortErrorInfo(QSerialPort::ParityError, QSerialPort::tr("Parity error detected while reading")));
+ else if (*data == '\0')
+ setError(QSerialPortErrorInfo(QSerialPort::BreakConditionError, QSerialPort::tr("Break condition detected while reading")));
else
- error.errorCode = *data == '\0' ?
- QSerialPort::BreakConditionError : QSerialPort::FramingError;
- setError(error);
+ setError(QSerialPortErrorInfo(QSerialPort::FramingError, QSerialPort::tr("Framing error detected while reading")));
return ++ret; //abort receiving
}
break;
diff --git a/src/serialport/qserialport_win.cpp b/src/serialport/qserialport_win.cpp
index d0bb24c..d3eda5f 100644
--- a/src/serialport/qserialport_win.cpp
+++ b/src/serialport/qserialport_win.cpp
@@ -386,7 +386,7 @@ bool QSerialPortPrivate::setBaudRate()
bool QSerialPortPrivate::setBaudRate(qint32 baudRate, QSerialPort::Directions directions)
{
if (directions != QSerialPort::AllDirections) {
- setError(QSerialPortErrorInfo(QSerialPort::UnsupportedOperationError));
+ setError(QSerialPortErrorInfo(QSerialPort::UnsupportedOperationError, QSerialPort::tr("Custom baud rate direction is unsupported")));
return false;
}
currentDcb.BaudRate = baudRate;
@@ -675,18 +675,16 @@ void QSerialPortPrivate::handleLineStatusErrors()
return;
}
- QSerialPortErrorInfo error;
-
if (errors & CE_FRAME) {
- error.errorCode = QSerialPort::FramingError;
+ setError(QSerialPortErrorInfo(QSerialPort::FramingError, QSerialPort::tr("Framing error detected while reading")));
} else if (errors & CE_RXPARITY) {
- error.errorCode = QSerialPort::ParityError;
+ setError(QSerialPortErrorInfo(QSerialPort::FramingError, QSerialPort::tr("ParityError error detected while reading")));
parityErrorOccurred = true;
} else if (errors & CE_BREAK) {
- error.errorCode = QSerialPort::BreakConditionError;
+ setError(QSerialPortErrorInfo(QSerialPort::BreakConditionError, QSerialPort::tr("Break condition detected while reading")));
+ } else {
+ setError(QSerialPortErrorInfo(QSerialPort::UnknownError, QSerialPort::tr("Unknown streaming error")));
}
-
- setError(error);
}
inline bool QSerialPortPrivate::initialize()
diff --git a/src/serialport/qserialport_wince.cpp b/src/serialport/qserialport_wince.cpp
index c76eaac..779b16c 100644
--- a/src/serialport/qserialport_wince.cpp
+++ b/src/serialport/qserialport_wince.cpp
@@ -401,7 +401,7 @@ bool QSerialPortPrivate::setBaudRate()
bool QSerialPortPrivate::setBaudRate(qint32 baudRate, QSerialPort::Directions directions)
{
if (directions != QSerialPort::AllDirections) {
- setError(QSerialPortErrorInfo(QSerialPort::UnsupportedOperationError));
+ setError(QSerialPortErrorInfo(QSerialPort::UnsupportedOperationError, QSerialPort::tr("Custom baud rate direction is unsupported")));
return false;
}
currentDcb.BaudRate = baudRate;
@@ -512,7 +512,7 @@ bool QSerialPortPrivate::notifyRead()
if (!sucessResult) {
readBuffer.truncate(bytesToRead);
- setError(QSerialPortErrorInfo(QSerialPort::ReadError));
+ setError(QSerialPortErrorInfo(QSerialPort::ReadError, QSerialPort::tr("Error reading from device")));
return false;
}
@@ -555,7 +555,7 @@ bool QSerialPortPrivate::notifyWrite()
DWORD bytesWritten = 0;
if (!::WriteFile(handle, ptr, nextSize, &bytesWritten, Q_NULLPTR)) {
- setError(QSerialPortErrorInfo(QSerialPort::WriteError));
+ setError(QSerialPortErrorInfo(QSerialPort::WriteError, QSerialPort::tr("Error writing to device")));
return false;
}
@@ -578,7 +578,7 @@ qint64 QSerialPortPrivate::writeData(const char *data, qint64 maxSize)
void QSerialPortPrivate::processIoErrors(bool hasError)
{
if (hasError) {
- setError(QSerialPortErrorInfo(QSerialPort::ResourceError));
+ setError(QSerialPortErrorInfo(QSerialPort::ResourceError, QSerialPort::tr("Device disappeared from the system")));
return;
}
@@ -588,18 +588,16 @@ void QSerialPortPrivate::processIoErrors(bool hasError)
return;
}
- QSerialPortErrorInfo error;
-
if (errors & CE_FRAME) {
- error.errorCode = QSerialPort::FramingError;
+ setError(QSerialPortErrorInfo(QSerialPort::FramingError, QSerialPort::tr("Framing error detected while reading")));
} else if (errors & CE_RXPARITY) {
- error.errorCode = QSerialPort::ParityError;
+ setError(QSerialPortErrorInfo(QSerialPort::FramingError, QSerialPort::tr("ParityError error detected while reading")));
parityErrorOccurred = true;
} else if (errors & CE_BREAK) {
- error.errorCode = QSerialPort::BreakConditionError;
+ setError(QSerialPortErrorInfo(QSerialPort::BreakConditionError, QSerialPort::tr("Break condition detected while reading")));
+ } else {
+ setError(QSerialPortErrorInfo(QSerialPort::UnknownError, QSerialPort::tr("Unknown streaming error")));
}
-
- setError(error);
}
inline bool QSerialPortPrivate::initialize(DWORD eventMask)
@@ -731,7 +729,7 @@ bool QSerialPortPrivate::waitForReadOrWrite(bool *selectForRead, bool *selectFor
breaker.stop();
if (breaker.isWorked()) {
- setError(QSerialPortErrorInfo(QSerialPort::TimeoutError));
+ setError(QSerialPortErrorInfo(QSerialPort::TimeoutError, QSerialPort::tr("Operation timed out")));
} else {
if (checkRead) {
Q_ASSERT(selectForRead);