From 8d4e72221aac525c101dd9772fc8bf6dd3db93b9 Mon Sep 17 00:00:00 2001 From: Alexander Kutsan Date: Fri, 4 Apr 2014 14:32:11 +0300 Subject: [PATCH] APPLINK-6567 VR.PerformInteraction --- .../commands/mobile/perform_interaction_request.h | 8 +- .../hmi/vr_perform_interaction_response.cc | 4 + .../create_interaction_choice_set_request.cc | 27 ------- .../commands/mobile/perform_interaction_request.cc | 90 ++++++++++++++++------ 4 files changed, 76 insertions(+), 53 deletions(-) diff --git a/src/components/application_manager/include/application_manager/commands/mobile/perform_interaction_request.h b/src/components/application_manager/include/application_manager/commands/mobile/perform_interaction_request.h index 912433c..7ede57f 100644 --- a/src/components/application_manager/include/application_manager/commands/mobile/perform_interaction_request.h +++ b/src/components/application_manager/include/application_manager/commands/mobile/perform_interaction_request.h @@ -101,7 +101,7 @@ class PerformInteractionRequest : public CommandRequestImpl { * @param message which should send to mobile side * */ - void ProcessVRNotification(const smart_objects::SmartObject& message); + void ProcessVRResponse(const smart_objects::SmartObject& message); /* * @brief Function will be called when event AppUnregistered comes @@ -204,7 +204,11 @@ class PerformInteractionRequest : public CommandRequestImpl { timer::TimerThread timer_; DISALLOW_COPY_AND_ASSIGN(PerformInteractionRequest); - mobile_apis::Result::eType tts_perform_interaction_code_; + mobile_apis::Result::eType vr_perform_interaction_code_; + mobile_apis::InteractionMode::eType interaction_mode_; + bool ui_response_recived; + bool vr_response_recived; + }; } // namespace commands diff --git a/src/components/application_manager/src/commands/hmi/vr_perform_interaction_response.cc b/src/components/application_manager/src/commands/hmi/vr_perform_interaction_response.cc index 1d443bf..fea09b9 100644 --- a/src/components/application_manager/src/commands/hmi/vr_perform_interaction_response.cc +++ b/src/components/application_manager/src/commands/hmi/vr_perform_interaction_response.cc @@ -30,6 +30,7 @@ * POSSIBILITY OF SUCH DAMAGE. */ #include "application_manager/commands/hmi/vr_perform_interaction_response.h" +#include "application_manager/event_engine/event.h" namespace application_manager { @@ -45,6 +46,9 @@ VRPerformInteractionResponse::~VRPerformInteractionResponse() { void VRPerformInteractionResponse::Run() { LOG4CXX_INFO(logger_, "VRPerformInteractionResponse::Run"); + event_engine::Event event(hmi_apis::FunctionID::VR_PerformInteraction); + event.set_smart_object(*message_); + event.raise(); } } // namespace commands diff --git a/src/components/application_manager/src/commands/mobile/create_interaction_choice_set_request.cc b/src/components/application_manager/src/commands/mobile/create_interaction_choice_set_request.cc index c9f6093..d43834d 100644 --- a/src/components/application_manager/src/commands/mobile/create_interaction_choice_set_request.cc +++ b/src/components/application_manager/src/commands/mobile/create_interaction_choice_set_request.cc @@ -161,33 +161,6 @@ mobile_apis::Result::eType CreateInteractionChoiceSetRequest::CheckChoiceSet( return mobile_apis::Result::DUPLICATE_NAME; } - // check dublicate with existing choisets - - for (ChoiceSetMap::const_iterator it = app_choice_set_map.begin(); - it != app_choice_set_map.end(); ++it) { - smart_objects::SmartObject* cur_set = it->second; - - const smart_objects::SmartArray* choices = - (*cur_set)[strings::choice_set].asArray(); - smart_objects::SmartArray::const_iterator cur_choise_it; - - for (cur_choise_it = choices->begin(); cur_choise_it != choices->end(); - ++cur_choise_it) { - //vr_commands - if (true == compareSynonyms((*cur_choise_it),(*it_array))) { - LOG4CXX_ERROR(logger_, "Dublicated VR synonyms"); - return mobile_apis::Result::DUPLICATE_NAME; - } - // menu_name - if((*cur_choise_it)[strings::menu_name].asString() == - (*it_array)[strings::menu_name].asString()) { - LOG4CXX_ERROR(logger_, "Dublicated Menu name "); - return mobile_apis::Result::DUPLICATE_NAME; - } - - } - } - // Check coincidence inside the current choice smart_objects::SmartArray::const_iterator it_vr = vr_array->begin(); diff --git a/src/components/application_manager/src/commands/mobile/perform_interaction_request.cc b/src/components/application_manager/src/commands/mobile/perform_interaction_request.cc index 9d1dae8..c00e9c6 100644 --- a/src/components/application_manager/src/commands/mobile/perform_interaction_request.cc +++ b/src/components/application_manager/src/commands/mobile/perform_interaction_request.cc @@ -50,7 +50,10 @@ PerformInteractionRequest::PerformInteractionRequest( const MessageSharedPtr& message) : CommandRequestImpl(message), timer_(this, &PerformInteractionRequest::onTimer), - tts_perform_interaction_code_(mobile_apis::Result::INVALID_ENUM) { + vr_perform_interaction_code_(mobile_apis::Result::INVALID_ENUM), + interaction_mode_(mobile_apis::InteractionMode::INVALID_ENUM), + ui_response_recived(false), + vr_response_recived(false) { subscribe_on_event(hmi_apis::FunctionID::UI_OnResetTimeout); subscribe_on_event(hmi_apis::FunctionID::VR_OnCommand); @@ -136,10 +139,10 @@ void PerformInteractionRequest::Run() { app->set_perform_interaction_mode(mode); - mobile_apis::InteractionMode::eType interaction_mode = + interaction_mode_ = static_cast(mode); - switch (interaction_mode) { + switch (interaction_mode_) { case mobile_apis::InteractionMode::BOTH: { LOG4CXX_INFO(logger_, "Interaction Mode: BOTH"); if (!CheckChoiceSetVRSynonyms(app)) { @@ -166,7 +169,6 @@ void PerformInteractionRequest::Run() { } app->set_perform_interaction_active(correlation_id); - SendVRPerformInteractionRequest(app); SendUIPerformInteractionRequest(app); break; } @@ -206,11 +208,7 @@ void PerformInteractionRequest::on_event(const event_engine::Event& event) { default_timeout()); break; } - case hmi_apis::FunctionID::VR_OnCommand: { - LOG4CXX_INFO(logger_, "Received VR_OnCommand event"); - ProcessVRNotification(event.smart_object()); - break; - } + case hmi_apis::FunctionID::UI_PerformInteraction: { LOG4CXX_INFO(logger_, "Received UI_PerformInteraction event"); ProcessPerformInteractionResponse(event.smart_object()); @@ -223,8 +221,7 @@ void PerformInteractionRequest::on_event(const event_engine::Event& event) { } case hmi_apis::FunctionID::VR_PerformInteraction: { LOG4CXX_INFO(logger_, "Received TTS_PerformInteraction"); - tts_perform_interaction_code_ = static_cast( - event.smart_object()[strings::params][hmi_response::code].asInt()); + ProcessVRResponse(event.smart_object()); break; } default: { @@ -237,25 +234,70 @@ void PerformInteractionRequest::on_event(const event_engine::Event& event) { void PerformInteractionRequest::onTimeOut() { LOG4CXX_INFO(logger_, "PerformInteractionRequest::onTimeOut"); - // Unsubscribe from event on UIPerformInteractionResponse to - // avoid of double execution of SendVrDeleteCommand() - unsubscribe_from_event(hmi_apis::FunctionID::UI_PerformInteraction); - DisablePerformInteraction(); - CommandRequestImpl::onTimeOut(); + + switch (interaction_mode_) { + case mobile_apis::InteractionMode::BOTH: { + if (true == vr_response_recived) { + unsubscribe_from_event(hmi_apis::FunctionID::UI_PerformInteraction); + DisablePerformInteraction(); + CommandRequestImpl::onTimeOut(); + } else { + ApplicationManagerImpl::instance()->updateRequestTimeout(connection_key(), + correlation_id(), + default_timeout()); + } + break; + } + case mobile_apis::InteractionMode::VR_ONLY: { + ApplicationManagerImpl::instance()->updateRequestTimeout(connection_key(), + correlation_id(), + default_timeout()); + break; + } + case mobile_apis::InteractionMode::MANUAL_ONLY: { + unsubscribe_from_event(hmi_apis::FunctionID::UI_PerformInteraction); + DisablePerformInteraction(); + CommandRequestImpl::onTimeOut(); + break; + } + }; } -void PerformInteractionRequest::ProcessVRNotification( +void PerformInteractionRequest::ProcessVRResponse( const smart_objects::SmartObject& message) { LOG4CXX_INFO(logger_, "PerformInteractionRequest::ProcessVRNotification"); - const uint32_t app_id = message[strings::msg_params][strings::app_id] - .asUInt(); + const uint32_t app_id = connection_key(); ApplicationSharedPtr app = ApplicationManagerImpl::instance()->application(app_id); - if (!app) { + if (!app.get()) { LOG4CXX_ERROR(logger_, "NULL pointer"); return; } - int32_t cmd_id = message[strings::msg_params][strings::cmd_id].asInt(); + + vr_response_recived = true; + vr_perform_interaction_code_ = static_cast( + message[strings::params][hmi_response::code].asInt()); + if (mobile_apis::Result::ABORTED == vr_perform_interaction_code_) { + LOG4CXX_INFO(logger_, "VR response abborted"); + if (mobile_apis::InteractionMode::VR_ONLY == interaction_mode_) { + LOG4CXX_INFO(logger_, "Abort send Close Popup"); + smart_objects::SmartObject c_p_request_so = smart_objects::SmartObject( + smart_objects::SmartType_Map); + c_p_request_so[hmi_request::method_name] = "UI.PerformInteraction"; + SendHMIRequest(hmi_apis::FunctionID::UI_ClosePopUp, &(c_p_request_so)); + DisablePerformInteraction(); + SendResponse(false, mobile_apis::Result::ABORTED); + return; + } else { + LOG4CXX_INFO(logger_, "Update timeout for UI"); + ApplicationManagerImpl::instance()->updateRequestTimeout(connection_key(), + correlation_id(), + default_timeout()); + return; + } + } + + int32_t choise_id = message[strings::msg_params][strings::choice_id].asInt(); const PerformChoiceSetMap& choice_set_map = app ->performinteraction_choice_set_map(); bool choice_id_chosen = false; @@ -265,7 +307,7 @@ void PerformInteractionRequest::ProcessVRNotification( const smart_objects::SmartObject& choice_set = (*it->second).getElement( strings::choice_set); for (size_t j = 0; j < choice_set.length(); ++j) { - if (cmd_id == + if (choise_id == choice_set.getElement(j).getElement(strings::choice_id).asInt()) { choice_id_chosen = true; break; @@ -284,7 +326,7 @@ void PerformInteractionRequest::ProcessVRNotification( static_cast(mobile_apis::FunctionID::PerformInteractionID); smart_objects::SmartObject msg_params = smart_objects::SmartObject( smart_objects::SmartType_Map); - msg_params[strings::choice_id] = cmd_id; + msg_params[strings::choice_id] = choise_id; msg_params[strings::trigger_source] = static_cast(mobile_apis::TriggerSource::TS_VR); SendResponse(true, mobile_apis::Result::SUCCESS, NULL, &(msg_params)); @@ -347,7 +389,7 @@ void PerformInteractionRequest::ProcessPerformInteractionResponse( const smart_objects::SmartObject& message) { LOG4CXX_INFO(logger_, "PerformInteractionRequest::ProcessPerformInteractionResponse"); - + ui_response_recived = true; DisablePerformInteraction(); smart_objects::SmartObject msg_params = -- 2.7.4