X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fwm_layer.cpp;h=f02a5b62823962e1ef36413ec80db374006da306;hb=e5295c77d4c436212265edeca7f9a4818a5133e6;hp=07b41e1e7c052978b1ce188d4b040829def63dc2;hpb=c3291c967516a188789a860821471d8c872fbb47;p=apps%2Fagl-service-windowmanager.git diff --git a/src/wm_layer.cpp b/src/wm_layer.cpp index 07b41e1..f02a5b6 100644 --- a/src/wm_layer.cpp +++ b/src/wm_layer.cpp @@ -15,56 +15,93 @@ */ #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; 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; } -unsigned LayerSetting::getNewLayerID(const string& role) +const vector LayerState::getIviIdList() +{ + return this->render_order; +} + +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 found = std::find(role_list.cbegin(), role_list.cend(), role); - if(found == role_list.cend()) + auto re = std::regex(this->role_list); + if (std::regex_match(role, re)) + { + // 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); + } + + if(ret == 0) { 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; + ret = 0; // reset for(unsigned i = this->idBegin(); i < this->idEnd(); i++) { auto ret_found = std::find(id_list.begin(), id_list.end(), i); @@ -88,36 +125,44 @@ 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; } -unsigned WMLayer::getNewLayerID(const std::string& role) +void WMLayer::appendArea(const string& area) { - return this->setting->getNewLayerID(role); + this->area_list.push_back(area); } -WMError WMLayer::setLayerState(const LayerState& l) +void WMLayer::removeLayerID(unsigned id) { - return WMError::SUCCESS; + 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()); } bool WMLayer::checkIDBelongTo(unsigned id) { - return (id > this->setting->idBegin() && id < this->setting->idEnd()); + return (id > this->idBegin() && id < this->idEnd()); +} + +/* WMError WMLayer::commitChange() +{ + this->state = this->before_state; } +void WMLayer::undo() +{ + this->before_state = this->state; +} + */ } // namespace wm