2 Simple DirectMedia Layer
3 Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
4 Copyright 2015 Samsung Electronics co., Ltd. All Rights Reserved.
6 This software is provided 'as-is', without any express or implied
7 warranty. In no event will the authors be held liable for any damages
8 arising from the use of this software.
10 Permission is granted to anyone to use this software for any purpose,
11 including commercial applications, and to alter it and redistribute it
12 freely, subject to the following restrictions:
14 1. The origin of this software must not be misrepresented; you must not
15 claim that you wrote the original software. If you use this software
16 in a product, an acknowledgment in the product documentation would be
17 appreciated but is not required.
18 2. Altered source versions must be plainly marked as such, and must not be
19 misrepresented as being the original software.
20 3. This notice may not be removed or altered from any source distribution.
23 #include "../../SDL_internal.h"
26 #include <app_internal.h>
27 #include <app_extension.h>
28 #include <system_settings.h>
32 #include "SDL_events.h"
33 #include "../../events/SDL_events_c.h"
35 #include "SDL_tizen.h"
37 static int tizen_appcore_initialized = 0;
38 static appcore_context_h appcore_handle = NULL;
39 static ui_app_lifecycle_callback_s event_callback = {0,};
40 static app_event_handler_h handlers[5] = {NULL, };
42 int _tizen_terminate_event_filter(void *userdata, SDL_Event * event);
43 int _tizen_aul_status_changed_cb(int status, void *data);
46 * Impplementation of serveral app core callback function for SDL Application and App Core
50 _tizen_sdl_create(void *data)
52 SDL_Log("App Create");
57 _tizen_sdl_pause (void *data)
60 SDL_SendAppEvent(SDL_APP_WILLENTERBACKGROUND);
61 SDL_SendAppEvent(SDL_APP_DIDENTERBACKGROUND);
66 _tizen_sdl_resume(void *data)
68 SDL_Log("App Resume");
69 SDL_SendAppEvent(SDL_APP_WILLENTERFOREGROUND);
70 SDL_SendAppEvent(SDL_APP_DIDENTERFOREGROUND);
75 _tizen_sdl_control(app_control_h app_control, void *data)
77 SDL_Log("App Control");
80 SDL_memset(&event, 0, sizeof(event));
81 event.type = SDL_APP_CONTROL;
83 event.user.data1 = (void*)app_control;
84 event.user.data2 = (void*)data;
86 SDL_PushEvent(&event);
91 _tizen_app_lang_changed(app_event_info_h event_info, void *user_data)
93 /*APP_EVENT_LANGUAGE_CHANGED*/
94 SDL_Log("Language changed");
97 SDL_memset(&event, 0, sizeof(event));
98 event.type = SDL_APP_LANGUAGE_CHANGED;
100 event.user.data1 = (void*)event_info;
101 event.user.data2 = (void*)user_data;
103 SDL_PushEvent(&event);
108 _tizen_app_orient_changed(app_event_info_h event_info, void *user_data)
110 /*APP_EVENT_DEVICE_ORIENTATION_CHANGED*/
111 app_device_orientation_e orientation;
112 app_event_get_device_orientation(event_info, &orientation);
113 SDL_Log("Orientation Changed, Rotation Degree : %d", orientation);
115 SDL_memset(&event, 0, sizeof(event));
116 event.type = SDL_ROTATEEVENT;
118 event.user.data1 = (void*)orientation;
119 event.user.data2 = (void*)-1;
121 SDL_PushEvent(&event);
126 _tizen_app_region_changed(app_event_info_h event_info, void *user_data)
128 /*APP_EVENT_REGION_FORMAT_CHANGED*/
129 SDL_Log("region changed");
132 SDL_memset(&event, 0, sizeof(event));
133 event.type = SDL_APP_RIGION_CHANGED;
135 event.user.data1 = (void*)event_info;
136 event.user.data2 = (void*)user_data;
138 SDL_PushEvent(&event);
142 _tizen_app_low_battery(app_event_info_h event_info, void *user_data)
144 /*APP_EVENT_LOW_BATTERY*/
145 SDL_Log("low battery");
148 SDL_memset(&event, 0, sizeof(event));
149 event.type = SDL_APP_LOWBATTERY;
151 event.user.data1 = (void*)event_info;
152 event.user.data2 = (void*)user_data;
154 SDL_PushEvent(&event);
159 _tizen_app_low_memory(app_event_info_h event_info, void *user_data)
161 /*APP_EVENT_LOW_MEMORY*/
162 SDL_Log("low memory");
163 SDL_SendAppEvent(SDL_APP_LOWMEMORY);
168 _tizen_aul_status_changed_cb(int status, void *data)
170 if (status == STATUS_DYING) {
171 SDL_Log(":: STATUS_DYING");
173 SDL_SendAppEvent(SDL_APP_TERMINATING);
175 SDL_DelEventWatch(_tizen_terminate_event_filter, NULL);
182 _tizen_terminate_event_filter(void *userdata, SDL_Event * event)
185 SDL_Log("Event is NULL");
189 switch(event->type) {
190 case SDL_APP_TERMINATING: {
191 aul_remove_status_local_cb(_tizen_aul_status_changed_cb, NULL);
192 SDL_tizen_app_exit();
203 SDL_tizen_app_init(int argc, char *argv[])
207 SDL_Log( "SDL Tizen App initialize");
209 if (tizen_appcore_initialized) {
210 SDL_LogError(SDL_LOG_CATEGORY_ASSERT,"Already initialized!");
213 tizen_appcore_initialized = 1;
214 if (argc < 1 || argv == NULL) {
215 SDL_LogError(SDL_LOG_CATEGORY_ASSERT,"APP_ERROR_INVALID_PARAMETER");
219 event_callback.create = _tizen_sdl_create;
220 event_callback.pause = _tizen_sdl_pause;
221 event_callback.resume = _tizen_sdl_resume;
222 event_callback.app_control = _tizen_sdl_control;
224 ui_app_add_event_handler(&handlers[APP_EVENT_LOW_BATTERY], APP_EVENT_LOW_BATTERY, _tizen_app_low_battery, NULL);
225 ui_app_add_event_handler(&handlers[APP_EVENT_LOW_MEMORY], APP_EVENT_LOW_MEMORY, _tizen_app_low_memory, NULL);
226 ui_app_add_event_handler(&handlers[APP_EVENT_DEVICE_ORIENTATION_CHANGED], APP_EVENT_DEVICE_ORIENTATION_CHANGED, _tizen_app_orient_changed, NULL);
227 ui_app_add_event_handler(&handlers[APP_EVENT_LANGUAGE_CHANGED], APP_EVENT_LANGUAGE_CHANGED, _tizen_app_lang_changed, NULL);
228 ui_app_add_event_handler(&handlers[APP_EVENT_REGION_FORMAT_CHANGED], APP_EVENT_REGION_FORMAT_CHANGED, _tizen_app_region_changed, NULL);
230 aul_ret = aul_add_status_local_cb(_tizen_aul_status_changed_cb, NULL);
231 if (aul_ret == AUL_R_ERROR) {
232 SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "AUL status changed callback setting is failed.");
236 /* add event watch for SDL_APP_TERMINATING */
237 SDL_AddEventWatch(_tizen_terminate_event_filter, NULL);
239 return ui_app_init(argc, argv, &event_callback, NULL, &appcore_handle);
243 SDL_tizen_app_exit(void)
245 SDL_Log("call ui_app_fini");
246 ui_app_fini(appcore_handle);