2 * Copyright (c) 2011 - 2016 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 #include <app_internal.h>
22 #include <tizen_error.h>
25 #include "app_extension.h"
31 #define LOG_TAG "CAPI_APPFW_APPLICATION"
34 app_event_callback_s *callback;
38 static bool __on_create(void *data)
40 app_context_s *context = data;
42 if (context->callback->create)
43 return context->callback->create(context->data);
48 static void __on_terminate(void *data)
50 app_context_s *context = data;
52 if (context->callback->terminate)
53 context->callback->terminate(context->data);
57 static void __on_pause(void *data)
59 app_context_s *context = data;
61 if (context->callback->pause)
62 context->callback->pause(context->data);
67 static void __on_resume(void *data)
69 app_context_s *context = data;
71 if (context->callback->resume)
72 context->callback->resume(context->data);
77 static void __on_app_control(app_control_h app_control, void *data)
79 app_context_s *context = data;
81 if (context->callback->app_control)
82 context->callback->app_control(app_control, context->data);
85 static void __on_low_memory(app_event_info_h event_info, void *data)
87 app_context_s *context = data;
89 if (context->callback->low_memory)
90 context->callback->low_memory(context->data);
93 static void __on_low_battery(app_event_info_h event_info, void *data)
95 app_context_s *context = data;
97 if (context->callback->low_battery)
98 context->callback->low_battery(context->data);
101 /* LCOV_EXCL_START */
102 static void __on_rotation_event(app_event_info_h event_info, void *data)
104 app_context_s *context = data;
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);
115 static void __on_lang_changed(app_event_info_h event_info, void *data)
117 app_context_s *context = data;
119 if (context->callback->language_changed)
120 context->callback->language_changed(context->data);
123 static void __on_region_changed(app_event_info_h event_info, void *data)
125 app_context_s *context = data;
127 if (context->callback->region_format_changed)
128 context->callback->region_format_changed(context->data);
131 int app_main(int argc, char **argv, app_event_callback_s *callback, void *data)
133 ui_app_lifecycle_callback_s cb = {
134 .create = __on_create,
135 .terminate = __on_terminate,
137 .resume = __on_resume,
138 .app_control = __on_app_control
141 app_context_s app_context = {
142 .callback = callback,
146 app_event_handler_h handler;
149 return app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
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);
162 return ui_app_main(argc, argv, &cb, &app_context);
165 int app_efl_main(int *argc, char ***argv, app_event_callback_s *callback, void *user_data)
167 if (argc == NULL || argv == NULL)
168 return app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
170 return app_main(*argc, *argv, callback, user_data);
178 void app_efl_exit(void)