diff options
author | JackLivio <jack@livio.io> | 2020-10-06 06:21:09 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-06 09:21:09 -0400 |
commit | 8539a42edacc4a09d5849c7c797f4deffa2d676f (patch) | |
tree | 8c952f61613ccca63162e44a946b3c57252eaac5 | |
parent | aa4d907a0b3233f3222d86b8bfb0ce13ae994790 (diff) | |
download | sdl_core-8539a42edacc4a09d5849c7c797f4deffa2d676f.tar.gz |
Re-order rai logic for plugins (#3526)
* Re-order rai logic for plugins
* style
* Add mock method
* Add method descriptions
* Add timing content
5 files changed, 36 insertions, 8 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 344a252bef..965f63e7cb 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 @@ -370,6 +370,9 @@ class ApplicationManagerImpl ApplicationSharedPtr RegisterApplication( const std::shared_ptr<smart_objects::SmartObject>& request_for_registration) OVERRIDE; + + void FinalizeAppRegistration(ApplicationSharedPtr application, + const uint32_t connection_key) OVERRIDE; /* * @brief Closes application by id * diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/register_app_interface_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/register_app_interface_request.cc index acc7b33b17..6ac830c378 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/register_app_interface_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/register_app_interface_request.cc @@ -690,6 +690,16 @@ void RegisterAppInterfaceRequest::Run() { SetupAppDeviceInfo(application); auto status_notifier = AddApplicationDataToPolicy(application); + auto on_app_registered = [application](plugin_manager::RPCPlugin& plugin) { + plugin.OnApplicationEvent(plugin_manager::kApplicationRegistered, + application); + }; + // To prevent timing issues, this event is called before an app is accessible + // by the applications accessor. This prevents incoming hmi rpcs from + // attempting to access an app before it has been fully initialized. + application_manager_.ApplyFunctorForEachPlugin(on_app_registered); + application_manager_.FinalizeAppRegistration(application, connection_key()); + std::string add_info; const auto is_resumption_required = ApplicationDataShouldBeResumed(add_info); @@ -710,12 +720,6 @@ void RegisterAppInterfaceRequest::Run() { SendSubscribeCustomButtonNotification(); SendChangeRegistrationOnHMI(application); - auto on_app_registered = [application](plugin_manager::RPCPlugin& plugin) { - plugin.OnApplicationEvent(plugin_manager::kApplicationRegistered, - application); - }; - application_manager_.ApplyFunctorForEachPlugin(on_app_registered); - if (is_resumption_required) { const auto& msg_params = (*message_)[strings::msg_params]; const auto& hash_id = msg_params[strings::hash_id].asString(); diff --git a/src/components/application_manager/src/application_manager_impl.cc b/src/components/application_manager/src/application_manager_impl.cc index 7b4920630b..ff22480cd5 100644 --- a/src/components/application_manager/src/application_manager_impl.cc +++ b/src/components/application_manager/src/application_manager_impl.cc @@ -755,6 +755,11 @@ ApplicationSharedPtr ApplicationManagerImpl::RegisterApplication( // Timer will be started after hmi level resumption. resume_controller().OnAppRegistrationStart(policy_app_id, device_mac); + return application; +} + +void ApplicationManagerImpl::FinalizeAppRegistration( + ApplicationSharedPtr application, const uint32_t connection_key) { AddAppToRegisteredAppList(application); // Update cloud app information, in case any pending apps are unable to be @@ -772,8 +777,6 @@ ApplicationSharedPtr ApplicationManagerImpl::RegisterApplication( connection_handler::DeviceHandle secondary_device_handle = itr->second; application->set_secondary_device(secondary_device_handle); } - - return application; } bool ApplicationManagerImpl::ActivateApplication(ApplicationSharedPtr app) { diff --git a/src/components/include/application_manager/application_manager.h b/src/components/include/application_manager/application_manager.h index 45fc73b895..bc7d90e02e 100644 --- a/src/components/include/application_manager/application_manager.h +++ b/src/components/include/application_manager/application_manager.h @@ -554,9 +554,24 @@ class ApplicationManager { */ virtual void IviInfoUpdated(const std::string& vehicle_info, int value) = 0; + /** + * @brief Creates the application object for a newly registered application. + * This method performs initialiation of the app object by setting properties + * and starting the resumption process if applicable. + * @param request_for_registration Smart Object RegisterAppInterfaceRequest + * message received from mobile. + */ virtual ApplicationSharedPtr RegisterApplication( const std::shared_ptr<smart_objects::SmartObject>& request_for_registration) = 0; + /** + * @brief Completes initialization process by adding the app to the + * applications accessor. App is now accessible by all other Core components. + * @param application ApplicationSharedPtr for newly registered application. + * @param connection_key Internal application id of registering application. + */ + virtual void FinalizeAppRegistration(ApplicationSharedPtr application, + const uint32_t connection_key) = 0; virtual void SendUpdateAppList() = 0; 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 e5667ef266..a85a651f80 100644 --- a/src/components/include/test/application_manager/mock_application_manager.h +++ b/src/components/include/test/application_manager/mock_application_manager.h @@ -220,6 +220,9 @@ class MockApplicationManager : public application_manager::ApplicationManager { application_manager::ApplicationSharedPtr( const std::shared_ptr<smart_objects::SmartObject>& request_for_registration)); + MOCK_METHOD2(FinalizeAppRegistration, + void(application_manager::ApplicationSharedPtr, + const uint32_t connection_key)); MOCK_METHOD0(SendUpdateAppList, void()); MOCK_METHOD2(MarkAppsGreyOut, void(const connection_handler::DeviceHandle handle, |