daf6a58e24ee58fce4e3b8410d1ddd69e1db9dd7
[platform/core/api/application.git] / src / app_main_legacy.c
1 /*
2  * Copyright (c) 2011 - 2016 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 <stdlib.h>
19 #include <dlog.h>
20
21 #include <app_internal.h>
22 #include <tizen_error.h>
23
24 #include <app.h>
25 #include "app_extension.h"
26
27 #ifdef LOG_TAG
28 #undef LOG_TAG
29 #endif
30
31 #define LOG_TAG "CAPI_APPFW_APPLICATION"
32
33 typedef struct {
34         app_event_callback_s *callback;
35         void *data;
36 } app_context_s;
37
38 static bool __on_create(void *data)
39 {
40         app_context_s *context = data;
41
42         if (context->callback->create)
43                 return context->callback->create(context->data);
44
45         return false;
46 }
47
48 static void __on_terminate(void *data)
49 {
50         app_context_s *context = data;
51
52         if (context->callback->terminate)
53                 context->callback->terminate(context->data);
54 }
55
56 /* LCOV_EXCL_START */
57 static void __on_pause(void *data)
58 {
59         app_context_s *context = data;
60
61         if (context->callback->pause)
62                 context->callback->pause(context->data);
63 }
64 /* LCOV_EXCL_STOP */
65
66 /* LCOV_EXCL_START */
67 static void __on_resume(void *data)
68 {
69         app_context_s *context = data;
70
71         if (context->callback->resume)
72                 context->callback->resume(context->data);
73
74 }
75 /* LCOV_EXCL_STOP */
76
77 static void __on_app_control(app_control_h app_control, void *data)
78 {
79         app_context_s *context = data;
80
81         if (context->callback->app_control)
82                 context->callback->app_control(app_control, context->data);
83 }
84
85 static void __on_low_memory(app_event_info_h event_info, void *data)
86 {
87         app_context_s *context = data;
88
89         if (context->callback->low_memory)
90                 context->callback->low_memory(context->data);
91 }
92
93 static void __on_low_battery(app_event_info_h event_info, void *data)
94 {
95         app_context_s *context = data;
96
97         if (context->callback->low_battery)
98                 context->callback->low_battery(context->data);
99 }
100
101 /* LCOV_EXCL_START */
102 static void __on_rotation_event(app_event_info_h event_info, void *data)
103 {
104         app_context_s *context = data;
105
106         if (context->callback->device_orientation) {
107                 app_device_orientation_e ori;
108                 app_event_get_device_orientation(event_info, &ori);
109                 context->callback->device_orientation(ori, context->data);
110         }
111
112 }
113 /* LCOV_EXCL_STOP */
114
115 static void __on_lang_changed(app_event_info_h event_info, void *data)
116 {
117         app_context_s *context = data;
118
119         if (context->callback->language_changed)
120                 context->callback->language_changed(context->data);
121 }
122
123 static void __on_region_changed(app_event_info_h event_info, void *data)
124 {
125         app_context_s *context = data;
126
127         if (context->callback->region_format_changed)
128                 context->callback->region_format_changed(context->data);
129 }
130
131 int app_main(int argc, char **argv, app_event_callback_s *callback, void *data)
132 {
133         ui_app_lifecycle_callback_s cb = {
134                 .create = __on_create,
135                 .terminate = __on_terminate,
136                 .pause = __on_pause,
137                 .resume = __on_resume,
138                 .app_control = __on_app_control
139         };
140
141         app_context_s app_context = {
142                 .callback = callback,
143                 .data = data
144         };
145
146         app_event_handler_h handler;
147
148         if (!callback)
149                 return app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
150
151         if (callback->low_memory)
152                 ui_app_add_event_handler(&handler, APP_EVENT_LOW_MEMORY, __on_low_memory, &app_context);
153         if (callback->low_battery)
154                 ui_app_add_event_handler(&handler, APP_EVENT_LOW_BATTERY, __on_low_battery, &app_context);
155         if (callback->language_changed)
156                 ui_app_add_event_handler(&handler, APP_EVENT_LANGUAGE_CHANGED, __on_lang_changed, &app_context);
157         if (callback->device_orientation)
158                 ui_app_add_event_handler(&handler, APP_EVENT_DEVICE_ORIENTATION_CHANGED, __on_rotation_event, &app_context);
159         if (callback->region_format_changed)
160                 ui_app_add_event_handler(&handler, APP_EVENT_REGION_FORMAT_CHANGED, __on_region_changed, &app_context);
161
162         return ui_app_main(argc, argv, &cb, &app_context);
163 }
164
165 int app_efl_main(int *argc, char ***argv, app_event_callback_s *callback, void *user_data)
166 {
167         return app_main(*argc, *argv, callback, user_data);
168 }
169
170 void app_exit(void)
171 {
172         ui_app_exit();
173 }
174
175 void app_efl_exit(void)
176 {
177         ui_app_exit();
178 }
179
180
181