Skip to content

Commit

Permalink
Support read attribute with complex type for general diagnostic cluster
Browse files Browse the repository at this point in the history
  • Loading branch information
yufengwangca committed Oct 26, 2021
1 parent 551e53f commit e0807c2
Showing 1 changed file with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,19 @@
*/

#include <app-common/zap-generated/attributes/Accessors.h>
#include <app-common/zap-generated/cluster-objects.h>
#include <app-common/zap-generated/ids/Attributes.h>
#include <app-common/zap-generated/ids/Clusters.h>
#include <app/AttributeAccessInterface.h>
#include <app/util/attribute-storage.h>
#include <platform/ConnectivityManager.h>
#include <platform/PlatformManager.h>

using namespace chip;
using namespace chip::app;
using namespace chip::app::Clusters;
using namespace chip::app::Clusters::GeneralDiagnostics::Attributes;
using chip::DeviceLayer::ConnectivityMgr;
using chip::DeviceLayer::PlatformManager;

namespace {
Expand All @@ -40,6 +44,7 @@ class GeneralDiagosticsAttrAccess : public AttributeAccessInterface
private:
template <typename T>
CHIP_ERROR ReadIfSupported(CHIP_ERROR (PlatformManager::*getter)(T &), AttributeValueEncoder & aEncoder);
CHIP_ERROR ReadNetworkInterfaces(AttributeValueEncoder & aEncoder);
};

template <typename T>
Expand All @@ -60,6 +65,27 @@ CHIP_ERROR GeneralDiagosticsAttrAccess::ReadIfSupported(CHIP_ERROR (PlatformMana
return aEncoder.Encode(data);
}

CHIP_ERROR GeneralDiagosticsAttrAccess::ReadNetworkInterfaces(AttributeValueEncoder & aEncoder)
{
DeviceLayer::NetworkInterface * netifs;

ReturnErrorOnFailure(ConnectivityMgr().GetNetworkInterfaces(&netifs));

CHIP_ERROR err = aEncoder.EncodeList([&netifs](const TagBoundEncoder & encoder) -> CHIP_ERROR {
for (DeviceLayer::NetworkInterface * ifp = netifs; ifp != nullptr; ifp = ifp->Next)
{
GeneralDiagnostics::Structs::NetworkInterfaceType::Type * networkInterface = ifp;
ReturnErrorOnFailure(encoder.Encode(*networkInterface));
}

return CHIP_NO_ERROR;
});

ConnectivityMgr().ReleaseNetworkInterfaces(netifs);

return err;
}

GeneralDiagosticsAttrAccess gAttrAccess;

CHIP_ERROR GeneralDiagosticsAttrAccess::Read(const ConcreteAttributePath & aPath, AttributeValueEncoder & aEncoder)
Expand All @@ -72,6 +98,9 @@ CHIP_ERROR GeneralDiagosticsAttrAccess::Read(const ConcreteAttributePath & aPath

switch (aPath.mAttributeId)
{
case NetworkInterfaces::Id: {
return ReadNetworkInterfaces(aEncoder);
}
case RebootCount::Id: {
return ReadIfSupported(&PlatformManager::GetRebootCount, aEncoder);
}
Expand Down

0 comments on commit e0807c2

Please sign in to comment.