summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrii Kalinich (GitHub) <AKalinich@luxoft.com>2021-08-25 16:52:38 -0400
committerGitHub <noreply@github.com>2021-08-25 16:52:38 -0400
commit7912ecb1c083bdaebadd43fe1530e9dded10083a (patch)
treec61ca8f988d43a22b0fe4d496254b364ea273be7
parentcf565cec5bfb2b66117a8ce6c3202d4cb1362f25 (diff)
downloadsdl_core-7912ecb1c083bdaebadd43fe1530e9dded10083a.tar.gz
Add method for delete empty message (#3751)
* Add method for delete empty message * Add WARNINGS code when some parameters were cut off Co-authored-by: Jacob Keeler <jacob.keeler@livioradio.com>
-rw-r--r--src/components/application_manager/include/application_manager/message_helper.h8
-rw-r--r--src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/mobile/get_vehicle_data_request.cc7
-rw-r--r--src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/mobile/on_vehicle_data_notification.cc2
-rw-r--r--src/components/application_manager/src/message_helper/message_helper.cc53
-rw-r--r--src/components/application_manager/test/include/application_manager/mock_message_helper.h2
-rw-r--r--src/components/application_manager/test/mock_message_helper.cc7
6 files changed, 79 insertions, 0 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 88200d6593..9cfb504b00 100644
--- a/src/components/application_manager/include/application_manager/message_helper.h
+++ b/src/components/application_manager/include/application_manager/message_helper.h
@@ -1096,6 +1096,14 @@ class MessageHelper {
const WindowID window_id);
/**
+ * @brief Recursively removes empty parameters of composite type from message
+ * @param msg_params smart object containing message params
+ * @return amount of empty parameters removed
+ */
+ static uint16_t RemoveEmptyMessageParams(
+ smart_objects::SmartObject& msg_params);
+
+ /**
* @brief AddDefaultParamsToTireStatus adds missing default sub-params to
* tirePressure param, if version of related application requires presence of
* all sub-params in response
diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/mobile/get_vehicle_data_request.cc b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/mobile/get_vehicle_data_request.cc
index 18149fbe02..854d78b684 100644
--- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/mobile/get_vehicle_data_request.cc
+++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/mobile/get_vehicle_data_request.cc
@@ -170,6 +170,13 @@ void GetVehicleDataRequest::on_event(const event_engine::Event& event) {
}
}
+ if (MessageHelper::RemoveEmptyMessageParams(
+ message[strings::msg_params]) > 0) {
+ mobile_result_code = mobile_apis::Result::WARNINGS;
+ response_info = app_mngr::commands::MergeInfos(
+ response_info, "Some vehicle data items could not be retrieved");
+ }
+
if (message[strings::msg_params].empty() &&
hmi_apis::Common_Result::DATA_NOT_AVAILABLE != result_code) {
response_info = "Failed to retrieve data from vehicle";
diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/mobile/on_vehicle_data_notification.cc b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/mobile/on_vehicle_data_notification.cc
index 0ae38a9398..71a6289d9c 100644
--- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/mobile/on_vehicle_data_notification.cc
+++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/mobile/on_vehicle_data_notification.cc
@@ -70,6 +70,8 @@ void OnVehicleDataNotification::Run() {
custom_vehicle_data_manager_.CreateMobileMessageParams(
(*message_)[strings::msg_params]);
+ MessageHelper::RemoveEmptyMessageParams((*message_)[strings::msg_params]);
+
const auto& param_names = (*message_)[strings::msg_params].enumerate();
for (const auto& name : param_names) {
SDL_LOG_DEBUG("vehicle_data name: " << name);
diff --git a/src/components/application_manager/src/message_helper/message_helper.cc b/src/components/application_manager/src/message_helper/message_helper.cc
index decdabb55c..606bc4c3f0 100644
--- a/src/components/application_manager/src/message_helper/message_helper.cc
+++ b/src/components/application_manager/src/message_helper/message_helper.cc
@@ -3475,6 +3475,59 @@ WindowID MessageHelper::ExtractWindowIdFromSmartObject(
return mobile_apis::PredefinedWindows::DEFAULT_WINDOW;
}
+uint16_t MessageHelper::RemoveEmptyMessageParams(
+ smart_objects::SmartObject& msg_params) {
+ uint16_t erased_params = 0;
+
+ if (msg_params.empty()) {
+ return erased_params;
+ }
+
+ const auto keys = msg_params.enumerate();
+ for (const auto& key_params : keys) {
+ auto& param = msg_params[key_params];
+
+ if (smart_objects::SmartType_Array == param.getType()) {
+ smart_objects::SmartArray* array = param.asArray();
+
+ if (array == nullptr || array->empty())
+ continue;
+
+ const bool are_all_empty =
+ std::all_of(array->begin(),
+ array->end(),
+ [](const smart_objects::SmartObject& item) {
+ if (smart_objects::SmartType_Array == item.getType() ||
+ smart_objects::SmartType_Map == item.getType()) {
+ return item.empty();
+ }
+
+ return false;
+ });
+
+ if (are_all_empty) {
+ SDL_LOG_DEBUG("Remove empty array " + key_params +
+ " from msg_params in HMI response");
+ msg_params.erase(key_params);
+ ++erased_params;
+ }
+
+ continue;
+ }
+
+ if (smart_objects::SmartType_Map == param.getType()) {
+ if (param.empty()) {
+ SDL_LOG_DEBUG("Remove empty field " + key_params +
+ " from msg_params in HMI response");
+ msg_params.erase(key_params);
+ ++erased_params;
+ }
+ }
+ }
+
+ return erased_params;
+}
+
void MessageHelper::AddDefaultParamsToTireStatus(
ApplicationSharedPtr app, smart_objects::SmartObject& response_from_hmi) {
const utils::SemanticVersion max_version_with_mandatory_params(8, 0, 0);
diff --git a/src/components/application_manager/test/include/application_manager/mock_message_helper.h b/src/components/application_manager/test/include/application_manager/mock_message_helper.h
index 9e69b0bcd6..67d992d4af 100644
--- a/src/components/application_manager/test/include/application_manager/mock_message_helper.h
+++ b/src/components/application_manager/test/include/application_manager/mock_message_helper.h
@@ -394,6 +394,8 @@ class MockMessageHelper {
application_manager::ApplicationSharedPtr application,
application_manager::ApplicationManager& app_mngr,
const application_manager::WindowID window_id));
+ MOCK_METHOD1(RemoveEmptyMessageParams,
+ uint16_t(const smart_objects::SmartObject&));
MOCK_METHOD2(AddDefaultParamsToTireStatus,
void(application_manager::ApplicationSharedPtr application,
diff --git a/src/components/application_manager/test/mock_message_helper.cc b/src/components/application_manager/test/mock_message_helper.cc
index 02cf70e3ba..9212b0feab 100644
--- a/src/components/application_manager/test/mock_message_helper.cc
+++ b/src/components/application_manager/test/mock_message_helper.cc
@@ -687,10 +687,17 @@ smart_objects::SmartObjectSPtr MessageHelper::CreateResponseMessageFromHmi(
function_id, correlation_id, result_code);
}
+uint16_t MessageHelper::RemoveEmptyMessageParams(
+ smart_objects::SmartObject& msg_params) {
+ return MockMessageHelper::message_helper_mock()->RemoveEmptyMessageParams(
+ msg_params);
+}
+
void MessageHelper::AddDefaultParamsToTireStatus(
application_manager::ApplicationSharedPtr application,
smart_objects::SmartObject& response_from_hmi) {
return MockMessageHelper::message_helper_mock()->AddDefaultParamsToTireStatus(
application, response_from_hmi);
}
+
} // namespace application_manager