Refactor APIs using appcore_base 24/82724/6
authorJunghoon Park <jh9216.park@samsung.com>
Fri, 5 Aug 2016 08:44:41 +0000 (17:44 +0900)
committerJunghoon Park <jh9216.park@samsung.com>
Fri, 10 Feb 2017 01:59:03 +0000 (10:59 +0900)
Change-Id: I6288e37a431da6b6202eb5a9c52aa80a31075177
Signed-off-by: Junghoon Park <jh9216.park@samsung.com>
include/appcore-agent.h [deleted file]
packaging/appcore-agent.spec
src/appcore-agent.c [deleted file]
src/service_app_error.c [deleted file]
src/service_app_main.c
src/service_app_private.h [deleted file]

diff --git a/include/appcore-agent.h b/include/appcore-agent.h
deleted file mode 100644 (file)
index 53a7316..0000000
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- *  app-core
- *
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>, Jaeho Lee <jaeho81.lee@samsung.com>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-
-
-#ifndef __AGENT_APPCORE_H__
-#define __AGENT_APPCORE_H__
-
-
-#include <libintl.h>
-#include <bundle.h>
-
-#include <app_control_internal.h>
-
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-struct agentcore_ops {
-       void *data;
-           /**< Callback data */
-       int (*create) (void *); /**< This callback function is called at the start of the application. */
-       int (*terminate) (void *); /**< This callback function is called once after the main loop of application exits. */
-       int (*app_control) (app_control_h, void *); /**< This callback function is called when other application send the launch request to the application. */
-
-       void *reserved[6];
-                  /**< Reserved */
-};
-
-enum appcore_agent_event {
-       APPCORE_AGENT_EVENT_UNKNOWN,
-                       /**< Unknown event */
-       APPCORE_AGENT_EVENT_LOW_MEMORY,
-                       /**< Low memory */
-       APPCORE_AGENT_EVENT_LOW_BATTERY,
-                       /**< Low battery */
-       APPCORE_AGENT_EVENT_LANG_CHANGE,
-                       /**< Language setting is changed */
-       APPCORE_AGENT_EVENT_REGION_CHANGE,
-                       /**< Region setting is changed */
-       APPCORE_AGENT_EVENT_SUSPENDED_STATE_CHANGE,
-                       /**< Suspend state is changed */
-};
-
-int appcore_agent_main(int argc, char **argv, struct agentcore_ops *ops);
-
-int appcore_agent_terminate();
-
-int appcore_agent_terminate_without_restart();
-
-int appcore_agent_set_event_callback(enum appcore_agent_event event,
-                                         int (*cb) (void *, void *), void *data);
-
-int _appcore_agent_init_suspend_dbus_handler(void *data);
-#ifdef __cplusplus
-}
-#endif
-
-#endif                         /* __AGENT_APPCORE_H__ */
index 9ac5bc1..afbfcd3 100644 (file)
@@ -65,7 +65,6 @@ MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'`
 %manifest %{name}.manifest
 %defattr(-,root,root,-)
 %{_libdir}/pkgconfig/appcore-agent.pc
-%{_includedir}/appcore-agent/appcore-agent.h
 
 
 %files -n capi-appfw-service-application-devel
diff --git a/src/appcore-agent.c b/src/appcore-agent.c
deleted file mode 100644 (file)
index 591eaac..0000000
+++ /dev/null
@@ -1,1118 +0,0 @@
-/*
- *  service-app-core
- *
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>, Jaeho Lee <jaeho81.lee@samsung.com>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-
-#define _GNU_SOURCE
-
-#include <errno.h>
-#include <string.h>
-#include <stdlib.h>
-#include <sys/types.h>
-#include <unistd.h>
-#include <malloc.h>
-#include <Ecore.h>
-#include <linux/limits.h>
-#include <dlfcn.h>
-#include <glib.h>
-
-#include <bundle.h>
-#include <aul.h>
-#include <appcore-common.h>
-#include <app_control_internal.h>
-#include <dlog.h>
-#include <vconf.h>
-#include <system_info.h>
-
-#include "appcore-agent.h"
-
-#include <gio/gio.h>
-
-#define RESOURCED_FREEZER_PATH "/Org/Tizen/Resourced/Freezer"
-#define RESOURCED_FREEZER_INTERFACE "org.tizen.resourced.frezer"
-#define RESOURCED_FREEZER_SIGNAL "FreezerState"
-#define APPFW_SUSPEND_HINT_PATH "/Org/Tizen/Appfw/SuspendHint"
-#define APPFW_SUSPEND_HINT_INTERFACE "org.tizen.appfw.SuspendHint"
-#define APPFW_SUSPEND_HINT_SIGNAL "SuspendHint"
-
-#ifdef LOG_TAG
-#undef LOG_TAG
-#endif
-
-#define LOG_TAG "APPCORE_AGENT"
-#define SQLITE_FLUSH_MAX       (1024 * 1024)
-
-#define _ERR(fmt, arg...) LOGE(fmt, ##arg)
-#define _INFO(fmt, arg...) LOGI(fmt, ##arg)
-#define _DBG(fmt, arg...) LOGD(fmt, ##arg)
-
-#ifndef EXPORT_API
-#define EXPORT_API __attribute__ ((visibility("default")))
-#endif
-
-#ifndef _ERR
-#define _ERR(fmt, arg...) LOGE(fmt, ##arg)
-#endif
-
-#ifndef _INFO
-#define _INFO(...) LOGI(__VA_ARGS__)
-#endif
-
-#ifndef _DBG
-#define _DBG(...) LOGD(__VA_ARGS__)
-#endif
-
-#define _warn_if(expr, fmt, arg...) do { \
-               if (expr) { \
-                       _ERR(fmt, ##arg); \
-               } \
-       } while (0)
-
-#define _ret_if(expr) do { \
-               if (expr) { \
-                       return; \
-               } \
-       } while (0)
-
-#define _retv_if(expr, val) do { \
-               if (expr) { \
-                       return (val); \
-               } \
-       } while (0)
-
-#define _retm_if(expr, fmt, arg...) do { \
-               if (expr) { \
-                       _ERR(fmt, ##arg); \
-                       return; \
-               } \
-       } while (0)
-
-#define _retvm_if(expr, val, fmt, arg...) do { \
-               if (expr) { \
-                       _ERR(fmt, ##arg); \
-                       return (val); \
-               } \
-       } while (0)
-
-#define APPID_MAX 256
-#define PATH_LOCALE "locale"
-
-
-typedef enum {
-       TIZEN_PROFILE_UNKNOWN = 0,
-       TIZEN_PROFILE_MOBILE = 0x1,
-       TIZEN_PROFILE_WEARABLE = 0x2,
-       TIZEN_PROFILE_TV = 0x4,
-       TIZEN_PROFILE_IVI = 0x8,
-       TIZEN_PROFILE_COMMON = 0x10,
-} tizen_profile_t;
-
-static tizen_profile_t _get_tizen_profile()
-{
-       static tizen_profile_t profile = TIZEN_PROFILE_UNKNOWN;
-       char *profileName;
-
-       if (__builtin_expect(profile != TIZEN_PROFILE_UNKNOWN, 1))
-               return profile;
-
-       system_info_get_platform_string("http://tizen.org/feature/profile", &profileName);
-       switch (*profileName) {
-       case 'm':
-       case 'M':
-               profile = TIZEN_PROFILE_MOBILE;
-               break;
-       case 'w':
-       case 'W':
-               profile = TIZEN_PROFILE_WEARABLE;
-               break;
-       case 't':
-       case 'T':
-               profile = TIZEN_PROFILE_TV;
-               break;
-       case 'i':
-       case 'I':
-               profile = TIZEN_PROFILE_IVI;
-               break;
-       default: // common or unknown ==> ALL ARE COMMON.
-               profile = TIZEN_PROFILE_COMMON;
-       }
-       free(profileName);
-
-       return profile;
-}
-#define TIZEN_FEATURE_BACKGROUND_MANAGEMENT (_get_tizen_profile() & (TIZEN_PROFILE_MOBILE | TIZEN_PROFILE_WEARABLE))
-
-static pid_t _pid;
-
-/**
- * Appcore internal system event
- */
-enum sys_event {
-       SE_UNKNOWN,
-       SE_LOWMEM,
-       SE_LOWBAT,
-       SE_LANGCHG,
-       SE_REGIONCHG,
-       SE_SUSPENDED_STATE,
-       SE_MAX
-};
-
-/**
- * agent internal state
- */
-enum agent_state {
-       AGS_NONE,
-       AGS_CREATED,
-       AGS_RUNNING,
-       AGS_STOPED,
-       AGS_DYING,
-};
-
-enum agent_event {
-       AGE_UNKNOWN,
-       AGE_CREATE,
-       AGE_TERMINATE,
-       AGE_STOP,
-       AGE_REQUEST,
-       AGE_MAX
-};
-
-
-static enum appcore_agent_event to_ae[SE_MAX] = {
-       APPCORE_AGENT_EVENT_UNKNOWN,            /* SE_UNKNOWN */
-       APPCORE_AGENT_EVENT_LOW_MEMORY,         /* SE_LOWMEM */
-       APPCORE_AGENT_EVENT_LOW_BATTERY,        /* SE_LOWBAT */
-       APPCORE_AGENT_EVENT_LANG_CHANGE,        /* SE_LANGCHG */
-       APPCORE_AGENT_EVENT_REGION_CHANGE,      /* SE_REGIONCHG */
-       APPCORE_AGENT_EVENT_SUSPENDED_STATE_CHANGE, /* SE_SUSPENDED_STATE */
-};
-
-static int appcore_agent_event_initialized[SE_MAX] = {0};
-
-enum cb_type {                 /* callback */
-       _CB_NONE,
-       _CB_SYSNOTI,
-       _CB_APPNOTI,
-       _CB_VCONF,
-};
-
-enum appcore_agent_suspended_state {
-       APPCORE_AGENT_SUSPENDED_STATE_WILL_ENTER_SUSPEND = 0,
-       APPCORE_AGENT_SUSPENDED_STATE_DID_EXIT_FROM_SUSPEND
-};
-
-struct evt_ops {
-       enum cb_type type;
-       union {
-               enum appcore_agent_event sys;
-               enum agent_event app;
-               const char *vkey;
-       } key;
-
-       int (*cb_pre) (void *);
-       int (*cb) (void *);
-       int (*cb_post) (void *);
-
-       int (*vcb_pre) (void *, void *);
-       int (*vcb) (void *, void *);
-       int (*vcb_post) (void *, void *);
-};
-
-struct agent_priv {
-       enum agent_state state;
-
-       struct agent_appcore *app_core;
-       struct agentcore_ops *ops;
-};
-
-static struct agent_priv priv;
-
-struct agent_ops {
-       void *data;
-       void (*cb_app)(enum agent_event, void *, bundle *);
-};
-
-/**
- * Appcore system event operation
- */
-struct sys_op {
-       int (*func) (void *, void *);
-       void *data;
-};
-
-struct agent_appcore {
-       int state;
-       unsigned int tid;
-       bool suspended_state;
-       bool allowed_bg;
-
-       const struct agent_ops *ops;
-       struct sys_op sops[SE_MAX];
-};
-
-static struct agent_appcore core;
-
-static int __sys_lowmem_post(void *data, void *evt);
-static int __sys_lowmem(void *data, void *evt);
-static int __sys_lowbatt(void *data, void *evt);
-static int __sys_langchg_pre(void *data, void *evt);
-static int __sys_langchg(void *data, void *evt);
-static int __sys_regionchg_pre(void *data, void *evt);
-static int __sys_regionchg(void *data, void *evt);
-
-static struct evt_ops evtops[] = {
-       {
-        .type = _CB_VCONF,
-        .key.vkey = VCONFKEY_SYSMAN_LOW_MEMORY,
-        .vcb_post = __sys_lowmem_post,
-        .vcb = __sys_lowmem,
-        },
-       {
-        .type = _CB_VCONF,
-        .key.vkey = VCONFKEY_SYSMAN_BATTERY_STATUS_LOW,
-        .vcb = __sys_lowbatt,
-        },
-       {
-       .type = _CB_VCONF,
-       .key.vkey = VCONFKEY_LANGSET,
-       .vcb_pre = __sys_langchg_pre,
-       .vcb = __sys_langchg,
-       },
-       {
-       .type = _CB_VCONF,
-       .key.vkey = VCONFKEY_REGIONFORMAT,
-       .vcb_pre = __sys_regionchg_pre,
-       .vcb = __sys_regionchg,
-        },
-       {
-       .type = _CB_VCONF,
-       .key.vkey = VCONFKEY_REGIONFORMAT_TIME1224,
-       .vcb = __sys_regionchg,
-        },
-};
-
-static GDBusConnection *bus = NULL;
-static guint __suspend_dbus_handler_initialized = 0;
-
-extern int app_control_create_event(bundle *data, struct app_control_s **app_control);
-static int __sys_do(struct agent_appcore *ac, void *event_info, enum sys_event event);
-
-/* LCOV_EXCL_START */
-static int appcore_agent_flush_memory(void)
-{
-       int (*flush_fn) (int);
-
-       if (!core.state) {
-               _ERR("Appcore not initialized");
-               return -1;
-       }
-
-       flush_fn = dlsym(RTLD_DEFAULT, "sqlite3_release_memory");
-       if (flush_fn) {
-               flush_fn(SQLITE_FLUSH_MAX);
-       }
-
-       malloc_trim(0);
-
-       return 0;
-}
-/* LCOV_EXCL_STOP */
-
-/* LCOV_EXCL_START */
-static void __prepare_to_suspend(void *data)
-{
-       int suspend = APPCORE_AGENT_SUSPENDED_STATE_WILL_ENTER_SUSPEND;
-       struct agent_appcore *ac = data;
-
-       if (ac && !ac->allowed_bg && !ac->suspended_state) {
-               _DBG("[__SUSPEND__]");
-               __sys_do(ac, &suspend, SE_SUSPENDED_STATE);
-               ac->suspended_state = true;
-       }
-}
-/* LCOV_EXCL_STOP */
-
-/* LCOV_EXCL_START */
-static void __exit_from_suspend(void *data)
-{
-       if (TIZEN_FEATURE_BACKGROUND_MANAGEMENT) {
-               int suspend = APPCORE_AGENT_SUSPENDED_STATE_DID_EXIT_FROM_SUSPEND;
-               struct agent_appcore *ac = data;
-
-               if (ac && !ac->allowed_bg && ac->suspended_state) {
-                       _DBG("[__SUSPEND__]");
-                       __sys_do(ac, &suspend, SE_SUSPENDED_STATE);
-                       ac->suspended_state = false;
-               }
-       }
-}
-/* LCOV_EXCL_START */
-
-/* LCOV_EXCL_START */
-static gboolean __flush_memory(gpointer data)
-{
-       struct agent_appcore *ac = (struct agent_appcore *)data;
-
-       appcore_agent_flush_memory();
-
-       if (!ac) {
-               return FALSE;
-       }
-       ac->tid = 0;
-
-       _DBG("[__SUSPEND__] flush case");
-       __prepare_to_suspend(ac);
-       return FALSE;
-}
-/* LCOV_EXCL_STOP */
-
-/* LCOV_EXCL_START */
-static void __add_suspend_timer(struct agent_appcore *ac)
-{
-       if (TIZEN_FEATURE_BACKGROUND_MANAGEMENT)
-               ac->tid = g_timeout_add_seconds(5, __flush_memory, ac);
-}
-/* LCOV_EXCL_STOP */
-
-/* LCOV_EXCL_START */
-static void __remove_suspend_timer(struct agent_appcore *ac)
-{
-       if (TIZEN_FEATURE_BACKGROUND_MANAGEMENT && ac->tid > 0) {
-               g_source_remove(ac->tid);
-               ac->tid = 0;
-       }
-}
-/* LCOV_EXCL_STOP */
-
-static void __exit_loop(void *data)
-{
-       ecore_main_loop_quit();
-       __remove_suspend_timer(&core);
-}
-
-static void __do_app(enum agent_event event, void *data, bundle * b)
-{
-       struct agent_priv *svc = data;
-       app_control_h app_control = NULL;
-
-       _ret_if(svc == NULL);
-
-       if (event == AGE_TERMINATE) {
-               svc->state = AGS_DYING;
-               ecore_main_loop_thread_safe_call_sync((Ecore_Data_Cb)__exit_loop, NULL);
-               return;
-       }
-
-       _ret_if(svc->ops == NULL);
-
-       if (app_control_create_event(b, &app_control) != 0)
-               return;
-
-       switch (event) {
-       case AGE_REQUEST:
-               if (svc->ops->app_control)
-                       svc->ops->app_control(app_control, svc->ops->data);
-               svc->state = AGS_RUNNING;
-               break;
-/*     case AGE_STOP:
-               if(svc->state == AGS_RUNNING) {
-                       if (svc->ops->stop)
-                               svc->ops->stop(svc->ops->data);
-                       svc->state = AGS_STOPED;
-               }
-               break;
-*/     default:
-               /* do nothing */
-               break;
-       }
-       app_control_destroy(app_control);
-}
-
-static struct agent_ops s_ops = {
-       .data = &priv,
-       .cb_app = __do_app,
-};
-
-static int __set_data(struct agent_priv *agent, struct agentcore_ops *ops)
-{
-       if (ops == NULL) {
-               errno = EINVAL;
-               return -1;
-       }
-
-       agent->ops = ops;
-       agent->app_core = NULL;
-
-       _pid = getpid();
-
-       return 0;
-}
-
-static int __agent_request(void *data, bundle * k)
-{
-       struct agent_appcore *ac = data;
-       _retv_if(ac == NULL || ac->ops == NULL, -1);
-       _retv_if(ac->ops->cb_app == NULL, 0);
-
-       ac->ops->cb_app(AGE_REQUEST, ac->ops->data, k);
-
-       return 0;
-}
-
-/* LCOV_EXCL_START */
-static int __agent_terminate(void *data)
-{
-       struct agent_appcore *ac = data;
-
-       _retv_if(ac == NULL || ac->ops == NULL, -1);
-       _retv_if(ac->ops->cb_app == NULL, 0);
-
-       ac->ops->cb_app(AGE_TERMINATE, ac->ops->data, NULL);
-
-       return 0;
-}
-/* LCOV_EXCL_STOP */
-
-static int __sys_do_default(struct agent_appcore *ac, enum sys_event event)
-{
-       int r;
-
-       switch (event) {
-       case SE_LOWBAT:
-               /*r = __def_lowbatt(ac);*/
-               r = 0;
-               break;
-       default:
-               r = 0;
-               break;
-       };
-
-       return r;
-}
-
-static int __sys_do(struct agent_appcore *ac, void *event_info, enum sys_event event)
-{
-       struct sys_op *op;
-
-       _retv_if(ac == NULL || event >= SE_MAX, -1);
-
-       op = &ac->sops[event];
-
-       if (op->func == NULL)
-               return __sys_do_default(ac, event);
-
-       return op->func(event_info, op->data);
-}
-
-static int __sys_lowmem_post(void *data, void *evt)
-{
-#if defined(MEMORY_FLUSH_ACTIVATE)
-       struct agent_appcore *ac = data;
-       ac->ops->cb_app(AE_LOWMEM_POST, ac->ops->data, NULL);
-#else
-       malloc_trim(0);
-#endif
-       return 0;
-}
-
-static int __sys_lowmem(void *data, void *evt)
-{
-       keynode_t *key = evt;
-       int val;
-
-       val = vconf_keynode_get_int(key);
-
-       if (val >= VCONFKEY_SYSMAN_LOW_MEMORY_SOFT_WARNING)
-               return __sys_do(data, (void *)&val, SE_LOWMEM);
-
-       return 0;
-}
-
-static int __sys_lowbatt(void *data, void *evt)
-{
-       keynode_t *key = evt;
-       int val;
-
-       val = vconf_keynode_get_int(key);
-
-       /* VCONFKEY_SYSMAN_BAT_CRITICAL_LOW or VCONFKEY_SYSMAN_POWER_OFF */
-       if (val <= VCONFKEY_SYSMAN_BAT_CRITICAL_LOW)
-               return __sys_do(data, (void *)&val, SE_LOWBAT);
-
-       return 0;
-}
-
-static int __sys_langchg_pre(void *data, void *evt)
-{
-       keynode_t *key = evt;
-       char language[32];
-       char *lang;
-       char *r;
-
-       lang = vconf_keynode_get_str(key);
-       if (lang) {
-               snprintf(language, sizeof(language), "%s:en_US:en_GB:en", lang);
-               setenv("LANGUAGE", language, 1);
-               setenv("LANG", lang, 1);
-               setenv("LC_MESSAGES", lang, 1);
-
-               r = setlocale(LC_ALL, lang);
-               if (r == NULL) {
-                       r = setlocale(LC_ALL, lang);
-                       if (r)
-                               _DBG("*****appcore-agent setlocale=%s\n", r);
-               }
-       }
-
-       return 0;
-}
-
-static int __sys_langchg(void *data, void *evt)
-{
-       keynode_t *key = evt;
-       char *val;
-
-       val = vconf_keynode_get_str(key);
-
-       return __sys_do(data, (void *)val, SE_LANGCHG);
-}
-
-static int __sys_regionchg_pre(void *data, void *evt)
-{
-       keynode_t *key = evt;
-       char *region;
-       char *r;
-
-       region = vconf_keynode_get_str(key);
-       if (region) {
-               setenv("LC_CTYPE", region, 1);
-               setenv("LC_NUMERIC", region, 1);
-               setenv("LC_TIME", region, 1);
-               setenv("LC_COLLATE", region, 1);
-               setenv("LC_MONETARY", region, 1);
-               setenv("LC_PAPER", region, 1);
-               setenv("LC_NAME", region, 1);
-               setenv("LC_ADDRESS", region, 1);
-               setenv("LC_TELEPHONE", region, 1);
-               setenv("LC_MEASUREMENT", region, 1);
-               setenv("LC_IDENTIFICATION", region, 1);
-
-               r = setlocale(LC_ALL, "");
-               if (r != NULL)
-                       _DBG("*****appcore-agent setlocale=%s\n", r);
-       }
-
-       return 0;
-}
-
-static int __sys_regionchg(void *data, void *evt)
-{
-       keynode_t *key = evt;
-       char *val = NULL;
-       const char *name;
-
-       name = vconf_keynode_get_name(key);
-       if (!strcmp(name, VCONFKEY_REGIONFORMAT))
-               val = vconf_keynode_get_str(key);
-
-       return __sys_do(data, (void *)val, SE_REGIONCHG);
-}
-
-static void __vconf_do(struct evt_ops *eo, keynode_t * key, void *data)
-{
-       _ret_if(eo == NULL);
-
-       if (eo->vcb_pre)
-               eo->vcb_pre(data, key);
-
-       if (eo->vcb)
-               eo->vcb(data, key);
-
-       if (eo->vcb_post)
-               eo->vcb_post(data, key);
-}
-
-static void __vconf_cb(keynode_t *key, void *data)
-{
-       int i;
-       const char *name;
-
-       name = vconf_keynode_get_name(key);
-       _ret_if(name == NULL);
-
-       SECURE_LOGD("[APP %d] vconf changed: %s", _pid, name);
-
-       for (i = 0; i < sizeof(evtops) / sizeof(evtops[0]); i++) {
-               struct evt_ops *eo = &evtops[i];
-
-               switch (eo->type) {
-               case _CB_VCONF:
-                       if (!strcmp(name, eo->key.vkey))
-                               __vconf_do(eo, key, data);
-                       break;
-               default:
-                       /* do nothing */
-                       break;
-               }
-       }
-}
-
-static int __add_vconf(struct agent_appcore *ac, enum sys_event se)
-{
-       int r;
-
-       switch (se) {
-       case SE_LOWMEM:
-               r = vconf_notify_key_changed(VCONFKEY_SYSMAN_LOW_MEMORY, __vconf_cb, ac);
-               break;
-       case SE_LOWBAT:
-               r = vconf_notify_key_changed(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, __vconf_cb, ac);
-               break;
-       case SE_LANGCHG:
-               r = vconf_notify_key_changed(VCONFKEY_LANGSET, __vconf_cb, ac);
-               break;
-       case SE_REGIONCHG:
-               r = vconf_notify_key_changed(VCONFKEY_REGIONFORMAT, __vconf_cb, ac);
-               if (r < 0)
-                       break;
-
-               r = vconf_notify_key_changed(VCONFKEY_REGIONFORMAT_TIME1224, __vconf_cb, ac);
-               break;
-       default:
-               r = -1;
-               break;
-       }
-
-       return r;
-}
-
-static int __del_vconf(enum sys_event se)
-{
-       int r;
-
-       switch (se) {
-       case SE_LOWMEM:
-               r = vconf_ignore_key_changed(VCONFKEY_SYSMAN_LOW_MEMORY, __vconf_cb);
-               break;
-       case SE_LOWBAT:
-               r = vconf_ignore_key_changed(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, __vconf_cb);
-               break;
-       case SE_LANGCHG:
-               r = vconf_ignore_key_changed(VCONFKEY_LANGSET, __vconf_cb);
-               break;
-       case SE_REGIONCHG:
-               r = vconf_ignore_key_changed(VCONFKEY_REGIONFORMAT, __vconf_cb);
-               if (r < 0)
-                       break;
-
-               r = vconf_ignore_key_changed(VCONFKEY_REGIONFORMAT_TIME1224, __vconf_cb);
-               break;
-       default:
-               r = -1;
-               break;
-       }
-
-       return r;
-}
-
-static int __del_vconf_list(void)
-{
-       int r;
-       enum sys_event se;
-
-       for (se = SE_LOWMEM; se < SE_MAX; se++) {
-               if (appcore_agent_event_initialized[se]) {
-                       r = __del_vconf(se);
-                       if (r < 0)
-                               _ERR("Delete vconf callback failed");
-                       else
-                               appcore_agent_event_initialized[se] = 0;
-               }
-       }
-
-       return 0;
-}
-
-static int __aul_handler(aul_type type, bundle *b, void *data)
-{
-       int ret = 0;
-       char *bg = NULL;
-       struct agent_appcore *ac = data;
-
-       switch (type) {
-       case AUL_START:
-               bundle_get_str(b, AUL_K_ALLOWED_BG, &bg);
-               if (bg && strncmp(bg, "ALLOWED_BG", strlen("ALLOWED_BG")) == 0) {
-                       _DBG("[__SUSPEND__] allowed background");
-                       ac->allowed_bg = true;
-                       __remove_suspend_timer(data);
-               }
-               ret = __agent_request(data, b);
-               break;
-       case AUL_RESUME:
-               bundle_get_str(b, AUL_K_ALLOWED_BG, &bg);
-               if (bg && strncmp(bg, "ALLOWED_BG", strlen("ALLOWED_BG")) == 0) {
-                       _DBG("[__SUSPEND__] allowed background");
-                       ac->allowed_bg = true;
-                       __remove_suspend_timer(data);
-               }
-               break;
-/*     case AUL_STOP:
-               __service_stop(data);
-               break;
-*/
-       case AUL_TERMINATE:
-       case AUL_TERMINATE_BGAPP:
-               if (!ac->allowed_bg) {
-                       __remove_suspend_timer(data);
-               }
-               ret = __agent_terminate(data);
-               break;
-       case AUL_SUSPEND:
-               ac->allowed_bg = false;
-               _DBG("[__SUSPEND__] suspend");
-               __add_suspend_timer(data);
-               break;
-       case AUL_WAKE:
-               if (!ac->allowed_bg) {
-                       _DBG("[__SUSPEND__] wake");
-                       __remove_suspend_timer(data);
-                       __exit_from_suspend(data);
-               }
-
-               if (b) {
-                       bundle_get_str(b, AUL_K_ALLOWED_BG, &bg);
-                       if (bg && strcmp(bg, "ALLOWED_BG") == 0) {
-                               _DBG("[__SUSPEND__] allowed background");
-                               ac->allowed_bg = true;
-                       }
-               }
-               break;
-       default:
-               /* do nothing */
-               break;
-       }
-
-       return ret;
-}
-
-static int __get_package_app_name(int pid, char **app_name)
-{
-       char *name_token = NULL;
-       char appid[APPID_MAX] = {0};
-       int r;
-
-       r = aul_app_get_appid_bypid(pid, appid, APPID_MAX);
-       if (r != AUL_R_OK)
-               return -1;
-
-       if (appid[0] == '\0')
-               return -1;
-
-       name_token = strrchr(appid, '.');
-       if (name_token == NULL)
-               return -1;
-
-       name_token++;
-
-       *app_name = strdup(name_token);
-       if (*app_name == NULL)
-               return -1;
-
-       return 0;
-}
-
-EXPORT_API int appcore_agent_set_event_callback(enum appcore_agent_event event,
-                                         int (*cb) (void *, void *), void *data)
-{
-       struct agent_appcore *ac = &core;
-       struct sys_op *op;
-       enum sys_event se;
-       int r = 0;
-
-       for (se = SE_UNKNOWN; se < SE_MAX; se++) {
-               if (event == to_ae[se])
-                       break;
-       }
-
-       if (se == SE_UNKNOWN || se >= SE_MAX) {
-               _ERR("Unregistered event");
-               errno = EINVAL;
-               return -1;
-       }
-
-       op = &ac->sops[se];
-
-       op->func = cb;
-       op->data = data;
-
-       if (op->func && !appcore_agent_event_initialized[se]) {
-               r = __add_vconf(ac, se);
-               if (r < 0)
-                       _ERR("Add vconf callback failed");
-               else
-                       appcore_agent_event_initialized[se] = 1;
-       } else if (!op->func && appcore_agent_event_initialized[se]) {
-               r = __del_vconf(se);
-               if (r < 0)
-                       _ERR("Delete vconf callback failed");
-               else
-                       appcore_agent_event_initialized[se] = 0;
-       }
-
-       return r;
-}
-
-static gboolean __init_suspend(gpointer data)
-{
-       int r;
-
-       r = _appcore_agent_init_suspend_dbus_handler(&core);
-       if (r == -1)
-               _ERR("Initailzing suspended state handler failed");
-
-       return FALSE;
-}
-
-static int __get_locale_resource_dir(char *locale_dir, int size)
-{
-       const char *res_path;
-
-       res_path = aul_get_app_resource_path();
-       if (res_path == NULL) {
-               _ERR("Failed to get resource path");
-               return -1;
-       }
-
-       snprintf(locale_dir, size, "%s" PATH_LOCALE, res_path);
-       if (access(locale_dir, R_OK) != 0)
-               return -1;
-
-       return 0;
-}
-
-EXPORT_API int appcore_agent_init(const struct agent_ops *ops,
-                           int argc, char **argv)
-{
-       int r;
-       char locale_dir[PATH_MAX];
-       char *app_name = NULL;
-
-       if (core.state != 0) {
-               errno = EALREADY;
-               return -1;
-       }
-
-       if (ops == NULL || ops->cb_app == NULL) {
-               errno = EINVAL;
-               return -1;
-       }
-
-       r = __get_package_app_name(getpid(), &app_name);
-       if (r < 0)
-               return -1;
-
-       r = __get_locale_resource_dir(locale_dir, sizeof(locale_dir));
-       SECURE_LOGD("dir : %s", locale_dir);
-       SECURE_LOGD("app name : %s", app_name);
-       r = appcore_set_i18n(app_name, locale_dir);
-       free(app_name);
-       _retv_if(r == -1, -1);
-
-       if (TIZEN_FEATURE_BACKGROUND_MANAGEMENT)
-               g_idle_add(__init_suspend, NULL);
-
-       r = aul_launch_init(__aul_handler, &core);
-       if (r < 0)
-               goto err;
-
-       r = aul_launch_argv_handler(argc, argv);
-       if (r < 0)
-               goto err;
-
-       core.ops = ops;
-       core.state = 1;         /* TODO: use enum value */
-       core.tid = 0;
-       core.suspended_state = false;
-       core.allowed_bg = false;
-
-       return 0;
- err:
-       __del_vconf_list();
-       return -1;
-}
-
-static void appcore_agent_get_app_core(struct agent_appcore **ac)
-{
-       *ac = &core;
-}
-
-static int __before_loop(struct agent_priv *agent, int argc, char **argv)
-{
-       int r;
-       struct agent_appcore *ac = NULL;
-
-       if (argc <= 0 || argv == NULL) {
-               errno = EINVAL;
-               return -1;
-       }
-
-       if (!ecore_init()) {
-               LOGE("Failed to initialize ecore");
-               return -1;
-       }
-
-       r = appcore_agent_init(&s_ops, argc, argv);
-       if (r < 0) {
-               ecore_shutdown();
-               return -1;
-       }
-
-       appcore_agent_get_app_core(&ac);
-       agent->app_core = ac;
-       SECURE_LOGD("[__SUSPEND__] agent appcore initialized, appcore addr: 0x%x", ac);
-
-       if (agent->ops && agent->ops->create) {
-               r = agent->ops->create(agent->ops->data);
-               if (r < 0) {
-                       if (agent->ops && agent->ops->terminate)
-                               agent->ops->terminate(agent->ops->data);
-                       ecore_shutdown();
-                       errno = ECANCELED;
-                       return -1;
-               }
-       }
-       agent->state = AGS_CREATED;
-
-       return 0;
-}
-
-static void __after_loop(struct agent_priv *agent)
-{
-       __del_vconf_list();
-       priv.state = AGS_DYING;
-       if (agent->ops && agent->ops->terminate)
-               agent->ops->terminate(agent->ops->data);
-       ecore_shutdown();
-}
-
-EXPORT_API int appcore_agent_terminate()
-{
-       __del_vconf_list();
-       ecore_main_loop_thread_safe_call_sync((Ecore_Data_Cb)__exit_loop, NULL);
-
-       return 0;
-}
-
-EXPORT_API int appcore_agent_terminate_without_restart()
-{
-       __del_vconf_list();
-       aul_status_update(STATUS_NORESTART);
-       ecore_main_loop_thread_safe_call_sync((Ecore_Data_Cb)__exit_loop, NULL);
-
-       return 0;
-}
-
-EXPORT_API int appcore_agent_main(int argc, char **argv,
-                               struct agentcore_ops *ops)
-{
-       int r;
-
-       r = __set_data(&priv, ops);
-       _retv_if(r == -1, -1);
-
-       r = __before_loop(&priv, argc, argv);
-       if (r == -1)
-               return -1;
-
-       ecore_main_loop_begin();
-
-       aul_status_update(STATUS_DYING);
-
-       __after_loop(&priv);
-
-       return 0;
-}
-
-/* LCOV_EXCL_START */
-static void __suspend_dbus_signal_handler(GDBusConnection *connection,
-                                       const gchar *sender_name,
-                                       const gchar *object_path,
-                                       const gchar *interface_name,
-                                       const gchar *signal_name,
-                                       GVariant *parameters,
-                                       gpointer user_data)
-{
-       struct agent_appcore *ac = (struct agent_appcore *)user_data;
-       gint suspend = APPCORE_SUSPENDED_STATE_DID_EXIT_FROM_SUSPEND;
-       gint pid;
-       gint status;
-
-       if (g_strcmp0(signal_name, RESOURCED_FREEZER_SIGNAL) == 0) {
-               g_variant_get(parameters, "(ii)", &status, &pid);
-               if (pid == getpid() && status == 0) { /* thawed */
-                       if (ac && !ac->allowed_bg && ac->suspended_state) {
-                               __remove_suspend_timer(ac);
-                               __sys_do(ac, &suspend, SE_SUSPENDED_STATE);
-                               ac->suspended_state = false;
-                               __add_suspend_timer(ac);
-                       }
-               }
-       }
-}
-/* LCOV_EXCL_STOP */
-
-int _appcore_agent_init_suspend_dbus_handler(void *data)
-{
-       GError *err = NULL;
-
-       if (__suspend_dbus_handler_initialized)
-               return 0;
-
-       if (!bus) {
-               bus = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err);
-               if (!bus) {
-                       _ERR("Failed to connect to the D-BUS daemon: %s",
-                                               err->message);
-                       g_error_free(err);
-                       return -1;
-               }
-       }
-
-       __suspend_dbus_handler_initialized = g_dbus_connection_signal_subscribe(
-                                               bus,
-                                               NULL,
-                                               RESOURCED_FREEZER_INTERFACE,
-                                               RESOURCED_FREEZER_SIGNAL,
-                                               RESOURCED_FREEZER_PATH,
-                                               NULL,
-                                               G_DBUS_SIGNAL_FLAGS_NONE,
-                                               __suspend_dbus_signal_handler,
-                                               data,
-                                               NULL);
-       if (__suspend_dbus_handler_initialized == 0) {
-               _ERR("g_dbus_connection_signal_subscribe() is failed.");
-               return -1;
-       }
-
-       _DBG("[__SUSPEND__] suspend signal initialized");
-
-       return 0;
-}
diff --git a/src/service_app_error.c b/src/service_app_error.c
deleted file mode 100644 (file)
index 814808c..0000000
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an AS IS BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-#include <string.h>
-#include <libintl.h>
-
-#include <dlog.h>
-#include <app_common.h>
-
-#include "service_app_private.h"
-
-#ifdef LOG_TAG
-#undef LOG_TAG
-#endif
-
-#define LOG_TAG "CAPI_APPFW_APPLICATION"
-
-static const char* service_app_error_to_string(app_error_e error)
-{
-       switch (error) {
-       case APP_ERROR_NONE:
-               return "NONE";
-       case APP_ERROR_INVALID_PARAMETER:
-               return "INVALID_PARAMETER";
-       case APP_ERROR_OUT_OF_MEMORY:
-               return "OUT_OF_MEMORY";
-       case APP_ERROR_INVALID_CONTEXT:
-               return "INVALID_CONTEXT";
-       case APP_ERROR_NO_SUCH_FILE:
-               return "NO_SUCH_FILE";
-       case APP_ERROR_ALREADY_RUNNING:
-               return "ALREADY_RUNNING";
-       default:
-               return "UNKNOWN";
-       }
-}
-
-int service_app_error(app_error_e error, const char* function, const char *description)
-{
-       if (description)
-               LOGE("[%s] %s(0x%08x) : %s", function, service_app_error_to_string(error), error, description);
-       else
-               LOGE("[%s] %s(0x%08x)", function, service_app_error_to_string(error), error);
-
-       return error;
-}
index de9c8f1..894fd03 100644 (file)
@@ -14,7 +14,6 @@
  * limitations under the License.
  */
 
-
 #include <stdlib.h>
 #include <unistd.h>
 #include <bundle.h>
 #include <dlog.h>
 #include <vconf-internal-keys.h>
 #include <app_common.h>
-#include <Eina.h>
-#include <appcore-agent.h>
+#include <Ecore.h>
+#include <appcore_base.h>
+#include <service_app.h>
 
-#include "service_app_private.h"
 #include "service_app_extension.h"
 
 #ifdef LOG_TAG
 #undef LOG_TAG
 #endif
 
-#ifndef TIZEN_PATH_MAX
-#define TIZEN_PATH_MAX 1024
-#endif
-
 #define LOG_TAG "CAPI_APPFW_APPLICATION"
 
-typedef enum {
-       SERVICE_APP_STATE_NOT_RUNNING, /* The application has been launched or was running but was terminated */
-       SERVICE_APP_STATE_CREATING, /* The application is initializing the resources on service_app_create_cb callback */
-       SERVICE_APP_STATE_RUNNING, /* The application is running in the foreground and background */
-} service_app_state_e;
-
-static int _service_app_get_id(char **id)
-{
-       static char id_buf[TIZEN_PATH_MAX] = {0, };
-       int ret = -1;
-
-       if (id == NULL)
-               return service_app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
-
-       if (id_buf[0] == '\0') {
-               ret = aul_app_get_appid_bypid(getpid(), id_buf, sizeof(id_buf));
-               if (ret < 0)
-                       return service_app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "failed to get the application ID");
-       }
-
-       if (id_buf[0] == '\0')
-               return service_app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "failed to get the application ID");
-
-       *id = strdup(id_buf);
-       if (*id == NULL)
-               return service_app_error(APP_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL);
-
-       return APP_ERROR_NONE;
-}
-
-static int _service_appget_package_app_name(const char *appid, char **name)
-{
-       char *name_token = NULL;
-
-       if (appid == NULL)
-               return service_app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
-
-       /* com.vendor.name -> name */
-       name_token = strrchr(appid, '.');
-       if (name_token == NULL)
-               return service_app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, NULL);
-
-       name_token++;
-
-       *name = strdup(name_token);
-       if (*name == NULL)
-               return service_app_error(APP_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL);
-
-       return APP_ERROR_NONE;
-}
+extern int app_control_create_event(bundle *data, struct app_control_s **app_control);
 
-EXPORT_API void service_app_exit_without_restart(void)
-{
-       appcore_agent_terminate_without_restart();
-}
-
-#define SERVICE_APP_EVENT_MAX 6
-static Eina_List *handler_list[SERVICE_APP_EVENT_MAX] = {NULL, };
-static int handler_initialized = 0;
-static int appcore_agent_initialized = 0;
+typedef enum {
+       APP_STATE_NOT_RUNNING,
+       APP_STATE_CREATING,
+       APP_STATE_RUNNING,
+} app_state_e;
 
 struct app_event_handler {
        app_event_type_e type;
        app_event_cb cb;
        void *data;
+       void* raw;
 };
 
 struct app_event_info {
@@ -111,335 +54,177 @@ struct app_event_info {
 };
 
 struct service_app_context {
-       char *package;
-       char *service_app_name;
-       service_app_state_e state;
-       service_app_lifecycle_callback_s *callback;
+       service_app_lifecycle_callback_s callback;
        void *data;
 };
 
-static void _free_handler_list(void)
-{
-       int i;
-       app_event_handler_h handler;
+static struct service_app_context __context;
+static app_state_e __app_state = APP_STATE_NOT_RUNNING;
 
-       for (i = 0; i < SERVICE_APP_EVENT_MAX; i++) {
-               EINA_LIST_FREE(handler_list[i], handler)
-               if (handler)
-                       free(handler);
-       }
+static int __app_event_converter[APPCORE_BASE_EVENT_MAX] = {
+       [APP_EVENT_LOW_MEMORY] = APPCORE_BASE_EVENT_LOW_MEMORY,
+       [APP_EVENT_LOW_BATTERY] = APPCORE_BASE_EVENT_LOW_BATTERY,
+       [APP_EVENT_LANGUAGE_CHANGED] = APPCORE_BASE_EVENT_LANG_CHANGE,
+       [APP_EVENT_DEVICE_ORIENTATION_CHANGED] = APPCORE_BASE_EVENT_DEVICE_ORIENTATION_CHANGED,
+       [APP_EVENT_REGION_FORMAT_CHANGED] = APPCORE_BASE_EVENT_REGION_CHANGE,
+       [APP_EVENT_SUSPENDED_STATE_CHANGED] = APPCORE_BASE_EVENT_SUSPENDED_STATE_CHANGE,
+};
 
-       eina_shutdown();
-}
+static int __on_error(app_error_e error, const char *function, const char *description);
 
-static int _service_app_low_memory(void *event_info, void *data)
+static int __service_app_create(void *data)
 {
-       Eina_List *l;
-       app_event_handler_h handler;
-       struct app_event_info event;
-
-       LOGI("service_app_low_memory");
-
-       event.type = APP_EVENT_LOW_MEMORY;
-       event.value = event_info;
-
-       EINA_LIST_FOREACH(handler_list[APP_EVENT_LOW_MEMORY], l, handler) {
-               handler->cb(&event, handler->data);
-       }
+       appcore_base_on_create();
+       ecore_init();
+       if (__context.callback.create == NULL ||
+                       __context.callback.create(__context.data) == false)
+               return __on_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "service_app_create_cb() returns false"); 
 
        return APP_ERROR_NONE;
 }
 
-static int _service_app_low_battery(void *event_info, void *data)
+static int __service_app_terminate(void *data)
 {
-       Eina_List *l;
-       app_event_handler_h handler;
-       struct app_event_info event;
-
-       LOGI("service_app_low_battery");
+       appcore_base_on_terminate();
 
-       event.type = APP_EVENT_LOW_BATTERY;
-       event.value = event_info;
-
-       EINA_LIST_FOREACH(handler_list[APP_EVENT_LOW_BATTERY], l, handler) {
-               handler->cb(&event, handler->data);
-       }
+       if (__context.callback.terminate)
+               __context.callback.terminate(__context.data);
 
        return APP_ERROR_NONE;
 }
 
-static int _service_app_lang_changed(void *event_info, void *data)
+static int __service_app_control(bundle *b, void *data)
 {
-       Eina_List *l;
-       app_event_handler_h handler;
-       struct app_event_info event;
+       app_control_h app_control = NULL;
 
-       LOGI("service_app_lang_changed");
+       LOGD("[SERVICE_APP] app_control callback");
+       appcore_base_on_control(b);
 
-       event.type = APP_EVENT_LANGUAGE_CHANGED;
-       event.value = event_info;
+       if (app_control_create_event(b, &app_control) != 0)
+               return -1;
 
-       EINA_LIST_FOREACH(handler_list[APP_EVENT_LANGUAGE_CHANGED], l, handler) {
-               handler->cb(&event, handler->data);
-       }
+       if (__context.callback.app_control)
+               __context.callback.app_control(app_control, __context.data);
 
-       return APP_ERROR_NONE;
-}
-
-static int _service_app_region_changed(void *event_info, void *data)
-{
-       Eina_List *l;
-       app_event_handler_h handler;
-       struct app_event_info event;
-
-       if (event_info == NULL) {
-               LOGI("receive empy event, ignore it");
-               return APP_ERROR_NONE;
-       }
-
-       LOGI("service_app_region_changed");
+       app_control_destroy(app_control);
 
-       event.type = APP_EVENT_REGION_FORMAT_CHANGED;
-       event.value = event_info;
-
-       EINA_LIST_FOREACH(handler_list[APP_EVENT_REGION_FORMAT_CHANGED], l, handler) {
-               handler->cb(&event, handler->data);
-       }
-
-       return APP_ERROR_NONE;
+       return 0;
 }
 
-/* LCOV_EXCL_START */
-static int _service_app_appcore_suspended_state_changed(void *event_info, void *data)
+static void __loop_run(void *data)
 {
-       Eina_List *l;
-       app_event_handler_h handler;
-       struct app_event_info event;
-
-       LOGI("_service_app_appcore_suspended_state_changed");
-       LOGD("[__SUSPEND__] suspended state: %d (0: suspend, 1: wake)", *(int *)event_info);
-
-       event.type = APP_EVENT_SUSPENDED_STATE_CHANGED;
-       event.value = event_info;
-
-       EINA_LIST_FOREACH(handler_list[APP_EVENT_SUSPENDED_STATE_CHANGED], l, handler) {
-               handler->cb(&event, handler->data);
-       }
-
-       return APP_ERROR_NONE;
+       ecore_main_loop_begin();
 }
-/* LCOV_EXCL_STOP */
 
-static void _service_app_appcore_agent_set_event_cb(app_event_type_e event_type)
+static void __loop_exit(void *data)
 {
-       switch (event_type) {
-       case APP_EVENT_LOW_MEMORY:
-               appcore_agent_set_event_callback(APPCORE_AGENT_EVENT_LOW_MEMORY, _service_app_low_memory, NULL);
-               break;
-       case APP_EVENT_LOW_BATTERY:
-               appcore_agent_set_event_callback(APPCORE_AGENT_EVENT_LOW_BATTERY, _service_app_low_battery, NULL);
-               break;
-       case APP_EVENT_LANGUAGE_CHANGED:
-               appcore_agent_set_event_callback(APPCORE_AGENT_EVENT_LANG_CHANGE, _service_app_lang_changed, NULL);
-               break;
-       case APP_EVENT_REGION_FORMAT_CHANGED:
-               appcore_agent_set_event_callback(APPCORE_AGENT_EVENT_REGION_CHANGE, _service_app_region_changed, NULL);
-               break;
-       case APP_EVENT_SUSPENDED_STATE_CHANGED:
-               LOGD("[__SUSPEND__]");
-               appcore_agent_set_event_callback(APPCORE_AGENT_EVENT_SUSPENDED_STATE_CHANGE, _service_app_appcore_suspended_state_changed, NULL);
-               break;
-       default:
-               break;
-       }
+       ecore_main_loop_quit();
 }
 
-static void _service_app_appcore_agent_unset_event_cb(app_event_type_e event_type)
+static const char *__error_to_string(app_error_e error)
 {
-       switch (event_type) {
-       case APP_EVENT_LOW_MEMORY:
-               appcore_agent_set_event_callback(APPCORE_AGENT_EVENT_LOW_MEMORY, NULL, NULL);
-               break;
-       case APP_EVENT_LOW_BATTERY:
-               appcore_agent_set_event_callback(APPCORE_AGENT_EVENT_LOW_BATTERY, NULL, NULL);
-               break;
-       case APP_EVENT_LANGUAGE_CHANGED:
-               appcore_agent_set_event_callback(APPCORE_AGENT_EVENT_LANG_CHANGE, NULL, NULL);
-               break;
-       case APP_EVENT_REGION_FORMAT_CHANGED:
-               appcore_agent_set_event_callback(APPCORE_AGENT_EVENT_REGION_CHANGE, NULL, NULL);
-               break;
-       case APP_EVENT_SUSPENDED_STATE_CHANGED:
-               LOGD("[__SUSPEND__]");
-               appcore_agent_set_event_callback(APPCORE_AGENT_EVENT_SUSPENDED_STATE_CHANGE, NULL, NULL);
-               break;
+       switch (error) {
+       case APP_ERROR_NONE:
+               return "NONE";
+       case APP_ERROR_INVALID_PARAMETER:
+               return "INVALID_PARAMETER";
+       case APP_ERROR_OUT_OF_MEMORY:
+               return "OUT_OF_MEMORY";
+       case APP_ERROR_INVALID_CONTEXT:
+               return "INVALID_CONTEXT";
+       case APP_ERROR_NO_SUCH_FILE:
+               return "NO_SUCH_FILE";
+       case APP_ERROR_ALREADY_RUNNING:
+               return "ALREADY_RUNNING";
        default:
-               break;
+               return "UNKNOWN";
        }
 }
 
-static void _service_app_set_appcore_event_cb(void)
+static int __on_error(app_error_e error, const char *function, const char *description)
 {
-       _service_app_appcore_agent_set_event_cb(APP_EVENT_LOW_MEMORY);
-       _service_app_appcore_agent_set_event_cb(APP_EVENT_LANGUAGE_CHANGED);
-       _service_app_appcore_agent_set_event_cb(APP_EVENT_REGION_FORMAT_CHANGED);
+       if (description)
+               LOGE("[%s] %s(0x%08x) : %s", function, __error_to_string(error), error, description);
+       else
+               LOGE("[%s] %s(0x%08x)", function, __error_to_string(error), error);
 
-       if (eina_list_count(handler_list[APP_EVENT_LOW_BATTERY]) > 0)
-               _service_app_appcore_agent_set_event_cb(APP_EVENT_LOW_BATTERY);
-
-       if (eina_list_count(handler_list[APP_EVENT_SUSPENDED_STATE_CHANGED]) > 0)
-               _service_app_appcore_agent_set_event_cb(APP_EVENT_SUSPENDED_STATE_CHANGED);
+       return error;
 }
 
-static void _service_app_unset_appcore_event_cb(void)
-{
-       _service_app_appcore_agent_unset_event_cb(APP_EVENT_LOW_MEMORY);
-       _service_app_appcore_agent_unset_event_cb(APP_EVENT_LANGUAGE_CHANGED);
-       _service_app_appcore_agent_unset_event_cb(APP_EVENT_REGION_FORMAT_CHANGED);
-
-       if (eina_list_count(handler_list[APP_EVENT_LOW_BATTERY]) > 0)
-               _service_app_appcore_agent_unset_event_cb(APP_EVENT_LOW_BATTERY);
-
-       if (eina_list_count(handler_list[APP_EVENT_SUSPENDED_STATE_CHANGED]) > 0)
-               _service_app_appcore_agent_unset_event_cb(APP_EVENT_SUSPENDED_STATE_CHANGED);
-}
-
-static int _service_app_create(void *data)
+EXPORT_API int service_app_main(int argc, char **argv, service_app_lifecycle_callback_s *callback, void *user_data)
 {
-       struct service_app_context *app_context = data;
-       service_app_create_cb create_cb;
-
-       if (app_context == NULL)
-               return service_app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, NULL);
-
-       appcore_agent_initialized = 1;
-       _service_app_set_appcore_event_cb();
+       int ret;
+       appcore_base_ops ops = appcore_base_get_default_ops();
 
-       create_cb = app_context->callback->create;
-       if (create_cb == NULL || create_cb(app_context->data) == false)
-               return service_app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "service_app_create_cb() returns false");
+       if (argc < 1 || argv == NULL || callback == NULL)
+               return __on_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
 
-       app_context->state = SERVICE_APP_STATE_RUNNING;
+       if (callback->create == NULL)
+               return __on_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, "service_app_create_cb() callback must be registered");
+
+       if (__app_state != APP_STATE_NOT_RUNNING)
+               return __on_error(APP_ERROR_ALREADY_RUNNING, __FUNCTION__, NULL);
+
+       /* override methods */
+       ops.create = __service_app_create;
+       ops.terminate = __service_app_terminate;
+       ops.control = __service_app_control;
+       ops.run = __loop_run;
+       ops.exit = __loop_exit;
+
+       __context.callback = *callback;
+       __context.data = user_data;
+
+       __app_state = APP_STATE_CREATING;
+       ret = appcore_base_init(ops, argc, argv, NULL);
+       if (ret < 0) {
+               __app_state = APP_STATE_NOT_RUNNING;
+               return __on_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, NULL);
+       }
 
+       appcore_base_fini();
+       __app_state = APP_STATE_NOT_RUNNING;
        return APP_ERROR_NONE;
 }
 
-static int _service_app_terminate(void *data)
+EXPORT_API void service_app_exit(void)
 {
-       struct service_app_context *app_context = data;
-       service_app_terminate_cb terminate_cb;
-
-       if (app_context == NULL)
-               return service_app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, NULL);
-
-       terminate_cb = app_context->callback->terminate;
-       if (terminate_cb != NULL)
-               terminate_cb(app_context->data);
-
-       _service_app_unset_appcore_event_cb();
-
-       if (handler_initialized)
-               _free_handler_list();
-
-       return APP_ERROR_NONE;
+       __loop_exit(NULL);
 }
 
-static int _service_app_reset(app_control_h app_control, void *data)
+static int __event_cb(void *event, void *data)
 {
-       struct service_app_context *app_context = data;
-       service_app_control_cb service_cb;
+       app_event_handler_h handler = data;
 
-       if (app_context == NULL)
-               return service_app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, NULL);
+       struct app_event_info app_event;
 
-       service_cb = app_context->callback->app_control;
-       if (service_cb != NULL)
-               service_cb(app_control, app_context->data);
+       app_event.type = handler->type;
+       app_event.value = event;
 
-       return APP_ERROR_NONE;
-}
-
-EXPORT_API int service_app_main(int argc, char **argv, service_app_lifecycle_callback_s *callback, void *user_data)
-{
-       struct service_app_context app_context = {
-               .state = SERVICE_APP_STATE_NOT_RUNNING,
-               .callback = callback,
-               .data = user_data
-       };
-
-       struct agentcore_ops appcore_context = {
-               .data = &app_context,
-               .create = _service_app_create,
-               .terminate = _service_app_terminate,
-               .app_control = _service_app_reset,
-       };
-
-       if (argc <= 0 || argv == NULL || callback == NULL)
-               return service_app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
-
-       if (callback->create == NULL)
-               return service_app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, "service_app_create_cb() callback must be registered");
-
-       if (app_context.state != SERVICE_APP_STATE_NOT_RUNNING)
-               return service_app_error(APP_ERROR_ALREADY_RUNNING, __FUNCTION__, NULL);
-
-       if (_service_app_get_id(&(app_context.package)) == APP_ERROR_NONE) {
-               if (_service_appget_package_app_name(app_context.package, &(app_context.service_app_name)) != APP_ERROR_NONE) {
-                       free(app_context.package);
-                       app_context.package = NULL;
-               }
-       }
-
-       app_context.state = SERVICE_APP_STATE_CREATING;
-
-       appcore_agent_main(argc, argv, &appcore_context);
-
-       if (app_context.service_app_name)
-               free(app_context.service_app_name);
-       if (app_context.package)
-               free(app_context.package);
-
-       return APP_ERROR_NONE;
-}
-
-EXPORT_API void service_app_exit(void)
-{
-       appcore_agent_terminate();
+       if (handler->cb)
+               handler->cb(&app_event, handler->data);
+       return 0;
 }
 
 EXPORT_API int service_app_add_event_handler(app_event_handler_h *event_handler, app_event_type_e event_type, app_event_cb callback, void *user_data)
 {
        app_event_handler_h handler;
-       Eina_List *l_itr;
-
-       if (!handler_initialized) {
-               eina_init();
-               handler_initialized = 1;
-       }
 
        if (event_handler == NULL || callback == NULL)
-               return service_app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, "null parameter");
+               return __on_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, "null parameter");
 
-       if (event_type < APP_EVENT_LOW_MEMORY || event_type > APP_EVENT_SUSPENDED_STATE_CHANGED)
-               return service_app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, "invalid event type");
-
-       EINA_LIST_FOREACH(handler_list[event_type], l_itr, handler) {
-               if (handler->cb == callback)
-                       return service_app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, "already registered");
-       }
+       if (event_type < APP_EVENT_LOW_MEMORY || event_type > APP_EVENT_SUSPENDED_STATE_CHANGED ||
+                       event_type == APP_EVENT_DEVICE_ORIENTATION_CHANGED)
+               return __on_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, "invalid event type");
 
        handler = calloc(1, sizeof(struct app_event_handler));
        if (!handler)
-               return service_app_error(APP_ERROR_OUT_OF_MEMORY, __FUNCTION__, "insufficient memory");
+               return __on_error(APP_ERROR_OUT_OF_MEMORY, __FUNCTION__, "insufficient memory");
 
        handler->type = event_type;
        handler->cb = callback;
        handler->data = user_data;
-
-       if (appcore_agent_initialized && eina_list_count(handler_list[event_type]) == 0)
-               _service_app_appcore_agent_set_event_cb(event_type);
-
-       handler_list[event_type] = eina_list_append(handler_list[event_type], handler);
+       handler->raw = appcore_base_add_event(__app_event_converter[event_type], __event_cb, handler);
 
        *event_handler = handler;
 
@@ -448,36 +233,31 @@ EXPORT_API int service_app_add_event_handler(app_event_handler_h *event_handler,
 
 EXPORT_API int service_app_remove_event_handler(app_event_handler_h event_handler)
 {
-       app_event_handler_h handler;
+       int ret;
        app_event_type_e type;
-       Eina_List *l_itr;
-       Eina_List *l_next;
 
        if (event_handler == NULL)
-               return service_app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
-
-       if (!handler_initialized) {
-               LOGI("handler list is not initialzed");
-               return APP_ERROR_NONE;
-       }
+               return __on_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
 
        type = event_handler->type;
-       if (type < APP_EVENT_LOW_MEMORY
-                       || type > APP_EVENT_REGION_FORMAT_CHANGED
-                       || type == APP_EVENT_DEVICE_ORIENTATION_CHANGED)
-               return service_app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
+       if (type < APP_EVENT_LOW_MEMORY ||
+                       type > APP_EVENT_SUSPENDED_STATE_CHANGED ||
+                       type == APP_EVENT_DEVICE_ORIENTATION_CHANGED)
+               return __on_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
 
-       EINA_LIST_FOREACH_SAFE(handler_list[type], l_itr, l_next, handler) {
-               if (handler == event_handler) {
-                       free(handler);
-                       handler_list[type] = eina_list_remove_list(handler_list[type], l_itr);
+       ret = appcore_base_remove_event(event_handler->raw);
+       free(event_handler);
 
-                       if (appcore_agent_initialized && eina_list_count(handler_list[type]) == 0)
-                               _service_app_appcore_agent_unset_event_cb(type);
+       if (ret < 0)
+               return __on_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
 
-                       return APP_ERROR_NONE;
-               }
-       }
+       return APP_ERROR_NONE;
+}
 
-       return service_app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, "cannot find such handler");
+EXPORT_API void service_app_exit_without_restart(void)
+{
+       aul_status_update(STATUS_NORESTART);
+       __loop_exit(NULL);
 }
+
+
diff --git a/src/service_app_private.h b/src/service_app_private.h
deleted file mode 100644 (file)
index ba58ecf..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an AS IS BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-#ifndef __TIZEN_APPFW_SERVICE_APP_PRIVATE_H__
-#define __TIZEN_APPFW_SERVICE_APP_PRIVATE_H__
-
-#include <service_app.h>
-#include <app_common.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-int service_app_error(app_error_e error, const char* function, const char *description);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __TIZEN_APPFW_SERVICE_APP_PRIVATE_H__ */