diff options
author | Laszlo Papp <lpapp@kde.org> | 2014-02-02 19:52:33 +0000 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-02-10 09:11:55 +0100 |
commit | 558efaa9e7827b652a1902c96dc5a275ebd5419a (patch) | |
tree | 991ae1cd8b3a5b7713430256038e4b17ac9a7a3b | |
parent | 1dcd4c2f7e5204ff5dc7a0d8c75ca65bbb28048b (diff) | |
download | qtserialport-558efaa9e7827b652a1902c96dc5a275ebd5419a.tar.gz |
Rename the "descriptor" to handle on Windows
* Windows uses the term handle instead of descriptor.
* It is also consistent with the rest how Qt manages it.
Conflicts:
src/serialport/qserialport_win.cpp
Change-Id: I68a672ea2d8e88e26ad5d822b157ccab79a3d2d9
Reviewed-by: Sergey Belyashov <Sergey.Belyashov@gmail.com>
Reviewed-by: Denis Shienkov <denis.shienkov@gmail.com>
-rw-r--r-- | src/serialport/qserialport_win.cpp | 56 | ||||
-rw-r--r-- | src/serialport/qserialport_win_p.h | 2 | ||||
-rw-r--r-- | src/serialport/qserialport_wince.cpp | 54 | ||||
-rw-r--r-- | src/serialport/qserialportinfo_win.cpp | 12 |
4 files changed, 62 insertions, 62 deletions
diff --git a/src/serialport/qserialport_win.cpp b/src/serialport/qserialport_win.cpp index 03775fb..4dc2fe6 100644 --- a/src/serialport/qserialport_win.cpp +++ b/src/serialport/qserialport_win.cpp @@ -98,7 +98,7 @@ static void initializeOverlappedStructure(OVERLAPPED &overlapped) QSerialPortPrivate::QSerialPortPrivate(QSerialPort *q) : QSerialPortPrivateData(q) - , descriptor(INVALID_HANDLE_VALUE) + , handle(INVALID_HANDLE_VALUE) , parityErrorOccurred(false) , readChunkBuffer(ReadChunkSize, 0) , readyReadEmitted(0) @@ -151,15 +151,15 @@ bool QSerialPortPrivate::open(QIODevice::OpenMode mode) if (mode & QIODevice::WriteOnly) desiredAccess |= GENERIC_WRITE; - descriptor = ::CreateFile(reinterpret_cast<const wchar_t*>(systemLocation.utf16()), + handle = ::CreateFile(reinterpret_cast<const wchar_t*>(systemLocation.utf16()), desiredAccess, 0, NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL); - if (descriptor == INVALID_HANDLE_VALUE) { + if (handle == INVALID_HANDLE_VALUE) { q->setError(decodeSystemError()); return false; } - if (!::GetCommState(descriptor, &restoredDcb)) { + if (!::GetCommState(handle, &restoredDcb)) { q->setError(decodeSystemError()); return false; } @@ -175,7 +175,7 @@ bool QSerialPortPrivate::open(QIODevice::OpenMode mode) if (!updateDcb()) return false; - if (!::GetCommTimeouts(descriptor, &restoredCommTimeouts)) { + if (!::GetCommTimeouts(handle, &restoredCommTimeouts)) { q->setError(decodeSystemError()); return false; } @@ -192,7 +192,7 @@ bool QSerialPortPrivate::open(QIODevice::OpenMode mode) if (mode & QIODevice::WriteOnly) writeCompletionNotifier->setEnabled(true); - if (!::SetCommMask(descriptor, originalEventMask)) { + if (!::SetCommMask(handle, originalEventMask)) { q->setError(decodeSystemError()); return false; } @@ -210,7 +210,7 @@ void QSerialPortPrivate::close() { Q_Q(QSerialPort); - if (!::CancelIo(descriptor)) + if (!::CancelIo(handle)) q->setError(decodeSystemError()); readCompletionNotifier->setEnabled(false); @@ -226,16 +226,16 @@ void QSerialPortPrivate::close() parityErrorOccurred = false; if (settingsRestoredOnClose) { - if (!::SetCommState(descriptor, &restoredDcb)) + if (!::SetCommState(handle, &restoredDcb)) q->setError(decodeSystemError()); - else if (!::SetCommTimeouts(descriptor, &restoredCommTimeouts)) + else if (!::SetCommTimeouts(handle, &restoredCommTimeouts)) q->setError(decodeSystemError()); } - if (!::CloseHandle(descriptor)) + if (!::CloseHandle(handle)) q->setError(decodeSystemError()); - descriptor = INVALID_HANDLE_VALUE; + handle = INVALID_HANDLE_VALUE; } #endif // #ifndef Q_OS_WINCE @@ -246,7 +246,7 @@ QSerialPort::PinoutSignals QSerialPortPrivate::pinoutSignals() DWORD modemStat = 0; - if (!::GetCommModemStatus(descriptor, &modemStat)) { + if (!::GetCommModemStatus(handle, &modemStat)) { q->setError(decodeSystemError()); return QSerialPort::NoSignal; } @@ -263,7 +263,7 @@ QSerialPort::PinoutSignals QSerialPortPrivate::pinoutSignals() ret |= QSerialPort::DataCarrierDetectSignal; DWORD bytesReturned = 0; - if (!::DeviceIoControl(descriptor, IOCTL_SERIAL_GET_DTRRTS, NULL, 0, + if (!::DeviceIoControl(handle, IOCTL_SERIAL_GET_DTRRTS, NULL, 0, &modemStat, sizeof(modemStat), &bytesReturned, NULL)) { q->setError(decodeSystemError()); @@ -282,7 +282,7 @@ bool QSerialPortPrivate::setDataTerminalReady(bool set) { Q_Q(QSerialPort); - if (!::EscapeCommFunction(descriptor, set ? SETDTR : CLRDTR)) { + if (!::EscapeCommFunction(handle, set ? SETDTR : CLRDTR)) { q->setError(decodeSystemError()); return false; } @@ -294,7 +294,7 @@ bool QSerialPortPrivate::setRequestToSend(bool set) { Q_Q(QSerialPort); - if (!::EscapeCommFunction(descriptor, set ? SETRTS : CLRRTS)) { + if (!::EscapeCommFunction(handle, set ? SETRTS : CLRRTS)) { q->setError(decodeSystemError()); return false; } @@ -306,7 +306,7 @@ bool QSerialPortPrivate::setRequestToSend(bool set) bool QSerialPortPrivate::flush() { - return startAsyncWrite() && ::FlushFileBuffers(descriptor); + return startAsyncWrite() && ::FlushFileBuffers(handle); } bool QSerialPortPrivate::clear(QSerialPort::Directions directions) @@ -320,7 +320,7 @@ bool QSerialPortPrivate::clear(QSerialPort::Directions directions) flags |= PURGE_TXABORT | PURGE_TXCLEAR; writeSequenceStarted = false; } - if (!::PurgeComm(descriptor, flags)) { + if (!::PurgeComm(handle, flags)) { q->setError(decodeSystemError()); return false; } @@ -347,7 +347,7 @@ bool QSerialPortPrivate::setBreakEnabled(bool set) { Q_Q(QSerialPort); - if (set ? !::SetCommBreak(descriptor) : !::ClearCommBreak(descriptor)) { + if (set ? !::SetCommBreak(handle) : !::ClearCommBreak(handle)) { q->setError(decodeSystemError()); return false; } @@ -539,7 +539,7 @@ void QSerialPortPrivate::_q_completeAsyncCommunication() DWORD numberOfBytesTransferred = 0; - if (!::GetOverlappedResult(descriptor, &communicationOverlapped, &numberOfBytesTransferred, FALSE)) + if (!::GetOverlappedResult(handle, &communicationOverlapped, &numberOfBytesTransferred, FALSE)) q->setError(decodeSystemError()); bool error = false; @@ -570,7 +570,7 @@ void QSerialPortPrivate::_q_completeAsyncRead() Q_Q(QSerialPort); DWORD numberOfBytesTransferred = 0; - if (!::GetOverlappedResult(descriptor, &readCompletionOverlapped, &numberOfBytesTransferred, FALSE)) + if (!::GetOverlappedResult(handle, &readCompletionOverlapped, &numberOfBytesTransferred, FALSE)) q->setError(decodeSystemError()); if (numberOfBytesTransferred > 0) { @@ -593,7 +593,7 @@ void QSerialPortPrivate::_q_completeAsyncWrite() Q_Q(QSerialPort); DWORD numberOfBytesTransferred = 0; - if (!::GetOverlappedResult(descriptor, &writeCompletionOverlapped, &numberOfBytesTransferred, FALSE)) { + if (!::GetOverlappedResult(handle, &writeCompletionOverlapped, &numberOfBytesTransferred, FALSE)) { numberOfBytesTransferred = 0; q->setError(decodeSystemError()); } @@ -612,7 +612,7 @@ bool QSerialPortPrivate::startAsyncCommunication() Q_Q(QSerialPort); initializeOverlappedStructure(communicationOverlapped); - if (!::WaitCommEvent(descriptor, &triggeredEventMask, &communicationOverlapped)) { + if (!::WaitCommEvent(handle, &triggeredEventMask, &communicationOverlapped)) { const QSerialPort::SerialPortError error = decodeSystemError(); if (error != QSerialPort::NoError) { q->setError(decodeSystemError()); @@ -638,7 +638,7 @@ bool QSerialPortPrivate::startAsyncRead() } initializeOverlappedStructure(readCompletionOverlapped); - if (::ReadFile(descriptor, readChunkBuffer.data(), bytesToRead, NULL, &readCompletionOverlapped)) + if (::ReadFile(handle, readChunkBuffer.data(), bytesToRead, NULL, &readCompletionOverlapped)) return true; QSerialPort::SerialPortError error = decodeSystemError(); @@ -661,7 +661,7 @@ bool QSerialPortPrivate::startAsyncWrite() return true; initializeOverlappedStructure(writeCompletionOverlapped); - if (!::WriteFile(descriptor, writeBuffer.readPointer(), + if (!::WriteFile(handle, writeBuffer.readPointer(), writeBuffer.nextDataBlockSize(), NULL, &writeCompletionOverlapped)) { @@ -726,7 +726,7 @@ void QSerialPortPrivate::processIoErrors(bool error) } DWORD errors = 0; - if (!::ClearCommError(descriptor, &errors, NULL)) { + if (!::ClearCommError(handle, &errors, NULL)) { q->setError(decodeSystemError()); return; } @@ -749,7 +749,7 @@ bool QSerialPortPrivate::updateDcb() { Q_Q(QSerialPort); - if (!::SetCommState(descriptor, ¤tDcb)) { + if (!::SetCommState(handle, ¤tDcb)) { q->setError(decodeSystemError()); return false; } @@ -760,7 +760,7 @@ bool QSerialPortPrivate::updateCommTimeouts() { Q_Q(QSerialPort); - if (!::SetCommTimeouts(descriptor, ¤tCommTimeouts)) { + if (!::SetCommTimeouts(handle, ¤tCommTimeouts)) { q->setError(decodeSystemError()); return false; } @@ -1030,7 +1030,7 @@ QList<qint32> QSerialPortPrivate::standardBaudRates() QSerialPort::Handle QSerialPort::handle() const { Q_D(const QSerialPort); - return d->descriptor; + return d->handle; } QT_END_NAMESPACE diff --git a/src/serialport/qserialport_win_p.h b/src/serialport/qserialport_win_p.h index 12bb3f1..0ece047 100644 --- a/src/serialport/qserialport_win_p.h +++ b/src/serialport/qserialport_win_p.h @@ -120,7 +120,7 @@ public: DCB restoredDcb; COMMTIMEOUTS currentCommTimeouts; COMMTIMEOUTS restoredCommTimeouts; - HANDLE descriptor; + HANDLE handle; bool parityErrorOccurred; #ifndef Q_OS_WINCE diff --git a/src/serialport/qserialport_wince.cpp b/src/serialport/qserialport_wince.cpp index bb76465..0a454b4 100644 --- a/src/serialport/qserialport_wince.cpp +++ b/src/serialport/qserialport_wince.cpp @@ -62,12 +62,12 @@ public: CommEventNotifier(DWORD mask, QSerialPortPrivate *d, QObject *parent) : QThread(parent), dptr(d), running(true) { connect(this, SIGNAL(eventMask(quint32)), this, SLOT(processNotification(quint32))); - ::SetCommMask(dptr->descriptor, mask); + ::SetCommMask(dptr->handle, mask); } virtual ~CommEventNotifier() { running = false; - ::SetCommMask(dptr->descriptor, 0); + ::SetCommMask(dptr->handle, 0); wait(); } @@ -75,7 +75,7 @@ protected: void run() Q_DECL_OVERRIDE { DWORD mask = 0; while (running) { - if (::WaitCommEvent(dptr->descriptor, &mask, FALSE)) { + if (::WaitCommEvent(dptr->handle, &mask, FALSE)) { // Wait until complete the operation changes the port settings, // see updateDcb(). dptr->settingsChangeMutex.lock(); @@ -115,8 +115,8 @@ class WaitCommEventBreaker : public QThread { Q_OBJECT public: - WaitCommEventBreaker(HANDLE descriptor, int timeout, QObject *parent = 0) - : QThread(parent), descriptor(descriptor), timeout(timeout), worked(false) { + WaitCommEventBreaker(HANDLE handle, int timeout, QObject *parent = 0) + : QThread(parent), handle(handle), timeout(timeout), worked(false) { start(); } @@ -144,12 +144,12 @@ protected: private slots: void processTimeout() { - ::SetCommMask(descriptor, 0); + ::SetCommMask(handle, 0); stop(); } private: - HANDLE descriptor; + HANDLE handle; int timeout; mutable bool worked; }; @@ -158,7 +158,7 @@ private: QSerialPortPrivate::QSerialPortPrivate(QSerialPort *q) : QSerialPortPrivateData(q) - , descriptor(INVALID_HANDLE_VALUE) + , handle(INVALID_HANDLE_VALUE) , parityErrorOccurred(false) , eventNotifier(0) { @@ -180,15 +180,15 @@ bool QSerialPortPrivate::open(QIODevice::OpenMode mode) eventMask |= EV_TXEMPTY; } - descriptor = ::CreateFile(reinterpret_cast<const wchar_t*>(systemLocation.utf16()), + handle = ::CreateFile(reinterpret_cast<const wchar_t*>(systemLocation.utf16()), desiredAccess, 0, NULL, OPEN_EXISTING, 0, NULL); - if (descriptor == INVALID_HANDLE_VALUE) { + if (handle == INVALID_HANDLE_VALUE) { q->setError(decodeSystemError()); return false; } - if (!::GetCommState(descriptor, &restoredDcb)) { + if (!::GetCommState(handle, &restoredDcb)) { q->setError(decodeSystemError()); return false; } @@ -204,7 +204,7 @@ bool QSerialPortPrivate::open(QIODevice::OpenMode mode) if (!updateDcb()) return false; - if (!::GetCommTimeouts(descriptor, &restoredCommTimeouts)) { + if (!::GetCommTimeouts(handle, &restoredCommTimeouts)) { q->setError(decodeSystemError()); return false; } @@ -230,17 +230,17 @@ void QSerialPortPrivate::close() } if (settingsRestoredOnClose) { - ::SetCommState(descriptor, &restoredDcb); - ::SetCommTimeouts(descriptor, &restoredCommTimeouts); + ::SetCommState(handle, &restoredDcb); + ::SetCommTimeouts(handle, &restoredCommTimeouts); } - ::CloseHandle(descriptor); - descriptor = INVALID_HANDLE_VALUE; + ::CloseHandle(handle); + handle = INVALID_HANDLE_VALUE; } bool QSerialPortPrivate::flush() { - return notifyWrite() && ::FlushFileBuffers(descriptor); + return notifyWrite() && ::FlushFileBuffers(handle); } bool QSerialPortPrivate::clear(QSerialPort::Directions directions) @@ -250,7 +250,7 @@ bool QSerialPortPrivate::clear(QSerialPort::Directions directions) flags |= PURGE_RXABORT | PURGE_RXCLEAR; if (directions & QSerialPort::Output) flags |= PURGE_TXABORT | PURGE_TXCLEAR; - return ::PurgeComm(descriptor, flags); + return ::PurgeComm(handle, flags); } void QSerialPortPrivate::startWriting() @@ -337,7 +337,7 @@ bool QSerialPortPrivate::notifyRead() char *ptr = readBuffer.reserve(bytesToRead); DWORD readBytes = 0; - BOOL sucessResult = ::ReadFile(descriptor, ptr, bytesToRead, &readBytes, NULL); + BOOL sucessResult = ::ReadFile(handle, ptr, bytesToRead, &readBytes, NULL); if (!sucessResult) { readBuffer.truncate(bytesToRead); @@ -383,7 +383,7 @@ bool QSerialPortPrivate::notifyWrite() const char *ptr = writeBuffer.readPointer(); DWORD bytesWritten = 0; - if (!::WriteFile(descriptor, ptr, nextSize, &bytesWritten, NULL)) { + if (!::WriteFile(handle, ptr, nextSize, &bytesWritten, NULL)) { q->setError(QSerialPort::WriteError); return false; } @@ -406,8 +406,8 @@ bool QSerialPortPrivate::waitForReadOrWrite(bool *selectForRead, bool *selectFor // FIXME: Here the situation is not properly handled with zero timeout: // breaker can work out before you call a method WaitCommEvent() // and so it will loop forever! - WaitCommEventBreaker breaker(descriptor, qMax(msecs, 0)); - ::WaitCommEvent(descriptor, &eventMask, NULL); + WaitCommEventBreaker breaker(handle, qMax(msecs, 0)); + ::WaitCommEvent(handle, &eventMask, NULL); breaker.stop(); if (breaker.isWorked()) { @@ -439,17 +439,17 @@ bool QSerialPortPrivate::updateDcb() DWORD eventMask = 0; // Save the event mask - if (!::GetCommMask(descriptor, &eventMask)) + if (!::GetCommMask(handle, &eventMask)) return false; // Break event notifier from WaitCommEvent - ::SetCommMask(descriptor, 0); + ::SetCommMask(handle, 0); // Change parameters - bool ret = ::SetCommState(descriptor, ¤tDcb); + bool ret = ::SetCommState(handle, ¤tDcb); if (!ret) q->setError(decodeSystemError()); // Restore the event mask - ::SetCommMask(descriptor, eventMask); + ::SetCommMask(handle, eventMask); return ret; } @@ -458,7 +458,7 @@ bool QSerialPortPrivate::updateCommTimeouts() { Q_Q(QSerialPort); - if (!::SetCommTimeouts(descriptor, ¤tCommTimeouts)) { + if (!::SetCommTimeouts(handle, ¤tCommTimeouts)) { q->setError(decodeSystemError()); return false; } diff --git a/src/serialport/qserialportinfo_win.cpp b/src/serialport/qserialportinfo_win.cpp index 9fceb31..e6296a2 100644 --- a/src/serialport/qserialportinfo_win.cpp +++ b/src/serialport/qserialportinfo_win.cpp @@ -308,28 +308,28 @@ QList<qint32> QSerialPortInfo::standardBaudRates() bool QSerialPortInfo::isBusy() const { - const HANDLE descriptor = ::CreateFile(reinterpret_cast<const wchar_t*>(systemLocation().utf16()), + const HANDLE handle = ::CreateFile(reinterpret_cast<const wchar_t*>(systemLocation().utf16()), GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); - if (descriptor == INVALID_HANDLE_VALUE) { + if (handle == INVALID_HANDLE_VALUE) { if (::GetLastError() == ERROR_ACCESS_DENIED) return true; } else { - ::CloseHandle(descriptor); + ::CloseHandle(handle); } return false; } bool QSerialPortInfo::isValid() const { - const HANDLE descriptor = ::CreateFile(reinterpret_cast<const wchar_t*>(systemLocation().utf16()), + const HANDLE handle = ::CreateFile(reinterpret_cast<const wchar_t*>(systemLocation().utf16()), GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); - if (descriptor == INVALID_HANDLE_VALUE) { + if (handle == INVALID_HANDLE_VALUE) { if (::GetLastError() != ERROR_ACCESS_DENIED) return false; } else { - ::CloseHandle(descriptor); + ::CloseHandle(handle); } return true; } |