diff options
Diffstat (limited to 'src/serialport')
-rw-r--r-- | src/serialport/qserialportinfo.cpp | 20 | ||||
-rw-r--r-- | src/serialport/qserialportinfo.h | 4 | ||||
-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 | 6 | ||||
-rw-r--r-- | src/serialport/qserialportinfo_win.cpp | 6 |
6 files changed, 49 insertions, 13 deletions
diff --git a/src/serialport/qserialportinfo.cpp b/src/serialport/qserialportinfo.cpp index e16e13e..b78c9eb 100644 --- a/src/serialport/qserialportinfo.cpp +++ b/src/serialport/qserialportinfo.cpp @@ -204,6 +204,26 @@ quint16 QSerialPortInfo::productIdentifier() const } /*! + Returns true if there is a valid 16-bit vendor number present; otherwise + returns false. +*/ +bool QSerialPortInfo::hasVendorIdentifier() const +{ + Q_D(const QSerialPortInfo); + return !d ? false : d->hasVendorIdentifier; +} + +/*! + Returns true if there is a valid 16-bit product number present; otherwise + returns false. +*/ +bool QSerialPortInfo::hasProductIdentifier() const +{ + Q_D(const QSerialPortInfo); + return !d ? false : d->hasProductIdentifier; +} + +/*! \fn bool QSerialPortInfo::isNull() const Returns whether this QSerialPortInfo object holds a diff --git a/src/serialport/qserialportinfo.h b/src/serialport/qserialportinfo.h index 19fd5b7..900b91b 100644 --- a/src/serialport/qserialportinfo.h +++ b/src/serialport/qserialportinfo.h @@ -71,9 +71,13 @@ public: QString systemLocation() const; QString description() const; QString manufacturer() const; + quint16 vendorIdentifier() const; quint16 productIdentifier() const; + bool hasVendorIdentifier() const; + bool hasProductIdentifier() const; + bool isNull() const; bool isBusy() const; bool isValid() const; diff --git a/src/serialport/qserialportinfo_mac.cpp b/src/serialport/qserialportinfo_mac.cpp index 59cfad9..44f26b5 100644 --- a/src/serialport/qserialportinfo_mac.cpp +++ b/src/serialport/qserialportinfo_mac.cpp @@ -235,20 +235,18 @@ QList<QSerialPortInfo> QSerialPortInfo::availablePorts() quint16 value = 0; if (vendorIdentifier) { - if (::CFNumberGetValue(CFNumberRef(vendorIdentifier), - kCFNumberIntType, - &value)) { + serialPortInfo.d_ptr->hasVendorIdentifier = ::CFNumberGetValue(CFNumberRef(vendorIdentifier), kCFNumberIntType, &value); + if (serialPortInfo.d_ptr->hasVendorIdentifier) serialPortInfo.d_ptr->vendorIdentifier = value; - } + ::CFRelease(vendorIdentifier); } if (productIdentifier) { - if (::CFNumberGetValue(CFNumberRef(productIdentifier), - kCFNumberIntType, - &value)) { + serialPortInfo.d_ptr->hasProductIdentifier = ::CFNumberGetValue(CFNumberRef(productIdentifier), kCFNumberIntType, &value); + if (serialPortInfo.d_ptr->hasProductIdentifier) serialPortInfo.d_ptr->productIdentifier = value; - } + ::CFRelease(productIdentifier); } diff --git a/src/serialport/qserialportinfo_p.h b/src/serialport/qserialportinfo_p.h index ee7b884..1f12e69 100644 --- a/src/serialport/qserialportinfo_p.h +++ b/src/serialport/qserialportinfo_p.h @@ -51,15 +51,25 @@ QT_BEGIN_NAMESPACE class QSerialPortInfoPrivate { public: - QSerialPortInfoPrivate() : vendorIdentifier(0), productIdentifier(0) {} + QSerialPortInfoPrivate() + : vendorIdentifier(0) + , productIdentifier(0) + , hasVendorIdentifier(false) + , hasProductIdentifier(false) + {} + ~QSerialPortInfoPrivate() {} QString portName; QString device; QString description; QString manufacturer; + quint16 vendorIdentifier; quint16 productIdentifier; + + bool hasVendorIdentifier; + bool hasProductIdentifier; }; class QSerialPortInfoPrivateDeleter diff --git a/src/serialport/qserialportinfo_unix.cpp b/src/serialport/qserialportinfo_unix.cpp index bfdc3d0..ee76fc6 100644 --- a/src/serialport/qserialportinfo_unix.cpp +++ b/src/serialport/qserialportinfo_unix.cpp @@ -147,10 +147,12 @@ QList<QSerialPortInfo> QSerialPortInfo::availablePorts() "ID_VENDOR"))).replace('_', ' '); serialPortInfo.d_ptr->vendorIdentifier = - QString::fromLatin1(::udev_device_get_property_value(dev, "ID_VENDOR_ID")).toInt(0, 16); + QString::fromLatin1(::udev_device_get_property_value(dev, + "ID_VENDOR_ID")).toInt(&serialPortInfo.d_ptr->hasVendorIdentifier, 16); serialPortInfo.d_ptr->productIdentifier = - QString::fromLatin1(::udev_device_get_property_value(dev, "ID_MODEL_ID")).toInt(0, 16); + QString::fromLatin1(::udev_device_get_property_value(dev, + "ID_MODEL_ID")).toInt(&serialPortInfo.d_ptr->hasProductIdentifier, 16); } else if (subsys == QLatin1String("pnp")) { // PNP bus type // Append this device. diff --git a/src/serialport/qserialportinfo_win.cpp b/src/serialport/qserialportinfo_win.cpp index 0a6618e..7ca1f5e 100644 --- a/src/serialport/qserialportinfo_win.cpp +++ b/src/serialport/qserialportinfo_win.cpp @@ -178,11 +178,13 @@ QList<QSerialPortInfo> QSerialPortInfo::availablePorts() int index = s.indexOf(vendorIdentifierPrefix); if (index != -1) - serialPortInfo.d_ptr->vendorIdentifier = s.mid(index + vendorIdentifierPrefix.size(), vendorIdentifierSize).toInt(0, 16); + serialPortInfo.d_ptr->vendorIdentifier = s.mid(index + vendorIdentifierPrefix.size(), vendorIdentifierSize) + .toInt(&serialPortInfo.d_ptr->hasVendorIdentifier, 16); index = s.indexOf(productIdentifierPrefix); if (index != -1) - serialPortInfo.d_ptr->productIdentifier = s.mid(index + productIdentifierPrefix.size(), productIdentifierSize).toInt(0, 16); + serialPortInfo.d_ptr->productIdentifier = s.mid(index + productIdentifierPrefix.size(), productIdentifierSize) + .toInt(&serialPortInfo.d_ptr->hasProductIdentifier, 16); serialPortInfoList.append(serialPortInfo); } |