diff --git a/src/app/CommandResponseHelper.h b/src/app/CommandResponseHelper.h index 840a8a590fc5ff..7785f2b10aefb8 100644 --- a/src/app/CommandResponseHelper.h +++ b/src/app/CommandResponseHelper.h @@ -21,6 +21,7 @@ #include #include #include +#include namespace chip { namespace app { @@ -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 diff --git a/src/app/clusters/channel-server/channel-server.cpp b/src/app/clusters/channel-server/channel-server.cpp index bc68441b9389fe..e97bc13caeeaae 100644 --- a/src/app/clusters/channel-server/channel-server.cpp +++ b/src/app/clusters/channel-server/channel-server.cpp @@ -174,12 +174,12 @@ bool emberAfChannelClusterChangeChannelRequestCallback(app::CommandHandler * com auto & match = commandData.match; - app::CommandResponseHelper responser(command, commandPath); + app::CommandResponseHelper 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: @@ -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); } diff --git a/src/app/clusters/content-launch-server/content-launch-server.cpp b/src/app/clusters/content-launch-server/content-launch-server.cpp index 079f459eb974eb..322daa310a682a 100644 --- a/src/app/clusters/content-launch-server/content-launch-server.cpp +++ b/src/app/clusters/content-launch-server/content-launch-server.cpp @@ -177,12 +177,12 @@ bool emberAfContentLauncherClusterLaunchContentRequestCallback( // auto searchIterator = commandData.search.begin(); std::list parameterList; - app::CommandResponseHelper responser(commandObj, commandPath); + app::CommandResponseHelper 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: @@ -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); } @@ -213,12 +213,12 @@ bool emberAfContentLauncherClusterLaunchURLRequestCallback( // auto brandingInformationIterator = commandData.brandingInformation.begin(); std::list brandingInformationList; - app::CommandResponseHelper responser(commandObj, commandPath); + app::CommandResponseHelper 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: @@ -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); }