From 42b0324d3c37d9bde5e06e183ec770c7556341c2 Mon Sep 17 00:00:00 2001 From: Denis Shienkov Date: Thu, 28 Sep 2017 13:22:28 +0300 Subject: Use C++11 member class initialization MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I427b993a3a71f199029a8956cdf0dc2c98f0e444 Reviewed-by: Alex Blasche Reviewed-by: André Hartmann --- src/serialport/qserialport.cpp | 32 +---------------- src/serialport/qserialport_p.h | 56 ++++++++++++++--------------- src/serialport/qserialportinfo_p.h | 20 +++-------- src/serialport/qwinoverlappedionotifier.cpp | 32 +++++++---------- 4 files changed, 46 insertions(+), 94 deletions(-) diff --git a/src/serialport/qserialport.cpp b/src/serialport/qserialport.cpp index 7853f1a..c4112a1 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; diff --git a/src/serialport/qserialport_p.h b/src/serialport/qserialport_p.h index 0e4f8bd..b0955ae 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 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 lockFileScopedPointer; diff --git a/src/serialport/qserialportinfo_p.h b/src/serialport/qserialportinfo_p.h index 483ff8c..405cc41 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 6ec7463..dfae3b0 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 results; }; @@ -147,8 +142,7 @@ class QWinIoCompletionPort : protected QThread public: QWinIoCompletionPort() : finishThreadKey(reinterpret_cast(this)), - drainQueueKey(reinterpret_cast(this + 1)), - hPort(INVALID_HANDLE_VALUE) + drainQueueKey(reinterpret_cast(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 notifiers; QMutex mutex; QMutex drainQueueMutex; - HANDLE hQueueDrainedEvent; + HANDLE hQueueDrainedEvent = nullptr; }; -- cgit v1.2.1