X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fwm_layer.cpp;h=b3e3d2c3251c4bd53c75c87ad9d14df06de37281;hb=d5a353563462d3eebd5e138a0ed4f850ea8cd809;hp=7b67042da38d422240c7493b5557eea25fdd9a6a;hpb=58da0c77b98af1b771e4af28b42d0a3ddec09877;p=apps%2Fagl-service-windowmanager.git diff --git a/src/wm_layer.cpp b/src/wm_layer.cpp index 7b67042..b3e3d2c 100644 --- a/src/wm_layer.cpp +++ b/src/wm_layer.cpp @@ -15,62 +15,152 @@ */ #include - +#include +#include +#include "wm_client.hpp" #include "wm_layer.hpp" -#include "wayland_ivi_wm.hpp" #include "json_helper.hpp" #include "util.hpp" using std::string; using std::vector; +using std::unordered_map; + +#define BG_LAYER_NAME "BackGroundLayer" namespace wm { LayerState::LayerState() - : _ivi_layer_id_list(), - area2ivi_layer_id() + : render_order(), + area2appid() {} -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) +void LayerState::attachIdToArea(const string& area, const WMClient& client) { - this->role_list.push_back(role); + this->area2appid[area] = client.appID(); + this->render_order.push_back(client.layerID()); } -void LayerSetting::appendArea(const string& area) +const unordered_map LayerState::popCurrentState() { - this->area_list.push_back(area); + unordered_map tmp = this->area2appid; + this->area2appid.clear(); + this->render_order.clear(); + return tmp; +} + +const unordered_map LayerState::getCurrentState() +{ + return this->area2appid; +} + +const vector LayerState::getIviIdList() +{ + return this->render_order; +} + +void LayerState::addLayer(unsigned layer) +{ + 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::setArea(const string& app, const string& area) +{ + this->area2appid[area] = app; } -unsigned LayerSetting::getNewLayerID(const string& role) +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 uuid) : tmp_state(), state(), uuid(uuid) +{ + this->name = jh::getStringFromJson(j, "name"); + this->role_list = jh::getStringFromJson(j, "role"); + const char* type = jh::getStringFromJson(j, "type"); + this->id_begin = static_cast(jh::getIntFromJson(j, "id_range_begin")); + this->id_end = static_cast(jh::getIntFromJson(j, "id_range_end")); + + if (name.size() == 0 || !type) + { + HMI_ERROR("Parse Error!!"); + exit(1); + } + if(this->id_begin > this->id_end) + { + HMI_ERROR("INVALID"); + exit(1); + } + string str_type = type; + this->type = (str_type == "tile") ? MANAGEMENT_TYPE::TILE : MANAGEMENT_TYPE::STACK; +} + +unsigned WMLayer::getNewLayerID(const string& role) { unsigned ret = 0; - auto found = std::find(role_list.cbegin(), role_list.cend(), role); - if(found == role_list.cend()) + 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; } - // generate new ivi layer id - ret = id_list.back() + 1; - HMI_INFO("wm", "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()) ) + size_t count = std::count(id_list.begin(), id_list.end(), ret); + if( (ret > this->idEnd()) || (count > 1)) { - HMI_NOTICE("wm", "id %d is not available then generate new id", ret); - ret = 0; + 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("wm", "set new id: %d", i); + HMI_INFO("set new id: %d", i); ret = i; break; } @@ -83,41 +173,97 @@ unsigned LayerSetting::getNewLayerID(const string& role) } else { - HMI_ERROR("wm", "failed to get New ID"); + HMI_ERROR("failed to get New ID"); } return ret; } -void LayerSetting::removeLayerID(unsigned id) +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::setAreaToState(const string& app, const string& area) +{ + this->tmp_state.setArea(app, area); +} + +void WMLayer::appendArea(const string& area) +{ + this->area_list.push_back(area); +} + +void WMLayer::terminateApp(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); } -WMLayer::WMLayer() - : before_state(), - state(), - setting{} +bool WMLayer::hasLayerID(unsigned id) { - // this->setting = std::make_unique(name, type, begin, end); + 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; } -unsigned WMLayer::getNewLayerID(const std::string& role) +bool WMLayer::hasRole(const string& role) { - return this->setting->getNewLayerID(role); + auto re = std::regex(this->role_list); + if (std::regex_match(role, re)) + { + HMI_DEBUG("role %s matches layer %s", role.c_str(), this->name.c_str()); + return true; + } + return false; } -WMError WMLayer::setLayerState(const LayerState& l) +void WMLayer::update() { - return WMError::SUCCESS; + this->state = this->tmp_state; } -bool WMLayer::checkIDBelongTo(unsigned id) +void WMLayer::undo() { - return (id > this->setting->idBegin() && id < this->setting->idEnd()); + 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 ====="); + +} + +/* void WMLayer::undo() +{ + this->tmp_state = this->state; +} + */ } // namespace wm