summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Shienkov <denis.shienkov@gmail.com>2014-11-28 21:25:36 +0000
committerDenis Shienkov <denis.shienkov@gmail.com>2014-12-02 12:06:26 +0100
commit38286174dd6b3df4e460977326423a6bbda59700 (patch)
tree21e1bccd334d0a52bf0b4dbee7a6c8c00baa53e7
parent383ee53814649190e24e08a16acd6aee629de157 (diff)
downloadqtserialport-38286174dd6b3df4e460977326423a6bbda59700.tar.gz
Improve QSPI algorithm on Unix
QSPI uses the wrong algorithm of devices search. In case no any devices are detected with udev (or with sysfs), starts a search with a filters. In this case a user gets a list of devices that are not a serial ports, that is wrong. The main idea should be in that udev or sysfs are the main sources of obtaining information. In case they returns an empty list this means that system has no serial ports. Algorithm is: Try to find devices through udev. If it fails (system error or udev is not present), then try to find using sysfs; otherwise return udev result, even if it has an empty list. If sysfs is fails (permission denied or sysfs is not present), then try to find devices in /dev/ as last attempt; otherwise return sysfs result, even if it has an empty list. Tested on Linux (with udev, sysfs, filters) using FTDI serial ports. Change-Id: I0132e27f720b007ea3f4861e9cd7ed77833cff8c Reviewed-by: Sergey Belyashov <Sergey.Belyashov@gmail.com>
-rw-r--r--src/serialport/qserialportinfo.h6
-rw-r--r--src/serialport/qserialportinfo_unix.cpp30
2 files changed, 22 insertions, 14 deletions
diff --git a/src/serialport/qserialportinfo.h b/src/serialport/qserialportinfo.h
index 0c7a0f1..714708d 100644
--- a/src/serialport/qserialportinfo.h
+++ b/src/serialport/qserialportinfo.h
@@ -82,9 +82,9 @@ public:
private:
QSerialPortInfo(const QSerialPortInfoPrivate &dd);
- friend QList<QSerialPortInfo> availablePortsByUdev();
- friend QList<QSerialPortInfo> availablePortsBySysfs();
- friend QList<QSerialPortInfo> availablePortsByFiltersOfDevices();
+ friend QList<QSerialPortInfo> availablePortsByUdev(bool &ok);
+ friend QList<QSerialPortInfo> availablePortsBySysfs(bool &ok);
+ friend QList<QSerialPortInfo> availablePortsByFiltersOfDevices(bool &ok);
QScopedPointer<QSerialPortInfoPrivate, QSerialPortInfoPrivateDeleter> d_ptr;
};
diff --git a/src/serialport/qserialportinfo_unix.cpp b/src/serialport/qserialportinfo_unix.cpp
index 9637581..8bf5692 100644
--- a/src/serialport/qserialportinfo_unix.cpp
+++ b/src/serialport/qserialportinfo_unix.cpp
@@ -93,7 +93,7 @@ static QStringList filteredDeviceFilePaths()
return result;
}
-QList<QSerialPortInfo> availablePortsByFiltersOfDevices()
+QList<QSerialPortInfo> availablePortsByFiltersOfDevices(bool &ok)
{
QList<QSerialPortInfo> serialPortInfoList;
@@ -104,15 +104,18 @@ QList<QSerialPortInfo> availablePortsByFiltersOfDevices()
serialPortInfoList.append(priv);
}
+ ok = true;
return serialPortInfoList;
}
-QList<QSerialPortInfo> availablePortsBySysfs()
+QList<QSerialPortInfo> availablePortsBySysfs(bool &ok)
{
QDir ttySysClassDir(QStringLiteral("/sys/class/tty"));
- if (!(ttySysClassDir.exists() && ttySysClassDir.isReadable()))
+ if (!(ttySysClassDir.exists() && ttySysClassDir.isReadable())) {
+ ok = false;
return QList<QSerialPortInfo>();
+ }
QList<QSerialPortInfo> serialPortInfoList;
ttySysClassDir.setFilter(QDir::Dirs | QDir::NoDotAndDotDot);
@@ -206,6 +209,7 @@ QList<QSerialPortInfo> availablePortsBySysfs()
serialPortInfoList.append(priv);
}
+ ok = true;
return serialPortInfoList;
}
@@ -282,8 +286,10 @@ QString getUdevSerialNumber(struct ::udev_device *dev)
return getUdevPropertyValue(dev,"ID_SERIAL_SHORT");
}
-QList<QSerialPortInfo> availablePortsByUdev()
+QList<QSerialPortInfo> availablePortsByUdev(bool &ok)
{
+ ok = false;
+
#ifndef LINK_LIBUDEV
static bool symbolsResolved = resolveSymbols(udevLibrary());
if (!symbolsResolved)
@@ -311,6 +317,8 @@ QList<QSerialPortInfo> availablePortsByUdev()
udev_list_entry *dev_list_entry;
udev_list_entry_foreach(dev_list_entry, devices) {
+ ok = true;
+
QScopedPointer<udev_device, ScopedPointerUdevDeviceDeleter>
dev(::udev_device_new_from_syspath(
udev.data(), ::udev_list_entry_get_name(dev_list_entry)));
@@ -352,17 +360,17 @@ QList<QSerialPortInfo> availablePortsByUdev()
QList<QSerialPortInfo> QSerialPortInfo::availablePorts()
{
- QList<QSerialPortInfo> serialPortInfoList = availablePortsByUdev();
+ bool ok;
+
+ QList<QSerialPortInfo> serialPortInfoList = availablePortsByUdev(ok);
#ifdef Q_OS_LINUX
- if (serialPortInfoList.isEmpty())
- serialPortInfoList = availablePortsBySysfs();
- else
- return serialPortInfoList;
+ if (!ok)
+ serialPortInfoList = availablePortsBySysfs(ok);
#endif
- if (serialPortInfoList.isEmpty())
- serialPortInfoList = availablePortsByFiltersOfDevices();
+ if (!ok)
+ serialPortInfoList = availablePortsByFiltersOfDevices(ok);
return serialPortInfoList;
}