summaryrefslogtreecommitdiff
path: root/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/change_registration_request.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/change_registration_request.cc')
-rw-r--r--src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/change_registration_request.cc107
1 files changed, 56 insertions, 51 deletions
diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/change_registration_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/change_registration_request.cc
index 13a57cf9a8..f7fc7d2284 100644
--- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/change_registration_request.cc
+++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/change_registration_request.cc
@@ -32,8 +32,11 @@
*/
#include "sdl_rpc_plugin/commands/mobile/change_registration_request.h"
+
#include <string.h>
+
#include <algorithm>
+
#include "application_manager/application_impl.h"
#include "application_manager/application_manager.h"
#include "application_manager/message_helper.h"
@@ -44,14 +47,14 @@
namespace {
namespace custom_str = utils::custom_string;
struct IsSameNickname {
- explicit IsSameNickname(const custom_str::CustomString& app_id)
- : app_id_(app_id) {}
+ explicit IsSameNickname(const custom_str::CustomString& app_name)
+ : app_name(app_name) {}
bool operator()(const policy::StringArray::value_type& nickname) const {
- return app_id_.CompareIgnoreCase(nickname.c_str());
+ return app_name.CompareIgnoreCase(nickname.c_str());
}
private:
- const custom_str::CustomString app_id_;
+ const custom_str::CustomString& app_name;
};
} // namespace
@@ -68,11 +71,11 @@ ChangeRegistrationRequest::ChangeRegistrationRequest(
rpc_service::RPCService& rpc_service,
HMICapabilities& hmi_capabilities,
policy::PolicyHandlerInterface& policy_handler)
- : CommandRequestImpl(message,
- application_manager,
- rpc_service,
- hmi_capabilities,
- policy_handler)
+ : RequestFromMobileImpl(message,
+ application_manager,
+ rpc_service,
+ hmi_capabilities,
+ policy_handler)
, ui_result_(hmi_apis::Common_Result::INVALID_ENUM)
, vr_result_(hmi_apis::Common_Result::INVALID_ENUM)
, tts_result_(hmi_apis::Common_Result::INVALID_ENUM) {}
@@ -83,7 +86,6 @@ void ChangeRegistrationRequest::SendVRRequest(
ApplicationSharedPtr app, smart_objects::SmartObject& msg_params) {
const HmiInterfaces& hmi_interfaces = application_manager_.hmi_interfaces();
auto function = hmi_apis::FunctionID::VR_ChangeRegistration;
- pending_requests_.Add(function);
smart_objects::SmartObject vr_params =
smart_objects::SmartObject(smart_objects::SmartType_Map);
@@ -102,7 +104,6 @@ void ChangeRegistrationRequest::SendTTSRequest(
ApplicationSharedPtr app, smart_objects::SmartObject& msg_params) {
const HmiInterfaces& hmi_interfaces = application_manager_.hmi_interfaces();
auto function = hmi_apis::FunctionID::TTS_ChangeRegistration;
- pending_requests_.Add(function);
smart_objects::SmartObject tts_params =
smart_objects::SmartObject(smart_objects::SmartType_Map);
@@ -124,7 +125,6 @@ void ChangeRegistrationRequest::SendUIRequest(
const int32_t hmi_language) {
const HmiInterfaces& hmi_interfaces = application_manager_.hmi_interfaces();
auto function = hmi_apis::FunctionID::UI_ChangeRegistration;
- pending_requests_.Add(function);
// UI processing
smart_objects::SmartObject ui_params =
smart_objects::SmartObject(smart_objects::SmartType_Map);
@@ -230,18 +230,30 @@ void ChangeRegistrationRequest::Run() {
SendResponse(false, mobile_apis::Result::UNSUPPORTED_RESOURCE);
return;
}
+
if (HmiInterfaces::InterfaceState::STATE_NOT_AVAILABLE != vr_state) {
- // VR processing
- SendVRRequest(app, msg_params);
+ StartAwaitForInterface(HmiInterfaces::InterfaceID::HMI_INTERFACE_VR);
}
+
if (HmiInterfaces::InterfaceState::STATE_NOT_AVAILABLE != tts_state) {
- // TTS processing
- SendTTSRequest(app, msg_params);
+ StartAwaitForInterface(HmiInterfaces::InterfaceID::HMI_INTERFACE_TTS);
}
if (HmiInterfaces::InterfaceState::STATE_NOT_AVAILABLE != ui_state) {
+ StartAwaitForInterface(HmiInterfaces::InterfaceID::HMI_INTERFACE_UI);
+ }
+
+ if (IsInterfaceAwaited(HmiInterfaces::HMI_INTERFACE_UI)) {
SendUIRequest(app, msg_params, hmi_language);
}
+
+ if (IsInterfaceAwaited(HmiInterfaces::HMI_INTERFACE_TTS)) {
+ SendTTSRequest(app, msg_params);
+ }
+
+ if (IsInterfaceAwaited(HmiInterfaces::HMI_INTERFACE_VR)) {
+ SendVRRequest(app, msg_params);
+ }
}
void ChangeRegistrationRequest::on_event(const event_engine::Event& event) {
@@ -254,7 +266,6 @@ void ChangeRegistrationRequest::on_event(const event_engine::Event& event) {
case hmi_apis::FunctionID::UI_ChangeRegistration: {
SDL_LOG_INFO("Received UI_ChangeRegistration event");
EndAwaitForInterface(HmiInterfaces::HMI_INTERFACE_UI);
- pending_requests_.Remove(event_id);
ui_result_ = static_cast<hmi_apis::Common_Result::eType>(
message[strings::params][hmi_response::code].asInt());
GetInfo(message, ui_response_info_);
@@ -263,7 +274,6 @@ void ChangeRegistrationRequest::on_event(const event_engine::Event& event) {
case hmi_apis::FunctionID::VR_ChangeRegistration: {
SDL_LOG_INFO("Received VR_ChangeRegistration event");
EndAwaitForInterface(HmiInterfaces::HMI_INTERFACE_VR);
- pending_requests_.Remove(event_id);
vr_result_ = static_cast<hmi_apis::Common_Result::eType>(
message[strings::params][hmi_response::code].asInt());
GetInfo(message, vr_response_info_);
@@ -272,7 +282,6 @@ void ChangeRegistrationRequest::on_event(const event_engine::Event& event) {
case hmi_apis::FunctionID::TTS_ChangeRegistration: {
SDL_LOG_INFO("Received TTS_ChangeRegistration event");
EndAwaitForInterface(HmiInterfaces::HMI_INTERFACE_TTS);
- pending_requests_.Remove(event_id);
tts_result_ = static_cast<hmi_apis::Common_Result::eType>(
message[strings::params][hmi_response::code].asInt());
GetInfo(message, tts_response_info_);
@@ -284,43 +293,39 @@ void ChangeRegistrationRequest::on_event(const event_engine::Event& event) {
}
}
- if (pending_requests_.IsFinal(event_id)) {
- ApplicationSharedPtr application =
- application_manager_.application(connection_key());
-
- if (!application) {
- SDL_LOG_ERROR("NULL pointer");
- return;
- }
+ if (IsPendingResponseExist()) {
+ SDL_LOG_DEBUG("Command still wating for HMI response");
+ return;
+ }
- if (hmi_apis::Common_Result::SUCCESS == ui_result_) {
- application->set_ui_language(static_cast<mobile_api::Language::eType>(
- (*message_)[strings::msg_params][strings::hmi_display_language]
- .asInt()));
- }
+ ApplicationSharedPtr application =
+ application_manager_.application(connection_key());
- if (hmi_apis::Common_Result::SUCCESS == vr_result_ ||
- hmi_apis::Common_Result::SUCCESS == tts_result_) {
- application->set_language(static_cast<mobile_api::Language::eType>(
- (*message_)[strings::msg_params][strings::language].asInt()));
- }
- mobile_apis::Result::eType result_code = mobile_apis::Result::INVALID_ENUM;
- std::string response_info;
- const bool result = PrepareResponseParameters(result_code, response_info);
+ if (!application) {
+ SDL_LOG_ERROR("NULL pointer");
+ return;
+ }
- (*message_)[strings::params][strings::function_id] =
- mobile_apis::FunctionID::eType::ChangeRegistrationID;
+ if (hmi_apis::Common_Result::SUCCESS == ui_result_) {
+ application->set_ui_language(static_cast<mobile_api::Language::eType>(
+ (*message_)[strings::msg_params][strings::hmi_display_language]
+ .asInt()));
+ }
- SendResponse(result,
- result_code,
- response_info.empty() ? NULL : response_info.c_str(),
- &(message[strings::msg_params]));
- } else {
- SDL_LOG_INFO(
- "There are some pending responses from HMI."
- "ChangeRegistrationRequest still waiting.");
+ if (hmi_apis::Common_Result::SUCCESS == vr_result_ ||
+ hmi_apis::Common_Result::SUCCESS == tts_result_) {
+ application->set_language(static_cast<mobile_api::Language::eType>(
+ (*message_)[strings::msg_params][strings::language].asInt()));
}
-}
+
+ mobile_apis::Result::eType result_code = mobile_apis::Result::INVALID_ENUM;
+ std::string response_info;
+ const bool result = PrepareResponseParameters(result_code, response_info);
+ SendResponse(result,
+ result_code,
+ response_info.empty() ? NULL : response_info.c_str(),
+ &(message[strings::msg_params]));
+} // namespace commands
namespace {
void CheckInfo(std::string& str) {