From 726a95bc8c63ddd1c968028b61068ba2c33b994e Mon Sep 17 00:00:00 2001 From: Kazumasa Mitsunari Date: Wed, 22 Aug 2018 21:13:48 +0900 Subject: Add loadLayerSetting Change-Id: I08be64a3b0194175db4b3b7ef259254c10ad038b Signed-off-by: Kazumasa Mitsunari --- src/wm_layer.cpp | 23 +++++++++++++++++++++++ src/wm_layer.hpp | 3 +++ src/wm_layer_control.cpp | 31 +++++++++++++++++++++++++++++-- 3 files changed, 55 insertions(+), 2 deletions(-) diff --git a/src/wm_layer.cpp b/src/wm_layer.cpp index 813684a..365e37d 100644 --- a/src/wm_layer.cpp +++ b/src/wm_layer.cpp @@ -104,6 +104,29 @@ WMLayer::WMLayer() // this->setting = std::make_unique(name, type, begin, end); } +WMLayer::WMLayer(json_object* j) : before_state(), state() +{ + LayerSetting::MANAGEMENT_TYPE t; + const char* layer_name = jh::getStringFromJson(j, "name"); + const char* role = jh::getStringFromJson(j, "role"); + const char* type = jh::getStringFromJson(j, "type"); + int begin = jh::getIntFromJson(j, "id_range_begin"); + int end = jh::getIntFromJson(j, "id_range_end"); + string name = layer_name; + + if (layer_name || type || begin >=0 || end >=0) + { + HMI_ERROR("Parse Error!!"); + } + if(begin > end) + { + HMI_ERROR("INVALID."); + } + string str_type = type; + t = (type == "tile") ? LayerSetting::TILE : LayerSetting::STACK; + this->setting = std::make_unique(name, t, begin, end); +} + unsigned WMLayer::getNewLayerID(const std::string& role) { return this->setting->getNewLayerID(role); diff --git a/src/wm_layer.hpp b/src/wm_layer.hpp index ac74530..6cfd9c2 100644 --- a/src/wm_layer.hpp +++ b/src/wm_layer.hpp @@ -23,6 +23,8 @@ #include #include "wm_error.hpp" +struct json_object; + namespace wm { @@ -79,6 +81,7 @@ class WMLayer { public: WMLayer(); + WMLayer(json_object* j); ~WMLayer() = default; unsigned getNewLayerID(const std::string& role); LayerState getLayerState() const { return before_state; } diff --git a/src/wm_layer_control.cpp b/src/wm_layer_control.cpp index a14c334..b15ebbb 100644 --- a/src/wm_layer_control.cpp +++ b/src/wm_layer_control.cpp @@ -118,6 +118,34 @@ void LayerControl::undoUpdate() {} WMError LayerControl::loadLayerSetting(const string &path) { + HMI_DEBUG("loading WMLayer(Application Containers) Setting from %s", path); + + json_object *json_obj, *json_cfg; + int ret = jh::inputJsonFilie(path.c_str(), &json_obj); + if (0 > ret) + { + HMI_DEBUG("Could not open %s, so use default area information", path.c_str()); + return WMError::FAIL; + } + HMI_INFO("json_obj dump:%s", json_object_get_string(json_obj)); + + if (!json_object_object_get_ex(json_obj, "mappings", &json_cfg)) + { + HMI_ERROR("Parse Error!!"); + return WMError::FAIL; + } + + int len = json_object_array_length(json_cfg); + HMI_DEBUG("json_cfg len:%d", len); + + for (int i = 0; i < len; i++) + { + json_object *json_tmp = json_object_array_get_idx(json_cfg, i); + HMI_DEBUG("> json_tmp dump:%s", json_object_get_string(json_tmp)); + + this->wm_layers.emplace_back(std::make_shared(json_tmp)); + } + return WMError::SUCCESS; } @@ -128,7 +156,7 @@ WMError LayerControl::loadAreaDb(const std::string& path) int ret = jh::inputJsonFilie(path.c_str(), &json_obj); if (0 > ret) { - HMI_DEBUG("Could not open area.db, so use default area information"); + HMI_DEBUG("Could not open %s, so use default area information", path.c_str()); return WMError::FAIL; } HMI_INFO("json_obj dump:%s", json_object_get_string(json_obj)); @@ -143,7 +171,6 @@ WMError LayerControl::loadAreaDb(const std::string& path) int len = json_object_array_length(json_cfg); HMI_DEBUG("json_cfg len:%d", len); - HMI_DEBUG("json_cfg dump:%s", json_object_get_string(json_cfg)); const char *area; for (int i = 0; i < len; i++) -- cgit 1.2.3-korg