diff options
author | Denis Shienkov <denis.shienkov@gmail.com> | 2015-09-11 12:25:13 +0300 |
---|---|---|
committer | Denis Shienkov <denis.shienkov@gmail.com> | 2015-09-11 12:43:52 +0000 |
commit | 24c96d1e5c06bcae05f66ad4603dc77fe5bc52ed (patch) | |
tree | 2972cec22a9fc112d9a77c9051920c7e33d7aac9 /src/plugins/canbus/peakcan/peakcanbackend.cpp | |
parent | c88c09e6bd8eb36c19ec7dd8c05d01c426b8ab4e (diff) |
PeakCan: Disable the read notification in separate method
A code related to the releasing of read notification resources
is moved to the separate disableReadNotification() method.
Change-Id: Ic9d65ba2c2c130eadd1828869cd31469b917d9fa
Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
Diffstat (limited to 'src/plugins/canbus/peakcan/peakcanbackend.cpp')
-rw-r--r-- | src/plugins/canbus/peakcan/peakcanbackend.cpp | 39 |
1 files changed, 25 insertions, 14 deletions
diff --git a/src/plugins/canbus/peakcan/peakcanbackend.cpp b/src/plugins/canbus/peakcan/peakcanbackend.cpp index ca36923..ab8f01d 100644 --- a/src/plugins/canbus/peakcan/peakcanbackend.cpp +++ b/src/plugins/canbus/peakcan/peakcanbackend.cpp @@ -223,20 +223,7 @@ void PeakCanBackendPrivate::close() Q_Q(PeakCanBackend); enableWriteNotification(false); - - if (incomingEventNotifier) { - incomingEventNotifier->setEnabled(false); - incomingEventNotifier->deleteLater(); - } - -#if defined(Q_OS_WIN32) - if (incomingEventHandle != INVALID_HANDLE_VALUE) { - ::CloseHandle(incomingEventHandle); - incomingEventHandle = INVALID_HANDLE_VALUE; - } -#else - incomingEventHandle = -1; -#endif + disableReadNotification(); if (outgoingEventNotifier) outgoingEventNotifier->deleteLater(); @@ -382,6 +369,30 @@ bool PeakCanBackendPrivate::enableReadNotification() return true; } +void PeakCanBackendPrivate::disableReadNotification() +{ + Q_Q(PeakCanBackend); + + quint32 value = 0; + if (TPCANStatus st = ::CAN_SetValue(channelIndex, PCAN_RECEIVE_EVENT, &value, sizeof(value)) != PCAN_ERROR_OK) + q->setError(systemErrorString(st), QCanBusDevice::ConnectionError); + + if (incomingEventNotifier) { + delete incomingEventNotifier; + incomingEventNotifier = Q_NULLPTR; + } + +#if defined(Q_OS_WIN32) + if (incomingEventHandle && (incomingEventHandle != INVALID_HANDLE_VALUE)) { + if (!::CloseHandle(incomingEventHandle)) + q->setError(qt_error_string(::GetLastError()), QCanBusDevice::ConnectionError); + incomingEventHandle = INVALID_HANDLE_VALUE; + } +#else + incomingEventHandle = -1; +#endif +} + void PeakCanBackendPrivate::canReadNotification() { Q_Q(PeakCanBackend); |