bool ConnectivityReportPlugin::receivePacket(const NetworkPacket &np)
{
if (np.type() == PACKET_TYPE_CONNECTIVITY_REPORT) {
auto subscriptions = np.get(QStringLiteral("signalStrengths"), QVariantMap());
if (!subscriptions.isEmpty()) {
auto networkInfo = subscriptions.first().toMap();
const auto oldCellularNetworkType = m_cellularNetworkType;
const auto oldNetworkStrength = m_cellularNetworkStrength;
m_cellularNetworkType = networkInfo.value(QStringLiteral("networkType")).toString();
m_cellularNetworkStrength = networkInfo.value(QStringLiteral("signalStrength")).toInt();
if (oldCellularNetworkType != m_cellularNetworkType || oldNetworkStrength != m_cellularNetworkStrength) {
Q_EMIT refreshed(m_cellularNetworkType, m_cellularNetworkStrength);
}
}
}
return true;
}
It receives a NetworkPacket object np and retrieves its data.
If the packet type is CONNECTIVITY_REPORT it gets the signal strength of the first network entry in the map, and updates the values of the member variables. Then it emits a signal of the type and strength changed signal.
If the packet type is CONNECTIVITY_REPORT it emits a signal of the type and strength changed signal.
If the packet type is DISCONNECTIVITY_REPORT it returns true. Otherwise it returns false.