diff options
author | Ira Lytvynenko <ILytvynenko@luxoft.com> | 2018-02-15 15:50:57 +0000 |
---|---|---|
committer | Ira Lytvynenko (GitHub) <ILytvynenko@luxoft.com> | 2018-06-26 12:01:45 +0300 |
commit | 44bb162a73480bfc45f2675897baae456ffcd932 (patch) | |
tree | 219f07c6b9a83b969d09707186cc2ba317babf24 /src | |
parent | c8c46e8a07a7817db63b8cfed6c8834f43296715 (diff) | |
download | sdl_core-44bb162a73480bfc45f2675897baae456ffcd932.tar.gz |
OnRemoteControlSettings and OnInteriorVehicleData notifications impl
Diffstat (limited to 'src')
6 files changed, 190 insertions, 33 deletions
diff --git a/src/components/application_manager/include/application_manager/commands/command_impl.h b/src/components/application_manager/include/application_manager/commands/command_impl.h index be79d9e8d1..7a97b113c8 100644 --- a/src/components/application_manager/include/application_manager/commands/command_impl.h +++ b/src/components/application_manager/include/application_manager/commands/command_impl.h @@ -172,6 +172,8 @@ class CommandImpl : public Command { */ void ReplaceHMIByMobileAppId(smart_objects::SmartObject& message); + std::vector<ApplicationSharedPtr> GetApplications(AppExtensionUID uid); + MessageSharedPtr message_; uint32_t default_timeout_; bool allowed_to_terminate_; diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/commands/hmi/rc_on_remote_control_settings_notification.h b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/commands/hmi/rc_on_remote_control_settings_notification.h index 535c02e59b..dfae97c5ac 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/commands/hmi/rc_on_remote_control_settings_notification.h +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/commands/hmi/rc_on_remote_control_settings_notification.h @@ -2,6 +2,7 @@ #define SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_RC_RPC_PLUGIN_INCLUDE_COMMANDS_HMI_RC_ON_REMOTE_CONTROL_SETTINGS_NOTIFICATION_H #include "application_manager/commands/notification_from_hmi.h" +#include "rc_rpc_plugin/resource_allocation_manager.h" #include "utils/macro.h" namespace rc_rpc_plugin { @@ -12,14 +13,31 @@ class RCOnRemoteControlSettingsNotification : public application_manager::commands::NotificationFromHMI { public: RCOnRemoteControlSettingsNotification( - const app_mngr::commands::MessageSharedPtr& message, - app_mngr::ApplicationManager& application_manager, - app_mngr::rpc_service::RPCService& rpc_service, - app_mngr::HMICapabilities& hmi_capabilities, - policy::PolicyHandlerInterface& policy_handle); - bool Init() OVERRIDE; + const app_mngr::commands::MessageSharedPtr& message, + app_mngr::ApplicationManager& application_manager, + app_mngr::rpc_service::RPCService& rpc_service, + app_mngr::HMICapabilities& hmi_capabilities, + policy::PolicyHandlerInterface& policy_handle, + rc_rpc_plugin::ResourceAllocationManager& resource_allocation_manager); + /** + * @brief Execute command + **/ void Run() OVERRIDE; - void on_event(const application_manager::event_engine::Event& event); + + virtual ~RCOnRemoteControlSettingsNotification(); + +private: + ResourceAllocationManager& resource_allocation_manager_; + + /** + * @brief Disalows RC functionality for all RC apps + * All registered apps with appHMIType REMOTE_CONTROL will be put to NONE hmi + * level + * OnHMIStatus (NONE) will be send to such apps + * All registered apps will be unsubsribed from OnInteriorVehicleData + * notifications + */ + void DisallowRCFunctionality(); }; } // namespace commands } // namespace rc_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/commands/mobile/on_interior_vehicle_data_notification.h b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/commands/mobile/on_interior_vehicle_data_notification.h index 5e5e670e0b..8cd996088b 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/commands/mobile/on_interior_vehicle_data_notification.h +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/commands/mobile/on_interior_vehicle_data_notification.h @@ -13,15 +13,15 @@ class OnInteriorVehicleDataNotification : public application_manager::commands::CommandNotificationImpl { public: OnInteriorVehicleDataNotification( - ResourceAllocationManager& resource_allocation_manager, const app_mngr::commands::MessageSharedPtr& message, app_mngr::ApplicationManager& application_manager, app_mngr::rpc_service::RPCService& rpc_service, app_mngr::HMICapabilities& hmi_capabilities, - policy::PolicyHandlerInterface& policy_handle); - bool Init() OVERRIDE; + policy::PolicyHandlerInterface& policy_handler); + void Run() OVERRIDE; - void on_event(const application_manager::event_engine::Event& event); + + virtual ~OnInteriorVehicleDataNotification(); }; } // namespace commands } // namespace rc_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/hmi/rc_on_remote_control_settings_notification.cc b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/hmi/rc_on_remote_control_settings_notification.cc index b246ee6f73..2069773970 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/hmi/rc_on_remote_control_settings_notification.cc +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/hmi/rc_on_remote_control_settings_notification.cc @@ -1,27 +1,116 @@ #include "rc_rpc_plugin/commands/hmi/rc_on_remote_control_settings_notification.h" +#include "rc_rpc_plugin/rc_rpc_plugin.h" +#include "rc_rpc_plugin/rc_module_constants.h" #include "utils/macro.h" namespace rc_rpc_plugin { namespace commands { -RCOnRemoteControlSettingsNotification::RCOnRemoteControlSettingsNotification( - const app_mngr::commands::MessageSharedPtr& message, +namespace { +std::map<std::string, hmi_apis::Common_RCAccessMode::eType> access_modes{ + {enums_value::kAutoAllow, hmi_apis::Common_RCAccessMode::AUTO_ALLOW}, + {enums_value::kAutoDeny, hmi_apis::Common_RCAccessMode::AUTO_DENY}, + {enums_value::kAskDriver, hmi_apis::Common_RCAccessMode::ASK_DRIVER}}; +} + +CREATE_LOGGERPTR_GLOBAL(logger_, "RemoteControlModule") + +RCOnRemoteControlSettingsNotification::RCOnRemoteControlSettingsNotification(const app_mngr::commands::MessageSharedPtr& message, app_mngr::ApplicationManager& application_manager, app_mngr::rpc_service::RPCService& rpc_service, app_mngr::HMICapabilities& hmi_capabilities, - policy::PolicyHandlerInterface& policy_handle) + policy::PolicyHandlerInterface& policy_handle, + ResourceAllocationManager &resource_allocation_manager) : application_manager::commands::NotificationFromHMI(message, application_manager, rpc_service, hmi_capabilities, - policy_handle) {} + policy_handle) + , resource_allocation_manager_(resource_allocation_manager){} + +hmi_apis::Common_RCAccessMode::eType AccessModeFromString( + const std::string& access_mode) { + std::map<std::string, hmi_apis::Common_RCAccessMode::eType>::const_iterator + mode = access_modes.find(access_mode); + return access_modes.end() != mode + ? mode->second + : hmi_apis::Common_RCAccessMode::INVALID_ENUM; +} + +std::string AccessModeToString( + const hmi_apis::Common_RCAccessMode::eType access_mode) { + std::map<std::string, hmi_apis::Common_RCAccessMode::eType>::const_iterator + it = access_modes.begin(); + for (; access_modes.end() != it; ++it) { + if (access_mode == it->second) { + return it->first; + } + } + const std::string error = "UNKNOW_ACCESS_MODE"; + DCHECK_OR_RETURN(false, error); + return error; +} + +void UnsubscribeFromInteriorVehicleDataForAllModules( + RCAppExtensionPtr extension) { + LOG4CXX_AUTO_TRACE(logger_); + extension->UnsubscribeFromInteriorVehicleData(enums_value::kClimate); + extension->UnsubscribeFromInteriorVehicleData(enums_value::kRadio); +} + +void RCOnRemoteControlSettingsNotification::DisallowRCFunctionality() { + LOG4CXX_AUTO_TRACE(logger_); + typedef std::vector<application_manager::ApplicationSharedPtr> Apps; + Apps apps = GetApplications(RCRPCPlugin::kRCPluginID); + for (Apps::iterator it = apps.begin(); it != apps.end(); ++it) { + application_manager::ApplicationSharedPtr app = *it; + DCHECK(app); + application_manager_.ChangeAppsHMILevel(app->app_id(), mobile_apis::HMILevel::eType::HMI_NONE); + + const RCAppExtensionPtr extension = + application_manager::AppExtensionPtr::static_pointer_cast< + RCAppExtension>(app->QueryInterface(RCRPCPlugin::kRCPluginID)); + if (extension) { + UnsubscribeFromInteriorVehicleDataForAllModules(extension); + } + } +} -bool RCOnRemoteControlSettingsNotification::Init() { - return true; +void RCOnRemoteControlSettingsNotification::Run() { + LOG4CXX_AUTO_TRACE(logger_); + + if (!(*message_)[app_mngr::strings::msg_params].keyExists(message_params::kAllowed)) { + LOG4CXX_DEBUG(logger_, + "Notification is ignored due to \"allow\" parameter absense"); + LOG4CXX_DEBUG(logger_, "RC Functionality remains unchanged"); + return; + } + + const bool is_allowed = (*message_)[app_mngr::strings::msg_params][message_params::kAllowed].asBool(); + if (is_allowed) { + hmi_apis::Common_RCAccessMode::eType access_mode = + hmi_apis::Common_RCAccessMode::INVALID_ENUM; + LOG4CXX_DEBUG(logger_, "Allowing RC Functionality"); + if ((*message_)[app_mngr::strings::msg_params].keyExists(message_params::kAccessMode)) { + const std::string access_mode_str = + (*message_)[app_mngr::strings::msg_params][message_params::kAccessMode].asString(); + + access_mode = AccessModeFromString(access_mode_str); + LOG4CXX_DEBUG(logger_, "Setting up access mode : " << access_mode_str); + } else { + access_mode = resource_allocation_manager_.GetAccessMode(); + LOG4CXX_DEBUG(logger_, + "No access mode received. Using last known: " + << AccessModeToString(access_mode)); + } + resource_allocation_manager_.SetAccessMode(access_mode); + } else { + LOG4CXX_DEBUG(logger_, "Disallowing RC Functionality"); + DisallowRCFunctionality(); + resource_allocation_manager_.ResetAllAllocations(); + } } -void RCOnRemoteControlSettingsNotification::Run() {} -void RCOnRemoteControlSettingsNotification::on_event( - const application_manager::event_engine::Event& event) {} + } // namespace commands } // namespace rc_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/mobile/on_interior_vehicle_data_notification.cc b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/mobile/on_interior_vehicle_data_notification.cc index 1a1b7703fb..3c306f65ec 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/mobile/on_interior_vehicle_data_notification.cc +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/mobile/on_interior_vehicle_data_notification.cc @@ -1,28 +1,50 @@ #include "rc_rpc_plugin/commands/mobile/on_interior_vehicle_data_notification.h" +#include "rc_rpc_plugin/rc_rpc_plugin.h" +#include "rc_rpc_plugin/rc_module_constants.h" #include "utils/macro.h" namespace rc_rpc_plugin { namespace commands { +CREATE_LOGGERPTR_GLOBAL(logger_, "RemoteControlModule") + OnInteriorVehicleDataNotification::OnInteriorVehicleDataNotification( - ResourceAllocationManager& resource_allocation_manager, const app_mngr::commands::MessageSharedPtr& message, app_mngr::ApplicationManager& application_manager, app_mngr::rpc_service::RPCService& rpc_service, app_mngr::HMICapabilities& hmi_capabilities, - policy::PolicyHandlerInterface& policy_handle) - : application_manager::commands::CommandNotificationImpl( - message, - application_manager, - rpc_service, - hmi_capabilities, - policy_handle) {} -bool OnInteriorVehicleDataNotification::Init() { - return true; + policy::PolicyHandlerInterface& policy_handler) + : app_mngr::commands::CommandNotificationImpl(message, + application_manager, + rpc_service, + hmi_capabilities, + policy_handler) {} + +OnInteriorVehicleDataNotification::~OnInteriorVehicleDataNotification() {} + +void OnInteriorVehicleDataNotification::Run() { + LOG4CXX_AUTO_TRACE(logger_); + + const std::string module_type = + (*message_)[app_mngr::strings::msg_params][message_params::kModuleType].asString(); + + typedef std::vector<application_manager::ApplicationSharedPtr> AppPtrs; + AppPtrs apps = GetApplications(RCRPCPlugin::kRCPluginID); + + for (AppPtrs::iterator it = apps.begin(); it != apps.end(); ++it) { + DCHECK(*it); + application_manager::Application& app = **it; + + RCAppExtensionPtr extension = + application_manager::AppExtensionPtr::static_pointer_cast< + RCAppExtension>(app.QueryInterface(RCRPCPlugin::kRCPluginID)); + DCHECK(extension); + LOG4CXX_TRACE(logger_, "Check subscription for " << app.app_id()); + if (extension->IsSubscibedToInteriorVehicleData(module_type)) { + SendNotification(); + } + } } -void OnInteriorVehicleDataNotification::Run() {} -void OnInteriorVehicleDataNotification::on_event( - const application_manager::event_engine::Event& event) {} } // namespace commands } // namespace rc_rpc_plugin diff --git a/src/components/application_manager/src/commands/command_impl.cc b/src/components/application_manager/src/commands/command_impl.cc index 22f6a822ff..593b8ee398 100644 --- a/src/components/application_manager/src/commands/command_impl.cc +++ b/src/components/application_manager/src/commands/command_impl.cc @@ -35,6 +35,16 @@ #include "application_manager/application_manager.h" namespace application_manager { + +namespace { +struct AppExtensionPredicate { + AppExtensionUID uid; + bool operator()(const ApplicationSharedPtr app) { + return app ? app->QueryInterface(uid).valid() : false; + } +}; +} + namespace commands { CREATE_LOGGERPTR_LOCAL(CommandImpl::logger_, "Commands") @@ -204,5 +214,21 @@ DEPRECATED void CommandImpl::ReplaceHMIByMobileAppId( } } +std::vector<ApplicationSharedPtr> CommandImpl::GetApplications( + AppExtensionUID uid) { + ApplicationSet accessor = application_manager_.applications().GetData(); + AppExtensionPredicate predicate; + predicate.uid = uid; + + std::vector<ApplicationSharedPtr> result; + ApplicationSetConstIt it = + std::find_if(accessor.begin(), accessor.end(), predicate); + while (it != accessor.end()) { + result.push_back(*it); + it = std::find_if(++it, accessor.end(), predicate); + } + return result; +} + } // namespace commands } // namespace application_manager |