Skip to content

Commit

Permalink
[TE7]:Support read attribute with complex type for general diagnostic…
Browse files Browse the repository at this point in the history
… cluster (project-chip#10641)

* Support read attribute with complex type for general diagnostic cluster

* Update src/app/clusters/general_diagnostics_server/general_diagnostics_server.cpp

Co-authored-by: Boris Zbarsky <[email protected]>

* Encode an empty list if GetNetworkInterfaces fails

Co-authored-by: Boris Zbarsky <[email protected]>
  • Loading branch information
2 people authored and JasonLiuZhuoCheng committed Oct 28, 2021
1 parent 1330aa7 commit c940b18
Showing 1 changed file with 34 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,32 @@ CHIP_ERROR GeneralDiagosticsAttrAccess::ReadIfSupported(CHIP_ERROR (PlatformMana
return aEncoder.Encode(data);
}

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

if (ConnectivityMgr().GetNetworkInterfaces(&netifs) == CHIP_NO_ERROR)
{
err = aEncoder.EncodeList([&netifs](const TagBoundEncoder & encoder) -> CHIP_ERROR {
for (DeviceLayer::NetworkInterface * ifp = netifs; ifp != nullptr; ifp = ifp->Next)
{
ReturnErrorOnFailure(encoder.Encode(*ifp));
}

return CHIP_NO_ERROR;
});

ConnectivityMgr().ReleaseNetworkInterfaces(netifs);
}
else
{
err = aEncoder.Encode(DataModel::List<EndpointId>());
}

return err;
}

GeneralDiagosticsAttrAccess gAttrAccess;

CHIP_ERROR GeneralDiagosticsAttrAccess::Read(const ConcreteAttributePath & aPath, AttributeValueEncoder & aEncoder)
Expand All @@ -72,6 +103,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 c940b18

Please sign in to comment.