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 <ilm/ilm_control.h>
20 #include "wm_client.hpp"
21 #include "wm_layer.hpp"
22 #include "json_helper.hpp"
27 using std::unordered_map;
32 LayerState::LayerState()
38 void LayerState::attachIdToArea(const string& area, const WMClient& client)
40 this->area2appid[area] = client.appID();
41 this->render_order.push_back(client.layerID());
44 const unordered_map<string, string> LayerState::popCurrentState()
46 unordered_map<string, string> tmp = this->area2appid;
47 this->area2appid.clear();
48 this->render_order.clear();
52 const unordered_map<string, string> LayerState::getCurrentState()
54 return this->area2appid;
57 const vector<unsigned> LayerState::getIviIdList()
59 return this->render_order;
62 void LayerState::addLayer(unsigned layer)
64 this->render_order.push_back(layer);
67 void LayerState::removeLayer(unsigned layer)
69 auto fwd_itr = std::remove_if(
70 this->render_order.begin(), this->render_order.end(),
71 [layer](unsigned elm) {
75 this->render_order.erase(fwd_itr, this->render_order.end());
78 void LayerState::setArea(const string& app, const string& area)
80 this->area2appid[area] = app;
83 WMLayer::WMLayer(json_object* j) : before_state(), state()
85 this->name = jh::getStringFromJson(j, "name");
86 this->role_list = jh::getStringFromJson(j, "role");
87 const char* type = jh::getStringFromJson(j, "type");
88 this->id_begin = static_cast<unsigned>(jh::getIntFromJson(j, "id_range_begin"));
89 this->id_end = static_cast<unsigned>(jh::getIntFromJson(j, "id_range_end"));
91 if (name.size() == 0 || type || this->id_begin == 0 || this->id_end == 0)
93 HMI_ERROR("Parse Error!!");
96 if(this->id_begin > this->id_end)
101 string str_type = type;
102 this->type = (str_type == "tile") ? MANAGEMENT_TYPE::TILE : MANAGEMENT_TYPE::STACK;
105 unsigned WMLayer::getNewLayerID(const string& role)
109 // generate new layer id;
110 if(this->hasRole(role))
112 ret = this->id_list.back() + 1;
113 HMI_INFO("Generate new id: %d", ret);
120 auto id_found = std::find(id_list.begin(), id_list.end(), ret);
121 if( (ret > this->idEnd()) || (id_found != id_list.cend()) )
123 HMI_NOTICE("id %d is not available then generate new id", ret);
125 for(unsigned i = this->idBegin(); i < this->idEnd(); i++)
127 auto ret_found = std::find(id_list.begin(), id_list.end(), i);
128 if(ret_found == id_list.cend())
130 HMI_INFO("set new id: %d", i);
139 id_list.push_back(ret);
143 HMI_ERROR("failed to get New ID");
148 const string& WMLayer::layerName()
153 WMError WMLayer::setLayerState(const LayerState& l)
155 this->before_state = l;
156 return WMError::SUCCESS;
159 void WMLayer::appendArea(const string& area)
161 this->area_list.push_back(area);
164 void WMLayer::removeLayerID(unsigned id)
166 auto fwd_itr = std::remove_if(this->id_list.begin(), this->id_list.end(),
170 this->id_list.erase(fwd_itr, this->id_list.end());
173 bool WMLayer::hasLayerID(unsigned id)
175 bool ret = (id > this->idBegin() && id < this->idEnd());
178 auto itr = std::find(this->id_list.begin(), this->id_list.end(), id);
179 return (itr != this->id_list.end()) ? true : false;
182 bool WMLayer::hasRole(const string& role)
184 auto re = std::regex(this->role_list);
185 if (std::regex_match(role, re))
187 HMI_DEBUG("role %s matches layer %d", role.c_str(), this->name.c_str());
193 /* WMError WMLayer::commitChange()
195 this->state = this->before_state;
200 this->before_state = this->state;