changed rotation code
[platform/core/appfw/app-core.git] / src / appcore-efl.c
1 /*
2  *  app-core
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>, Jaeho Lee <jaeho81.lee@samsung.com>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  */
21
22
23 #include <errno.h>
24 #include <string.h>
25 #include <stdlib.h>
26 #include <X11/Xatom.h>
27 #include <X11/Xlib.h>
28 #include <Ecore_X.h>
29 #include <Ecore.h>
30 #include <Ecore_Evas.h>
31 #include <Ecore_Input_Evas.h>
32 #include <Elementary.h>
33 #include <glib-object.h>
34 #include <malloc.h>
35 #include <sysman.h>
36 #include <glib.h>
37 #include <stdbool.h>
38 #include "appcore-internal.h"
39 #include "appcore-efl.h"
40
41 static pid_t _pid;
42
43 static bool resource_reclaiming = TRUE;
44
45 struct ui_priv {
46         const char *name;
47         enum app_state state;
48
49         Ecore_Event_Handler *hshow;
50         Ecore_Event_Handler *hhide;
51         Ecore_Event_Handler *hvchange;
52         Ecore_Event_Handler *hcmsg; /* WM_ROTATE */
53
54         Ecore_Timer *mftimer;   /* Ecore Timer for memory flushing */
55
56         struct appcore_ops *ops;
57         void (*mfcb) (void);    /* Memory Flushing Callback */
58
59         /* WM_ROTATE */
60         int wm_rot_supported;
61         int rot_started;
62         int (*rot_cb) (enum appcore_rm, void *);
63         void *rot_cb_data;
64         enum appcore_rm rot_mode;
65 };
66
67 static struct ui_priv priv;
68
69 static const char *_ae_name[AE_MAX] = {
70         [AE_UNKNOWN] = "UNKNOWN",
71         [AE_CREATE] = "CREATE",
72         [AE_TERMINATE] = "TERMINATE",
73         [AE_PAUSE] = "PAUSE",
74         [AE_RESUME] = "RESUME",
75         [AE_RESET] = "RESET",
76         [AE_LOWMEM_POST] = "LOWMEM_POST",
77         [AE_MEM_FLUSH] = "MEM_FLUSH",
78 };
79
80 static const char *_as_name[] = {
81         [AS_NONE] = "NONE",
82         [AS_CREATED] = "CREATED",
83         [AS_RUNNING] = "RUNNING",
84         [AS_PAUSED] = "PAUSED",
85         [AS_DYING] = "DYING",
86 };
87
88 static bool b_active = 0;
89 struct win_node {
90         unsigned int win;
91         bool bfobscured;
92 };
93
94 static struct ui_wm_rotate wm_rotate;
95
96 static int WIN_COMP(gconstpointer data1, gconstpointer data2)
97 {
98         struct win_node *a = (struct win_node *)data1;
99         struct win_node *b = (struct win_node *)data2;
100         return (int)((a->win)-(b->win));
101 }
102
103 GSList *g_winnode_list = NULL;
104
105 #if defined(MEMORY_FLUSH_ACTIVATE)
106 static Eina_Bool __appcore_memory_flush_cb(void *data)
107 {
108         struct ui_priv *ui = (struct ui_priv *)data;
109
110         appcore_flush_memory();
111         ui->mftimer = NULL;
112
113         return ECORE_CALLBACK_CANCEL;
114 }
115
116 static int __appcore_low_memory_post_cb(struct ui_priv *ui)
117 {
118         if (ui->state == AS_PAUSED) {
119                 appcore_flush_memory();
120         } else {
121                 malloc_trim(0);
122         }
123
124         return 0;
125 }
126
127 static void __appcore_timer_add(struct ui_priv *ui)
128 {
129         ui->mftimer = ecore_timer_add(5, __appcore_memory_flush_cb, ui);
130 }
131
132 static void __appcore_timer_del(struct ui_priv *ui)
133 {
134         if (ui->mftimer) {
135                 ecore_timer_del(ui->mftimer);
136                 ui->mftimer = NULL;
137         }
138 }
139
140 #else
141
142 static int __appcore_low_memory_post_cb(ui_priv *ui)
143 {
144         return -1;
145 }
146
147 #define __appcore_timer_add(ui) 0
148 #define __appcore_timer_del(ui) 0
149
150 #endif
151
152 static void __appcore_efl_memory_flush_cb(void)
153 {
154         _DBG("[APP %d]   __appcore_efl_memory_flush_cb()", _pid);
155         elm_cache_all_flush();
156 }
157
158 static void __do_app(enum app_event event, void *data, bundle * b)
159 {
160         int r = -1;
161         struct ui_priv *ui = data;
162
163         _DBG("[APP %d] Event: %d", _pid, event);
164         _ret_if(ui == NULL || event >= AE_MAX);
165         _DBG("[APP %d] Event: %s State: %s", _pid, _ae_name[event],
166              _as_name[ui->state]);
167
168         if (event == AE_MEM_FLUSH) {
169                 ui->mfcb();
170                 return;
171         }
172
173         if (event == AE_LOWMEM_POST) {
174                 if (__appcore_low_memory_post_cb(ui) == 0)
175                         return;
176         }
177
178         if (!(ui->state == AS_PAUSED && event == AE_PAUSE))
179                 __appcore_timer_del(ui);
180
181         if (event == AE_TERMINATE) {
182                 _DBG("[APP %d] TERMINATE", _pid);
183                 ui->state = AS_DYING;
184                 elm_exit();
185                 return;
186         }
187
188         _ret_if(ui->ops == NULL);
189
190         switch (event) {
191         case AE_RESET:
192                 _DBG("[APP %d] RESET", _pid);
193                 LOG(LOG_DEBUG, "LAUNCH", "[%s:Application:reset:start]",
194                     ui->name);
195                 if (ui->ops->reset)
196                         r = ui->ops->reset(b, ui->ops->data);
197                 ui->state = AS_RUNNING;
198                 LOG(LOG_DEBUG, "LAUNCH", "[%s:Application:reset:done]",
199                     ui->name);
200                 break;
201         case AE_PAUSE:
202                 if (ui->state == AS_RUNNING) {
203                         _DBG("[APP %d] PAUSE", _pid);
204                         if (ui->ops->pause)
205                                 r = ui->ops->pause(ui->ops->data);
206                         ui->state = AS_PAUSED;
207                         if(r >= 0 && resource_reclaiming == TRUE)
208                                 __appcore_timer_add(ui);
209                 }
210                 /* TODO : rotation stop */
211                 //r = appcore_pause_rotation_cb();
212
213                 sysman_inform_backgrd();
214                 break;
215         case AE_RESUME:
216                 LOG(LOG_DEBUG, "LAUNCH", "[%s:Application:resume:start]",
217                     ui->name);
218                 if (ui->state == AS_PAUSED) {
219                         _DBG("[APP %d] RESUME", _pid);
220                         if (ui->ops->resume)
221                                 r = ui->ops->resume(ui->ops->data);
222                         ui->state = AS_RUNNING;
223                 }
224                 /*TODO : rotation start*/
225                 //r = appcore_resume_rotation_cb();
226                 LOG(LOG_DEBUG, "LAUNCH", "[%s:Application:resume:done]",
227                     ui->name);
228                 LOG(LOG_DEBUG, "LAUNCH", "[%s:Application:Launching:done]",
229                     ui->name);
230                 sysman_inform_foregrd();
231
232                 break;
233         default:
234                 /* do nothing */
235                 break;
236         }
237 }
238
239 static struct ui_ops efl_ops = {
240         .data = &priv,
241         .cb_app = __do_app,
242 };
243
244
245 static bool __check_visible(void)
246 {
247         GSList *iter = NULL;
248         struct win_node *entry = NULL;
249
250         _DBG("[EVENT_TEST][EVENT] __check_visible\n");
251         
252         for (iter = g_winnode_list; iter != NULL; iter = g_slist_next(iter)) {
253                 entry = iter->data;     
254                 _DBG("win : %x obscured : %d\n", entry->win, entry->bfobscured);
255                 if(entry->bfobscured == FALSE)
256                         return TRUE;            
257         }
258         return FALSE;
259 }
260
261 static bool __exist_win(unsigned int win)
262 {
263         struct win_node temp;
264         GSList *f;
265
266         temp.win = win;
267
268         f = g_slist_find_custom(g_winnode_list, &temp, WIN_COMP);
269         if (f == NULL) {
270                 return FALSE;
271         } else {
272                 return TRUE;
273         }
274
275 }
276
277 static bool __add_win(unsigned int win)
278 {
279         struct win_node *t;
280         GSList *f;
281
282         t = calloc(1, sizeof(struct win_node));
283         if (t == NULL)
284                 return FALSE;
285
286         t->win = win;
287         t->bfobscured = FALSE;
288
289         _DBG("[EVENT_TEST][EVENT] __add_win WIN:%x\n", win);
290
291         f = g_slist_find_custom(g_winnode_list, t, WIN_COMP);
292
293         if (f) {
294                 errno = ENOENT;
295                 _DBG("[EVENT_TEST][EVENT] ERROR There is already window : %x \n", win);
296                 free(t);
297                 return 0;
298         }
299
300         g_winnode_list = g_slist_append(g_winnode_list, t);
301
302         return TRUE;
303
304 }
305
306 static bool __delete_win(unsigned int win)
307 {
308         struct win_node temp;
309         GSList *f;
310
311         temp.win = win;
312
313         f = g_slist_find_custom(g_winnode_list, &temp, WIN_COMP);
314         if (f == NULL) {
315                 errno = ENOENT;
316                 _DBG("[EVENT_TEST][EVENT] ERROR There is no window : %x \n",
317                      win);
318                 return 0;
319         }
320
321         g_winnode_list = g_slist_remove_link(g_winnode_list, f);
322
323         free(f->data);
324
325         return TRUE;
326 }
327
328 static bool __update_win(unsigned int win, bool bfobscured)
329 {
330         struct win_node temp;
331         GSList *f;
332
333         struct win_node *t;
334
335         _DBG("[EVENT_TEST][EVENT] __update_win WIN:%x fully_obscured %d\n", win,
336              bfobscured);
337
338         temp.win = win;
339
340         f = g_slist_find_custom(g_winnode_list, &temp, WIN_COMP);
341
342         if (f == NULL) {
343                 errno = ENOENT;
344                 _DBG("[EVENT_TEST][EVENT] ERROR There is no window : %x \n", win);
345                 return FALSE;
346         }
347
348         g_winnode_list = g_slist_remove_link(g_winnode_list, f);
349
350         free(f->data);
351
352         t = calloc(1, sizeof(struct win_node));
353         if (t == NULL)
354                 return FALSE;
355
356         t->win = win;
357         t->bfobscured = bfobscured;
358
359         g_winnode_list = g_slist_append(g_winnode_list, t);
360         
361         return TRUE;
362
363 }
364
365 /* WM_ROTATE */
366 static Ecore_X_Atom _WM_WINDOW_ROTATION_SUPPORTED = 0;
367 static Ecore_X_Atom _WM_WINDOW_ROTATION_CHANGE_REQUEST = 0;
368
369 static int __check_wm_rotation_support(void)
370 {
371         Ecore_X_Window root, win, win2;
372         int ret;
373
374         if (!_WM_WINDOW_ROTATION_SUPPORTED) {
375                 _WM_WINDOW_ROTATION_SUPPORTED =
376                                         ecore_x_atom_get("_E_WINDOW_ROTATION_SUPPORTED");
377         }
378
379         if (!_WM_WINDOW_ROTATION_CHANGE_REQUEST) {
380                 _WM_WINDOW_ROTATION_CHANGE_REQUEST =
381                                         ecore_x_atom_get("_E_WINDOW_ROTATION_CHANGE_REQUEST");
382         }
383
384         root = ecore_x_window_root_first_get();
385         ret = ecore_x_window_prop_xid_get(root,
386                         _WM_WINDOW_ROTATION_SUPPORTED,
387                         ECORE_X_ATOM_WINDOW,
388                         &win, 1);
389         if ((ret == 1) && (win))
390         {
391                 ret = ecore_x_window_prop_xid_get(win,
392                                 _WM_WINDOW_ROTATION_SUPPORTED,
393                                 ECORE_X_ATOM_WINDOW,
394                                 &win2, 1);
395                 if ((ret == 1) && (win2 == win))
396                         return 0;
397         }
398
399         return -1;
400 }
401
402 static void __set_wm_rotation_support(unsigned int win, unsigned int set)
403 {
404         GSList *iter = NULL;
405         struct win_node *entry = NULL;
406
407         if (0 == win) {
408                 for (iter = g_winnode_list; iter != NULL; iter = g_slist_next(iter)) {
409                         entry = iter->data;
410                         if (entry->win) {
411                                 ecore_x_window_prop_card32_set(entry->win,
412                                                 _WM_WINDOW_ROTATION_SUPPORTED,
413                                                 &set, 1);
414                         }
415                 }
416         } else {
417                 ecore_x_window_prop_card32_set(win,
418                                 _WM_WINDOW_ROTATION_SUPPORTED,
419                                 &set, 1);
420         }
421 }
422
423 Ecore_X_Atom atom_parent;
424
425 static Eina_Bool __show_cb(void *data, int type, void *event)
426 {
427         Ecore_X_Event_Window_Show *ev;
428         int ret;
429         Ecore_X_Window parent;
430
431         ev = event;
432
433         ret = ecore_x_window_prop_window_get(ev->win, atom_parent, &parent, 1);
434         if (ret != 1)
435         {
436                 // This is child window. Skip!!!
437                 return ECORE_CALLBACK_PASS_ON;
438         }
439
440         _DBG("[EVENT_TEST][EVENT] GET SHOW EVENT!!!. WIN:%x\n", ev->win);
441
442         if (!__exist_win((unsigned int)ev->win)) {
443                 /* WM_ROTATE */
444                 if ((priv.wm_rot_supported) && (1 == priv.rot_started)) {
445                         __set_wm_rotation_support(ev->win, 1);
446                 }
447                 __add_win((unsigned int)ev->win);
448         }
449         else
450                 __update_win((unsigned int)ev->win, FALSE);
451
452         return ECORE_CALLBACK_RENEW;
453 }
454
455 static Eina_Bool __hide_cb(void *data, int type, void *event)
456 {
457         Ecore_X_Event_Window_Hide *ev;
458         int bvisibility = 0;
459
460         ev = event;
461
462         _DBG("[EVENT_TEST][EVENT] GET HIDE EVENT!!!. WIN:%x\n", ev->win);
463
464         if (__exist_win((unsigned int)ev->win)) {
465                 __delete_win((unsigned int)ev->win);
466                 
467                 bvisibility = __check_visible();
468                 if (!bvisibility && b_active == 1) {
469                         _DBG(" Go to Pasue state \n");
470                         b_active = 0;
471                         __do_app(AE_PAUSE, data, NULL);
472                 }
473         }
474
475         return ECORE_CALLBACK_RENEW;
476 }
477
478 static Eina_Bool __visibility_cb(void *data, int type, void *event)
479 {
480         Ecore_X_Event_Window_Visibility_Change *ev;
481         int bvisibility = 0;
482
483         ev = event;
484
485         __update_win((unsigned int)ev->win, ev->fully_obscured);
486         bvisibility = __check_visible();
487
488         if (bvisibility && b_active == 0) {
489                 _DBG(" Go to Resume state\n");
490                 b_active = 1;
491                 __do_app(AE_RESUME, data, NULL);
492
493         } else if (!bvisibility && b_active == 1) {
494                 _DBG(" Go to Pasue state \n");
495                 b_active = 0;
496                 __do_app(AE_PAUSE, data, NULL);
497         } else
498                 _DBG(" No change state \n");
499
500         return ECORE_CALLBACK_RENEW;
501
502 }
503
504 /* WM_ROTATE */
505 static Eina_Bool __cmsg_cb(void *data, int type, void *event)
506 {
507         struct ui_priv *ui = (struct ui_priv *)data;
508         Ecore_X_Event_Client_Message *e = event;
509
510         if (!ui) return ECORE_CALLBACK_PASS_ON;
511         if (e->format != 32) return ECORE_CALLBACK_PASS_ON;
512         if (e->message_type == _WM_WINDOW_ROTATION_CHANGE_REQUEST) {
513                 if ((0 == ui->wm_rot_supported) ||
514                         (0 == ui->rot_started) ||
515                         (NULL == ui->rot_cb)) {
516                         return ECORE_CALLBACK_PASS_ON;
517                 }
518
519                 enum appcore_rm rm;
520                 switch (e->data.l[1])
521                 {
522                         case   0: rm = APPCORE_RM_PORTRAIT_NORMAL;   break;
523                         case  90: rm = APPCORE_RM_LANDSCAPE_REVERSE; break;
524                         case 180: rm = APPCORE_RM_PORTRAIT_REVERSE;  break;
525                         case 270: rm = APPCORE_RM_LANDSCAPE_NORMAL;  break;
526                         default:  rm = APPCORE_RM_UNKNOWN;           break;
527                 }
528
529                 ui->rot_mode = rm;
530
531                 if (APPCORE_RM_UNKNOWN != rm) {
532                         ui->rot_cb(rm, ui->rot_cb_data);
533                 }
534         }
535
536         return ECORE_CALLBACK_PASS_ON;
537 }
538
539 static void __add_climsg_cb(struct ui_priv *ui)
540 {
541         _ret_if(ui == NULL);
542
543         atom_parent = ecore_x_atom_get("_E_PARENT_BORDER_WINDOW");
544         if (!atom_parent)
545         {
546                 // Do Error Handling
547         }
548
549         ui->hshow =
550             ecore_event_handler_add(ECORE_X_EVENT_WINDOW_SHOW, __show_cb, ui);
551         ui->hhide =
552             ecore_event_handler_add(ECORE_X_EVENT_WINDOW_HIDE, __hide_cb, ui);
553         ui->hvchange =
554             ecore_event_handler_add(ECORE_X_EVENT_WINDOW_VISIBILITY_CHANGE,
555                                     __visibility_cb, ui);
556
557         /* Add client message callback for WM_ROTATE */
558         if(!__check_wm_rotation_support())
559         {
560                 ui->hcmsg =
561                         ecore_event_handler_add(ECORE_X_EVENT_CLIENT_MESSAGE, __cmsg_cb, ui);
562                 ui->wm_rot_supported = 1;
563                 appcore_set_wm_rotation(&wm_rotate);
564         }
565 }
566
567 static int __before_loop(struct ui_priv *ui, int *argc, char ***argv)
568 {
569         int r;
570         char *hwacc = NULL;
571
572         if (argc == NULL || argv == NULL) {
573                 _ERR("argc/argv is NULL");
574                 errno = EINVAL;
575                 return -1;
576         }
577
578         g_type_init();
579         elm_init(*argc, *argv);
580
581         hwacc = getenv("HWACC");
582
583         if(hwacc == NULL) {
584                 _DBG("elm_config_preferred_engine_set is not called");
585         } else if(strcmp(hwacc, "USE") == 0) {
586                 elm_config_preferred_engine_set("opengl_x11");
587                 _DBG("elm_config_preferred_engine_set : opengl_x11");
588         } else if(strcmp(hwacc, "NOT_USE") == 0) {
589                 elm_config_preferred_engine_set("software_x11");
590                 _DBG("elm_config_preferred_engine_set : software_x11");
591         } else {
592                 _DBG("elm_config_preferred_engine_set is not called");
593         }
594
595         r = appcore_init(ui->name, &efl_ops, *argc, *argv);
596         _retv_if(r == -1, -1);
597
598         LOG(LOG_DEBUG, "LAUNCH", "[%s:Platform:appcore_init:done]", ui->name);
599         if (ui->ops && ui->ops->create) {
600                 r = ui->ops->create(ui->ops->data);
601                 if (r == -1) {
602                         _ERR("create() return error");
603                         appcore_exit();
604                         errno = ECANCELED;
605                         return -1;
606                 }
607                 LOG(LOG_DEBUG, "LAUNCH", "[%s:Application:create:done]",
608                     ui->name);
609         }
610         ui->state = AS_CREATED;
611
612         __add_climsg_cb(ui);
613
614         return 0;
615 }
616
617 static void __after_loop(struct ui_priv *ui)
618 {
619         appcore_unset_rotation_cb();
620         appcore_exit();
621
622         if (ui->ops && ui->ops->terminate)
623                 ui->ops->terminate(ui->ops->data);
624
625         if (ui->hshow)
626                 ecore_event_handler_del(ui->hshow);
627         if (ui->hhide)
628                 ecore_event_handler_del(ui->hhide);
629         if (ui->hvchange)
630                 ecore_event_handler_del(ui->hvchange);
631
632         __appcore_timer_del(ui);
633
634         elm_shutdown();
635 }
636
637 static int __set_data(struct ui_priv *ui, const char *name,
638                     struct appcore_ops *ops)
639 {
640         if (ui->name) {
641                 _ERR("Mainloop already started");
642                 errno = EINPROGRESS;
643                 return -1;
644         }
645
646         if (name == NULL || name[0] == '\0') {
647                 _ERR("Invalid name");
648                 errno = EINVAL;
649                 return -1;
650         }
651
652         if (ops == NULL) {
653                 _ERR("ops is NULL");
654                 errno = EINVAL;
655                 return -1;
656         }
657
658         ui->name = strdup(name);
659         _retv_if(ui->name == NULL, -1);
660
661         ui->ops = ops;
662
663         ui->mfcb = __appcore_efl_memory_flush_cb;
664
665         _pid = getpid();
666
667         /* WM_ROTATE */
668         ui->wm_rot_supported = 0;
669         ui->rot_started = 0;
670         ui->rot_cb = NULL;
671         ui->rot_cb_data = NULL;
672         ui->rot_mode = APPCORE_RM_UNKNOWN;
673
674         return 0;
675 }
676
677 static void __unset_data(struct ui_priv *ui)
678 {
679         if (ui->name)
680                 free((void *)ui->name);
681
682         memset(ui, 0, sizeof(struct ui_priv));
683 }
684
685 /* WM_ROTATE */
686 static int __wm_set_rotation_cb(int (*cb) (enum appcore_rm, void *), void *data)
687 {
688         if (cb == NULL) {
689                 errno = EINVAL;
690                 return -1;
691         }
692
693         if ((priv.wm_rot_supported) && (0 == priv.rot_started)) {
694                 __set_wm_rotation_support(0, 1);
695         }
696
697         priv.rot_cb = cb;
698         priv.rot_cb_data = data;
699         priv.rot_started = 1;
700
701         return 0;
702 }
703
704 static int __wm_unset_rotation_cb(void)
705 {
706         if ((priv.wm_rot_supported) && (1 == priv.rot_started)) {
707                 __set_wm_rotation_support(0, 0);
708         }
709
710         priv.rot_cb = NULL;
711         priv.rot_cb_data = NULL;
712         priv.rot_started = 0;
713
714         return 0;
715 }
716
717 static int __wm_get_rotation_state(enum appcore_rm *curr)
718 {
719         if (curr == NULL) {
720                 errno = EINVAL;
721                 return -1;
722         }
723
724         *curr = priv.rot_mode;
725
726         return 0;
727 }
728
729 static int __wm_pause_rotation_cb(void)
730 {
731         if ((1 == priv.rot_started) && (priv.wm_rot_supported)) {
732                 __set_wm_rotation_support(0, 0);
733         }
734
735         priv.rot_started = 0;
736
737         return 0;
738 }
739
740 static int __wm_resume_rotation_cb(void)
741 {
742         if ((0 == priv.rot_started) && (priv.wm_rot_supported)) {
743                 __set_wm_rotation_support(0, 1);
744         }
745
746         priv.rot_started = 1;
747
748         return 0;
749 }
750
751 static struct ui_wm_rotate wm_rotate = {
752         __wm_set_rotation_cb,
753         __wm_unset_rotation_cb,
754         __wm_get_rotation_state,
755         __wm_pause_rotation_cb,
756         __wm_resume_rotation_cb
757 };
758
759 EXPORT_API int appcore_efl_main(const char *name, int *argc, char ***argv,
760                                 struct appcore_ops *ops)
761 {
762         int r;
763
764         LOG(LOG_DEBUG, "LAUNCH", "[%s:Application:main:done]", name);
765
766         r = __set_data(&priv, name, ops);
767         _retv_if(r == -1, -1);
768
769         r = __before_loop(&priv, argc, argv);
770         if (r == -1) {
771                 __unset_data(&priv);
772                 return -1;
773         }
774
775         elm_run();
776
777         __after_loop(&priv);
778
779         __unset_data(&priv);
780
781         return 0;
782 }
783
784 EXPORT_API int appcore_set_system_resource_reclaiming(bool enable)
785 {
786         resource_reclaiming = enable;
787
788         return 0;
789 }