Remove hmi-debug.h
[apps/agl-service-windowmanager-2017.git] / src / wm_layer.cpp
1 /*
2  * Copyright (c) 2017 TOYOTA MOTOR CORPORATION
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include <regex>
18
19 #include "wm_layer.hpp"
20 #include "wayland_ivi_wm.hpp"
21 #include "json_helper.hpp"
22 #include "util.hpp"
23
24 using std::string;
25 using std::vector;
26
27 namespace wm
28 {
29
30 LayerState::LayerState()
31     :  _ivi_layer_id_list(),
32        area2ivi_layer_id()
33 {}
34
35 LayerSetting::LayerSetting(const string& name, MANAGEMENT_TYPE type, unsigned begin, unsigned end)
36     : name(name), type(type),
37      role_list(), area_list(), id_list(),
38      id_begin(begin), id_end(end)
39 {}
40
41 void LayerSetting::appendRole(const string& role)
42 {
43     this->role_list.push_back(role);
44 }
45
46 void LayerSetting::appendArea(const string& area)
47 {
48     this->area_list.push_back(area);
49 }
50
51 unsigned LayerSetting::getNewLayerID(const string& role)
52 {
53     unsigned ret = 0;
54     auto found = std::find(role_list.cbegin(), role_list.cend(), role);
55     if(found == role_list.cend())
56     {
57         return ret;
58     }
59     // generate new ivi layer id
60     ret = id_list.back() + 1;
61     HMI_INFO("wm", "generate ivi_layer_id : %d on the layer: %s", ret, this->name.c_str());
62
63     auto id_found = std::find(id_list.begin(), id_list.end(), ret);
64     if( (ret > this->idEnd()) || (id_found != id_list.cend()) )
65     {
66         HMI_NOTICE("wm", "id %d is not available then generate new id", ret);
67         ret = 0;
68         for(unsigned i = this->idBegin(); i < this->idEnd(); i++)
69         {
70             auto ret_found = std::find(id_list.begin(), id_list.end(), i);
71             if(ret_found == id_list.cend())
72             {
73                 HMI_INFO("wm", "set new id: %d", i);
74                 ret = i;
75                 break;
76             }
77         }
78     }
79
80     if(ret != 0)
81     {
82         id_list.push_back(ret);
83     }
84     else
85     {
86         HMI_ERROR("wm", "failed to get New ID");
87     }
88     return ret;
89 }
90
91 void LayerSetting::removeLayerID(unsigned id)
92 {
93     auto fwd_itr = std::remove_if(this->id_list.begin(), this->id_list.end(),
94         [id](unsigned elm) {
95             return elm == id;
96         });
97     this->id_list.erase(fwd_itr, this->id_list.end());
98 }
99
100 WMLayer::WMLayer()
101     :  before_state(),
102        state(),
103        setting{}
104 {
105     // this->setting = std::make_unique<LayerSetting>(name, type, begin, end);
106 }
107
108 unsigned WMLayer::getNewLayerID(const std::string& role)
109 {
110     return this->setting->getNewLayerID(role);
111 }
112
113 WMError WMLayer::setLayerState(const LayerState& l)
114 {
115     return WMError::SUCCESS;
116 }
117
118 bool WMLayer::checkIDBelongTo(unsigned id)
119 {
120     return (id > this->setting->idBegin() && id < this->setting->idEnd());
121 }
122
123 } // namespace wm