Add loadLayerSetting
authorKazumasa Mitsunari <knimitz@witz-inc.co.jp>
Wed, 22 Aug 2018 12:13:48 +0000 (21:13 +0900)
committerKazumasa Mitsunari <knimitz@witz-inc.co.jp>
Wed, 22 Aug 2018 12:13:48 +0000 (21:13 +0900)
Change-Id: I08be64a3b0194175db4b3b7ef259254c10ad038b
Signed-off-by: Kazumasa Mitsunari <knimitz@witz-inc.co.jp>
src/wm_layer.cpp
src/wm_layer.hpp
src/wm_layer_control.cpp

index 813684a..365e37d 100644 (file)
@@ -104,6 +104,29 @@ WMLayer::WMLayer()
     // this->setting = std::make_unique<LayerSetting>(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<LayerSetting>(name, t, begin, end);
+}
+
 unsigned WMLayer::getNewLayerID(const std::string& role)
 {
     return this->setting->getNewLayerID(role);
index ac74530..6cfd9c2 100644 (file)
@@ -23,6 +23,8 @@
 #include <memory>
 #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; }
index a14c334..b15ebbb 100644 (file)
@@ -118,6 +118,34 @@ void LayerControl::undoUpdate() {}
 \r
 WMError LayerControl::loadLayerSetting(const string &path)\r
 {\r
+    HMI_DEBUG("loading WMLayer(Application Containers) Setting from %s", path);\r
+\r
+    json_object *json_obj, *json_cfg;\r
+    int ret = jh::inputJsonFilie(path.c_str(), &json_obj);\r
+    if (0 > ret)\r
+    {\r
+        HMI_DEBUG("Could not open %s, so use default area information", path.c_str());\r
+        return WMError::FAIL;\r
+    }\r
+    HMI_INFO("json_obj dump:%s", json_object_get_string(json_obj));\r
+\r
+    if (!json_object_object_get_ex(json_obj, "mappings", &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
+\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
+        this->wm_layers.emplace_back(std::make_shared<WMLayer>(json_tmp));\r
+    }\r
+\r
     return WMError::SUCCESS;\r
 }\r
 \r
@@ -128,7 +156,7 @@ WMError LayerControl::loadAreaDb(const std::string& path)
     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
+        HMI_DEBUG("Could not open %s, so use default area information", path.c_str());\r
         return WMError::FAIL;\r
     }\r
     HMI_INFO("json_obj dump:%s", json_object_get_string(json_obj));\r
@@ -143,7 +171,6 @@ WMError LayerControl::loadAreaDb(const std::string& path)
 \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