diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/serialport/qserialport.cpp | 18 | ||||
-rw-r--r-- | src/serialport/qserialport_unix.cpp | 35 | ||||
-rw-r--r-- | src/serialport/qserialport_unix_p.h | 3 | ||||
-rw-r--r-- | src/serialport/qserialport_win.cpp | 18 | ||||
-rw-r--r-- | src/serialport/qserialport_win_p.h | 3 | ||||
-rw-r--r-- | src/serialport/qserialport_wince.cpp | 16 | ||||
-rw-r--r-- | src/serialport/qserialport_wince_p.h | 3 | ||||
-rw-r--r-- | src/serialport/qserialportinfo_mac.cpp | 14 | ||||
-rw-r--r-- | src/serialport/qserialportinfo_p.h | 12 | ||||
-rw-r--r-- | src/serialport/qserialportinfo_unix.cpp | 18 | ||||
-rw-r--r-- | src/serialport/qserialportinfo_win.cpp | 23 | ||||
-rw-r--r-- | src/serialport/qserialportinfo_wince.cpp | 14 |
12 files changed, 78 insertions, 99 deletions
diff --git a/src/serialport/qserialport.cpp b/src/serialport/qserialport.cpp index 82bcde3..2bd7c69 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" #ifdef Q_OS_WINCE #include "qserialport_wince_p.h" @@ -435,7 +436,7 @@ QSerialPort::~QSerialPort() void QSerialPort::setPortName(const QString &name) { Q_D(QSerialPort); - d->systemLocation = QSerialPortPrivate::portNameToSystemLocation(name); + d->systemLocation = QSerialPortInfoPrivate::portNameToSystemLocation(name); } /*! @@ -446,7 +447,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(); } /*! @@ -460,7 +461,7 @@ 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 @@ -471,16 +472,9 @@ void QSerialPort::setPort(const QSerialPortInfo &serialPortInfo) \li Returns the system location as it is, as it is equivalent to the port name. \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() @@ -488,7 +482,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_unix.cpp b/src/serialport/qserialport_unix.cpp index c836eb2..599f151 100644 --- a/src/serialport/qserialport_unix.cpp +++ b/src/serialport/qserialport_unix.cpp @@ -34,6 +34,7 @@ ****************************************************************************/ #include "qserialport_unix_p.h" +#include "qserialportinfo_p.h" #include <errno.h> #include <sys/time.h> @@ -163,7 +164,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"); @@ -1156,38 +1157,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_unix_p.h b/src/serialport/qserialport_unix_p.h index 1cc767d..f1821ea 100644 --- a/src/serialport/qserialport_unix_p.h +++ b/src/serialport/qserialport_unix_p.h @@ -131,9 +131,6 @@ public: qint64 bytesToWrite() const; qint64 writeData(const char *data, qint64 maxSize); - static QString portNameToSystemLocation(const QString &port); - static QString portNameFromSystemLocation(const QString &location); - static qint32 baudRateFromSetting(qint32 setting); static qint32 settingFromBaudRate(qint32 baudRate); diff --git a/src/serialport/qserialport_win.cpp b/src/serialport/qserialport_win.cpp index 5a2cf8e..7b7405e 100644 --- a/src/serialport/qserialport_win.cpp +++ b/src/serialport/qserialport_win.cpp @@ -900,24 +900,6 @@ bool QSerialPortPrivate::waitAnyEvent(int msecs, bool *timedOut, HANDLE *trigger return true; } -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_win_p.h b/src/serialport/qserialport_win_p.h index 78529e8..1e941a0 100644 --- a/src/serialport/qserialport_win_p.h +++ b/src/serialport/qserialport_win_p.h @@ -108,9 +108,6 @@ public: qint64 bytesToWrite() const; qint64 writeData(const char *data, qint64 maxSize); - static QString portNameToSystemLocation(const QString &port); - static QString portNameFromSystemLocation(const QString &location); - static qint32 baudRateFromSetting(qint32 setting); static qint32 settingFromBaudRate(qint32 baudRate); diff --git a/src/serialport/qserialport_wince.cpp b/src/serialport/qserialport_wince.cpp index ee5d395..04c09b1 100644 --- a/src/serialport/qserialport_wince.cpp +++ b/src/serialport/qserialport_wince.cpp @@ -766,22 +766,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/qserialport_wince_p.h b/src/serialport/qserialport_wince_p.h index dedd4b1..3fc4e23 100644 --- a/src/serialport/qserialport_wince_p.h +++ b/src/serialport/qserialport_wince_p.h @@ -99,9 +99,6 @@ public: qint64 bytesToWrite() const; qint64 writeData(const char *data, qint64 maxSize); - static QString portNameToSystemLocation(const QString &port); - static QString portNameFromSystemLocation(const QString &location); - static qint32 baudRateFromSetting(qint32 setting); static qint32 settingFromBaudRate(qint32 baudRate); diff --git a/src/serialport/qserialportinfo_mac.cpp b/src/serialport/qserialportinfo_mac.cpp index 3685d55..54abe21 100644 --- a/src/serialport/qserialportinfo_mac.cpp +++ b/src/serialport/qserialportinfo_mac.cpp @@ -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 6ab4117..c9f1086 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 7322a3c..9637581 100644 --- a/src/serialport/qserialportinfo_unix.cpp +++ b/src/serialport/qserialportinfo_unix.cpp @@ -100,7 +100,7 @@ QList<QSerialPortInfo> availablePortsByFiltersOfDevices() foreach (const QString &deviceFilePath, filteredDeviceFilePaths()) { QSerialPortInfoPrivate priv; priv.device = deviceFilePath; - priv.portName = QSerialPortPrivate::portNameFromSystemLocation(deviceFilePath); + priv.portName = QSerialPortInfoPrivate::portNameFromSystemLocation(deviceFilePath); serialPortInfoList.append(priv); } @@ -202,7 +202,7 @@ QList<QSerialPortInfo> availablePortsBySysfs() } priv.portName = targetPath.mid(lastIndexOfSlash + 1); - priv.device = QSerialPortPrivate::portNameToSystemLocation(priv.portName); + priv.device = QSerialPortInfoPrivate::portNameToSystemLocation(priv.portName); serialPortInfoList.append(priv); } @@ -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 d4dff94..e595964 100644 --- a/src/serialport/qserialportinfo_win.cpp +++ b/src/serialport/qserialportinfo_win.cpp @@ -315,7 +315,7 @@ QList<QSerialPortInfo> QSerialPortInfo::availablePorts() QSerialPortInfoPrivate priv; priv.portName = portName; - priv.device = QSerialPortPrivate::portNameToSystemLocation(portName); + priv.device = QSerialPortInfoPrivate::portNameToSystemLocation(portName); priv.description = deviceDescription(deviceInfoSet, &deviceInfoData); priv.manufacturer = deviceManufacturer(deviceInfoSet, &deviceInfoData); @@ -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 f39b5a2..5a7ce62 100644 --- a/src/serialport/qserialportinfo_wince.cpp +++ b/src/serialport/qserialportinfo_wince.cpp @@ -107,7 +107,7 @@ QList<QSerialPortInfo> QSerialPortInfo::availablePorts() do { QSerialPortInfoPrivate priv; priv.device = QString::fromWCharArray(di.szLegacyName); - priv.portName = QSerialPortPrivate::portNameFromSystemLocation(priv.device); + priv.portName = QSerialPortInfoPrivate::portNameFromSystemLocation(priv.device); priv.description = findDescription(HKEY_LOCAL_MACHINE, QString::fromWCharArray(di.szDeviceKey)); @@ -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 |