summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAGaliuzov <AGaliuzov@luxoft.com>2016-01-13 13:38:45 +0200
committerAGaliuzov <AGaliuzov@luxoft.com>2016-01-13 13:38:45 +0200
commit60726ea9c1fbcd094d443149230704c38a2c62da (patch)
treeaa2f2be26ef584973bdcd43ee10111283276cee2
parent0858ec0c51c60857145eb826f18c86fb2971cf01 (diff)
parenteb6f505884f9f94b552929635b86a6a22d322163 (diff)
downloadsmartdevicelink-60726ea9c1fbcd094d443149230704c38a2c62da.tar.gz
Merge pull request #318 from LuxoftSDL/hotfix/Fix_endpoints_data_copying_during_Policy_Table_Update
Fix endpoints data copying during Policy Table Update
-rw-r--r--src/components/policy/src/policy/policy_table/table_struct/types.cc18
-rw-r--r--src/components/policy/src/policy/policy_table/table_struct/types.h1
-rw-r--r--src/components/policy/src/policy/src/cache_manager.cc18
-rw-r--r--src/components/rpc_base/include/rpc_base/rpc_base.h2
-rw-r--r--src/components/rpc_base/include/rpc_base/rpc_base_inl.h7
5 files changed, 40 insertions, 6 deletions
diff --git a/src/components/policy/src/policy/policy_table/table_struct/types.cc b/src/components/policy/src/policy/policy_table/table_struct/types.cc
index dcbd66dce..fb1daf2b3 100644
--- a/src/components/policy/src/policy/policy_table/table_struct/types.cc
+++ b/src/components/policy/src/policy/policy_table/table_struct/types.cc
@@ -489,6 +489,24 @@ ModuleConfig::ModuleConfig(const Json::Value* value__)
vehicle_model(impl::ValueMember(value__, "vehicle_model")),
vehicle_year(impl::ValueMember(value__, "vehicle_year")) {
}
+
+void ModuleConfig::SafeCopyFrom(const ModuleConfig& from) {
+// device_certificates = from.device_certificates; // According to the requirements this is optional.
+ exchange_after_x_ignition_cycles = from.exchange_after_x_ignition_cycles;
+ exchange_after_x_kilometers = from.exchange_after_x_kilometers;
+ exchange_after_x_days = from.exchange_after_x_days;
+ timeout_after_x_seconds = from.timeout_after_x_seconds;
+ seconds_between_retries = from.seconds_between_retries;
+ endpoints = from.endpoints;
+ notifications_per_minute_by_priority = from.notifications_per_minute_by_priority;
+
+ vehicle_make.assign_if_valid(from.vehicle_make);
+ vehicle_model.assign_if_valid(from.vehicle_model);
+ vehicle_year.assign_if_valid(from.vehicle_year);
+ certificate .assign_if_valid(from.certificate);
+
+}
+
Json::Value ModuleConfig::ToJsonValue() const {
Json::Value result__(Json::objectValue);
impl::WriteJsonField("device_certificates", device_certificates, &result__);
diff --git a/src/components/policy/src/policy/policy_table/table_struct/types.h b/src/components/policy/src/policy/policy_table/table_struct/types.h
index 622775399..a7b0e2d49 100644
--- a/src/components/policy/src/policy/policy_table/table_struct/types.h
+++ b/src/components/policy/src/policy/policy_table/table_struct/types.h
@@ -187,6 +187,7 @@ struct ModuleConfig : CompositeType {
ModuleConfig(uint8_t exchange_after_x_ignition_cycles, int64_t exchange_after_x_kilometers, uint8_t exchange_after_x_days, uint16_t timeout_after_x_seconds, const SecondsBetweenRetries& seconds_between_retries, const ServiceEndpoints& endpoints, const NumberOfNotificationsPerMinute& notifications_per_minute_by_priority);
~ModuleConfig();
explicit ModuleConfig(const Json::Value* value__);
+ void SafeCopyFrom(const ModuleConfig& from);
Json::Value ToJsonValue() const;
bool is_valid() const;
bool is_initialized() const;
diff --git a/src/components/policy/src/policy/src/cache_manager.cc b/src/components/policy/src/policy/src/cache_manager.cc
index 05c36223d..67348c1e9 100644
--- a/src/components/policy/src/policy/src/cache_manager.cc
+++ b/src/components/policy/src/policy/src/cache_manager.cc
@@ -228,8 +228,13 @@ bool CacheManager::ApplyUpdate(const policy_table::Table& update_pt) {
pt_->policy_table.app_policies_section.apps[iter->first].set_to_null();
pt_->policy_table.app_policies_section.apps[iter->first].set_to_string("");
} else if (policy::kDefaultId == (iter->second).get_string()) {
- pt_->policy_table.app_policies_section.apps[iter->first] =
- pt_->policy_table.app_policies_section.apps[kDefaultId];
+ policy_table::ApplicationPolicies::const_iterator iter_default =
+ update_pt.policy_table.app_policies_section.apps.find(kDefaultId);
+ if (update_pt.policy_table.app_policies_section.apps.end() == iter_default) {
+ LOG4CXX_ERROR(logger_, "The default section was not found in PTU");
+ continue;
+ }
+ pt_->policy_table.app_policies_section.apps[iter->first] = iter_default->second;
} else {
pt_->policy_table.app_policies_section.apps[iter->first] = iter->second;
}
@@ -238,10 +243,11 @@ bool CacheManager::ApplyUpdate(const policy_table::Table& update_pt) {
pt_->policy_table.app_policies_section.device =
update_pt.policy_table.app_policies_section.device;
- if (update_pt.policy_table.consumer_friendly_messages.is_initialized()) {
- pt_->policy_table.consumer_friendly_messages =
- update_pt.policy_table.consumer_friendly_messages;
- }
+ pt_->policy_table.module_config.SafeCopyFrom(update_pt.policy_table.module_config);
+
+ pt_->policy_table.consumer_friendly_messages.assign_if_valid(
+ update_pt.policy_table.consumer_friendly_messages);
+
ResetCalculatedPermissions();
Backup();
return true;
diff --git a/src/components/rpc_base/include/rpc_base/rpc_base.h b/src/components/rpc_base/include/rpc_base/rpc_base.h
index 1792262a0..019f7edc0 100644
--- a/src/components/rpc_base/include/rpc_base/rpc_base.h
+++ b/src/components/rpc_base/include/rpc_base/rpc_base.h
@@ -393,6 +393,8 @@ class Optional {
const T& operator*() const;
T* operator->();
const T* operator->() const;
+
+ void assign_if_valid(const Optional<T>& value);
// For pointer-like 'if (optional_value)' tests
// Better than operator bool because bool can be implicitly
// casted to integral types
diff --git a/src/components/rpc_base/include/rpc_base/rpc_base_inl.h b/src/components/rpc_base/include/rpc_base/rpc_base_inl.h
index 9a59e169c..2241a4707 100644
--- a/src/components/rpc_base/include/rpc_base/rpc_base_inl.h
+++ b/src/components/rpc_base/include/rpc_base/rpc_base_inl.h
@@ -604,6 +604,13 @@ const T* Optional<T>::operator->() const {
}
template<typename T>
+void Optional<T>::assign_if_valid(const Optional<T>& value) {
+ if (value.is_initialized()) {
+ value_ = value.value_;
+ }
+}
+
+template<typename T>
Optional<T>::operator const void*() const {
return is_initialized() ? &value_ : NULL;
}