diff options
author | JackLivio <jack@livio.io> | 2018-09-19 17:24:57 -0400 |
---|---|---|
committer | JackLivio <jack@livio.io> | 2018-09-19 17:24:57 -0400 |
commit | 55a73f739d9d92d975b9c7d95c3b3001a007c8d1 (patch) | |
tree | 39025988159c000fb4c261b657c7aee06d9c0153 /src/components/policy/policy_regular/src | |
parent | 78ac9a2cd006eed81fdbf273fea7dba531113830 (diff) | |
download | sdl_core-55a73f739d9d92d975b9c7d95c3b3001a007c8d1.tar.gz |
Add filtering for policy table parameters
Diffstat (limited to 'src/components/policy/policy_regular/src')
-rw-r--r-- | src/components/policy/policy_regular/src/policy_manager_impl.cc | 119 | ||||
-rw-r--r-- | src/components/policy/policy_regular/src/policy_table/enums.cc | 7 |
2 files changed, 123 insertions, 3 deletions
diff --git a/src/components/policy/policy_regular/src/policy_manager_impl.cc b/src/components/policy/policy_regular/src/policy_manager_impl.cc index 8c70437bfc..17f0fdebd9 100644 --- a/src/components/policy/policy_regular/src/policy_manager_impl.cc +++ b/src/components/policy/policy_regular/src/policy_manager_impl.cc @@ -160,10 +160,19 @@ void FilterInvalidFunctions(policy_table::Rpc& rpcs) { } /** - * @brief FilterInvalidParameters filter parameters that not present in schema + * @brief FilterInvalidRPCParameters filter parameters that not present in + * schema * @param rpc_parameters parameters to filter */ -void FilterInvalidParameters(policy_table::RpcParameters& rpc_parameters) { +void FilterInvalidRPCParameters(policy_table::RpcParameters& rpc_parameters) { + policy_table::HmiLevels valid_hmi_levels; + for (auto& hmi_level : rpc_parameters.hmi_levels) { + if (hmi_level.is_valid()) { + valid_hmi_levels.push_back(hmi_level); + } + } + rpc_parameters.hmi_levels.swap(valid_hmi_levels); + policy_table::Parameters valid_params; for (auto& param : *(rpc_parameters.parameters)) { if (param.is_valid()) { @@ -174,16 +183,120 @@ void FilterInvalidParameters(policy_table::RpcParameters& rpc_parameters) { } /** + * @brief FilterInvalidNotifications filter notification priorities that are not + * present in schema + * @param notification priorities to filter + */ +void FilterInvalidNotifications( + policy_table::NumberOfNotificationsPerMinute& notifications) { + policy_table::NumberOfNotificationsPerMinute valid_notifications; + for (const auto& notification : notifications) { + policy_table::Priority priority; + if (policy_table::EnumFromJsonString(notification.first, &priority)) { + valid_notifications.insert(notification); + } + } + notifications.swap(valid_notifications); +} + +/** + * @brief FilterInvalidApplicationParameters filter app params that are not + * present in schema + * @param object of app policy params to filter + */ +void FilterInvalidApplicationParameters( + policy_table::ApplicationParams& app_params) { + // Filter AppHMIType array + policy_table::AppHMITypes valid_app_hmi_types; + policy_table::AppHMITypes app_hmi_types = *(app_params.AppHMIType); + for (const auto& app_hmi_type : app_hmi_types) { + if (app_hmi_type.is_valid()) { + valid_app_hmi_types.push_back(app_hmi_type); + } + } + app_params.AppHMIType->swap(valid_app_hmi_types); + + // Filter RquestTypes array + policy_table::RequestTypes valid_request_types; + policy_table::RequestTypes request_types = *(app_params.RequestType); + for (const auto& request_type : request_types) { + if (request_type.is_valid()) { + valid_request_types.push_back(request_type); + } + } + if (valid_request_types.empty() && !request_types.empty()) { + // An empty RequestType array will allow all request types. No valid + // parameters are in the filtered array, so assign an uninitizlied value to + // for array to be "omitted" + policy_table::RequestTypes omitted_request_types; + *(app_params.RequestType) = omitted_request_types; + } else { + app_params.RequestType->swap(valid_request_types); + } + + // Filter RquestSubTypes array + policy_table::RequestSubTypes valid_request_sub_types; + policy_table::RequestSubTypes request_sub_types = + *(app_params.RequestSubType); + for (const auto& request_sub_type : request_sub_types) { + if (request_sub_type.is_valid()) { + valid_request_sub_types.push_back(request_sub_type); + } + } + if (valid_request_types.empty() && !request_types.empty()) { + // An empty RequestSubType array will allow all request types. No valid + // parameters are in the filtered array, so assign an uninitizlied value to + // for array to be "omitted" + policy_table::RequestTypes omitted_request_types; + *(app_params.RequestType) = omitted_request_types; + } else { + app_params.RequestType->swap(valid_request_types); + } + + // Filter moduleType array + policy_table::ModuleTypes valid_module_types; + policy_table::ModuleTypes module_types = *(app_params.moduleType); + for (const auto& module_type : module_types) { + if (module_type.is_valid()) { + valid_module_types.push_back(module_type); + } + } + if (valid_module_types.empty() && !module_types.empty()) { + // An empty moduleType array will allow all request types. No valid + // parameters are in the filtered array, so assign an uninitizlied value to + // for array to be "omitted" + policy_table::ModuleTypes omitted_module_types; + *(app_params.moduleType) = omitted_module_types; + } else { + app_params.moduleType->swap(valid_module_types); + } +} + +/** * @brief FilterPolicyTable filter values that not present in schema * @param pt policy table to filter */ void FilterPolicyTable(policy_table::PolicyTable& pt) { + policy_table::ModuleConfig& module_config = pt.module_config; + if (module_config.is_initialized() && + module_config.notifications_per_minute_by_priority.is_initialized()) { + FilterInvalidNotifications( + module_config.notifications_per_minute_by_priority); + } + + if (pt.app_policies_section.is_initialized()) { + policy_table::ApplicationPolicies& apps = pt.app_policies_section.apps; + for (auto& app_policy : apps) { + FilterInvalidApplicationParameters(app_policy.second); + } + } + for (auto& group : pt.functional_groupings) { policy_table::Rpc& rpcs = group.second.rpcs; FilterInvalidFunctions(rpcs); for (auto& func : rpcs) { - FilterInvalidParameters(func.second); + FilterInvalidRPCParameters(func.second); } } } diff --git a/src/components/policy/policy_regular/src/policy_table/enums.cc b/src/components/policy/policy_regular/src/policy_table/enums.cc index 6f914807c5..ec92d064da 100644 --- a/src/components/policy/policy_regular/src/policy_table/enums.cc +++ b/src/components/policy/policy_regular/src/policy_table/enums.cc @@ -15,6 +15,8 @@ bool IsValidEnum(Priority val) { return true; case P_NORMAL: return true; + case P_PROJECTION: + return true; case P_NONE: return true; default: @@ -33,6 +35,8 @@ const char* EnumToJsonString(Priority val) { return "COMMUNICATION"; case P_NORMAL: return "NORMAL"; + case P_PROJECTION: + return "PROJECTION"; case P_NONE: return "NONE"; default: @@ -55,6 +59,9 @@ bool EnumFromJsonString(const std::string& literal, Priority* result) { } else if ("NORMAL" == literal) { *result = P_NORMAL; return true; + } else if ("PROJECTION" == literal) { + *result = P_PROJECTION; + return true; } else if ("NONE" == literal) { *result = P_NONE; return true; |