2 * Copyright (c) 2000 - 2017 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.
22 #include <sys/types.h>
25 #include <linux/limits.h>
30 #include <bundle_internal.h>
31 #include <system_info.h>
34 #include "appcore-internal.h"
35 #include "appcore-common.h"
36 #include "appcore_base.h"
38 #define SQLITE_FLUSH_MAX (1024*1024)
40 static appcore_base_event_h __handles[APPCORE_BASE_EVENT_MAX];
41 static int __convertor[] = {
42 [APPCORE_EVENT_UNKNOWN] = APPCORE_BASE_EVENT_START,
43 [APPCORE_EVENT_LOW_MEMORY] = APPCORE_BASE_EVENT_LOW_MEMORY,
44 [APPCORE_EVENT_LOW_BATTERY] = APPCORE_BASE_EVENT_LOW_BATTERY,
45 [APPCORE_EVENT_LANG_CHANGE] = APPCORE_BASE_EVENT_LANG_CHANGE,
46 [APPCORE_EVENT_REGION_CHANGE] = APPCORE_BASE_EVENT_REGION_CHANGE,
47 [APPCORE_EVENT_SUSPENDED_STATE_CHANGE] = APPCORE_BASE_EVENT_SUSPENDED_STATE_CHANGE,
48 [APPCORE_EVENT_UPDATE_REQUESTED] = APPCORE_BASE_EVENT_UPDATE_REQUESTED,
51 struct appcore_context {
55 static struct appcore_context __context;
57 EXPORT_API int appcore_set_event_callback(enum appcore_event event,
58 int (*cb) (void *, void *), void *data)
61 if (__handles[event]) {
62 ret = appcore_base_remove_event(__handles[event]);
64 _ERR("Fail to remove event");
66 __handles[event] = appcore_base_add_event((enum appcore_base_event)__convertor[event], cb, data);
71 static int __app_create(void *data)
73 appcore_base_on_create();
75 if (__context.ops.cb_app == NULL)
78 __context.ops.cb_app(AE_CREATE, __context.ops.data, NULL);
82 static int __app_terminate(void *data)
84 appcore_base_on_terminate();
86 if (__context.ops.cb_app)
87 __context.ops.cb_app(AE_TERMINATE, __context.ops.data, NULL);
92 static int __app_control(bundle *b, void *data)
94 appcore_base_on_control(b);
96 if (__context.ops.cb_app)
97 __context.ops.cb_app(AE_RESET, __context.ops.data, b);
102 EXPORT_API int appcore_init(const char *name, const struct ui_ops *ops,
103 int argc, char **argv)
105 appcore_base_ops base_ops = appcore_base_get_default_ops();
107 /* override methods */
108 base_ops.create = __app_create;
109 base_ops.terminate = __app_terminate;
110 base_ops.control = __app_control;
112 base_ops.exit = NULL;
114 __context.ops = *ops;
116 return appcore_base_init(base_ops, argc, argv, NULL);
119 EXPORT_API void appcore_exit(void)
124 EXPORT_API int appcore_flush_memory(void)
126 int (*flush_fn) (int);
128 _DBG("[APP %d] Flushing memory ...", getpid());
129 if (__context.ops.cb_app)
130 __context.ops.cb_app(AE_MEM_FLUSH, __context.ops.data, NULL);
132 flush_fn = dlsym(RTLD_DEFAULT, "sqlite3_release_memory");
134 flush_fn(SQLITE_FLUSH_MAX);
137 _DBG("[APP %d] Flushing memory DONE", getpid());