From 76db80bc23ad4229b79a7d72ff0c9259f9db7193 Mon Sep 17 00:00:00 2001 From: Dmitriy Klimenko Date: Tue, 14 Apr 2015 19:02:32 -0700 Subject: APPLINK-11722: [RTC 566543] Generic Error received for PI with message as Wrong Choice id was received from HMI --- .../include/application_manager/application.h | 48 ++++++----------- .../application_manager/application_data_impl.h | 37 ++----------- .../commands/mobile/perform_interaction_request.h | 9 ++-- .../src/application_data_impl.cc | 60 +++++++++++----------- .../application_manager/src/application_impl.cc | 1 - .../delete_interaction_choice_set_request.cc | 15 +++--- .../commands/mobile/perform_interaction_request.cc | 41 ++++++++++----- 7 files changed, 90 insertions(+), 121 deletions(-) diff --git a/src/components/application_manager/include/application_manager/application.h b/src/components/application_manager/include/application_manager/application.h index d18ca599f..7835cae26 100644 --- a/src/components/application_manager/include/application_manager/application.h +++ b/src/components/application_manager/include/application_manager/application.h @@ -142,10 +142,19 @@ typedef std::map SubMenuMap; */ typedef std::map ChoiceSetMap; +/* + * @brief Typedef for perform interaction choice + * @param choice id + * @param SmartObject choice + */ +typedef std::map PerformChoice; + /* * @brief Typedef for perform interaction choice set + * @param request corellation id + * @param map of choices */ -typedef std::map PerformChoiceSetMap; +typedef std::map PerformChoiceSetMap; /** * @brief Defines id of SoftButton @@ -256,18 +265,20 @@ class DynamicApplicationData { /* * @brief Adds perform interaction choice set to the application * - * @param choice_set_id Unique ID used for this interaction choice set + * @param correlation_id Unique ID of the request that added this choice set + * @param choice_set_id Unique ID used for this interaction choice set * @param choice_set SmartObject that represents choice set */ virtual void AddPerformInteractionChoiceSet( - uint32_t choice_set_id, + uint32_t correlation_id, uint32_t choice_set_id, const smart_objects::SmartObject& choice_set) = 0; /* - * @brief Deletes entirely perform interaction choice set map + * @brief Deletes entirely perform interaction choice set for request + * @param correlation_id Unique ID of the request that added this choice set * */ - virtual void DeletePerformInteractionChoiceSetMap() = 0; + virtual void DeletePerformInteractionChoiceSet(uint32_t correlation_id) = 0; /* * @brief Retrieves entirely ChoiceSet - VR commands map @@ -277,17 +288,6 @@ class DynamicApplicationData { virtual DataAccessor performinteraction_choice_set_map() const = 0; - /* - * @brief Retrieves choice set that is currently in use by perform - * interaction - * - * @param choice_set_id Unique ID of the interaction choice set - * - * @return SmartObject that represents choice set - */ - virtual smart_objects::SmartObject* FindPerformInteractionChoiceSet( - uint32_t choice_set_id) const = 0; - /* * @brief Retrieve application commands */ @@ -317,22 +317,6 @@ class DynamicApplicationData { */ virtual uint32_t is_perform_interaction_active() const = 0; - /* - * @brief Sets the choice that was selected in - * response to PerformInteraction - * - * @param choice Choice that was selected - */ - virtual void set_perform_interaction_ui_corrid(uint32_t choice) = 0; - - /* - * @brief Retrieve the choice that was selected in - * response to PerformInteraction - * - * @return Choice that was selected in response to PerformInteraction - */ - virtual uint32_t perform_interaction_ui_corrid() const = 0; - /* * @brief Sets the mode for perform interaction: UI/VR/BOTH * diff --git a/src/components/application_manager/include/application_manager/application_data_impl.h b/src/components/application_manager/include/application_manager/application_data_impl.h index 11c57a7fc..62d3d1c8c 100644 --- a/src/components/application_manager/include/application_manager/application_data_impl.h +++ b/src/components/application_manager/include/application_manager/application_data_impl.h @@ -165,17 +165,19 @@ class DynamicApplicationDataImpl : public virtual Application { /* * @brief Adds perform interaction choice set to the application * + * @param correlation_id Unique ID of the request that added this choice set * @param choice_set_id Unique ID used for this interaction choice set * @param choice_set SmartObject that represents choice set */ - void AddPerformInteractionChoiceSet( + void AddPerformInteractionChoiceSet(uint32_t correlation_id, uint32_t choice_set_id, const smart_objects::SmartObject& choice_set); /* * @brief Deletes entirely perform interaction choice set map + * @param correlation_id Unique ID of the request that added this choice set * */ - void DeletePerformInteractionChoiceSetMap(); + void DeletePerformInteractionChoiceSet(uint32_t correlation_id); /* * @brief Retrieves entirely ChoiceSet - VR commands map @@ -184,17 +186,6 @@ class DynamicApplicationDataImpl : public virtual Application { */ inline DataAccessor performinteraction_choice_set_map() const; - /* - * @brief Retrieves choice set that is currently in use by perform - * interaction - * - * @param choice_set_id Unique ID of the interaction choice set - * - * @return SmartObject that represents choice set - */ - smart_objects::SmartObject* FindPerformInteractionChoiceSet( - uint32_t choice_set_id) const; - /* * @brief Retrieve application commands */ @@ -224,21 +215,6 @@ class DynamicApplicationDataImpl : public virtual Application { */ inline uint32_t is_perform_interaction_active() const; - /* - * @brief Sets the choice that was selected in - * response to PerformInteraction - * - * @param choice Choice that was selected - */ - void set_perform_interaction_ui_corrid(uint32_t corr_id); - - /* - * @brief Retrieve the choice that was selected in - * response to PerformInteraction - * - * @return Choice that was selected in response to PerformInteraction - */ - inline uint32_t perform_interaction_ui_corrid() const; /* * @brief Sets the mode for perform interaction: UI/VR/BOTH * @@ -289,7 +265,6 @@ protected: PerformChoiceSetMap performinteraction_choice_set_map_; mutable sync_primitives::Lock performinteraction_choice_set_lock_; uint32_t is_perform_interaction_active_; - uint32_t perform_interaction_ui_corrid_; bool is_reset_global_properties_active_; int32_t perform_interaction_mode_; @@ -323,10 +298,6 @@ uint32_t DynamicApplicationDataImpl::is_perform_interaction_active() const { return is_perform_interaction_active_; } -uint32_t DynamicApplicationDataImpl::perform_interaction_ui_corrid() const { - return perform_interaction_ui_corrid_; -} - bool DynamicApplicationDataImpl::is_reset_global_properties_active() const { return is_reset_global_properties_active_; } 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 910917283..02575c112 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 @@ -198,11 +198,12 @@ class PerformInteractionRequest : public CommandRequestImpl { bool CheckChoiceIDFromResponse(ApplicationSharedPtr app, int32_t choice_id); // members - mobile_apis::Result::eType vr_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_; - bool app_pi_was_active_before_; + bool ui_response_recived_; + bool vr_response_recived_; + bool app_pi_was_active_before_; + static uint32_t pi_requests_count_; DISALLOW_COPY_AND_ASSIGN(PerformInteractionRequest); }; diff --git a/src/components/application_manager/src/application_data_impl.cc b/src/components/application_manager/src/application_data_impl.cc index ce143fab5..bfdbadfc8 100644 --- a/src/components/application_manager/src/application_data_impl.cc +++ b/src/components/application_manager/src/application_data_impl.cc @@ -169,8 +169,8 @@ DynamicApplicationDataImpl::DynamicApplicationDataImpl() sub_menu_(), choice_set_map_(), performinteraction_choice_set_map_(), + performinteraction_choice_set_lock_(true), is_perform_interaction_active_(false), - perform_interaction_ui_corrid_(0), is_reset_global_properties_active_(false), perform_interaction_mode_(-1) { } @@ -220,7 +220,11 @@ DynamicApplicationDataImpl::~DynamicApplicationDataImpl() { PerformChoiceSetMap::iterator it = performinteraction_choice_set_map_.begin(); for (; performinteraction_choice_set_map_.end() != it; ++it) { - delete it->second; + PerformChoice::iterator choice_it = performinteraction_choice_set_map_[it->first].begin(); + for (; performinteraction_choice_set_map_[it->first].end() != choice_it; ++choice_it) { + delete choice_it->second; + } + performinteraction_choice_set_map_[it->first].clear(); } performinteraction_choice_set_map_.clear(); } @@ -406,7 +410,10 @@ void DynamicApplicationDataImpl::SetGlobalProperties( void DynamicApplicationDataImpl::AddCommand( uint32_t cmd_id, const smart_objects::SmartObject& command) { sync_primitives::AutoLock lock(commands_lock_); - commands_[cmd_id] = new smart_objects::SmartObject(command); + CommandsMap::const_iterator it = commands_.find(cmd_id); + if (commands_.end() == it) { + commands_[cmd_id] = new smart_objects::SmartObject(command); + } } void DynamicApplicationDataImpl::RemoveCommand(uint32_t cmd_id) { @@ -433,7 +440,10 @@ smart_objects::SmartObject* DynamicApplicationDataImpl::FindCommand( void DynamicApplicationDataImpl::AddSubMenu( uint32_t menu_id, const smart_objects::SmartObject& menu) { sync_primitives::AutoLock lock(sub_menu_lock_); - sub_menu_[menu_id] = new smart_objects::SmartObject(menu); + SubMenuMap::const_iterator it = sub_menu_.find(menu_id); + if (sub_menu_.end() == it) { + sub_menu_[menu_id] = new smart_objects::SmartObject(menu); + } } void DynamicApplicationDataImpl::RemoveSubMenu(uint32_t menu_id) { @@ -474,7 +484,10 @@ bool DynamicApplicationDataImpl::IsSubMenuNameAlreadyExist( void DynamicApplicationDataImpl::AddChoiceSet( uint32_t choice_set_id, const smart_objects::SmartObject& choice_set) { sync_primitives::AutoLock lock(choice_set_map_lock_); - choice_set_map_[choice_set_id] = new smart_objects::SmartObject(choice_set); + ChoiceSetMap::const_iterator it = choice_set_map_.find(choice_set_id); + if (choice_set_map_.end() == it) { + choice_set_map_[choice_set_id] = new smart_objects::SmartObject(choice_set); + } } void DynamicApplicationDataImpl::RemoveChoiceSet(uint32_t choice_set_id) { @@ -499,33 +512,23 @@ smart_objects::SmartObject* DynamicApplicationDataImpl::FindChoiceSet( } void DynamicApplicationDataImpl::AddPerformInteractionChoiceSet( - uint32_t choice_set_id, const smart_objects::SmartObject& vr_commands) { + uint32_t correlation_id, uint32_t choice_set_id, + const smart_objects::SmartObject& vr_commands) { sync_primitives::AutoLock lock(performinteraction_choice_set_lock_); - performinteraction_choice_set_map_[choice_set_id] = - new smart_objects::SmartObject(vr_commands); + performinteraction_choice_set_map_[correlation_id].insert( + std::make_pair(choice_set_id, new smart_objects::SmartObject(vr_commands))); } -void DynamicApplicationDataImpl::DeletePerformInteractionChoiceSetMap() { +void DynamicApplicationDataImpl::DeletePerformInteractionChoiceSet( + uint32_t correlation_id) { sync_primitives::AutoLock lock(performinteraction_choice_set_lock_); - PerformChoiceSetMap::iterator it = performinteraction_choice_set_map_.begin(); - for (; performinteraction_choice_set_map_.end() != it; ++it) { + PerformChoice::iterator it = + performinteraction_choice_set_map_[correlation_id].begin(); + for (; performinteraction_choice_set_map_[correlation_id].end() != it; ++it) { delete it->second; } - performinteraction_choice_set_map_.clear(); -} - -smart_objects::SmartObject* -DynamicApplicationDataImpl::FindPerformInteractionChoiceSet( - uint32_t choice_set_id) const { - sync_primitives::AutoLock lock(performinteraction_choice_set_lock_); - PerformChoiceSetMap::const_iterator it = performinteraction_choice_set_map_ - .find(choice_set_id); - - if (it != performinteraction_choice_set_map_.end()) { - return it->second; - } - - return NULL; + performinteraction_choice_set_map_[correlation_id].clear(); + performinteraction_choice_set_map_.erase(correlation_id); } void DynamicApplicationDataImpl::set_perform_interaction_active( @@ -533,11 +536,6 @@ void DynamicApplicationDataImpl::set_perform_interaction_active( is_perform_interaction_active_ = active; } -void DynamicApplicationDataImpl::set_perform_interaction_ui_corrid( - uint32_t corr_id) { - perform_interaction_ui_corrid_ = corr_id; -} - void DynamicApplicationDataImpl::set_reset_global_properties_active( bool active) { is_reset_global_properties_active_ = active; diff --git a/src/components/application_manager/src/application_impl.cc b/src/components/application_manager/src/application_impl.cc index 2d848ad2c..a533be2e2 100644 --- a/src/components/application_manager/src/application_impl.cc +++ b/src/components/application_manager/src/application_impl.cc @@ -163,7 +163,6 @@ ApplicationImpl::~ApplicationImpl() { if (is_perform_interaction_active()) { set_perform_interaction_active(0); set_perform_interaction_mode(-1); - DeletePerformInteractionChoiceSetMap(); } CleanupFiles(); } diff --git a/src/components/application_manager/src/commands/mobile/delete_interaction_choice_set_request.cc b/src/components/application_manager/src/commands/mobile/delete_interaction_choice_set_request.cc index 6c61bfd2a..35c8b96d2 100644 --- a/src/components/application_manager/src/commands/mobile/delete_interaction_choice_set_request.cc +++ b/src/components/application_manager/src/commands/mobile/delete_interaction_choice_set_request.cc @@ -100,12 +100,15 @@ bool DeleteInteractionChoiceSetRequest::ChoiceSetInUse(ApplicationConstSharedPtr PerformChoiceSetMap::const_iterator it = choice_set_map.begin(); for (; choice_set_map.end() != it; ++it) { - if (it->first - == (*message_)[strings::msg_params] - [strings::interaction_choice_set_id].asUInt()) { - LOG4CXX_ERROR_EXT(logger_, - "DeleteInteractionChoiceSetRequest::ChoiceSetInUse"); - return true; + const PerformChoice& choice = it->second; + PerformChoice::const_iterator choice_it = choice.begin(); + for (; choice.end() != choice_it; ++choice_it) { + if (choice_it->first == (*message_)[strings::msg_params] + [strings::interaction_choice_set_id].asUInt()) { + LOG4CXX_ERROR_EXT(logger_, + "DeleteInteractionChoiceSetRequest::ChoiceSetInUse"); + return true; + } } } } 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 a80c5df96..54edc8e51 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 @@ -46,6 +46,8 @@ namespace application_manager { namespace commands { +uint32_t PerformInteractionRequest::pi_requests_count_ = 0; + PerformInteractionRequest::PerformInteractionRequest( const MessageSharedPtr& message) : CommandRequestImpl(message), @@ -200,6 +202,8 @@ void PerformInteractionRequest::Run() { app->set_perform_interaction_mode(static_cast(interaction_mode_)); app->set_perform_interaction_active(true); + // increment amount of active requests + ++pi_requests_count_; SendVRPerformInteractionRequest(app); SendUIPerformInteractionRequest(app); } @@ -454,7 +458,8 @@ void PerformInteractionRequest::SendUIPerformInteractionRequest( choice_set_id_list[i].asInt()); if (choice_set) { // save perform interaction choice set - app->AddPerformInteractionChoiceSet(choice_set_id_list[i].asInt(), + app->AddPerformInteractionChoiceSet(correlation_id(), + choice_set_id_list[i].asInt(), *choice_set); for (size_t j = 0; j < (*choice_set)[strings::choice_set].length(); ++j) { if (mobile_apis::InteractionMode::VR_ONLY != mode) { @@ -724,12 +729,15 @@ void PerformInteractionRequest::DisablePerformInteraction() { return; } - if (app->is_perform_interaction_active() && - (!app_pi_was_active_before_)) { - app->set_perform_interaction_active(false); - app->set_perform_interaction_mode(-1); - app->DeletePerformInteractionChoiceSetMap(); + if (app->is_perform_interaction_active()) { + // decrease amount of active requests + --pi_requests_count_; + if (!pi_requests_count_) { + app->set_perform_interaction_active(false); + app->set_perform_interaction_mode(-1); + } } + app->DeletePerformInteractionChoiceSet(correlation_id()); } bool PerformInteractionRequest::IsWhiteSpaceExist() { @@ -833,14 +841,19 @@ bool PerformInteractionRequest::CheckChoiceIDFromResponse( app->performinteraction_choice_set_map(); const PerformChoiceSetMap& choice_set_map = accessor.GetData(); - for (PerformChoiceSetMap::const_iterator it = choice_set_map.begin(); - choice_set_map.end() != it; ++it) { - const smart_objects::SmartObject& choice_set = (*it->second).getElement( - strings::choice_set); - for (size_t j = 0; j < choice_set.length(); ++j) { - if (choice_id == - choice_set.getElement(j).getElement(strings::choice_id).asInt()) { - return true; + PerformChoiceSetMap::const_iterator choice_set_map_it = + choice_set_map.find(correlation_id()); + if (choice_set_map.end() != choice_set_map_it) { + const PerformChoice& choice = choice_set_map_it->second; + PerformChoice::const_iterator it = choice.begin(); + for (; choice.end() != it; ++it) { + const smart_objects::SmartObject& choice_set = (*it->second).getElement( + strings::choice_set); + for (size_t j = 0; j < choice_set.length(); ++j) { + if (choice_id == + choice_set.getElement(j).getElement(strings::choice_id).asInt()) { + return true; + } } } } -- cgit v1.2.1