diff options
author | AGaliuzov <AGaliuzov@luxoft.com> | 2015-10-27 17:17:28 +0200 |
---|---|---|
committer | AGaliuzov <AGaliuzov@luxoft.com> | 2015-10-27 17:17:28 +0200 |
commit | a9929be59cda0ab3898cb9cbd1a5b95c3a9eb591 (patch) | |
tree | dd6954cbf92d9dbb8ada4261e64d5c6f13f532eb | |
parent | 9e3d29cf1b73256ee7deb7d642619032c9aa5d40 (diff) | |
parent | 3392825f055342cba7ee269299c19c2ddf9529bb (diff) | |
download | smartdevicelink-a9929be59cda0ab3898cb9cbd1a5b95c3a9eb591.tar.gz |
Merge pull request #248 from LuxoftSDL/hotfix/OnVehicleData_send_to_app_that_unsubscribed_vehicleData
Fix OnVehidacleData sended to app with unsubscribed vehicleData
-rw-r--r-- | src/components/application_manager/src/commands/mobile/on_vehicle_data_notification.cc | 59 |
1 files changed, 38 insertions, 21 deletions
diff --git a/src/components/application_manager/src/commands/mobile/on_vehicle_data_notification.cc b/src/components/application_manager/src/commands/mobile/on_vehicle_data_notification.cc index 044bb16b4..68755bef5 100644 --- a/src/components/application_manager/src/commands/mobile/on_vehicle_data_notification.cc +++ b/src/components/application_manager/src/commands/mobile/on_vehicle_data_notification.cc @@ -52,36 +52,53 @@ OnVehicleDataNotification::~OnVehicleDataNotification() { void OnVehicleDataNotification::Run() { LOG4CXX_AUTO_TRACE(logger_); + std::vector<ApplicationSharedPtr> appNotification; + std::vector<ApplicationSharedPtr>::iterator appNotification_it = + appNotification.begin(); + std::vector<smart_objects::SmartObject> appSO; + const VehicleData& vehicle_data = MessageHelper::vehicle_data(); VehicleData::const_iterator it = vehicle_data.begin(); for (; vehicle_data.end() != it; ++it) { if (true == (*message_)[strings::msg_params].keyExists(it->first)) { - const std::vector<utils::SharedPtr<Application>>& applications = - ApplicationManagerImpl::instance()->IviInfoUpdated(it->second, - (*message_)[strings::msg_params][it->first].asInt()); - - std::vector<utils::SharedPtr<Application>>::const_iterator it = applications.begin(); - for (; applications.end() != it; ++it) { - utils::SharedPtr<Application> app = *it; - if (!app) { - LOG4CXX_ERROR_EXT(logger_, "NULL pointer"); - continue; + const std::vector<ApplicationSharedPtr>& applications = + ApplicationManagerImpl::instance()->IviInfoUpdated(it->second, + (*message_)[strings::msg_params][it->first].asInt()); + + std::vector<ApplicationSharedPtr>::const_iterator app_it = applications.begin(); + for (; applications.end() != app_it; ++app_it) { + const ApplicationSharedPtr app = *app_it; + DCHECK(app); + + appNotification_it = find(appNotification.begin(), appNotification.end(), app); + if (appNotification_it == appNotification.end()) { + appNotification.push_back(app); + smart_objects::SmartObject msg_param = smart_objects::SmartObject( + smart_objects::SmartType_Map); + msg_param[it->first] = (*message_)[strings::msg_params][it->first]; + appSO.push_back(msg_param); + } else { + size_t idx = std::distance(appNotification.begin(), appNotification_it); + appSO[idx][it->first] = (*message_)[strings::msg_params][it->first]; } - - LOG4CXX_INFO( - logger_, - "Send OnVehicleData PRNDL notification to " << app->name() - << " application id " << app->app_id()); - - (*message_)[strings::params][strings::connection_key] = app->app_id(); - - SendNotification(); } - - return; } } + + LOG4CXX_DEBUG(logger_, "Number of Notifications to be send: " << + appNotification.size()); + + for (size_t idx = 0; idx < appNotification.size(); idx++) { + LOG4CXX_INFO( + logger_, + "Send OnVehicleData PRNDL notification to " << appNotification[idx]->name() + << " application id " << appNotification[idx]->app_id()); + (*message_)[strings::params][strings::connection_key] = + appNotification[idx]->app_id(); + (*message_)[strings::msg_params] = appSO[idx]; + SendNotification(); + } } } // namespace commands |