Skip to content

Commit

Permalink
Separate subscription processing for mobile requests and resumption
Browse files Browse the repository at this point in the history
  • Loading branch information
ychernysheva committed Jul 16, 2021
1 parent 94c770b commit d156a9f
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 89 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,17 @@ class ResumptionDataProcessorImpl
const smart_objects::SmartObject& request,
const smart_objects::SmartObject& response) const;

/**
* @brief Checks whether SubscribeButton response successful or not and
* subscribes application if successful
* @param app_id application id
* @param request reference to request SO
* @param response reference to response SO
*/
void ProcessSubscribeButtonResponse(
const uint32_t app_id,
const smart_objects::SmartObject& request,
const smart_objects::SmartObject& response);
app_mngr::ApplicationManager& application_manager_;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ namespace hmi {
/**
* @brief SubscribeButtonRequest command class
**/
class SubscribeButtonRequest : public app_mngr::commands::RequestToHMI,
public app_mngr::event_engine::EventObserver {
class SubscribeButtonRequest : public app_mngr::commands::RequestToHMI {
public:
/**
* @brief SubscribeButtonRequest class constructor
Expand All @@ -70,22 +69,9 @@ 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);

/**
* @brief Determines whether internal unsubscription must be performed
* and HMI UnsubscribeButton request should be sent
* @param hmi_result - result code received from HMI
* @param app - reference to application instance
* @return bool - true if app should unsubscribe internally
**/
bool ShouldUnsubscribeIntertally(
const hmi_apis::Common_Result::eType hmi_result,
const app_mngr::Application& app) const;

hmi_apis::Common_ButtonName::eType button_name_;
};

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

subscribe_on_event(hmi_apis::FunctionID::Buttons_SubscribeButton,
correlation_id());
SendRequest();
}

Expand All @@ -86,53 +83,6 @@ void SubscribeButtonRequest::onTimeOut() {
static_cast<hmi_apis::FunctionID::eType>(function_id()));
}

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());

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

if (CommandImpl::IsHMIResultSuccess(hmi_result,
HmiInterfaces::HMI_INTERFACE_Buttons)) {
app->SubscribeToButton(static_cast<mobile_apis::ButtonName::eType>(btn_id));
} else if (ShouldUnsubscribeIntertally(hmi_result, *app)) {
app->UnsubscribeFromButton(
static_cast<mobile_apis::ButtonName::eType>(btn_id));
}
}

bool SubscribeButtonRequest::ShouldUnsubscribeIntertally(
const hmi_apis::Common_Result::eType hmi_result,
const app_mngr::Application& app) const {
return (!CommandImpl::IsHMIResultSuccess(
hmi_result, HmiInterfaces::HMI_INTERFACE_Buttons) &&
app.is_resuming());
}

} // namespace hmi
} // namespace commands
} // namespace sdl_rpc_plugin
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,11 @@ void SubscribeButtonRequest::on_event(const event_engine::Event& event) {
const bool result = PrepareResultForMobileResponse(
hmi_result, HmiInterfaces::HMI_INTERFACE_Buttons);

if (result) {
const auto btn_id = static_cast<mobile_apis::ButtonName::eType>(
(*message_)[str::msg_params][str::button_name].asInt());
app->SubscribeToButton(btn_id);
}
mobile_apis::Result::eType result_code =
MessageHelper::HMIToMobileResult(hmi_result);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,11 @@ void ResumptionDataProcessorImpl::ProcessResumptionStatus(
CheckVehicleDataResponse(found_request.message, response, status);
}

if (hmi_apis::FunctionID::Buttons_SubscribeButton ==
found_request.request_id.function_id) {
ProcessSubscribeButtonResponse(app_id, found_request.message, response);
}

if (hmi_apis::FunctionID::UI_CreateWindow ==
found_request.request_id.function_id) {
CheckCreateWindowResponse(found_request.message, response);
Expand Down Expand Up @@ -857,19 +862,19 @@ void ResumptionDataProcessorImpl::AddButtonsSubscriptions(
const smart_objects::SmartObject& subscriptions =
saved_app[strings::application_subscriptions];

ButtonSubscriptions button_subscriptions;
if (subscriptions.keyExists(strings::application_buttons)) {
const smart_objects::SmartObject& subscriptions_buttons =
subscriptions[strings::application_buttons];
mobile_apis::ButtonName::eType btn;
for (size_t i = 0; i < subscriptions_buttons.length(); ++i) {
btn = static_cast<mobile_apis::ButtonName::eType>(
(subscriptions_buttons[i]).asInt());
application->SubscribeToButton(btn);
if (mobile_apis::ButtonName::CUSTOM_BUTTON != btn) {
button_subscriptions.insert(btn);
}
}

ButtonSubscriptions button_subscriptions =
GetButtonSubscriptionsToResume(application);

ProcessMessagesToHMI(
MessageHelper::CreateButtonSubscriptionsHandlingRequestsList(
application,
Expand All @@ -879,19 +884,6 @@ void ResumptionDataProcessorImpl::AddButtonsSubscriptions(
}
}

ButtonSubscriptions ResumptionDataProcessorImpl::GetButtonSubscriptionsToResume(
ApplicationSharedPtr application) const {
ButtonSubscriptions button_subscriptions =
application->SubscribedButtons().GetData();
auto it = button_subscriptions.find(mobile_apis::ButtonName::CUSTOM_BUTTON);

if (it != button_subscriptions.end()) {
button_subscriptions.erase(it);
}

return button_subscriptions;
}

void ResumptionDataProcessorImpl::AddPluginsSubscriptions(
ApplicationSharedPtr application,
const smart_objects::SmartObject& saved_app) {
Expand Down Expand Up @@ -1051,6 +1043,26 @@ void ResumptionDataProcessorImpl::CheckVehicleDataResponse(
}
}

void ResumptionDataProcessorImpl::ProcessSubscribeButtonResponse(
const uint32_t app_id,
const smart_objects::SmartObject& request,
const smart_objects::SmartObject& response) {
SDL_LOG_AUTO_TRACE();
if (!IsResponseSuccessful(response)) {
return;
}

ApplicationSharedPtr app = application_manager_.application(app_id);
if (!app) {
SDL_LOG_ERROR("NULL pointer.");
return;
}
const mobile_apis::ButtonName::eType btn_id =
static_cast<mobile_apis::ButtonName::eType>(
request[strings::msg_params][strings::button_name].asInt());
app->SubscribeToButton(btn_id);
}

void ResumptionDataProcessorImpl::CheckModuleDataSubscription(
const ns_smart_device_link::ns_smart_objects::SmartObject& request,
const ns_smart_device_link::ns_smart_objects::SmartObject& response,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -611,12 +611,6 @@ TEST_F(ResumeCtrlTest, StartResumption_AppWithSubscribeOnButtons) {

EXPECT_CALL(*mock_app_, set_grammar_id(kTestGrammarId_));

for (uint32_t i = 0; i < count_of_buttons; ++i) {
EXPECT_CALL(
*mock_app_,
SubscribeToButton(static_cast<mobile_apis::ButtonName::eType>(i)));
}

std::list<application_manager::AppExtensionPtr> extensions;
extensions.insert(extensions.begin(), mock_app_extension_);

Expand Down

0 comments on commit d156a9f

Please sign in to comment.