diff options
Diffstat (limited to 'src/components/application_manager/src/commands/mobile/alert_maneuver_request.cc')
-rw-r--r-- | src/components/application_manager/src/commands/mobile/alert_maneuver_request.cc | 174 |
1 files changed, 111 insertions, 63 deletions
diff --git a/src/components/application_manager/src/commands/mobile/alert_maneuver_request.cc b/src/components/application_manager/src/commands/mobile/alert_maneuver_request.cc index f1575a1a4b..ea00bc8d70 100644 --- a/src/components/application_manager/src/commands/mobile/alert_maneuver_request.cc +++ b/src/components/application_manager/src/commands/mobile/alert_maneuver_request.cc @@ -1,6 +1,5 @@ /* - - Copyright (c) 2013, Ford Motor Company + Copyright (c) 2016, Ford Motor Company All rights reserved. Redistribution and use in source and binary forms, with or without @@ -31,25 +30,28 @@ POSSIBILITY OF SUCH DAMAGE. */ -#include <string.h> +#include <cstring> +#include <string> #include "application_manager/commands/mobile/alert_maneuver_request.h" -#include "application_manager/application_manager_impl.h" + #include "application_manager/application_impl.h" +#include "application_manager/policies/policy_handler.h" #include "application_manager/message_helper.h" +#include "utils/helpers.h" namespace application_manager { namespace commands { -AlertManeuverRequest::AlertManeuverRequest(const MessageSharedPtr& message) - : CommandRequestImpl(message), - tts_speak_result_code_(mobile_apis::Result::INVALID_ENUM), - navi_alert_maneuver_result_code_(mobile_apis::Result::INVALID_ENUM) { +AlertManeuverRequest::AlertManeuverRequest( + const MessageSharedPtr& message, ApplicationManager& application_manager) + : CommandRequestImpl(message, application_manager) + , tts_speak_result_code_(mobile_apis::Result::INVALID_ENUM) + , navi_alert_maneuver_result_code_(mobile_apis::Result::INVALID_ENUM) { subscribe_on_event(hmi_apis::FunctionID::TTS_OnResetTimeout); } -AlertManeuverRequest::~AlertManeuverRequest() { -} +AlertManeuverRequest::~AlertManeuverRequest() {} void AlertManeuverRequest::Run() { LOG4CXX_AUTO_TRACE(logger_); @@ -61,7 +63,7 @@ void AlertManeuverRequest::Run() { return; } - ApplicationSharedPtr app = ApplicationManagerImpl::instance()->application( + ApplicationSharedPtr app = application_manager_.application( (*message_)[strings::params][strings::connection_key].asUInt()); if (NULL == app.get()) { @@ -78,10 +80,13 @@ void AlertManeuverRequest::Run() { return; } - //ProcessSoftButtons checks strings on the contents incorrect character + // ProcessSoftButtons checks strings on the contents incorrect character mobile_apis::Result::eType processing_result = - MessageHelper::ProcessSoftButtons((*message_)[strings::msg_params], app); + MessageHelper::ProcessSoftButtons((*message_)[strings::msg_params], + app, + application_manager_.GetPolicyHandler(), + application_manager_); if (mobile_apis::Result::SUCCESS != processing_result) { LOG4CXX_ERROR(logger_, "Wrong soft buttons parameters!"); @@ -100,25 +105,25 @@ void AlertManeuverRequest::Run() { } } - smart_objects::SmartObject msg_params = smart_objects::SmartObject( - smart_objects::SmartType_Map); + smart_objects::SmartObject msg_params = + smart_objects::SmartObject(smart_objects::SmartType_Map); msg_params[strings::app_id] = app->app_id(); if ((*message_)[strings::msg_params].keyExists(strings::soft_buttons)) { msg_params[hmi_request::soft_buttons] = - (*message_)[strings::msg_params][strings::soft_buttons]; - MessageHelper::SubscribeApplicationToSoftButton((*message_)[strings::msg_params], - app, function_id()); + (*message_)[strings::msg_params][strings::soft_buttons]; + MessageHelper::SubscribeApplicationToSoftButton( + (*message_)[strings::msg_params], app, function_id()); } pending_requests_.Add(hmi_apis::FunctionID::Navigation_AlertManeuver); - SendHMIRequest(hmi_apis::FunctionID::Navigation_AlertManeuver, - &msg_params, true); + SendHMIRequest( + hmi_apis::FunctionID::Navigation_AlertManeuver, &msg_params, true); if (tts_is_ok) { - smart_objects::SmartObject msg_params = smart_objects::SmartObject( - smart_objects::SmartType_Map); + smart_objects::SmartObject msg_params = + smart_objects::SmartObject(smart_objects::SmartType_Map); msg_params[hmi_request::tts_chunks] = (*message_)[strings::msg_params][strings::tts_chunks]; @@ -131,9 +136,12 @@ void AlertManeuverRequest::Run() { void AlertManeuverRequest::on_event(const event_engine::Event& event) { LOG4CXX_AUTO_TRACE(logger_); + using namespace helpers; const smart_objects::SmartObject& message = event.smart_object(); - - mobile_apis::Result::eType result_code = mobile_apis::Result::INVALID_ENUM; + bool is_tts_ok; + bool is_no_navi_error; + hmi_apis::Common_Result::eType tts_result; + hmi_apis::Common_Result::eType navi_result; hmi_apis::FunctionID::eType event_id = event.id(); switch (event_id) { case hmi_apis::FunctionID::Navigation_AlertManeuver: { @@ -143,8 +151,23 @@ void AlertManeuverRequest::on_event(const event_engine::Event& event) { navi_alert_maneuver_result_code_ = static_cast<mobile_apis::Result::eType>( - message[strings::params][hmi_response::code].asInt()); - + message[strings::params][hmi_response::code].asInt()); + navi_result = + MessageHelper::MobileToHMIResult(navi_alert_maneuver_result_code_); + is_no_navi_error = Compare<hmi_apis::Common_Result::eType, EQ, ONE>( + navi_result, + hmi_apis::Common_Result::SUCCESS, + hmi_apis::Common_Result::WARNINGS); + + const bool is_navi_success = + Compare<hmi_apis::Common_Result::eType, EQ, ONE>( + navi_result, hmi_apis::Common_Result::SUCCESS); + if (is_navi_success) { + info_navi_ = + message[strings::msg_params][hmi_response::message].asString(); + } else { + info_navi_ = message[strings::msg_params][strings::info].asString(); + } break; } case hmi_apis::FunctionID::TTS_Speak: { @@ -152,60 +175,85 @@ void AlertManeuverRequest::on_event(const event_engine::Event& event) { pending_requests_.Remove(event_id); - tts_speak_result_code_ = - static_cast<mobile_apis::Result::eType>( + tts_speak_result_code_ = static_cast<mobile_apis::Result::eType>( message[strings::params][hmi_response::code].asInt()); + tts_result = MessageHelper::MobileToHMIResult(tts_speak_result_code_); + + is_tts_ok = Compare<hmi_apis::Common_Result::eType, EQ, ONE>( + tts_result, + hmi_apis::Common_Result::SUCCESS, + hmi_apis::Common_Result::UNSUPPORTED_RESOURCE, + hmi_apis::Common_Result::WARNINGS, + hmi_apis::Common_Result::INVALID_ENUM); + + const bool is_tts_success = + Compare<hmi_apis::Common_Result::eType, EQ, ONE>( + tts_result, hmi_apis::Common_Result::SUCCESS); + if (is_tts_success) { + info_tts_ = + message[strings::msg_params][hmi_response::message].asString(); + } else { + info_tts_ = message[strings::msg_params][strings::info].asString(); + } break; } case hmi_apis::FunctionID::TTS_OnResetTimeout: { LOG4CXX_INFO(logger_, "Received TTS_OnResetTimeout event"); - ApplicationManagerImpl::instance()->updateRequestTimeout( + application_manager_.updateRequestTimeout( connection_key(), correlation_id(), default_timeout()); break; } default: { - LOG4CXX_ERROR(logger_,"Received unknown event" << event.id()); - SendResponse(false, result_code, "Received unknown event"); + LOG4CXX_ERROR(logger_, "Received unknown event" << event.id()); + SendResponse( + false, mobile_apis::Result::INVALID_ENUM, "Received unknown event"); return; } } - if (pending_requests_.IsFinal(event_id)) { - - bool result = ((hmi_apis::Common_Result::SUCCESS == - static_cast<hmi_apis::Common_Result::eType>(tts_speak_result_code_) || - hmi_apis::Common_Result::UNSUPPORTED_RESOURCE == - static_cast<hmi_apis::Common_Result::eType>(tts_speak_result_code_) || - (hmi_apis::Common_Result::INVALID_ENUM == - static_cast<hmi_apis::Common_Result::eType>(tts_speak_result_code_))) && - (hmi_apis::Common_Result::SUCCESS == - static_cast<hmi_apis::Common_Result::eType>(navi_alert_maneuver_result_code_))) || - (hmi_apis::Common_Result::SUCCESS == static_cast<hmi_apis::Common_Result::eType>( - tts_speak_result_code_) && hmi_apis::Common_Result::UNSUPPORTED_RESOURCE == - static_cast<hmi_apis::Common_Result::eType>(navi_alert_maneuver_result_code_)); - - mobile_apis::Result::eType result_code = - static_cast<mobile_apis::Result::eType>(std::max(tts_speak_result_code_, - navi_alert_maneuver_result_code_)); - - const char* return_info = NULL; - - if (result && hmi_apis::Common_Result::UNSUPPORTED_RESOURCE == - static_cast<hmi_apis::Common_Result::eType>(tts_speak_result_code_)) { - result_code = mobile_apis::Result::WARNINGS; - return_info = - std::string("Unsupported phoneme type sent in a prompt").c_str(); - } + if (!pending_requests_.IsFinal(event_id)) { + LOG4CXX_DEBUG(logger_, + "There are some pending responses from HMI." + "AlertManeuverRequest still waiting."); + return; + } + + const bool result = + (is_tts_ok && is_no_navi_error) || + (hmi_apis::Common_Result::SUCCESS == tts_result && + hmi_apis::Common_Result::UNSUPPORTED_RESOURCE == navi_result); + + mobile_apis::Result::eType result_code = + static_cast<mobile_apis::Result::eType>( + std::max(tts_speak_result_code_, navi_alert_maneuver_result_code_)); + + std::string return_info; - SendResponse(result, result_code, return_info, - &(message[strings::msg_params])); - } else { - LOG4CXX_INFO(logger_, - "There are some pending responses from HMI." - "AlertManeuverRequest still waiting."); + const bool is_tts_or_navi_warning = + Compare<hmi_apis::Common_Result::eType, EQ, ONE>( + hmi_apis::Common_Result::WARNINGS, tts_result, navi_result); + + if (result && (is_tts_or_navi_warning || + hmi_apis::Common_Result::UNSUPPORTED_RESOURCE == tts_result)) { + result_code = mobile_apis::Result::WARNINGS; + return_info = std::string("Unsupported phoneme type sent in a prompt"); + } + + if (!info_tts_.empty() && !info_navi_.empty()) { + info_tts_ += ". "; + } + return_info = info_tts_ + info_navi_; + bool must_be_empty_info = false; + if (return_info.find("\n") != std::string::npos || + return_info.find("\t") != std::string::npos) { + must_be_empty_info = true; } + SendResponse(result, + result_code, + (must_be_empty_info) ? NULL : return_info.c_str(), + &(message[strings::msg_params])); } bool AlertManeuverRequest::IsWhiteSpaceExist() { |