diff options
Diffstat (limited to 'SDL_Core/src/components/application_manager/src/message_helper.cc')
-rw-r--r-- | SDL_Core/src/components/application_manager/src/message_helper.cc | 1593 |
1 files changed, 0 insertions, 1593 deletions
diff --git a/SDL_Core/src/components/application_manager/src/message_helper.cc b/SDL_Core/src/components/application_manager/src/message_helper.cc deleted file mode 100644 index 9e7bf4842..000000000 --- a/SDL_Core/src/components/application_manager/src/message_helper.cc +++ /dev/null @@ -1,1593 +0,0 @@ -/* - Copyright (c) 2013, Ford Motor Company - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - - Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following - disclaimer in the documentation and/or other materials provided with the - distribution. - - Neither the name of the Ford Motor Company nor the names of its contributors - may be used to endorse or promote products derived from this software - without specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. - */ - -#include <set> -#include <string> -#include <algorithm> - -#include "utils/macro.h" -#include "application_manager/application_manager_impl.h" -#include "application_manager/message_helper.h" -#include "application_manager/commands/command_impl.h" -#include "connection_handler/connection_handler_impl.h" -#include "application_manager/application.h" -#include "config_profile/profile.h" -#include "utils/file_system.h" -#include "interfaces/MOBILE_API.h" - - -namespace { - -log4cxx::LoggerPtr g_logger = - log4cxx::LoggerPtr(log4cxx::Logger::getLogger("ApplicationManager")); - -hmi_apis::Common_Language::eType ToCommonLanguage( - mobile_apis::Language::eType mobile_language) { - // Update this check if mobile_api::Language - // or hmi_apis::Common_Language changes. - // Or, better, generate functions like this from XML - long lang_val = long(mobile_language); - long max_common_lang_val = long(hmi_apis::Common_Language::NO_NO); - long max_mobile_lang = long(mobile_apis::Language::NO_NO); - if (max_common_lang_val != max_mobile_lang) { - LOG4CXX_ERROR(g_logger, "Mapping between Common_Language and Language" - " has changed! Please update converter function"); - } - if (lang_val > max_common_lang_val) { - LOG4CXX_ERROR(g_logger, "Non-convertable language ID"); - } - return hmi_apis::Common_Language::eType(lang_val); -} - -} - -namespace application_manager { - -namespace { - -bool ValidateSoftButtons(smart_objects::SmartObject& soft_buttons) { - using namespace smart_objects; - for (size_t i = 0; i < soft_buttons.length(); ++i) { - SmartObject& button = soft_buttons[i]; - - // Check if image parameter is valid - if (button.keyExists(strings::image)) { - SmartObject& buttonImage = button[strings::image]; - - // Image name must not be empty - std::string file_name = buttonImage[strings::value].asString(); - file_name.erase(remove(file_name.begin(), file_name.end(), ' '), file_name.end()); - if (file_name.empty()) { - return false; - } - } - } - return true; -} - -} -std::pair<const char*, VehicleDataType> kVehicleDataInitializer[] = { -std::make_pair(strings::gps, VehicleDataType::GPS), -std::make_pair(strings::speed, VehicleDataType::SPEED), -std::make_pair(strings::rpm, VehicleDataType::RPM), -std::make_pair(strings::fuel_level, VehicleDataType::FUELLEVEL), -std::make_pair(strings::fuel_level_state, VehicleDataType::FUELLEVEL_STATE), -std::make_pair(strings::instant_fuel_consumption, VehicleDataType::FUELCONSUMPTION), -std::make_pair(strings::external_temp, VehicleDataType::EXTERNTEMP), -std::make_pair(strings::vin, VehicleDataType::VIN ), -std::make_pair(strings::prndl, VehicleDataType::PRNDL), -std::make_pair(strings::tire_pressure, VehicleDataType::TIREPRESSURE), -std::make_pair(strings::odometer, VehicleDataType::ODOMETER), -std::make_pair(strings::belt_status, VehicleDataType::BELTSTATUS), -std::make_pair(strings::body_information, VehicleDataType::BODYINFO), -std::make_pair(strings::device_status, VehicleDataType::DEVICESTATUS), -std::make_pair(strings::driver_braking, VehicleDataType::BRAKING), -std::make_pair(strings::wiper_status, VehicleDataType::WIPERSTATUS), -std::make_pair(strings::head_lamp_status, VehicleDataType::HEADLAMPSTATUS), -std::make_pair(strings::e_call_info, VehicleDataType::ECALLINFO), -std::make_pair(strings::airbag_status, VehicleDataType::AIRBAGSTATUS), -std::make_pair(strings::emergency_event, VehicleDataType::EMERGENCYEVENT), -std::make_pair(strings::cluster_mode_status, VehicleDataType::CLUSTERMODESTATUS), -std::make_pair(strings::my_key, VehicleDataType::MYKEY), -/* - NOT DEFINED in mobile API - std::make_pair(strings::gps, VehicleDataType::BATTVOLTAGE), - */ -std::make_pair(strings::engine_torque, VehicleDataType::ENGINETORQUE ), -std::make_pair(strings::acc_pedal_pos, VehicleDataType::ACCPEDAL), -std::make_pair(strings::steering_wheel_angle, VehicleDataType::STEERINGWHEEL), -}; - -const VehicleData MessageHelper::vehicle_data_(kVehicleDataInitializer, - kVehicleDataInitializer + - ARRAYSIZE(kVehicleDataInitializer)); - - -#ifdef QT_HMI -namespace { - struct VehicleInfo_Requests { - hmi_apis::FunctionID::eType func_id; - const char* str; - }; - static VehicleInfo_Requests ivi_subrequests[] = { - { hmi_apis::FunctionID::VehicleInfo_SubscribeGps, strings::gps}, - { hmi_apis::FunctionID::VehicleInfo_SubscribeSpeed, strings::speed}, - { hmi_apis::FunctionID::VehicleInfo_SubscribeRpm, strings::rpm}, - { hmi_apis::FunctionID::VehicleInfo_SubscribeFuelLevel, strings::fuel_level}, - { hmi_apis::FunctionID::VehicleInfo_SubscribeFuelLevel_State, strings::fuel_level_state}, - { hmi_apis::FunctionID::VehicleInfo_SubscribeInstantFuelConsumption, strings::instant_fuel_consumption}, - { hmi_apis::FunctionID::VehicleInfo_SubscribeExternalTemperature, strings::external_temp}, - { hmi_apis::FunctionID::VehicleInfo_SubscribeVin, strings::vin}, - { hmi_apis::FunctionID::VehicleInfo_SubscribePrndl, strings::prndl}, - { hmi_apis::FunctionID::VehicleInfo_SubscribeTirePressure, strings::tire_pressure}, - { hmi_apis::FunctionID::VehicleInfo_SubscribeOdometer, strings::odometer}, - { hmi_apis::FunctionID::VehicleInfo_SubscribeBeltStatus, strings::belt_status}, - { hmi_apis::FunctionID::VehicleInfo_SubscribeBodyInformation, strings::body_information}, - { hmi_apis::FunctionID::VehicleInfo_SubscribeDeviceStatus, strings::device_status}, - { hmi_apis::FunctionID::VehicleInfo_SubscribeDriverBraking, strings::driver_braking}, - { hmi_apis::FunctionID::VehicleInfo_SubscribeWiperStatus, strings::wiper_status}, - { hmi_apis::FunctionID::VehicleInfo_SubscribeHeadLampStatus, strings::head_lamp_status}, - { hmi_apis::FunctionID::VehicleInfo_SubscribeEngineTorque, strings::engine_torque}, - { hmi_apis::FunctionID::VehicleInfo_SubscribeAccPedalPosition, strings::acc_pedal_pos}, - { hmi_apis::FunctionID::VehicleInfo_SubscribeSteeringWheelAngle, strings::steering_wheel_angle}, - { hmi_apis::FunctionID::VehicleInfo_SubscribeECallInfo, strings::e_call_info}, - { hmi_apis::FunctionID::VehicleInfo_SubscribeAirbagStatus, strings::airbag_status}, - { hmi_apis::FunctionID::VehicleInfo_SubscribeEmergencyEvent, strings::emergency_event}, - { hmi_apis::FunctionID::VehicleInfo_SubscribeClusterModeStatus, strings::cluster_mode_status}, - { hmi_apis::FunctionID::VehicleInfo_SubscribeMyKey, strings::my_key}, - }; -} -#endif // #ifdef QT_HMI - - -void MessageHelper::SendHMIStatusNotification( - const Application& application_impl) { - smart_objects::SmartObject* notification = new smart_objects::SmartObject; - if (!notification) { - // TODO(VS): please add logger. - return; - } - smart_objects::SmartObject& message = *notification; - - message[strings::params][strings::function_id] = - static_cast<int32_t>(mobile_api::FunctionID::OnHMIStatusID); - - message[strings::params][strings::message_type] = - static_cast<int32_t>(application_manager::MessageType::kNotification); - - message[strings::params][strings::connection_key] = - static_cast<int32_t>(application_impl.app_id()); - - message[strings::msg_params][strings::hmi_level] = - static_cast<int32_t>(application_impl.hmi_level()); - - message[strings::msg_params][strings::audio_streaming_state] = - static_cast<int32_t>(application_impl.audio_streaming_state()); - - message[strings::msg_params][strings::system_context] = - static_cast<int32_t>(application_impl.system_context()); - - DCHECK(ApplicationManagerImpl::instance()->ManageMobileCommand(notification)); -} - -void MessageHelper::SendOnAppRegisteredNotificationToHMI( - const Application& application_impl) { - smart_objects::SmartObject* notification = new smart_objects::SmartObject; - if (!notification) { - // TODO(VS): please add logger. - return; - } - smart_objects::SmartObject& message = *notification; - - message[strings::params][strings::function_id] = - static_cast<int32_t>(hmi_apis::FunctionID::BasicCommunication_OnAppRegistered); - - message[strings::params][strings::message_type] = - static_cast<int32_t>(application_manager::MessageType::kNotification); - message[strings::msg_params][strings::application][strings::app_name] = - application_impl.name(); - - const smart_objects::SmartObject* ngn_media_screen_name = - application_impl.ngn_media_screen_name(); - - if (ngn_media_screen_name) { - message[strings::msg_params][strings::application] - [strings::ngn_media_screen_app_name] = *ngn_media_screen_name; - } - - message[strings::msg_params][strings::application][strings::icon] = - application_impl.app_icon_path(); - - std::string dev_name = ApplicationManagerImpl::instance()->GetDeviceName( - application_impl.device()); - message[strings::msg_params][strings::application][strings::device_name] = - dev_name; - - message[strings::msg_params][strings::application][strings::app_id] = - application_impl.app_id(); - - message[strings::msg_params][strings::application][strings::hmi_display_language_desired] = - static_cast<int32_t>(application_impl.ui_language()); - - message[strings::msg_params][strings::application][strings::is_media_application] = - application_impl.is_media_application(); - - const smart_objects::SmartObject* app_type = application_impl.app_types(); - - if (app_type) { - message[strings::msg_params][strings::application][strings::app_type] = - *app_type; - } - if (application_impl.vr_synonyms()) { - message[strings::msg_params][strings::vr_synonyms] = *(application_impl.vr_synonyms()); - } - if (application_impl.tts_name()) { - message[strings::msg_params][strings::tts_name] = *(application_impl.tts_name()); - } - DCHECK(ApplicationManagerImpl::instance()->ManageHMICommand(notification)); -} - -smart_objects::SmartObject* MessageHelper::CreateGeneralVrCommand() { - smart_objects::SmartObject* vr_help_command = new smart_objects::SmartObject( - smart_objects::SmartType_Array); - if (!vr_help_command) { - return NULL; - } - smart_objects::SmartObject& help_object = *vr_help_command; - const std::vector<std::string>& vr_general_cmds = profile::Profile::instance() - ->vr_commands(); - for (uint32_t i = 0; i < vr_general_cmds.size(); ++i) { - help_object[i] = vr_general_cmds[i]; - } - return vr_help_command; -} - -void MessageHelper::SendHelpVrCommand() { - smart_objects::SmartObject* vr_help_command = CreateGeneralVrCommand(); - if (!vr_help_command) { - return; - } - uint32_t max_cmd_id = profile::Profile::instance()->max_cmd_id(); - SendAddVRCommandToHMI(max_cmd_id + 1, *vr_help_command, 0); -} - -smart_objects::SmartObject* MessageHelper::GetHashUpdateNotification(const uint32_t app_id) { - - LOG4CXX_INFO(g_logger, "GetHashUpdateNotification" << app_id); - ApplicationSharedPtr app = ApplicationManagerImpl::instance()->application(app_id); - DCHECK(app.get()); - - smart_objects::SmartObject* message = new smart_objects::SmartObject( - smart_objects::SmartType_Map); - (*message)[strings::params][strings::function_id] = - mobile_apis::FunctionID::OnHashChangeID; - (*message)[strings::params][strings::connection_key] = app_id; - - return message; -} - -void MessageHelper::SendHashUpdateNotification(const uint32_t app_id) { - LOG4CXX_INFO(g_logger, "SendHashUpdateNotification"); - - smart_objects::SmartObject* so = GetHashUpdateNotification(app_id); - PrintSmartObject(*so); - DCHECK(ApplicationManagerImpl::instance()->ManageMobileCommand(so)); -} - -void MessageHelper::SendRemoveVrCommandsOnUnregisterApp(ApplicationConstSharedPtr app) { - uint32_t max_cmd_id = profile::Profile::instance()->max_cmd_id(); - - if (app->vr_synonyms()) { - SendRemoveCommandToHMI( - static_cast<int32_t>(hmi_apis::FunctionID::VR_DeleteCommand), - max_cmd_id + app->app_id(), app->app_id()); - } -} - -void MessageHelper::SendOnAppInterfaceUnregisteredNotificationToMobile( - int32_t connection_key, - mobile_api::AppInterfaceUnregisteredReason::eType reason) { - smart_objects::SmartObject* notification = new smart_objects::SmartObject; - if (!notification) { - // TODO(VS): please add logger. - return; - } - smart_objects::SmartObject& message = *notification; - - message[strings::params][strings::function_id] = - static_cast<int32_t>(mobile_api::FunctionID::OnAppInterfaceUnregisteredID); - - message[strings::params][strings::message_type] = - static_cast<int32_t>(kNotification); - - message[strings::params][strings::connection_key] = connection_key; - - message[strings::msg_params][strings::reason] = - static_cast<int32_t>(reason); - - DCHECK(ApplicationManagerImpl::instance()->ManageMobileCommand(notification)); -} - -const VehicleData& MessageHelper::vehicle_data() { - return vehicle_data_; -} - -smart_objects::SmartObject* MessageHelper::CreateBlockedByPoliciesResponse( - mobile_apis::FunctionID::eType function_id, - mobile_apis::Result::eType result, uint32_t correlation_id, - uint32_t connection_key) { - smart_objects::SmartObject* response = new smart_objects::SmartObject; - if (!response) { - return NULL; - } - - (*response)[strings::params][strings::function_id] = static_cast<int>(function_id); - (*response)[strings::params][strings::message_type] = static_cast<int>(kResponse); - (*response)[strings::msg_params][strings::success] = false; - (*response)[strings::msg_params][strings::result_code] = static_cast<int>(result); - (*response)[strings::params][strings::correlation_id] = correlation_id; - (*response)[strings::params][strings::connection_key] = connection_key; - (*response)[strings::params][strings::protocol_type] = - commands::CommandImpl::mobile_protocol_type_; - (*response)[strings::params][strings::protocol_version] = - static_cast<int>(kV2); - return response; -} - -smart_objects::SmartObject* MessageHelper::CreateDeviceListSO( - const connection_handler::DeviceList& devices) { - smart_objects::SmartObject* device_list_so = new smart_objects::SmartObject( - smart_objects::SmartType_Map); - - if (NULL == device_list_so) { - return NULL; - } - - (*device_list_so)[strings::device_list] = smart_objects::SmartObject( - smart_objects::SmartType_Array); - smart_objects::SmartObject& list_so = (*device_list_so)[strings::device_list]; - int32_t index = 0; - for (connection_handler::DeviceList::const_iterator it = devices.begin(); - devices.end() != it; ++it) { - const connection_handler::Device& d = static_cast<connection_handler::Device>(it->second); - list_so[index][strings::name] = - d.user_friendly_name(); - list_so[index][strings::id] = it->second.device_handle(); - ++index; - } - return device_list_so; -} - -smart_objects::SmartObject* MessageHelper::CreateModuleInfoSO( - uint32_t function_id) { - smart_objects::SmartObject* module_info = new smart_objects::SmartObject( - smart_objects::SmartType_Map); - if (NULL == module_info) { - return NULL; - } - smart_objects::SmartObject& object = *module_info; - object[strings::params][strings::message_type] = - static_cast<int>(kRequest); - object[strings::params][strings::function_id] = - static_cast<int>(function_id); - object[strings::params][strings::correlation_id] = - ApplicationManagerImpl::instance()->GetNextHMICorrelationID(); - object[strings::msg_params] = smart_objects::SmartObject( - smart_objects::SmartType_Map); - return module_info; -} - -smart_objects::SmartObject* MessageHelper::CreateSetAppIcon( - const std::string& path_to_icon, uint32_t app_id) { - smart_objects::SmartObject* set_icon = new smart_objects::SmartObject( - smart_objects::SmartType_Map); - - if (!set_icon) { - return NULL; - } - - smart_objects::SmartObject& object = *set_icon; - object[strings::sync_file_name][strings::value] = path_to_icon; - // TODO(PV): need to store actual image type - object[strings::sync_file_name][strings::image_type] = - static_cast<int>(mobile_api::ImageType::DYNAMIC); - object[strings::app_id] = app_id; - - return set_icon; -} - -bool MessageHelper::SendIVISubscribtions(const uint32_t app_id) { - LOG4CXX_INFO(g_logger, " MessageHelper::SendIVISubscribtions "); - - bool succes = true; - ApplicationSharedPtr app = ApplicationManagerImpl::instance()->application(app_id); - DCHECK(app.get()); - - SmartObjectList requests = GetIVISubscribtionRequests(app_id); - for (SmartObjectList::const_iterator it = requests.begin(); - it != requests.end(); ++it) { - if (!ApplicationManagerImpl::instance()->ManageHMICommand(*it)) { - succes = false; - } - } - return succes; -} - -MessageHelper::SmartObjectList MessageHelper::GetIVISubscribtionRequests(const uint32_t app_id) { - LOG4CXX_INFO(g_logger, " MessageHelper::GetIVISubscribtionRequests "); - - ApplicationSharedPtr app = ApplicationManagerImpl::instance()->application(app_id); - DCHECK(app); - - smart_objects::SmartObject msg_params = smart_objects::SmartObject( - smart_objects::SmartType_Map); - msg_params[strings::app_id] = app_id; - const VehicleData& vehicle_data = MessageHelper::vehicle_data_; - VehicleData::const_iterator ivi_it = vehicle_data.begin(); - const std::set<uint32_t>& subscribes = app->SubscribesIVI(); - - for (; vehicle_data.end() != ivi_it; ++ivi_it) { - uint32_t type_id = static_cast<int>(ivi_it->second); - if (subscribes.end() != subscribes.find(type_id)) { - std::string key_name = ivi_it->first; - msg_params[key_name] = true; - } - } - - SmartObjectList hmi_requests; -#ifdef WEB_HMI - smart_objects::SmartObject* request = MessageHelper::CreateModuleInfoSO( - hmi_apis::FunctionID::VehicleInfo_SubscribeVehicleData); - (*request)[strings::msg_params] = msg_params; - hmi_requests.push_back(request); -#endif // #ifdef WEB_HMI - -#ifdef QT_HMI - //Generate list of ivi_subrequests - for (int i = 0; i < sizeof(ivi_subrequests) / sizeof(ivi_subrequests[0]); ++i) { - const VehicleInfo_Requests& sr = ivi_subrequests[i]; - if (true == msg_params.keyExists(sr.str) - && true == msg_params[sr.str].asBool()) { - smart_objects::SmartObject* request = MessageHelper::CreateModuleInfoSO( - sr.func_id); - (*request)[strings::msg_params] = msg_params; - hmi_requests.push_back(request); - } - } -#endif // #ifdef QT_HMI - return hmi_requests; -} - -void MessageHelper::SendAppDataToHMI(ApplicationConstSharedPtr app) { - uint32_t id = app->app_id(); - - utils::SharedPtr<smart_objects::SmartObject> set_app_icon( - new smart_objects::SmartObject); - if (set_app_icon) { - smart_objects::SmartObject& so_to_send = *set_app_icon; - so_to_send[strings::params][strings::function_id] = - static_cast<int>(hmi_apis::FunctionID::UI_SetAppIcon); - so_to_send[strings::params][strings::message_type] = - static_cast<int>(hmi_apis::messageType::request); - so_to_send[strings::params][strings::protocol_version] = - commands::CommandImpl::protocol_version_; - so_to_send[strings::params][strings::protocol_type] = - commands::CommandImpl::hmi_protocol_type_; - so_to_send[strings::params][strings::correlation_id] = - ApplicationManagerImpl::instance()->GetNextHMICorrelationID(); - - so_to_send[strings::msg_params] = smart_objects::SmartObject( - smart_objects::SmartType_Map); - smart_objects::SmartObject* msg_params = MessageHelper::CreateSetAppIcon( - app->app_icon_path(), id); - - if (msg_params) { - so_to_send[strings::msg_params] = *msg_params; - } - // TODO(PV): appropriate handling of result - DCHECK(ApplicationManagerImpl::instance()->ManageHMICommand(set_app_icon)); - } - - SendGlobalPropertiesToHMI(app); - SendShowRequestToHMI(app); - SendAddCommandRequestToHMI(app); -} - -void MessageHelper::SendGlobalPropertiesToHMI(ApplicationConstSharedPtr app) { - DCHECK(app.get()); - - SmartObjectList requests = CreateGlobalPropertiesRequestsToHMI(app); - for (SmartObjectList::const_iterator it = requests.begin(); - it != requests.end(); ++it) { - DCHECK(ApplicationManagerImpl::instance()->ManageHMICommand(*it)) - } -} - -MessageHelper::SmartObjectList MessageHelper::CreateGlobalPropertiesRequestsToHMI(ApplicationConstSharedPtr app) { - - SmartObjectList requests; - DCHECK(app.get()); - - // UI global properties - - if (app->vr_help_title() || app->vr_help()) { - smart_objects::SmartObject* ui_global_properties = - new smart_objects::SmartObject(smart_objects::SmartType_Map); - - if (!ui_global_properties) { - return requests; - } - - (*ui_global_properties)[strings::params][strings::function_id] = - static_cast<int>(hmi_apis::FunctionID::UI_SetGlobalProperties); - (*ui_global_properties)[strings::params][strings::message_type] = - static_cast<int>(hmi_apis::messageType::request); - (*ui_global_properties)[strings::params][strings::protocol_version] = - commands::CommandImpl::protocol_version_; - (*ui_global_properties)[strings::params][strings::protocol_type] = - commands::CommandImpl::hmi_protocol_type_; - (*ui_global_properties)[strings::params][strings::correlation_id] = - ApplicationManagerImpl::instance()->GetNextHMICorrelationID(); - - smart_objects::SmartObject ui_msg_params = smart_objects::SmartObject( - smart_objects::SmartType_Map); - if (app->vr_help_title()) { - ui_msg_params[strings::vr_help_title] = (*app->vr_help_title()); - } - if (app->vr_help()) { - ui_msg_params[strings::vr_help] = (*app->vr_help()); - } - ui_msg_params[strings::app_id] = app->app_id(); - - (*ui_global_properties)[strings::msg_params] = ui_msg_params; - - requests.push_back(ui_global_properties); - } - - // TTS global properties - if (app->help_prompt() || app->timeout_prompt()) { - smart_objects::SmartObject* tts_global_properties = - new smart_objects::SmartObject(smart_objects::SmartType_Map); - - if (!tts_global_properties) { - return requests; - } - - (*tts_global_properties)[strings::params][strings::function_id] = - static_cast<int>(hmi_apis::FunctionID::TTS_SetGlobalProperties); - (*tts_global_properties)[strings::params][strings::message_type] = - static_cast<int>(hmi_apis::messageType::request); - (*tts_global_properties)[strings::params][strings::protocol_version] = - commands::CommandImpl::protocol_version_; - (*tts_global_properties)[strings::params][strings::protocol_type] = - commands::CommandImpl::hmi_protocol_type_; - (*tts_global_properties)[strings::params][strings::correlation_id] = - ApplicationManagerImpl::instance()->GetNextHMICorrelationID(); - - smart_objects::SmartObject tts_msg_params = smart_objects::SmartObject( - smart_objects::SmartType_Map); - if (app->help_prompt()) { - tts_msg_params[strings::help_prompt] = (*app->help_prompt()); - } - if (app->timeout_prompt()) { - tts_msg_params[strings::timeout_prompt] = (*app->timeout_prompt()); - } - tts_msg_params[strings::app_id] = app->app_id(); - - (*tts_global_properties)[strings::msg_params] = tts_msg_params; - - requests.push_back(tts_global_properties); - } - return requests; -} - -smart_objects::SmartObject* MessageHelper::CreateAppVrHelp(ApplicationConstSharedPtr app) { - smart_objects::SmartObject* result = new smart_objects::SmartObject( - smart_objects::SmartType_Map); - if (!result) { - return NULL; - } - smart_objects::SmartObject& vr_help = *result; - if (app->vr_help_title()) { - vr_help[strings::vr_help_title] = (*app->vr_help_title()); - } else { - vr_help[strings::vr_help_title] = app->name(); - } - - if (app->vr_help()) { - vr_help[strings::vr_help] = (*app->vr_help()); - } else { - const std::set<ApplicationSharedPtr>& apps = ApplicationManagerImpl::instance() - ->applications(); - - int32_t index = 0; - std::set<ApplicationSharedPtr>::const_iterator it_app = apps.begin(); - for (; apps.end() != it_app; ++it_app) { - if ((*it_app)->vr_synonyms()) { - smart_objects::SmartObject item(smart_objects::SmartType_Map); - item[strings::text] = (*((*it_app)->vr_synonyms())).getElement(0); - item[strings::position] = index + 1; - vr_help[strings::vr_help][index++] = item; - } - } - - // copy all app VR commands - const CommandsMap& commands = app->commands_map(); - CommandsMap::const_iterator it = commands.begin(); - - for (; commands.end() != it; ++it) { - smart_objects::SmartObject item(smart_objects::SmartType_Map); - item[strings::text] = - (*it->second)[strings::vr_commands][0].asString(); - item[strings::position] = index + 1; - vr_help[strings::vr_help][index++] = item; - } - } - return result; -} - -void MessageHelper::SendShowRequestToHMI(ApplicationConstSharedPtr app) { - if (!app) { - return; - } - - smart_objects::SmartObject* ui_show = new smart_objects::SmartObject( - smart_objects::SmartType_Map); - - if (!ui_show) { - return; - } - - if (app->show_command()) { - (*ui_show)[strings::params][strings::function_id] = - static_cast<int>(hmi_apis::FunctionID::UI_Show); - (*ui_show)[strings::params][strings::message_type] = - static_cast<int>(hmi_apis::messageType::request); - (*ui_show)[strings::params][strings::protocol_version] = - commands::CommandImpl::protocol_version_; - (*ui_show)[strings::params][strings::protocol_type] = - commands::CommandImpl::hmi_protocol_type_; - (*ui_show)[strings::params][strings::correlation_id] = - ApplicationManagerImpl::instance()->GetNextHMICorrelationID(); - (*ui_show)[strings::msg_params] = (*app->show_command()); - DCHECK(ApplicationManagerImpl::instance()->ManageHMICommand(ui_show)); - } -} - -void MessageHelper::SendShowConstantTBTRequestToHMI(ApplicationConstSharedPtr app) { - if (!app) { - return; - } - - smart_objects::SmartObject* navi_show_tbt = new smart_objects::SmartObject( - smart_objects::SmartType_Map); - - if (!navi_show_tbt) { - return; - } - - if (app->tbt_show_command()) { - (*navi_show_tbt)[strings::params][strings::function_id] = - static_cast<int>(hmi_apis::FunctionID::Navigation_ShowConstantTBT); - (*navi_show_tbt)[strings::params][strings::message_type] = - static_cast<int>(hmi_apis::messageType::request); - (*navi_show_tbt)[strings::params][strings::protocol_version] = - commands::CommandImpl::protocol_version_; - (*navi_show_tbt)[strings::params][strings::protocol_type] = - commands::CommandImpl::hmi_protocol_type_; - (*navi_show_tbt)[strings::params][strings::correlation_id] = - ApplicationManagerImpl::instance()->GetNextHMICorrelationID(); - (*navi_show_tbt)[strings::msg_params] = (*app->tbt_show_command()); - DCHECK(ApplicationManagerImpl::instance()->ManageHMICommand(navi_show_tbt)); - } -} - -void MessageHelper::SendAddCommandRequestToHMI(ApplicationConstSharedPtr app) { - if (!app) { - return; - } - SmartObjectList requests = CreateAddCommandRequestToHMI(app); - for (SmartObjectList::iterator it = requests.begin(); - it != requests.end(); ++it) { - DCHECK(ApplicationManagerImpl::instance()->ManageHMICommand(*it)); - } -} - -MessageHelper::SmartObjectList MessageHelper::CreateAddCommandRequestToHMI(ApplicationConstSharedPtr app) { - DCHECK(app.get()); - - SmartObjectList requests; - const CommandsMap& commands = app->commands_map(); - CommandsMap::const_iterator i = commands.begin(); - for (; commands.end() != i; ++i) { - // UI Interface - if ((*i->second).keyExists(strings::menu_params)) { - smart_objects::SmartObject* ui_command = new smart_objects::SmartObject( - smart_objects::SmartType_Map); - - if (!ui_command) { - return requests; - } - - (*ui_command)[strings::params][strings::function_id] = - static_cast<int>(hmi_apis::FunctionID::UI_AddCommand); - (*ui_command)[strings::params][strings::message_type] = - static_cast<int>(hmi_apis::messageType::request); - (*ui_command)[strings::params][strings::protocol_version] = - commands::CommandImpl::protocol_version_; - (*ui_command)[strings::params][strings::protocol_type] = - commands::CommandImpl::hmi_protocol_type_; - (*ui_command)[strings::params][strings::correlation_id] = - ApplicationManagerImpl::instance()->GetNextHMICorrelationID(); - - smart_objects::SmartObject msg_params = smart_objects::SmartObject( - smart_objects::SmartType_Map); - msg_params[strings::cmd_id] = i->first; - msg_params[strings::menu_params] = (*i->second)[strings::menu_params]; - msg_params[strings::app_id] = app->app_id(); - - if (((*i->second)[strings::cmd_icon].keyExists(strings::value)) - && (0 < (*i->second)[strings::cmd_icon][strings::value].length())) { - msg_params[strings::cmd_icon] = (*i->second)[strings::cmd_icon]; - msg_params[strings::cmd_icon][strings::value] = - (*i->second)[strings::cmd_icon][strings::value].asString(); - } - (*ui_command)[strings::msg_params] = msg_params; - requests.push_back(ui_command); - } - - // VR Interface - if ((*i->second).keyExists(strings::vr_commands)) { - SendAddVRCommandToHMI(i->first, (*i->second)[strings::vr_commands], - app->app_id()); - } - } - return requests; -} - -smart_objects::SmartObject* MessageHelper::CreateChangeRegistration( - int32_t function_id, int32_t language, uint32_t app_id) { - smart_objects::SmartObject* command = new smart_objects::SmartObject( - smart_objects::SmartType_Map); - if (!command) { - return NULL; - } - smart_objects::SmartObject& params = *command; - - params[strings::params][strings::message_type] = - static_cast<int>(hmi_apis::messageType::request); - params[strings::params][strings::protocol_version] = - commands::CommandImpl::protocol_version_; - params[strings::params][strings::protocol_type] = - commands::CommandImpl::hmi_protocol_type_; - - params[strings::params][strings::function_id] = function_id; - - params[strings::params][strings::correlation_id] = - ApplicationManagerImpl::instance()->GetNextHMICorrelationID(); - - smart_objects::SmartObject msg_params = smart_objects::SmartObject( - smart_objects::SmartType_Map); - msg_params[strings::language] = language; - msg_params[strings::app_id] = app_id; - - params[strings::msg_params] = msg_params; - return command; -} - -void MessageHelper::SendChangeRegistrationRequestToHMI(ApplicationConstSharedPtr app) { - hmi_apis::Common_Language::eType app_common_language = - ToCommonLanguage(app->language()); - const HMICapabilities& hmi_capabilities = - ApplicationManagerImpl::instance()->hmi_capabilities(); - if (mobile_apis::Language::INVALID_ENUM != app->language()) { - smart_objects::SmartObject* vr_command = CreateChangeRegistration( - hmi_apis::FunctionID::VR_ChangeRegistration, app->language(), - app->app_id()); - - if (vr_command) { - ApplicationManagerImpl::instance()->ManageHMICommand(vr_command); - } - } - - if (mobile_apis::Language::INVALID_ENUM != app->language()) { - smart_objects::SmartObject* tts_command = CreateChangeRegistration( - hmi_apis::FunctionID::TTS_ChangeRegistration, app->language(), - app->app_id()); - - if (tts_command) { - ApplicationManagerImpl::instance()->ManageHMICommand(tts_command); - } - } - - if (mobile_apis::Language::INVALID_ENUM != app->ui_language()) { - smart_objects::SmartObject* ui_command = CreateChangeRegistration( - hmi_apis::FunctionID::UI_ChangeRegistration, app->ui_language(), - app->app_id()); - - if (ui_command) { - ApplicationManagerImpl::instance()->ManageHMICommand(ui_command); - } - - } -} - -void MessageHelper::SendAddVRCommandToHMI( - uint32_t cmd_id, const smart_objects::SmartObject& vr_commands, - uint32_t app_id) { - smart_objects::SmartObject* request = CreateAddVRCommandToHMI(cmd_id, vr_commands, app_id); - DCHECK(ApplicationManagerImpl::instance()->ManageHMICommand(request)); -} - -smart_objects::SmartObject* MessageHelper::CreateAddVRCommandToHMI(uint32_t cmd_id, const NsSmartDeviceLink::NsSmartObjects::SmartObject &vr_commands, uint32_t app_id) { - smart_objects::SmartObject* vr_command = new smart_objects::SmartObject( - smart_objects::SmartType_Map); - - if (!vr_command) { - return NULL; - } - - (*vr_command)[strings::params][strings::function_id] = - hmi_apis::FunctionID::VR_AddCommand; - (*vr_command)[strings::params][strings::message_type] = - hmi_apis::messageType::request; - (*vr_command)[strings::params][strings::protocol_version] = - commands::CommandImpl::protocol_version_; - (*vr_command)[strings::params][strings::protocol_type] = - commands::CommandImpl::hmi_protocol_type_; - (*vr_command)[strings::params][strings::correlation_id] = - ApplicationManagerImpl::instance()->GetNextHMICorrelationID(); - - smart_objects::SmartObject msg_params = smart_objects::SmartObject( - smart_objects::SmartType_Map); - if (0 != cmd_id) { - msg_params[strings::cmd_id] = cmd_id; - } - msg_params[strings::vr_commands] = vr_commands; - if (0 < app_id) { - msg_params[strings::app_id] = app_id; - } - (*vr_command)[strings::msg_params] = msg_params; - - return vr_command; -} - -void MessageHelper::SendAddSubMenuRequestToHMI(ApplicationConstSharedPtr app) { - DCHECK(app.get()); - SmartObjectList requests = CreateAddSubMenuRequestToHMI(app); - for (SmartObjectList::iterator it = requests.begin(); - it != requests.end(); ++it) { - DCHECK(ApplicationManagerImpl::instance()->ManageHMICommand(*it)); - } -} - -MessageHelper::SmartObjectList MessageHelper::CreateAddSubMenuRequestToHMI(ApplicationConstSharedPtr app) { - SmartObjectList requsets; - const SubMenuMap& sub_menu = app->sub_menu_map(); - SubMenuMap::const_iterator i = sub_menu.begin(); - for (; sub_menu.end() != i; ++i) { - smart_objects::SmartObject* ui_sub_menu = new smart_objects::SmartObject( - smart_objects::SmartType_Map); - - if (!ui_sub_menu) { - return requsets; - } - - (*ui_sub_menu)[strings::params][strings::function_id] = - hmi_apis::FunctionID::UI_AddSubMenu; - (*ui_sub_menu)[strings::params][strings::message_type] = - hmi_apis::messageType::request; - (*ui_sub_menu)[strings::params][strings::protocol_version] = - commands::CommandImpl::protocol_version_; - (*ui_sub_menu)[strings::params][strings::protocol_type] = - commands::CommandImpl::hmi_protocol_type_; - (*ui_sub_menu)[strings::params][strings::correlation_id] = - ApplicationManagerImpl::instance()->GetNextHMICorrelationID(); - - smart_objects::SmartObject msg_params = smart_objects::SmartObject( - smart_objects::SmartType_Map); - - msg_params[strings::menu_id] = i->first; - msg_params[strings::menu_params][strings::position] = - (*i->second)[strings::position]; - msg_params[strings::menu_params][strings::menu_name] = - (*i->second)[strings::menu_name]; - msg_params[strings::app_id] = app->app_id(); - (*ui_sub_menu)[strings::msg_params] = msg_params; - requsets.push_back(ui_sub_menu); - } - return requsets; -} - -void MessageHelper::RemoveAppDataFromHMI(ApplicationSharedPtr app) { - SendDeleteCommandRequestToHMI(app); - SendDeleteSubMenuRequestToHMI(app); - SendRemoveVrCommandsOnUnregisterApp(app); - ResetGlobalproperties(app); -} - -void MessageHelper::SendOnSdlCloseNotificationToHMI() { - smart_objects::SmartObject* notification = new smart_objects::SmartObject( - smart_objects::SmartType_Map); - if (!notification) { - return; - } - smart_objects::SmartObject& message = *notification; - message[strings::params][strings::function_id] = - hmi_apis::FunctionID::BasicCommunication_OnSDLClose; - message[strings::params][strings::message_type] = MessageType::kNotification; - - ApplicationManagerImpl::instance()->ManageHMICommand(&message); -} - -void MessageHelper::SendOnAppUnregNotificationToHMI(ApplicationConstSharedPtr app) { - smart_objects::SmartObject* notification = new smart_objects::SmartObject( - smart_objects::SmartType_Map); - if (!notification) { - return; - } - - smart_objects::SmartObject& message = *notification; - - message[strings::params][strings::function_id] = - hmi_apis::FunctionID::BasicCommunication_OnAppUnregistered; - - message[strings::params][strings::message_type] = MessageType::kNotification; - message[strings::msg_params][strings::app_id] = app->app_id(); - - ApplicationManagerImpl::instance()->ManageHMICommand(&message); -} - -void MessageHelper::SendDeleteCommandRequestToHMI(ApplicationConstSharedPtr app) { - if (!app) { - return; - } - - const CommandsMap& commands = app->commands_map(); - CommandsMap::const_iterator i = commands.begin(); - for (; commands.end() != i; ++i) { - if ((*i->second).keyExists(strings::menu_params)) { - SendRemoveCommandToHMI( - static_cast<int32_t>(hmi_apis::FunctionID::UI_DeleteCommand), - i->first, app->app_id()); - } - - if ((*i->second).keyExists(strings::vr_commands)) { - SendRemoveCommandToHMI( - static_cast<int32_t>(hmi_apis::FunctionID::VR_DeleteCommand), - i->first, app->app_id()); - } - } -} - -void MessageHelper::SendRemoveCommandToHMI(int32_t function_id, int32_t command_id, - uint32_t app_id) { - smart_objects::SmartObject* delete_cmd = new smart_objects::SmartObject( - smart_objects::SmartType_Map); - - if (!delete_cmd) { - return; - } - - (*delete_cmd)[strings::params][strings::function_id] = function_id; - (*delete_cmd)[strings::params][strings::message_type] = - hmi_apis::messageType::request; - (*delete_cmd)[strings::params][strings::protocol_version] = - commands::CommandImpl::protocol_version_; - (*delete_cmd)[strings::params][strings::protocol_type] = - commands::CommandImpl::hmi_protocol_type_; - (*delete_cmd)[strings::params][strings::correlation_id] = - ApplicationManagerImpl::instance()->GetNextHMICorrelationID(); - - smart_objects::SmartObject msg_params = smart_objects::SmartObject( - smart_objects::SmartType_Map); - msg_params[strings::cmd_id] = command_id; - msg_params[strings::app_id] = app_id; - (*delete_cmd)[strings::msg_params] = msg_params; - ApplicationManagerImpl::instance()->ManageHMICommand(delete_cmd); -} - -void MessageHelper::SendDeleteSubMenuRequestToHMI(ApplicationConstSharedPtr app) { - if (!app) { - return; - } - - const SubMenuMap& sub_menu = app->sub_menu_map(); - SubMenuMap::const_iterator i = sub_menu.begin(); - for (; sub_menu.end() != i; ++i) { - smart_objects::SmartObject* delete_sub_menu = - new smart_objects::SmartObject(smart_objects::SmartType_Map); - - if (!delete_sub_menu) { - return; - } - - (*delete_sub_menu)[strings::params][strings::function_id] = - hmi_apis::FunctionID::UI_DeleteSubMenu; - (*delete_sub_menu)[strings::params][strings::message_type] = - hmi_apis::messageType::request; - (*delete_sub_menu)[strings::params][strings::protocol_version] = - commands::CommandImpl::protocol_version_; - (*delete_sub_menu)[strings::params][strings::protocol_type] = - commands::CommandImpl::hmi_protocol_type_; - (*delete_sub_menu)[strings::params][strings::correlation_id] = - ApplicationManagerImpl::instance()->GetNextHMICorrelationID(); - - smart_objects::SmartObject msg_params = smart_objects::SmartObject( - smart_objects::SmartType_Map); - - msg_params[strings::menu_id] = i->first; - msg_params[strings::menu_params][strings::position] = - (*i->second)[strings::position]; - msg_params[strings::menu_params][strings::menu_name] = - (*i->second)[strings::menu_name]; - msg_params[strings::app_id] = app->app_id(); - (*delete_sub_menu)[strings::msg_params] = msg_params; - - ApplicationManagerImpl::instance()->ManageHMICommand(delete_sub_menu); - } -} - -void MessageHelper::SendActivateAppToHMI(uint32_t const app_id) { - smart_objects::SmartObject* message = new smart_objects::SmartObject( - smart_objects::SmartType_Map); - if (!message) { - return; - } - - (*message)[strings::params][strings::function_id] = - hmi_apis::FunctionID::BasicCommunication_ActivateApp; - (*message)[strings::params][strings::message_type] = MessageType::kRequest; - (*message)[strings::params][strings::correlation_id] = - ApplicationManagerImpl::instance()->GetNextHMICorrelationID(); - (*message)[strings::msg_params][strings::app_id] = app_id; - - ApplicationManagerImpl::instance()->ManageHMICommand(message); -} - -smart_objects::SmartObject* MessageHelper::CreateNegativeResponse( - uint32_t connection_key, int32_t function_id, uint32_t correlation_id, - int32_t result_code) { - smart_objects::SmartObject* response = new smart_objects::SmartObject( - smart_objects::SmartType_Map); - smart_objects::SmartObject& response_data = *response; - response_data[strings::params][strings::function_id] = function_id; - response_data[strings::params][strings::message_type] = - mobile_apis::messageType::response; - response_data[strings::params][strings::correlation_id] = correlation_id; - response_data[strings::params][strings::protocol_type] = - commands::CommandImpl::mobile_protocol_type_; - response_data[strings::params][strings::protocol_version] = - commands::CommandImpl::protocol_version_; - response_data[strings::msg_params][strings::result_code] = result_code; - response_data[strings::msg_params][strings::success] = false; - response_data[strings::params][strings::connection_key] = connection_key; - - return response; -} - -void MessageHelper::ResetGlobalproperties(ApplicationSharedPtr app) { - // reset help_prompt - const std::vector<std::string>& help_prompt = profile::Profile::instance() - ->help_prompt(); - - smart_objects::SmartObject so_help_prompt = smart_objects::SmartObject( - smart_objects::SmartType_Array); - - for (uint32_t i = 0; i < help_prompt.size(); ++i) { - smart_objects::SmartObject helpPrompt = smart_objects::SmartObject( - smart_objects::SmartType_Map); - helpPrompt[strings::text] = help_prompt[i]; - so_help_prompt[i] = helpPrompt; - } - - app->set_help_prompt(so_help_prompt); - - // reset timeout prompt - const std::vector<std::string>& time_out_promt = profile::Profile::instance() - ->time_out_promt(); - - smart_objects::SmartObject so_time_out_promt = smart_objects::SmartObject( - smart_objects::SmartType_Array); - - for (uint32_t i = 0; i < time_out_promt.size(); ++i) { - smart_objects::SmartObject timeoutPrompt = smart_objects::SmartObject( - smart_objects::SmartType_Map); - timeoutPrompt[strings::text] = time_out_promt[i]; - so_time_out_promt[i] = timeoutPrompt; - } - - app->set_timeout_prompt(so_time_out_promt); - - // reset VR help title - smart_objects::SmartObject help_title(app->name()); - app->set_vr_help_title(help_title); - - // reset VR help items - const CommandsMap& cmdMap = app->commands_map(); - smart_objects::SmartObject vr_help_items; - - int32_t index = 0; - CommandsMap::const_iterator command_it = cmdMap.begin(); - - for (; cmdMap.end() != command_it; ++command_it) { - if (true == (*command_it->second).keyExists(strings::vr_commands)) { - // use only first - vr_help_items[index][strings::position] = (index + 1); - vr_help_items[index++][strings::text] = - (*command_it->second)[strings::vr_commands][0]; - } - } - - app->set_vr_help(vr_help_items); - - // send global properties - SendGlobalPropertiesToHMI(app); -} - -void MessageHelper::SendNaviStartStream( - const std::string& url, int32_t connection_key) { - LOG4CXX_INFO(g_logger, "MessageHelper::SendNaviStartStream"); - smart_objects::SmartObject* start_stream = - new smart_objects::SmartObject(smart_objects::SmartType_Map); - - if (!start_stream) { - return; - } - - (*start_stream)[strings::params][strings::function_id] = - hmi_apis::FunctionID::Navigation_StartStream; - (*start_stream)[strings::params][strings::message_type] = - hmi_apis::messageType::request; - (*start_stream)[strings::params][strings::protocol_version] = - commands::CommandImpl::protocol_version_; - (*start_stream)[strings::params][strings::protocol_type] = - commands::CommandImpl::hmi_protocol_type_; - (*start_stream)[strings::params][strings::correlation_id] = - ApplicationManagerImpl::instance()->GetNextHMICorrelationID(); - - smart_objects::SmartObject msg_params = - smart_objects::SmartObject(smart_objects::SmartType_Map); - - uint32_t app_id = 0; - connection_handler::ConnectionHandlerImpl::instance()->GetDataOnSessionKey( - connection_key, - &app_id); - - msg_params[strings::app_id] = app_id; - msg_params[strings::url] = url; - - (*start_stream)[strings::msg_params] = msg_params; - - ApplicationManagerImpl::instance()->ManageHMICommand(start_stream); -} - -void MessageHelper::SendNaviStopStream(int32_t connection_key) { - smart_objects::SmartObject* stop_stream = - new smart_objects::SmartObject(smart_objects::SmartType_Map); - - if (!stop_stream) { - return; - } - - (*stop_stream)[strings::params][strings::function_id] = - hmi_apis::FunctionID::Navigation_StopStream; - (*stop_stream)[strings::params][strings::message_type] = - hmi_apis::messageType::request; - (*stop_stream)[strings::params][strings::protocol_version] = - commands::CommandImpl::protocol_version_; - (*stop_stream)[strings::params][strings::protocol_type] = - commands::CommandImpl::hmi_protocol_type_; - (*stop_stream)[strings::params][strings::correlation_id] = - ApplicationManagerImpl::instance()->GetNextHMICorrelationID(); - - smart_objects::SmartObject msg_params = - smart_objects::SmartObject(smart_objects::SmartType_Map); - - uint32_t app_id = 0; - connection_handler::ConnectionHandlerImpl::instance()->GetDataOnSessionKey( - connection_key, - &app_id); - - msg_params[strings::app_id] = app_id; - - (*stop_stream)[strings::msg_params] = msg_params; - - ApplicationManagerImpl::instance()->ManageHMICommand(stop_stream); -} - -void MessageHelper::SendAudioStartStream( - const std::string& url, int32_t connection_key) { - - smart_objects::SmartObject* start_stream = - new smart_objects::SmartObject(smart_objects::SmartType_Map); - - if (!start_stream) { - return; - } - - (*start_stream)[strings::params][strings::function_id] = - hmi_apis::FunctionID::Navigation_StartAudioStream; - (*start_stream)[strings::params][strings::message_type] = - hmi_apis::messageType::request; - (*start_stream)[strings::params][strings::protocol_version] = - commands::CommandImpl::protocol_version_; - (*start_stream)[strings::params][strings::protocol_type] = - commands::CommandImpl::hmi_protocol_type_; - (*start_stream)[strings::params][strings::correlation_id] = - ApplicationManagerImpl::instance()->GetNextHMICorrelationID(); - - smart_objects::SmartObject msg_params = - smart_objects::SmartObject(smart_objects::SmartType_Map); - - uint32_t app_id = 0; - connection_handler::ConnectionHandlerImpl::instance()->GetDataOnSessionKey( - connection_key, - &app_id); - - msg_params[strings::app_id] = app_id; - msg_params[strings::url] = url; - - (*start_stream)[strings::msg_params] = msg_params; - - DCHECK(ApplicationManagerImpl::instance()->ManageHMICommand(start_stream)); -} - -void MessageHelper::SendAudioStopStream(int32_t connection_key) { - smart_objects::SmartObject* stop_stream = - new smart_objects::SmartObject(smart_objects::SmartType_Map); - - if (!stop_stream) { - return; - } - - (*stop_stream)[strings::params][strings::function_id] = - hmi_apis::FunctionID::Navigation_StopAudioStream; - (*stop_stream)[strings::params][strings::message_type] = - hmi_apis::messageType::request; - (*stop_stream)[strings::params][strings::protocol_version] = - commands::CommandImpl::protocol_version_; - (*stop_stream)[strings::params][strings::protocol_type] = - commands::CommandImpl::hmi_protocol_type_; - (*stop_stream)[strings::params][strings::correlation_id] = - ApplicationManagerImpl::instance()->GetNextHMICorrelationID(); - - smart_objects::SmartObject msg_params = - smart_objects::SmartObject(smart_objects::SmartType_Map); - - uint32_t app_id = 0; - connection_handler::ConnectionHandlerImpl::instance()->GetDataOnSessionKey( - connection_key, - &app_id); - - msg_params[strings::app_id] = app_id; - - (*stop_stream)[strings::msg_params] = msg_params; - - ApplicationManagerImpl::instance()->ManageHMICommand(stop_stream); -} - -bool MessageHelper::SendStopAudioPathThru() { - LOG4CXX_INFO(g_logger,"MessageHelper::SendAudioStopAudioPathThru"); - - NsSmartDeviceLink::NsSmartObjects::SmartObject* result = - new NsSmartDeviceLink::NsSmartObjects::SmartObject; - const uint32_t hmi_correlation_id = ApplicationManagerImpl::instance()-> - GetNextHMICorrelationID(); - NsSmartDeviceLink::NsSmartObjects::SmartObject& request = *result; - request[strings::params][strings::message_type] = MessageType::kRequest; - request[strings::params][strings::function_id] = hmi_apis::FunctionID::UI_EndAudioPassThru; - request[strings::params][strings::correlation_id] = hmi_correlation_id; - request[strings::params][strings::protocol_version] = - commands::CommandImpl::protocol_version_; - request[strings::params][strings::protocol_type] = - commands::CommandImpl::hmi_protocol_type_; - return ApplicationManagerImpl::instance()->ManageHMICommand(result); -} - -mobile_apis::Result::eType MessageHelper::VerifyImageFiles( - smart_objects::SmartObject& message, ApplicationConstSharedPtr app) { - if (NsSmartDeviceLink::NsSmartObjects::SmartType_Array == message.getType()) { - for (int32_t i = 0; i < message.length(); ++i) { - mobile_apis::Result::eType res = VerifyImageFiles(message[i], app); - if (mobile_apis::Result::SUCCESS != res) { - return res; - } - } - } else if (NsSmartDeviceLink::NsSmartObjects::SmartType_Map - == message.getType()) { - if (message.keyExists(strings::image_type)) { - mobile_apis::Result::eType verification_result = - VerifyImage(message, app); - - if (mobile_apis::Result::SUCCESS != verification_result) { - return verification_result; // exit point - } - } else { - std::set < std::string > keys = message.enumerate(); - - for (std::set<std::string>::const_iterator key = keys.begin(); - key != keys.end(); ++key) { - if (strings::soft_buttons != (*key)) { - mobile_apis::Result::eType res = VerifyImageFiles(message[*key], app); - if (mobile_apis::Result::SUCCESS != res) { - return res; - } - } - } - } - } // all other types shoudn't be processed - - return mobile_apis::Result::SUCCESS; -} - -mobile_apis::Result::eType MessageHelper::VerifyImage( - smart_objects::SmartObject& image, ApplicationConstSharedPtr app) { - const std::string& file_name = image[strings::value].asString(); - - std::string str = file_name; - str.erase(remove(str.begin(), str.end(), ' '), str.end()); - if (0 == str.size()) { - return mobile_apis::Result::INVALID_DATA; - } - - std::string relative_file_path = app->name(); - relative_file_path += "/"; - relative_file_path += file_name; - - std::string full_file_path = file_system::FullPath(relative_file_path); - - if (!file_system::FileExists(full_file_path)) { - return mobile_apis::Result::INVALID_DATA; - } - - const HMICapabilities& hmi_capabilities = - ApplicationManagerImpl::instance()->hmi_capabilities(); - if (!hmi_capabilities.VerifyImageType( - static_cast<mobile_apis::ImageType::eType>(image[strings::image_type] - .asInt()))) { - return mobile_apis::Result::UNSUPPORTED_RESOURCE; - } - - image[strings::value] = full_file_path; - - return mobile_apis::Result::SUCCESS; -} - -bool MessageHelper::VerifySoftButtonText -(smart_objects::SmartObject& soft_button) { - std::string text = soft_button[strings::text].asString(); - text.erase(remove(text.begin(), text.end(), ' '), text.end()); - text.erase(remove(text.begin(), text.end(), '\n'), text.end()); - if (text.size()) { - return true; - } else { - soft_button.erase(strings::text); - } - - return false; -} - -mobile_apis::Result::eType MessageHelper::ProcessSoftButtons( - smart_objects::SmartObject& message_params, ApplicationConstSharedPtr app) { - if (!message_params.keyExists(strings::soft_buttons)) { - return mobile_apis::Result::SUCCESS; - } - - const HMICapabilities& hmi_capabilities = - ApplicationManagerImpl::instance()->hmi_capabilities(); - const smart_objects::SmartObject* soft_button_capabilities = - hmi_capabilities.soft_button_capabilities(); - bool image_supported = false; - if (soft_button_capabilities) { - image_supported = - (*soft_button_capabilities)[hmi_response::image_supported].asBool(); - } - - smart_objects::SmartObject& request_soft_buttons = - message_params[strings::soft_buttons]; - - // Check whether soft buttons request is well-formed - if (!ValidateSoftButtons(request_soft_buttons)) - return mobile_apis::Result::INVALID_DATA; - - smart_objects::SmartObject soft_buttons = smart_objects::SmartObject( - smart_objects::SmartType_Array); - bool flag_unsuported_resource = false; - - int32_t j = 0; - for (int32_t i = 0; i < request_soft_buttons.length(); ++i) { - switch (request_soft_buttons[i][strings::type].asInt()) { - case mobile_apis::SoftButtonType::SBT_IMAGE: { - if (!image_supported) { - continue; - } - - if (request_soft_buttons[i].keyExists(strings::image)) { - mobile_apis::Result::eType verification_result = VerifyImage( - request_soft_buttons[i][strings::image], app); - - if (mobile_apis::Result::SUCCESS != verification_result) { - if (mobile_apis::Result::UNSUPPORTED_RESOURCE == - verification_result) { - request_soft_buttons[i].erase(strings::image); - flag_unsuported_resource = true; - } else { - return mobile_apis::Result::INVALID_DATA; - } - } - } else { - return mobile_apis::Result::INVALID_DATA; - } - break; - } - case mobile_apis::SoftButtonType::SBT_TEXT: { - if (!request_soft_buttons[i].keyExists(strings::text)) { - return mobile_apis::Result::INVALID_DATA; - } - - if (!VerifySoftButtonText(request_soft_buttons[i])) { - continue; - } - break; - } - case mobile_apis::SoftButtonType::SBT_BOTH: { - - if (request_soft_buttons[i].keyExists(strings::text)) { - VerifySoftButtonText(request_soft_buttons[i]); - } else { - return mobile_apis::Result::INVALID_DATA; - } - - bool image_exist = false; - if (image_supported) { - image_exist = request_soft_buttons[i].keyExists(strings::image); - if (!image_exist) { - return mobile_apis::Result::INVALID_DATA; - } - } - if (image_exist) { - mobile_apis::Result::eType verification_result = VerifyImage( - request_soft_buttons[i][strings::image], app); - - if (mobile_apis::Result::SUCCESS != verification_result) { - if (mobile_apis::Result::UNSUPPORTED_RESOURCE == - verification_result) { - request_soft_buttons[i].erase(strings::image); - flag_unsuported_resource = true; - } else { - return mobile_apis::Result::INVALID_DATA; - } - } - } - break; - } - default: { - continue; - break; - } - } - - soft_buttons[j] = request_soft_buttons[i]; - - if (!soft_buttons[j].keyExists(strings::system_action)) { - soft_buttons[j][strings::system_action] = - mobile_apis::SystemAction::DEFAULT_ACTION; - } - - ++j; - } - - request_soft_buttons = soft_buttons; - - if (0 == request_soft_buttons.length()) { - message_params.erase(strings::soft_buttons); - } - if (flag_unsuported_resource) { - return mobile_apis::Result::UNSUPPORTED_RESOURCE; - } else { - return mobile_apis::Result::SUCCESS; - } -} - -// TODO(AK): change printf to logger -bool MessageHelper::PrintSmartObject(const smart_objects::SmartObject& object) { - static uint32_t tab = 0; - std::string tab_buffer; - - if (tab == 0) { - printf("\n-------------------------------------------------------------"); - } - - for (uint32_t i = 0; i < tab; ++i) { - tab_buffer += "\t"; - } - - switch (object.getType()) { - case NsSmartDeviceLink::NsSmartObjects::SmartType_Array: { - for (size_t i = 0; i < object.length(); i++) { - ++tab; - - printf("\n%s%d: ", tab_buffer.c_str(), i); - if (!PrintSmartObject(object.getElement(i))) { - printf("\n"); - return false; - } - } - break; - } - case NsSmartDeviceLink::NsSmartObjects::SmartType_Map: { - std::set < std::string > keys = object.enumerate(); - - for (std::set<std::string>::const_iterator key = keys.begin(); - key != keys.end(); key++) { - ++tab; - - printf("\n%s%s: ", tab_buffer.c_str(), (*key).c_str()); - if (!PrintSmartObject(object[(*key).c_str()])) { - printf("\n"); - return false; - } - } - break; - } - case NsSmartDeviceLink::NsSmartObjects::SmartType_Boolean: - object.asBool() ? printf("true\n") : printf("false\n"); - break; - case NsSmartDeviceLink::NsSmartObjects::SmartType_Double: { - printf("%f", object.asDouble()); - break; - } - case NsSmartDeviceLink::NsSmartObjects::SmartType_Integer: - printf("%d", object.asInt()); - break; - case NsSmartDeviceLink::NsSmartObjects::SmartType_String: - printf("%s", object.asString().c_str()); - break; - case NsSmartDeviceLink::NsSmartObjects::SmartType_Character: - printf("%c", object.asChar()); - break; - default: - printf("PrintSmartObject - default case\n"); - break; - } - - if (0 != tab) { - --tab; - } else { - printf("\n-------------------------------------------------------------\n"); - } - - return true; -} - -} // namespace application_manager |