From 81f621bb92e4a2065830bb54523a9b73ea993b2b Mon Sep 17 00:00:00 2001 From: "Mykola Korniichuk (GitHub)" <42380041+mkorniichuk@users.noreply.github.com> Date: Fri, 13 Sep 2019 16:01:37 +0300 Subject: Error message processing from HMI (#3016) * git error message processing from HMI * Fix comments and signed-unsigned conversion * fixup! Fix comments and signed-unsigned conversion --- .../commands/command_request_impl.h | 26 ++++++++++++------ .../custom_vehicle_data_manager.h | 2 ++ .../custom_vehicle_data_manager_impl.h | 2 ++ .../commands/mobile/get_vehicle_data_request.cc | 32 ++++++++++++++++------ .../src/custom_vehicle_data_manager_impl.cc | 6 ++++ .../mobile/get_vehicle_data_request_test.cc | 6 +++- .../mock_custom_vehicle_data_manager.h | 2 ++ .../src/commands/command_request_impl.cc | 32 +++++++++++----------- .../application_manager/src/rpc_handler_impl.cc | 2 +- 9 files changed, 76 insertions(+), 34 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 5e46021c83..293366f91a 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 @@ -214,6 +214,24 @@ class CommandRequestImpl : public CommandImpl, mobile_apis::Result::eType GetMobileResultCode( const hmi_apis::Common_Result::eType& hmi_code) const; + /** + * @brief Checks Mobile result code for single RPC + * @param result_code contains result code from response to Mobile + * @return true if result code complies to successful result codes, + * false otherwise. + */ + static bool IsMobileResultSuccess( + const mobile_apis::Result::eType result_code); + + /** + * @brief Checks HMI result code for single RPC + * @param result_code contains result code from HMI response + * @return true if result code complies to successful result codes, + * false otherwise. + */ + static bool IsHMIResultSuccess( + const hmi_apis::Common_Result::eType result_code); + protected: /** * @brief Checks message permissions and parameters according to policy table @@ -248,14 +266,6 @@ class CommandRequestImpl : public CommandImpl, */ bool HasDisallowedParams() const; - /** - * @brief Checks result code from Mobile for single RPC - * @param result_code contains result code from Mobile response - * @return true if result code complies successful result codes, - * false otherwise. - */ - bool IsMobileResultSuccess(mobile_apis::Result::eType result_code) const; - /** * @brief Checks result code from HMI for single RPC * and returns parameter for sending to mobile app. diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/custom_vehicle_data_manager.h b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/custom_vehicle_data_manager.h index 45c7da726d..b34a9f84b8 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/custom_vehicle_data_manager.h +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/custom_vehicle_data_manager.h @@ -39,6 +39,8 @@ class CustomVehicleDataManager { smart_objects::SmartObject& msg_params) = 0; virtual void OnPolicyEvent(plugin_manager::PolicyEvent policy_event) = 0; + + virtual bool IsValidCustomVehicleDataName(const std::string& name) const = 0; }; } // namespace vehicle_info_plugin #endif // SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_VEHICLE_INFO_PLUGIN_INCLUDE_VEHICLE_INFO_PLUGIN_CUSTOM_VEHICLE_DATA_MANAGER_H_ diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/custom_vehicle_data_manager_impl.h b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/custom_vehicle_data_manager_impl.h index 1d689b087b..701bb1ba74 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/custom_vehicle_data_manager_impl.h +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/custom_vehicle_data_manager_impl.h @@ -40,6 +40,8 @@ class CustomVehicleDataManagerImpl : public CustomVehicleDataManager { void OnPolicyEvent(plugin_manager::PolicyEvent policy_event) OVERRIDE; + bool IsValidCustomVehicleDataName(const std::string& name) const OVERRIDE; + private: class RPCParams { public: diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/mobile/get_vehicle_data_request.cc b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/mobile/get_vehicle_data_request.cc index e389c87894..d15cf6a580 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/mobile/get_vehicle_data_request.cc +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/mobile/get_vehicle_data_request.cc @@ -116,16 +116,31 @@ void GetVehicleDataRequest::on_event(const event_engine::Event& event) { switch (event.id()) { case hmi_apis::FunctionID::VehicleInfo_GetVehicleData: { EndAwaitForInterface(HmiInterfaces::HMI_INTERFACE_VehicleInfo); - hmi_apis::Common_Result::eType result_code = - static_cast( - message[strings::params][hmi_response::code].asInt()); + auto result_code = static_cast( + message[strings::params][hmi_response::code].asInt()); + auto mobile_result_code = GetMobileResultCode(result_code); bool result = PrepareResultForMobileResponse( result_code, HmiInterfaces::HMI_INTERFACE_VehicleInfo); std::string response_info; GetInfo(message, response_info); - result = result || - ((hmi_apis::Common_Result::DATA_NOT_AVAILABLE == result_code) && - (message[strings::msg_params].length() > 1)); + + auto data_not_available_with_params = [this, &result_code, &message]() { + if (hmi_apis::Common_Result::DATA_NOT_AVAILABLE != result_code) { + return false; + } + + const auto& vehicle_data = MessageHelper::vehicle_data(); + const auto& msg_params = message[strings::msg_params]; + for (const auto& item : msg_params.enumerate()) { + if (vehicle_data.end() != vehicle_data.find(item) || + custom_vehicle_data_manager_.IsValidCustomVehicleDataName(item)) { + return true; + } + } + return false; + }; + + result = result || data_not_available_with_params(); if (true == message[strings::msg_params].keyExists(hmi_response::method)) { @@ -147,7 +162,8 @@ void GetVehicleDataRequest::on_event(const event_engine::Event& event) { } } - if (message[strings::msg_params].empty()) { + if (message[strings::msg_params].empty() && + hmi_apis::Common_Result::DATA_NOT_AVAILABLE != result_code) { response_info = "Failed to retrieve data from vehicle"; SendResponse( false, mobile_apis::Result::GENERIC_ERROR, response_info.c_str()); @@ -156,7 +172,7 @@ void GetVehicleDataRequest::on_event(const event_engine::Event& event) { } SendResponse(result, - MessageHelper::HMIToMobileResult(result_code), + mobile_result_code, response_info.empty() ? NULL : response_info.c_str(), &(message[strings::msg_params])); break; diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/custom_vehicle_data_manager_impl.cc b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/custom_vehicle_data_manager_impl.cc index dd51d172c9..32cf2b957e 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/custom_vehicle_data_manager_impl.cc +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/custom_vehicle_data_manager_impl.cc @@ -71,6 +71,12 @@ std::string CustomVehicleDataManagerImpl::GetVehicleDataItemType( : vehicle_data_item_name; } +bool CustomVehicleDataManagerImpl::IsValidCustomVehicleDataName( + const std::string& name) const { + const auto& schema = FindSchemaByNameNonRecursive(name); + return schema.is_initialized(); +} + void CustomVehicleDataManagerImpl::CreateMobileMessageParams( smart_objects::SmartObject& msg_params) { using namespace application_manager; diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/mobile/get_vehicle_data_request_test.cc b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/mobile/get_vehicle_data_request_test.cc index 3d33566ca9..d27e332601 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/mobile/get_vehicle_data_request_test.cc +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/mobile/get_vehicle_data_request_test.cc @@ -229,7 +229,11 @@ TEST_F(GetVehicleDataRequestTest, OnEvent_DataNotAvailable_SUCCESS) { const hmi_apis::Common_Result::eType hmi_response_code = hmi_apis::Common_Result::DATA_NOT_AVAILABLE; const mobile_result::eType mobile_response_code = - mobile_result::DATA_NOT_AVAILABLE; + mobile_result::VEHICLE_DATA_NOT_AVAILABLE; + + am::VehicleData vehicle_data; + ON_CALL(mock_message_helper_, vehicle_data()) + .WillByDefault(ReturnRef(vehicle_data)); MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); (*command_msg)[am::strings::params][am::strings::connection_key] = diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/include/vehicle_info_plugin/mock_custom_vehicle_data_manager.h b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/include/vehicle_info_plugin/mock_custom_vehicle_data_manager.h index df7ecc8904..472568d378 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/include/vehicle_info_plugin/mock_custom_vehicle_data_manager.h +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/include/vehicle_info_plugin/mock_custom_vehicle_data_manager.h @@ -16,6 +16,8 @@ class MockCustomVehicleDataManager : public CustomVehicleDataManager { MOCK_CONST_METHOD1(GetVehicleDataItemType, std::string(const std::string& vehicle_data_item_name)); MOCK_METHOD1(OnPolicyEvent, void(plugin_manager::PolicyEvent policy_event)); + MOCK_CONST_METHOD1(IsValidCustomVehicleDataName, + bool(const std::string& name)); }; } // namespace vehicle_info_plugin 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 1379bc9f48..257ccfd9c3 100644 --- a/src/components/application_manager/src/commands/command_request_impl.cc +++ b/src/components/application_manager/src/commands/command_request_impl.cc @@ -189,13 +189,7 @@ ResponseInfo::ResponseInfo(const hmi_apis::Common_Result::eType result, interface_state = application_manager.hmi_interfaces().GetInterfaceState(hmi_interface); - is_ok = Compare( - result_code, - hmi_apis::Common_Result::SUCCESS, - hmi_apis::Common_Result::WARNINGS, - hmi_apis::Common_Result::WRONG_LANGUAGE, - hmi_apis::Common_Result::RETRY, - hmi_apis::Common_Result::SAVED); + is_ok = CommandRequestImpl::IsHMIResultSuccess(result_code); is_not_used = hmi_apis::Common_Result::INVALID_ENUM == result_code; @@ -897,7 +891,7 @@ bool CommandRequestImpl::HasDisallowedParams() const { } bool CommandRequestImpl::IsMobileResultSuccess( - mobile_apis::Result::eType result_code) const { + const mobile_apis::Result::eType result_code) { LOG4CXX_AUTO_TRACE(logger_); using namespace helpers; return Compare( @@ -909,18 +903,24 @@ bool CommandRequestImpl::IsMobileResultSuccess( mobile_apis::Result::SAVED); } +bool CommandRequestImpl::IsHMIResultSuccess( + const hmi_apis::Common_Result::eType result_code) { + LOG4CXX_AUTO_TRACE(logger_); + using namespace helpers; + return Compare( + result_code, + hmi_apis::Common_Result::SUCCESS, + hmi_apis::Common_Result::WARNINGS, + hmi_apis::Common_Result::WRONG_LANGUAGE, + hmi_apis::Common_Result::RETRY, + hmi_apis::Common_Result::SAVED); +} + bool CommandRequestImpl::PrepareResultForMobileResponse( hmi_apis::Common_Result::eType result_code, HmiInterfaces::InterfaceID interface) const { LOG4CXX_AUTO_TRACE(logger_); - using namespace helpers; - if (Compare( - result_code, - hmi_apis::Common_Result::SUCCESS, - hmi_apis::Common_Result::WARNINGS, - hmi_apis::Common_Result::WRONG_LANGUAGE, - hmi_apis::Common_Result::RETRY, - hmi_apis::Common_Result::SAVED)) { + if (IsHMIResultSuccess(result_code)) { return true; } diff --git a/src/components/application_manager/src/rpc_handler_impl.cc b/src/components/application_manager/src/rpc_handler_impl.cc index a2b1245882..d1ca05e9a1 100644 --- a/src/components/application_manager/src/rpc_handler_impl.cc +++ b/src/components/application_manager/src/rpc_handler_impl.cc @@ -405,7 +405,7 @@ bool RPCHandlerImpl::ConvertMessageToSO( "Convertion result: " << result << " function id " << output[jhs::S_PARAMS][jhs::S_FUNCTION_ID].asInt()); - if (!hmi_so_factory().attachSchema(output, !allow_unknown_parameters)) { + if (!hmi_so_factory().attachSchema(output, false)) { LOG4CXX_WARN(logger_, "Failed to attach schema to object."); return false; } -- cgit v1.2.1