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"
34 #include "../../video/tizen/SDL_tizenwindow.h"
36 #include "SDL_tizen.h"
38 static int tizen_appcore_initialized = 0;
39 static appcore_context_h appcore_handle = NULL;
40 static ui_app_lifecycle_callback_s event_callback = {0,};
41 static app_event_handler_h handlers[5] = {NULL, };
43 int _tizen_terminate_event_filter(void *userdata, SDL_Event * event);
44 int _tizen_aul_status_changed_cb(int status, void *data);
47 * Impplementation of serveral app core callback function for SDL Application and App Core
51 _tizen_sdl_create(void *data)
53 SDL_Log("App Create");
58 _tizen_sdl_pause (void *data)
61 SDL_SendAppEvent(SDL_APP_WILLENTERBACKGROUND);
62 SDL_SendAppEvent(SDL_APP_DIDENTERBACKGROUND);
64 _tizen_ecore_ipc_client_send(OP_PAUSE, 0, 0, 0);
70 _tizen_sdl_resume(void *data)
72 SDL_Log("App Resume");
73 SDL_SendAppEvent(SDL_APP_WILLENTERFOREGROUND);
74 SDL_SendAppEvent(SDL_APP_DIDENTERFOREGROUND);
76 _tizen_ecore_ipc_client_send(OP_RESUME, 0, 0, 0);
82 _tizen_sdl_control(app_control_h app_control, void *data)
84 SDL_Log("App Control");
87 SDL_memset(&event, 0, sizeof(event));
88 event.type = SDL_APP_CONTROL;
90 event.user.data1 = (void*)app_control;
91 event.user.data2 = (void*)data;
93 SDL_PushEvent(&event);
98 _tizen_app_lang_changed(app_event_info_h event_info, void *user_data)
100 /*APP_EVENT_LANGUAGE_CHANGED*/
101 SDL_Log("Language changed");
104 SDL_memset(&event, 0, sizeof(event));
105 event.type = SDL_APP_LANGUAGE_CHANGED;
107 event.user.data1 = (void*)event_info;
108 event.user.data2 = (void*)user_data;
110 SDL_PushEvent(&event);
115 //APP_EVENT_DEVICE_ORIENTATION_CHANGED
117 _tizen_app_orient_changed(app_event_info_h event_info, void *user_data)
119 app_device_orientation_e orientation;
120 app_event_get_device_orientation(event_info, &orientation);
121 SDL_Log("Orientation Changed, Rotation Degree : %d", orientation);
123 SDL_memset(&event, 0, sizeof(event));
124 event.type = SDL_ROTATEEVENT;
126 event.user.data1 = (void*)orientation;
127 event.user.data2 = (void*)-1;
129 SDL_PushEvent(&event);
135 _tizen_app_region_changed(app_event_info_h event_info, void *user_data)
137 /*APP_EVENT_REGION_FORMAT_CHANGED*/
138 SDL_Log("region changed");
141 SDL_memset(&event, 0, sizeof(event));
142 event.type = SDL_APP_REGION_CHANGED;
144 event.user.data1 = (void*)event_info;
145 event.user.data2 = (void*)user_data;
147 SDL_PushEvent(&event);
151 _tizen_app_low_battery(app_event_info_h event_info, void *user_data)
153 /*APP_EVENT_LOW_BATTERY*/
154 SDL_Log("low battery");
157 SDL_memset(&event, 0, sizeof(event));
158 event.type = SDL_APP_LOWBATTERY;
160 event.user.data1 = (void*)event_info;
161 event.user.data2 = (void*)user_data;
163 SDL_PushEvent(&event);
168 _tizen_app_low_memory(app_event_info_h event_info, void *user_data)
170 /*APP_EVENT_LOW_MEMORY*/
171 SDL_Log("low memory");
172 SDL_SendAppEvent(SDL_APP_LOWMEMORY);
177 _tizen_aul_status_changed_cb(int status, void *data)
179 if (status == STATUS_DYING) {
180 SDL_Log(":: STATUS_DYING");
182 SDL_SendAppEvent(SDL_APP_TERMINATING);
184 SDL_DelEventWatch(_tizen_terminate_event_filter, NULL);
191 _tizen_terminate_event_filter(void *userdata, SDL_Event * event)
194 SDL_Log("Event is NULL");
198 switch(event->type) {
199 case SDL_APP_TERMINATING: {
200 aul_remove_status_local_cb(_tizen_aul_status_changed_cb, NULL);
201 SDL_tizen_app_exit();
212 SDL_tizen_app_init(int argc, char *argv[])
216 SDL_Log( "SDL Tizen App initialize");
218 if (tizen_appcore_initialized) {
219 SDL_LogError(SDL_LOG_CATEGORY_ASSERT,"Already initialized!");
222 tizen_appcore_initialized = 1;
223 if (argc < 1 || argv == NULL) {
224 SDL_LogError(SDL_LOG_CATEGORY_ASSERT,"APP_ERROR_INVALID_PARAMETER");
228 event_callback.create = _tizen_sdl_create;
229 event_callback.pause = _tizen_sdl_pause;
230 event_callback.resume = _tizen_sdl_resume;
231 event_callback.app_control = _tizen_sdl_control;
233 ui_app_add_event_handler(&handlers[APP_EVENT_LOW_BATTERY], APP_EVENT_LOW_BATTERY, _tizen_app_low_battery, NULL);
234 ui_app_add_event_handler(&handlers[APP_EVENT_LOW_MEMORY], APP_EVENT_LOW_MEMORY, _tizen_app_low_memory, NULL);
235 // ui_app_add_event_handler(&handlers[APP_EVENT_DEVICE_ORIENTATION_CHANGED], APP_EVENT_DEVICE_ORIENTATION_CHANGED, _tizen_app_orient_changed, NULL);
236 ui_app_add_event_handler(&handlers[APP_EVENT_LANGUAGE_CHANGED], APP_EVENT_LANGUAGE_CHANGED, _tizen_app_lang_changed, NULL);
237 ui_app_add_event_handler(&handlers[APP_EVENT_REGION_FORMAT_CHANGED], APP_EVENT_REGION_FORMAT_CHANGED, _tizen_app_region_changed, NULL);
239 aul_ret = aul_add_status_local_cb(_tizen_aul_status_changed_cb, NULL);
240 if (aul_ret == AUL_R_ERROR) {
241 SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "AUL status changed callback setting is failed.");
245 /* add event watch for SDL_APP_TERMINATING */
246 SDL_AddEventWatch(_tizen_terminate_event_filter, NULL);
248 return ui_app_init(argc, argv, &event_callback, NULL, &appcore_handle);
252 SDL_tizen_app_exit(void)
254 SDL_Log("call ui_app_fini");
255 ui_app_fini(appcore_handle);
256 appcore_handle = NULL;