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 appcore_base_remove_event(__handles[event]);
62 __handles[event] = appcore_base_add_event((enum appcore_base_event)__convertor[event], cb, data);
67 static int __app_create(void *data)
69 appcore_base_on_create();
71 if (__context.ops.cb_app == NULL)
74 __context.ops.cb_app(AE_CREATE, __context.ops.data, NULL);
78 static int __app_terminate(void *data)
80 appcore_base_on_terminate();
82 if (__context.ops.cb_app)
83 __context.ops.cb_app(AE_TERMINATE, __context.ops.data, NULL);
88 static int __app_control(bundle *b, void *data)
90 appcore_base_on_control(b);
92 if (__context.ops.cb_app)
93 __context.ops.cb_app(AE_RESET, __context.ops.data, b);
98 EXPORT_API int appcore_init(const char *name, const struct ui_ops *ops,
99 int argc, char **argv)
101 appcore_base_ops base_ops = appcore_base_get_default_ops();
103 /* override methods */
104 base_ops.create = __app_create;
105 base_ops.terminate = __app_terminate;
106 base_ops.control = __app_control;
108 base_ops.exit = NULL;
110 __context.ops = *ops;
112 return appcore_base_init(base_ops, argc, argv, NULL);
115 EXPORT_API void appcore_exit(void)
120 EXPORT_API int appcore_flush_memory(void)
122 int (*flush_fn) (int);
124 _DBG("[APP %d] Flushing memory ...", getpid());
125 if (__context.ops.cb_app)
126 __context.ops.cb_app(AE_MEM_FLUSH, __context.ops.data, NULL);
128 flush_fn = dlsym(RTLD_DEFAULT, "sqlite3_release_memory");
130 flush_fn(SQLITE_FLUSH_MAX);
133 _DBG("[APP %d] Flushing memory DONE", getpid());