--- /dev/null
+Jayoun Lee <airjany@samsung.com>
+Sunwook Bae <sunwook45.bae@samsung.com>
+Jaeho Lee <jaeho81.lee@samsung.com>
+Semun Lee <sm79.lee@samsung.com>
--- /dev/null
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+PROJECT(appcore-watch C)
+
+SET(PREFIX ${CMAKE_INSTALL_PREFIX})
+SET(EXEC_PREFIX "\${prefix}")
+SET(LIBDIR "\${prefix}/lib")
+SET(INCLUDEDIR "\${prefix}/include")
+SET(VERSION_MAJOR 1)
+SET(VERSION "${VERSION_MAJOR}.1")
+
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include)
+
+ADD_DEFINITIONS("-DPREFIX=\"${PREFIX}\"")
+
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden")
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -g -Wall")
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
+
+SET(CMAKE_SKIP_BUILD_RPATH TRUE)
+
+#################################################################
+# Build appcore-watch Library
+# ------------------------------
+SET(APPCORE_WATCH "appcore-watch")
+SET(SRCS_watch
+ src/appcore-watch.c
+ src/appcore-watch-signal.c
+ src/appcore-watch-i18n.c
+ src/watch_app_main.c
+ src/watch_app_error.c
+ )
+SET(HEADERS_watch appcore-watch.h
+ watch_app.h watch_app_efl.h)
+
+INCLUDE(FindPkgConfig)
+pkg_check_modules(pkg_watch REQUIRED
+ aul
+ dlog
+ dbus-glib-1
+ alarm-service
+ capi-appfw-app-control
+ capi-appfw-app-common
+ vconf
+ elementary
+ vconf-internal-keys
+ libtzplatform-config
+ capi-appfw-widget-application
+ icu-uc
+ )
+FOREACH(flag ${pkg_watch_CFLAGS})
+ SET(EXTRA_CFLAGS_watch "${EXTRA_CFLAGS_watch} ${flag}")
+ENDFOREACH(flag)
+
+ADD_LIBRARY(${APPCORE_WATCH} SHARED ${SRCS_watch})
+SET_TARGET_PROPERTIES(${APPCORE_WATCH} PROPERTIES SOVERSION ${VERSION_MAJOR})
+SET_TARGET_PROPERTIES(${APPCORE_WATCH} PROPERTIES VERSION ${VERSION})
+SET_TARGET_PROPERTIES(${APPCORE_WATCH} PROPERTIES COMPILE_FLAGS ${EXTRA_CFLAGS_watch})
+TARGET_LINK_LIBRARIES(${APPCORE_WATCH} ${pkg_watch_LDFLAGS} "-ldl")
+
+CONFIGURE_FILE(${APPCORE_WATCH}.pc.in ${APPCORE_WATCH}.pc @ONLY)
+
+INSTALL(TARGETS ${APPCORE_WATCH} DESTINATION lib COMPONENT RuntimeLibraries)
+INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${APPCORE_WATCH}.pc DESTINATION lib/pkgconfig)
+FOREACH(hfile ${HEADERS_watch})
+ INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/${hfile} DESTINATION include/appcore-watch)
+ENDFOREACH(hfile)
--- /dev/null
+Copyright (c) 2015 Samsung Electronics Co., Ltd. All rights reserved.\r
+\r
+ Apache License\r
+ Version 2.0, January 2004\r
+ http://www.apache.org/licenses/\r
+\r
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION\r
+\r
+ 1. Definitions.\r
+\r
+ "License" shall mean the terms and conditions for use, reproduction,\r
+ and distribution as defined by Sections 1 through 9 of this document.\r
+\r
+ "Licensor" shall mean the copyright owner or entity authorized by\r
+ the copyright owner that is granting the License.\r
+\r
+ "Legal Entity" shall mean the union of the acting entity and all\r
+ other entities that control, are controlled by, or are under common\r
+ control with that entity. For the purposes of this definition,\r
+ "control" means (i) the power, direct or indirect, to cause the\r
+ direction or management of such entity, whether by contract or\r
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the\r
+ outstanding shares, or (iii) beneficial ownership of such entity.\r
+\r
+ "You" (or "Your") shall mean an individual or Legal Entity\r
+ exercising permissions granted by this License.\r
+\r
+ "Source" form shall mean the preferred form for making modifications,\r
+ including but not limited to software source code, documentation\r
+ source, and configuration files.\r
+\r
+ "Object" form shall mean any form resulting from mechanical\r
+ transformation or translation of a Source form, including but\r
+ not limited to compiled object code, generated documentation,\r
+ and conversions to other media types.\r
+\r
+ "Work" shall mean the work of authorship, whether in Source or\r
+ Object form, made available under the License, as indicated by a\r
+ copyright notice that is included in or attached to the work\r
+ (an example is provided in the Appendix below).\r
+\r
+ "Derivative Works" shall mean any work, whether in Source or Object\r
+ form, that is based on (or derived from) the Work and for which the\r
+ editorial revisions, annotations, elaborations, or other modifications\r
+ represent, as a whole, an original work of authorship. For the purposes\r
+ of this License, Derivative Works shall not include works that remain\r
+ separable from, or merely link (or bind by name) to the interfaces of,\r
+ the Work and Derivative Works thereof.\r
+\r
+ "Contribution" shall mean any work of authorship, including\r
+ the original version of the Work and any modifications or additions\r
+ to that Work or Derivative Works thereof, that is intentionally\r
+ submitted to Licensor for inclusion in the Work by the copyright owner\r
+ or by an individual or Legal Entity authorized to submit on behalf of\r
+ the copyright owner. For the purposes of this definition, "submitted"\r
+ means any form of electronic, verbal, or written communication sent\r
+ to the Licensor or its representatives, including but not limited to\r
+ communication on electronic mailing lists, source code control systems,\r
+ and issue tracking systems that are managed by, or on behalf of, the\r
+ Licensor for the purpose of discussing and improving the Work, but\r
+ excluding communication that is conspicuously marked or otherwise\r
+ designated in writing by the copyright owner as "Not a Contribution."\r
+\r
+ "Contributor" shall mean Licensor and any individual or Legal Entity\r
+ on behalf of whom a Contribution has been received by Licensor and\r
+ subsequently incorporated within the Work.\r
+\r
+ 2. Grant of Copyright License. Subject to the terms and conditions of\r
+ this License, each Contributor hereby grants to You a perpetual,\r
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable\r
+ copyright license to reproduce, prepare Derivative Works of,\r
+ publicly display, publicly perform, sublicense, and distribute the\r
+ Work and such Derivative Works in Source or Object form.\r
+\r
+ 3. Grant of Patent License. Subject to the terms and conditions of\r
+ this License, each Contributor hereby grants to You a perpetual,\r
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable\r
+ (except as stated in this section) patent license to make, have made,\r
+ use, offer to sell, sell, import, and otherwise transfer the Work,\r
+ where such license applies only to those patent claims licensable\r
+ by such Contributor that are necessarily infringed by their\r
+ Contribution(s) alone or by combination of their Contribution(s)\r
+ with the Work to which such Contribution(s) was submitted. If You\r
+ institute patent litigation against any entity (including a\r
+ cross-claim or counterclaim in a lawsuit) alleging that the Work\r
+ or a Contribution incorporated within the Work constitutes direct\r
+ or contributory patent infringement, then any patent licenses\r
+ granted to You under this License for that Work shall terminate\r
+ as of the date such litigation is filed.\r
+\r
+ 4. Redistribution. You may reproduce and distribute copies of the\r
+ Work or Derivative Works thereof in any medium, with or without\r
+ modifications, and in Source or Object form, provided that You\r
+ meet the following conditions:\r
+\r
+ (a) You must give any other recipients of the Work or\r
+ Derivative Works a copy of this License; and\r
+\r
+ (b) You must cause any modified files to carry prominent notices\r
+ stating that You changed the files; and\r
+\r
+ (c) You must retain, in the Source form of any Derivative Works\r
+ that You distribute, all copyright, patent, trademark, and\r
+ attribution notices from the Source form of the Work,\r
+ excluding those notices that do not pertain to any part of\r
+ the Derivative Works; and\r
+\r
+ (d) If the Work includes a "NOTICE" text file as part of its\r
+ distribution, then any Derivative Works that You distribute must\r
+ include a readable copy of the attribution notices contained\r
+ within such NOTICE file, excluding those notices that do not\r
+ pertain to any part of the Derivative Works, in at least one\r
+ of the following places: within a NOTICE text file distributed\r
+ as part of the Derivative Works; within the Source form or\r
+ documentation, if provided along with the Derivative Works; or,\r
+ within a display generated by the Derivative Works, if and\r
+ wherever such third-party notices normally appear. The contents\r
+ of the NOTICE file are for informational purposes only and\r
+ do not modify the License. You may add Your own attribution\r
+ notices within Derivative Works that You distribute, alongside\r
+ or as an addendum to the NOTICE text from the Work, provided\r
+ that such additional attribution notices cannot be construed\r
+ as modifying the License.\r
+\r
+ You may add Your own copyright statement to Your modifications and\r
+ may provide additional or different license terms and conditions\r
+ for use, reproduction, or distribution of Your modifications, or\r
+ for any such Derivative Works as a whole, provided Your use,\r
+ reproduction, and distribution of the Work otherwise complies with\r
+ the conditions stated in this License.\r
+\r
+ 5. Submission of Contributions. Unless You explicitly state otherwise,\r
+ any Contribution intentionally submitted for inclusion in the Work\r
+ by You to the Licensor shall be under the terms and conditions of\r
+ this License, without any additional terms or conditions.\r
+ Notwithstanding the above, nothing herein shall supersede or modify\r
+ the terms of any separate license agreement you may have executed\r
+ with Licensor regarding such Contributions.\r
+\r
+ 6. Trademarks. This License does not grant permission to use the trade\r
+ names, trademarks, service marks, or product names of the Licensor,\r
+ except as required for reasonable and customary use in describing the\r
+ origin of the Work and reproducing the content of the NOTICE file.\r
+\r
+ 7. Disclaimer of Warranty. Unless required by applicable law or\r
+ agreed to in writing, Licensor provides the Work (and each\r
+ Contributor provides its Contributions) on an "AS IS" BASIS,\r
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or\r
+ implied, including, without limitation, any warranties or conditions\r
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A\r
+ PARTICULAR PURPOSE. You are solely responsible for determining the\r
+ appropriateness of using or redistributing the Work and assume any\r
+ risks associated with Your exercise of permissions under this License.\r
+\r
+ 8. Limitation of Liability. In no event and under no legal theory,\r
+ whether in tort (including negligence), contract, or otherwise,\r
+ unless required by applicable law (such as deliberate and grossly\r
+ negligent acts) or agreed to in writing, shall any Contributor be\r
+ liable to You for damages, including any direct, indirect, special,\r
+ incidental, or consequential damages of any character arising as a\r
+ result of this License or out of the use or inability to use the\r
+ Work (including but not limited to damages for loss of goodwill,\r
+ work stoppage, computer failure or malfunction, or any and all\r
+ other commercial damages or losses), even if such Contributor\r
+ has been advised of the possibility of such damages.\r
+\r
+ 9. Accepting Warranty or Additional Liability. While redistributing\r
+ the Work or Derivative Works thereof, You may choose to offer,\r
+ and charge a fee for, acceptance of support, warranty, indemnity,\r
+ or other liability obligations and/or rights consistent with this\r
+ License. However, in accepting such obligations, You may act only\r
+ on Your own behalf and on Your sole responsibility, not on behalf\r
+ of any other Contributor, and only if You agree to indemnify,\r
+ defend, and hold each Contributor harmless for any liability\r
+ incurred by, or claims asserted against, such Contributor by reason\r
+ of your accepting any such warranty or additional liability.\r
+\r
+ END OF TERMS AND CONDITIONS\r
+\r
+ APPENDIX: How to apply the Apache License to your work.\r
+\r
+ To apply the Apache License to your work, attach the following\r
+ boilerplate notice, with the fields enclosed by brackets "[]"\r
+ replaced with your own identifying information. (Don't include\r
+ the brackets!) The text should be enclosed in the appropriate\r
+ comment syntax for the file format. We also recommend that a\r
+ file or class name and description of purpose be included on the\r
+ same "printed page" as the copyright notice for easier\r
+ identification within third-party archives.\r
+\r
+ Copyright [yyyy] [name of copyright owner]\r
+\r
+ Licensed under the Apache License, Version 2.0 (the "License");\r
+ you may not use this file except in compliance with the License.\r
+ You may obtain a copy of the License at\r
+\r
+ http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+ Unless required by applicable law or agreed to in writing, software\r
+ distributed under the License is distributed on an "AS IS" BASIS,\r
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ See the License for the specific language governing permissions and\r
+ limitations under the License.\r
+\r
--- /dev/null
+<manifest>
+ <request>
+ <domain name="_"/>
+ </request>
+</manifest>
--- /dev/null
+# Package Information for pkg-config
+
+prefix=@PREFIX@
+exec_prefix=@EXEC_PREFIX@
+libdir=@LIBDIR@
+includedir=@INCLUDEDIR@
+
+Name: appcore-watch
+Description: appcore watch library
+Version: @VERSION@
+Requires: aul dlog capi-appfw-app-control
+Libs: -L${libdir} -lappcore-watch
+Cflags: -I${includedir} -I${includedir}/appcore-watch
--- /dev/null
+# Package Information for pkg-config
+
+prefix=/usr
+exec_prefix=${prefix}
+libdir=${prefix}/lib
+includedir=${prefix}/include
+
+Name: appcore-watch
+Description: watch application library
+Version: 1.1
+Requires: aul dlog capi-appfw-app-control capi-appfw-app-common
+Libs: -L${libdir} -lappcore-watch
+Cflags: -I${includedir} -I${includedir}/appcore-watch
--- /dev/null
+/*
+ * app-core
+ *
+ * Copyright (c) 2015 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.
+ */
+
+/**
+ *
+ * @ingroup CAPI_APPLICATION_FRAMEWORK
+ * @defgroup CAPI_WATCH_APP_MODULE Watch Application
+ * @brief Watch application API
+ *
+ * @section CAPI_WATCH_APP_MODULE_HEADER Required Header
+ * \#include <watch_app.h>
+ * \#include <watch_app_efl.h>
+ * @section CAPI_WATCH_APP_MODULE_OVERVIEW Overview
+ * The @ref CAPI_WATCH_APP_MODULE API provides functions for handling Tizen watch application state changes or system events. Tizen watch application can be shown in the idle screen of the wearable device.
+ * This API also provides time utility functions for developting Tizen watch applications. You can develop a watch application that shows exact time using these time utility functions.
+ * For low powered wearable device, Tizen watch application supports a special mode that is named 'ambient'. When the device enters ambient mode, Tizen watch application that is shown in the idle screen can show limited UI and receives only ambient tick event at each minute to reduce power consumption. The limitation of UI that can be drawn in the ambient mode depends on the device. Usually, you should draw black and white UI only, and you should use below 20% of the pixels of the screen. If you don't want to draw your own ambient mode UI, you can set the 'ambient-support' attribute of the application as 'false' in the tizen-manifest.xml. Then, the platform will show proper default ambient mode UI.
+ *
+ * This API provides interfaces for the following categories:
+ * - Starting or exiting the main event loop
+ * - Registering callbacks for application state change events including timetick events
+ * - Registering callbacks for basic system events
+ * - Time related utility APIs for watch applications
+ *
+ * @subsection CAPI_WATCH_APP_MODULE_STATE_CHANGE_EVENT Registering Callbacks for Application State Change Events
+ * The state change events for Tizen watch application is similar to the Tizen UI applications. See the @ref CAPI_APPLICATION_MODULE.
+ * In Tizen watch application, an ambient changed event is added to support ambient mode. Time tick related events are also added to provide an exact time tick for the watch application.
+ *
+ * <p>
+ * <table>
+ * <tr>
+ * <th> Callback </th>
+ * <th> Description </th>
+ * </tr>
+ * <tr>
+ * <td>watch_app_create_cb()</td>
+ * <td>Hook to take necessary actions before the main event loop starts.
+ * Your UI generation code should be placed here so that you do not miss any events from your application UI.
+ * </td>
+ * </tr>
+ * <tr>
+ * <td>watch_app_control_cb()</td>
+ * <td> Hook to take necessary actions when your application called by another application.
+ * When the application gets launch request, this callback function is called.
+ * The application can get information about what is to be performed by using App Control API from app_control handle.
+ * </td>
+ * </tr>
+ * <tr>
+ * <td> watch_app_resume_cb() </td>
+ * <td> Hook to take necessary actions when an application becomes visible.
+ * If anything is relinquished in app_pause_cb() but is necessary to resume
+ * the application, it must be re-allocated here.
+ * </td>
+ * </tr>
+ * <tr>
+ * <td> watch_app_pause_cb() </td>
+ * <td> Hook to take necessary actions when an application becomes invisible.
+ * For example, you might wish to release memory resources so other applications can use these resources.
+ * It is important not to starve the application in front, which is interacting with the user.
+ * </td>
+ * </tr>
+ * <tr>
+ * <td> watch_app_terminate_cb() </td>
+ * <td> Hook to take necessary actions when your application is terminating.
+ * Your application should release all resources, especially any
+ * allocations and shared resources must be freed here so other running applications can fully use these shared resources.
+ * </td>
+ * </tr>
+ * <tr>
+ * <td> watch_app_ambient_changed_cb() </td>
+ * <td> Hook to take necessary actions when the device enters ambient mode. Your application needs to adopt its UI to be compatibile with the ambient mode. Note that, you only can use very limited colors and pixels of the screen when the device is in the ambient mode. Usually, you should use only black and white to draw the ambient mode UI and use below 20% of the pixels of the screen. If you don't want to draw your own ambient mode UI, you can set the 'ambient-support' attribute of the application as 'false' in the tizen-manifest.xml. Then, the platform will show proper default ambient mode UI.
+ * </tr>
+ * <tr>
+ * <td> watch_app_time_tick_cb() </td>
+ * <td> This callback is called at each second when your application is visible. This callback is not called when your application is not visible or the device is in ambient mode. You can use this tick to update the time that is being displayed by your watch application.</td>
+ * </tr>
+ * <tr>
+ * <td> watch_app_ambient_tick_cb() </td>
+ * <td> This callback is called at each minute when the device is ambient mode. You can use this tick to update the time that is being displayed by your watch application while the device is in ambient mode. You should not do a job that takes long time in this callback. You should update the UI as fast as possible in this callback. The platform might make the device to sleep in short time after the ambient tick expires.</td>
+ * </tr>
+ * </table>
+ * </p>
+ *
+ * Refer to the following state diagram to see the possible transitions and callbacks that are called while transition.
+ * @image html watch_app_lifecycle.png "Watch Application States"
+ *
+ * It is almost same as the Tizen UI application.
+ * Here are some remarks:
+ * - When your application is in running state, if the device enters the ambient mode, watch_app_pause_cb() will be called before the watch_app_ambient_changed_cb() is called. It is because you need to draw new UI for the ambient mode and release unnecessary resources in the ambient mode.
+ * - When the device returns from the ambient mode, the watch_app_resume_cb() will be called if your application is visible after the device returns from the ambient mode.
+ * - watch_app_time_tick() is only called while your application is visible.
+ * - watch_app_ambient_tick() is only called while the device is in the ambient mode.
+ *
+ * @subsection CAPI_WATCH_APP_MODULE_SYSTEM_EVENT Registering Callbacks for System Events
+ * Tizen watch applications can receive system events with watch_app_add_event_handler() api. The type of system events that can be received are same as Tizen UI applications. See @ref CAPI_APPLICATION_MODULE.
+ *
+ *
+ */
--- /dev/null
+/*
+ * Copyright (c) 2015 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_H__
+#define __APPCORE_WATCH_H__
+
+
+#include <libintl.h>
+#include <bundle.h>
+
+#include "app_control.h"
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct watchcore_ops {
+ void *data;
+ /**< Callback data */
+ int (*create) (int w, int h, void *); /**< This callback function is called at the start of the application. */
+ int (*app_control) (app_control_h, void *); /**< This callback function is called when other application send the launch request to the application. */
+ int (*pause) (void *); /**< Called when every window goes back */
+ int (*resume) (void *); /**< Called when any window comes on top */
+ int (*terminate) (void *); /**< This callback function is called once after the main loop of application exits. */
+ void (*time_tick) (void *, void *);
+ void (*ambient_tick) (void *, void *);
+ void (*ambient_changed) (int, void *);
+
+ void *reserved[6];
+ /**< Reserved */
+};
+
+enum watch_core_event {
+ /**< Unknown event */
+ WATCH_CORE_EVENT_UNKNOWN,
+
+ /**< Low memory */
+ WATCH_CORE_EVENT_LOW_MEMORY,
+
+ /**< Low battery */
+ WATCH_CORE_EVENT_LOW_BATTERY,
+
+ /**< Language setting is changed */
+ WATCH_CORE_EVENT_LANG_CHANGE,
+
+ /**< Region setting is changed */
+ WATCH_CORE_EVENT_REGION_CHANGE,
+};
+
+struct watch_time_s
+{
+ int year;
+ int month;
+ int day_of_week;
+ int day;
+ int hour;
+ int hour24;
+ int minute;
+ int second;
+ int millisecond;
+ time_t timestamp;
+ char *timezone;
+};
+
+int watch_core_main(const char *appid, int argc, char **argv, struct watchcore_ops *ops);
+
+int watch_core_terminate();
+
+int watch_core_set_event_callback(enum watch_core_event event,
+ int (*cb)(void *, void *), void *data);
+
+
+void watch_core_get_timeinfo(struct watch_time_s *timeinfo);
+
+bool watch_core_get_24h_mode(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __APPCORE_WATCH_H__ */
--- /dev/null
+/*
+ * Copyright (c) 2015 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_APP_H__
+#define __TIZEN_APPFW_WATCH_APP_H__
+
+#include <tizen.h>
+#include <time.h>
+#include <app_control.h>
+#include <app_common.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @addtogroup CAPI_WATCH_APP_MODULE
+ * @{
+ */
+
+/**
+ * @brief watch_time_h watch_time handle
+ * @since_tizen 2.3.1
+ */
+typedef struct _watch_time_s* watch_time_h;
+
+/**
+ * @brief Called when the application starts.
+ * @since_tizen 2.3.1
+ *
+ * @details The callback function is called before the main loop of the application starts.
+ * In this callback, you can initialize application resources like window creation, data structure, and so on.
+ * After this callback function returns @c true, the main loop starts up and watch_app_control_cb() is subsequently called.
+ * If this callback function returns @c false, the main loop doesn't start and watch_app_terminate_cb() is subsequently called.
+ *
+ * @param[in] width The width of the window of idle screen that will show the watch UI
+ * @param[in] height The height of the window of idle screen that will show the watch UI
+ * @param[in] user_data The user data passed from the callback registration function
+ * @return @c true on success,
+ * otherwise @c false
+ * @see watch_app_main()
+ * @see #watch_app_lifecycle_callback_s
+ */
+typedef bool (*watch_app_create_cb) (int width, int height, void *user_data);
+
+/**
+ * @brief Called when another application sends a launch request to the application.
+ * @since_tizen 2.3.1
+ *
+ * @details When the application is launched, this callback function is called after the main loop of the application starts up.
+ * The passed app_control handle describes the launch request and contains the information about why the application is launched.
+ * If the launch request is sent to the application in the running or pause state,
+ * this callback function can be called again to notify that the application has been asked to launch.
+ *
+ * The application is responsible for handling each launch request and responding appropriately.
+ * Using the App Control API, the application can get information about what is to be performed.
+ * The app_control handle may include only the default operation (#APP_CONTROL_OPERATION_DEFAULT) without any data.
+ * For more information, see The @ref CAPI_APP_CONTROL_MODULE API description.
+ *
+ * @param[in] app_control The handle to the app_control
+ * @param[in] user_data The user data passed from the callback registration function
+ * @see watch_app_main()
+ * @see #watch_app_lifecycle_callback_s
+ * @see @ref CAPI_APP_CONTROL_MODULE API
+ */
+typedef void (*watch_app_control_cb) (app_control_h app_control, void *user_data);
+
+/**
+ * @brief Called when the application is completely obscured by another application and becomes invisible.
+ * @since_tizen 2.3.1
+ *
+ * @details The application is not terminated and still running in the paused state.
+ *
+ * @param[in] user_data The user data passed from the callback registration function
+ * @see watch_app_main()
+ * @see #watch_app_lifecycle_callback_s
+ */
+typedef void (*watch_app_pause_cb) (void *user_data);
+
+/**
+ * @brief Called when the application becomes visible.
+ * @since_tizen 2.3.1
+ *
+ * @remarks This callback function is not called when the application moves from the created state to the running state.
+ *
+ * @param[in] user_data The user data passed from the callback registration function
+ * @see watch_app_main()
+ * @see #watch_app_lifecycle_callback_s
+ */
+typedef void (*watch_app_resume_cb) (void *user_data);
+
+/**
+ * @brief Called when the application's main loop exits.
+ * @details You should release the application's resources in this function.
+ * @since_tizen 2.3.1
+ *
+ * @param[in] user_data The user data passed from the callback registration function
+ * @see watch_app_main()
+ * @see #watch_app_lifecycle_callback_s
+ */
+typedef void (*watch_app_terminate_cb) (void *user_data);
+
+/**
+ * @brief Called at each second. This callback is not called while the app is paused or the device is in ambient mode.
+ * @since_tizen 2.3.1
+ *
+ * @param[in] watch_time The watch time handle. watch_time will not be available after returning this callback. It will be freed by the framework.
+ * @param[in] user_data The user data to be passed to the callback functions
+ */
+typedef void (*watch_app_time_tick_cb) (watch_time_h watch_time, void *user_data);
+
+/**
+ * @brief Called at each minute when the device in the ambient mode.
+ * @since_tizen 2.3.1
+ *
+ * @remarks You should not do a job that takes long time in this callback. You should update the UI as fast as possible in this callback. The platform might make the device to sleep in short time after the ambient tick expires.
+ *
+ * @param[in] watch_time The watch time handle. watch_time will not be available after returning this callback. It will be freed by the framework.
+ * @param[in] user_data The user data to be passed to the callback functions
+ */
+typedef void (*watch_app_ambient_tick_cb) (watch_time_h watch_time, void *user_data);
+
+/**
+ * @brief Called when the device enters or exits the ambient mode.
+ * @since_tizen 2.3.1
+ *
+ * @remarks For low powered wearable device, Tizen watch application supports a special mode that is named 'ambient'. When the device enters ambient mode, Tizen watch application that is shown in the idle screen can show limited UI and receives only ambient tick event at each minute to reduce power consumption. The limitation of UI that can be drawn in the ambient mode depends on the device. Usually, you should draw black and white UI only, and you should use below 20% of the pixels of the screen. If you don't want to draw your own ambient mode UI, you can set the 'ambient-support' attribute of the application as 'false' in the tizen-manifest.xml. Then, the platform will show proper default ambient mode UI.
+ *
+ * @param[in] ambient_mode If @c true the device enters the ambient mode,
+ * otherwise @c false
+ * @param[in] user_data The user data to be passed to the callback functions
+ */
+typedef void (*watch_app_ambient_changed_cb) (bool ambient_mode, void *user_data);
+
+
+/**
+ * @brief The structure type containing the set of callback functions for handling application events.
+ * @details It is one of the input parameters of the watch_app_main() function.
+ * @since_tizen 2.3.1
+ *
+ * @see watch_app_main()
+ * @see watch_app_create_cb()
+ * @see watch_app_control_cb()
+ * @see watch_app_pause_cb()
+ * @see watch_app_resume_cb()
+ * @see watch_app_time_tick_cb()
+ * @see watch_app_ambient_tick_cb()
+ * @see watch_app_ambient_changed_cb()
+ * @see watch_app_terminate_cb()
+ */
+typedef struct
+{
+ watch_app_create_cb create; /**< This callback function is called at the start of the application. */
+ watch_app_control_cb app_control; /**< This callback function is called when another application sends the launch request to the application. */
+ watch_app_pause_cb pause; /**< This callback function is called each time the application is completely obscured by another application and becomes invisible to the user. */
+ watch_app_resume_cb resume; /**< This callback function is called each time the application becomes visible to the user. */
+ watch_app_terminate_cb terminate; /**< This callback function is called before the application exits. */
+ watch_app_time_tick_cb time_tick; /**< This callback function is called at each second. */
+ watch_app_ambient_tick_cb ambient_tick; /**< This callback function is called at each minute in ambient mode. */
+ watch_app_ambient_changed_cb ambient_changed; /**< This callback function is called when the device enters or exits ambient mode. */
+
+} watch_app_lifecycle_callback_s;
+
+
+/**
+ * @brief Adds the system event handler
+ * @since_tizen 2.3.1
+ *
+ * @param[out] handler The event handler
+ * @param[in] event_type The system event type
+ * @param[in] callback The callback function
+ * @param[in] user_data The user data to be passed to the callback function
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #APP_ERROR_NONE Successfull
+ * @retval #APP_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #APP_ERROR_OUT_OF_MEMORY Out of memory
+ *
+ * @see app_event_type_e
+ * @see app_event_cb
+ * @see watch_app_remove_event_handler
+ */
+int watch_app_add_event_handler(app_event_handler_h *handler, app_event_type_e event_type, app_event_cb callback, void *user_data);
+
+
+/**
+ * @brief Removes registered event handler
+ * @since_tizen 2.3.1
+ *
+ * @param[in] event_handler The event handler
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #APP_ERROR_NONE Successfull
+ * @retval #APP_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @see watch_app_add_event_handler
+ */
+int watch_app_remove_event_handler(app_event_handler_h event_handler);
+
+
+/**
+ * @brief Runs the main loop of the application until watch_app_exit() is called.
+ * @since_tizen 2.3.1
+ *
+ * @remarks http://tizen.org/privilege/alarm.set privilege is needed to receive ambient ticks at each minute. If your app hasn't the privilege and you set the watch_app_ambient_tick_cb(), #APP_ERROR_PERMISSION_DENIED will be returned.
+ *
+ * @param[in] argc The argument count
+ * @param[in] argv The argument vector
+ * @param[in] callback The set of callback functions to handle application events
+ * @param[in] user_data The user data to be passed to the callback functions
+ *
+ * @return @c 0 on success,
+ * otherwise a negative error value.
+ * @retval #APP_ERROR_NONE Successful
+ * @retval #APP_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #APP_ERROR_INVALID_CONTEXT The application is illegally launched, not launched by the launch system.
+ * @retval #APP_ERROR_ALREADY_RUNNING The main loop has already started
+ * @retval #APP_ERROR_PERMISSION_DENIED Permission denied
+ *
+ * @see watch_app_main()
+ * @see watch_app_create_cb()
+ * @see watch_app_control_cb()
+ * @see watch_app_pause_cb()
+ * @see watch_app_resume_cb()
+ * @see watch_app_time_tick_cb()
+ * @see watch_app_ambient_tick_cb()
+ * @see watch_app_ambient_changed_cb()
+ * @see watch_app_terminate_cb()
+ * @see #watch_app_lifecycle_callback_s
+ */
+int watch_app_main(int argc, char **argv, watch_app_lifecycle_callback_s *callback, void *user_data);
+
+
+/**
+ * @brief Exits the main loop of the application.
+ * @details The main loop of the application stops and watch_app_terminate_cb() is invoked.
+ * @since_tizen 2.3.1
+ *
+ * @see watch_app_main()
+ * @see watch_app_terminate_cb()
+ */
+void watch_app_exit(void);
+
+/**
+ * @brief Gets the current time.
+ * @since_tizen 2.3.1
+ *
+ * @remarks You must release @a watch_time using watch_time_delete() after using it.
+ *
+ * @param[out] watch_time The watch_time handle to be newly created on successl
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #APP_ERROR_INVALID_PARAMETER Invalid Parameter
+ * @retval #APP_ERROR_OUT_OF_MEMORY Out of Memory
+ * @retval #APP_ERROR_NONE Successful
+ */
+int watch_time_get_current_time(watch_time_h* watch_time);
+
+/**
+ * @brief Deletes the watch time handle and releases all its resources.
+ * @since_tizen 2.3.1
+ *
+ * @param[in] watch_time The watch_time handle
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #APP_ERROR_INVALID_PARAMETER Invalid Parameter
+ * @retval #APP_ERROR_NONE Successful
+ */
+int watch_time_delete(watch_time_h watch_time);
+
+/**
+ * @brief Gets the year info.
+ * @since_tizen 2.3.1
+ *
+ * @param[in] watch_time The watch_time handle
+ * @param[out] year The year info
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #APP_ERROR_INVALID_PARAMETER Invalid Parameter
+ * @retval #APP_ERROR_NONE Successful
+ */
+int watch_time_get_year(watch_time_h watch_time, int *year);
+
+/**
+ * @brief Gets the month info.
+ * @since_tizen 2.3.1
+ *
+ * @param[in] watch_time The watch_time handle
+ * @param[out] month The month info
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #APP_ERROR_INVALID_PARAMETER Invalid Parameter
+ * @retval #APP_ERROR_NONE Successful
+ */
+int watch_time_get_month(watch_time_h watch_time, int *month);
+
+/**
+ * @brief Gets the day info.
+ * @since_tizen 2.3.1
+ *
+ * @param[in] watch_time The watch_time handle
+ * @param[out] day The day info
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #APP_ERROR_INVALID_PARAMETER Invalid Parameter
+ * @retval #APP_ERROR_NONE Successful
+ */
+int watch_time_get_day(watch_time_h watch_time, int *day);
+
+/**
+ * @brief Gets the day of week info.
+ * @since_tizen 2.3.1
+ *
+ * @param[in] watch_time The watch_time handle
+ * @param[out] day_of_week The day of week info. The value returns from 1 (Sunday) to 7 (Saturday).
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #APP_ERROR_INVALID_PARAMETER Invalid Parameter
+ * @retval #APP_ERROR_NONE Successful
+ */
+int watch_time_get_day_of_week(watch_time_h watch_time, int *day_of_week);
+
+/**
+ * @brief Gets the hour info.
+ * @since_tizen 2.3.1
+ *
+ * @param[in] watch_time The watch_time handle
+ * @param[out] hour The hour info
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #APP_ERROR_INVALID_PARAMETER Invalid Parameter
+ * @retval #APP_ERROR_NONE Successful
+ */
+int watch_time_get_hour(watch_time_h watch_time, int *hour);
+
+/**
+ * @brief Gets the hour info in 24-hour presentation.
+ * @since_tizen 2.3.1
+ *
+ * @param[in] watch_time The watch_time handle
+ * @param[out] hour24 The hour info
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #APP_ERROR_INVALID_PARAMETER Invalid Parameter
+ * @retval #APP_ERROR_NONE Successful
+ */
+int watch_time_get_hour24(watch_time_h watch_time, int *hour24);
+
+/**
+ * @brief Gets the minute info.
+ * @since_tizen 2.3.1
+ *
+ * @param[in] watch_time The watch_time handle
+ * @param[out] minute The minute info
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #APP_ERROR_INVALID_PARAMETER Invalid Parameter
+ * @retval #APP_ERROR_NONE Successful
+ */
+int watch_time_get_minute(watch_time_h watch_time, int *minute);
+
+/**
+ * @brief Gets the second info.
+ * @since_tizen 2.3.1
+ *
+ * @param[in] watch_time The watch_time handle
+ * @param[out] second The second info
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #APP_ERROR_INVALID_PARAMETER Invalid Parameter
+ * @retval #APP_ERROR_NONE Successful
+ */
+int watch_time_get_second(watch_time_h watch_time, int *second);
+
+/**
+ * @brief Gets the millisecond info.
+ * @since_tizen 2.3.1
+ *
+ * @param[in] watch_time The watch_time handle
+ * @param[out] millisecond The millisecond info
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #APP_ERROR_INVALID_PARAMETER Invalid Parameter
+ * @retval #APP_ERROR_NONE Successful
+ */
+int watch_time_get_millisecond(watch_time_h watch_time, int *millisecond);
+
+/**
+ * @brief Gets the UTC time.
+ * @since_tizen 2.3.1
+ *
+ * @param[in] watch_time The watch_time handle
+ * @param[out] utc_time The UTC time
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #APP_ERROR_INVALID_PARAMETER Invalid Parameter
+ * @retval #APP_ERROR_NONE Successful
+ */
+int watch_time_get_utc_time(watch_time_h watch_time, struct tm *utc_time);
+
+/**
+ * @brief Gets the UTC timestamp.
+ * @since_tizen 2.3.1
+ *
+ * @param[in] watch_time The watch_time handle
+ * @param[out] utc_timestamp The UTC timestamp
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #APP_ERROR_INVALID_PARAMETER Invalid Parameter
+ * @retval #APP_ERROR_NONE Successful
+ */
+int watch_time_get_utc_timestamp(watch_time_h watch_time, time_t *utc_timestamp);
+
+/**
+ * @brief Gets the ID of timezone for the @a watch_time handle.
+ * @since_tizen 2.3.1
+ *
+ * @remarks You must release @a time_zone_id using free() after using it.
+ *
+ * @param[in] watch_time The watch_time handle
+ * @param[out] time_zone_id The Timezone ID, such as "America/Los_Angeles"
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #APP_ERROR_INVALID_PARAMETER Invalid Parameter
+ * @retval #APP_ERROR_NONE Successful
+ */
+int watch_time_get_time_zone(watch_time_h watch_time, char **time_zone_id);
+
+/**
+ * @}
+ */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __TIZEN_APPFW_WATCH_APP_H__ */
--- /dev/null
+/*
+ * Copyright (c) 2015 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_APP_EFL_H__
+#define __TIZEN_APPFW_WATCH_APP_EFL_H__
+
+#include <Evas.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/**
+ * @addtogroup CAPI_WATCH_APP_MODULE
+ * @{
+ */
+
+/**
+ * @brief Gets Evas_Object for a Elementary window of watch application. You must use this window to draw watch UI on the idle screen.
+ * @since_tizen 2.3.1
+ *
+ * @param[out] win The pointer of Evas_Object for a Elementary window.
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #APP_ERROR_INVALID_PARAMETER Invalid Parameter
+ * @retval #APP_ERROR_OUT_OF_MEMORY Out of memory
+ * @retval #APP_ERROR_INVALID_CONTEXT Watch app is not initialized properly
+ * @retval #APP_ERROR_NONE Successful
+ */
+int watch_app_get_elm_win(Evas_Object **win);
+
+
+/**
+ * @}
+ */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
--- /dev/null
+Name: appcore-watch
+Summary: Watch Application
+Version: 1.3.0
+Release: 3
+Group: Application Framework/Libraries
+License: Apache-2.0
+Source0: appcore-watch-%{version}.tar.gz
+BuildRequires: pkgconfig(aul)
+BuildRequires: pkgconfig(dlog)
+BuildRequires: pkgconfig(elementary)
+BuildRequires: pkgconfig(dbus-glib-1)
+BuildRequires: pkgconfig(vconf)
+BuildRequires: pkgconfig(vconf-internal-keys)
+BuildRequires: pkgconfig(alarm-service)
+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: cmake
+
+
+%description
+Watch application
+
+
+%package devel
+Summary: appcore watch
+Group: Development/Libraries
+Requires: %{name} = %{version}-%{release}
+%description devel
+appcore watch (developement files)
+
+%package -n capi-appfw-watch-application-devel
+Summary: watch appliation
+Group: Development/Libraries
+Requires: appcore-watch-devel = %{version}-%{release}
+%description -n capi-appfw-watch-application-devel
+watch application (developement files)
+
+%prep
+%setup -q
+
+
+%build
+%if 0%{?sec_build_binary_debug_enable}
+export CFLAGS="$CFLAGS -DTIZEN_DEBUG_ENABLE"
+export CXXFLAGS="$CXXFLAGS -DTIZEN_DEBUG_ENABLE"
+export FFLAGS="$FFLAGS -DTIZEN_DEBUG_ENABLE"
+%endif
+export CFLAGS="$CFLAGS -Wall -Werror -Wno-unused-function -Wno-unused-but-set-variable"
+CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS" cmake . -DCMAKE_INSTALL_PREFIX=/usr
+
+make %{?jobs:-j%jobs}
+
+%install
+rm -rf %{buildroot}
+%make_install
+
+mkdir -p %{buildroot}/usr/lib/pkgconfig
+cp capi-appfw-watch-application.pc %{buildroot}/usr/lib/pkgconfig
+mkdir -p %{buildroot}/usr/share/license
+cp LICENSE %{buildroot}/usr/share/license/%{name}
+
+
+%post -p /sbin/ldconfig
+
+%postun -p /sbin/ldconfig
+
+
+%files
+%manifest appcore-watch.manifest
+%defattr(-,root,root,-)
+/usr/lib/libappcore-watch.so
+/usr/lib/libappcore-watch.so.1
+/usr/lib/libappcore-watch.so.1.1
+/usr/share/license/%{name}
+
+%files devel
+%defattr(-,root,root,-)
+/usr/lib/pkgconfig/appcore-watch.pc
+/usr/include/appcore-watch/appcore-watch.h
+
+%files -n capi-appfw-watch-application-devel
+/usr/include/appcore-watch/watch_app.h
+/usr/include/appcore-watch/watch_app_efl.h
+/usr/lib/pkgconfig/capi-appfw-watch-application.pc
+
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <locale.h>
+#include <libintl.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <unistd.h>
+#include <linux/limits.h>
+#include <glib.h>
+#include <tzplatform_config.h>
+
+#include <aul.h>
+#include <vconf.h>
+
+#include "appcore-watch-log.h"
+#include "appcore-watch-internal.h"
+
+#define PKGNAME_MAX 256
+#define PATH_APP_ROOT tzplatform_getenv(TZ_USER_APP)
+#define PATH_SYS_RO_APP_ROOT tzplatform_getenv(TZ_SYS_RO_APP)
+#define PATH_SYS_RW_APP_ROOT tzplatform_getenv(TZ_SYS_RW_APP)
+#define PATH_RES "/res"
+#define PATH_LOCALE "/locale"
+
+void _update_lang(void)
+{
+ char *lang = vconf_get_str(VCONFKEY_LANGSET);
+ if (lang) {
+ setenv("LANG", lang, 1);
+ setenv("LC_MESSAGES", lang, 1);
+
+ char *r = setlocale(LC_ALL, "");
+ if (r == NULL) {
+ r = setlocale(LC_ALL, lang);
+ if (r) {
+ _D("*****appcore setlocale=%s\n", r);
+ }
+ }
+ free(lang);
+ } else {
+ _E("failed to get current language for set lang env");
+ }
+}
+
+void _update_region(void)
+{
+ char *region;
+ char *r;
+
+ region = vconf_get_str(VCONFKEY_REGIONFORMAT);
+ if (region) {
+ setenv("LC_CTYPE", region, 1);
+ setenv("LC_NUMERIC", region, 1);
+ setenv("LC_TIME", region, 1);
+ setenv("LC_COLLATE", region, 1);
+ setenv("LC_MONETARY", region, 1);
+ setenv("LC_PAPER", region, 1);
+ setenv("LC_NAME", region, 1);
+ setenv("LC_ADDRESS", region, 1);
+ setenv("LC_TELEPHONE", region, 1);
+ setenv("LC_MEASUREMENT", region, 1);
+ setenv("LC_IDENTIFICATION", region, 1);
+ r = setlocale(LC_ALL, "");
+ if (r != NULL) {
+ _D("*****appcore setlocale=%s\n", r);
+ }
+ free(region);
+ } else {
+ _E("failed to get current region format for set region env");
+ }
+}
+
+/* from appcore.c */
+static int __get_dir_name(char *dirname)
+{
+ char pkg_name[PKGNAME_MAX];
+ int r;
+ int pid;
+
+ pid = getpid();
+ if (pid < 0)
+ return -1;
+
+ if (aul_app_get_pkgname_bypid(pid, pkg_name, PKGNAME_MAX) != AUL_R_OK)
+ return -1;
+
+ r = snprintf(dirname, PATH_MAX, "%s/%s" PATH_RES PATH_LOCALE,
+ PATH_APP_ROOT, pkg_name);
+
+ if (r < 0)
+ return -1;
+
+ if (access(dirname, R_OK) == 0)
+ return 0;
+
+ r = snprintf(dirname, PATH_MAX, "%s/%s" PATH_RES PATH_LOCALE,
+ PATH_SYS_RO_APP_ROOT, pkg_name);
+
+ if (r < 0)
+ return -1;
+
+ if (access(dirname, R_OK) == 0)
+ return 0;
+
+ r = snprintf(dirname, PATH_MAX, "%s/%s" PATH_RES PATH_LOCALE,
+ PATH_SYS_RW_APP_ROOT, pkg_name);
+
+ if (r < 0)
+ return -1;
+
+ return 0;
+}
+
+
+static int __set_i18n(const char *domain)
+{
+ char *r;
+ char dirname[PATH_MAX];
+
+ if (domain == NULL) {
+ errno = EINVAL;
+ return -1;
+ }
+
+ __get_dir_name(dirname);
+ _D("locale dir: %s", dirname);
+
+ r = setlocale(LC_ALL, "");
+ /* if locale is not set properly, try again to set as language base */
+ if (r == NULL) {
+ char *lang = vconf_get_str(VCONFKEY_LANGSET);
+ r = setlocale(LC_ALL, lang);
+ if (r) {
+ _D("*****appcore setlocale=%s\n", r);
+ }
+ if (lang) {
+ free(lang);
+ }
+ }
+ if (r == NULL) {
+ _E("appcore: setlocale() error");
+ }
+
+ r = bindtextdomain(domain, dirname);
+ if (r == NULL) {
+ _E("appcore: bindtextdomain() error");
+ }
+
+ r = textdomain(domain);
+ if (r == NULL) {
+ _E("appcore: textdomain() error");
+ }
+
+ return 0;
+}
+
+int _set_i18n(const char *domainname)
+{
+ _update_lang();
+ _update_region();
+
+ return __set_i18n(domainname);
+}
+
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#ifndef __APPCORE_WATCH_INTERNAL_H__
+#define __APPCORE_WATCH_INTERNAL_H__
+
+int _set_i18n(const char *domainname);
+void _update_lang(void);
+void _update_region(void);
+
+#endif /* __APPCORE_WATCH_INTERNAL_H__ */
--- /dev/null
+/*
+ * Copyright (c) 2015 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_
--- /dev/null
+/*
+ * Copyright (c) 2015 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 <dbus/dbus.h>
+#include <dbus/dbus-glib-lowlevel.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 DBusConnection *bus = NULL;
+
+static int (*_deviced_signal_alpm_handler) (int ambient, void *data);
+static void *_deviced_signal_alpm_data;
+
+static DBusHandlerResult
+__dbus_signal_filter(DBusConnection *conn, DBusMessage *message,
+ void *user_data)
+{
+ const char *sender;
+ const char *interface;
+ const char *value;
+
+ DBusError error;
+ dbus_error_init(&error);
+
+ sender = dbus_message_get_sender(message);
+ if (sender == NULL)
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
+ interface = dbus_message_get_interface(message);
+ if (interface == NULL) {
+ _E("reject by security issue - no interface\n");
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ }
+
+ if (dbus_message_is_signal(message, interface, DEVICED_SIGNAL_HOME_SCREEN))
+ {
+ if (dbus_message_get_args(message, &error, DBUS_TYPE_STRING, &value, DBUS_TYPE_INVALID) == FALSE) {
+ _E("Failed to get data: %s", error.message);
+ dbus_error_free(&error);
+ }
+
+ if (_deviced_signal_alpm_handler)
+ {
+ if (strcmp(value, CLOCK_START) == 0)
+ {
+ _deviced_signal_alpm_handler(1, _deviced_signal_alpm_data);
+ }
+ else if (strcmp(value, CLOCK_STOP) == 0)
+ {
+ _deviced_signal_alpm_handler(0, _deviced_signal_alpm_data);
+ }
+ }
+ }
+
+ return DBUS_HANDLER_RESULT_HANDLED;
+}
+
+static int __dbus_init(void)
+{
+ if (bus)
+ return 0;
+
+ DBusError error;
+ dbus_error_init(&error);
+ bus = dbus_bus_get_private(DBUS_BUS_SYSTEM, &error);
+ if (!bus) {
+ _E("Failed to connect to the D-BUS daemon: %s", error.message);
+ dbus_error_free(&error);
+ return -1;
+ }
+
+ dbus_connection_setup_with_g_main(bus, NULL);
+
+ return 0;
+}
+
+static int __dbus_signal_handler_init(const char* path, const char* interface)
+{
+ char rule[MAX_BUFFER_SIZE] = {0,};
+
+ DBusError error;
+ dbus_error_init(&error);
+
+ snprintf(rule, MAX_BUFFER_SIZE,
+ "path='%s',type='signal',interface='%s'", path, interface);
+
+ dbus_bus_add_match(bus, rule, &error);
+ if (dbus_error_is_set(&error)) {
+ _E("Fail to rule set: %s", error.message);
+ dbus_error_free(&error);
+ return -1;
+ }
+
+ if (dbus_connection_add_filter(bus, __dbus_signal_filter, NULL, NULL) == FALSE) {
+ _E("add filter fail");
+ return -1;
+ }
+
+ return 0;
+}
+
+int _watch_core_listen_alpm_handler(int (*func) (int, void *), void *data)
+{
+ _D("watch_core_listen_deviced_alpm");
+
+ __dbus_init();
+
+ if(__dbus_signal_handler_init(DEVICED_PATH, DEVICED_INTERFACE) < 0)
+ {
+ _E("error app signal init");
+ return -1;
+ }
+
+ _deviced_signal_alpm_handler = func;
+ _deviced_signal_alpm_data = data;
+
+ return 0;
+}
+
+int _watch_core_send_alpm_update_done(void)
+{
+ DBusMessage *message;
+
+ __dbus_init();
+
+ message = dbus_message_new_signal(ALPM_VIEWER_PATH,
+ ALPM_VIEWER_INTERFACE,
+ ALPM_VIEWER_SIGNAL_DRAW_DONE);
+
+ if (dbus_message_append_args(message,
+ DBUS_TYPE_INVALID) == FALSE) {
+ _E("Failed to load data error");
+ return -1;
+ }
+
+ if (dbus_connection_send(bus, message, NULL) == FALSE) {
+ _E("dbus send error");
+ return -1;
+ }
+
+ dbus_connection_flush(bus);
+ dbus_message_unref(message);
+
+ _I("send a alpm update done signal");
+
+ return 0;
+}
+
--- /dev/null
+/*
+ * Copyright (c) 2015 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__
+
+
+#include <dbus/dbus.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"
+
+int _watch_core_listen_alpm_handler(int (*func) (int, void *), void *data);
+int _watch_core_send_alpm_update_done(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __APPCORE_WATCH_SIGNAL_H__ */
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#define _GNU_SOURCE
+
+#include <errno.h>
+#include <string.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <malloc.h>
+#include <assert.h>
+
+#include <Elementary.h>
+
+#include <app_control.h>
+#include <app_control_internal.h>
+
+#include <aul.h>
+#include <dlog.h>
+#include <vconf.h>
+#include <alarm.h>
+#include <glib-object.h>
+
+
+#include <widget_app.h>
+
+#include "appcore-watch.h"
+#include "appcore-watch-log.h"
+#include "appcore-watch-signal.h"
+#include "appcore-watch-internal.h"
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+
+#define LOG_TAG "WATCH_CORE"
+
+#include <unicode/utypes.h>
+#include <unicode/putil.h>
+#include <unicode/uiter.h>
+#include <unicode/udat.h>
+#include <unicode/udatpg.h>
+#include <unicode/ustring.h>
+
+#define WATCH_ID "internal://WATCH_ID"
+
+#define AUL_K_CALLER_APPID "__AUL_CALLER_APPID__"
+#define APPID_BUFFER_MAX 255
+
+#define TIMEZONE_BUFFER_MAX 1024
+#define LOCAL_TIME_PATH "/opt/etc/localtime"
+
+#define ONE_SECOND 1000
+#define ONE_MINUTE 60
+#define ONE_HOUR 60
+
+static Ecore_Timer *watch_tick = NULL;
+
+static alarm_id_t alarm_id = 0;
+
+/**
+ * Appcore internal system event
+ */
+enum sys_event {
+ SE_UNKNOWN,
+ SE_LOWMEM,
+ SE_LOWBAT,
+ SE_LANGCHG,
+ SE_REGIONCHG,
+ SE_TIMECHG,
+ SE_MAX
+};
+
+/**
+ * watch internal state
+ */
+enum watch_state {
+ WS_NONE,
+ WS_CREATED,
+ WS_RUNNING,
+ WS_PAUSED,
+ WS_DYING,
+};
+
+enum watch_event {
+ WE_UNKNOWN,
+ WE_CREATE,
+ WE_PAUSE,
+ WE_RESUME,
+ WE_APPCONTROL,
+ WE_AMBIENT,
+ WE_TERMINATE,
+ WE_MAX
+};
+
+
+static enum watch_core_event to_ae[SE_MAX] = {
+ WATCH_CORE_EVENT_UNKNOWN, /* SE_UNKNOWN */
+ WATCH_CORE_EVENT_LOW_MEMORY, /* SE_LOWMEM */
+ WATCH_CORE_EVENT_LOW_BATTERY, /* SE_LOWBAT */
+ WATCH_CORE_EVENT_LANG_CHANGE,
+ WATCH_CORE_EVENT_REGION_CHANGE,
+};
+
+static int watch_core_event_initialized[SE_MAX] = {0};
+
+enum cb_type { /* callback */
+ _CB_NONE,
+ _CB_SYSNOTI,
+ _CB_APPNOTI,
+ _CB_VCONF,
+};
+
+struct evt_ops {
+ enum cb_type type;
+ union {
+ enum watch_core_event sys;
+ enum watch_event app;
+ const char *vkey;
+ } key;
+
+ int (*cb_pre) (void *);
+ int (*cb) (void *);
+ int (*cb_post) (void *);
+
+ int (*vcb_pre) (void *, void *);
+ int (*vcb) (void *, void *);
+ int (*vcb_post) (void *, void *);
+};
+
+struct watch_priv {
+ const char *appid;
+ const char *name;
+ pid_t pid;
+ enum watch_state state;
+ int ambient_mode;
+ int ambient_mode_skip_resume;
+
+ struct watchcore_ops *ops;
+};
+
+static struct watch_priv priv;
+
+struct watch_ops {
+ void *data;
+ void (*cb_app)(enum watch_event, void *, bundle *);
+};
+
+/**
+ * Appcore system event operation
+ */
+struct sys_op {
+ int (*func) (void *, void *);
+ void *data;
+};
+
+struct watch_core {
+ int init;
+
+ const struct watch_ops *ops;
+ struct sys_op sops[SE_MAX];
+};
+
+static struct watch_core core;
+
+static int __sys_lowmem_post(void *data, void *evt);
+static int __sys_lowmem(void *data, void *evt);
+static int __sys_lowbatt(void *data, void *evt);
+static int __sys_langchg_pre(void *data, void *evt);
+static int __sys_langchg(void *data, void *evt);
+static int __sys_regionchg_pre(void *data, void *evt);
+static int __sys_regionchg(void *data, void *evt);
+
+
+static struct evt_ops evtops[] = {
+ {
+ .type = _CB_VCONF,
+ .key.vkey = VCONFKEY_SYSMAN_LOW_MEMORY,
+ .vcb_post = __sys_lowmem_post,
+ .vcb = __sys_lowmem,
+ },
+ {
+ .type = _CB_VCONF,
+ .key.vkey = VCONFKEY_SYSMAN_BATTERY_STATUS_LOW,
+ .vcb = __sys_lowbatt,
+ },
+ {
+ .type = _CB_VCONF,
+ .key.vkey = VCONFKEY_LANGSET,
+ .vcb_pre = __sys_langchg_pre,
+ .vcb = __sys_langchg,
+ },
+ {
+ .type = _CB_VCONF,
+ .key.vkey = VCONFKEY_REGIONFORMAT,
+ .vcb_pre = __sys_regionchg_pre,
+ .vcb = __sys_regionchg,
+ },
+};
+
+static void __watch_core_signal_init(void);
+static int __watch_core_widget_init(void);
+
+static Eina_Bool __watch_core_time_tick(void *data);
+static void __watch_core_time_tick_cancel(void);
+
+static int __watch_core_ambient_tick(alarm_id_t id, void *data);
+
+static int __widget_create(const char *id, const char *content, int w, int h, void *data);
+static int __widget_resize(const char *id, int w, int h, void *data);
+static int __widget_destroy(const char *id, widget_app_destroy_type_e reason, void *data);
+static int __widget_pause(const char *id, void *data);
+static int __widget_resume(const char *id, void *data);
+
+extern int app_control_create_event(bundle *data, struct app_control_s **app_control);
+
+static void __exit_loop(void *data)
+{
+ ecore_main_loop_quit();
+}
+
+static void __do_app(enum watch_event event, void *data, bundle * b)
+{
+ struct watch_priv *watch_data = data;
+ app_control_h app_control = NULL;
+
+ _ret_if(watch_data == NULL);
+
+ if (event == WE_TERMINATE)
+ {
+ watch_data->state = WS_DYING;
+ ecore_main_loop_thread_safe_call_sync((Ecore_Data_Cb)__exit_loop, NULL);
+ return;
+ }
+
+ _ret_if(watch_data->ops == NULL);
+
+ switch (event)
+ {
+ case WE_APPCONTROL:
+ _D("appcontrol request");
+
+ if (app_control_create_event(b, &app_control) != 0)
+ {
+ _E("failed to get the app_control handle");
+ return;
+ }
+
+ if (watch_data->ops->app_control)
+ watch_data->ops->app_control(app_control, watch_data->ops->data);
+
+ app_control_destroy(app_control);
+
+ break;
+
+ case WE_PAUSE:
+ _D("WE_PAUSE");
+
+ if (watch_data->state == WS_CREATED)
+ {
+ _E("Invalid state");
+
+ return;
+ }
+
+ // Handling the ambient mode
+ if (watch_data->ambient_mode)
+ {
+ watch_data->ambient_mode_skip_resume = 1;
+ }
+
+ // Cancel the time_tick callback
+ __watch_core_time_tick_cancel();
+
+ if (watch_data->state == WS_RUNNING)
+ {
+
+ if (watch_data->ops->pause) {
+ int r = priv.ops->pause(priv.ops->data);
+ if (r < 0) {
+ _E("pause() fails");
+ }
+ }
+ }
+
+ watch_data->state = WS_PAUSED;
+ break;
+
+ case WE_RESUME:
+ _D("WE_RESUME");
+
+ // Handling the ambient mode
+ if (watch_data->ambient_mode)
+ {
+ watch_data->ambient_mode_skip_resume = 0;
+ return;
+ }
+
+ if (watch_data->state == WS_PAUSED || watch_data->state == WS_CREATED)
+ {
+ if (watch_data->ops->resume) {
+ int r = priv.ops->resume(priv.ops->data);
+ if (r < 0) {
+ _E("resume() fails");
+ }
+ }
+ }
+
+ watch_data->state = WS_RUNNING;
+
+ // Set the time tick callback
+ if (!watch_tick)
+ {
+ __watch_core_time_tick(NULL);
+ }
+ else
+ {
+ __watch_core_time_tick_cancel();
+ __watch_core_time_tick(NULL);
+ }
+
+ break;
+
+ case WE_AMBIENT:
+ _D("WE_AMBIENT");
+
+ if (priv.ops && priv.ops->ambient_changed) {
+ priv.ops->ambient_changed(watch_data->ambient_mode, priv.ops->data);
+ }
+
+ break;
+
+ default:
+ break;
+ }
+
+}
+
+static struct watch_ops w_ops = {
+ .data = &priv,
+ .cb_app = __do_app,
+};
+
+char* __get_domain_name(const char *appid)
+{
+ char *name_token = NULL;
+
+ if (appid == NULL)
+ {
+ _E("appid is NULL");
+ return NULL;
+ }
+
+ // com.vendor.name -> name
+ name_token = strrchr(appid, '.');
+
+ if (name_token == NULL)
+ {
+ _E("appid is invalid");
+ return NULL;
+ }
+
+ name_token++;
+
+ return strdup(name_token);
+}
+
+static int __set_data(struct watch_priv *watch, const char *appid, struct watchcore_ops *ops)
+{
+ if (ops == NULL) {
+ errno = EINVAL;
+ return -1;
+ }
+
+ watch->ops = ops;
+
+ watch->appid = strdup(appid);
+ watch->name = __get_domain_name(appid);
+ watch->pid = getpid();
+
+ return 0;
+}
+
+static int __watch_appcontrol(void *data, bundle * k)
+{
+ struct watch_core *wc = data;
+ _retv_if(wc == NULL || wc->ops == NULL, -1);
+ _retv_if(wc->ops->cb_app == NULL, 0);
+
+ wc->ops->cb_app(WE_APPCONTROL, wc->ops->data, k);
+
+ return 0;
+}
+
+static int __watch_terminate(void *data)
+{
+ struct watch_core *wc = data;
+
+ _retv_if(wc == NULL || wc->ops == NULL, -1);
+ _retv_if(wc->ops->cb_app == NULL, 0);
+
+ wc->ops->cb_app(WE_TERMINATE, wc->ops->data, NULL);
+
+ return 0;
+}
+
+static int __sys_do_default(struct watch_core *wc, enum sys_event event)
+{
+ int r;
+
+ switch (event) {
+ case SE_LOWBAT:
+ /*r = __def_lowbatt(wc);*/
+ r = 0;
+ break;
+ default:
+ r = 0;
+ break;
+ };
+
+ return r;
+}
+
+static int __sys_do(struct watch_core *wc, void *event_info, enum sys_event event)
+{
+ struct sys_op *op;
+
+ _retv_if(wc == NULL || event >= SE_MAX, -1);
+
+ op = &wc->sops[event];
+
+ if (op->func == NULL)
+ return __sys_do_default(wc, event);
+
+ return op->func(event_info, op->data);
+}
+
+static int __sys_lowmem_post(void *data, void *evt)
+{
+ keynode_t *key = evt;
+ int val;
+
+ val = vconf_keynode_get_int(key);
+
+ if (val == VCONFKEY_SYSMAN_LOW_MEMORY_SOFT_WARNING) {
+#if defined(MEMORY_FLUSH_ACTIVATE)
+ struct appcore *wc = data;
+ wc->ops->cb_app(AE_LOWMEM_POST, wc->ops->data, NULL);
+#else
+ malloc_trim(0);
+#endif
+ }
+ return 0;
+}
+
+static int __sys_lowmem(void *data, void *evt)
+{
+ keynode_t *key = evt;
+ int val;
+
+ val = vconf_keynode_get_int(key);
+
+ if (val == VCONFKEY_SYSMAN_LOW_MEMORY_SOFT_WARNING)
+ return __sys_do(data, (void *)&val, SE_LOWMEM);
+
+ return 0;
+}
+
+static int __sys_lowbatt(void *data, void *evt)
+{
+ keynode_t *key = evt;
+ int val;
+
+ val = vconf_keynode_get_int(key);
+
+ /* VCONFKEY_SYSMAN_BAT_CRITICAL_LOW or VCONFKEY_SYSMAN_POWER_OFF */
+ if (val <= VCONFKEY_SYSMAN_BAT_CRITICAL_LOW)
+ return __sys_do(data, (void *)&val, SE_LOWBAT);
+
+ return 0;
+}
+
+static int __sys_langchg_pre(void *data, void *evt)
+{
+ _update_lang();
+ return 0;
+}
+
+static int __sys_langchg(void *data, void *evt)
+{
+ keynode_t *key = evt;
+ char *val;
+
+ val = vconf_keynode_get_str(key);
+
+ return __sys_do(data, (void *)val, SE_LANGCHG);
+}
+
+static int __sys_regionchg_pre(void *data, void *evt)
+{
+ _update_region();
+ return 0;
+}
+
+static int __sys_regionchg(void *data, void *evt)
+{
+ keynode_t *key = evt;
+ char *val;
+
+ val = vconf_keynode_get_str(key);
+
+ return __sys_do(data, (void *)val, SE_REGIONCHG);
+}
+
+static void __vconf_do(struct evt_ops *eo, keynode_t * key, void *data)
+{
+ _ret_if(eo == NULL);
+
+ if (eo->vcb_pre)
+ eo->vcb_pre(data, key);
+
+ if (eo->vcb)
+ eo->vcb(data, key);
+
+ if (eo->vcb_post)
+ eo->vcb_post(data, key);
+}
+
+static void __vconf_cb(keynode_t *key, void *data)
+{
+ int i;
+ const char *name;
+
+ name = vconf_keynode_get_name(key);
+ _ret_if(name == NULL);
+
+ _D("vconf changed: %s", name);
+
+ // Check the time changed event
+ if (!strcmp(name, VCONFKEY_SYSTEM_TIME_CHANGED))
+ {
+ struct watch_priv *watch_data = data;
+
+ _D("ambient_mode: %d", watch_data->ambient_mode);
+
+ if (watch_data->ambient_mode)
+ {
+ __watch_core_ambient_tick(0, NULL);
+ }
+
+ return;
+ }
+
+ for (i = 0; i < sizeof(evtops) / sizeof(evtops[0]); i++) {
+ struct evt_ops *eo = &evtops[i];
+
+ switch (eo->type) {
+ case _CB_VCONF:
+ if (!strcmp(name, eo->key.vkey))
+ __vconf_do(eo, key, data);
+ break;
+ default:
+ break;
+ }
+ }
+}
+
+static int __add_vconf(struct watch_core *wc, enum sys_event se)
+{
+ int r;
+
+ switch (se) {
+ case SE_LOWMEM:
+ r = vconf_notify_key_changed(VCONFKEY_SYSMAN_LOW_MEMORY, __vconf_cb, wc);
+ break;
+ case SE_LOWBAT:
+ r = vconf_notify_key_changed(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, __vconf_cb, wc);
+ break;
+ case SE_LANGCHG:
+ r = vconf_notify_key_changed(VCONFKEY_LANGSET, __vconf_cb, wc);
+ break;
+ case SE_REGIONCHG:
+ r = vconf_notify_key_changed(VCONFKEY_REGIONFORMAT, __vconf_cb, wc);
+ break;
+ case SE_TIMECHG:
+ r = vconf_notify_key_changed(VCONFKEY_SYSTEM_TIME_CHANGED, __vconf_cb, &priv);
+ break;
+ default:
+ r = -1;
+ break;
+ }
+
+ return r;
+}
+
+static int __del_vconf(enum sys_event se)
+{
+ int r;
+
+ switch (se) {
+ case SE_LOWMEM:
+ r = vconf_ignore_key_changed(VCONFKEY_SYSMAN_LOW_MEMORY, __vconf_cb);
+ break;
+ case SE_LOWBAT:
+ r = vconf_ignore_key_changed(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, __vconf_cb);
+ break;
+ case SE_LANGCHG:
+ r = vconf_ignore_key_changed(VCONFKEY_LANGSET, __vconf_cb);
+ break;
+ case SE_REGIONCHG:
+ r = vconf_ignore_key_changed(VCONFKEY_REGIONFORMAT, __vconf_cb);
+ break;
+ case SE_TIMECHG:
+ r = vconf_ignore_key_changed(VCONFKEY_SYSTEM_TIME_CHANGED, __vconf_cb);
+ break;
+ default:
+ r = -1;
+ break;
+ }
+
+ return r;
+}
+
+static int __del_vconf_list(void)
+{
+ int r;
+ enum sys_event se;
+
+ for (se = SE_LOWMEM; se < SE_MAX; se++) {
+ if (watch_core_event_initialized[se]) {
+ r = __del_vconf(se);
+ if (r < 0)
+ _E("Delete vconf callback failed");
+ else
+ watch_core_event_initialized[se] = 0;
+ }
+ }
+
+ return 0;
+}
+
+static int __aul_handler(aul_type type, bundle *b, void *data)
+{
+ int ret;
+
+ switch (type) {
+ case AUL_START:
+ ret = __watch_appcontrol(data, b);
+ break;
+ case AUL_RESUME:
+ break;
+ case AUL_TERMINATE:
+ ret = __watch_terminate(data);
+ break;
+ default:
+ break;
+ }
+
+ return 0;
+}
+
+EXPORT_API int watch_core_set_event_callback(enum watch_core_event event,
+ int (*cb) (void *, void *), void *data)
+{
+ struct watch_core *wc = &core;
+ struct sys_op *op;
+ enum sys_event se;
+ int r = 0;
+
+ for (se = SE_UNKNOWN; se < SE_MAX; se++) {
+ if (event == to_ae[se])
+ break;
+ }
+
+ if (se == SE_UNKNOWN || se >= SE_MAX) {
+ _E("Unregistered event");
+ errno = EINVAL;
+ return -1;
+ }
+
+ op = &wc->sops[se];
+
+ op->func = cb;
+ op->data = data;
+
+ if (op->func && !watch_core_event_initialized[se]) {
+ r = __add_vconf(wc, se);
+ if (r < 0)
+ _E("Add vconf callback failed");
+ else
+ watch_core_event_initialized[se] = 1;
+ } else if (!op->func && watch_core_event_initialized[se]) {
+ r = __del_vconf(se);
+ if (r < 0)
+ _E("Delete vconf callback failed");
+ else
+ watch_core_event_initialized[se] = 0;
+ }
+
+ return 0;
+}
+
+static char* __get_timezone(void)
+{
+ char buf[TIMEZONE_BUFFER_MAX] = {0,};
+
+ ssize_t len = readlink(LOCAL_TIME_PATH, buf, sizeof(buf)-1);
+
+ if (len != -1)
+ {
+ buf[len] = '\0';
+ }
+ else // handle error condition
+ {
+ return vconf_get_str(VCONFKEY_SETAPPL_TIMEZONE_ID);
+ }
+
+ return strdup(buf+20);
+}
+
+static void __get_timeinfo(struct watch_time_s *timeinfo)
+{
+ UErrorCode status = U_ZERO_ERROR;
+
+ // UTC time
+ struct timeval current;
+ gettimeofday(¤t, NULL);
+ timeinfo->timestamp = current.tv_sec;
+
+ // Time zone
+ char* timezone = __get_timezone();
+ UChar utf16_timezone[64] = {0};
+ u_uastrncpy(utf16_timezone, timezone, 64);
+
+ // Local time
+ UCalendar *cal = ucal_open(utf16_timezone, u_strlen(utf16_timezone), uloc_getDefault(), UCAL_TRADITIONAL, &status);
+ if (cal == NULL)
+ return;
+
+ timeinfo->year = ucal_get(cal, UCAL_YEAR, &status);
+ timeinfo->month = ucal_get(cal, UCAL_MONTH, &status) + 1;
+ timeinfo->day = ucal_get(cal, UCAL_DATE, &status);
+ timeinfo->day_of_week = ucal_get(cal, UCAL_DAY_OF_WEEK, &status);
+ timeinfo->hour = ucal_get(cal, UCAL_HOUR_OF_DAY, &status);
+ timeinfo->hour24 = ucal_get(cal, UCAL_HOUR_OF_DAY, &status);
+ timeinfo->minute = ucal_get(cal, UCAL_MINUTE, &status);
+ timeinfo->second = ucal_get(cal, UCAL_SECOND, &status);
+ timeinfo->millisecond = ucal_get(cal, UCAL_MILLISECOND, &status);
+ timeinfo->timezone = timezone;
+
+ timeinfo->hour -= (timeinfo->hour > 12) ? 12 : 0;
+ timeinfo->hour = (timeinfo->hour == 0) ? 12 : timeinfo->hour;
+
+ ucal_clear(cal);
+ ucal_close(cal);
+}
+
+int watch_core_init(const char *name, const struct watch_ops *ops,
+ int argc, char **argv)
+{
+ int r;
+
+ if (core.init != 0) {
+ errno = EALREADY;
+ return -1;
+ }
+
+ if (ops == NULL || ops->cb_app == NULL) {
+ errno = EINVAL;
+ return -1;
+ }
+
+ r = _set_i18n(name);
+ _retv_if(r == -1, -1);
+
+ r = __add_vconf(&core, SE_TIMECHG);
+ if (r < 0) {
+ _E("Add vconf callback failed");
+ goto err;
+ }
+
+ r = aul_launch_init(__aul_handler, &core);
+ if (r < 0) {
+ _E("Fail to call the aul_launch_init");
+ assert(0);
+ goto err;
+ }
+
+ r = aul_launch_argv_handler(argc, argv);
+ if (r < 0) {
+ _E("Fail to call the aul_launch_argv_handler");
+ goto err;
+ }
+
+ core.ops = ops;
+ core.init = 1;
+
+ return 0;
+
+ err:
+ return -1;
+}
+
+static void __watch_core_alarm_init(void)
+{
+ int r = 0;
+ int pid = getpid();
+ char appid[APPID_BUFFER_MAX] = {0,};
+ r = aul_app_get_appid_bypid(pid, appid, APPID_BUFFER_MAX);
+ if (r < 0) {
+ _E("fail to get the appid from the pid : %d", pid);
+ assert(0);
+ }
+
+ r = alarmmgr_init(appid);
+ if (r < 0) {
+ _E("fail to alarmmgr_init : error_code : %d",r);
+ assert(0);
+ }
+
+}
+
+static void __watch_core_time_tick_cancel(void)
+{
+ if (watch_tick)
+ {
+ ecore_timer_del(watch_tick);
+ watch_tick = NULL;
+ }
+}
+
+static Eina_Bool __watch_core_time_tick(void *data)
+{
+ _D("state: %d", priv.state);
+
+ if (priv.ops && priv.ops->time_tick && priv.state != WS_PAUSED)
+ {
+ struct watch_time_s timeinfo;
+ __get_timeinfo(&timeinfo);
+
+ // Set a next timer
+ double sec = (ONE_SECOND - timeinfo.millisecond) / 1000.0;
+ watch_tick = ecore_timer_add(sec, __watch_core_time_tick, NULL);
+
+ _D("next time tick: %f", sec);
+
+ priv.ops->time_tick(&timeinfo, priv.ops->data);
+ }
+
+ return ECORE_CALLBACK_CANCEL;
+}
+
+static int __watch_core_ambient_tick(alarm_id_t id, void *data)
+{
+ _D("state: %d", priv.state);
+
+ if (priv.ops && priv.ops->ambient_tick && priv.state != WS_RUNNING)
+ {
+ struct watch_time_s timeinfo;
+ __get_timeinfo(&timeinfo);
+
+ priv.ops->ambient_tick(&timeinfo, priv.ops->data);
+ }
+
+ return 0;
+}
+
+static int __widget_create(const char *id, const char *content, int w, int h, void *data)
+{
+ _D("widget_create");
+
+ if (priv.ops && priv.ops->create)
+ {
+ int r = priv.ops->create(w, h, priv.ops->data);
+ if (r < 0)
+ {
+ _E("Failed to initialize the application");
+ __exit_loop(NULL);
+ }
+ }
+
+ priv.state = WS_CREATED;
+
+ _D("widget_create done");
+
+ // Alarm init
+ __watch_core_alarm_init();
+
+ return WIDGET_ERROR_NONE;
+}
+
+static int __widget_resize(const char *id, int w, int h, void *data)
+{
+
+ return WIDGET_ERROR_NONE;
+}
+
+static int __widget_destroy(const char *id, widget_app_destroy_type_e reason, void *data)
+{
+ _D("widget_destory");
+
+ __exit_loop(NULL);
+
+ return WIDGET_ERROR_NONE;
+}
+
+static int __widget_pause(const char *id, void *data)
+{
+ _D("widget_pause");
+
+ __do_app(WE_PAUSE, &priv, NULL);
+
+ return WIDGET_ERROR_NONE;
+}
+
+static int __widget_resume(const char *id, void *data)
+{
+ _D("widget_resume");
+
+ __do_app(WE_RESUME, &priv, NULL);
+
+ return WIDGET_ERROR_NONE;
+}
+
+static int __signal_alpm_handler(int ambient, void *data)
+{
+ _D("_signal_alpm_handler: ambient: %d, state: %d", ambient, priv.state);
+
+ if (priv.ambient_mode == ambient)
+ {
+ _E("invalid state");
+ return 0;
+ }
+
+ // Enter the ambient mode
+ if (ambient)
+ {
+ if (priv.state != WS_PAUSED)
+ {
+ __do_app(WE_PAUSE, &priv, NULL);
+ priv.ambient_mode_skip_resume = 0;
+ }
+ else
+ {
+ priv.ambient_mode_skip_resume = 1;
+ }
+
+ priv.ambient_mode = 1;
+ __do_app(WE_AMBIENT, &priv, NULL);
+
+ if (priv.ops && priv.ops->ambient_tick) {
+ struct watch_time_s timeinfo;
+ __get_timeinfo(&timeinfo);
+
+ int sec = ONE_MINUTE - timeinfo.second;
+
+ _D("next time tick: %d", sec);
+
+ // Set a next alarm
+ int r = alarmmgr_add_alarm_withcb(ALARM_TYPE_VOLATILE, sec, 60,
+ __watch_core_ambient_tick, data, &alarm_id);
+ if (r < 0) {
+ _E("fail to alarmmgr_add_alarm_withcb : error_code : %d",r);
+ }
+
+ priv.ops->ambient_tick(&timeinfo, priv.ops->data);
+ }
+
+ // Send a update done signal
+ _watch_core_send_alpm_update_done();
+
+ }
+ // Exit the ambient mode
+ else
+ {
+ priv.ambient_mode = 0;
+ __do_app(WE_AMBIENT, &priv, NULL);
+
+ _D("Resume check: %d", priv.ambient_mode_skip_resume);
+ if (!priv.ambient_mode_skip_resume)
+ {
+ _D("Call the resume after ambient mode changed");
+ __do_app(WE_RESUME, &priv, NULL);
+ }
+
+ // Disable alarm
+ if (alarm_id)
+ {
+ alarmmgr_remove_alarm(alarm_id);
+ alarm_id = 0;
+ }
+ }
+
+ return 0;
+}
+
+static int __watch_core_widget_init(void)
+{
+ _D("Initialize the widget");
+
+ return 0;
+
+}
+
+static void __watch_core_signal_init(void)
+{
+ _watch_core_listen_alpm_handler(__signal_alpm_handler, NULL);
+}
+
+static int __before_loop(struct watch_priv *watch, int argc, char **argv)
+{
+ int r = 0;
+
+ if (argc <= 0 || argv == NULL) {
+ errno = EINVAL;
+ _E("argument are invalid");
+ return -1;
+ }
+
+ priv.ambient_mode = 0;
+ priv.ambient_mode_skip_resume = 0;
+
+#if !(GLIB_CHECK_VERSION(2, 36, 0))
+ g_type_init();
+#endif
+
+ elm_init(argc, argv);
+
+ r = watch_core_init(watch->name, &w_ops, argc, argv);
+ _retv_if(r < 0, -1);
+
+ r = __watch_core_widget_init();
+ _retv_if(r < 0, r);
+
+ __watch_core_signal_init();
+
+ return 0;
+}
+
+static void __after_loop(struct watch_priv *watch)
+{
+ if (priv.state == WS_RUNNING && watch->ops && watch->ops->pause)
+ watch->ops->pause(watch->ops->data);
+
+ priv.state = WS_DYING;
+
+ /* Cancel the time_tick callback */
+ __watch_core_time_tick_cancel();
+
+ if (watch->ops && watch->ops->terminate)
+ watch->ops->terminate(watch->ops->data);
+
+ elm_shutdown();
+
+ alarmmgr_fini();
+}
+
+
+EXPORT_API int watch_core_main(const char *appid, int argc, char **argv,
+ struct watchcore_ops *ops)
+{
+ int r;
+
+ r = __set_data(&priv, appid, ops);
+ _retv_if(r == -1, -1);
+
+ r = __before_loop(&priv, argc, argv);
+ if (r != 0) {
+ __del_vconf_list();
+ return r;
+ }
+
+ ecore_main_loop_begin();
+
+ aul_status_update(STATUS_DYING);
+
+ __after_loop(&priv);
+
+
+ return 0;
+}
+
+EXPORT_API int watch_core_terminate()
+{
+ ecore_main_loop_thread_safe_call_sync((Ecore_Data_Cb)__exit_loop, NULL);
+ return 0;
+}
+
+
+EXPORT_API void watch_core_get_timeinfo(struct watch_time_s *timeinfo)
+{
+ __get_timeinfo(timeinfo);
+}
+
--- /dev/null
+/*
+ * Copyright (c) 2015 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;
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 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 <stdlib.h>
+
+#include <bundle.h>
+#include <aul.h>
+#include <dlog.h>
+#include <app_common.h>
+#include <app_control.h>
+
+#include <Eina.h>
+#include <Evas.h>
+#include <Elementary.h>
+
+#include "appcore-watch.h"
+#include "appcore-watch-log.h"
+#include "watch_app_private.h"
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+
+#define LOG_TAG "CAPI_WATCH_APPLICATION"
+
+#define WATCH_ID "internal://WATCH_ID"
+
+typedef enum {
+ WATCH_APP_STATE_NOT_RUNNING, // The application has been launched or was running but was terminated
+ WATCH_APP_STATE_CREATING, // The application is initializing the resources on watch_app_create_cb callback
+ WATCH_APP_STATE_RUNNING, // The application is running in the foreground and background
+} watch_app_state_e;
+
+typedef struct {
+ char *package;
+ char *watch_app_name;
+ watch_app_state_e state;
+ watch_app_lifecycle_callback_s *callback;
+ void *data;
+} watch_app_context_s;
+
+typedef watch_app_context_s *watch_app_context_h;
+
+struct _watch_time_s
+{
+ int year;
+ int month;
+ int day_of_week;
+ int day;
+ int hour;
+ int hour24;
+ int minute;
+ int second;
+ int millisecond;
+ time_t timestamp;
+ char *timezone;
+};
+
+
+#define WATCH_APP_EVENT_MAX 5
+static Eina_List *handler_list[WATCH_APP_EVENT_MAX] = {NULL, };
+static int _initialized = 0;
+static int watch_core_initialized = 0;
+
+struct app_event_handler {
+ app_event_type_e type;
+ app_event_cb cb;
+ void *data;
+};
+
+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;
+ void *data;
+};
+
+static void _free_handler_list(void)
+{
+ int i;
+ app_event_handler_h handler;
+
+ for (i = 0; i < WATCH_APP_EVENT_MAX; i++) {
+ EINA_LIST_FREE(handler_list[i], handler)
+ free(handler);
+ }
+
+ eina_shutdown();
+}
+
+static int _watch_core_low_memory(void *event_info, void *data)
+{
+ Eina_List *l;
+ app_event_handler_h handler;
+ struct app_event_info event;
+
+ _I("watch_app_low_memory");
+
+ event.type = APP_EVENT_LOW_MEMORY;
+ event.value = event_info;
+
+ EINA_LIST_FOREACH(handler_list[APP_EVENT_LOW_MEMORY], l, handler) {
+ handler->cb(&event, handler->data);
+ }
+
+ return APP_ERROR_NONE;
+}
+
+static int _watch_core_low_battery(void *event_info, void *data)
+{
+ Eina_List *l;
+ app_event_handler_h handler;
+ struct app_event_info event;
+
+ _I("watch_app_low_battery");
+
+ event.type = APP_EVENT_LOW_BATTERY;
+ event.value = event_info;
+
+ EINA_LIST_FOREACH(handler_list[APP_EVENT_LOW_BATTERY], l, handler) {
+ handler->cb(&event, handler->data);
+ }
+
+ return APP_ERROR_NONE;
+}
+
+static int _watch_core_lang_changed(void *event_info, void *data)
+{
+ Eina_List *l;
+ app_event_handler_h handler;
+ struct app_event_info event;
+
+ _I("_watch_core_lang_changed");
+
+ event.type = APP_EVENT_LANGUAGE_CHANGED;
+ event.value = event_info;
+
+ EINA_LIST_FOREACH(handler_list[APP_EVENT_LANGUAGE_CHANGED], l, handler) {
+ handler->cb(&event, handler->data);
+ }
+
+ return APP_ERROR_NONE;
+}
+
+static int _watch_core_region_changed(void *event_info, void *data)
+{
+ Eina_List *l;
+ app_event_handler_h handler;
+ struct app_event_info event;
+
+ _I("_ui_app_appcore_region_changed");
+
+ event.type = APP_EVENT_REGION_FORMAT_CHANGED;
+ event.value = event_info;
+
+ EINA_LIST_FOREACH(handler_list[APP_EVENT_REGION_FORMAT_CHANGED], l, handler) {
+ handler->cb(&event, handler->data);
+ }
+
+ return APP_ERROR_NONE;
+}
+
+static void _watch_core_set_appcore_event_cb(struct watch_app_context *app_context)
+{
+ watch_core_set_event_callback(WATCH_CORE_EVENT_LOW_MEMORY, _watch_core_low_memory, app_context);
+ watch_core_set_event_callback(WATCH_CORE_EVENT_LANG_CHANGE, _watch_core_lang_changed, app_context);
+ watch_core_set_event_callback(WATCH_CORE_EVENT_REGION_CHANGE, _watch_core_region_changed, app_context);
+
+ if (eina_list_count(handler_list[APP_EVENT_LOW_BATTERY]) > 0)
+ watch_core_set_event_callback(WATCH_CORE_EVENT_LOW_BATTERY, _watch_core_low_battery, app_context);
+}
+
+static void _watch_core_unset_appcore_event_cb(void)
+{
+ watch_core_set_event_callback(WATCH_CORE_EVENT_LOW_MEMORY, NULL, NULL);
+ watch_core_set_event_callback(WATCH_CORE_EVENT_LANG_CHANGE, NULL, NULL);
+ watch_core_set_event_callback(WATCH_CORE_EVENT_REGION_CHANGE, NULL, NULL);
+
+ if (eina_list_count(handler_list[APP_EVENT_LOW_BATTERY]) > 0)
+ watch_core_set_event_callback(WATCH_CORE_EVENT_LOW_BATTERY, NULL, NULL);
+}
+
+static int _watch_core_create(int w, int h, void *data)
+{
+ _W("_watch_core_create");
+ struct watch_app_context *app_context = data;
+ watch_app_create_cb create_cb;
+
+ if (app_context == NULL) {
+ return watch_app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, NULL);
+ }
+
+ watch_core_initialized = 1;
+ _watch_core_set_appcore_event_cb(app_context);
+
+ create_cb = app_context->callback->create;
+
+ if (create_cb == NULL || create_cb(w, h, app_context->data) == false) {
+ return watch_app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "watch_app_create_cb() returns false");
+ }
+
+ app_context->state = WATCH_APP_STATE_RUNNING;
+
+ return APP_ERROR_NONE;
+}
+
+static int _watch_core_control(app_control_h app_control, void *data)
+{
+ _W("_watch_core_control");
+ struct watch_app_context *app_context = data;
+ watch_app_control_cb app_control_cb;
+
+ if (app_context == NULL)
+ return watch_app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, NULL);
+
+ app_control_cb = app_context->callback->app_control;
+
+ if (app_control_cb != NULL)
+ app_control_cb(app_control, app_context->data);
+
+ return APP_ERROR_NONE;
+}
+
+static int _watch_core_pause(void *data)
+{
+ _W("_watch_core_pause");
+ struct watch_app_context *app_context = data;
+ watch_app_pause_cb pause_cb;
+
+ if (app_context == NULL)
+ return watch_app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, NULL);
+
+ pause_cb = app_context->callback->pause;
+
+ if (pause_cb != NULL)
+ pause_cb(app_context->data);
+
+ return APP_ERROR_NONE;
+}
+
+static int _watch_core_resume(void *data)
+{
+ _W("_watch_core_resume");
+ struct watch_app_context *app_context = data;
+ watch_app_resume_cb resume_cb;
+
+ if (app_context == NULL)
+ return watch_app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, NULL);
+
+ resume_cb = app_context->callback->resume;
+
+ if (resume_cb != NULL)
+ resume_cb(app_context->data);
+
+ return APP_ERROR_NONE;
+}
+
+static int _watch_core_terminate(void *data)
+{
+ _W("_watch_core_terminate");
+ struct watch_app_context *app_context = data;
+ watch_app_terminate_cb terminate_cb;
+
+ if (app_context == NULL)
+ return watch_app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, NULL);
+
+ terminate_cb = app_context->callback->terminate;
+
+ if (terminate_cb != NULL)
+ terminate_cb(app_context->data);
+
+ _watch_core_unset_appcore_event_cb();
+
+ if (_initialized)
+ _free_handler_list();
+
+ return APP_ERROR_NONE;
+}
+
+static void _watch_core_time_tick(void *watchtime, void *data)
+{
+ _I("_watch_core_time_tick");
+ struct watch_app_context *app_context = data;
+ watch_app_time_tick_cb time_tick_cb;
+
+ if (app_context == NULL)
+ return;
+
+ time_tick_cb = app_context->callback->time_tick;
+
+ if (time_tick_cb != NULL)
+ time_tick_cb((watch_time_h)watchtime, app_context->data);
+}
+
+static void _watch_core_ambient_tick(void *watchtime, void *data)
+{
+ _W("_watch_core_ambient_tick");
+ struct watch_app_context *app_context = data;
+ watch_app_ambient_tick_cb ambient_tick_cb;
+
+ if (app_context == NULL)
+ return;
+
+ ambient_tick_cb = app_context->callback->ambient_tick;
+
+ if (ambient_tick_cb != NULL)
+ ambient_tick_cb((watch_time_h)watchtime, app_context->data);
+}
+
+static void _watch_core_ambient_changed(int ambient, void *data)
+{
+ _W("_watch_core_ambient_changed: %d", ambient);
+ struct watch_app_context *app_context = data;
+ watch_app_ambient_changed_cb ambient_changed_cb;
+
+ if (app_context == NULL)
+ return;
+
+ ambient_changed_cb = app_context->callback->ambient_changed;
+
+ if (ambient_changed_cb != NULL)
+ ambient_changed_cb((bool)ambient, app_context->data);
+}
+
+
+EXPORT_API int watch_app_main(int argc, char **argv, watch_app_lifecycle_callback_s *callback, void *user_data)
+{
+ struct watch_app_context app_context = {
+ .appid = NULL,
+ .state = WATCH_APP_STATE_NOT_RUNNING,
+ .callback = callback,
+ .data = user_data
+ };
+
+ struct watchcore_ops watchcore_context = {
+ .data = &app_context,
+ .create = _watch_core_create,
+ .app_control = _watch_core_control,
+ .pause = _watch_core_pause,
+ .resume = _watch_core_resume,
+ .terminate = _watch_core_terminate,
+ .time_tick = _watch_core_time_tick,
+ .ambient_tick = _watch_core_ambient_tick,
+ .ambient_changed = _watch_core_ambient_changed,
+ };
+
+ 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 (app_context.state != WATCH_APP_STATE_NOT_RUNNING)
+ return watch_app_error(APP_ERROR_ALREADY_RUNNING, __FUNCTION__, NULL);
+
+ if (app_get_id(&(app_context.appid)) != APP_ERROR_NONE)
+ return watch_app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "failed to get the appid");
+
+ app_context.state = WATCH_APP_STATE_CREATING;
+
+ watch_core_main(app_context.appid, argc, argv, &watchcore_context);
+
+ free(app_context.appid);
+
+ return APP_ERROR_NONE;
+}
+
+EXPORT_API void watch_app_exit(void)
+{
+ _I("watch_app_exit");
+ watch_core_terminate();
+}
+
+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;
+ Eina_List *l_itr;
+
+ if (!_initialized) {
+ eina_init();
+ _initialized = 1;
+ }
+
+ 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);
+
+ EINA_LIST_FOREACH(handler_list[event_type], l_itr, handler) {
+ if (handler->cb == callback)
+ return watch_app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
+ }
+
+ handler = calloc(1, sizeof(struct app_event_handler));
+ if (!handler)
+ return watch_app_error(APP_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL);
+
+ handler->type = event_type;
+ handler->cb = callback;
+ handler->data = user_data;
+
+ if (watch_core_initialized
+ && event_type == APP_EVENT_LOW_BATTERY
+ && eina_list_count(handler_list[event_type]) == 0)
+ watch_core_set_event_callback(WATCH_CORE_EVENT_LOW_BATTERY, _watch_core_low_battery, NULL);
+
+ handler_list[event_type] = eina_list_append(handler_list[event_type], handler);
+
+ *event_handler = handler;
+
+ return APP_ERROR_NONE;
+}
+
+EXPORT_API int watch_app_remove_event_handler(app_event_handler_h event_handler)
+{
+ app_event_handler_h handler;
+ app_event_type_e type;
+ Eina_List *l_itr;
+ Eina_List *l_next;
+
+ if (event_handler == NULL)
+ return watch_app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
+
+ if (!_initialized) {
+ _I("handler list is not initialized");
+ return APP_ERROR_NONE;
+ }
+
+ type = event_handler->type;
+ if (type < APP_EVENT_LOW_MEMORY || type > APP_EVENT_REGION_FORMAT_CHANGED)
+ return watch_app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
+
+ EINA_LIST_FOREACH_SAFE(handler_list[type], l_itr, l_next, handler) {
+ if (handler == event_handler) {
+ free(handler);
+ handler_list[type] = eina_list_remove_list(handler_list[type], l_itr);
+
+ if (watch_core_initialized
+ && type == APP_EVENT_LOW_BATTERY
+ && eina_list_count(handler_list[type]) == 0)
+ watch_core_set_event_callback(WATCH_CORE_EVENT_LOW_BATTERY, NULL, NULL);
+
+ return APP_ERROR_NONE;
+ }
+ }
+
+ return watch_app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, "cannot find such handler");
+}
+
+EXPORT_API int watch_time_get_current_time(watch_time_h* watch_time)
+{
+ if (watch_time == NULL)
+ return watch_app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
+
+ struct watch_time_s *time_info;
+
+ time_info = calloc(1, sizeof(struct watch_time_s));
+ if (time_info == NULL)
+ return watch_app_error(APP_ERROR_OUT_OF_MEMORY, __FUNCTION__, "failed to create a handle");
+
+ watch_core_get_timeinfo(time_info);
+
+ *watch_time = (struct _watch_time_s *)time_info;
+
+ return APP_ERROR_NONE;
+}
+
+EXPORT_API int watch_time_delete(watch_time_h watch_time)
+{
+ 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 (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 (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 (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 (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 (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 (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 (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 (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 (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)
+{
+ if (watch_time == NULL || utc_time == NULL)
+ return watch_app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
+
+ time_t 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 (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 (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_app_get_elm_win(Evas_Object **win)
+{
+ Evas_Object *ret_win;
+
+ if (win == NULL)
+ return watch_app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
+
+ ret_win = elm_win_add(NULL, NULL, ELM_WIN_BASIC);
+ if (ret_win == NULL)
+ return watch_app_error(APP_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL);
+
+ *win = ret_win;
+ return APP_ERROR_NONE;
+}
+
--- /dev/null
+/*
+ * Copyright (c) 2015 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>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int watch_app_error(app_error_e error, const char* function, const char *description);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __WATCH_APP_PRIVATE_H__ */