#include <regex>
+#include "wm_client.hpp"
#include "wm_layer.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()
{}
+
+void LayerState::attachIdToArea(const string& area, const WMClient& client)
+{
+ this->area2appid[area] = client.appID();
+ this->render_order.push_back(client.layerID());
+}
+
+const unordered_map<std::string, std::string> LayerState::popCurrentState()
+{
+ unordered_map<string, string> tmp = this->area2appid;
+ this->area2appid.clear();
+ this->render_order.clear();
+ return tmp;
+}
+
+const unordered_map<std::string, std::string> LayerState::getCurrentState()
+{
+ return this->area2appid;
+}
+
+const vector<unsigned> 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 LayerSetting::appendRole(const string& role)
+void LayerSetting::setRoleList(const string& role)
{
- this->role_list.push_back(role);
+ this->role_list = role;
}
void LayerSetting::appendArea(const string& area)
unsigned LayerSetting::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);
{
LayerSetting::MANAGEMENT_TYPE t;
const char* layer_name = jh::getStringFromJson(j, "name");
- const char* role = jh::getStringFromJson(j, "role");
+ 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)
+ if (layer_name || type || begin < 0 || end < 0)
{
HMI_ERROR("Parse Error!!");
}
HMI_ERROR("INVALID.");
}
string str_type = type;
- t = (type == "tile") ? LayerSetting::TILE : LayerSetting::STACK;
+ t = (str_type == "tile") ? LayerSetting::TILE : LayerSetting::STACK;
this->setting = std::make_unique<LayerSetting>(name, t, begin, end);
- this->setting->appendRole(role);
+ this->setting->setRoleList(roles);
}
unsigned WMLayer::getNewLayerID(const std::string& role)
WMError WMLayer::setLayerState(const LayerState& l)
{
+ this->before_state = l;
return WMError::SUCCESS;
}
return (id > this->setting->idBegin() && id < this->setting->idEnd());
}
+/* WMError WMLayer::commitChange()
+{
+ this->state = this->before_state;
+}
+
+void WMLayer::undo()
+{
+ this->before_state = this->state;
+}
+ */
} // namespace wm
#include "wm_layer.hpp"\r
#include "json_helper.hpp"\r
\r
-#define LC_AREA_PATH "/etc/area.db"\r
+#define LC_AREA_PATH "/etc/areas.db"\r
#define LC_LAYER_SETTING_PATH "/etc/layer_setting.json"\r
\r
using std::string;\r
+using std::vector;\r
\r
namespace wm {\r
\r
-static void notification_static(ilmObjectType object,\r
+LayerControl* g_lc_ctxt;\r
+\r
+static void createCallback_static(ilmObjectType object,\r
t_ilm_uint id,\r
t_ilm_bool created,\r
void* data)\r
{\r
- static_cast<LayerControl*>(data)->dispatchILMEvent(object, id, created);\r
+ static_cast<LayerControl*>(data)->dispatchCreateEvent(object, id, created);\r
+}\r
+\r
+static void surfaceCallback_static(t_ilm_surface surface,\r
+ struct ilmSurfaceProperties* surface_prop,\r
+ t_ilm_notification_mask mask)\r
+{\r
+ g_lc_ctxt->dispatchPropertyChangeEvent(surface, surface_prop, mask);\r
+}\r
+\r
+static void layerCallback_static(t_ilm_layer layer,\r
+ struct ilmLayerProperties* layer_prop,\r
+ t_ilm_notification_mask mask)\r
+{\r
+ g_lc_ctxt->dispatchPropertyChangeEvent(layer, layer_prop, mask);\r
}\r
\r
LayerControl::LayerControl(const std::string& root)\r
assert(ret == WMError::SUCCESS);\r
}\r
\r
-WMError LayerControl::init()\r
+WMError LayerControl::init(const LayerControlCallbacks& cb)\r
{\r
ilmErrorTypes rc = ilm_init();\r
t_ilm_uint num = 0;\r
}\r
if(rc != ILM_SUCCESS) goto lc_init_error;\r
\r
+ // Get current screen setting\r
rc = ilm_getScreenIDs(&num, &ids);\r
\r
if(rc != ILM_SUCCESS) goto lc_init_error;\r
if(rc != ILM_SUCCESS) goto lc_init_error;\r
\r
// Register Callback from ILM\r
- ilm_registerNotification(notification_static, this);\r
+ this->cb = cb;\r
+ ilm_registerNotification(createCallback_static, this);\r
\r
return WMError::SUCCESS;\r
\r
return ret;\r
}\r
\r
-WMError LayerControl::updateLayer(WMLayer& wm_layer)\r
+WMError LayerControl::updateLayer(LayerState& layer_state)\r
{\r
return WMError::SUCCESS;\r
}\r
\r
-void LayerControl::commitChange() {}\r
+WMError LayerControl::commitChange()\r
+{\r
+ WMError rc = WMError::SUCCESS;\r
+ vector<unsigned> ivi_l_ids;\r
+ for(const auto& l : this->wm_layers)\r
+ {\r
+ auto state = l->getLayerState();\r
+ for(const auto& id : state.getIviIdList())\r
+ {\r
+ ivi_l_ids.push_back(id);\r
+ }\r
+ }\r
+ t_ilm_layer* id_array = new t_ilm_layer[ivi_l_ids.size()];\r
+ if(id_array == nullptr)\r
+ {\r
+ HMI_WARNING("short memory");\r
+ this->undoUpdate();\r
+ return WMError::FAIL;\r
+ }\r
+ int count = 0;\r
+ for(const auto& i : ivi_l_ids)\r
+ {\r
+ id_array[count] = i;\r
+ }\r
+\r
+ ilmErrorTypes ret = ilm_displaySetRenderOrder(this->screenID, id_array, ivi_l_ids.size());\r
+ if(ret != ILM_SUCCESS)\r
+ {\r
+ this->undoUpdate();\r
+ rc = WMError::FAIL;\r
+ }\r
+ delete id_array;\r
+ return rc;\r
+}\r
\r
void LayerControl::undoUpdate() {}\r
\r
return WMError::SUCCESS;\r
}\r
\r
-void LayerControl::dispatchILMEvent(ilmObjectType object, t_ilm_uint id, t_ilm_bool created)\r
+void LayerControl::dispatchCreateEvent(ilmObjectType object, unsigned id, bool created)\r
+{\r
+ this->cb.test(id);\r
+ if (ILM_SURFACE == object)\r
+ {\r
+ if (created)\r
+ {\r
+ ilmSurfaceProperties sp;\r
+ ilmErrorTypes rc;\r
+ rc = ilm_getPropertiesOfSurface(id, &sp);\r
+ if(rc != ILM_SUCCESS)\r
+ return;\r
+ // this->cb->surfaceCreated(pid, id);\r
+ ilm_surfaceAddNotification(id, surfaceCallback_static);\r
+ ilm_surfaceSetSourceRectangle(id, 0, 0, sp.origSourceWidth, sp.origSourceHeight);\r
+ }\r
+ else\r
+ {\r
+ // this->cb->surfaceDestroyed(id);\r
+ }\r
+ }\r
+ if (ILM_LAYER == object)\r
+ {\r
+ if(created)\r
+ {\r
+ ilm_layerAddNotification(id, layerCallback_static);\r
+ // this->cb->layerCreated(id);\r
+ }\r
+ else\r
+ {\r
+ // this->cb->layerDestroyed(id); // Means Application is dead.\r
+ }\r
+ }\r
+}\r
+\r
+void LayerControl::dispatchPropertyChangeEvent(unsigned id,\r
+ struct ilmSurfaceProperties* sprop,\r
+ t_ilm_notification_mask mask)\r
+{\r
+ pid_t pid = sprop->creatorPid;\r
+ HMI_DEBUG("pid : %d", pid);\r
+\r
+ if (ILM_NOTIFICATION_VISIBILITY & mask)\r
+ {\r
+ //this->cb->surfaceVisibilityChanged(id, sprop->visibility);\r
+ }\r
+ if (ILM_NOTIFICATION_OPACITY & mask)\r
+ {\r
+ }\r
+ if (ILM_NOTIFICATION_ORIENTATION & mask)\r
+ {\r
+ }\r
+ if (ILM_NOTIFICATION_SOURCE_RECT & mask)\r
+ {\r
+ // this->cb->surfaceSourceRectChanged(id, )\r
+ }\r
+ if (ILM_NOTIFICATION_DEST_RECT & mask)\r
+ {\r
+ // this->cb->surfaceSourceRectChanged(id, )\r
+ }\r
+ if (ILM_NOTIFICATION_CONTENT_AVAILABLE & mask)\r
+ {\r
+ }\r
+ if (ILM_NOTIFICATION_CONTENT_REMOVED & mask)\r
+ {\r
+ /* application being down */\r
+ // m_appLayers.remove(pid);\r
+ }\r
+ if (ILM_NOTIFICATION_CONFIGURED & mask)\r
+ {\r
+ /* qDebug("ILM_NOTIFICATION_CONFIGURED");\r
+ qDebug(" surfaceProperties %d", surface);\r
+ qDebug(" surfaceProperties.origSourceWidth: %d", surfaceProperties->origSourceWidth);\r
+ qDebug(" surfaceProperties.origSourceHeight: %d", surfaceProperties->origSourceHeight);\r
+\r
+ if (surface == WINDOWMANAGER_HOMESCREEN_MAIN_SURFACE_ID) {\r
+ addSurfaceToLayer(surface, WINDOWMANAGER_LAYER_HOMESCREEN);\r
+ configureHomeScreenMainSurface(surface, surfaceProperties->origSourceWidth, surfaceProperties->origSourceHeight);\r
+ } else {\r
+ ilmErrorTypes result;\r
+ t_ilm_layer layer = addSurfaceToAppLayer(pid, surface);\r
+\r
+ if (layer != 0) {\r
+ configureAppSurface(surface,\r
+ surfaceProperties->origSourceWidth,\r
+ surfaceProperties->origSourceHeight);\r
+\r
+ result = ilm_layerAddSurface(layer, surface);\r
+ if (result != ILM_SUCCESS) {\r
+ qDebug("ilm_layerAddSurface(%d,%d) failed.", layer, surface);\r
+ }\r
+ ilm_commitChanges();\r
+ }\r
+ }\r
+ updateScreen(); */\r
+ }\r
+}\r
+\r
+void LayerControl::dispatchPropertyChangeEvent(unsigned id,\r
+ struct ilmLayerProperties* lprop,\r
+ t_ilm_notification_mask mask)\r
{\r
- ;\r
+ if (ILM_NOTIFICATION_VISIBILITY & mask)\r
+ {\r
+ //this->cb->layerVisibilityChanged(id, sprop->visibility);\r
+ }\r
+ if (ILM_NOTIFICATION_OPACITY & mask)\r
+ {\r
+ }\r
+ if (ILM_NOTIFICATION_ORIENTATION & mask)\r
+ {\r
+ }\r
+ if (ILM_NOTIFICATION_SOURCE_RECT & mask)\r
+ {\r
+ // this->cb->surfaceSourceRectChanged(id, )\r
+ }\r
+ if (ILM_NOTIFICATION_DEST_RECT & mask)\r
+ {\r
+ // this->cb->surfaceSourceRectChanged(id, )\r
+ }\r
+ if (ILM_NOTIFICATION_CONTENT_AVAILABLE & mask)\r
+ {\r
+ }\r
+ if (ILM_NOTIFICATION_CONTENT_REMOVED & mask)\r
+ {\r
+ /* application being down */\r
+ // m_appLayers.remove(pid);\r
+ }\r
+ if (ILM_NOTIFICATION_CONFIGURED & mask)\r
+ {\r
+ /* qDebug("ILM_NOTIFICATION_CONFIGURED");\r
+ qDebug(" surfaceProperties %d", surface);\r
+ qDebug(" surfaceProperties.origSourceWidth: %d", surfaceProperties->origSourceWidth);\r
+ qDebug(" surfaceProperties.origSourceHeight: %d", surfaceProperties->origSourceHeight);\r
+\r
+ if (surface == WINDOWMANAGER_HOMESCREEN_MAIN_SURFACE_ID) {\r
+ addSurfaceToLayer(surface, WINDOWMANAGER_LAYER_HOMESCREEN);\r
+ configureHomeScreenMainSurface(surface, surfaceProperties->origSourceWidth, surfaceProperties->origSourceHeight);\r
+ } else {\r
+ ilmErrorTypes result;\r
+ t_ilm_layer layer = addSurfaceToAppLayer(pid, surface);\r
+\r
+ if (layer != 0) {\r
+ configureAppSurface(surface,\r
+ surfaceProperties->origSourceWidth,\r
+ surfaceProperties->origSourceHeight);\r
+\r
+ result = ilm_layerAddSurface(layer, surface);\r
+ if (result != ILM_SUCCESS) {\r
+ qDebug("ilm_layerAddSurface(%d,%d) failed.", layer, surface);\r
+ }\r
+ ilm_commitChanges();\r
+ }\r
+ }\r
+ updateScreen(); */\r
+ }\r
}\r
\r
} // namespace wm
\ No newline at end of file
#include <memory>\r
#include <vector>\r
#include <unordered_map>\r
+#include <functional>\r
#include <ilm/ilm_control.h>\r
#include "wm_error.hpp"\r
#include "util.hpp"\r
\r
};\r
\r
+class LayerControlCallbacks {\r
+ public:\r
+ LayerControlCallbacks() {};\r
+ virtual ~LayerControlCallbacks() = default;\r
+ LayerControlCallbacks(const LayerControlCallbacks &obj) = default;\r
+\r
+ // callback functions\r
+ virtual void test(unsigned i) { HMI_DEBUG("test %d", i); }\r
+ std::function<void(unsigned)> surfaceCreated;\r
+ /* std::function<void(unsigned)> surfaceDestroyed;\r
+ std::function<void(unsigned)> layerCreated;\r
+ std::function<void(unsigned)> layerDestroyed; */\r
+};\r
+\r
class WMLayer;\r
+class LayerState;\r
class LayerControl\r
{\r
public:\r
explicit LayerControl(const std::string& root);\r
~LayerControl() = default;\r
- WMError init();\r
+ WMError init(const LayerControlCallbacks& cb);\r
unsigned getNewLayerID(const std::string& role);\r
// void setRenderOrder(const std::vector<unsigned> layer_render_order);\r
// std::vector<unsigned> getAllRenderOrder();\r
// std::vector<std::shared_ptr<WMLayer>>& getAllLayers();\r
// std::vector<unsigned> getRenderOrder(const std::string& layer_name);\r
- WMError updateLayer(WMLayer& wm_layer);\r
- void commitChange();\r
+ WMError updateLayer(LayerState& layer_state);\r
+ WMError commitChange();\r
void undoUpdate();\r
\r
// Don't use this function.\r
- void dispatchILMEvent(ilmObjectType object, t_ilm_uint id, t_ilm_bool created);\r
+ void dispatchCreateEvent(ilmObjectType object, unsigned id, bool created);\r
+ void dispatchPropertyChangeEvent(unsigned id, struct ilmSurfaceProperties*, t_ilm_notification_mask);\r
+ void dispatchPropertyChangeEvent(unsigned id, struct ilmLayerProperties*, t_ilm_notification_mask);\r
private:\r
WMError loadLayerSetting(const std::string& path);\r
WMError loadAreaDb(const std::string& path);\r
+\r
std::vector<std::shared_ptr<WMLayer>> wm_layers;\r
std::unordered_map<std::string, struct rect> area2size;\r
unsigned screenID;\r
struct ilmScreenProperties screen_prop;\r
+ LayerControlCallbacks cb;\r
};\r
\r
} // namespace wm
\ No newline at end of file