Skip to content

Commit

Permalink
Move diagnostic APIs from ConnectivityMgr to DiagnosticDataProvider (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
yufengwangca authored and pull[bot] committed Jun 23, 2022
1 parent 1b382e1 commit 0d7aaad
Show file tree
Hide file tree
Showing 22 changed files with 1,175 additions and 1,407 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@
#include <app/util/af.h>
#include <app/util/attribute-storage.h>
#include <lib/core/Optional.h>
#include <platform/ConnectivityManager.h>
#include <platform/DiagnosticDataProvider.h>

using namespace chip;
using namespace chip::app;
using namespace chip::app::Clusters;
using namespace chip::app::Clusters::EthernetNetworkDiagnostics;
using namespace chip::app::Clusters::EthernetNetworkDiagnostics::Attributes;
using chip::DeviceLayer::ConnectivityManager;
using chip::DeviceLayer::DiagnosticDataProvider;

namespace {

Expand All @@ -46,15 +46,15 @@ class EthernetDiagosticsAttrAccess : public AttributeAccessInterface

private:
template <typename T>
CHIP_ERROR ReadIfSupported(CHIP_ERROR (ConnectivityManager::*getter)(T &), AttributeValueEncoder & aEncoder);
CHIP_ERROR ReadIfSupported(CHIP_ERROR (DiagnosticDataProvider::*getter)(T &), AttributeValueEncoder & aEncoder);
};

template <typename T>
CHIP_ERROR EthernetDiagosticsAttrAccess::ReadIfSupported(CHIP_ERROR (ConnectivityManager::*getter)(T &),
CHIP_ERROR EthernetDiagosticsAttrAccess::ReadIfSupported(CHIP_ERROR (DiagnosticDataProvider::*getter)(T &),
AttributeValueEncoder & aEncoder)
{
T data;
CHIP_ERROR err = (DeviceLayer::ConnectivityMgr().*getter)(data);
CHIP_ERROR err = (DeviceLayer::GetDiagnosticDataProvider().*getter)(data);
if (err == CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE)
{
data = 0;
Expand All @@ -80,31 +80,31 @@ CHIP_ERROR EthernetDiagosticsAttrAccess::Read(const ConcreteReadAttributePath &
switch (aPath.mAttributeId)
{
case PHYRate::Id: {
return ReadIfSupported(&ConnectivityManager::GetEthPHYRate, aEncoder);
return ReadIfSupported(&DiagnosticDataProvider::GetEthPHYRate, aEncoder);
}
case FullDuplex::Id: {
return ReadIfSupported(&ConnectivityManager::GetEthFullDuplex, aEncoder);
return ReadIfSupported(&DiagnosticDataProvider::GetEthFullDuplex, aEncoder);
}
case CarrierDetect::Id: {
return ReadIfSupported(&ConnectivityManager::GetEthCarrierDetect, aEncoder);
return ReadIfSupported(&DiagnosticDataProvider::GetEthCarrierDetect, aEncoder);
}
case TimeSinceReset::Id: {
return ReadIfSupported(&ConnectivityManager::GetEthTimeSinceReset, aEncoder);
return ReadIfSupported(&DiagnosticDataProvider::GetEthTimeSinceReset, aEncoder);
}
case PacketRxCount::Id: {
return ReadIfSupported(&ConnectivityManager::GetEthPacketRxCount, aEncoder);
return ReadIfSupported(&DiagnosticDataProvider::GetEthPacketRxCount, aEncoder);
}
case PacketTxCount::Id: {
return ReadIfSupported(&ConnectivityManager::GetEthPacketTxCount, aEncoder);
return ReadIfSupported(&DiagnosticDataProvider::GetEthPacketTxCount, aEncoder);
}
case TxErrCount::Id: {
return ReadIfSupported(&ConnectivityManager::GetEthTxErrCount, aEncoder);
return ReadIfSupported(&DiagnosticDataProvider::GetEthTxErrCount, aEncoder);
}
case CollisionCount::Id: {
return ReadIfSupported(&ConnectivityManager::GetEthCollisionCount, aEncoder);
return ReadIfSupported(&DiagnosticDataProvider::GetEthCollisionCount, aEncoder);
}
case OverrunCount::Id: {
return ReadIfSupported(&ConnectivityManager::GetEthOverrunCount, aEncoder);
return ReadIfSupported(&DiagnosticDataProvider::GetEthOverrunCount, aEncoder);
}
default: {
break;
Expand All @@ -121,7 +121,7 @@ bool emberAfEthernetNetworkDiagnosticsClusterResetCountsCallback(app::CommandHan
EndpointId endpoint = commandPath.mEndpointId;
EmberAfStatus status = EMBER_ZCL_STATUS_SUCCESS;

VerifyOrExit(DeviceLayer::ConnectivityMgr().ResetEthNetworkDiagnosticsCounts() == CHIP_NO_ERROR,
VerifyOrExit(DeviceLayer::GetDiagnosticDataProvider().ResetEthNetworkDiagnosticsCounts() == CHIP_NO_ERROR,
status = EMBER_ZCL_STATUS_FAILURE);

status = EthernetNetworkDiagnostics::Attributes::PacketRxCount::Set(endpoint, 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ CHIP_ERROR GeneralDiagosticsAttrAccess::ReadNetworkInterfaces(AttributeValueEnco
CHIP_ERROR err = CHIP_NO_ERROR;
DeviceLayer::NetworkInterface * netifs;

if (ConnectivityMgr().GetNetworkInterfaces(&netifs) == CHIP_NO_ERROR)
if (DeviceLayer::GetDiagnosticDataProvider().GetNetworkInterfaces(&netifs) == CHIP_NO_ERROR)
{
err = aEncoder.EncodeList([&netifs](const TagBoundEncoder & encoder) -> CHIP_ERROR {
for (DeviceLayer::NetworkInterface * ifp = netifs; ifp != nullptr; ifp = ifp->Next)
Expand All @@ -114,7 +114,7 @@ CHIP_ERROR GeneralDiagosticsAttrAccess::ReadNetworkInterfaces(AttributeValueEnco
return CHIP_NO_ERROR;
});

ConnectivityMgr().ReleaseNetworkInterfaces(netifs);
DeviceLayer::GetDiagnosticDataProvider().ReleaseNetworkInterfaces(netifs);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,14 @@
#include <app/util/af.h>
#include <app/util/attribute-storage.h>
#include <lib/core/Optional.h>
#include <platform/ConnectivityManager.h>
#include <platform/DiagnosticDataProvider.h>

using namespace chip;
using namespace chip::app;
using namespace chip::app::Clusters;
using namespace chip::app::Clusters::WiFiNetworkDiagnostics;
using namespace chip::app::Clusters::WiFiNetworkDiagnostics::Attributes;
using chip::DeviceLayer::ConnectivityManager;
using chip::DeviceLayer::ConnectivityMgr;
using chip::DeviceLayer::DiagnosticDataProvider;

namespace {

Expand All @@ -47,17 +46,17 @@ class WiFiDiagosticsAttrAccess : public AttributeAccessInterface

private:
template <typename T>
CHIP_ERROR ReadIfSupported(CHIP_ERROR (ConnectivityManager::*getter)(T &), AttributeValueEncoder & aEncoder);
CHIP_ERROR ReadIfSupported(CHIP_ERROR (DiagnosticDataProvider::*getter)(T &), AttributeValueEncoder & aEncoder);

CHIP_ERROR ReadWiFiBssId(AttributeValueEncoder & aEncoder);
};

template <typename T>
CHIP_ERROR WiFiDiagosticsAttrAccess::ReadIfSupported(CHIP_ERROR (ConnectivityManager::*getter)(T &),
CHIP_ERROR WiFiDiagosticsAttrAccess::ReadIfSupported(CHIP_ERROR (DiagnosticDataProvider::*getter)(T &),
AttributeValueEncoder & aEncoder)
{
T data;
CHIP_ERROR err = (DeviceLayer::ConnectivityMgr().*getter)(data);
CHIP_ERROR err = (DeviceLayer::GetDiagnosticDataProvider().*getter)(data);
if (err == CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE)
{
data = 0;
Expand All @@ -75,7 +74,7 @@ CHIP_ERROR WiFiDiagosticsAttrAccess::ReadWiFiBssId(AttributeValueEncoder & aEnco
// TODO: Use Nullable<ByteSpan> after we get darwin converted over to the new APIs.
Bssid::TypeInfo::Type bssid;

if (ConnectivityMgr().GetWiFiBssId(bssid) == CHIP_NO_ERROR)
if (DeviceLayer::GetDiagnosticDataProvider().GetWiFiBssId(bssid) == CHIP_NO_ERROR)
{
ChipLogProgress(Zcl, "Node is currently connected to Wi-Fi network with BSSID:");
ChipLogByteSpan(Zcl, bssid);
Expand Down Expand Up @@ -104,40 +103,40 @@ CHIP_ERROR WiFiDiagosticsAttrAccess::Read(const ConcreteReadAttributePath & aPat
return ReadWiFiBssId(aEncoder);
}
case Attributes::SecurityType::Id: {
return ReadIfSupported(&ConnectivityManager::GetWiFiSecurityType, aEncoder);
return ReadIfSupported(&DiagnosticDataProvider::GetWiFiSecurityType, aEncoder);
}
case WiFiVersion::Id: {
return ReadIfSupported(&ConnectivityManager::GetWiFiVersion, aEncoder);
return ReadIfSupported(&DiagnosticDataProvider::GetWiFiVersion, aEncoder);
}
case ChannelNumber::Id: {
return ReadIfSupported(&ConnectivityManager::GetWiFiChannelNumber, aEncoder);
return ReadIfSupported(&DiagnosticDataProvider::GetWiFiChannelNumber, aEncoder);
}
case Rssi::Id: {
return ReadIfSupported(&ConnectivityManager::GetWiFiRssi, aEncoder);
return ReadIfSupported(&DiagnosticDataProvider::GetWiFiRssi, aEncoder);
}
case BeaconLostCount::Id: {
return ReadIfSupported(&ConnectivityManager::GetWiFiBeaconLostCount, aEncoder);
return ReadIfSupported(&DiagnosticDataProvider::GetWiFiBeaconLostCount, aEncoder);
}
case BeaconRxCount::Id: {
return ReadIfSupported(&ConnectivityManager::GetWiFiBeaconRxCount, aEncoder);
return ReadIfSupported(&DiagnosticDataProvider::GetWiFiBeaconRxCount, aEncoder);
}
case PacketMulticastRxCount::Id: {
return ReadIfSupported(&ConnectivityManager::GetWiFiPacketMulticastRxCount, aEncoder);
return ReadIfSupported(&DiagnosticDataProvider::GetWiFiPacketMulticastRxCount, aEncoder);
}
case PacketMulticastTxCount::Id: {
return ReadIfSupported(&ConnectivityManager::GetWiFiPacketMulticastTxCount, aEncoder);
return ReadIfSupported(&DiagnosticDataProvider::GetWiFiPacketMulticastTxCount, aEncoder);
}
case PacketUnicastRxCount::Id: {
return ReadIfSupported(&ConnectivityManager::GetWiFiPacketUnicastRxCount, aEncoder);
return ReadIfSupported(&DiagnosticDataProvider::GetWiFiPacketUnicastRxCount, aEncoder);
}
case PacketUnicastTxCount::Id: {
return ReadIfSupported(&ConnectivityManager::GetWiFiPacketUnicastTxCount, aEncoder);
return ReadIfSupported(&DiagnosticDataProvider::GetWiFiPacketUnicastTxCount, aEncoder);
}
case CurrentMaxRate::Id: {
return ReadIfSupported(&ConnectivityManager::GetWiFiCurrentMaxRate, aEncoder);
return ReadIfSupported(&DiagnosticDataProvider::GetWiFiCurrentMaxRate, aEncoder);
}
case OverrunCount::Id: {
return ReadIfSupported(&ConnectivityManager::GetWiFiOverrunCount, aEncoder);
return ReadIfSupported(&DiagnosticDataProvider::GetWiFiOverrunCount, aEncoder);
}
default: {
break;
Expand All @@ -154,7 +153,7 @@ bool emberAfWiFiNetworkDiagnosticsClusterResetCountsCallback(app::CommandHandler
EndpointId endpoint = commandPath.mEndpointId;
EmberAfStatus status = EMBER_ZCL_STATUS_SUCCESS;

VerifyOrExit(DeviceLayer::ConnectivityMgr().ResetWiFiNetworkDiagnosticsCounts() == CHIP_NO_ERROR,
VerifyOrExit(DeviceLayer::GetDiagnosticDataProvider().ResetWiFiNetworkDiagnosticsCounts() == CHIP_NO_ERROR,
status = EMBER_ZCL_STATUS_FAILURE);

status = WiFiNetworkDiagnostics::Attributes::BeaconLostCount::Set(endpoint, 0);
Expand Down
Loading

0 comments on commit 0d7aaad

Please sign in to comment.