diff options
-rw-r--r-- | src/app.cpp | 10 | ||||
-rw-r--r-- | src/layout_manager/db/layout.db | 32 | ||||
-rw-r--r-- | src/policy_manager/policy_manager.cpp | 286 | ||||
-rw-r--r-- | src/policy_manager/policy_manager.hpp | 3 |
4 files changed, 314 insertions, 17 deletions
diff --git a/src/app.cpp b/src/app.cpp index 1e7a617..a480e49 100644 --- a/src/app.cpp +++ b/src/app.cpp @@ -523,7 +523,15 @@ void App::allocateWindowResource(char const *event, char const *drawing_name, if (nullptr != new_area) { json_object_object_add(json_in, "area", json_object_new_string(new_area)); } - rm::g_new_role = std::string(new_role); // TODO: workaround + + // TODO: workaround + if (nullptr != new_role) { + rm::g_new_role = std::string(new_role); + } + else { + rm::g_new_role = std::string(""); + } + this->pm_.inputEvent(json_in); // Release json_object diff --git a/src/layout_manager/db/layout.db b/src/layout_manager/db/layout.db index 02139e6..0945bcd 100644 --- a/src/layout_manager/db/layout.db +++ b/src/layout_manager/db/layout.db @@ -6,7 +6,7 @@ "areas": [ { "name": "pop_up", - "role": "incomming_call" + "category": "incomming_call" } ] }, @@ -16,7 +16,7 @@ "areas": [ { "name": "system_alert", - "role": "system_alert" + "category": "system_alert" } ] }, @@ -26,7 +26,7 @@ "areas": [ { "name": "normal", - "role": "map" + "category": "map" } ] }, @@ -36,7 +36,7 @@ "areas": [ { "name": "split.main", - "role": "map" + "category": "map" }, { "name": "split.sub", @@ -50,7 +50,7 @@ "areas": [ { "name": "fullscreen", - "role": "map" + "category": "map" } ] }, @@ -94,7 +94,7 @@ "areas": [ { "name": "fullscreen", - "role": "homescreen" + "category": "homescreen" } ] }, @@ -104,7 +104,7 @@ "areas": [ { "name": "system_alert", - "role": "system_alert" + "category": "system_alert" } ] }, @@ -114,7 +114,7 @@ "areas": [ { "name": "restriction.normal", - "role": "restriction" + "category": "restriction" } ] }, @@ -124,7 +124,7 @@ "areas": [ { "name": "restriction.split.main", - "role": "restriction" + "category": "restriction" } ] }, @@ -134,7 +134,7 @@ "areas": [ { "name": "restriction.split.sub", - "role": "restriction" + "category": "restriction" } ] }, @@ -144,7 +144,7 @@ "areas": [ { "name": "software_keyboard", - "role": "software_keyboard" + "category": "software_keyboard" } ] }, @@ -154,7 +154,7 @@ "areas": [ { "name": "normal", - "role": "map" + "category": "map" } ] }, @@ -164,11 +164,11 @@ "areas": [ { "name": "split.main", - "role": "map" + "category": "map" }, { "name": "split.sub", - "role": "general" + "category": "general" } ] }, @@ -178,7 +178,7 @@ "areas": [ { "name": "normal", - "role": "general" + "category": "general" } ] }, @@ -188,7 +188,7 @@ "areas": [ { "name": "fullscreen", - "role": "homescreen" + "category": "homescreen" } ] } diff --git a/src/policy_manager/policy_manager.cpp b/src/policy_manager/policy_manager.cpp index 6d25574..73f9350 100644 --- a/src/policy_manager/policy_manager.cpp +++ b/src/policy_manager/policy_manager.cpp @@ -43,6 +43,7 @@ std::map<int, struct sd_event_source*> event_source_list; PolicyManager::CallbackTable callback; LayersState g_prv_layers; LayersState g_crr_layers; +LayoutState g_default_layout_state; } // namespace pm @@ -85,6 +86,13 @@ int PolicyManager::initialize() { return ret; } + // Load layout.db + ret = this->loadLayoutDb(); + if (0 > ret) { + HMI_ERROR("wm:pm", "Load layout.db Error!!"); + return ret; + } + // Initialize current/previous state of layers pm::AppAttribute init_app; pm::AreasState init_area; @@ -662,6 +670,124 @@ int PolicyManager::loadRoleDb() { return 0; } +extern const char* kDefaultLayoutDb; +int PolicyManager::loadLayoutDb() { + HMI_DEBUG("wm:lm", "Call"); + + // Get afm application installed dir + char const *afm_app_install_dir = getenv("AFM_APP_INSTALL_DIR"); + HMI_DEBUG("wm:pm", "afm_app_install_dir:%s", afm_app_install_dir); + + std::string file_name; + if (!afm_app_install_dir) { + HMI_ERROR("wm:pm", "AFM_APP_INSTALL_DIR is not defined"); + } + else { + file_name = std::string(afm_app_install_dir) + std::string("/etc/layout.db"); + } + + // Load layout.db + json_object* json_obj; + int ret = this->inputJsonFilie(file_name.c_str(), &json_obj); + if (0 > ret) { + HMI_DEBUG("wm:pm", "Could not open layout.db, so use default layout information"); + json_obj = json_tokener_parse(kDefaultLayoutDb); + } + HMI_DEBUG("wm:pm", "json_obj dump:%s", json_object_get_string(json_obj)); + + // Perse layouts + HMI_DEBUG("wm:pm", "Perse layouts"); + json_object* json_cfg; + if (!json_object_object_get_ex(json_obj, "layouts", &json_cfg)) { + HMI_ERROR("wm:pm", "Parse Error!!"); + return -1; + } + + int len = json_object_array_length(json_cfg); + HMI_DEBUG("wm:pm", "json_cfg len:%d", len); + HMI_DEBUG("wm:pm", "json_cfg dump:%s", json_object_get_string(json_cfg)); + + const char* layout; + const char* role; + const char* category; + for (int i=0; i<len; i++) { + json_object* json_tmp = json_object_array_get_idx(json_cfg, i); + + layout = this->getStringFromJson(json_tmp, "name"); + if (nullptr == layout) { + HMI_ERROR("wm:pm", "Parse Error!!"); + return -1; + } + HMI_DEBUG("wm:pm", "> layout:%s", layout); + + json_object* json_area_array; + if (!json_object_object_get_ex(json_tmp, "areas", &json_area_array)) { + HMI_ERROR("wm:pm", "Parse Error!!"); + return -1; + } + + int len_area = json_object_array_length(json_area_array); + HMI_DEBUG("wm:pm", "json_area_array len:%d", len_area); + HMI_DEBUG("wm:pm", "json_area_array dump:%s", json_object_get_string(json_area_array)); + + pm::AreasState areas_state; + for (int j=0; j<len_area; j++) { + json_object* json_area = json_object_array_get_idx(json_area_array, j); + + // Get area name + const char* area = this->getStringFromJson(json_area, "name"); + if (nullptr == area) { + HMI_ERROR("wm:pm", "Parse Error!!"); + return -1; + } + HMI_DEBUG("wm:pm", ">> area:%s", area); + + // Get app attribute of the area + pm::AppAttribute app_attribute; + category = this->getStringFromJson(json_area, "category"); + if (nullptr == category) { + HMI_ERROR("wm:pm", "Parse Error!!"); + return -1; + } + app_attribute["category"] = std::string(category); + HMI_DEBUG("wm:pm", ">>> category:%s", category); + + role = this->getStringFromJson(json_area, "role"); + if (nullptr != role) { + // Role is NOT essential here + app_attribute["role"] = std::string(role); + HMI_DEBUG("wm:pm", ">>> role:%s", role); + } + + areas_state[area] = app_attribute; + } + + pm::g_default_layout_state[layout] = areas_state; + } + + // Check + for(auto itr_layout = pm::g_default_layout_state.begin(); + itr_layout != pm::g_default_layout_state.end(); ++itr_layout) { + HMI_DEBUG("wm:pm", ">>> layout:%s", itr_layout->first.c_str()); + + for (auto itr_area = itr_layout->second.begin(); + itr_area != itr_layout->second.end(); ++itr_area) { + HMI_DEBUG("wm:pm", ">>> >>> area:%s", itr_area->first.c_str()); + + for (auto itr_role = itr_area->second.begin(); + itr_role != itr_area->second.end(); ++itr_role) { + HMI_DEBUG("wm:pm", ">>> >>> >>> attribute:%s, name:%s", + itr_role->first.c_str(), itr_role->second.c_str()); + } + } + } + + // Release json_object + json_object_put(json_obj); + + return 0; +} + // TODO: // This function will be removed because json_helper has same function. // json_helper should be library. @@ -802,3 +928,163 @@ const char* kDefaultRoleDb = "{ \ } \ ] \ }"; + + +const char* kDefaultLayoutDb = "{ \ + \"layouts\": [ \ + { \ + \"name\": \"pu\", \ + \"layer\": \"on_screen\", \ + \"areas\": [ \ + { \ + \"name\": \"pop_up\", \ + \"role\": \"incomming_call\" \ + } \ + ] \ + }, \ + { \ + \"name\": \"sa\", \ + \"layer\": \"on_screen\", \ + \"areas\": [ \ + { \ + \"name\": \"system_alert\", \ + \"role\": \"system_alert\" \ + } \ + ] \ + }, \ + { \ + \"name\": \"m1\", \ + \"layer\": \"apps\", \ + \"areas\": [ \ + { \ + \"name\": \"normal\", \ + \"role\": \"map\" \ + } \ + ] \ + }, \ + { \ + \"name\": \"m2\", \ + \"layer\": \"apps\", \ + \"areas\": [ \ + { \ + \"name\": \"split.main\", \ + \"role\": \"map\" \ + }, \ + { \ + \"name\": \"split.sub\", \ + \"category\": \"hvac\" \ + } \ + ] \ + }, \ + { \ + \"name\": \"mf\", \ + \"layer\": \"apps\", \ + \"areas\": [ \ + { \ + \"name\": \"full\", \ + \"role\": \"map\" \ + } \ + ] \ + }, \ + { \ + \"name\": \"s1\", \ + \"layer\": \"apps\", \ + \"areas\": [ \ + { \ + \"name\": \"normal\", \ + \"category\": \"splitable\" \ + } \ + ] \ + }, \ + { \ + \"name\": \"s2\", \ + \"layer\": \"apps\", \ + \"areas\": [ \ + { \ + \"name\": \"split.main\", \ + \"category\": \"splitable\" \ + }, \ + { \ + \"name\": \"split.sub\", \ + \"category\": \"splitable\" \ + } \ + ] \ + }, \ + { \ + \"name\": \"g\", \ + \"layer\": \"apps\", \ + \"areas\": [ \ + { \ + \"name\": \"normal\", \ + \"category\": \"general\" \ + } \ + ] \ + }, \ + { \ + \"name\": \"hs\", \ + \"layer\": \"homescreen\", \ + \"areas\": [ \ + { \ + \"name\": \"full\", \ + \"role\": \"homescreen\" \ + } \ + ] \ + } \ + ], \ + \"areas\": [ \ + { \ + \"name\": \"normal\", \ + \"rect\": { \ + \"x\": 0, \ + \"y\": 218, \ + \"w\": 1080, \ + \"h\": 1488 \ + } \ + }, \ + { \ + \"name\": \"split.main\", \ + \"rect\": { \ + \"x\": 0, \ + \"y\": 218, \ + \"w\": 1080, \ + \"h\": 744 \ + } \ + }, \ + { \ + \"name\": \"split.sub\", \ + \"rect\": { \ + \"x\": 0, \ + \"y\": 962, \ + \"w\": 1080, \ + \"h\": 744 \ + } \ + }, \ + { \ + \"name\": \"full\", \ + \"rect\": { \ + \"x\": 0, \ + \"y\": 0, \ + \"w\": 1080, \ + \"h\": 1920 \ + } \ + }, \ + { \ + \"name\": \"pop_up\", \ + \"rect\": { \ + \"x\": 0, \ + \"y\": 640, \ + \"w\": 1080, \ + \"h\": 640 \ + } \ + }, \ + { \ + \"name\": \"system_alert\", \ + \"rect\": { \ + \"x\": 0, \ + \"y\": 640, \ + \"w\": 1080, \ + \"h\": 640 \ + } \ + } \ + ] \ +}"; diff --git a/src/policy_manager/policy_manager.hpp b/src/policy_manager/policy_manager.hpp index 9a40d7c..f026edd 100644 --- a/src/policy_manager/policy_manager.hpp +++ b/src/policy_manager/policy_manager.hpp @@ -82,6 +82,9 @@ private: // Load role.db int loadRoleDb(); + // Load layout.db + int loadLayoutDb(); + const char* getStringFromJson(json_object* obj, const char* key); int inputJsonFilie(const char* file, json_object** obj); std::vector<std::string> parseString(std::string str, char delimiter); |