1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
|
/*
* 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 <ilm/ilm_control.h>
#include <stdlib.h>
#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()
: 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;
}
WMLayer::WMLayer(json_object* j) : before_state(), state()
{
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"));
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 WMLayer::getNewLayerID(const string& role)
{
unsigned ret = 0;
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;
}
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; // reset
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("set new id: %d", i);
ret = i;
break;
}
}
}
if(ret != 0)
{
id_list.push_back(ret);
}
else
{
HMI_ERROR("failed to get New ID");
}
return ret;
}
const string& WMLayer::layerName()
{
return this->name;
}
WMError WMLayer::setLayerState(const LayerState& l)
{
this->before_state = l;
return WMError::SUCCESS;
}
void WMLayer::appendArea(const string& area)
{
this->area_list.push_back(area);
}
void WMLayer::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());
}
bool WMLayer::checkIDBelongTo(unsigned id)
{
return (id > this->idBegin() && id < this->idEnd());
}
/* WMError WMLayer::commitChange()
{
this->state = this->before_state;
}
void WMLayer::undo()
{
this->before_state = this->state;
}
*/
} // namespace wm
|