From ac86aa9a064bce07c5cec933fb27dfd9f92c7bc0 Mon Sep 17 00:00:00 2001 From: Alexander Date: Sat, 16 Jun 2018 19:45:29 +0300 Subject: Replace all of application SubscribeToIVI to app extension subscribeToVehicleInfo --- .../include/application_manager/application.h | 1 - .../include/application_manager/application_impl.h | 1 - .../vehicle_info_app_extension.h | 9 +++++--- .../mobile/subscribe_vehicle_data_request.cc | 8 +++++-- .../src/vehicle_info_app_extension.cc | 26 +++++++++++++++++----- .../application_manager/src/application_impl.cc | 8 ------- .../test/application_helper_test.cc | 4 +--- .../include/application_manager/mock_application.h | 1 - .../test/resumption/resume_ctrl_test.cc | 6 ----- 9 files changed, 34 insertions(+), 30 deletions(-) diff --git a/src/components/application_manager/include/application_manager/application.h b/src/components/application_manager/include/application_manager/application.h index fd0503581c..8ffab07ee8 100644 --- a/src/components/application_manager/include/application_manager/application.h +++ b/src/components/application_manager/include/application_manager/application.h @@ -625,7 +625,6 @@ class Application : public virtual InitialApplicationData, virtual bool UnsubscribeFromButton( mobile_apis::ButtonName::eType btn_name) = 0; - virtual bool SubscribeToIVI(uint32_t vehicle_info_type) = 0; virtual bool IsSubscribedToIVI(uint32_t vehicle_info_type) const = 0; virtual bool UnsubscribeFromIVI(uint32_t vehicle_info_type) = 0; diff --git a/src/components/application_manager/include/application_manager/application_impl.h b/src/components/application_manager/include/application_manager/application_impl.h index b2a24c878a..a03d08ba60 100644 --- a/src/components/application_manager/include/application_manager/application_impl.h +++ b/src/components/application_manager/include/application_manager/application_impl.h @@ -213,7 +213,6 @@ class ApplicationImpl : public virtual Application, bool IsSubscribedToButton(mobile_apis::ButtonName::eType btn_name); bool UnsubscribeFromButton(mobile_apis::ButtonName::eType btn_name); - bool SubscribeToIVI(uint32_t vehicle_info_type) OVERRIDE; bool IsSubscribedToIVI(uint32_t vehicle_info_type) const OVERRIDE; bool UnsubscribeFromIVI(uint32_t vehicle_info_type) OVERRIDE; DataAccessor SubscribedIVI() const OVERRIDE; diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/vehicle_info_app_extension.h b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/vehicle_info_app_extension.h index fd9aea5321..497fe5e904 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/vehicle_info_app_extension.h +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/vehicle_info_app_extension.h @@ -47,12 +47,12 @@ typedef mobile_apis::VehicleDataType::eType VehicleDataType; */ typedef std::set VehicleInfoSubscriptions; -class VehicleInfoAppExtension : app_mngr::AppExtension { +class VehicleInfoAppExtension : public app_mngr::AppExtension { public: - explicit VehicleInfoAppExtension(app_mngr::AppExtensionUID uid); + explicit VehicleInfoAppExtension(); virtual ~VehicleInfoAppExtension(); - void subscribeToVehicleInfo(const VehicleDataType vehicle_data); + bool subscribeToVehicleInfo(const VehicleDataType vehicle_data); void unsubscribeFromVehicleInfo(const VehicleDataType vehicle_data); void unsubscribeFromVehicleInfo(); bool isSubscribedToVehicleInfo(const VehicleDataType vehicle_data_type) const; @@ -61,6 +61,9 @@ class VehicleInfoAppExtension : app_mngr::AppExtension { void SaveResumptionData( NsSmartDeviceLink::NsSmartObjects::SmartObject& resumption_data) OVERRIDE; void PorcessResumption(const smart_objects::SmartObject& resumption_data) OVERRIDE; + static unsigned VehicleInfoAppExtensionUID; + static VehicleInfoAppExtension& ExtractVIExtension( + application_manager::Application& app); private: VehicleInfoSubscriptions subscribed_data_; diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/mobile/subscribe_vehicle_data_request.cc b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/mobile/subscribe_vehicle_data_request.cc index 766e720217..51c5fab6fe 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/mobile/subscribe_vehicle_data_request.cc +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/mobile/subscribe_vehicle_data_request.cc @@ -39,6 +39,7 @@ #include "application_manager/application_impl.h" #include "application_manager/message_helper.h" #include "utils/helpers.h" +#include "vehicle_info_plugin/vehicle_info_app_extension.h" namespace vehicle_info_plugin { using namespace application_manager; @@ -269,7 +270,8 @@ void SubscribeVehicleDataRequest::on_event(const event_engine::Event& event) { app_mngr::VehicleInfoSubscriptions::const_iterator key = vi_waiting_for_subscribe_.begin(); for (; key != vi_waiting_for_subscribe_.end(); ++key) { - app->SubscribeToIVI(*key); + auto& ext = VehicleInfoAppExtension::ExtractVIExtension(*app); + ext.subscribeToVehicleInfo(*key); } } } @@ -436,7 +438,9 @@ void SubscribeVehicleDataRequest::CheckVISubscriptions( "There are apps subscribed already for " "VehicleDataType: " << key_type); - if (!app->SubscribeToIVI(static_cast(key_type))) { + auto& ext = VehicleInfoAppExtension::ExtractVIExtension(*app); + + if (!ext.subscribeToVehicleInfo(key_type)) { LOG4CXX_ERROR( logger_, "Unable to subscribe for VehicleDataType: " << key_type); diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/vehicle_info_app_extension.cc b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/vehicle_info_app_extension.cc index f182e3258a..3cce05190a 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/vehicle_info_app_extension.cc +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/vehicle_info_app_extension.cc @@ -31,14 +31,17 @@ */ #include "vehicle_info_plugin/vehicle_info_app_extension.h" +#include "vehicle_info_plugin/vehicle_info_plugin.h" CREATE_LOGGERPTR_GLOBAL(logger_, "VehicleInfoPlugin") namespace vehicle_info_plugin { -VehicleInfoAppExtension::VehicleInfoAppExtension( - application_manager::AppExtensionUID uid) - : app_mngr::AppExtension(uid) { +unsigned VehicleInfoAppExtension::VehicleInfoAppExtensionUID = 146; + +VehicleInfoAppExtension::VehicleInfoAppExtension() + : app_mngr::AppExtension( + VehicleInfoAppExtension::VehicleInfoAppExtensionUID) { LOG4CXX_AUTO_TRACE(logger_); } @@ -46,10 +49,10 @@ VehicleInfoAppExtension::~VehicleInfoAppExtension() { LOG4CXX_AUTO_TRACE(logger_); } -void VehicleInfoAppExtension::subscribeToVehicleInfo( +bool VehicleInfoAppExtension::subscribeToVehicleInfo( const VehicleDataType vehicle_data) { LOG4CXX_DEBUG(logger_, vehicle_data); - subscribed_data_.insert(vehicle_data); + return subscribed_data_.insert(vehicle_data).second; } void VehicleInfoAppExtension::unsubscribeFromVehicleInfo( @@ -103,4 +106,17 @@ void VehicleInfoAppExtension::PorcessResumption( // application, application_manager_)); } } + +VehicleInfoAppExtension& VehicleInfoAppExtension::ExtractVIExtension( + application_manager::Application& app) { + auto ext_ptr = + app.QueryInterface(VehicleInfoAppExtension::VehicleInfoAppExtensionUID); + DCHECK(ext_ptr); + DCHECK(dynamic_cast(ext_ptr.get())); + auto vi_app_extension = + application_manager::AppExtensionPtr::static_pointer_cast< + VehicleInfoAppExtension>(ext_ptr); + DCHECK(vi_app_extension); + return *vi_app_extension; +} } diff --git a/src/components/application_manager/src/application_impl.cc b/src/components/application_manager/src/application_impl.cc index cea72e5362..fdc4a3120a 100644 --- a/src/components/application_manager/src/application_impl.cc +++ b/src/components/application_manager/src/application_impl.cc @@ -758,14 +758,6 @@ bool ApplicationImpl::UnsubscribeFromButton( return subscribed_buttons_.erase(btn_name); } -bool ApplicationImpl::SubscribeToIVI(uint32_t vehicle_info_type) { - sync_primitives::AutoLock lock(vi_lock_); - return subscribed_vehicle_info_ - .insert( - static_cast(vehicle_info_type)) - .second; -} - bool ApplicationImpl::IsSubscribedToIVI(uint32_t vehicle_info_type) const { sync_primitives::AutoLock lock(vi_lock_); VehicleInfoSubscriptions::const_iterator it = subscribed_vehicle_info_.find( diff --git a/src/components/application_manager/test/application_helper_test.cc b/src/components/application_manager/test/application_helper_test.cc index a0b6fd6aa2..620aad0f0b 100644 --- a/src/components/application_manager/test/application_helper_test.cc +++ b/src/components/application_manager/test/application_helper_test.cc @@ -147,7 +147,7 @@ TEST_F(ApplicationHelperTest, RecallApplicationData_ExpectAppDataReset) { app_impl_->AddCommand(cmd_id, cmd[strings::msg_params]); app_impl_->AddSubMenu(menu_id, cmd[strings::menu_params]); app_impl_->AddChoiceSet(choice_set_id, cmd[strings::msg_params]); - EXPECT_TRUE(app_impl_->SubscribeToIVI(static_cast(vi))); + EXPECT_TRUE(app_impl_->SubscribeToButton(button)); const std::string some_string = "some_string"; @@ -230,8 +230,6 @@ TEST_F(ApplicationHelperTest, RecallApplicationData_ExpectHMICleanupRequests) { app_impl_->AddCommand(cmd_id, cmd[strings::msg_params]); app_impl_->AddSubMenu(menu_id, cmd[strings::menu_params]); app_impl_->AddChoiceSet(choice_set_id, cmd[strings::msg_params]); - app_impl_->SubscribeToIVI(static_cast( - mobile_apis::VehicleDataType::VEHICLEDATA_ACCPEDAL)); app_impl_->SubscribeToButton(mobile_apis::ButtonName::AC); EXPECT_CALL(*mock_message_helper_, SendUnsubscribedWayPoints(_)); diff --git a/src/components/application_manager/test/include/application_manager/mock_application.h b/src/components/application_manager/test/include/application_manager/mock_application.h index ef1cd46cce..d531371c0c 100644 --- a/src/components/application_manager/test/include/application_manager/mock_application.h +++ b/src/components/application_manager/test/include/application_manager/mock_application.h @@ -150,7 +150,6 @@ class MockApplication : public ::application_manager::Application { bool(mobile_apis::ButtonName::eType btn_name)); MOCK_METHOD1(UnsubscribeFromButton, bool(mobile_apis::ButtonName::eType btn_name)); - MOCK_METHOD1(SubscribeToIVI, bool(uint32_t vehicle_info_type)); MOCK_CONST_METHOD1(IsSubscribedToIVI, bool(uint32_t vehicle_info_type)); MOCK_METHOD1(UnsubscribeFromIVI, bool(uint32_t vehicle_info_type)); MOCK_METHOD0(ResetDataInNone, void()); diff --git a/src/components/application_manager/test/resumption/resume_ctrl_test.cc b/src/components/application_manager/test/resumption/resume_ctrl_test.cc index 85801d7e73..eb724a88c2 100644 --- a/src/components/application_manager/test/resumption/resume_ctrl_test.cc +++ b/src/components/application_manager/test/resumption/resume_ctrl_test.cc @@ -479,12 +479,6 @@ TEST_F(ResumeCtrlTest, StartResumption_AppWithSubscriptionToIVI) { EXPECT_CALL(*app_mock_, set_grammar_id(kTestGrammarId_)); - for (size_t i = 0; i < app_vi.length(); ++i) { - EXPECT_CALL( - *app_mock_, - SubscribeToIVI(static_cast(i))); - } - smart_objects::SmartObjectList requests; EXPECT_CALL(*application_manager::MockMessageHelper::message_helper_mock(), GetIVISubscriptionRequests(_)).WillRepeatedly(Return(requests)); -- cgit v1.2.1