/* * Copyright (c) 2017 TOYOTA MOTOR CORPORATION * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include #include "wm_layer.hpp" #include "wayland_ivi_wm.hpp" #include "json_helper.hpp" #include "util.hpp" using std::string; using std::vector; namespace wm { LayerState::LayerState() : _ivi_layer_id_list(), area2ivi_layer_id() {} LayerSetting::LayerSetting(const string& name, MANAGEMENT_TYPE type, unsigned begin, unsigned end) : name(name), type(type), role_list(), area_list(), id_list(), id_begin(begin), id_end(end) {} void LayerSetting::appendRole(const string& role) { this->role_list.push_back(role); } void LayerSetting::appendArea(const string& area) { this->area_list.push_back(area); } unsigned LayerSetting::getNewLayerID(const string& role) { unsigned ret = 0; auto found = std::find(role_list.cbegin(), role_list.cend(), role); if(found == role_list.cend()) { return ret; } // generate new ivi layer id ret = id_list.back() + 1; HMI_INFO("generate ivi_layer_id : %d on the layer: %s", ret, this->name.c_str()); auto id_found = std::find(id_list.begin(), id_list.end(), ret); if( (ret > this->idEnd()) || (id_found != id_list.cend()) ) { HMI_NOTICE("id %d is not available then generate new id", ret); ret = 0; for(unsigned i = this->idBegin(); i < this->idEnd(); i++) { auto ret_found = std::find(id_list.begin(), id_list.end(), i); if(ret_found == id_list.cend()) { HMI_INFO("set new id: %d", i); ret = i; break; } } } if(ret != 0) { id_list.push_back(ret); } else { HMI_ERROR("failed to get New ID"); } return ret; } void LayerSetting::removeLayerID(unsigned id) { auto fwd_itr = std::remove_if(this->id_list.begin(), this->id_list.end(), [id](unsigned elm) { return elm == id; }); this->id_list.erase(fwd_itr, this->id_list.end()); } WMLayer::WMLayer() : before_state(), state(), setting{} { // this->setting = std::make_unique(name, type, begin, end); } unsigned WMLayer::getNewLayerID(const std::string& role) { return this->setting->getNewLayerID(role); } WMError WMLayer::setLayerState(const LayerState& l) { return WMError::SUCCESS; } bool WMLayer::checkIDBelongTo(unsigned id) { return (id > this->setting->idBegin() && id < this->setting->idEnd()); } } // namespace wm