From a11fa1dfd529948da961d3d292926a15f9b7005b Mon Sep 17 00:00:00 2001 From: Denis Shienkov Date: Sat, 30 Apr 2016 14:07:05 +0300 Subject: Drop the Win CE support Now we can drop the WinCE (5/6) support, because its compilers do not support the C++11 features, that lead to the further API limitations and so on. Change-Id: I2431d15b1361f1e093fc09ff7fbe824daeac3984 Reviewed-by: Frank Meerkoetter Reviewed-by: Sergey Belyashov Reviewed-by: Friedemann Kleint --- src/serialport/qserialport.cpp | 5 +- src/serialport/qserialport.h | 2 +- src/serialport/qserialport_p.h | 28 +- src/serialport/qserialport_wince.cpp | 756 ------------------------------- src/serialport/qserialportinfo_wince.cpp | 173 ------- src/serialport/serialport-lib.pri | 6 - 6 files changed, 4 insertions(+), 966 deletions(-) delete mode 100644 src/serialport/qserialport_wince.cpp delete mode 100644 src/serialport/qserialportinfo_wince.cpp (limited to 'src/serialport') diff --git a/src/serialport/qserialport.cpp b/src/serialport/qserialport.cpp index 3d11b31..ba2f5fc 100644 --- a/src/serialport/qserialport.cpp +++ b/src/serialport/qserialport.cpp @@ -100,10 +100,7 @@ QSerialPortPrivate::QSerialPortPrivate() , settingsRestoredOnClose(true) #endif , isBreakEnabled(false) -#if defined(Q_OS_WINCE) - , handle(INVALID_HANDLE_VALUE) - , eventNotifier(0) -#elif defined(Q_OS_WIN32) +#if defined(Q_OS_WIN32) , handle(INVALID_HANDLE_VALUE) , readChunkBuffer(ReadChunkSize, 0) , communicationStarted(false) diff --git a/src/serialport/qserialport.h b/src/serialport/qserialport.h index 530b3fc..4772724 100644 --- a/src/serialport/qserialport.h +++ b/src/serialport/qserialport.h @@ -71,7 +71,7 @@ class Q_SERIALPORT_EXPORT QSerialPort : public QIODevice #endif Q_PROPERTY(bool breakEnabled READ isBreakEnabled WRITE setBreakEnabled NOTIFY breakEnabledChanged) -#if defined(Q_OS_WIN32) || defined(Q_OS_WINCE) +#if defined(Q_OS_WIN32) typedef void* Handle; #else typedef int Handle; diff --git a/src/serialport/qserialport_p.h b/src/serialport/qserialport_p.h index e84066a..ae2089d 100644 --- a/src/serialport/qserialport_p.h +++ b/src/serialport/qserialport_p.h @@ -58,10 +58,7 @@ #include #include -#if defined(Q_OS_WINCE) -# include -# include -#elif defined(Q_OS_WIN32) +#if defined(Q_OS_WIN32) # include #elif defined(Q_OS_UNIX) # include @@ -184,28 +181,7 @@ public: bool settingsRestoredOnClose; bool isBreakEnabled; -#if defined(Q_OS_WINCE) - - bool initialize(DWORD eventMask); - bool updateDcb(); - - bool waitForReadOrWrite(bool *selectForRead, bool *selectForWrite, - bool checkRead, bool checkWrite, - int msecs); - - bool notifyRead(); - bool notifyWrite(); - - DCB currentDcb; - DCB restoredDcb; - COMMTIMEOUTS currentCommTimeouts; - COMMTIMEOUTS restoredCommTimeouts; - HANDLE handle; - - QThread *eventNotifier; - QMutex settingsChangeMutex; - -#elif defined(Q_OS_WIN32) +#if defined(Q_OS_WIN32) bool initialize(); bool setDcb(DCB *dcb); diff --git a/src/serialport/qserialport_wince.cpp b/src/serialport/qserialport_wince.cpp deleted file mode 100644 index 4cfcef3..0000000 --- a/src/serialport/qserialport_wince.cpp +++ /dev/null @@ -1,756 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Denis Shienkov -** Copyright (C) 2012 Laszlo Papp -** Copyright (C) 2012 Andre Hartmann -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtSerialPort module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qserialport_p.h" - -#include -#include -#include -#include - -#ifndef CTL_CODE -# define CTL_CODE(DeviceType, Function, Method, Access) ( \ - ((DeviceType) << 16) | ((Access) << 14) | ((Function) << 2) | (Method) \ - ) -#endif - -#ifndef FILE_DEVICE_SERIAL_PORT -# define FILE_DEVICE_SERIAL_PORT 27 -#endif - -#ifndef METHOD_BUFFERED -# define METHOD_BUFFERED 0 -#endif - -#ifndef FILE_ANY_ACCESS -# define FILE_ANY_ACCESS 0x00000000 -#endif - -#ifndef IOCTL_SERIAL_GET_DTRRTS -# define IOCTL_SERIAL_GET_DTRRTS \ - CTL_CODE(FILE_DEVICE_SERIAL_PORT, 30, METHOD_BUFFERED, FILE_ANY_ACCESS) -#endif - -#ifndef SERIAL_DTR_STATE -# define SERIAL_DTR_STATE 0x00000001 -#endif - -#ifndef SERIAL_RTS_STATE -# define SERIAL_RTS_STATE 0x00000002 -#endif - -QT_BEGIN_NAMESPACE - -class QSerialPortPrivate; - -class CommEventNotifier : public QThread -{ - Q_OBJECT -signals: - void eventMask(quint32 mask); - -public: - CommEventNotifier(DWORD mask, QSerialPortPrivate *d, QObject *parent) - : QThread(parent), dptr(d) { - connect(this, &CommEventNotifier::eventMask, this, &CommEventNotifier::processNotification); - ::SetCommMask(dptr->handle, mask); - } - - virtual ~CommEventNotifier() { - ::SetCommMask(dptr->handle, 0); - } - -protected: - void run() Q_DECL_OVERRIDE { - DWORD mask = 0; - while (true) { - if (::WaitCommEvent(dptr->handle, &mask, FALSE)) { - // Wait until complete the operation changes the port settings, - // see updateDcb(). - dptr->settingsChangeMutex.lock(); - dptr->settingsChangeMutex.unlock(); - emit eventMask(quint32(mask)); - } - } - } - -private slots: - void processNotification(quint32 eventMask) { - - 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 ((eventMask == 0) - || ((eventMask & (EV_ERR | EV_RXCHAR | EV_TXEMPTY)) == 0)) { - error = true; - } - - if (EV_RXCHAR & eventMask) - dptr->notifyRead(); - if (EV_TXEMPTY & eventMask) - dptr->notifyWrite(); - } - -private: - QSerialPortPrivate *dptr; -}; - -class WaitCommEventBreaker : public QThread -{ - Q_OBJECT -public: - WaitCommEventBreaker(HANDLE handle, int timeout, QObject *parent = Q_NULLPTR) - : QThread(parent), handle(handle), timeout(timeout), worked(false) { - start(); - } - - virtual ~WaitCommEventBreaker() { - stop(); - wait(); - } - - void stop() { - exit(0); - } - - bool isWorked() const { - return worked; - } - -protected: - void run() { - QTimer timer; - QObject::connect(&timer, &QTimer::timeout, this, &WaitCommEventBreaker::processTimeout, Qt::DirectConnection); - timer.start(timeout); - exec(); - worked = true; - } - -private slots: - void processTimeout() { - ::SetCommMask(handle, 0); - stop(); - } - -private: - HANDLE handle; - int timeout; - mutable bool worked; -}; - -#include "qserialport_wince.moc" - -bool QSerialPortPrivate::open(QIODevice::OpenMode mode) -{ - DWORD desiredAccess = 0; - DWORD eventMask = 0; - - if (mode & QIODevice::ReadOnly) { - desiredAccess |= GENERIC_READ; - eventMask |= EV_RXCHAR; - } - if (mode & QIODevice::WriteOnly) { - desiredAccess |= GENERIC_WRITE; - eventMask |= EV_TXEMPTY; - } - - handle = ::CreateFile(reinterpret_cast(systemLocation.utf16()), - desiredAccess, 0, Q_NULLPTR, OPEN_EXISTING, 0, Q_NULLPTR); - - if (handle == INVALID_HANDLE_VALUE) { - setError(getSystemError()); - return false; - } - - if (initialize(eventMask)) - return true; - - ::CloseHandle(handle); - return false; -} - -void QSerialPortPrivate::close() -{ - if (eventNotifier) { - eventNotifier->terminate(); - eventNotifier->wait(); - delete eventNotifier; - eventNotifier = Q_NULLPTR; - } - - if (settingsRestoredOnClose) { - ::SetCommState(handle, &restoredDcb); - ::SetCommTimeouts(handle, &restoredCommTimeouts); - } - - ::CloseHandle(handle); - handle = INVALID_HANDLE_VALUE; -} - -QSerialPort::PinoutSignals QSerialPortPrivate::pinoutSignals() -{ - DWORD modemStat = 0; - - if (!::GetCommModemStatus(handle, &modemStat)) { - setError(getSystemError()); - return QSerialPort::NoSignal; - } - - QSerialPort::PinoutSignals ret = QSerialPort::NoSignal; - - if (modemStat & MS_CTS_ON) - ret |= QSerialPort::ClearToSendSignal; - if (modemStat & MS_DSR_ON) - ret |= QSerialPort::DataSetReadySignal; - if (modemStat & MS_RING_ON) - ret |= QSerialPort::RingIndicatorSignal; - if (modemStat & MS_RLSD_ON) - ret |= QSerialPort::DataCarrierDetectSignal; - - DWORD bytesReturned = 0; - if (!::DeviceIoControl(handle, IOCTL_SERIAL_GET_DTRRTS, Q_NULLPTR, 0, - &modemStat, sizeof(modemStat), - &bytesReturned, Q_NULLPTR)) { - setError(getSystemError()); - return ret; - } - - if (modemStat & SERIAL_DTR_STATE) - ret |= QSerialPort::DataTerminalReadySignal; - if (modemStat & SERIAL_RTS_STATE) - ret |= QSerialPort::RequestToSendSignal; - - return ret; -} - -bool QSerialPortPrivate::setDataTerminalReady(bool set) -{ - if (!::EscapeCommFunction(handle, set ? SETDTR : CLRDTR)) { - setError(getSystemError()); - return false; - } - - currentDcb.fDtrControl = set ? DTR_CONTROL_ENABLE : DTR_CONTROL_DISABLE; - return true; -} - -bool QSerialPortPrivate::setRequestToSend(bool set) -{ - if (!::EscapeCommFunction(handle, set ? SETRTS : CLRRTS)) { - setError(getSystemError()); - return false; - } - - return true; -} - -bool QSerialPortPrivate::flush() -{ - return notifyWrite() && ::FlushFileBuffers(handle); -} - -bool QSerialPortPrivate::clear(QSerialPort::Directions directions) -{ - DWORD flags = 0; - if (directions & QSerialPort::Input) - flags |= PURGE_RXABORT | PURGE_RXCLEAR; - if (directions & QSerialPort::Output) - flags |= PURGE_TXABORT | PURGE_TXCLEAR; - return ::PurgeComm(handle, flags); -} - -bool QSerialPortPrivate::sendBreak(int duration) -{ - if (!setBreakEnabled(true)) - return false; - - ::Sleep(duration); - - if (!setBreakEnabled(false)) - return false; - - return true; -} - -bool QSerialPortPrivate::setBreakEnabled(bool set) -{ - if (set ? !::SetCommBreak(handle) : !::ClearCommBreak(handle)) { - setError(getSystemError()); - return false; - } - - return true; -} - -bool QSerialPortPrivate::waitForReadyRead(int msec) -{ - if (!buffer.isEmpty()) - return true; - - QElapsedTimer stopWatch; - stopWatch.start(); - - forever { - bool readyToRead = false; - bool readyToWrite = false; - if (!waitForReadOrWrite(&readyToRead, &readyToWrite, - true, !writeBuffer.isEmpty(), - qt_subtract_from_timeout(msec, stopWatch.elapsed()))) { - return false; - } - if (readyToRead) { - if (notifyRead()) - return true; - } - if (readyToWrite) - notifyWrite(); - } - return false; -} - -bool QSerialPortPrivate::waitForBytesWritten(int msec) -{ - if (writeBuffer.isEmpty()) - return false; - - QElapsedTimer stopWatch; - stopWatch.start(); - - forever { - bool readyToRead = false; - bool readyToWrite = false; - if (!waitForReadOrWrite(&readyToRead, &readyToWrite, - true, !writeBuffer.isEmpty(), - qt_subtract_from_timeout(msec, stopWatch.elapsed()))) { - return false; - } - if (readyToRead) { - if (!notifyRead()) - return false; - } - if (readyToWrite) { - if (notifyWrite()) - return true; - } - } - return false; -} - -bool QSerialPortPrivate::setBaudRate() -{ - return setBaudRate(inputBaudRate, QSerialPort::AllDirections); -} - -bool QSerialPortPrivate::setBaudRate(qint32 baudRate, QSerialPort::Directions directions) -{ - if (directions != QSerialPort::AllDirections) { - setError(QSerialPortErrorInfo(QSerialPort::UnsupportedOperationError, QSerialPort::tr("Custom baud rate direction is unsupported"))); - return false; - } - currentDcb.BaudRate = baudRate; - return updateDcb(); -} - -bool QSerialPortPrivate::setDataBits(QSerialPort::DataBits dataBits) -{ - currentDcb.ByteSize = dataBits; - return updateDcb(); -} - -bool QSerialPortPrivate::setParity(QSerialPort::Parity parity) -{ - currentDcb.fParity = TRUE; - switch (parity) { - case QSerialPort::NoParity: - currentDcb.Parity = NOPARITY; - currentDcb.fParity = FALSE; - break; - case QSerialPort::OddParity: - currentDcb.Parity = ODDPARITY; - break; - case QSerialPort::EvenParity: - currentDcb.Parity = EVENPARITY; - break; - case QSerialPort::MarkParity: - currentDcb.Parity = MARKPARITY; - break; - case QSerialPort::SpaceParity: - currentDcb.Parity = SPACEPARITY; - break; - default: - currentDcb.Parity = NOPARITY; - currentDcb.fParity = FALSE; - break; - } - return updateDcb(); -} - -bool QSerialPortPrivate::setStopBits(QSerialPort::StopBits stopBits) -{ - switch (stopBits) { - case QSerialPort::OneStop: - currentDcb.StopBits = ONESTOPBIT; - break; - case QSerialPort::OneAndHalfStop: - currentDcb.StopBits = ONE5STOPBITS; - break; - case QSerialPort::TwoStop: - currentDcb.StopBits = TWOSTOPBITS; - break; - default: - currentDcb.StopBits = ONESTOPBIT; - break; - } - return updateDcb(); -} - -bool QSerialPortPrivate::setFlowControl(QSerialPort::FlowControl flowControl) -{ - currentDcb.fInX = FALSE; - currentDcb.fOutX = FALSE; - currentDcb.fOutxCtsFlow = FALSE; - currentDcb.fRtsControl = RTS_CONTROL_DISABLE; - switch (flowControl) { - case QSerialPort::NoFlowControl: - break; - case QSerialPort::SoftwareControl: - currentDcb.fInX = TRUE; - currentDcb.fOutX = TRUE; - break; - case QSerialPort::HardwareControl: - currentDcb.fOutxCtsFlow = TRUE; - currentDcb.fRtsControl = RTS_CONTROL_HANDSHAKE; - break; - default: - break; - } - return updateDcb(); -} - -bool QSerialPortPrivate::notifyRead() -{ - Q_Q(QSerialPort); - - DWORD bytesToRead = ReadChunkSize; - - if (readBufferMaxSize && bytesToRead > (readBufferMaxSize - buffer.size())) { - bytesToRead = readBufferMaxSize - buffer.size(); - if (bytesToRead == 0) { - // Buffer is full. User must read data from the buffer - // before we can read more from the port. - return false; - } - } - - char *ptr = buffer.reserve(bytesToRead); - - DWORD readBytes = 0; - BOOL sucessResult = ::ReadFile(handle, ptr, bytesToRead, &readBytes, Q_NULLPTR); - - if (!sucessResult) { - buffer.chop(bytesToRead); - setError(QSerialPortErrorInfo(QSerialPort::ReadError)); - return false; - } - - buffer.chop(bytesToRead - qMax(readBytes, DWORD(0))); - - if (readBytes > 0) - emit q->readyRead(); - - return true; -} - -bool QSerialPortPrivate::notifyWrite() -{ - Q_Q(QSerialPort); - - int nextSize = writeBuffer.nextDataBlockSize(); - - const char *ptr = writeBuffer.readPointer(); - - DWORD bytesWritten = 0; - if (!::WriteFile(handle, ptr, nextSize, &bytesWritten, Q_NULLPTR)) { - setError(QSerialPortErrorInfo(QSerialPort::WriteError)); - return false; - } - - writeBuffer.free(bytesWritten); - - if (bytesWritten > 0) - emit q->bytesWritten(bytesWritten); - - return true; -} - -qint64 QSerialPortPrivate::writeData(const char *data, qint64 maxSize) -{ - ::memcpy(writeBuffer.reserve(maxSize), data, maxSize); - if (!writeBuffer.isEmpty()) - notifyWrite(); - return maxSize; -} - -inline bool QSerialPortPrivate::initialize(DWORD eventMask) -{ - Q_Q(QSerialPort); - - ::ZeroMemory(&restoredDcb, sizeof(restoredDcb)); - restoredDcb.DCBlength = sizeof(restoredDcb); - - if (!::GetCommState(handle, &restoredDcb)) { - setError(getSystemError()); - return false; - } - - currentDcb = restoredDcb; - currentDcb.fBinary = true; - currentDcb.fInX = false; - currentDcb.fOutX = false; - currentDcb.fAbortOnError = false; - currentDcb.fNull = false; - currentDcb.fErrorChar = false; - - if (currentDcb.fDtrControl == DTR_CONTROL_HANDSHAKE) - currentDcb.fDtrControl = DTR_CONTROL_DISABLE; - - if (!updateDcb()) - return false; - - if (!::GetCommTimeouts(handle, &restoredCommTimeouts)) { - setError(getSystemError()); - return false; - } - - ::memset(¤tCommTimeouts, 0, sizeof(currentCommTimeouts)); - currentCommTimeouts.ReadIntervalTimeout = MAXDWORD; - - if (!::SetCommTimeouts(handle, ¤tCommTimeouts)) { - setError(getSystemError()); - return false; - } - - eventNotifier = new CommEventNotifier(eventMask, this, q); - eventNotifier->start(); - - return true; -} - -bool QSerialPortPrivate::updateDcb() -{ - QMutexLocker locker(&settingsChangeMutex); - - DWORD eventMask = 0; - // Save the event mask - if (!::GetCommMask(handle, &eventMask)) - return false; - - // Break event notifier from WaitCommEvent - ::SetCommMask(handle, 0); - // Change parameters - bool ret = ::SetCommState(handle, ¤tDcb); - if (!ret) - setError(getSystemError()); - // Restore the event mask - ::SetCommMask(handle, eventMask); - - return ret; -} - -QSerialPortErrorInfo QSerialPortPrivate::getSystemError(int systemErrorCode) const -{ - if (systemErrorCode == -1) - systemErrorCode = ::GetLastError(); - - QSerialPortErrorInfo error; - error.errorString = qt_error_string(systemErrorCode); - - switch (systemErrorCode) { - case ERROR_IO_PENDING: - error.errorCode = QSerialPort::NoError; - break; - case ERROR_MORE_DATA: - error.errorCode = QSerialPort::NoError; - break; - case ERROR_FILE_NOT_FOUND: - error.errorCode = QSerialPort::DeviceNotFoundError; - break; - case ERROR_PATH_NOT_FOUND: - error.errorCode = QSerialPort::DeviceNotFoundError; - break; - case ERROR_INVALID_NAME: - error.errorCode = QSerialPort::DeviceNotFoundError; - break; - case ERROR_ACCESS_DENIED: - error.errorCode = QSerialPort::PermissionError; - break; - case ERROR_INVALID_HANDLE: - error.errorCode = QSerialPort::ResourceError; - break; - case ERROR_INVALID_PARAMETER: - error.errorCode = QSerialPort::UnsupportedOperationError; - break; - case ERROR_BAD_COMMAND: - error.errorCode = QSerialPort::ResourceError; - break; - case ERROR_DEVICE_REMOVED: - error.errorCode = QSerialPort::ResourceError; - break; - default: - error.errorCode = QSerialPort::UnknownError; - break; - } - return error; -} - -bool QSerialPortPrivate::waitForReadOrWrite(bool *selectForRead, bool *selectForWrite, - bool checkRead, bool checkWrite, - int msecs) -{ - DWORD eventMask = 0; - // 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(handle, qMax(msecs, 0)); - ::WaitCommEvent(handle, &eventMask, Q_NULLPTR); - breaker.stop(); - - if (breaker.isWorked()) { - setError(QSerialPortErrorInfo(QSerialPort::TimeoutError)); - } else { - if (checkRead) { - Q_ASSERT(selectForRead); - *selectForRead = eventMask & EV_RXCHAR; - } - if (checkWrite) { - Q_ASSERT(selectForWrite); - *selectForWrite = eventMask & EV_TXEMPTY; - } - - return true; - } - - return false; -} - -static const QList standardBaudRatePairList() -{ - - static const QList standardBaudRatesTable = QList() - - #ifdef CBR_110 - << CBR_110 - #endif - - #ifdef CBR_300 - << CBR_300 - #endif - - #ifdef CBR_600 - << CBR_600 - #endif - - #ifdef CBR_1200 - << CBR_1200 - #endif - - #ifdef CBR_2400 - << CBR_2400 - #endif - - #ifdef CBR_4800 - << CBR_4800 - #endif - - #ifdef CBR_9600 - << CBR_9600 - #endif - - #ifdef CBR_14400 - << CBR_14400 - #endif - - #ifdef CBR_19200 - << CBR_19200 - #endif - - #ifdef CBR_38400 - << CBR_38400 - #endif - - #ifdef CBR_56000 - << CBR_56000 - #endif - - #ifdef CBR_57600 - << CBR_57600 - #endif - - #ifdef CBR_115200 - << CBR_115200 - #endif - - #ifdef CBR_128000 - << CBR_128000 - #endif - - #ifdef CBR_256000 - << CBR_256000 - #endif - ; - - return standardBaudRatesTable; -}; - -QList QSerialPortPrivate::standardBaudRates() -{ - return standardBaudRatePairList(); -} - -QSerialPort::Handle QSerialPort::handle() const -{ - Q_D(const QSerialPort); - return d->handle; -} - -QT_END_NAMESPACE diff --git a/src/serialport/qserialportinfo_wince.cpp b/src/serialport/qserialportinfo_wince.cpp deleted file mode 100644 index 4abf2c2..0000000 --- a/src/serialport/qserialportinfo_wince.cpp +++ /dev/null @@ -1,173 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011-2012 Denis Shienkov -** Copyright (C) 2011 Sergey Belyashov -** Copyright (C) 2012 Laszlo Papp -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtSerialPort module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qserialportinfo.h" -#include "qserialportinfo_p.h" -#include "qserialport_p.h" - -#include - -QT_BEGIN_NAMESPACE - -static QString findDescription(HKEY parentKeyHandle, const QString &subKey) -{ - const static QString valueName(QStringLiteral("FriendlyName")); - - QString result; - HKEY hSubKey = Q_NULLPTR; - LONG res = ::RegOpenKeyEx(parentKeyHandle, reinterpret_cast(subKey.utf16()), - 0, KEY_QUERY_VALUE | KEY_ENUMERATE_SUB_KEYS, &hSubKey); - - if (res == ERROR_SUCCESS) { - - DWORD dataType = 0; - DWORD dataSize = 0; - res = ::RegQueryValueEx(hSubKey, reinterpret_cast(valueName.utf16()), - Q_NULLPTR, &dataType, Q_NULLPTR, &dataSize); - - if (res == ERROR_SUCCESS) { - QByteArray data(dataSize, 0); - res = ::RegQueryValueEx(hSubKey, reinterpret_cast(valueName.utf16()), - Q_NULLPTR, Q_NULLPTR, - reinterpret_cast(data.data()), - &dataSize); - - if (res == ERROR_SUCCESS) { - switch (dataType) { - case REG_EXPAND_SZ: - case REG_SZ: - if (dataSize) - result = QString::fromWCharArray(reinterpret_cast(data.constData())); - break; - default: - break; - } - } - } else { - DWORD index = 0; - dataSize = 255; // Max. key length (see MSDN). - QByteArray data(dataSize, 0); - while (::RegEnumKeyEx(hSubKey, index++, - reinterpret_cast(data.data()), &dataSize, - Q_NULLPTR, Q_NULLPTR, Q_NULLPTR, Q_NULLPTR) == ERROR_SUCCESS) { - - result = findDescription(hSubKey, - QString::fromUtf16(reinterpret_cast(data.data()), dataSize)); - if (!result.isEmpty()) - break; - } - } - ::RegCloseKey(hSubKey); - } - return result; -} - -QList QSerialPortInfo::availablePorts() -{ - QList serialPortInfoList; - - DEVMGR_DEVICE_INFORMATION di; - di.dwSize = sizeof(di); - const HANDLE hSearch = ::FindFirstDevice(DeviceSearchByLegacyName, - L"COM*", - &di); - if (hSearch != INVALID_HANDLE_VALUE) { - do { - QSerialPortInfoPrivate priv; - priv.device = QString::fromWCharArray(di.szLegacyName); - priv.portName = QSerialPortInfoPrivate::portNameFromSystemLocation(priv.device); - priv.description = findDescription(HKEY_LOCAL_MACHINE, - QString::fromWCharArray(di.szDeviceKey)); - - serialPortInfoList.append(priv); - - } while (::FindNextDevice(hSearch, &di)); - ::FindClose(hSearch); - } - - return serialPortInfoList; -} - -#if QT_DEPRECATED_SINCE(5, 6) -bool QSerialPortInfo::isBusy() const -{ - const HANDLE handle = ::CreateFile(reinterpret_cast(systemLocation().utf16()), - GENERIC_READ | GENERIC_WRITE, 0, Q_NULLPTR, OPEN_EXISTING, 0, Q_NULLPTR); - - if (handle == INVALID_HANDLE_VALUE) { - if (::GetLastError() == ERROR_ACCESS_DENIED) - return true; - } else { - ::CloseHandle(handle); - } - return false; -} -#endif // QT_DEPRECATED_SINCE(5, 6) - -#if QT_DEPRECATED_SINCE(5, 2) -bool QSerialPortInfo::isValid() const -{ - const HANDLE handle = ::CreateFile(reinterpret_cast(systemLocation().utf16()), - GENERIC_READ | GENERIC_WRITE, 0, Q_NULLPTR, OPEN_EXISTING, 0, Q_NULLPTR); - - if (handle == INVALID_HANDLE_VALUE) { - if (::GetLastError() != ERROR_ACCESS_DENIED) - return false; - } else { - ::CloseHandle(handle); - } - return true; -} -#endif // QT_DEPRECATED_SINCE(5, 2) - -QString QSerialPortInfoPrivate::portNameToSystemLocation(const QString &source) -{ - return source.endsWith(QLatin1Char(':')) - ? source : (source + QLatin1Char(':')); -} - -QString QSerialPortInfoPrivate::portNameFromSystemLocation(const QString &source) -{ - return source.endsWith(QLatin1Char(':')) - ? source.mid(0, source.size() - 1) : source; -} - -QT_END_NAMESPACE diff --git a/src/serialport/serialport-lib.pri b/src/serialport/serialport-lib.pri index 7179bea..02dc3e5 100644 --- a/src/serialport/serialport-lib.pri +++ b/src/serialport/serialport-lib.pri @@ -27,12 +27,6 @@ win32:!wince* { LIBS_PRIVATE += -lsetupapi -ladvapi32 } -wince* { - SOURCES += \ - $$PWD/qserialport_wince.cpp \ - $$PWD/qserialportinfo_wince.cpp -} - unix { SOURCES += \ $$PWD/qserialport_unix.cpp -- cgit v1.2.1