diff options
6 files changed, 92 insertions, 39 deletions
diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/resource_allocation_manager.h b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/resource_allocation_manager.h index 98da8bc27d..5140d10722 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/resource_allocation_manager.h +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/resource_allocation_manager.h @@ -56,6 +56,19 @@ enum eType { FREE = 0, BUSY }; } /** + * Defines triggers for OnRCStatus notification sending + */ +namespace NotificationTrigger { +/** + * @brief The eType + * APP_REGISTRATION RC app registation event + * RC_STATE_CHANGING enabling/disabling RC on HMI event + * MODULE_ALLOCATION module allocation/deallocation event + */ +enum eType { APP_REGISTRATION = 0, MODULE_ALLOCATION, RC_STATE_CHANGING }; +} + +/** * @brief Resources defines list of resources */ typedef std::vector<std::string> Resources; @@ -146,9 +159,10 @@ class ResourceAllocationManager { /** * @brief Create and send OnRCStatusNotification to mobile and HMI - * @param application + * @param event trigger for notification sending */ - virtual void SendOnRCStatusNotification() = 0; + virtual void SendOnRCStatusNotifications( + NotificationTrigger::eType event) = 0; virtual bool is_rc_enabled() const = 0; diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/resource_allocation_manager_impl.h b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/resource_allocation_manager_impl.h index 4c72e9ea2c..368c5fa785 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/resource_allocation_manager_impl.h +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/resource_allocation_manager_impl.h @@ -118,7 +118,7 @@ class ResourceAllocationManagerImpl : public ResourceAllocationManager { RCAppExtensionPtr GetApplicationExtention( application_manager::ApplicationSharedPtr application) FINAL; - void SendOnRCStatusNotification() FINAL; + void SendOnRCStatusNotifications(NotificationTrigger::eType event) FINAL; bool is_rc_enabled() const FINAL; diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/rc_rpc_plugin.cc b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/rc_rpc_plugin.cc index a001e4734f..c086a10d3b 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/rc_rpc_plugin.cc +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/rc_rpc_plugin.cc @@ -91,9 +91,8 @@ void RCRPCPlugin::OnApplicationEvent( switch (event) { case plugins::kApplicationRegistered: { application->AddExtension(new RCAppExtension(kRCPluginID)); - if (resource_allocation_manager_->is_rc_enabled()) { - resource_allocation_manager_->SendOnRCStatusNotification(); - } + resource_allocation_manager_->SendOnRCStatusNotifications( + NotificationTrigger::APP_REGISTRATION); break; } case plugins::kApplicationExit: { diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/resource_allocation_manager_impl.cc b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/resource_allocation_manager_impl.cc index 1d2dbf8997..2478196e86 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/resource_allocation_manager_impl.cc +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/resource_allocation_manager_impl.cc @@ -174,7 +174,7 @@ void ResourceAllocationManagerImpl::ProcessApplicationPolicyUpdate() { if (rc_extention) { rc_extention->UnsubscribeFromInteriorVehicleData(*module); } - SendOnRCStatusNotification(); + SendOnRCStatusNotifications(NotificationTrigger::MODULE_ALLOCATION); } } } @@ -227,34 +227,36 @@ void ConstructOnRCStatusNotificationParams( smart_objects::SmartObject& msg_params, const std::map<std::string, uint32_t>& allocated_resources, const std::vector<std::string>& supported_resources, - const uint32_t app_id) { + const uint32_t app_id, + const bool is_rc_enabled) { namespace strings = application_manager::strings; namespace message_params = rc_rpc_plugin::message_params; using smart_objects::SmartObject; using smart_objects::SmartType_Map; using smart_objects::SmartType_Array; LOG4CXX_AUTO_TRACE(logger_); - - auto modules_inserter = [](SmartObject& result_modules) { - return [&result_modules](const std::string& module_name) { - smart_objects::SmartObject module_data = - SmartObject(smart_objects::SmartType_Map); - auto module_type = - StringToEnum<mobile_apis::ModuleType::eType>(module_name); - module_data[message_params::kModuleType] = module_type; - result_modules.asArray()->push_back(module_data); - }; - }; SmartObject allocated_modules = SmartObject(SmartType_Array); - for (const auto& module : allocated_resources) { - if (module.second == app_id) { - modules_inserter(allocated_modules)(module.first); - } - } SmartObject free_modules = SmartObject(SmartType_Array); - for (auto& module : supported_resources) { - if (allocated_resources.find(module) == allocated_resources.end()) { - modules_inserter(free_modules)(module); + if (is_rc_enabled) { + auto modules_inserter = [](SmartObject& result_modules) { + return [&result_modules](const std::string& module_name) { + smart_objects::SmartObject module_data = + SmartObject(smart_objects::SmartType_Map); + auto module_type = + StringToEnum<mobile_apis::ModuleType::eType>(module_name); + module_data[message_params::kModuleType] = module_type; + result_modules.asArray()->push_back(module_data); + }; + }; + for (const auto& module : allocated_resources) { + if (module.second == app_id) { + modules_inserter(allocated_modules)(module.first); + } + } + for (auto& module : supported_resources) { + if (allocated_resources.find(module) == allocated_resources.end()) { + modules_inserter(free_modules)(module); + } } } msg_params[message_params::kAllocatedModules] = allocated_modules; @@ -269,8 +271,11 @@ ResourceAllocationManagerImpl::CreateOnRCStatusNotificationToMobile( auto msg_to_mobile = MessageHelper::CreateNotification( mobile_apis::FunctionID::OnRCStatusID, app->app_id()); auto& msg_params = (*msg_to_mobile)[application_manager::strings::msg_params]; - ConstructOnRCStatusNotificationParams( - msg_params, allocated_resources_, all_supported_modules(), app->app_id()); + ConstructOnRCStatusNotificationParams(msg_params, + allocated_resources_, + all_supported_modules(), + app->app_id(), + is_rc_enabled()); return msg_to_mobile; } @@ -282,8 +287,11 @@ ResourceAllocationManagerImpl::CreateOnRCStatusNotificationToHmi( auto msg_to_hmi = MessageHelper::CreateHMINotification(hmi_apis::FunctionID::RC_OnRCStatus); auto& msg_params = (*msg_to_hmi)[application_manager::strings::msg_params]; - ConstructOnRCStatusNotificationParams( - msg_params, allocated_resources_, all_supported_modules(), app->app_id()); + ConstructOnRCStatusNotificationParams(msg_params, + allocated_resources_, + all_supported_modules(), + app->app_id(), + is_rc_enabled()); msg_params[application_manager::strings::app_id] = app->hmi_app_id(); return msg_to_hmi; } @@ -292,17 +300,40 @@ void ResourceAllocationManagerImpl::SetResourceAquired( const std::string& module_type, const uint32_t app_id) { LOG4CXX_AUTO_TRACE(logger_); allocated_resources_[module_type] = app_id; - SendOnRCStatusNotification(); + SendOnRCStatusNotifications(NotificationTrigger::MODULE_ALLOCATION); } -void ResourceAllocationManagerImpl::SendOnRCStatusNotification() { +void ResourceAllocationManagerImpl::SendOnRCStatusNotifications( + NotificationTrigger::eType event) { LOG4CXX_AUTO_TRACE(logger_); auto rc_apps = RCRPCPlugin::GetRCApplications(app_mngr_); for (const auto& rc_app : rc_apps) { - auto msg_to_mobile = CreateOnRCStatusNotificationToMobile(rc_app); - rpc_service_.SendMessageToMobile(msg_to_mobile); - auto msg_to_hmi = CreateOnRCStatusNotificationToHmi(rc_app); - rpc_service_.SendMessageToHMI(msg_to_hmi); + smart_objects::SmartObjectSPtr msg_to_mobile; + smart_objects::SmartObjectSPtr msg_to_hmi; + switch (event) { + case NotificationTrigger::APP_REGISTRATION: + msg_to_mobile = CreateOnRCStatusNotificationToMobile(rc_app); + (*msg_to_mobile)[application_manager::strings::msg_params] + [message_params::kAllowed] = is_rc_enabled(); + rpc_service_.SendMessageToMobile(msg_to_mobile); + if (is_rc_enabled()) { + msg_to_hmi = CreateOnRCStatusNotificationToHmi(rc_app); + rpc_service_.SendMessageToHMI(msg_to_hmi); + } + break; + case NotificationTrigger::MODULE_ALLOCATION: + msg_to_mobile = CreateOnRCStatusNotificationToMobile(rc_app); + rpc_service_.SendMessageToMobile(msg_to_mobile); + msg_to_hmi = CreateOnRCStatusNotificationToHmi(rc_app); + rpc_service_.SendMessageToHMI(msg_to_hmi); + break; + case NotificationTrigger::RC_STATE_CHANGING: + msg_to_mobile = CreateOnRCStatusNotificationToMobile(rc_app); + (*msg_to_mobile)[application_manager::strings::msg_params] + [message_params::kAllowed] = is_rc_enabled(); + rpc_service_.SendMessageToMobile(msg_to_mobile); + break; + } } } @@ -312,6 +343,7 @@ bool ResourceAllocationManagerImpl::is_rc_enabled() const { void ResourceAllocationManagerImpl::set_rc_enabled(const bool value) { is_rc_enabled_ = value; + SendOnRCStatusNotifications(NotificationTrigger::RC_STATE_CHANGING); } void ResourceAllocationManagerImpl::SetResourceFree( @@ -476,7 +508,7 @@ void ResourceAllocationManagerImpl::OnApplicationEvent( ReleaseResource(*module, application->app_id()); } if (!acquired_modules.empty()) { - SendOnRCStatusNotification(); + SendOnRCStatusNotifications(NotificationTrigger::MODULE_ALLOCATION); } Apps app_list; app_list.push_back(application); diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/include/rc_rpc_plugin/mock/mock_resource_allocation_manager.h b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/include/rc_rpc_plugin/mock/mock_resource_allocation_manager.h index df0daad0b9..a443b24f3a 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/include/rc_rpc_plugin/mock/mock_resource_allocation_manager.h +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/include/rc_rpc_plugin/mock/mock_resource_allocation_manager.h @@ -65,7 +65,8 @@ class MockResourceAllocationManager rc_rpc_plugin::RCAppExtensionPtr( application_manager::ApplicationSharedPtr application)); MOCK_METHOD0(ResetAllAllocations, void()); - MOCK_METHOD0(SendOnRCStatusNotification, void()); + MOCK_METHOD1(SendOnRCStatusNotifications, + void(rc_rpc_plugin::NotificationTrigger::eType)); MOCK_CONST_METHOD0(is_rc_enabled, bool()); MOCK_METHOD1(set_rc_enabled, void(const bool value)); }; diff --git a/src/components/interfaces/MOBILE_API.xml b/src/components/interfaces/MOBILE_API.xml index a751447bd3..3daaf413cb 100644 --- a/src/components/interfaces/MOBILE_API.xml +++ b/src/components/interfaces/MOBILE_API.xml @@ -6345,6 +6345,13 @@ <function name="OnRCStatus" functionID="OnRCStatusID" messagetype="notification"> <description>Issued by SDL to notify the application about remote control status change on SDL</description> + <param name="allowed" type="Boolean" mandatory="false"> + <description> + If "true" - RC is allowed; if "false" - RC is disallowed. + Not present in notification in case by module allocation/deallocation. + Present in notification in cases enabling/disabling RC or RC-app registration. + </description> + </param> <param name="allocatedModules" type="ModuleData" minsize="0" maxsize="100" array="true" mandatory="true"> <description>Contains a list (zero or more) of module types that are allocated to the application.</description> </param> |