Skip to content

Commit

Permalink
Merge pull request #34 from CustomSDL/feature/REVSDL-1194-moduleType-…
Browse files Browse the repository at this point in the history
…other-sections

REVSDL-1194: Fix support moduleTypes for other sections
  • Loading branch information
Konstantin Kolodii committed Jun 19, 2015
2 parents 9a489af + feddc11 commit 3cae655
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
18 changes: 18 additions & 0 deletions src/components/policy/src/policy/src/cache_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,20 @@ void CacheManager::CheckSnapshotInitialization() {
*(snapshot_->policy_table.module_config.preloaded_pt) = false;
}

struct HandleModuleTypes {
private:
CacheManagerInterface* cache_;
public:
explicit HandleModuleTypes(CacheManagerInterface* cache) : cache_(cache) {}
void operator()(policy_table::ApplicationPolicies::value_type& item) {
const std::string& app_id = item.first;
if (cache_->IsPredataPolicy(app_id) || app_id == kDeviceId) {
LOG4CXX_INFO(logger_, "Clear module types for application " << app_id);
item.second.moduleType = rpc::Optional<policy_table::ModuleTypes>();
}
}
};

void CacheManager::PersistData() {
LOG4CXX_AUTO_TRACE(logger_);
if (backup_.valid()) {
Expand All @@ -592,6 +606,8 @@ void CacheManager::PersistData() {
policy_table::Table copy_pt(*pt_);
cache_lock_.Release();

policy_table::ApplicationPolicies& apps = copy_pt.policy_table.app_policies;
std::for_each(apps.begin(), apps.end(), HandleModuleTypes(this));
backup_->Save(copy_pt);
backup_->SaveUpdateRequired(update_required);

Expand Down Expand Up @@ -995,6 +1011,8 @@ bool CacheManager::LoadFromFile(const std::string& file_name) {

pt_ = new policy_table::Table(&value);
if (pt_->is_valid()) {
policy_table::ApplicationPolicies& apps = pt_->policy_table.app_policies;
std::for_each(apps.begin(), apps.end(), HandleModuleTypes(this));
if (backup_->Save(*pt_)) {
backup_->WriteDb();
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1586,7 +1586,10 @@ bool SQLPTRepresentation::SaveModuleType(const std::string& app_id,
policy_table::ModuleTypes::const_iterator it;
for (it = types.begin(); it != types.end(); ++it) {
query.Bind(0, app_id);
query.Bind(1, std::string(policy_table::EnumToJsonString(*it)));
std::string module(policy_table::EnumToJsonString(*it));
query.Bind(1, module);
LOG4CXX_DEBUG(logger_,
"Module(app: " << app_id << ", type: " << module << ")");
if (!query.Exec() || !query.Reset()) {
LOG4CXX_WARN(logger_, "Incorrect insert into module type.");
return false;
Expand Down

0 comments on commit 3cae655

Please # to comment.