b171a27e610fd0ffcdd84a7793cc879031a1ce3a
[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 #include <stdbool.h>
21
22 #include "appcore-internal.h"
23 #include "appcore-efl.h"
24 #include "appcore_efl_base.h"
25
26 struct appcore_efl_context {
27         struct appcore_ops ops;
28 };
29
30 static struct appcore_efl_context __context;
31
32 static int __ui_app_create(void *data)
33 {
34         appcore_efl_base_on_create();
35
36         if (__context.ops.create) {
37                 if (__context.ops.create(__context.ops.data) < 0)
38                         return -1;
39         }
40
41         return 0;
42 }
43
44 static int __ui_app_terminate(void *data)
45 {
46         appcore_efl_base_on_terminate();
47
48         if (__context.ops.terminate)
49                 __context.ops.terminate(__context.ops.data);
50
51         return 0;
52 }
53
54 static int __ui_app_control(bundle *b, void *data)
55 {
56         appcore_efl_base_on_control(b);
57
58         if (__context.ops.reset)
59                 __context.ops.reset(b, __context.ops.data);
60
61         return 0;
62 }
63
64 static int __ui_app_pause(void *data)
65 {
66         appcore_efl_base_on_pause();
67
68         if (__context.ops.pause)
69                 __context.ops.pause(__context.ops.data);
70         return 0;
71 }
72
73 static int __ui_app_resume(void *data)
74 {
75         appcore_efl_base_on_resume();
76
77         if (__context.ops.resume)
78                 __context.ops.resume(__context.ops.data);
79         return 0;
80 }
81
82 EXPORT_API int appcore_efl_init(const char *name, int *argc, char ***argv,
83                      struct appcore_ops *ops)
84 {
85         int ret;
86         appcore_efl_base_ops efl_ops = appcore_efl_base_get_default_ops();
87
88         /* override methods */
89         efl_ops.ui_base.base.create = __ui_app_create;
90         efl_ops.ui_base.base.control = __ui_app_control;
91         efl_ops.ui_base.base.terminate = __ui_app_terminate;
92         efl_ops.ui_base.pause = __ui_app_pause;
93         efl_ops.ui_base.resume = __ui_app_resume;
94
95         __context.ops = *ops;
96
97         ret = appcore_efl_base_init(efl_ops, *argc, *argv, NULL,
98                         APPCORE_EFL_BASE_HINT_WINDOW_GROUP_CONTROL |
99                         APPCORE_EFL_BASE_HINT_WINDOW_STACK_CONTROL |
100                         APPCORE_EFL_BASE_HINT_BG_LAUNCH_CONTROL |
101                         APPCORE_EFL_BASE_HINT_HW_ACC_CONTROL |
102                         APPCORE_EFL_BASE_HINT_WINDOW_AUTO_CONTROL |
103                         APPCORE_EFL_BASE_HINT_LEGACY_CONTROL);
104
105         return ret;
106 }
107
108 EXPORT_API void appcore_efl_fini(void)
109 {
110         appcore_efl_base_fini();
111 }
112
113 EXPORT_API int appcore_efl_main(const char *name, int *argc, char ***argv,
114                                 struct appcore_ops *ops)
115 {
116         int r;
117
118         r = appcore_efl_init(name, argc, argv, ops);
119         if (r < 0)
120                 return r;
121
122         appcore_efl_fini();
123
124         return 0;
125 }
126
127 EXPORT_API void appcore_group_attach()
128 {
129         appcore_efl_base_group_add();
130 }
131
132 EXPORT_API void appcore_group_lower()
133 {
134         appcore_efl_base_group_remove();
135 }
136
137 EXPORT_API unsigned int appcore_get_main_window(void)
138 {
139         return appcore_efl_base_get_main_window();
140 }
141
142 EXPORT_API unsigned int appcore_get_main_surface(void)
143 {
144         return appcore_get_main_surface();
145 }
146
147 EXPORT_API int appcore_set_system_resource_reclaiming(bool enable)
148 {
149         return 0;
150 }