Remove elementary dependency from multiwindow base
[platform/core/appfw/app-core.git] / src / multiwindow_base / appcore_multiwindow_base.c
1 /*
2  * Copyright (c) 2017 Samsung Electronics Co., Ltd. All rights reserved.
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 <sys/types.h>
18 #include <stdio.h>
19 #include <stdarg.h>
20 #include <errno.h>
21 #include <string.h>
22 #include <stdlib.h>
23 #include <linux/limits.h>
24
25 #include <Ecore_Wayland.h>
26 #include <glib-object.h>
27 #include <malloc.h>
28 #include <glib.h>
29 #include <gio/gio.h>
30 #include <stdbool.h>
31 #include <aul.h>
32 #include <aul_svc.h>
33 #include <bundle_internal.h>
34
35 #include "appcore_base.h"
36 #include "appcore_multiwindow_base.h"
37 #include "appcore_multiwindow_base_private.h"
38
39 appcore_multiwindow_base_context _appcore_mw_context;
40
41 static Eina_Bool __stub_show_cb(void *data, int type, void *event)
42 {
43         if (_appcore_mw_context.ops.window.show)
44                 _appcore_mw_context.ops.window.show(type, event, _appcore_mw_context.data);
45
46         return ECORE_CALLBACK_RENEW;
47 }
48
49 static Eina_Bool __stub_hide_cb(void *data, int type, void *event)
50 {
51         if (_appcore_mw_context.ops.window.hide)
52                 _appcore_mw_context.ops.window.hide(type, event, _appcore_mw_context.data);
53
54         return ECORE_CALLBACK_RENEW;
55 }
56
57 static Eina_Bool __stub_visibility_cb(void *data, int type, void *event)
58 {
59         if (_appcore_mw_context.ops.window.visibility)
60                 _appcore_mw_context.ops.window.visibility(type, event, _appcore_mw_context.data);
61
62         return ECORE_CALLBACK_RENEW;
63 }
64
65 static Eina_Bool __stub_lower_cb(void *data, int type, void *event)
66 {
67         if (_appcore_mw_context.ops.window.lower)
68                 _appcore_mw_context.ops.window.lower(type, event, _appcore_mw_context.data);
69
70         return ECORE_CALLBACK_RENEW;
71 }
72
73 static Eina_Bool __stub_pre_visibility_cb(void *data, int type, void *event)
74 {
75         if (_appcore_mw_context.ops.window.pre_visibility)
76                 _appcore_mw_context.ops.window.pre_visibility(type, event, _appcore_mw_context.data);
77
78         return ECORE_CALLBACK_RENEW;
79 }
80
81 EXPORT_API int appcore_multiwindow_base_init(appcore_multiwindow_base_ops ops, int argc, char **argv, void *data)
82 {
83         _appcore_mw_context.ops = ops;
84         _appcore_mw_context.data = data;
85         _appcore_mw_context.argc = argc;
86         _appcore_mw_context.argv = argv;
87
88         return appcore_base_init(ops.base, argc, argv, data);
89 }
90
91 static void __destroy_iter(gpointer data, gpointer user_data)
92 {
93         appcore_multiwindow_base_instance *inst = data;
94
95         if (!inst)
96                 return;
97
98         appcore_multiwindow_base_instance_exit(inst);
99 }
100
101 static void __destroy_all(void)
102 {
103         g_list_foreach(_appcore_mw_context.instances, __destroy_iter, NULL);
104 }
105
106 static void __free_class(gpointer data)
107 {
108         appcore_multiwindow_base_class *cls = data;
109
110         free(cls->id);
111         free(cls);
112 }
113
114 EXPORT_API void appcore_multiwindow_base_fini(void)
115 {
116         __destroy_all();
117         g_list_free_full(_appcore_mw_context.classes, __free_class);
118         _appcore_mw_context.classes = NULL;
119
120         if (_appcore_mw_context.hshow) {
121                 ecore_event_handler_del(_appcore_mw_context.hshow);
122                 _appcore_mw_context.hshow = NULL;
123         }
124
125         if (_appcore_mw_context.hhide) {
126                 ecore_event_handler_del(_appcore_mw_context.hhide);
127                 _appcore_mw_context.hhide = NULL;
128         }
129
130         if (_appcore_mw_context.hvchange) {
131                 ecore_event_handler_del(_appcore_mw_context.hvchange);
132                 _appcore_mw_context.hvchange = NULL;
133         }
134
135         if (_appcore_mw_context.hlower) {
136                 ecore_event_handler_del(_appcore_mw_context.hlower);
137                 _appcore_mw_context.hlower = NULL;
138         }
139
140         if (_appcore_mw_context.hpvchange) {
141                 ecore_event_handler_del(_appcore_mw_context.hpvchange);
142                 _appcore_mw_context.hpvchange = NULL;
143         }
144
145         appcore_base_fini();
146 }
147
148 EXPORT_API void appcore_multiwindow_base_exit(void)
149 {
150         if (_appcore_mw_context.ops.base.exit)
151                 _appcore_mw_context.ops.base.exit(_appcore_mw_context.data);
152 }
153
154 static int __on_receive(aul_type type, bundle *b, void *data)
155 {
156         return appcore_multiwindow_base_on_receive(type, b);
157 }
158
159 static int __on_create(void *data)
160 {
161         return appcore_multiwindow_base_on_create();
162 }
163
164 static int __on_terminate(void *data)
165 {
166         return appcore_multiwindow_base_on_terminate();
167 }
168
169 static void __window_on_show(int type, void *event, void *data)
170 {
171         appcore_multiwindow_base_window_on_show(type, event);
172 }
173
174 static void __window_on_hide(int type, void *event, void *data)
175 {
176         appcore_multiwindow_base_window_on_hide(type, event);
177 }
178
179 static void __window_on_lower(int type, void *event, void *data)
180 {
181         appcore_multiwindow_base_window_on_lower(type, event);
182 }
183
184 static void __window_on_visibility(int type, void *event, void *data)
185 {
186         appcore_multiwindow_base_window_on_visibility(type, event);
187 }
188
189 static void __window_on_pre_visibility(int type, void *event, void *data)
190 {
191         appcore_multiwindow_base_window_on_pre_visibility(type, event);
192 }
193
194 EXPORT_API appcore_multiwindow_base_ops appcore_multiwindow_base_get_default_ops(void)
195 {
196         appcore_multiwindow_base_ops ops;
197
198         ops.base = appcore_base_get_default_ops();
199
200         /* override methods */
201         ops.base.create = __on_create;
202         ops.base.terminate = __on_terminate;
203         ops.base.receive = __on_receive;
204         ops.base.init = NULL;
205         ops.base.finish = NULL;
206         ops.base.run = NULL;
207         ops.base.exit = NULL;
208
209         ops.window.show = __window_on_show;
210         ops.window.hide = __window_on_hide;
211         ops.window.lower = __window_on_lower;
212         ops.window.visibility = __window_on_visibility;
213         ops.window.pre_visibility = __window_on_pre_visibility;
214
215         return ops;
216 }
217
218 EXPORT_API int appcore_multiwindow_base_on_receive(aul_type type, bundle *b)
219 {
220         appcore_base_on_receive(type, b);
221
222         return 0;
223 }
224
225 EXPORT_API int appcore_multiwindow_base_on_create(void)
226 {
227         appcore_base_on_create();
228
229         _appcore_mw_context.hshow = ecore_event_handler_add(ECORE_WL_EVENT_WINDOW_SHOW, __stub_show_cb, NULL);
230         _appcore_mw_context.hhide = ecore_event_handler_add(ECORE_WL_EVENT_WINDOW_HIDE, __stub_hide_cb, NULL);
231         _appcore_mw_context.hvchange = ecore_event_handler_add(ECORE_WL_EVENT_WINDOW_VISIBILITY_CHANGE,
232                         __stub_visibility_cb, NULL);
233         _appcore_mw_context.hlower = ecore_event_handler_add(ECORE_WL_EVENT_WINDOW_LOWER, __stub_lower_cb, NULL);
234         _appcore_mw_context.hpvchange = ecore_event_handler_add(ECORE_WL_EVENT_WINDOW_PRE_VISIBILITY_CHANGE,
235                         __stub_pre_visibility_cb, NULL);
236
237         return 0;
238 }
239
240 EXPORT_API int appcore_multiwindow_base_on_terminate(void)
241 {
242         appcore_base_on_terminate();
243
244         return 0;
245 }
246
247 EXPORT_API int appcore_multiwindow_base_on_control(bundle *b)
248 {
249         appcore_base_on_control(b);
250
251         return 0;
252 }
253