From ca66798559857e0884872f2dbb32a2a445afda3e Mon Sep 17 00:00:00 2001 From: Kazumasa Mitsunari Date: Wed, 22 Aug 2018 20:16:16 +0900 Subject: Add loadAreaDb Change-Id: Iccbb3730395832b1f0d3301f3866337211cf5907 Signed-off-by: Kazumasa Mitsunari --- src/wm_layer_control.cpp | 76 +++++++++++++++++++++++++++++++++++++++++++++++- src/wm_layer_control.hpp | 5 +++- 2 files changed, 79 insertions(+), 2 deletions(-) diff --git a/src/wm_layer_control.cpp b/src/wm_layer_control.cpp index 5f23af1..a14c334 100644 --- a/src/wm_layer_control.cpp +++ b/src/wm_layer_control.cpp @@ -17,6 +17,7 @@ #include #include "wm_layer_control.hpp" #include "wm_layer.hpp" +#include "json_helper.hpp" #define LC_AREA_PATH "/etc/area.db" #define LC_LAYER_SETTING_PATH "/etc/layer_setting.json" @@ -38,7 +39,11 @@ LayerControl::LayerControl(const std::string& root) string area_path = root + LC_AREA_PATH; string layer_path= root + LC_LAYER_SETTING_PATH; // load layers.setting.json + WMError ret = this->loadLayerSetting(layer_path); + assert(ret == WMError::SUCCESS); // load area.db + ret = this->loadAreaDb(area_path); + assert(ret == WMError::SUCCESS); } WMError LayerControl::init() @@ -111,11 +116,80 @@ void LayerControl::commitChange() {} void LayerControl::undoUpdate() {} -WMError LayerControl::load(const string &path) +WMError LayerControl::loadLayerSetting(const string &path) { return WMError::SUCCESS; } +WMError LayerControl::loadAreaDb(const std::string& path) +{ + // Load area.db + json_object *json_obj; + int ret = jh::inputJsonFilie(path.c_str(), &json_obj); + if (0 > ret) + { + HMI_DEBUG("Could not open area.db, so use default area information"); + return WMError::FAIL; + } + HMI_INFO("json_obj dump:%s", json_object_get_string(json_obj)); + + // Perse areas + json_object *json_cfg; + if (!json_object_object_get_ex(json_obj, "areas", &json_cfg)) + { + HMI_ERROR("Parse Error!!"); + return WMError::FAIL; + } + + 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++) + { + json_object *json_tmp = json_object_array_get_idx(json_cfg, i); + HMI_DEBUG("> json_tmp dump:%s", json_object_get_string(json_tmp)); + + area = jh::getStringFromJson(json_tmp, "name"); + if (nullptr == area) + { + HMI_ERROR("Parse Error!!"); + return WMError::FAIL; + } + HMI_DEBUG("> area:%s", area); + + json_object *json_rect; + if (!json_object_object_get_ex(json_tmp, "rect", &json_rect)) + { + HMI_ERROR("Parse Error!!"); + return WMError::FAIL; + } + HMI_DEBUG("> json_rect dump:%s", json_object_get_string(json_rect)); + + struct rect area_size; + area_size.x = jh::getIntFromJson(json_rect, "x"); + area_size.y = jh::getIntFromJson(json_rect, "y"); + area_size.w = jh::getIntFromJson(json_rect, "w"); + area_size.h = jh::getIntFromJson(json_rect, "h"); + + this->area2size[area] = area_size; + } + + // Check + for (const auto& itr : this->area2size) + { + HMI_DEBUG("area:%s x:%d y:%d w:%d h:%d", + itr.first.c_str(), itr.second.x, itr.second.y, + itr.second.w, itr.second.h); + } + + // Release json_object + json_object_put(json_obj); + + return WMError::SUCCESS; +} + void LayerControl::dispatchILMEvent(ilmObjectType object, t_ilm_uint id, t_ilm_bool created) { ; diff --git a/src/wm_layer_control.hpp b/src/wm_layer_control.hpp index 18f7359..d8d3273 100644 --- a/src/wm_layer_control.hpp +++ b/src/wm_layer_control.hpp @@ -17,6 +17,7 @@ #include #include #include +#include #include #include "wm_error.hpp" #include "util.hpp" @@ -46,8 +47,10 @@ class LayerControl // Don't use this function. void dispatchILMEvent(ilmObjectType object, t_ilm_uint id, t_ilm_bool created); private: - WMError load(const std::string& path); + WMError loadLayerSetting(const std::string& path); + WMError loadAreaDb(const std::string& path); std::vector> wm_layers; + std::unordered_map area2size; unsigned screenID; struct ilmScreenProperties screen_prop; }; -- cgit 1.2.3-korg