From ea27269a2f22e0bcde09a7a9e0722c3c04607a84 Mon Sep 17 00:00:00 2001 From: Junghoon Park Date: Fri, 25 May 2018 13:28:23 +0900 Subject: [PATCH] Refactor appcore-watch - Make reusable library, appcore-watch-base which has no dependency with elementary Change-Id: I347fd69636c669ab9ec47580a3d51c5fad6c4aa3 Signed-off-by: Junghoon Park --- CMakeLists.txt | 48 +- appcore-watch-base.pc.in | 13 + appcore-watch.pc.in | 2 +- capi-appfw-watch-application.pc | 3 +- include/watch_base.h | 124 ++++ packaging/appcore-watch.spec | 48 +- src/appcore-watch-signal.h | 48 -- src/{watch_app_main.c => base/watch_base.c} | 817 +++++++-------------- src/{appcore-watch-log.h => base/watch_base_log.h} | 9 +- .../watch_base_signal.c} | 30 +- .../watch_base_signal.h} | 21 +- src/base/watch_base_time.c | 335 +++++++++ src/base/watch_base_time.h | 48 ++ src/efl_base/watch_app_log.h | 47 ++ src/efl_base/watch_app_main.c | 360 +++++++++ src/watch_app_error.c | 64 -- 16 files changed, 1317 insertions(+), 700 deletions(-) create mode 100644 appcore-watch-base.pc.in create mode 100755 include/watch_base.h delete mode 100755 src/appcore-watch-signal.h rename src/{watch_app_main.c => base/watch_base.c} (52%) rename src/{appcore-watch-log.h => base/watch_base_log.h} (90%) rename src/{appcore-watch-signal.c => base/watch_base_signal.c} (82%) rename src/{watch_app_private.h => base/watch_base_signal.h} (59%) create mode 100755 src/base/watch_base_time.c create mode 100755 src/base/watch_base_time.h create mode 100755 src/efl_base/watch_app_log.h create mode 100755 src/efl_base/watch_app_main.c delete mode 100755 src/watch_app_error.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 0ca14fc..cabef15 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 index 0000000..0bb582c --- /dev/null +++ b/appcore-watch-base.pc.in @@ -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 diff --git a/appcore-watch.pc.in b/appcore-watch.pc.in index a87f082..8bdb406 100644 --- a/appcore-watch.pc.in +++ b/appcore-watch.pc.in @@ -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 diff --git a/capi-appfw-watch-application.pc b/capi-appfw-watch-application.pc index 87fa585..dc37e12 100644 --- a/capi-appfw-watch-application.pc +++ b/capi-appfw-watch-application.pc @@ -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 index 0000000..96414b1 --- /dev/null +++ b/include/watch_base.h @@ -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 +#include +#include +#include + +#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__ */ + diff --git a/packaging/appcore-watch.spec b/packaging/appcore-watch.spec index 040c7ce..f7cc5bd 100644 --- a/packaging/appcore-watch.spec +++ b/packaging/appcore-watch.spec @@ -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-signal.h b/src/appcore-watch-signal.h deleted file mode 100755 index 662fc8b..0000000 --- a/src/appcore-watch-signal.h +++ /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/watch_app_main.c b/src/base/watch_base.c similarity index 52% rename from src/watch_app_main.c rename to src/base/watch_base.c index a477c53..838d46d 100755 --- a/src/watch_app_main.c +++ b/src/base/watch_base.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 - 2016 Samsung Electronics Co., Ltd All Rights Reserved + * 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. @@ -23,23 +23,13 @@ #include #include -#include -#include -#include -#include -#include -#include - #include #include #include #include -#include -#include -#include #include #include -#include +#include #include #include #include @@ -49,34 +39,33 @@ #include #include #include +#include -#include "appcore-watch-log.h" -#include "watch_app_private.h" -#include "appcore-watch-signal.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 "CAPI_WATCH_APPLICATION" +#define LOG_TAG "WATCH_BASE" -#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" +#define WATCH_BASE_FEATURE "http://tizen.org/feature/watch_app" 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; + WATCH_BASE_STATE_NOT_RUNNING = 0, + WATCH_BASE_STATE_CREATING, + WATCH_BASE_STATE_RUNNING, +} watch_base_state_e; enum watch_state { WS_NONE, @@ -86,32 +75,18 @@ enum watch_state { 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 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; @@ -127,10 +102,10 @@ struct app_event_info { void *value; }; -struct watch_app_context { +struct watch_base_context { char *appid; - watch_app_state_e state; - watch_app_lifecycle_callback_s callback; + watch_base_state_e state; + watch_base_ops callback; int width; int height; enum watch_visible_state watch_visibility; @@ -165,26 +140,59 @@ static int __app_event_converter[APPCORE_BASE_EVENT_MAX] = { [APP_EVENT_SUSPENDED_STATE_CHANGED] = APPCORE_BASE_EVENT_SUSPENDED_STATE_CHANGE, }; -struct watch_app_context __context; +static struct watch_base_context __context; static double __prev_target_tick = -1; -static Evas_Object *__watch_win; -enum watch_state __state; +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 bool __check_feature(void) +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_APP_FEATURE, &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_APP_FEATURE); + LOGE("[%s] feature is disabled", WATCH_BASE_FEATURE); return false; } } @@ -210,60 +218,6 @@ static void __alarm_init(void) } } -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(¤t, 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; @@ -272,20 +226,20 @@ static double __get_next_tick_sec() int idx; double target; - struct _watch_time_s timeinfo = { + struct _watch_base_time_s timeinfo = { .timezone = NULL }; - __get_timeinfo(&timeinfo); + _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_APP_TIME_TICKS_PER_SECOND) { + if (app_tick_type == WATCH_BASE_TIME_TICKS_PER_SECOND) { term = (double)ONE_SECOND / (double)app_tick_resolution; - } else if (app_tick_type == WATCH_APP_TIME_TICKS_PER_MINUTE) { + } 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_APP_TIME_TICKS_PER_HOUR) { + } else if (app_tick_type == WATCH_BASE_TIME_TICKS_PER_HOUR) { term = (double)ONE_HOUR_IN_SEC / (double)app_tick_resolution; term *= 1000; } @@ -306,7 +260,8 @@ static double __get_next_tick_sec() } /* LCOV_EXCL_START */ -static int __get_ambient_tick_offset(struct _watch_time_s timeinfo, int interval, int minute_base, int hour_base) +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; @@ -335,11 +290,11 @@ static int __get_ambient_tick_offset(struct _watch_time_s timeinfo, int interval /* LCOV_EXCL_START */ static int __ambient_tick_cb(alarm_id_t id, void *data) { - struct _watch_time_s timeinfo = { + struct _watch_base_time_s timeinfo = { .timezone = NULL }; - __get_timeinfo(&timeinfo); + _watch_base_time_get_timeinfo(&timeinfo); __on_ambient_tick(&timeinfo, data); if (timeinfo.timezone) @@ -354,13 +309,13 @@ static int __set_ambient_tick_cb(void *data) { int offset_sec = 0; int interval = 0; - struct _watch_time_s timeinfo = { + struct _watch_base_time_s timeinfo = { .timezone = NULL }; int r; struct ambient_tick_type_info info; - __get_timeinfo(&timeinfo); + _watch_base_time_get_timeinfo(&timeinfo); info = ambient_tick_type_infos[ambient_tick_type]; interval = info.interval; @@ -372,8 +327,8 @@ static int __set_ambient_tick_cb(void *data) _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); + 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); @@ -389,7 +344,7 @@ static int __set_ambient_tick_cb(void *data) /* LCOV_EXCL_START */ static int __signal_alpm_handler(int ambient, void *data) { - struct _watch_time_s timeinfo = { + struct _watch_base_time_s timeinfo = { .timezone = NULL }; @@ -401,8 +356,8 @@ static int __signal_alpm_handler(int ambient, void *data) /* Enter the ambient mode */ if (ambient) { - if (appcore_efl_base_is_resumed()) { - appcore_efl_base_on_pause(); + if (appcore_ui_base_is_resumed()) { + appcore_ui_base_on_pause(); __context.ambient_mode_skip_resume = false; } else { __context.ambient_mode_skip_resume = true; @@ -415,10 +370,10 @@ static int __signal_alpm_handler(int ambient, void *data) __set_ambient_tick_cb(data); /* Send a update done signal */ - _watch_core_send_alpm_update_done(); + _watch_base_signal_send_alpm_update_done(); } else { /* Exit the ambient mode */ - __get_timeinfo(&timeinfo); + _watch_base_time_get_timeinfo(&timeinfo); __on_ambient_tick(&timeinfo, data); __context.ambient_mode = false; @@ -427,7 +382,7 @@ static int __signal_alpm_handler(int ambient, void *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(); + appcore_ui_base_resume(); } /* Disable alarm */ @@ -446,14 +401,14 @@ static int __signal_alpm_handler(int ambient, void *data) static Eina_Bool __time_tick_cb(void *data) { - struct _watch_time_s timeinfo = { + struct _watch_base_time_s timeinfo = { .timezone = NULL }; double sec; _D("state: %d", __state); if (__context.callback.time_tick && __state != WS_PAUSED) { - __get_timeinfo(&timeinfo); + _watch_base_time_get_timeinfo(&timeinfo); /* Set a next timer */ sec = __get_next_tick_sec(); @@ -498,8 +453,8 @@ static void __set_default_tick_by_metadata() /* 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; + _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; @@ -509,8 +464,8 @@ static void __set_default_tick_by_metadata() 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; + _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; @@ -524,12 +479,12 @@ static void __set_default_tick_by_metadata() /* LCOV_EXCL_START */ static void __vconf_time_changed_cb(keynode_t *key, void *data) { - struct _watch_time_s timeinfo = { + struct _watch_base_time_s timeinfo = { .timezone = NULL }; _D("ambient_mode check: %d", __context.ambient_mode); - __get_timeinfo(&timeinfo); + _watch_base_time_get_timeinfo(&timeinfo); if (__context.ambient_mode) { if (alarm_id) { alarmmgr_remove_alarm(alarm_id); @@ -548,27 +503,20 @@ static void __vconf_time_changed_cb(keynode_t *key, void *data) } /* LCOV_EXCL_STOP */ -static int __on_create(void *data) +static int __on_ui_base_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); + watch_base_create_cb create_cb; + _W("_watch_base_signal_create"); 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"); + 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_APP_STATE_RUNNING; + __context.state = WATCH_BASE_STATE_RUNNING; vconf_notify_key_changed(VCONFKEY_SYSTEM_TIME_CHANGED, __vconf_time_changed_cb, data); @@ -576,12 +524,12 @@ static int __on_create(void *data) return APP_ERROR_NONE; } -static int __on_control(bundle *b, void *data) +static int __on_ui_base_control(bundle *b, void *data) { app_control_h app_control = NULL; - appcore_efl_base_on_control(b); + appcore_ui_base_on_control(b); - _W("_watch_core_control"); + _W("_watch_base_signal_control"); if (app_control_create_event(b, &app_control) != 0) return -1; @@ -595,9 +543,9 @@ static int __on_control(bundle *b, void *data) } /* LCOV_EXCL_START */ -static int __on_pause(void *data) +static int __on_ui_base_pause(void *data) { - _W("_watch_core_pause"); + _W("_watch_base_signal_pause"); if (__state == WS_CREATED) { _E("Invalid state"); @@ -608,11 +556,7 @@ static int __on_pause(void *data) 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); } @@ -625,31 +569,31 @@ static int __on_pause(void *data) static void __on_pre_resume(void *data) { - int w, h; - Ecore_Evas *ee; - struct _watch_time_s timeinfo = { + 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 }; - __get_timeinfo(&timeinfo); - __on_time_tick(&timeinfo, data); + _watch_base_time_get_timeinfo(&timeinfo); + __on_time_tick(&timeinfo, NULL); 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 void __on_base_preresume(void *data) +{ + watch_base_on_preresume(); } -static int __on_resume(void *data) +static int __on_ui_base_resume(void *data) { - _W("_watch_core_resume"); + _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; @@ -663,8 +607,6 @@ static int __on_resume(void *data) 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); @@ -680,59 +622,56 @@ static int __on_resume(void *data) return APP_ERROR_NONE; } -static int __on_terminate(void *data) +static int __on_ui_base_terminate(void *data) { - _W("_watch_core_terminate"); + _W("__on_ui_base_terminate"); __state = WS_DYING; - if (appcore_efl_base_is_resumed()) - appcore_efl_base_pause(); + 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(); - 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; + watch_base_time_tick_cb time_tick_cb; - _I("_watch_core_time_tick"); + _I("_watch_base_signal_time_tick"); time_tick_cb = __context.callback.time_tick; if (time_tick_cb != NULL) - time_tick_cb((watch_time_h)watchtime, __context.data); + time_tick_cb((watch_base_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; + watch_base_ambient_tick_cb ambient_tick_cb; - _W("_watch_core_ambient_tick"); + _W("_watch_base_signal_ambient_tick"); ambient_tick_cb = __context.callback.ambient_tick; if (ambient_tick_cb != NULL) - ambient_tick_cb((watch_time_h)watchtime, __context.data); + 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_app_ambient_changed_cb ambient_changed_cb; + watch_base_ambient_changed_cb ambient_changed_cb; - _W("_watch_core_ambient_changed: %d", ambient); + _W("_watch_base_signal_ambient_changed: %d", ambient); ambient_changed_cb = __context.callback.ambient_changed; @@ -743,9 +682,9 @@ static void __on_ambient_changed(int ambient, void *data) static void __on_window_show(int type, void *event, void *data) { - appcore_efl_base_window_on_show(type, event); + appcore_ui_base_window_on_show(type, event); if (__context.viewer_visibility == AUL_SCREEN_STATUS_RESUME) - appcore_efl_base_resume(); + appcore_ui_base_resume(); else _D("viewer is not resumed, do not resume watch"); } @@ -760,17 +699,17 @@ static void __on_window_visibility(int type, void *event, void *data) if (ev->fully_obscured) { __context.watch_visibility = WVS_PAUSE; - __on_pause(NULL); + __on_ui_base_pause(NULL); } else { __context.watch_visibility = WVS_RESUME; if (__context.viewer_visibility == AUL_SCREEN_STATUS_RESUME) - __on_resume(NULL); + __on_ui_base_resume(NULL); else _D("Viewer is paused, do not resume watch"); } } -static int __set_ambient_tick_type(watch_app_ambient_tick_type_e type) +static int __set_ambient_tick_type(watch_base_ambient_tick_type_e type) { _D("set ambient tick type : %d", type); ambient_tick_type = type; @@ -783,16 +722,16 @@ static int __set_ambient_tick_type(watch_app_ambient_tick_type_e type) return 0; } -static int __get_ambient_tick_type(watch_app_ambient_tick_type_e *type) +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_app_time_tick_resolution_e type) +static int __set_time_tick_frequency(int ticks, watch_base_time_tick_resolution_e type) { double sec = 1.0; - struct _watch_time_s timeinfo = { + struct _watch_base_time_s timeinfo = { .timezone = NULL }; @@ -807,8 +746,8 @@ static int __set_time_tick_frequency(int ticks, watch_app_time_tick_resolution_e 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); + if (appcore_ui_base_is_resumed()) { + _watch_base_time_get_timeinfo(&timeinfo); __on_time_tick(&timeinfo, NULL); } @@ -818,7 +757,7 @@ static int __set_time_tick_frequency(int ticks, watch_app_time_tick_resolution_e return 0; } -static int __get_time_tick_frequency(int *ticks, watch_app_time_tick_resolution_e *type) +static int __get_time_tick_frequency(int *ticks, watch_base_time_tick_resolution_e *type) { *ticks = app_tick_resolution; *type = app_tick_type; @@ -830,7 +769,7 @@ static int __viewer_state_handler(const char *widget_id, aul_app_com_result_e e, { int *state = NULL; size_t state_sz = 0; - struct _watch_time_s timeinfo = { + struct _watch_base_time_s timeinfo = { .timezone = NULL }; @@ -849,9 +788,9 @@ static int __viewer_state_handler(const char *widget_id, aul_app_com_result_e e, if (*state == AUL_SCREEN_STATUS_RESUME && __context.watch_visibility == WVS_RESUME) { - __on_resume(NULL); + __on_ui_base_resume(NULL); } else if (*state == AUL_SCREEN_STATUS_PAUSE) { - __on_pause(NULL); + __on_ui_base_pause(NULL); } else if (*state == AUL_SCREEN_STATUS_PRE_RESUME) { _D("call pre resume tick"); __on_pre_resume(NULL); @@ -869,8 +808,85 @@ static void __lcd_on_handler(void *user_data) __on_pre_resume(NULL); } -EXPORT_API int watch_app_main(int argc, char **argv, - watch_app_lifecycle_callback_s *callback, void *user_data) +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; @@ -878,20 +894,25 @@ EXPORT_API int watch_app_main(int argc, char **argv, char *height_str = NULL; int width = 360; int height = 360; - appcore_efl_base_ops ops = appcore_efl_base_get_default_ops(); + appcore_ui_base_ops ops = appcore_ui_base_get_default_ops(); char *viewer_visibility_str = NULL; - if (!__check_feature()) + if (!watch_base_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; + 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) { @@ -917,21 +938,21 @@ EXPORT_API int watch_app_main(int argc, char **argv, } if (argc <= 0 || argv == NULL || callback == NULL) - return watch_app_error(APP_ERROR_INVALID_PARAMETER, + return watch_base_set_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); if (callback->create == NULL) - return watch_app_error(APP_ERROR_INVALID_PARAMETER, + return watch_base_set_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, - "watch_app_create_cb() callback must be " + "watch_base_create_cb() callback must be " "registered"); - if (__context.state != WATCH_APP_STATE_NOT_RUNNING) - return watch_app_error(APP_ERROR_ALREADY_RUNNING, __FUNCTION__, + 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_app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, + 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, @@ -939,7 +960,7 @@ EXPORT_API int watch_app_main(int argc, char **argv, if (ret < 0) { free(__context.appid); __context.appid = NULL; - return watch_app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, + return watch_base_set_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "Failed to create app com"); } @@ -950,34 +971,35 @@ EXPORT_API int watch_app_main(int argc, char **argv, __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); + __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); +} - ret = appcore_efl_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; - - 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; + _watch_base_signal_ignore_lcd_status_signal(); + appcore_ui_base_fini(); + __context.state = WATCH_BASE_STATE_NOT_RUNNING; } -EXPORT_API void watch_app_exit(void) +EXPORT_API void watch_base_exit(void) { - _I("watch_app_exit"); - appcore_efl_base_exit(); + _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; @@ -991,27 +1013,27 @@ static int __event_cb(void *event, void *data) return 0; } -EXPORT_API int watch_app_add_event_handler(app_event_handler_h *event_handler, +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 (!__check_feature()) + if (!watch_base_check_feature()) return APP_ERROR_NOT_SUPPORTED; if (event_handler == NULL || callback == NULL) - return watch_app_error(APP_ERROR_INVALID_PARAMETER, + 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_app_error(APP_ERROR_INVALID_PARAMETER, + return watch_base_set_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__, + return watch_base_set_error(APP_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL); handler->type = event_type; @@ -1024,329 +1046,46 @@ EXPORT_API int watch_app_add_event_handler(app_event_handler_h *event_handler, return APP_ERROR_NONE; } -EXPORT_API int watch_app_remove_event_handler(app_event_handler_h event_handler) +EXPORT_API int watch_base_remove_event_handler(app_event_handler_h event_handler) { int ret; app_event_type_e type; - if (!__check_feature()) + if (!watch_base_check_feature()) return APP_ERROR_NOT_SUPPORTED; if (event_handler == NULL) - return watch_app_error(APP_ERROR_INVALID_PARAMETER, + 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_app_error(APP_ERROR_INVALID_PARAMETER, + return watch_base_set_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"); + return watch_base_set_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(×tamp, 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) +EXPORT_API int watch_base_set_ambient_tick_type(watch_base_ambient_tick_type_e type) { - if (!__check_feature()) + if (!watch_base_check_feature()) return APP_ERROR_NOT_SUPPORTED; - if (type < WATCH_APP_AMBIENT_TICK_NO_TICK || type > WATCH_APP_AMBIENT_TICK_EVERY_DAY) + 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_app_get_ambient_tick_type(watch_app_ambient_tick_type_e *type) +EXPORT_API int watch_base_get_ambient_tick_type(watch_base_ambient_tick_type_e *type) { - if (!__check_feature()) + if (!watch_base_check_feature()) return APP_ERROR_NOT_SUPPORTED; if (type == NULL) @@ -1354,19 +1093,19 @@ EXPORT_API int watch_app_get_ambient_tick_type(watch_app_ambient_tick_type_e *ty return __get_ambient_tick_type(type); } -EXPORT_API int watch_app_set_time_tick_frequency(int ticks, watch_app_time_tick_resolution_e type) +EXPORT_API int watch_base_set_time_tick_frequency(int ticks, watch_base_time_tick_resolution_e type) { - if (!__check_feature()) + if (!watch_base_check_feature()) return APP_ERROR_NOT_SUPPORTED; - if (type < WATCH_APP_TIME_TICKS_PER_SECOND || type > WATCH_APP_TIME_TICKS_PER_HOUR) + 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_app_get_time_tick_frequency(int *ticks, watch_app_time_tick_resolution_e *type) +EXPORT_API int watch_base_get_time_tick_frequency(int *ticks, watch_base_time_tick_resolution_e *type) { - if (!__check_feature()) + if (!watch_base_check_feature()) return APP_ERROR_NOT_SUPPORTED; if (type == NULL || ticks == NULL) diff --git a/src/appcore-watch-log.h b/src/base/watch_base_log.h similarity index 90% rename from src/appcore-watch-log.h rename to src/base/watch_base_log.h index d9190d2..252d47f 100755 --- a/src/appcore-watch-log.h +++ b/src/base/watch_base_log.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 - 2016 Samsung Electronics Co., Ltd All Rights Reserved + * 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. @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef __APPFW_WATCH_LOG_H__ -#define __APPFW_WATCH_LOG_H__ +#ifndef __WATCH_BASE_LOG_H__ +#define __WATCH_BASE_LOG_H__ #include @@ -76,5 +76,4 @@ } \ } while (0) -#endif /*__APPFW_WATCH_LOG_H_ */ - +#endif /*__WATCH_BASE_LOG_H__ */ diff --git a/src/appcore-watch-signal.c b/src/base/watch_base_signal.c similarity index 82% rename from src/appcore-watch-signal.c rename to src/base/watch_base_signal.c index 1d3408f..dbc5b78 100755 --- a/src/appcore-watch-signal.c +++ b/src/base/watch_base_signal.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 - 2016 Samsung Electronics Co., Ltd All Rights Reserved + * 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. @@ -27,16 +27,28 @@ #include #include -#include "appcore-watch-log.h" -#include "appcore-watch-signal.h" +#include "watch_base_log.h" +#include "watch_base_signal.h" #ifdef LOG_TAG #undef LOG_TAG #endif -#define LOG_TAG "WATCH_CORE" +#define LOG_TAG "WATCH_BASE_SIGNAL" -#define MAX_BUFFER_SIZE 512 +#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; @@ -121,7 +133,7 @@ static int __dbus_signal_handler_init(const char *path, const char *interface) return 0; } -int _watch_core_listen_alpm_handler(int (*func) (int, void *), void *data) +int _watch_base_signal_listen_alpm_handler(int (*func) (int, void *), void *data) { _D("watch_core_listen_deviced_alpm"); @@ -140,7 +152,7 @@ int _watch_core_listen_alpm_handler(int (*func) (int, void *), void *data) } /* LCOV_EXCL_START */ -int _watch_core_send_alpm_update_done(void) +int _watch_base_signal_send_alpm_update_done(void) { GError *err = NULL; @@ -190,7 +202,7 @@ static void __lcd_on_signal_handler(GDBusConnection *connection, } /* LCOV_EXCL_STOP */ -int _watch_core_listen_lcd_status_signal(void (*func)(void *), void *data) +int _watch_base_signal_listen_lcd_status_signal(void (*func)(void *), void *data) { if (__dbus_init() < 0) return -1; @@ -218,7 +230,7 @@ int _watch_core_listen_lcd_status_signal(void (*func)(void *), void *data) return 0; } -void _watch_core_ignore_lcd_status_signal(void) +void _watch_base_signal_ignore_lcd_status_signal(void) { __deviced_signal_lcd_handler = NULL; __deviced_signal_lcd_data = NULL; diff --git a/src/watch_app_private.h b/src/base/watch_base_signal.h similarity index 59% rename from src/watch_app_private.h rename to src/base/watch_base_signal.h index 4c56433..8503a40 100755 --- a/src/watch_app_private.h +++ b/src/base/watch_base_signal.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 - 2016 Samsung Electronics Co., Ltd All Rights Reserved + * 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. @@ -14,26 +14,21 @@ * limitations under the License. */ - -#ifndef __WATCH_APP_PRIVATE_H__ -#define __WATCH_APP_PRIVATE_H__ - -#include -#include -#include +#ifndef __WATCH_BASE_SIGNAL_H__ +#define __WATCH_BASE_SIGNAL_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); +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_APP_PRIVATE_H__ */ +#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 index 0000000..c808f69 --- /dev/null +++ b/src/base/watch_base_time.c @@ -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 +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#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(¤t, 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(×tamp, 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 index 0000000..6694915 --- /dev/null +++ b/src/base/watch_base_time.h @@ -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 + +#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 index 0000000..1723957 --- /dev/null +++ b/src/efl_base/watch_app_log.h @@ -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 + +#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 index 0000000..d4d893f --- /dev/null +++ b/src/efl_base/watch_app_main.c @@ -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 +#include +#include +#include + +#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 index 757c125..0000000 --- a/src/watch_app_error.c +++ /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 -#include - -#include -#include - -#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; -} - -- 2.7.4