Skip to content

Commit

Permalink
Address Livio comments
Browse files Browse the repository at this point in the history
  • Loading branch information
AKalinich-Luxoft committed Aug 4, 2021
1 parent daa1060 commit 1614294
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,15 @@ 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.");
SDL_LOG_ERROR("Unexpected event id received: " << event.id());
return;
}

unsubscribe_from_event(hmi_apis::FunctionID::Buttons_SubscribeButton);

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,13 @@ void UnsubscribeButtonRequest::onTimeOut() {
void UnsubscribeButtonRequest::on_event(const event_engine::Event& event) {
SDL_LOG_AUTO_TRACE();

if (hmi_apis::FunctionID::Buttons_UnsubscribeButton != event.id()) {
SDL_LOG_ERROR("Unexpected event id received: " << event.id());
return;
}

unsubscribe_from_event(hmi_apis::FunctionID::Buttons_UnsubscribeButton);

ApplicationSharedPtr app =
application_manager_.application_by_hmi_app(application_id());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,25 +64,11 @@ void OnButtonEventNotification::SendButtonNotification(
ApplicationSharedPtr app) {
SDL_LOG_AUTO_TRACE();

auto& ref = (*message_)[strings::msg_params];

mobile_apis::ButtonEventMode::eType btn_event_mode;
if (ref.keyExists(hmi_response::button_mode)) {
btn_event_mode = static_cast<mobile_apis::ButtonEventMode::eType>(
ref[hmi_response::button_mode].asInt());

} else if (ref.keyExists(strings::button_event_mode)) {
btn_event_mode = static_cast<mobile_apis::ButtonEventMode::eType>(
ref[strings::button_event_mode].asInt());
}

message_ = MessageHelper::CreateButtonNotificationToMobile(app, *message_);

(*message_)[strings::msg_params][strings::button_event_mode] = btn_event_mode;

(*message_)[strings::params][strings::function_id] =
mobile_apis::FunctionID::eType::OnButtonEventID;

message_ = MessageHelper::CreateButtonNotificationToMobile(app, *message_);

SendNotification();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,23 +65,11 @@ void OnButtonPressNotification::SendButtonNotification(
ApplicationSharedPtr app) {
SDL_LOG_AUTO_TRACE();

mobile_apis::ButtonPressMode::eType btn_press_mode;
if ((*message_)[strings::msg_params].keyExists(hmi_response::button_mode)) {
btn_press_mode = static_cast<mobile_apis::ButtonPressMode::eType>(
(*message_)[strings::msg_params][hmi_response::button_mode].asInt());

} else if ((*message_)[strings::msg_params].keyExists(
strings::button_press_mode)) {
btn_press_mode = static_cast<mobile_apis::ButtonPressMode::eType>(
(*message_)[strings::msg_params][strings::button_press_mode].asInt());
}
(*message_)[strings::params][strings::function_id] =
mobile_apis::FunctionID::eType::OnButtonPressID;

message_ = MessageHelper::CreateButtonNotificationToMobile(app, *message_);

(*message_)[strings::msg_params][strings::button_press_mode] = btn_press_mode;

(*message_)[strings::params][strings::function_id] =
mobile_apis::FunctionID::eType::OnButtonPressID;
SendNotification();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ TYPED_TEST(OnButtonNotificationCommandsTest, Run_CustomButton_SUCCESS) {
auto mock_message_helper = am::MockMessageHelper::message_helper_mock();
smart_objects::SmartObjectSPtr msg =
std::make_shared<smart_objects::SmartObject>();
(*msg)[strings::params][strings::function_id] = TestFixture::kFunctionId;
EXPECT_CALL(*mock_message_helper, CreateButtonNotificationToMobile(_, _))
.WillRepeatedly(Return(msg));

Expand Down Expand Up @@ -370,6 +371,7 @@ TYPED_TEST(OnButtonNotificationCommandsTest, Run_SUCCESS) {
auto mock_message_helper = am::MockMessageHelper::message_helper_mock();
smart_objects::SmartObjectSPtr msg =
std::make_shared<smart_objects::SmartObject>();
(*msg)[strings::params][strings::function_id] = TestFixture::kFunctionId;
EXPECT_CALL(*mock_message_helper, CreateButtonNotificationToMobile(_, _))
.WillRepeatedly(Return(msg));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1110,6 +1110,35 @@ smart_objects::SmartObjectSPtr MessageHelper::CreateButtonNotificationToMobile(

ref[strings::msg_params][strings::button_name] = btn_id;

auto get_mode_code = [&source_message](
const std::string& hmi_param_name,
const std::string& mobile_param_name) -> int64_t {
if (source_message[strings::msg_params].keyExists(hmi_param_name)) {
return source_message[strings::msg_params][hmi_param_name].asInt();
}

if (source_message[strings::msg_params].keyExists(mobile_param_name)) {
return source_message[strings::msg_params][mobile_param_name].asInt();
}

return -1;
};

const auto function_id = static_cast<mobile_apis::FunctionID::eType>(
source_message[strings::params][strings::function_id].asInt());

if (mobile_apis::FunctionID::eType::OnButtonPressID == function_id) {
const auto press_mode = static_cast<mobile_apis::ButtonPressMode::eType>(
get_mode_code(hmi_response::button_mode, strings::button_press_mode));
ref[strings::msg_params][strings::button_press_mode] = press_mode;
}

if (mobile_apis::FunctionID::eType::OnButtonEventID == function_id) {
const auto press_mode = static_cast<mobile_apis::ButtonEventMode::eType>(
get_mode_code(hmi_response::button_mode, strings::button_event_mode));
ref[strings::msg_params][strings::button_event_mode] = press_mode;
}

if (source_message[strings::msg_params].keyExists(
hmi_response::custom_button_id)) {
ref[strings::msg_params][strings::custom_button_id] =
Expand Down

0 comments on commit 1614294

Please sign in to comment.