diff options
author | Liang Qi <liang.qi@qt.io> | 2017-11-20 13:18:07 +0100 |
---|---|---|
committer | Liang Qi <liang.qi@qt.io> | 2017-11-20 14:39:23 +0100 |
commit | 692a6db62b6c54f518d9e5b4f1f8f134fb3719fc (patch) | |
tree | 5b6f1d14e116ae3eb6b0c7a461ba1354e63c9bde /src | |
parent | baa87d4c34059b790c93d210f07696de818e8d5e (diff) | |
parent | b0948ec06644dd88ba8ec660c1fb39c49a6d0e70 (diff) |
Merge remote-tracking branch 'origin/5.10' into dev
Conflicts:
examples/serialport/blockingmaster/masterthread.h
examples/serialport/blockingslave/slavethread.h
Change-Id: I6b6bf25b41ff0f1b0b9632069d3b13f6c47c6421
Diffstat (limited to 'src')
-rw-r--r-- | src/serialport/doc/src/index.qdoc | 11 | ||||
-rw-r--r-- | src/serialport/doc/src/qtserialport-module.qdoc | 10 | ||||
-rw-r--r-- | src/serialport/qserialport.cpp | 36 | ||||
-rw-r--r-- | src/serialport/qserialport_p.h | 56 | ||||
-rw-r--r-- | src/serialport/qserialport_unix.cpp | 35 | ||||
-rw-r--r-- | src/serialport/qserialportinfo_p.h | 20 | ||||
-rw-r--r-- | src/serialport/qwinoverlappedionotifier.cpp | 32 |
7 files changed, 79 insertions, 121 deletions
diff --git a/src/serialport/doc/src/index.qdoc b/src/serialport/doc/src/index.qdoc index 3b0f7624..041188e0 100644 --- a/src/serialport/doc/src/index.qdoc +++ b/src/serialport/doc/src/index.qdoc @@ -43,11 +43,18 @@ \li Pinout signal change notification. \endlist - To use these classes in your application, use the following include + To use the serial port in your application, add the following include statement: \code - #include <QtSerialPort/QtSerialPort> + #include <QSerialPort> + \endcode + + For information about available serial ports, use the following include + statement: + + \code + #include <QSerialPortInfo> \endcode To link against the module, add this line to your \l qmake \c diff --git a/src/serialport/doc/src/qtserialport-module.qdoc b/src/serialport/doc/src/qtserialport-module.qdoc index 325b7800..6c153a00 100644 --- a/src/serialport/doc/src/qtserialport-module.qdoc +++ b/src/serialport/doc/src/qtserialport-module.qdoc @@ -32,11 +32,17 @@ \qtvariable serialport \brief List of C++ classes that enable access to a serial port. - To use these classes in your application, use the following include + To use QSerialPort in your application, add the following include statement: \code - #include <QtSerialPort/QtSerialPort> + #include <QSerialPort> + \endcode + + For QSerialPortInfo, use the following include statement: + + \code + #include <QSerialPortInfo> \endcode To link against the module, add this line to your \l qmake \c diff --git a/src/serialport/qserialport.cpp b/src/serialport/qserialport.cpp index 7853f1a6..3b887366 100644 --- a/src/serialport/qserialport.cpp +++ b/src/serialport/qserialport.cpp @@ -87,38 +87,8 @@ QSerialPortErrorInfo::QSerialPortErrorInfo(QSerialPort::SerialPortError newError } QSerialPortPrivate::QSerialPortPrivate() - : readBufferMaxSize(0) - , error(QSerialPort::NoError) - , inputBaudRate(9600) - , outputBaudRate(9600) - , dataBits(QSerialPort::Data8) - , parity(QSerialPort::NoParity) - , stopBits(QSerialPort::OneStop) - , flowControl(QSerialPort::NoFlowControl) -#if QT_DEPRECATED_SINCE(5,3) - , settingsRestoredOnClose(true) -#endif - , isBreakEnabled(false) #if defined(Q_OS_WIN32) - , handle(INVALID_HANDLE_VALUE) - , readChunkBuffer(QSERIALPORT_BUFFERSIZE, 0) - , communicationStarted(false) - , writeStarted(false) - , readStarted(false) - , notifier(0) - , startAsyncWriteTimer(0) - , triggeredEventMask(0) -#elif defined(Q_OS_UNIX) - , descriptor(-1) - , readNotifier(0) - , writeNotifier(0) - , readPortNotifierCalled(false) - , readPortNotifierState(false) - , readPortNotifierStateSet(false) - , emittedReadyRead(false) - , emittedBytesWritten(false) - , pendingBytesWritten(0) - , writeSequenceStarted(false) + : readChunkBuffer(QSERIALPORT_BUFFERSIZE, 0) #endif { writeBufferChunkSize = QSERIALPORT_BUFFERSIZE; @@ -1308,7 +1278,7 @@ bool QSerialPort::canReadLine() const This function blocks until new data is available for reading and the \l{QIODevice::}{readyRead()} signal has been emitted. The function will timeout after \a msecs milliseconds; the default timeout is - 30000 milliseconds. + 30000 milliseconds. If \a msecs is -1, this function will not time out. The function returns \c true if the readyRead() signal is emitted and there is new data available for reading; otherwise it returns \c false @@ -1340,7 +1310,7 @@ bool QSerialPort::waitForReadyRead(int msecs) This function blocks until at least one byte has been written to the serial port and the \l{QIODevice::}{bytesWritten()} signal has been emitted. The function will timeout after \a msecs milliseconds; the default timeout is - 30000 milliseconds. + 30000 milliseconds. If \a msecs is -1, this function will not time out. The function returns \c true if the bytesWritten() signal is emitted; otherwise it returns \c false (if an error occurred or the operation timed out). diff --git a/src/serialport/qserialport_p.h b/src/serialport/qserialport_p.h index 0e4f8bde..b0955aef 100644 --- a/src/serialport/qserialport_p.h +++ b/src/serialport/qserialport_p.h @@ -117,7 +117,7 @@ class QSerialPortErrorInfo public: explicit QSerialPortErrorInfo(QSerialPort::SerialPortError newErrorCode = QSerialPort::UnknownError, const QString &newErrorString = QString()); - QSerialPort::SerialPortError errorCode; + QSerialPort::SerialPortError errorCode = QSerialPort::UnknownError; QString errorString; }; @@ -164,17 +164,17 @@ public: static QList<qint32> standardBaudRates(); - qint64 readBufferMaxSize; - QSerialPort::SerialPortError error; + qint64 readBufferMaxSize = 0; + QSerialPort::SerialPortError error = QSerialPort::NoError; QString systemLocation; - qint32 inputBaudRate; - qint32 outputBaudRate; - QSerialPort::DataBits dataBits; - QSerialPort::Parity parity; - QSerialPort::StopBits stopBits; - QSerialPort::FlowControl flowControl; - bool settingsRestoredOnClose; - bool isBreakEnabled; + qint32 inputBaudRate = QSerialPort::Baud9600; + qint32 outputBaudRate = QSerialPort::Baud9600; + QSerialPort::DataBits dataBits = QSerialPort::Data8; + QSerialPort::Parity parity = QSerialPort::NoParity; + QSerialPort::StopBits stopBits = QSerialPort::OneStop; + QSerialPort::FlowControl flowControl = QSerialPort::NoFlowControl; + bool settingsRestoredOnClose = true; + bool isBreakEnabled = false; bool startAsyncRead(); @@ -199,18 +199,18 @@ public: DCB restoredDcb; COMMTIMEOUTS currentCommTimeouts; COMMTIMEOUTS restoredCommTimeouts; - HANDLE handle; + HANDLE handle = INVALID_HANDLE_VALUE; QByteArray readChunkBuffer; QByteArray writeChunkBuffer; - bool communicationStarted; - bool writeStarted; - bool readStarted; - QWinOverlappedIoNotifier *notifier; - QTimer *startAsyncWriteTimer; + bool communicationStarted = false; + bool writeStarted = false; + bool readStarted = false; + QWinOverlappedIoNotifier *notifier = nullptr; + QTimer *startAsyncWriteTimer = nullptr; OVERLAPPED communicationOverlapped; OVERLAPPED readCompletionOverlapped; OVERLAPPED writeCompletionOverlapped; - DWORD triggeredEventMask; + DWORD triggeredEventMask = 0; #elif defined(Q_OS_UNIX) @@ -243,20 +243,20 @@ public: bool completeAsyncWrite(); struct termios restoredTermios; - int descriptor; + int descriptor = -1; - QSocketNotifier *readNotifier; - QSocketNotifier *writeNotifier; + QSocketNotifier *readNotifier = nullptr; + QSocketNotifier *writeNotifier = nullptr; - bool readPortNotifierCalled; - bool readPortNotifierState; - bool readPortNotifierStateSet; + bool readPortNotifierCalled = false; + bool readPortNotifierState = false; + bool readPortNotifierStateSet = false; - bool emittedReadyRead; - bool emittedBytesWritten; + bool emittedReadyRead = false; + bool emittedBytesWritten = false; - qint64 pendingBytesWritten; - bool writeSequenceStarted; + qint64 pendingBytesWritten = 0; + bool writeSequenceStarted = false; QScopedPointer<QLockFile> lockFileScopedPointer; diff --git a/src/serialport/qserialport_unix.cpp b/src/serialport/qserialport_unix.cpp index 87d7e405..a13a2890 100644 --- a/src/serialport/qserialport_unix.cpp +++ b/src/serialport/qserialport_unix.cpp @@ -42,10 +42,17 @@ #include "qserialport_p.h" #include "qserialportinfo_p.h" +#include <QtCore/qelapsedtimer.h> +#include <QtCore/qmap.h> +#include <QtCore/qsocketnotifier.h> +#include <QtCore/qstandardpaths.h> + +#include <private/qcore_unix_p.h> + #include <errno.h> -#include <sys/time.h> -#include <sys/ioctl.h> #include <fcntl.h> +#include <sys/ioctl.h> +#include <sys/time.h> #include <unistd.h> #ifdef Q_OS_OSX @@ -93,16 +100,6 @@ struct termios2 { #endif -#include <private/qcore_unix_p.h> - -#include <QtCore/qelapsedtimer.h> -#include <QtCore/qsocketnotifier.h> -#include <QtCore/qmap.h> - -#ifdef Q_OS_OSX -#include <QtCore/qstandardpaths.h> -#endif - QT_BEGIN_NAMESPACE QString serialPortLockFilePath(const QString &portName) @@ -118,12 +115,8 @@ QString serialPortLockFilePath(const QString &portName) << QStringLiteral("/run/lock") #ifdef Q_OS_ANDROID << QStringLiteral("/data/local/tmp") -#elif defined(Q_OS_OSX) - // This is the workaround to specify a temporary directory - // on OSX when running the App Sandbox feature. - << QStandardPaths::writableLocation(QStandardPaths::TempLocation); #endif - ; + << QStandardPaths::writableLocation(QStandardPaths::TempLocation); QString fileName = portName; fileName.replace(QLatin1Char('/'), QLatin1Char('_')); @@ -156,7 +149,7 @@ QString serialPortLockFilePath(const QString &portName) class ReadNotifier : public QSocketNotifier { public: - ReadNotifier(QSerialPortPrivate *d, QObject *parent) + explicit ReadNotifier(QSerialPortPrivate *d, QObject *parent) : QSocketNotifier(d->descriptor, QSocketNotifier::Read, parent) , dptr(d) { @@ -173,13 +166,13 @@ protected: } private: - QSerialPortPrivate *dptr; + QSerialPortPrivate * const dptr; }; class WriteNotifier : public QSocketNotifier { public: - WriteNotifier(QSerialPortPrivate *d, QObject *parent) + explicit WriteNotifier(QSerialPortPrivate *d, QObject *parent) : QSocketNotifier(d->descriptor, QSocketNotifier::Write, parent) , dptr(d) { @@ -196,7 +189,7 @@ protected: } private: - QSerialPortPrivate *dptr; + QSerialPortPrivate * const dptr; }; static inline void qt_set_common_props(termios *tio, QIODevice::OpenMode m) diff --git a/src/serialport/qserialportinfo_p.h b/src/serialport/qserialportinfo_p.h index 483ff8cc..405cc419 100644 --- a/src/serialport/qserialportinfo_p.h +++ b/src/serialport/qserialportinfo_p.h @@ -60,18 +60,6 @@ QT_BEGIN_NAMESPACE class Q_AUTOTEST_EXPORT QSerialPortInfoPrivate { public: - QSerialPortInfoPrivate() - : vendorIdentifier(0) - , productIdentifier(0) - , hasVendorIdentifier(false) - , hasProductIdentifier(false) - { - } - - ~QSerialPortInfoPrivate() - { - } - static QString portNameToSystemLocation(const QString &source); static QString portNameFromSystemLocation(const QString &source); @@ -81,11 +69,11 @@ public: QString manufacturer; QString serialNumber; - quint16 vendorIdentifier; - quint16 productIdentifier; + quint16 vendorIdentifier = 0; + quint16 productIdentifier = 0; - bool hasVendorIdentifier; - bool hasProductIdentifier; + bool hasVendorIdentifier = false; + bool hasProductIdentifier = false; }; class QSerialPortInfoPrivateDeleter diff --git a/src/serialport/qwinoverlappedionotifier.cpp b/src/serialport/qwinoverlappedionotifier.cpp index 6ec7463d..dfae3b00 100644 --- a/src/serialport/qwinoverlappedionotifier.cpp +++ b/src/serialport/qwinoverlappedionotifier.cpp @@ -101,13 +101,13 @@ QT_BEGIN_NAMESPACE struct IOResult { - IOResult(DWORD n = 0, DWORD e = 0, OVERLAPPED *p = 0) + IOResult(DWORD n = 0, DWORD e = 0, OVERLAPPED *p = nullptr) : numberOfBytes(n), errorCode(e), overlapped(p) {} - DWORD numberOfBytes; - DWORD errorCode; - OVERLAPPED *overlapped; + DWORD numberOfBytes = 0; + DWORD errorCode = 0; + OVERLAPPED *overlapped = nullptr; }; @@ -117,11 +117,6 @@ class QWinOverlappedIoNotifierPrivate : public QObjectPrivate { Q_DECLARE_PUBLIC(QWinOverlappedIoNotifier) public: - QWinOverlappedIoNotifierPrivate() - : hHandle(INVALID_HANDLE_VALUE) - { - } - OVERLAPPED *waitForAnyNotified(QDeadlineTimer deadline); void notify(DWORD numberOfBytes, DWORD errorCode, OVERLAPPED *overlapped); void _q_notified(); @@ -130,9 +125,9 @@ public: static QWinIoCompletionPort *iocp; static HANDLE iocpInstanceLock; static unsigned int iocpInstanceRefCount; - HANDLE hHandle; - HANDLE hSemaphore; - HANDLE hResultsMutex; + HANDLE hHandle = INVALID_HANDLE_VALUE; + HANDLE hSemaphore = nullptr; + HANDLE hResultsMutex = nullptr; QAtomicInt waiting; QQueue<IOResult> results; }; @@ -147,8 +142,7 @@ class QWinIoCompletionPort : protected QThread public: QWinIoCompletionPort() : finishThreadKey(reinterpret_cast<ULONG_PTR>(this)), - drainQueueKey(reinterpret_cast<ULONG_PTR>(this + 1)), - hPort(INVALID_HANDLE_VALUE) + drainQueueKey(reinterpret_cast<ULONG_PTR>(this + 1)) { setObjectName(QLatin1String("I/O completion port thread")); HANDLE hIOCP = CreateIoCompletionPort(INVALID_HANDLE_VALUE, NULL, 0, 0); @@ -208,9 +202,9 @@ public: protected: void run() { - DWORD dwBytesRead; - ULONG_PTR pulCompletionKey; - OVERLAPPED *overlapped; + DWORD dwBytesRead = 0; + ULONG_PTR pulCompletionKey = 0; + OVERLAPPED *overlapped = nullptr; DWORD msecs = INFINITE; forever { @@ -253,11 +247,11 @@ protected: private: const ULONG_PTR finishThreadKey; const ULONG_PTR drainQueueKey; - HANDLE hPort; + HANDLE hPort = INVALID_HANDLE_VALUE; QSet<QWinOverlappedIoNotifierPrivate *> notifiers; QMutex mutex; QMutex drainQueueMutex; - HANDLE hQueueDrainedEvent; + HANDLE hQueueDrainedEvent = nullptr; }; |