Disable gl engine
[platform/core/appfw/data-provider-slave.git] / src / main.c
1 /*
2  * Copyright 2013  Samsung Electronics Co., Ltd
3  *
4  * Licensed under the Flora License, Version 1.1 (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://floralicense.org/license/
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 <string.h>
20 #include <malloc.h>
21 #include <mcheck.h>
22 #include <dlfcn.h>
23
24 #include <Elementary.h>
25
26 #include <glib.h>
27 #include <glib-object.h>
28 #include <gio/gio.h>
29 #include <json-glib/json-glib.h>
30 #include <Ecore.h>
31 #include <Ecore_X.h>
32 #include <app.h>
33 #include <Edje.h>
34 #include <Eina.h>
35 #include <efl_assist.h>
36
37 #include <system_settings.h>
38
39 #include <dlog.h>
40 #include <bundle.h>
41 #include <dynamicbox_service.h>
42 #include <dynamicbox_provider.h>
43 #include <dynamicbox_script.h>
44 #include <dynamicbox_conf.h>
45 #include <dynamicbox.h>
46 #include <internal/dynamicbox.h>
47 #include <vconf.h>
48
49 #include "critical_log.h"
50 #include "debug.h"
51 #include "fault.h"
52 #include "update_monitor.h"
53 #include "client.h"
54 #include "util.h"
55 #include "so_handler.h"
56 #include "dbox.h"
57 #include "conf.h"
58 #include "theme_loader.h"
59
60 #define TEXT_CLASS         "tizen"
61 #define DEFAULT_FONT_SIZE  -100
62 #define WVGA_DEFAULT_SCALE 1.8f
63
64 #if !defined(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_NAME)
65 #define VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_NAME "db/setting/accessibility/font_name"
66 #endif
67
68 #if !defined(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE)
69 #define VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE "db/setting/accessibility/font_size"
70 #endif
71
72 static struct info {
73     char *font_name;
74     int font_size;
75     int (*heap_monitor_initialized)(void);
76     size_t (*heap_monitor_target_usage)(const char *name);
77     int (*heap_monitor_add_target)(const char *name);
78     int (*heap_monitor_del_target)(const char *name);
79     void *heap_monitor;
80     Ea_Theme_Font_Table *table;
81
82     app_event_handler_h lang_changed_handler;
83     app_event_handler_h region_changed_handler;
84 } s_info = {
85     .font_name = NULL,
86     .font_size = DEFAULT_FONT_SIZE,
87     .heap_monitor_initialized = NULL,
88     .heap_monitor_target_usage = NULL,
89     .heap_monitor_add_target = NULL,
90     .heap_monitor_del_target = NULL,
91     .heap_monitor = NULL,
92     .table = NULL,
93     .lang_changed_handler = NULL,
94     .region_changed_handler = NULL,
95 };
96
97 #define SLAVE_VCONFKEY_FONT_NAME "db/setting/accessibility/font_name"
98
99 static void font_changed_cb(void *user_data)
100 {
101     char *font_name;
102
103     evas_font_reinit();
104
105     if (s_info.font_name) {
106         font_name = vconf_get_str(SLAVE_VCONFKEY_FONT_NAME);
107         if (!font_name) {
108             ErrPrint("Invalid font name (NULL)\n");
109             return;
110         }
111
112         if (!strcmp(s_info.font_name, font_name)) {
113             DbgPrint("Font is not changed (Old: %s(%p) <> New: %s(%p))\n", s_info.font_name, s_info.font_name, font_name, font_name);
114             free(font_name);
115             return;
116         }
117
118         DbgPrint("Release old font name: %s(%p)\n", s_info.font_name, s_info.font_name);
119         free(s_info.font_name);
120     } else {
121         int ret;
122
123         font_name = NULL;
124         ret = system_settings_get_value_string(SYSTEM_SETTINGS_KEY_FONT_TYPE, &font_name);
125         if (ret != SYSTEM_SETTINGS_ERROR_NONE || !font_name) {
126             ErrPrint("System settings: %d, font_name[%p]\n", ret, font_name);
127             return;
128         }
129     }
130
131     s_info.font_name = font_name;
132     DbgPrint("Font name is changed to %s(%p)\n", s_info.font_name, s_info.font_name);
133
134     /**
135      * @NOTE
136      * Try to update all dynamicboxes
137      */
138     edje_text_class_set(TEXT_CLASS, s_info.font_name, DEFAULT_FONT_SIZE);
139
140     DbgPrint("Call system event\n");
141     dbox_system_event_all(DBOX_SYS_EVENT_FONT_CHANGED);
142 }
143
144 static inline int convert_font_size(int size)
145 {
146     switch (size) {
147         case SYSTEM_SETTINGS_FONT_SIZE_SMALL:
148             size = -80;
149             break;
150         case SYSTEM_SETTINGS_FONT_SIZE_NORMAL:
151             size = -100;
152             break;
153         case SYSTEM_SETTINGS_FONT_SIZE_LARGE:
154             size = -150;
155             break;
156         case SYSTEM_SETTINGS_FONT_SIZE_HUGE:
157             size = -190;
158             break;
159         case SYSTEM_SETTINGS_FONT_SIZE_GIANT:
160             size = -250;
161             break;
162         default:
163             size = -100;
164             break;
165     }
166
167     DbgPrint("Return size: %d\n", size);
168     return size;
169 }
170
171 static void font_size_cb(system_settings_key_e key, void *user_data)
172 {
173     int size;
174
175     if (system_settings_get_value_int(SYSTEM_SETTINGS_KEY_FONT_SIZE, &size) != SYSTEM_SETTINGS_ERROR_NONE) {
176         return;
177     }
178
179     size = convert_font_size(size);
180
181     if (size == s_info.font_size) {
182         DbgPrint("Font size is not changed\n");
183         return;
184     }
185
186     s_info.font_size = size;
187     DbgPrint("Font size is changed to %d, but don't try to update it.\n", size);
188 }
189
190 static void tts_changed_cb(keynode_t *node, void *user_data)
191 {
192     DbgPrint("TTS status is changed\n");
193     dbox_system_event_all(DBOX_SYS_EVENT_TTS_CHANGED);
194 }
195
196 static void mmc_changed_cb(keynode_t *node, void *user_data)
197 {
198     DbgPrint("MMC status is changed\n");
199     dbox_system_event_all(DBOX_SYS_EVENT_MMC_STATUS_CHANGED);
200 }
201
202 static void time_changed_cb(keynode_t *node, void *user_data)
203 {
204     DbgPrint("Time is changed\n");
205     dbox_system_event_all(DBOX_SYS_EVENT_TIME_CHANGED);
206 }
207
208 static void initialize_glib_type_system(void)
209 {
210     GType type;
211
212     type = G_TYPE_DBUS_ACTION_GROUP;
213     if (type != G_TYPE_OBJECT) {
214         DbgPrint("initialized\n");
215     }
216     type = G_TYPE_DBUS_ANNOTATION_INFO;
217     if (type != G_TYPE_OBJECT) {
218         DbgPrint("initialized\n");
219     }
220     type = G_TYPE_DBUS_ARG_INFO;
221     if (type != G_TYPE_OBJECT) {
222         DbgPrint("initialized\n");
223     }
224     type = G_TYPE_DBUS_AUTH_OBSERVER;
225     if (type != G_TYPE_OBJECT) {
226         DbgPrint("initialized\n");
227     }
228     type = G_TYPE_DBUS_CALL_FLAGS;
229     if (type != G_TYPE_OBJECT) {
230         DbgPrint("initialized\n");
231     }
232     type = G_TYPE_DBUS_CAPABILITY_FLAGS;
233     if (type != G_TYPE_OBJECT) {
234         DbgPrint("initialized\n");
235     }
236     type = G_TYPE_DBUS_CONNECTION;
237     if (type != G_TYPE_OBJECT) {
238         DbgPrint("initialized\n");
239     }
240     type = G_TYPE_DBUS_CONNECTION_FLAGS;
241     if (type != G_TYPE_OBJECT) {
242         DbgPrint("initialized\n");
243     }
244     type = G_TYPE_DBUS_ERROR;
245     if (type != G_TYPE_OBJECT) {
246         DbgPrint("initialized\n");
247     }
248     type = G_TYPE_DBUS_INTERFACE;
249     if (type != G_TYPE_OBJECT) {
250         DbgPrint("initialized\n");
251     }
252     type = G_TYPE_DBUS_INTERFACE_INFO;
253     if (type != G_TYPE_OBJECT) {
254         DbgPrint("initialized\n");
255     }
256     type = G_TYPE_DBUS_INTERFACE_SKELETON;
257     if (type != G_TYPE_OBJECT) {
258         DbgPrint("initialized\n");
259     }
260     type = G_TYPE_DBUS_INTERFACE_SKELETON_FLAGS;
261     if (type != G_TYPE_OBJECT) {
262         DbgPrint("initialized\n");
263     }
264     type = G_TYPE_DBUS_MENU_MODEL;
265     if (type != G_TYPE_OBJECT) {
266         DbgPrint("initialized\n");
267     }
268     type = G_TYPE_DBUS_MESSAGE;
269     if (type != G_TYPE_OBJECT) {
270         DbgPrint("initialized\n");
271     }
272     type = G_TYPE_DBUS_MESSAGE_BYTE_ORDER;
273     if (type != G_TYPE_OBJECT) {
274         DbgPrint("initialized\n");
275     }
276     type = G_TYPE_DBUS_MESSAGE_FLAGS;
277     if (type != G_TYPE_OBJECT) {
278         DbgPrint("initialized\n");
279     }
280     type = G_TYPE_DBUS_MESSAGE_HEADER_FIELD;
281     if (type != G_TYPE_OBJECT) {
282         DbgPrint("initialized\n");
283     }
284     type = G_TYPE_DBUS_MESSAGE_TYPE;
285     if (type != G_TYPE_OBJECT) {
286         DbgPrint("initialized\n");
287     }
288     type = G_TYPE_DBUS_METHOD_INFO;
289     if (type != G_TYPE_OBJECT) {
290         DbgPrint("initialized\n");
291     }
292     type = G_TYPE_DBUS_METHOD_INVOCATION;
293     if (type != G_TYPE_OBJECT) {
294         DbgPrint("initialized\n");
295     }
296     type = G_TYPE_DBUS_NODE_INFO;
297     if (type != G_TYPE_OBJECT) {
298         DbgPrint("initialized\n");
299     }
300     type = G_TYPE_DBUS_OBJECT;
301     if (type != G_TYPE_OBJECT) {
302         DbgPrint("initialized\n");
303     }
304     type = G_TYPE_DBUS_OBJECT_MANAGER;
305     if (type != G_TYPE_OBJECT) {
306         DbgPrint("initialized\n");
307     }
308     type = G_TYPE_DBUS_OBJECT_MANAGER_CLIENT;
309     if (type != G_TYPE_OBJECT) {
310         DbgPrint("initialized\n");
311     }
312     type = G_TYPE_DBUS_OBJECT_MANAGER_CLIENT_FLAGS;
313     if (type != G_TYPE_OBJECT) {
314         DbgPrint("initialized\n");
315     }
316     type = G_TYPE_DBUS_OBJECT_MANAGER_SERVER;
317     if (type != G_TYPE_OBJECT) {
318         DbgPrint("initialized\n");
319     }
320     type = G_TYPE_DBUS_OBJECT_PROXY;
321     if (type != G_TYPE_OBJECT) {
322         DbgPrint("initialized\n");
323     }
324     type = G_TYPE_DBUS_OBJECT_SKELETON;
325     if (type != G_TYPE_OBJECT) {
326         DbgPrint("initialized\n");
327     }
328     type = G_TYPE_DBUS_PROPERTY_INFO;
329     if (type != G_TYPE_OBJECT) {
330         DbgPrint("initialized\n");
331     }
332     type = G_TYPE_DBUS_PROPERTY_INFO_FLAGS;
333     if (type != G_TYPE_OBJECT) {
334         DbgPrint("initialized\n");
335     }
336     type = G_TYPE_DBUS_PROXY;
337     if (type != G_TYPE_OBJECT) {
338         DbgPrint("initialized\n");
339     }
340     type = G_TYPE_DBUS_PROXY_FLAGS;
341     if (type != G_TYPE_OBJECT) {
342         DbgPrint("initialized\n");
343     }
344     type = G_TYPE_DBUS_SEND_MESSAGE_FLAGS;
345     if (type != G_TYPE_OBJECT) {
346         DbgPrint("initialized\n");
347     }
348     type = G_TYPE_DBUS_SERVER;
349     if (type != G_TYPE_OBJECT) {
350         DbgPrint("initialized\n");
351     }
352     type = G_TYPE_DBUS_SERVER_FLAGS;
353     if (type != G_TYPE_OBJECT) {
354         DbgPrint("initialized\n");
355     }
356     type = G_TYPE_DBUS_SIGNAL_FLAGS;
357     if (type != G_TYPE_OBJECT) {
358         DbgPrint("initialized\n");
359     }
360     type = G_TYPE_DBUS_SIGNAL_INFO;
361     if (type != G_TYPE_OBJECT) {
362         DbgPrint("initialized\n");
363     }
364     type = G_TYPE_DBUS_SUBTREE_FLAGS;
365     if (type != G_TYPE_OBJECT) {
366         DbgPrint("initialized\n");
367     }
368     type = JSON_TYPE_NODE;
369     if (type != G_TYPE_OBJECT) {
370         DbgPrint("initialized\n");
371     }
372     type = JSON_TYPE_OBJECT;
373     if (type != G_TYPE_OBJECT) {
374         DbgPrint("initialized\n");
375     }
376     type = JSON_TYPE_ARRAY;
377     if (type != G_TYPE_OBJECT) {
378         DbgPrint("initialized\n");
379     }
380     type = JSON_TYPE_ARRAY;
381     if (type != G_TYPE_OBJECT) {
382         DbgPrint("initialized\n");
383     }
384     type = JSON_TYPE_SERIALIZABLE;
385     if (type != G_TYPE_OBJECT) {
386         DbgPrint("initialized\n");
387     }
388     type = JSON_TYPE_PARSER;
389     if (type != G_TYPE_OBJECT) {
390         DbgPrint("initialized\n");
391     }
392     type = JSON_TYPE_GENERATOR;
393     if (type != G_TYPE_OBJECT) {
394         DbgPrint("initialized\n");
395     }
396 }
397
398 static bool app_create(void *argv)
399 {
400     int ret;
401
402     elm_app_base_scale_set(WVGA_DEFAULT_SCALE);
403 //    elm_config_preferred_engine_set("opengl_x11");
404
405     dynamicbox_conf_init();
406     if (!dynamicbox_conf_is_loaded()) {
407         ret = dynamicbox_conf_load();
408         if (ret < 0) {
409             DbgPrint("Configureation manager is initiated: %d\n", ret);
410         }
411     }
412
413     critical_log_init(util_basename(((char **)argv)[0]));
414
415     /*!
416      * Touch the glib type system
417      */
418     initialize_glib_type_system();
419
420     DbgPrint("Scale factor: %lf\n", elm_config_scale_get());
421
422     if (DYNAMICBOX_CONF_COM_CORE_THREAD) {
423         if (setenv("PROVIDER_COM_CORE_THREAD", "true", 0) < 0) {
424             ErrPrint("setenv: %s\n", strerror(errno));
425         }
426     } else {
427         if (setenv("PROVIDER_COM_CORE_THREAD", "false", 0) < 0){
428             ErrPrint("setenv: %s\n", strerror(errno));
429         }
430     }
431
432     ret = dynamicbox_service_init();
433     if (ret < 0) {
434         DbgPrint("Livebox service init: %d\n", ret);
435     }
436
437     /**
438      * @note
439      * Slave is not able to initiate system, before
440      * receive its name from the master
441      *
442      * So create callback doesn't do anything.
443      */
444     ret = fault_init(argv);
445     if (ret < 0) {
446         DbgPrint("Crash recover is initiated: %d\n", ret);
447     }
448
449     ret = update_monitor_init();
450     if (ret < 0) {
451         DbgPrint("Content update monitor is initiated: %d\n", ret);
452     }
453
454     s_info.table = ea_theme_font_table_new("/usr/share/themes/FontInfoTable.xml");
455     if (s_info.table) {
456         DbgPrint("FONT TABLE Prepared");
457         ea_theme_fonts_set(s_info.table);
458     }
459     ea_theme_event_callback_add(EA_THEME_CALLBACK_TYPE_FONT, font_changed_cb, NULL);
460
461     ret = system_settings_set_changed_cb(SYSTEM_SETTINGS_KEY_FONT_SIZE, font_size_cb, NULL);
462     if (ret < 0) {
463         DbgPrint("System font size changed callback is added: %d\n", ret);
464     }
465
466     ret = vconf_notify_key_changed(VCONFKEY_SYSTEM_TIME_CHANGED, time_changed_cb, NULL);
467     if (ret < 0) {
468         DbgPrint("System time changed event callback added: %d\n", ret);
469     }
470
471     ret = vconf_notify_key_changed(VCONFKEY_SYSMAN_MMC_STATUS, mmc_changed_cb, NULL);
472     if (ret < 0) {
473         DbgPrint("MMC status changed event callback added: %d\n", ret);
474     }
475
476     ret = vconf_notify_key_changed(VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, tts_changed_cb, NULL);
477     if (ret < 0) {
478         DbgPrint("TTS changed callback is added: %s\n", ret);
479     }
480
481     font_changed_cb(NULL);
482     font_size_cb(SYSTEM_SETTINGS_KEY_FONT_SIZE, NULL);
483     theme_loader_load(THEME_DIR);
484
485     dbox_init();
486
487     return TRUE;
488 }
489
490 static void app_terminate(void *data)
491 {
492     int ret;
493
494     DbgPrint("Terminating provider\n");
495
496     dbox_fini();
497
498     theme_loader_unload();
499
500     if (s_info.table) {
501         DbgPrint("FONT TABLE Destroyed");
502         ea_theme_font_table_free(s_info.table);
503         s_info.table = NULL;
504     }
505
506     ret = vconf_ignore_key_changed(VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, tts_changed_cb);
507     if (ret < 0) {
508         DbgPrint("TTS changed callback is added: %s\n", ret);
509     }
510
511     ret = system_settings_unset_changed_cb(SYSTEM_SETTINGS_KEY_FONT_SIZE);
512     if (ret < 0) {
513         DbgPrint("unset fontsize: %d\n", ret);
514     }
515
516     ea_theme_event_callback_del(EA_THEME_CALLBACK_TYPE_FONT, font_changed_cb);
517
518     ret = vconf_ignore_key_changed(VCONFKEY_SYSTEM_TIME_CHANGED, time_changed_cb);
519     if (ret < 0) {
520         DbgPrint("Remove time changed callback: %d\n", ret);
521     }
522
523     ret = vconf_ignore_key_changed(VCONFKEY_SYSMAN_MMC_STATUS, mmc_changed_cb);
524     if (ret < 0) {
525         DbgPrint("Remove MMC status changed callback: %d\n", ret);
526     }
527
528     ret = update_monitor_fini();
529     if (ret < 0) {
530         DbgPrint("Content update monitor is finalized: %d\n", ret);
531     }
532
533     ret = fault_fini();
534     if (ret < 0) {
535         DbgPrint("Crash recover is finalized: %d\n", ret);
536     }
537
538     ret = client_fini();
539     if (ret < 0) {
540         DbgPrint("client finalized: %d\n", ret); 
541     }
542
543     ret = dynamicbox_service_fini();
544     if (ret < 0) {
545         DbgPrint("dynamicbox service fini: %d\n", ret);
546     }
547
548     free(s_info.font_name);
549     s_info.font_name = NULL;
550
551     critical_log_fini();
552
553     exit(0);
554     return;
555 }
556
557 static void app_pause(void *data)
558 {
559     /* Will not be invoked */
560     return;
561 }
562
563 static void app_resume(void *data)
564 {
565     /* Will not be invoked */
566     return;
567 }
568
569 static void app_region_changed(app_event_info_h event_info, void *data)
570 {
571     // char *region;
572     // app_event_get_region_format(event_info, &region);
573     dbox_system_event_all(DBOX_SYS_EVENT_REGION_CHANGED);
574 }
575
576 static void app_language_changed(app_event_info_h event_info, void *data)
577 {
578     // char *lang;
579     // app_event_get_language(event_info, &lang);
580     dbox_system_event_all(DBOX_SYS_EVENT_LANG_CHANGED);
581 }
582
583 static void app_control(app_control_h service, void *data)
584 {
585     int ret;
586     char *name;
587     char *secured;
588     static int initialized = 0;
589
590     if (initialized) {
591         ErrPrint("Already initialized\n");
592         return;
593     }
594
595     ret = app_control_get_extra_data(service, "name", &name);
596     if (ret != APP_CONTROL_ERROR_NONE) {
597         ErrPrint("Name is not valid\n");
598         return;
599     }
600
601     ret = app_control_get_extra_data(service, "secured", &secured);
602     if (ret != APP_CONTROL_ERROR_NONE) {
603         free(name);
604         ErrPrint("Secured is not valid\n");
605         return;
606     }
607
608     if (!strcasecmp(secured, "true")) {
609         /* Don't use the update timer */
610         dbox_turn_secured_on();
611     }
612
613     DbgPrint("Name assigned: %s\n", name);
614     DbgPrint("Secured: %s\n", secured);
615     ret = client_init(name);
616     free(name);
617     free(secured);
618
619     initialized = 1;
620     return;
621 }
622
623 #if defined(_ENABLE_MCHECK)
624 static inline void mcheck_cb(enum mcheck_status status)
625 {
626     char *ptr;
627
628     ptr = util_get_current_module(NULL);
629
630     switch (status) {
631         case MCHECK_DISABLED:
632             ErrPrint("[DISABLED] Heap incosistency detected: %s\n", ptr);
633             break;
634         case MCHECK_OK:
635             ErrPrint("[OK] Heap incosistency detected: %s\n", ptr);
636             break;
637         case MCHECK_HEAD:
638             ErrPrint("[HEAD] Heap incosistency detected: %s\n", ptr);
639             break;
640         case MCHECK_TAIL:
641             ErrPrint("[TAIL] Heap incosistency detected: %s\n", ptr);
642             break;
643         case MCHECK_FREE:
644             ErrPrint("[FREE] Heap incosistency detected: %s\n", ptr);
645             break;
646         default:
647             break;
648     }
649 }
650 #endif
651
652 #define HEAP_MONITOR_PATH "/usr/lib/libheap-monitor.so"
653 #define BIN_PATH "/usr/apps/com.samsung.data-provider-slave/bin/"
654 int main(int argc, char *argv[])
655 {
656     int ret;
657     ui_app_lifecycle_callback_s event_callback;
658
659     const char *option;
660
661     memset(argv[0], 0, strlen(argv[0]));
662     strcpy(argv[0], BIN_PATH "data-provider-slave");
663     DbgPrint("Replace argv[0] with %s\n", argv[0]);
664
665 #if defined(_ENABLE_MCHECK)
666     mcheck(mcheck_cb);
667 #endif
668     option = getenv("PROVIDER_DISABLE_CALL_OPTION");
669     if (option && !strcasecmp(option, "true")) {
670         fault_disable_call_option();
671     }
672
673     option = getenv("PROVIDER_HEAP_MONITOR_START");
674     if (option && !strcasecmp(option, "true")) {
675         s_info.heap_monitor = dlopen(HEAP_MONITOR_PATH, RTLD_NOW);
676         if (s_info.heap_monitor) {
677             s_info.heap_monitor_initialized = dlsym(s_info.heap_monitor, "heap_monitor_initialized");
678             s_info.heap_monitor_target_usage = dlsym(s_info.heap_monitor, "heap_monitor_target_usage");
679             s_info.heap_monitor_add_target = dlsym(s_info.heap_monitor, "heap_monitor_add_target");
680             s_info.heap_monitor_del_target = dlsym(s_info.heap_monitor, "heap_monitor_del_target");
681         }
682     }
683
684     if (setenv("BUFMGR_LOCK_TYPE", "once", 0) < 0) {
685         ErrPrint("setenv: %s\n", strerror(errno));
686     }
687
688     if (setenv("BUFMGR_MAP_CACHE", "true", 0) < 0) {
689         ErrPrint("setenv: %s\n", strerror(errno));
690     }
691
692     event_callback.create = app_create;
693     event_callback.terminate = app_terminate;
694     event_callback.pause = app_pause;
695     event_callback.resume = app_resume;
696     event_callback.app_control = app_control;
697
698     ui_app_add_event_handler(&s_info.lang_changed_handler, APP_EVENT_LANGUAGE_CHANGED, app_language_changed, argv);
699     ui_app_add_event_handler(&s_info.region_changed_handler, APP_EVENT_REGION_FORMAT_CHANGED, app_region_changed, argv);
700     // APP_EVENT_DEVICE_ORIENTATION_CHANGED
701     // APP_EVENT_LOW_MEMORY
702     // APP_EVENT_LOW_BATTERY
703
704     ret = ui_app_main(argc, argv, &event_callback, (void *)argv);
705     ErrPrint("app_efl_main: %d\n", ret);
706
707     if (s_info.heap_monitor) {
708         if (dlclose(s_info.heap_monitor) < 0) {
709             ErrPrint("dlclose: %s\n", strerror(errno));
710         }
711     }
712
713     return ret;
714 }
715
716 HAPI int main_heap_monitor_is_enabled(void)
717 {
718     return s_info.heap_monitor_initialized ? s_info.heap_monitor_initialized() : 0;
719 }
720
721 HAPI size_t main_heap_monitor_target_usage(const char *name)
722 {
723     return s_info.heap_monitor_target_usage ? s_info.heap_monitor_target_usage(name) : 0;
724 }
725
726 HAPI int main_heap_monitor_add_target(const char *name)
727 {
728     return s_info.heap_monitor_add_target ? s_info.heap_monitor_add_target(name) : 0;
729 }
730
731 HAPI int main_heap_monitor_del_target(const char *name)
732 {
733     return s_info.heap_monitor_del_target ? s_info.heap_monitor_del_target(name) : 0;
734 }
735
736 /* End of a file */