Skip to content

Commit

Permalink
Fix subscribing on event.
Browse files Browse the repository at this point in the history
We need subscribe on ActivateAppResponse event,
not on CloseApplicationRequest.
  • Loading branch information
IGapchuk committed Nov 22, 2018
1 parent fc270f5 commit b232e7d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 39 deletions.
3 changes: 2 additions & 1 deletion src/appMain/sdl_preloaded_pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@
"CloseApplication": {
"hmi_levels": ["BACKGROUND",
"FULL",
"LIMITED"]
"LIMITED",
"NONE"]
},
"CreateInteractionChoiceSet": {
"hmi_levels": ["BACKGROUND",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,19 +87,14 @@ class CloseApplicationRequest : public app_mngr::commands::CommandRequestImpl {
* @param hmi_level - New HMI level for specified application.
* @param send_policy_priority - Defines whether to send "priority" field
* with request
* @param activate_app_corr_id - Variable for detting ActivateAppRequest
* correlation id.
* @return - True if command is executed, otherwise return false.
*/
bool SendBCActivateApp(app_mngr::ApplicationConstSharedPtr app,
hmi_apis::Common_HMILevel::eType hmi_level,
bool send_policy_priority);

/**
* @brief Send OnHMIStatus notification to mobile.
* @param app - Application to with will send OnHMIStatus.
* @param app_manager - Referance to Application Manager instance.
*/
void SendHMIStatusNotification(app_mngr::ApplicationConstSharedPtr app,
app_mngr::ApplicationManager& app_manager);
bool send_policy_priority,
uint32_t& activate_app_corr_id);
};

} // namespace commands
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,13 @@ void CloseApplicationRequest::Run() {
SendResponse(false, mobile_apis::Result::IGNORED);
}

const bool sent_success =
SendBCActivateApp(application, hmi_apis::Common_HMILevel::NONE, true);
uint32_t activate_app_corr_id = 0;
const bool sent_success = SendBCActivateApp(
application, hmi_apis::Common_HMILevel::NONE, true, activate_app_corr_id);

if (sent_success) {
const uint32_t corr_id = static_cast<uint32_t>(
(*message_)[strings::params][strings::correlation_id].asUInt());
subscribe_on_event(hmi_apis::FunctionID::BasicCommunication_ActivateApp,
corr_id);
activate_app_corr_id);
} else {
LOG4CXX_ERROR(logger_, "Unable to send BC.ActivateApp");
SendResponse(false, mobile_apis::Result::IGNORED);
Expand All @@ -109,23 +108,26 @@ void CloseApplicationRequest::on_event(const event_engine::Event& event) {
hmi_apis::Common_Result::SUCCESS,
hmi_apis::Common_Result::WARNINGS);

auto application = application_manager_.application(connection_key());
if (success) {
auto application = application_manager_.application(connection_key());
application->set_hmi_level(mobile_apis::HMILevel::HMI_NONE);
SendHMIStatusNotification(application, application_manager_);
LOG4CXX_DEBUG(logger_,
"OnHMIStatusNotification did send to Mobile with HMI_level: "
<< application->hmi_level());
"Application with id " << application->app_id()
<< " has switched to HMI_level NONE.");
} else {
LOG4CXX_WARN(logger_, "OnHMIStatusNotification didn't send to Mobile.");
LOG4CXX_WARN(logger_,
"Application with id "
<< application->app_id()
<< " hasn't switched to HMI_level NONE.");
}
SendResponse(success, mobile_result);
}

bool CloseApplicationRequest::SendBCActivateApp(
ApplicationConstSharedPtr app,
hmi_apis::Common_HMILevel::eType hmi_level,
bool send_policy_priority) {
bool send_policy_priority,
uint32_t& activate_app_corr_id) {
LOG4CXX_AUTO_TRACE(logger_);
smart_objects::SmartObjectSPtr bc_activate_app_request =
MessageHelper::GetBCActivateAppRequestToHMI(
Expand All @@ -145,26 +147,11 @@ bool CloseApplicationRequest::SendBCActivateApp(
LOG4CXX_ERROR(logger_, "Unable to send BC.ActivateAppRequest");
return false;
}
activate_app_corr_id =
(*bc_activate_app_request)[strings::params][strings::correlation_id]
.asUInt();
return true;
}

void CloseApplicationRequest::SendHMIStatusNotification(
ApplicationConstSharedPtr app, ApplicationManager& app_manager) {
using namespace application_manager;
LOG4CXX_AUTO_TRACE(logger_);

smart_objects::SmartObjectSPtr message = MessageHelper::CreateNotification(
mobile_apis::FunctionID::OnHMIStatusID, app->app_id());

(*message)[strings::msg_params][strings::hmi_level] =
static_cast<int32_t>(app->hmi_level());
(*message)[strings::msg_params][strings::audio_streaming_state] =
static_cast<int32_t>(app->audio_streaming_state());
(*message)[strings::msg_params][strings::system_context] =
static_cast<int32_t>(app->system_context());
application_manager_.GetRPCService().ManageMobileCommand(message,
Command::SOURCE_SDL);
}

} // namespace commands
} // namespace sdl_rpc_plugin

0 comments on commit b232e7d

Please sign in to comment.