*/
#include <regex>
-
+#include <ilm/ilm_control.h>
+#include <stdlib.h>
#include "wm_client.hpp"
#include "wm_layer.hpp"
#include "json_helper.hpp"
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;
}
-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, unsigned uuid) : tmp_state(), state(), uuid(uuid)
{
- unsigned ret = 0;
- auto re = std::regex(this->role_list);
- if (std::regex_match(role, re))
+ 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<unsigned>(jh::getIntFromJson(j, "id_range_begin"));
+ this->id_end = static_cast<unsigned>(jh::getIntFromJson(j, "id_range_end"));
+
+ if (name.size() == 0 || !type)
+ {
+ HMI_ERROR("Parse Error!!");
+ exit(1);
+ }
+ if(this->id_begin > this->id_end)
{
- // 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_ERROR("INVALID");
+ exit(1);
}
+ string str_type = type;
+ this->type = (str_type == "tile") ? MANAGEMENT_TYPE::TILE : MANAGEMENT_TYPE::STACK;
+}
- if(ret == 0)
+unsigned WMLayer::getNewLayerID(const string& role)
+{
+ unsigned ret = 0;
+
+ // 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
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<LayerSetting>(name, type, begin, end);
+ this->tmp_state = l;
+ return WMError::SUCCESS;
}
-WMLayer::WMLayer(json_object* j) : before_state(), state()
+void WMLayer::addLayer(unsigned layer)
{
- 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;
+ this->tmp_state.addLayer(layer);
+}
- 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<LayerSetting>(name, t, begin, end);
- this->setting->setRoleList(roles);
+void WMLayer::appendArea(const string& area)
+{
+ 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());
+ // TODO : use virtual to avoid compare
+ if(this->name == BG_LAYER_NAME)
+ return false;
+ 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::undo()
+/* void WMLayer::undo()
{
- this->before_state = this->state;
+ this->tmp_state = this->state;
}
*/
} // namespace wm