/* * Copyright (c) 2017 TOYOTA MOTOR CORPORATION * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include #include "layout.hpp" #include "json_helper.hpp" #include "hmi-debug.h" LayoutManager::LayoutManager() { HMI_DEBUG("wm:lm", "Call"); } int LayoutManager::initialize() { HMI_DEBUG("wm:lm", "Call"); int ret = 0; // Load layout.db ret = this->loadLayoutDb(); if (0 > ret) { HMI_ERROR("wm:lm", "Load layout.db Error!!"); return ret; } return ret; } compositor::rect LayoutManager::getAreaSize(const char* area) { return this->area2size[area]; } extern const char* kDefaultLayoutDb; int LayoutManager::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:lm", "afm_app_install_dir:%s", afm_app_install_dir); std::string file_name; if (!afm_app_install_dir) { HMI_ERROR("wm:lm", "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 = jh::inputJsonFilie(file_name.c_str(), &json_obj); if (0 > ret) { HMI_DEBUG("wm:lm", "Could not open layout.db, so use default layout information"); json_obj = json_tokener_parse(kDefaultLayoutDb); } HMI_DEBUG("wm:lm", "json_obj dump:%s", json_object_get_string(json_obj)); // 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; } 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* area; for (int i=0; i json_tmp dump:%s", json_object_get_string(json_tmp)); area = jh::getStringFromJson(json_tmp, "name"); if (nullptr == area) { HMI_ERROR("wm:lm", "Parse Error!!"); return -1; } HMI_DEBUG("wm:lm", "> area:%s", area); json_object* json_rect; if (!json_object_object_get_ex(json_tmp, "rect", &json_rect)) { HMI_ERROR("wm:lm", "Parse Error!!"); return -1; } HMI_DEBUG("wm:lm", "> json_rect dump:%s", json_object_get_string(json_rect)); compositor::rect area_size; area_size.x = jh::getIntFromJson(json_rect, "x"); area_size.y = jh::getIntFromJson(json_rect, "y"); area_size.w = jh::getIntFromJson(json_rect, "w"); area_size.h = jh::getIntFromJson(json_rect, "h"); this->area2size[area] = area_size; } // Check for(auto itr = this->area2size.begin(); itr != this->area2size.end(); ++itr) { HMI_DEBUG("wm:lm", "area:%s x:%d y:%d w:%d h:%d", itr->first.c_str(), itr->second.x, itr->second.y, itr->second.w, itr->second.h); } // Release json_object json_object_put(json_obj); return 0; } 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 \ } \ } \ ] \ }";