diff options
author | Ira Lytvynenko <ILytvynenko@luxoft.com> | 2018-02-14 17:13:16 +0200 |
---|---|---|
committer | Ira Lytvynenko (GitHub) <ILytvynenko@luxoft.com> | 2018-06-26 12:01:45 +0300 |
commit | f8865f545e6b7831cf8365f19043627e2be51bbf (patch) | |
tree | 70d5a798c76b5d3898edf0bda82e880267c28e06 /src/components/application_manager/rpc_plugins/rc_rpc_plugin/src | |
parent | c8c8d7f4425e23fe1acaf8d7ff9828b60079ac4f (diff) | |
download | sdl_core-f8865f545e6b7831cf8365f19043627e2be51bbf.tar.gz |
GetInteriorVehicleData implementation and some fixes
Diffstat (limited to 'src/components/application_manager/rpc_plugins/rc_rpc_plugin/src')
8 files changed, 195 insertions, 32 deletions
diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/hmi/rc_get_interior_vehicle_data_request.cc b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/hmi/rc_get_interior_vehicle_data_request.cc index ae8a314aac..c9bb54cafb 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/hmi/rc_get_interior_vehicle_data_request.cc +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/hmi/rc_get_interior_vehicle_data_request.cc @@ -9,12 +9,12 @@ RCGetInteriorVehicleDataRequest::RCGetInteriorVehicleDataRequest( app_mngr::ApplicationManager& application_manager) : app_mngr::commands::RequestToHMI(message, application_manager) {} -bool RCGetInteriorVehicleDataRequest::Init() { - return true; +RCGetInteriorVehicleDataRequest::~RCGetInteriorVehicleDataRequest(){} + +void RCGetInteriorVehicleDataRequest::Run() { + LOG4CXX_AUTO_TRACE(logger_); + SendRequest(); } -void RCGetInteriorVehicleDataRequest::Run() {} -void RCGetInteriorVehicleDataRequest::on_event( - const application_manager::event_engine::Event& event) {} } // namespace commands } // namespace rc_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/hmi/rc_get_interior_vehicle_data_response.cc b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/hmi/rc_get_interior_vehicle_data_response.cc index 3a988d3469..3d77d0d28c 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/hmi/rc_get_interior_vehicle_data_response.cc +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/hmi/rc_get_interior_vehicle_data_response.cc @@ -1,5 +1,5 @@ #include "rc_rpc_plugin/commands/hmi/rc_get_interior_vehicle_data_response.h" -#include "utils/macro.h" +#include "application_manager/event_engine/event.h" namespace rc_rpc_plugin { namespace commands { @@ -7,14 +7,17 @@ namespace commands { RCGetInteriorVehicleDataResponse::RCGetInteriorVehicleDataResponse( const app_mngr::commands::MessageSharedPtr& message, app_mngr::ApplicationManager& application_manager) - :app_mngr::commands::ResponseToHMI(message, application_manager) {} + :app_mngr::commands::ResponseFromHMI(message, application_manager) {} -bool RCGetInteriorVehicleDataResponse::Init() { - return true; +void RCGetInteriorVehicleDataResponse::Run() { + LOG4CXX_AUTO_TRACE(logger_); + + app_mngr::event_engine::Event event(hmi_apis::FunctionID::Buttons_ButtonPress); + event.set_smart_object(*message_); + event.raise(application_manager_.event_dispatcher()); } -void RCGetInteriorVehicleDataResponse::Run() {} -void RCGetInteriorVehicleDataResponse::on_event( - const application_manager::event_engine::Event& event) {} + +RCGetInteriorVehicleDataResponse::~RCGetInteriorVehicleDataResponse(){} } // namespace commands } // namespace rc_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/mobile/get_interior_vehicle_data_request.cc b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/mobile/get_interior_vehicle_data_request.cc index 3c8e4d2f4b..8d3190b0e9 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/mobile/get_interior_vehicle_data_request.cc +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/mobile/get_interior_vehicle_data_request.cc @@ -1,20 +1,180 @@ #include "rc_rpc_plugin/commands/mobile/get_interior_vehicle_data_request.h" +#include "rc_rpc_plugin/rc_module_constants.h" #include "utils/macro.h" +#include "interfaces/MOBILE_API.h" namespace rc_rpc_plugin { namespace commands { +using namespace json_keys; +using namespace message_params; + +CREATE_LOGGERPTR_GLOBAL(logger_, "RemoteControlModule") + GetInteriorVehicleDataRequest::GetInteriorVehicleDataRequest( - const app_mngr::commands::MessageSharedPtr& message, - app_mngr::ApplicationManager& application_manager) - : app_mngr::commands::CommandRequestImpl(message, application_manager) {} + const app_mngr::commands::MessageSharedPtr& message, + app_mngr::ApplicationManager& application_manager, + rc_rpc_plugin::ResourceAllocationManager& resource_allocation_manager) + : RCCommandRequest( + resource_allocation_manager, message, application_manager) {} + +bool CheckIfModuleTypeExistInCapabilities( + const smart_objects::SmartObject& rc_capabilities, + const std::string& module_type) { + LOG4CXX_AUTO_TRACE(logger_); + if (enums_value::kRadio == module_type && + !rc_capabilities.keyExists(strings::kradioControlCapabilities)) { + LOG4CXX_DEBUG(logger_, " Radio control capabilities not present"); + return false; + } + if (enums_value::kClimate == module_type && + !rc_capabilities.keyExists(strings::kclimateControlCapabilities)) { + LOG4CXX_DEBUG(logger_, " Climate control capabilities not present"); + return false; + } -bool GetInteriorVehicleDataRequest::Init() { return true; } -void GetInteriorVehicleDataRequest::Run() {} -void GetInteriorVehicleDataRequest::on_event( - const application_manager::event_engine::Event& event) {} + +void GetInteriorVehicleDataRequest::Execute() { + LOG4CXX_AUTO_TRACE(logger_); + + const smart_objects::SmartObject* rc_capabilities = + application_manager_.hmi_capabilities().rc_capability(); + const std::string module_type = + (*message_)[app_mngr::strings::msg_params][message_params::kModuleType].asString(); + if (rc_capabilities && + !CheckIfModuleTypeExistInCapabilities(*rc_capabilities, + module_type)) { + LOG4CXX_WARN(logger_, "Accessing not supported module data"); + SendResponse(false, + mobile_apis::Result::UNSUPPORTED_RESOURCE, + "Accessing not supported module data"); + return; + } + if (HasRequestExcessiveSubscription()) { + RemoveExcessiveSubscription(); + } + + SendHMIRequest(hmi_apis::FunctionID::RC_GetInteriorVehicleData, + &(*message_)[app_mngr::strings::msg_params], true); +} + +void GetInteriorVehicleDataRequest::on_event(const app_mngr::event_engine::Event& event) { + LOG4CXX_AUTO_TRACE(logger_); + if (hmi_apis::FunctionID::RC_GetInteriorVehicleData != event.id()){ + return; + } + + const smart_objects::SmartObject& hmi_response = event.smart_object(); + + mobile_apis::Result::eType result_code = + GetMobileResultCode(static_cast<hmi_apis::Common_Result::eType>( + hmi_response[app_mngr::strings::params][app_mngr::hmi_response::code] + .asUInt())); + + bool result = + helpers::Compare<mobile_apis::Result::eType, helpers::EQ, helpers::ONE>( + result_code, + mobile_apis::Result::SUCCESS, + mobile_apis::Result::WARNINGS); + + if (mobile_apis::Result::READ_ONLY == result_code) { + result = false; + result_code = mobile_apis::Result::GENERIC_ERROR; + } + + if (result) { + ProccessSubscription(hmi_response); + } + std::string response_info; + GetInfo(hmi_response, response_info); + SendResponse(result, result_code, response_info.c_str()); +} + +void GetInteriorVehicleDataRequest::ProccessSubscription( + const NsSmartDeviceLink::NsSmartObjects::SmartObject& hmi_response) { + LOG4CXX_AUTO_TRACE(logger_); + + const bool is_subscribe_present_in_request = + (*message_)[app_mngr::strings::msg_params].keyExists(message_params::kSubscribe); + const bool isSubscribed_present_in_response = + hmi_response[json_keys::kResult].keyExists(message_params::kIsSubscribed); + + if (!is_subscribe_present_in_request && !isSubscribed_present_in_response) { + return; + } + app_mngr::ApplicationSharedPtr app = + application_manager_.application(CommandRequestImpl::connection_key()); + RCAppExtensionPtr extension = resource_allocation_manager_.GetApplicationExtention(app); + if (is_subscribe_present_in_request && !isSubscribed_present_in_response) { + LOG4CXX_WARN(logger_, + "conditional mandatory parameter " + << message_params::kIsSubscribed << " missed in hmi response"); + return; + } + + if (!is_subscribe_present_in_request && isSubscribed_present_in_response) { + LOG4CXX_WARN(logger_, + "Parameter " << message_params::kIsSubscribed + << " is ignored due to absence '" + << message_params::kSubscribe + << "' parameter in request"); + return; + } + + const bool request_subscribe = + (*message_)[app_mngr::strings::msg_params][message_params::kSubscribe].asBool(); + const bool response_subscribe = + hmi_response[json_keys::kResult][message_params::kIsSubscribed].asBool(); + LOG4CXX_TRACE(logger_, "request_subscribe = " << request_subscribe); + LOG4CXX_TRACE(logger_, "response_subscribe = " << response_subscribe); + if (request_subscribe == response_subscribe) { + const std::string module_type = + (*message_)[app_mngr::strings::msg_params][message_params::kModuleType].asString(); + if (response_subscribe) { + LOG4CXX_DEBUG(logger_, + "SubscribeToInteriorVehicleData " + << app->app_id() << " " + << module_type); + extension->SubscribeToInteriorVehicleData(module_type); + } else { + LOG4CXX_DEBUG(logger_, + "UnsubscribeFromInteriorVehicleData " + << app->app_id() << " " + << module_type); + extension->UnsubscribeFromInteriorVehicleData(module_type); + } + } +} + +bool GetInteriorVehicleDataRequest::HasRequestExcessiveSubscription() { + LOG4CXX_AUTO_TRACE(logger_); + const bool is_subscribe_present_in_request = + (*message_)[app_mngr::strings::msg_params].keyExists(message_params::kSubscribe); + + if (is_subscribe_present_in_request) { + app_mngr::ApplicationSharedPtr app = + application_manager_.application(CommandRequestImpl::connection_key()); + RCAppExtensionPtr extension = resource_allocation_manager_.GetApplicationExtention(app); + + const bool is_app_already_subscribed = + extension->IsSubscibedToInteriorVehicleData( + (*message_)[app_mngr::strings::msg_params][message_params::kModuleType].asString()); + const bool app_wants_to_subscribe = + (*message_)[app_mngr::strings::msg_params][message_params::kSubscribe].asBool(); + if (!app_wants_to_subscribe && !is_app_already_subscribed) { + return true; + } + return app_wants_to_subscribe && is_app_already_subscribed; + } + return false; +} + +void GetInteriorVehicleDataRequest::RemoveExcessiveSubscription() { + LOG4CXX_AUTO_TRACE(logger_); + (*message_)[app_mngr::strings::msg_params].erase(message_params::kSubscribe); +} } // namespace commands } // namespace rc_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/mobile/get_interior_vehicle_data_response.cc b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/mobile/get_interior_vehicle_data_response.cc index c8c8a56675..795c9a8178 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/mobile/get_interior_vehicle_data_response.cc +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/mobile/get_interior_vehicle_data_response.cc @@ -9,12 +9,12 @@ GetInteriorVehicleDataResponse::GetInteriorVehicleDataResponse( app_mngr::ApplicationManager& application_manager) : app_mngr::commands::CommandResponseImpl(message, application_manager) {} -bool GetInteriorVehicleDataResponse::Init() { - return true; +GetInteriorVehicleDataResponse::~GetInteriorVehicleDataResponse(){} + +void GetInteriorVehicleDataResponse::Run() { + LOG4CXX_AUTO_TRACE(logger_); + application_manager_.GetRPCService().SendMessageToMobile(message_); } -void GetInteriorVehicleDataResponse::Run() {} -void GetInteriorVehicleDataResponse::on_event( - const application_manager::event_engine::Event& event) {} } // namespace commands } // namespace rc_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/rc_command_request.cc b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/rc_command_request.cc index f39707c7d9..3fb8e45739 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/rc_command_request.cc +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/rc_command_request.cc @@ -206,9 +206,9 @@ void RCCommandRequest::ProcessAccessResponse( bool is_allowed = false; if (result) { - if (message[app_mngr::strings::msg_params].keyExists(message_params::kAllowed)) { + if (message[json_keys::kResult].keyExists(message_params::kAllowed)) { is_allowed = - message[app_mngr::strings::msg_params][message_params::kAllowed].asBool(); + message[json_keys::kResult][message_params::kAllowed].asBool(); } if (is_allowed) { resource_allocation_manager_.ForceAcquireResource(module_type, diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/rc_app_extension.cc b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/rc_app_extension.cc index 8a4ad3c331..65d78020bb 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/rc_app_extension.cc +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/rc_app_extension.cc @@ -37,12 +37,12 @@ RCAppExtension::RCAppExtension(application_manager::AppExtensionUID uid) : AppExtension(uid) {} void RCAppExtension::SubscribeToInteriorVehicleData( - const Json::Value& module_type) { + const std::string& module_type) { subscribed_interior_vehicle_data_.insert(module_type); } void RCAppExtension::UnsubscribeFromInteriorVehicleData( - const Json::Value& module_type) { + const std::string& module_type) { subscribed_interior_vehicle_data_.erase(module_type); } @@ -51,8 +51,8 @@ void RCAppExtension::UnsubscribeFromInteriorVehicleData() { } bool RCAppExtension::IsSubscibedToInteriorVehicleData( - const Json::Value& module_type) { - std::set<Json::Value>::iterator it = + const std::string& module_type) { + std::set<std::string>::iterator it = subscribed_interior_vehicle_data_.find(module_type); return (it != subscribed_interior_vehicle_data_.end()); diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/rc_command_factory.cc b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/rc_command_factory.cc index 57294b91a9..a7018987c4 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/rc_command_factory.cc +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/rc_command_factory.cc @@ -102,7 +102,7 @@ CommandSharedPtr RCCommandFactory::CreateMobileCommand( if ((*message)[strings::params][strings::message_type] == static_cast<int>(application_manager::MessageType::kRequest)) { command.reset( - new commands::GetInteriorVehicleDataRequest(message, app_manager_)); + new commands::GetInteriorVehicleDataRequest(message, app_manager_, allocation_manager_)); } else { command.reset(new commands::GetInteriorVehicleDataResponse( message, app_manager_)); diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/resource_allocation_manager_impl.cc b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/resource_allocation_manager_impl.cc index 4344a3a9c5..7116ecd6a5 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/resource_allocation_manager_impl.cc +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/resource_allocation_manager_impl.cc @@ -158,7 +158,7 @@ void ResourceAllocationManagerImpl::ProcessApplicationPolicyUpdate() { for (; disallowed_modules.end() != module; ++module) { ReleaseResource(*module, application_id); if (rc_extention) { - rc_extention->UnsubscribeFromInteriorVehicleData(Json::Value(*module)); + rc_extention->UnsubscribeFromInteriorVehicleData(*module); } } } |