From 39b586294a0c637d8f33b2b25b7c7e07ad9348f1 Mon Sep 17 00:00:00 2001
From: Daehyeon Jung
+ *
+ *
+ *
+ *
+ * Callback
+ * Description
+ *
+ *
+ * watch_app_create_cb()
+ * 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.
+ *
+ *
+ *
+ * watch_app_control_cb()
+ * 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.
+ *
+ *
+ *
+ * watch_app_resume_cb()
+ * 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.
+ *
+ *
+ *
+ * watch_app_pause_cb()
+ * 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.
+ *
+ *
+ *
+ * watch_app_terminate_cb()
+ * 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.
+ *
+ *
+ *
+ * watch_app_ambient_changed_cb()
+ * 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.
+ *
+ *
+ * watch_app_time_tick_cb()
+ * 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.
+ *
+ *
+ * watch_app_ambient_tick_cb()
+ * 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.
+ *
w=2Ij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&9)CUxhS{{t)xYFPjP literal 0 HcmV?d00001 diff --git a/include/appcore-watch.h b/include/appcore-watch.h new file mode 100755 index 0000000..75d8e59 --- /dev/null +++ b/include/appcore-watch.h @@ -0,0 +1,95 @@ +/* + * 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 +#include + +#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__ */ diff --git a/include/watch_app.h b/include/watch_app.h new file mode 100755 index 0000000..d7e8b88 --- /dev/null +++ b/include/watch_app.h @@ -0,0 +1,451 @@ +/* + * 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 +#include +#include +#include + +#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__ */ diff --git a/include/watch_app_efl.h b/include/watch_app_efl.h new file mode 100644 index 0000000..f4863a6 --- /dev/null +++ b/include/watch_app_efl.h @@ -0,0 +1,55 @@ +/* + * 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 + +#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 diff --git a/packaging/appcore-watch.spec b/packaging/appcore-watch.spec new file mode 100644 index 0000000..a59d439 --- /dev/null +++ b/packaging/appcore-watch.spec @@ -0,0 +1,88 @@ +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 + diff --git a/src/appcore-watch-i18n.c b/src/appcore-watch-i18n.c new file mode 100755 index 0000000..9f2c83e --- /dev/null +++ b/src/appcore-watch-i18n.c @@ -0,0 +1,180 @@ +/* + * 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#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); +} + diff --git a/src/appcore-watch-internal.h b/src/appcore-watch-internal.h new file mode 100644 index 0000000..3ae04ea --- /dev/null +++ b/src/appcore-watch-internal.h @@ -0,0 +1,25 @@ +/* + * 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__ */ diff --git a/src/appcore-watch-log.h b/src/appcore-watch-log.h new file mode 100755 index 0000000..49f0d8f --- /dev/null +++ b/src/appcore-watch-log.h @@ -0,0 +1,81 @@ +/* + * 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 + +#define _E(fmt, arg...) LOGE(fmt, ##arg) +#define _I(fmt, arg...) LOGI(fmt, ##arg) +#define _D(fmt, arg...) LOGD(fmt, ##arg) +#define _W(fmt, arg...) LOGW(fmt, ##arg) + +#ifndef EXPORT_API +#define EXPORT_API __attribute__ ((visibility("default"))) +#endif + +#ifndef _E +#define _E(fmt, arg...) LOGE(fmt, ##arg) +#endif + +#ifndef _I +#define _I(...) LOGI(__VA_ARGS__) +#endif + +#ifndef _D +#define _D(...) LOGD(__VA_ARGS__) +#endif + +#ifndef _W +#define _W(...) LOGW(__VA_ARGS__) +#endif + +#define _warn_if(expr, fmt, arg...) do { \ + if (expr) { \ + _ERR(fmt, ##arg); \ + } \ + } while (0) + +#define _ret_if(expr) do { \ + if (expr) { \ + return; \ + } \ + } while (0) + +#define _retv_if(expr, val) do { \ + if (expr) { \ + return (val); \ + } \ + } while (0) + +#define _retm_if(expr, fmt, arg...) do { \ + if (expr) { \ + _ERR(fmt, ##arg); \ + return; \ + } \ + } while (0) + +#define _retvm_if(expr, val, fmt, arg...) do { \ + if (expr) { \ + _ERR(fmt, ##arg); \ + return (val); \ + } \ + } while (0) + + +#endif //__APPFW_WATCH_LOG_H_ diff --git a/src/appcore-watch-signal.c b/src/appcore-watch-signal.c new file mode 100755 index 0000000..0f4eea4 --- /dev/null +++ b/src/appcore-watch-signal.c @@ -0,0 +1,185 @@ +/* + * 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 +#include +#include +#include +#include +#include + +#include + +#include +#include + +#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; +} + diff --git a/src/appcore-watch-signal.h b/src/appcore-watch-signal.h new file mode 100755 index 0000000..6a35b47 --- /dev/null +++ b/src/appcore-watch-signal.h @@ -0,0 +1,46 @@ +/* + * 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 + +#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__ */ diff --git a/src/appcore-watch.c b/src/appcore-watch.c new file mode 100755 index 0000000..a10cb41 --- /dev/null +++ b/src/appcore-watch.c @@ -0,0 +1,1109 @@ +/* + * 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 +#include +#include +#include +#include +#include +#include + +#include + +#include +#include + +#include +#include +#include +#include +#include + + +#include + +#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 +#include +#include +#include +#include +#include + +#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); +} + diff --git a/src/watch_app_error.c b/src/watch_app_error.c new file mode 100755 index 0000000..1da14fe --- /dev/null +++ b/src/watch_app_error.c @@ -0,0 +1,71 @@ +/* + * 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 +#include + +#include +#include + +#include "watch_app_private.h" + +#ifdef LOG_TAG +#undef LOG_TAG +#endif + +#define LOG_TAG "CAPI_APPFW_APPLICATION" + +static const char* watch_app_error_to_string(app_error_e error) +{ + switch (error) + { + case APP_ERROR_NONE: + return "NONE"; + + case APP_ERROR_INVALID_PARAMETER: + return "INVALID_PARAMETER"; + + case APP_ERROR_OUT_OF_MEMORY: + return "OUT_OF_MEMORY"; + + case APP_ERROR_INVALID_CONTEXT: + return "INVALID_CONTEXT"; + + case APP_ERROR_NO_SUCH_FILE: + return "NO_SUCH_FILE"; + + case APP_ERROR_ALREADY_RUNNING: + return "ALREADY_RUNNING"; + + default : + return "UNKNOWN"; + } +} + +int watch_app_error(app_error_e error, const char* function, const char *description) +{ + if (description) + { + LOGE("[%s] %s(0x%08x) : %s", function, watch_app_error_to_string(error), error, description); + } + else + { + LOGE("[%s] %s(0x%08x)", function, watch_app_error_to_string(error), error); + } + + return error; +} diff --git a/src/watch_app_main.c b/src/watch_app_main.c new file mode 100755 index 0000000..140fc74 --- /dev/null +++ b/src/watch_app_main.c @@ -0,0 +1,628 @@ +/* + * 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 + +#include +#include +#include +#include +#include + +#include +#include +#include + +#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; +} + diff --git a/src/watch_app_private.h b/src/watch_app_private.h new file mode 100755 index 0000000..65a6c04 --- /dev/null +++ b/src/watch_app_private.h @@ -0,0 +1,34 @@ +/* + * 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 +#include + +#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__ */ -- 2.7.4