summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLaszlo Papp <lpapp@kde.org>2013-10-04 00:07:53 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-10-04 09:36:48 +0200
commit0eed986ec745828d38141d0568a9fc40f603b163 (patch)
tree06043d9ae4632c6688a19eb414fb2717fb200ee5 /src
parent3309138e2574fa277eb3eb65ad26ab0836925f17 (diff)
Add a new error value called "NotOpenError"
This error message is used when the serial port parameter setters are called even though the serial port is not open, and it should be. The details are very similar to the previously introduced TimeoutError, as in: 1) The "\since 5.2" notion has to be added manually as qdoc has no support for enumeration values in that regard. 2) The value itself has to be added at the end of the enumeration not to break the binary compatibility unnecessarily. It is fine as long as the error documentation for the end users can be kept in the order we wish to do. Each method documentation already contains the information that the error is set properly when that occurs, so this change can be considered as a bug fix rather than a new feature. It is a behavior change of course just as any bug fix. The previous operation was wrong to go ahead down to the syscalls even though the serial port was not open. Thereby, that was a bit pointless. Unfortunately, there is no similar error introduced for the existing QIODevice subclasses just yet, but this term is at least inline with the open mode of QIODevice which is "NotOpen". For sure, when the parameter setters are called by the end user without the device being open results false return value as per method documentation. This change was tested on Linux with Qt 4 and then 5. Change-Id: I1bc7309e34bdf59793f1de510866dae1bb48b539 Reviewed-by: Sergey Belyashov <Sergey.Belyashov@gmail.com> Reviewed-by: Denis Shienkov <denis.shienkov@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/serialport/qserialport.cpp44
-rw-r--r--src/serialport/qserialport.h3
2 files changed, 46 insertions, 1 deletions
diff --git a/src/serialport/qserialport.cpp b/src/serialport/qserialport.cpp
index fb427dc7..34214afa 100644
--- a/src/serialport/qserialport.cpp
+++ b/src/serialport/qserialport.cpp
@@ -306,6 +306,10 @@ int QSerialPortPrivateData::timeoutValue(int msecs, int elapsed)
having enough permission and credentials to open.
\value OpenError An error occurred while attempting to
open an already opened device in this object.
+ \value NotOpenError This error occurs when an operation is executed
+ that can only be successfully performed if the
+ device is open. This value was introduced in
+ QtSerialPort 5.2.
\value ParityError Parity error detected by the hardware while reading data.
\value FramingError Framing error detected by the hardware while reading data.
\value BreakConditionError Break condition detected by the hardware on
@@ -544,6 +548,11 @@ bool QSerialPort::setBaudRate(qint32 baudRate, Directions directions)
{
Q_D(QSerialPort);
+ if (!isOpen()) {
+ setError(QSerialPort::NotOpenError);
+ return false;
+ }
+
if (d->setBaudRate(baudRate, directions)) {
if (directions & QSerialPort::Input) {
if (d->inputBaudRate != baudRate)
@@ -598,6 +607,11 @@ bool QSerialPort::setDataBits(DataBits dataBits)
{
Q_D(QSerialPort);
+ if (!isOpen()) {
+ setError(QSerialPort::NotOpenError);
+ return false;
+ }
+
if (d->setDataBits(dataBits)) {
if (d->dataBits != dataBits) {
d->dataBits = dataBits;
@@ -637,6 +651,11 @@ bool QSerialPort::setParity(Parity parity)
{
Q_D(QSerialPort);
+ if (!isOpen()) {
+ setError(QSerialPort::NotOpenError);
+ return false;
+ }
+
if (d->setParity(parity)) {
if (d->parity != parity) {
d->parity = parity;
@@ -675,6 +694,11 @@ bool QSerialPort::setStopBits(StopBits stopBits)
{
Q_D(QSerialPort);
+ if (!isOpen()) {
+ setError(QSerialPort::NotOpenError);
+ return false;
+ }
+
if (d->setStopBits(stopBits)) {
if (d->stopBits != stopBits) {
d->stopBits = stopBits;
@@ -713,6 +737,11 @@ bool QSerialPort::setFlowControl(FlowControl flow)
{
Q_D(QSerialPort);
+ if (!isOpen()) {
+ setError(QSerialPort::NotOpenError);
+ return false;
+ }
+
if (d->setFlowControl(flow)) {
if (d->flow != flow) {
d->flow = flow;
@@ -752,6 +781,11 @@ bool QSerialPort::setDataTerminalReady(bool set)
{
Q_D(QSerialPort);
+ if (!isOpen()) {
+ setError(QSerialPort::NotOpenError);
+ return false;
+ }
+
bool retval = d->setDataTerminalReady(set);
if (retval && (d->dataTerminalReady != set)) {
d->dataTerminalReady = set;
@@ -790,6 +824,11 @@ bool QSerialPort::setRequestToSend(bool set)
{
Q_D(QSerialPort);
+ if (!isOpen()) {
+ setError(QSerialPort::NotOpenError);
+ return false;
+ }
+
bool retval = d->setRequestToSend(set);
if (retval && (d->requestToSend != set)) {
d->requestToSend = set;
@@ -911,6 +950,11 @@ bool QSerialPort::setDataErrorPolicy(DataErrorPolicy policy)
{
Q_D(QSerialPort);
+ if (!isOpen()) {
+ setError(QSerialPort::NotOpenError);
+ return false;
+ }
+
const bool ret = d->policy == policy || d->setDataErrorPolicy(policy);
if (ret && (d->policy != policy)) {
d->policy = policy;
diff --git a/src/serialport/qserialport.h b/src/serialport/qserialport.h
index 781a98b1..81a39fb3 100644
--- a/src/serialport/qserialport.h
+++ b/src/serialport/qserialport.h
@@ -165,7 +165,8 @@ public:
ResourceError,
UnsupportedOperationError,
UnknownError,
- TimeoutError
+ TimeoutError,
+ NotOpenError
};
explicit QSerialPort(QObject *parent = 0);