diff options
Diffstat (limited to 'src/components/application_manager')
5 files changed, 125 insertions, 7 deletions
diff --git a/src/components/application_manager/include/application_manager/message_helper.h b/src/components/application_manager/include/application_manager/message_helper.h index 9559c2007e..3c90928d8a 100644 --- a/src/components/application_manager/include/application_manager/message_helper.h +++ b/src/components/application_manager/include/application_manager/message_helper.h @@ -50,6 +50,7 @@ #include "application_manager/policies/policy_handler_interface.h" #include "smart_objects/smart_object.h" #include "transport_manager/common.h" +#include <application_manager/smart_object_keys.h> namespace policy { class PolicyHandlerInterface; @@ -854,6 +855,41 @@ class MessageHelper { */ static smart_objects::SmartObjectSPtr CreateMessageForHMI( hmi_apis::messageType::eType message_type, const uint32_t correlation_id); + + + // Check whether each choice has the vrCommands field + // returns -1 for failure, 0 if all choice include vrCommands, and 1 if none do + // vrCommands is an all-or-none deal + static int CheckChoiceSet_VRCommands( + const smart_objects::SmartObject& choice_set) { + + // if this becomes true, someone doesn't have vrCommands + bool all_have = true; + // if this is true, no one has vrCommands + bool none_have = true; + smart_objects::SmartArray::const_iterator current_choice_set_it = choice_set.asArray()->begin(); + // Iterate through choices + for (; choice_set.asArray()->end() != current_choice_set_it; ++current_choice_set_it) { + // if the vrCommands is present + if (current_choice_set_it->keyExists(application_manager::strings::vr_commands)) { + // this one has the parameter + none_have = false; + } else { + // this one doesn't + all_have = false; + } + } + // everyone has it + if (all_have) { + return 0; + } + // No one has it + if (none_have) { + return 1; + } + // mix-and-match, this is an error + return -1; + } private: /** 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 40e706b851..02ea6945f7 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 @@ -211,6 +211,20 @@ class PerformInteractionRequest app_mngr::ApplicationSharedPtr app, const size_t choice_set_id_list_length, const smart_objects::SmartObject& choice_set_id_list) const; + + + /** + * @brief Checks each choice in each set for having a VRcommands parameter + * @param app contains pointer to application. + * @param choice_set_id_list_length contains amount + * of choice set ids. + * @param choice_set_id_list array of choice set ids + * @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; /** * @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 7451ea7905..9b365b3f13 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,10 +124,27 @@ void CreateInteractionChoiceSetRequest::Run() { SendResponse(false, result); return; } - uint32_t grammar_id = application_manager_.GenerateGrammarID(); - (*message_)[strings::msg_params][strings::grammar_id] = grammar_id; + std::cerr << "checking choice set\n"; + int vr_status = MessageHelper::CheckChoiceSet_VRCommands((*message_)[strings::msg_params][strings::choice_set]); + 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."); + return; // exit now, this is a bad set + + } else if (vr_status == 0) { + std::cerr << "choice set has valid FULL set of VR parameters" << '\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); + } else { + std::cerr << "choice set has valid EMPTY set of VR parameters" << '\n'; + + } + // continue on as usual app->AddChoiceSet(choice_set_id_, (*message_)[strings::msg_params]); - SendVRAddCommandRequests(app); } mobile_apis::Result::eType CreateInteractionChoiceSetRequest::CheckChoiceSet( @@ -149,7 +166,7 @@ mobile_apis::Result::eType CreateInteractionChoiceSetRequest::CheckChoiceSet( (*current_choice_set_it)[strings::choice_id].asInt()); if (!ins_res.second) { LOG4CXX_ERROR(logger_, - "Choise with ID " + "Choice with ID " << (*current_choice_set_it)[strings::choice_id].asInt() << " already exists"); return mobile_apis::Result::INVALID_ID; 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 8710f3c3d6..7753c16acf 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,7 +163,18 @@ 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( @@ -942,6 +953,37 @@ bool PerformInteractionRequest::CheckChoiceIDFromResponse( return false; } + +bool PerformInteractionRequest::CheckChoiceSetList_VRCommands( + ApplicationSharedPtr app, + const size_t choice_set_id_list_length, + const smart_objects::SmartObject& choice_set_id_list) const { + LOG4CXX_AUTO_TRACE(logger_); + + smart_objects::SmartObject* choice_set = 0; + std::pair<std::set<uint32_t>::iterator, bool> ins_res; + + for (size_t i = 0; i < choice_set_id_list_length; ++i) { + choice_set = app->FindChoiceSet(choice_set_id_list[i].asInt()); + // this should never ever happen + // if (!choice_set) { + // LOG4CXX_ERROR( + // logger_, + // "Couldn't find choiceset_id = " << choice_set_id_list[i].asInt()); + // return false; + // } + + + int vr_status = MessageHelper::CheckChoiceSet_VRCommands(*choice_set); + // if not all choices have vr commands + if (vr_status != 0) { + std::cerr << "choice set has member missing vr commands\n"; + return false; + } + } + return true; +} + bool PerformInteractionRequest::CheckChoiceIDFromRequest( ApplicationSharedPtr app, const size_t choice_set_id_list_length, @@ -961,6 +1003,13 @@ bool PerformInteractionRequest::CheckChoiceIDFromRequest( "Couldn't find choiset_id = " << choice_set_id_list[i].asInt()); return false; } + + + int vr_status = MessageHelper::CheckChoiceSet_VRCommands(*choice_set); + // if not all choices have vr commands + if (vr_status != 0) { + + } choice_list_length = (*choice_set)[strings::choice_set].length(); const smart_objects::SmartObject& choices_list = (*choice_set)[strings::choice_set]; diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/create_interaction_choice_set_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/create_interaction_choice_set_test.cc index ed264ff2ab..349764b9e9 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/create_interaction_choice_set_test.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/create_interaction_choice_set_test.cc @@ -197,8 +197,10 @@ TEST_F(CreateInteractionChoiceSetRequestTest, OnEvent_VR_UNSUPPORTED_RESOURCE) { MessageSharedPtr msg_vr = CreateFullParamsVRSO(); (*msg_vr)[strings::msg_params][strings::choice_set][0][strings::choice_id] = 10; - (*msg_vr)[strings::msg_params][strings::choice_set][0][strings::menu_name] = - "menu_name"; +(*msg_vr)[strings::msg_params][strings::choice_set][0][strings::menu_name] = + "menu_name"; +(*msg_vr)[strings::msg_params][strings::choice_set][0][strings::vr_commands][0] = + kVrCommands1; (*msg_vr)[strings::msg_params][strings::interaction_choice_set_id] = 11; std::shared_ptr<CreateInteractionChoiceSetRequest> req_vr = CreateCommand<CreateInteractionChoiceSetRequest>(msg_vr); |