diff options
Diffstat (limited to 'src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/on_button_press_notification.cc')
-rw-r--r-- | src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/on_button_press_notification.cc | 153 |
1 files changed, 11 insertions, 142 deletions
diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/on_button_press_notification.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/on_button_press_notification.cc index 4444f0d156..90bf618c35 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/on_button_press_notification.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/on_button_press_notification.cc @@ -34,6 +34,7 @@ #include "sdl_rpc_plugin/commands/mobile/on_button_press_notification.h" #include "application_manager/application_impl.h" +#include "application_manager/message_helper.h" #include "interfaces/MOBILE_API.h" #include "utils/semantic_version.h" @@ -52,155 +53,23 @@ OnButtonPressNotification::OnButtonPressNotification( rpc_service::RPCService& rpc_service, HMICapabilities& hmi_capabilities, policy::PolicyHandlerInterface& policy_handler) - : CommandNotificationImpl(message, - application_manager, - rpc_service, - hmi_capabilities, - policy_handler) {} + : ButtonNotificationToMobile(message, + application_manager, + rpc_service, + hmi_capabilities, + policy_handler) {} OnButtonPressNotification::~OnButtonPressNotification() {} -void OnButtonPressNotification::Run() { +void OnButtonPressNotification::SendButtonNotification( + ApplicationSharedPtr app) { SDL_LOG_AUTO_TRACE(); - const uint32_t btn_id = static_cast<uint32_t>( - (*message_)[strings::msg_params][hmi_response::button_name].asInt()); - - const bool is_app_id_exists = - (*message_)[strings::msg_params].keyExists(strings::app_id); - ApplicationSharedPtr app; - if (is_app_id_exists) { - app = application_manager_.application( - (*message_)[strings::msg_params][strings::app_id].asUInt()); - } - - // CUSTOM_BUTTON notification - if (static_cast<uint32_t>(mobile_apis::ButtonName::CUSTOM_BUTTON) == btn_id) { - // app_id is mandatory for CUSTOM_BUTTON notification - if (!is_app_id_exists) { - SDL_LOG_ERROR("CUSTOM_BUTTON OnButtonPress without app_id."); - return; - } - - // custom_button_id is mandatory for CUSTOM_BUTTON notification - if (false == (*message_)[strings::msg_params].keyExists( - hmi_response::custom_button_id)) { - SDL_LOG_ERROR("CUSTOM_BUTTON OnButtonPress without custom_button_id."); - return; - } - - if (!app) { - SDL_LOG_ERROR("Application doesn't exist."); - return; - } - - uint32_t custom_btn_id = 0; - custom_btn_id = - (*message_)[strings::msg_params][hmi_response::custom_button_id] - .asUInt(); - - if (false == app->IsSubscribedToSoftButton(custom_btn_id)) { - SDL_LOG_ERROR("Application doesn't subscribed to this custom_button_id."); - return; - } - - // Send ButtonPress notification only in HMI_FULL or HMI_LIMITED mode - const auto window_id = app->GetSoftButtonWindowID(custom_btn_id); - app->hmi_level(mobile_apis::PredefinedWindows::DEFAULT_WINDOW); - (*message_)[strings::msg_params][strings::window_id] = window_id; - const auto window_hmi_level = app->hmi_level(window_id); - if ((mobile_api::HMILevel::HMI_NONE == window_hmi_level)) { - SDL_LOG_WARN( - "CUSTOM_BUTTON OnButtonPress notification is not allowed in " - "NONE hmi level"); - return; - } - - SendButtonPress(app); - return; - } - - const std::vector<ApplicationSharedPtr>& subscribed_apps = - application_manager_.applications_by_button(btn_id); - - std::vector<ApplicationSharedPtr>::const_iterator it = - subscribed_apps.begin(); - for (; subscribed_apps.end() != it; ++it) { - ApplicationSharedPtr subscribed_app = *it; - if (!subscribed_app) { - SDL_LOG_WARN("Null pointer to subscribed app."); - continue; - } - - // Send ButtonPress notification only in HMI_FULL or HMI_LIMITED mode - const mobile_apis::HMILevel::eType app_hmi_level = - subscribed_app->hmi_level( - mobile_apis::PredefinedWindows::DEFAULT_WINDOW); - if ((mobile_api::HMILevel::HMI_FULL != app_hmi_level) && - (mobile_api::HMILevel::HMI_LIMITED != app_hmi_level)) { - SDL_LOG_WARN("OnButtonPress notification is allowed only " - << "in FULL or LIMITED hmi level"); - continue; - } - // if "appID" is present, send it to named app only if its FULL or - // LIMITED - if (app.use_count() != 0) { - if (app->app_id() == subscribed_app->app_id()) { - SendButtonPress(subscribed_app); - } - } else if (hmi_apis::Common_ButtonName::OK != btn_id || - subscribed_app->IsFullscreen()) { - // if No "appID" and OK button - send it FULL apps only. - // if not OK button, send to LIMITED subscribed apps - SendButtonPress(subscribed_app); - } - } -} - -void OnButtonPressNotification::SendButtonPress(ApplicationConstSharedPtr app) { - if (!app) { - SDL_LOG_ERROR("OnButtonPress NULL pointer"); - return; - } - - smart_objects::SmartObjectSPtr on_btn_press = - std::make_shared<smart_objects::SmartObject>(); - - if (!on_btn_press) { - SDL_LOG_ERROR("OnButtonPress NULL pointer"); - return; - } - - (*on_btn_press)[strings::params][strings::connection_key] = app->app_id(); - - (*on_btn_press)[strings::params][strings::function_id] = - static_cast<int32_t>(mobile_apis::FunctionID::eType::OnButtonPressID); - - mobile_apis::ButtonName::eType btn_id = - static_cast<mobile_apis::ButtonName::eType>( - (*message_)[strings::msg_params][hmi_response::button_name].asInt()); - - if (btn_id == mobile_apis::ButtonName::PLAY_PAUSE && - app->msg_version() < utils::rpc_version_5) { - btn_id = mobile_apis::ButtonName::OK; - } - - (*on_btn_press)[strings::msg_params][strings::button_name] = btn_id; - (*on_btn_press)[strings::msg_params][strings::button_press_mode] = - (*message_)[strings::msg_params][hmi_response::button_mode]; - - if ((*message_)[strings::msg_params].keyExists( - hmi_response::custom_button_id)) { - (*on_btn_press)[strings::msg_params][strings::custom_button_id] = - (*message_)[strings::msg_params][strings::custom_button_id]; - } + (*message_)[strings::params][strings::function_id] = + mobile_apis::FunctionID::eType::OnButtonPressID; - if ((*message_)[strings::msg_params].keyExists(strings::window_id)) { - (*on_btn_press)[strings::msg_params][strings::window_id] = - (*message_)[strings::msg_params][strings::window_id]; - } + message_ = MessageHelper::CreateButtonNotificationToMobile(app, *message_); - message_ = on_btn_press; SendNotification(); } |