2 * Samsung Ukraine R&D Center (SRK under a contract between)
3 * LLC "Samsung Electronics Co", Ltd (Seoul, Republic of Korea)
4 * Copyright (C) 2017 Samsung Electronics Co., Ltd. All rights reserved.
7 * @file iot_tvext_enforce.cpp
8 * @brief Implementation of TV 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>
14 #include "iot_tvext_enforce.h"
16 #include "dpm_api_mapper.h"
20 #define TAG "nmdaemon"
27 TvExtPolicyEnforce::TvExtPolicyEnforce(PolicyEnforce& enforce)
30 LOG_D(TAG, "Register tvext policy enforce class");
31 m_enforce.RegisterGroup(static_cast<IPolicyGroupEnforce*>(this), std::string("tv-extension"));
34 TvExtPolicyEnforce::~TvExtPolicyEnforce()
38 bool TvExtPolicyEnforce::Init()
40 LOG_D(TAG, "Init tvext policy applier");
45 void TvExtPolicyEnforce::Deinit()
47 LOG_D(TAG, "De-Init tvext policy applier");
50 bool TvExtPolicyEnforce::ParseGroup(Json::Value& groupList)
52 LOG_D(TAG, "...Start tvext policies parsing and applying...");
54 dpm_api::Mapper mapper;
55 bool first_time = true;
57 for (auto& node : groupList) {
58 std::string name = node.get("name", "").asString();
59 int state = node.get("state", 0).asInt();
60 Json::Value items = node.get("items", "");
63 LOG_E(TAG, "skiping policy without name.");
67 dpm_api::ErrorCode err;
69 std::vector<std::string> v;
70 for (auto& item : items) {
71 v.push_back(item.asString());
74 LOG_D(TAG, " Enforce policy [%s] to state %d", name.c_str(), state);
80 std::this_thread::sleep_for(std::chrono::seconds(1));
83 LOG_D(TAG, " mapper apply %s to state %d", name.c_str(), state);
85 err = mapper.apply(name, state, v);
87 if (err != dpm_api::SUCCESS) {
88 LOG_E(TAG, " Enforce policy [%s] error: %s", name.c_str(), mapper.getErrorString(err));
90 LOG_D(TAG, " Enforce policy [%s] ok", name.c_str());
92 } catch (std::exception& e) {
93 LOG_E(TAG, " Enforce policy [%s] exception: %s", name.c_str(), e.what());
96 LOG_D(TAG, "...Finish tvext policies parsing and applying...");
101 TvExtPolicyEnforce tvextEnforce(PolicyEnforce::GetInstance());