97cf8a8bd95b36cc36451af545baf76192884e9e
[apps/agl-service-windowmanager.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     const std::unordered_map<std::string, std::string> getCurrentState();
38     const std::vector<unsigned> getIviIdList();
39     void addLayer(unsigned layer);
40     void removeLayer(unsigned layer);
41     void attachAppToArea(const std::string& app, const std::string& area);
42
43     // Debug
44     void dump();
45
46   private:
47     std::vector<unsigned> render_order;
48     std::unordered_map<std::string, std::string> area2appid;
49 };
50
51 class WMLayer
52 {
53   public:
54     explicit WMLayer(json_object* j, unsigned wm_layer_id);
55     ~WMLayer() = default;
56
57     // Status & Setting API
58     unsigned getNewLayerID(const std::string& role);
59     unsigned idBegin() { return this->id_begin; }
60     unsigned idEnd()   { return this->id_end; }
61     unsigned getWMLayerID() { return this->wm_layer_id; }
62     const std::string& layerName();
63     void appendArea(const std::string& area);
64     LayerState& getLayerState() { return tmp_state; }
65     WMError setLayerState(const LayerState& l);
66     bool hasLayerID(unsigned id);
67     bool hasRole(const std::string& role);
68
69     // Manipulation
70     void addLayerToState(unsigned layer);
71     void removeLayerFromState(unsigned layer);
72     void attachAppToArea(const std::string& app, const std::string& area);
73     std::string attachedApp(const std::string& area);
74     void update();
75     void undo();
76
77     // Event
78     void appTerminated(unsigned layer);
79
80     // Debug
81     void dump();
82
83   private:
84     LayerState tmp_state;
85     LayerState state;
86     unsigned wm_layer_id;
87     std::string name = ""; // Layer name
88     std::string role_list;
89     std::vector<std::string> area_list;
90     std::vector<unsigned>    id_list;
91     unsigned id_begin;
92     unsigned id_end;
93 };
94
95 } // namespace wm
96
97 #endif // WM_LAYER_HPP