using std::vector;
using std::unordered_map;
+#define BG_LAYER_NAME "BackGroundLayer"
+
namespace wm
{
this->render_order.push_back(client.layerID());
}
-const unordered_map<std::string, std::string> LayerState::popCurrentState()
+const unordered_map<string, string> LayerState::popCurrentState()
{
unordered_map<string, string> tmp = this->area2appid;
this->area2appid.clear();
return tmp;
}
-const unordered_map<std::string, std::string> LayerState::getCurrentState()
+const unordered_map<string, string> LayerState::getCurrentState()
{
return this->area2appid;
}
return this->render_order;
}
-WMLayer::WMLayer(json_object* j) : before_state(), state()
+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;
+}
+
+void LayerState::dump()
+{
+ std::string str;
+ for(const auto& ro : this->render_order)
+ {
+ 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");
this->id_begin = static_cast<unsigned>(jh::getIntFromJson(j, "id_range_begin"));
this->id_end = static_cast<unsigned>(jh::getIntFromJson(j, "id_range_end"));
- if (name.size() == 0 || type || this->id_begin == 0 || this->id_end == 0)
+ if (name.size() == 0 || !type)
{
HMI_ERROR("Parse Error!!");
exit(1);
unsigned WMLayer::getNewLayerID(const string& role)
{
unsigned ret = 0;
- auto re = std::regex(this->role_list);
- if (std::regex_match(role, re))
+ if(this->name == BG_LAYER_NAME)
+ return ret;
+
+ // 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);
+ 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);
}
-
- if(ret == 0)
+ 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
WMError WMLayer::setLayerState(const LayerState& l)
{
- this->before_state = 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::removeLayerID(unsigned id)
+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);
+}
+
+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::checkIDBelongTo(unsigned id)
+bool WMLayer::hasRole(const string& role)
{
- return (id > this->idBegin() && id < this->idEnd());
+ 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::commitChange()
+WMError WMLayer::commitChange()
{
- this->state = this->before_state;
+ this->state = this->tmp_state;
+ return WMError::SUCCESS;
+}
+
+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()
+/* void WMLayer::undo()
{
- this->before_state = this->state;
+ this->tmp_state = this->state;
}
*/
} // namespace wm