Add loadAreaDb
[apps/agl-service-windowmanager.git] / src / wm_layer_control.cpp
index 0d8c924..a14c334 100644 (file)
  * See the License for the specific language governing permissions and\r
  * limitations under the License.\r
  */\r
-\r
 #include <assert.h>\r
-#include "layers.hpp"\r
+#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
 \r
 using std::string;\r
 \r
 namespace wm {\r
 \r
-LayerControl::LayerControl(const string& path) : wm_layers()\r
+static void notification_static(ilmObjectType object,\r
+                            t_ilm_uint id,\r
+                            t_ilm_bool created,\r
+                            void* data)\r
 {\r
-    WMError ret = this->load(path);\r
+    static_cast<LayerControl*>(data)->dispatchILMEvent(object, id, created);\r
+}\r
+\r
+LayerControl::LayerControl(const std::string& root)\r
+{\r
+    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
-LayerControl::~LayerControl()\r
-{}\r
+WMError LayerControl::init()\r
+{\r
+    ilmErrorTypes rc = ilm_init();\r
+    t_ilm_uint num = 0;\r
+    t_ilm_uint *ids;\r
+    int cnt = 0;\r
+\r
+    while (rc != ILM_SUCCESS)\r
+    {\r
+        cnt++;\r
+        if (20 <= cnt)\r
+        {\r
+            HMI_ERROR("Could not connect to compositor");\r
+            goto lc_init_error;\r
+        }\r
+        HMI_ERROR("Wait to start weston ...");\r
+        sleep(1);\r
+        ilm_init();\r
+    }\r
+    if(rc != ILM_SUCCESS) goto lc_init_error;\r
+\r
+    rc = ilm_getScreenIDs(&num, &ids);\r
+\r
+    if(rc != ILM_SUCCESS) goto lc_init_error;\r
+\r
+    for(unsigned i = 0; i < num; i++)\r
+    {\r
+        HMI_INFO("get screen: %d", ids[i]);\r
+    }\r
+    // Currently, 0 is only available\r
+    this->screenID = ids[0];\r
+\r
+    rc = ilm_getPropertiesOfScreen(this->screenID, &this->screen_prop);\r
+\r
+    if(rc != ILM_SUCCESS) goto lc_init_error;\r
+\r
+    // Register Callback from ILM\r
+    ilm_registerNotification(notification_static, this);\r
+\r
+    return WMError::SUCCESS;\r
+\r
+lc_init_error:\r
+    HMI_ERROR("Failed to initialize. Terminate WM");\r
+\r
+    return WMError::FAIL;\r
+}\r
 \r
 unsigned LayerControl::getNewLayerID(const string& role)\r
 {\r
@@ -54,9 +116,83 @@ 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
+}\r
+\r
 } // namespace wm
\ No newline at end of file