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.
19 #include "wm_layer.hpp"
20 #include "json_helper.hpp"
29 LayerState::LayerState()
30 : _ivi_layer_id_list(),
34 LayerSetting::LayerSetting(const string& name, MANAGEMENT_TYPE type, unsigned begin, unsigned end)
35 : name(name), type(type),
36 role_list(), area_list(), id_list(),
37 id_begin(begin), id_end(end)
40 void LayerSetting::appendRole(const string& role)
42 this->role_list.push_back(role);
45 void LayerSetting::appendArea(const string& area)
47 this->area_list.push_back(area);
50 unsigned LayerSetting::getNewLayerID(const string& role)
53 auto found = std::find(role_list.cbegin(), role_list.cend(), role);
54 if(found == role_list.cend())
58 // generate new ivi layer id
59 ret = id_list.back() + 1;
60 HMI_INFO("generate ivi_layer_id : %d on the layer: %s", ret, this->name.c_str());
62 auto id_found = std::find(id_list.begin(), id_list.end(), ret);
63 if( (ret > this->idEnd()) || (id_found != id_list.cend()) )
65 HMI_NOTICE("id %d is not available then generate new id", ret);
67 for(unsigned i = this->idBegin(); i < this->idEnd(); i++)
69 auto ret_found = std::find(id_list.begin(), id_list.end(), i);
70 if(ret_found == id_list.cend())
72 HMI_INFO("set new id: %d", i);
81 id_list.push_back(ret);
85 HMI_ERROR("failed to get New ID");
90 void LayerSetting::removeLayerID(unsigned id)
92 auto fwd_itr = std::remove_if(this->id_list.begin(), this->id_list.end(),
96 this->id_list.erase(fwd_itr, this->id_list.end());
104 // this->setting = std::make_unique<LayerSetting>(name, type, begin, end);
107 WMLayer::WMLayer(json_object* j) : before_state(), state()
109 LayerSetting::MANAGEMENT_TYPE t;
110 const char* layer_name = jh::getStringFromJson(j, "name");
111 const char* role = jh::getStringFromJson(j, "role");
112 const char* type = jh::getStringFromJson(j, "type");
113 int begin = jh::getIntFromJson(j, "id_range_begin");
114 int end = jh::getIntFromJson(j, "id_range_end");
115 string name = layer_name;
117 if (layer_name || type || begin >=0 || end >=0)
119 HMI_ERROR("Parse Error!!");
123 HMI_ERROR("INVALID.");
125 string str_type = type;
126 t = (type == "tile") ? LayerSetting::TILE : LayerSetting::STACK;
127 this->setting = std::make_unique<LayerSetting>(name, t, begin, end);
130 unsigned WMLayer::getNewLayerID(const std::string& role)
132 return this->setting->getNewLayerID(role);
135 WMError WMLayer::setLayerState(const LayerState& l)
137 return WMError::SUCCESS;
140 bool WMLayer::checkIDBelongTo(unsigned id)
142 return (id > this->setting->idBegin() && id < this->setting->idEnd());