2 * Samsung Ukraine R&D Center (SRK under a contract between)
3 * LLC "Samsung Electronics Co", Ltd (Seoul, Republic of Korea)
4 * Copyright (C) 2018 Samsung Electronics Co., Ltd. All rights reserved.
7 * @file common_enforce.cpp
8 * @brief Implementation of common policy
9 * @date Created Jul 05, 2016
10 * @author Mail to: <A HREF="mailto:a.volkov@samsung.com">Aleksey Volkov, a.volkov@samsung.com</A>
15 #include "common_enforce.h"
17 #include "samonitor_tag.h"
18 #include "dpm_api_mapper.h"
24 CommonPolicyEnforce::CommonPolicyEnforce(PolicyEnforce& enforce)
27 LOG_D(TAG, "Register common policy enforce class");
28 m_enforce.RegisterGroup(static_cast<IPolicyGroupEnforce*>(this), std::string("common-policies"));
31 CommonPolicyEnforce::~CommonPolicyEnforce()
35 bool CommonPolicyEnforce::Init(/*PolicyContext& context*/)
37 LOG_D(TAG, "Init common policy applier");
42 void CommonPolicyEnforce::Deinit()
44 LOG_D(TAG, "De-Init common policy applier");
47 bool CommonPolicyEnforce::ParseGroup(Json::Value& groupList)
49 LOG_D(TAG, "...Start common policies parsing and applying...");
51 dpm_api::Mapper mapper;
52 bool first_time = true;
54 for (auto& node : groupList) {
55 std::string name = node.get("name", "").asString();
56 int state = node.get("state", 0).asInt();
57 Json::Value items = node.get("items", "");
60 LOG_E(TAG, "skiping policy without name.");
64 dpm_api::ErrorCode err;
66 std::vector<std::string> v;
67 for (auto& item : items) {
68 v.push_back(item.asString());
71 LOG_D(TAG, " Enforce policy [%s] to state %d", name.c_str(), state);
77 std::this_thread::sleep_for(std::chrono::seconds(1));
80 LOG_D(TAG, " mapper apply %s to state %d", name.c_str(), state);
82 err = mapper.apply(name, state, v);
84 if (err != dpm_api::SUCCESS) {
85 LOG_E(TAG, " Enforce policy [%s] error: %s", name.c_str(), mapper.getErrorString(err));
87 LOG_D(TAG, " Enforce policy [%s] ok", name.c_str());
89 } catch (std::exception& e) {
90 LOG_E(TAG, " Enforce policy [%s] exception: %s", name.c_str(), e.what());
93 LOG_D(TAG, "...Finish common policies parsing and applying...");
98 CommonPolicyEnforce commonEnforce(PolicyEnforce::GetInstance());