summaryrefslogtreecommitdiff
path: root/src/serialport/qserialport_win.cpp
diff options
context:
space:
mode:
authorFrederik Gladhorn <frederik.gladhorn@digia.com>2013-12-24 01:06:18 +0100
committerFrederik Gladhorn <frederik.gladhorn@digia.com>2014-01-02 16:17:28 +0100
commit343bf28e95581476f6f41334e69d21aae5df70bd (patch)
treefec910cfe43af133c515b9d487cdb8bb65df0d77 /src/serialport/qserialport_win.cpp
parent6f699f91ed8f184eee26b83e5f6edfa04b27b4ec (diff)
parent4e15aa6d7c4f9a03f4ae57b3ba04ade3400cccf1 (diff)
downloadqtserialport-343bf28e95581476f6f41334e69d21aae5df70bd.tar.gz
Merge remote-tracking branch 'origin/stable' into dev
Conflicts: .qmake.conf src/serialport/qserialportinfo_unix.cpp Change-Id: I9582d161018939defd3ba81d601fff176e86eb3c
Diffstat (limited to 'src/serialport/qserialport_win.cpp')
-rw-r--r--src/serialport/qserialport_win.cpp480
1 files changed, 181 insertions, 299 deletions
diff --git a/src/serialport/qserialport_win.cpp b/src/serialport/qserialport_win.cpp
index 80cba34..506dc94 100644
--- a/src/serialport/qserialport_win.cpp
+++ b/src/serialport/qserialport_win.cpp
@@ -88,167 +88,55 @@ QT_BEGIN_NAMESPACE
#ifndef Q_OS_WINCE
-class AbstractOverlappedEventNotifier : public QWinEventNotifier
+static void initializeOverlappedStructure(OVERLAPPED &overlapped)
{
- Q_OBJECT
-public:
- enum Type { CommEvent, ReadCompletionEvent, WriteCompletionEvent };
-
- AbstractOverlappedEventNotifier(QSerialPortPrivate *d, Type type, bool manual, QObject *parent)
- : QWinEventNotifier(parent), dptr(d), t(type) {
- ::ZeroMemory(&o, sizeof(o));
- o.hEvent = ::CreateEvent(NULL, manual, FALSE, NULL);
- if (!o.hEvent) {
- dptr->setError(dptr->decodeSystemError());
- } else {
- setHandle(o.hEvent);
- dptr->notifiers[o.hEvent] = this;
- }
- }
-
- virtual bool processCompletionRoutine() = 0;
-
- virtual ~AbstractOverlappedEventNotifier() {
- setEnabled(false);
- if (!::CloseHandle(o.hEvent))
- dptr->setError(dptr->decodeSystemError());
- }
-
- Type type() const { return t; }
- OVERLAPPED *overlappedPointer() { return &o; }
-
-protected:
- bool event(QEvent *e) Q_DECL_OVERRIDE {
- const bool ret = QWinEventNotifier::event(e);
- if (e->type() == QEvent::WinEventAct)
- processCompletionRoutine();
- return ret;
- }
-
- QSerialPortPrivate *dptr;
- Type t;
- OVERLAPPED o;
-};
-
-class CommOverlappedEventNotifier : public AbstractOverlappedEventNotifier
-{
- Q_OBJECT
-public:
- CommOverlappedEventNotifier(QSerialPortPrivate *d, DWORD eventMask, QObject *parent)
- : AbstractOverlappedEventNotifier(d, CommEvent, false, parent)
- , originalEventMask(eventMask), triggeredEventMask(0) {
- if (!::SetCommMask(dptr->descriptor, originalEventMask))
- dptr->setError(dptr->decodeSystemError());
- else
- startWaitCommEvent();
- }
-
- void startWaitCommEvent() {
- if (!::WaitCommEvent(dptr->descriptor, &triggeredEventMask, &o)) {
- const QSerialPort::SerialPortError error = dptr->decodeSystemError();
- if (error != QSerialPort::NoError) {
- dptr->setError(dptr->decodeSystemError());
- return;
- }
- }
- }
-
- bool processCompletionRoutine() Q_DECL_OVERRIDE {
- DWORD numberOfBytesTransferred = 0;
-
- if (!::GetOverlappedResult(dptr->descriptor, &o, &numberOfBytesTransferred, FALSE))
- dptr->setError(dptr->decodeSystemError());
-
- bool error = false;
-
- // Check for unexpected event. This event triggered when pulled previously
- // opened device from the system, when opened as for not to read and not to
- // write options and so forth.
- if (triggeredEventMask == 0)
- error = true;
-
- // Workaround for standard CDC ACM serial ports, for which triggered an
- // unexpected event EV_TXEMPTY at data transmission.
- if ((originalEventMask & triggeredEventMask) == 0) {
- if ((triggeredEventMask & EV_TXEMPTY) == 0)
- error = true;
- }
-
- // Start processing a caught error.
- if (error || (EV_ERR & triggeredEventMask))
- dptr->processIoErrors(error);
-
- if (!error)
- dptr->startAsyncRead();
-
- return !error;
- }
-
-private:
- DWORD originalEventMask;
- DWORD triggeredEventMask;
-};
-
-class ReadOverlappedCompletionNotifier : public AbstractOverlappedEventNotifier
-{
- Q_OBJECT
-public:
- ReadOverlappedCompletionNotifier(QSerialPortPrivate *d, QObject *parent)
- : AbstractOverlappedEventNotifier(d, ReadCompletionEvent, false, parent) {}
-
- bool processCompletionRoutine() Q_DECL_OVERRIDE {
- DWORD numberOfBytesTransferred = 0;
- if (!::GetOverlappedResult(dptr->descriptor, &o, &numberOfBytesTransferred, FALSE))
- dptr->setError(dptr->decodeSystemError());
-
- dptr->completeAsyncRead(numberOfBytesTransferred);
-
- // start async read for possible remainder into driver queue
- if ((numberOfBytesTransferred > 0) && (dptr->policy == QSerialPort::IgnorePolicy)) {
- dptr->startAsyncRead();
- } else { // driver queue is emplty, so startup wait comm event
- CommOverlappedEventNotifier *n =
- qobject_cast<CommOverlappedEventNotifier *>(dptr->lookupCommEventNotifier());
- if (n)
- n->startWaitCommEvent();
- }
-
- return true;
- }
-};
-
-class WriteOverlappedCompletionNotifier : public AbstractOverlappedEventNotifier
-{
- Q_OBJECT
-public:
- WriteOverlappedCompletionNotifier(QSerialPortPrivate *d, QObject *parent)
- : AbstractOverlappedEventNotifier(d, WriteCompletionEvent, false, parent) {}
-
- bool processCompletionRoutine() Q_DECL_OVERRIDE {
- setEnabled(false);
- DWORD numberOfBytesTransferred = 0;
- if (!::GetOverlappedResult(dptr->descriptor, &o, &numberOfBytesTransferred, FALSE)) {
- numberOfBytesTransferred = 0;
- dptr->setError(dptr->decodeSystemError());
- }
-
- dptr->completeAsyncWrite(numberOfBytesTransferred);
- return true;
- }
-};
-
-#include "qserialport_win.moc"
+ overlapped.Internal = 0;
+ overlapped.InternalHigh = 0;
+ overlapped.Offset = 0;
+ overlapped.OffsetHigh = 0;
+}
QSerialPortPrivate::QSerialPortPrivate(QSerialPort *q)
: QSerialPortPrivateData(q)
, descriptor(INVALID_HANDLE_VALUE)
, parityErrorOccurred(false)
- , actualReadBufferSize(0)
+ , readChunkBuffer(ReadChunkSize, 0)
, actualWriteBufferSize(0)
, acyncWritePosition(0)
, readyReadEmitted(0)
, writeSequenceStarted(false)
+ , communicationNotifier(new QWinEventNotifier(q))
+ , readCompletionNotifier(new QWinEventNotifier(q))
+ , writeCompletionNotifier(new QWinEventNotifier(q))
+ , originalEventMask(0)
+ , triggeredEventMask(0)
{
+ ::ZeroMemory(&communicationOverlapped, sizeof(communicationOverlapped));
+ communicationOverlapped.hEvent = ::CreateEvent(NULL, FALSE, FALSE, NULL);
+ if (!communicationOverlapped.hEvent)
+ q->setError(decodeSystemError());
+ else {
+ communicationNotifier->setHandle(communicationOverlapped.hEvent);
+ q->connect(communicationNotifier, SIGNAL(activated(HANDLE)), q, SLOT(_q_canCompleteCommunication()));
+ }
+
+ ::ZeroMemory(&readCompletionOverlapped, sizeof(readCompletionOverlapped));
+ readCompletionOverlapped.hEvent = ::CreateEvent(NULL, FALSE, FALSE, NULL);
+ if (!readCompletionOverlapped.hEvent)
+ q->setError(decodeSystemError());
+ else {
+ readCompletionNotifier->setHandle(readCompletionOverlapped.hEvent);
+ q->connect(readCompletionNotifier, SIGNAL(activated(HANDLE)), q, SLOT(_q_canCompleteRead()));
+ }
+
+ ::ZeroMemory(&writeCompletionOverlapped, sizeof(writeCompletionOverlapped));
+ writeCompletionOverlapped.hEvent = ::CreateEvent(NULL, FALSE, FALSE, NULL);
+ if (!writeCompletionOverlapped.hEvent)
+ q->setError(decodeSystemError());
+ else {
+ writeCompletionNotifier->setHandle(writeCompletionOverlapped.hEvent);
+ q->connect(writeCompletionNotifier, SIGNAL(activated(HANDLE)), q, SLOT(_q_canCompleteWrite()));
+ }
}
bool QSerialPortPrivate::open(QIODevice::OpenMode mode)
@@ -256,7 +144,7 @@ bool QSerialPortPrivate::open(QIODevice::OpenMode mode)
Q_Q(QSerialPort);
DWORD desiredAccess = 0;
- DWORD originalEventMask = EV_ERR;
+ originalEventMask = EV_ERR;
if (mode & QIODevice::ReadOnly) {
desiredAccess |= GENERIC_READ;
@@ -300,13 +188,27 @@ bool QSerialPortPrivate::open(QIODevice::OpenMode mode)
if (!updateCommTimeouts())
return false;
- if (originalEventMask & EV_RXCHAR) {
- QWinEventNotifier *n = new ReadOverlappedCompletionNotifier(this, q);
- n->setEnabled(true);
+ if (mode & QIODevice::ReadOnly)
+ readCompletionNotifier->setEnabled(true);
+
+ if (mode & QIODevice::WriteOnly)
+ writeCompletionNotifier->setEnabled(true);
+
+ if (!::SetCommMask(descriptor, originalEventMask)) {
+ q->setError(decodeSystemError());
+ return false;
+ }
+
+ initializeOverlappedStructure(communicationOverlapped);
+ if (!::WaitCommEvent(descriptor, &triggeredEventMask, &communicationOverlapped)) {
+ const QSerialPort::SerialPortError error = decodeSystemError();
+ if (error != QSerialPort::NoError) {
+ q->setError(decodeSystemError());
+ return false;
+ }
}
- QWinEventNotifier *n = new CommOverlappedEventNotifier(this, originalEventMask, q);
- n->setEnabled(true);
+ communicationNotifier->setEnabled(true);
detectDefaultSettings();
return true;
@@ -319,11 +221,11 @@ void QSerialPortPrivate::close()
if (!::CancelIo(descriptor))
q->setError(decodeSystemError());
- qDeleteAll(notifiers);
- notifiers.clear();
+ readCompletionNotifier->setEnabled(false);
+ writeCompletionNotifier->setEnabled(false);
+ communicationNotifier->setEnabled(false);
readBuffer.clear();
- actualReadBufferSize = 0;
writeSequenceStarted = false;
writeBuffer.clear();
@@ -356,7 +258,7 @@ QSerialPort::PinoutSignals QSerialPortPrivate::pinoutSignals()
if (!::GetCommModemStatus(descriptor, &modemStat)) {
q->setError(decodeSystemError());
- return QSerialPort::UnknownSignal;
+ return QSerialPort::NoSignal;
}
QSerialPort::PinoutSignals ret = QSerialPort::NoSignal;
@@ -405,10 +307,8 @@ bool QSerialPortPrivate::flush()
bool QSerialPortPrivate::clear(QSerialPort::Directions directions)
{
DWORD flags = 0;
- if (directions & QSerialPort::Input) {
+ if (directions & QSerialPort::Input)
flags |= PURGE_RXABORT | PURGE_RXCLEAR;
- actualReadBufferSize = 0;
- }
if (directions & QSerialPort::Output) {
flags |= PURGE_TXABORT | PURGE_TXCLEAR;
actualWriteBufferSize = 0;
@@ -466,38 +366,6 @@ qint64 QSerialPortPrivate::systemOutputQueueSize ()
#ifndef Q_OS_WINCE
-qint64 QSerialPortPrivate::bytesAvailable() const
-{
- return actualReadBufferSize;
-}
-
-qint64 QSerialPortPrivate::readFromBuffer(char *data, qint64 maxSize)
-{
- if (actualReadBufferSize == 0)
- return 0;
-
- qint64 readSoFar = -1;
- if (maxSize == 1 && actualReadBufferSize > 0) {
- *data = readBuffer.getChar();
- actualReadBufferSize--;
- readSoFar = 1;
- } else {
- const qint64 bytesToRead = qMin(qint64(actualReadBufferSize), maxSize);
- readSoFar = 0;
- while (readSoFar < bytesToRead) {
- const char *ptr = readBuffer.readPointer();
- const int bytesToReadFromThisBlock = qMin(bytesToRead - readSoFar,
- qint64(readBuffer.nextDataBlockSize()));
- ::memcpy(data + readSoFar, ptr, bytesToReadFromThisBlock);
- readSoFar += bytesToReadFromThisBlock;
- readBuffer.free(bytesToReadFromThisBlock);
- actualReadBufferSize -= bytesToReadFromThisBlock;
- }
- }
-
- return readSoFar;
-}
-
qint64 QSerialPortPrivate::writeToBuffer(const char *data, qint64 maxSize)
{
char *ptr = writeBuffer.reserve(maxSize);
@@ -524,28 +392,28 @@ bool QSerialPortPrivate::waitForReadyRead(int msecs)
do {
bool timedOut = false;
- AbstractOverlappedEventNotifier *n = 0;
+ HANDLE triggeredEvent = 0;
- if (!waitAnyEvent(timeoutValue(msecs, stopWatch.elapsed()), &timedOut, &n) || !n) {
+ if (!waitAnyEvent(timeoutValue(msecs, stopWatch.elapsed()), &timedOut, &triggeredEvent) || !triggeredEvent) {
// This is occur timeout or another error
if (!timedOut)
q->setError(decodeSystemError());
return false;
}
- switch (n->type()) {
- case AbstractOverlappedEventNotifier::CommEvent:
- if (!n->processCompletionRoutine())
+ if (triggeredEvent == communicationOverlapped.hEvent) {
+ _q_canCompleteCommunication();
+ if (error != QSerialPort::NoError)
return false;
- break;
- case AbstractOverlappedEventNotifier::ReadCompletionEvent:
- return n->processCompletionRoutine();
- case AbstractOverlappedEventNotifier::WriteCompletionEvent:
- n->processCompletionRoutine();
- break;
- default: // newer called
+ } else if (triggeredEvent == readCompletionOverlapped.hEvent) {
+ _q_canCompleteRead();
+ return error == QSerialPort::NoError;
+ } else if (triggeredEvent == writeCompletionOverlapped.hEvent) {
+ _q_canCompleteWrite();
+ } else {
return false;
}
+
} while (msecs == -1 || timeoutValue(msecs, stopWatch.elapsed()) > 0);
return false;
@@ -563,25 +431,25 @@ bool QSerialPortPrivate::waitForBytesWritten(int msecs)
forever {
bool timedOut = false;
- AbstractOverlappedEventNotifier *n = 0;
+ HANDLE triggeredEvent = 0;
- if (!waitAnyEvent(timeoutValue(msecs, stopWatch.elapsed()), &timedOut, &n) || !n) {
+ if (!waitAnyEvent(timeoutValue(msecs, stopWatch.elapsed()), &timedOut, &triggeredEvent) || !triggeredEvent) {
if (!timedOut)
q->setError(decodeSystemError());
return false;
}
- switch (n->type()) {
- case AbstractOverlappedEventNotifier::CommEvent:
- // do nothing, jump to ReadCompletionEvent case
- case AbstractOverlappedEventNotifier::ReadCompletionEvent:
- n->processCompletionRoutine();
- break;
- case AbstractOverlappedEventNotifier::WriteCompletionEvent:
- return n->processCompletionRoutine();
- default: // newer called
+ if (triggeredEvent == communicationOverlapped.hEvent) {
+ _q_canCompleteRead();
+ } else if (triggeredEvent == readCompletionOverlapped.hEvent) {
+ _q_canCompleteRead();
+ } else if (triggeredEvent == writeCompletionOverlapped.hEvent) {
+ _q_canCompleteWrite();
+ return error == QSerialPort::NoError;
+ } else {
return false;
}
+
}
return false;
@@ -685,6 +553,75 @@ bool QSerialPortPrivate::setDataErrorPolicy(QSerialPort::DataErrorPolicy policy)
#ifndef Q_OS_WINCE
+void QSerialPortPrivate::_q_canCompleteCommunication()
+{
+ Q_Q(QSerialPort);
+
+ DWORD numberOfBytesTransferred = 0;
+
+ if (!::GetOverlappedResult(descriptor, &communicationOverlapped, &numberOfBytesTransferred, FALSE))
+ q->setError(decodeSystemError());
+
+ bool error = false;
+
+ // Check for unexpected event. This event triggered when pulled previously
+ // opened device from the system, when opened as for not to read and not to
+ // write options and so forth.
+ if (triggeredEventMask == 0)
+ error = true;
+
+ // Workaround for standard CDC ACM serial ports, for which triggered an
+ // unexpected event EV_TXEMPTY at data transmission.
+ if ((originalEventMask & triggeredEventMask) == 0) {
+ if ((triggeredEventMask & EV_TXEMPTY) == 0)
+ error = true;
+ }
+
+ // Start processing a caught error.
+ if (error || (EV_ERR & triggeredEventMask))
+ processIoErrors(error);
+
+ if (!error)
+ startAsyncRead();
+}
+
+void QSerialPortPrivate::_q_canCompleteRead()
+{
+ Q_Q(QSerialPort);
+
+ DWORD numberOfBytesTransferred = 0;
+ if (!::GetOverlappedResult(descriptor, &readCompletionOverlapped, &numberOfBytesTransferred, FALSE))
+ q->setError(decodeSystemError());
+
+ completeAsyncRead(numberOfBytesTransferred);
+
+ // start async read for possible remainder into driver queue
+ if ((numberOfBytesTransferred > 0) && (policy == QSerialPort::IgnorePolicy)) {
+ startAsyncRead();
+ } else { // driver queue is emplty, so startup wait comm event
+ initializeOverlappedStructure(communicationOverlapped);
+ if (!::WaitCommEvent(descriptor, &triggeredEventMask, &communicationOverlapped)) {
+ const QSerialPort::SerialPortError error = decodeSystemError();
+ if (error != QSerialPort::NoError) {
+ q->setError(decodeSystemError());
+ }
+ }
+ }
+}
+
+void QSerialPortPrivate::_q_canCompleteWrite()
+{
+ Q_Q(QSerialPort);
+
+ DWORD numberOfBytesTransferred = 0;
+ if (!::GetOverlappedResult(descriptor, &writeCompletionOverlapped, &numberOfBytesTransferred, FALSE)) {
+ numberOfBytesTransferred = 0;
+ q->setError(decodeSystemError());
+ }
+
+ completeAsyncWrite(numberOfBytesTransferred);
+}
+
bool QSerialPortPrivate::startAsyncRead()
{
Q_Q(QSerialPort);
@@ -700,15 +637,8 @@ bool QSerialPortPrivate::startAsyncRead()
}
}
- AbstractOverlappedEventNotifier *n = lookupReadCompletionNotifier();
- if (!n) {
- q->setError(QSerialPort::ResourceError);
- return false;
- }
-
- char *ptr = readBuffer.reserve(bytesToRead);
-
- if (::ReadFile(descriptor, ptr, bytesToRead, NULL, n->overlappedPointer()))
+ initializeOverlappedStructure(readCompletionOverlapped);
+ if (::ReadFile(descriptor, readChunkBuffer.data(), bytesToRead, NULL, &readCompletionOverlapped))
return true;
QSerialPort::SerialPortError error = decodeSystemError();
@@ -717,7 +647,6 @@ bool QSerialPortPrivate::startAsyncRead()
error = QSerialPort::ReadError;
q->setError(error);
- readBuffer.truncate(actualReadBufferSize);
return false;
}
@@ -740,15 +669,8 @@ bool QSerialPortPrivate::startAsyncWrite(int maxSize)
writeSequenceStarted = true;
- AbstractOverlappedEventNotifier *n = lookupFreeWriteCompletionNotifier();
- if (!n) {
- q->setError(QSerialPort::ResourceError);
- return false;
- }
-
- n->setEnabled(true);
-
- if (::WriteFile(descriptor, ptr, nextSize, NULL, n->overlappedPointer()))
+ initializeOverlappedStructure(writeCompletionOverlapped);
+ if (::WriteFile(descriptor, ptr, nextSize, NULL, &writeCompletionOverlapped))
return true;
QSerialPort::SerialPortError error = decodeSystemError();
@@ -800,11 +722,10 @@ void QSerialPortPrivate::completeAsyncRead(DWORD numberOfBytes)
{
Q_Q(QSerialPort);
- actualReadBufferSize += qint64(numberOfBytes);
- readBuffer.truncate(actualReadBufferSize);
-
if (numberOfBytes > 0) {
+ readBuffer.append(readChunkBuffer.left(numberOfBytes));
+
// Process emulate policy.
if ((policy != QSerialPort::IgnorePolicy) && parityErrorOccurred) {
@@ -854,39 +775,6 @@ void QSerialPortPrivate::completeAsyncWrite(DWORD numberOfBytes)
startAsyncWrite(WriteChunkSize);
}
-AbstractOverlappedEventNotifier *QSerialPortPrivate::lookupFreeWriteCompletionNotifier()
-{
- Q_Q(QSerialPort);
-
- // find first free not running write notifier
- foreach (AbstractOverlappedEventNotifier *n, notifiers) {
- if ((n->type() == AbstractOverlappedEventNotifier::WriteCompletionEvent)
- && !n->isEnabled()) {
- return n;
- }
- }
- // if all write notifiers in use, then create new write notifier
- return new WriteOverlappedCompletionNotifier(this, q);
-}
-
-AbstractOverlappedEventNotifier *QSerialPortPrivate::lookupCommEventNotifier()
-{
- foreach (AbstractOverlappedEventNotifier *n, notifiers) {
- if (n->type() == AbstractOverlappedEventNotifier::CommEvent)
- return n;
- }
- return 0;
-}
-
-AbstractOverlappedEventNotifier *QSerialPortPrivate::lookupReadCompletionNotifier()
-{
- foreach (AbstractOverlappedEventNotifier *n, notifiers) {
- if (n->type() == AbstractOverlappedEventNotifier::ReadCompletionEvent)
- return n;
- }
- return 0;
-}
-
bool QSerialPortPrivate::updateDcb()
{
Q_Q(QSerialPort);
@@ -932,7 +820,8 @@ void QSerialPortPrivate::detectDefaultSettings()
dataBits = QSerialPort::Data8;
break;
default:
- dataBits = QSerialPort::UnknownDataBits;
+ qWarning("%s: Unexpected data bits settings", Q_FUNC_INFO);
+ dataBits = QSerialPort::Data8;
break;
}
@@ -947,8 +836,10 @@ void QSerialPortPrivate::detectDefaultSettings()
parity = QSerialPort::EvenParity;
else if ((currentDcb.Parity == ODDPARITY) && currentDcb.fParity)
parity = QSerialPort::OddParity;
- else
- parity = QSerialPort::UnknownParity;
+ else {
+ qWarning("%s: Unexpected parity settings", Q_FUNC_INFO);
+ parity = QSerialPort::NoParity;
+ }
// Detect stopbits.
switch (currentDcb.StopBits) {
@@ -962,7 +853,8 @@ void QSerialPortPrivate::detectDefaultSettings()
stopBits = QSerialPort::TwoStop;
break;
default:
- stopBits = QSerialPort::UnknownStopBits;
+ qWarning("%s: Unexpected stop bits settings", Q_FUNC_INFO);
+ stopBits = QSerialPort::OneStop;
break;
}
@@ -976,8 +868,10 @@ void QSerialPortPrivate::detectDefaultSettings()
} else if (currentDcb.fOutxCtsFlow && (currentDcb.fRtsControl == RTS_CONTROL_HANDSHAKE)
&& !currentDcb.fInX && !currentDcb.fOutX) {
flow = QSerialPort::HardwareControl;
- } else
- flow = QSerialPort::UnknownFlowControl;
+ } else {
+ qWarning("%s: Unexpected flow control settings", Q_FUNC_INFO);
+ flow = QSerialPort::NoFlowControl;
+ }
}
QSerialPort::SerialPortError QSerialPortPrivate::decodeSystemError() const
@@ -1017,14 +911,17 @@ QSerialPort::SerialPortError QSerialPortPrivate::decodeSystemError() const
#ifndef Q_OS_WINCE
-bool QSerialPortPrivate::waitAnyEvent(int msecs, bool *timedOut,
- AbstractOverlappedEventNotifier **triggeredNotifier)
+bool QSerialPortPrivate::waitAnyEvent(int msecs, bool *timedOut, HANDLE *triggeredEvent)
{
Q_Q(QSerialPort);
Q_ASSERT(timedOut);
- QVector<HANDLE> handles = notifiers.keys().toVector();
+ QVector<HANDLE> handles = QVector<HANDLE>()
+ << communicationOverlapped.hEvent
+ << readCompletionOverlapped.hEvent
+ << writeCompletionOverlapped.hEvent;
+
DWORD waitResult = ::WaitForMultipleObjects(handles.count(),
handles.constData(),
FALSE, // wait any event
@@ -1038,8 +935,7 @@ bool QSerialPortPrivate::waitAnyEvent(int msecs, bool *timedOut,
if (waitResult >= DWORD(WAIT_OBJECT_0 + handles.count()))
return false;
- HANDLE h = handles.at(waitResult - WAIT_OBJECT_0);
- *triggeredNotifier = notifiers.value(h);
+ *triggeredEvent = handles.at(waitResult - WAIT_OBJECT_0);
return true;
}
@@ -1155,21 +1051,7 @@ qint32 QSerialPortPrivate::settingFromBaudRate(qint32 baudRate)
QList<qint32> QSerialPortPrivate::standardBaudRates()
{
- QList<qint32> ret;
- const QList<qint32> baudRatePairs = standardBaudRatePairList();
-
- foreach (qint32 baudRatePair, baudRatePairs) {
- ret.append(baudRatePair);
- }
-
- return ret;
-}
-
-void QSerialPortPrivate::setError(QSerialPort::SerialPortError serialPortError, const QString &errorString)
-{
- Q_Q(QSerialPort);
-
- q->setError(serialPortError, errorString);
+ return standardBaudRatePairList();
}
QSerialPort::Handle QSerialPort::handle() const