summaryrefslogtreecommitdiff
path: root/src/components/application_manager/src/commands/mobile/add_command_request.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/application_manager/src/commands/mobile/add_command_request.cc')
-rw-r--r--src/components/application_manager/src/commands/mobile/add_command_request.cc310
1 files changed, 170 insertions, 140 deletions
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 da44d0e7c4..03bdfadd66 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
@@ -33,27 +33,30 @@
#include <string>
#include "application_manager/commands/mobile/add_command_request.h"
-#include "application_manager/application_manager_impl.h"
+
#include "application_manager/application.h"
#include "application_manager/message_helper.h"
#include "utils/file_system.h"
+#include "utils/helpers.h"
+#include "utils/custom_string.h"
namespace application_manager {
namespace commands {
-AddCommandRequest::AddCommandRequest(const MessageSharedPtr& message)
- : CommandRequestImpl(message),
- send_ui_(false),
- send_vr_(false),
- is_ui_received_(false),
- is_vr_received_(false),
- ui_result_(hmi_apis::Common_Result::INVALID_ENUM),
- vr_result_(hmi_apis::Common_Result::INVALID_ENUM) {
-}
+namespace custom_str = utils::custom_string;
-AddCommandRequest::~AddCommandRequest() {
-}
+AddCommandRequest::AddCommandRequest(const MessageSharedPtr& message,
+ ApplicationManager& application_manager)
+ : CommandRequestImpl(message, application_manager)
+ , send_ui_(false)
+ , send_vr_(false)
+ , is_ui_received_(false)
+ , is_vr_received_(false)
+ , ui_result_(hmi_apis::Common_Result::INVALID_ENUM)
+ , vr_result_(hmi_apis::Common_Result::INVALID_ENUM) {}
+
+AddCommandRequest::~AddCommandRequest() {}
void AddCommandRequest::onTimeOut() {
LOG4CXX_AUTO_TRACE(logger_);
@@ -64,43 +67,43 @@ void AddCommandRequest::onTimeOut() {
void AddCommandRequest::Run() {
LOG4CXX_AUTO_TRACE(logger_);
- ApplicationSharedPtr app = ApplicationManagerImpl::instance()->application(
+ ApplicationSharedPtr app = application_manager_.application(
(*message_)[strings::params][strings::connection_key].asUInt());
if (!app) {
- LOG4CXX_ERROR_EXT(logger_, "No application associated with session key");
+ LOG4CXX_ERROR(logger_, "No application associated with session key");
SendResponse(false, mobile_apis::Result::APPLICATION_NOT_REGISTERED);
return;
}
if ((*message_)[strings::msg_params].keyExists(strings::cmd_icon)) {
- mobile_apis::Result::eType verification_result =
- MessageHelper::VerifyImage((*message_)[strings::msg_params]
- [strings::cmd_icon], app);
+ mobile_apis::Result::eType verification_result = MessageHelper::VerifyImage(
+ (*message_)[strings::msg_params][strings::cmd_icon],
+ app,
+ application_manager_);
if (mobile_apis::Result::SUCCESS != verification_result) {
- LOG4CXX_ERROR_EXT(
- logger_,
- "MessageHelper::VerifyImage return " << verification_result);
+ LOG4CXX_ERROR(
+ logger_, "MessageHelper::VerifyImage return " << verification_result);
SendResponse(false, verification_result);
return;
}
}
if (!((*message_)[strings::msg_params].keyExists(strings::cmd_id))) {
- LOG4CXX_ERROR_EXT(logger_, "INVALID_DATA");
+ LOG4CXX_ERROR(logger_, "INVALID_DATA");
SendResponse(false, mobile_apis::Result::INVALID_DATA);
return;
}
if (app->FindCommand(
- (*message_)[strings::msg_params][strings::cmd_id].asUInt())) {
- LOG4CXX_ERROR_EXT(logger_, "INVALID_ID");
+ (*message_)[strings::msg_params][strings::cmd_id].asUInt())) {
+ LOG4CXX_ERROR(logger_, "INVALID_ID");
SendResponse(false, mobile_apis::Result::INVALID_ID);
return;
}
- bool data_exist = false;
+ bool data_exist = false;
if ((*message_)[strings::msg_params].keyExists(strings::menu_params)) {
if (!CheckCommandName(app)) {
@@ -108,21 +111,21 @@ void AddCommandRequest::Run() {
return;
}
if (((*message_)[strings::msg_params][strings::menu_params].keyExists(
- hmi_request::parent_id)) && (0 != (*message_)[strings::msg_params]
- [strings::menu_params][hmi_request::parent_id].asUInt())) {
+ hmi_request::parent_id)) &&
+ (0 !=
+ (*message_)[strings::msg_params][strings::menu_params]
+ [hmi_request::parent_id].asUInt())) {
if (!CheckCommandParentId(app)) {
- SendResponse(false, mobile_apis::Result::INVALID_ID,
- "Parent ID doesn't exist");
+ SendResponse(
+ false, mobile_apis::Result::INVALID_ID, "Parent ID doesn't exist");
return;
}
}
data_exist = true;
}
- if (((*message_)[strings::msg_params].keyExists(strings::vr_commands))
- && ((*message_)[strings::msg_params]
- [strings::vr_commands].length() > 0)) {
-
+ if (((*message_)[strings::msg_params].keyExists(strings::vr_commands)) &&
+ ((*message_)[strings::msg_params][strings::vr_commands].length() > 0)) {
if (!CheckCommandVRSynonym(app)) {
SendResponse(false, mobile_apis::Result::DUPLICATE_NAME);
return;
@@ -132,24 +135,22 @@ void AddCommandRequest::Run() {
}
if (!data_exist) {
- LOG4CXX_ERROR_EXT(logger_, "INVALID_DATA");
+ LOG4CXX_ERROR(logger_, "INVALID_DATA");
SendResponse(false, mobile_apis::Result::INVALID_DATA);
return;
}
if (IsWhiteSpaceExist()) {
- LOG4CXX_ERROR(logger_,
- "Incoming add command has contains \t\n \\t \\n");
+ LOG4CXX_ERROR(logger_, "Incoming add command has contains \t\n \\t \\n");
SendResponse(false, mobile_apis::Result::INVALID_DATA);
return;
}
- app->AddCommand((*message_)[strings::msg_params]
- [strings::cmd_id].asUInt(),
- (*message_)[strings::msg_params]);
+ app->AddCommand((*message_)[strings::msg_params][strings::cmd_id].asUInt(),
+ (*message_)[strings::msg_params]);
- smart_objects::SmartObject ui_msg_params = smart_objects::SmartObject(
- smart_objects::SmartType_Map);
+ smart_objects::SmartObject ui_msg_params =
+ smart_objects::SmartObject(smart_objects::SmartType_Map);
if ((*message_)[strings::msg_params].keyExists(strings::menu_params)) {
ui_msg_params[strings::cmd_id] =
(*message_)[strings::msg_params][strings::cmd_id];
@@ -158,10 +159,11 @@ void AddCommandRequest::Run() {
ui_msg_params[strings::app_id] = app->app_id();
- if ( ((*message_)[strings::msg_params].keyExists(strings::cmd_icon))
- && ((*message_)[strings::msg_params][strings::cmd_icon].keyExists(strings::value))
- && (0 < (*message_)[strings::msg_params][strings::cmd_icon]
- [strings::value].length())) {
+ if (((*message_)[strings::msg_params].keyExists(strings::cmd_icon)) &&
+ ((*message_)[strings::msg_params][strings::cmd_icon].keyExists(
+ strings::value)) &&
+ (0 < (*message_)[strings::msg_params][strings::cmd_icon][strings::value]
+ .length())) {
ui_msg_params[strings::cmd_icon] =
(*message_)[strings::msg_params][strings::cmd_icon];
}
@@ -169,8 +171,8 @@ void AddCommandRequest::Run() {
send_ui_ = true;
}
- smart_objects::SmartObject vr_msg_params = smart_objects::SmartObject(
- smart_objects::SmartType_Map);
+ smart_objects::SmartObject vr_msg_params =
+ smart_objects::SmartObject(smart_objects::SmartType_Map);
if ((*message_)[strings::msg_params].keyExists(strings::vr_commands)) {
vr_msg_params[strings::cmd_id] =
(*message_)[strings::msg_params][strings::cmd_id];
@@ -203,27 +205,28 @@ bool AddCommandRequest::CheckCommandName(ApplicationConstSharedPtr app) {
CommandsMap::const_iterator i = commands.begin();
uint32_t saved_parent_id = 0;
uint32_t parent_id = 0;
- if ((*message_)[strings::msg_params]
- [strings::menu_params].keyExists(hmi_request::parent_id)) {
- parent_id = (*message_)[strings::msg_params]
- [strings::menu_params][hmi_request::parent_id].asUInt();
+ if ((*message_)[strings::msg_params][strings::menu_params].keyExists(
+ hmi_request::parent_id)) {
+ parent_id = (*message_)[strings::msg_params][strings::menu_params]
+ [hmi_request::parent_id].asUInt();
}
for (; commands.end() != i; ++i) {
-
if (!(*i->second).keyExists(strings::menu_params)) {
continue;
}
saved_parent_id = 0;
if ((*i->second)[strings::menu_params].keyExists(hmi_request::parent_id)) {
- saved_parent_id = (*i->second)[strings::menu_params][hmi_request::parent_id].asUInt();
+ saved_parent_id =
+ (*i->second)[strings::menu_params][hmi_request::parent_id].asUInt();
}
- if (((*i->second)[strings::menu_params][strings::menu_name].asString()
- == (*message_)[strings::msg_params][strings::menu_params]
- [strings::menu_name].asString()) &&
+ if (((*i->second)[strings::menu_params][strings::menu_name].asString() ==
+ (*message_)[strings::msg_params][strings::menu_params]
+ [strings::menu_name].asString()) &&
(saved_parent_id == parent_id)) {
- LOG4CXX_INFO(logger_, "AddCommandRequest::CheckCommandName received"
+ LOG4CXX_INFO(logger_,
+ "AddCommandRequest::CheckCommandName received"
" command name already exist in same level menu");
return false;
}
@@ -241,23 +244,23 @@ bool AddCommandRequest::CheckCommandVRSynonym(ApplicationConstSharedPtr app) {
CommandsMap::const_iterator it = commands.begin();
for (; commands.end() != it; ++it) {
-
- if(!(*it->second).keyExists(strings::vr_commands)) {
+ if (!(*it->second).keyExists(strings::vr_commands)) {
continue;
}
for (size_t i = 0; i < (*it->second)[strings::vr_commands].length(); ++i) {
for (size_t j = 0;
- j < (*message_)[strings::msg_params][strings::vr_commands].length();
- ++j) {
- std::string vr_cmd_i =
- (*it->second)[strings::vr_commands][i].asString();
- std::string vr_cmd_j =
- (*message_)[strings::msg_params]
- [strings::vr_commands][j].asString();
-
- if (0 == strcasecmp(vr_cmd_i.c_str(), vr_cmd_j.c_str())) {
- LOG4CXX_INFO(logger_, "AddCommandRequest::CheckCommandVRSynonym"
+ j < (*message_)[strings::msg_params][strings::vr_commands].length();
+ ++j) {
+ const custom_str::CustomString& vr_cmd_i =
+ (*it->second)[strings::vr_commands][i].asCustomString();
+ const custom_str::CustomString& vr_cmd_j =
+ (*message_)[strings::msg_params][strings::vr_commands][j]
+ .asCustomString();
+
+ if (vr_cmd_i.CompareIgnoreCase(vr_cmd_j)) {
+ LOG4CXX_INFO(logger_,
+ "AddCommandRequest::CheckCommandVRSynonym"
" received command vr synonym already exist");
return false;
}
@@ -274,11 +277,12 @@ bool AddCommandRequest::CheckCommandParentId(ApplicationConstSharedPtr app) {
const int32_t parent_id =
(*message_)[strings::msg_params][strings::menu_params]
- [hmi_request::parent_id].asInt();
+ [hmi_request::parent_id].asInt();
smart_objects::SmartObject* parent = app->FindSubMenu(parent_id);
if (!parent) {
- LOG4CXX_INFO(logger_, "AddCommandRequest::CheckCommandParentId received"
+ LOG4CXX_INFO(logger_,
+ "AddCommandRequest::CheckCommandParentId received"
" submenu doesn't exist");
return false;
}
@@ -287,11 +291,12 @@ bool AddCommandRequest::CheckCommandParentId(ApplicationConstSharedPtr app) {
void AddCommandRequest::on_event(const event_engine::Event& event) {
LOG4CXX_AUTO_TRACE(logger_);
+ using namespace helpers;
const smart_objects::SmartObject& message = event.smart_object();
ApplicationSharedPtr application =
- ApplicationManagerImpl::instance()->application(connection_key());
+ application_manager_.application(connection_key());
if (!application) {
LOG4CXX_ERROR(logger_, "NULL pointer");
@@ -299,7 +304,8 @@ void AddCommandRequest::on_event(const event_engine::Event& event) {
}
smart_objects::SmartObject msg_param(smart_objects::SmartType_Map);
- msg_param[strings::cmd_id] = (*message_)[strings::msg_params][strings::cmd_id];
+ msg_param[strings::cmd_id] =
+ (*message_)[strings::msg_params][strings::cmd_id];
msg_param[strings::app_id] = application->app_id();
switch (event.id()) {
@@ -326,79 +332,104 @@ void AddCommandRequest::on_event(const event_engine::Event& event) {
break;
}
default: {
- LOG4CXX_ERROR(logger_,"Received unknown event" << event.id());
+ LOG4CXX_ERROR(logger_, "Received unknown event" << event.id());
return;
}
}
- if (!IsPendingResponseExist()) {
-
- ApplicationSharedPtr application =
- ApplicationManagerImpl::instance()->application(connection_key());
+ if (IsPendingResponseExist()) {
+ return;
+ }
- if (hmi_apis::Common_Result::REJECTED == ui_result_) {
- RemoveCommand();
- }
+ if (hmi_apis::Common_Result::REJECTED == ui_result_) {
+ RemoveCommand();
+ }
- smart_objects::SmartObject msg_params(smart_objects::SmartType_Map);
- msg_params[strings::cmd_id] = (*message_)[strings::msg_params][strings::cmd_id];
- msg_params[strings::app_id] = application->app_id();
-
- mobile_apis::Result::eType result_code = mobile_apis::Result::INVALID_ENUM;
-
- bool result = ((hmi_apis::Common_Result::SUCCESS == ui_result_) &&
- (hmi_apis::Common_Result::SUCCESS == vr_result_)) ||
- ((hmi_apis::Common_Result::SUCCESS == ui_result_) &&
- (hmi_apis::Common_Result::INVALID_ENUM == vr_result_ ||
- hmi_apis::Common_Result::UNSUPPORTED_RESOURCE == vr_result_)) ||
- ((hmi_apis::Common_Result::INVALID_ENUM == ui_result_ ||
- hmi_apis::Common_Result::UNSUPPORTED_RESOURCE == ui_result_ ) &&
- (hmi_apis::Common_Result::SUCCESS == vr_result_));
-
- if (!result && (hmi_apis::Common_Result::REJECTED == ui_result_)) {
- result_code = static_cast<mobile_apis::Result::eType>(ui_result_);
- } else {
- result_code = static_cast<mobile_apis::Result::eType>(
- std::max(ui_result_, vr_result_));
- }
+ smart_objects::SmartObject msg_params(smart_objects::SmartType_Map);
+ msg_params[strings::cmd_id] =
+ (*message_)[strings::msg_params][strings::cmd_id];
+ msg_params[strings::app_id] = application->app_id();
+
+ mobile_apis::Result::eType result_code = mobile_apis::Result::INVALID_ENUM;
+
+ const bool is_vr_invalid_unsupported =
+ Compare<hmi_apis::Common_Result::eType, EQ, ONE>(
+ vr_result_,
+ hmi_apis::Common_Result::INVALID_ENUM,
+ hmi_apis::Common_Result::UNSUPPORTED_RESOURCE);
+
+ const bool is_ui_ivalid_unsupported =
+ Compare<hmi_apis::Common_Result::eType, EQ, ONE>(
+ ui_result_,
+ hmi_apis::Common_Result::INVALID_ENUM,
+ hmi_apis::Common_Result::UNSUPPORTED_RESOURCE);
+
+ const bool is_no_ui_error = Compare<hmi_apis::Common_Result::eType, EQ, ONE>(
+ ui_result_,
+ hmi_apis::Common_Result::SUCCESS,
+ hmi_apis::Common_Result::WARNINGS);
+
+ const bool is_no_vr_error = Compare<hmi_apis::Common_Result::eType, EQ, ONE>(
+ vr_result_,
+ hmi_apis::Common_Result::SUCCESS,
+ hmi_apis::Common_Result::WARNINGS);
+
+ bool result = (is_no_ui_error && is_no_vr_error) ||
+ (is_no_ui_error && is_vr_invalid_unsupported) ||
+ (is_no_vr_error && is_ui_ivalid_unsupported);
+
+ const bool is_vr_or_ui_warning =
+ Compare<hmi_apis::Common_Result::eType, EQ, ONE>(
+ hmi_apis::Common_Result::WARNINGS, ui_result_, vr_result_);
+
+ if (!result && hmi_apis::Common_Result::REJECTED == ui_result_) {
+ result_code = MessageHelper::HMIToMobileResult(ui_result_);
+ } else if (is_vr_or_ui_warning) {
+ result_code = mobile_apis::Result::WARNINGS;
+ } else {
+ result_code =
+ MessageHelper::HMIToMobileResult(std::max(ui_result_, vr_result_));
+ }
- if (BothSend() && hmi_apis::Common_Result::SUCCESS == vr_result_) {
- if (hmi_apis::Common_Result::SUCCESS != ui_result_ &&
- hmi_apis::Common_Result::WARNINGS != ui_result_ &&
- hmi_apis::Common_Result::UNSUPPORTED_RESOURCE != ui_result_) {
+ if (BothSend() && hmi_apis::Common_Result::SUCCESS == vr_result_) {
+ const bool is_ui_not_ok = Compare<hmi_apis::Common_Result::eType, NEQ, ALL>(
+ ui_result_,
+ hmi_apis::Common_Result::SUCCESS,
+ hmi_apis::Common_Result::WARNINGS,
+ hmi_apis::Common_Result::UNSUPPORTED_RESOURCE);
- result_code =
- (ui_result_ == hmi_apis::Common_Result::REJECTED) ?
- mobile_apis::Result::REJECTED : mobile_apis::Result::GENERIC_ERROR;
+ if (is_ui_not_ok) {
+ result_code = ui_result_ == hmi_apis::Common_Result::REJECTED
+ ? mobile_apis::Result::REJECTED
+ : mobile_apis::Result::GENERIC_ERROR;
- msg_params[strings::grammar_id] = application->get_grammar_id();
- msg_params[strings::type] = hmi_apis::Common_VRCommandType::Command;
+ msg_params[strings::grammar_id] = application->get_grammar_id();
+ msg_params[strings::type] = hmi_apis::Common_VRCommandType::Command;
- SendHMIRequest(hmi_apis::FunctionID::VR_DeleteCommand, &msg_params);
- application->RemoveCommand((*message_)[strings::msg_params]
- [strings::cmd_id].asUInt());
- result = false;
- }
+ SendHMIRequest(hmi_apis::FunctionID::VR_DeleteCommand, &msg_params);
+ application->RemoveCommand(
+ (*message_)[strings::msg_params][strings::cmd_id].asUInt());
+ result = false;
}
+ }
- if(BothSend() && hmi_apis::Common_Result::SUCCESS == ui_result_ &&
- hmi_apis::Common_Result::SUCCESS != vr_result_) {
+ if (BothSend() && hmi_apis::Common_Result::SUCCESS == ui_result_ &&
+ !is_no_vr_error) {
+ result_code = vr_result_ == hmi_apis::Common_Result::REJECTED
+ ? mobile_apis::Result::REJECTED
+ : mobile_apis::Result::GENERIC_ERROR;
- result_code =
- (vr_result_ == hmi_apis::Common_Result::REJECTED) ?
- mobile_apis::Result::REJECTED : mobile_apis::Result::GENERIC_ERROR;
+ SendHMIRequest(hmi_apis::FunctionID::UI_DeleteCommand, &msg_params);
- SendHMIRequest(hmi_apis::FunctionID::UI_DeleteCommand, &msg_params);
+ application->RemoveCommand(
+ (*message_)[strings::msg_params][strings::cmd_id].asUInt());
+ result = false;
+ }
- application->RemoveCommand((*message_)[strings::msg_params]
- [strings::cmd_id].asUInt());
- result = false;
- }
+ SendResponse(result, result_code, NULL, &(message[strings::msg_params]));
- SendResponse(result, result_code, NULL, &(message[strings::msg_params]));
- if (true == result) {
- application->UpdateHash();
- }
+ if (result) {
+ application->UpdateHash();
}
}
@@ -412,7 +443,7 @@ bool AddCommandRequest::IsWhiteSpaceExist() {
if ((*message_)[strings::msg_params].keyExists(strings::menu_params)) {
str = (*message_)[strings::msg_params][strings::menu_params]
- [strings::menu_name].asCharArray();
+ [strings::menu_name].asCharArray();
if (!CheckSyntax(str)) {
LOG4CXX_ERROR(logger_, "Invalid menu name syntax check failed.");
return true;
@@ -424,8 +455,8 @@ bool AddCommandRequest::IsWhiteSpaceExist() {
(*message_)[strings::msg_params][strings::vr_commands].length();
for (size_t i = 0; i < len; ++i) {
- str = (*message_)[strings::msg_params]
- [strings::vr_commands][i].asCharArray();
+ str = (*message_)[strings::msg_params][strings::vr_commands][i]
+ .asCharArray();
if (!CheckSyntax(str)) {
LOG4CXX_ERROR(logger_, "Invalid vr_commands syntax check failed");
return true;
@@ -434,8 +465,8 @@ bool AddCommandRequest::IsWhiteSpaceExist() {
}
if ((*message_)[strings::msg_params].keyExists(strings::cmd_icon)) {
- str = (*message_)[strings::msg_params]
- [strings::cmd_icon][strings::value].asCharArray();
+ str = (*message_)[strings::msg_params][strings::cmd_icon][strings::value]
+ .asCharArray();
if (!CheckSyntax(str)) {
LOG4CXX_ERROR(logger_, "Invalid cmd_icon value syntax check failed");
return true;
@@ -450,19 +481,19 @@ bool AddCommandRequest::BothSend() const {
void AddCommandRequest::RemoveCommand() {
LOG4CXX_AUTO_TRACE(logger_);
- ApplicationSharedPtr app = ApplicationManagerImpl::instance()->application(
- connection_key());
+ ApplicationSharedPtr app = application_manager_.application(connection_key());
if (!app.valid()) {
LOG4CXX_ERROR(logger_, "No application associated with session key");
return;
}
smart_objects::SmartObject msg_params(smart_objects::SmartType_Map);
- msg_params[strings::cmd_id] = (*message_)[strings::msg_params][strings::cmd_id];
+ msg_params[strings::cmd_id] =
+ (*message_)[strings::msg_params][strings::cmd_id];
msg_params[strings::app_id] = app->app_id();
- app->RemoveCommand((*message_)[strings::msg_params]
- [strings::cmd_id].asUInt());
+ app->RemoveCommand(
+ (*message_)[strings::msg_params][strings::cmd_id].asUInt());
if (BothSend() && !(is_vr_received_ || is_ui_received_)) {
// in case we have send bth UI and VR and no one respond
@@ -479,7 +510,6 @@ void AddCommandRequest::RemoveCommand() {
msg_params[strings::type] = hmi_apis::Common_VRCommandType::Command;
SendHMIRequest(hmi_apis::FunctionID::VR_DeleteCommand, &msg_params);
}
-
}
} // namespace commands