From 3c48b918339b25fa21595d7bed6dc8b9e5ca65b0 Mon Sep 17 00:00:00 2001 From: Denis Shienkov Date: Tue, 1 Jul 2014 18:57:59 +0400 Subject: Make independent implementation of QSerialPortInfo for OS X MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Building in OS X uses some shared code from the serialportinfo_unix.cpp module with the OS X specific code from the serialportinfo_mac.cpp module. Thus, all code of the serialportinfo_unix.cpp module, which not related with the OS X, is shielded by a macro. It adds an excessive garbage for readability in this module and also some confusion in the *.pri file. It makes sense to make implementation of the serialportinfo_mac.cpp module completely independent, that will simplify maintaining of source code. Besides are added tests which can reveal declared but not implemented methods in building, and also to check a correctness of default values at running. Tested build on OS X 10.8.4 with Qt4, an then on Android with Qt5. Change-Id: I67935b64e2b623fb8d4c14d59e1b87f1eac71c3e Reviewed-by: Bernard Pratz Reviewed-by: Peter Kümmel Reviewed-by: Denis Shienkov --- src/serialport/qserialportinfo_mac.cpp | 35 +++++++++++++++++++++++++++++++++ src/serialport/qserialportinfo_unix.cpp | 8 -------- src/serialport/serialport-lib.pri | 11 +++++++---- 3 files changed, 42 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/serialport/qserialportinfo_mac.cpp b/src/serialport/qserialportinfo_mac.cpp index 2c2564e9..d540b150 100644 --- a/src/serialport/qserialportinfo_mac.cpp +++ b/src/serialport/qserialportinfo_mac.cpp @@ -43,6 +43,7 @@ #include "qserialportinfo.h" #include "qserialportinfo_p.h" +#include "qserialport_unix_p.h" #include @@ -290,4 +291,38 @@ QList QSerialPortInfo::availablePorts() return serialPortInfoList; } +QList QSerialPortInfo::standardBaudRates() +{ + return QSerialPortPrivate::standardBaudRates(); +} + +bool QSerialPortInfo::isBusy() const +{ + QString lockFilePath = serialPortLockFilePath(portName()); + if (lockFilePath.isEmpty()) + return false; + + QFile reader(lockFilePath); + if (!reader.open(QIODevice::ReadOnly)) + return false; + + QByteArray pidLine = reader.readLine(); + pidLine.chop(1); + if (pidLine.isEmpty()) + return false; + + qint64 pid = pidLine.toLongLong(); + + if (pid && (::kill(pid, 0) == -1) && (errno == ESRCH)) + return false; // PID doesn't exist anymore + + return true; +} + +bool QSerialPortInfo::isValid() const +{ + QFile f(systemLocation()); + return f.exists(); +} + QT_END_NAMESPACE diff --git a/src/serialport/qserialportinfo_unix.cpp b/src/serialport/qserialportinfo_unix.cpp index ce5f3a95..0ed8703b 100644 --- a/src/serialport/qserialportinfo_unix.cpp +++ b/src/serialport/qserialportinfo_unix.cpp @@ -55,16 +55,10 @@ #include // kill #include // kill -#ifndef Q_OS_MAC - #include "qtudev_p.h" -#endif - QT_BEGIN_NAMESPACE -#ifndef Q_OS_MAC - static QStringList filteredDeviceFilePaths() { static const QStringList deviceFileNameFilterList = QStringList() @@ -379,8 +373,6 @@ QList QSerialPortInfo::availablePorts() return serialPortInfoList; } -#endif - QList QSerialPortInfo::standardBaudRates() { return QSerialPortPrivate::standardBaudRates(); diff --git a/src/serialport/serialport-lib.pri b/src/serialport/serialport-lib.pri index 166a6fac..9c9b0768 100644 --- a/src/serialport/serialport-lib.pri +++ b/src/serialport/serialport-lib.pri @@ -78,11 +78,14 @@ unix:!symbian { $$PWD/qserialport_unix_p.h SOURCES += \ - $$PWD/qserialport_unix.cpp \ - $$PWD/qserialportinfo_unix.cpp + $$PWD/qserialport_unix.cpp - macx { - SOURCES += $$PWD/qserialportinfo_mac.cpp + !mac { + SOURCES += \ + $$PWD/qserialportinfo_unix.cpp + } else { + SOURCES += \ + $$PWD/qserialportinfo_mac.cpp LIBS_PRIVATE += -framework IOKit -framework CoreFoundation } -- cgit v1.2.3