5f23af16128b23da61eadf152f32339a3e2d953e
[apps/agl-service-windowmanager.git] / src / wm_layer_control.cpp
1 /*\r
2  * Copyright (c) 2017 TOYOTA MOTOR CORPORATION\r
3  *\r
4  * Licensed under the Apache License, Version 2.0 (the "License");\r
5  * you may not use this file except in compliance with the License.\r
6  * You may obtain a copy of the License at\r
7  *\r
8  *      http://www.apache.org/licenses/LICENSE-2.0\r
9  *\r
10  * Unless required by applicable law or agreed to in writing, software\r
11  * distributed under the License is distributed on an "AS IS" BASIS,\r
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
13  * See the License for the specific language governing permissions and\r
14  * limitations under the License.\r
15  */\r
16 #include <assert.h>\r
17 #include <unistd.h>\r
18 #include "wm_layer_control.hpp"\r
19 #include "wm_layer.hpp"\r
20 \r
21 #define LC_AREA_PATH "/etc/area.db"\r
22 #define LC_LAYER_SETTING_PATH "/etc/layer_setting.json"\r
23 \r
24 using std::string;\r
25 \r
26 namespace wm {\r
27 \r
28 static void notification_static(ilmObjectType object,\r
29                             t_ilm_uint id,\r
30                             t_ilm_bool created,\r
31                             void* data)\r
32 {\r
33     static_cast<LayerControl*>(data)->dispatchILMEvent(object, id, created);\r
34 }\r
35 \r
36 LayerControl::LayerControl(const std::string& root)\r
37 {\r
38     string area_path = root + LC_AREA_PATH;\r
39     string layer_path= root + LC_LAYER_SETTING_PATH;\r
40     // load layers.setting.json\r
41     // load area.db\r
42 }\r
43 \r
44 WMError LayerControl::init()\r
45 {\r
46     ilmErrorTypes rc = ilm_init();\r
47     t_ilm_uint num = 0;\r
48     t_ilm_uint *ids;\r
49     int cnt = 0;\r
50 \r
51     while (rc != ILM_SUCCESS)\r
52     {\r
53         cnt++;\r
54         if (20 <= cnt)\r
55         {\r
56             HMI_ERROR("Could not connect to compositor");\r
57             goto lc_init_error;\r
58         }\r
59         HMI_ERROR("Wait to start weston ...");\r
60         sleep(1);\r
61         ilm_init();\r
62     }\r
63     if(rc != ILM_SUCCESS) goto lc_init_error;\r
64 \r
65     rc = ilm_getScreenIDs(&num, &ids);\r
66 \r
67     if(rc != ILM_SUCCESS) goto lc_init_error;\r
68 \r
69     for(unsigned i = 0; i < num; i++)\r
70     {\r
71         HMI_INFO("get screen: %d", ids[i]);\r
72     }\r
73     // Currently, 0 is only available\r
74     this->screenID = ids[0];\r
75 \r
76     rc = ilm_getPropertiesOfScreen(this->screenID, &this->screen_prop);\r
77 \r
78     if(rc != ILM_SUCCESS) goto lc_init_error;\r
79 \r
80     // Register Callback from ILM\r
81     ilm_registerNotification(notification_static, this);\r
82 \r
83     return WMError::SUCCESS;\r
84 \r
85 lc_init_error:\r
86     HMI_ERROR("Failed to initialize. Terminate WM");\r
87 \r
88     return WMError::FAIL;\r
89 }\r
90 \r
91 unsigned LayerControl::getNewLayerID(const string& role)\r
92 {\r
93     unsigned ret = 0;\r
94     for(const auto& l: this->wm_layers)\r
95     {\r
96         ret = l->getNewLayerID(role);\r
97         if(ret != 0)\r
98         {\r
99             break;\r
100         }\r
101     }\r
102     return ret;\r
103 }\r
104 \r
105 WMError LayerControl::updateLayer(WMLayer& wm_layer)\r
106 {\r
107     return WMError::SUCCESS;\r
108 }\r
109 \r
110 void LayerControl::commitChange() {}\r
111 \r
112 void LayerControl::undoUpdate() {}\r
113 \r
114 WMError LayerControl::load(const string &path)\r
115 {\r
116     return WMError::SUCCESS;\r
117 }\r
118 \r
119 void LayerControl::dispatchILMEvent(ilmObjectType object, t_ilm_uint id, t_ilm_bool created)\r
120 {\r
121     ;\r
122 }\r
123 \r
124 } // namespace wm