Refactor APIs using appcore_ui_base 96/112896/10
authorJunghoon Park <jh9216.park@samsung.com>
Fri, 3 Feb 2017 07:21:50 +0000 (16:21 +0900)
committerJunghoon Park <jh9216.park@samsung.com>
Mon, 20 Feb 2017 03:55:16 +0000 (12:55 +0900)
- require :
  https://review.tizen.org/gerrit/#/c/82655/

Change-Id: I949a220dae05ecdc1722b9ede4face915822ca1b
Signed-off-by: Junghoon Park <jh9216.park@samsung.com>
CMakeLists.txt
include/appcore-watch.h
packaging/appcore-watch.spec
src/appcore-watch-i18n.c [deleted file]
src/appcore-watch-internal.h [deleted file]
src/appcore-watch.c [deleted file]
src/watch_app_main.c

index d1a530223f2944d8fd88bef18aadbbdd937a9862..72b96098ba40bc428e87082e5a70cf1005537541 100644 (file)
@@ -38,6 +38,8 @@ pkg_check_modules(pkg_watch REQUIRED
                glib-2.0
                gio-2.0
                screen_connector_provider
+               appcore-common
+               appcore-efl
                )
 FOREACH(flag ${pkg_watch_CFLAGS})
        SET(EXTRA_CFLAGS_watch "${EXTRA_CFLAGS_watch} ${flag}")
index 2b4645b3c881664cf997412bedd5c96d9d13c6a1..badccb2e016136d1f3e9bb8d562e359c0ba92197 100755 (executable)
 #ifndef __APPCORE_WATCH_H__
 #define __APPCORE_WATCH_H__
 
-#include <libintl.h>
-#include <bundle.h>
-
-#include "app_control.h"
-#include "watch_app.h"
-
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-struct watchcore_ops {
-       void *data; /**< Callback data */
-       int (*create) (int w, int h, void *); /**< This callback function is called at the start of the application. */
-       int (*app_control) (app_control_h, void *); /**< This callback function is called when other application send the launch request to the application. */
-       int (*pause) (void *); /**< Called when every window goes back */
-       int (*resume) (void *); /**< Called when any window comes on top */
-       int (*terminate) (void *); /**< This callback function is called once after the main loop of application exits. */
-       void (*time_tick) (void *, void *);
-       void (*ambient_tick) (void *, void *);
-       void (*ambient_changed) (int, void *);
-       void *reserved[6]; /**< Reserved */
-};
-
-enum watch_core_event {
-       WATCH_CORE_EVENT_UNKNOWN, /**< Unknown event */
-       WATCH_CORE_EVENT_LOW_MEMORY, /**< Low memory */
-       WATCH_CORE_EVENT_LOW_BATTERY, /**< Low battery */
-       WATCH_CORE_EVENT_LANG_CHANGE, /**< Language setting is changed */
-       WATCH_CORE_EVENT_REGION_CHANGE, /**< Region setting is changed */
-};
-
-struct watch_time_s {
-       int year;
-       int month;
-       int day_of_week;
-       int day;
-       int hour;
-       int hour24;
-       int minute;
-       int second;
-       int millisecond;
-       time_t timestamp;
-       char *timezone;
-};
-
-int watch_core_main(const char *appid, int argc, char **argv,
-               struct watchcore_ops *ops);
-int watch_core_terminate();
-int watch_core_set_event_callback(enum watch_core_event event,
-               int (*cb) (void *, void *), void *data);
-const char *watch_core_get_appid();
-void watch_core_get_timeinfo(struct watch_time_s *timeinfo);
-bool watch_core_get_24h_mode(void);
-int watch_core_set_ambient_tick_type(watch_app_ambient_tick_type_e type);
-int watch_core_get_ambient_tick_type(watch_app_ambient_tick_type_e *type);
-int watch_core_set_time_tick_frequency(int ticks, watch_app_time_tick_resolution_e type);
-int watch_core_get_time_tick_frequency(int *ticks, watch_app_time_tick_resolution_e *type);
-
-#ifdef __cplusplus
-}
-#endif
-
 #endif /* __APPCORE_WATCH_H__ */
 
index 1fcb6ecaac2b022ff67eb2948bdf470acff1a9bd..b247c5e7282f4a5805dffb888e79f9eb16a6c8b5 100644 (file)
@@ -11,6 +11,8 @@ BuildRequires:  pkgconfig(elementary)
 BuildRequires:  pkgconfig(vconf)
 BuildRequires:  pkgconfig(vconf-internal-keys)
 BuildRequires:  pkgconfig(alarm-service)
+BuildRequires:  pkgconfig(appcore-common)
+BuildRequires:  pkgconfig(appcore-efl)
 BuildRequires:  pkgconfig(capi-appfw-app-control)
 BuildRequires:  pkgconfig(capi-appfw-app-common)
 BuildRequires: pkgconfig(capi-appfw-widget-application)
diff --git a/src/appcore-watch-i18n.c b/src/appcore-watch-i18n.c
deleted file mode 100755 (executable)
index 31846d4..0000000
+++ /dev/null
@@ -1,148 +0,0 @@
-/*
- * Copyright (c) 2015 - 2016 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 <locale.h>
-#include <libintl.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <errno.h>
-#include <unistd.h>
-#include <linux/limits.h>
-
-#include <glib.h>
-#include <aul.h>
-#include <vconf.h>
-
-#include "appcore-watch-log.h"
-#include "appcore-watch-internal.h"
-
-#define PATH_LOCALE "locale"
-
-void _update_lang(void)
-{
-       char language[32];
-       char *r;
-       char *lang = vconf_get_str(VCONFKEY_LANGSET);
-       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, "");
-               if (r == NULL) {
-                       r = setlocale(LC_ALL, lang); /* LCOV_EXCL_LINE */
-                       if (r) /* LCOV_EXCL_LINE */
-                               _D("*****appcore setlocale=%s\n", r); /* LCOV_EXCL_LINE */
-               }
-               free(lang);
-       } else {
-               _E("failed to get current language for set lang env"); /* LCOV_EXCL_LINE */
-       }
-}
-
-void _update_region(void)
-{
-       char *region;
-       char *r;
-
-       region = vconf_get_str(VCONFKEY_REGIONFORMAT);
-       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)
-                       _D("*****appcore setlocale=%s\n", r);
-               free(region);
-       } else {
-               _E("failed to get current region format for set region env"); /* LCOV_EXCL_LINE */
-       }
-}
-
-/* from appcore.c */
-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) {
-               _E("Failed to get resource path"); /* LCOV_EXCL_LINE */
-               return -1; /* LCOV_EXCL_LINE */
-       }
-
-       snprintf(locale_dir, size, "%s" PATH_LOCALE, res_path);
-       if (access(locale_dir, R_OK) != 0)
-               return -1;
-
-       return 0;
-}
-
-static int __set_i18n(const char *domain)
-{
-       char *r;
-       char locale_dir[PATH_MAX];
-       char *lang;
-
-       if (domain == NULL) {
-               errno = EINVAL; /* LCOV_EXCL_LINE */
-               return -1; /* LCOV_EXCL_LINE */
-       }
-
-       __get_locale_resource_dir(locale_dir, sizeof(locale_dir));
-       _D("locale dir: %s", locale_dir);
-
-       r = setlocale(LC_ALL, "");
-       /* if locale is not set properly, try again to set as language base */
-       if (r == NULL) {
-               lang = vconf_get_str(VCONFKEY_LANGSET); /* LCOV_EXCL_LINE */
-               r = setlocale(LC_ALL, lang); /* LCOV_EXCL_LINE */
-               if (r) /* LCOV_EXCL_LINE */
-                       _D("*****appcore setlocale=%s\n", r); /* LCOV_EXCL_LINE */
-               if (lang) /* LCOV_EXCL_LINE */
-                       free(lang); /* LCOV_EXCL_LINE */
-       }
-       if (r == NULL)
-               _E("appcore: setlocale() error"); /* LCOV_EXCL_LINE */
-
-       r = bindtextdomain(domain, locale_dir);
-       if (r == NULL)
-               _E("appcore: bindtextdomain() error"); /* LCOV_EXCL_LINE */
-
-       r = textdomain(domain);
-       if (r == NULL)
-               _E("appcore: textdomain() error"); /* LCOV_EXCL_LINE */
-
-       return 0;
-}
-
-int _set_i18n(const char *domainname)
-{
-       _update_lang();
-       _update_region();
-
-       return __set_i18n(domainname);
-}
-
diff --git a/src/appcore-watch-internal.h b/src/appcore-watch-internal.h
deleted file mode 100644 (file)
index 5034692..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * Copyright (c) 2015 - 2016 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 __APPCORE_WATCH_INTERNAL_H__
-#define __APPCORE_WATCH_INTERNAL_H__
-
-int _set_i18n(const char *domainname);
-void _update_lang(void);
-void _update_region(void);
-
-#endif /* __APPCORE_WATCH_INTERNAL_H__ */
-
diff --git a/src/appcore-watch.c b/src/appcore-watch.c
deleted file mode 100755 (executable)
index cc93811..0000000
+++ /dev/null
@@ -1,1308 +0,0 @@
-/*
- * Copyright (c) 2015 - 2016 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.
- */
-
-#define _GNU_SOURCE
-
-#include <errno.h>
-#include <string.h>
-#include <stdlib.h>
-#include <sys/types.h>
-#include <unistd.h>
-#include <malloc.h>
-#include <assert.h>
-
-#include <bundle_internal.h>
-#include <Elementary.h>
-#include <app_control.h>
-#include <app_control_internal.h>
-#include <aul.h>
-#include <dlog.h>
-#include <vconf.h>
-#include <alarm.h>
-#include <glib-object.h>
-#include <Ecore_Wayland.h>
-#include <widget_app.h>
-#include <screen_connector_provider.h>
-
-#include "appcore-watch.h"
-#include "appcore-watch-log.h"
-#include "appcore-watch-signal.h"
-#include "appcore-watch-internal.h"
-
-#ifdef LOG_TAG
-#undef LOG_TAG
-#endif
-
-#define LOG_TAG "WATCH_CORE"
-
-#include <unicode/utypes.h>
-#include <unicode/putil.h>
-#include <unicode/uiter.h>
-#include <unicode/udat.h>
-#include <unicode/udatpg.h>
-#include <unicode/ustring.h>
-
-#define WATCH_ID "internal://WATCH_ID"
-#define AUL_K_CALLER_APPID "__AUL_CALLER_APPID__"
-#define APPID_BUFFER_MAX 255
-#define TIMEZONE_BUFFER_MAX 1024
-#define LOCAL_TIME_PATH "/opt/etc/localtime"
-#define ONE_SECOND             1000
-#define ONE_MINUTE_IN_SEC      60
-#define ONE_HOUR_IN_SEC                3600
-#define ONE_DAY_IN_SEC         86400
-
-static Ecore_Timer *watch_tick = NULL;
-static alarm_id_t alarm_id = 0;
-static watch_app_ambient_tick_type_e ambient_tick_type
-                                       = WATCH_APP_AMBIENT_TICK_EVERY_MINUTE;
-
-static watch_app_time_tick_resolution_e app_tick_type = WATCH_APP_TIME_TICKS_PER_SECOND;
-static int app_tick_resolution = 1;
-
-/**
- * Appcore internal system event
- */
-enum sys_event {
-       SE_UNKNOWN,
-       SE_LOWMEM,
-       SE_LOWBAT,
-       SE_LANGCHG,
-       SE_REGIONCHG,
-       SE_TIMECHG,
-       SE_MAX
-};
-
-/**
- * watch internal state
- */
-enum watch_state {
-       WS_NONE,
-       WS_CREATED,
-       WS_RUNNING,
-       WS_PAUSED,
-       WS_DYING,
-};
-
-enum watch_event {
-       WE_UNKNOWN,
-       WE_CREATE,
-       WE_PAUSE,
-       WE_RESUME,
-       WE_APPCONTROL,
-       WE_AMBIENT,
-       WE_TERMINATE,
-       WE_MAX
-};
-
-static enum watch_core_event to_ae[SE_MAX] = {
-       WATCH_CORE_EVENT_UNKNOWN,       /* SE_UNKNOWN */
-       WATCH_CORE_EVENT_LOW_MEMORY,    /* SE_LOWMEM */
-       WATCH_CORE_EVENT_LOW_BATTERY,   /* SE_LOWBAT */
-       WATCH_CORE_EVENT_LANG_CHANGE,
-       WATCH_CORE_EVENT_REGION_CHANGE,
-};
-
-static int watch_core_event_initialized[SE_MAX] = {0};
-
-enum cb_type {                 /* callback */
-       _CB_NONE,
-       _CB_SYSNOTI,
-       _CB_APPNOTI,
-       _CB_VCONF,
-};
-
-struct evt_ops {
-       enum cb_type type;
-       union {
-               enum watch_core_event sys;
-               enum watch_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 watch_priv {
-       const char *appid;
-       const char *name;
-       pid_t pid;
-       enum watch_state state;
-       int ambient_mode;
-       int ambient_mode_skip_resume;
-
-       struct watchcore_ops *ops;
-};
-
-static struct watch_priv priv;
-
-struct watch_ops {
-       void *data;
-       void (*cb_app)(enum watch_event, void *, bundle *);
-};
-
-/**
- * Appcore system event operation
- */
-struct sys_op {
-       int (*func) (void *, void *);
-       void *data;
-};
-
-struct watch_core {
-       int init;
-
-       const struct watch_ops *ops;
-       struct sys_op sops[SE_MAX];
-};
-
-static struct watch_core 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,
-       },
-};
-
-static void __watch_core_signal_init(void);
-static int  __watch_core_widget_init(void);
-
-static Eina_Bool __watch_core_time_tick(void *data);
-static void __watch_core_time_tick_cancel(void);
-
-static int __watch_core_ambient_tick(alarm_id_t id, void *data);
-
-static int __widget_create(const char *id, const char *content, int w, int h,
-               void *data);
-static int __widget_resize(const char *id, int w, int h, void *data);
-static int __widget_destroy(const char *id, widget_app_destroy_type_e reason,
-               void *data);
-static int __widget_pause(const char *id, void *data);
-static int __widget_resume(const char *id, void *data);
-static void __get_timeinfo(struct watch_time_s *timeinfo);
-
-extern int app_control_create_event(bundle *data,
-               struct app_control_s **app_control);
-
-static struct ambient_tick_type_info {
-       int interval;
-       int minute_base;
-       int hour_base;
-} ambient_tick_type_infos[] = {
-       {0, 0, 0},
-       {ONE_MINUTE_IN_SEC, 1, 0},
-       {ONE_MINUTE_IN_SEC * 5, 5, 0},
-       {ONE_MINUTE_IN_SEC * 15, 15, 0},
-       {ONE_MINUTE_IN_SEC * 30, 30, 0},
-       {ONE_HOUR_IN_SEC, 0, 1},
-       {ONE_HOUR_IN_SEC * 3, 0, 3},
-       {ONE_HOUR_IN_SEC * 6, 0, 6},
-       {ONE_HOUR_IN_SEC * 12, 0, 12},
-       {ONE_DAY_IN_SEC, 0, 12}
-};
-
-static void __exit_loop(void *data)
-{
-       ecore_main_loop_quit();
-}
-
-static void __do_app(enum watch_event event, void *data, bundle * b)
-{
-       struct watch_priv *watch_data = data;
-       app_control_h app_control = NULL;
-       int r;
-
-       _ret_if(watch_data == NULL);
-
-       if (event == WE_TERMINATE) {
-               watch_data->state = WS_DYING;
-               ecore_main_loop_thread_safe_call_sync(
-                               (Ecore_Data_Cb)__exit_loop, NULL);
-               return;
-       }
-
-       _ret_if(watch_data->ops == NULL);
-
-       switch (event) {
-       case WE_APPCONTROL:
-               _D("appcontrol request");
-               if (app_control_create_event(b, &app_control) != 0) {
-                       _E("failed to get the app_control handle");
-                       return;
-               }
-
-               if (watch_data->ops->app_control)
-                       watch_data->ops->app_control(app_control,
-                                       watch_data->ops->data);
-
-               app_control_destroy(app_control);
-               break;
-       case WE_PAUSE:
-               _D("WE_PAUSE");
-               if (watch_data->state == WS_CREATED) {
-                       _E("Invalid state");
-                       return;
-               }
-
-               /* Handling the ambient mode */
-               if (watch_data->ambient_mode)
-                       watch_data->ambient_mode_skip_resume = 1;
-
-               /* Cancel the time_tick callback */
-               __watch_core_time_tick_cancel();
-               if (watch_data->state == WS_RUNNING) {
-                       if (watch_data->ops->pause) {
-                               r = priv.ops->pause(priv.ops->data);
-                               if (r < 0)
-                                       _E("pause() fails");
-                       }
-               }
-
-               watch_data->state = WS_PAUSED;
-               break;
-       case WE_RESUME:
-               _D("WE_RESUME");
-
-               /* Handling the ambient mode */
-               if (watch_data->ambient_mode) {
-                       watch_data->ambient_mode_skip_resume = 0;
-                       return;
-               }
-
-               if (watch_data->state == WS_PAUSED ||
-                               watch_data->state == WS_CREATED) {
-                       if (watch_data->ops->resume) {
-                               r = priv.ops->resume(priv.ops->data);
-                               if (r < 0)
-                                       _E("resume() fails");
-                       }
-
-                       watch_data->state = WS_RUNNING;
-
-                       /* Set the time tick callback */
-                       if (!watch_tick) {
-                               __watch_core_time_tick(NULL);
-                       } else {
-                               __watch_core_time_tick_cancel();
-                               __watch_core_time_tick(NULL);
-                       }
-               }
-               break;
-       case WE_AMBIENT:
-               _D("WE_AMBIENT");
-               if (priv.ops && priv.ops->ambient_changed)
-                       priv.ops->ambient_changed(watch_data->ambient_mode,
-                                       priv.ops->data);
-
-               break;
-       default:
-               break;
-       }
-}
-
-static struct watch_ops w_ops = {
-       .data = &priv,
-       .cb_app = __do_app,
-};
-
-static char *__get_domain_name(const char *appid)
-{
-       char *name_token = NULL;
-
-       if (appid == NULL) {
-               _E("appid is NULL");
-               return NULL;
-       }
-
-       /* com.vendor.name -> name */
-       name_token = strrchr(appid, '.');
-       if (name_token == NULL) {
-               _E("appid is invalid");
-               return NULL;
-       }
-
-       name_token++;
-
-       return strdup(name_token);
-}
-
-static int __set_data(struct watch_priv *watch, const char *appid,
-               struct watchcore_ops *ops)
-{
-       if (ops == NULL) {
-               errno = EINVAL;
-               return -1;
-       }
-
-       watch->ops = ops;
-       watch->appid = strdup(appid);
-       watch->name = __get_domain_name(appid);
-       watch->pid = getpid();
-
-       return 0;
-}
-
-static int __watch_appcontrol(void *data, bundle *k)
-{
-       struct watch_core *wc = data;
-       _retv_if(wc == NULL || wc->ops == NULL, -1);
-       _retv_if(wc->ops->cb_app == NULL, 0);
-
-       wc->ops->cb_app(WE_APPCONTROL, wc->ops->data, k);
-
-       return 0;
-}
-
-/* LCOV_EXCL_START */
-static int __watch_terminate(void *data)
-{
-       struct watch_core *wc = data;
-
-       _retv_if(wc == NULL || wc->ops == NULL, -1);
-       _retv_if(wc->ops->cb_app == NULL, 0);
-
-       wc->ops->cb_app(WE_TERMINATE, wc->ops->data, NULL);
-
-       return 0;
-}
-/* LCOV_EXCL_STOP */
-
-/* LCOV_EXCL_START */
-static int __sys_do_default(struct watch_core *wc, enum sys_event event)
-{
-       switch (event) {
-       case SE_LOWBAT:
-               /*r = __def_lowbatt(wc);*/
-               break;
-       default:
-               break;
-       }
-
-       return 0;
-}
-/* LCOV_EXCL_STOP */
-
-static int __sys_do(struct watch_core *wc, void *event_info,
-               enum sys_event event)
-{
-       struct sys_op *op;
-
-       _retv_if(wc == NULL || event >= SE_MAX, -1);
-
-       op = &wc->sops[event];
-
-       if (op->func == NULL)
-               return __sys_do_default(wc, event);
-
-       return op->func(event_info, op->data);
-}
-
-static int __sys_lowmem_post(void *data, void *evt)
-{
-       keynode_t *key = evt;
-       int val;
-
-       val = vconf_keynode_get_int(key);
-
-       if (val == VCONFKEY_SYSMAN_LOW_MEMORY_SOFT_WARNING) {
-#if defined(MEMORY_FLUSH_ACTIVATE)
-               struct appcore *wc = data;
-               wc->ops->cb_app(AE_LOWMEM_POST, wc->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)
-{
-       _update_lang();
-       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)
-{
-       _update_region();
-       return 0;
-}
-
-static int __sys_regionchg(void *data, void *evt)
-{
-       keynode_t *key = evt;
-       char *val;
-
-       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 int __get_ambient_tick_offset(struct watch_time_s timeinfo, int interval, int minute_base, int hour_base)
-{
-       int remain_hour = 0;
-       int remain_min = 0;
-       int offset_sec = 0;
-
-       if (hour_base != 0) {
-               if (interval == ONE_DAY_IN_SEC) {
-                       remain_hour = hour_base - timeinfo.hour24;
-                       if (remain_hour < 0)
-                               remain_hour += 24;
-                       remain_min = remain_hour * 60 - timeinfo.minute;
-                       offset_sec = remain_min * ONE_MINUTE_IN_SEC - timeinfo.second;
-               } else {
-                       remain_hour = hour_base - (timeinfo.hour24 % hour_base);
-                       remain_min = remain_hour * 60 - timeinfo.minute;
-                       offset_sec = remain_min * ONE_MINUTE_IN_SEC - timeinfo.second;
-               }
-       } else {
-               remain_min = minute_base - (timeinfo.minute % minute_base);
-               offset_sec = remain_min * ONE_MINUTE_IN_SEC - timeinfo.second;
-       }
-       return offset_sec;
-}
-
-static int __set_ambient_tick_cb()
-{
-       int offset_sec = 0;
-       int interval = 0;
-       struct watch_time_s timeinfo;
-       int r;
-       struct ambient_tick_type_info info;
-
-       __get_timeinfo(&timeinfo);
-       info = ambient_tick_type_infos[ambient_tick_type];
-       interval = info.interval;
-
-       if (interval == 0) {
-               priv.ops->ambient_tick(&timeinfo, priv.ops->data);
-       } else {
-               offset_sec = __get_ambient_tick_offset(timeinfo, info.interval,
-                               info.minute_base, info.hour_base);
-               _D("next time tick: %d", offset_sec);
-
-               /* Set a next alarm */
-               r = alarmmgr_add_alarm_withcb(ALARM_TYPE_VOLATILE, offset_sec, interval,
-                               __watch_core_ambient_tick, NULL, &alarm_id);
-               if (r < 0)
-                       _E("fail to alarmmgr_add_alarm_withcb : error_code : %d", r);
-       }
-
-       return 0;
-}
-
-static void __vconf_cb(keynode_t *key, void *data)
-{
-       int i;
-       const char *name;
-       struct watch_priv *watch_data = data;
-       struct evt_ops *eo;
-
-       name = vconf_keynode_get_name(key);
-       _ret_if(name == NULL);
-
-       _D("vconf changed: %s", name);
-
-       /* Check the time changed event */
-       if (!strcmp(name, VCONFKEY_SYSTEM_TIME_CHANGED)) {
-               _D("ambient_mode: %d", watch_data->ambient_mode);
-               if (watch_data->ambient_mode) {
-                       if (alarm_id) {
-                               alarmmgr_remove_alarm(alarm_id);
-                               alarm_id = 0;
-                       }
-                       __set_ambient_tick_cb();
-               }
-
-               return;
-       }
-
-       for (i = 0; i < sizeof(evtops) / sizeof(evtops[0]); i++) {
-               eo = &evtops[i];
-
-               switch (eo->type) {
-               case _CB_VCONF:
-                       if (!strcmp(name, eo->key.vkey))
-                               __vconf_do(eo, key, data);
-                       break;
-               default:
-                       break;
-               }
-       }
-}
-
-static int __add_vconf(struct watch_core *wc, enum sys_event se)
-{
-       int r;
-
-       switch (se) {
-       case SE_LOWMEM:
-               r = vconf_notify_key_changed(VCONFKEY_SYSMAN_LOW_MEMORY,
-                               __vconf_cb, wc);
-               break;
-       case SE_LOWBAT:
-               r = vconf_notify_key_changed(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW,
-                               __vconf_cb, wc);
-               break;
-       case SE_LANGCHG:
-               r = vconf_notify_key_changed(VCONFKEY_LANGSET, __vconf_cb, wc);
-               break;
-       case SE_REGIONCHG:
-               r = vconf_notify_key_changed(VCONFKEY_REGIONFORMAT, __vconf_cb,
-                               wc);
-               break;
-       case SE_TIMECHG:
-               r = vconf_notify_key_changed(VCONFKEY_SYSTEM_TIME_CHANGED,
-                               __vconf_cb, &priv);
-               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);
-               break;
-       case SE_TIMECHG:
-               r = vconf_ignore_key_changed(VCONFKEY_SYSTEM_TIME_CHANGED,
-                               __vconf_cb);
-               break;
-       default:
-               r = -1;
-               break;
-       }
-
-       return r;
-}
-
-/* LCOV_EXCL_START */
-static int __del_vconf_list(void)
-{
-       int r;
-       enum sys_event se;
-
-       for (se = SE_LOWMEM; se < SE_MAX; se++) {
-               if (watch_core_event_initialized[se]) {
-                       r = __del_vconf(se);
-                       if (r < 0)
-                               _E("Delete vconf callback failed");
-                       else
-                               watch_core_event_initialized[se] = 0;
-               }
-       }
-
-       return 0;
-}
-/* LCOV_EXCL_STOP */
-
-static int __aul_handler(aul_type type, bundle *b, void *data)
-{
-       int ret;
-
-       switch (type) {
-       case AUL_START:
-               ret = __watch_appcontrol(data, b);
-               break;
-       case AUL_RESUME:
-               break;
-       case AUL_TERMINATE:
-               ret = __watch_terminate(data);
-               break;
-       default:
-               break;
-       }
-
-       return 0;
-}
-
-EXPORT_API int watch_core_set_event_callback(enum watch_core_event event,
-               int (*cb) (void *, void *), void *data)
-{
-       struct watch_core *wc = &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) {
-               _E("Unregistered event");
-               errno = EINVAL;
-               return -1;
-       }
-
-       op = &wc->sops[se];
-
-       op->func = cb;
-       op->data = data;
-
-       if (op->func && !watch_core_event_initialized[se]) {
-               r = __add_vconf(wc, se);
-               if (r < 0)
-                       _E("Add vconf callback failed");
-               else
-                       watch_core_event_initialized[se] = 1;
-       } else if (!op->func && watch_core_event_initialized[se]) {
-               r = __del_vconf(se);
-               if (r < 0)
-                       _E("Delete vconf callback failed");
-               else
-                       watch_core_event_initialized[se] = 0;
-       }
-
-       return 0;
-}
-
-static char *__get_timezone(void)
-{
-       char buf[TIMEZONE_BUFFER_MAX] = {0,};
-       ssize_t len = readlink(LOCAL_TIME_PATH, buf, sizeof(buf) - 1);
-
-       if (len != -1)
-               buf[len] = '\0';
-       else  /* handle error condition */
-               return vconf_get_str(VCONFKEY_SETAPPL_TIMEZONE_ID);
-
-       return strdup(buf + 20);
-}
-
-static void __get_timeinfo(struct watch_time_s *timeinfo)
-{
-       UErrorCode status = U_ZERO_ERROR;
-       struct timeval current;
-       char *timezone;
-       UCalendar *cal;
-
-       /* UTC time */
-       gettimeofday(&current, NULL);
-       timeinfo->timestamp = current.tv_sec;
-
-       /* Time zone */
-       timezone = __get_timezone();
-       UChar utf16_timezone[64] = {0};
-       u_uastrncpy(utf16_timezone, timezone, 64);
-
-       /* Local time */
-       cal = ucal_open(utf16_timezone, u_strlen(utf16_timezone),
-                       uloc_getDefault(), UCAL_TRADITIONAL, &status);
-       if (cal == NULL)
-               return;
-
-       timeinfo->year = ucal_get(cal, UCAL_YEAR, &status);
-       timeinfo->month = ucal_get(cal, UCAL_MONTH, &status) + 1;
-       timeinfo->day = ucal_get(cal, UCAL_DATE, &status);
-       timeinfo->day_of_week = ucal_get(cal, UCAL_DAY_OF_WEEK, &status);
-       timeinfo->hour = ucal_get(cal, UCAL_HOUR_OF_DAY, &status);
-       timeinfo->hour24 = ucal_get(cal, UCAL_HOUR_OF_DAY, &status);
-       timeinfo->minute = ucal_get(cal, UCAL_MINUTE, &status);
-       timeinfo->second = ucal_get(cal, UCAL_SECOND, &status);
-       timeinfo->millisecond = ucal_get(cal, UCAL_MILLISECOND, &status);
-       timeinfo->timezone = timezone;
-
-       timeinfo->hour -= (timeinfo->hour > 12) ? 12 : 0;
-       timeinfo->hour = (timeinfo->hour == 0) ? 12 : timeinfo->hour;
-
-       ucal_clear(cal);
-       ucal_close(cal);
-}
-
-int watch_core_init(const char *name, const struct watch_ops *ops,
-               int argc, char **argv)
-{
-       int r;
-
-       if (core.init != 0) {
-               errno = EALREADY;
-               return -1;
-       }
-
-       if (ops == NULL || ops->cb_app == NULL) {
-               errno = EINVAL;
-               return -1;
-       }
-
-       r = _set_i18n(name);
-       _retv_if(r == -1, -1);
-
-       r = __add_vconf(&core, SE_TIMECHG);
-       if (r < 0) {
-               _E("Add vconf callback failed");
-               goto err;
-       }
-
-       r = aul_launch_init(__aul_handler, &core);
-       if (r < 0) {
-               _E("Fail to call the aul_launch_init");
-               assert(0);
-               goto err;
-       }
-
-       r = aul_launch_argv_handler(argc, argv);
-       if (r < 0) {
-               _E("Fail to call the aul_launch_argv_handler");
-               goto err;
-       }
-
-       core.ops = ops;
-       core.init = 1;
-
-       return 0;
-
-err:
-       return -1;
-}
-
-static void __watch_core_alarm_init(void)
-{
-       int r = 0;
-       int pid = getpid();
-       char appid[APPID_BUFFER_MAX] = {0,};
-
-       r = aul_app_get_appid_bypid(pid, appid, APPID_BUFFER_MAX);
-       if (r < 0) {
-               _E("fail to get the appid from the pid : %d", pid);
-               assert(0);
-       }
-
-       r = alarmmgr_init(appid);
-       if (r < 0) {
-               _E("fail to alarmmgr_init : error_code : %d", r);
-               assert(0);
-       }
-}
-
-static void __watch_core_time_tick_cancel(void)
-{
-       if (watch_tick) {
-               ecore_timer_del(watch_tick);
-               watch_tick = NULL;
-       }
-}
-
-static double __get_next_tick_sec()
-{
-       double cur_time_in_milli;
-       double term = 1.0;
-       double sec = 1.0;
-       int idx;
-       struct watch_time_s timeinfo;
-
-       __get_timeinfo(&timeinfo);
-       cur_time_in_milli = timeinfo.hour24 * 60 * 60 * 1000 + timeinfo.minute * 60 * 1000 +
-                       timeinfo.minute * 60 * 1000 + timeinfo.second * 1000 + timeinfo.millisecond;
-
-       if (app_tick_type == WATCH_APP_TIME_TICKS_PER_SECOND) {
-               term = (double)ONE_SECOND / (double)app_tick_resolution;
-       } else if (app_tick_type == WATCH_APP_TIME_TICKS_PER_MINUTE) {
-               term = (double)ONE_MINUTE_IN_SEC / (double)app_tick_resolution;
-               term *= 1000;
-       } else if (app_tick_type == WATCH_APP_TIME_TICKS_PER_HOUR) {
-               term = (double)ONE_HOUR_IN_SEC / (double)app_tick_resolution;
-               term *= 1000;
-       }
-
-       idx = cur_time_in_milli / term;
-       sec = (((idx + 1) * term) - cur_time_in_milli) / 1000.0;
-
-       return sec;
-}
-
-static Eina_Bool __watch_core_time_tick(void *data)
-{
-       struct watch_time_s timeinfo;
-       double sec;
-
-       _D("state: %d", priv.state);
-
-       if (priv.ops && priv.ops->time_tick && priv.state != WS_PAUSED) {
-               __get_timeinfo(&timeinfo);
-
-               /* Set a next timer */
-               sec = __get_next_tick_sec();
-               watch_tick = ecore_timer_add(sec, __watch_core_time_tick, NULL);
-
-               _D("next time tick: %f, type %d, ticks %d", sec, app_tick_resolution, app_tick_type);
-               priv.ops->time_tick(&timeinfo, priv.ops->data);
-       }
-
-       return ECORE_CALLBACK_CANCEL;
-}
-
-/* LCOV_EXCL_START */
-static int __watch_core_ambient_tick(alarm_id_t id, void *data)
-{
-       struct watch_time_s timeinfo;
-
-       _D("state: %d", priv.state);
-       if (priv.ops && priv.ops->ambient_tick && priv.state != WS_RUNNING) {
-               __get_timeinfo(&timeinfo);
-               priv.ops->ambient_tick(&timeinfo, priv.ops->data);
-       }
-
-       return 0;
-}
-/* LCOV_EXCL_STOP */
-
-static int __widget_create(const char *id, const char *content, int w, int h,
-               void *data)
-{
-       int r;
-       _D("widget_create");
-
-       if (priv.ops && priv.ops->create) {
-               r = priv.ops->create(w, h, priv.ops->data);
-               if (r < 0) {
-                       _E("Failed to initialize the application");
-                       __exit_loop(NULL);
-               }
-       }
-
-       priv.state = WS_CREATED;
-
-       _D("widget_create done");
-
-       /* Alarm init */
-       __watch_core_alarm_init();
-
-       return WIDGET_ERROR_NONE;
-}
-
-/* LCOV_EXCL_START */
-static int __widget_resize(const char *id, int w, int h, void *data)
-{
-
-       return WIDGET_ERROR_NONE;
-}
-/* LCOV_EXCL_STOP */
-
-/* LCOV_EXCL_START */
-static int __widget_destroy(const char *id, widget_app_destroy_type_e reason,
-               void *data)
-{
-       _D("widget_destory");
-
-       __exit_loop(NULL);
-
-       return WIDGET_ERROR_NONE;
-}
-/* LCOV_EXCL_STOP */
-
-/* LCOV_EXCL_START */
-static int __widget_pause(const char *id, void *data)
-{
-       _D("widget_pause");
-
-       __do_app(WE_PAUSE, &priv, NULL);
-
-       return WIDGET_ERROR_NONE;
-}
-/* LCOV_EXCL_STOP */
-
-/* LCOV_EXCL_START */
-static int __widget_resume(const char *id, void *data)
-{
-       _D("widget_resume");
-
-       __do_app(WE_RESUME, &priv, NULL);
-
-       return WIDGET_ERROR_NONE;
-}
-/* LCOV_EXCL_STOP */
-
-/* LCOV_EXCL_START */
-static int __signal_alpm_handler(int ambient, void *data)
-{
-       _D("_signal_alpm_handler: ambient: %d, state: %d", ambient, priv.state);
-
-       if (priv.ambient_mode == ambient) {
-               _E("invalid state");
-               return 0;
-       }
-
-       /* Enter the ambient mode */
-       if (ambient) {
-               if (priv.state != WS_PAUSED) {
-                       __do_app(WE_PAUSE, &priv, NULL);
-                       priv.ambient_mode_skip_resume = 0;
-               } else {
-                       priv.ambient_mode_skip_resume = 1;
-               }
-
-               priv.ambient_mode = 1;
-               __do_app(WE_AMBIENT, &priv, NULL);
-
-               if (priv.ops && priv.ops->ambient_tick)
-                       __set_ambient_tick_cb();
-
-               /* Send a update done signal */
-               _watch_core_send_alpm_update_done();
-
-       } else { /* Exit the ambient mode */
-               priv.ambient_mode = 0;
-               __do_app(WE_AMBIENT, &priv, NULL);
-
-               _D("Resume check: %d", priv.ambient_mode_skip_resume);
-               if (!priv.ambient_mode_skip_resume) {
-                       _D("Call the resume after ambient mode changed");
-                       __do_app(WE_RESUME, &priv, NULL);
-               }
-
-               /* Disable alarm */
-               if (alarm_id) {
-                       alarmmgr_remove_alarm(alarm_id);
-                       alarm_id = 0;
-               }
-       }
-
-       return 0;
-}
-/* LCOV_EXCL_STOP */
-
-static Eina_Bool __show_cb(void *data, int type, void *event)
-{
-       Ecore_Wl_Event_Window_Show *ev = event;
-
-       _D("show %d %d", (unsigned int)ev->win, (unsigned int)ev->data[0]);
-
-       __do_app(WE_RESUME, &priv, NULL);
-
-       return ECORE_CALLBACK_RENEW;
-}
-
-static Eina_Bool __hide_cb(void *data, int type, void *event)
-{
-       Ecore_Wl_Event_Window_Hide *ev = event;
-
-       _D("hide %d", (unsigned int)ev->win);
-
-       __do_app(WE_PAUSE, &priv, NULL);
-
-       return ECORE_CALLBACK_RENEW;
-}
-
-/* LCOV_EXCL_START */
-static Eina_Bool __visibility_cb(void *data, int type, void *event)
-{
-       Ecore_Wl_Event_Window_Visibility_Change *ev = event;
-
-       _D("visibility %d %d", (unsigned int)ev->win, (unsigned int)ev->fully_obscured);
-
-       if (ev->fully_obscured)
-               __do_app(WE_PAUSE, &priv, NULL);
-       else
-               __do_app(WE_RESUME, &priv, NULL);
-
-       return ECORE_CALLBACK_RENEW;
-}
-/* LCOV_EXCL_STOP */
-
-/* LCOV_EXCL_START */
-static Eina_Bool __lower_cb(void *data, int type, void *event)
-{
-       _D("lower");
-
-       return ECORE_CALLBACK_RENEW;
-}
-/* LCOV_EXCL_STOP */
-
-static void __add_climsg(void)
-{
-       ecore_event_handler_add(ECORE_WL_EVENT_WINDOW_SHOW, __show_cb, NULL);
-       ecore_event_handler_add(ECORE_WL_EVENT_WINDOW_HIDE, __hide_cb, NULL);
-       ecore_event_handler_add(ECORE_WL_EVENT_WINDOW_VISIBILITY_CHANGE, __visibility_cb, NULL);
-       ecore_event_handler_add(ECORE_WL_EVENT_WINDOW_LOWER, __lower_cb, NULL);
-}
-
-static void __watch_core_signal_init(void)
-{
-       _watch_core_listen_alpm_handler(__signal_alpm_handler, NULL);
-}
-
-static int __before_loop(struct watch_priv *watch, int argc, char **argv)
-{
-       int r;
-       bundle *kb = NULL;
-       char *width_str = NULL;
-       char *height_str = NULL;
-       int width = 360;
-       int height = 360;
-
-
-       if (argc <= 0 || argv == NULL) {
-               errno = EINVAL;
-               _E("argument are invalid");
-               return -1;
-       }
-
-       priv.ambient_mode = 0;
-       priv.ambient_mode_skip_resume = 0;
-
-#if !(GLIB_CHECK_VERSION(2, 36, 0))
-       g_type_init();
-#endif
-
-       kb = bundle_import_from_argv(argc, argv);
-       if (kb) {
-               bundle_get_str(kb, "WATCH_WIDTH", &width_str);
-               bundle_get_str(kb, "WATCH_HEIGHT", &height_str);
-
-               if (width_str)
-                       width = atoi(width_str);
-
-               if (height_str)
-                       height = atoi(height_str);
-
-               bundle_free(kb);
-       } else {
-               _E("failed to get launch argv");
-       }
-
-       elm_init(argc, argv);
-
-       __add_climsg();
-
-       r = watch_core_init(watch->name, &w_ops, argc, argv);
-       _retv_if(r < 0, -1);
-
-       screen_connector_provider_init();
-
-       __widget_create(NULL, NULL, width, height, NULL);
-
-       __watch_core_signal_init();
-
-       return 0;
-}
-
-static void __after_loop(struct watch_priv *watch)
-{
-       if (priv.state == WS_RUNNING && watch->ops && watch->ops->pause)
-               watch->ops->pause(watch->ops->data);
-
-       priv.state = WS_DYING;
-
-       /* Cancel the time_tick callback */
-       __watch_core_time_tick_cancel();
-
-       if (watch->ops && watch->ops->terminate)
-               watch->ops->terminate(watch->ops->data);
-
-       screen_connector_provider_fini();
-
-       elm_shutdown();
-
-       alarmmgr_fini();
-}
-
-EXPORT_API int watch_core_main(const char *appid, int argc, char **argv,
-                               struct watchcore_ops *ops)
-{
-       int r;
-
-       r = __set_data(&priv, appid, ops);
-       _retv_if(r == -1, -1);
-
-       r = __before_loop(&priv, argc, argv);
-       if (r != 0) {
-               __del_vconf_list();
-               return r;
-       }
-
-       ecore_main_loop_begin();
-
-       aul_status_update(STATUS_DYING);
-
-       __after_loop(&priv);
-
-
-       return 0;
-}
-
-EXPORT_API int watch_core_terminate()
-{
-       ecore_main_loop_thread_safe_call_sync((Ecore_Data_Cb)__exit_loop, NULL);
-       return 0;
-}
-
-EXPORT_API void watch_core_get_timeinfo(struct watch_time_s *timeinfo)
-{
-       __get_timeinfo(timeinfo);
-}
-
-EXPORT_API const char *watch_core_get_appid()
-{
-       return priv.appid;
-}
-
-EXPORT_API int watch_core_set_ambient_tick_type(watch_app_ambient_tick_type_e type)
-{
-       _D("set ambient tick type : %d", type);
-       ambient_tick_type = type;
-
-       if (alarm_id) {
-               alarmmgr_remove_alarm(alarm_id);
-               alarm_id = 0;
-               __set_ambient_tick_cb();
-       }
-       return 0;
-}
-
-EXPORT_API int watch_core_get_ambient_tick_type(watch_app_ambient_tick_type_e *type)
-{
-       *type = ambient_tick_type;
-       return 0;
-}
-
-EXPORT_API int watch_core_set_time_tick_frequency(int ticks, watch_app_time_tick_resolution_e type)
-{
-       double sec = 1.0;
-       struct watch_time_s timeinfo;
-
-       _D("ticks: %d, type: %d", ticks, type);
-       ecore_timer_precision_set(0.0000001);
-       __watch_core_time_tick_cancel();
-
-       app_tick_type = type;
-       app_tick_resolution = ticks;
-
-       sec = __get_next_tick_sec();
-       /* Set a next timer */
-       watch_tick = ecore_timer_add(sec, __watch_core_time_tick, NULL);
-       _D("next time tick: %f", sec);
-
-       if (priv.ops && priv.ops->time_tick && priv.state != WS_PAUSED) {
-               __get_timeinfo(&timeinfo);
-               priv.ops->time_tick(&timeinfo, priv.ops->data);
-       }
-
-       return 0;
-}
-
-EXPORT_API int watch_core_get_time_tick_frequency(int *ticks, watch_app_time_tick_resolution_e *type)
-{
-       *ticks = app_tick_resolution;
-       *type = app_tick_type;
-       return 0;
-}
-
-
index be336c6a2ac9d5cd47887d54bc890c8b15c67638..ec851935952845f01c500eb102fe4c68dcc85e69 100755 (executable)
  * limitations under the License.
  */
 
+#include <assert.h>
+#include <errno.h>
+#include <string.h>
 #include <stdlib.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <malloc.h>
+#include <libintl.h>
+
+#include <unicode/utypes.h>
+#include <unicode/putil.h>
+#include <unicode/uiter.h>
+#include <unicode/udat.h>
+#include <unicode/udatpg.h>
+#include <unicode/ustring.h>
 
 #include <bundle.h>
 #include <aul.h>
 #include <dlog.h>
 #include <app_common.h>
 #include <app_control.h>
-#include <Eina.h>
 #include <Evas.h>
 #include <Elementary.h>
 #include <Ecore_Wayland.h>
 #include <screen_connector_provider.h>
+#include <appcore_ui_base.h>
+#include <alarm.h>
+#include <vconf.h>
+#include <glib-object.h>
+#include <Ecore_Wayland.h>
+#include <app_control.h>
+#include <app_control_internal.h>
+#include <bundle_internal.h>
 
-#include "appcore-watch.h"
 #include "appcore-watch-log.h"
 #include "watch_app_private.h"
+#include "appcore-watch-signal.h"
 
 #ifdef LOG_TAG
 #undef LOG_TAG
 #define LOG_TAG "CAPI_WATCH_APPLICATION"
 
 #define WATCH_ID "internal://WATCH_ID"
+#define AUL_K_CALLER_APPID "__AUL_CALLER_APPID__"
+#define APPID_BUFFER_MAX 255
+#define TIMEZONE_BUFFER_MAX 1024
+#define LOCAL_TIME_PATH "/opt/etc/localtime"
+#define ONE_SECOND             1000
+#define ONE_MINUTE_IN_SEC      60
+#define ONE_HOUR_IN_SEC                3600
+#define ONE_DAY_IN_SEC         86400
 
 typedef enum {
-       WATCH_APP_STATE_NOT_RUNNING, /* The application has been launched or was running but was terminated */
+       WATCH_APP_STATE_NOT_RUNNING = 0, /* The application has been launched or was running but was terminated */
        WATCH_APP_STATE_CREATING, /* The application is initializing the resources on watch_app_create_cb callback */
        WATCH_APP_STATE_RUNNING, /* The application is running in the foreground and background */
 } watch_app_state_e;
 
-typedef struct {
-       char *package;
-       char *watch_app_name;
-       watch_app_state_e state;
-       watch_app_lifecycle_callback_s *callback;
-       void *data;
-} watch_app_context_s;
-
-typedef watch_app_context_s *watch_app_context_h;
-
 struct _watch_time_s {
        int year;
        int month;
@@ -70,14 +89,19 @@ struct _watch_time_s {
 };
 
 #define WATCH_APP_EVENT_MAX 5
-static Eina_List *handler_list[WATCH_APP_EVENT_MAX] = {NULL, };
-static int _initialized = 0;
-static int watch_core_initialized = 0;
+static Ecore_Timer *watch_tick = NULL;
+static alarm_id_t alarm_id = 0;
+static watch_app_ambient_tick_type_e ambient_tick_type
+                                       = WATCH_APP_AMBIENT_TICK_EVERY_MINUTE;
+
+static watch_app_time_tick_resolution_e app_tick_type = WATCH_APP_TIME_TICKS_PER_SECOND;
+static int app_tick_resolution = 1;
 
 struct app_event_handler {
        app_event_type_e type;
        app_event_cb cb;
        void *data;
+       void *raw;
 };
 
 struct app_event_info {
@@ -88,305 +112,518 @@ struct app_event_info {
 struct watch_app_context {
        char *appid;
        watch_app_state_e state;
-       watch_app_lifecycle_callback_s *callback;
+       watch_app_lifecycle_callback_s callback;
+       int width;
+       int height;
+       bool ambient_mode;
+       bool ambient_mode_skip_resume;
        void *data;
 };
 
-static void _free_handler_list(void)
+static struct ambient_tick_type_info {
+       int interval;
+       int minute_base;
+       int hour_base;
+} ambient_tick_type_infos[] = {
+       {0, 0, 0},
+       {ONE_MINUTE_IN_SEC, 1, 0},
+       {ONE_MINUTE_IN_SEC * 5, 5, 0},
+       {ONE_MINUTE_IN_SEC * 15, 15, 0},
+       {ONE_MINUTE_IN_SEC * 30, 30, 0},
+       {ONE_HOUR_IN_SEC, 0, 1},
+       {ONE_HOUR_IN_SEC * 3, 0, 3},
+       {ONE_HOUR_IN_SEC * 6, 0, 6},
+       {ONE_HOUR_IN_SEC * 12, 0, 12},
+       {ONE_DAY_IN_SEC, 0, 12}
+};
+
+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_REGION_FORMAT_CHANGED] = APPCORE_BASE_EVENT_REGION_CHANGE,
+       [APP_EVENT_SUSPENDED_STATE_CHANGED] = APPCORE_BASE_EVENT_SUSPENDED_STATE_CHANGE,
+};
+
+struct watch_app_context __context;
+
+static void __on_ambient_tick(void *watchtime, void *data);
+static void __on_ambient_changed(int ambient, void *data);
+static void __on_time_tick(void *watchtime, void *data);
+
+static void __alarm_init(void)
 {
-       int i;
-       app_event_handler_h handler;
+       int r = 0;
+       int pid = getpid();
+       char appid[APPID_BUFFER_MAX] = {0,};
 
-       for (i = 0; i < WATCH_APP_EVENT_MAX; i++) {
-               EINA_LIST_FREE(handler_list[i], handler)
-                       free(handler);
+       r = aul_app_get_appid_bypid(pid, appid, APPID_BUFFER_MAX);
+       if (r < 0) {
+               _E("fail to get the appid from the pid : %d", pid);
+               assert(0);
        }
 
-       eina_shutdown();
+       r = alarmmgr_init(appid);
+       if (r < 0) {
+               _E("fail to alarmmgr_init : error_code : %d", r);
+               assert(0);
+       }
 }
 
-static int _watch_core_low_memory(void *event_info, void *data)
+static char *__get_timezone(void)
 {
-       Eina_List *l;
-       app_event_handler_h handler;
-       struct app_event_info event;
+       char buf[TIMEZONE_BUFFER_MAX] = {0,};
+       ssize_t len = readlink(LOCAL_TIME_PATH, buf, sizeof(buf) - 1);
 
-       _I("watch_app_low_memory");
+       if (len != -1)
+               buf[len] = '\0';
+       else  /* handle error condition */
+               return vconf_get_str(VCONFKEY_SETAPPL_TIMEZONE_ID);
 
-       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);
-       }
-
-       return APP_ERROR_NONE;
+       return strdup(buf + 20);
 }
 
-static int _watch_core_low_battery(void *event_info, void *data)
+static void __get_timeinfo(struct _watch_time_s *timeinfo)
 {
-       Eina_List *l;
-       app_event_handler_h handler;
-       struct app_event_info event;
+       UErrorCode status = U_ZERO_ERROR;
+       struct timeval current;
+       char *timezone;
+       UCalendar *cal;
 
-       _I("watch_app_low_battery");
+       /* UTC time */
+       gettimeofday(&current, NULL);
+       timeinfo->timestamp = current.tv_sec;
 
-       event.type = APP_EVENT_LOW_BATTERY;
-       event.value = event_info;
+       /* Time zone */
+       timezone = __get_timezone();
+       UChar utf16_timezone[64] = {0};
+       u_uastrncpy(utf16_timezone, timezone, 64);
+
+       /* Local time */
+       cal = ucal_open(utf16_timezone, u_strlen(utf16_timezone),
+                       uloc_getDefault(), UCAL_TRADITIONAL, &status);
+       if (cal == NULL)
+               return;
 
-       EINA_LIST_FOREACH(handler_list[APP_EVENT_LOW_BATTERY], l, handler) {
-               handler->cb(&event, handler->data);
+       timeinfo->year = ucal_get(cal, UCAL_YEAR, &status);
+       timeinfo->month = ucal_get(cal, UCAL_MONTH, &status) + 1;
+       timeinfo->day = ucal_get(cal, UCAL_DATE, &status);
+       timeinfo->day_of_week = ucal_get(cal, UCAL_DAY_OF_WEEK, &status);
+       timeinfo->hour = ucal_get(cal, UCAL_HOUR_OF_DAY, &status);
+       timeinfo->hour24 = ucal_get(cal, UCAL_HOUR_OF_DAY, &status);
+       timeinfo->minute = ucal_get(cal, UCAL_MINUTE, &status);
+       timeinfo->second = ucal_get(cal, UCAL_SECOND, &status);
+       timeinfo->millisecond = ucal_get(cal, UCAL_MILLISECOND, &status);
+       timeinfo->timezone = timezone;
+
+       timeinfo->hour -= (timeinfo->hour > 12) ? 12 : 0;
+       timeinfo->hour = (timeinfo->hour == 0) ? 12 : timeinfo->hour;
+
+       ucal_clear(cal);
+       ucal_close(cal);
+}
+
+static double __get_next_tick_sec()
+{
+       double cur_time_in_milli;
+       double term = 1.0;
+       double sec = 1.0;
+       int idx;
+       struct _watch_time_s timeinfo;
+
+       __get_timeinfo(&timeinfo);
+       cur_time_in_milli = timeinfo.hour24 * 60 * 60 * 1000 + timeinfo.minute * 60 * 1000 +
+                       timeinfo.minute * 60 * 1000 + timeinfo.second * 1000 + timeinfo.millisecond;
+
+       if (app_tick_type == WATCH_APP_TIME_TICKS_PER_SECOND) {
+               term = (double)ONE_SECOND / (double)app_tick_resolution;
+       } else if (app_tick_type == WATCH_APP_TIME_TICKS_PER_MINUTE) {
+               term = (double)ONE_MINUTE_IN_SEC / (double)app_tick_resolution;
+               term *= 1000;
+       } else if (app_tick_type == WATCH_APP_TIME_TICKS_PER_HOUR) {
+               term = (double)ONE_HOUR_IN_SEC / (double)app_tick_resolution;
+               term *= 1000;
        }
 
-       return APP_ERROR_NONE;
+       idx = cur_time_in_milli / term;
+       sec = (((idx + 1) * term) - cur_time_in_milli) / 1000.0;
+
+       return sec;
 }
 
-static int _watch_core_lang_changed(void *event_info, void *data)
+static int __get_ambient_tick_offset(struct _watch_time_s timeinfo, int interval, int minute_base, int hour_base)
 {
-       Eina_List *l;
-       app_event_handler_h handler;
-       struct app_event_info event;
+       int remain_hour = 0;
+       int remain_min = 0;
+       int offset_sec = 0;
 
-       _I("_watch_core_lang_changed");
+       if (hour_base != 0) {
+               if (interval == ONE_DAY_IN_SEC) {
+                       remain_hour = hour_base - timeinfo.hour24;
+                       if (remain_hour < 0)
+                               remain_hour += 24;
+                       remain_min = remain_hour * 60 - timeinfo.minute;
+                       offset_sec = remain_min * ONE_MINUTE_IN_SEC - timeinfo.second;
+               } else {
+                       remain_hour = hour_base - (timeinfo.hour24 % hour_base);
+                       remain_min = remain_hour * 60 - timeinfo.minute;
+                       offset_sec = remain_min * ONE_MINUTE_IN_SEC - timeinfo.second;
+               }
+       } else {
+               remain_min = minute_base - (timeinfo.minute % minute_base);
+               offset_sec = remain_min * ONE_MINUTE_IN_SEC - timeinfo.second;
+       }
+       return offset_sec;
+}
 
-       event.type = APP_EVENT_LANGUAGE_CHANGED;
-       event.value = event_info;
+/* LCOV_EXCL_START */
+static int __ambient_tick_cb(alarm_id_t id, void *data)
+{
+       struct _watch_time_s timeinfo;
+
+       __get_timeinfo(&timeinfo);
+       __on_ambient_tick(&timeinfo, data);
+
+       return 0;
+}
+/* LCOV_EXCL_STOP */
 
-       EINA_LIST_FOREACH(handler_list[APP_EVENT_LANGUAGE_CHANGED], l,
-                       handler) {
-               handler->cb(&event, handler->data);
+static int __set_ambient_tick_cb(void *data)
+{
+       int offset_sec = 0;
+       int interval = 0;
+       struct _watch_time_s timeinfo;
+       int r;
+       struct ambient_tick_type_info info;
+
+       __get_timeinfo(&timeinfo);
+       info = ambient_tick_type_infos[ambient_tick_type];
+       interval = info.interval;
+
+       if (interval == 0) {
+               __on_ambient_tick(&timeinfo, data);
+       } else {
+               offset_sec = __get_ambient_tick_offset(timeinfo, info.interval,
+                               info.minute_base, info.hour_base);
+               _D("next time tick: %d", offset_sec);
+
+               /* Set a next alarm */
+               r = alarmmgr_add_alarm_withcb(ALARM_TYPE_VOLATILE, offset_sec, interval,
+                               __ambient_tick_cb, data, &alarm_id);
+               if (r < 0)
+                       _E("fail to alarmmgr_add_alarm_withcb : error_code : %d", r);
        }
 
-       return APP_ERROR_NONE;
+       return 0;
 }
 
-static int _watch_core_region_changed(void *event_info, void *data)
+/* LCOV_EXCL_START */
+static int __signal_alpm_handler(int ambient, void *data)
 {
-       Eina_List *l;
-       app_event_handler_h handler;
-       struct app_event_info event;
+       _D("_signal_alpm_handler: ambient: %d", ambient);
 
-       _I("_ui_app_appcore_region_changed");
+       if (__context.ambient_mode == ambient) {
+               _E("invalid state");
+               return 0;
+       }
+
+       /* Enter the ambient mode */
+       if (ambient) {
+               if (appcore_ui_base_is_resumed()) {
+                       appcore_ui_base_on_pause();
+                       __context.ambient_mode_skip_resume = false;
+               } else {
+                       __context.ambient_mode_skip_resume = true;
+               }
+
+               __context.ambient_mode = true;
+               __on_ambient_changed(1, data);
 
-       event.type = APP_EVENT_REGION_FORMAT_CHANGED;
-       event.value = event_info;
+               if (__context.callback.ambient_tick)
+                       __set_ambient_tick_cb(data);
+
+               /* Send a update done signal */
+               _watch_core_send_alpm_update_done();
+       } else { /* Exit the ambient mode */
+               __context.ambient_mode = false;
+               __on_ambient_changed(0, data);
+
+               _D("Resume check: %d", __context.ambient_mode_skip_resume);
+               if (!__context.ambient_mode_skip_resume) {
+                       _D("Call the resume after ambient mode changed");
+                       appcore_ui_base_resume();
+               }
 
-       EINA_LIST_FOREACH(handler_list[APP_EVENT_REGION_FORMAT_CHANGED], l,
-                       handler) {
-               handler->cb(&event, handler->data);
+               /* Disable alarm */
+               if (alarm_id) {
+                       alarmmgr_remove_alarm(alarm_id);
+                       alarm_id = 0;
+               }
        }
 
-       return APP_ERROR_NONE;
+       return 0;
 }
+/* LCOV_EXCL_STOP */
 
-static void _watch_core_set_appcore_event_cb(
-               struct watch_app_context *app_context)
+static Eina_Bool __time_tick_cb(void *data)
 {
-       watch_core_set_event_callback(WATCH_CORE_EVENT_LOW_MEMORY,
-                       _watch_core_low_memory, app_context);
-       watch_core_set_event_callback(WATCH_CORE_EVENT_LANG_CHANGE,
-                       _watch_core_lang_changed, app_context);
-       watch_core_set_event_callback(WATCH_CORE_EVENT_REGION_CHANGE,
-                       _watch_core_region_changed, app_context);
+       struct _watch_time_s timeinfo;
+       double sec;
+
+       __get_timeinfo(&timeinfo);
 
-       if (eina_list_count(handler_list[APP_EVENT_LOW_BATTERY]) > 0)
-               watch_core_set_event_callback(WATCH_CORE_EVENT_LOW_BATTERY,
-                               _watch_core_low_battery, app_context);
+       /* Set a next timer */
+       sec = __get_next_tick_sec();
+       watch_tick = ecore_timer_add(sec, __time_tick_cb, data);
+       __on_time_tick(&timeinfo, data);
+
+       return ECORE_CALLBACK_CANCEL;
 }
 
-static void _watch_core_unset_appcore_event_cb(void)
+static void __time_tick_cancel(void)
 {
-       watch_core_set_event_callback(WATCH_CORE_EVENT_LOW_MEMORY, NULL, NULL);
-       watch_core_set_event_callback(WATCH_CORE_EVENT_LANG_CHANGE, NULL, NULL);
-       watch_core_set_event_callback(WATCH_CORE_EVENT_REGION_CHANGE, NULL,
-                       NULL);
-
-       if (eina_list_count(handler_list[APP_EVENT_LOW_BATTERY]) > 0)
-               watch_core_set_event_callback(WATCH_CORE_EVENT_LOW_BATTERY,
-                               NULL, NULL);
+       if (watch_tick) {
+               ecore_timer_del(watch_tick);
+               watch_tick = NULL;
+       }
 }
 
-static int _watch_core_create(int w, int h, void *data)
+static int __on_create(void *data)
 {
-       struct watch_app_context *app_context = data;
        watch_app_create_cb create_cb;
 
        _W("_watch_core_create");
 
-       if (app_context == NULL)
-               return watch_app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__,
-                               NULL);
-
-       watch_core_initialized = 1;
-       _watch_core_set_appcore_event_cb(app_context);
+       screen_connector_provider_init();
+       _watch_core_listen_alpm_handler(__signal_alpm_handler, data);
 
-       create_cb = app_context->callback->create;
+       create_cb = __context.callback.create;
 
-       if (create_cb == NULL || create_cb(w, h, app_context->data) == false)
+       appcore_ui_base_on_create();
+       if (create_cb == NULL || create_cb(__context.width, __context.height, __context.data) == false)
                return watch_app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__,
                                "watch_app_create_cb() returns false");
 
-       app_context->state = WATCH_APP_STATE_RUNNING;
+       /* Alarm init */
+       __alarm_init();
+       __context.state = WATCH_APP_STATE_RUNNING;
 
        return APP_ERROR_NONE;
 }
 
-static int _watch_core_control(app_control_h app_control, void *data)
+static int __on_control(bundle *b, void *data)
 {
-       struct watch_app_context *app_context = data;
-       watch_app_control_cb app_control_cb;
+       app_control_h app_control = NULL;
+       appcore_ui_base_on_control(b);
 
        _W("_watch_core_control");
 
-       if (app_context == NULL)
-               return watch_app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__,
-                               NULL);
+       if (app_control_create_event(b, &app_control) != 0)
+               return -1;
 
-       app_control_cb = app_context->callback->app_control;
+       if (__context.callback.app_control)
+               __context.callback.app_control(app_control, __context.data);
 
-       if (app_control_cb != NULL)
-               app_control_cb(app_control, app_context->data);
+       app_control_destroy(app_control);
 
        return APP_ERROR_NONE;
 }
 
 /* LCOV_EXCL_START */
-static int _watch_core_pause(void *data)
+static int __on_pause(void *data)
 {
-       struct watch_app_context *app_context = data;
-       watch_app_pause_cb pause_cb;
-
        _W("_watch_core_pause");
 
-       if (app_context == NULL)
-               return watch_app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__,
-                               NULL);
+       /* Handling the ambient mode */
+       if (__context.ambient_mode)
+               __context.ambient_mode_skip_resume = 1;
 
-       pause_cb = app_context->callback->pause;
+       /* Cancel the time_tick callback */
+       __time_tick_cancel();
 
-       if (pause_cb != NULL)
-               pause_cb(app_context->data);
+       appcore_ui_base_on_pause();
+       if (__context.callback.pause)
+               __context.callback.pause(__context.data);
 
        return APP_ERROR_NONE;
 }
 /* LCOV_EXCL_STOP */
 
-static int _watch_core_resume(void *data)
+static int __on_resume(void *data)
 {
-       struct watch_app_context *app_context = data;
-       watch_app_resume_cb resume_cb;
-
        _W("_watch_core_resume");
 
-       if (app_context == NULL)
-               return watch_app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__,
-                               NULL);
+       appcore_ui_base_on_resume();
+
+       if (__context.ambient_mode) {
+               __context.ambient_mode_skip_resume = false;
+               return 0;
+       }
 
-       resume_cb = app_context->callback->resume;
+       if (__context.callback.resume)
+               __context.callback.resume(__context.data);
 
-       if (resume_cb != NULL)
-               resume_cb(app_context->data);
+       if (!watch_tick) {
+               __time_tick_cb(data);
+       } else {
+               __time_tick_cancel();
+               __time_tick_cb(data);
+       }
 
        return APP_ERROR_NONE;
 }
 
-static int _watch_core_terminate(void *data)
+static int __on_terminate(void *data)
 {
-       struct watch_app_context *app_context = data;
-       watch_app_terminate_cb terminate_cb;
-
        _W("_watch_core_terminate");
 
-       if (app_context == NULL)
-               return watch_app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__,
-                               NULL);
-
-       terminate_cb = app_context->callback->terminate;
+       if (appcore_ui_base_is_resumed())
+               appcore_ui_base_pause();
 
-       if (terminate_cb != NULL)
-               terminate_cb(app_context->data);
+       /* Cancel the time_tick callback */
+       __time_tick_cancel();
 
-       _watch_core_unset_appcore_event_cb();
+       if (__context.callback.terminate)
+               __context.callback.terminate(__context.data);
 
-       if (_initialized)
-               _free_handler_list();
+       alarmmgr_fini();
+       appcore_ui_base_on_terminate();
+       screen_connector_provider_fini();
 
        return APP_ERROR_NONE;
 }
 
-static void _watch_core_time_tick(void *watchtime, void *data)
+static void __on_time_tick(void *watchtime, void *data)
 {
-       struct watch_app_context *app_context = data;
        watch_app_time_tick_cb time_tick_cb;
 
        _I("_watch_core_time_tick");
 
-       if (app_context == NULL)
-               return;
-
-       time_tick_cb = app_context->callback->time_tick;
+       time_tick_cb = __context.callback.time_tick;
 
        if (time_tick_cb != NULL)
-               time_tick_cb((watch_time_h)watchtime, app_context->data);
+               time_tick_cb((watch_time_h)watchtime, __context.data);
 }
 
 /* LCOV_EXCL_START */
-static void _watch_core_ambient_tick(void *watchtime, void *data)
+static void __on_ambient_tick(void *watchtime, void *data)
 {
-       struct watch_app_context *app_context = data;
        watch_app_ambient_tick_cb ambient_tick_cb;
 
        _W("_watch_core_ambient_tick");
 
-       if (app_context == NULL)
-               return;
-
-       ambient_tick_cb = app_context->callback->ambient_tick;
+       ambient_tick_cb = __context.callback.ambient_tick;
 
        if (ambient_tick_cb != NULL)
-               ambient_tick_cb((watch_time_h)watchtime, app_context->data);
+               ambient_tick_cb((watch_time_h)watchtime, __context.data);
 }
 /* LCOV_EXCL_STOP */
 
 /* LCOV_EXCL_START */
-static void _watch_core_ambient_changed(int ambient, void *data)
+static void __on_ambient_changed(int ambient, void *data)
 {
-       struct watch_app_context *app_context = data;
        watch_app_ambient_changed_cb ambient_changed_cb;
 
        _W("_watch_core_ambient_changed: %d", ambient);
 
-       if (app_context == NULL)
-               return;
-
-       ambient_changed_cb = app_context->callback->ambient_changed;
+       ambient_changed_cb = __context.callback.ambient_changed;
 
        if (ambient_changed_cb != NULL)
-               ambient_changed_cb((bool)ambient, app_context->data);
+               ambient_changed_cb((bool)ambient, __context.data);
 }
 /* LCOV_EXCL_STOP */
 
+static void __on_window_show(int type, void *event, void *data)
+{
+       appcore_ui_base_window_on_show(type, event);
+       appcore_ui_base_resume();
+}
+
+static int __set_ambient_tick_type(watch_app_ambient_tick_type_e type)
+{
+       _D("set ambient tick type : %d", type);
+       ambient_tick_type = type;
+
+       if (alarm_id) {
+               alarmmgr_remove_alarm(alarm_id);
+               alarm_id = 0;
+               __set_ambient_tick_cb(NULL);
+       }
+       return 0;
+}
+
+static int __get_ambient_tick_type(watch_app_ambient_tick_type_e *type)
+{
+       *type = ambient_tick_type;
+       return 0;
+}
+
+static int __set_time_tick_frequency(int ticks, watch_app_time_tick_resolution_e type)
+{
+       double sec = 1.0;
+       struct _watch_time_s timeinfo;
+
+       _D("ticks: %d, type: %d", ticks, type);
+       ecore_timer_precision_set(0.0000001);
+       __time_tick_cancel();
+
+       app_tick_type = type;
+       app_tick_resolution = ticks;
+
+       sec = __get_next_tick_sec();
+       /* Set a next timer */
+       watch_tick = ecore_timer_add(sec, __time_tick_cb, NULL);
+       _D("next time tick: %f", sec);
+
+       if (appcore_ui_base_is_resumed()) {
+               __get_timeinfo(&timeinfo);
+               __on_time_tick(&timeinfo, NULL);
+       }
+
+       return 0;
+}
+
+static int __get_time_tick_frequency(int *ticks, watch_app_time_tick_resolution_e *type)
+{
+       *ticks = app_tick_resolution;
+       *type = app_tick_type;
+       return 0;
+}
+
 EXPORT_API int watch_app_main(int argc, char **argv,
                watch_app_lifecycle_callback_s *callback, void *user_data)
 {
-       struct watch_app_context app_context = {
-               .appid = NULL,
-               .state = WATCH_APP_STATE_NOT_RUNNING,
-               .callback = callback,
-               .data = user_data
-       };
-
-       struct watchcore_ops watchcore_context = {
-               .data = &app_context,
-               .create = _watch_core_create,
-               .app_control = _watch_core_control,
-               .pause = _watch_core_pause,
-               .resume = _watch_core_resume,
-               .terminate = _watch_core_terminate,
-               .time_tick = _watch_core_time_tick,
-               .ambient_tick = _watch_core_ambient_tick,
-               .ambient_changed = _watch_core_ambient_changed,
-       };
+       int ret;
+       bundle *kb;
+       char *width_str = NULL;
+       char *height_str = NULL;
+       int width = 360;
+       int height = 360;
+       appcore_ui_base_ops ops = appcore_ui_base_get_default_ops();
+
+       /* override methods */
+       ops.base.create = __on_create;
+       ops.base.control = __on_control;
+       ops.base.terminate = __on_terminate;
+       ops.pause = __on_pause;
+       ops.resume = __on_resume;
+       ops.window.show = __on_window_show;
+
+       kb = bundle_import_from_argv(argc, argv);
+       if (kb) {
+               bundle_get_str(kb, "WATCH_WIDTH", &width_str);
+               bundle_get_str(kb, "WATCH_HEIGHT", &height_str);
+
+               if (width_str)
+                       width = atoi(width_str);
+
+               if (height_str)
+                       height = atoi(height_str);
+
+               bundle_free(kb);
+       } else {
+               _E("failed to get launch argv");
+       }
 
        if (argc <= 0 || argv == NULL || callback == NULL)
                return watch_app_error(APP_ERROR_INVALID_PARAMETER,
@@ -398,19 +635,33 @@ EXPORT_API int watch_app_main(int argc, char **argv,
                                "watch_app_create_cb() callback must be "
                                "registered");
 
-       if (app_context.state != WATCH_APP_STATE_NOT_RUNNING)
+       if (__context.state != WATCH_APP_STATE_NOT_RUNNING)
                return watch_app_error(APP_ERROR_ALREADY_RUNNING, __FUNCTION__,
                                NULL);
 
-       if (app_get_id(&(app_context.appid)) != APP_ERROR_NONE)
+       if (app_get_id(&(__context.appid)) != APP_ERROR_NONE)
                return watch_app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__,
                                "failed to get the appid");
 
-       app_context.state = WATCH_APP_STATE_CREATING;
-
-       watch_core_main(app_context.appid, argc, argv, &watchcore_context);
+       __context.callback = *callback;
+       __context.width = width;
+       __context.height = height;
+       __context.ambient_mode = false;
+       __context.ambient_mode_skip_resume = false;
+       __context.data = user_data;
+       __context.state = WATCH_APP_STATE_CREATING;
+
+       ret = appcore_ui_base_init(ops, argc, argv, NULL, 0);
+       free(__context.appid);
+       __context.appid = NULL;
+
+       if (ret < 0) {
+               __context.state = WATCH_APP_STATE_NOT_RUNNING;
+               return watch_app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, NULL);
+       }
 
-       free(app_context.appid);
+       appcore_ui_base_fini();
+       __context.state = WATCH_APP_STATE_NOT_RUNNING;
 
        return APP_ERROR_NONE;
 }
@@ -418,7 +669,20 @@ EXPORT_API int watch_app_main(int argc, char **argv,
 EXPORT_API void watch_app_exit(void)
 {
        _I("watch_app_exit");
-       watch_core_terminate();
+       appcore_ui_base_exit();
+}
+
+static int __event_cb(void *event, void *data)
+{
+       app_event_handler_h handler = data;
+       struct app_event_info app_event;
+
+       app_event.type = handler->type;
+       app_event.value = event;
+       if (handler->cb)
+               handler->cb(&app_event, handler->data);
+
+       return 0;
 }
 
 EXPORT_API int watch_app_add_event_handler(app_event_handler_h *event_handler,
@@ -426,12 +690,6 @@ EXPORT_API int watch_app_add_event_handler(app_event_handler_h *event_handler,
                void *user_data)
 {
        app_event_handler_h handler;
-       Eina_List *l_itr;
-
-       if (!_initialized) {
-               eina_init();
-               _initialized = 1;
-       }
 
        if (event_handler == NULL || callback == NULL)
                return watch_app_error(APP_ERROR_INVALID_PARAMETER,
@@ -442,12 +700,6 @@ EXPORT_API int watch_app_add_event_handler(app_event_handler_h *event_handler,
                return watch_app_error(APP_ERROR_INVALID_PARAMETER,
                                __FUNCTION__, NULL);
 
-       EINA_LIST_FOREACH(handler_list[event_type], l_itr, handler) {
-               if (handler->cb == callback)
-                       return watch_app_error(APP_ERROR_INVALID_PARAMETER,
-                                       __FUNCTION__, NULL);
-       }
-
        handler = calloc(1, sizeof(struct app_event_handler));
        if (!handler)
                return watch_app_error(APP_ERROR_OUT_OF_MEMORY, __FUNCTION__,
@@ -456,15 +708,7 @@ EXPORT_API int watch_app_add_event_handler(app_event_handler_h *event_handler,
        handler->type = event_type;
        handler->cb = callback;
        handler->data = user_data;
-
-       if (watch_core_initialized
-                       && event_type == APP_EVENT_LOW_BATTERY
-                       && eina_list_count(handler_list[event_type]) == 0)
-               watch_core_set_event_callback(WATCH_CORE_EVENT_LOW_BATTERY,
-                               _watch_core_low_battery, NULL);
-
-       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;
 
@@ -473,61 +717,42 @@ EXPORT_API int watch_app_add_event_handler(app_event_handler_h *event_handler,
 
 EXPORT_API int watch_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 watch_app_error(APP_ERROR_INVALID_PARAMETER,
                                __FUNCTION__, NULL);
 
-       if (!_initialized) {
-               _I("handler list is not initialized");
-               return APP_ERROR_NONE;
-       }
-
        type = event_handler->type;
        if (type < APP_EVENT_LOW_MEMORY ||
                        type > APP_EVENT_REGION_FORMAT_CHANGED)
                return watch_app_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);
+       if (ret < 0)
+               return watch_app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, "invalid raw handler");
 
-                       if (watch_core_initialized
-                               && type == APP_EVENT_LOW_BATTERY
-                               && eina_list_count(handler_list[type]) == 0)
-                               watch_core_set_event_callback(
-                                               WATCH_CORE_EVENT_LOW_BATTERY,
-                                               NULL, NULL);
+       free(event_handler);
 
-                       return APP_ERROR_NONE;
-               }
-       }
-
-       return watch_app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__,
-                       "cannot find such handler");
+       return APP_ERROR_NONE;
 }
 
 EXPORT_API int watch_time_get_current_time(watch_time_h *watch_time)
 {
-       struct watch_time_s *time_info;
+       struct _watch_time_s *time_info;
 
        if (watch_time == NULL)
                return watch_app_error(APP_ERROR_INVALID_PARAMETER,
                                __FUNCTION__, NULL);
 
-       time_info = calloc(1, sizeof(struct watch_time_s));
+       time_info = calloc(1, sizeof(struct _watch_time_s));
        if (time_info == NULL)
                return watch_app_error(APP_ERROR_OUT_OF_MEMORY, __FUNCTION__,
                                "failed to create a handle");
 
-       watch_core_get_timeinfo(time_info);
+       __get_timeinfo(time_info);
 
        *watch_time = (struct _watch_time_s *)time_info;
 
@@ -692,7 +917,7 @@ EXPORT_API int watch_app_get_elm_win(Evas_Object **win)
                return watch_app_error(APP_ERROR_INVALID_PARAMETER,
                                __FUNCTION__, NULL);
 
-       ret_win = elm_win_add(NULL, watch_core_get_appid(), ELM_WIN_BASIC);
+       ret_win = elm_win_add(NULL, __context.appid, ELM_WIN_BASIC);
        if (ret_win == NULL)
                return watch_app_error(APP_ERROR_OUT_OF_MEMORY, __FUNCTION__,
                                NULL);
@@ -702,7 +927,7 @@ EXPORT_API int watch_app_get_elm_win(Evas_Object **win)
                _E("failed to get surface");
 
        surface = ecore_wl_window_surface_get(wl_win);
-       remote = screen_connector_provider_create(watch_core_get_appid(),
+       remote = screen_connector_provider_create(__context.appid,
                        surface);
        screen_connector_provider_set_event_filter(remote,
                        SCREEN_CONNECTOR_INPUT_TYPE_MOUSE_MOVE_X_Y |
@@ -716,26 +941,26 @@ EXPORT_API int watch_app_set_ambient_tick_type(watch_app_ambient_tick_type_e typ
 {
        if (type < WATCH_APP_AMBIENT_TICK_NO_TICK || type > WATCH_APP_AMBIENT_TICK_EVERY_DAY)
                return APP_ERROR_INVALID_PARAMETER;
-       return watch_core_set_ambient_tick_type(type);
+       return __set_ambient_tick_type(type);
 }
 
 EXPORT_API int watch_app_get_ambient_tick_type(watch_app_ambient_tick_type_e *type)
 {
        if (type == NULL)
                return APP_ERROR_INVALID_PARAMETER;
-       return watch_core_get_ambient_tick_type(type);
+       return __get_ambient_tick_type(type);
 }
 
 EXPORT_API int watch_app_set_time_tick_frequency(int ticks, watch_app_time_tick_resolution_e type)
 {
        if (type < WATCH_APP_TIME_TICKS_PER_SECOND || type > WATCH_APP_TIME_TICKS_PER_HOUR)
                return APP_ERROR_INVALID_PARAMETER;
-       return watch_core_set_time_tick_frequency(ticks, type);
+       return __set_time_tick_frequency(ticks, type);
 }
 
 EXPORT_API int watch_app_get_time_tick_frequency(int *ticks, watch_app_time_tick_resolution_e *type)
 {
        if (type == NULL || ticks == NULL)
                return APP_ERROR_INVALID_PARAMETER;
-       return watch_core_get_time_tick_frequency(ticks, type);
+       return __get_time_tick_frequency(ticks, type);
 }