diff options
Diffstat (limited to 'src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/vehicle_info_plugin.cc')
-rw-r--r-- | src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/vehicle_info_plugin.cc | 40 |
1 files changed, 31 insertions, 9 deletions
diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/vehicle_info_plugin.cc b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/vehicle_info_plugin.cc index 3e8ef6b29d..1c553fb84d 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/vehicle_info_plugin.cc +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/vehicle_info_plugin.cc @@ -154,28 +154,50 @@ void VehicleInfoPlugin::UnsubscribeFromRemovedVDItems() { application_manager_->GetRPCService().ManageHMICommand(message); } +bool IsOtherAppAlreadySubscribedFor( + const std::string& ivi_name, + const application_manager::ApplicationManager& app_mngr, + const uint32_t current_app_id) { + auto applications = app_mngr.applications(); + + for (auto& app : applications.GetData()) { + auto& ext = VehicleInfoAppExtension::ExtractVIExtension(*app); + if (ext.isSubscribedToVehicleInfo(ivi_name) && + (app->app_id() != current_app_id)) { + return true; + } + } + return false; +} + void VehicleInfoPlugin::ProcessResumptionSubscription( application_manager::Application& app, VehicleInfoAppExtension& ext) { LOG4CXX_AUTO_TRACE(logger_); smart_objects::SmartObject msg_params = smart_objects::SmartObject(smart_objects::SmartType_Map); - msg_params[strings::app_id] = app.app_id(); + const auto& subscriptions = ext.Subscriptions(); + if (subscriptions.empty()) { LOG4CXX_DEBUG(logger_, "No vehicle data to subscribe. Exiting"); return; } - for (const auto& item : subscriptions) { - msg_params[item] = true; + for (auto& ivi : subscriptions) { + if (!IsOtherAppAlreadySubscribedFor( + ivi, *application_manager_, app.app_id())) { + msg_params[ivi] = true; + } } - smart_objects::SmartObjectSPtr request = - application_manager::MessageHelper::CreateModuleInfoSO( - hmi_apis::FunctionID::VehicleInfo_SubscribeVehicleData, - *application_manager_); - (*request)[strings::msg_params] = msg_params; - application_manager_->GetRPCService().ManageHMICommand(request); + if (!msg_params.empty()) { + auto request = application_manager::MessageHelper::CreateModuleInfoSO( + hmi_apis::FunctionID::VehicleInfo_SubscribeVehicleData, + *application_manager_); + msg_params[strings::app_id] = app.app_id(); + (*request)[strings::msg_params] = msg_params; + application_manager_->GetRPCService().ManageHMICommand(request); + } } application_manager::ApplicationSharedPtr FindAppSubscribedToIVI( |