Skip to content

Commit

Permalink
Stop using emberAfSendImmediateDefaultResponse. (#25064)
Browse files Browse the repository at this point in the history
* Stop using emberAfSendImmediateDefaultResponse.

This commit was generated by installing the git-extras package and
running the following commands:

  git sed 'emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_INVALID_COMMAND);' 'commandObj->AddStatus(commandPath, Status::InvalidCommand);'
  git sed 'emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_SUCCESS);' 'commandObj->AddStatus(commandPath, Status::Success);'
  git sed 'emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_FAILURE);' 'commandObj->AddStatus(commandPath, Status::Failure);'
  git sed 'emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_UNSUPPORTED_COMMAND);' 'commandObj->AddStatus(commandPath, Status::UnsupportedCommand);'
  git sed 'emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_MALFORMED_COMMAND);' 'commandObj->AddStatus(commandPath, Status::InvalidAction);'
  git sed 'emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_CONSTRAINT_ERROR);' 'commandObj->AddStatus(commandPath, Status::ConstraintError);'
  git sed 'emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_NOT_FOUND);' 'commandObj->AddStatus(commandPath, Status::NotFound);'

* Manual changes to make the mass-replaces compile.

* Manual changes to remove emberAfSendImmediateDefaultResponse.
  • Loading branch information
bzbarsky-apple authored and pull[bot] committed Jul 26, 2023
1 parent 3f3e969 commit 2508752
Show file tree
Hide file tree
Showing 39 changed files with 675 additions and 633 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ class StaticSupportedModesManager : public chip::app::Clusters::ModeSelect::Supp

SupportedModesManager::ModeOptionsProvider getModeOptionsProvider(EndpointId endpointId) const override;

EmberAfStatus getModeOptionByMode(EndpointId endpointId, uint8_t mode, const ModeOptionStructType ** dataPtr) const override;
Protocols::InteractionModel::Status getModeOptionByMode(EndpointId endpointId, uint8_t mode,
const ModeOptionStructType ** dataPtr) const override;

~StaticSupportedModesManager(){};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ using namespace std;
using namespace chip;
using namespace chip::app::Clusters;
using namespace chip::app::Clusters::ModeSelect;
using chip::Protocols::InteractionModel::Status;

using ModeOptionStructType = Structs::ModeOptionStruct::Type;
using SemanticTag = Structs::SemanticTagStruct::Type;
Expand Down Expand Up @@ -51,13 +52,13 @@ SupportedModesManager::ModeOptionsProvider StaticSupportedModesManager::getModeO
return ModeOptionsProvider(nullptr, nullptr);
}

EmberAfStatus StaticSupportedModesManager::getModeOptionByMode(unsigned short endpointId, unsigned char mode,
const ModeOptionStructType ** dataPtr) const
Status StaticSupportedModesManager::getModeOptionByMode(unsigned short endpointId, unsigned char mode,
const ModeOptionStructType ** dataPtr) const
{
auto modeOptionsProvider = this->getModeOptionsProvider(endpointId);
if (modeOptionsProvider.begin() == nullptr)
{
return EMBER_ZCL_STATUS_UNSUPPORTED_CLUSTER;
return Status::UnsupportedCluster;
}
auto * begin = this->getModeOptionsProvider(endpointId).begin();
auto * end = this->getModeOptionsProvider(endpointId).end();
Expand All @@ -68,11 +69,11 @@ EmberAfStatus StaticSupportedModesManager::getModeOptionByMode(unsigned short en
if (modeOption.mode == mode)
{
*dataPtr = &modeOption;
return EMBER_ZCL_STATUS_SUCCESS;
return Status::Success;
}
}
emberAfPrintln(EMBER_AF_PRINT_DEBUG, "Cannot find the mode %u", mode);
return EMBER_ZCL_STATUS_INVALID_COMMAND;
return Status::InvalidCommand;
}

const ModeSelect::SupportedModesManager * ModeSelect::getSupportedModesManager()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ class StaticSupportedModesManager : public chip::app::Clusters::ModeSelect::Supp

SupportedModesManager::ModeOptionsProvider getModeOptionsProvider(EndpointId endpointId) const override;

EmberAfStatus getModeOptionByMode(EndpointId endpointId, uint8_t mode, const ModeOptionStructType ** dataPtr) const override;
Protocols::InteractionModel::Status getModeOptionByMode(EndpointId endpointId, uint8_t mode,
const ModeOptionStructType ** dataPtr) const override;

~StaticSupportedModesManager(){};

Expand Down
11 changes: 6 additions & 5 deletions examples/placeholder/linux/static-supported-modes-manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ using namespace std;
using namespace chip;
using namespace chip::app::Clusters;
using namespace chip::app::Clusters::ModeSelect;
using chip::Protocols::InteractionModel::Status;

using ModeOptionStructType = Structs::ModeOptionStruct::Type;
using SemanticTag = Structs::SemanticTagStruct::Type;
Expand Down Expand Up @@ -51,13 +52,13 @@ SupportedModesManager::ModeOptionsProvider StaticSupportedModesManager::getModeO
return ModeOptionsProvider(nullptr, nullptr);
}

EmberAfStatus StaticSupportedModesManager::getModeOptionByMode(unsigned short endpointId, unsigned char mode,
const ModeOptionStructType ** dataPtr) const
Status StaticSupportedModesManager::getModeOptionByMode(unsigned short endpointId, unsigned char mode,
const ModeOptionStructType ** dataPtr) const
{
auto modeOptionsProvider = this->getModeOptionsProvider(endpointId);
if (modeOptionsProvider.begin() == nullptr)
{
return EMBER_ZCL_STATUS_UNSUPPORTED_CLUSTER;
return Status::UnsupportedCluster;
}
auto * begin = this->getModeOptionsProvider(endpointId).begin();
auto * end = this->getModeOptionsProvider(endpointId).end();
Expand All @@ -68,11 +69,11 @@ EmberAfStatus StaticSupportedModesManager::getModeOptionByMode(unsigned short en
if (modeOption.mode == mode)
{
*dataPtr = &modeOption;
return EMBER_ZCL_STATUS_SUCCESS;
return Status::Success;
}
}
emberAfPrintln(EMBER_AF_PRINT_DEBUG, "Cannot find the mode %u", mode);
return EMBER_ZCL_STATUS_INVALID_COMMAND;
return Status::InvalidCommand;
}

const ModeSelect::SupportedModesManager * ModeSelect::getSupportedModesManager()
Expand Down
23 changes: 12 additions & 11 deletions src/app/clusters/account-login-server/account-login-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ using namespace chip::app::Clusters::AccountLogin;
using namespace chip::AppPlatform;
#endif // CHIP_DEVICE_CONFIG_APP_PLATFORM_ENABLED
using chip::app::Clusters::AccountLogin::Delegate;
using chip::Protocols::InteractionModel::Status;

static constexpr size_t kAccountLoginDeletageTableSize =
EMBER_AF_ACCOUNT_LOGIN_CLUSTER_SERVER_ENDPOINT_COUNT + CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT;
Expand Down Expand Up @@ -125,7 +126,7 @@ bool emberAfAccountLoginClusterGetSetupPINCallback(app::CommandHandler * command
{
ChipLogError(Zcl, "emberAfAccountLoginClusterGetSetupPINCallback error: %s", err.AsString());

emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_FAILURE);
command->AddStatus(commandPath, Status::Failure);
}

return true;
Expand All @@ -136,7 +137,7 @@ bool emberAfAccountLoginClusterLoginCallback(app::CommandHandler * command, cons
{
CHIP_ERROR err = CHIP_NO_ERROR;
EndpointId endpoint = commandPath.mEndpointId;
EmberAfStatus status = EMBER_ZCL_STATUS_SUCCESS;
Status status = Status::Success;
auto & tempAccountIdentifier = commandData.tempAccountIdentifier;
auto & setupPin = commandData.setupPIN;

Expand All @@ -145,42 +146,42 @@ bool emberAfAccountLoginClusterLoginCallback(app::CommandHandler * command, cons

if (!delegate->HandleLogin(tempAccountIdentifier, setupPin))
{
status = EMBER_ZCL_STATUS_UNSUPPORTED_ACCESS;
status = Status::UnsupportedAccess;
}

exit:
if (err != CHIP_NO_ERROR)
{
ChipLogError(Zcl, "emberAfAccountLoginClusterLoginCallback error: %s", err.AsString());
status = EMBER_ZCL_STATUS_FAILURE;
status = Status::Failure;
}
emberAfSendImmediateDefaultResponse(status);
command->AddStatus(commandPath, status);
return true;
}

bool emberAfAccountLoginClusterLogoutCallback(app::CommandHandler * commandObj, const app::ConcreteCommandPath & commandPath,
const Commands::Logout::DecodableType & commandData)
{
CHIP_ERROR err = CHIP_NO_ERROR;
EndpointId endpoint = commandPath.mEndpointId;
EmberAfStatus status = EMBER_ZCL_STATUS_SUCCESS;
CHIP_ERROR err = CHIP_NO_ERROR;
EndpointId endpoint = commandPath.mEndpointId;
Status status = Status::Success;

Delegate * delegate = GetDelegate(endpoint);
VerifyOrExit(isDelegateNull(delegate, endpoint) != true, err = CHIP_ERROR_INCORRECT_STATE);

if (!delegate->HandleLogout())
{
status = EMBER_ZCL_STATUS_FAILURE;
status = Status::Failure;
}

exit:
if (err != CHIP_NO_ERROR)
{
ChipLogError(Zcl, "emberAfAccountLoginClusterLogoutCallback error: %s", err.AsString());
status = EMBER_ZCL_STATUS_FAILURE;
status = Status::Failure;
}

emberAfSendImmediateDefaultResponse(status);
commandObj->AddStatus(commandPath, status);
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ using namespace chip::app;
using namespace chip::app::Clusters;
using namespace chip::app::Clusters::AdministratorCommissioning;
using namespace chip::Protocols;
using chip::Protocols::InteractionModel::Status;

class AdministratorCommissioningAttrAccess : public AttributeAccessInterface
{
Expand Down Expand Up @@ -199,7 +200,7 @@ bool emberAfAdministratorCommissioningClusterRevokeCommissioningCallback(
{
Server::GetInstance().GetCommissioningWindowManager().CloseCommissioningWindow();
ChipLogProgress(Zcl, "Commissioning window is now closed");
emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_SUCCESS);
commandObj->AddStatus(commandPath, Status::Success);
}
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ static constexpr size_t kApplicationLauncherDelegateTableSize =
using chip::app::Clusters::ApplicationBasic::CatalogVendorApp;
using chip::app::Clusters::ApplicationLauncher::Delegate;
using ApplicationStatusEnum = app::Clusters::ApplicationBasic::ApplicationStatusEnum;
using chip::Protocols::InteractionModel::Status;

namespace {

Expand Down Expand Up @@ -301,7 +302,7 @@ bool emberAfApplicationLauncherClusterLaunchAppCallback(app::CommandHandler * co
if (err != CHIP_NO_ERROR)
{
ChipLogError(Zcl, "emberAfApplicationLauncherClusterLaunchAppCallback error: %s", err.AsString());
emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_FAILURE);
command->AddStatus(commandPath, Status::Failure);
}

return true;
Expand Down Expand Up @@ -390,7 +391,7 @@ bool emberAfApplicationLauncherClusterStopAppCallback(app::CommandHandler * comm
if (err != CHIP_NO_ERROR)
{
ChipLogError(Zcl, "emberAfApplicationLauncherClusterStopAppCallback error: %s", err.AsString());
emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_FAILURE);
command->AddStatus(commandPath, Status::Failure);
}

return true;
Expand Down Expand Up @@ -475,7 +476,7 @@ bool emberAfApplicationLauncherClusterHideAppCallback(app::CommandHandler * comm
if (err != CHIP_NO_ERROR)
{
ChipLogError(Zcl, "emberAfApplicationLauncherClusterStopAppCallback error: %s", err.AsString());
emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_FAILURE);
command->AddStatus(commandPath, Status::Failure);
}

return true;
Expand Down
15 changes: 8 additions & 7 deletions src/app/clusters/audio-output-server/audio-output-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

using namespace chip;
using namespace chip::app::Clusters::AudioOutput;
using chip::Protocols::InteractionModel::Status;

static constexpr size_t kAudioOutputDelegateTableSize =
EMBER_AF_AUDIO_OUTPUT_CLUSTER_SERVER_ENDPOINT_COUNT + CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT;
Expand Down Expand Up @@ -212,27 +213,27 @@ bool emberAfAudioOutputClusterRenameOutputCallback(app::CommandHandler * command
bool emberAfAudioOutputClusterSelectOutputCallback(app::CommandHandler * command, const app::ConcreteCommandPath & commandPath,
const Commands::SelectOutput::DecodableType & commandData)
{
CHIP_ERROR err = CHIP_NO_ERROR;
EndpointId endpoint = commandPath.mEndpointId;
EmberAfStatus status = EMBER_ZCL_STATUS_SUCCESS;
auto & index = commandData.index;
CHIP_ERROR err = CHIP_NO_ERROR;
EndpointId endpoint = commandPath.mEndpointId;
Status status = Status::Success;
auto & index = commandData.index;

Delegate * delegate = GetDelegate(endpoint);
VerifyOrExit(isDelegateNull(delegate, endpoint) != true, err = CHIP_ERROR_INCORRECT_STATE);

if (!delegate->HandleSelectOutput(index))
{
status = EMBER_ZCL_STATUS_FAILURE;
status = Status::Failure;
}

exit:
if (err != CHIP_NO_ERROR)
{
ChipLogError(Zcl, "emberAfAudioOutputClusterSelectOutputCallback error: %s", err.AsString());
status = EMBER_ZCL_STATUS_FAILURE;
status = Status::Failure;
}

emberAfSendImmediateDefaultResponse(status);
command->AddStatus(commandPath, status);
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
using namespace chip;
using namespace chip::app::Clusters;
using namespace chip::app::Clusters::BarrierControl;
using chip::Protocols::InteractionModel::Status;

typedef struct
{
Expand Down Expand Up @@ -258,9 +259,9 @@ void emberAfBarrierControlClusterServerTickCallback(EndpointId endpoint)
// -----------------------------------------------------------------------------
// Handling commands

static void sendDefaultResponse(EmberAfStatus status)
static void sendDefaultResponse(app::CommandHandler * commandObj, const app::ConcreteCommandPath & commandPath, Status status)
{
if (emberAfSendImmediateDefaultResponse(status) != EMBER_SUCCESS)
if (commandObj->AddStatus(commandPath, status) != CHIP_NO_ERROR)
{
emberAfBarrierControlClusterPrintln("Failed to send default response");
}
Expand All @@ -272,21 +273,21 @@ bool emberAfBarrierControlClusterBarrierControlGoToPercentCallback(
{
auto & percentOpen = commandData.percentOpen;

EndpointId endpoint = commandPath.mEndpointId;
EmberAfStatus status = EMBER_ZCL_STATUS_SUCCESS;
EndpointId endpoint = commandPath.mEndpointId;
Status status = Status::Success;

emberAfBarrierControlClusterPrintln("RX: GoToPercentCallback p=%d", percentOpen);

if (isRemoteLockoutOn(endpoint))
{
status = EMBER_ZCL_STATUS_FAILURE;
status = Status::Failure;
}
else if (percentOpen > 100 // "100" means "100%", so greater than that is invalid
|| (!emAfPluginBarrierControlServerIsPartialBarrierSupported(endpoint) &&
percentOpen != EMBER_ZCL_BARRIER_CONTROL_BARRIER_POSITION_CLOSED &&
percentOpen != EMBER_ZCL_BARRIER_CONTROL_BARRIER_POSITION_OPEN))
{
status = EMBER_ZCL_STATUS_CONSTRAINT_ERROR;
status = Status::ConstraintError;
}
else
{
Expand All @@ -307,7 +308,7 @@ bool emberAfBarrierControlClusterBarrierControlGoToPercentCallback(
}
}

sendDefaultResponse(status);
sendDefaultResponse(commandObj, commandPath, status);

return true;
}
Expand All @@ -319,7 +320,7 @@ bool emberAfBarrierControlClusterBarrierControlStopCallback(app::CommandHandler
EndpointId endpoint = commandPath.mEndpointId;
emberAfDeactivateServerTick(endpoint, BarrierControl::Id);
setMovingState(endpoint, EMBER_ZCL_BARRIER_CONTROL_MOVING_STATE_STOPPED);
sendDefaultResponse(EMBER_ZCL_STATUS_SUCCESS);
sendDefaultResponse(commandObj, commandPath, Status::Success);
return true;
}

Expand Down
Loading

0 comments on commit 2508752

Please sign in to comment.