From 6660fa1cd097a56f8edd4e99922f806762b5017d Mon Sep 17 00:00:00 2001 From: Alexander Kutsan Date: Wed, 2 Apr 2014 13:02:54 +0300 Subject: [PATCH] APPLINK-6502 check duplicated on Create Interactoion ChoiceSet Signed-off-by: Justin Dickow Conflicts: src/components/application_manager/src/application_manager_impl.cc --- .../include/application_manager/application.h | 2 ++ .../include/application_manager/application_impl.h | 4 +++ .../application_manager/application_manager_impl.h | 2 +- .../application_manager/src/application_impl.cc | 11 ++++++- .../src/application_manager_impl.cc | 11 +++---- .../src/commands/mobile/add_command_request.cc | 2 +- .../create_interaction_choice_set_request.cc | 35 ++++++++++++++++++++-- .../commands/mobile/perform_interaction_request.cc | 23 +++++++++----- .../src/commands/mobile/put_file_request.cc | 12 ++++---- 9 files changed, 75 insertions(+), 27 deletions(-) diff --git a/src/components/application_manager/include/application_manager/application.h b/src/components/application_manager/include/application_manager/application.h index d4fcbe1..be9e702 100644 --- a/src/components/application_manager/include/application_manager/application.h +++ b/src/components/application_manager/include/application_manager/application.h @@ -415,6 +415,8 @@ class Application : public virtual InitialApplicationData, virtual bool set_app_icon_path(const std::string& file_name) = 0; virtual void set_app_allowed(const bool& allowed) = 0; virtual void set_device(connection_handler::DeviceHandle device) = 0; + virtual uint32_t get_grammar_id() = 0; + virtual void set_grammar_id(uint32_t value) = 0; virtual bool AddFile(AppFile& file) = 0; virtual const AppFilesMap& getAppFiles() const = 0; diff --git a/src/components/application_manager/include/application_manager/application_impl.h b/src/components/application_manager/include/application_manager/application_impl.h index 4be0875..0e6326b 100644 --- a/src/components/application_manager/include/application_manager/application_impl.h +++ b/src/components/application_manager/include/application_manager/application_impl.h @@ -103,6 +103,8 @@ class ApplicationImpl : public virtual InitialApplicationDataImpl, bool set_app_icon_path(const std::string& path); void set_app_allowed(const bool& allowed); void set_device(connection_handler::DeviceHandle device); + virtual uint32_t get_grammar_id(); + virtual void set_grammar_id(uint32_t value); bool AddFile(AppFile& file); bool UpdateFile(AppFile& file); @@ -140,6 +142,8 @@ class ApplicationImpl : public virtual InitialApplicationDataImpl, private: uint32_t hash_val_; + uint32_t grammar_id_; + smart_objects::SmartObject* active_message_; diff --git a/src/components/application_manager/include/application_manager/application_manager_impl.h b/src/components/application_manager/include/application_manager/application_manager_impl.h index 1c41d61..d408071 100644 --- a/src/components/application_manager/include/application_manager/application_manager_impl.h +++ b/src/components/application_manager/include/application_manager/application_manager_impl.h @@ -447,7 +447,7 @@ class ApplicationManagerImpl : public ApplicationManager, */ ResumeCtrl& resume_controller() { return resume_ctrl_; } - uint32_t GetGrammarID(); + uint32_t GenerateGrammarID(); /* * @brief Save binary data to specified directory * diff --git a/src/components/application_manager/src/application_impl.cc b/src/components/application_manager/src/application_impl.cc index b82467d..bf84482 100644 --- a/src/components/application_manager/src/application_impl.cc +++ b/src/components/application_manager/src/application_impl.cc @@ -59,7 +59,8 @@ ApplicationImpl::ApplicationImpl(uint32_t application_id) is_app_allowed_(true), has_been_activated_(false), tts_speak_state_(false), - device_(0) { + device_(0), + grammar_id_(0) { } ApplicationImpl::~ApplicationImpl() { @@ -248,6 +249,14 @@ void ApplicationImpl::set_device(connection_handler::DeviceHandle device) { device_ = device; } +uint32_t ApplicationImpl::get_grammar_id() { + return grammar_id_; +} + +void ApplicationImpl::set_grammar_id(uint32_t value) { + grammar_id_ = value; +} + bool ApplicationImpl::has_been_activated() const { return has_been_activated_; } diff --git a/src/components/application_manager/src/application_manager_impl.cc b/src/components/application_manager/src/application_manager_impl.cc index 651bce3..8a06dba 100644 --- a/src/components/application_manager/src/application_manager_impl.cc +++ b/src/components/application_manager/src/application_manager_impl.cc @@ -248,11 +248,8 @@ ApplicationSharedPtr ApplicationManagerImpl::RegisterApplication( } } - smart_objects::SmartObject& params = message[strings::msg_params]; - - ApplicationSharedPtr application(new ApplicationImpl(app_id, - params[strings::app_id].asString(), - NULL)); + ApplicationSharedPtr application(new + ApplicationImpl(app_id)); if (!application) { utils::SharedPtr response( MessageHelper::CreateNegativeResponse( @@ -268,7 +265,7 @@ ApplicationSharedPtr ApplicationManagerImpl::RegisterApplication( application->set_name(name); application->set_device(device_id); - + application->set_grammar_id(GenerateGrammarID()); application->set_language( static_cast( message[strings::msg_params][strings::language_desired].asInt())); @@ -748,7 +745,7 @@ bool ApplicationManagerImpl::IsVideoStreamingAllowed(uint32_t connection_key) co return false; } -uint32_t ApplicationManagerImpl::GetGrammarID() { +uint32_t ApplicationManagerImpl::GenerateGrammarID() { return rand(); } diff --git a/src/components/application_manager/src/commands/mobile/add_command_request.cc b/src/components/application_manager/src/commands/mobile/add_command_request.cc index f4f3eeb..3fd9c50 100644 --- a/src/components/application_manager/src/commands/mobile/add_command_request.cc +++ b/src/components/application_manager/src/commands/mobile/add_command_request.cc @@ -168,7 +168,7 @@ void AddCommandRequest::Run() { vr_msg_params[strings::app_id] = app->app_id(); vr_msg_params[strings::type] = hmi_apis::Common_VRCommandType::Command; - vr_msg_params[strings::grammar_id] = ApplicationManagerImpl::instance()->GetGrammarID(); + vr_msg_params[strings::grammar_id] = app->get_grammar_id(); send_vr_ = true; } 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 6f2a7e6..7074826 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 @@ -94,7 +94,7 @@ void CreateInteractionChoiceSetRequest::Run() { SendResponse(false, result); return; } - uint32_t grammar_id = ApplicationManagerImpl::instance()->GetGrammarID(); + uint32_t grammar_id = ApplicationManagerImpl::instance()->GenerateGrammarID(); (*message_)[strings::msg_params][strings::grammar_id] = grammar_id; app->AddChoiceSet(choice_set_id, (*message_)[strings::msg_params]); SendVRAddCommandRequest(app); @@ -117,6 +117,8 @@ mobile_apis::Result::eType CreateInteractionChoiceSetRequest::CheckChoiceSet( // Self check of new choice set for params coincidence for (; it_array != it_array_end; ++it_array) { + const smart_objects::SmartArray* vr_array = + (*it_array)[strings::vr_commands].asArray(); CoincidencePredicateChoiceID c((*it_array)[strings::choice_id].asInt()); if (1 != std::count_if( @@ -159,9 +161,36 @@ 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 - const smart_objects::SmartArray* vr_array = - (*it_array)[strings::vr_commands].asArray(); smart_objects::SmartArray::const_iterator it_vr = vr_array->begin(); smart_objects::SmartArray::const_iterator it_vr_end = vr_array->end(); 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 c35c73a..ca2fd4b 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 @@ -477,6 +477,21 @@ void PerformInteractionRequest::SendTTSPerformInteractionRequest( application_manager::ApplicationSharedPtr const app) { smart_objects::SmartObject msg_params = smart_objects::SmartObject(smart_objects::SmartType_Map); + smart_objects::SmartObject& choice_list = + (*message_)[strings::msg_params][strings::interaction_choice_set_id_list]; + + msg_params[strings::grammar_id] = smart_objects::SmartObject(smart_objects::SmartType_Array); + int32_t grammar_id_index = 0; + for (uint32_t i = 0; i < choice_list.length(); ++i) { + smart_objects::SmartObject* choice_set = + app->FindChoiceSet(choice_list[i].asInt()); + if (!choice_set) { + LOG4CXX_WARN(logger_, "Couldn't found choiset"); + continue; + } + uint32_t grammar_id = (*choice_set)[strings::grammar_id].asUInt(); + msg_params[strings::grammar_id][grammar_id_index++]= (*choice_set)[strings::grammar_id]; + } if ((*message_)[strings::msg_params].keyExists(strings::help_prompt)) { @@ -485,17 +500,10 @@ void PerformInteractionRequest::SendTTSPerformInteractionRequest( DeleteParameterFromTTSChunk(&msg_params[strings::help_prompt]); } else { - - smart_objects::SmartObject& choice_list = - (*message_)[strings::msg_params][strings::interaction_choice_set_id_list]; - msg_params[strings::help_prompt] = smart_objects::SmartObject(smart_objects::SmartType_Array); int32_t index = 0; - int32_t grammar_id_index = 0; - - msg_params[strings::grammar_id] = smart_objects::SmartObject(smart_objects::SmartType_Array); for (uint32_t i = 0; i < choice_list.length(); ++i) { smart_objects::SmartObject* choice_set = app->FindChoiceSet(choice_list[i].asInt()); @@ -513,7 +521,6 @@ void PerformInteractionRequest::SendTTSPerformInteractionRequest( msg_params[strings::help_prompt][index++] = item; } } - msg_params[strings::grammar_id][grammar_id_index++]= (*choice_set)[strings::grammar_id]; } else { LOG4CXX_ERROR(logger_, "Can't found choiset!") } diff --git a/src/components/application_manager/src/commands/mobile/put_file_request.cc b/src/components/application_manager/src/commands/mobile/put_file_request.cc index b2651a6..eed6977 100644 --- a/src/components/application_manager/src/commands/mobile/put_file_request.cc +++ b/src/components/application_manager/src/commands/mobile/put_file_request.cc @@ -136,7 +136,7 @@ void PutFileRequest::Run() { full_file_path = profile::Profile::instance()->system_files_path(); if (!file_system::CreateDirectoryRecursively(full_file_path)) { - LOG4CXX_ERROR(logger_, "Cann't create folder."); + LOG4CXX_ERROR(logger_, "Cann't create folder"); SendResponse(false, mobile_apis::Result::GENERIC_ERROR, "Cann't create folder.", &response_params); @@ -154,7 +154,7 @@ void PutFileRequest::Run() { > file_system::GetAvailableSpaceForApp(application->name())) { LOG4CXX_ERROR(logger_, "Out of free app memory."); SendResponse(false, mobile_apis::Result::OUT_OF_MEMORY, - "Out of memory.", + "Out of memory", &response_params); return; } @@ -170,7 +170,7 @@ void PutFileRequest::Run() { case mobile_apis::Result::SUCCESS: { AppFile file(sync_file_name_, is_persistent_file_, is_download_compleate, file_type_); - if (offset_ == 0) { + if (0 == offset_) { LOG4CXX_INFO(logger_, "New file downloading"); if (!application->AddFile(file)) { LOG4CXX_INFO( @@ -199,8 +199,8 @@ void PutFileRequest::Run() { break; } default: - LOG4CXX_INFO(logger_, "Save in unsuccesfull result = " << save_result); - SendResponse(false, save_result, "Cant' save file", &response_params); + LOG4CXX_INFO(logger_, "Save in unsuccesfull. Result = " << save_result); + SendResponse(false, save_result, "Can't save file", &response_params); break; } } @@ -218,7 +218,7 @@ void PutFileRequest::SendOnPutFileNotification() { message[strings::msg_params][strings::app_id] = connection_key(); message[strings::msg_params][strings::sync_file_name] = sync_file_name_; message[strings::msg_params][strings::offset] = offset_; - if ( offset_ == 0 ) { + if (0 == offset_) { message[strings::msg_params][strings::file_size] = (*message_)[strings::msg_params][strings::length]; } -- 2.7.4