Add boot sequence and multi ecu transfer
[apps/agl-service-windowmanager.git] / src / wm_layer_control.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 #include <string>
18 #include <memory>
19 #include <vector>
20 #include <unordered_map>
21 #include <functional>
22 #include <ilm/ilm_control.h>
23 #include "wm_error.hpp"
24 #include "util.hpp"
25
26 namespace wm {
27
28 class Screen {
29   public:
30     Screen(unsigned id, unsigned w, unsigned h) : _screen_id(id), _width(w), _height(h){}
31     unsigned width() const { return _width; }
32     unsigned height() const { return _height; }
33     unsigned id() const { return _screen_id; }
34     unsigned scale() const { return _scale; }
35     int offsetX() const { return _offset_x; }
36     int offsetY() const { return _offset_y; }
37     void setScale(double scl) { this->_scale = scl; }
38     void setOffset(int x, int y) { this->_offset_x = x; this->_offset_y = y; }
39   private:
40     unsigned _screen_id;
41     unsigned _width;
42     unsigned _height;
43     unsigned _pysical_width = 0;
44     unsigned _pysical_height = 0;
45     int _offset_x = 0;
46     int _offset_y = 0;
47     double _scale = 1.0;
48 };
49
50 class LayerControlCallbacks {
51   public:
52     LayerControlCallbacks() {};
53     ~LayerControlCallbacks() = default;
54     LayerControlCallbacks(const LayerControlCallbacks &obj) = default;
55
56     // callback functions
57     std::function<void(unsigned, unsigned)> surfaceCreated;
58     std::function<void(unsigned)> surfaceDestroyed;
59     /*
60     std::function<void(unsigned)> layerCreated;
61     std::function<void(unsigned)> layerDestroyed;
62     */
63 };
64
65 class WMLayer;
66 class LayerState;
67 class WMAction;
68 class WMClient;
69
70 class LayerControl
71 {
72   public:
73     explicit LayerControl(const std::string& root, const std::string& ecu_name);
74     ~LayerControl() = default;
75     WMError init(const LayerControlCallbacks& cb);
76     void createNewLayer(unsigned id);
77     void createNewRemoteLayer(unsigned id);
78     unsigned getNewLayerID(const std::string& role, std::string* layer_name);
79     std::shared_ptr<WMLayer> getWMLayer(unsigned layer);
80     std::shared_ptr<WMLayer> getWMLayer(std::string layer_name);
81     struct rect getAreaSize(const std::string& area);
82     void setupArea(const rectangle& base_rct, double scaling);
83     Screen getScreenInfo();
84     double scale();
85     WMError updateLayer(LayerState& layer_state);
86     WMError renderLayers();
87     // WMError renderLayersRemote();
88     WMError setXDGSurfaceOriginSize(unsigned surface);
89     void undoUpdate();
90     WMError layoutChange(const WMAction& action);
91     WMError visibilityChange(const WMAction &action);
92     const std::unordered_map<std::string, struct rect>& getAreaList() {return this->area2size;}
93     WMError updateAreaList(const ChangeAreaReq& req);
94     WMError getUpdateAreaList(ChangeAreaReq* req);
95     WMError changeAreaSize(std::shared_ptr<WMClient> client, const std::string& area);
96     void appTerminated(const std::shared_ptr<WMClient> client);
97
98     // Don't use this function.
99     void dispatchCreateEvent(ilmObjectType object, unsigned id, bool created);
100     void dispatchSurfacePropChangeEvent(unsigned id, struct ilmSurfaceProperties*, t_ilm_notification_mask);
101     void dispatchLayerPropChangeEvent(unsigned id, struct ilmLayerProperties*, t_ilm_notification_mask);
102
103     bool hasRemoteLayer(unsigned layer);
104
105   private:
106     WMError makeVisible(const std::shared_ptr<WMClient> client);
107     WMError makeInvisible(const std::shared_ptr<WMClient> client);
108     bool moveForeGround(const std::shared_ptr<WMClient> client);
109     bool moveBackGround(const std::shared_ptr<WMClient> client);
110     bool moveRemote(unsigned layer, const std::string& area);
111     bool moveLocal(unsigned layer);
112     int loadWestonSetting(const std::string &path);
113     WMError loadLayerSetting(const std::string& path);
114     WMError loadAreasConfigFile(const std::string& path, const std::string& ecu_name);
115
116     std::vector<std::shared_ptr<WMLayer>> wm_layers;
117     std::vector<Screen> wm_screens;
118     std::unordered_map<unsigned, unsigned> lid2wmlid;
119     std::unordered_map<std::string, struct rect> area2size;
120     unsigned screenID;
121
122     double scaling;
123     int offset_x;
124     int offset_y;
125     LayerControlCallbacks cb;
126
127     long times;
128     long sleep;
129 };
130
131 } // namespace wm