diff options
author | Denis Shienkov <denis.shienkov@gmail.com> | 2016-07-15 16:26:12 +0300 |
---|---|---|
committer | Denis Shienkov <denis.shienkov@gmail.com> | 2016-07-22 13:54:49 +0000 |
commit | 36b24743ccecd56b132cd81f05842943ff716943 (patch) | |
tree | f2e68a75efb65cae2e11f7750a099f9f89355ba7 /src | |
parent | 25c8ece6f31e2dc7e31bf00d8bcaf49f2d3283a5 (diff) |
CAN: Prevent to open or close an already opened or closed device
We do not need do excess checks on is "open/close", as this
should becomes once in QCanBusDevice.
* QCBD::connectDevice() should return an error when the device
still is in progress of connecting/disconnecting, or already
connected.
* QCBD::disconnectDevice() has to make disconnection when the
device is in connected or connecting state; otherwise if the
device is in disconnecting state, then it should do nothing
(and as well when the device is in disconnected state).
Note: This behavior is similar to QAbstractSocket.
Change-Id: I4b62e728d37b190fbaee768bdd0a2878c3ba98ab
Reviewed-by: André Hartmann <aha_1980@gmx.de>
Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/serialbus/qcanbusdevice.cpp | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/src/serialbus/qcanbusdevice.cpp b/src/serialbus/qcanbusdevice.cpp index 13f4530..00505bf 100644 --- a/src/serialbus/qcanbusdevice.cpp +++ b/src/serialbus/qcanbusdevice.cpp @@ -520,8 +520,11 @@ bool QCanBusDevice::connectDevice() { Q_D(QCanBusDevice); - if (d->state != QCanBusDevice::UnconnectedState) + if (d->state != QCanBusDevice::UnconnectedState) { + setError(tr("Can not connect an already connected device"), + QCanBusDevice::ConnectionError); return false; + } setState(ConnectingState); @@ -542,6 +545,14 @@ bool QCanBusDevice::connectDevice() */ void QCanBusDevice::disconnectDevice() { + Q_D(QCanBusDevice); + + if (d->state == QCanBusDevice::UnconnectedState + || d->state == QCanBusDevice::ClosingState) { + qWarning("Can not disconnect an unconnected device"); + return; + } + setState(QCanBusDevice::ClosingState); //Unconnected is set by backend -> might be delayed by event loop |