diff options
author | Artem Nosach <ANosach@luxoft.com> | 2015-04-17 17:46:56 +0300 |
---|---|---|
committer | Artem Nosach <ANosach@luxoft.com> | 2015-04-23 15:33:15 +0300 |
commit | 81208d859b07241abe8706d51eccbb74db72140b (patch) | |
tree | b5a5d6be8d014229d419ca1dc65d54b5ef9de341 | |
parent | 6750a2c7de94e01949d79c9cd0d4bfbbb88df772 (diff) | |
download | sdl_core-81208d859b07241abe8706d51eccbb74db72140b.tar.gz |
Add CheckHMICapabilities() to SubscribeButton request.
2 files changed, 44 insertions, 0 deletions
diff --git a/src/components/application_manager/include/application_manager/commands/mobile/subscribe_button_request.h b/src/components/application_manager/include/application_manager/commands/mobile/subscribe_button_request.h index fbab967d24..12168e2473 100644 --- a/src/components/application_manager/include/application_manager/commands/mobile/subscribe_button_request.h +++ b/src/components/application_manager/include/application_manager/commands/mobile/subscribe_button_request.h @@ -85,6 +85,12 @@ class SubscribeButtonRequest : public CommandRequestImpl { */ void SendSubscribeButtonNotification(); + /** + * @brief Checks HMI capabilities for specified button support + * @param button Button to check + */ + bool CheckHMICapabilities(mobile_apis::ButtonName::eType button); + DISALLOW_COPY_AND_ASSIGN(SubscribeButtonRequest); }; diff --git a/src/components/application_manager/src/commands/mobile/subscribe_button_request.cc b/src/components/application_manager/src/commands/mobile/subscribe_button_request.cc index 64ef9f7a17..ece7c8332e 100644 --- a/src/components/application_manager/src/commands/mobile/subscribe_button_request.cc +++ b/src/components/application_manager/src/commands/mobile/subscribe_button_request.cc @@ -70,6 +70,13 @@ void SubscribeButtonRequest::Run() { return; } + if (!CheckHMICapabilities(btn_id)) { + LOG4CXX_ERROR_EXT(logger_, "Subscribe on button " << btn_id + << " isn't allowed by HMI capabilities"); + SendResponse(false, mobile_apis::Result::UNSUPPORTED_RESOURCE); + return; + } + if (app->IsSubscribedToButton(btn_id)) { LOG4CXX_ERROR_EXT(logger_, "Already subscribed to button " << btn_id); SendResponse(false, mobile_apis::Result::IGNORED); @@ -97,6 +104,37 @@ bool SubscribeButtonRequest::IsSubscriptionAllowed( return true; } +bool SubscribeButtonRequest::CheckHMICapabilities( + mobile_apis::ButtonName::eType button) { + using namespace smart_objects; + using namespace mobile_apis; + LOG4CXX_AUTO_TRACE(logger_); + + ApplicationManagerImpl* app_mgr = ApplicationManagerImpl::instance(); + DCHECK_OR_RETURN(app_mgr, false); + + const HMICapabilities& hmi_caps = app_mgr->hmi_capabilities(); + if (!hmi_caps.is_ui_cooperating()) { + LOG4CXX_ERROR_EXT(logger_, "UI is not supported by HMI."); + return false; + } + + const SmartObject* button_caps_ptr = hmi_caps.button_capabilities(); + if (button_caps_ptr) { + const SmartObject& button_caps = *button_caps_ptr; + const size_t length = button_caps.length(); + for (size_t i = 0; i < length; ++i) { + const SmartObject& caps = button_caps[i]; + const ButtonName::eType name = + static_cast<ButtonName::eType>(caps.getElement(hmi_response::button_name).asInt()); + if (name == button) { + return true; + } + } + } + return false; +} + void SubscribeButtonRequest::SendSubscribeButtonNotification() { using namespace smart_objects; using namespace hmi_apis; |