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