Skip to content

Commit

Permalink
Improve the CommandResponseHelper API a bit. (#13485)
Browse files Browse the repository at this point in the history
Fix some grammar/style issues, stop using the deprecated
emberAfSendImmediateDefaultResponse API.
  • Loading branch information
bzbarsky-apple authored and pull[bot] committed May 13, 2022
1 parent 6b2c9cf commit 1080812
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 22 deletions.
45 changes: 35 additions & 10 deletions src/app/CommandResponseHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <app/CommandHandler.h>
#include <app/ConcreteCommandPath.h>
#include <app/util/af.h>
#include <protocols/interaction_model/Constants.h>

namespace chip {
namespace app {
Expand All @@ -30,31 +31,55 @@ class CommandResponseHelper
{
public:
CommandResponseHelper(app::CommandHandler * command, const app::ConcreteCommandPath & commandPath) :
mCommand(command), mCommandPath(commandPath), responsed(false)
mCommandHandler(command), mCommandPath(commandPath), mSentResponse(false)
{}

CHIP_ERROR Success(const CommandData & response)
CHIP_ERROR Success(const CommandData & aResponse)
{
CHIP_ERROR err = mCommand->AddResponseData(mCommandPath, response);
CHIP_ERROR err = mCommandHandler->AddResponseData(mCommandPath, aResponse);
if (err == CHIP_NO_ERROR)
{
responsed = true;
mSentResponse = true;
}
return err;
};

void Response(EmberAfStatus status)
CHIP_ERROR Success(ClusterStatus aClusterStatus)
{
emberAfSendImmediateDefaultResponse(status);
responsed = true;
CHIP_ERROR err = mCommandHandler->AddClusterSpecificSuccess(mCommandPath, aClusterStatus);
if (err == CHIP_NO_ERROR)
{
mSentResponse = true;
}
return err;
}

CHIP_ERROR Failure(Protocols::InteractionModel::Status aStatus)
{
CHIP_ERROR err = mCommandHandler->AddStatus(mCommandPath, aStatus);
if (err == CHIP_NO_ERROR)
{
mSentResponse = true;
}
return err;
}

CHIP_ERROR Failure(ClusterStatus aClusterStatus)
{
CHIP_ERROR err = mCommandHandler->AddClusterSpecificFailure(mCommandPath, aClusterStatus);
if (err == CHIP_NO_ERROR)
{
mSentResponse = true;
}
return err;
}

bool IsResponsed() { return responsed; }
bool HasSentResponse() const { return mSentResponse; }

private:
app::CommandHandler * mCommand;
app::CommandHandler * mCommandHandler;
app::ConcreteCommandPath mCommandPath;
bool responsed;
bool mSentResponse;
};

} // namespace app
Expand Down
8 changes: 4 additions & 4 deletions src/app/clusters/channel-server/channel-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,12 @@ bool emberAfChannelClusterChangeChannelRequestCallback(app::CommandHandler * com

auto & match = commandData.match;

app::CommandResponseHelper<Commands::ChangeChannelResponse::Type> responser(command, commandPath);
app::CommandResponseHelper<Commands::ChangeChannelResponse::Type> responder(command, commandPath);

Delegate * delegate = GetDelegate(endpoint);
VerifyOrExit(isDelegateNull(delegate, endpoint) != true, err = CHIP_ERROR_INCORRECT_STATE);
{
delegate->HandleChangeChannel(match, responser);
delegate->HandleChangeChannel(match, responder);
}

exit:
Expand All @@ -188,8 +188,8 @@ bool emberAfChannelClusterChangeChannelRequestCallback(app::CommandHandler * com
ChipLogError(Zcl, "emberAfChannelClusterChangeChannelRequestCallback error: %s", err.AsString());
}

// If isDelegateNull, no one will call responser, so IsResponsed will be false
if (!responser.IsResponsed())
// If isDelegateNull, no one will call responder, so HasSentResponse will be false
if (!responder.HasSentResponse())
{
emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_FAILURE);
}
Expand Down
16 changes: 8 additions & 8 deletions src/app/clusters/content-launch-server/content-launch-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,12 @@ bool emberAfContentLauncherClusterLaunchContentRequestCallback(
// auto searchIterator = commandData.search.begin();
std::list<Parameter> parameterList;

app::CommandResponseHelper<Commands::LaunchResponse::Type> responser(commandObj, commandPath);
app::CommandResponseHelper<Commands::LaunchResponse::Type> responder(commandObj, commandPath);

Delegate * delegate = GetDelegate(endpoint);
VerifyOrExit(isDelegateNull(delegate, endpoint) != true, err = CHIP_ERROR_INCORRECT_STATE);
{
delegate->HandleLaunchContent(parameterList, autoplay, data, responser);
delegate->HandleLaunchContent(parameterList, autoplay, data, responder);
}

exit:
Expand All @@ -191,8 +191,8 @@ bool emberAfContentLauncherClusterLaunchContentRequestCallback(
ChipLogError(Zcl, "emberAfContentLauncherClusterLaunchContentRequestCallback error: %s", err.AsString());
}

// If isDelegateNull, no one will call responser, so IsResponsed will be false
if (!responser.IsResponsed())
// If isDelegateNull, no one will call responder, so HasSentResponse will be false
if (!responder.HasSentResponse())
{
emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_FAILURE);
}
Expand All @@ -213,12 +213,12 @@ bool emberAfContentLauncherClusterLaunchURLRequestCallback(
// auto brandingInformationIterator = commandData.brandingInformation.begin();
std::list<BrandingInformation> brandingInformationList;

app::CommandResponseHelper<Commands::LaunchResponse::Type> responser(commandObj, commandPath);
app::CommandResponseHelper<Commands::LaunchResponse::Type> responder(commandObj, commandPath);

Delegate * delegate = GetDelegate(endpoint);
VerifyOrExit(isDelegateNull(delegate, endpoint) != true, err = CHIP_ERROR_INCORRECT_STATE);
{
delegate->HandleLaunchUrl(contentUrl, displayString, brandingInformationList, responser);
delegate->HandleLaunchUrl(contentUrl, displayString, brandingInformationList, responder);
}

exit:
Expand All @@ -227,8 +227,8 @@ bool emberAfContentLauncherClusterLaunchURLRequestCallback(
ChipLogError(Zcl, "emberAfContentLauncherClusterLaunchURLCallback error: %s", err.AsString());
}

// If isDelegateNull, no one will call responser, so IsResponsed will be false
if (!responser.IsResponsed())
// If isDelegateNull, no one will call responder, so HasSentResponse will be false
if (!responder.HasSentResponse())
{
emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_FAILURE);
}
Expand Down

0 comments on commit 1080812

Please sign in to comment.