From 172c4fb3d449b908baff3111fd171b42935fbb4f Mon Sep 17 00:00:00 2001 From: Yuta Doi Date: Fri, 15 Jun 2018 11:42:37 +0900 Subject: Add new addStateToJson() Signed-off-by: Yuta Doi --- src/policy_manager/policy_manager.cpp | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/src/policy_manager/policy_manager.cpp b/src/policy_manager/policy_manager.cpp index b55a44d..2e4a6f9 100644 --- a/src/policy_manager/policy_manager.cpp +++ b/src/policy_manager/policy_manager.cpp @@ -175,6 +175,28 @@ static void addStateToJson( json_object_object_add(*json_out, key, json_obj); } +static void addStateToJson(const char* layer_name, unsigned int changed, + pm::AreaList area_list, json_object** json_out) { + if ((nullptr == layer_name) || (1 < changed) || (nullptr == json_out)) { + HMI_ERROR("wm:pm", "Invalid argument!!!"); + return; + } + + json_object* json_areas = json_object_new_array(); + json_object* json_tmp; + for (pm::AreaState as : area_list) { + json_tmp = json_object_new_object(); + json_object_object_add(json_tmp, "name", json_object_new_string(as.name.c_str())); + json_object_object_add(json_tmp, "role", json_object_new_string(as.role.c_str())); + json_object_array_add(json_areas, json_tmp); + } + + json_object_object_add(*json_out, "name", json_object_new_string(layer_name)); + json_object_object_add(*json_out, "changed", json_object_new_boolean(changed)); + json_object_object_add(*json_out, "areas", json_areas); +} + + static int checkPolicyEntry(int event, uint64_t delay_ms, const char* role); static int checkPolicy(sd_event_source *source, void *data) { HMI_DEBUG("wm:pm", "Call"); @@ -516,12 +538,16 @@ static int checkPolicy(sd_event_source *source, void *data) { // { // "homescreen": { - // "is_changed": , - // "state": + // "changed": , + // "areas": [ + // { + // "name":, + // "role": + // }. + // ... + // ] // } // }, - // ] - // } json_tmp = json_object_new_object(); addStateToJson("homescreen", crr_state.layer[stm::gStmLayerNoHomescreen].is_changed, -- cgit 1.2.3-korg