Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
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
5
#
include
"qconnmannetworkinformationbackend.h"
6
7
#
include
<
QtCore
/
qglobal
.
h
>
8
#
include
<
QtCore
/
private
/
qobject_p
.
h
>
9
10
#
include
<
QtDBus
/
qdbusmessage
.
h
>
11
12
QT_BEGIN_NAMESPACE
13
Q_DECLARE_LOGGING_CATEGORY(lcNetInfoConnman)
14
Q_LOGGING_CATEGORY(lcNetInfoConnman,
"qt.network.info.connman"
)
15
16
using
namespace
Qt::StringLiterals;
17
18
namespace
{
19
QNetworkInformation::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
31
QNetworkInformation::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
46
static
QString
backendName
()
47
{
48
return
"connman"_L1
;
49
}
50
51
QString
QConnManNetworkInformationBackend
::
name
()
const
52
{
53
return
backendName();
54
}
55
56
class
QConnManNetworkInformationBackendFactory
:
public
QNetworkInformationBackendFactory
57
{
58
Q_OBJECT
59
Q_PLUGIN_METADATA(IID QNetworkInformationBackendFactory_iid)
60
Q_INTERFACES
(
QNetworkInformationBackendFactory
)
61
public
:
62
QConnManNetworkInformationBackendFactory
() =
default
;
63
~
QConnManNetworkInformationBackendFactory
() =
default
;
64
QString
name
()
const
override
{
return
backendName(); }
65
QNetworkInformation
::
Features
featuresSupported
()
const
override
66
{
67
if
(!
QConnManInterfaceBase
::
connmanAvailable
(
)
)
68
return
{};
69
return
QConnManNetworkInformationBackend::featuresSupportedStatic();
70
}
71
72
QNetworkInformationBackend
*
73
create
(QNetworkInformation::Features requiredFeatures)
const
override
74
{
75
if
((requiredFeatures & featuresSupported()) != requiredFeatures)
76
return
nullptr
;
77
if
(!
QConnManInterfaceBase
::
connmanAvailable
(
)
)
78
return
nullptr
;
79
auto
backend =
new
QConnManNetworkInformationBackend
();
80
if
(!backend->isValid())
81
delete
std::exchange(backend,
nullptr
);
82
return
backend;
83
}
84
85
private
:
86
Q_DISABLE_COPY_MOVE
(
QConnManNetworkInformationBackendFactory
)
87
};
88
89
QConnManNetworkInformationBackend
::QConnManNetworkInformationBackend()
90
{
91
if
(!iface.isValid())
92
return
;
93
iface.setBackend(
this
);
94
onStateChanged(iface.state());
95
onTypeChanged(iface.type());
96
}
97
98
void
QConnManNetworkInformationBackend
::
onStateChanged
(
const
QString &state)
99
{
100
qCInfo(lcNetInfoConnman) <<
"network state changed to"
<< state;
101
QNetworkInformation::Reachability reachability = reachabilityFromState(state);
102
setReachability(reachability);
103
}
104
105
void
QConnManNetworkInformationBackend
::
onTypeChanged
(
const
QString &type)
106
{
107
qCInfo(lcNetInfoConnman) <<
"network type changed to"
<< type;
108
QNetworkInformation::TransportMedium medium = transportMediumFromType(type);
109
setTransportMedium(medium);
110
}
111
112
QT_END_NAMESPACE
113
114
#
include
"qconnmannetworkinformationbackend.moc"
115
#
include
"moc_qconnmannetworkinformationbackend.cpp"
QConnManInterfaceBase
Definition
qconnmanservice.h:29
QConnManInterfaceBase::connmanAvailable
static bool connmanAvailable()
Definition
qconnmanservice.cpp:45
QConnManNetworkInformationBackendFactory
Definition
qconnmannetworkinformationbackend.cpp:57
QConnManNetworkInformationBackendFactory::~QConnManNetworkInformationBackendFactory
~QConnManNetworkInformationBackendFactory()=default
QConnManNetworkInformationBackendFactory::create
QNetworkInformationBackend * create(QNetworkInformation::Features requiredFeatures) const override
Create and return an instance of QNetworkInformationBackend.
Definition
qconnmannetworkinformationbackend.cpp:73
QConnManNetworkInformationBackendFactory::name
QString name() const override
Backend name, return the same in QNetworkInformationBackend::name().
Definition
qconnmannetworkinformationbackend.cpp:64
QConnManNetworkInformationBackendFactory::featuresSupported
QNetworkInformation::Features featuresSupported() const override
Features supported, return the same in QNetworkInformationBackend::featuresSupported().
Definition
qconnmannetworkinformationbackend.cpp:65
QConnManNetworkInformationBackend
Definition
qconnmannetworkinformationbackend.h:25
QConnManNetworkInformationBackend::onStateChanged
void onStateChanged(const QString &state)
Definition
qconnmannetworkinformationbackend.cpp:98
QConnManNetworkInformationBackend::onTypeChanged
void onTypeChanged(const QString &type)
Definition
qconnmannetworkinformationbackend.cpp:105
QConnManNetworkInformationBackend::name
QString name() const override
Backend name, return the same in QNetworkInformationBackendFactory::name().
Definition
qconnmannetworkinformationbackend.cpp:51
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
backendName
static QString backendName()
Definition
qconnmannetworkinformationbackend.cpp:46
qtbase
src
plugins
networkinformation
connman
qconnmannetworkinformationbackend.cpp
Generated on
for Qt by
1.18.0