Skip to content

Commit

Permalink
QtAndroidSerialPort: Rebase on Latest QSerialPortInfo (#11525)
Browse files Browse the repository at this point in the history
  • Loading branch information
HTRamsey authored May 14, 2024
1 parent 0fa19b5 commit 71efca9
Show file tree
Hide file tree
Showing 9 changed files with 225 additions and 284 deletions.
3 changes: 3 additions & 0 deletions libs/qtandroidserialport/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@ qt_add_library(qtandroidserialport STATIC
qserialport_p.h
qserialport_android.cpp
qserialport_android_p.h
qserialportglobal.h
qserialportinfo.cpp
qserialportinfo.h
qserialportinfo_p.h
qserialportinfo_android.cpp
qtserialportexports.h
qtserialportversion.h
)

target_link_libraries(qtandroidserialport
Expand Down
12 changes: 12 additions & 0 deletions libs/qtandroidserialport/qserialportglobal.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright (C) 2012 Denis Shienkov <[email protected]>
// Copyright (C) 2012 Laszlo Papp <[email protected]>
// 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

#include <QtCore/qstring.h>
#include <QtCore/qglobal.h>
#include "qtserialportexports.h"

#endif // QSERIALPORTGLOBAL_H
121 changes: 42 additions & 79 deletions libs/qtandroidserialport/qserialportinfo.cpp
Original file line number Diff line number Diff line change
@@ -1,44 +1,21 @@
/****************************************************************************
**
** Copyright (C) 2011-2012 Denis Shienkov <[email protected]>
** Copyright (C) 2011 Sergey Belyashov <[email protected]>
** Copyright (C) 2012 Laszlo Papp <[email protected]>
** Contact: http://www.qt.io/licensing/
**
** This file is part of the QtSerialPort module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL21$
** 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 http://www.qt.io/terms-conditions. For further
** information use the contact form at http://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 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** As a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** $QT_END_LICENSE$
**
****************************************************************************/
// Copyright (C) 2011-2012 Denis Shienkov <[email protected]>
// Copyright (C) 2011 Sergey Belyashov <[email protected]>
// Copyright (C) 2012 Laszlo Papp <[email protected]>
// 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"
#include "qserialport.h"
#include "qserialport_android_p.h"

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
Expand All @@ -49,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
*/
Expand All @@ -72,21 +57,16 @@ QSerialPortInfo::QSerialPortInfo()
Constructs a copy of \a other.
*/
QSerialPortInfo::QSerialPortInfo(const QSerialPortInfo &other)
: d_ptr(other.d_ptr ? new QSerialPortInfoPrivate(*other.d_ptr) : Q_NULLPTR)
: d_ptr(other.d_ptr ? new QSerialPortInfoPrivate(*other.d_ptr) : nullptr)
{
}

/*!
Constructs a QSerialPortInfo object from serial \a port.
*/
QSerialPortInfo::QSerialPortInfo(const QSerialPort &port)
: QSerialPortInfo(port.portName())
{
foreach (const QSerialPortInfo &serialPortInfo, availablePorts()) {
if (port.portName() == serialPortInfo.portName()) {
*this = serialPortInfo;
break;
}
}
}

/*!
Expand All @@ -98,9 +78,10 @@ QSerialPortInfo::QSerialPortInfo(const QSerialPort &port)
*/
QSerialPortInfo::QSerialPortInfo(const QString &name)
{
foreach (const QSerialPortInfo &serialPortInfo, availablePorts()) {
if (name == serialPortInfo.portName()) {
*this = serialPortInfo;
const auto infos = QSerialPortInfo::availablePorts();
for (const QSerialPortInfo &info : infos) {
if (name == info.portName()) {
*this = info;
break;
}
}
Expand All @@ -119,8 +100,7 @@ QSerialPortInfo::~QSerialPortInfo()
{
}

/*! \fn void QSerialPortInfo::swap(QSerialPortInfo &other)
/*!
Swaps QSerialPortInfo \a other with this QSerialPortInfo. This operation is
very fast and never fails.
*/
Expand Down Expand Up @@ -225,8 +205,8 @@ quint16 QSerialPortInfo::productIdentifier() const
}

/*!
Returns true if there is a valid 16-bit vendor number present; otherwise
returns false.
Returns \c true if there is a valid \c 16-bit vendor number present; otherwise
returns \c false.
\sa vendorIdentifier(), productIdentifier(), hasProductIdentifier()
*/
Expand All @@ -237,8 +217,8 @@ bool QSerialPortInfo::hasVendorIdentifier() const
}

/*!
Returns true if there is a valid 16-bit product number present; otherwise
returns false.
Returns \c true if there is a valid \c 16-bit product number present; otherwise
returns \c false.
\sa productIdentifier(), vendorIdentifier(), hasVendorIdentifier()
*/
Expand All @@ -253,35 +233,18 @@ bool QSerialPortInfo::hasProductIdentifier() const
Returns whether this QSerialPortInfo object holds a
serial port definition.
\sa isBusy()
*/

/*!
\fn bool QSerialPortInfo::isBusy() const
Returns true if serial port is busy;
otherwise returns false.
\sa isNull()
*/

/*!
\fn bool QSerialPortInfo::isValid() const
\obsolete
Returns true if serial port is present on system;
otherwise returns false.
\sa isNull(), isBusy()
*/

/*!
\fn QList<qint32> QSerialPortInfo::standardBaudRates()
Returns a list of available standard baud rates supported by
the current serial port.
Returns a list of available standard baud rates supported
by the target platform.
*/
QList<qint32> QSerialPortInfo::standardBaudRates()
{
return QSerialPortPrivate::standardBaudRates();
}

/*!
\fn QList<QSerialPortInfo> QSerialPortInfo::availablePorts()
Expand Down
49 changes: 8 additions & 41 deletions libs/qtandroidserialport/qserialportinfo.h
Original file line number Diff line number Diff line change
@@ -1,49 +1,21 @@
/****************************************************************************
**
** Copyright (C) 2012 Denis Shienkov <[email protected]>
** Copyright (C) 2012 Laszlo Papp <[email protected]>
** Contact: http://www.qt.io/licensing/
**
** This file is part of the QtSerialPort module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL21$
** 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 http://www.qt.io/terms-conditions. For further
** information use the contact form at http://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 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** As a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** $QT_END_LICENSE$
**
****************************************************************************/
// Copyright (C) 2012 Denis Shienkov <[email protected]>
// Copyright (C) 2012 Laszlo Papp <[email protected]>
// 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

#include <QtCore/qlist.h>
#include <QtCore/qscopedpointer.h>

#include "qserialportglobal.h"

QT_BEGIN_NAMESPACE

class QSerialPort;
class QSerialPortInfoPrivate;

class QSerialPortInfo
class Q_SERIALPORT_EXPORT QSerialPortInfo
{
Q_DECLARE_PRIVATE(QSerialPortInfo)
public:
Expand All @@ -69,21 +41,16 @@ class QSerialPortInfo
bool hasProductIdentifier() const;

bool isNull() const;
bool isBusy() const;
#if QT_DEPRECATED_SINCE(5, 2)
QT_DEPRECATED bool isValid() const;
#endif

static QList<qint32> standardBaudRates();
static QList<QSerialPortInfo> availablePorts();

std::unique_ptr<QSerialPortInfoPrivate> d_ptr;

private:
QSerialPortInfo(const QSerialPortInfoPrivate &dd);
friend QList<QSerialPortInfo> availablePortsByUdev(bool &ok);
friend QList<QSerialPortInfo> availablePortsBySysfs(bool &ok);
friend QList<QSerialPortInfo> availablePortsByFiltersOfDevices();
friend QList<QSerialPortInfo> availablePortsByFiltersOfDevices(bool &ok);
std::unique_ptr<QSerialPortInfoPrivate> d_ptr;
};

inline bool QSerialPortInfo::isNull() const
Expand Down
Loading

0 comments on commit 71efca9

Please sign in to comment.