Skip to content

Commit

Permalink
Return on_event() back to HMI subscription request
Browse files Browse the repository at this point in the history
  • Loading branch information
AKalinich-Luxoft committed Jul 16, 2021
1 parent d156a9f commit 82703c9
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ namespace hmi {
/**
* @brief SubscribeButtonRequest command class
**/
class SubscribeButtonRequest : public app_mngr::commands::RequestToHMI {
class SubscribeButtonRequest : public app_mngr::commands::RequestToHMI,
public app_mngr::event_engine::EventObserver {
public:
/**
* @brief SubscribeButtonRequest class constructor
Expand All @@ -69,6 +70,8 @@ class SubscribeButtonRequest : public app_mngr::commands::RequestToHMI {

void onTimeOut() OVERRIDE;

void on_event(const application_manager::event_engine::Event& event) OVERRIDE;

private:
DISALLOW_COPY_AND_ASSIGN(SubscribeButtonRequest);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ SubscribeButtonRequest::SubscribeButtonRequest(
application_manager,
rpc_service,
hmi_capabilities,
policy_handle) {
policy_handle)
, EventObserver(application_manager.event_dispatcher()) {
hmi_apis::Common_ButtonName::eType button_name =
static_cast<hmi_apis::Common_ButtonName::eType>(
(*message_)[app_mngr::strings::msg_params]
Expand All @@ -68,9 +69,56 @@ SubscribeButtonRequest::~SubscribeButtonRequest() {}
void SubscribeButtonRequest::Run() {
SDL_LOG_AUTO_TRACE();

const auto btn_id = static_cast<mobile_apis::ButtonName::eType>(
(*message_)[strings::msg_params][strings::button_name].asInt());

// Specific case when app subscribes to CUSTOM_BUTTON upon registration and no
// explicit mobile request exist when response arrives. In this case event
// should be catched by HMI request itself.
if (mobile_apis::ButtonName::CUSTOM_BUTTON == btn_id) {
subscribe_on_event(hmi_apis::FunctionID::Buttons_SubscribeButton,
correlation_id());
}

SendRequest();
}

void SubscribeButtonRequest::on_event(const event_engine::Event& event) {
SDL_LOG_AUTO_TRACE();
using namespace helpers;

const smart_objects::SmartObject& message = event.smart_object();

if (hmi_apis::FunctionID::Buttons_SubscribeButton != event.id()) {
SDL_LOG_ERROR("Received unknown event.");
return;
}

const uint32_t app_id =
(*message_)[strings::msg_params][strings::app_id].asUInt();

ApplicationSharedPtr app =
application_manager_.application_by_hmi_app(app_id);

if (!app) {
SDL_LOG_ERROR("NULL pointer.");
return;
}

hmi_apis::Common_Result::eType hmi_result =
static_cast<hmi_apis::Common_Result::eType>(
message[strings::params][hmi_response::code].asInt());

if (CommandImpl::IsHMIResultSuccess(hmi_result,
HmiInterfaces::HMI_INTERFACE_Buttons)) {
const mobile_apis::ButtonName::eType btn_id =
static_cast<mobile_apis::ButtonName::eType>(
(*message_)[strings::msg_params][strings::button_name].asInt());

app->SubscribeToButton(static_cast<mobile_apis::ButtonName::eType>(btn_id));
}
}

void SubscribeButtonRequest::onTimeOut() {
SDL_LOG_AUTO_TRACE();

Expand Down

0 comments on commit 82703c9

Please sign in to comment.