summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@theqtcompany.com>2015-03-17 16:40:51 +0100
committerLiang Qi <liang.qi@theqtcompany.com>2015-03-17 16:40:51 +0100
commit90ac0fffa223d8f81cf9a3c6a89cd4ec1de5f537 (patch)
tree77aaa8aa13bc5be4db7f4123cbfe49699ff72a78
parent4f04bc5e0ac96963480e800e40411f7c9c0cdfb9 (diff)
parent687dfa9312c1ef4894c32a1966b8ac968110b71e (diff)
downloadqtserialport-90ac0fffa223d8f81cf9a3c6a89cd4ec1de5f537.tar.gz
Merge remote-tracking branch 'origin/5.5' into dev
Change-Id: I770c9c0fa63645afa430041280e0fbd2be42cb61
-rw-r--r--src/serialport/qserialport.cpp8
-rw-r--r--src/serialport/qserialport.h4
-rw-r--r--src/serialport/qserialport_p.h25
-rw-r--r--src/serialport/qserialport_unix.cpp18
-rw-r--r--src/serialport/qserialportinfo_mac.cpp13
-rw-r--r--src/serialport/qserialportinfo_unix.cpp4
-rw-r--r--tests/auto/qserialportinfoprivate/tst_qserialportinfoprivate.cpp8
7 files changed, 38 insertions, 42 deletions
diff --git a/src/serialport/qserialport.cpp b/src/serialport/qserialport.cpp
index cb87689..a7075e0 100644
--- a/src/serialport/qserialport.cpp
+++ b/src/serialport/qserialport.cpp
@@ -46,7 +46,7 @@ QT_BEGIN_NAMESPACE
QSerialPortPrivate::QSerialPortPrivate()
: readBufferMaxSize(0)
- , writeBuffer(SERIALPORT_BUFFERSIZE)
+ , writeBuffer(InitialBufferSize)
, error(QSerialPort::NoError)
, inputBaudRate(9600)
, outputBaudRate(9600)
@@ -59,11 +59,11 @@ QSerialPortPrivate::QSerialPortPrivate()
, settingsRestoredOnClose(true)
#endif
, isBreakEnabled(false)
-#if defined (Q_OS_WINCE)
+#if defined(Q_OS_WINCE)
, handle(INVALID_HANDLE_VALUE)
, parityErrorOccurred(false)
, eventNotifier(0)
-#elif defined (Q_OS_WIN32)
+#elif defined(Q_OS_WIN32)
, handle(INVALID_HANDLE_VALUE)
, parityErrorOccurred(false)
, readChunkBuffer(ReadChunkSize, 0)
@@ -75,7 +75,7 @@ QSerialPortPrivate::QSerialPortPrivate()
, originalEventMask(0)
, triggeredEventMask(0)
, actualBytesToWrite(0)
-#elif defined (Q_OS_UNIX)
+#elif defined(Q_OS_UNIX)
, descriptor(-1)
, readNotifier(0)
, writeNotifier(0)
diff --git a/src/serialport/qserialport.h b/src/serialport/qserialport.h
index 0fc7139..3137ba1 100644
--- a/src/serialport/qserialport.h
+++ b/src/serialport/qserialport.h
@@ -142,7 +142,7 @@ public:
Q_DECLARE_FLAGS(PinoutSignals, PinoutSignal)
#if QT_DEPRECATED_SINCE(5, 2)
-#if defined _MSC_VER
+#if defined(_MSC_VER)
#pragma deprecated(UnknownBaud)
#pragma deprecated(UnknownDataBits)
#pragma deprecated(UnknownParity)
@@ -279,7 +279,7 @@ private:
Q_DISABLE_COPY(QSerialPort)
-#if defined (Q_OS_WIN32)
+#if defined(Q_OS_WIN32)
Q_PRIVATE_SLOT(d_func(), bool _q_startAsyncWrite())
Q_PRIVATE_SLOT(d_func(), void _q_notified(quint32, quint32, OVERLAPPED*))
#endif
diff --git a/src/serialport/qserialport_p.h b/src/serialport/qserialport_p.h
index 3da5b59..81e0e94 100644
--- a/src/serialport/qserialport_p.h
+++ b/src/serialport/qserialport_p.h
@@ -52,12 +52,12 @@
#include <private/qringbuffer_p.h>
#include <private/qiodevice_p.h>
-#if defined (Q_OS_WINCE)
+#if defined(Q_OS_WINCE)
# include <QtCore/qmutex.h>
# include <qt_windows.h>
-#elif defined (Q_OS_WIN32)
+#elif defined(Q_OS_WIN32)
# include <qt_windows.h>
-#elif defined (Q_OS_UNIX)
+#elif defined(Q_OS_UNIX)
# include <QtCore/qlockfile.h>
# include <QtCore/qscopedpointer.h>
# include <QtCore/qfileinfo.h>
@@ -88,7 +88,7 @@ struct serial_struct {
# define ASYNC_SPD_CUST 0x0030
# define ASYNC_SPD_MASK 0x1030
# define PORT_UNKNOWN 0
-# elif defined (Q_OS_LINUX)
+# elif defined(Q_OS_LINUX)
# include <linux/serial.h>
# endif
#else
@@ -97,16 +97,12 @@ struct serial_struct {
QT_BEGIN_NAMESPACE
-#ifndef SERIALPORT_BUFFERSIZE
-# define SERIALPORT_BUFFERSIZE 16384
-#endif
-
class QThread;
class QWinOverlappedIoNotifier;
class QTimer;
class QSocketNotifier;
-#if defined (Q_OS_UNIX)
+#if defined(Q_OS_UNIX)
QString serialPortLockFilePath(const QString &portName);
#endif
@@ -115,12 +111,13 @@ class QSerialPortPrivate : public QIODevicePrivate
Q_DECLARE_PUBLIC(QSerialPort)
public:
enum IoConstants {
- ReadChunkSize = 512
+ ReadChunkSize = 512,
+ InitialBufferSize = 16384
};
QSerialPortPrivate();
- int timeoutValue(int msecs, int elapsed);
+ static int timeoutValue(int msecs, int elapsed);
bool open(QIODevice::OpenMode mode);
void close();
@@ -176,7 +173,7 @@ public:
bool settingsRestoredOnClose;
bool isBreakEnabled;
-#if defined (Q_OS_WINCE)
+#if defined(Q_OS_WINCE)
bool initialize(DWORD eventMask);
bool updateDcb();
@@ -200,7 +197,7 @@ public:
QThread *eventNotifier;
QMutex settingsChangeMutex;
-#elif defined (Q_OS_WIN32)
+#elif defined(Q_OS_WIN32)
bool initialize();
bool updateDcb();
@@ -240,7 +237,7 @@ public:
DWORD triggeredEventMask;
qint64 actualBytesToWrite;
-#elif defined (Q_OS_UNIX)
+#elif defined(Q_OS_UNIX)
bool initialize(QIODevice::OpenMode mode);
bool updateTermios();
diff --git a/src/serialport/qserialport_unix.cpp b/src/serialport/qserialport_unix.cpp
index 34ef41d..30131ca 100644
--- a/src/serialport/qserialport_unix.cpp
+++ b/src/serialport/qserialport_unix.cpp
@@ -43,7 +43,7 @@
#include <unistd.h>
#ifdef Q_OS_MAC
-#if defined (MAC_OS_X_VERSION_10_4) && (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_4)
+#if defined(MAC_OS_X_VERSION_10_4) && (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_4)
#include <IOKit/serial/ioss.h>
#endif
#endif
@@ -271,14 +271,14 @@ QSerialPort::PinoutSignals QSerialPortPrivate::pinoutSignals()
#ifdef TIOCM_CAR
if (arg & TIOCM_CAR)
ret |= QSerialPort::DataCarrierDetectSignal;
-#elif defined TIOCM_CD
+#elif defined(TIOCM_CD)
if (arg & TIOCM_CD)
ret |= QSerialPort::DataCarrierDetectSignal;
#endif
#ifdef TIOCM_RNG
if (arg & TIOCM_RNG)
ret |= QSerialPort::RingIndicatorSignal;
-#elif defined TIOCM_RI
+#elif defined(TIOCM_RI)
if (arg & TIOCM_RI)
ret |= QSerialPort::RingIndicatorSignal;
#endif
@@ -439,6 +439,8 @@ QSerialPortPrivate::setStandardBaudRate(qint32 baudRate, QSerialPort::Directions
{
struct serial_struct currentSerialInfo;
+ ::memset(&currentSerialInfo, 0, sizeof(currentSerialInfo));
+
if ((::ioctl(descriptor, TIOCGSERIAL, &currentSerialInfo) != -1)
&& (currentSerialInfo.flags & ASYNC_SPD_CUST)) {
currentSerialInfo.flags &= ~ASYNC_SPD_CUST;
@@ -469,6 +471,8 @@ QSerialPortPrivate::setCustomBaudRate(qint32 baudRate, QSerialPort::Directions d
struct serial_struct currentSerialInfo;
+ ::memset(&currentSerialInfo, 0, sizeof(currentSerialInfo));
+
if (::ioctl(descriptor, TIOCGSERIAL, &currentSerialInfo) == -1)
return decodeSystemError();
@@ -499,7 +503,7 @@ QSerialPortPrivate::setCustomBaudRate(qint32 baudRate, QSerialPort::Directions d
{
Q_UNUSED(directions);
-#if defined (MAC_OS_X_VERSION_10_4) && (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_4)
+#if defined(MAC_OS_X_VERSION_10_4) && (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_4)
if (::ioctl(descriptor, IOSSIOSPEED, &baudRate) == -1)
return decodeSystemError();
@@ -509,7 +513,7 @@ QSerialPortPrivate::setCustomBaudRate(qint32 baudRate, QSerialPort::Directions d
return QSerialPort::UnsupportedOperationError;
}
-#elif defined (Q_OS_QNX)
+#elif defined(Q_OS_QNX)
QSerialPort::SerialPortError
QSerialPortPrivate::setCustomBaudRate(qint32 baudRate, QSerialPort::Directions directions)
@@ -988,7 +992,7 @@ bool QSerialPortPrivate::waitForReadOrWrite(bool *selectForRead, bool *selectFor
qint64 QSerialPortPrivate::readFromPort(char *data, qint64 maxSize)
{
qint64 bytesRead = 0;
-#if defined (CMSPAR)
+#if defined(CMSPAR)
if (parity == QSerialPort::NoParity
|| policy != QSerialPort::StopReceivingPolicy) {
#else
@@ -1006,7 +1010,7 @@ qint64 QSerialPortPrivate::readFromPort(char *data, qint64 maxSize)
qint64 QSerialPortPrivate::writeToPort(const char *data, qint64 maxSize)
{
qint64 bytesWritten = 0;
-#if defined (CMSPAR)
+#if defined(CMSPAR)
bytesWritten = qt_safe_write(descriptor, data, maxSize);
#else
if (parity != QSerialPort::MarkParity
diff --git a/src/serialport/qserialportinfo_mac.cpp b/src/serialport/qserialportinfo_mac.cpp
index 2a3c260..6c175f6 100644
--- a/src/serialport/qserialportinfo_mac.cpp
+++ b/src/serialport/qserialportinfo_mac.cpp
@@ -89,11 +89,6 @@ static bool isCompleteInfo(const QSerialPortInfoPrivate &priv)
&& priv.hasVendorIdentifier;
}
-static QString devicePortName(io_registry_entry_t ioRegistryEntry)
-{
- return searchStringProperty(ioRegistryEntry, QCFString(kIOTTYDeviceKey));
-}
-
static QString deviceSystemLocation(io_registry_entry_t ioRegistryEntry)
{
return searchStringProperty(ioRegistryEntry, QCFString(kIOCalloutDeviceKey));
@@ -163,11 +158,11 @@ QList<QSerialPortInfo> QSerialPortInfo::availablePorts()
QSerialPortInfoPrivate priv;
forever {
- if (priv.portName.isEmpty())
- priv.portName = devicePortName(serialPortService);
-
- if (priv.device.isEmpty())
+ if (priv.device.isEmpty()) {
priv.device = deviceSystemLocation(serialPortService);
+ if (!priv.device.isEmpty())
+ priv.portName = QSerialPortInfoPrivate::portNameFromSystemLocation(priv.device);
+ }
if (priv.description.isEmpty())
priv.description = deviceDescription(serialPortService);
diff --git a/src/serialport/qserialportinfo_unix.cpp b/src/serialport/qserialportinfo_unix.cpp
index 312b99f..7da8f52 100644
--- a/src/serialport/qserialportinfo_unix.cpp
+++ b/src/serialport/qserialportinfo_unix.cpp
@@ -67,9 +67,9 @@ static QStringList filteredDeviceFilePaths()
<< QStringLiteral("ttyAMA*") // AMBA serial device for embedded platform on ARM (i.e. Raspberry Pi).
<< QStringLiteral("rfcomm*") // Bluetooth serial device.
<< QStringLiteral("ircomm*"); // IrDA serial device.
-#elif defined (Q_OS_FREEBSD)
+#elif defined(Q_OS_FREEBSD)
<< QStringLiteral("cu*");
-#elif defined (Q_OS_QNX)
+#elif defined(Q_OS_QNX)
<< QStringLiteral("ser*");
#else
;
diff --git a/tests/auto/qserialportinfoprivate/tst_qserialportinfoprivate.cpp b/tests/auto/qserialportinfoprivate/tst_qserialportinfoprivate.cpp
index 486699f..fa76a1a 100644
--- a/tests/auto/qserialportinfoprivate/tst_qserialportinfoprivate.cpp
+++ b/tests/auto/qserialportinfoprivate/tst_qserialportinfoprivate.cpp
@@ -56,14 +56,14 @@ void tst_QSerialPortInfoPrivate::canonical_data()
QTest::addColumn<QString>("name");
QTest::addColumn<QString>("location");
-#if defined (Q_OS_WINCE)
+#if defined(Q_OS_WINCE)
QTest::newRow("Test1") << "COM1" << "COM1" << "COM1:";
QTest::newRow("Test2") << "COM1:" << "COM1" << "COM1:";
-#elif defined (Q_OS_WIN32)
+#elif defined(Q_OS_WIN32)
QTest::newRow("Test1") << "COM1" << "COM1" << "\\\\.\\COM1";
QTest::newRow("Test2") << "\\\\.\\COM1" << "COM1" << "\\\\.\\COM1";
QTest::newRow("Test3") << "//./COM1" << "COM1" << "//./COM1";
-#elif defined (Q_OS_OSX)
+#elif defined(Q_OS_OSX)
QTest::newRow("Test1") << "ttyS0" << "ttyS0" << "/dev/ttyS0";
QTest::newRow("Test2") << "cu.serial1" << "cu.serial1" << "/dev/cu.serial1";
QTest::newRow("Test3") << "tty.serial1" << "tty.serial1" << "/dev/tty.serial1";
@@ -76,7 +76,7 @@ void tst_QSerialPortInfoPrivate::canonical_data()
QTest::newRow("Test10") << "serial/ttyS0" << "serial/ttyS0" << "/dev/serial/ttyS0";
QTest::newRow("Test11") << "./ttyS0" << "./ttyS0" << "./ttyS0";
QTest::newRow("Test12") << "../ttyS0" << "../ttyS0" << "../ttyS0";
-#elif defined (Q_OS_UNIX)
+#elif defined(Q_OS_UNIX)
QTest::newRow("Test1") << "ttyS0" << "ttyS0" << "/dev/ttyS0";
QTest::newRow("Test2") << "/dev/ttyS0" << "ttyS0" << "/dev/ttyS0";
QTest::newRow("Test3") << "/dev/serial/ttyS0" << "serial/ttyS0" << "/dev/serial/ttyS0";