Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qconnmannetworkinformationbackend.cpp
Go to the documentation of this file.
1// Copyright (C) 2025 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
6
7#include <QtCore/qglobal.h>
8#include <QtCore/private/qobject_p.h>
9
10#include <QtDBus/qdbusmessage.h>
11
13Q_DECLARE_LOGGING_CATEGORY(lcNetInfoConnman)
14Q_LOGGING_CATEGORY(lcNetInfoConnman, "qt.network.info.connman")
15
16using namespace Qt::StringLiterals;
17
18namespace {
19QNetworkInformation::Reachability reachabilityFromState(const QString &state)
20{
21 if (state == "idle"_L1)
22 return QNetworkInformation::Reachability::Disconnected;
23 else if (state == "ready"_L1)
24 return QNetworkInformation::Reachability::Local;
25 else if (state == "online"_L1)
26 return QNetworkInformation::Reachability::Online;
27 else
28 return QNetworkInformation::Reachability::Unknown;
29}
30
31QNetworkInformation::TransportMedium transportMediumFromType(const QString &type)
32{
33 if (type == "ethernet"_L1)
34 return QNetworkInformation::TransportMedium::Ethernet;
35 else if (type == "wifi"_L1)
36 return QNetworkInformation::TransportMedium::WiFi;
37 else if (type == "bluetooth"_L1)
38 return QNetworkInformation::TransportMedium::Bluetooth;
39 else if (type == "cellular"_L1)
40 return QNetworkInformation::TransportMedium::Cellular;
41 else
42 return QNetworkInformation::TransportMedium::Unknown;
43}
44} // unnamed namespace
45
47{
48 return "connman"_L1;
49}
50
52{
53 return backendName();
54}
55
57{
58 Q_OBJECT
59 Q_PLUGIN_METADATA(IID QNetworkInformationBackendFactory_iid)
61public:
64 QString name() const override { return backendName(); }
66 {
68 return {};
69 return QConnManNetworkInformationBackend::featuresSupportedStatic();
70 }
71
73 create(QNetworkInformation::Features requiredFeatures) const override
74 {
75 if ((requiredFeatures & featuresSupported()) != requiredFeatures)
76 return nullptr;
78 return nullptr;
79 auto backend = new QConnManNetworkInformationBackend();
80 if (!backend->isValid())
81 delete std::exchange(backend, nullptr);
82 return backend;
83 }
84
85private:
87};
88
89QConnManNetworkInformationBackend::QConnManNetworkInformationBackend()
90{
91 if (!iface.isValid())
92 return;
93 iface.setBackend(this);
94 onStateChanged(iface.state());
95 onTypeChanged(iface.type());
96}
97
99{
100 qCInfo(lcNetInfoConnman) << "network state changed to" << state;
101 QNetworkInformation::Reachability reachability = reachabilityFromState(state);
102 setReachability(reachability);
103}
104
106{
107 qCInfo(lcNetInfoConnman) << "network type changed to" << type;
108 QNetworkInformation::TransportMedium medium = transportMediumFromType(type);
109 setTransportMedium(medium);
110}
111
112QT_END_NAMESPACE
113
114#include "qconnmannetworkinformationbackend.moc"
115#include "moc_qconnmannetworkinformationbackend.cpp"
static bool connmanAvailable()
QNetworkInformationBackend * create(QNetworkInformation::Features requiredFeatures) const override
Create and return an instance of QNetworkInformationBackend.
QString name() const override
Backend name, return the same in QNetworkInformationBackend::name().
QNetworkInformation::Features featuresSupported() const override
Features supported, return the same in QNetworkInformationBackend::featuresSupported().
QString name() const override
Backend name, return the same in QNetworkInformationBackendFactory::name().
static QString backendName()