diff options
author | Conlain Kelly <conlain.k@gmail.com> | 2018-06-18 13:08:41 -0400 |
---|---|---|
committer | Conlain Kelly <conlain.k@gmail.com> | 2018-06-18 13:08:41 -0400 |
commit | a767768447c9e7c7898b5b2847e54aa985fc5041 (patch) | |
tree | df8ef162e679d11de8e7115f495eedc3f87dbac3 /src/components | |
parent | 0dec6ef21fdfd752e33b0364c9e50d27c736371e (diff) | |
download | sdl_core-a767768447c9e7c7898b5b2847e54aa985fc5041.tar.gz |
replace auto_ptr with unique_ptr, refactor device_apps_launcher.cc/.h
Diffstat (limited to 'src/components')
16 files changed, 110 insertions, 92 deletions
diff --git a/src/components/application_manager/include/application_manager/app_launch/app_launch_data_db.h b/src/components/application_manager/include/application_manager/app_launch/app_launch_data_db.h index 92d6bbd9ef..ccbf4c7c01 100644 --- a/src/components/application_manager/include/application_manager/app_launch/app_launch_data_db.h +++ b/src/components/application_manager/include/application_manager/app_launch/app_launch_data_db.h @@ -153,7 +153,7 @@ class AppLaunchDataDB : public AppLaunchDataImpl { /** * @brief returns pointer to data base */ - std::auto_ptr<utils::dbms::SQLDatabase> db_; + std::unique_ptr<utils::dbms::SQLDatabase> db_; /** * @brief indicate initializing status of DB diff --git a/src/components/application_manager/include/application_manager/app_launch/device_apps_launcher.h b/src/components/application_manager/include/application_manager/app_launch/device_apps_launcher.h index f1f29471e6..609c833bf5 100644 --- a/src/components/application_manager/include/application_manager/app_launch/device_apps_launcher.h +++ b/src/components/application_manager/include/application_manager/app_launch/device_apps_launcher.h @@ -10,9 +10,39 @@ namespace app_launch { class AppLaunchCtrlImpl; -class DeviceAppsLauncherImpl; +class DeviceAppsLauncher; class AppsLauncher; class AppLaunchSettings; +class Launcher; +class LauncherGenerator; + +// impl class must be defined for unique_ptr in DeviceAppsLauncher +class DeviceAppsLauncherImpl { + public: + DeviceAppsLauncherImpl(DeviceAppsLauncher& interface, + AppsLauncher& apps_launcher); + + bool LaunchAppsOnDevice( + const std::string& device_mac, + const std::vector<ApplicationDataPtr>& applications_to_launch); + + struct LauncherFinder { + LauncherFinder(const std::string& device_mac) : device_mac_(device_mac) {} + + bool operator()(const utils::SharedPtr<Launcher>& launcher) const; + + std::string device_mac_; + }; + + bool StopLaunchingAppsOnDevice(const std::string& device_mac); + + private: + sync_primitives::Lock launchers_lock_; + std::vector<utils::SharedPtr<Launcher>> free_launchers_; + std::vector<utils::SharedPtr<Launcher>> works_launchers_; + DeviceAppsLauncher& interface_; +}; + /** * @brief The MultipleAppsLauncher struct * should manage launching applications and gaps between launching application @@ -36,7 +66,7 @@ class DeviceAppsLauncher { private: application_manager::ApplicationManager& app_mngr_; const AppLaunchSettings& settings_; - std::auto_ptr<DeviceAppsLauncherImpl> impl_; + std::unique_ptr<DeviceAppsLauncherImpl> impl_; friend class DeviceAppsLauncherImpl; DISALLOW_COPY_AND_ASSIGN(DeviceAppsLauncher); }; 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 30816e0ffa..d77f2316a7 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 @@ -1592,7 +1592,7 @@ class ApplicationManagerImpl hmi_message_handler::HMIMessageHandler* hmi_handler_; connection_handler::ConnectionHandler* connection_handler_; - std::auto_ptr<policy::PolicyHandlerInterface> policy_handler_; + std::unique_ptr<policy::PolicyHandlerInterface> policy_handler_; protocol_handler::ProtocolHandler* protocol_handler_; request_controller::RequestController request_ctrl_; @@ -1637,7 +1637,7 @@ class ApplicationManagerImpl // Thread that pumps messages audio pass thru to mobile. impl::AudioPassThruQueue audio_pass_thru_messages_; - std::auto_ptr<HMICapabilities> hmi_capabilities_; + std::unique_ptr<HMICapabilities> hmi_capabilities_; // The reason of HU shutdown mobile_api::AppInterfaceUnregisteredReason::eType unregister_reason_; @@ -1646,7 +1646,7 @@ class ApplicationManagerImpl * about persistent application data on disk, and save session ID for resuming * application in case INGITION_OFF or MASTER_RESSET */ - std::auto_ptr<resumption::ResumeCtrl> resume_ctrl_; + std::unique_ptr<resumption::ResumeCtrl> resume_ctrl_; HmiInterfacesImpl hmi_interfaces_; @@ -1661,8 +1661,8 @@ class ApplicationManagerImpl sync_primitives::Lock timer_pool_lock_; sync_primitives::Lock stopping_application_mng_lock_; StateControllerImpl state_ctrl_; - std::auto_ptr<app_launch::AppLaunchData> app_launch_dto_; - std::auto_ptr<app_launch::AppLaunchCtrl> app_launch_ctrl_; + std::unique_ptr<app_launch::AppLaunchData> app_launch_dto_; + std::unique_ptr<app_launch::AppLaunchCtrl> app_launch_ctrl_; /** * @brief ReregisterWaitList is list of applications expected to be diff --git a/src/components/application_manager/include/application_manager/usage_statistics.h b/src/components/application_manager/include/application_manager/usage_statistics.h index 886389b05c..aa07e41cad 100644 --- a/src/components/application_manager/include/application_manager/usage_statistics.h +++ b/src/components/application_manager/include/application_manager/usage_statistics.h @@ -66,7 +66,7 @@ class UsageStatistics { void RecordTLSError(); private: - std::auto_ptr<usage_statistics::AppStopwatch> time_in_hmi_state_sptr_; + std::unique_ptr<usage_statistics::AppStopwatch> time_in_hmi_state_sptr_; usage_statistics::AppInfo app_registration_language_gui_; usage_statistics::AppInfo app_registration_language_vui_; usage_statistics::AppCounter count_of_rejected_rpc_calls_; diff --git a/src/components/application_manager/src/app_launch/app_launch_data_db.cc b/src/components/application_manager/src/app_launch/app_launch_data_db.cc index f3adfc749b..64f9102d90 100644 --- a/src/components/application_manager/src/app_launch/app_launch_data_db.cc +++ b/src/components/application_manager/src/app_launch/app_launch_data_db.cc @@ -384,7 +384,7 @@ bool AppLaunchDataDB::WriteDb() { utils::dbms::SQLDatabase* AppLaunchDataDB::db() const { #ifdef __QNX__ - std::auto_ptr<utils::dbms::SQLDatabase> db_qnx( + std::unique_ptr<utils::dbms::SQLDatabase> db_qnx( new utils::dbms::SQLDatabase(kDatabaseName)); db_qnx.get()->Open(); return db_qnx.get(); diff --git a/src/components/application_manager/src/app_launch/device_apps_launcher.cc b/src/components/application_manager/src/app_launch/device_apps_launcher.cc index 0eb9245cf8..53ab04effd 100644 --- a/src/components/application_manager/src/app_launch/device_apps_launcher.cc +++ b/src/components/application_manager/src/app_launch/device_apps_launcher.cc @@ -59,9 +59,9 @@ class Launcher { device_launcher_.settings().wait_time_between_apps(), timer::kSingleShot); } else { - LOG4CXX_DEBUG(logger_, - "All Apps on " << apps_on_device_->first - << " posponed launched"); + LOG4CXX_DEBUG( + logger_, + "All Apps on " << apps_on_device_->first << " posponed launched"); device_launcher_.StopLaunchingAppsOnDevice(apps_on_device_->first); } } @@ -116,71 +116,59 @@ struct LauncherGenerator { AppsLauncher& apps_launcher_; }; -class DeviceAppsLauncherImpl { - public: - DeviceAppsLauncherImpl(DeviceAppsLauncher& interface, - AppsLauncher& apps_launcher) - : interface_(interface) { - sync_primitives::AutoLock lock(launchers_lock_); - LauncherGenerator generate( - interface.app_mngr_.resume_controller(), interface, apps_launcher); - free_launchers_.reserve(interface.settings_.max_number_of_ios_device()); - std::generate_n(std::back_inserter(free_launchers_), - interface.settings_.max_number_of_ios_device(), - generate); - } - - bool LaunchAppsOnDevice( - const std::string& device_mac, - const std::vector<ApplicationDataPtr>& applications_to_launch) { - LOG4CXX_AUTO_TRACE(logger_); - LOG4CXX_DEBUG(logger_, - "On Device " << device_mac << " will be launched " - << applications_to_launch.size() << " apps"); - AppsOnDevicePtr apps_on_device = - utils::MakeShared<AppsOnDevice>(device_mac, applications_to_launch); - sync_primitives::AutoLock lock(launchers_lock_); - DCHECK_OR_RETURN(!free_launchers_.empty(), false) - const Launchers::iterator it = free_launchers_.begin(); - LauncherPtr launcher = *it; - works_launchers_.push_back(launcher); - free_launchers_.erase(it); - launcher->Start(apps_on_device); - return true; - } +// DeviceAppsLauncherImpl member function definitions +DeviceAppsLauncherImpl::DeviceAppsLauncherImpl(DeviceAppsLauncher& interface, + AppsLauncher& apps_launcher) + : interface_(interface) { + sync_primitives::AutoLock lock(launchers_lock_); + LauncherGenerator generate( + interface.app_mngr_.resume_controller(), interface, apps_launcher); + free_launchers_.reserve(interface.settings_.max_number_of_ios_device()); + std::generate_n(std::back_inserter(free_launchers_), + interface.settings_.max_number_of_ios_device(), + generate); +} - struct LauncherFinder { - LauncherFinder(const std::string& device_mac) : device_mac_(device_mac) {} +bool DeviceAppsLauncherImpl::LauncherFinder::operator()( + const utils::SharedPtr<Launcher>& launcher) const { + return device_mac_ == launcher->apps_on_device_->first; +} - bool operator()(const LauncherPtr& launcher) const { - return device_mac_ == launcher->apps_on_device_->first; - } +bool DeviceAppsLauncherImpl::LaunchAppsOnDevice( + const std::string& device_mac, + const std::vector<ApplicationDataPtr>& applications_to_launch) { + LOG4CXX_AUTO_TRACE(logger_); + LOG4CXX_DEBUG(logger_, + "On Device " << device_mac << " will be launched " + << applications_to_launch.size() << " apps"); + AppsOnDevicePtr apps_on_device = + utils::MakeShared<AppsOnDevice>(device_mac, applications_to_launch); + sync_primitives::AutoLock lock(launchers_lock_); + DCHECK_OR_RETURN(!free_launchers_.empty(), false) + const Launchers::iterator it = free_launchers_.begin(); + LauncherPtr launcher = *it; + works_launchers_.push_back(launcher); + free_launchers_.erase(it); + launcher->Start(apps_on_device); + return true; +} - std::string device_mac_; - }; - - bool StopLaunchingAppsOnDevice(const std::string& device_mac) { - LOG4CXX_AUTO_TRACE(logger_); - sync_primitives::AutoLock lock(launchers_lock_); - const Launchers::iterator it = std::find_if(works_launchers_.begin(), - works_launchers_.end(), - LauncherFinder(device_mac)); - if (it == works_launchers_.end()) { - return false; - } - LauncherPtr launcher = *it; - launcher->Clear(); - free_launchers_.push_back(launcher); - works_launchers_.erase(it); - return true; +bool DeviceAppsLauncherImpl::StopLaunchingAppsOnDevice( + const std::string& device_mac) { + LOG4CXX_AUTO_TRACE(logger_); + sync_primitives::AutoLock lock(launchers_lock_); + const Launchers::iterator it = std::find_if(works_launchers_.begin(), + works_launchers_.end(), + LauncherFinder(device_mac)); + if (it == works_launchers_.end()) { + return false; } - - private: - sync_primitives::Lock launchers_lock_; - Launchers free_launchers_; - Launchers works_launchers_; - DeviceAppsLauncher& interface_; -}; + LauncherPtr launcher = *it; + launcher->Clear(); + free_launchers_.push_back(launcher); + works_launchers_.erase(it); + return true; +} bool DeviceAppsLauncher::LaunchAppsOnDevice( const std::string& device_mac, diff --git a/src/components/application_manager/src/mobile_message_handler.cc b/src/components/application_manager/src/mobile_message_handler.cc index 2f06c5f3b5..03cb0c6e6b 100644 --- a/src/components/application_manager/src/mobile_message_handler.cc +++ b/src/components/application_manager/src/mobile_message_handler.cc @@ -178,7 +178,7 @@ MobileMessageHandler::HandleIncomingMessageProtocolV2( return NULL; } - std::auto_ptr<application_manager::Message> outgoing_message( + std::unique_ptr<application_manager::Message> outgoing_message( new application_manager::Message( protocol_handler::MessagePriority::FromServiceType( message->service_type()))); diff --git a/src/components/application_manager/test/app_launch/app_launch_ctrl_test.cc b/src/components/application_manager/test/app_launch/app_launch_ctrl_test.cc index 1b90f29647..2fda4a7031 100644 --- a/src/components/application_manager/test/app_launch/app_launch_ctrl_test.cc +++ b/src/components/application_manager/test/app_launch/app_launch_ctrl_test.cc @@ -164,7 +164,7 @@ class AppLaunchCtrlTest : public ::testing::Test { NiceMock<ch_test::MockConnectionHandler> connection_handler_mock_; NiceMock<resumprion_test::MockResumeCtrl> resume_ctrl_mock_; NiceMock<app_launch_test::MockAppLaunchSettings> settings_; - std::auto_ptr<app_launch::AppLaunchCtrlImpl> app_launch_ctrl_; + std::unique_ptr<app_launch::AppLaunchCtrlImpl> app_launch_ctrl_; }; app_launch::ApplicationData AppDataFromApp( diff --git a/src/components/application_manager/test/app_launch/app_launch_data_db_test.cc b/src/components/application_manager/test/app_launch/app_launch_data_db_test.cc index e095f0682e..bfae920dbf 100644 --- a/src/components/application_manager/test/app_launch/app_launch_data_db_test.cc +++ b/src/components/application_manager/test/app_launch/app_launch_data_db_test.cc @@ -113,7 +113,7 @@ class AppLaunchDataDBTest : public ::testing::Test { return test_db_; } - static std::auto_ptr<AppLaunchDataDB> res_db_; + static std::unique_ptr<AppLaunchDataDB> res_db_; AppLaunchDataDB* res_db() { return res_db_.get(); @@ -145,7 +145,7 @@ class AppLaunchDataDBTest : public ::testing::Test { }; utils::dbms::SQLDatabase* AppLaunchDataDBTest::test_db_ = NULL; -std::auto_ptr<AppLaunchDataDB> AppLaunchDataDBTest::res_db_; +std::unique_ptr<AppLaunchDataDB> AppLaunchDataDBTest::res_db_; void AppLaunchDataDBTest::AddApplicationDataWithIncreaseTable( const ApplicationData& data) { diff --git a/src/components/application_manager/test/app_launch/app_launch_data_json_test.cc b/src/components/application_manager/test/app_launch/app_launch_data_json_test.cc index cc7d3f5814..04006954b5 100644 --- a/src/components/application_manager/test/app_launch/app_launch_data_json_test.cc +++ b/src/components/application_manager/test/app_launch/app_launch_data_json_test.cc @@ -67,7 +67,7 @@ class AppLaunchDataJsonTest : public ::testing::Test { private: virtual void SetUp() { ::file_system::DeleteFile(kAppStorageFile); - test_last_state_ = std::auto_ptr<resumption::LastState>( + test_last_state_ = std::unique_ptr<resumption::LastState>( new resumption::LastStateImpl(kAppStorageFolder, kAppInfoStorage)); ASSERT_TRUE(::file_system::CreateFile(kAppStorageFile)); @@ -102,8 +102,8 @@ class AppLaunchDataJsonTest : public ::testing::Test { void GetApplicationData_EXPECT_FALSE(const ApplicationData& in_data); std::string AddCounter(const std::string& inp, int32_t val); - std::auto_ptr<resumption::LastState> test_last_state_; - std::auto_ptr<AppLaunchDataJson> res_json_; + std::unique_ptr<resumption::LastState> test_last_state_; + std::unique_ptr<AppLaunchDataJson> res_json_; void SetTimestamp(const ApplicationData& in_data, TimevalStruct& timestamp); }; diff --git a/src/components/application_manager/test/application_manager_impl_test.cc b/src/components/application_manager/test/application_manager_impl_test.cc index 9cc552f188..54faac0d25 100644 --- a/src/components/application_manager/test/application_manager_impl_test.cc +++ b/src/components/application_manager/test/application_manager_impl_test.cc @@ -187,7 +187,7 @@ class ApplicationManagerImplTest : public ::testing::Test { NiceMock<protocol_handler_test::MockSessionObserver> mock_session_observer_; NiceMock<MockApplicationManagerSettings> mock_application_manager_settings_; application_manager_test::MockApplicationManager mock_app_mngr_; - std::auto_ptr<am::ApplicationManagerImpl> app_manager_impl_; + std::unique_ptr<am::ApplicationManagerImpl> app_manager_impl_; application_manager::MockMessageHelper* mock_message_helper_; uint32_t app_id_; utils::SharedPtr<MockApplication> mock_app_ptr_; diff --git a/src/components/application_manager/test/usage_statistics_test.cc b/src/components/application_manager/test/usage_statistics_test.cc index 6efef83052..b07ce310e9 100644 --- a/src/components/application_manager/test/usage_statistics_test.cc +++ b/src/components/application_manager/test/usage_statistics_test.cc @@ -78,14 +78,14 @@ class UsageStatisticsTest : public testing::Test { protected: utils::SharedPtr<MockStatisticsManager> mock_statistics_manager_sptr_; - std::auto_ptr<application_manager::UsageStatistics> + std::unique_ptr<application_manager::UsageStatistics> usage_statistics_test_object1_sptr_; const std::string language_; }; TEST_F(UsageStatisticsTest, RecordHmiStateChanged_CallMethod_ExpectMethodCall) { // Arrange - std::auto_ptr<MockAppStopwatch> mock_app_stopwatch_object( + std::unique_ptr<MockAppStopwatch> mock_app_stopwatch_object( new MockAppStopwatch); // Checks @@ -93,7 +93,7 @@ TEST_F(UsageStatisticsTest, RecordHmiStateChanged_CallMethod_ExpectMethodCall) { EXPECT_CALL(*mock_app_stopwatch_object, Switch(kTestAppStopwatchId)); // Act - std::auto_ptr<application_manager::UsageStatistics> + std::unique_ptr<application_manager::UsageStatistics> usage_statistics_test_object2_sptr_( new application_manager::UsageStatistics( kAppId, diff --git a/src/components/connection_handler/src/connection_handler_impl.cc b/src/components/connection_handler/src/connection_handler_impl.cc index 5b26304302..9de541df3a 100644 --- a/src/components/connection_handler/src/connection_handler_impl.cc +++ b/src/components/connection_handler/src/connection_handler_impl.cc @@ -1179,7 +1179,7 @@ void ConnectionHandlerImpl::OnConnectionEnded( connection_list_lock_.Release(); return; } - std::auto_ptr<Connection> connection(itr->second); + std::unique_ptr<Connection> connection(itr->second); connection_list_.erase(itr); connection_list_lock_.Release(); diff --git a/src/components/policy/policy_external/test/sql_pt_representation_test.cc b/src/components/policy/policy_external/test/sql_pt_representation_test.cc index 0b0831eaad..a5589cc904 100644 --- a/src/components/policy/policy_external/test/sql_pt_representation_test.cc +++ b/src/components/policy/policy_external/test/sql_pt_representation_test.cc @@ -81,14 +81,14 @@ class SQLPTRepresentationTest : public SQLPTRepresentation, static const std::string kDatabaseName; static utils::dbms::SQLQuery* query_wrapper_; // Gtest can show message that this object doesn't destroyed - static std::auto_ptr<policy_handler_test::MockPolicySettings> + static std::unique_ptr<policy_handler_test::MockPolicySettings> policy_settings_; static void SetUpTestCase() { const std::string kAppStorageFolder = "storage_SQLPTRepresentationTest"; reps = new SQLPTRepresentation(in_memory_); ASSERT_TRUE(reps != NULL); - policy_settings_ = std::auto_ptr<policy_handler_test::MockPolicySettings>( + policy_settings_ = std::unique_ptr<policy_handler_test::MockPolicySettings>( new policy_handler_test::MockPolicySettings()); ON_CALL(*policy_settings_, app_storage_folder()) .WillByDefault(ReturnRef(kAppStorageFolder)); @@ -348,7 +348,7 @@ SQLPTRepresentation* SQLPTRepresentationTest::reps = 0; utils::dbms::SQLQuery* SQLPTRepresentationTest::query_wrapper_ = 0; const std::string SQLPTRepresentationTest::kDatabaseName = ":memory:"; const bool SQLPTRepresentationTest::in_memory_ = true; -std::auto_ptr<policy_handler_test::MockPolicySettings> +std::unique_ptr<policy_handler_test::MockPolicySettings> SQLPTRepresentationTest::policy_settings_; class SQLPTRepresentationTest2 : public ::testing::Test { diff --git a/src/components/policy/policy_regular/test/sql_pt_representation_test.cc b/src/components/policy/policy_regular/test/sql_pt_representation_test.cc index a5f3741331..40dae10a4f 100644 --- a/src/components/policy/policy_regular/test/sql_pt_representation_test.cc +++ b/src/components/policy/policy_regular/test/sql_pt_representation_test.cc @@ -78,12 +78,12 @@ class SQLPTRepresentationTest : public SQLPTRepresentation, static const std::string kDatabaseName; static const std::string kAppStorageFolder; // Gtest can show message that this object doesn't destroyed - std::auto_ptr<NiceMock<MockPolicySettings> > policy_settings_; + std::unique_ptr<NiceMock<MockPolicySettings> > policy_settings_; void SetUp() OVERRIDE { file_system::CreateDirectory(kAppStorageFolder); reps = new SQLPTRepresentation; - policy_settings_ = std::auto_ptr<NiceMock<MockPolicySettings> >( + policy_settings_ = std::unique_ptr<NiceMock<MockPolicySettings> >( new NiceMock<MockPolicySettings>()); ON_CALL(*policy_settings_, app_storage_folder()) .WillByDefault(ReturnRef(kAppStorageFolder)); diff --git a/src/components/utils/include/utils/timer.h b/src/components/utils/include/utils/timer.h index ab3d48ef6f..e391db992c 100644 --- a/src/components/utils/include/utils/timer.h +++ b/src/components/utils/include/utils/timer.h @@ -218,7 +218,7 @@ class Timer { mutable sync_primitives::Lock state_lock_; - mutable std::auto_ptr<TimerDelegate> delegate_; + mutable std::unique_ptr<TimerDelegate> delegate_; threads::Thread* thread_; /** |