diff options
author | Sergey Belyashov <Sergey.Belyashov@gmail.com> | 2013-02-09 17:01:02 +0400 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-02-11 21:06:09 +0100 |
commit | 6e19301a87e9d0098d7e89e41d37f44ed9dad4bf (patch) | |
tree | 2c992ca25fc26fe23716ba4a139b308ec0a6cf66 | |
parent | a5eb09c28b6115296848af929c7df571d447580b (diff) | |
download | qtserialport-6e19301a87e9d0098d7e89e41d37f44ed9dad4bf.tar.gz |
Establish proper error handling for lines() method
Because lines method always uses system call to acquire actual status
which may fail in some reasons, it may change error state of SerialPort
object. So lines should be non-const method. In case of an error and when
no any lines active it returns NoLine value.
Original patch for this change is provided by Israel Lins <israelins85@yahoo.com.br>
Change-Id: I0858200ef29ce7f67175c66898f69d1766f0f760
Reviewed-by: Laszlo Papp <lpapp@kde.org>
Reviewed-by: Denis Shienkov <denis.shienkov@gmail.com>
-rw-r--r-- | src/serialport/qserialport.cpp | 3 | ||||
-rw-r--r-- | src/serialport/qserialport.h | 3 | ||||
-rw-r--r-- | src/serialport/qserialport_symbian.cpp | 2 | ||||
-rw-r--r-- | src/serialport/qserialport_unix.cpp | 6 | ||||
-rw-r--r-- | src/serialport/qserialport_win.cpp | 6 |
5 files changed, 13 insertions, 7 deletions
diff --git a/src/serialport/qserialport.cpp b/src/serialport/qserialport.cpp index ffd10dc..e4b76df 100644 --- a/src/serialport/qserialport.cpp +++ b/src/serialport/qserialport.cpp @@ -319,6 +319,7 @@ int QSerialPortPrivateData::timeoutValue(int msecs, int elapsed) This enum describes the possible RS-232 pinout signals. + \value NoLine no any line is active \value Le DSR (data set ready/line enable). \value Dtr DTR (data terminal ready). \value Rts RTS (request to send). @@ -886,7 +887,7 @@ bool QSerialPort::isRequestToSend() const \sa isDataTerminalReady(), isRequestToSend, setDataTerminalReady(), setRequestToSend() */ -QSerialPort::Lines QSerialPort::lines() const +QSerialPort::Lines QSerialPort::lines() { Q_D(const QSerialPort); return d->lines(); diff --git a/src/serialport/qserialport.h b/src/serialport/qserialport.h index 5f1b06b..4275c95 100644 --- a/src/serialport/qserialport.h +++ b/src/serialport/qserialport.h @@ -122,6 +122,7 @@ public: }; enum Line { + NoLine = 0x00, LeLine = 0x01, DtrLine = 0x02, RtsLine = 0x04, @@ -191,7 +192,7 @@ public: bool isDataTerminalReady() const; bool isRequestToSend() const; - Lines lines() const; + Lines lines(); bool flush(); bool clear(Directions dir = AllDirections); diff --git a/src/serialport/qserialport_symbian.cpp b/src/serialport/qserialport_symbian.cpp index cca7c02..dc7d239 100644 --- a/src/serialport/qserialport_symbian.cpp +++ b/src/serialport/qserialport_symbian.cpp @@ -160,7 +160,7 @@ void QSerialPortPrivate::close() QSerialPort::Lines QSerialPortPrivate::lines() const { - QSerialPort::Lines ret = 0; + QSerialPort::Lines ret = QSerialPort::NoLine; TUint signalMask = 0; descriptor.Signals(signalMask); diff --git a/src/serialport/qserialport_unix.cpp b/src/serialport/qserialport_unix.cpp index 7e14b3d..134b08d 100644 --- a/src/serialport/qserialport_unix.cpp +++ b/src/serialport/qserialport_unix.cpp @@ -255,10 +255,12 @@ void QSerialPortPrivate::close() QSerialPort::Lines QSerialPortPrivate::lines() const { int arg = 0; - QSerialPort::Lines ret = 0; + QSerialPort::Lines ret = QSerialPort::NoLine; - if (::ioctl(descriptor, TIOCMGET, &arg) == -1) + if (::ioctl(descriptor, TIOCMGET, &arg) == -1) { + q_ptr->setError(decodeSystemError()); return ret; + } #ifdef TIOCM_LE if (arg & TIOCM_LE) diff --git a/src/serialport/qserialport_win.cpp b/src/serialport/qserialport_win.cpp index 56da5d8..7f86ff3 100644 --- a/src/serialport/qserialport_win.cpp +++ b/src/serialport/qserialport_win.cpp @@ -308,10 +308,12 @@ void QSerialPortPrivate::close() QSerialPort::Lines QSerialPortPrivate::lines() const { DWORD modemStat = 0; - QSerialPort::Lines ret = 0; + QSerialPort::Lines ret = QSerialPort::NoLine; - if (!::GetCommModemStatus(descriptor, &modemStat)) + if (!::GetCommModemStatus(descriptor, &modemStat)) { + q_ptr->setError(decodeSystemError()); return ret; + } if (modemStat & MS_CTS_ON) ret |= QSerialPort::CtsLine; |