X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fwm_layer.cpp;h=154d874c9b50fa734f399c148597162051fada6a;hb=2ce7162980b40cf5587ed8a0247f3e9bd3407ad7;hp=773b5c23857abcb585e812cca68cf9ea11c79476;hpb=0b011c00b0c8aa847a4d0aa460a335c5eae8f010;p=apps%2Fagl-service-windowmanager.git diff --git a/src/wm_layer.cpp b/src/wm_layer.cpp index 773b5c2..154d874 100644 --- a/src/wm_layer.cpp +++ b/src/wm_layer.cpp @@ -15,7 +15,8 @@ */ #include - +#include +#include #include "wm_client.hpp" #include "wm_layer.hpp" #include "json_helper.hpp" @@ -25,6 +26,8 @@ using std::string; using std::vector; using std::unordered_map; +#define BG_LAYER_NAME "BackGroundLayer" + namespace wm { @@ -40,7 +43,7 @@ void LayerState::attachIdToArea(const string& area, const WMClient& client) this->render_order.push_back(client.layerID()); } -const unordered_map LayerState::popCurrentState() +const unordered_map LayerState::popCurrentState() { unordered_map tmp = this->area2appid; this->area2appid.clear(); @@ -48,7 +51,7 @@ const unordered_map LayerState::popCurrentState() return tmp; } -const unordered_map LayerState::getCurrentState() +const unordered_map LayerState::getCurrentState() { return this->area2appid; } @@ -58,40 +61,89 @@ const vector LayerState::getIviIdList() return this->render_order; } -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 LayerState::addLayer(unsigned layer) +{ + this->render_order.push_back(layer); +} -void LayerSetting::setRoleList(const string& role) +void LayerState::removeLayer(unsigned layer) { - this->role_list = role; + 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 LayerSetting::appendArea(const string& area) +void LayerState::setArea(const string& app, const string& area) { - this->area_list.push_back(area); + this->area2appid[area] = app; } -unsigned LayerSetting::getNewLayerID(const string& role) +void LayerState::dump() { - unsigned ret = 0; - auto re = std::regex(this->role_list); - if (std::regex_match(role, re)) + std::string str; + for(const auto& ro : this->render_order) { - // generate new layer id; - ret = this->id_list.back() + 1; - HMI_DEBUG("role %s matches layer %d, new layerID %d", role.c_str(), this->name.c_str(), ret); + str += std::to_string(ro); + str += ","; } + DUMP(" render order : %s", str.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(ret == 0) + 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; + 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; } - 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("id %d is not available then generate new id", ret); ret = 0; // reset @@ -118,71 +170,83 @@ unsigned LayerSetting::getNewLayerID(const string& role) 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::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; } -WMLayer::WMLayer(json_object* j) : before_state(), state() +bool WMLayer::hasRole(const string& role) { - LayerSetting::MANAGEMENT_TYPE t; - const char* layer_name = jh::getStringFromJson(j, "name"); - const char* roles = jh::getStringFromJson(j, "role"); - const char* type = jh::getStringFromJson(j, "type"); - int begin = jh::getIntFromJson(j, "id_range_begin"); - int end = jh::getIntFromJson(j, "id_range_end"); - string name = layer_name; - - if (layer_name || type || begin < 0 || end < 0) - { - HMI_ERROR("Parse Error!!"); - } - if(begin > end) + auto re = std::regex(this->role_list); + if (std::regex_match(role, re)) { - HMI_ERROR("INVALID."); + HMI_DEBUG("role %s matches layer %s", role.c_str(), this->name.c_str()); + return true; } - string str_type = type; - t = (str_type == "tile") ? LayerSetting::TILE : LayerSetting::STACK; - this->setting = std::make_unique(name, t, begin, end); - this->setting->setRoleList(roles); -} - -unsigned WMLayer::getNewLayerID(const std::string& role) -{ - return this->setting->getNewLayerID(role); + return false; } -WMError WMLayer::setLayerState(const LayerState& l) +WMError WMLayer::commitChange() { - this->before_state = l; + this->state = this->tmp_state; return WMError::SUCCESS; } -bool WMLayer::checkIDBelongTo(unsigned id) +void WMLayer::dump() { - return (id > this->setting->idBegin() && id < this->setting->idEnd()); -} + DUMP("===== wm layer status ====="); + DUMP("Layer :%s", this->name.c_str()); + this->tmp_state.dump(); + this->state.dump(); + DUMP("===== wm layer status end ====="); -/* WMError WMLayer::commitChange() -{ - this->state = this->before_state; } -void WMLayer::undo() +/* void WMLayer::undo() { - this->before_state = this->state; + this->tmp_state = this->state; } */ } // namespace wm