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 "wayland_ivi_wm.hpp"
21 #include "json_helper.hpp"
22 #include "hmi-debug.h"
30 LayerState::LayerState()
31 : _ivi_layer_id_list(),
35 LayerSetting::LayerSetting(const string& name, MANAGEMENT_TYPE type, unsigned begin, unsigned end)
36 : name(name), type(type),
37 role_list(), area_list(), id_list(),
38 id_begin(begin), id_end(end)
41 void LayerSetting::appendRole(const string& role)
43 this->role_list.push_back(role);
46 void LayerSetting::appendArea(const string& area)
48 this->area_list.push_back(area);
51 unsigned LayerSetting::getNewLayerID(const string& role)
54 auto found = std::find(role_list.cbegin(), role_list.cend(), role);
55 if(found == role_list.cend())
59 // generate new ivi layer id
60 ret = id_list.back() + 1;
61 HMI_INFO("wm", "generate ivi_layer_id : %d on the layer: %s", ret, this->name.c_str());
63 auto id_found = std::find(id_list.begin(), id_list.end(), ret);
64 if( (ret > this->idEnd()) || (id_found != id_list.cend()) )
66 HMI_NOTICE("wm", "id %d is not available then generate new id", ret);
68 for(unsigned i = this->idBegin(); i < this->idEnd(); i++)
70 auto ret_found = std::find(id_list.begin(), id_list.end(), i);
71 if(ret_found == id_list.cend())
73 HMI_INFO("wm", "set new id: %d", i);
82 id_list.push_back(ret);
86 HMI_ERROR("wm", "failed to get New ID");
91 void LayerSetting::removeLayerID(unsigned id)
93 auto fwd_itr = std::remove_if(this->id_list.begin(), this->id_list.end(),
97 this->id_list.erase(fwd_itr, this->id_list.end());
105 // this->setting = std::make_unique<LayerSetting>(name, type, begin, end);
108 unsigned WMLayer::getNewLayerID(const std::string& role)
110 return this->setting->getNewLayerID(role);
113 WMError WMLayer::setLayerState(const LayerState& l)
115 return WMError::SUCCESS;
118 bool WMLayer::checkIDBelongTo(unsigned id)
120 return (id > this->setting->idBegin() && id < this->setting->idEnd());