2 * Copyright (c) 2017 TOYOTA MOTOR CORPORATION
\r
4 * Licensed under the Apache License, Version 2.0 (the "License");
\r
5 * you may not use this file except in compliance with the License.
\r
6 * You may obtain a copy of the License at
\r
8 * http://www.apache.org/licenses/LICENSE-2.0
\r
10 * Unless required by applicable law or agreed to in writing, software
\r
11 * distributed under the License is distributed on an "AS IS" BASIS,
\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 * See the License for the specific language governing permissions and
\r
14 * limitations under the License.
\r
18 #include "wm_layer_control.hpp"
\r
19 #include "wm_layer.hpp"
\r
20 #include "json_helper.hpp"
\r
22 #define LC_AREA_PATH "/etc/area.db"
\r
23 #define LC_LAYER_SETTING_PATH "/etc/layer_setting.json"
\r
29 static void notification_static(ilmObjectType object,
\r
34 static_cast<LayerControl*>(data)->dispatchILMEvent(object, id, created);
\r
37 LayerControl::LayerControl(const std::string& root)
\r
39 string area_path = root + LC_AREA_PATH;
\r
40 string layer_path= root + LC_LAYER_SETTING_PATH;
\r
41 // load layers.setting.json
\r
42 WMError ret = this->loadLayerSetting(layer_path);
\r
43 assert(ret == WMError::SUCCESS);
\r
45 ret = this->loadAreaDb(area_path);
\r
46 assert(ret == WMError::SUCCESS);
\r
49 WMError LayerControl::init()
\r
51 ilmErrorTypes rc = ilm_init();
\r
56 while (rc != ILM_SUCCESS)
\r
61 HMI_ERROR("Could not connect to compositor");
\r
64 HMI_ERROR("Wait to start weston ...");
\r
68 if(rc != ILM_SUCCESS) goto lc_init_error;
\r
70 rc = ilm_getScreenIDs(&num, &ids);
\r
72 if(rc != ILM_SUCCESS) goto lc_init_error;
\r
74 for(unsigned i = 0; i < num; i++)
\r
76 HMI_INFO("get screen: %d", ids[i]);
\r
78 // Currently, 0 is only available
\r
79 this->screenID = ids[0];
\r
81 rc = ilm_getPropertiesOfScreen(this->screenID, &this->screen_prop);
\r
83 if(rc != ILM_SUCCESS) goto lc_init_error;
\r
85 // Register Callback from ILM
\r
86 ilm_registerNotification(notification_static, this);
\r
88 return WMError::SUCCESS;
\r
91 HMI_ERROR("Failed to initialize. Terminate WM");
\r
93 return WMError::FAIL;
\r
96 unsigned LayerControl::getNewLayerID(const string& role)
\r
99 for(const auto& l: this->wm_layers)
\r
101 ret = l->getNewLayerID(role);
\r
110 WMError LayerControl::updateLayer(WMLayer& wm_layer)
\r
112 return WMError::SUCCESS;
\r
115 void LayerControl::commitChange() {}
\r
117 void LayerControl::undoUpdate() {}
\r
119 WMError LayerControl::loadLayerSetting(const string &path)
\r
121 HMI_DEBUG("loading WMLayer(Application Containers) Setting from %s", path);
\r
123 json_object *json_obj, *json_cfg;
\r
124 int ret = jh::inputJsonFilie(path.c_str(), &json_obj);
\r
127 HMI_DEBUG("Could not open %s, so use default area information", path.c_str());
\r
128 return WMError::FAIL;
\r
130 HMI_INFO("json_obj dump:%s", json_object_get_string(json_obj));
\r
132 if (!json_object_object_get_ex(json_obj, "mappings", &json_cfg))
\r
134 HMI_ERROR("Parse Error!!");
\r
135 return WMError::FAIL;
\r
138 int len = json_object_array_length(json_cfg);
\r
139 HMI_DEBUG("json_cfg len:%d", len);
\r
141 for (int i = 0; i < len; i++)
\r
143 json_object *json_tmp = json_object_array_get_idx(json_cfg, i);
\r
144 HMI_DEBUG("> json_tmp dump:%s", json_object_get_string(json_tmp));
\r
146 this->wm_layers.emplace_back(std::make_shared<WMLayer>(json_tmp));
\r
149 return WMError::SUCCESS;
\r
152 WMError LayerControl::loadAreaDb(const std::string& path)
\r
155 json_object *json_obj;
\r
156 int ret = jh::inputJsonFilie(path.c_str(), &json_obj);
\r
159 HMI_DEBUG("Could not open %s, so use default area information", path.c_str());
\r
160 return WMError::FAIL;
\r
162 HMI_INFO("json_obj dump:%s", json_object_get_string(json_obj));
\r
165 json_object *json_cfg;
\r
166 if (!json_object_object_get_ex(json_obj, "areas", &json_cfg))
\r
168 HMI_ERROR("Parse Error!!");
\r
169 return WMError::FAIL;
\r
172 int len = json_object_array_length(json_cfg);
\r
173 HMI_DEBUG("json_cfg len:%d", len);
\r
176 for (int i = 0; i < len; i++)
\r
178 json_object *json_tmp = json_object_array_get_idx(json_cfg, i);
\r
179 HMI_DEBUG("> json_tmp dump:%s", json_object_get_string(json_tmp));
\r
181 area = jh::getStringFromJson(json_tmp, "name");
\r
182 if (nullptr == area)
\r
184 HMI_ERROR("Parse Error!!");
\r
185 return WMError::FAIL;
\r
187 HMI_DEBUG("> area:%s", area);
\r
189 json_object *json_rect;
\r
190 if (!json_object_object_get_ex(json_tmp, "rect", &json_rect))
\r
192 HMI_ERROR("Parse Error!!");
\r
193 return WMError::FAIL;
\r
195 HMI_DEBUG("> json_rect dump:%s", json_object_get_string(json_rect));
\r
197 struct rect area_size;
\r
198 area_size.x = jh::getIntFromJson(json_rect, "x");
\r
199 area_size.y = jh::getIntFromJson(json_rect, "y");
\r
200 area_size.w = jh::getIntFromJson(json_rect, "w");
\r
201 area_size.h = jh::getIntFromJson(json_rect, "h");
\r
203 this->area2size[area] = area_size;
\r
207 for (const auto& itr : this->area2size)
\r
209 HMI_DEBUG("area:%s x:%d y:%d w:%d h:%d",
\r
210 itr.first.c_str(), itr.second.x, itr.second.y,
\r
211 itr.second.w, itr.second.h);
\r
214 // Release json_object
\r
215 json_object_put(json_obj);
\r
217 return WMError::SUCCESS;
\r
220 void LayerControl::dispatchILMEvent(ilmObjectType object, t_ilm_uint id, t_ilm_bool created)
\r