diff options
author | Conlain Kelly <conlain.k@gmail.com> | 2018-07-24 13:53:31 -0400 |
---|---|---|
committer | Conlain Kelly <conlain.k@gmail.com> | 2018-07-24 13:53:31 -0400 |
commit | 28246b04368088a1ebd11e3c1b6885cace6e643b (patch) | |
tree | b1855c6dc0f810013016924e586db550245d3274 | |
parent | b5043f977fc861c581e7b912923847b0d85aea7c (diff) | |
download | sdl_core-28246b04368088a1ebd11e3c1b6885cace6e643b.tar.gz |
Fix segfault, add perform interaction checks
3 files changed, 50 insertions, 36 deletions
diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/perform_interaction_request.h b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/perform_interaction_request.h index 02ea6945f7..7684b3fd3f 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/perform_interaction_request.h +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/perform_interaction_request.h @@ -222,9 +222,7 @@ class PerformInteractionRequest * @return returns false request has choice sets with no vrCommands */ bool CheckChoiceSetList_VRCommands( - app_mngr::ApplicationSharedPtr app, - const size_t choice_set_id_list_length, - const smart_objects::SmartObject& choice_set_id_list) const; + app_mngr::ApplicationSharedPtr app); /** * @brief Tells if there are sent requests without responses diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/create_interaction_choice_set_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/create_interaction_choice_set_request.cc index b20b657279..48f15aafda 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/create_interaction_choice_set_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/create_interaction_choice_set_request.cc @@ -124,7 +124,7 @@ void CreateInteractionChoiceSetRequest::Run() { if (vr_status == -1) { std::cerr << "choice set has invalid MIXED set of VR parameters" << '\n'; // this is an error - SendResponse(false, Result::INVALID_DATA, "Some choices don't contain VR commands."); + SendResponse(false, Result::INVALID_DATA, "Some choices don't contain VR commands. Either all or none must have voice commands."); return; // exit now, this is a bad set } else if (vr_status == 0) { @@ -139,13 +139,23 @@ void CreateInteractionChoiceSetRequest::Run() { return; } if (vr_status == 0) { + std::cerr << "creating grammar\n"; // everyone had a vr command, setup the grammar uint32_t grammar_id = application_manager_.GenerateGrammarID(); (*message_)[strings::msg_params][strings::grammar_id] = grammar_id; - SendVRAddCommandRequests(app); } // continue on as usual + std::cerr << "adding choice set\n"; app->AddChoiceSet(choice_set_id_, (*message_)[strings::msg_params]); + std::cerr << "added! choice set\n"; + + if (vr_status == 0) { + SendVRAddCommandRequests(app); + std::cerr << "requests sent!!!!\n"; + } else { + SendResponse(true, Result::SUCCESS); + + } } mobile_apis::Result::eType CreateInteractionChoiceSetRequest::CheckChoiceSet( @@ -191,12 +201,14 @@ mobile_apis::Result::eType CreateInteractionChoiceSetRequest::CheckChoiceSet( bool CreateInteractionChoiceSetRequest::compareSynonyms( const NsSmartDeviceLink::NsSmartObjects::SmartObject& choice1, const NsSmartDeviceLink::NsSmartObjects::SmartObject& choice2) { - smart_objects::SmartArray* vr_cmds_1 = - choice1[strings::vr_commands].asArray(); - DCHECK(vr_cmds_1 != NULL); - smart_objects::SmartArray* vr_cmds_2 = - choice2[strings::vr_commands].asArray(); - DCHECK(vr_cmds_2 != NULL); + // only compare if they both have vr commands + if (!(choice1.keyExists(strings::vr_commands) && + choice2.keyExists(strings::vr_commands))) { + std::cerr << "someone is empty!\n"; + return false; // clearly there isn't a duplicate if one of them is null + } + smart_objects::SmartArray* vr_cmds_1 = choice1[strings::vr_commands].asArray(); + smart_objects::SmartArray* vr_cmds_2 = choice2[strings::vr_commands].asArray(); smart_objects::SmartArray::iterator it; it = std::find_first_of(vr_cmds_1->begin(), diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/perform_interaction_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/perform_interaction_request.cc index 5a614b73c4..6a55936bcc 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/perform_interaction_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/perform_interaction_request.cc @@ -163,18 +163,6 @@ void PerformInteractionRequest::Run() { SendResponse(false, mobile_apis::Result::INVALID_ID); return; } - if (!CheckChoiceSetList_VRCommands( - app, - choice_set_id_list_length, - msg_params[strings::interaction_choice_set_id_list])) { - LOG4CXX_ERROR(logger_, - "PerformInteraction has choice sets with " - "missing vrCommands"); - SendResponse(false, - mobile_apis::Result::INVALID_DATA, - "Some choices don't contain VR commands."); - return; - } if (msg_params.keyExists(strings::vr_help)) { if (mobile_apis::Result::SUCCESS != MessageHelper::VerifyImageVrHelpItems( @@ -197,7 +185,7 @@ void PerformInteractionRequest::Run() { case mobile_apis::InteractionMode::BOTH: { LOG4CXX_DEBUG(logger_, "Interaction Mode: BOTH"); if (!CheckChoiceSetVRSynonyms(app) || !CheckChoiceSetMenuNames(app) || - !CheckVrHelpItemPositions(app)) { + !CheckVrHelpItemPositions(app) || !CheckChoiceSetList_VRCommands(app)) { return; } break; @@ -212,7 +200,8 @@ void PerformInteractionRequest::Run() { } case mobile_apis::InteractionMode::VR_ONLY: { LOG4CXX_DEBUG(logger_, "Interaction Mode: VR_ONLY"); - if (!CheckChoiceSetVRSynonyms(app) || !CheckVrHelpItemPositions(app)) { + if (!CheckChoiceSetVRSynonyms(app) || !CheckVrHelpItemPositions(app) || + !CheckChoiceSetList_VRCommands(app)) { return; } break; @@ -757,6 +746,15 @@ bool PerformInteractionRequest::CheckChoiceSetVRSynonyms( size_t jj = 0; for (; ii < (*i_choice_set)[strings::choice_set].length(); ++ii) { for (; jj < (*j_choice_set)[strings::choice_set].length(); ++jj) { + if (!((*i_choice_set)[strings::choice_set][ii].keyExists( + strings::vr_commands) && + (*j_choice_set)[strings::choice_set][jj].keyExists( + strings::vr_commands))) { + LOG4CXX_DEBUG( + logger_, + "One or both sets has missing vr commands, skipping synonym check"); + return true; + } // choice_set pointer contains SmartObject msg_params smart_objects::SmartObject& ii_vr_commands = (*i_choice_set)[strings::choice_set][ii][strings::vr_commands]; @@ -955,36 +953,42 @@ bool PerformInteractionRequest::CheckChoiceIDFromResponse( bool PerformInteractionRequest::CheckChoiceSetList_VRCommands( - ApplicationSharedPtr app, - const size_t choice_set_id_list_length, - const smart_objects::SmartObject& choice_set_id_list) const { + ApplicationSharedPtr app) { LOG4CXX_AUTO_TRACE(logger_); + + const smart_objects::SmartObject& choice_set_id_list = + (*message_)[strings::msg_params][strings::interaction_choice_set_id_list]; - smart_objects::SmartObject* choice_set = 0; - std::pair<std::set<uint32_t>::iterator, bool> ins_res; + smart_objects::SmartObject* choice_set = nullptr; - for (size_t i = 0; i < choice_set_id_list_length; ++i) { - // std::cerr << "loop entered!\n"; + for (size_t i = 0; i < choice_set_id_list.length(); ++i) { + std::cerr << "loop entered!\n"; choice_set = app->FindChoiceSet(choice_set_id_list[i].asInt()); - // std::cerr << "set found!!\n"; + std::cerr << "set found!!\n"; // this should never ever happen if (choice_set == nullptr) { std::cerr << "bad choice set list!\n"; return false; } - // std::cerr<< "SMARTTYPE is " << choice_set->getType() << std::endl; + std::cerr<< "SMARTTYPE is " << choice_set->getType() << std::endl; - // std::cerr << "checking status!!!\n"; + std::cerr << "checking status!!!\n"; const smart_objects::SmartObject& choices_list = (*choice_set)[strings::choice_set]; int vr_status = MessageHelper::CheckChoiceSet_VRCommands(choices_list); - // std::cerr << "status checked!!!!\n"; + std::cerr << "status checked!!!!\n"; // if not all choices have vr commands if (vr_status != 0) { std::cerr << "choice set has member missing vr commands\n"; + LOG4CXX_ERROR(logger_, + "PerformInteraction has choice sets with " + "missing vrCommands, not in MANUAL_ONLY mode"); + SendResponse(false, + mobile_apis::Result::INVALID_DATA, + "Some choices don't contain VR commands."); return false; } } |