diff options
Diffstat (limited to 'src/network/access/qnetworkaccessbackend.cpp')
-rw-r--r-- | src/network/access/qnetworkaccessbackend.cpp | 167 |
1 files changed, 124 insertions, 43 deletions
diff --git a/src/network/access/qnetworkaccessbackend.cpp b/src/network/access/qnetworkaccessbackend.cpp index f7e29340d9..5dbcef4bbe 100644 --- a/src/network/access/qnetworkaccessbackend.cpp +++ b/src/network/access/qnetworkaccessbackend.cpp @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2020 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtNetwork 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) 2020 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 "qnetworkaccessbackend_p.h" #include "qnetworkreplyimpl_p.h" @@ -72,7 +36,7 @@ public: static QBasicAtomicInt valid; }; Q_GLOBAL_STATIC(QNetworkAccessBackendFactoryData, factoryData) -QBasicAtomicInt QNetworkAccessBackendFactoryData::valid = Q_BASIC_ATOMIC_INITIALIZER(0); +Q_CONSTINIT QBasicAtomicInt QNetworkAccessBackendFactoryData::valid = Q_BASIC_ATOMIC_INITIALIZER(0); class QNetworkAccessBackendPrivate : public QObjectPrivate { @@ -80,7 +44,7 @@ public: QNetworkAccessBackend::TargetTypes m_targetTypes; QNetworkAccessBackend::SecurityFeatures m_securityFeatures; QNetworkAccessBackend::IOFeatures m_ioFeatures; - QSharedPointer<QNonContiguousByteDevice> uploadByteDevice; + std::shared_ptr<QNonContiguousByteDevice> uploadByteDevice; QIODevice *wrappedUploadByteDevice; QNetworkReplyImplPrivate *m_reply = nullptr; QNetworkAccessManagerPrivate *m_manager = nullptr; @@ -126,6 +90,76 @@ QStringList QNetworkAccessManagerPrivate::backendSupportedSchemes() const } /*! + \class QNetworkAccessBackendFactory + \brief QNetworkAccessBackendFactory is the base class to inherit + from for Qt to instantiate and query your QNetworkAccessBackend + plugin. + \since 6.0 + \internal + +//! [semi-private-notice] + The class is considered semi-private and as such requires linking + to "NetworkPrivate" to access the header. Furthermore it means + the class is not under the same binary compatibility restrictions + as the rest of Qt. While we still try to avoid breakage it may + still occur. The class is primarily meant to be used by plugins + which would be recompiled every time Qt is updated. +//! [semi-private-notice] + + This class acts as the primary interface to the plugin and must + be derived from. It deals with both querying supported schemes + and the creation of QNetworkAccessBackend + + Since they are both abstract function you are required to + implement supportedSchemes() and create(). +*/ + +/*! + \fn QStringList QNetworkAccessBackendFactory::supportedSchemes() const + + Override this method in your own derived class to let Qt know + what schemes your class can handle. +*/ + +/*! + \fn QNetworkAccessBackendFactory::create(QNetworkAccessManager::Operation op, const QNetworkRequest &request) const + + Override this method in your own class and return a + heap-allocated instance of your class derived from + QNetworkAccessBackend. + + If \a op or a property of \a request is not supported (for + example the URL's scheme) then you must return \nullptr. + + \sa QNetworkRequest::attribute(), QNetworkRequest::url(), QUrl::scheme() +*/ + +/*! + \class QNetworkAccessBackend + \brief QNetworkAccessBackend is the base class for implementing + support for schemes used by QNetworkAccessManager. + \since 6.0 + \internal + + \include access/qnetworkaccessbackend.cpp semi-private-notice + + This class can be derived from to add support for further schemes + in QNetworkAccessManager. + + The design of QNetworkAccessBackend makes it possible to specialize + behavior as needed for certain backends. + This was done using the (currently) 3 enums TargetType, + SecurityFeatures and IOFeatures. For example while only open() + and close() are abstract functions you are also required to + implement either read() or readPointer() and advanceReadPointer() + depending on whether you enable IOFeature::ZeroCopy or not. + Read more about it in the documentation for each of the + enumerators. + + \sa TargetType, SecurityFeatures, IOFeatures +*/ + +/*! \enum QNetworkAccessBackend::TargetType Use the values in this enum to specify what type of target @@ -276,6 +310,47 @@ bool QNetworkAccessBackend::start() return true; } +/*! + \fn void QNetworkAccessBackend::open() = 0 + + You must implement this in your derived class. + During this call you must open the connection and begin the request + (see: request()). + + As the connection progresses you must call the various public and + protected slots on QNetworkAccessBackend. As an example, when you have + received some data you must call readyRead(). And when all the data has been + received you must call finished(). This could, for example, be done by + binding signals inside your own implementation to the slots, or by calling + them directly. + + \sa close() +*/ + +/*! + \fn void QNetworkAccessBackend::close() = 0 + + You must implement this function in your derived class. + This function gets called when the QNetworkReply is closed or aborted. + + You should not emit an error or call finished() during this call since + QtNetwork will set and emit the \c{QNetworkReply::OperationCanceledError} + error by itself after control flow returns from this function. +*/ + +/*! + \fn qint64 QNetworkAccessBackend::bytesAvailable() const = 0 + + You must implement this function in your derived class. + This function is called at various times. It may be called because the user + called QNetworkReply::bytesAvailable(), and it may be called before an + attempt to read is made. + + While this function doesn't technically need to return an accurate number, + it may result in reduced performance if it does not. This function must + return zero if there are no bytes available. +*/ + #if QT_CONFIG(ssl) /*! Passes a \a configuration with the user's desired TLS @@ -566,7 +641,7 @@ QIODevice *QNetworkAccessBackend::createUploadByteDevice() // We want signal emissions only for normal asynchronous uploads if (!isSynchronous()) { - connect(d->uploadByteDevice.data(), &QNonContiguousByteDevice::readProgress, this, + connect(d->uploadByteDevice.get(), &QNonContiguousByteDevice::readProgress, this, [this](qint64 a, qint64 b) { Q_D(QNetworkAccessBackend); if (!d->m_reply->isFinished) @@ -574,7 +649,7 @@ QIODevice *QNetworkAccessBackend::createUploadByteDevice() }); } - d->wrappedUploadByteDevice = QNonContiguousByteDeviceFactory::wrap(d->uploadByteDevice.data()); + d->wrappedUploadByteDevice = QNonContiguousByteDeviceFactory::wrap(d->uploadByteDevice.get()); return d->wrappedUploadByteDevice; } @@ -738,6 +813,12 @@ QNetworkAccessBackendFactory::QNetworkAccessBackendFactory() /*! Destructs QNetworkAccessBackendFactory */ -QNetworkAccessBackendFactory::~QNetworkAccessBackendFactory() = default; +QNetworkAccessBackendFactory::~QNetworkAccessBackendFactory() +{ + if (factoryData.exists()) + factoryData->removeAll(this); +}; QT_END_NAMESPACE + +#include "moc_qnetworkaccessbackend_p.cpp" |