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<std::string, std::string> LayerState::popCurrentState()
46 unordered_map<string, string> tmp = this->area2appid;
47 this->area2appid.clear();
48 this->render_order.clear();
52 const unordered_map<std::string, std::string> LayerState::getCurrentState()
54 return this->area2appid;
57 const vector<unsigned> LayerState::getIviIdList()
59 return this->render_order;
62 WMLayer::WMLayer(json_object* j) : before_state(), state()
64 this->name = jh::getStringFromJson(j, "name");
65 this->role_list = jh::getStringFromJson(j, "role");
66 const char* type = jh::getStringFromJson(j, "type");
67 this->id_begin = static_cast<unsigned>(jh::getIntFromJson(j, "id_range_begin"));
68 this->id_end = static_cast<unsigned>(jh::getIntFromJson(j, "id_range_end"));
70 if (name.size() == 0 || type || this->id_begin == 0 || this->id_end == 0)
72 HMI_ERROR("Parse Error!!");
75 if(this->id_begin > this->id_end)
80 string str_type = type;
81 this->type = (str_type == "tile") ? MANAGEMENT_TYPE::TILE : MANAGEMENT_TYPE::STACK;
84 unsigned WMLayer::getNewLayerID(const string& role)
87 auto re = std::regex(this->role_list);
88 if (std::regex_match(role, re))
90 // generate new layer id;
91 ret = this->id_list.back() + 1;
92 HMI_DEBUG("role %s matches layer %d, new layerID %d", role.c_str(), this->name.c_str(), ret);
100 auto id_found = std::find(id_list.begin(), id_list.end(), ret);
101 if( (ret > this->idEnd()) || (id_found != id_list.cend()) )
103 HMI_NOTICE("id %d is not available then generate new id", ret);
105 for(unsigned i = this->idBegin(); i < this->idEnd(); i++)
107 auto ret_found = std::find(id_list.begin(), id_list.end(), i);
108 if(ret_found == id_list.cend())
110 HMI_INFO("set new id: %d", i);
119 id_list.push_back(ret);
123 HMI_ERROR("failed to get New ID");
128 const string& WMLayer::layerName()
133 WMError WMLayer::setLayerState(const LayerState& l)
135 this->before_state = l;
136 return WMError::SUCCESS;
139 void WMLayer::appendArea(const string& area)
141 this->area_list.push_back(area);
144 void WMLayer::removeLayerID(unsigned id)
146 auto fwd_itr = std::remove_if(this->id_list.begin(), this->id_list.end(),
150 this->id_list.erase(fwd_itr, this->id_list.end());
153 bool WMLayer::checkIDBelongTo(unsigned id)
155 return (id > this->idBegin() && id < this->idEnd());
158 /* WMError WMLayer::commitChange()
160 this->state = this->before_state;
165 this->before_state = this->state;