From 9f94fcde4cd2d1a48171ca0e171cffdd5b437e87 Mon Sep 17 00:00:00 2001 From: Shobhit Adlakha Date: Wed, 31 Aug 2022 14:07:39 -0400 Subject: Fix CheckButtonName check for module types other than CLIMATE and RADIO (#3944) * Fix CheckButtonName to work with module types other than climate and radio * Move SOURCE button name from buttons_radio to buttons_audio * Revert "Move SOURCE button name from buttons_radio to buttons_audio" This reverts commit fde9b4bfee4cc1b1e98346c670e92816b52084cd. * Address review comment --- .../src/rc_capabilities_manager_impl.cc | 25 +++++++++++----------- 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/rc_capabilities_manager_impl.cc b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/rc_capabilities_manager_impl.cc index 75ccd46e4d..875455f545 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/rc_capabilities_manager_impl.cc +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/rc_capabilities_manager_impl.cc @@ -371,23 +371,24 @@ bool RCCapabilitiesManagerImpl::CheckButtonName( SDL_LOG_AUTO_TRACE(); auto rc_capabilities = hmi_capabilities_.rc_capability(); if (!rc_capabilities) { - SDL_LOG_ERROR("No remote controll capabilities available"); + SDL_LOG_ERROR("No remote control capabilities available"); return false; } - if (enums_value::kRadio == module_type) { - if (!helpers::in_range(RCHelpers::buttons_radio(), button_name)) { - SDL_LOG_WARN("Trying to acceess climate button with module type radio"); - return false; - } - } + auto module_type_mismatch = [&button_name, &module_type]( + const std::string& type, + const std::vector&& buttons) { + return (helpers::in_range(buttons, button_name) && type != module_type); + }; - if (enums_value::kClimate == module_type) { - if (!helpers::in_range(RCHelpers::buttons_climate(), button_name)) { - SDL_LOG_WARN("Trying to acceess radio button with module type climate"); - return false; - } + if (module_type_mismatch(enums_value::kRadio, RCHelpers::buttons_radio()) || + module_type_mismatch(enums_value::kClimate, + RCHelpers::buttons_climate())) { + SDL_LOG_WARN("Trying to access incompatible button: " + << button_name << " with module type: " << module_type); + return false; } + return true; } -- cgit v1.2.1