diff options
Diffstat (limited to 'src')
35 files changed, 298 insertions, 886 deletions
diff --git a/src/serialport/CMakeLists.txt b/src/serialport/CMakeLists.txt index 8c7863a1..496d741f 100644 --- a/src/serialport/CMakeLists.txt +++ b/src/serialport/CMakeLists.txt @@ -1,3 +1,6 @@ +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + ##################################################################### ## SerialPort Module: ##################################################################### @@ -8,6 +11,9 @@ qt_internal_add_module(SerialPort qserialport.cpp qserialport.h qserialport_p.h qserialportglobal.h qserialportinfo.cpp qserialportinfo.h qserialportinfo_p.h + removed_api.cpp + NO_PCH_SOURCES + removed_api.cpp INCLUDE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR} LIBRARIES @@ -22,11 +28,6 @@ qt_internal_add_module(SerialPort ## Scopes: ##################################################################### -qt_internal_extend_target(SerialPort CONDITION config_ntddmodm - DEFINES - QT_NO_REDEFINE_GUID_DEVINTERFACE_MODEM -) - qt_internal_extend_target(SerialPort CONDITION QT_FEATURE_libudev AND UNIX DEFINES LINK_LIBUDEV diff --git a/src/serialport/configure.cmake b/src/serialport/configure.cmake index a9ce0492..21606039 100644 --- a/src/serialport/configure.cmake +++ b/src/serialport/configure.cmake @@ -1,3 +1,6 @@ +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + #### Inputs @@ -37,7 +40,7 @@ qt_feature("ntddmodm" PRIVATE CONDITION TEST_ntddmodm DISABLE INPUT_ntddmodm STREQUAL 'no' ) -qt_feature_definition("ntddmodm" "QT_NO_REDEFINE_GUID_DEVINTERFACE_MODEM" NEGATE) +qt_feature_definition("ntddmodm" "QT_NO_REDEFINE_GUID_DEVINTERFACE_MODEM") qt_configure_add_summary_section(NAME "Serial Port") qt_configure_add_summary_entry(ARGS "ntddmodm") qt_configure_end_summary_section() # end of "Serial Port" section diff --git a/src/serialport/doc/images/blockingreceiver-example.png b/src/serialport/doc/images/blockingreceiver-example.png Binary files differindex c02ae859..7bdafde6 100644 --- a/src/serialport/doc/images/blockingreceiver-example.png +++ b/src/serialport/doc/images/blockingreceiver-example.png diff --git a/src/serialport/doc/images/blockingsender-example.png b/src/serialport/doc/images/blockingsender-example.png Binary files differindex 9b5fc4a6..14ee55c5 100644 --- a/src/serialport/doc/images/blockingsender-example.png +++ b/src/serialport/doc/images/blockingsender-example.png diff --git a/src/serialport/doc/images/cenumerator-example.png b/src/serialport/doc/images/cenumerator-example.png Binary files differdeleted file mode 100644 index 03792e71..00000000 --- a/src/serialport/doc/images/cenumerator-example.png +++ /dev/null diff --git a/src/serialport/doc/images/creaderasync-example.png b/src/serialport/doc/images/creaderasync-example.png Binary files differdeleted file mode 100644 index ffa3636a..00000000 --- a/src/serialport/doc/images/creaderasync-example.png +++ /dev/null diff --git a/src/serialport/doc/images/creadersync-example.png b/src/serialport/doc/images/creadersync-example.png Binary files differdeleted file mode 100644 index 476dcbe4..00000000 --- a/src/serialport/doc/images/creadersync-example.png +++ /dev/null diff --git a/src/serialport/doc/images/cwriterasync-example.png b/src/serialport/doc/images/cwriterasync-example.png Binary files differdeleted file mode 100644 index ebe11dc8..00000000 --- a/src/serialport/doc/images/cwriterasync-example.png +++ /dev/null diff --git a/src/serialport/doc/images/cwritersync-example.png b/src/serialport/doc/images/cwritersync-example.png Binary files differdeleted file mode 100644 index 669985d2..00000000 --- a/src/serialport/doc/images/cwritersync-example.png +++ /dev/null diff --git a/src/serialport/doc/images/enumerator-example.png b/src/serialport/doc/images/enumerator-example.png Binary files differdeleted file mode 100644 index c96d990c..00000000 --- a/src/serialport/doc/images/enumerator-example.png +++ /dev/null diff --git a/src/serialport/doc/images/terminal-example.png b/src/serialport/doc/images/terminal-example.png Binary files differindex 9affaae1..7cdbd213 100644 --- a/src/serialport/doc/images/terminal-example.png +++ b/src/serialport/doc/images/terminal-example.png diff --git a/src/serialport/doc/qtserialport.qdocconf b/src/serialport/doc/qtserialport.qdocconf index 270449fb..a852fb3d 100644 --- a/src/serialport/doc/qtserialport.qdocconf +++ b/src/serialport/doc/qtserialport.qdocconf @@ -27,12 +27,16 @@ qhp.QtSerialPort.subprojects.examples.sortPages = true headerdirs += .. sourcedirs += .. -exampledirs += ../../../examples/serialport +exampledirs += \ + ../../../examples/serialport \ + snippets + +excludedirs += snippets imagedirs += images examplesinstallpath = serialport -depends += qtcore qtdoc qtnetwork qmake +depends += qtcore qtdoc qtnetwork qmake qtcmake navigation.landingpage = "Qt Serial Port" navigation.cppclassespage = "Qt Serial Port C++ Classes" diff --git a/src/serialport/doc/snippets/doc_src_serialport.cpp b/src/serialport/doc/snippets/doc_src_serialport.cpp new file mode 100644 index 00000000..11476c91 --- /dev/null +++ b/src/serialport/doc/snippets/doc_src_serialport.cpp @@ -0,0 +1,41 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause + +#include <QtCore/qcoreapplication.h> +#include <QtCore/qdebug.h> + +#include <QtSerialPort/qserialportinfo.h> + +void enumeratePorts() +{ +//! [enumerate_ports] + const auto serialPortInfos = QSerialPortInfo::availablePorts(); + for (const QSerialPortInfo &portInfo : serialPortInfos) { + qDebug() << "\n" + << "Port:" << portInfo.portName() << "\n" + << "Location:" << portInfo.systemLocation() << "\n" + << "Description:" << portInfo.description() << "\n" + << "Manufacturer:" << portInfo.manufacturer() << "\n" + << "Serial number:" << portInfo.serialNumber() << "\n" + << "Vendor Identifier:" + << (portInfo.hasVendorIdentifier() + ? QByteArray::number(portInfo.vendorIdentifier(), 16) + : QByteArray()) << "\n" + << "Product Identifier:" + << (portInfo.hasProductIdentifier() + ? QByteArray::number(portInfo.productIdentifier(), 16) + : QByteArray()); + } +//! [enumerate_ports] +} + +int main(int argc, char **argv) +{ + QCoreApplication app(argc, argv); + + enumeratePorts(); + + return app.exec(); +} + +#include "doc_src_serialport.moc" diff --git a/src/serialport/doc/src/index.qdoc b/src/serialport/doc/src/index.qdoc index 2c349e44..3da928c2 100644 --- a/src/serialport/doc/src/index.qdoc +++ b/src/serialport/doc/src/index.qdoc @@ -1,29 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2011 - 2012 Denis Shienkov <denis.shienkov@gmail.com> -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:FDL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Free Documentation License Usage -** Alternatively, this file may be used under the terms of the GNU Free -** Documentation License version 1.3 as published by the Free Software -** Foundation and appearing in the file included in the packaging of -** this file. Please review the following information to ensure -** the GNU Free Documentation License version 1.3 requirements -** will be met: https://www.gnu.org/licenses/fdl-1.3.html. -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2011 - 2012 Denis Shienkov <denis.shienkov@gmail.com> +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only /*! \page qtserialport-index.html @@ -31,39 +7,29 @@ \title Qt Serial Port \brief Provides an API to make serial programming simple and portable. - Qt Serial Port provides the basic functionality, which includes - configuring, I/O operations, getting and setting the control signals of the - RS-232 pinouts. + Qt Serial Port provides basic functionality for configuration, I/O + operations, and getting and setting the control signals of the RS-232 + pinouts. The following items are not supported by this module: \list \li Terminal features, such as echo, control CR/LF, and so on. - \li Text mode. - \li Configuring timeouts and delays while reading or writing. - \li Pinout signal change notification. + \li Text mode display for data transfer. + \li Timeout and delay configuration while reading or writing. + \li Notification on changing pinout signal. \endlist - To use the serial port in your application, add the following include - statement: + \section1 Using the Module - \code - #include <QSerialPort> - \endcode + \include {module-use.qdocinc} {using the c++ api} - For information about available serial ports, use the following include - statement: + \section2 Building with CMake - \code - #include <QSerialPortInfo> - \endcode + \include {module-use.qdocinc} {building with cmake} {SerialPort} - To use the module with cmake, use the \c{find_package()} command to locate - the needed module components in the \c{Qt6} package: - \include qtserialport-module-use.qdocinc cmakebuild + \section2 Building with qmake - To use the module for building with qmake, add the module as a value of the - \c QT variable in the project's .pro file: - \include qtserialport-module-use.qdocinc qmakebuild + \include {module-use.qdocinc} {building_with_qmake} {serialport} \section1 Module Evolution \l{Changes to Qt SerialPort} lists important changes in the module API diff --git a/src/serialport/doc/src/qt6-changes.qdoc b/src/serialport/doc/src/qt6-changes.qdoc index aaab6bfb..d3ded94c 100644 --- a/src/serialport/doc/src/qt6-changes.qdoc +++ b/src/serialport/doc/src/qt6-changes.qdoc @@ -1,29 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2021 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:FDL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Free Documentation License Usage -** Alternatively, this file may be used under the terms of the GNU Free -** Documentation License version 1.3 as published by the Free Software -** Foundation and appearing in the file included in the packaging of -** this file. Please review the following information to ensure -** the GNU Free Documentation License version 1.3 requirements -** will be met: https://www.gnu.org/licenses/fdl-1.3.html. -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2021 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only /*! \page qtserialport-changes-qt6.html diff --git a/src/serialport/doc/src/qtserialport-examples.qdoc b/src/serialport/doc/src/qtserialport-examples.qdoc index c6802249..51bd9491 100644 --- a/src/serialport/doc/src/qtserialport-examples.qdoc +++ b/src/serialport/doc/src/qtserialport-examples.qdoc @@ -1,31 +1,7 @@ -/**************************************************************************** -** -** Copyright (C) 2011-2012 Denis Shienkov <denis.shienkov@gmail.com> -** Copyright (C) 2012 Laszlo Papp <lpapp@kde.org> -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:FDL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Free Documentation License Usage -** Alternatively, this file may be used under the terms of the GNU Free -** Documentation License version 1.3 as published by the Free Software -** Foundation and appearing in the file included in the packaging of -** this file. Please review the following information to ensure -** the GNU Free Documentation License version 1.3 requirements -** will be met: https://www.gnu.org/licenses/fdl-1.3.html. -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2011-2012 Denis Shienkov <denis.shienkov@gmail.com> +// Copyright (C) 2012 Laszlo Papp <lpapp@kde.org> +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only /*! \title Qt Serial Port Examples diff --git a/src/serialport/doc/src/qtserialport-module-use.qdocinc b/src/serialport/doc/src/qtserialport-module-use.qdocinc index 47c5b24b..e723fd93 100644 --- a/src/serialport/doc/src/qtserialport-module-use.qdocinc +++ b/src/serialport/doc/src/qtserialport-module-use.qdocinc @@ -1,33 +1,9 @@ -/**************************************************************************** -** -** Copyright (C) 2021 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:FDL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Free Documentation License Usage -** Alternatively, this file may be used under the terms of the GNU Free -** Documentation License version 1.3 as published by the Free Software -** Foundation and appearing in the file included in the packaging of -** this file. Please review the following information to ensure -** the GNU Free Documentation License version 1.3 requirements -** will be met: https://www.gnu.org/licenses/fdl-1.3.html. -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2021 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only //! [cmakebuild] \code - find_package(Qt6 COMPONENTS SerialPort REQUIRED) + find_package(Qt6 REQUIRED COMPONENTS SerialPort) target_link_libraries(mytarget PRIVATE Qt6::SerialPort) \endcode //! [cmakebuild] diff --git a/src/serialport/doc/src/qtserialport-module.qdoc b/src/serialport/doc/src/qtserialport-module.qdoc index 2496df25..cf4523be 100644 --- a/src/serialport/doc/src/qtserialport-module.qdoc +++ b/src/serialport/doc/src/qtserialport-module.qdoc @@ -1,29 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2011 - 2012 Denis Shienkov <denis.shienkov@gmail.com> -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:FDL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Free Documentation License Usage -** Alternatively, this file may be used under the terms of the GNU Free -** Documentation License version 1.3 as published by the Free Software -** Foundation and appearing in the file included in the packaging of -** this file. Please review the following information to ensure -** the GNU Free Documentation License version 1.3 requirements -** will be met: https://www.gnu.org/licenses/fdl-1.3.html. -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2011 - 2012 Denis Shienkov <denis.shienkov@gmail.com> +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only /*! \module QtSerialPort diff --git a/src/serialport/qserialport.cpp b/src/serialport/qserialport.cpp index bc9504c2..fadd98eb 100644 --- a/src/serialport/qserialport.cpp +++ b/src/serialport/qserialport.cpp @@ -1,44 +1,8 @@ -/**************************************************************************** -** -** Copyright (C) 2011-2012 Denis Shienkov <denis.shienkov@gmail.com> -** Copyright (C) 2011 Sergey Belyashov <Sergey.Belyashov@gmail.com> -** Copyright (C) 2012 Laszlo Papp <lpapp@kde.org> -** Copyright (C) 2012 Andre Hartmann <aha_1980@gmx.de> -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtSerialPort module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2011-2012 Denis Shienkov <denis.shienkov@gmail.com> +// Copyright (C) 2011 Sergey Belyashov <Sergey.Belyashov@gmail.com> +// Copyright (C) 2012 Laszlo Papp <lpapp@kde.org> +// Copyright (C) 2012 Andre Hartmann <aha_1980@gmx.de> +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #include "qserialport.h" #include "qserialportinfo.h" @@ -101,6 +65,7 @@ void QSerialPortPrivate::setError(const QSerialPortErrorInfo &errorInfo) q->setErrorString(errorInfo.errorString); error.setValue(errorInfo.errorCode); + error.notify(); emit q->errorOccurred(error); } @@ -606,16 +571,16 @@ qint32 QSerialPort::baudRate(Directions directions) const bool QSerialPort::setDataBits(DataBits dataBits) { Q_D(QSerialPort); - - const auto currentDataBits = d->dataBits.value(); + d->dataBits.removeBindingUnlessInWrapper(); + const auto currentDataBits = d->dataBits.valueBypassingBindings(); if (!isOpen() || d->setDataBits(dataBits)) { - d->dataBits.setValue(dataBits); - if (currentDataBits != dataBits) + d->dataBits.setValueBypassingBindings(dataBits); + if (currentDataBits != dataBits) { + d->dataBits.notify(); emit dataBitsChanged(dataBits); + } return true; } - d->dataBits.setValue(currentDataBits); // removes the binding if necessary, keep - return false; } @@ -657,16 +622,16 @@ QBindable<QSerialPort::DataBits> QSerialPort::bindableDataBits() bool QSerialPort::setParity(Parity parity) { Q_D(QSerialPort); - - const auto currentParity = d->parity.value(); + d->parity.removeBindingUnlessInWrapper(); + const auto currentParity = d->parity.valueBypassingBindings(); if (!isOpen() || d->setParity(parity)) { - d->parity.setValue(parity); - if (currentParity != parity) + d->parity.setValueBypassingBindings(parity); + if (currentParity != parity) { + d->parity.notify(); emit parityChanged(parity); + } return true; } - d->parity.setValue(currentParity); // removes the binding if necessary, keep - return false; } @@ -707,16 +672,16 @@ QBindable<QSerialPort::Parity> QSerialPort::bindableParity() bool QSerialPort::setStopBits(StopBits stopBits) { Q_D(QSerialPort); - - const auto currentStopBits = d->stopBits.value(); + d->stopBits.removeBindingUnlessInWrapper(); + const auto currentStopBits = d->stopBits.valueBypassingBindings(); if (!isOpen() || d->setStopBits(stopBits)) { - d->stopBits.setValue(stopBits); - if (currentStopBits != stopBits) + d->stopBits.setValueBypassingBindings(stopBits); + if (currentStopBits != stopBits) { + d->stopBits.notify(); emit stopBitsChanged(stopBits); + } return true; } - d->stopBits.setValue(currentStopBits); // removes the binding if necessary, keep - return false; } @@ -726,7 +691,7 @@ QSerialPort::StopBits QSerialPort::stopBits() const return d->stopBits; } -QBindable<bool> QSerialPort::bindableStopBits() +QBindable<QSerialPort::StopBits> QSerialPort::bindableStopBits(QT6_IMPL_NEW_OVERLOAD) { return &d_func()->stopBits; } @@ -757,16 +722,16 @@ QBindable<bool> QSerialPort::bindableStopBits() bool QSerialPort::setFlowControl(FlowControl flowControl) { Q_D(QSerialPort); - - const auto currentFlowControl = d->flowControl.value(); + d->flowControl.removeBindingUnlessInWrapper(); + const auto currentFlowControl = d->flowControl.valueBypassingBindings(); if (!isOpen() || d->setFlowControl(flowControl)) { - d->flowControl.setValue(flowControl); - if (currentFlowControl != flowControl) + d->flowControl.setValueBypassingBindings(flowControl); + if (currentFlowControl != flowControl) { + d->flowControl.notify(); emit flowControlChanged(flowControl); + } return true; } - d->flowControl.setValue(currentFlowControl); // removes the binding if necessary, keep - return false; } @@ -1177,21 +1142,21 @@ bool QSerialPort::waitForBytesWritten(int msecs) bool QSerialPort::setBreakEnabled(bool set) { Q_D(QSerialPort); - - const auto currentSet = d->isBreakEnabled.value(); + d->isBreakEnabled.removeBindingUnlessInWrapper(); + const auto currentSet = d->isBreakEnabled.valueBypassingBindings(); if (isOpen()) { if (d->setBreakEnabled(set)) { - d->isBreakEnabled.setValue(set); - if (currentSet != set) + d->isBreakEnabled.setValueBypassingBindings(set); + if (currentSet != set) { + d->isBreakEnabled.notify(); emit breakEnabledChanged(set); + } return true; } } else { d->setError(QSerialPortErrorInfo(QSerialPort::NotOpenError)); qWarning("%s: device not open", Q_FUNC_INFO); } - d->isBreakEnabled.setValue(currentSet); // removes the binding if necessary, keep - return false; } diff --git a/src/serialport/qserialport.h b/src/serialport/qserialport.h index 0170c282..336ead03 100644 --- a/src/serialport/qserialport.h +++ b/src/serialport/qserialport.h @@ -1,47 +1,12 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Denis Shienkov <denis.shienkov@gmail.com> -** Copyright (C) 2013 Laszlo Papp <lpapp@kde.org> -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtSerialPort module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2012 Denis Shienkov <denis.shienkov@gmail.com> +// Copyright (C) 2013 Laszlo Papp <lpapp@kde.org> +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #ifndef QSERIALPORT_H #define QSERIALPORT_H #include <QtCore/qiodevice.h> +#include <QtCore/qproperty.h> #include <QtSerialPort/qserialportglobal.h> @@ -184,7 +149,10 @@ public: bool setStopBits(StopBits stopBits); StopBits stopBits() const; +#if QT_SERIALPORT_REMOVED_SINCE(6, 7) QBindable<bool> bindableStopBits(); +#endif + QBindable<StopBits> bindableStopBits(QT6_DECL_NEW_OVERLOAD); bool setFlowControl(FlowControl flowControl); FlowControl flowControl() const; diff --git a/src/serialport/qserialport_p.h b/src/serialport/qserialport_p.h index a24ed0b4..fd9fee37 100644 --- a/src/serialport/qserialport_p.h +++ b/src/serialport/qserialport_p.h @@ -1,43 +1,7 @@ -/**************************************************************************** -** -** Copyright (C) 2011-2012 Denis Shienkov <denis.shienkov@gmail.com> -** Copyright (C) 2011 Sergey Belyashov <Sergey.Belyashov@gmail.com> -** Copyright (C) 2012 Laszlo Papp <lpapp@kde.org> -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtSerialPort module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2011-2012 Denis Shienkov <denis.shienkov@gmail.com> +// Copyright (C) 2011 Sergey Belyashov <Sergey.Belyashov@gmail.com> +// Copyright (C) 2012 Laszlo Papp <lpapp@kde.org> +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #ifndef QSERIALPORT_P_H #define QSERIALPORT_P_H @@ -60,11 +24,12 @@ #include <private/qiodevice_p.h> #include <private/qproperty_p.h> +#include <memory> + #if defined(Q_OS_WIN32) # include <qt_windows.h> #elif defined(Q_OS_UNIX) # include <QtCore/qlockfile.h> -# include <QtCore/qscopedpointer.h> # include <QtCore/qfileinfo.h> # include <QtCore/qstringlist.h> # include <limits.h> @@ -125,8 +90,9 @@ public: class QSerialPortPrivate : public QIODevicePrivate { - Q_DECLARE_PUBLIC(QSerialPort) public: + Q_DECLARE_PUBLIC(QSerialPort) + QSerialPortPrivate(); bool open(QIODevice::OpenMode mode); @@ -286,7 +252,7 @@ public: qint64 pendingBytesWritten = 0; bool writeSequenceStarted = false; - QScopedPointer<QLockFile> lockFileScopedPointer; + std::unique_ptr<QLockFile> lockFileScopedPointer; #endif }; diff --git a/src/serialport/qserialport_unix.cpp b/src/serialport/qserialport_unix.cpp index 294782b5..7e642e57 100644 --- a/src/serialport/qserialport_unix.cpp +++ b/src/serialport/qserialport_unix.cpp @@ -1,47 +1,12 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Denis Shienkov <denis.shienkov@gmail.com> -** Copyright (C) 2012 Laszlo Papp <lpapp@kde.org> -** Copyright (C) 2012 Andre Hartmann <aha_1980@gmx.de> -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtSerialPort module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2012 Denis Shienkov <denis.shienkov@gmail.com> +// Copyright (C) 2012 Laszlo Papp <lpapp@kde.org> +// Copyright (C) 2012 Andre Hartmann <aha_1980@gmx.de> +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #include "qserialport_p.h" #include "qserialportinfo_p.h" +#include <QtCore/qdeadlinetimer.h> #include <QtCore/qelapsedtimer.h> #include <QtCore/qmap.h> #include <QtCore/qsocketnotifier.h> @@ -55,7 +20,7 @@ #include <sys/time.h> #include <unistd.h> -#ifdef Q_OS_OSX +#ifdef Q_OS_MACOS #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 @@ -316,7 +281,7 @@ bool QSerialPortPrivate::open(QIODevice::OpenMode mode) return false; } - QScopedPointer<QLockFile> newLockFileScopedPointer(new QLockFile(lockFilePath)); + auto newLockFileScopedPointer = std::make_unique<QLockFile>(lockFilePath); if (!newLockFileScopedPointer->tryLock()) { setError(QSerialPortErrorInfo(QSerialPort::PermissionError, QSerialPort::tr("Permission error while locking the device"))); @@ -349,7 +314,7 @@ bool QSerialPortPrivate::open(QIODevice::OpenMode mode) return false; } - lockFileScopedPointer.swap(newLockFileScopedPointer); + lockFileScopedPointer = std::move(newLockFileScopedPointer); return true; } @@ -650,7 +615,7 @@ bool QSerialPortPrivate::setCustomBaudRate(qint32 baudRate, QSerialPort::Directi return setStandardBaudRate(B38400, directions); } -#elif defined(Q_OS_OSX) +#elif defined(Q_OS_MACOS) bool QSerialPortPrivate::setCustomBaudRate(qint32 baudRate, QSerialPort::Directions directions) { @@ -786,7 +751,7 @@ bool QSerialPortPrivate::readNotification() buffer.chop(bytesToRead - qMax(readBytes, qint64(0))); - if (readBytes <= 0) { + if (readBytes < 0) { QSerialPortErrorInfo error = getSystemError(); if (error.errorCode != QSerialPort::ResourceError) error.errorCode = QSerialPort::ReadError; @@ -794,6 +759,8 @@ bool QSerialPortPrivate::readNotification() setReadNotificationEnabled(false); setError(error); return false; + } else if (readBytes == 0) { + return false; } newBytes = buffer.size() - newBytes; @@ -885,6 +852,9 @@ inline bool QSerialPortPrivate::initialize(QIODevice::OpenMode mode) if (mode & QIODevice::ReadOnly) setReadNotificationEnabled(true); + // flush IO buffers + clear(QSerialPort::AllDirections); + return true; } @@ -947,7 +917,7 @@ QSerialPortErrorInfo QSerialPortPrivate::getSystemError(int systemErrorCode) con case EBADF: error.errorCode = QSerialPort::ResourceError; break; -#ifdef Q_OS_OSX +#ifdef Q_OS_MACOS case ENXIO: error.errorCode = QSerialPort::ResourceError; break; @@ -1028,7 +998,7 @@ bool QSerialPortPrivate::waitForReadOrWrite(bool *selectForRead, bool *selectFor if (checkWrite) pfd.events |= POLLOUT; - const int ret = qt_poll_msecs(&pfd, 1, msecs); + const int ret = qt_safe_poll(&pfd, 1, QDeadlineTimer(msecs)); if (ret < 0) { setError(getSystemError()); return false; diff --git a/src/serialport/qserialport_win.cpp b/src/serialport/qserialport_win.cpp index ad3a113a..0bd6343e 100644 --- a/src/serialport/qserialport_win.cpp +++ b/src/serialport/qserialport_win.cpp @@ -1,43 +1,7 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Denis Shienkov <denis.shienkov@gmail.com> -** Copyright (C) 2012 Laszlo Papp <lpapp@kde.org> -** Copyright (C) 2012 Andre Hartmann <aha_1980@gmx.de> -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtSerialPort module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2012 Denis Shienkov <denis.shienkov@gmail.com> +// Copyright (C) 2012 Laszlo Papp <lpapp@kde.org> +// Copyright (C) 2012 Andre Hartmann <aha_1980@gmx.de> +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #include "qserialport_p.h" #include "qwinoverlappedionotifier_p.h" @@ -569,6 +533,12 @@ bool QSerialPortPrivate::startAsyncRead() bool QSerialPortPrivate::_q_startAsyncWrite() { + if (handle == INVALID_HANDLE_VALUE) { + // Prevent a crash if the application incorrectly has not called open() before + // calling this (QTBUG-120412) + return false; + } + if (writeBuffer.isEmpty() || writeStarted) return true; diff --git a/src/serialport/qserialportglobal.h b/src/serialport/qserialportglobal.h index 77a82d3d..8bfd2996 100644 --- a/src/serialport/qserialportglobal.h +++ b/src/serialport/qserialportglobal.h @@ -1,42 +1,6 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Denis Shienkov <denis.shienkov@gmail.com> -** Copyright (C) 2012 Laszlo Papp <lpapp@kde.org> -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtSerialPort module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2012 Denis Shienkov <denis.shienkov@gmail.com> +// Copyright (C) 2012 Laszlo Papp <lpapp@kde.org> +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #ifndef QSERIALPORTGLOBAL_H #define QSERIALPORTGLOBAL_H diff --git a/src/serialport/qserialportinfo.cpp b/src/serialport/qserialportinfo.cpp index d823eac7..be58f694 100644 --- a/src/serialport/qserialportinfo.cpp +++ b/src/serialport/qserialportinfo.cpp @@ -1,43 +1,7 @@ -/**************************************************************************** -** -** Copyright (C) 2011-2012 Denis Shienkov <denis.shienkov@gmail.com> -** Copyright (C) 2011 Sergey Belyashov <Sergey.Belyashov@gmail.com> -** Copyright (C) 2012 Laszlo Papp <lpapp@kde.org> -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtSerialPort module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2011-2012 Denis Shienkov <denis.shienkov@gmail.com> +// Copyright (C) 2011 Sergey Belyashov <Sergey.Belyashov@gmail.com> +// Copyright (C) 2012 Laszlo Papp <lpapp@kde.org> +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #include "qserialportinfo.h" #include "qserialportinfo_p.h" @@ -46,6 +10,12 @@ QT_BEGIN_NAMESPACE +// We changed from QScopedPointer to std::unique_ptr, make sure it's +// binary compatible. The QScopedPointer had a non-default deleter, but +// the deleter just provides a static function to use for deletion so we don't +// include it in this template definition (the deleter-class was deleted). +static_assert(sizeof(std::unique_ptr<QSerialPortInfoPrivate>) + == sizeof(QScopedPointer<QSerialPortInfoPrivate>)); /*! \class QSerialPortInfo @@ -56,12 +26,20 @@ QT_BEGIN_NAMESPACE \inmodule QtSerialPort \since 5.1 - Use the static functions to generate a list of QSerialPortInfo - objects. Each QSerialPortInfo object in the list represents a single - serial port and can be queried for the port name, system location, - description, and manufacturer. The QSerialPortInfo class can also be - used as an input parameter for the setPort() method of the QSerialPort - class. + Use the static \l availablePorts() function to generate a list of + QSerialPortInfo objects. Each QSerialPortInfo object in the list represents + a single serial port and can be queried for the \l {portName}{port name}, + \l {systemLocation}{system location}, \l description, \l manufacturer, and + some other hardware parameters. The QSerialPortInfo class can also be + used as an input parameter for the \l {QSerialPort::}{setPort()} method of + the QSerialPort class. + + \section1 Example Usage + + The example code enumerates all available serial ports and prints their + parameters to console: + + \snippet doc_src_serialport.cpp enumerate_ports \sa QSerialPort */ diff --git a/src/serialport/qserialportinfo.h b/src/serialport/qserialportinfo.h index 9ef8c22d..d6c1e668 100644 --- a/src/serialport/qserialportinfo.h +++ b/src/serialport/qserialportinfo.h @@ -1,42 +1,6 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Denis Shienkov <denis.shienkov@gmail.com> -** Copyright (C) 2012 Laszlo Papp <lpapp@kde.org> -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtSerialPort module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2012 Denis Shienkov <denis.shienkov@gmail.com> +// Copyright (C) 2012 Laszlo Papp <lpapp@kde.org> +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #ifndef QSERIALPORTINFO_H #define QSERIALPORTINFO_H @@ -50,7 +14,6 @@ QT_BEGIN_NAMESPACE class QSerialPort; class QSerialPortInfoPrivate; -class QSerialPortInfoPrivateDeleter; class Q_SERIALPORT_EXPORT QSerialPortInfo { @@ -87,7 +50,7 @@ private: friend QList<QSerialPortInfo> availablePortsByUdev(bool &ok); friend QList<QSerialPortInfo> availablePortsBySysfs(bool &ok); friend QList<QSerialPortInfo> availablePortsByFiltersOfDevices(bool &ok); - QScopedPointer<QSerialPortInfoPrivate, QSerialPortInfoPrivateDeleter> d_ptr; + std::unique_ptr<QSerialPortInfoPrivate> d_ptr; }; inline bool QSerialPortInfo::isNull() const diff --git a/src/serialport/qserialportinfo_freebsd.cpp b/src/serialport/qserialportinfo_freebsd.cpp index 53416c28..5852cd7b 100644 --- a/src/serialport/qserialportinfo_freebsd.cpp +++ b/src/serialport/qserialportinfo_freebsd.cpp @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 Denis Shienkov <denis.shienkov@gmail.com> -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtSerialPort module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 Denis Shienkov <denis.shienkov@gmail.com> +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #include "qserialportinfo.h" #include "qserialportinfo_p.h" @@ -320,10 +284,10 @@ QList<QSerialPortInfo> QSerialPortInfo::availablePorts() QList<QSerialPortInfo> serialPortInfoList; - for (const QSerialPortInfo &cuaCandidate : qAsConst(cuaCandidates)) { + for (const QSerialPortInfo &cuaCandidate : std::as_const(cuaCandidates)) { const QString cuaPortName = cuaCandidate.portName(); const QString cuaToken = deviceProperty(cuaPortName, "cua"); - for (const QSerialPortInfo &ttyCandidate : qAsConst(ttyCandidates)) { + for (const QSerialPortInfo &ttyCandidate : std::as_const(ttyCandidates)) { const QString ttyPortName = ttyCandidate.portName(); const QString ttyToken = deviceProperty(ttyPortName, "tty"); if (cuaToken != ttyToken) diff --git a/src/serialport/qserialportinfo_osx.cpp b/src/serialport/qserialportinfo_osx.cpp index 8daa8a7e..203b084c 100644 --- a/src/serialport/qserialportinfo_osx.cpp +++ b/src/serialport/qserialportinfo_osx.cpp @@ -1,43 +1,7 @@ -/**************************************************************************** -** -** Copyright (C) 2011-2012 Denis Shienkov <denis.shienkov@gmail.com> -** Copyright (C) 2011 Sergey Belyashov <Sergey.Belyashov@gmail.com> -** Copyright (C) 2012 Laszlo Papp <lpapp@kde.org> -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtSerialPort module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2011-2012 Denis Shienkov <denis.shienkov@gmail.com> +// Copyright (C) 2011 Sergey Belyashov <Sergey.Belyashov@gmail.com> +// Copyright (C) 2012 Laszlo Papp <lpapp@kde.org> +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #include "qserialportinfo.h" #include "qserialportinfo_p.h" diff --git a/src/serialport/qserialportinfo_p.h b/src/serialport/qserialportinfo_p.h index 405cc419..1a949f08 100644 --- a/src/serialport/qserialportinfo_p.h +++ b/src/serialport/qserialportinfo_p.h @@ -1,43 +1,7 @@ -/**************************************************************************** -** -** Copyright (C) 2011-2012 Denis Shienkov <denis.shienkov@gmail.com> -** Copyright (C) 2011 Sergey Belyashov <Sergey.Belyashov@gmail.com> -** Copyright (C) 2012 Laszlo Papp <lpapp@kde.org> -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtSerialPort module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2011-2012 Denis Shienkov <denis.shienkov@gmail.com> +// Copyright (C) 2017 Sergey Belyashov <Sergey.Belyashov@gmail.com> +// Copyright (C) 2013 Laszlo Papp <lpapp@kde.org> +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #ifndef QSERIALPORTINFO_P_H #define QSERIALPORTINFO_P_H @@ -54,6 +18,7 @@ // #include <QtCore/qstring.h> +#include <QtCore/private/qglobal_p.h> QT_BEGIN_NAMESPACE @@ -76,14 +41,6 @@ public: bool hasProductIdentifier = false; }; -class QSerialPortInfoPrivateDeleter -{ -public: - static void cleanup(QSerialPortInfoPrivate *p) { - delete p; - } -}; - QT_END_NAMESPACE #endif // QSERIALPORTINFO_P_H diff --git a/src/serialport/qserialportinfo_unix.cpp b/src/serialport/qserialportinfo_unix.cpp index 93760e22..4f9304bf 100644 --- a/src/serialport/qserialportinfo_unix.cpp +++ b/src/serialport/qserialportinfo_unix.cpp @@ -1,43 +1,7 @@ -/**************************************************************************** -** -** Copyright (C) 2011-2012 Denis Shienkov <denis.shienkov@gmail.com> -** Copyright (C) 2011 Sergey Belyashov <Sergey.Belyashov@gmail.com> -** Copyright (C) 2012 Laszlo Papp <lpapp@kde.org> -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtSerialPort module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2011-2012 Denis Shienkov <denis.shienkov@gmail.com> +// Copyright (C) 2011 Sergey Belyashov <Sergey.Belyashov@gmail.com> +// Copyright (C) 2012 Laszlo Papp <lpapp@kde.org> +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #include "qserialportinfo.h" #include "qserialportinfo_p.h" @@ -46,10 +10,11 @@ #include <QtCore/qlockfile.h> #include <QtCore/qfile.h> #include <QtCore/qdir.h> -#include <QtCore/qscopedpointer.h> #include <private/qcore_unix_p.h> +#include <memory> + #include <errno.h> #include <sys/types.h> // kill #include <signal.h> // kill @@ -313,29 +278,22 @@ QList<QSerialPortInfo> availablePortsBySysfs(bool &ok) return serialPortInfoList; } -struct ScopedPointerUdevDeleter -{ - static inline void cleanup(struct ::udev *pointer) +struct udev_deleter { + void operator()(struct ::udev *pointer) const { ::udev_unref(pointer); } -}; - -struct ScopedPointerUdevEnumeratorDeleter -{ - static inline void cleanup(struct ::udev_enumerate *pointer) + void operator()(struct ::udev_enumerate *pointer) const { ::udev_enumerate_unref(pointer); } -}; - -struct ScopedPointerUdevDeviceDeleter -{ - static inline void cleanup(struct ::udev_device *pointer) + void operator()(struct ::udev_device *pointer) const { ::udev_device_unref(pointer); } }; +template <typename T> +using udev_ptr = std::unique_ptr<T, udev_deleter>; #ifndef LINK_LIBUDEV Q_GLOBAL_STATIC(QLibrary, udevLibrary) @@ -396,21 +354,20 @@ QList<QSerialPortInfo> availablePortsByUdev(bool &ok) return QList<QSerialPortInfo>(); #endif - QScopedPointer<struct ::udev, ScopedPointerUdevDeleter> udev(::udev_new()); + const udev_ptr<struct ::udev> udev(::udev_new()); if (!udev) return QList<QSerialPortInfo>(); - QScopedPointer<udev_enumerate, ScopedPointerUdevEnumeratorDeleter> - enumerate(::udev_enumerate_new(udev.data())); + const udev_ptr<udev_enumerate> enumerate(::udev_enumerate_new(udev.get())); if (!enumerate) return QList<QSerialPortInfo>(); - ::udev_enumerate_add_match_subsystem(enumerate.data(), "tty"); - ::udev_enumerate_scan_devices(enumerate.data()); + ::udev_enumerate_add_match_subsystem(enumerate.get(), "tty"); + ::udev_enumerate_scan_devices(enumerate.get()); - udev_list_entry *devices = ::udev_enumerate_get_list_entry(enumerate.data()); + udev_list_entry *devices = ::udev_enumerate_get_list_entry(enumerate.get()); QList<QSerialPortInfo> serialPortInfoList; udev_list_entry *dev_list_entry; @@ -418,29 +375,29 @@ QList<QSerialPortInfo> availablePortsByUdev(bool &ok) ok = true; - QScopedPointer<udev_device, ScopedPointerUdevDeviceDeleter> + const udev_ptr<udev_device> dev(::udev_device_new_from_syspath( - udev.data(), ::udev_list_entry_get_name(dev_list_entry))); + udev.get(), ::udev_list_entry_get_name(dev_list_entry))); if (!dev) return serialPortInfoList; QSerialPortInfoPrivate priv; - priv.device = deviceLocation(dev.data()); - priv.portName = deviceName(dev.data()); + priv.device = deviceLocation(dev.get()); + priv.portName = deviceName(dev.get()); - udev_device *parentdev = ::udev_device_get_parent(dev.data()); + udev_device *parentdev = ::udev_device_get_parent(dev.get()); if (parentdev) { const QString driverName = deviceDriver(parentdev); if (isSerial8250Driver(driverName) && !isValidSerial8250(priv.device)) continue; - priv.description = deviceDescription(dev.data()); - priv.manufacturer = deviceManufacturer(dev.data()); - priv.serialNumber = deviceSerialNumber(dev.data()); - priv.vendorIdentifier = deviceVendorIdentifier(dev.data(), priv.hasVendorIdentifier); - priv.productIdentifier = deviceProductIdentifier(dev.data(), priv.hasProductIdentifier); + priv.description = deviceDescription(dev.get()); + priv.manufacturer = deviceManufacturer(dev.get()); + priv.serialNumber = deviceSerialNumber(dev.get()); + priv.vendorIdentifier = deviceVendorIdentifier(dev.get(), priv.hasVendorIdentifier); + priv.productIdentifier = deviceProductIdentifier(dev.get(), priv.hasProductIdentifier); } else { if (!isRfcommDevice(priv.portName) && !isVirtualNullModemDevice(priv.portName) diff --git a/src/serialport/qserialportinfo_win.cpp b/src/serialport/qserialportinfo_win.cpp index 2c584471..30159f1c 100644 --- a/src/serialport/qserialportinfo_win.cpp +++ b/src/serialport/qserialportinfo_win.cpp @@ -1,43 +1,7 @@ -/**************************************************************************** -** -** Copyright (C) 2011-2012 Denis Shienkov <denis.shienkov@gmail.com> -** Copyright (C) 2011 Sergey Belyashov <Sergey.Belyashov@gmail.com> -** Copyright (C) 2012 Laszlo Papp <lpapp@kde.org> -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtSerialPort module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2011-2012 Denis Shienkov <denis.shienkov@gmail.com> +// Copyright (C) 2011 Sergey Belyashov <Sergey.Belyashov@gmail.com> +// Copyright (C) 2012 Laszlo Papp <lpapp@kde.org> +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #include "qserialportinfo.h" #include "qserialportinfo_p.h" diff --git a/src/serialport/qtudev_p.h b/src/serialport/qtudev_p.h index af2dab2e..311fa753 100644 --- a/src/serialport/qtudev_p.h +++ b/src/serialport/qtudev_p.h @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Laszlo Papp <lpapp@kde.org> -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtSerialPort module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2013 Laszlo Papp <lpapp@kde.org> +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #ifndef QTUDEV_P_H #define QTUDEV_P_H @@ -60,6 +24,7 @@ extern "C" #include <QtCore/qlibrary.h> #include <QtCore/qstring.h> #include <QtCore/qdebug.h> +#include <QtCore/private/qglobal_p.h> #define GENERATE_SYMBOL_VARIABLE(returnType, symbolName, ...) \ typedef returnType (*fp_##symbolName)(__VA_ARGS__); \ diff --git a/src/serialport/qwinoverlappedionotifier.cpp b/src/serialport/qwinoverlappedionotifier.cpp index 08561685..3e85fd84 100644 --- a/src/serialport/qwinoverlappedionotifier.cpp +++ b/src/serialport/qwinoverlappedionotifier.cpp @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtCore module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #include "qwinoverlappedionotifier_p.h" #include <qdebug.h> @@ -129,6 +93,7 @@ public: HANDLE hSemaphore = nullptr; HANDLE hResultsMutex = nullptr; QAtomicInt waiting; + QAtomicInt signalSent; QQueue<IOResult> results; }; @@ -395,16 +360,45 @@ void QWinOverlappedIoNotifierPrivate::notify(DWORD numberOfBytes, DWORD errorCod Q_Q(QWinOverlappedIoNotifier); WaitForSingleObject(hResultsMutex, INFINITE); results.enqueue(IOResult(numberOfBytes, errorCode, overlapped)); - ReleaseMutex(hResultsMutex); ReleaseSemaphore(hSemaphore, 1, NULL); - if (!waiting) + ReleaseMutex(hResultsMutex); + // Do not send a signal if we didn't process the previous one. + // This is done to prevent soft memory leaks when working in a completely + // synchronous way. + if (!waiting && !signalSent.loadAcquire()) { + signalSent.storeRelease(1); emit q->_q_notify(); + } } void QWinOverlappedIoNotifierPrivate::_q_notified() { - if (WaitForSingleObject(hSemaphore, 0) == WAIT_OBJECT_0) - dispatchNextIoResult(); + Q_Q(QWinOverlappedIoNotifier); + signalSent.storeRelease(0); // signal processed - ready for a new one + if (WaitForSingleObject(hSemaphore, 0) == WAIT_OBJECT_0) { + // As we do not queue signals anymore, we need to process the whole + // queue at once. + WaitForSingleObject(hResultsMutex, INFINITE); + QQueue<IOResult> values; + results.swap(values); + // Decreasing the semaphore count to keep it in sync with the number + // of messages in queue. As ReleaseSemaphore does not accept negative + // values, this is sort of a recommended way to go: + // https://learn.microsoft.com/en-us/windows/win32/api/synchapi/nf-synchapi-releasesemaphore#remarks + int numToDecrease = values.size() - 1; + while (numToDecrease > 0) { + WaitForSingleObject(hSemaphore, 0); + --numToDecrease; + } + ReleaseMutex(hResultsMutex); + // 'q' can go out of scope if the user decides to close the serial port + // while processing some answer. So we need to guard against that. + QPointer<QWinOverlappedIoNotifier> qptr(q); + while (!values.empty() && qptr) { + IOResult ioresult = values.dequeue(); + emit qptr->notified(ioresult.numberOfBytes, ioresult.errorCode, ioresult.overlapped); + } + } } OVERLAPPED *QWinOverlappedIoNotifierPrivate::dispatchNextIoResult() diff --git a/src/serialport/qwinoverlappedionotifier_p.h b/src/serialport/qwinoverlappedionotifier_p.h index 9ee998bd..45d252e2 100644 --- a/src/serialport/qwinoverlappedionotifier_p.h +++ b/src/serialport/qwinoverlappedionotifier_p.h @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtCore module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #ifndef QWINOVERLAPPEDIONOTIFIER_P_H #define QWINOVERLAPPEDIONOTIFIER_P_H diff --git a/src/serialport/removed_api.cpp b/src/serialport/removed_api.cpp new file mode 100644 index 00000000..1d9fe2f7 --- /dev/null +++ b/src/serialport/removed_api.cpp @@ -0,0 +1,20 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only + +#define QT_SERIALPORT_BUILD_REMOVED_API + +#include "qserialportglobal.h" + +QT_USE_NAMESPACE + +#if QT_SERIALPORT_REMOVED_SINCE(6, 7) + +#include "qserialport.h" +#include "qserialport_p.h" + +QBindable<bool> QSerialPort::bindableStopBits() +{ + return &d_func()->stopBits; +} + +#endif // QT_SERIALPORT_REMOVED_SINCE(6, 7) |