diff options
author | Pavel Zhdanov (GitHub) <39907184+ZhdanovP@users.noreply.github.com> | 2020-06-08 18:03:06 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-08 11:03:06 -0400 |
commit | 908b473c971e98581dbc7fd026361406766b81c0 (patch) | |
tree | d40f55b46e0336fc3ff8b1d5ca28a7136a7ab8e0 /src/components/application_manager | |
parent | 343f003df46a3abfbc3c88e0716c37c5a2638559 (diff) | |
download | sdl_core-908b473c971e98581dbc7fd026361406766b81c0.tar.gz |
Sdl must store onWayPointChange internally (#2490)
* Add saving way points during notification
- When OnWayPointNotification appeared the wayPoint is saving
- When new app subscribing on wayPointNotification stored way points are sending to app
* Add unit tests
* fix style, update to remove (uint32_t) overload of SubscribeAppForWayPoints
Co-authored-by: collin <collin+i@collinmcqueen.com>
Diffstat (limited to 'src/components/application_manager')
4 files changed, 81 insertions, 7 deletions
diff --git a/src/components/application_manager/include/application_manager/application_manager_impl.h b/src/components/application_manager/include/application_manager/application_manager_impl.h index 0d940d6ab1..633bea87be 100644 --- a/src/components/application_manager/include/application_manager/application_manager_impl.h +++ b/src/components/application_manager/include/application_manager/application_manager_impl.h @@ -285,6 +285,9 @@ class ApplicationManagerImpl */ bool IsAppSubscribedForWayPoints(ApplicationSharedPtr app) const OVERRIDE; + void SaveWayPointsMessage( + smart_objects::SmartObjectSPtr way_points_message) OVERRIDE; + /** * @brief Subscribe Application for way points * @param Application id @@ -1530,6 +1533,8 @@ class ApplicationManagerImpl */ std::set<uint32_t> subscribed_way_points_apps_list_; + smart_objects::SmartObjectSPtr way_points_data_; + /** * @brief Map contains applications which * will send TTS global properties to HMI after timeout diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/on_way_point_change_notification.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/on_way_point_change_notification.cc index e89ede53b9..39e0735013 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/on_way_point_change_notification.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/on_way_point_change_notification.cc @@ -65,6 +65,7 @@ void OnWayPointChangeNotification::Run() { (*message_)[strings::params][strings::connection_key] = *app_id; SendNotification(); } + application_manager_.SaveWayPointsMessage(message_); } } // namespace commands } // namespace sdl_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_way_point_change_notification_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_way_point_change_notification_test.cc index 83958954cd..ec401ae2a8 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_way_point_change_notification_test.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_way_point_change_notification_test.cc @@ -59,19 +59,40 @@ using sdl_rpc_plugin::commands::OnWayPointChangeNotification; typedef std::shared_ptr<OnWayPointChangeNotification> NotificationPtr; namespace { -const uint32_t kAppId = 1u; +const uint32_t kApp1Id = 1u; +const uint32_t kApp2Id = 2u; } // namespace class OnWayPointChangeNotificationTest : public CommandsTest<CommandsTestMocks::kIsNice> { public: - OnWayPointChangeNotificationTest() - : command_(CreateCommand<OnWayPointChangeNotification>()) {} + OnWayPointChangeNotificationTest() {} + + void SetUp() OVERRIDE { + command_ = CreateCommand(); + } + + std::shared_ptr<OnWayPointChangeNotification> CreateCommand() { + InitCommand(CommandsTest<CommandsTestMocks::kIsNice>::kDefaultTimeout_); + message_ = CreateMessage(); + return std::make_shared<OnWayPointChangeNotification>( + message_, + app_mngr_, + mock_rpc_service_, + mock_hmi_capabilities_, + mock_policy_handler_); + } + + MessageSharedPtr CreateMessage( + const smart_objects::SmartType type = smart_objects::SmartType_Null) { + return std::make_shared<SmartObject>(type); + } NotificationPtr command_; + MessageSharedPtr message_; }; -MATCHER(CheckMessageData, "") { +MATCHER_P(CheckMessageData, appID, "") { const bool kIsMobileProtocolTypeCorrect = (*arg)[am::strings::params][am::strings::protocol_type].asInt() == am::commands::CommandImpl::mobile_protocol_type_; @@ -86,7 +107,7 @@ MATCHER(CheckMessageData, "") { const bool kIsConnectionKeyCorrect = (*arg)[am::strings::params][am::strings::connection_key].asUInt() == - kAppId; + appID; using namespace helpers; return Compare<bool, EQ, ALL>(true, @@ -99,11 +120,42 @@ MATCHER(CheckMessageData, "") { TEST_F(OnWayPointChangeNotificationTest, Run_NotEmptyListOfAppsSubscribedForWayPoints_SUCCESS) { std::set<uint32_t> apps_subscribed_for_way_points; - apps_subscribed_for_way_points.insert(kAppId); + apps_subscribed_for_way_points.insert(kApp1Id); EXPECT_CALL(app_mngr_, GetAppsSubscribedForWayPoints()) .WillOnce(Return(apps_subscribed_for_way_points)); - EXPECT_CALL(mock_rpc_service_, SendMessageToMobile(CheckMessageData(), _)); + EXPECT_CALL(mock_rpc_service_, + SendMessageToMobile(CheckMessageData(kApp1Id), _)); + + command_->Run(); +} + +TEST_F(OnWayPointChangeNotificationTest, + Run_StoreWayPointsDuringNotification_SUCCESS) { + std::set<uint32_t> apps_subscribed_for_way_points; + apps_subscribed_for_way_points.insert(kApp1Id); + + EXPECT_CALL(app_mngr_, GetAppsSubscribedForWayPoints()) + .WillOnce(Return(apps_subscribed_for_way_points)); + EXPECT_CALL(mock_rpc_service_, + SendMessageToMobile(CheckMessageData(kApp1Id), _)); + EXPECT_CALL(app_mngr_, SaveWayPointsMessage(message_)); + + command_->Run(); +} + +TEST_F(OnWayPointChangeNotificationTest, + Run_BroadcastingWayPointsToAllApps_SUCCESS) { + std::set<uint32_t> apps_subscribed_for_way_points; + apps_subscribed_for_way_points.insert(kApp1Id); + apps_subscribed_for_way_points.insert(kApp2Id); + + EXPECT_CALL(app_mngr_, GetAppsSubscribedForWayPoints()) + .WillOnce(Return(apps_subscribed_for_way_points)); + EXPECT_CALL(mock_rpc_service_, + SendMessageToMobile(CheckMessageData(kApp1Id), _)); + EXPECT_CALL(mock_rpc_service_, + SendMessageToMobile(CheckMessageData(kApp2Id), _)); command_->Run(); } diff --git a/src/components/application_manager/src/application_manager_impl.cc b/src/components/application_manager/src/application_manager_impl.cc index b1a348dafb..009052bc72 100644 --- a/src/components/application_manager/src/application_manager_impl.cc +++ b/src/components/application_manager/src/application_manager_impl.cc @@ -4657,6 +4657,13 @@ void ApplicationManagerImpl::SubscribeAppForWayPoints(uint32_t app_id) { LOG4CXX_DEBUG(logger_, "There are applications subscribed: " << subscribed_way_points_apps_list_.size()); + if (way_points_data_) { + smart_objects::SmartObjectSPtr way_point_notification_ = + std::make_shared<smart_objects::SmartObject>(*way_points_data_); + (*way_point_notification_)[strings::params][strings::connection_key] = + app_id; + GetRPCService().SendMessageToMobile(way_point_notification_); + } } void ApplicationManagerImpl::SubscribeAppForWayPoints( @@ -4672,6 +4679,9 @@ void ApplicationManagerImpl::UnsubscribeAppFromWayPoints(uint32_t app_id) { LOG4CXX_DEBUG(logger_, "There are applications subscribed: " << subscribed_way_points_apps_list_.size()); + if (subscribed_way_points_apps_list_.empty()) { + way_points_data_.reset(); + } } void ApplicationManagerImpl::UnsubscribeAppFromWayPoints( @@ -4688,6 +4698,12 @@ bool ApplicationManagerImpl::IsAnyAppSubscribedForWayPoints() const { return !subscribed_way_points_apps_list_.empty(); } +void ApplicationManagerImpl::SaveWayPointsMessage( + std::shared_ptr<smart_objects::SmartObject> way_points_message) { + sync_primitives::AutoLock lock(subscribed_way_points_apps_lock_); + way_points_data_ = way_points_message; +} + const std::set<uint32_t> ApplicationManagerImpl::GetAppsSubscribedForWayPoints() const { LOG4CXX_AUTO_TRACE(logger_); |