diff --git a/src/app/clusters/media-input-server/media-input-server.cpp b/src/app/clusters/media-input-server/media-input-server.cpp index 12eda44fe57451..cff8580c9bf186 100644 --- a/src/app/clusters/media-input-server/media-input-server.cpp +++ b/src/app/clusters/media-input-server/media-input-server.cpp @@ -170,23 +170,26 @@ CHIP_ERROR MediaInputAttrAccess::ReadCurrentInputAttribute(app::AttributeValueEn bool emberAfMediaInputClusterSelectInputCallback(app::CommandHandler * command, const app::ConcreteCommandPath & commandPath, const Commands::SelectInput::DecodableType & commandData) { - CHIP_ERROR err = CHIP_NO_ERROR; - EndpointId endpoint = commandPath.mEndpointId; + CHIP_ERROR err = CHIP_NO_ERROR; + EndpointId endpoint = commandPath.mEndpointId; + EmberAfStatus status = EMBER_ZCL_STATUS_SUCCESS; auto & input = commandData.index; Delegate * delegate = GetDelegate(endpoint); VerifyOrExit(isDelegateNull(delegate, endpoint) != true, err = CHIP_ERROR_INCORRECT_STATE); + if (!delegate->HandleSelectInput(input)) + { + status = EMBER_ZCL_STATUS_FAILURE; + } exit: if (err != CHIP_NO_ERROR) { ChipLogError(Zcl, "emberAfMediaInputClusterSelectInputCallback error: %s", err.AsString()); - emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_FAILURE); + status = EMBER_ZCL_STATUS_FAILURE; } - bool success = delegate->HandleSelectInput(input); - EmberAfStatus status = success ? EMBER_ZCL_STATUS_SUCCESS : EMBER_ZCL_STATUS_FAILURE; emberAfSendImmediateDefaultResponse(status); return true; } @@ -194,21 +197,25 @@ bool emberAfMediaInputClusterSelectInputCallback(app::CommandHandler * command, bool emberAfMediaInputClusterShowInputStatusCallback(app::CommandHandler * command, const app::ConcreteCommandPath & commandPath, const Commands::ShowInputStatus::DecodableType & commandData) { - CHIP_ERROR err = CHIP_NO_ERROR; - EndpointId endpoint = commandPath.mEndpointId; + CHIP_ERROR err = CHIP_NO_ERROR; + EndpointId endpoint = commandPath.mEndpointId; + EmberAfStatus status = EMBER_ZCL_STATUS_SUCCESS; Delegate * delegate = GetDelegate(endpoint); VerifyOrExit(isDelegateNull(delegate, endpoint) != true, err = CHIP_ERROR_INCORRECT_STATE); + if (!delegate->HandleShowInputStatus()) + { + status = EMBER_ZCL_STATUS_FAILURE; + } + exit: if (err != CHIP_NO_ERROR) { ChipLogError(Zcl, "emberAfMediaInputClusterShowInputStatusCallback error: %s", err.AsString()); - emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_FAILURE); + status = EMBER_ZCL_STATUS_FAILURE; } - bool success = delegate->HandleShowInputStatus(); - EmberAfStatus status = success ? EMBER_ZCL_STATUS_SUCCESS : EMBER_ZCL_STATUS_FAILURE; emberAfSendImmediateDefaultResponse(status); return true; } @@ -216,21 +223,25 @@ bool emberAfMediaInputClusterShowInputStatusCallback(app::CommandHandler * comma bool emberAfMediaInputClusterHideInputStatusCallback(app::CommandHandler * command, const app::ConcreteCommandPath & commandPath, const Commands::HideInputStatus::DecodableType & commandData) { - CHIP_ERROR err = CHIP_NO_ERROR; - EndpointId endpoint = commandPath.mEndpointId; + CHIP_ERROR err = CHIP_NO_ERROR; + EndpointId endpoint = commandPath.mEndpointId; + EmberAfStatus status = EMBER_ZCL_STATUS_SUCCESS; Delegate * delegate = GetDelegate(endpoint); VerifyOrExit(isDelegateNull(delegate, endpoint) != true, err = CHIP_ERROR_INCORRECT_STATE); + if (!delegate->HandleHideInputStatus()) + { + status = EMBER_ZCL_STATUS_FAILURE; + } + exit: if (err != CHIP_NO_ERROR) { ChipLogError(Zcl, "emberAfMediaInputClusterHideInputStatusCallback error: %s", err.AsString()); - emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_FAILURE); + status = EMBER_ZCL_STATUS_FAILURE; } - bool success = delegate->HandleHideInputStatus(); - EmberAfStatus status = success ? EMBER_ZCL_STATUS_SUCCESS : EMBER_ZCL_STATUS_FAILURE; emberAfSendImmediateDefaultResponse(status); return true; } @@ -245,19 +256,30 @@ bool emberAfMediaInputClusterRenameInputCallback(app::CommandHandler * command, Delegate * delegate = GetDelegate(endpoint); VerifyOrExit(isDelegateNull(delegate, endpoint) != true, err = CHIP_ERROR_INCORRECT_STATE); + if (!HasFeature(endpoint, MediaInputFeature::kNameUpdates)) + { + ChipLogError(Zcl, "MediaInput no name updates feature"); + err = CHIP_ERROR_INCORRECT_STATE; + ExitNow(); + } -exit: - if (HasFeature(endpoint, MediaInputFeature::kNameUpdates) && err == CHIP_NO_ERROR) + Protocols::InteractionModel::Status status; + + if (delegate->HandleRenameInput(index, name)) { - bool success = delegate->HandleRenameInput(index, name); - Protocols::InteractionModel::Status status = - success ? Protocols::InteractionModel::Status::Success : Protocols::InteractionModel::Status::Failure; - command->AddStatus(commandPath, status); + status = Protocols::InteractionModel::Status::Success; } else { - err != CHIP_NO_ERROR ? ChipLogError(Zcl, "emberAfMediaInputClusterRenameInputCallback error: %s", err.AsString()) - : ChipLogError(Zcl, "MediaInput no name updates feature"); + status = Protocols::InteractionModel::Status::Failure; + } + command->AddStatus(commandPath, status); + +exit: + + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "emberAfMediaInputClusterRenameInputCallback error: %" CHIP_ERROR_FORMAT, err.Format()); command->AddStatus(commandPath, Protocols::InteractionModel::Status::Failure); }