Skip to content

Commit

Permalink
Migrate Test cluster to cluster-objects-based APIs. (#10420)
Browse files Browse the repository at this point in the history
  • Loading branch information
bzbarsky-apple authored and pull[bot] committed Nov 18, 2021
1 parent 5194a68 commit 1637508
Showing 1 changed file with 21 additions and 33 deletions.
54 changes: 21 additions & 33 deletions src/app/clusters/test-cluster-server/test-cluster-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@
#include <lib/support/logging/CHIPLogging.h>

using namespace chip;
using namespace chip::app;
using namespace chip::app::Clusters::TestCluster;
using namespace chip::app::Clusters::TestCluster::Commands;

constexpr const char * kErrorStr = "Test Cluster: List Octet cluster (0x%02x) Error setting '%s' attribute: 0x%02x";

Expand Down Expand Up @@ -128,61 +130,47 @@ EmberAfStatus writeTestListStructOctetAttribute(EndpointId endpoint)
} // namespace

bool emberAfTestClusterClusterTestCallback(app::CommandHandler *, const app::ConcreteCommandPath & commandPath,
const Commands::Test::DecodableType & commandData)
const Test::DecodableType & commandData)
{
emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_SUCCESS);
return true;
}

bool sendNumericResponse(EndpointId endpoint, app::CommandHandler * apCommandObj, CommandId responseCommand, uint8_t returnValue)
bool emberAfTestClusterClusterTestSpecificCallback(CommandHandler * apCommandObj, const ConcreteCommandPath & commandPath,
const TestSpecific::DecodableType & commandData)
{
CHIP_ERROR err = CHIP_NO_ERROR;

app::CommandPathParams cmdParams = { endpoint, /* group id */ 0, ZCL_TEST_CLUSTER_ID, responseCommand,
(app::CommandPathFlags::kEndpointIdValid) };
TLV::TLVWriter * writer = nullptr;

VerifyOrExit(apCommandObj != nullptr, err = CHIP_ERROR_INCORRECT_STATE);

SuccessOrExit(err = apCommandObj->PrepareCommand(cmdParams));
writer = apCommandObj->GetCommandDataElementTLVWriter();
SuccessOrExit(err = writer->Put(TLV::ContextTag(0), returnValue));
SuccessOrExit(err = apCommandObj->FinishCommand());

exit:
TestSpecificResponse::Type responseData;
responseData.returnValue = 7;
CHIP_ERROR err = apCommandObj->AddResponseData(commandPath, responseData);
if (CHIP_NO_ERROR != err)
{
ChipLogError(Zcl, "Test Cluster: failed to send TestSpecific response: %" CHIP_ERROR_FORMAT, err.Format());
}
return true;
}

bool emberAfTestClusterClusterTestSpecificCallback(app::CommandHandler * apCommandObj, const app::ConcreteCommandPath & commandPath,
const Commands::TestSpecific::DecodableType & commandData)
{
return sendNumericResponse(commandPath.mEndpointId, apCommandObj, Commands::TestSpecificResponse::Id, 7);
}

bool emberAfTestClusterClusterTestNotHandledCallback(app::CommandHandler *, const app::ConcreteCommandPath & commandPath,
const Commands::TestNotHandled::DecodableType & commandData)
bool emberAfTestClusterClusterTestNotHandledCallback(CommandHandler *, const ConcreteCommandPath & commandPath,
const TestNotHandled::DecodableType & commandData)
{
return false;
}

bool emberAfTestClusterClusterTestAddArgumentsCallback(app::CommandHandler * apCommandObj,
const app::ConcreteCommandPath & commandPath,
const Commands::TestAddArguments::DecodableType & commandData)
bool emberAfTestClusterClusterTestAddArgumentsCallback(CommandHandler * apCommandObj, const ConcreteCommandPath & commandPath,
const TestAddArguments::DecodableType & commandData)
{
auto & arg1 = commandData.arg1;
auto & arg2 = commandData.arg2;

if (arg1 > UINT8_MAX - arg2)
if (commandData.arg1 > UINT8_MAX - commandData.arg2)
{
return emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_INVALID_ARGUMENT);
}

return sendNumericResponse(commandPath.mEndpointId, apCommandObj, Commands::TestAddArgumentsResponse::Id,
static_cast<uint8_t>(arg1 + arg2));
TestAddArgumentsResponse::Type responseData;
responseData.returnValue = static_cast<uint8_t>(commandData.arg1 + commandData.arg2);
CHIP_ERROR err = apCommandObj->AddResponseData(commandPath, responseData);
if (CHIP_NO_ERROR != err)
{
ChipLogError(Zcl, "Test Cluster: failed to send TestAddArguments response: %" CHIP_ERROR_FORMAT, err.Format());
}
return true;
}

// -----------------------------------------------------------------------------
Expand Down

0 comments on commit 1637508

Please sign in to comment.