summaryrefslogtreecommitdiff
path: root/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/hmi/as_get_app_service_data_request_from_hmi.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/hmi/as_get_app_service_data_request_from_hmi.cc')
-rw-r--r--src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/hmi/as_get_app_service_data_request_from_hmi.cc188
1 files changed, 169 insertions, 19 deletions
diff --git a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/hmi/as_get_app_service_data_request_from_hmi.cc b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/hmi/as_get_app_service_data_request_from_hmi.cc
index a339ffb9a6..2da8834b96 100644
--- a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/hmi/as_get_app_service_data_request_from_hmi.cc
+++ b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/hmi/as_get_app_service_data_request_from_hmi.cc
@@ -31,6 +31,7 @@
*/
#include "app_service_rpc_plugin/commands/hmi/as_get_app_service_data_request_from_hmi.h"
+#include "application_manager/app_service_manager.h"
#include "application_manager/application_impl.h"
#include "application_manager/rpc_service.h"
#include "interfaces/MOBILE_API.h"
@@ -70,30 +71,180 @@ void ASGetAppServiceDataRequestFromHMI::Run() {
true);
}
+void ASGetAppServiceDataRequestFromHMI::GetWeatherImagePaths(
+ smart_objects::SmartObject& data, ApplicationSharedPtr app) {
+ if (data[strings::location].keyExists(strings::location_image)) {
+ MessageHelper::VerifyImage(data[strings::location][strings::location_image],
+ app,
+ application_manager_);
+ }
+
+ if (data.keyExists(strings::current_forecast) &&
+ data[strings::current_forecast].keyExists(strings::weather_icon)) {
+ MessageHelper::VerifyImage(
+ data[strings::current_forecast][strings::weather_icon],
+ app,
+ application_manager_);
+ }
+
+ if (data.keyExists(strings::minute_forecast)) {
+ smart_objects::SmartObject& minute_forecast =
+ data[strings::minute_forecast];
+ for (size_t i = 0; i < minute_forecast.length(); i++) {
+ if (minute_forecast[i].keyExists(strings::weather_icon)) {
+ MessageHelper::VerifyImage(minute_forecast[i][strings::weather_icon],
+ app,
+ application_manager_);
+ }
+ }
+ }
+
+ if (data.keyExists(strings::hourly_forecast)) {
+ smart_objects::SmartObject& hourly_forecast =
+ data[strings::hourly_forecast];
+ for (size_t i = 0; i < hourly_forecast.length(); i++) {
+ if (hourly_forecast[i].keyExists(strings::weather_icon)) {
+ MessageHelper::VerifyImage(hourly_forecast[i][strings::weather_icon],
+ app,
+ application_manager_);
+ }
+ }
+ }
+
+ if (data.keyExists(strings::multiday_forecast)) {
+ smart_objects::SmartObject& multiday_forecast =
+ data[strings::multiday_forecast];
+ for (size_t i = 0; i < multiday_forecast.length(); i++) {
+ if (multiday_forecast[i].keyExists(strings::weather_icon)) {
+ MessageHelper::VerifyImage(multiday_forecast[i][strings::weather_icon],
+ app,
+ application_manager_);
+ }
+ }
+ }
+}
+
+void ASGetAppServiceDataRequestFromHMI::GetNavigationImagePaths(
+ smart_objects::SmartObject& data, ApplicationSharedPtr app) {
+ if (data.keyExists(strings::origin) &&
+ data[strings::origin].keyExists(strings::location_image)) {
+ MessageHelper::VerifyImage(data[strings::origin][strings::location_image],
+ app,
+ application_manager_);
+ }
+
+ if (data.keyExists(strings::destination) &&
+ data[strings::destination].keyExists(strings::location_image)) {
+ MessageHelper::VerifyImage(
+ data[strings::destination][strings::location_image],
+ app,
+ application_manager_);
+ }
+
+ if (data.keyExists(strings::instructions)) {
+ smart_objects::SmartObject& instructions = data[strings::instructions];
+ for (size_t i = 0; i < instructions.length(); i++) {
+ if (instructions[i].keyExists(strings::image)) {
+ MessageHelper::VerifyImage(
+ instructions[i][strings::image], app, application_manager_);
+ }
+
+ if (instructions[i].keyExists(strings::location_details) &&
+ instructions[i][strings::location_details].keyExists(
+ strings::location_image)) {
+ MessageHelper::VerifyImage(
+ instructions[i][strings::location_details][strings::location_image],
+ app,
+ application_manager_);
+ }
+ }
+ }
+}
+
+bool ASGetAppServiceDataRequestFromHMI::ValidateResponse(
+ smart_objects::SmartObject& message_params) {
+ if (!message_params.keyExists(strings::service_data)) {
+ LOG4CXX_DEBUG(
+ logger_,
+ "GASD response received without any service data, passing through");
+ return true;
+ }
+ smart_objects::SmartObject& service_data =
+ message_params[strings::service_data];
+ std::string service_type = service_data[strings::service_type].asString();
+ mobile_apis::AppServiceType::eType service_type_value;
+ const std::string& service_id = service_data[strings::service_id].asString();
+ auto service =
+ application_manager_.GetAppServiceManager().FindServiceByID(service_id);
+ if (!service) {
+ LOG4CXX_ERROR(logger_,
+ "GASD response received with an unpublished service ID");
+ SendErrorResponse(
+ correlation_id(),
+ hmi_apis::FunctionID::AppService_GetAppServiceData,
+ hmi_apis::Common_Result::GENERIC_ERROR,
+ "The provider responded with incorrect data",
+ application_manager::commands::Command::SOURCE_SDL_TO_HMI);
+ return false;
+ }
+
+ using namespace ns_smart_device_link::ns_smart_objects;
+ if (service && service->mobile_service &&
+ EnumConversionHelper<mobile_apis::AppServiceType::eType>::StringToEnum(
+ service_type, &service_type_value)) {
+ auto app = application_manager_.application(service->connection_key);
+ if (!app) {
+ LOG4CXX_ERROR(logger_,
+ "Failed to find service provider for GASD response");
+ SendErrorResponse(
+ correlation_id(),
+ hmi_apis::FunctionID::AppService_GetAppServiceData,
+ hmi_apis::Common_Result::GENERIC_ERROR,
+ "The provider responded with incorrect data",
+ application_manager::commands::Command::SOURCE_SDL_TO_HMI);
+ return false;
+ }
+
+ if (service_type_value == mobile_apis::AppServiceType::WEATHER &&
+ service_data.keyExists(strings::weather_service_data)) {
+ GetWeatherImagePaths(service_data[strings::weather_service_data], app);
+ }
+
+ if (service_type_value == mobile_apis::AppServiceType::NAVIGATION &&
+ service_data.keyExists(strings::navigation_service_data)) {
+ GetNavigationImagePaths(service_data[strings::navigation_service_data],
+ app);
+ }
+ }
+ return true;
+}
+
void ASGetAppServiceDataRequestFromHMI::on_event(
const event_engine::Event& event) {
- const smart_objects::SmartObject& event_message = event.smart_object();
+ smart_objects::SmartObject event_message(event.smart_object());
- auto msg_params = event_message[strings::msg_params];
+ auto& msg_params = event_message[strings::msg_params];
hmi_apis::Common_Result::eType result =
static_cast<hmi_apis::Common_Result::eType>(
event_message[strings::params][hmi_response::code].asInt());
bool success =
IsHMIResultSuccess(result, HmiInterfaces::HMI_INTERFACE_AppService);
- SendResponse(success,
- correlation_id(),
- hmi_apis::FunctionID::AppService_GetAppServiceData,
- result,
- &msg_params,
- application_manager::commands::Command::SOURCE_SDL_TO_HMI);
+ if (ValidateResponse(msg_params)) {
+ SendResponse(success,
+ correlation_id(),
+ hmi_apis::FunctionID::AppService_GetAppServiceData,
+ result,
+ &msg_params,
+ application_manager::commands::Command::SOURCE_SDL_TO_HMI);
+ }
}
void ASGetAppServiceDataRequestFromHMI::on_event(
const event_engine::MobileEvent& event) {
- const smart_objects::SmartObject& event_message = event.smart_object();
+ smart_objects::SmartObject event_message(event.smart_object());
- auto msg_params = event_message[strings::msg_params];
+ auto& msg_params = event_message[strings::msg_params];
mobile_apis::Result::eType mobile_result =
static_cast<mobile_apis::Result::eType>(
@@ -102,19 +253,18 @@ void ASGetAppServiceDataRequestFromHMI::on_event(
MessageHelper::MobileToHMIResult(mobile_result);
bool success = IsMobileResultSuccess(mobile_result);
- SendResponse(success,
- correlation_id(),
- hmi_apis::FunctionID::AppService_GetAppServiceData,
- result,
- &msg_params,
- application_manager::commands::Command::SOURCE_SDL_TO_HMI);
+ if (ValidateResponse(msg_params)) {
+ SendResponse(success,
+ correlation_id(),
+ hmi_apis::FunctionID::AppService_GetAppServiceData,
+ result,
+ &msg_params,
+ application_manager::commands::Command::SOURCE_SDL_TO_HMI);
+ }
}
void ASGetAppServiceDataRequestFromHMI::onTimeOut() {
LOG4CXX_AUTO_TRACE(logger_);
- smart_objects::SmartObject response_params;
- response_params[strings::info] =
- "The provider did not respond to the request";
SendErrorResponse(correlation_id(),
hmi_apis::FunctionID::AppService_GetAppServiceData,
hmi_apis::Common_Result::GENERIC_ERROR,