summaryrefslogtreecommitdiffstats
path: root/src/serialport/qserialportinfo_unix.cpp
diff options
context:
space:
mode:
authorLaszlo Papp <lpapp@kde.org>2013-11-23 10:32:01 +0000
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-11-25 09:55:06 +0100
commitd97a152bf14cd7b58e576bd6b4a5f304527f940e (patch)
treedf8317cc7ad8230dd109ba3b0951bfa0361c2ef4 /src/serialport/qserialportinfo_unix.cpp
parent1a6ec9148a782c06ee84961c16a57411dc8bcbee (diff)
Try to load udev at runtime if we do not link against it
There was an explicit option previously added into 5.2.0 due to lack of time to implement this runtime resolution properly. The libudev load variable can now be eliminated which also simplifies the packaging. This change also takes care of avoiding the regression by not loading udev at runtime at all for Qt 4. That has always been the case, so there are no regressions there. A TODO comment has been left in the code though about it. The helper free functions cannot be static because they are declared as friend outside that source file. Ideally, we could have a better approach, but that would require more significant refactoring, and such a revamp has to become stable in the 'dev' branch before going into the 'stable' branch. Thereby, this is an acceptable compromise. It does not break binary compatibility either to remove or add friend declarations to a class. The change has been tested on Archlinux (x86_64) with Qt 4 and then 5 using the cenumerator example. The change has been tested both with udev and without that, i.e with sysfs on my Linux system. Change-Id: Ia7d7ecb336c1de1913e1dd60177ae7469e90c329 Reviewed-by: Sergey Belyashov <Sergey.Belyashov@gmail.com> Reviewed-by: Denis Shienkov <denis.shienkov@gmail.com>
Diffstat (limited to 'src/serialport/qserialportinfo_unix.cpp')
-rw-r--r--src/serialport/qserialportinfo_unix.cpp62
1 files changed, 36 insertions, 26 deletions
diff --git a/src/serialport/qserialportinfo_unix.cpp b/src/serialport/qserialportinfo_unix.cpp
index 5fb110ce..fee8b845 100644
--- a/src/serialport/qserialportinfo_unix.cpp
+++ b/src/serialport/qserialportinfo_unix.cpp
@@ -47,15 +47,11 @@
#include <QtCore/qlockfile.h>
#include <QtCore/qfile.h>
+#include <QtCore/qdir.h>
#ifndef Q_OS_MAC
-#if defined(LINK_LIBUDEV) || defined(LOAD_LIBUDEV)
#include "qtudev_p.h"
-#else
-#include <QtCore/qdir.h>
-#include <QtCore/qstringlist.h>
-#endif
#endif
@@ -63,8 +59,6 @@ QT_BEGIN_NAMESPACE
#ifndef Q_OS_MAC
-#if !defined(LINK_LIBUDEV) && !defined(LOAD_LIBUDEV)
-
static QStringList filteredDeviceFilePaths()
{
static const QStringList deviceFileNameFilterList = QStringList()
@@ -105,16 +99,25 @@ static QStringList filteredDeviceFilePaths()
return result;
}
-QList<QSerialPortInfo> QSerialPortInfo::availablePorts()
+QList<QSerialPortInfo> availablePortsByFiltersOfDevices()
{
QList<QSerialPortInfo> serialPortInfoList;
- bool sysfsEnabled = false;
+ foreach (const QString &deviceFilePath, filteredDeviceFilePaths()) {
+ QSerialPortInfo serialPortInfo;
+ serialPortInfo.d_ptr->device = deviceFilePath;
+ serialPortInfo.d_ptr->portName = QSerialPortPrivate::portNameFromSystemLocation(deviceFilePath);
+ serialPortInfoList.append(serialPortInfo);
+ }
-#ifdef Q_OS_LINUX
+ return serialPortInfoList;
+}
+QList<QSerialPortInfo> availablePortsBySysfs()
+{
+ QList<QSerialPortInfo> serialPortInfoList;
QDir ttySysClassDir(QStringLiteral("/sys/class/tty"));
- sysfsEnabled = ttySysClassDir.exists() && ttySysClassDir.isReadable();
+ const bool sysfsEnabled = ttySysClassDir.exists() && ttySysClassDir.isReadable();
if (sysfsEnabled) {
ttySysClassDir.setFilter(QDir::Dirs | QDir::NoDotAndDotDot);
@@ -187,25 +190,12 @@ QList<QSerialPortInfo> QSerialPortInfo::availablePorts()
}
}
-#endif
-
- if (!sysfsEnabled) {
- foreach (const QString &deviceFilePath, filteredDeviceFilePaths()) {
- QSerialPortInfo serialPortInfo;
- serialPortInfo.d_ptr->device = deviceFilePath;
- serialPortInfo.d_ptr->portName = QSerialPortPrivate::portNameFromSystemLocation(deviceFilePath);
- serialPortInfoList.append(serialPortInfo);
- }
- }
-
return serialPortInfoList;
}
-#else
-
-QList<QSerialPortInfo> QSerialPortInfo::availablePorts()
+QList<QSerialPortInfo> availablePortsByUdev()
{
-#ifdef LOAD_LIBUDEV
+#ifndef LINK_LIBUDEV
static bool symbolsResolved = resolveSymbols();
if (!symbolsResolved)
return QList<QSerialPortInfo>();
@@ -298,8 +288,28 @@ QList<QSerialPortInfo> QSerialPortInfo::availablePorts()
return serialPortInfoList;
}
+QList<QSerialPortInfo> QSerialPortInfo::availablePorts()
+{
+ QList<QSerialPortInfo> serialPortInfoList;
+ // TODO: Remove this condition once the udev runtime symbol resolution crash
+ // is fixed for Qt 4.
+#if defined(LINK_LIBUDEV) || (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
+ serialPortInfoList = availablePortsByUdev();
+#endif
+
+#ifdef Q_OS_LINUX
+ if (serialPortInfoList.isEmpty())
+ serialPortInfoList = availablePortsBySysfs();
+ else
+ return serialPortInfoList;
#endif
+ if (serialPortInfoList.isEmpty())
+ serialPortInfoList = availablePortsByFiltersOfDevices();
+
+ return serialPortInfoList;
+}
+
#endif
QList<qint32> QSerialPortInfo::standardBaudRates()