diff options
Diffstat (limited to 'src')
8 files changed, 93 insertions, 11 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_); diff --git a/src/components/include/application_manager/application_manager.h b/src/components/include/application_manager/application_manager.h index 61ff026987..9de5b3a143 100644 --- a/src/components/include/application_manager/application_manager.h +++ b/src/components/include/application_manager/application_manager.h @@ -389,6 +389,13 @@ class ApplicationManager { virtual bool IsAnyAppSubscribedForWayPoints() const = 0; /** + * @brief Save message after OnWayPointsChangeNotification reception + * @param way_points_message pointer to the smartobject + */ + virtual void SaveWayPointsMessage( + smart_objects::SmartObjectSPtr way_points_message) = 0; + + /** * @brief Get subscribed for way points * @return reference to set of subscribed apps for way points */ diff --git a/src/components/include/test/application_manager/mock_application_manager.h b/src/components/include/test/application_manager/mock_application_manager.h index 34786910b9..cd15caf7a5 100644 --- a/src/components/include/test/application_manager/mock_application_manager.h +++ b/src/components/include/test/application_manager/mock_application_manager.h @@ -349,6 +349,8 @@ class MockApplicationManager : public application_manager::ApplicationManager { void(application_manager::ApplicationSharedPtr)); MOCK_CONST_METHOD0(IsAnyAppSubscribedForWayPoints, bool()); MOCK_CONST_METHOD0(GetAppsSubscribedForWayPoints, const std::set<uint32_t>()); + MOCK_METHOD1(SaveWayPointsMessage, + void(std::shared_ptr<smart_objects::SmartObject>)); MOCK_CONST_METHOD1( WaitingApplicationByID, application_manager::ApplicationConstSharedPtr(const uint32_t)); diff --git a/src/components/protocol_handler/src/protocol_handler_impl.cc b/src/components/protocol_handler/src/protocol_handler_impl.cc index b502a924af..7769696a76 100644 --- a/src/components/protocol_handler/src/protocol_handler_impl.cc +++ b/src/components/protocol_handler/src/protocol_handler_impl.cc @@ -1835,8 +1835,7 @@ void ProtocolHandlerImpl::NotifySessionStarted( } std::shared_ptr<BsonObject> start_session_ack_params( - new BsonObject(), - [](BsonObject* obj) { + new BsonObject(), [](BsonObject* obj) { bson_object_deinitialize(obj); delete obj; }); diff --git a/src/components/protocol_handler/test/incoming_data_handler_test.cc b/src/components/protocol_handler/test/incoming_data_handler_test.cc index c9bfa748dd..1476db0dd9 100644 --- a/src/components/protocol_handler/test/incoming_data_handler_test.cc +++ b/src/components/protocol_handler/test/incoming_data_handler_test.cc @@ -261,8 +261,8 @@ TEST_F(IncomingDataHandlerTest, MixedPayloadData_TwoConnections) { for (FrameList::const_iterator it = actual_frames.begin(); it != actual_frames.end(); ++it, ++it_exp) { - EXPECT_EQ(**it, **it_exp) << "Element number " - << std::distance(mobile_packets.begin(), it_exp); + EXPECT_EQ(**it, **it_exp) + << "Element number " << std::distance(mobile_packets.begin(), it_exp); } } |