Add dummy backend to QNetworkInformation
The integration of QTBUG-113813 has failed because at the moment there is no network information backend for QNX. Implement a simple dummy backend to handle these cases. Task-number: QTBUG-113813 Change-Id: Id6fa3e590c43b0125d82e8680733e30788d9894e Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
This commit is contained in:
parent
5054279bee
commit
9334947d36
@ -50,6 +50,18 @@ static void networkInfoCleanup()
|
||||
dataHolder->instanceHolder.reset();
|
||||
}
|
||||
|
||||
using namespace Qt::Literals::StringLiterals;
|
||||
|
||||
class QNetworkInformationDummyBackend : public QNetworkInformationBackend {
|
||||
Q_OBJECT
|
||||
public:
|
||||
QString name() const override { return u"dummy"_s; }
|
||||
QNetworkInformation::Features featuresSupported() const override
|
||||
{
|
||||
return {};
|
||||
}
|
||||
};
|
||||
|
||||
class QNetworkInformationPrivate : public QObjectPrivate
|
||||
{
|
||||
Q_DECLARE_PUBLIC(QNetworkInformation)
|
||||
@ -60,6 +72,7 @@ public:
|
||||
|
||||
static QNetworkInformation *create(QNetworkInformation::Features features);
|
||||
static QNetworkInformation *create(QStringView name);
|
||||
static QNetworkInformation *createDummy();
|
||||
static QNetworkInformation *instance()
|
||||
{
|
||||
if (!dataHolder())
|
||||
@ -266,6 +279,20 @@ QNetworkInformation *QNetworkInformationPrivate::create(QNetworkInformation::Fea
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
QNetworkInformation *QNetworkInformationPrivate::createDummy()
|
||||
{
|
||||
if (!dataHolder())
|
||||
return nullptr;
|
||||
|
||||
QMutexLocker locker(&dataHolder->instanceMutex);
|
||||
if (dataHolder->instanceHolder)
|
||||
return dataHolder->instanceHolder.get();
|
||||
|
||||
QNetworkInformationBackend *backend = new QNetworkInformationDummyBackend;
|
||||
dataHolder->instanceHolder.reset(new QNetworkInformation(backend));
|
||||
return dataHolder->instanceHolder.get();
|
||||
}
|
||||
|
||||
/*!
|
||||
\class QNetworkInformationBackend
|
||||
\internal (Semi-private)
|
||||
@ -644,7 +671,8 @@ bool QNetworkInformation::loadDefaultBackend()
|
||||
index = QNetworkInformationBackend::PluginNamesLinuxIndex;
|
||||
#endif
|
||||
if (index == -1)
|
||||
return false;
|
||||
return loadBackendByName(u"dummy");
|
||||
|
||||
return loadBackendByName(QNetworkInformationBackend::PluginNames[index]);
|
||||
}
|
||||
|
||||
@ -661,6 +689,9 @@ bool QNetworkInformation::loadDefaultBackend()
|
||||
*/
|
||||
bool QNetworkInformation::loadBackendByName(QStringView backend)
|
||||
{
|
||||
if (backend == u"dummy")
|
||||
return QNetworkInformationPrivate::createDummy() != nullptr;
|
||||
|
||||
auto loadedBackend = QNetworkInformationPrivate::create(backend);
|
||||
return loadedBackend && loadedBackend->backendName().compare(backend, Qt::CaseInsensitive) == 0;
|
||||
}
|
||||
@ -727,3 +758,4 @@ QT_END_NAMESPACE
|
||||
|
||||
#include "moc_qnetworkinformation.cpp"
|
||||
#include "moc_qnetworkinformation_p.cpp"
|
||||
#include "qnetworkinformation.moc"
|
||||
|
Loading…
Reference in New Issue
Block a user