diff options
author | Frederik Gladhorn <frederik.gladhorn@theqtcompany.com> | 2015-01-20 12:33:16 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2015-01-20 12:33:16 +0100 |
commit | 5d819074af293c0855090ceb23a26fe8401a4255 (patch) | |
tree | 7f273c7438387ff86287aa3c344fae8fed6f56c5 /src/serialport | |
parent | b1005907d26a3e2f5dffaec93d656a0c1210961f (diff) | |
parent | 40d3bc669e7f556ac8d6492ad324827dcf6da6c1 (diff) |
Merge "Merge remote-tracking branch 'origin/5.4' into dev" into refs/staging/dev
Diffstat (limited to 'src/serialport')
-rw-r--r-- | src/serialport/qserialport.cpp | 18 | ||||
-rw-r--r-- | src/serialport/qserialport.h | 2 | ||||
-rw-r--r-- | src/serialport/qserialport_unix.cpp | 37 | ||||
-rw-r--r-- | src/serialport/qserialport_win.cpp | 30 | ||||
-rw-r--r-- | src/serialport/qserialport_wince.cpp | 18 | ||||
-rw-r--r-- | src/serialport/qserialportinfo.cpp | 8 | ||||
-rw-r--r-- | src/serialport/qserialportinfo.h | 1 | ||||
-rw-r--r-- | src/serialport/qserialportinfo_mac.cpp | 68 | ||||
-rw-r--r-- | src/serialport/qserialportinfo_p.h | 12 | ||||
-rw-r--r-- | src/serialport/qserialportinfo_unix.cpp | 74 | ||||
-rw-r--r-- | src/serialport/qserialportinfo_win.cpp | 43 | ||||
-rw-r--r-- | src/serialport/qserialportinfo_wince.cpp | 24 |
12 files changed, 161 insertions, 174 deletions
diff --git a/src/serialport/qserialport.cpp b/src/serialport/qserialport.cpp index f4f7478d..cc3e211b 100644 --- a/src/serialport/qserialport.cpp +++ b/src/serialport/qserialport.cpp @@ -36,6 +36,7 @@ #include "qserialport.h" #include "qserialportinfo.h" +#include "qserialportinfo_p.h" #include "qserialport_p.h" @@ -448,7 +449,7 @@ QSerialPort::~QSerialPort() void QSerialPort::setPortName(const QString &name) { Q_D(QSerialPort); - d->systemLocation = QSerialPortPrivate::portNameToSystemLocation(name); + d->systemLocation = QSerialPortInfoPrivate::portNameToSystemLocation(name); } /*! @@ -459,7 +460,7 @@ void QSerialPort::setPortName(const QString &name) void QSerialPort::setPort(const QSerialPortInfo &serialPortInfo) { Q_D(QSerialPort); - d->systemLocation = QSerialPortPrivate::portNameToSystemLocation(serialPortInfo.systemLocation()); + d->systemLocation = serialPortInfo.systemLocation(); } /*! @@ -473,23 +474,16 @@ void QSerialPort::setPort(const QSerialPortInfo &serialPortInfo) \li Brief Description \row \li Windows - \li Removes the prefix "\\\\.\\" from the system location + \li Removes the prefix "\\\\.\\" or "//./" from the system location and returns the remainder of the string. \row \li Windows CE \li Removes the suffix ":" from the system location and returns the remainder of the string. \row - \li GNU/Linux + \li Unix, BSD \li Removes the prefix "/dev/" from the system location and returns the remainder of the string. - \row - \li Mac OSX - \li Removes the prefix "/dev/cu." and "/dev/tty." from the - system location and returns the remainder of the string. - \row - \li Other *nix - \li The same as for GNU/Linux. \endtable \sa setPort(), QSerialPortInfo::portName() @@ -497,7 +491,7 @@ void QSerialPort::setPort(const QSerialPortInfo &serialPortInfo) QString QSerialPort::portName() const { Q_D(const QSerialPort); - return QSerialPortPrivate::portNameFromSystemLocation(d->systemLocation); + return QSerialPortInfoPrivate::portNameFromSystemLocation(d->systemLocation); } /*! diff --git a/src/serialport/qserialport.h b/src/serialport/qserialport.h index ebd748aa..45f2054d 100644 --- a/src/serialport/qserialport.h +++ b/src/serialport/qserialport.h @@ -279,7 +279,7 @@ private: Q_DISABLE_COPY(QSerialPort) -#if defined (Q_OS_WIN32) || defined(Q_OS_WIN64) +#if defined (Q_OS_WIN32) Q_PRIVATE_SLOT(d_func(), bool _q_startAsyncWrite()) Q_PRIVATE_SLOT(d_func(), void _q_notified(quint32, quint32, OVERLAPPED*)) #endif diff --git a/src/serialport/qserialport_unix.cpp b/src/serialport/qserialport_unix.cpp index 46c9d8bf..e9f69bf8 100644 --- a/src/serialport/qserialport_unix.cpp +++ b/src/serialport/qserialport_unix.cpp @@ -34,6 +34,7 @@ ****************************************************************************/ #include "qserialport_p.h" +#include "qserialportinfo_p.h" #include <errno.h> #include <sys/time.h> @@ -148,7 +149,7 @@ bool QSerialPortPrivate::open(QIODevice::OpenMode mode) { Q_Q(QSerialPort); - QString lockFilePath = serialPortLockFilePath(portNameFromSystemLocation(systemLocation)); + QString lockFilePath = serialPortLockFilePath(QSerialPortInfoPrivate::portNameFromSystemLocation(systemLocation)); bool isLockFileEmpty = lockFilePath.isEmpty(); if (isLockFileEmpty) { qWarning("Failed to create a lock file for opening the device"); @@ -367,7 +368,6 @@ bool QSerialPortPrivate::waitForReadyRead(int msecs) Q_Q(QSerialPort); QElapsedTimer stopWatch; - stopWatch.start(); do { @@ -398,7 +398,6 @@ bool QSerialPortPrivate::waitForBytesWritten(int msecs) return false; QElapsedTimer stopWatch; - stopWatch.start(); forever { @@ -1145,38 +1144,6 @@ qint64 QSerialPortPrivate::readPerChar(char *data, qint64 maxSize) return ret; } -#ifdef Q_OS_MAC -static const QString defaultFilePathPrefix = QStringLiteral("/dev/cu."); -static const QString unusedFilePathPrefix = QStringLiteral("/dev/tty."); -#else -static const QString defaultFilePathPrefix = QStringLiteral("/dev/"); -#endif - -QString QSerialPortPrivate::portNameToSystemLocation(const QString &port) -{ - QString ret = port; - -#ifdef Q_OS_MAC - ret.remove(unusedFilePathPrefix); -#endif - - if (!ret.contains(defaultFilePathPrefix)) - ret.prepend(defaultFilePathPrefix); - return ret; -} - -QString QSerialPortPrivate::portNameFromSystemLocation(const QString &location) -{ - QString ret = location; - -#ifdef Q_OS_MAC - ret.remove(unusedFilePathPrefix); -#endif - - ret.remove(defaultFilePathPrefix); - return ret; -} - typedef QMap<qint32, qint32> BaudRateMap; // The OS specific defines can be found in termios.h diff --git a/src/serialport/qserialport_win.cpp b/src/serialport/qserialport_win.cpp index e92dce21..db3ef694 100644 --- a/src/serialport/qserialport_win.cpp +++ b/src/serialport/qserialport_win.cpp @@ -273,15 +273,15 @@ qint64 QSerialPortPrivate::readData(char *data, qint64 maxSize) bool QSerialPortPrivate::waitForReadyRead(int msecs) { - QElapsedTimer stopWatch; - stopWatch.start(); - if (!writeStarted && !_q_startAsyncWrite()) return false; const qint64 initialReadBufferSize = buffer.size(); qint64 currentReadBufferSize = initialReadBufferSize; + QElapsedTimer stopWatch; + stopWatch.start(); + do { OVERLAPPED *overlapped = waitForNotified(timeoutValue(msecs, stopWatch.elapsed())); if (!overlapped) @@ -321,12 +321,12 @@ bool QSerialPortPrivate::waitForBytesWritten(int msecs) if (writeBuffer.isEmpty()) return false; - QElapsedTimer stopWatch; - stopWatch.start(); - if (!writeStarted && !_q_startAsyncWrite()) return false; + QElapsedTimer stopWatch; + stopWatch.start(); + forever { OVERLAPPED *overlapped = waitForNotified(timeoutValue(msecs, stopWatch.elapsed())); if (!overlapped) @@ -843,24 +843,6 @@ QSerialPort::SerialPortError QSerialPortPrivate::decodeSystemError(int systemErr return error; } -static const QString defaultPathPrefix = QStringLiteral("\\\\.\\"); - -QString QSerialPortPrivate::portNameToSystemLocation(const QString &port) -{ - QString ret = port; - if (!ret.contains(defaultPathPrefix)) - ret.prepend(defaultPathPrefix); - return ret; -} - -QString QSerialPortPrivate::portNameFromSystemLocation(const QString &location) -{ - QString ret = location; - if (ret.contains(defaultPathPrefix)) - ret.remove(defaultPathPrefix); - return ret; -} - // This table contains standard values of baud rates that // are defined in MSDN and/or in Win SDK file winbase.h diff --git a/src/serialport/qserialport_wince.cpp b/src/serialport/qserialport_wince.cpp index 9258e7e1..f8a63f24 100644 --- a/src/serialport/qserialport_wince.cpp +++ b/src/serialport/qserialport_wince.cpp @@ -340,7 +340,6 @@ bool QSerialPortPrivate::waitForReadyRead(int msec) return true; QElapsedTimer stopWatch; - stopWatch.start(); forever { @@ -369,7 +368,6 @@ bool QSerialPortPrivate::waitForBytesWritten(int msec) return false; QElapsedTimer stopWatch; - stopWatch.start(); forever { @@ -762,22 +760,6 @@ bool QSerialPortPrivate::waitForReadOrWrite(bool *selectForRead, bool *selectFor return false; } -QString QSerialPortPrivate::portNameToSystemLocation(const QString &port) -{ - QString ret = port; - if (!ret.contains(QLatin1Char(':'))) - ret.append(QLatin1Char(':')); - return ret; -} - -QString QSerialPortPrivate::portNameFromSystemLocation(const QString &location) -{ - QString ret = location; - if (ret.contains(QLatin1Char(':'))) - ret.remove(QLatin1Char(':')); - return ret; -} - static const QList<qint32> standardBaudRatePairList() { diff --git a/src/serialport/qserialportinfo.cpp b/src/serialport/qserialportinfo.cpp index 23a4d1c7..ced43619 100644 --- a/src/serialport/qserialportinfo.cpp +++ b/src/serialport/qserialportinfo.cpp @@ -65,7 +65,6 @@ QT_BEGIN_NAMESPACE \sa isNull() */ QSerialPortInfo::QSerialPortInfo() - : d_ptr(new QSerialPortInfoPrivate) { } @@ -81,7 +80,6 @@ QSerialPortInfo::QSerialPortInfo(const QSerialPortInfo &other) Constructs a QSerialPortInfo object from serial \a port. */ QSerialPortInfo::QSerialPortInfo(const QSerialPort &port) - : d_ptr(new QSerialPortInfoPrivate) { foreach (const QSerialPortInfo &serialPortInfo, availablePorts()) { if (port.portName() == serialPortInfo.portName()) { @@ -99,7 +97,6 @@ QSerialPortInfo::QSerialPortInfo(const QSerialPort &port) instance for that port. */ QSerialPortInfo::QSerialPortInfo(const QString &name) - : d_ptr(new QSerialPortInfoPrivate) { foreach (const QSerialPortInfo &serialPortInfo, availablePorts()) { if (name == serialPortInfo.portName()) { @@ -109,6 +106,11 @@ QSerialPortInfo::QSerialPortInfo(const QString &name) } } +QSerialPortInfo::QSerialPortInfo(const QSerialPortInfoPrivate &dd) + : d_ptr(new QSerialPortInfoPrivate(dd)) +{ +} + /*! Destroys the QSerialPortInfo object. References to the values in the object become invalid. diff --git a/src/serialport/qserialportinfo.h b/src/serialport/qserialportinfo.h index 262e54dd..0c7a0f1e 100644 --- a/src/serialport/qserialportinfo.h +++ b/src/serialport/qserialportinfo.h @@ -81,6 +81,7 @@ public: static QList<QSerialPortInfo> availablePorts(); private: + QSerialPortInfo(const QSerialPortInfoPrivate &dd); friend QList<QSerialPortInfo> availablePortsByUdev(); friend QList<QSerialPortInfo> availablePortsBySysfs(); friend QList<QSerialPortInfo> availablePortsByFiltersOfDevices(); diff --git a/src/serialport/qserialportinfo_mac.cpp b/src/serialport/qserialportinfo_mac.cpp index 8b1536fb..28d69347 100644 --- a/src/serialport/qserialportinfo_mac.cpp +++ b/src/serialport/qserialportinfo_mac.cpp @@ -78,15 +78,15 @@ static quint16 searchShortIntProperty(io_registry_entry_t ioRegistryEntry, return value; } -static bool isCompleteInfo(const QSerialPortInfo &portInfo) +static bool isCompleteInfo(const QSerialPortInfoPrivate &priv) { - return !portInfo.portName().isEmpty() - && !portInfo.systemLocation().isEmpty() - && !portInfo.manufacturer().isEmpty() - && !portInfo.description().isEmpty() - && !portInfo.serialNumber().isEmpty() - && portInfo.hasProductIdentifier() - && portInfo.hasVendorIdentifier(); + return !priv.portName.isEmpty() + && !priv.device.isEmpty() + && !priv.manufacturer.isEmpty() + && !priv.description.isEmpty() + && !priv.serialNumber.isEmpty() + && priv.hasProductIdentifier + && priv.hasVendorIdentifier; } static QString devicePortName(io_registry_entry_t ioRegistryEntry) @@ -160,37 +160,37 @@ QList<QSerialPortInfo> QSerialPortInfo::availablePorts() if (!serialPortService) break; - QSerialPortInfo serialPortInfo; + QSerialPortInfoPrivate priv; forever { - if (serialPortInfo.portName().isEmpty()) - serialPortInfo.d_ptr->portName = devicePortName(serialPortService); + if (priv.portName.isEmpty()) + priv.portName = devicePortName(serialPortService); - if (serialPortInfo.systemLocation().isEmpty()) - serialPortInfo.d_ptr->device = deviceSystemLocation(serialPortService); + if (priv.device.isEmpty()) + priv.device = deviceSystemLocation(serialPortService); - if (serialPortInfo.description().isEmpty()) - serialPortInfo.d_ptr->description = deviceDescription(serialPortService); + if (priv.description.isEmpty()) + priv.description = deviceDescription(serialPortService); - if (serialPortInfo.manufacturer().isEmpty()) - serialPortInfo.d_ptr->manufacturer = deviceManufacturer(serialPortService); + if (priv.manufacturer.isEmpty()) + priv.manufacturer = deviceManufacturer(serialPortService); - if (serialPortInfo.serialNumber().isEmpty()) - serialPortInfo.d_ptr->serialNumber = deviceSerialNumber(serialPortService); + if (priv.serialNumber.isEmpty()) + priv.serialNumber = deviceSerialNumber(serialPortService); - if (!serialPortInfo.hasVendorIdentifier()) { - serialPortInfo.d_ptr->vendorIdentifier = + if (!priv.hasVendorIdentifier) { + priv.vendorIdentifier = deviceVendorIdentifier(serialPortService, - serialPortInfo.d_ptr->hasVendorIdentifier); + priv.hasVendorIdentifier); } - if (!serialPortInfo.hasProductIdentifier()) { - serialPortInfo.d_ptr->productIdentifier = + if (!priv.hasProductIdentifier) { + priv.productIdentifier = deviceProductIdentifier(serialPortService, - serialPortInfo.d_ptr->hasProductIdentifier); + priv.hasProductIdentifier); } - if (isCompleteInfo(serialPortInfo)) { + if (isCompleteInfo(priv)) { ::IOObjectRelease(serialPortService); break; } @@ -200,7 +200,7 @@ QList<QSerialPortInfo> QSerialPortInfo::availablePorts() break; } - serialPortInfoList.append(serialPortInfo); + serialPortInfoList.append(priv); } ::IOObjectRelease(serialPortIterator); @@ -242,4 +242,18 @@ bool QSerialPortInfo::isValid() const return f.exists(); } +QString QSerialPortInfoPrivate::portNameToSystemLocation(const QString &source) +{ + return (source.startsWith(QLatin1Char('/')) + || source.startsWith(QStringLiteral("./")) + || source.startsWith(QStringLiteral("../"))) + ? source : (QStringLiteral("/dev/") + source); +} + +QString QSerialPortInfoPrivate::portNameFromSystemLocation(const QString &source) +{ + return source.startsWith(QStringLiteral("/dev/")) + ? source.mid(5) : source; +} + QT_END_NAMESPACE diff --git a/src/serialport/qserialportinfo_p.h b/src/serialport/qserialportinfo_p.h index 6ab41170..c9f10863 100644 --- a/src/serialport/qserialportinfo_p.h +++ b/src/serialport/qserialportinfo_p.h @@ -51,7 +51,7 @@ QT_BEGIN_NAMESPACE -class QSerialPortInfoPrivate +class Q_AUTOTEST_EXPORT QSerialPortInfoPrivate { public: QSerialPortInfoPrivate() @@ -59,9 +59,15 @@ public: , productIdentifier(0) , hasVendorIdentifier(false) , hasProductIdentifier(false) - {} + { + } + + ~QSerialPortInfoPrivate() + { + } - ~QSerialPortInfoPrivate() {} + static QString portNameToSystemLocation(const QString &source); + static QString portNameFromSystemLocation(const QString &source); QString portName; QString device; diff --git a/src/serialport/qserialportinfo_unix.cpp b/src/serialport/qserialportinfo_unix.cpp index a7a11868..4395d9bc 100644 --- a/src/serialport/qserialportinfo_unix.cpp +++ b/src/serialport/qserialportinfo_unix.cpp @@ -98,10 +98,10 @@ QList<QSerialPortInfo> availablePortsByFiltersOfDevices() QList<QSerialPortInfo> serialPortInfoList; foreach (const QString &deviceFilePath, filteredDeviceFilePaths()) { - QSerialPortInfo serialPortInfo; - serialPortInfo.d_ptr->device = deviceFilePath; - serialPortInfo.d_ptr->portName = QSerialPortPrivate::portNameFromSystemLocation(deviceFilePath); - serialPortInfoList.append(serialPortInfo); + QSerialPortInfoPrivate priv; + priv.device = deviceFilePath; + priv.portName = QSerialPortInfoPrivate::portNameFromSystemLocation(deviceFilePath); + serialPortInfoList.append(priv); } return serialPortInfoList; @@ -125,7 +125,7 @@ QList<QSerialPortInfo> availablePortsBySysfs() if (lastIndexOfSlash == -1) continue; - QSerialPortInfo serialPortInfo; + QSerialPortInfoPrivate priv; if (targetPath.contains(QStringLiteral("pnp"))) { // TODO: Obtain more information #ifndef Q_OS_ANDROID @@ -155,26 +155,26 @@ QList<QSerialPortInfo> availablePortsBySysfs() QFile description(QFileInfo(targetDir, QStringLiteral("product")).absoluteFilePath()); if (description.open(QIODevice::ReadOnly | QIODevice::Text)) - serialPortInfo.d_ptr->description = QString::fromLatin1(description.readAll()).simplified(); + priv.description = QString::fromLatin1(description.readAll()).simplified(); QFile manufacturer(QFileInfo(targetDir, QStringLiteral("manufacturer")).absoluteFilePath()); if (manufacturer.open(QIODevice::ReadOnly | QIODevice::Text)) - serialPortInfo.d_ptr->manufacturer = QString::fromLatin1(manufacturer.readAll()).simplified(); + priv.manufacturer = QString::fromLatin1(manufacturer.readAll()).simplified(); QFile serialNumber(QFileInfo(targetDir, QStringLiteral("serial")).absoluteFilePath()); if (serialNumber.open(QIODevice::ReadOnly | QIODevice::Text)) - serialPortInfo.d_ptr->serialNumber = QString::fromLatin1(serialNumber.readAll()).simplified(); + priv.serialNumber = QString::fromLatin1(serialNumber.readAll()).simplified(); QFile vendorIdentifier(QFileInfo(targetDir, QStringLiteral("idVendor")).absoluteFilePath()); if (vendorIdentifier.open(QIODevice::ReadOnly | QIODevice::Text)) { - serialPortInfo.d_ptr->vendorIdentifier = QString::fromLatin1(vendorIdentifier.readAll()) - .toInt(&serialPortInfo.d_ptr->hasVendorIdentifier, 16); + priv.vendorIdentifier = QString::fromLatin1(vendorIdentifier.readAll()) + .toInt(&priv.hasVendorIdentifier, 16); } QFile productIdentifier(QFileInfo(targetDir, QStringLiteral("idProduct")).absoluteFilePath()); if (productIdentifier.open(QIODevice::ReadOnly | QIODevice::Text)) { - serialPortInfo.d_ptr->productIdentifier = QString::fromLatin1(productIdentifier.readAll()) - .toInt(&serialPortInfo.d_ptr->hasProductIdentifier, 16); + priv.productIdentifier = QString::fromLatin1(productIdentifier.readAll()) + .toInt(&priv.hasProductIdentifier, 16); } break; @@ -185,13 +185,13 @@ QList<QSerialPortInfo> availablePortsBySysfs() QDir targetDir(targetPath + QStringLiteral("/device")); QFile vendorIdentifier(QFileInfo(targetDir, QStringLiteral("vendor")).absoluteFilePath()); if (vendorIdentifier.open(QIODevice::ReadOnly | QIODevice::Text)) { - serialPortInfo.d_ptr->vendorIdentifier = QString::fromLatin1(vendorIdentifier.readAll()) - .toInt(&serialPortInfo.d_ptr->hasVendorIdentifier, 16); + priv.vendorIdentifier = QString::fromLatin1(vendorIdentifier.readAll()) + .toInt(&priv.hasVendorIdentifier, 16); } QFile productIdentifier(QFileInfo(targetDir, QStringLiteral("device")).absoluteFilePath()); if (productIdentifier.open(QIODevice::ReadOnly | QIODevice::Text)) { - serialPortInfo.d_ptr->productIdentifier = QString::fromLatin1(productIdentifier.readAll()) - .toInt(&serialPortInfo.d_ptr->hasProductIdentifier, 16); + priv.productIdentifier = QString::fromLatin1(productIdentifier.readAll()) + .toInt(&priv.hasProductIdentifier, 16); } // TODO: Obtain more information about the device } else if (targetPath.contains(QStringLiteral(".serial/tty/tty"))) { @@ -201,9 +201,9 @@ QList<QSerialPortInfo> availablePortsBySysfs() continue; } - serialPortInfo.d_ptr->portName = targetPath.mid(lastIndexOfSlash + 1); - serialPortInfo.d_ptr->device = QSerialPortPrivate::portNameToSystemLocation(serialPortInfo.d_ptr->portName); - serialPortInfoList.append(serialPortInfo); + priv.portName = targetPath.mid(lastIndexOfSlash + 1); + priv.device = QSerialPortInfoPrivate::portNameToSystemLocation(priv.portName); + serialPortInfoList.append(priv); } return serialPortInfoList; @@ -318,25 +318,25 @@ QList<QSerialPortInfo> availablePortsByUdev() if (!dev) return serialPortInfoList; - QSerialPortInfo serialPortInfo; + QSerialPortInfoPrivate priv; - serialPortInfo.d_ptr->device = QString::fromLatin1(::udev_device_get_devnode(dev.data())); - serialPortInfo.d_ptr->portName = QString::fromLatin1(::udev_device_get_sysname(dev.data())); + priv.device = QString::fromLatin1(::udev_device_get_devnode(dev.data())); + priv.portName = QString::fromLatin1(::udev_device_get_sysname(dev.data())); udev_device *parentdev = ::udev_device_get_parent(dev.data()); if (parentdev) { if (checkUdevForSerial8250Driver(parentdev)) continue; - serialPortInfo.d_ptr->description = getUdevModelName(dev.data()); - serialPortInfo.d_ptr->manufacturer = getUdevVendorName(dev.data()); - serialPortInfo.d_ptr->serialNumber = getUdevSerialNumber(dev.data()); - serialPortInfo.d_ptr->vendorIdentifier = getUdevVendorIdentifier(dev.data(), serialPortInfo.d_ptr->hasVendorIdentifier); - serialPortInfo.d_ptr->productIdentifier = getUdevModelIdentifier(dev.data(), serialPortInfo.d_ptr->hasProductIdentifier); + priv.description = getUdevModelName(dev.data()); + priv.manufacturer = getUdevVendorName(dev.data()); + priv.serialNumber = getUdevSerialNumber(dev.data()); + priv.vendorIdentifier = getUdevVendorIdentifier(dev.data(), priv.hasVendorIdentifier); + priv.productIdentifier = getUdevModelIdentifier(dev.data(), priv.hasProductIdentifier); } else { - if (serialPortInfo.d_ptr->portName.startsWith(rfcommDeviceName)) { + if (priv.portName.startsWith(rfcommDeviceName)) { bool ok; - int portNumber = serialPortInfo.d_ptr->portName.mid(rfcommDeviceName.length()).toInt(&ok); + int portNumber = priv.portName.mid(rfcommDeviceName.length()).toInt(&ok); if (!ok || (portNumber < 0) || (portNumber > 255)) continue; } else { @@ -344,7 +344,7 @@ QList<QSerialPortInfo> availablePortsByUdev() } } - serialPortInfoList.append(serialPortInfo); + serialPortInfoList.append(priv); } return serialPortInfoList; @@ -401,4 +401,18 @@ bool QSerialPortInfo::isValid() const return f.exists(); } +QString QSerialPortInfoPrivate::portNameToSystemLocation(const QString &source) +{ + return (source.startsWith(QLatin1Char('/')) + || source.startsWith(QStringLiteral("./")) + || source.startsWith(QStringLiteral("../"))) + ? source : (QStringLiteral("/dev/") + source); +} + +QString QSerialPortInfoPrivate::portNameFromSystemLocation(const QString &source) +{ + return source.startsWith(QStringLiteral("/dev/")) + ? source.mid(5) : source; +} + QT_END_NAMESPACE diff --git a/src/serialport/qserialportinfo_win.cpp b/src/serialport/qserialportinfo_win.cpp index 4b30a09c..a94a5ff9 100644 --- a/src/serialport/qserialportinfo_win.cpp +++ b/src/serialport/qserialportinfo_win.cpp @@ -312,23 +312,23 @@ QList<QSerialPortInfo> QSerialPortInfo::availablePorts() continue; } - QSerialPortInfo serialPortInfo; + QSerialPortInfoPrivate priv; - serialPortInfo.d_ptr->portName = portName; - serialPortInfo.d_ptr->device = QSerialPortPrivate::portNameToSystemLocation(portName); - serialPortInfo.d_ptr->description = deviceDescription(deviceInfoSet, &deviceInfoData); - serialPortInfo.d_ptr->manufacturer = deviceManufacturer(deviceInfoSet, &deviceInfoData); + priv.portName = portName; + priv.device = QSerialPortInfoPrivate::portNameToSystemLocation(portName); + priv.description = deviceDescription(deviceInfoSet, &deviceInfoData); + priv.manufacturer = deviceManufacturer(deviceInfoSet, &deviceInfoData); const QString instanceIdentifier = deviceInstanceIdentifier(deviceInfoData.DevInst); - serialPortInfo.d_ptr->serialNumber = + priv.serialNumber = deviceSerialNumber(instanceIdentifier, deviceInfoData.DevInst); - serialPortInfo.d_ptr->vendorIdentifier = - deviceVendorIdentifier(instanceIdentifier, serialPortInfo.d_ptr->hasVendorIdentifier); - serialPortInfo.d_ptr->productIdentifier = - deviceProductIdentifier(instanceIdentifier, serialPortInfo.d_ptr->hasProductIdentifier); + priv.vendorIdentifier = + deviceVendorIdentifier(instanceIdentifier, priv.hasVendorIdentifier); + priv.productIdentifier = + deviceProductIdentifier(instanceIdentifier, priv.hasProductIdentifier); - serialPortInfoList.append(serialPortInfo); + serialPortInfoList.append(priv); } ::SetupDiDestroyDeviceInfoList(deviceInfoSet); } @@ -336,10 +336,10 @@ QList<QSerialPortInfo> QSerialPortInfo::availablePorts() foreach (const QString &portName, portNamesFromHardwareDeviceMap()) { if (std::find_if(serialPortInfoList.begin(), serialPortInfoList.end(), SerialPortNameEqualFunctor(portName)) == serialPortInfoList.end()) { - QSerialPortInfo serialPortInfo; - serialPortInfo.d_ptr->portName = portName; - serialPortInfo.d_ptr->device = QSerialPortPrivate::portNameToSystemLocation(portName); - serialPortInfoList.append(serialPortInfo); + QSerialPortInfoPrivate priv; + priv.portName = portName; + priv.device = QSerialPortInfoPrivate::portNameToSystemLocation(portName); + serialPortInfoList.append(priv); } } @@ -379,4 +379,17 @@ bool QSerialPortInfo::isValid() const return true; } +QString QSerialPortInfoPrivate::portNameToSystemLocation(const QString &source) +{ + return source.startsWith(QStringLiteral("COM")) + ? (QStringLiteral("\\\\.\\") + source) : source; +} + +QString QSerialPortInfoPrivate::portNameFromSystemLocation(const QString &source) +{ + return (source.startsWith(QStringLiteral("\\\\.\\")) + || source.startsWith(QStringLiteral("//./"))) + ? source.mid(4) : source; +} + QT_END_NAMESPACE diff --git a/src/serialport/qserialportinfo_wince.cpp b/src/serialport/qserialportinfo_wince.cpp index 4cb8b921..42c3977f 100644 --- a/src/serialport/qserialportinfo_wince.cpp +++ b/src/serialport/qserialportinfo_wince.cpp @@ -105,13 +105,13 @@ QList<QSerialPortInfo> QSerialPortInfo::availablePorts() &di); if (hSearch != INVALID_HANDLE_VALUE) { do { - QSerialPortInfo serialPortInfo; - serialPortInfo.d_ptr->device = QString::fromWCharArray(di.szLegacyName); - serialPortInfo.d_ptr->portName = QSerialPortPrivate::portNameFromSystemLocation(serialPortInfo.d_ptr->device); - serialPortInfo.d_ptr->description = findDescription(HKEY_LOCAL_MACHINE, - QString::fromWCharArray(di.szDeviceKey)); + 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(serialPortInfo); + serialPortInfoList.append(priv); } while (::FindNextDevice(hSearch, &di)); ::FindClose(hSearch); @@ -153,4 +153,16 @@ bool QSerialPortInfo::isValid() const return true; } +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 |