Add loadAreaDb
authorKazumasa Mitsunari <knimitz@witz-inc.co.jp>
Wed, 22 Aug 2018 11:16:16 +0000 (20:16 +0900)
committerKazumasa Mitsunari <knimitz@witz-inc.co.jp>
Wed, 22 Aug 2018 11:16:16 +0000 (20:16 +0900)
Change-Id: Iccbb3730395832b1f0d3301f3866337211cf5907
Signed-off-by: Kazumasa Mitsunari <knimitz@witz-inc.co.jp>
src/wm_layer_control.cpp
src/wm_layer_control.hpp

index 5f23af1..a14c334 100644 (file)
@@ -17,6 +17,7 @@
 #include <unistd.h>\r
 #include "wm_layer_control.hpp"\r
 #include "wm_layer.hpp"\r
+#include "json_helper.hpp"\r
 \r
 #define LC_AREA_PATH "/etc/area.db"\r
 #define LC_LAYER_SETTING_PATH "/etc/layer_setting.json"\r
@@ -38,7 +39,11 @@ LayerControl::LayerControl(const std::string& root)
     string area_path = root + LC_AREA_PATH;\r
     string layer_path= root + LC_LAYER_SETTING_PATH;\r
     // load layers.setting.json\r
+    WMError ret = this->loadLayerSetting(layer_path);\r
+    assert(ret == WMError::SUCCESS);\r
     // load area.db\r
+    ret = this->loadAreaDb(area_path);\r
+    assert(ret == WMError::SUCCESS);\r
 }\r
 \r
 WMError LayerControl::init()\r
@@ -111,11 +116,80 @@ void LayerControl::commitChange() {}
 \r
 void LayerControl::undoUpdate() {}\r
 \r
-WMError LayerControl::load(const string &path)\r
+WMError LayerControl::loadLayerSetting(const string &path)\r
 {\r
     return WMError::SUCCESS;\r
 }\r
 \r
+WMError LayerControl::loadAreaDb(const std::string& path)\r
+{\r
+    // Load area.db\r
+    json_object *json_obj;\r
+    int ret = jh::inputJsonFilie(path.c_str(), &json_obj);\r
+    if (0 > ret)\r
+    {\r
+        HMI_DEBUG("Could not open area.db, so use default area information");\r
+        return WMError::FAIL;\r
+    }\r
+    HMI_INFO("json_obj dump:%s", json_object_get_string(json_obj));\r
+\r
+    // Perse areas\r
+    json_object *json_cfg;\r
+    if (!json_object_object_get_ex(json_obj, "areas", &json_cfg))\r
+    {\r
+        HMI_ERROR("Parse Error!!");\r
+        return WMError::FAIL;\r
+    }\r
+\r
+    int len = json_object_array_length(json_cfg);\r
+    HMI_DEBUG("json_cfg len:%d", len);\r
+    HMI_DEBUG("json_cfg dump:%s", json_object_get_string(json_cfg));\r
+\r
+    const char *area;\r
+    for (int i = 0; i < len; i++)\r
+    {\r
+        json_object *json_tmp = json_object_array_get_idx(json_cfg, i);\r
+        HMI_DEBUG("> json_tmp dump:%s", json_object_get_string(json_tmp));\r
+\r
+        area = jh::getStringFromJson(json_tmp, "name");\r
+        if (nullptr == area)\r
+        {\r
+            HMI_ERROR("Parse Error!!");\r
+            return WMError::FAIL;\r
+        }\r
+        HMI_DEBUG("> area:%s", area);\r
+\r
+        json_object *json_rect;\r
+        if (!json_object_object_get_ex(json_tmp, "rect", &json_rect))\r
+        {\r
+            HMI_ERROR("Parse Error!!");\r
+            return WMError::FAIL;\r
+        }\r
+        HMI_DEBUG("> json_rect dump:%s", json_object_get_string(json_rect));\r
+\r
+        struct rect area_size;\r
+        area_size.x = jh::getIntFromJson(json_rect, "x");\r
+        area_size.y = jh::getIntFromJson(json_rect, "y");\r
+        area_size.w = jh::getIntFromJson(json_rect, "w");\r
+        area_size.h = jh::getIntFromJson(json_rect, "h");\r
+\r
+        this->area2size[area] = area_size;\r
+    }\r
+\r
+    // Check\r
+    for (const auto& itr : this->area2size)\r
+    {\r
+        HMI_DEBUG("area:%s x:%d y:%d w:%d h:%d",\r
+                  itr.first.c_str(), itr.second.x, itr.second.y,\r
+                  itr.second.w, itr.second.h);\r
+    }\r
+\r
+    // Release json_object\r
+    json_object_put(json_obj);\r
+\r
+    return WMError::SUCCESS;\r
+}\r
+\r
 void LayerControl::dispatchILMEvent(ilmObjectType object, t_ilm_uint id, t_ilm_bool created)\r
 {\r
     ;\r
index 18f7359..d8d3273 100644 (file)
@@ -17,6 +17,7 @@
 #include <string>\r
 #include <memory>\r
 #include <vector>\r
+#include <unordered_map>\r
 #include <ilm/ilm_control.h>\r
 #include "wm_error.hpp"\r
 #include "util.hpp"\r
@@ -46,8 +47,10 @@ class LayerControl
     // Don't use this function.\r
     void dispatchILMEvent(ilmObjectType object, t_ilm_uint id, t_ilm_bool created);\r
   private:\r
-    WMError load(const std::string& path);\r
+    WMError loadLayerSetting(const std::string& path);\r
+    WMError loadAreaDb(const std::string& path);\r
     std::vector<std::shared_ptr<WMLayer>> wm_layers;\r
+    std::unordered_map<std::string, struct rect> area2size;\r
     unsigned screenID;\r
     struct ilmScreenProperties screen_prop;\r
 };\r