Update wm_layer
authorKazumasa Mitsunari <knimitz@witz-inc.co.jp>
Mon, 27 Aug 2018 06:28:00 +0000 (15:28 +0900)
committerKazumasa Mitsunari <knimitz@witz-inc.co.jp>
Mon, 27 Aug 2018 10:17:17 +0000 (19:17 +0900)
Change-Id: Ia8277ba20a97a0a5b3617ae14a447e0e962afafd
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 773b5c2..f02a5b6 100644 (file)
@@ -15,7 +15,8 @@
  */
 
 #include <regex>
-
+#include <ilm/ilm_control.h>
+#include <stdlib.h>
 #include "wm_client.hpp"
 #include "wm_layer.hpp"
 #include "json_helper.hpp"
@@ -58,23 +59,29 @@ 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::setRoleList(const string& role)
+WMLayer::WMLayer(json_object* j) : before_state(), state()
 {
-    this->role_list = role;
-}
+    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"));
 
-void LayerSetting::appendArea(const string& area)
-{
-    this->area_list.push_back(area);
+    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 LayerSetting::getNewLayerID(const string& role)
+unsigned WMLayer::getNewLayerID(const string& role)
 {
     unsigned ret = 0;
     auto re = std::regex(this->role_list);
@@ -118,61 +125,34 @@ unsigned LayerSetting::getNewLayerID(const string& role)
     return ret;
 }
 
-void LayerSetting::removeLayerID(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());
-}
-
-WMLayer::WMLayer()
-    :  before_state(),
-       state(),
-       setting{}
+const string& WMLayer::layerName()
 {
-    // this->setting = std::make_unique<LayerSetting>(name, type, begin, end);
+    return this->name;
 }
 
-WMLayer::WMLayer(json_object* j) : before_state(), state()
+WMError WMLayer::setLayerState(const LayerState& l)
 {
-    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;
-
-    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);
+    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)
 {
-    this->before_state = l;
-    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()
index 001134a..3362ba7 100644 (file)
@@ -44,7 +44,7 @@ class LayerState
     std::unordered_map<std::string, std::string> area2appid;
 };
 
-class LayerSetting
+class WMLayer
 {
   public:
     enum MANAGEMENT_TYPE
@@ -53,26 +53,21 @@ class LayerSetting
         STACK
     };
 
-    explicit LayerSetting(const std::string& name, MANAGEMENT_TYPE type, unsigned begin, unsigned end);
-    ~LayerSetting() = default;
-
-    const std::string& layerName() { return this->name; }
-    MANAGEMENT_TYPE layerType() { return this->type; };
-    void setRoleList(const std::string& role);
-    void appendArea(const std::string& area);
+    explicit WMLayer(json_object* j);
+    ~WMLayer() = default;
+    unsigned getNewLayerID(const std::string& role);
     unsigned idBegin() { return this->id_begin; }
     unsigned idEnd()   { return this->id_end; }
-    unsigned getNewLayerID(const std::string& role);
+    const std::string& layerName();
+    MANAGEMENT_TYPE    layerType() { return this->type; }
+    void appendArea(const std::string& area);
     void removeLayerID(unsigned id);
-
-/*     unsigned getNewID(const std::string& role);
-    void remove(unsigned ivi_layer_id);
-    void clear();
-    bool attach(unsigned ivi_layer_id, const std::string& area);
-    void stack(unsigned ivi_layer_id, const std::string& area);
-    bool updateRenderOrder(const std::vector<unsigned> list); */
-
+    LayerState getLayerState() const { return before_state; }
+    WMError    setLayerState(const LayerState& l);
+    bool checkIDBelongTo(unsigned id);
   private:
+    LayerState before_state;
+    LayerState state;
     std::string name = ""; // Layer name
     MANAGEMENT_TYPE type;
     std::string role_list;
@@ -82,22 +77,6 @@ class LayerSetting
     unsigned id_end;
 };
 
-class WMLayer
-{
-  public:
-    WMLayer();
-    WMLayer(json_object* j);
-    ~WMLayer() = default;
-    unsigned getNewLayerID(const std::string& role);
-    LayerState getLayerState() const { return before_state; }
-    WMError setLayerState(const LayerState& l);
-    bool checkIDBelongTo(unsigned id);
-  private:
-    LayerState before_state;
-    LayerState state;
-    std::unique_ptr<LayerSetting> setting;
-};
-
 } // namespace wm
 
 #endif // WM_LAYERS_H
index 0e72fab..9c60286 100644 (file)
@@ -21,6 +21,7 @@
 \r
 #define LC_AREA_PATH "/etc/areas.db"\r
 #define LC_LAYER_SETTING_PATH "/etc/layer_setting.json"\r
+#define LC_DEFAULT_AREA "normal.full"\r
 \r
 using std::string;\r
 using std::vector;\r
@@ -112,7 +113,19 @@ lc_init_error:
     return WMError::FAIL;\r
 }\r
 \r
-unsigned LayerControl::getNewLayerID(const string& role)\r
+void LayerControl::createNewLayer(unsigned id)\r
+{\r
+    HMI_INFO("create new ID :%d", id);\r
+    struct rect rct = this->area2size[LC_DEFAULT_AREA];\r
+    ilm_layerCreateWithDimension(&id, rct.w, rct.h);\r
+    ilm_layerSetSourceRectangle(id, rct.x, rct.y, rct.w, rct.h);\r
+    ilm_layerSetDestinationRectangle(id, rct.x, rct.y, rct.w, rct.h);\r
+    ilm_layerSetOpacity(id, 1.0);\r
+    ilm_layerSetVisibility(id, ILM_TRUE);\r
+    ilm_commitChanges();\r
+}\r
+\r
+unsigned LayerControl::getNewLayerID(const string& role, string* layer_name)\r
 {\r
     unsigned ret = 0;\r
     for(const auto& l: this->wm_layers)\r
@@ -120,6 +133,7 @@ unsigned LayerControl::getNewLayerID(const string& role)
         ret = l->getNewLayerID(role);\r
         if(ret != 0)\r
         {\r
+            *layer_name = l->layerName();\r
             break;\r
         }\r
     }\r
@@ -134,6 +148,7 @@ struct rect LayerControl::getAreaSize(const std::string& area)
 void LayerControl::setupArea(double scaling)\r
 {\r
     struct rect rct;\r
+    this->scaling = scaling;\r
 \r
     rct = this->area2size["normal.full"];\r
     this->area2size["normalfull"] = rct;\r
@@ -156,6 +171,11 @@ Screen LayerControl::getScreenInfo()
     return Screen(this->screen_prop.screenWidth, this->screen_prop.screenHeight);\r
 }\r
 \r
+double LayerControl::scale()\r
+{\r
+    return this->scaling;\r
+}\r
+\r
 WMError LayerControl::updateLayer(LayerState& layer_state)\r
 {\r
     return WMError::SUCCESS;\r
index 647a5c7..db482bf 100644 (file)
@@ -60,10 +60,12 @@ class LayerControl
     explicit LayerControl(const std::string& root);\r
     ~LayerControl() = default;\r
     WMError init(const LayerControlCallbacks& cb);\r
-    unsigned getNewLayerID(const std::string& role);\r
+    void createNewLayer(unsigned id);\r
+    unsigned getNewLayerID(const std::string& role, std::string* layer_name);\r
     struct rect getAreaSize(const std::string& area);\r
     void setupArea(double scaling);\r
     Screen getScreenInfo();\r
+    double scale();\r
     // void setRenderOrder(const std::vector<unsigned> layer_render_order);\r
     // std::vector<unsigned> getAllRenderOrder();\r
     // std::vector<std::shared_ptr<WMLayer>>& getAllLayers();\r
@@ -84,6 +86,7 @@ class LayerControl
     std::unordered_map<std::string, struct rect> area2size;\r
     unsigned screenID;\r
     struct ilmScreenProperties screen_prop;\r
+    double scaling;\r
     LayerControlCallbacks cb;\r
 };\r
 \r