X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fwm_layer.cpp;fp=src%2Fwm_layer.cpp;h=294e356b462c6084767fdbe4d56431ea7d97c7fd;hb=010ca3f3459a52e44deb5e70e94e9cd394814e3e;hp=c70265124277443a2b7f10b4e74b92e1b0642718;hpb=c2110a3ec8fa74f2fc37e4909db547aa4a36c851;p=apps%2Fagl-service-windowmanager.git diff --git a/src/wm_layer.cpp b/src/wm_layer.cpp index c702651..294e356 100644 --- a/src/wm_layer.cpp +++ b/src/wm_layer.cpp @@ -23,15 +23,190 @@ #include "util.hpp" using std::string; +using std::vector; +using std::unordered_map; + +#define BG_LAYER_NAME "BackGroundLayer" namespace wm { -WMLayer::WMLayer(json_object* j) +LayerState::LayerState() + : render_order(), + area2appid() +{} + +const vector LayerState::getIviIdList() +{ + return this->render_order; +} + +void LayerState::addLayer(unsigned layer) +{ + auto result = std::find(this->render_order.begin(), this->render_order.end(), layer); + if(result == this->render_order.end()) + this->render_order.push_back(layer); +} + +void LayerState::removeLayer(unsigned layer) +{ + auto fwd_itr = std::remove_if( + this->render_order.begin(), this->render_order.end(), + [layer](unsigned elm) { + if(elm == layer) + HMI_DEBUG("remove layer %d", elm); + return elm == layer; + } + ); + this->render_order.erase(fwd_itr, this->render_order.end()); +} + +void LayerState::attachAppToArea(const string& app, const string& area) +{ + this->area2appid[area] = app; +} + +void LayerState::dump() +{ + std::string ids, apps; + for(const auto& ro : this->render_order) + { + ids += std::to_string(ro); + ids += ","; + } + for(const auto& area : this->area2appid) + { + apps += area.first; + apps += ":"; + apps += area.second; + apps += ","; + } + DUMP(" render order : %s", ids.c_str()); + DUMP(" area, app : %s", apps.c_str()); +} + +WMLayer::WMLayer(json_object* j, unsigned wm_layer_id) : tmp_state(), state(), wm_layer_id(wm_layer_id) { this->name = jh::getStringFromJson(j, "name"); this->role_list = jh::getStringFromJson(j, "role"); - this->layer_id = static_cast(jh::getIntFromJson(j, "layer_id")); + this->id_begin = static_cast(jh::getIntFromJson(j, "id_range_begin")); + this->id_end = static_cast(jh::getIntFromJson(j, "id_range_end")); + + if (name.empty()) + { + HMI_ERROR("Parse Error!!"); + exit(1); + } + if(this->id_begin > this->id_end) + { + HMI_ERROR("INVALID"); + exit(1); + } +} + +unsigned WMLayer::getNewLayerID(const string& role) +{ + unsigned ret = 0; + if(this->name == BG_LAYER_NAME) + return ret; + + // generate new layer id; + if(this->hasRole(role)) + { + if(this->id_list.size() == 0) + { + ret = this->idBegin(); + this->id_list.push_back(ret); + } + else + { + ret = this->id_list.back() + 1; + } + HMI_INFO("Generate new id: %d", ret); + } + else + { + return ret; + } + + size_t count = std::count(id_list.begin(), id_list.end(), ret); + if( (ret > this->idEnd()) || (count > 1)) + { + HMI_NOTICE("id %d is not available then generate new id", ret); + ret = 0; // reset + 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; +} + +const string& WMLayer::layerName() +{ + return this->name; +} + +WMError WMLayer::setLayerState(const LayerState& l) +{ + this->tmp_state = l; + return WMError::SUCCESS; +} + +void WMLayer::addLayerToState(unsigned layer) +{ + this->tmp_state.addLayer(layer); +} + +void WMLayer::removeLayerFromState(unsigned layer) +{ + this->tmp_state.removeLayer(layer); +} + +void WMLayer::attachAppToArea(const string& app, const string& area) +{ + this->tmp_state.attachAppToArea(app, area); +} + +void WMLayer::appendArea(const string& area) +{ + this->area_list.push_back(area); +} + +void WMLayer::appTerminated(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()); + this->tmp_state.removeLayer(id); + this->state.removeLayer(id); + ilm_layerRemove(id); +} + +bool WMLayer::hasLayerID(unsigned id) +{ + bool ret = (id >= this->idBegin() && id <= this->idEnd()); + if(!ret) + return ret; + auto itr = std::find(this->id_list.begin(), this->id_list.end(), id); + return (itr != this->id_list.end()) ? true : false; } bool WMLayer::hasRole(const string& role) @@ -45,4 +220,24 @@ bool WMLayer::hasRole(const string& role) return false; } +void WMLayer::update() +{ + this->state = this->tmp_state; +} + +void WMLayer::undo() +{ + this->tmp_state = this->state; +} + +void WMLayer::dump() +{ + DUMP("===== wm layer status ====="); + DUMP("Layer :%s", this->name.c_str()); + this->tmp_state.dump(); + this->state.dump(); + DUMP("===== wm layer status end ====="); + +} + } // namespace wm