summaryrefslogtreecommitdiffstats
path: root/src/network/kernel
diff options
context:
space:
mode:
authorMårten Nordheim <marten.nordheim@qt.io>2021-10-21 13:07:33 +0200
committerMårten Nordheim <marten.nordheim@qt.io>2021-10-22 09:40:49 +0200
commitbfe579613a12efe13be35b1a52975dddeb0d8026 (patch)
treea8d3431d449060e1e3fd17dde258c2fddffe0521 /src/network/kernel
parent5f8e9c194e06b7a886cb69b24a37b62ab23c79a8 (diff)
QNI: Add a convenience method for loading the default plugin
We have some official plugins, we may as well treat them as default and give a convenient function which loads those. Change-Id: I6251c77ac042b795bcf24b86e510e960ee4bab54 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
Diffstat (limited to 'src/network/kernel')
-rw-r--r--src/network/kernel/qnetworkinformation.cpp55
-rw-r--r--src/network/kernel/qnetworkinformation.h1
-rw-r--r--src/network/kernel/qnetworkinformation_p.h11
3 files changed, 65 insertions, 2 deletions
diff --git a/src/network/kernel/qnetworkinformation.cpp b/src/network/kernel/qnetworkinformation.cpp
index 79375dee81..4f0b1405ef 100644
--- a/src/network/kernel/qnetworkinformation.cpp
+++ b/src/network/kernel/qnetworkinformation.cpp
@@ -604,11 +604,62 @@ QNetworkInformation::Features QNetworkInformation::supportedFeatures() const
}
/*!
+ \since 6.3
+
+ Attempts to load the platform-default backend.
+
+ This platform-to-plugin mapping is as follows:
+
+ \table
+ \header
+ \li Platform
+ \li Plugin-name
+ \row
+ \li Windows
+ \li networklistmanager
+ \row
+ \li Apple (macOS/iOS)
+ \li scnetworkreachability
+ \row
+ \li Android
+ \li android
+ \row
+ \li Linux
+ \li networkmanager
+ \endtable
+
+ This function is provided for convenience where the default for a given
+ platform is good enough. If you are not using the default plugins you must
+ use one of the other load() overloads.
+
+ Returns \c true if it managed to load the backend or if it was already
+ loaded. Returns \c false otherwise.
+
+ \sa instance
+*/
+bool QNetworkInformation::load()
+{
+ int index = -1;
+#ifdef Q_OS_WIN
+ index = QNetworkInformationBackend::PluginNamesWindowsIndex;
+#elif defined(Q_OS_DARWIN)
+ index = QNetworkInformationBackend::PluginNamesAppleIndex;
+#elif defined(Q_OS_ANDROID)
+ index = QNetworkInformationBackend::PluginNamesAndroidIndex;
+#elif defined(Q_OS_LINUX)
+ index = QNetworkInformationBackend::PluginNamesLinuxIndex;
+#endif
+ if (index == -1)
+ return false;
+ return load(QNetworkInformationBackend::PluginNames[index]);
+}
+
+/*!
Attempts to load a backend whose name matches \a backend
(case insensitively).
Returns \c true if it managed to load the requested backend or
- if it was already loaded. Returns \c false otherwise
+ if it was already loaded. Returns \c false otherwise.
\sa instance
*/
@@ -622,7 +673,7 @@ bool QNetworkInformation::load(QStringView backend)
Load a backend which supports \a features.
Returns \c true if it managed to load the requested backend or
- if it was already loaded. Returns \c false otherwise
+ if it was already loaded. Returns \c false otherwise.
\sa instance
*/
diff --git a/src/network/kernel/qnetworkinformation.h b/src/network/kernel/qnetworkinformation.h
index febf5bbc8f..e280894fef 100644
--- a/src/network/kernel/qnetworkinformation.h
+++ b/src/network/kernel/qnetworkinformation.h
@@ -96,6 +96,7 @@ public:
bool supports(Features features) const;
Features supportedFeatures() const;
+ static bool load();
static bool load(QStringView backend);
static bool load(Features features);
static QStringList availableBackends();
diff --git a/src/network/kernel/qnetworkinformation_p.h b/src/network/kernel/qnetworkinformation_p.h
index ba07870be3..971340b6e3 100644
--- a/src/network/kernel/qnetworkinformation_p.h
+++ b/src/network/kernel/qnetworkinformation_p.h
@@ -67,6 +67,17 @@ class Q_NETWORK_EXPORT QNetworkInformationBackend : public QObject
using TransportMedium = QNetworkInformation::TransportMedium;
public:
+ static inline const char16_t PluginNames[4][22] = {
+ { u"networklistmanager" },
+ { u"scnetworkreachability" },
+ { u"android" },
+ { u"networkmanager" },
+ };
+ static constexpr int PluginNamesWindowsIndex = 0;
+ static constexpr int PluginNamesAppleIndex = 1;
+ static constexpr int PluginNamesAndroidIndex = 2;
+ static constexpr int PluginNamesLinuxIndex = 3;
+
QNetworkInformationBackend() = default;
~QNetworkInformationBackend() override;