c291151ff465b257bff0218d335b82ba94a190a0
[apps/agl-service-windowmanager-2017.git] / src / wm_layer.hpp
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 #ifndef WM_LAYER_HPP
18 #define WM_LAYER_HPP
19
20 #include <string>
21 #include <vector>
22 #include <unordered_map>
23 #include <memory>
24 #include "wm_error.hpp"
25
26 struct json_object;
27
28 namespace wm
29 {
30
31 class WMClient;
32 class LayerState
33 {
34   public:
35     LayerState();
36     ~LayerState() = default;
37     void attachIdToArea(const std::string& area, const WMClient&);
38     const std::unordered_map<std::string, std::string> popCurrentState();
39     const std::unordered_map<std::string, std::string> getCurrentState();
40     const std::vector<unsigned> getIviIdList();
41     void addLayer(unsigned layer);
42     void removeLayer(unsigned layer);
43     void setArea(const std::string& app, const std::string& area);
44
45     // Debug
46     void dump();
47
48   private:
49     std::vector<unsigned> render_order;
50     std::unordered_map<std::string, std::string> area2appid;
51 };
52
53 class WMLayer
54 {
55   public:
56     enum MANAGEMENT_TYPE
57     {
58         TILE,
59         STACK
60     };
61
62     explicit WMLayer(json_object* j, unsigned uuid);
63     ~WMLayer() = default;
64
65     // Status & Setting API
66     unsigned getNewLayerID(const std::string& role);
67     unsigned idBegin() { return this->id_begin; }
68     unsigned idEnd()   { return this->id_end; }
69     unsigned getUuid() { return this->uuid; }
70     const std::string& layerName();
71     MANAGEMENT_TYPE    layerType() { return this->type; }
72     void appendArea(const std::string& area);
73     LayerState& getLayerState() { return tmp_state; }
74     WMError setLayerState(const LayerState& l);
75     bool hasLayerID(unsigned id);
76     bool hasRole(const std::string& role);
77
78     // Manipulation
79     void addLayerToState(unsigned layer);
80     void removeLayerFromState(unsigned layer);
81     void setAreaToState(const std::string& app, const std::string& area);
82     void terminateApp(unsigned layer);
83     WMError commitChange();
84
85     // Debug
86     void dump();
87
88   private:
89     LayerState tmp_state;
90     LayerState state;
91     unsigned uuid;
92     std::string name = ""; // Layer name
93     MANAGEMENT_TYPE type;
94     std::string role_list;
95     std::vector<std::string> area_list;
96     std::vector<unsigned>    id_list;
97     unsigned id_begin;
98     unsigned id_end;
99 };
100
101 } // namespace wm
102
103 #endif // WM_LAYER_HPP