From 36098a64cf5bcac3d721f126e3d809674badc110 Mon Sep 17 00:00:00 2001 From: Yuta Doi Date: Fri, 15 Jun 2018 20:40:22 +0900 Subject: Modify format of layout information and process for updating layout and delete unnecessary process Change-Id: I266cbc684c28b49d9855db851a56afbff3588b35 Signed-off-by: Yuta Doi --- src/layout_manager/layout.cpp | 348 +----------------------------------------- src/layout_manager/layout.hpp | 19 --- 2 files changed, 2 insertions(+), 365 deletions(-) (limited to 'src/layout_manager') diff --git a/src/layout_manager/layout.cpp b/src/layout_manager/layout.cpp index cd81d8f..49381cc 100644 --- a/src/layout_manager/layout.cpp +++ b/src/layout_manager/layout.cpp @@ -37,276 +37,13 @@ int LayoutManager::initialize() { return ret; } - TypeLayouts layout; - TypeAreas area; - TypeRolCtg rol_ctg; - - rol_ctg["none"] = "none"; - area["none"] = rol_ctg; - layout["none"] = area; - - this->prv_layers_["on_screen"] = layout; - this->prv_layers_["apps"] = layout; - this->prv_layers_["homescreen"] = layout; - this->prv_layers_["restriction"] = layout; - - this->crr_layers_["on_screen"] = layout; - this->crr_layers_["apps"] = layout; - this->crr_layers_["homescreen"] = layout; - this->crr_layers_["restriction"] = layout; - - this->prv_layers_car_stop_["on_screen"] = layout; - this->prv_layers_car_stop_["apps"] = layout; - this->prv_layers_car_stop_["homescreen"] = layout; - this->prv_layers_car_stop_["restriction"] = layout; - - return ret; -} - -bool LayoutManager::updateLayout(json_object* obj, - const char* new_role, const char* category) { - HMI_DEBUG("wm:lm", "Call"); - - bool ret = false; - - // Check car state change - json_object* json_car; - if (!json_object_object_get_ex(obj, "car", &json_car)) { - HMI_ERROR("wm:lm", "Parse Error!!"); - return -1; - } - - json_bool is_car_state_changed; - std::string car_state = ""; - is_car_state_changed = jh::getBoolFromJson(json_car, "is_changed"); - if (is_car_state_changed) { - // If car state is changed, get car state - car_state = jh::getStringFromJson(json_car, "state"); - } - - // Check restriction mode change - json_object* json_restriction_mode; - if (!json_object_object_get_ex(obj, "restriction_mode", &json_restriction_mode)) { - HMI_ERROR("wm:lm", "Parse Error!!"); - return -1; - } - - json_bool is_restriction_mode_changed; - std::string restriction_mode = ""; - is_restriction_mode_changed = jh::getBoolFromJson(json_restriction_mode, "is_changed"); - if (is_restriction_mode_changed) { - // If restriction mode is changed, get restriction mode - restriction_mode = jh::getStringFromJson(json_restriction_mode, "state"); - } - - // Update layout of all layers - json_object* json_layers; - if (!json_object_object_get_ex(obj, "layers", &json_layers)) { - HMI_ERROR("wm:lm", "Parse Error!!"); - return -1; - } - - int len = json_object_array_length(json_layers); - HMI_DEBUG("wm:lm", "json_layers len:%d", len); - HMI_DEBUG("wm:lm", "json_layers dump:%s", json_object_get_string(json_layers)); - - for (int i=0; iprv_layers_[layer] = this->crr_layers_[layer]; - std::string prv_layout_name = this->prv_layers_[layer].begin()->first; - -#if 1 - // If restriction mode is changed off -> on, - // store current state for state of restriction mode off - if ((is_restriction_mode_changed) && ("restriction_mode_on" == restriction_mode)) { - HMI_DEBUG("wm:lm", "Store current state for state of restriction mode off"); - this->prv_layers_car_stop_[layer] = this->crr_layers_[layer]; - } -#else - // If car state is changed car_stop -> car_run, - // store current state for state of car stop - if ((is_car_state_changed) && ("car_run" == car_state)) { - HMI_DEBUG("wm:lm", "Store current state for state of car stop"); - this->prv_layers_car_stop_[layer] = this->crr_layers_[layer]; - } -#endif - - json_object* json_is_changed; - if (!json_object_object_get_ex(json_layer, "is_changed", &json_is_changed)) { - HMI_ERROR("wm:lm", "Not found key \"is_changed\""); - return false; - } - - // If layer state is changed - if (json_object_get_boolean(json_is_changed)) { - // Set layout changed flag - this->is_layout_changed_[layer] = true; - - json_object* json_state; - if (!json_object_object_get_ex(json_layer, "state", &json_state)) { - HMI_ERROR("wm:lm", "Not found key \"state\""); - return false; - } - - const char* crr_layout_name = json_object_get_string(json_state); - HMI_DEBUG("wm:lm", "crr state: %s", crr_layout_name); - - TypeLayouts crr_layout; -#if 1 - if ((is_restriction_mode_changed) && ("restriction_mode_off" == restriction_mode)) { - // If restriction mode is changed on -> off, - // restore state of restriction mode off - HMI_DEBUG("wm:lm", "Restriction mode is changed on -> off, so restore state of restriction mode off"); - crr_layout = this->prv_layers_car_stop_[layer]; -#else - if ((is_car_state_changed) && ("car_stop" == car_state)) { - // If car state is changed car_run -> car_stop, - // restore state of car stop - HMI_DEBUG("wm:lm", "Car state is changed car_run -> car_stop, so restore state of car stop"); - crr_layout = this->prv_layers_car_stop_[layer]; -#endif - } - else if ("none" == std::string(crr_layout_name)) { - // If current layout is "none", - // current areas is set with "none" - HMI_DEBUG("wm:lm", "Current layout is \"none\""); - TypeAreas area; - TypeRolCtg rol_ctg; - rol_ctg["none"] = "none"; - area["none"] = rol_ctg; - crr_layout["none"] = area; - } - else { - if (std::string(crr_layout_name) == prv_layout_name) { - // If previous layout is same with current, - // previous areas are copied to current - HMI_DEBUG("wm:lm", "Previous layout is same with current"); - crr_layout[crr_layout_name] = this->prv_layers_[layer][crr_layout_name]; - } - else { - // If previous layout is NOT same with current, - // current areas is set with default value - HMI_DEBUG("wm:lm", "Previous layout is NOT same with current"); - crr_layout[crr_layout_name] = this->layout_define_[crr_layout_name]; - } - - // Update role in new area -#if 1 - if (is_restriction_mode_changed) { - // Updating role is not necessary - // because new_role is not specified - // when restriction mode is changed - HMI_DEBUG("wm:lm", "Updating role is not necessary because new_role is not specified when restriction mode is changed"); -#else - if (is_car_state_changed) { - // Updating role is not necessary - // because new_role is not specified - // when car state is changed - HMI_DEBUG("wm:lm", "Updating role is not necessary because new_role is not specified when car state is changed"); -#endif - } - else { - HMI_DEBUG("wm:lm", "Get new_area for new role"); - // Get new_area for new role - std::string new_area = this->getAreaName(this->layout_define_[crr_layout_name], - new_role, category); - - if ("none" == new_area) { - HMI_DEBUG("wm:lm", "It is not necessary to update role of areas in this layer, because new_role is not specified for this layer"); - } - else { - // Update role in new area - // because new_role is specified for this layer - TypeRolCtg crr_role; - crr_role["role"] = std::string(new_role); - crr_layout[crr_layout_name][new_area] = crr_role; - } - } - } - - // Update layer state - this->crr_layers_[layer] = crr_layout; - - // Check - for (auto itr_layout = this->crr_layers_[layer].begin(); - itr_layout != this->crr_layers_[layer].end(); ++itr_layout) { - for (auto itr_area = itr_layout->second.begin(); - itr_area != itr_layout->second.end(); ++itr_area) { - for (auto itr_role = itr_area->second.begin(); - itr_role != itr_area->second.end(); ++itr_role) { - HMI_DEBUG("wm:lm", "layout:%s, area:%s, rol_ctg:%s, name:%s", - itr_layout->first.c_str(), itr_area->first.c_str(), - itr_role->first.c_str(), itr_role->second.c_str()); - } - } - } - - ret = true; - } - else { - // Clear layout changed flag - this->is_layout_changed_[layer] = false; - } - } return ret; } -// TODO: This API is for workaround, so this will be removed -void LayoutManager::updateArea(const char* layer, const char* role, const char* area) { - this->crr_layers_[layer].begin()->second[area]["role"] = std::string(role); -} - -LayoutManager::TypeLayers LayoutManager::getCurrentLayers() { - return this->crr_layers_; -} - -LayoutManager::TypeLayers LayoutManager::getPreviousLayers() { - return this->prv_layers_; -} - compositor::rect LayoutManager::getAreaSize(const char* area) { return this->area2size_[area]; } -std::string LayoutManager::getAreaName(TypeAreas areas, const char* role, const char* category) { - for (auto itr_area = areas.begin(); itr_area != areas.end(); ++itr_area) { - std::string area_name = itr_area->first; - TypeRolCtg rol_ctg = itr_area->second; - - if ("role" == rol_ctg.begin()->first) { - if (std::string(role) == rol_ctg.begin()->second) { - return area_name; - } - } - else if ("category" == rol_ctg.begin()->first) { - if (std::string(category) == rol_ctg.begin()->second) { - return area_name; - } - } - else { - return std::string("none"); - } - } - return std::string("none"); -} - - -bool LayoutManager::isLayoutChanged(const char* layer) { - return this->is_layout_changed_[layer]; -} - - extern const char* kDefaultLayoutDb; int LayoutManager::loadLayoutDb() { HMI_DEBUG("wm:lm", "Call"); @@ -332,96 +69,15 @@ int LayoutManager::loadLayoutDb() { } HMI_DEBUG("wm:lm", "json_obj dump:%s", json_object_get_string(json_obj)); - // Perse layouts - HMI_DEBUG("wm:lm", "Perse layouts"); - json_object* json_cfg; - if (!json_object_object_get_ex(json_obj, "layouts", &json_cfg)) { - HMI_ERROR("wm:lm", "Parse Error!!"); - return -1; - } - - int len = json_object_array_length(json_cfg); - HMI_DEBUG("wm:lm", "json_cfg len:%d", len); - HMI_DEBUG("wm:lm", "json_cfg dump:%s", json_object_get_string(json_cfg)); - - const char* layout; - const char* role; - const char* category; - for (int i=0; i layout:%s", layout); - - json_object* json_area_array; - if (!json_object_object_get_ex(json_tmp, "areas", &json_area_array)) { - HMI_ERROR("wm:lm", "Parse Error!!"); - return -1; - } - - int len_area = json_object_array_length(json_area_array); - HMI_DEBUG("wm:lm", "json_area_array len:%d", len_area); - HMI_DEBUG("wm:lm", "json_area_array dump:%s", json_object_get_string(json_area_array)); - - TypeAreas areas; - for (int j=0; j> area:%s", area); - - TypeRolCtg rol_ctg_name; - role = jh::getStringFromJson(json_area, "role"); - if (nullptr == role) { - category = jh::getStringFromJson(json_area, "category"); - if (nullptr == category) { - HMI_ERROR("wm:lm", "Parse Error!!"); - return -1; - } - rol_ctg_name["category"] = std::string(category); - HMI_DEBUG("wm:lm", ">>> category:%s", category); - } - else { - rol_ctg_name["role"] = std::string(role); - HMI_DEBUG("wm:lm", ">>> role:%s", role); - } - - areas[area] = rol_ctg_name; - } - - this->layout_define_[layout] = areas; - } - - // Check - for(auto itr_layout = this->layout_define_.begin(); - itr_layout != this->layout_define_.end(); ++itr_layout) { - for (auto itr_area = itr_layout->second.begin(); - itr_area != itr_layout->second.end(); ++itr_area) { - for (auto itr_role = itr_area->second.begin(); - itr_role != itr_area->second.end(); ++itr_role) { - HMI_DEBUG("wm:lm", "layout:%s, area:%s, rol_ctg:%s, name:%s", - itr_layout->first.c_str(), itr_area->first.c_str(), - itr_role->first.c_str(), itr_role->second.c_str()); - } - } - } - // Perse areas HMI_DEBUG("wm:lm", "Perse areas"); + json_object* json_cfg; if (!json_object_object_get_ex(json_obj, "areas", &json_cfg)) { HMI_ERROR("wm:lm", "Parse Error!!"); return -1; } - len = json_object_array_length(json_cfg); + int len = json_object_array_length(json_cfg); HMI_DEBUG("wm:lm", "json_cfg len:%d", len); HMI_DEBUG("wm:lm", "json_cfg dump:%s", json_object_get_string(json_cfg)); diff --git a/src/layout_manager/layout.hpp b/src/layout_manager/layout.hpp index bfa4a6c..648d80e 100644 --- a/src/layout_manager/layout.hpp +++ b/src/layout_manager/layout.hpp @@ -45,19 +45,8 @@ public: explicit LayoutManager(); ~LayoutManager() = default; - typedef std::unordered_map TypeRolCtg; - typedef std::unordered_map TypeAreas; - typedef std::unordered_map TypeLayouts; - typedef std::unordered_map TypeLayers; - int initialize(); - bool updateLayout(json_object* obj, const char* new_role, const char* new_area); - TypeLayers getCurrentLayers(); - TypeLayers getPreviousLayers(); compositor::rect getAreaSize(const char* area); - bool isLayoutChanged(const char* layer); - - void updateArea(const char* layer, const char* role, const char* area); private: // Disable copy and move @@ -66,17 +55,9 @@ private: LayoutManager(LayoutManager &&) = delete; LayoutManager &operator=(LayoutManager &&) = delete; - TypeLayouts layout_define_; std::unordered_map area2size_; - TypeLayers crr_layers_, prv_layers_; - TypeLayers prv_layers_car_stop_; - - std::unordered_map is_layout_changed_; - - std::string getAreaName(TypeAreas area, const char* role, const char* category); int loadLayoutDb(); - std::string role2App(std::string role, void* ptr); }; -- cgit 1.2.3-korg