diff options
author | Andrii Kalinich (GitHub) <AKalinich@luxoft.com> | 2021-08-09 12:58:18 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-09 12:58:18 -0400 |
commit | 595d76585bdcc110ae4093a62f7ff77445aa88e2 (patch) | |
tree | 5129c00a6049aa447cd9a6de454ae2862624c56b | |
parent | c94a3cfb7d0dfc606c96c3cf08a5674b6e7ca1da (diff) | |
download | sdl_core-595d76585bdcc110ae4093a62f7ff77445aa88e2.tar.gz |
Fix handling of RC.SetGlobalProperties response (#3741)
* Added result processing and wrote a test for RC_SetGlobalProperties
* Apply suggestions from code review
Co-authored-by: Shobhit Adlakha <ShobhitAd@users.noreply.github.com>
* Added result processing and wrote a test for RC_SetGlobalProperties
Co-authored-by: Roman Reznichenko <roman.reznichenko@dxc.com>
Co-authored-by: Shobhit Adlakha <ShobhitAd@users.noreply.github.com>
5 files changed, 112 insertions, 10 deletions
diff --git a/src/components/application_manager/include/application_manager/commands/command_request_impl.h b/src/components/application_manager/include/application_manager/commands/command_request_impl.h index 5723de3b08..084340ad08 100644 --- a/src/components/application_manager/include/application_manager/commands/command_request_impl.h +++ b/src/components/application_manager/include/application_manager/commands/command_request_impl.h @@ -274,6 +274,22 @@ class CommandRequestImpl : public CommandImpl, ResponseInfo& out_second) const; /** + * @brief Checks result code from HMI for splitted RPC + * and returns parameter for sending to mobile app. + * @param out_first Contains result_code from HMI response and + * interface that returns response + * @param out_second Contains result_code from HMI response and + * interface that returns response + * @param out_third Contains result_code from HMI response and + * interface that returns response + * @return true if result code complies successful result code + * otherwise returns false + */ + bool PrepareResultForMobileResponse(ResponseInfo& out_first, + ResponseInfo& out_second, + ResponseInfo& out_third) const; + + /** * @brief If message from HMI contains returns this info * or process result code from HMI and checks state of interface * and create info. @@ -297,6 +313,19 @@ class CommandRequestImpl : public CommandImpl, const ResponseInfo& first, const ResponseInfo& second); /** + * @brief Prepare result code for sending to mobile application + * @param first contains result_code from HMI response and + * interface that returns response + * @param second contains result_code from HMI response and + * interface that returns response. + * @return resulting code for sending to mobile application. + */ + mobile_apis::Result::eType PrepareResultCodeForResponse( + const ResponseInfo& first, + const ResponseInfo& second, + const ResponseInfo& third); + + /** * @brief Resolves if the return code must be * UNSUPPORTED_RESOURCE * @param first contains result_code from HMI response and diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/reset_global_properties_request.h b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/reset_global_properties_request.h index 7475520889..760eb09c2d 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/reset_global_properties_request.h +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/reset_global_properties_request.h @@ -105,7 +105,9 @@ class ResetGlobalPropertiesRequest hmi_apis::Common_Result::eType ui_result_; hmi_apis::Common_Result::eType tts_result_; + hmi_apis::Common_Result::eType rc_result_; std::string ui_response_info_; + std::string rc_response_info_; std::string tts_response_info_; }; diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/reset_global_properties_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/reset_global_properties_request.cc index f4e07d4b78..dd5e3d3e88 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/reset_global_properties_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/reset_global_properties_request.cc @@ -58,7 +58,8 @@ ResetGlobalPropertiesRequest::ResetGlobalPropertiesRequest( hmi_capabilities, policy_handler) , ui_result_(hmi_apis::Common_Result::INVALID_ENUM) - , tts_result_(hmi_apis::Common_Result::INVALID_ENUM) {} + , tts_result_(hmi_apis::Common_Result::INVALID_ENUM) + , rc_result_(hmi_apis::Common_Result::INVALID_ENUM) {} ResetGlobalPropertiesRequest::~ResetGlobalPropertiesRequest() {} @@ -146,6 +147,14 @@ void ResetGlobalPropertiesRequest::on_event(const event_engine::Event& event) { GetInfo(message, tts_response_info_); break; } + case hmi_apis::FunctionID::RC_SetGlobalProperties: { + SDL_LOG_INFO("Received RC_SetGlobalProperties event"); + EndAwaitForInterface(HmiInterfaces::HMI_INTERFACE_RC); + rc_result_ = static_cast<hmi_apis::Common_Result::eType>( + message[strings::params][hmi_response::code].asInt()); + GetInfo(message, rc_response_info_); + break; + } default: { SDL_LOG_ERROR("Received unknown event " << event.id()); return; @@ -183,6 +192,8 @@ bool ResetGlobalPropertiesRequest::PrepareResponseParameters( ui_result_, HmiInterfaces::HMI_INTERFACE_UI, application_manager_); app_mngr::commands::ResponseInfo tts_properties_info( tts_result_, HmiInterfaces::HMI_INTERFACE_TTS, application_manager_); + app_mngr::commands::ResponseInfo rc_properties_info( + rc_result_, HmiInterfaces::HMI_INTERFACE_RC, application_manager_); HmiInterfaces::InterfaceState tts_interface_state = application_manager_.hmi_interfaces().GetInterfaceState( @@ -195,14 +206,13 @@ bool ResetGlobalPropertiesRequest::PrepareResponseParameters( out_result_code = mobile_apis::Result::WARNINGS; out_response_info = "Unsupported phoneme type sent in a prompt"; } else { - result = - PrepareResultForMobileResponse(ui_properties_info, tts_properties_info); - out_result_code = - PrepareResultCodeForResponse(ui_properties_info, tts_properties_info); - out_response_info = app_mngr::commands::MergeInfos(tts_properties_info, - tts_response_info_, - ui_properties_info, - ui_response_info_); + result = PrepareResultForMobileResponse( + ui_properties_info, tts_properties_info, rc_properties_info); + out_result_code = PrepareResultCodeForResponse( + ui_properties_info, tts_properties_info, rc_properties_info); + + out_response_info = app_mngr::commands::MergeInfos( + tts_response_info_, ui_response_info_, rc_response_info_); } return result; @@ -210,7 +220,8 @@ bool ResetGlobalPropertiesRequest::PrepareResponseParameters( bool ResetGlobalPropertiesRequest::IsPendingResponseExist() { return IsInterfaceAwaited(HmiInterfaces::HMI_INTERFACE_TTS) || - IsInterfaceAwaited(HmiInterfaces::HMI_INTERFACE_UI); + IsInterfaceAwaited(HmiInterfaces::HMI_INTERFACE_UI) || + IsInterfaceAwaited(HmiInterfaces::HMI_INTERFACE_RC); } } // namespace commands diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/reset_global_properties_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/reset_global_properties_test.cc index 8ca15f39fe..f62f6b4682 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/reset_global_properties_test.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/reset_global_properties_test.cc @@ -282,6 +282,42 @@ TEST_F(ResetGlobalPropertiesRequestTest, command_->on_event(event); } +TEST_F(ResetGlobalPropertiesRequestTest, + OnEvent_RC_SetGlobalProperties_SUCCESS) { + am::ResetGlobalPropertiesResult result; + result.user_location = true; + + EXPECT_CALL(app_mngr_, ResetGlobalProperties(_, _)).WillOnce(Return(result)); + + smart_objects::SmartObjectSPtr msg_params = + std::make_shared<smart_objects::SmartObject>( + smart_objects::SmartType_Map); + + EXPECT_CALL(mock_message_helper_, CreateRCResetGlobalPropertiesRequest(_, _)) + .WillOnce(Return(msg_params)); + + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand( + HMIResultCodeIs(hmi_apis::FunctionID::RC_SetGlobalProperties), _)) + .WillOnce(Return(true)); + + command_->Run(); + + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand( + MobileResultCodeIs(mobile_apis::Result::eType::SUCCESS), + am::commands::Command::SOURCE_SDL)); + + (*msg_)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::SUCCESS; + + Event event(hmi_apis::FunctionID::RC_SetGlobalProperties); + event.set_smart_object(*msg_); + + command_->on_event(event); +} + TEST_F(ResetGlobalPropertiesResponseTest, Run_Sendmsg_SUCCESS) { MessageSharedPtr message(CreateMessage()); ResetGlobalPropertiesResponsePtr command( diff --git a/src/components/application_manager/src/commands/command_request_impl.cc b/src/components/application_manager/src/commands/command_request_impl.cc index 0bf3716aa9..dad2689f29 100644 --- a/src/components/application_manager/src/commands/command_request_impl.cc +++ b/src/components/application_manager/src/commands/command_request_impl.cc @@ -748,6 +748,17 @@ bool CommandRequestImpl::PrepareResultForMobileResponse( return result; } +bool CommandRequestImpl::PrepareResultForMobileResponse( + ResponseInfo& out_first, + ResponseInfo& out_second, + ResponseInfo& out_third) const { + SDL_LOG_AUTO_TRACE(); + bool result = (PrepareResultForMobileResponse(out_first, out_second) || + PrepareResultForMobileResponse(out_second, out_third)) && + PrepareResultForMobileResponse(out_first, out_third); + return result; +} + void CommandRequestImpl::GetInfo( const smart_objects::SmartObject& response_from_hmi, std::string& out_info) { @@ -787,6 +798,19 @@ mobile_apis::Result::eType CommandRequestImpl::PrepareResultCodeForResponse( return result_code; } +mobile_apis::Result::eType CommandRequestImpl::PrepareResultCodeForResponse( + const ResponseInfo& first, + const ResponseInfo& second, + const ResponseInfo& third) { + SDL_LOG_AUTO_TRACE(); + + const auto first_comparison = PrepareResultCodeForResponse(first, second); + const auto second_comparison = PrepareResultCodeForResponse(second, third); + const auto third_comparison = PrepareResultCodeForResponse(first, third); + + return std::max({first_comparison, second_comparison, third_comparison}); +} + const CommandParametersPermissions& CommandRequestImpl::parameters_permissions() const { return parameters_permissions_; |