X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fwm_layer.cpp;h=d74418aa1f5344a7b20a55c26a2fa46329bd49f1;hb=58561703d4053dfd454fe564b59215ce025c4a12;hp=773b5c23857abcb585e812cca68cf9ea11c79476;hpb=0b011c00b0c8aa847a4d0aa460a335c5eae8f010;p=apps%2Fagl-service-windowmanager.git diff --git a/src/wm_layer.cpp b/src/wm_layer.cpp index 773b5c2..d74418a 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" @@ -40,7 +41,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 +49,7 @@ const unordered_map LayerState::popCurrentState() return tmp; } -const unordered_map LayerState::getCurrentState() +const unordered_map LayerState::getCurrentState() { return this->area2appid; } @@ -58,34 +59,60 @@ 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) { + 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) +WMLayer::WMLayer(json_object* j) : before_state(), state() +{ + 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 || this->id_begin == 0 || this->id_end == 0) + { + 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 re = std::regex(this->role_list); - if (std::regex_match(role, re)) + + // generate new layer id; + if(this->hasRole(role)) { - // 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); + HMI_INFO("Generate new id: %d", ret); } - - if(ret == 0) + else { return ret; } @@ -118,61 +145,49 @@ unsigned LayerSetting::getNewLayerID(const string& role) return ret; } -void LayerSetting::removeLayerID(unsigned id) +const string& WMLayer::layerName() { - 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()); + return this->name; } -WMLayer::WMLayer() - : before_state(), - state(), - setting{} +WMError WMLayer::setLayerState(const LayerState& l) { - // this->setting = std::make_unique(name, type, begin, end); + this->before_state = l; + return WMError::SUCCESS; } -WMLayer::WMLayer(json_object* j) : before_state(), state() +void WMLayer::appendArea(const string& area) { - 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) - { - HMI_ERROR("INVALID."); - } - 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); + this->area_list.push_back(area); } -unsigned WMLayer::getNewLayerID(const std::string& role) +void WMLayer::removeLayerID(unsigned id) { - return this->setting->getNewLayerID(role); + 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()); } -WMError WMLayer::setLayerState(const LayerState& l) +bool WMLayer::hasLayerID(unsigned id) { - this->before_state = l; - return WMError::SUCCESS; + 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::checkIDBelongTo(unsigned id) +bool WMLayer::hasRole(const string& role) { - return (id > this->setting->idBegin() && id < this->setting->idEnd()); + auto re = std::regex(this->role_list); + if (std::regex_match(role, re)) + { + HMI_DEBUG("role %s matches layer %d", role.c_str(), this->name.c_str()); + return true; + } + return false; } /* WMError WMLayer::commitChange()