aboutsummaryrefslogtreecommitdiffstats
path: root/src/wm_layer.cpp
blob: 07b41e1e7c052978b1ce188d4b040829def63dc2 (plain)
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
/*
 * 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 "util.hpp"

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("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;
        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;
}

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