2 * Copyright (c) 2017 TOYOTA MOTOR CORPORATION
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include <json-c/json.h>
20 #include "json_helper.hpp"
21 #include "hmi-debug.h"
24 LayoutManager::LayoutManager() {
25 HMI_DEBUG("wm:lm", "Call");
28 int LayoutManager::initialize() {
29 HMI_DEBUG("wm:lm", "Call");
34 ret = this->loadAreaDb();
36 HMI_ERROR("wm:lm", "Load layout.db Error!!");
43 compositor::rect LayoutManager::getAreaSize(const char* area) {
44 return this->area2size[area];
47 extern const char* kDefaultAreaDb;
48 int LayoutManager::loadAreaDb() {
49 HMI_DEBUG("wm:lm", "Call");
51 // Get afm application installed dir
52 char const *afm_app_install_dir = getenv("AFM_APP_INSTALL_DIR");
53 HMI_DEBUG("wm:lm", "afm_app_install_dir:%s", afm_app_install_dir);
55 std::string file_name;
56 if (!afm_app_install_dir) {
57 HMI_ERROR("wm:lm", "AFM_APP_INSTALL_DIR is not defined");
60 file_name = std::string(afm_app_install_dir) + std::string("/etc/area.db");
64 json_object* json_obj;
65 int ret = jh::inputJsonFilie(file_name.c_str(), &json_obj);
67 HMI_DEBUG("wm:lm", "Could not open area.db, so use default area information");
68 json_obj = json_tokener_parse(kDefaultAreaDb);
70 HMI_DEBUG("wm:lm", "json_obj dump:%s", json_object_get_string(json_obj));
73 HMI_DEBUG("wm:lm", "Perse areas");
74 json_object* json_cfg;
75 if (!json_object_object_get_ex(json_obj, "areas", &json_cfg)) {
76 HMI_ERROR("wm:lm", "Parse Error!!");
80 int len = json_object_array_length(json_cfg);
81 HMI_DEBUG("wm:lm", "json_cfg len:%d", len);
82 HMI_DEBUG("wm:lm", "json_cfg dump:%s", json_object_get_string(json_cfg));
85 for (int i=0; i<len; i++) {
86 json_object* json_tmp = json_object_array_get_idx(json_cfg, i);
87 HMI_DEBUG("wm:lm", "> json_tmp dump:%s", json_object_get_string(json_tmp));
89 area = jh::getStringFromJson(json_tmp, "name");
90 if (nullptr == area) {
91 HMI_ERROR("wm:lm", "Parse Error!!");
94 HMI_DEBUG("wm:lm", "> area:%s", area);
96 json_object* json_rect;
97 if (!json_object_object_get_ex(json_tmp, "rect", &json_rect)) {
98 HMI_ERROR("wm:lm", "Parse Error!!");
101 HMI_DEBUG("wm:lm", "> json_rect dump:%s", json_object_get_string(json_rect));
103 compositor::rect area_size;
104 area_size.x = jh::getIntFromJson(json_rect, "x");
105 area_size.y = jh::getIntFromJson(json_rect, "y");
106 area_size.w = jh::getIntFromJson(json_rect, "w");
107 area_size.h = jh::getIntFromJson(json_rect, "h");
109 this->area2size[area] = area_size;
113 for(auto itr = this->area2size.begin();
114 itr != this->area2size.end(); ++itr) {
115 HMI_DEBUG("wm:lm", "area:%s x:%d y:%d w:%d h:%d",
116 itr->first.c_str(), itr->second.x, itr->second.y,
117 itr->second.w, itr->second.h);
120 // Release json_object
121 json_object_put(json_obj);
126 const char* kDefaultAreaDb = "{ \
129 \"name\": \"fullscreen\", \
138 \"name\": \"normal\", \
147 \"name\": \"split.main\", \
156 \"name\": \"split.sub\", \
165 \"name\": \"software_keyboard\", \
174 \"name\": \"restriction.normal\", \
183 \"name\": \"restriction.split.main\", \
192 \"name\": \"restriction.split.sub\", \
201 \"name\": \"pop_up\", \
210 \"name\": \"system_alert\", \