Refactor appcore-watch 24/180124/7
authorJunghoon Park <jh9216.park@samsung.com>
Fri, 25 May 2018 04:28:23 +0000 (13:28 +0900)
committerJunghoon Park <jh9216.park@samsung.com>
Fri, 15 Jun 2018 04:35:39 +0000 (13:35 +0900)
- Make reusable library, appcore-watch-base which has no dependency with
  elementary

Change-Id: I347fd69636c669ab9ec47580a3d51c5fad6c4aa3
Signed-off-by: Junghoon Park <jh9216.park@samsung.com>
20 files changed:
CMakeLists.txt
appcore-watch-base.pc.in [new file with mode: 0644]
appcore-watch.pc.in
capi-appfw-watch-application.pc
include/watch_base.h [new file with mode: 0755]
packaging/appcore-watch.spec
src/appcore-watch-log.h [deleted file]
src/appcore-watch-signal.c [deleted file]
src/appcore-watch-signal.h [deleted file]
src/base/watch_base.c [new file with mode: 0755]
src/base/watch_base_log.h [new file with mode: 0755]
src/base/watch_base_signal.c [new file with mode: 0755]
src/base/watch_base_signal.h [new file with mode: 0755]
src/base/watch_base_time.c [new file with mode: 0755]
src/base/watch_base_time.h [new file with mode: 0755]
src/efl_base/watch_app_log.h [new file with mode: 0755]
src/efl_base/watch_app_main.c [new file with mode: 0755]
src/watch_app_error.c [deleted file]
src/watch_app_main.c [deleted file]
src/watch_app_private.h [deleted file]

index 0ca14fc0a925a6a576c74b05edeee9257d794292..cabef15db2bbd0ed434afa902b0817f1d6883905 100644 (file)
@@ -17,19 +17,20 @@ SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
 SET(CMAKE_SKIP_BUILD_RPATH TRUE)
 
 #################################################################
-# Build appcore-watch Library
+# Build appcore-watch-base Library
 # ------------------------------
-SET(APPCORE_WATCH "appcore-watch")
+SET(APPCORE_WATCH_BASE "appcore-watch-base")
+SET(SOURCES_base src/base/watch_base_signal.c src/base/watch_base.c src/base/watch_base_time.c)
 
 INCLUDE(FindPkgConfig)
-pkg_check_modules(pkg_watch REQUIRED
+pkg_check_modules(pkg_watch_base REQUIRED
                aul
                dlog
                alarm-service
                capi-appfw-app-control
                capi-appfw-app-common
                vconf
-               elementary
+               ecore
                ecore-wl2
                vconf-internal-keys
                libtzplatform-config
@@ -39,20 +40,49 @@ pkg_check_modules(pkg_watch REQUIRED
                gio-2.0
                screen_connector_provider
                appcore-common
-               appcore-efl
+               appcore-ui
                pkgmgr-info
                capi-system-info
                )
+FOREACH(flag ${pkg_watch_base_CFLAGS})
+       SET(EXTRA_CFLAGS_watch_base "${EXTRA_CFLAGS_watch_base} ${flag}")
+ENDFOREACH(flag)
+
+ADD_LIBRARY(${APPCORE_WATCH_BASE} SHARED ${SOURCES_base})
+SET_TARGET_PROPERTIES(${APPCORE_WATCH_BASE} PROPERTIES SOVERSION ${MAJORVER})
+SET_TARGET_PROPERTIES(${APPCORE_WATCH_BASE} PROPERTIES VERSION ${FULLVER})
+SET_TARGET_PROPERTIES(${APPCORE_WATCH_BASE} PROPERTIES COMPILE_FLAGS ${EXTRA_CFLAGS_watch_base})
+TARGET_LINK_LIBRARIES(${APPCORE_WATCH_BASE} ${pkg_watch_base_LDFLAGS} "-ldl -Wl,--no-undefined")
+
+CONFIGURE_FILE(${APPCORE_WATCH_BASE}.pc.in ${APPCORE_WATCH_BASE}.pc @ONLY)
+
+INSTALL(TARGETS ${APPCORE_WATCH_BASE} DESTINATION ${LIB_INSTALL_DIR} COMPONENT RuntimeLibraries)
+INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${APPCORE_WATCH_BASE}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
+
+#################################################################
+# Build appcore-watch Library
+# ------------------------------
+SET(APPCORE_WATCH "appcore-watch")
+SET(SOURCES_efl src/efl_base/watch_app_main.c)
+
+INCLUDE(FindPkgConfig)
+pkg_check_modules(pkg_watch REQUIRED
+               dlog
+               capi-appfw-app-control
+               capi-appfw-app-common
+               elementary
+               ecore-wl2
+               screen_connector_provider
+               )
 FOREACH(flag ${pkg_watch_CFLAGS})
        SET(EXTRA_CFLAGS_watch "${EXTRA_CFLAGS_watch} ${flag}")
 ENDFOREACH(flag)
 
-AUX_SOURCE_DIRECTORY(src SOURCES)
-ADD_LIBRARY(${APPCORE_WATCH} SHARED ${SOURCES})
+ADD_LIBRARY(${APPCORE_WATCH} SHARED ${SOURCES_efl})
 SET_TARGET_PROPERTIES(${APPCORE_WATCH} PROPERTIES SOVERSION ${MAJORVER})
 SET_TARGET_PROPERTIES(${APPCORE_WATCH} PROPERTIES VERSION ${FULLVER})
 SET_TARGET_PROPERTIES(${APPCORE_WATCH} PROPERTIES COMPILE_FLAGS ${EXTRA_CFLAGS_watch})
-TARGET_LINK_LIBRARIES(${APPCORE_WATCH} ${pkg_watch_LDFLAGS} "-ldl -Wl,--no-undefined")
+TARGET_LINK_LIBRARIES(${APPCORE_WATCH} ${pkg_watch_LDFLAGS} ${APPCORE_WATCH_BASE} "-ldl -Wl,--no-undefined")
 
 CONFIGURE_FILE(${APPCORE_WATCH}.pc.in ${APPCORE_WATCH}.pc @ONLY)
 
@@ -62,4 +92,4 @@ INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${APPCORE_WATCH}.pc DESTINATION ${LIB_
 INSTALL(DIRECTORY ${CMAKE_SOURCE_DIR}/include/ DESTINATION include/appcore-watch/
        FILES_MATCHING
        PATTERN "*.h"
-       )
+       )
\ No newline at end of file
diff --git a/appcore-watch-base.pc.in b/appcore-watch-base.pc.in
new file mode 100644 (file)
index 0000000..0bb582c
--- /dev/null
@@ -0,0 +1,13 @@
+# Package Information for pkg-config
+
+prefix=@PREFIX@
+exec_prefix=@EXEC_PREFIX@
+libdir=@LIBDIR@
+includedir=@INCLUDEDIR@
+
+Name: appcore-watch-base
+Description: Watch base library
+Version: @FULLVER@
+Requires: aul dlog capi-appfw-app-control
+Libs: -L${libdir} -lappcore-watch-base
+Cflags: -I${includedir} -I${includedir}/appcore-watch
index a87f0823e63e9d6a47072eeb9bf7535978b01874..8bdb40606f237d44e39d1ebf26bc696b9bf65a48 100644 (file)
@@ -8,6 +8,6 @@ includedir=@INCLUDEDIR@
 Name: appcore-watch
 Description: appcore watch library
 Version: @FULLVER@
-Requires: aul dlog capi-appfw-app-control
+Requires: aul dlog capi-appfw-app-control appcore-watch-base
 Libs: -L${libdir} -lappcore-watch
 Cflags: -I${includedir} -I${includedir}/appcore-watch
index 87fa58512ff842ffcb1b12a0b22d2aa9c4429d78..dc37e120eea1c332f5a248cd7f393c54051100a3 100644 (file)
@@ -8,6 +8,7 @@ includedir=${prefix}/include
 Name: appcore-watch
 Description: watch application library
 Version: 1.1
-Requires: aul dlog capi-appfw-app-control capi-appfw-app-common
+Requires.private: aul dlog capi-appfw-app-control capi-appfw-app-common
+Requires: appcore-watch-base
 Libs: -L${libdir} -lappcore-watch
 Cflags: -I${includedir} -I${includedir}/appcore-watch
diff --git a/include/watch_base.h b/include/watch_base.h
new file mode 100755 (executable)
index 0000000..96414b1
--- /dev/null
@@ -0,0 +1,124 @@
+/*
+ * Copyright (c) 2018 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_WATCH_BASE_H__
+#define __TIZEN_APPFW_WATCH_BASE_H__
+
+#include <tizen.h>
+#include <time.h>
+#include <app_control.h>
+#include <app_common.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct _watch_base_time_s *watch_base_time_h;
+
+typedef bool (*watch_base_create_cb) (int width, int height, void *user_data);
+typedef void (*watch_base_control_cb) (app_control_h app_control, void *user_data);
+typedef void (*watch_base_pause_cb) (void *user_data);
+typedef void (*watch_base_resume_cb) (void *user_data);
+typedef void (*watch_base_preresume_cb) (void *user_data);
+typedef void (*watch_base_terminate_cb) (void *user_data);
+typedef void (*watch_base_time_tick_cb) (watch_base_time_h watch_base_time, void *user_data);
+typedef void (*watch_base_ambient_tick_cb) (watch_base_time_h watch_base_time, void *user_data);
+typedef void (*watch_base_ambient_changed_cb) (bool ambient_mode, void *user_data);
+typedef void (*watch_base_init_cb)(int argc, char **argv, void *data);
+typedef void (*watch_base_finish_cb)(void);
+typedef void (*watch_base_run_cb)(void *data);
+typedef void (*watch_base_exit_cb)(void *data);
+
+typedef struct {
+       watch_base_create_cb create;
+       watch_base_control_cb app_control;
+       watch_base_pause_cb pause;
+       watch_base_resume_cb resume;
+       watch_base_preresume_cb preresume;
+       watch_base_terminate_cb terminate;
+       watch_base_time_tick_cb time_tick;
+       watch_base_ambient_tick_cb ambient_tick;
+       watch_base_ambient_changed_cb ambient_changed;
+       watch_base_init_cb init;
+       watch_base_finish_cb finish;
+       watch_base_run_cb run;
+       watch_base_exit_cb exit;
+} watch_base_ops;
+
+int watch_base_add_event_handler(app_event_handler_h *handler, app_event_type_e event_type, app_event_cb callback, void *user_data);
+int watch_base_remove_event_handler(app_event_handler_h event_handler);
+int watch_base_init(int argc, char **argv, watch_base_ops *callback, void *user_data);
+void watch_base_fini(void);
+void watch_base_exit(void);
+
+typedef enum {
+       WATCH_BASE_TIME_TICKS_PER_SECOND, /**< 1 ~ 60 ticks per second */
+       WATCH_BASE_TIME_TICKS_PER_MINUTE, /**< 1 ~ 60 ticks per minute */
+       WATCH_BASE_TIME_TICKS_PER_HOUR, /**< 1 ~ 60 ticks per hour */
+} watch_base_time_tick_resolution_e;
+
+int watch_base_set_time_tick_frequency(int ticks, watch_base_time_tick_resolution_e type);
+int watch_base_get_time_tick_frequency(int *ticks, watch_base_time_tick_resolution_e *type);
+int watch_base_set_error(app_error_e error, const char *function,
+               const char *description);
+bool watch_base_check_feature(void);
+const char *watch_base_get_current_appid(void);
+
+void watch_base_on_create(int width, int height);
+void watch_base_on_control(app_control_h app_control);
+void watch_base_on_pause(void);
+void watch_base_on_resume(void);
+void watch_base_on_preresume(void);
+void watch_base_on_terminate(void);
+watch_base_ops watch_base_get_default_ops(void);
+
+typedef enum {
+       WATCH_BASE_AMBIENT_TICK_NO_TICK,
+       WATCH_BASE_AMBIENT_TICK_EVERY_MINUTE,
+       WATCH_BASE_AMBIENT_TICK_EVERY_FIVE_MINUTES,
+       WATCH_BASE_AMBIENT_TICK_EVERY_FIFTEEN_MINUTES,
+       WATCH_BASE_AMBIENT_TICK_EVERY_THIRTY_MINUTES,
+       WATCH_BASE_AMBIENT_TICK_EVERY_HOUR,
+       WATCH_BASE_AMBIENT_TICK_EVERY_THREE_HOURS,
+       WATCH_BASE_AMBIENT_TICK_EVERY_SIX_HOURS,
+       WATCH_BASE_AMBIENT_TICK_EVERY_TWELVE_HOURS,
+       WATCH_BASE_AMBIENT_TICK_EVERY_DAY
+} watch_base_ambient_tick_type_e;
+
+int watch_base_set_ambient_tick_type(watch_base_ambient_tick_type_e type);
+int watch_base_get_ambient_tick_type(watch_base_ambient_tick_type_e *type);
+int watch_base_time_get_current_time(watch_base_time_h *watch_base_time);
+int watch_base_time_delete(watch_base_time_h watch_base_time);
+int watch_base_time_get_year(watch_base_time_h watch_base_time, int *year);
+int watch_base_time_get_month(watch_base_time_h watch_base_time, int *month);
+int watch_base_time_get_day(watch_base_time_h watch_base_time, int *day);
+int watch_base_time_get_day_of_week(watch_base_time_h watch_base_time, int *day_of_week);
+int watch_base_time_get_hour(watch_base_time_h watch_base_time, int *hour);
+int watch_base_time_get_hour24(watch_base_time_h watch_base_time, int *hour24);
+int watch_base_time_get_minute(watch_base_time_h watch_base_time, int *minute);
+int watch_base_time_get_second(watch_base_time_h watch_base_time, int *second);
+int watch_base_time_get_millisecond(watch_base_time_h watch_base_time, int *millisecond);
+int watch_base_time_get_utc_time(watch_base_time_h watch_base_time, struct tm *utc_time);
+int watch_base_time_get_utc_timestamp(watch_base_time_h watch_base_time, time_t *utc_timestamp);
+int watch_base_time_get_time_zone(watch_base_time_h watch_base_time, char **time_zone_id);
+int watch_base_time_get_dst_status(watch_base_time_h watch_base_time, bool *status);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __TIZEN_APPFW_WATCH_BASE_H__ */
+
index 040c7ce3449961ca33b08bf43b42887f8cc0539c..f7cc5bdc175f51e36b87c38134986dd92953c945 100644 (file)
@@ -12,18 +12,19 @@ BuildRequires:  pkgconfig(vconf)
 BuildRequires:  pkgconfig(vconf-internal-keys)
 BuildRequires:  pkgconfig(alarm-service)
 BuildRequires:  pkgconfig(appcore-common)
-BuildRequires:  pkgconfig(appcore-efl)
+BuildRequires:  pkgconfig(appcore-ui)
 BuildRequires:  pkgconfig(capi-appfw-app-control)
 BuildRequires:  pkgconfig(capi-appfw-app-common)
-BuildRequires: pkgconfig(capi-appfw-widget-application)
-BuildRequires: pkgconfig(libtzplatform-config)
-BuildRequires: pkgconfig(icu-uc)
-BuildRequires: pkgconfig(ecore-wl2)
-BuildRequires: pkgconfig(glib-2.0)
-BuildRequires: pkgconfig(gio-2.0)
-BuildRequires: pkgconfig(screen_connector_provider)
-BuildRequires: pkgconfig(pkgmgr-info)
-BuildRequires: pkgconfig(capi-system-info)
+BuildRequires:  pkgconfig(capi-appfw-widget-application)
+BuildRequires:  pkgconfig(libtzplatform-config)
+BuildRequires:  pkgconfig(icu-uc)
+BuildRequires:  pkgconfig(ecore)
+BuildRequires:  pkgconfig(ecore-wl2)
+BuildRequires:  pkgconfig(glib-2.0)
+BuildRequires:  pkgconfig(gio-2.0)
+BuildRequires:  pkgconfig(screen_connector_provider)
+BuildRequires:  pkgconfig(pkgmgr-info)
+BuildRequires:  pkgconfig(capi-system-info)
 BuildRequires:  cmake
 Requires: amd-mod-watch
 
@@ -39,12 +40,26 @@ Requires:   %{name} = %{version}-%{release}
 appcore watch (developement files)
 
 %package -n capi-appfw-watch-application-devel
-Summary:    watch appliation
+Summary:    Watch appliation
 Group:      Development/Libraries
 Requires:    appcore-watch-devel = %{version}-%{release}
 %description -n capi-appfw-watch-application-devel
 watch application (developement files)
 
+%package -n appcore-watch-base
+Summary:    Watch base library
+Group:      Development/Libraries
+%description -n appcore-watch-base
+Watch base library
+
+%package -n appcore-watch-base-devel
+Summary:    Watch base library
+Group:      Development/Libraries
+Requires:   %{name} = %{version}-%{release}
+%description -n appcore-watch-base-devel
+Watch base library (development files)
+
+
 %prep
 %setup -q
 
@@ -95,3 +110,14 @@ cp capi-appfw-watch-application.pc %{buildroot}%{_libdir}/pkgconfig
 %{_includedir}/appcore-watch/watch_app_efl.h
 %{_libdir}/pkgconfig/capi-appfw-watch-application.pc
 %{_libdir}/libappcore-watch.so
+
+%files -n appcore-watch-base
+%manifest %{name}.manifest
+%defattr(-,root,root,-)
+%{_libdir}/libappcore-watch-base.so.*
+%license LICENSE
+
+%files -n appcore-watch-base-devel
+%{_includedir}/appcore-watch/watch_base.h
+%{_libdir}/pkgconfig/appcore-watch-base.pc
+%{_libdir}/libappcore-watch-base.so
diff --git a/src/appcore-watch-log.h b/src/appcore-watch-log.h
deleted file mode 100755 (executable)
index d9190d2..0000000
+++ /dev/null
@@ -1,80 +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 __APPFW_WATCH_LOG_H__
-#define __APPFW_WATCH_LOG_H__
-
-#include <dlog.h>
-
-#define _E(fmt, arg...) LOGE(fmt, ##arg)
-#define _I(fmt, arg...) LOGI(fmt, ##arg)
-#define _D(fmt, arg...) LOGD(fmt, ##arg)
-#define _W(fmt, arg...) LOGW(fmt, ##arg)
-
-#ifndef EXPORT_API
-#define EXPORT_API __attribute__ ((visibility("default")))
-#endif
-
-#ifndef _E
-#define _E(fmt, arg...) LOGE(fmt, ##arg)
-#endif
-
-#ifndef _I
-#define _I(...) LOGI(__VA_ARGS__)
-#endif
-
-#ifndef _D
-#define _D(...) LOGD(__VA_ARGS__)
-#endif
-
-#ifndef _W
-#define _W(...) LOGW(__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)
-
-#endif /*__APPFW_WATCH_LOG_H_ */
-
diff --git a/src/appcore-watch-signal.c b/src/appcore-watch-signal.c
deleted file mode 100755 (executable)
index 1d3408f..0000000
+++ /dev/null
@@ -1,234 +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 <dlog.h>
-#include <glib.h>
-#include <gio/gio.h>
-
-#include "appcore-watch-log.h"
-#include "appcore-watch-signal.h"
-
-#ifdef LOG_TAG
-#undef LOG_TAG
-#endif
-
-#define LOG_TAG "WATCH_CORE"
-
-#define MAX_BUFFER_SIZE                512
-
-static GDBusConnection *conn;
-static unsigned int __conn_ref;
-static guint s_id;
-static int (*_deviced_signal_alpm_handler)(int ambient, void *data);
-static void *_deviced_signal_alpm_data;
-static guint __lcd_sid;
-static void (*__deviced_signal_lcd_handler)(void *data);
-static void *__deviced_signal_lcd_data;
-
-/* LCOV_EXCL_START */
-static void __dbus_signal_filter(GDBusConnection *connection,
-               const gchar *sender_name, const gchar *object_name,
-               const gchar *interface_name, const gchar *signal_name,
-               GVariant *parameters, gpointer user_data)
-{
-       gchar *value = NULL;
-
-       if (g_strcmp0(signal_name, DEVICED_SIGNAL_HOME_SCREEN) == 0) {
-               if (_deviced_signal_alpm_handler) {
-                       g_variant_get(parameters, "(&s)", &value);
-                       if (g_strcmp0(value, CLOCK_START) == 0) {
-                               _deviced_signal_alpm_handler(1,
-                                               _deviced_signal_alpm_data);
-                       } else if (g_strcmp0(value, CLOCK_STOP) == 0) {
-                               _deviced_signal_alpm_handler(0,
-                                               _deviced_signal_alpm_data);
-                       }
-               }
-       }
-}
-/* LCOV_EXCL_STOP */
-
-static int __dbus_init(void)
-{
-       GError *err = NULL;
-
-       if (conn == NULL) {
-               conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err);
-               if (conn == NULL) {
-                       _E("g_bus_get_sync() is failed. %s", err->message); /* LCOV_EXCL_LINE */
-                       g_error_free(err); /* LCOV_EXCL_LINE */
-                       return -1; /* LCOV_EXCL_LINE */
-               }
-       }
-
-       g_clear_error(&err);
-       __conn_ref++;
-
-       return 0;
-}
-
-static void __dbus_fini(void)
-{
-       if (__conn_ref == 0)
-               return;
-
-       __conn_ref--;
-       if (__conn_ref == 0) {
-               g_object_unref(conn);
-               conn = NULL;
-       }
-}
-
-static int __dbus_signal_handler_init(const char *path, const char *interface)
-{
-       s_id = g_dbus_connection_signal_subscribe(conn,
-                                       NULL,
-                                       interface,
-                                       NULL,
-                                       path,
-                                       NULL,
-                                       G_DBUS_SIGNAL_FLAGS_NONE,
-                                       __dbus_signal_filter,
-                                       NULL,
-                                       NULL);
-       if (s_id == 0) {
-               _E("g_dbus_connection_signal_subscribe() is failed."); /* LCOV_EXCL_LINE */
-               return -1; /* LCOV_EXCL_LINE */
-       }
-
-       return 0;
-}
-
-int _watch_core_listen_alpm_handler(int (*func) (int, void *), void *data)
-{
-       _D("watch_core_listen_deviced_alpm");
-
-       if (__dbus_init() < 0)
-               return -1;
-
-       if (__dbus_signal_handler_init(DEVICED_PATH, DEVICED_INTERFACE) < 0) {
-               _E("error app signal init"); /* LCOV_EXCL_LINE */
-               return -1; /* LCOV_EXCL_LINE */
-       }
-
-       _deviced_signal_alpm_handler = func;
-       _deviced_signal_alpm_data = data;
-
-       return 0;
-}
-
-/* LCOV_EXCL_START */
-int _watch_core_send_alpm_update_done(void)
-{
-       GError *err = NULL;
-
-       if (__dbus_init() < 0)
-               return -1;
-
-       if (g_dbus_connection_emit_signal(conn,
-                                       NULL,
-                                       ALPM_VIEWER_PATH,
-                                       ALPM_VIEWER_INTERFACE,
-                                       ALPM_VIEWER_SIGNAL_DRAW_DONE,
-                                       NULL,
-                                       &err) == FALSE) {
-               _E("g_dbus_connection_emit_signal() is failed. %s",
-                               err->message);
-               g_error_free(err); /* LCOV_EXCL_LINE */
-               return -1;
-       }
-
-       if (g_dbus_connection_flush_sync(conn, NULL, &err) == FALSE) {
-               _E("g_dbus_connection_flush_sync() is failed. %s",
-                               err->message);
-               g_error_free(err); /* LCOV_EXCL_LINE */
-               return -1;
-       }
-
-       g_clear_error(&err);
-
-       _I("send a alpm update done signal");
-
-       return 0;
-}
-/* LCOV_EXCL_STOP */
-
-/* LCOV_EXCL_START */
-static void __lcd_on_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)
-{
-       _I("LCD ON");
-       if (__deviced_signal_lcd_handler)
-               __deviced_signal_lcd_handler(__deviced_signal_lcd_data);
-}
-/* LCOV_EXCL_STOP */
-
-int _watch_core_listen_lcd_status_signal(void (*func)(void *), void *data)
-{
-       if (__dbus_init() < 0)
-               return -1;
-
-       __lcd_sid = g_dbus_connection_signal_subscribe(conn,
-                       NULL,
-                       DEVICED_INTERFACE_DISPLAY,
-                       LCD_ON,
-                       DEVICED_PATH_DISPLAY,
-                       NULL,
-                       G_DBUS_SIGNAL_FLAGS_NONE,
-                       __lcd_on_signal_handler,
-                       NULL,
-                       NULL);
-       if (!__lcd_sid) {
-               _E("Failed to subscribe LCD status signal");
-               return -1;
-       }
-
-       __deviced_signal_lcd_handler = func;
-       __deviced_signal_lcd_data = data;
-
-       _D("Listen LCD status signal");
-
-       return 0;
-}
-
-void _watch_core_ignore_lcd_status_signal(void)
-{
-       __deviced_signal_lcd_handler = NULL;
-       __deviced_signal_lcd_data = NULL;
-
-       if (__lcd_sid) {
-               g_dbus_connection_signal_unsubscribe(conn, __lcd_sid);
-               __lcd_sid = 0;
-       }
-
-       __dbus_fini();
-
-       _D("Ignore LCD status signal");
-}
diff --git a/src/appcore-watch-signal.h b/src/appcore-watch-signal.h
deleted file mode 100755 (executable)
index 662fc8b..0000000
+++ /dev/null
@@ -1,48 +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_SIGNAL_H__
-#define __APPCORE_WATCH_SIGNAL_H__
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define ALPM_VIEWER_PATH "/Org/Tizen/Coreapps/Alpmviewer/Clockdraw"
-#define ALPM_VIEWER_INTERFACE "org.tizen.coreapps.alpmviewer.clockdraw"
-#define ALPM_VIEWER_SIGNAL_DRAW_DONE "drawdone"
-
-#define DEVICED_PATH "/Org/Tizen/System/DeviceD"
-#define DEVICED_INTERFACE "org.tizen.system.deviced"
-#define DEVICED_SIGNAL_HOME_SCREEN "HomeScreen"
-#define CLOCK_START "clockbegin"
-#define CLOCK_STOP "clockstop"
-
-#define DEVICED_PATH_DISPLAY            "/Org/Tizen/System/DeviceD/Display"
-#define DEVICED_INTERFACE_DISPLAY       "org.tizen.system.deviced.display"
-#define LCD_ON                         "LCDOn"
-
-int _watch_core_listen_alpm_handler(int (*func)(int, void *), void *data);
-int _watch_core_send_alpm_update_done(void);
-int _watch_core_listen_lcd_status_signal(void (*func)(void *), void *data);
-void _watch_core_ignore_lcd_status_signal(void);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __APPCORE_WATCH_SIGNAL_H__ */
-
diff --git a/src/base/watch_base.c b/src/base/watch_base.c
new file mode 100755 (executable)
index 0000000..838d46d
--- /dev/null
@@ -0,0 +1,1114 @@
+/*
+ * Copyright (c) 2015 - 2018 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 <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 <bundle.h>
+#include <aul.h>
+#include <dlog.h>
+#include <app_common.h>
+#include <Ecore_Wl2.h>
+#include <screen_connector_provider.h>
+#include <appcore_ui_base.h>
+#include <alarm.h>
+#include <vconf.h>
+#include <glib-object.h>
+#include <app_control.h>
+#include <app_control_internal.h>
+#include <bundle_internal.h>
+#include <pkgmgr-info.h>
+#include <aul_app_com.h>
+#include <aul_screen_connector.h>
+#include <system_info.h>
+
+#include "watch_base_log.h"
+#include "watch_base_signal.h"
+#include "watch_base_time.h"
+#include "watch_base.h"
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+
+#define LOG_TAG "WATCH_BASE"
+
+#define APPID_BUFFER_MAX 255
+#define ONE_SECOND             1000
+#define ONE_MINUTE_IN_SEC      60
+#define ONE_HOUR_IN_SEC                3600
+#define ONE_DAY_IN_SEC         86400
+#define METADATA_TICK_PER_SECOND       "http://developer.samsung.com/tizen/metadata/tickpersecond"
+#define METADATA_MINUTE_TICK           "http://developer.samsung.com/tizen/metadata/minutetick"
+#define WATCH_BASE_FEATURE "http://tizen.org/feature/watch_app"
+
+typedef enum {
+       WATCH_BASE_STATE_NOT_RUNNING = 0,
+       WATCH_BASE_STATE_CREATING,
+       WATCH_BASE_STATE_RUNNING,
+} watch_base_state_e;
+
+enum watch_state {
+       WS_NONE,
+       WS_CREATED,
+       WS_RUNNING,
+       WS_PAUSED,
+       WS_DYING,
+};
+
+enum watch_visible_state {
+       WVS_UNKNOWN,
+       WVS_PAUSE,
+       WVS_RESUME
+};
+
+static Ecore_Timer *watch_tick;
+static alarm_id_t alarm_id;
+static watch_base_ambient_tick_type_e ambient_tick_type
+               = WATCH_BASE_AMBIENT_TICK_EVERY_MINUTE;
+static watch_base_time_tick_resolution_e app_tick_type
+               = WATCH_BASE_TIME_TICKS_PER_SECOND;
+static int app_tick_resolution = 1;
+static aul_app_com_connection_h __conn_viewer_state;
+
+struct app_event_handler {
+       app_event_type_e type;
+       app_event_cb cb;
+       void *data;
+       void *raw;
+};
+
+struct app_event_info {
+       app_event_type_e type;
+       void *value;
+};
+
+struct watch_base_context {
+       char *appid;
+       watch_base_state_e state;
+       watch_base_ops callback;
+       int width;
+       int height;
+       enum watch_visible_state watch_visibility;
+       int viewer_visibility;
+       bool ambient_mode;
+       bool ambient_mode_skip_resume;
+       void *data;
+};
+
+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,
+};
+
+static struct watch_base_context __context;
+static double __prev_target_tick = -1;
+static enum watch_state __state;
+
+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 const char *__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";
+       }
+}
+
+EXPORT_API int watch_base_set_error(app_error_e error, const char *function,
+               const char *description)
+{
+       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);
+
+       return error;
+}
+
+EXPORT_API bool watch_base_check_feature(void)
+{
+       static bool is_checked = false;
+       static bool is_supported = false;
+
+       if (is_checked)
+               return is_supported;
+       if (!system_info_get_platform_bool(WATCH_BASE_FEATURE, &is_supported)) {
+               is_checked = true;
+               if (!is_supported) {
+                       LOGE("[%s] feature is disabled", WATCH_BASE_FEATURE);
+                       return false;
+               }
+       }
+       return is_supported;
+}
+
+static void __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 != AUL_R_OK) {
+               _E("fail to get the appid from the pid : %d", pid);
+               assert(0);
+       }
+
+       r = alarmmgr_init(appid);
+       if (r != ALARMMGR_RESULT_SUCCESS) {
+               _E("fail to alarmmgr_init : error_code : %d", r);
+               assert(0);
+       }
+}
+
+static double __get_next_tick_sec()
+{
+       double cur_time_in_milli;
+       double term = 1.0;
+       double sec = 1.0;
+       int idx;
+       double target;
+
+       struct _watch_base_time_s timeinfo = {
+               .timezone = NULL
+       };
+
+       _watch_base_time_get_timeinfo(&timeinfo);
+       cur_time_in_milli = timeinfo.hour24 * 60 * 60 * 1000 + timeinfo.minute * 60 * 1000 +
+                       timeinfo.second * 1000 + timeinfo.millisecond;
+
+       if (app_tick_type == WATCH_BASE_TIME_TICKS_PER_SECOND) {
+               term = (double)ONE_SECOND / (double)app_tick_resolution;
+       } else if (app_tick_type == WATCH_BASE_TIME_TICKS_PER_MINUTE) {
+               term = (double)ONE_MINUTE_IN_SEC / (double)app_tick_resolution;
+               term *= 1000;
+       } else if (app_tick_type == WATCH_BASE_TIME_TICKS_PER_HOUR) {
+               term = (double)ONE_HOUR_IN_SEC / (double)app_tick_resolution;
+               term *= 1000;
+       }
+
+       idx = cur_time_in_milli / term;
+       target = (idx + 1) * term;
+
+       if (__prev_target_tick == target)
+               target = __prev_target_tick + term;
+
+       sec = (target - cur_time_in_milli) / 1000.0;
+       __prev_target_tick = target;
+
+       if (timeinfo.timezone)
+               free(timeinfo.timezone);
+
+       return sec;
+}
+
+/* LCOV_EXCL_START */
+static int __get_ambient_tick_offset(struct _watch_base_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;
+}
+/* LCOV_EXCL_STOP */
+
+/* LCOV_EXCL_START */
+static int __ambient_tick_cb(alarm_id_t id, void *data)
+{
+       struct _watch_base_time_s timeinfo = {
+               .timezone = NULL
+       };
+
+       _watch_base_time_get_timeinfo(&timeinfo);
+       __on_ambient_tick(&timeinfo, data);
+
+       if (timeinfo.timezone)
+               free(timeinfo.timezone);
+
+       return 0;
+}
+/* LCOV_EXCL_STOP */
+
+/* LCOV_EXCL_START */
+static int __set_ambient_tick_cb(void *data)
+{
+       int offset_sec = 0;
+       int interval = 0;
+       struct _watch_base_time_s timeinfo = {
+               .timezone = NULL
+       };
+       int r;
+       struct ambient_tick_type_info info;
+
+       _watch_base_time_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);
+               __on_ambient_tick(&timeinfo, data);
+       }
+
+       if (timeinfo.timezone)
+               free(timeinfo.timezone);
+
+       return 0;
+}
+/* LCOV_EXCL_STOP */
+
+/* LCOV_EXCL_START */
+static int __signal_alpm_handler(int ambient, void *data)
+{
+       struct _watch_base_time_s timeinfo = {
+               .timezone = NULL
+       };
+
+       _D("_signal_alpm_handler: ambient: %d", ambient);
+       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);
+
+               if (__context.callback.ambient_tick)
+                       __set_ambient_tick_cb(data);
+
+               /* Send a update done signal */
+               _watch_base_signal_send_alpm_update_done();
+       } else { /* Exit the ambient mode */
+
+               _watch_base_time_get_timeinfo(&timeinfo);
+               __on_ambient_tick(&timeinfo, data);
+
+               __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();
+               }
+
+               /* Disable alarm */
+               if (alarm_id) {
+                       alarmmgr_remove_alarm(alarm_id);
+                       alarm_id = 0;
+               }
+       }
+
+       if (timeinfo.timezone)
+               free(timeinfo.timezone);
+
+       return 0;
+}
+/* LCOV_EXCL_STOP */
+
+static Eina_Bool __time_tick_cb(void *data)
+{
+       struct _watch_base_time_s timeinfo = {
+               .timezone = NULL
+       };
+       double sec;
+
+       _D("state: %d", __state);
+       if (__context.callback.time_tick && __state != WS_PAUSED) {
+               _watch_base_time_get_timeinfo(&timeinfo);
+
+               /* Set a next timer */
+               sec = __get_next_tick_sec();
+               watch_tick = ecore_timer_add(sec, __time_tick_cb, data);
+               __on_time_tick(&timeinfo, data);
+
+               if (timeinfo.timezone)
+                       free(timeinfo.timezone);
+       }
+
+       return ECORE_CALLBACK_CANCEL;
+}
+
+static void __time_tick_cancel(void)
+{
+       if (watch_tick) {
+               ecore_timer_del(watch_tick);
+               watch_tick = NULL;
+               __prev_target_tick = -1;
+       }
+}
+
+static void __set_default_tick_by_metadata()
+{
+       char appid[APPID_BUFFER_MAX] = {0,};
+       pkgmgrinfo_appinfo_h handle = NULL;
+       char *second_tick = NULL;
+       char *minute_tick = NULL;
+       int ret;
+       int tick;
+
+       ret = aul_app_get_appid_bypid(getpid(), appid, sizeof(appid));
+       if (ret < 0) {
+               _E("fail to get the appid from the pid : %d", getpid());
+               return;
+       }
+
+       ret = pkgmgrinfo_appinfo_get_appinfo(appid, &handle);
+       if (ret != PMINFO_R_OK)
+               return;
+
+       /* If both minute tick & second tick are declared, only minute tick has to be applied */
+       ret = pkgmgrinfo_appinfo_get_metadata_value(handle, METADATA_MINUTE_TICK, &minute_tick);
+       if (ret == PMINFO_R_OK) {
+               _D("set default tick 1, type %d", WATCH_BASE_TIME_TICKS_PER_MINUTE);
+               app_tick_type = WATCH_BASE_TIME_TICKS_PER_MINUTE;
+               app_tick_resolution = 1;
+               pkgmgrinfo_appinfo_destroy_appinfo(handle);
+               return;
+       }
+
+       pkgmgrinfo_appinfo_get_metadata_value(handle, METADATA_TICK_PER_SECOND, &second_tick);
+       if (second_tick) {
+               sscanf(second_tick, "%d", &tick);
+               if (tick > 0) {
+                       _D("set default tick %d, type %d", tick, WATCH_BASE_TIME_TICKS_PER_SECOND);
+                       app_tick_type = WATCH_BASE_TIME_TICKS_PER_SECOND;
+                       app_tick_resolution = tick;
+                       pkgmgrinfo_appinfo_destroy_appinfo(handle);
+                       return;
+               }
+       }
+
+       pkgmgrinfo_appinfo_destroy_appinfo(handle);
+       return;
+}
+
+/* LCOV_EXCL_START */
+static void __vconf_time_changed_cb(keynode_t *key, void *data)
+{
+       struct _watch_base_time_s timeinfo = {
+               .timezone = NULL
+       };
+
+       _D("ambient_mode check: %d", __context.ambient_mode);
+       _watch_base_time_get_timeinfo(&timeinfo);
+       if (__context.ambient_mode) {
+               if (alarm_id) {
+                       alarmmgr_remove_alarm(alarm_id);
+                       alarm_id = 0;
+               }
+               __set_ambient_tick_cb(data);
+               __on_ambient_tick(&timeinfo, data);
+       } else {
+               __time_tick_cb(data);
+       }
+
+       if (timeinfo.timezone)
+               free(timeinfo.timezone);
+
+       return;
+}
+/* LCOV_EXCL_STOP */
+
+static int __on_ui_base_create(void *data)
+{
+       watch_base_create_cb create_cb;
+
+       _W("_watch_base_signal_create");
+       create_cb = __context.callback.create;
+       if (create_cb == NULL || create_cb(__context.width, __context.height, __context.data) == false)
+               return watch_base_set_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__,
+                               "watch_base_create_cb() returns false");
+       __state = WS_CREATED;
+
+       /* Alarm init */
+       __alarm_init();
+       __context.state = WATCH_BASE_STATE_RUNNING;
+
+       vconf_notify_key_changed(VCONFKEY_SYSTEM_TIME_CHANGED,
+                               __vconf_time_changed_cb, data);
+
+       return APP_ERROR_NONE;
+}
+
+static int __on_ui_base_control(bundle *b, void *data)
+{
+       app_control_h app_control = NULL;
+       appcore_ui_base_on_control(b);
+
+       _W("_watch_base_signal_control");
+
+       if (app_control_create_event(b, &app_control) != 0)
+               return -1;
+
+       if (__context.callback.app_control)
+               __context.callback.app_control(app_control, __context.data);
+
+       app_control_destroy(app_control);
+
+       return APP_ERROR_NONE;
+}
+
+/* LCOV_EXCL_START */
+static int __on_ui_base_pause(void *data)
+{
+       _W("_watch_base_signal_pause");
+
+       if (__state == WS_CREATED) {
+               _E("Invalid state");
+               return APP_ERROR_NONE;
+       }
+
+       /* Handling the ambient mode */
+       if (__context.ambient_mode)
+               __context.ambient_mode_skip_resume = 1;
+
+       if (__state == WS_RUNNING) {
+               if (__context.callback.pause)
+                       __context.callback.pause(__context.data);
+       }
+
+       __state = WS_PAUSED;
+
+       return APP_ERROR_NONE;
+}
+/* LCOV_EXCL_STOP */
+
+static void __on_pre_resume(void *data)
+{
+       if (__context.callback.preresume)
+               __context.callback.preresume(__context.data);
+}
+
+EXPORT_API void watch_base_on_preresume(void)
+{
+       struct _watch_base_time_s timeinfo = {
+               .timezone = NULL
+       };
+
+       _watch_base_time_get_timeinfo(&timeinfo);
+       __on_time_tick(&timeinfo, NULL);
+
+       if (timeinfo.timezone)
+               free(timeinfo.timezone);
+}
+
+static void __on_base_preresume(void *data)
+{
+       watch_base_on_preresume();
+}
+
+static int __on_ui_base_resume(void *data)
+{
+       _W("_watch_base_signal_resume");
+       if (__context.viewer_visibility != AUL_SCREEN_STATUS_RESUME) {
+               _D("Viewer is paused, do not resume watch");
+               return APP_ERROR_NONE;
+       }
+
+       if (__context.ambient_mode) {
+               __context.ambient_mode_skip_resume = false;
+               return 0;
+       }
+
+       if (__state != WS_PAUSED && __state != WS_CREATED)
+               return APP_ERROR_NONE;
+
+       if (__context.callback.resume)
+               __context.callback.resume(__context.data);
+
+       __state = WS_RUNNING;
+
+       if (!watch_tick) {
+               __time_tick_cb(data);
+       } else {
+               __time_tick_cancel();
+               __time_tick_cb(data);
+       }
+
+       return APP_ERROR_NONE;
+}
+
+static int __on_ui_base_terminate(void *data)
+{
+       _W("__on_ui_base_terminate");
+
+       __state = WS_DYING;
+       if (appcore_ui_base_is_resumed())
+               appcore_ui_base_pause();
+
+       /* Cancel the time_tick callback */
+       __time_tick_cancel();
+
+       if (__context.callback.terminate)
+               __context.callback.terminate(__context.data);
+       alarmmgr_fini();
+
+       return APP_ERROR_NONE;
+}
+
+static void __on_time_tick(void *watchtime, void *data)
+{
+       watch_base_time_tick_cb time_tick_cb;
+
+       _I("_watch_base_signal_time_tick");
+
+       time_tick_cb = __context.callback.time_tick;
+
+       if (time_tick_cb != NULL)
+               time_tick_cb((watch_base_time_h)watchtime, __context.data);
+}
+
+/* LCOV_EXCL_START */
+static void __on_ambient_tick(void *watchtime, void *data)
+{
+       watch_base_ambient_tick_cb ambient_tick_cb;
+
+       _W("_watch_base_signal_ambient_tick");
+
+       ambient_tick_cb = __context.callback.ambient_tick;
+
+       if (ambient_tick_cb != NULL)
+               ambient_tick_cb((watch_base_time_h)watchtime, __context.data);
+}
+/* LCOV_EXCL_STOP */
+
+/* LCOV_EXCL_START */
+static void __on_ambient_changed(int ambient, void *data)
+{
+       watch_base_ambient_changed_cb ambient_changed_cb;
+
+       _W("_watch_base_signal_ambient_changed: %d", ambient);
+
+       ambient_changed_cb = __context.callback.ambient_changed;
+
+       if (ambient_changed_cb != NULL)
+               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);
+       if (__context.viewer_visibility == AUL_SCREEN_STATUS_RESUME)
+               appcore_ui_base_resume();
+       else
+               _D("viewer is not resumed, do not resume watch");
+}
+
+static void __on_window_visibility(int type, void *event, void *data)
+{
+       Ecore_Wl2_Event_Window_Visibility_Change *ev = event;
+
+       _D("visibility %u %u",
+                       (unsigned int)ev->win,
+                       (unsigned int)ev->fully_obscured);
+
+       if (ev->fully_obscured) {
+               __context.watch_visibility = WVS_PAUSE;
+               __on_ui_base_pause(NULL);
+       } else {
+               __context.watch_visibility = WVS_RESUME;
+               if (__context.viewer_visibility == AUL_SCREEN_STATUS_RESUME)
+                       __on_ui_base_resume(NULL);
+               else
+                       _D("Viewer is paused, do not resume watch");
+       }
+}
+
+static int __set_ambient_tick_type(watch_base_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_base_ambient_tick_type_e *type)
+{
+       *type = ambient_tick_type;
+       return 0;
+}
+
+static int __set_time_tick_frequency(int ticks, watch_base_time_tick_resolution_e type)
+{
+       double sec = 1.0;
+       struct _watch_base_time_s timeinfo = {
+               .timezone = NULL
+       };
+
+       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: %lf, type: %d, tick: %d", sec, type, ticks);
+
+       if (appcore_ui_base_is_resumed()) {
+               _watch_base_time_get_timeinfo(&timeinfo);
+               __on_time_tick(&timeinfo, NULL);
+       }
+
+       if (timeinfo.timezone)
+               free(timeinfo.timezone);
+
+       return 0;
+}
+
+static int __get_time_tick_frequency(int *ticks, watch_base_time_tick_resolution_e *type)
+{
+       *ticks = app_tick_resolution;
+       *type = app_tick_type;
+       return 0;
+}
+
+static int __viewer_state_handler(const char *widget_id, aul_app_com_result_e e,
+               bundle *envelope, void *user_data)
+{
+       int *state = NULL;
+       size_t state_sz = 0;
+       struct _watch_base_time_s timeinfo = {
+               .timezone = NULL
+       };
+
+       bundle_get_byte(envelope, "__AUL_SC_VIEWER_STATUS__", (void **)&state,
+                       &state_sz);
+       if (state == NULL) {
+               _E("Failed to get viewer status");
+               return -1;
+       }
+
+       _D("receive viewer state %d", *state);
+       if (*state != AUL_SCREEN_STATUS_PRE_RESUME) {
+               __context.viewer_visibility = *state;
+               _D("set viewer state to %d", *state);
+       }
+
+       if (*state == AUL_SCREEN_STATUS_RESUME &&
+                       __context.watch_visibility == WVS_RESUME) {
+               __on_ui_base_resume(NULL);
+       } else if (*state == AUL_SCREEN_STATUS_PAUSE) {
+               __on_ui_base_pause(NULL);
+       } else if (*state == AUL_SCREEN_STATUS_PRE_RESUME) {
+               _D("call pre resume tick");
+               __on_pre_resume(NULL);
+       }
+
+       if (timeinfo.timezone)
+               free(timeinfo.timezone);
+
+       return 0;
+}
+
+static void __lcd_on_handler(void *user_data)
+{
+       _D("Call pre resume tick");
+       __on_pre_resume(NULL);
+}
+
+EXPORT_API void watch_base_on_create(int width, int height)
+{
+       _W("watch_base_on_create");
+       __set_default_tick_by_metadata();
+       screen_connector_provider_init();
+       _watch_base_signal_listen_alpm_handler(__signal_alpm_handler, NULL);
+       appcore_ui_base_on_create();
+}
+
+static bool __on_create(int width, int height, void *user_data)
+{
+       watch_base_on_create(width, height);
+       return true;
+}
+
+EXPORT_API void watch_base_on_control(app_control_h app_control)
+{
+}
+
+static void __on_control(app_control_h app_control, void *user_data)
+{
+       watch_base_on_control(app_control);
+}
+
+EXPORT_API void watch_base_on_pause(void)
+{
+       __time_tick_cancel();
+       appcore_ui_base_on_pause();
+}
+
+static void __on_pause(void *user_data)
+{
+       watch_base_on_pause();
+}
+
+EXPORT_API void watch_base_on_resume(void)
+{
+       appcore_ui_base_on_resume();
+}
+
+static void __on_resume(void *user_data)
+{
+       watch_base_on_resume();
+}
+
+EXPORT_API void watch_base_on_terminate(void)
+{
+       appcore_ui_base_on_terminate();
+       screen_connector_provider_fini();
+}
+
+static void __on_terminate(void *user_data)
+{
+       watch_base_on_terminate();
+}
+
+EXPORT_API watch_base_ops watch_base_get_default_ops(void)
+{
+       watch_base_ops ops;
+
+       ops.create = __on_create;
+       ops.app_control = __on_control;
+       ops.pause = __on_pause;
+       ops.resume = __on_resume;
+       ops.preresume = __on_base_preresume;
+       ops.terminate = __on_terminate;
+       ops.time_tick = NULL;
+       ops.ambient_tick = NULL;
+       ops.ambient_changed = NULL;
+       ops.init = NULL;
+       ops.finish = NULL;
+       ops.run = NULL;
+       ops.exit = NULL;
+
+       return ops;
+}
+
+EXPORT_API int watch_base_init(int argc, char **argv,
+               watch_base_ops *callback, void *user_data)
+{
+       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();
+       char *viewer_visibility_str = NULL;
+
+       if (!watch_base_check_feature())
+               return APP_ERROR_NOT_SUPPORTED;
+
+       /* override methods */
+       ops.base.create = __on_ui_base_create;
+       ops.base.control = __on_ui_base_control;
+       ops.base.terminate = __on_ui_base_terminate;
+       ops.base.init = callback->init;
+       ops.base.finish = callback->finish;
+       ops.base.run = callback->run;
+       ops.base.exit = callback->exit;
+       ops.window.show = __on_window_show;
+       ops.window.visibility = __on_window_visibility;
+       ops.pause = __on_ui_base_pause;
+       ops.resume = __on_ui_base_resume;
+
+
+       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);
+               bundle_get_str(kb, "WATCH_VIEWER_VISIBILITY",
+                               &viewer_visibility_str);
+
+               if (width_str)
+                       width = atoi(width_str);
+
+               if (height_str)
+                       height = atoi(height_str);
+
+               if (viewer_visibility_str) {
+                       __context.viewer_visibility =
+                                       atoi(viewer_visibility_str);
+               }
+
+               bundle_free(kb);
+       } else {
+               _E("failed to get launch argv");
+       }
+
+       if (argc <= 0 || argv == NULL || callback == NULL)
+               return watch_base_set_error(APP_ERROR_INVALID_PARAMETER,
+                               __FUNCTION__, NULL);
+
+       if (callback->create == NULL)
+               return watch_base_set_error(APP_ERROR_INVALID_PARAMETER,
+                               __FUNCTION__,
+                               "watch_base_create_cb() callback must be "
+                               "registered");
+
+       if (__context.state != WATCH_BASE_STATE_NOT_RUNNING)
+               return watch_base_set_error(APP_ERROR_ALREADY_RUNNING, __FUNCTION__,
+                               NULL);
+
+       if (app_get_id(&(__context.appid)) != APP_ERROR_NONE)
+               return watch_base_set_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__,
+                               "failed to get the appid");
+
+       ret = aul_app_com_create(__context.appid, NULL, __viewer_state_handler,
+                       NULL, &__conn_viewer_state);
+       if (ret < 0) {
+               free(__context.appid);
+               __context.appid = NULL;
+               return watch_base_set_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__,
+                               "Failed to create app com");
+       }
+
+       __context.callback = *callback;
+       __context.width = width;
+       __context.height = height;
+       __context.watch_visibility = WVS_UNKNOWN;
+       __context.ambient_mode = false;
+       __context.ambient_mode_skip_resume = false;
+       __context.data = user_data;
+       __context.state = WATCH_BASE_STATE_CREATING;
+       _watch_base_signal_listen_lcd_status_signal(__lcd_on_handler, NULL);
+
+       return appcore_ui_base_init(ops, argc, argv, NULL, 0);
+}
+
+EXPORT_API void watch_base_fini(void)
+{
+       free(__context.appid);
+       __context.appid = NULL;
+       aul_app_com_leave(__conn_viewer_state);
+       __conn_viewer_state = NULL;
+       _watch_base_signal_ignore_lcd_status_signal();
+       appcore_ui_base_fini();
+       __context.state = WATCH_BASE_STATE_NOT_RUNNING;
+}
+
+EXPORT_API void watch_base_exit(void)
+{
+       _I("watch_base_exit");
+       appcore_ui_base_exit();
+       aul_notify_exit();
+}
+
+EXPORT_API const char *watch_base_get_current_appid(void)
+{
+       return __context.appid;
+}
+
+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_base_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;
+
+       if (!watch_base_check_feature())
+               return APP_ERROR_NOT_SUPPORTED;
+
+       if (event_handler == NULL || callback == NULL)
+               return watch_base_set_error(APP_ERROR_INVALID_PARAMETER,
+                               __FUNCTION__, NULL);
+
+       if (event_type < APP_EVENT_LOW_MEMORY ||
+                       event_type > APP_EVENT_REGION_FORMAT_CHANGED)
+               return watch_base_set_error(APP_ERROR_INVALID_PARAMETER,
+                               __FUNCTION__, NULL);
+
+       handler = calloc(1, sizeof(struct app_event_handler));
+       if (!handler)
+               return watch_base_set_error(APP_ERROR_OUT_OF_MEMORY, __FUNCTION__,
+                               NULL);
+
+       handler->type = event_type;
+       handler->cb = callback;
+       handler->data = user_data;
+       handler->raw = appcore_base_add_event(__app_event_converter[event_type], __event_cb, handler);
+
+       *event_handler = handler;
+
+       return APP_ERROR_NONE;
+}
+
+EXPORT_API int watch_base_remove_event_handler(app_event_handler_h event_handler)
+{
+       int ret;
+       app_event_type_e type;
+
+       if (!watch_base_check_feature())
+               return APP_ERROR_NOT_SUPPORTED;
+
+       if (event_handler == NULL)
+               return watch_base_set_error(APP_ERROR_INVALID_PARAMETER,
+                               __FUNCTION__, NULL);
+
+       type = event_handler->type;
+       if (type < APP_EVENT_LOW_MEMORY ||
+                       type > APP_EVENT_REGION_FORMAT_CHANGED)
+               return watch_base_set_error(APP_ERROR_INVALID_PARAMETER,
+                               __FUNCTION__, NULL);
+
+       ret = appcore_base_remove_event(event_handler->raw);
+       if (ret < 0)
+               return watch_base_set_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, "invalid raw handler");
+
+       free(event_handler);
+
+       return APP_ERROR_NONE;
+}
+
+EXPORT_API int watch_base_set_ambient_tick_type(watch_base_ambient_tick_type_e type)
+{
+       if (!watch_base_check_feature())
+               return APP_ERROR_NOT_SUPPORTED;
+
+       if (type < WATCH_BASE_AMBIENT_TICK_NO_TICK || type > WATCH_BASE_AMBIENT_TICK_EVERY_DAY)
+               return APP_ERROR_INVALID_PARAMETER;
+       return __set_ambient_tick_type(type);
+}
+
+EXPORT_API int watch_base_get_ambient_tick_type(watch_base_ambient_tick_type_e *type)
+{
+       if (!watch_base_check_feature())
+               return APP_ERROR_NOT_SUPPORTED;
+
+       if (type == NULL)
+               return APP_ERROR_INVALID_PARAMETER;
+       return __get_ambient_tick_type(type);
+}
+
+EXPORT_API int watch_base_set_time_tick_frequency(int ticks, watch_base_time_tick_resolution_e type)
+{
+       if (!watch_base_check_feature())
+               return APP_ERROR_NOT_SUPPORTED;
+
+       if (type < WATCH_BASE_TIME_TICKS_PER_SECOND || type > WATCH_BASE_TIME_TICKS_PER_HOUR)
+               return APP_ERROR_INVALID_PARAMETER;
+       return __set_time_tick_frequency(ticks, type);
+}
+
+EXPORT_API int watch_base_get_time_tick_frequency(int *ticks, watch_base_time_tick_resolution_e *type)
+{
+       if (!watch_base_check_feature())
+               return APP_ERROR_NOT_SUPPORTED;
+
+       if (type == NULL || ticks == NULL)
+               return APP_ERROR_INVALID_PARAMETER;
+       return __get_time_tick_frequency(ticks, type);
+}
diff --git a/src/base/watch_base_log.h b/src/base/watch_base_log.h
new file mode 100755 (executable)
index 0000000..252d47f
--- /dev/null
@@ -0,0 +1,79 @@
+/*
+ * Copyright (c) 2015 - 2018 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 __WATCH_BASE_LOG_H__
+#define __WATCH_BASE_LOG_H__
+
+#include <dlog.h>
+
+#define _E(fmt, arg...) LOGE(fmt, ##arg)
+#define _I(fmt, arg...) LOGI(fmt, ##arg)
+#define _D(fmt, arg...) LOGD(fmt, ##arg)
+#define _W(fmt, arg...) LOGW(fmt, ##arg)
+
+#ifndef EXPORT_API
+#define EXPORT_API __attribute__ ((visibility("default")))
+#endif
+
+#ifndef _E
+#define _E(fmt, arg...) LOGE(fmt, ##arg)
+#endif
+
+#ifndef _I
+#define _I(...) LOGI(__VA_ARGS__)
+#endif
+
+#ifndef _D
+#define _D(...) LOGD(__VA_ARGS__)
+#endif
+
+#ifndef _W
+#define _W(...) LOGW(__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)
+
+#endif /*__WATCH_BASE_LOG_H__ */
diff --git a/src/base/watch_base_signal.c b/src/base/watch_base_signal.c
new file mode 100755 (executable)
index 0000000..dbc5b78
--- /dev/null
@@ -0,0 +1,246 @@
+/*
+ * Copyright (c) 2015 - 2018 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 <dlog.h>
+#include <glib.h>
+#include <gio/gio.h>
+
+#include "watch_base_log.h"
+#include "watch_base_signal.h"
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+
+#define LOG_TAG "WATCH_BASE_SIGNAL"
+
+#define ALPM_VIEWER_PATH "/Org/Tizen/Coreapps/Alpmviewer/Clockdraw"
+#define ALPM_VIEWER_INTERFACE "org.tizen.coreapps.alpmviewer.clockdraw"
+#define ALPM_VIEWER_SIGNAL_DRAW_DONE "drawdone"
+
+#define DEVICED_PATH "/Org/Tizen/System/DeviceD"
+#define DEVICED_INTERFACE "org.tizen.system.deviced"
+#define DEVICED_SIGNAL_HOME_SCREEN "HomeScreen"
+#define CLOCK_START "clockbegin"
+#define CLOCK_STOP "clockstop"
+
+#define DEVICED_PATH_DISPLAY            "/Org/Tizen/System/DeviceD/Display"
+#define DEVICED_INTERFACE_DISPLAY       "org.tizen.system.deviced.display"
+#define LCD_ON                         "LCDOn"
+
+static GDBusConnection *conn;
+static unsigned int __conn_ref;
+static guint s_id;
+static int (*_deviced_signal_alpm_handler)(int ambient, void *data);
+static void *_deviced_signal_alpm_data;
+static guint __lcd_sid;
+static void (*__deviced_signal_lcd_handler)(void *data);
+static void *__deviced_signal_lcd_data;
+
+/* LCOV_EXCL_START */
+static void __dbus_signal_filter(GDBusConnection *connection,
+               const gchar *sender_name, const gchar *object_name,
+               const gchar *interface_name, const gchar *signal_name,
+               GVariant *parameters, gpointer user_data)
+{
+       gchar *value = NULL;
+
+       if (g_strcmp0(signal_name, DEVICED_SIGNAL_HOME_SCREEN) == 0) {
+               if (_deviced_signal_alpm_handler) {
+                       g_variant_get(parameters, "(&s)", &value);
+                       if (g_strcmp0(value, CLOCK_START) == 0) {
+                               _deviced_signal_alpm_handler(1,
+                                               _deviced_signal_alpm_data);
+                       } else if (g_strcmp0(value, CLOCK_STOP) == 0) {
+                               _deviced_signal_alpm_handler(0,
+                                               _deviced_signal_alpm_data);
+                       }
+               }
+       }
+}
+/* LCOV_EXCL_STOP */
+
+static int __dbus_init(void)
+{
+       GError *err = NULL;
+
+       if (conn == NULL) {
+               conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err);
+               if (conn == NULL) {
+                       _E("g_bus_get_sync() is failed. %s", err->message); /* LCOV_EXCL_LINE */
+                       g_error_free(err); /* LCOV_EXCL_LINE */
+                       return -1; /* LCOV_EXCL_LINE */
+               }
+       }
+
+       g_clear_error(&err);
+       __conn_ref++;
+
+       return 0;
+}
+
+static void __dbus_fini(void)
+{
+       if (__conn_ref == 0)
+               return;
+
+       __conn_ref--;
+       if (__conn_ref == 0) {
+               g_object_unref(conn);
+               conn = NULL;
+       }
+}
+
+static int __dbus_signal_handler_init(const char *path, const char *interface)
+{
+       s_id = g_dbus_connection_signal_subscribe(conn,
+                                       NULL,
+                                       interface,
+                                       NULL,
+                                       path,
+                                       NULL,
+                                       G_DBUS_SIGNAL_FLAGS_NONE,
+                                       __dbus_signal_filter,
+                                       NULL,
+                                       NULL);
+       if (s_id == 0) {
+               _E("g_dbus_connection_signal_subscribe() is failed."); /* LCOV_EXCL_LINE */
+               return -1; /* LCOV_EXCL_LINE */
+       }
+
+       return 0;
+}
+
+int _watch_base_signal_listen_alpm_handler(int (*func) (int, void *), void *data)
+{
+       _D("watch_core_listen_deviced_alpm");
+
+       if (__dbus_init() < 0)
+               return -1;
+
+       if (__dbus_signal_handler_init(DEVICED_PATH, DEVICED_INTERFACE) < 0) {
+               _E("error app signal init"); /* LCOV_EXCL_LINE */
+               return -1; /* LCOV_EXCL_LINE */
+       }
+
+       _deviced_signal_alpm_handler = func;
+       _deviced_signal_alpm_data = data;
+
+       return 0;
+}
+
+/* LCOV_EXCL_START */
+int _watch_base_signal_send_alpm_update_done(void)
+{
+       GError *err = NULL;
+
+       if (__dbus_init() < 0)
+               return -1;
+
+       if (g_dbus_connection_emit_signal(conn,
+                                       NULL,
+                                       ALPM_VIEWER_PATH,
+                                       ALPM_VIEWER_INTERFACE,
+                                       ALPM_VIEWER_SIGNAL_DRAW_DONE,
+                                       NULL,
+                                       &err) == FALSE) {
+               _E("g_dbus_connection_emit_signal() is failed. %s",
+                               err->message);
+               g_error_free(err); /* LCOV_EXCL_LINE */
+               return -1;
+       }
+
+       if (g_dbus_connection_flush_sync(conn, NULL, &err) == FALSE) {
+               _E("g_dbus_connection_flush_sync() is failed. %s",
+                               err->message);
+               g_error_free(err); /* LCOV_EXCL_LINE */
+               return -1;
+       }
+
+       g_clear_error(&err);
+
+       _I("send a alpm update done signal");
+
+       return 0;
+}
+/* LCOV_EXCL_STOP */
+
+/* LCOV_EXCL_START */
+static void __lcd_on_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)
+{
+       _I("LCD ON");
+       if (__deviced_signal_lcd_handler)
+               __deviced_signal_lcd_handler(__deviced_signal_lcd_data);
+}
+/* LCOV_EXCL_STOP */
+
+int _watch_base_signal_listen_lcd_status_signal(void (*func)(void *), void *data)
+{
+       if (__dbus_init() < 0)
+               return -1;
+
+       __lcd_sid = g_dbus_connection_signal_subscribe(conn,
+                       NULL,
+                       DEVICED_INTERFACE_DISPLAY,
+                       LCD_ON,
+                       DEVICED_PATH_DISPLAY,
+                       NULL,
+                       G_DBUS_SIGNAL_FLAGS_NONE,
+                       __lcd_on_signal_handler,
+                       NULL,
+                       NULL);
+       if (!__lcd_sid) {
+               _E("Failed to subscribe LCD status signal");
+               return -1;
+       }
+
+       __deviced_signal_lcd_handler = func;
+       __deviced_signal_lcd_data = data;
+
+       _D("Listen LCD status signal");
+
+       return 0;
+}
+
+void _watch_base_signal_ignore_lcd_status_signal(void)
+{
+       __deviced_signal_lcd_handler = NULL;
+       __deviced_signal_lcd_data = NULL;
+
+       if (__lcd_sid) {
+               g_dbus_connection_signal_unsubscribe(conn, __lcd_sid);
+               __lcd_sid = 0;
+       }
+
+       __dbus_fini();
+
+       _D("Ignore LCD status signal");
+}
diff --git a/src/base/watch_base_signal.h b/src/base/watch_base_signal.h
new file mode 100755 (executable)
index 0000000..8503a40
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2015 - 2018 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 __WATCH_BASE_SIGNAL_H__
+#define __WATCH_BASE_SIGNAL_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int _watch_base_signal_listen_alpm_handler(int (*func)(int, void *), void *data);
+int _watch_base_signal_send_alpm_update_done(void);
+int _watch_base_signal_listen_lcd_status_signal(void (*func)(void *), void *data);
+void _watch_base_signal_ignore_lcd_status_signal(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __WATCH_BASE_SIGNAL_H__ */
+
diff --git a/src/base/watch_base_time.c b/src/base/watch_base_time.c
new file mode 100755 (executable)
index 0000000..c808f69
--- /dev/null
@@ -0,0 +1,335 @@
+/*
+ * Copyright (c) 2018 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 <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 <dlog.h>
+#include <app_common.h>
+#include <vconf.h>
+
+#include "watch_base_log.h"
+#include "watch_base_time.h"
+#include "watch_base.h"
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+
+#define LOG_TAG "WATCH_BASE_TIME"
+
+#define TIMEZONE_BUFFER_MAX 1024
+#define LOCAL_TIME_PATH "/opt/etc/localtime"
+
+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);
+}
+
+void _watch_base_time_get_timeinfo(struct _watch_base_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->indaylight = ucal_inDaylightTime(cal, &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);
+}
+
+EXPORT_API int watch_base_time_get_current_time(watch_base_time_h *watch_time)
+{
+       struct _watch_base_time_s *time_info;
+
+       if (!watch_base_check_feature())
+               return APP_ERROR_NOT_SUPPORTED;
+
+       if (watch_time == NULL)
+               return watch_base_set_error(APP_ERROR_INVALID_PARAMETER,
+                               __FUNCTION__, NULL);
+
+       time_info = calloc(1, sizeof(struct _watch_base_time_s));
+       if (time_info == NULL)
+               return watch_base_set_error(APP_ERROR_OUT_OF_MEMORY, __FUNCTION__,
+                               "failed to create a handle");
+
+       _watch_base_time_get_timeinfo(time_info);
+
+       *watch_time = (struct _watch_base_time_s *)time_info;
+
+       return APP_ERROR_NONE;
+}
+
+EXPORT_API int watch_base_time_delete(watch_base_time_h watch_time)
+{
+       if (!watch_base_check_feature())
+               return APP_ERROR_NOT_SUPPORTED;
+
+       if (watch_time == NULL)
+               return watch_base_set_error(APP_ERROR_INVALID_PARAMETER,
+                               __FUNCTION__, NULL);
+
+       if (watch_time->timezone)
+               free(watch_time->timezone);
+
+       free(watch_time);
+
+       return APP_ERROR_NONE;
+}
+
+EXPORT_API int watch_base_time_get_year(watch_base_time_h watch_time, int *year)
+{
+       if (!watch_base_check_feature())
+               return APP_ERROR_NOT_SUPPORTED;
+
+       if (watch_time == NULL)
+               return watch_base_set_error(APP_ERROR_INVALID_PARAMETER,
+                               __FUNCTION__, NULL);
+
+       *year = watch_time->year;
+       return APP_ERROR_NONE;
+}
+
+EXPORT_API int watch_base_time_get_month(watch_base_time_h watch_time, int *month)
+{
+       if (!watch_base_check_feature())
+               return APP_ERROR_NOT_SUPPORTED;
+
+       if (watch_time == NULL)
+               return watch_base_set_error(APP_ERROR_INVALID_PARAMETER,
+                               __FUNCTION__, NULL);
+
+       *month = watch_time->month;
+       return APP_ERROR_NONE;
+}
+
+EXPORT_API int watch_base_time_get_day(watch_base_time_h watch_time, int *day)
+{
+       if (!watch_base_check_feature())
+               return APP_ERROR_NOT_SUPPORTED;
+
+       if (watch_time == NULL)
+               return watch_base_set_error(APP_ERROR_INVALID_PARAMETER,
+                               __FUNCTION__, NULL);
+
+       *day = watch_time->day;
+       return APP_ERROR_NONE;
+}
+
+EXPORT_API int watch_base_time_get_day_of_week(watch_base_time_h watch_time,
+               int *day_of_week)
+{
+       if (!watch_base_check_feature())
+               return APP_ERROR_NOT_SUPPORTED;
+
+       if (watch_time == NULL)
+               return watch_base_set_error(APP_ERROR_INVALID_PARAMETER,
+                               __FUNCTION__, NULL);
+
+       *day_of_week = watch_time->day_of_week;
+       return APP_ERROR_NONE;
+}
+
+EXPORT_API int watch_base_time_get_hour(watch_base_time_h watch_time, int *hour)
+{
+       if (!watch_base_check_feature())
+               return APP_ERROR_NOT_SUPPORTED;
+
+       if (watch_time == NULL)
+               return watch_base_set_error(APP_ERROR_INVALID_PARAMETER,
+                               __FUNCTION__, NULL);
+
+       *hour = watch_time->hour;
+       return APP_ERROR_NONE;
+}
+
+EXPORT_API int watch_base_time_get_hour24(watch_base_time_h watch_time, int *hour24)
+{
+       if (!watch_base_check_feature())
+               return APP_ERROR_NOT_SUPPORTED;
+
+       if (watch_time == NULL)
+               return watch_base_set_error(APP_ERROR_INVALID_PARAMETER,
+                               __FUNCTION__, NULL);
+
+       *hour24 = watch_time->hour24;
+       return APP_ERROR_NONE;
+}
+
+EXPORT_API int watch_base_time_get_minute(watch_base_time_h watch_time, int *minute)
+{
+       if (!watch_base_check_feature())
+               return APP_ERROR_NOT_SUPPORTED;
+
+       if (watch_time == NULL)
+               return watch_base_set_error(APP_ERROR_INVALID_PARAMETER,
+                               __FUNCTION__, NULL);
+
+       *minute = watch_time->minute;
+       return APP_ERROR_NONE;
+}
+
+EXPORT_API int watch_base_time_get_second(watch_base_time_h watch_time, int *second)
+{
+       if (!watch_base_check_feature())
+               return APP_ERROR_NOT_SUPPORTED;
+
+       if (watch_time == NULL)
+               return watch_base_set_error(APP_ERROR_INVALID_PARAMETER,
+                               __FUNCTION__, NULL);
+
+       *second = watch_time->second;
+       return APP_ERROR_NONE;
+}
+
+EXPORT_API int watch_base_time_get_millisecond(watch_base_time_h watch_time,
+               int *millisecond)
+{
+       if (!watch_base_check_feature())
+               return APP_ERROR_NOT_SUPPORTED;
+
+       if (watch_time == NULL)
+               return watch_base_set_error(APP_ERROR_INVALID_PARAMETER,
+                               __FUNCTION__, NULL);
+
+       *millisecond = watch_time->millisecond;
+       return APP_ERROR_NONE;
+}
+
+EXPORT_API int watch_base_time_get_utc_time(watch_base_time_h watch_time,
+               struct tm *utc_time)
+{
+       time_t timestamp;
+
+       if (!watch_base_check_feature())
+               return APP_ERROR_NOT_SUPPORTED;
+
+       if (watch_time == NULL || utc_time == NULL)
+               return watch_base_set_error(APP_ERROR_INVALID_PARAMETER,
+                               __FUNCTION__, NULL);
+
+       timestamp = watch_time->timestamp;
+
+       gmtime_r(&timestamp, utc_time);
+
+       return APP_ERROR_NONE;
+}
+
+EXPORT_API int watch_base_time_get_utc_timestamp(watch_base_time_h watch_time,
+               time_t *utc_timestamp)
+{
+       if (!watch_base_check_feature())
+               return APP_ERROR_NOT_SUPPORTED;
+
+       if (watch_time == NULL)
+               return watch_base_set_error(APP_ERROR_INVALID_PARAMETER,
+                               __FUNCTION__, NULL);
+
+       *utc_timestamp = watch_time->timestamp;
+
+       return APP_ERROR_NONE;
+}
+
+EXPORT_API int watch_base_time_get_time_zone(watch_base_time_h watch_time,
+               char **time_zone_id)
+{
+       if (!watch_base_check_feature())
+               return APP_ERROR_NOT_SUPPORTED;
+
+       if (watch_time == NULL || watch_time->timezone == NULL
+                       || time_zone_id == NULL)
+               return watch_base_set_error(APP_ERROR_INVALID_PARAMETER,
+                               __FUNCTION__, NULL);
+
+       *time_zone_id = strdup(watch_time->timezone);
+
+       return APP_ERROR_NONE;
+}
+
+EXPORT_API int watch_base_time_get_dst_status(watch_base_time_h watch_time, bool *status)
+{
+       if (!watch_base_check_feature())
+               return APP_ERROR_NOT_SUPPORTED;
+
+       if (watch_time == NULL || status == NULL)
+               return watch_base_set_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
+
+       if (watch_time->indaylight)
+               *status = true;
+       else
+               *status = false;
+
+       return APP_ERROR_NONE;
+}
+
+EXPORT_API int watch_base_time_get_daylight_time_status(watch_base_time_h watch_time, bool *daylight)
+{
+       if (!watch_base_check_feature())
+               return APP_ERROR_NOT_SUPPORTED;
+
+       return watch_base_time_get_dst_status(watch_time, daylight);
+}
diff --git a/src/base/watch_base_time.h b/src/base/watch_base_time.h
new file mode 100755 (executable)
index 0000000..6694915
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2015 - 2018 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 __WATCH_BASE_TIME_H__
+#define __WATCH_BASE_TIME_H__
+
+#include <sys/time.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct _watch_base_time_s {
+       int year;
+       int month;
+       int day_of_week;
+       int day;
+       int hour;
+       int hour24;
+       int minute;
+       int second;
+       int millisecond;
+       int indaylight;
+       time_t timestamp;
+       char *timezone;
+};
+
+void _watch_base_time_get_timeinfo(struct _watch_base_time_s *timeinfo);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __WATCH_BASE_TIME_H__ */
+
diff --git a/src/efl_base/watch_app_log.h b/src/efl_base/watch_app_log.h
new file mode 100755 (executable)
index 0000000..1723957
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2015 - 2018 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 __WATCH_APP_LOG_H__
+#define __WATCH_APP_LOG_H__
+
+#include <dlog.h>
+
+#define _E(fmt, arg...) LOGE(fmt, ##arg)
+#define _I(fmt, arg...) LOGI(fmt, ##arg)
+#define _D(fmt, arg...) LOGD(fmt, ##arg)
+#define _W(fmt, arg...) LOGW(fmt, ##arg)
+
+#ifndef EXPORT_API
+#define EXPORT_API __attribute__ ((visibility("default")))
+#endif
+
+#ifndef _E
+#define _E(fmt, arg...) LOGE(fmt, ##arg)
+#endif
+
+#ifndef _I
+#define _I(...) LOGI(__VA_ARGS__)
+#endif
+
+#ifndef _D
+#define _D(...) LOGD(__VA_ARGS__)
+#endif
+
+#ifndef _W
+#define _W(...) LOGW(__VA_ARGS__)
+#endif
+
+#endif /*__WATCH_APP_LOG_H_ */
diff --git a/src/efl_base/watch_app_main.c b/src/efl_base/watch_app_main.c
new file mode 100755 (executable)
index 0000000..d4d893f
--- /dev/null
@@ -0,0 +1,360 @@
+/*
+ * Copyright (c) 2015 - 2018 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 <Evas.h>
+#include <Elementary.h>
+#include <Ecore_Wl2.h>
+#include <screen_connector_provider.h>
+
+#include "watch_app_log.h"
+#include "watch_base.h"
+#include "watch_app.h"
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+
+#define LOG_TAG "CAPI_WATCH_APPLICATION"
+
+struct watch_app_context {
+       watch_app_lifecycle_callback_s callback;
+       void *data;
+};
+
+static struct watch_app_context __context;
+static Evas_Object *__watch_win;
+
+static void __on_init(int argc, char **argv, void *data)
+{
+       elm_init(argc, argv);
+}
+
+static void __on_finish(void)
+{
+       elm_shutdown();
+}
+
+static void __on_run(void *data)
+{
+       elm_run();
+}
+
+static void __on_exit(void *data)
+{
+       elm_exit();
+}
+
+static void __on_pre_resume(void *data)
+{
+       int w, h;
+       Ecore_Evas *ee;
+
+       watch_base_on_preresume();
+
+       if (__watch_win == NULL)
+               return;
+
+       ee = ecore_evas_ecore_evas_get(evas_object_evas_get(__watch_win));
+       evas_output_viewport_get(ecore_evas_get(ee), NULL, NULL, &w, &h);
+       evas_obscured_clear(ecore_evas_get(ee));
+       evas_damage_rectangle_add(ecore_evas_get(ee), 0, 0, w, h);
+       ecore_evas_manual_render(ee);
+}
+
+static bool __on_create(int width, int height, void *user_data)
+{
+       watch_base_on_create(width, height);
+       if (__context.callback.create)
+               return __context.callback.create(width, height, __context.data);
+       return false;
+}
+
+static void __on_control(app_control_h app_control, void *user_data)
+{
+       watch_base_on_control(app_control);
+       if (__context.callback.app_control)
+               __context.callback.app_control(app_control, __context.data);
+}
+
+static void __on_pause(void *user_data)
+{
+       watch_base_on_pause();
+       if (__context.callback.pause)
+               __context.callback.pause(__context.data);
+}
+
+static void __on_resume(void *user_data)
+{
+       watch_base_on_resume();
+       if (__context.callback.resume)
+               __context.callback.resume(__context.data);
+}
+
+static void __on_terminate(void *user_data)
+{
+       if (__context.callback.terminate)
+               __context.callback.terminate(__context.data);
+       watch_base_on_terminate();
+}
+
+static void __on_time_tick(watch_base_time_h watch_base_time, void *user_data)
+{
+       if (__context.callback.time_tick) {
+               __context.callback.time_tick((watch_time_h)watch_base_time,
+                               __context.data);
+       }
+}
+
+static void __on_ambient_tick(watch_base_time_h watch_base_time, void *user_data)
+{
+       if (__context.callback.ambient_tick) {
+               __context.callback.ambient_tick((watch_time_h)watch_base_time,
+                               __context.data);
+       }
+}
+
+static void __on_ambient_changed(bool ambient_mode, void *user_data)
+{
+       if (__context.callback.ambient_changed) {
+               __context.callback.ambient_changed(ambient_mode,
+                               __context.data);
+       }
+}
+
+EXPORT_API int watch_app_main(int argc, char **argv,
+               watch_app_lifecycle_callback_s *callback, void *user_data)
+{
+       int r;
+       watch_base_ops ops = watch_base_get_default_ops();
+
+       if (argc <= 0 || argv == NULL || callback == NULL)
+               return watch_base_set_error(APP_ERROR_INVALID_PARAMETER,
+                               __FUNCTION__, NULL);
+
+       if (callback->create == NULL)
+               return watch_base_set_error(APP_ERROR_INVALID_PARAMETER,
+                               __FUNCTION__,
+                               "create-callback is NULL");
+
+       ops.create = __on_create;
+       ops.app_control = __on_control;
+       ops.pause = __on_pause;
+       ops.preresume = __on_pre_resume;
+       ops.resume = __on_resume;
+       ops.terminate = __on_terminate;
+       ops.time_tick = __on_time_tick;
+       ops.ambient_tick = __on_ambient_tick;
+       ops.ambient_changed = __on_ambient_changed;
+       ops.init = __on_init;
+       ops.finish = __on_finish;
+       ops.run = __on_run;
+       ops.exit = __on_exit;
+
+       __context.callback = *callback;
+       __context.data = user_data;
+
+       r = watch_base_init(argc, argv, &ops, NULL);
+       watch_base_fini();
+
+       return r;
+}
+
+EXPORT_API void watch_app_exit(void)
+{
+       watch_base_exit();
+}
+
+EXPORT_API int watch_app_add_event_handler(app_event_handler_h *event_handler,
+               app_event_type_e event_type, app_event_cb callback,
+               void *user_data)
+{
+       return watch_base_add_event_handler(event_handler, event_type,
+               callback, user_data);
+}
+
+EXPORT_API int watch_app_remove_event_handler(app_event_handler_h event_handler)
+{
+       return watch_base_remove_event_handler(event_handler);
+}
+
+EXPORT_API int watch_time_get_current_time(watch_time_h *watch_time)
+{
+       return watch_base_time_get_current_time((watch_base_time_h *)watch_time);
+}
+
+EXPORT_API int watch_time_delete(watch_time_h watch_time)
+{
+       return watch_base_time_delete((watch_base_time_h)watch_time);
+}
+
+EXPORT_API int watch_time_get_year(watch_time_h watch_time, int *year)
+{
+       return watch_base_time_get_year((watch_base_time_h)watch_time, year);
+}
+
+EXPORT_API int watch_time_get_month(watch_time_h watch_time, int *month)
+{
+       return watch_base_time_get_month((watch_base_time_h)watch_time, month);
+}
+
+EXPORT_API int watch_time_get_day(watch_time_h watch_time, int *day)
+{
+       return watch_base_time_get_day((watch_base_time_h)watch_time, day);
+}
+
+EXPORT_API int watch_time_get_day_of_week(watch_time_h watch_time,
+               int *day_of_week)
+{
+       return watch_base_time_get_day_of_week((watch_base_time_h)watch_time,
+                       day_of_week);
+}
+
+EXPORT_API int watch_time_get_hour(watch_time_h watch_time, int *hour)
+{
+       return watch_base_time_get_hour((watch_base_time_h)watch_time, hour);
+}
+
+EXPORT_API int watch_time_get_hour24(watch_time_h watch_time, int *hour24)
+{
+       return watch_base_time_get_hour24((watch_base_time_h)watch_time, hour24);
+}
+
+EXPORT_API int watch_time_get_minute(watch_time_h watch_time, int *minute)
+{
+       return watch_base_time_get_minute((watch_base_time_h)watch_time, minute);
+}
+
+EXPORT_API int watch_time_get_second(watch_time_h watch_time, int *second)
+{
+       return watch_base_time_get_second((watch_base_time_h)watch_time, second);
+}
+
+EXPORT_API int watch_time_get_millisecond(watch_time_h watch_time,
+               int *millisecond)
+{
+       return watch_base_time_get_millisecond((watch_base_time_h)watch_time,
+                       millisecond);
+}
+
+EXPORT_API int watch_time_get_utc_time(watch_time_h watch_time,
+               struct tm *utc_time)
+{
+       return watch_base_time_get_utc_time((watch_base_time_h)watch_time,
+                       utc_time);
+}
+
+EXPORT_API int watch_time_get_utc_timestamp(watch_time_h watch_time,
+               time_t *utc_timestamp)
+{
+       return watch_base_time_get_utc_timestamp((watch_base_time_h)watch_time,
+                       utc_timestamp);
+}
+
+EXPORT_API int watch_time_get_time_zone(watch_time_h watch_time,
+               char **time_zone_id)
+{
+       return watch_base_time_get_time_zone((watch_base_time_h)watch_time,
+                       time_zone_id);
+}
+
+EXPORT_API int watch_time_get_dst_status(watch_time_h watch_time, bool *status)
+{
+       return watch_base_time_get_dst_status((watch_base_time_h)watch_time,
+                       status);
+}
+
+EXPORT_API int watch_time_get_daylight_time_status(watch_time_h watch_time,
+               bool *daylight)
+{
+       return watch_base_time_get_dst_status(
+                       (watch_base_time_h)watch_time, daylight);
+}
+
+static void __win_del_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
+{
+       char *plug_id;
+       plug_id = evas_object_data_del(obj, "___PLUGID");
+       free(plug_id);
+
+       if (__watch_win == obj)
+               __watch_win = NULL;
+}
+
+EXPORT_API int watch_app_get_elm_win(Evas_Object **win)
+{
+       Evas_Object *ret_win;
+       struct wl_surface *surface;
+       Ecore_Wl2_Window *wl_win;
+       Ecore_Evas *ee;
+       char buffer[256];
+
+       if (!watch_base_check_feature())
+               return APP_ERROR_NOT_SUPPORTED;
+
+       if (win == NULL)
+               return watch_base_set_error(APP_ERROR_INVALID_PARAMETER,
+                               __FUNCTION__, NULL);
+
+       ret_win = elm_win_add(NULL, watch_base_get_current_appid(), ELM_WIN_BASIC);
+       if (ret_win == NULL)
+               return watch_base_set_error(APP_ERROR_OUT_OF_MEMORY,
+                               __FUNCTION__, NULL);
+
+       ee = ecore_evas_ecore_evas_get(evas_object_evas_get(ret_win));
+       wl_win = ecore_evas_wayland2_window_get(ee);
+       if (wl_win == NULL)
+               _E("failed to get surface");
+
+       surface = ecore_wl2_window_surface_get(wl_win);
+       screen_connector_provider_remote_enable(watch_base_get_current_appid(),
+                       surface);
+
+       /* Set data to use in accessibility */
+       snprintf(buffer, sizeof(buffer), "%s:%d", watch_base_get_current_appid(), getpid());
+       evas_object_data_set(ret_win, "___PLUGID", strdup(buffer));
+       evas_object_event_callback_add(ret_win, EVAS_CALLBACK_DEL, __win_del_cb, NULL);
+
+       *win = ret_win;
+       __watch_win = ret_win;
+
+       return APP_ERROR_NONE;
+}
+
+EXPORT_API int watch_app_set_ambient_tick_type(watch_app_ambient_tick_type_e type)
+{
+       return watch_base_set_ambient_tick_type(
+                       (watch_base_ambient_tick_type_e)type);
+}
+
+EXPORT_API int watch_app_get_ambient_tick_type(watch_app_ambient_tick_type_e *type)
+{
+       return watch_base_get_ambient_tick_type(
+                       (watch_base_ambient_tick_type_e *)type);
+}
+
+EXPORT_API int watch_app_set_time_tick_frequency(int ticks,
+               watch_app_time_tick_resolution_e type)
+{
+       return watch_base_set_time_tick_frequency(ticks,
+                       (watch_base_time_tick_resolution_e)type);
+}
+
+EXPORT_API int watch_app_get_time_tick_frequency(int *ticks,
+               watch_app_time_tick_resolution_e *type)
+{
+       return watch_base_get_time_tick_frequency(ticks,
+                       (watch_base_time_tick_resolution_e *)type);
+}
diff --git a/src/watch_app_error.c b/src/watch_app_error.c
deleted file mode 100755 (executable)
index 757c125..0000000
+++ /dev/null
@@ -1,64 +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 <string.h>
-#include <libintl.h>
-
-#include <dlog.h>
-#include <app_common.h>
-
-#include "watch_app_private.h"
-
-#ifdef LOG_TAG
-#undef LOG_TAG
-#endif
-
-#define LOG_TAG "CAPI_APPFW_APPLICATION"
-
-static const char *watch_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 watch_app_error(app_error_e error, const char *function,
-               const char *description)
-{
-       if (description)
-               LOGE("[%s] %s(0x%08x) : %s", function,
-                               watch_app_error_to_string(error), error,
-                               description);
-       else
-               LOGE("[%s] %s(0x%08x)", function,
-                               watch_app_error_to_string(error), error);
-
-       return error;
-}
-
diff --git a/src/watch_app_main.c b/src/watch_app_main.c
deleted file mode 100755 (executable)
index a477c53..0000000
+++ /dev/null
@@ -1,1375 +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 <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 <Evas.h>
-#include <Elementary.h>
-#include <Ecore_Wl2.h>
-#include <screen_connector_provider.h>
-#include <appcore_efl_base.h>
-#include <alarm.h>
-#include <vconf.h>
-#include <glib-object.h>
-#include <app_control.h>
-#include <app_control_internal.h>
-#include <bundle_internal.h>
-#include <pkgmgr-info.h>
-#include <aul_app_com.h>
-#include <aul_screen_connector.h>
-
-#include "appcore-watch-log.h"
-#include "watch_app_private.h"
-#include "appcore-watch-signal.h"
-
-#ifdef LOG_TAG
-#undef LOG_TAG
-#endif
-
-#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
-#define METADATA_TICK_PER_SECOND       "http://developer.samsung.com/tizen/metadata/tickpersecond"
-#define METADATA_MINUTE_TICK           "http://developer.samsung.com/tizen/metadata/minutetick"
-
-typedef enum {
-       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;
-
-enum watch_state {
-       WS_NONE,
-       WS_CREATED,
-       WS_RUNNING,
-       WS_PAUSED,
-       WS_DYING,
-};
-
-struct _watch_time_s {
-       int year;
-       int month;
-       int day_of_week;
-       int day;
-       int hour;
-       int hour24;
-       int minute;
-       int second;
-       int millisecond;
-       int indaylight;
-       time_t timestamp;
-       char *timezone;
-};
-
-enum watch_visible_state {
-       WVS_UNKNOWN,
-       WVS_PAUSE,
-       WVS_RESUME
-};
-
-#define WATCH_APP_EVENT_MAX 5
-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;
-static aul_app_com_connection_h __conn_viewer_state;
-
-struct app_event_handler {
-       app_event_type_e type;
-       app_event_cb cb;
-       void *data;
-       void *raw;
-};
-
-struct app_event_info {
-       app_event_type_e type;
-       void *value;
-};
-
-struct watch_app_context {
-       char *appid;
-       watch_app_state_e state;
-       watch_app_lifecycle_callback_s callback;
-       int width;
-       int height;
-       enum watch_visible_state watch_visibility;
-       int viewer_visibility;
-       bool ambient_mode;
-       bool ambient_mode_skip_resume;
-       void *data;
-};
-
-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 double __prev_target_tick = -1;
-static Evas_Object *__watch_win;
-enum watch_state __state;
-
-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 bool __check_feature(void)
-{
-       static bool is_checked = false;
-       static bool is_supported = false;
-
-       if (is_checked)
-               return is_supported;
-       if (!system_info_get_platform_bool(WATCH_APP_FEATURE, &is_supported)) {
-               is_checked = true;
-               if (!is_supported) {
-                       LOGE("[%s] feature is disabled", WATCH_APP_FEATURE);
-                       return false;
-               }
-       }
-       return is_supported;
-}
-
-static void __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 != AUL_R_OK) {
-               _E("fail to get the appid from the pid : %d", pid);
-               assert(0);
-       }
-
-       r = alarmmgr_init(appid);
-       if (r != ALARMMGR_RESULT_SUCCESS) {
-               _E("fail to alarmmgr_init : error_code : %d", r);
-               assert(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->indaylight = ucal_inDaylightTime(cal, &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;
-       double target;
-
-       struct _watch_time_s timeinfo = {
-               .timezone = NULL
-       };
-
-       __get_timeinfo(&timeinfo);
-       cur_time_in_milli = timeinfo.hour24 * 60 * 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;
-       target = (idx + 1) * term;
-
-       if (__prev_target_tick == target)
-               target = __prev_target_tick + term;
-
-       sec = (target - cur_time_in_milli) / 1000.0;
-       __prev_target_tick = target;
-
-       if (timeinfo.timezone)
-               free(timeinfo.timezone);
-
-       return sec;
-}
-
-/* LCOV_EXCL_START */
-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;
-}
-/* LCOV_EXCL_STOP */
-
-/* LCOV_EXCL_START */
-static int __ambient_tick_cb(alarm_id_t id, void *data)
-{
-       struct _watch_time_s timeinfo = {
-               .timezone = NULL
-       };
-
-       __get_timeinfo(&timeinfo);
-       __on_ambient_tick(&timeinfo, data);
-
-       if (timeinfo.timezone)
-               free(timeinfo.timezone);
-
-       return 0;
-}
-/* LCOV_EXCL_STOP */
-
-/* LCOV_EXCL_START */
-static int __set_ambient_tick_cb(void *data)
-{
-       int offset_sec = 0;
-       int interval = 0;
-       struct _watch_time_s timeinfo = {
-               .timezone = NULL
-       };
-       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);
-               __on_ambient_tick(&timeinfo, data);
-       }
-
-       if (timeinfo.timezone)
-               free(timeinfo.timezone);
-
-       return 0;
-}
-/* LCOV_EXCL_STOP */
-
-/* LCOV_EXCL_START */
-static int __signal_alpm_handler(int ambient, void *data)
-{
-       struct _watch_time_s timeinfo = {
-               .timezone = NULL
-       };
-
-       _D("_signal_alpm_handler: ambient: %d", ambient);
-       if (__context.ambient_mode == ambient) {
-               _E("invalid state");
-               return 0;
-       }
-
-       /* Enter the ambient mode */
-       if (ambient) {
-               if (appcore_efl_base_is_resumed()) {
-                       appcore_efl_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);
-
-               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 */
-
-               __get_timeinfo(&timeinfo);
-               __on_ambient_tick(&timeinfo, data);
-
-               __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_efl_base_resume();
-               }
-
-               /* Disable alarm */
-               if (alarm_id) {
-                       alarmmgr_remove_alarm(alarm_id);
-                       alarm_id = 0;
-               }
-       }
-
-       if (timeinfo.timezone)
-               free(timeinfo.timezone);
-
-       return 0;
-}
-/* LCOV_EXCL_STOP */
-
-static Eina_Bool __time_tick_cb(void *data)
-{
-       struct _watch_time_s timeinfo = {
-               .timezone = NULL
-       };
-       double sec;
-
-       _D("state: %d", __state);
-       if (__context.callback.time_tick && __state != WS_PAUSED) {
-               __get_timeinfo(&timeinfo);
-
-               /* Set a next timer */
-               sec = __get_next_tick_sec();
-               watch_tick = ecore_timer_add(sec, __time_tick_cb, data);
-               __on_time_tick(&timeinfo, data);
-
-               if (timeinfo.timezone)
-                       free(timeinfo.timezone);
-       }
-
-       return ECORE_CALLBACK_CANCEL;
-}
-
-static void __time_tick_cancel(void)
-{
-       if (watch_tick) {
-               ecore_timer_del(watch_tick);
-               watch_tick = NULL;
-               __prev_target_tick = -1;
-       }
-}
-
-static void __set_default_tick_by_metadata()
-{
-       char appid[APPID_BUFFER_MAX] = {0,};
-       pkgmgrinfo_appinfo_h handle = NULL;
-       char *second_tick = NULL;
-       char *minute_tick = NULL;
-       int ret;
-       int tick;
-
-       ret = aul_app_get_appid_bypid(getpid(), appid, sizeof(appid));
-       if (ret < 0) {
-               _E("fail to get the appid from the pid : %d", getpid());
-               return;
-       }
-
-       ret = pkgmgrinfo_appinfo_get_appinfo(appid, &handle);
-       if (ret != PMINFO_R_OK)
-               return;
-
-       /* If both minute tick & second tick are declared, only minute tick has to be applied */
-       ret = pkgmgrinfo_appinfo_get_metadata_value(handle, METADATA_MINUTE_TICK, &minute_tick);
-       if (ret == PMINFO_R_OK) {
-               _D("set default tick 1, type %d", WATCH_APP_TIME_TICKS_PER_MINUTE);
-               app_tick_type = WATCH_APP_TIME_TICKS_PER_MINUTE;
-               app_tick_resolution = 1;
-               pkgmgrinfo_appinfo_destroy_appinfo(handle);
-               return;
-       }
-
-       pkgmgrinfo_appinfo_get_metadata_value(handle, METADATA_TICK_PER_SECOND, &second_tick);
-       if (second_tick) {
-               sscanf(second_tick, "%d", &tick);
-               if (tick > 0) {
-                       _D("set default tick %d, type %d", tick, WATCH_APP_TIME_TICKS_PER_SECOND);
-                       app_tick_type = WATCH_APP_TIME_TICKS_PER_SECOND;
-                       app_tick_resolution = tick;
-                       pkgmgrinfo_appinfo_destroy_appinfo(handle);
-                       return;
-               }
-       }
-
-       pkgmgrinfo_appinfo_destroy_appinfo(handle);
-       return;
-}
-
-/* LCOV_EXCL_START */
-static void __vconf_time_changed_cb(keynode_t *key, void *data)
-{
-       struct _watch_time_s timeinfo = {
-               .timezone = NULL
-       };
-
-       _D("ambient_mode check: %d", __context.ambient_mode);
-       __get_timeinfo(&timeinfo);
-       if (__context.ambient_mode) {
-               if (alarm_id) {
-                       alarmmgr_remove_alarm(alarm_id);
-                       alarm_id = 0;
-               }
-               __set_ambient_tick_cb(data);
-               __on_ambient_tick(&timeinfo, data);
-       } else {
-               __time_tick_cb(data);
-       }
-
-       if (timeinfo.timezone)
-               free(timeinfo.timezone);
-
-       return;
-}
-/* LCOV_EXCL_STOP */
-
-static int __on_create(void *data)
-{
-       watch_app_create_cb create_cb;
-
-       _W("_watch_core_create");
-
-       __set_default_tick_by_metadata();
-       screen_connector_provider_init();
-       _watch_core_listen_alpm_handler(__signal_alpm_handler, data);
-
-       create_cb = __context.callback.create;
-
-       appcore_efl_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");
-       __state = WS_CREATED;
-
-       /* Alarm init */
-       __alarm_init();
-       __context.state = WATCH_APP_STATE_RUNNING;
-
-       vconf_notify_key_changed(VCONFKEY_SYSTEM_TIME_CHANGED,
-                               __vconf_time_changed_cb, data);
-
-       return APP_ERROR_NONE;
-}
-
-static int __on_control(bundle *b, void *data)
-{
-       app_control_h app_control = NULL;
-       appcore_efl_base_on_control(b);
-
-       _W("_watch_core_control");
-
-       if (app_control_create_event(b, &app_control) != 0)
-               return -1;
-
-       if (__context.callback.app_control)
-               __context.callback.app_control(app_control, __context.data);
-
-       app_control_destroy(app_control);
-
-       return APP_ERROR_NONE;
-}
-
-/* LCOV_EXCL_START */
-static int __on_pause(void *data)
-{
-       _W("_watch_core_pause");
-
-       if (__state == WS_CREATED) {
-               _E("Invalid state");
-               return APP_ERROR_NONE;
-       }
-
-       /* Handling the ambient mode */
-       if (__context.ambient_mode)
-               __context.ambient_mode_skip_resume = 1;
-
-       /* Cancel the time_tick callback */
-       __time_tick_cancel();
-
-       if (__state == WS_RUNNING) {
-               appcore_efl_base_on_pause();
-               if (__context.callback.pause)
-                       __context.callback.pause(__context.data);
-       }
-
-       __state = WS_PAUSED;
-
-       return APP_ERROR_NONE;
-}
-/* LCOV_EXCL_STOP */
-
-static void __on_pre_resume(void *data)
-{
-       int w, h;
-       Ecore_Evas *ee;
-       struct _watch_time_s timeinfo = {
-               .timezone = NULL
-       };
-
-       __get_timeinfo(&timeinfo);
-       __on_time_tick(&timeinfo, data);
-
-       if (timeinfo.timezone)
-               free(timeinfo.timezone);
-
-       if (__watch_win == NULL)
-               return;
-
-       ee = ecore_evas_ecore_evas_get(evas_object_evas_get(__watch_win));
-       evas_output_viewport_get(ecore_evas_get(ee), NULL, NULL, &w, &h);
-       evas_obscured_clear(ecore_evas_get(ee));
-       evas_damage_rectangle_add(ecore_evas_get(ee), 0, 0, w, h);
-       ecore_evas_manual_render(ee);
-}
-
-static int __on_resume(void *data)
-{
-       _W("_watch_core_resume");
-       if (__context.viewer_visibility != AUL_SCREEN_STATUS_RESUME) {
-               _D("Viewer is paused, do not resume watch");
-               return APP_ERROR_NONE;
-       }
-
-       if (__context.ambient_mode) {
-               __context.ambient_mode_skip_resume = false;
-               return 0;
-       }
-
-       if (__state != WS_PAUSED && __state != WS_CREATED)
-               return APP_ERROR_NONE;
-
-       appcore_efl_base_on_resume();
-
-       if (__context.callback.resume)
-               __context.callback.resume(__context.data);
-
-       __state = WS_RUNNING;
-
-       if (!watch_tick) {
-               __time_tick_cb(data);
-       } else {
-               __time_tick_cancel();
-               __time_tick_cb(data);
-       }
-
-       return APP_ERROR_NONE;
-}
-
-static int __on_terminate(void *data)
-{
-       _W("_watch_core_terminate");
-
-       __state = WS_DYING;
-       if (appcore_efl_base_is_resumed())
-               appcore_efl_base_pause();
-
-       /* Cancel the time_tick callback */
-       __time_tick_cancel();
-
-       if (__context.callback.terminate)
-               __context.callback.terminate(__context.data);
-
-       alarmmgr_fini();
-       appcore_efl_base_on_terminate();
-       screen_connector_provider_fini();
-
-       return APP_ERROR_NONE;
-}
-
-static void __on_time_tick(void *watchtime, void *data)
-{
-       watch_app_time_tick_cb time_tick_cb;
-
-       _I("_watch_core_time_tick");
-
-       time_tick_cb = __context.callback.time_tick;
-
-       if (time_tick_cb != NULL)
-               time_tick_cb((watch_time_h)watchtime, __context.data);
-}
-
-/* LCOV_EXCL_START */
-static void __on_ambient_tick(void *watchtime, void *data)
-{
-       watch_app_ambient_tick_cb ambient_tick_cb;
-
-       _W("_watch_core_ambient_tick");
-
-       ambient_tick_cb = __context.callback.ambient_tick;
-
-       if (ambient_tick_cb != NULL)
-               ambient_tick_cb((watch_time_h)watchtime, __context.data);
-}
-/* LCOV_EXCL_STOP */
-
-/* LCOV_EXCL_START */
-static void __on_ambient_changed(int ambient, void *data)
-{
-       watch_app_ambient_changed_cb ambient_changed_cb;
-
-       _W("_watch_core_ambient_changed: %d", ambient);
-
-       ambient_changed_cb = __context.callback.ambient_changed;
-
-       if (ambient_changed_cb != NULL)
-               ambient_changed_cb((bool)ambient, __context.data);
-}
-/* LCOV_EXCL_STOP */
-
-static void __on_window_show(int type, void *event, void *data)
-{
-       appcore_efl_base_window_on_show(type, event);
-       if (__context.viewer_visibility == AUL_SCREEN_STATUS_RESUME)
-               appcore_efl_base_resume();
-       else
-               _D("viewer is not resumed, do not resume watch");
-}
-
-static void __on_window_visibility(int type, void *event, void *data)
-{
-       Ecore_Wl2_Event_Window_Visibility_Change *ev = event;
-
-       _D("visibility %u %u",
-                       (unsigned int)ev->win,
-                       (unsigned int)ev->fully_obscured);
-
-       if (ev->fully_obscured) {
-               __context.watch_visibility = WVS_PAUSE;
-               __on_pause(NULL);
-       } else {
-               __context.watch_visibility = WVS_RESUME;
-               if (__context.viewer_visibility == AUL_SCREEN_STATUS_RESUME)
-                       __on_resume(NULL);
-               else
-                       _D("Viewer is paused, do not resume watch");
-       }
-}
-
-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 = {
-               .timezone = NULL
-       };
-
-       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: %lf, type: %d, tick: %d", sec, type, ticks);
-
-       if (appcore_efl_base_is_resumed()) {
-               __get_timeinfo(&timeinfo);
-               __on_time_tick(&timeinfo, NULL);
-       }
-
-       if (timeinfo.timezone)
-               free(timeinfo.timezone);
-
-       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;
-}
-
-static int __viewer_state_handler(const char *widget_id, aul_app_com_result_e e,
-               bundle *envelope, void *user_data)
-{
-       int *state = NULL;
-       size_t state_sz = 0;
-       struct _watch_time_s timeinfo = {
-               .timezone = NULL
-       };
-
-       bundle_get_byte(envelope, "__AUL_SC_VIEWER_STATUS__", (void **)&state,
-                       &state_sz);
-       if (state == NULL) {
-               _E("Failed to get viewer status");
-               return -1;
-       }
-
-       _D("receive viewer state %d", *state);
-       if (*state != AUL_SCREEN_STATUS_PRE_RESUME) {
-               __context.viewer_visibility = *state;
-               _D("set viewer state to %d", *state);
-       }
-
-       if (*state == AUL_SCREEN_STATUS_RESUME &&
-                       __context.watch_visibility == WVS_RESUME) {
-               __on_resume(NULL);
-       } else if (*state == AUL_SCREEN_STATUS_PAUSE) {
-               __on_pause(NULL);
-       } else if (*state == AUL_SCREEN_STATUS_PRE_RESUME) {
-               _D("call pre resume tick");
-               __on_pre_resume(NULL);
-       }
-
-       if (timeinfo.timezone)
-               free(timeinfo.timezone);
-
-       return 0;
-}
-
-static void __lcd_on_handler(void *user_data)
-{
-       _D("Call pre resume tick");
-       __on_pre_resume(NULL);
-}
-
-EXPORT_API int watch_app_main(int argc, char **argv,
-               watch_app_lifecycle_callback_s *callback, void *user_data)
-{
-       int ret;
-       bundle *kb;
-       char *width_str = NULL;
-       char *height_str = NULL;
-       int width = 360;
-       int height = 360;
-       appcore_efl_base_ops ops = appcore_efl_base_get_default_ops();
-       char *viewer_visibility_str = NULL;
-
-       if (!__check_feature())
-               return APP_ERROR_NOT_SUPPORTED;
-
-       /* override methods */
-       ops.ui_base.base.create = __on_create;
-       ops.ui_base.base.control = __on_control;
-       ops.ui_base.base.terminate = __on_terminate;
-       ops.ui_base.pause = __on_pause;
-       ops.ui_base.resume = __on_resume;
-       ops.ui_base.window.show = __on_window_show;
-       ops.ui_base.window.visibility = __on_window_visibility;
-
-       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);
-               bundle_get_str(kb, "WATCH_VIEWER_VISIBILITY",
-                               &viewer_visibility_str);
-
-               if (width_str)
-                       width = atoi(width_str);
-
-               if (height_str)
-                       height = atoi(height_str);
-
-               if (viewer_visibility_str) {
-                       __context.viewer_visibility =
-                                       atoi(viewer_visibility_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,
-                               __FUNCTION__, NULL);
-
-       if (callback->create == NULL)
-               return watch_app_error(APP_ERROR_INVALID_PARAMETER,
-                               __FUNCTION__,
-                               "watch_app_create_cb() callback must be "
-                               "registered");
-
-       if (__context.state != WATCH_APP_STATE_NOT_RUNNING)
-               return watch_app_error(APP_ERROR_ALREADY_RUNNING, __FUNCTION__,
-                               NULL);
-
-       if (app_get_id(&(__context.appid)) != APP_ERROR_NONE)
-               return watch_app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__,
-                               "failed to get the appid");
-
-       ret = aul_app_com_create(__context.appid, NULL, __viewer_state_handler,
-                       NULL, &__conn_viewer_state);
-       if (ret < 0) {
-               free(__context.appid);
-               __context.appid = NULL;
-               return watch_app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__,
-                               "Failed to create app com");
-       }
-
-       __context.callback = *callback;
-       __context.width = width;
-       __context.height = height;
-       __context.watch_visibility = WVS_UNKNOWN;
-       __context.ambient_mode = false;
-       __context.ambient_mode_skip_resume = false;
-       __context.data = user_data;
-       __context.state = WATCH_APP_STATE_CREATING;
-       _watch_core_listen_lcd_status_signal(__lcd_on_handler, NULL);
-
-       ret = appcore_efl_base_init(ops, argc, argv, NULL, 0);
-       free(__context.appid);
-       __context.appid = NULL;
-       aul_app_com_leave(__conn_viewer_state);
-       __conn_viewer_state = NULL;
-
-       if (ret < 0) {
-               __context.state = WATCH_APP_STATE_NOT_RUNNING;
-               return watch_app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, NULL);
-       }
-
-       _watch_core_ignore_lcd_status_signal();
-       appcore_efl_base_fini();
-       __context.state = WATCH_APP_STATE_NOT_RUNNING;
-
-       return APP_ERROR_NONE;
-}
-
-EXPORT_API void watch_app_exit(void)
-{
-       _I("watch_app_exit");
-       appcore_efl_base_exit();
-       aul_notify_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,
-               app_event_type_e event_type, app_event_cb callback,
-               void *user_data)
-{
-       app_event_handler_h handler;
-
-       if (!__check_feature())
-               return APP_ERROR_NOT_SUPPORTED;
-
-       if (event_handler == NULL || callback == NULL)
-               return watch_app_error(APP_ERROR_INVALID_PARAMETER,
-                               __FUNCTION__, NULL);
-
-       if (event_type < APP_EVENT_LOW_MEMORY ||
-                       event_type > APP_EVENT_REGION_FORMAT_CHANGED)
-               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__,
-                               NULL);
-
-       handler->type = event_type;
-       handler->cb = callback;
-       handler->data = user_data;
-       handler->raw = appcore_base_add_event(__app_event_converter[event_type], __event_cb, handler);
-
-       *event_handler = handler;
-
-       return APP_ERROR_NONE;
-}
-
-EXPORT_API int watch_app_remove_event_handler(app_event_handler_h event_handler)
-{
-       int ret;
-       app_event_type_e type;
-
-       if (!__check_feature())
-               return APP_ERROR_NOT_SUPPORTED;
-
-       if (event_handler == NULL)
-               return watch_app_error(APP_ERROR_INVALID_PARAMETER,
-                               __FUNCTION__, NULL);
-
-       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);
-
-       ret = appcore_base_remove_event(event_handler->raw);
-       if (ret < 0)
-               return watch_app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, "invalid raw handler");
-
-       free(event_handler);
-
-       return APP_ERROR_NONE;
-}
-
-EXPORT_API int watch_time_get_current_time(watch_time_h *watch_time)
-{
-       struct _watch_time_s *time_info;
-
-       if (!__check_feature())
-               return APP_ERROR_NOT_SUPPORTED;
-
-       if (watch_time == NULL)
-               return watch_app_error(APP_ERROR_INVALID_PARAMETER,
-                               __FUNCTION__, NULL);
-
-       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");
-
-       __get_timeinfo(time_info);
-
-       *watch_time = (struct _watch_time_s *)time_info;
-
-       return APP_ERROR_NONE;
-}
-
-EXPORT_API int watch_time_delete(watch_time_h watch_time)
-{
-       if (!__check_feature())
-               return APP_ERROR_NOT_SUPPORTED;
-
-       if (watch_time == NULL)
-               return watch_app_error(APP_ERROR_INVALID_PARAMETER,
-                               __FUNCTION__, NULL);
-
-       if (watch_time->timezone)
-               free(watch_time->timezone);
-
-       free(watch_time);
-
-       return APP_ERROR_NONE;
-}
-
-EXPORT_API int watch_time_get_year(watch_time_h watch_time, int *year)
-{
-       if (!__check_feature())
-               return APP_ERROR_NOT_SUPPORTED;
-
-       if (watch_time == NULL)
-               return watch_app_error(APP_ERROR_INVALID_PARAMETER,
-                               __FUNCTION__, NULL);
-
-       *year = watch_time->year;
-       return APP_ERROR_NONE;
-}
-
-EXPORT_API int watch_time_get_month(watch_time_h watch_time, int *month)
-{
-       if (!__check_feature())
-               return APP_ERROR_NOT_SUPPORTED;
-
-       if (watch_time == NULL)
-               return watch_app_error(APP_ERROR_INVALID_PARAMETER,
-                               __FUNCTION__, NULL);
-
-       *month = watch_time->month;
-       return APP_ERROR_NONE;
-}
-
-EXPORT_API int watch_time_get_day(watch_time_h watch_time, int *day)
-{
-       if (!__check_feature())
-               return APP_ERROR_NOT_SUPPORTED;
-
-       if (watch_time == NULL)
-               return watch_app_error(APP_ERROR_INVALID_PARAMETER,
-                               __FUNCTION__, NULL);
-
-       *day = watch_time->day;
-       return APP_ERROR_NONE;
-}
-
-EXPORT_API int watch_time_get_day_of_week(watch_time_h watch_time,
-               int *day_of_week)
-{
-       if (!__check_feature())
-               return APP_ERROR_NOT_SUPPORTED;
-
-       if (watch_time == NULL)
-               return watch_app_error(APP_ERROR_INVALID_PARAMETER,
-                               __FUNCTION__, NULL);
-
-       *day_of_week = watch_time->day_of_week;
-       return APP_ERROR_NONE;
-}
-
-EXPORT_API int watch_time_get_hour(watch_time_h watch_time, int *hour)
-{
-       if (!__check_feature())
-               return APP_ERROR_NOT_SUPPORTED;
-
-       if (watch_time == NULL)
-               return watch_app_error(APP_ERROR_INVALID_PARAMETER,
-                               __FUNCTION__, NULL);
-
-       *hour = watch_time->hour;
-       return APP_ERROR_NONE;
-}
-
-EXPORT_API int watch_time_get_hour24(watch_time_h watch_time, int *hour24)
-{
-       if (!__check_feature())
-               return APP_ERROR_NOT_SUPPORTED;
-
-       if (watch_time == NULL)
-               return watch_app_error(APP_ERROR_INVALID_PARAMETER,
-                               __FUNCTION__, NULL);
-
-       *hour24 = watch_time->hour24;
-       return APP_ERROR_NONE;
-}
-
-EXPORT_API int watch_time_get_minute(watch_time_h watch_time, int *minute)
-{
-       if (!__check_feature())
-               return APP_ERROR_NOT_SUPPORTED;
-
-       if (watch_time == NULL)
-               return watch_app_error(APP_ERROR_INVALID_PARAMETER,
-                               __FUNCTION__, NULL);
-
-       *minute = watch_time->minute;
-       return APP_ERROR_NONE;
-}
-
-EXPORT_API int watch_time_get_second(watch_time_h watch_time, int *second)
-{
-       if (!__check_feature())
-               return APP_ERROR_NOT_SUPPORTED;
-
-       if (watch_time == NULL)
-               return watch_app_error(APP_ERROR_INVALID_PARAMETER,
-                               __FUNCTION__, NULL);
-
-       *second = watch_time->second;
-       return APP_ERROR_NONE;
-}
-
-EXPORT_API int watch_time_get_millisecond(watch_time_h watch_time,
-               int *millisecond)
-{
-       if (!__check_feature())
-               return APP_ERROR_NOT_SUPPORTED;
-
-       if (watch_time == NULL)
-               return watch_app_error(APP_ERROR_INVALID_PARAMETER,
-                               __FUNCTION__, NULL);
-
-       *millisecond = watch_time->millisecond;
-       return APP_ERROR_NONE;
-}
-
-EXPORT_API int watch_time_get_utc_time(watch_time_h watch_time,
-               struct tm *utc_time)
-{
-       time_t timestamp;
-
-       if (!__check_feature())
-               return APP_ERROR_NOT_SUPPORTED;
-
-       if (watch_time == NULL || utc_time == NULL)
-               return watch_app_error(APP_ERROR_INVALID_PARAMETER,
-                               __FUNCTION__, NULL);
-
-       timestamp = watch_time->timestamp;
-
-       gmtime_r(&timestamp, utc_time);
-
-       return APP_ERROR_NONE;
-}
-
-EXPORT_API int watch_time_get_utc_timestamp(watch_time_h watch_time,
-               time_t *utc_timestamp)
-{
-       if (!__check_feature())
-               return APP_ERROR_NOT_SUPPORTED;
-
-       if (watch_time == NULL)
-               return watch_app_error(APP_ERROR_INVALID_PARAMETER,
-                               __FUNCTION__, NULL);
-
-       *utc_timestamp = watch_time->timestamp;
-
-       return APP_ERROR_NONE;
-}
-
-EXPORT_API int watch_time_get_time_zone(watch_time_h watch_time,
-               char **time_zone_id)
-{
-       if (!__check_feature())
-               return APP_ERROR_NOT_SUPPORTED;
-
-       if (watch_time == NULL || watch_time->timezone == NULL
-                       || time_zone_id == NULL)
-               return watch_app_error(APP_ERROR_INVALID_PARAMETER,
-                               __FUNCTION__, NULL);
-
-       *time_zone_id = strdup(watch_time->timezone);
-
-       return APP_ERROR_NONE;
-}
-
-EXPORT_API int watch_time_get_dst_status(watch_time_h watch_time, bool *status)
-{
-       if (!__check_feature())
-               return APP_ERROR_NOT_SUPPORTED;
-
-       if (watch_time == NULL || status == NULL)
-               return watch_app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
-
-       if (watch_time->indaylight)
-               *status = true;
-       else
-               *status = false;
-
-       return APP_ERROR_NONE;
-}
-
-EXPORT_API int watch_time_get_daylight_time_status(watch_time_h watch_time, bool *daylight)
-{
-       if (!__check_feature())
-               return APP_ERROR_NOT_SUPPORTED;
-
-       return watch_time_get_dst_status(watch_time, daylight);
-}
-
-static void __win_del_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
-{
-       char *plug_id;
-       plug_id = evas_object_data_del(obj, "___PLUGID");
-       free(plug_id);
-
-       if (__watch_win == obj)
-               __watch_win = NULL;
-}
-
-EXPORT_API int watch_app_get_elm_win(Evas_Object **win)
-{
-       Evas_Object *ret_win;
-       struct wl_surface *surface;
-       Ecore_Wl2_Window *wl_win;
-       Ecore_Evas *ee;
-       char buffer[256];
-
-       if (!__check_feature())
-               return APP_ERROR_NOT_SUPPORTED;
-
-       if (win == NULL)
-               return watch_app_error(APP_ERROR_INVALID_PARAMETER,
-                               __FUNCTION__, NULL);
-
-       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);
-
-       ee = ecore_evas_ecore_evas_get(evas_object_evas_get(ret_win));
-       wl_win = ecore_evas_wayland2_window_get(ee);
-       if (wl_win == NULL)
-               _E("failed to get surface");
-
-       surface = ecore_wl2_window_surface_get(wl_win);
-       screen_connector_provider_remote_enable(__context.appid,
-                       surface);
-
-       /* Set data to use in accessibility */
-       snprintf(buffer, sizeof(buffer), "%s:%d", __context.appid, getpid());
-       evas_object_data_set(ret_win, "___PLUGID", strdup(buffer));
-       evas_object_event_callback_add(ret_win, EVAS_CALLBACK_DEL, __win_del_cb, NULL);
-
-       *win = ret_win;
-       __watch_win = ret_win;
-
-       return APP_ERROR_NONE;
-}
-
-EXPORT_API int watch_app_set_ambient_tick_type(watch_app_ambient_tick_type_e type)
-{
-       if (!__check_feature())
-               return APP_ERROR_NOT_SUPPORTED;
-
-       if (type < WATCH_APP_AMBIENT_TICK_NO_TICK || type > WATCH_APP_AMBIENT_TICK_EVERY_DAY)
-               return APP_ERROR_INVALID_PARAMETER;
-       return __set_ambient_tick_type(type);
-}
-
-EXPORT_API int watch_app_get_ambient_tick_type(watch_app_ambient_tick_type_e *type)
-{
-       if (!__check_feature())
-               return APP_ERROR_NOT_SUPPORTED;
-
-       if (type == NULL)
-               return APP_ERROR_INVALID_PARAMETER;
-       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 (!__check_feature())
-               return APP_ERROR_NOT_SUPPORTED;
-
-       if (type < WATCH_APP_TIME_TICKS_PER_SECOND || type > WATCH_APP_TIME_TICKS_PER_HOUR)
-               return APP_ERROR_INVALID_PARAMETER;
-       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 (!__check_feature())
-               return APP_ERROR_NOT_SUPPORTED;
-
-       if (type == NULL || ticks == NULL)
-               return APP_ERROR_INVALID_PARAMETER;
-       return __get_time_tick_frequency(ticks, type);
-}
diff --git a/src/watch_app_private.h b/src/watch_app_private.h
deleted file mode 100755 (executable)
index 4c56433..0000000
+++ /dev/null
@@ -1,39 +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 __WATCH_APP_PRIVATE_H__
-#define __WATCH_APP_PRIVATE_H__
-
-#include <watch_app.h>
-#include <app_common.h>
-#include <system_info.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define WATCH_APP_FEATURE "http://tizen.org/feature/watch_app"
-
-int watch_app_error(app_error_e error, const char *function,
-               const char *description);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __WATCH_APP_PRIVATE_H__ */
-