--- /dev/null
+/*\r
+ * Copyright (c) 2017 TOYOTA MOTOR CORPORATION\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+#include <assert.h>\r
+#include "layers.hpp"\r
+#include "layout_manager.hpp"\r
+\r
+using std::string;\r
+\r
+namespace wm {\r
+\r
+LayoutManager::LayoutManager(const string& path) : wm_layers()\r
+{\r
+ WMError ret = this->load(path);\r
+ assert(ret == WMError::SUCCESS);\r
+}\r
+\r
+LayoutManager::~LayoutManager()\r
+{}\r
+\r
+unsigned LayoutManager::getNewLayerID(const string& role)\r
+{\r
+ unsigned ret = 0;\r
+ for(const auto& l: this->wm_layers)\r
+ {\r
+ ret = l->getNewLayerID(role);\r
+ if(ret != 0)\r
+ {\r
+ break;\r
+ }\r
+ }\r
+ return ret;\r
+}\r
+\r
+WMError LayoutManager::updateLayer(WMLayer& wm_layer)\r
+{\r
+ return WMError::SUCCESS;\r
+}\r
+\r
+void LayoutManager::commitChange() {}\r
+\r
+void LayoutManager::undoUpdate() {}\r
+\r
+WMError LayoutManager::load(const string &path)\r
+{\r
+ return WMError::SUCCESS;\r
+}\r
+\r
+} // namespace wm
\ No newline at end of file
--- /dev/null
+/*\r
+ * Copyright (c) 2017 TOYOTA MOTOR CORPORATION\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+#include <string>\r
+#include <memory>\r
+#include <vector>\r
+\r
+#include "wm_error.hpp"\r
+#include "wm_layer.hpp"\r
+\r
+namespace wm {\r
+\r
+class LayoutManager\r
+{\r
+ public:\r
+ explicit LayoutManager(const std::string& path);\r
+ ~LayoutManager();\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
+ void undoUpdate();\r
+ private:\r
+ WMError load(const std::string& path);\r
+ std::vector<std::shared_ptr<WMLayer>> wm_layers;\r
+};\r
+\r
+} // namespace wm
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2017 TOYOTA MOTOR CORPORATION
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <regex>
+
+#include "wm_layer.hpp"
+#include "wayland_ivi_wm.hpp"
+#include "json_helper.hpp"
+#include "hmi-debug.h"
+
+using std::string;
+using std::vector;
+
+namespace wm
+{
+
+LayerState::LayerState()
+ : _ivi_layer_id_list(),
+ area2ivi_layer_id()
+{}
+
+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)
+{
+ this->role_list.push_back(role);
+}
+
+void LayerSetting::appendArea(const string& area)
+{
+ this->area_list.push_back(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())
+ {
+ return ret;
+ }
+ // generate new ivi layer id
+ ret = id_list.back() + 1;
+ HMI_INFO("wm", "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("wm", "id %d is not available then generate new id", ret);
+ ret = 0;
+ for(unsigned i = this->idBegin(); i < this->idEnd(); i++)
+ {
+ auto ret_found = std::find(id_list.begin(), id_list.end(), i);
+ if(ret_found == id_list.cend())
+ {
+ HMI_INFO("wm", "set new id: %d", i);
+ ret = i;
+ break;
+ }
+ }
+ }
+
+ if(ret != 0)
+ {
+ id_list.push_back(ret);
+ }
+ else
+ {
+ HMI_ERROR("wm", "failed to get New ID");
+ }
+ 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{}
+{
+ // this->setting = std::make_unique<LayerSetting>(name, type, begin, end);
+}
+
+unsigned WMLayer::getNewLayerID(const std::string& role)
+{
+ return this->setting->getNewLayerID(role);
+}
+
+WMError WMLayer::setLayerState(const LayerState& l)
+{
+ return WMError::SUCCESS;
+}
+
+bool WMLayer::checkIDBelongTo(unsigned id)
+{
+ return (id > this->setting->idBegin() && id < this->setting->idEnd());
+}
+
+} // namespace wm
--- /dev/null
+/*
+ * Copyright (c) 2017 TOYOTA MOTOR CORPORATION
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef WM_LAYERS_H
+#define WM_LAYERS_H
+
+#include <string>
+#include <vector>
+#include <unordered_map>
+#include <memory>
+#include "wm_error.hpp"
+
+namespace wm
+{
+
+class LayerState
+{
+ public:
+ LayerState();
+ ~LayerState() = default;
+ private:
+ std::vector<unsigned> _ivi_layer_id_list;
+ std::unordered_map<std::string, unsigned> area2ivi_layer_id;
+ // std::map<std::string, unsigned> _render_order;
+};
+
+class LayerSetting
+{
+ public:
+ enum MANAGEMENT_TYPE
+ {
+ TILE,
+ 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 appendRole(const std::string& role);
+ void appendArea(const std::string& area);
+ unsigned idBegin() { return this->id_begin; }
+ unsigned idEnd() { return this->id_end; }
+ unsigned getNewLayerID(const std::string& role);
+ 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); */
+
+ private:
+ std::string name = ""; // Layer name
+ MANAGEMENT_TYPE type;
+ std::vector<std::string> role_list;
+ std::vector<std::string> area_list;
+ std::vector<unsigned> id_list;
+ unsigned id_begin;
+ unsigned id_end;
+};
+
+class WMLayer
+{
+ public:
+ WMLayer();
+ ~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