Update wm_layer
authorKazumasa Mitsunari <knimitz@witz-inc.co.jp>
Mon, 27 Aug 2018 02:13:14 +0000 (11:13 +0900)
committerKazumasa Mitsunari <knimitz@witz-inc.co.jp>
Mon, 27 Aug 2018 10:16:45 +0000 (19:16 +0900)
Change-Id: Id4b9fe2ec6603e8ab0ad5cfa9b0af6dce3b1d149
Signed-off-by: Kazumasa Mitsunari <knimitz@witz-inc.co.jp>
src/wm_layer.cpp
src/wm_layer.hpp
src/wm_layer_control.cpp
src/wm_layer_control.hpp

index 6131165..773b5c2 100644 (file)
 
 #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)
@@ -50,20 +77,24 @@ 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);
@@ -108,13 +139,13 @@ WMLayer::WMLayer(json_object* j) : before_state(), state()
 {
     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!!");
     }
@@ -123,9 +154,9 @@ WMLayer::WMLayer(json_object* j) : before_state(), state()
         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)
@@ -135,6 +166,7 @@ unsigned WMLayer::getNewLayerID(const std::string& role)
 
 WMError WMLayer::setLayerState(const LayerState& l)
 {
+    this->before_state = l;
     return WMError::SUCCESS;
 }
 
@@ -143,4 +175,14 @@ bool WMLayer::checkIDBelongTo(unsigned id)
     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
index 6cfd9c2..001134a 100644 (file)
@@ -28,15 +28,20 @@ struct json_object;
 namespace wm
 {
 
+class WMClient;
 class LayerState
 {
   public:
     LayerState();
     ~LayerState() = default;
+    void attachIdToArea(const std::string& area, const WMClient&);
+    const std::unordered_map<std::string, std::string> popCurrentState();
+    const std::unordered_map<std::string, std::string> getCurrentState();
+    const std::vector<unsigned> getIviIdList();
+
   private:
-    std::vector<unsigned> _ivi_layer_id_list;
-    std::unordered_map<std::string, unsigned> area2ivi_layer_id;
-    // std::map<std::string, unsigned> _render_order;
+    std::vector<unsigned> render_order;
+    std::unordered_map<std::string, std::string> area2appid;
 };
 
 class LayerSetting
@@ -53,7 +58,7 @@ class LayerSetting
 
     const std::string& layerName() { return this->name; }
     MANAGEMENT_TYPE layerType() { return this->type; };
-    void appendRole(const std::string& role);
+    void setRoleList(const std::string& role);
     void appendArea(const std::string& area);
     unsigned idBegin() { return this->id_begin; }
     unsigned idEnd()   { return this->id_end; }
@@ -70,7 +75,7 @@ class LayerSetting
   private:
     std::string name = ""; // Layer name
     MANAGEMENT_TYPE type;
-    std::vector<std::string> role_list;
+    std::string role_list;
     std::vector<std::string> area_list;
     std::vector<unsigned>    id_list;
     unsigned id_begin;
index b15ebbb..72a3a19 100644 (file)
 #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
@@ -46,7 +63,7 @@ LayerControl::LayerControl(const std::string& root)
     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
@@ -67,6 +84,7 @@ WMError LayerControl::init()
     }\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
@@ -83,7 +101,8 @@ WMError LayerControl::init()
     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
@@ -107,12 +126,45 @@ unsigned LayerControl::getNewLayerID(const string& role)
     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
@@ -217,9 +269,162 @@ WMError LayerControl::loadAreaDb(const std::string& path)
     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
index d8d3273..ad6bf53 100644 (file)
@@ -18,6 +18,7 @@
 #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
@@ -28,31 +29,50 @@ class Screen : public rectangle {
 \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