3046d9f09a2adf26bf8a0e100d58353a1641c1ef
[platform/core/appfw/app-core.git] / src / legacy / appcore-efl.c
1 /*
2  * Copyright (c) 2000 - 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 <stdio.h>
18 #include <string.h>
19 #include <stdlib.h>
20
21 #include <glib-object.h>
22 #include <malloc.h>
23 #include <glib.h>
24 #include <gio/gio.h>
25 #include <stdbool.h>
26 #include <Elementary.h>
27
28 #include "appcore-internal.h"
29 #include "appcore-efl.h"
30 #include "appcore_ui_base.h"
31 #include <system_info.h>
32
33 struct appcore_efl_context {
34         struct appcore_ops ops;
35 };
36
37 static struct appcore_efl_context __context;
38
39 static int __ui_app_create(void *data)
40 {
41         appcore_ui_base_on_create();
42
43         if (__context.ops.create) {
44                 if (__context.ops.create(__context.ops.data) < 0)
45                         return -1;
46         }
47
48         return 0;
49 }
50
51 static int __ui_app_terminate(void *data)
52 {
53         appcore_ui_base_on_terminate();
54
55         if (__context.ops.terminate)
56                 __context.ops.terminate(__context.ops.data);
57
58         return 0;
59 }
60
61 static int __ui_app_control(bundle *b, void *data)
62 {
63         appcore_ui_base_on_control(b);
64
65         if (__context.ops.reset)
66                 __context.ops.reset(b, __context.ops.data);
67
68         return 0;
69 }
70
71 static int __ui_app_pause(void *data)
72 {
73         appcore_ui_base_on_pause();
74
75         if (__context.ops.pause)
76                 __context.ops.pause(__context.ops.data);
77         return 0;
78 }
79
80 static int __ui_app_resume(void *data)
81 {
82         appcore_ui_base_on_resume();
83
84         if (__context.ops.resume)
85                 __context.ops.resume(__context.ops.data);
86         return 0;
87 }
88
89 EXPORT_API int appcore_efl_init(const char *name, int *argc, char ***argv,
90                      struct appcore_ops *ops)
91 {
92         int ret;
93         appcore_ui_base_ops ui_ops = appcore_ui_base_get_default_ops();
94
95         /* override methods */
96         ui_ops.base.create = __ui_app_create;
97         ui_ops.base.control = __ui_app_control;
98         ui_ops.base.terminate = __ui_app_terminate;
99         ui_ops.pause = __ui_app_pause;
100         ui_ops.resume = __ui_app_resume;
101         ui_ops.base.run = NULL;
102
103         __context.ops = *ops;
104
105         ret = appcore_ui_base_init(ui_ops, *argc, *argv, NULL,
106                         APPCORE_UI_BASE_HINT_WINDOW_GROUP_CONTROL |
107                         APPCORE_UI_BASE_HINT_WINDOW_STACK_CONTROL |
108                         APPCORE_UI_BASE_HINT_BG_LAUNCH_CONTROL |
109                         APPCORE_UI_BASE_HINT_HW_ACC_CONTROL);
110
111         return ret;
112 }
113
114 EXPORT_API void appcore_efl_fini(void)
115 {
116         appcore_ui_base_fini();
117 }
118
119 EXPORT_API int appcore_efl_main(const char *name, int *argc, char ***argv,
120                                 struct appcore_ops *ops)
121 {
122         int r;
123
124         r = appcore_efl_init(name, argc, argv, ops);
125
126         if (r >= 0)
127                 elm_run();
128
129         appcore_efl_fini();
130
131         return 0;
132 }
133
134 EXPORT_API void appcore_group_attach()
135 {
136         appcore_ui_base_group_add();
137 }
138
139 EXPORT_API void appcore_group_lower()
140 {
141         appcore_ui_base_group_remove();
142 }
143
144 EXPORT_API unsigned int appcore_get_main_window(void)
145 {
146         return appcore_ui_base_get_main_window();
147 }
148
149 EXPORT_API unsigned int appcore_get_main_surface(void)
150 {
151         return appcore_get_main_surface();
152 }
153
154 EXPORT_API int appcore_set_system_resource_reclaiming(bool enable)
155 {
156         return 0;
157 }
158
159