Skip to content

Commit

Permalink
Resume button subscriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
ychernysheva committed Jul 12, 2021
1 parent 4cf9954 commit 06dc978
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -307,18 +307,21 @@ class MessageHelper {
ApplicationConstSharedPtr app, ApplicationManager& app_mngr);

/**
* @brief Creates button subscription notifications for buttons
* @brief Creates button subscription requests for buttons
* that application is subscribed on
* @param app shared pointer to application instance
* @param app_mngr reference to application manager
* @param app application to be subscribed for button
* @param button_subscriptions collection of subscribed buttons
* @return list of notification messages in SmartObject format
* @param function_id function ID
* @param app_mngr reference to application manager
* @return list of all buttons subscription requests ready to be sent to hmi
* @note for every button separate request is created in the list
*/
static smart_objects::SmartObjectList
CreateOnButtonSubscriptionNotificationsForApp(
CreateButtonSubscriptionsHandlingRequestsList(
ApplicationConstSharedPtr app,
ApplicationManager& app_mngr,
const ButtonSubscriptions& button_subscriptions);
const ButtonSubscriptions& button_subscriptions,
const hmi_apis::FunctionID::eType function_id,
ApplicationManager& app_mngr);

/**
* @brief Creates button subscription request to hmi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1206,16 +1206,15 @@ MessageHelper::CreateOnButtonSubscriptionNotification(
}

smart_objects::SmartObjectList
MessageHelper::CreateOnButtonSubscriptionNotificationsForApp(
MessageHelper::CreateButtonSubscriptionsHandlingRequestsList(
ApplicationConstSharedPtr app,
ApplicationManager& app_mngr,
const ButtonSubscriptions& button_subscriptions) {
using namespace smart_objects;
const ButtonSubscriptions& button_subscriptions,
const hmi_apis::FunctionID::eType function_id,
ApplicationManager& app_mngr) {
using namespace hmi_apis;
using namespace mobile_apis;
SDL_LOG_AUTO_TRACE();

SmartObjectList button_subscription_requests;
smart_objects::SmartObjectList button_subscription_requests;

if (app.use_count() == 0) {
SDL_LOG_ERROR("Invalid application pointer ");
Expand All @@ -1227,7 +1226,8 @@ MessageHelper::CreateOnButtonSubscriptionNotificationsForApp(
static_cast<Common_ButtonName::eType>(it);

button_subscription_requests.push_back(
CreateOnButtonSubscriptionNotification(app->hmi_app_id(), btn, true));
CreateButtonSubscriptionHandlingRequestToHmi(
app->app_id(), btn, function_id, app_mngr));
}

return button_subscription_requests;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -871,8 +871,11 @@ void ResumptionDataProcessorImpl::AddButtonsSubscriptions(
GetButtonSubscriptionsToResume(application);

ProcessMessagesToHMI(
MessageHelper::CreateOnButtonSubscriptionNotificationsForApp(
application, application_manager_, button_subscriptions));
MessageHelper::CreateButtonSubscriptionsHandlingRequestsList(
application,
button_subscriptions,
hmi_apis::FunctionID::Buttons_SubscribeButton,
application_manager_));
}
}

Expand Down Expand Up @@ -916,11 +919,13 @@ void ResumptionDataProcessorImpl::DeleteButtonsSubscriptions(
if (hmi_apis::Common_ButtonName::CUSTOM_BUTTON == hmi_btn) {
continue;
}
auto notification = MessageHelper::CreateOnButtonSubscriptionNotification(
application->hmi_app_id(), hmi_btn, false);
// is_subscribed = false
ProcessMessageToHMI(notification, false);
application->UnsubscribeFromButton(btn);
smart_objects::SmartObjectSPtr unsubscribe_request =
MessageHelper::CreateButtonSubscriptionHandlingRequestToHmi(
application->app_id(),
hmi_btn,
hmi_apis::FunctionID::Buttons_UnsubscribeButton,
application_manager_);
ProcessMessageToHMI(unsubscribe_request, false);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,12 @@ class MockMessageHelper {
MOCK_METHOD2(CreateHMIStatusNotification,
smart_objects::SmartObjectSPtr(ApplicationSharedPtr application,
const WindowID window_id));
MOCK_METHOD3(CreateOnButtonSubscriptionNotificationsForApp,
MOCK_METHOD4(CreateButtonSubscriptionsHandlingRequestsList,
smart_objects::SmartObjectList(
ApplicationConstSharedPtr application,
ApplicationManager& app_mngr,
const ButtonSubscriptions& button_subscriptions));
const ButtonSubscriptions& button_subscriptions,
const hmi_apis::FunctionID::eType function_id,
ApplicationManager& app_mngr));
MOCK_METHOD4(SendPolicyUpdate,
void(const std::string& file_path,
const uint32_t timeout,
Expand Down
13 changes: 7 additions & 6 deletions src/components/application_manager/test/mock_message_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -620,13 +620,14 @@ MessageHelper::CreateButtonSubscriptionHandlingRequestToHmi(
}

smart_objects::SmartObjectList
MessageHelper::CreateOnButtonSubscriptionNotificationsForApp(
ApplicationConstSharedPtr application,
ApplicationManager& app_mngr,
const ButtonSubscriptions& button_subscriptions) {
MessageHelper::CreateButtonSubscriptionsHandlingRequestsList(
ApplicationConstSharedPtr app,
const ButtonSubscriptions& button_subscriptions,
const hmi_apis::FunctionID::eType function_id,
ApplicationManager& app_mngr) {
return MockMessageHelper::message_helper_mock()
->CreateOnButtonSubscriptionNotificationsForApp(
application, app_mngr, button_subscriptions);
->CreateButtonSubscriptionsHandlingRequestsList(
app, button_subscriptions, function_id, app_mngr);
}

void MessageHelper::SendUnsubscribeButtonNotification(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -604,10 +604,10 @@ TEST_F(ResumeCtrlTest, StartResumption_AppWithSubscribeOnButtons) {
ON_CALL(*mock_app_, SubscribedButtons())
.WillByDefault(Return(button_subscription_accessor));

smart_objects::SmartObjectList button_subscription_notifications;
smart_objects::SmartObjectList button_subscription_requests_list;
ON_CALL(*application_manager::MockMessageHelper::message_helper_mock(),
CreateOnButtonSubscriptionNotificationsForApp(_, _, _))
.WillByDefault(Return(button_subscription_notifications));
CreateButtonSubscriptionsHandlingRequestsList(_, _, _, _))
.WillByDefault(Return(button_subscription_requests_list));

EXPECT_CALL(*mock_app_, set_grammar_id(kTestGrammarId_));

Expand All @@ -624,7 +624,7 @@ TEST_F(ResumeCtrlTest, StartResumption_AppWithSubscribeOnButtons) {

EXPECT_CALL(*mock_app_extension_, ProcessResumption(saved_app));
EXPECT_CALL(*application_manager::MockMessageHelper::message_helper_mock(),
CreateOnButtonSubscriptionNotificationsForApp(_, _, _));
CreateButtonSubscriptionsHandlingRequestsList(_, _, _, _));

const bool res = res_ctrl_->StartResumption(mock_app_, kHash_, callback_);
EXPECT_TRUE(res);
Expand Down

0 comments on commit 06dc978

Please sign in to comment.