diff options
Diffstat (limited to 'src/policy_manager/policy_manager.cpp')
-rw-r--r-- | src/policy_manager/policy_manager.cpp | 286 |
1 files changed, 286 insertions, 0 deletions
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 \ + } \ + } \ + ] \ +}"; |