diff options
Diffstat (limited to 'src/components/policy/policy_external/src/cache_manager.cc')
-rw-r--r-- | src/components/policy/policy_external/src/cache_manager.cc | 109 |
1 files changed, 82 insertions, 27 deletions
diff --git a/src/components/policy/policy_external/src/cache_manager.cc b/src/components/policy/policy_external/src/cache_manager.cc index 965b91c9f4..3e1538ab04 100644 --- a/src/components/policy/policy_external/src/cache_manager.cc +++ b/src/components/policy/policy_external/src/cache_manager.cc @@ -33,6 +33,7 @@ #include "policy/cache_manager.h" #include <algorithm> +#include <boost/algorithm/string.hpp> #include <cmath> #include <ctime> #include <functional> @@ -752,6 +753,26 @@ bool CacheManager::ApplyUpdate(const policy_table::Table& update_pt) { pt_->policy_table.consumer_friendly_messages.assign_if_valid( update_pt.policy_table.consumer_friendly_messages); + pt_->policy_table.module_config.endpoint_properties = + update_pt.policy_table.module_config.endpoint_properties; + + // Apply update for vehicle data + if (update_pt.policy_table.vehicle_data.is_initialized()) { + if (!update_pt.policy_table.vehicle_data->schema_items.is_initialized() || + update_pt.policy_table.vehicle_data->schema_items->empty()) { + pt_->policy_table.vehicle_data->schema_items = + rpc::Optional<policy_table::VehicleDataItems>(); + } else { + policy_table::VehicleDataItems custom_items = CollectCustomVDItems( + *update_pt.policy_table.vehicle_data->schema_items); + + pt_->policy_table.vehicle_data->schema_version = + update_pt.policy_table.vehicle_data->schema_version; + pt_->policy_table.vehicle_data->schema_items = + rpc::Optional<policy_table::VehicleDataItems>(custom_items); + } + } + ResetCalculatedPermissions(); Backup(); @@ -762,6 +783,21 @@ bool CacheManager::ApplyUpdate(const policy_table::Table& update_pt) { return true; } +policy_table::VehicleDataItems CacheManager::CollectCustomVDItems( + const policy_table::VehicleDataItems& vd_items) { + policy_table::VehicleDataItems result_items; + for (auto& item : vd_items) { + const std::string i_name = "VEHICLEDATA_" + std::string(item.name); + const std::string vd_name = boost::to_upper_copy<std::string>(i_name); + const bool is_standard = + policy_table::EnumSchemaItemFactory::IsRPCSpecVehicleDataType(vd_name); + if (!is_standard) { + result_items.push_back(item); + } + } + return result_items; +} + void CacheManager::GetHMIAppTypeAfterUpdate( std::map<std::string, StringArray>& app_hmi_types) { LOG4CXX_AUTO_TRACE(logger_); @@ -1231,14 +1267,8 @@ void CacheManager::CheckPermissions(const PTString& app_id, if (rpc_param.hmi_levels.end() != hmi_iter) { result.hmi_level_permitted = PermitResult::kRpcAllowed; - policy_table::Parameters::const_iterator params_iter = - rpc_param.parameters->begin(); - policy_table::Parameters::const_iterator params_iter_end = - rpc_param.parameters->end(); - - for (; params_iter != params_iter_end; ++params_iter) { - result.list_of_allowed_params.insert( - policy_table::EnumToJsonString(*params_iter)); + for (const auto& param : *rpc_param.parameters) { + result.list_of_allowed_params.insert(std::string(param)); } } } @@ -1387,20 +1417,21 @@ bool CacheManager::SecondsBetweenRetries(std::vector<int>& seconds) { return true; } -const policy::VehicleInfo CacheManager::GetVehicleInfo() const { - CACHE_MANAGER_CHECK(VehicleInfo()); +const std::vector<policy_table::VehicleDataItem> +CacheManager::GetVehicleDataItems() const { + CACHE_MANAGER_CHECK(std::vector<policy_table::VehicleDataItem>()); sync_primitives::AutoLock auto_lock(cache_lock_); - policy_table::ModuleConfig& module_config = pt_->policy_table.module_config; - VehicleInfo vehicle_info; - vehicle_info.vehicle_make = *module_config.vehicle_make; - vehicle_info.vehicle_model = *module_config.vehicle_model; - vehicle_info.vehicle_year = *module_config.vehicle_year; - LOG4CXX_DEBUG( - logger_, - "Vehicle info (make, model, year):" << vehicle_info.vehicle_make << "," - << vehicle_info.vehicle_model << "," - << vehicle_info.vehicle_year); - return vehicle_info; + + if (pt_->policy_table.vehicle_data.is_initialized() && + pt_->policy_table.vehicle_data->schema_items.is_initialized()) { + return *(pt_->policy_table.vehicle_data->schema_items); + } + + return std::vector<policy_table::VehicleDataItem>(); +} + +Json::Value CacheManager::GetPolicyTableData() const { + return pt_->policy_table.ToJsonValue(); } void CacheManager::GetEnabledCloudApps( @@ -1669,11 +1700,19 @@ std::vector<UserFriendlyMessage> CacheManager::GetUserFriendlyMsg( void CacheManager::GetUpdateUrls(const uint32_t service_type, EndpointUrls& out_end_points) { - std::stringstream service_type_stream; - service_type_stream << (service_type <= 9 ? "0x0" : "0x") << service_type; - - const std::string service_type_str = service_type_stream.str(); - GetUpdateUrls(service_type_str, out_end_points); + auto find_hexademical = + [service_type](policy_table::ServiceEndpoints::value_type end_point) { + uint32_t decimal; + std::istringstream(end_point.first) >> std::hex >> decimal; + return end_point.first.compare(0, 2, "0x") == 0 && + decimal == service_type; + }; + auto& end_points = pt_->policy_table.module_config.endpoints; + const auto end_point = + std::find_if(end_points.begin(), end_points.end(), find_hexademical); + if (end_point != end_points.end()) { + GetUpdateUrls(end_point->first, out_end_points); + } } void CacheManager::GetUpdateUrls(const std::string& service_type, @@ -2014,6 +2053,14 @@ std::shared_ptr<policy_table::Table> CacheManager::GenerateSnapshot() { sync_primitives::AutoLock auto_lock(cache_lock_); snapshot_->policy_table = pt_->policy_table; + if (pt_->policy_table.vehicle_data.is_initialized()) { + snapshot_->policy_table.vehicle_data = + rpc::Optional<policy_table::VehicleData>(); + snapshot_->policy_table.vehicle_data->mark_initialized(); + snapshot_->policy_table.vehicle_data->schema_version = + pt_->policy_table.vehicle_data->schema_version; + } + snapshot_->SetPolicyTableType(policy_table::PT_SNAPSHOT); CheckSnapshotInitialization(); @@ -2531,6 +2578,8 @@ bool CacheManager::Init(const std::string& file_name, } else { rpc::ValidationReport report("policy_table"); snapshot->ReportErrors(&report); + LOG4CXX_DEBUG(logger_, + "Validation report: " << rpc::PrettyFormat(report)); ex_backup_->RemoveDB(); } } break; @@ -2595,7 +2644,6 @@ bool CacheManager::LoadFromFile(const std::string& file_name, LOG4CXX_FATAL(logger_, "Failed to read policy table source file."); return false; } - Json::Value value; Json::Reader reader(Json::Features::strictMode()); std::string json(json_string.begin(), json_string.end()); @@ -2934,6 +2982,7 @@ bool CacheManager::MergePreloadPT(const std::string& file_name) { MergeFG(new_table, current); MergeAP(new_table, current); MergeCFM(new_table, current); + MergeVD(new_table, current); Backup(); } return true; @@ -3001,6 +3050,12 @@ void CacheManager::MergeCFM(const policy_table::PolicyTable& new_pt, } } +void CacheManager::MergeVD(const policy_table::PolicyTable& new_pt, + policy_table::PolicyTable& pt) { + LOG4CXX_AUTO_TRACE(logger_); + pt.vehicle_data.assign_if_valid(new_pt.vehicle_data); +} + void CacheManager::InitBackupThread() { LOG4CXX_AUTO_TRACE(logger_); backuper_ = new BackgroundBackuper(this); |