Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Software Diagnostics not claim to support ResetWatermarks if it's not supported. #19536

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@
#include <app-common/zap-generated/ids/Clusters.h>
#include <app/AttributeAccessInterface.h>
#include <app/CommandHandler.h>
#include <app/CommandHandlerInterface.h>
#include <app/ConcreteCommandPath.h>
#include <app/EventLogging.h>
#include <app/InteractionModelEngine.h>
#include <app/util/af.h>
#include <app/util/attribute-storage.h>
#include <lib/core/Optional.h>
Expand Down Expand Up @@ -52,8 +54,21 @@ class SoftwareDiagosticsAttrAccess : public AttributeAccessInterface
CHIP_ERROR ReadThreadMetrics(AttributeValueEncoder & aEncoder);
};

class SoftwareDiagnosticsCommandHandler : public CommandHandlerInterface
{
public:
// Register for the SoftwareDiagnostics cluster on all endpoints.
SoftwareDiagnosticsCommandHandler() : CommandHandlerInterface(Optional<EndpointId>::Missing(), SoftwareDiagnostics::Id) {}

void InvokeCommand(HandlerContext & handlerContext) override;

CHIP_ERROR EnumerateAcceptedCommands(const ConcreteClusterPath & cluster, CommandIdCallback callback, void * context) override;
};

SoftwareDiagosticsAttrAccess gAttrAccess;

SoftwareDiagnosticsCommandHandler gCommandHandler;

CHIP_ERROR SoftwareDiagosticsAttrAccess::Read(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder)
{
if (aPath.mClusterId != SoftwareDiagnostics::Id)
Expand Down Expand Up @@ -131,6 +146,42 @@ CHIP_ERROR SoftwareDiagosticsAttrAccess::ReadThreadMetrics(AttributeValueEncoder
return err;
}

void SoftwareDiagnosticsCommandHandler::InvokeCommand(HandlerContext & handlerContext)
{
using Protocols::InteractionModel::Status;
if (handlerContext.mRequestPath.mCommandId != Commands::ResetWatermarks::Id)
{
// Normal error handling
return;
}

handlerContext.SetCommandHandled();
Status status = Status::Success;
if (!DeviceLayer::GetDiagnosticDataProvider().SupportsWatermarks())
{
status = Status::UnsupportedCommand;
}
else if (DeviceLayer::GetDiagnosticDataProvider().ResetWatermarks() != CHIP_NO_ERROR)
{
status = Status::Failure;
}
handlerContext.mCommandHandler.AddStatus(handlerContext.mRequestPath, status);
}

CHIP_ERROR SoftwareDiagnosticsCommandHandler::EnumerateAcceptedCommands(const ConcreteClusterPath & cluster,
CommandIdCallback callback, void * context)
{
if (!DeviceLayer::GetDiagnosticDataProvider().SupportsWatermarks())
{
// No commmands.
return CHIP_NO_ERROR;
}

callback(Commands::ResetWatermarks::Id, context);

return CHIP_NO_ERROR;
}

} // anonymous namespace

namespace chip {
Expand Down Expand Up @@ -174,21 +225,12 @@ bool emberAfSoftwareDiagnosticsClusterResetWatermarksCallback(app::CommandHandle
const app::ConcreteCommandPath & commandPath,
const Commands::ResetWatermarks::DecodableType & commandData)
{
EmberAfStatus status = EMBER_ZCL_STATUS_SUCCESS;

// If implemented, the server SHALL set the value of the CurrentHeapHighWatermark attribute to the
// value of the CurrentHeapUsed.
if (DeviceLayer::GetDiagnosticDataProvider().ResetWatermarks() != CHIP_NO_ERROR)
{
status = EMBER_ZCL_STATUS_FAILURE;
}

emberAfSendImmediateDefaultResponse(status);

return true;
// Shouldn't be called at all.
return false;
}

void MatterSoftwareDiagnosticsPluginServerInitCallback()
{
registerAttributeAccessOverride(&gAttrAccess);
InteractionModelEngine::GetInstance()->RegisterCommandHandler(&gCommandHandler);
}