appcore-widget : initial commit 63/40863/2 accepted/tizen/mobile/20150611.064405 submit/tizen/20150611.004031 submit/tizen_mobile/20150611.052908
authorJiwoong Im <jiwoong.im@samsung.com>
Wed, 10 Jun 2015 02:39:55 +0000 (11:39 +0900)
committerJiwoong Im <jiwoong.im@samsung.com>
Wed, 10 Jun 2015 03:57:27 +0000 (12:57 +0900)
The capi-appcore-widget provides functions for handling Tizen widget
application state changes or system events.
Tizen widget application can be shown in the home screen.
This APIs support making multiple widget instances per an application.

This API provides interfaces for the following categories:
- Starting or exiting the main event loop
- Registering callbacks for application state change events
- Registering callbacks for basic system events
- Registering callbacks for instance state change events

Change-Id: I9400f117c5c4c1e2efb0214caf41798691c308cb
Signed-off-by: Jiwoong Im <jiwoong.im@samsung.com>
17 files changed:
AUTHORS [new file with mode: 0644]
CMakeLists.txt [new file with mode: 0644]
LICENSE [new file with mode: 0644]
appcore-widget.manifest [new file with mode: 0644]
capi-appfw-widget-application.pc [new file with mode: 0644]
doc/appcore-widget_doc.h [new file with mode: 0755]
doc/images/widget_app_lifecycle.png [new file with mode: 0755]
doc/images/widget_obj_lifecycle.png [new file with mode: 0755]
include/widget_app.h [new file with mode: 0755]
include/widget_app_efl.h [new file with mode: 0644]
include/widget_app_internal.h [new file with mode: 0644]
packaging/appcore-widget.spec [new file with mode: 0644]
src/widget-i18n.c [new file with mode: 0755]
src/widget-log.h [new file with mode: 0755]
src/widget-private.h [new file with mode: 0644]
src/widget_app.c [new file with mode: 0755]
src/widget_error.c [new file with mode: 0755]

diff --git a/AUTHORS b/AUTHORS
new file mode 100644 (file)
index 0000000..12534b4
--- /dev/null
+++ b/AUTHORS
@@ -0,0 +1 @@
+Junghoon Park <jh9216.park@samsung.com>
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644 (file)
index 0000000..86cbc99
--- /dev/null
@@ -0,0 +1,59 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+PROJECT(appcore-widget C)
+
+SET(PREFIX ${CMAKE_INSTALL_PREFIX})
+SET(EXEC_PREFIX "\${prefix}")
+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-widget Library
+# ------------------------------
+SET(APPCORE_WIDGET "capi-appfw-widget-application")
+SET(SRCS_widget
+               src/widget-i18n.c
+               src/widget_app.c
+               src/widget_error.c
+               )
+SET(HEADERS_widget widget_app.h widget_app_efl.h widget_app_internal.h)
+
+INCLUDE(FindPkgConfig)
+pkg_check_modules(pkg_widget REQUIRED
+               aul
+               dlog
+               capi-appfw-app-control
+               capi-appfw-app-common
+               vconf
+               elementary
+               vconf-internal-keys
+               widget_service
+               widget_provider_app
+               widget
+               capi-system-info
+               )
+FOREACH(flag ${pkg_widget_CFLAGS})
+       SET(EXTRA_CFLAGS_widget "${EXTRA_CFLAGS_widget} ${flag}")
+ENDFOREACH(flag)
+
+ADD_LIBRARY(${APPCORE_WIDGET} SHARED ${SRCS_widget})
+SET_TARGET_PROPERTIES(${APPCORE_WIDGET} PROPERTIES SOVERSION ${VERSION_MAJOR})
+SET_TARGET_PROPERTIES(${APPCORE_WIDGET} PROPERTIES VERSION ${VERSION})
+SET_TARGET_PROPERTIES(${APPCORE_WIDGET} PROPERTIES COMPILE_FLAGS ${EXTRA_CFLAGS_widget})
+TARGET_LINK_LIBRARIES(${APPCORE_WIDGET} ${pkg_widget_LDFLAGS} "-ldl")
+
+INSTALL(TARGETS ${APPCORE_WIDGET} DESTINATION ${LIB_INSTALL_DIR} COMPONENT RuntimeLibraries)
+INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${APPCORE_WIDGET}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
+FOREACH(hfile ${HEADERS_widget})
+       INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/${hfile} DESTINATION include/appfw)
+ENDFOREACH(hfile)
diff --git a/LICENSE b/LICENSE
new file mode 100644 (file)
index 0000000..9c13a9b
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,204 @@
+Copyright (c) 2000 - 2011 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
diff --git a/appcore-widget.manifest b/appcore-widget.manifest
new file mode 100644 (file)
index 0000000..97e8c31
--- /dev/null
@@ -0,0 +1,5 @@
+<manifest>
+       <request>
+               <domain name="_"/>
+       </request>
+</manifest>
diff --git a/capi-appfw-widget-application.pc b/capi-appfw-widget-application.pc
new file mode 100644 (file)
index 0000000..e7ded40
--- /dev/null
@@ -0,0 +1,13 @@
+# Package Information for pkg-config
+
+prefix=@PREFIX@
+exec_prefix=@EXEC_PREFIX@
+libdir=@LIB_INSTALL_DIR@
+includedir=@INCLUDEDIR@
+
+Name: capi-appfw-widget-application
+Description: widget application library
+Version: 1.1
+Requires: aul dlog elementary capi-appfw-app-control capi-appfw-app-common widget_service widget_provider_app widget
+Libs: -L${libdir} -lcapi-appfw-widget-application
+Cflags: -I${includedir} -I${includedir}/appfw
diff --git a/doc/appcore-widget_doc.h b/doc/appcore-widget_doc.h
new file mode 100755 (executable)
index 0000000..a6833ee
--- /dev/null
@@ -0,0 +1,126 @@
+/*
+ * 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_WIDGET_FRAMEWORK
+ * @defgroup CAPI_WIDGET_APP_MODULE Widget Application
+ * @brief Widget application API
+ *
+ * @section CAPI_WIDGET_APP_MODULE_HEADER Required Header
+ *   \#include <widget_app.h>
+ *   \#include <widget_app_efl.h>
+ * @section CAPI_WIDGET_APP_MODULE_OVERVIEW Overview
+ * The @ref CAPI_WIDGET_APP_MODULE API provides functions for handling Tizen widget application state changes or system events. Tizen widget application can be shown in the home screen.
+ * This APIs support making multiple widget instances per an application.
+ *
+ * This API provides interfaces for the following categories:
+ * - Starting or exiting the main event loop
+ * - Registering callbacks for application state change events
+ * - Registering callbacks for basic system events
+ * - Registering callbacks for instance state change events
+ *
+ * @subsection CAPI_WIDGET_APP_MODULE_STATE_CHANGE_EVENT Registering Callbacks for Application State Change Events
+ * As for Tizen widget application states, it is very simple and somewhat similer to Tizen service application states.
+ *
+ * <p>
+ * <table>
+ * <tr>
+ *   <th> Callback </th>
+ *   <th> Description </th>
+ * </tr>
+ * <tr>
+ *   <td>widget_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.
+ *   Please make sure that you should make a class handle and return it. It will be used when the event for creating widget instance is received.
+ *   You can initialize shared resources for widget instances in this callback function as well.
+ * </td>
+ * </tr>
+ * <tr>
+ *  <td> widget_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>
+ * </table>
+ * </p>
+ *
+ * Please refer to the following state diagram to see the possible transitions and callbacks that are called while transition.
+ * @image html widget_app_lifecycle.png "Widget Application States"
+ *
+ * @subsection CAPI_WIDGET_APP_MODULE_SYSTEM_EVENT Registering Callbacks for System Events
+ * Tizen widget applications can receive system events with widget_app_add_event_handler() api.
+ * The type of system events that can be received are same as Tizen UI applications except for APP_EVENT_DEVICE_ORIENTATION_CHANGED.
+ * See @ref CAPI_APPLICATION_MODULE.
+ * The event for APP_EVENT_DEVICE_ORIENTATION_CHANGED is not supported in this module.
+ *
+ * @subsection CAPI_WIDGET_APP_INSTNACE_STATE_CHANGE_EVENT Registering callbacks for instance state change events
+ * As for Tizen widget instance states, it is somewhat similer to Tizen application states.
+ *
+ * <p>
+ * <table>
+ * <tr>
+ *   <th> Callback </th>
+ *   <th> Description </th>
+ * </tr>
+ * <tr>
+ *   <td> widget_obj_create_cb() </td>
+ *   <td> Called after widget instance is created.
+ *    In this callback, you can initialize resources for this instance.
+ *    If parameter 'content' is not NULL, You should restore the pervious status.
+ *   </td>
+ * </tr>
+ * <tr>
+ *  <td> widget_obj_destroy_cb() </td>
+ *  <td> Called before widget instance is destroyed.
+ *   In this callback, you can finalize resources for this instance.
+ *  </td>
+ * </tr>
+ * <tr>
+ *  <td> widget_obj_pause_cb() </td>
+ *  <td> Called when the widget is invisible.
+ *   The paused instance may be destroyed by framework
+ *  </td>
+ * </tr>
+ * <tr>
+ *  <td> widget_obj_resume_cb() </td>
+ *  <td> Called when the widget is visible.
+ *   The callback function is called when the widget is visible.
+ *  </td>
+ * </tr>
+ * <tr>
+ *  <td> widget_obj_resize_cb() </td>
+ *  <td> Called before the widget size is changed.
+ *   The callback function is called before the widget size is changed.
+ *  </td>
+ * </tr>
+ * <tr>
+ *  <td> widget_obj_update_cb() </td>
+ *  <td> Called when the event for updating widget is received.
+ *   The callback function is called when the event for updating widget is received.
+ *  </td>
+ * </tr>
+ * </table>
+ * </p>
+ *
+ * Please refer to the following state diagram to see the possible transitions and callbacks that are called while transition.
+ * @image html widget_obj_lifecycle.png "Widget Instance States"
+ *
+ *
+ *
+ */
diff --git a/doc/images/widget_app_lifecycle.png b/doc/images/widget_app_lifecycle.png
new file mode 100755 (executable)
index 0000000..13d394c
Binary files /dev/null and b/doc/images/widget_app_lifecycle.png differ
diff --git a/doc/images/widget_obj_lifecycle.png b/doc/images/widget_obj_lifecycle.png
new file mode 100755 (executable)
index 0000000..71113aa
Binary files /dev/null and b/doc/images/widget_obj_lifecycle.png differ
diff --git a/include/widget_app.h b/include/widget_app.h
new file mode 100755 (executable)
index 0000000..49180e1
--- /dev/null
@@ -0,0 +1,424 @@
+/*
+ * 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_WIDGET_APP_H__
+#define __TIZEN_APPFW_WIDGET_APP_H__
+
+#include <tizen.h>
+#include <app_control.h>
+#include <app_common.h>
+#include <bundle.h>
+#include <widget_errno.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @addtogroup CAPI_WIDGET_APP_MODULE
+ * @{
+ */
+
+/**
+ * @brief Destroy type of widget instance
+ * @since_tizen 2.3.1
+ */
+typedef enum widget_app_destroy_type {
+       WIDGET_APP_DESTROY_TYPE_DEFAULT = 0x00,   /**< Deleted */
+       WIDGET_APP_DESTROY_TYPE_UPGRADE = 0x01,   /**< Deleted for upgrading */
+       WIDGET_APP_DESTROY_TYPE_UNINSTALL = 0x02, /**< Deleted by uninstalling */
+       WIDGET_APP_DESTROY_TYPE_TERMINATE = 0x03, /**< Deleted for reboot device */
+       WIDGET_APP_DESTROY_TYPE_FAULT = 0x04,     /**< Deleted by system-fault */
+       WIDGET_APP_DESTROY_TYPE_TEMPORARY = 0x05, /**< Temporarly deleted, will be created again */
+       WIDGET_APP_DESTROY_TYPE_UNKNOWN = 0x06    /**< Undefined reason */
+} widget_app_destroy_type_e; /**< Delete type */
+
+/**
+ * @brief The handle for widget class.
+ * @since_tizen 2.3.1
+ */
+typedef struct _widget_class* widget_class_h;
+
+/**
+ * @brief The handle for widget context
+ * @since_tizen 2.3.1
+ */
+typedef struct _widget_context* widget_context_h;
+
+/**
+ * @brief Called when the widget instance starts.
+ * @since_tizen 2.3.1
+ *
+ * @details The callback function is called after widget instance is created.
+ *          In this callback, you can initialize resources for this instance.
+ *
+ * @param[in] context The context of widget instance.
+ * @param[in] content The data set for the previous status
+ * @param[in] w The pixel value for widget width
+ * @param[in] h The pixel value for widget height
+ *
+ * @return #WIDGET_ERROR_NONE on success,
+ *         otherwise an error code (see WIDGET_ERROR_XXX) on failure
+ */
+typedef int (*widget_instance_create_cb)(widget_context_h context, bundle *content, int w, int h);
+
+/**
+ * @brief Called before the widget instance is destroyed.
+ * @since_tizen 2.3.1
+ *
+ * @details The callback function is called before widget instance is destroyed.
+ *          In this callback, you can finalize resources for this instance.
+ *          If reason is not #WIDGET_APP_DESTROY_TYPE_DEFAULT, It should store the current status by using incoming bundle.
+ *
+ * @param[in] context The context of widget instance.
+ * @param[in] reason The reason for destruction
+ * @param[in,out] content The data set to save
+ * @remark Note that the parameter 'content' is used to save the status of the widget instance.
+ *         As a input parameter, content contains the saved status of the widget instance.
+ *         You can fill the content parameter with the current status in this callback,
+ *         then the framework will save the content by receiving it as a output parameter.
+ *         Consequently, you should not use widget_app_context_set_content_info() api in this callback.
+ *         The content will be overwritten after this callback returns with the 'content' parameter.
+ *
+ * @return #WIDGET_ERROR_NONE on success,
+ *         otherwise an error code (see WIDGET_ERROR_XXX) on failure
+ */
+typedef int (*widget_instance_destroy_cb)(widget_context_h context, widget_app_destroy_type_e reason, bundle *content);
+
+/**
+ * @brief Called when the widget is invisible.
+ * @since_tizen 2.3.1
+ *
+ * @details The callback function is called when the widget is invisible.
+ *          The paused instance may be destroyed by framework
+ *
+ * @param[in] context The context of widget instance.
+ * @return #WIDGET_ERROR_NONE on success,
+ *         otherwise an error code (see WIDGET_ERROR_XXX) on failure
+ */
+typedef int (*widget_instance_pause_cb)(widget_context_h context);
+
+/**
+ * @brief Called when the widget is visible.
+ * @since_tizen 2.3.1
+ *
+ * @details The callback function is called when the widget is visible.
+ *
+ * @param[in] context The context of widget instance.
+ * @return #WIDGET_ERROR_NONE on success,
+ *         otherwise an error code (see WIDGET_ERROR_XXX) on failure
+ */
+typedef int (*widget_instance_resume_cb)(widget_context_h context);
+
+/**
+ * @brief Called before the widget size is changed.
+ * @since_tizen 2.3.1
+ *
+ * @details The callback function is called before the widget size is changed.
+ *
+ * @param[in] context The context of widget instance.
+ * @param[in] w The pixel value for widget width
+ * @param[in] h The pixel value for widget height
+ * @return #WIDGET_ERROR_NONE on success,
+ *         otherwise an error code (see WIDGET_ERROR_XXX) on failure
+ */
+typedef int (*widget_instance_resize_cb)(widget_context_h context, int w, int h);
+
+/**
+ * @brief Called when the event for updating widget is received.
+ * @since_tizen 2.3.1
+ *
+ * @details The callback function is called when the event for updating widget is received.
+ *
+ * @param[in] context The context of widget instance.
+ * @param[in] content The data set for updating this widget. It will be provided by requester.
+ *                    Requester can use widget_service_trigger_update().
+ * @param[in] force Although the widget is paused, if it is TRUE, the widget can be updated.
+ * @return #WIDGET_ERROR_NONE on success,
+ *         otherwise an error code (see WIDGET_ERROR_XXX) on failure
+ * @see widget_service_trigger_update
+ */
+typedef int (*widget_instance_update_cb)(widget_context_h context, bundle *content, int force);
+
+/**
+ * @brief The structure for lifecycle of a widget instance
+ * @since_tizen 2.3.1
+ */
+typedef struct
+{
+       widget_instance_create_cb create; /**< The callback function is called after widget instance is created. */
+       widget_instance_destroy_cb destroy; /**< The callback function is called before widget instance is destroyed. */
+       widget_instance_pause_cb pause; /**< The callback function is called when the widget is invisible. */
+       widget_instance_resume_cb resume; /**< The callback function is called when the widget is visible. */
+       widget_instance_resize_cb resize; /**< The callback function is called before the widget size is changed. */
+       widget_instance_update_cb update; /**< The callback function is called when the event for updating widget is received. */
+} widget_instance_lifecycle_callback_s;
+
+/**
+ * @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 resources which can be shared among widget instances.
+ *          This function should return the handle for widget class so that it will be used for making instances of widget.
+ *
+ * @param[in] user_data The user data passed from the callback registration function
+ * @return The object of widget class
+ * @see widget_app_main()
+ * @code
+ *
+ * static widget_class_h __widget_app_created(void *user_data)
+ * {
+ *     widget_instance_lifecycle_callback_s callback = { .... };
+ *
+ *     return widget_app_class_create(callback);
+ * }
+ *
+ * @endcode
+ */
+typedef widget_class_h (*widget_app_create_cb)(void *user_data);
+
+/**
+ * @brief Called when the application's main loop exits.
+ * @details This callback function is called once after the main loop of the application exits.
+ *          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 widget_app_main()
+ */
+typedef void (*widget_app_terminate_cb)(void *user_data);
+
+/**
+ * @brief The structure for lifecycle of a widget application
+ * @since_tizen 2.3.1
+ */
+typedef struct
+{
+       widget_app_create_cb create; /**< The callback function is called before the main loop of the application starts. */
+       widget_app_terminate_cb terminate; /**< This callback function is called once after the main loop of the application exits. */
+} widget_app_lifecycle_callback_s;
+
+/**
+ * @brief Called for each widget context
+ * @since_tizen 2.3.1
+ *
+ * @details This function will be called in the function of widget_app_foreach_context repeatedly.
+ *
+ * @param[in] context The context for widget instance
+ * @param[in] data The data for caller
+ * @return true to continue with the next iteration of the loop,
+ *         otherwise false to break out of the loop.
+ * @see widget_app_foreach_context
+ */
+typedef bool (*widget_context_cb)(widget_context_h context, void *data);
+
+/**
+ * @brief Runs the main loop of the application until widget_app_exit() is called.
+ * @since_tizen 2.3.1
+ *
+ * @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 #WIDGET_ERROR_NONE Successful
+ * @retval #WIDGET_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #WIDGET_ERROR_NOT_SUPPORTED Not supported
+ * @retval #WIDGET_ERROR_FAULT Unrecoverable error
+ * @see widget_app_exit
+ */
+int widget_app_main(int argc, char **argv, widget_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 widget_app_terminate_cb() is invoked.
+ * @since_tizen 2.3.1
+ *
+ * @return @c 0 on success,
+ *         otherwise a negative error value.
+ * @retval #WIDGET_ERROR_NOT_SUPPORTED Not supported
+ * @retval #WIDGET_ERROR_FAULT Unrecoverable error
+ * @see widget_app_main
+ * @see widget_app_terminate_cb
+ */
+int widget_app_exit(void);
+
+/**
+ * @brief Finishes context for the widget instance
+ * @since_tizen 2.3.1
+ *
+ * @param[in] context The context for widget instance
+ *
+ * @return @c 0 on success, otherwise a negative error value.
+ * @retval #WIDGET_ERROR_NONE Successfull
+ * @retval #WIDGET_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #WIDGET_ERROR_NOT_SUPPORTED Not supported
+ * @retval #WIDGET_ERROR_FAULT Unrecoverable error
+ */
+int widget_app_terminate_context(widget_context_h context);
+
+/**
+ * @brief Retrieves all widget contexts in this application
+ * @since_tizen 2.3.1
+ *
+ * @param[in] callback The iteration callback function
+ * @param[in] data The data for the callback function
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #WIDGET_ERROR_NONE Successfull
+ * @retval #WIDGET_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #WIDGET_ERROR_CANCELED The iteration is canceled
+ * @retval #WIDGET_ERROR_NOT_SUPPORTED Not supported
+ * @retval #WIDGET_ERROR_FAULT Unrecoverable error
+ * @see widget_app_foreach_context
+ */
+int widget_app_foreach_context(widget_context_cb callback, void *data);
+
+/**
+ * @brief Adds the system event handler
+ * @since_tizen 2.3.1
+ *
+ * @param[out] event_handler The event handler
+ * @param[in] event_type The system event type. APP_EVENT_DEVICE_ORIENTATION_CHANGED is not supported
+ * @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 #WIDGET_ERROR_NONE Successfull
+ * @retval #WIDGET_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #WIDGET_ERROR_OUT_OF_MEMORY Out of memory
+ * @retval #WIDGET_ERROR_NOT_SUPPORTED Not supported
+ * @retval #WIDGET_ERROR_FAULT Unrecoverable error
+ * @see app_event_type_e
+ * @see app_event_cb
+ * @see watch_app_remove_event_handler
+ */
+int widget_app_add_event_handler(app_event_handler_h *event_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 #WIDGET_ERROR_NONE Successfull
+ * @retval #WIDGET_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #WIDGET_ERROR_NOT_SUPPORTED Not supported
+ * @retval #WIDGET_ERROR_FAULT Unrecoverable error
+ * @see watch_app_add_event_handler
+ */
+int widget_app_remove_event_handler(app_event_handler_h event_handler);
+
+/**
+ * @brief Gets a widget instance id
+ * @since_tizen 2.3.1
+ *
+ * @param[in] context The context for widget instance
+ *
+ * @return Widget ID on success, otherwise NULL
+ *         You can get the returned value using get_last_result()
+ * @retval #WIDGET_ERROR_NOT_SUPPORTED Not supported
+ * @retval #WIDGET_ERROR_FAULT Unrecoverable error
+ * @remark You must not free returned Widget ID
+ * @see get_last_result
+ */
+const char* widget_app_get_id(widget_context_h context);
+
+/**
+ * @brief Makes a class for widget instances.
+ * @since_tizen 2.3.1
+ *
+ * @param[in] callback The set of lifecycle callbacks
+ * @return The handle of class on success, otherwise NULL
+ *         You can get the returned value using get_last_result()
+ * @retval #WIDGET_ERROR_NOT_SUPPORTED Not supported
+ * @see get_last_result
+ */
+widget_class_h widget_app_class_create(widget_instance_lifecycle_callback_s callback);
+
+/**
+ * @brief Sets a tag in the context
+ * @since_tizen 2.3.1
+ *
+ * @param[in] context The context for widget instance
+ * @param[in] tag The value to save
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #WIDGET_ERROR_NOT_SUPPORTED Not supported
+ * @retval #WIDGET_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #WIDGET_ERROR_FAULT Unrecoverable error
+ */
+int widget_app_context_set_tag(widget_context_h context, void *tag);
+
+/**
+ * @brief Gets the tag in the context
+ * @since_tizen 2.3.1
+ *
+ * @param[in] context The context for widget instance
+ * @param[out] tag The value to get
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #WIDGET_ERROR_NOT_SUPPORTED Not supported
+ * @retval #WIDGET_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #WIDGET_ERROR_FAULT Unrecoverable error
+ */
+int widget_app_context_get_tag(widget_context_h context, void **tag);
+
+/**
+ * @brief Sets the content info to the widget
+ * @since_tizen 2.3.1
+ * @param[in] context The context for widget instance
+ * @param[in] content_info The data set to save
+ * @return #WIDGET_ERROR_NONE on success,
+ *          otherwise an error code (see WIDGET_ERROR_XXX) on failure
+ * @retval #WIDGET_ERROR_INVALID_PARAMETER Invalid argument
+ * @retval #WIDGET_ERROR_NOT_SUPPORTED Not supported
+ * @retval #WIDGET_ERROR_OUT_OF_MEMORY Out of memory
+ * @retval #WIDGET_ERROR_FAULT Unrecoverable error
+ * @retval #WIDGET_ERROR_NONE Successfully sent
+ */
+int widget_app_context_set_content_info(widget_context_h context, bundle *content_info);
+
+/**
+ * @brief Sends the title to the widget
+ * @since_tizen 2.3.1
+ * @param[in] context The context for widget instance
+ * @param[in] title When an accessibility mode is turned on, this string will be read.
+ * @return #WIDGET_ERROR_NONE on success,
+ *          otherwise an error code (see WIDGET_ERROR_XXX) on failure
+ * @retval #WIDGET_ERROR_INVALID_PARAMETER Invalid argument
+ * @retval #WIDGET_ERROR_NOT_SUPPORTED Not supported
+ * @retval #WIDGET_ERROR_OUT_OF_MEMORY Out of memory
+ * @retval #WIDGET_ERROR_FAULT Unrecoverable error
+ * @retval #WIDGET_ERROR_NONE Successfully sent
+ */
+int widget_app_context_set_title(widget_context_h context, const char *title);
+
+/**
+ * @}
+ */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __TIZEN_APPFW_WIDGET_APP_H__ */
diff --git a/include/widget_app_efl.h b/include/widget_app_efl.h
new file mode 100644 (file)
index 0000000..4bd1765
--- /dev/null
@@ -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_WIDGET_APP_EFL_H__
+#define __TIZEN_APPFW_WIDGET_APP_EFL_H__
+
+#include <widget_app.h>
+#include <Evas.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @addtogroup CAPI_WIDGET_APP_MODULE
+ * @{
+ */
+
+/**
+ * @brief Gets a evas object for the widget
+ * @since_tizen 2.3.1
+ *
+ * @param[in] context The context for widget instance
+ * @param[out] win Evas object for window
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #WIDGET_ERROR_NONE Successfull
+ * @retval #WIDGET_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #WIDGET_ERROR_FAULT Failed to make evas object
+ * @retval #WIDGET_ERROR_NOT_SUPPORTED Not supported
+ */
+int widget_app_get_elm_win(widget_context_h context, Evas_Object **win);
+
+/**
+ * @}
+ */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/include/widget_app_internal.h b/include/widget_app_internal.h
new file mode 100644 (file)
index 0000000..968f584
--- /dev/null
@@ -0,0 +1,74 @@
+/*
+ * 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_WIDGET_APP_INTERNAL_H__
+#define __TIZEN_APPFW_WIDGET_APP_INTERNAL_H__
+
+#include <widget_app.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * For in-house applications
+ *
+ */
+
+typedef struct
+{
+       struct __pointer
+       {
+               double x;
+               double y;
+               int down;
+       } pointer;
+
+       struct __part
+       {
+               double sx;
+               double sy;
+               double ex;
+               double ey;
+       } part;
+
+} widget_obj_event_info_s;
+
+typedef int (*widget_instance_text_signal_cb)(widget_context_h context, const char *signal_name,
+        const char *source, widget_obj_event_info_s *info);
+
+typedef struct _widget_obj_private_ops
+{
+       widget_instance_text_signal_cb text_signal;
+} widget_obj_private_ops_s;
+
+typedef struct _widget_class_factory_full widget_class_factory_full_s;
+typedef const widget_class_factory_full_s* (*widget_class_factory_override_text_signal)(widget_instance_text_signal_cb op);
+
+typedef widget_class_h (*_widget_class_factory_operation_make)(widget_instance_lifecycle_callback_s callback);
+
+struct _widget_class_factory_full
+{
+       widget_class_factory_override_text_signal override_text_signal;
+};
+
+const widget_class_factory_full_s* widget_app_get_class_factory(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/packaging/appcore-widget.spec b/packaging/appcore-widget.spec
new file mode 100644 (file)
index 0000000..e8c6bcf
--- /dev/null
@@ -0,0 +1,70 @@
+Name:       appcore-widget
+Summary:    Widget Application
+Version:    1.0.0.0
+Release:    1
+Group:      Application Framework/Libraries
+License:    Apache-2.0
+Source0:    appcore-widget-%{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(widget_service)
+BuildRequires:  pkgconfig(widget_provider_app)
+BuildRequires:  pkgconfig(capi-system-info)
+BuildRequires:  pkgconfig(widget)
+BuildRequires:  cmake
+
+
+%description
+Widget application
+
+%package -n capi-appfw-widget-application-devel
+Summary:    Widget application
+Group:      Development/Libraries
+Requires:   %{name} = %{version}-%{release}
+%description -n capi-appfw-widget-application-devel
+widget application (development files)
+
+%prep
+%setup -q
+
+%build
+MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'`
+%cmake . -DFULLVER=%{version} -DMAJORVER=${MAJORVER}
+%__make %{?jobs:-j%jobs}
+
+%install
+rm -rf %{buildroot}
+%make_install
+
+mkdir -p %{buildroot}%{_libdir}/pkgconfig
+cp capi-appfw-widget-application.pc %{buildroot}%{_libdir}/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-widget.manifest
+%defattr(-,root,root,-)
+%{_libdir}/libcapi-appfw-widget-application.so
+%{_libdir}/libcapi-appfw-widget-application.so.1
+%{_libdir}/libcapi-appfw-widget-application.so.1.1
+/usr/share/license/%{name}
+
+%files -n capi-appfw-widget-application-devel
+/usr/include/appfw/widget_app.h
+/usr/include/appfw/widget_app_efl.h
+/usr/include/appfw/widget_app_internal.h
+%{_libdir}/pkgconfig/capi-appfw-widget-application.pc
+
diff --git a/src/widget-i18n.c b/src/widget-i18n.c
new file mode 100755 (executable)
index 0000000..84c96aa
--- /dev/null
@@ -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 <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 <fcntl.h>
+
+#include <aul.h>
+#include <vconf.h>
+
+#include "widget-log.h"
+#include "widget-private.h"
+
+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");
+       }
+}
+
+static int __read_proc(const char *path, char *buf, int size)
+{
+       int fd;
+       int ret;
+
+       if (buf == NULL || path == NULL)
+               return -1;
+
+       fd = open(path, O_RDONLY);
+       if (fd < 0)
+               return -1;
+
+       ret = read(fd, buf, size - 1);
+       if (ret <= 0) {
+               close(fd);
+               return -1;
+       } else
+               buf[ret] = 0;
+
+       close(fd);
+
+       return ret;
+}
+
+static char* __proc_get_cmdline()
+{
+#define MAX_CMD_BUFSZ 1024
+
+       char buf[MAX_CMD_BUFSZ];
+       int ret;
+
+       snprintf(buf, sizeof(buf), "/proc/%d/cmdline", getpid());
+       ret = __read_proc(buf, buf, sizeof(buf));
+       if (ret <= 0)
+               return NULL;
+
+       return strdup(buf);
+}
+
+static void __get_dir_name(char *dirname, int maxlen)
+{
+       const char *path = NULL;
+
+       path = aul_get_app_root_path();
+       snprintf(dirname, maxlen, "%s/res/locale", path);
+       free(path);
+}
+
+
+static int __set_i18n(const char *domain)
+{
+       char *r;
+       char dirname[PATH_MAX] = {0, };
+
+       if (domain == NULL) {
+               errno = EINVAL;
+               return -1;
+       }
+
+       __get_dir_name(dirname, PATH_MAX - 1);
+       _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/widget-log.h b/src/widget-log.h
new file mode 100755 (executable)
index 0000000..e8eb56d
--- /dev/null
@@ -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_WIDGET_LOG_H__
+#define __APPFW_WIDGET_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_WIDGET_LOG_H_
diff --git a/src/widget-private.h b/src/widget-private.h
new file mode 100644 (file)
index 0000000..662b734
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+ * 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_WIDGET_PRIVATE_H__
+#define __APPCORE_WIDGET_PRIVATE_H__
+
+#include <widget_app.h>
+#include <app_common.h>
+#include <widget_errno.h>
+
+#define FEATURE_SHELL_APPWIDGET "http://tizen.org/feature/shell.appwidget"
+
+
+int _set_i18n(const char *domainname);
+void _update_lang(void);
+void _update_region(void);
+int widget_app_error(widget_error_e error, const char* function, const char *description);
+
+#endif /* __APPCORE_WIDGET_PRIVATE_H__ */
diff --git a/src/widget_app.c b/src/widget_app.c
new file mode 100755 (executable)
index 0000000..17dd0f2
--- /dev/null
@@ -0,0 +1,1048 @@
+/*
+ * 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 <glib.h>
+#include <glib-object.h>
+#include <app_control.h>
+#include <app_control_internal.h>
+#include <widget.h>
+#include <widget_service.h>
+#include <widget_service_internal.h>
+#include <widget_provider_app.h>
+#include <widget_provider_app_internal.h>
+#include <Elementary.h>
+#include <vconf.h>
+#include <widget_errno.h>
+#include <system_info.h>
+
+#include "widget_app.h"
+#include "widget-log.h"
+#include "widget-private.h"
+#include "widget_app_internal.h"
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+
+#define STR_MAX_BUF 128
+#define LOG_TAG "CAPI_WIDGET_APPLICATION"
+#define K_REASON    "__WC_K_REASON__"
+
+#define ELM_WIN_TIZEN_WIDGET -1
+/* TODO
+ * This definition is intended to prevent the build break.
+ * This should be removed after adding ELM_WIN_TIZEN_WIDGET in Elm_Win_Type.
+ */
+
+#define WIDGET_APP_EVENT_MAX 5
+static GList *handler_list[WIDGET_APP_EVENT_MAX] = {NULL, };
+
+typedef enum _widget_obj_state_e {
+    WC_READY = 0,
+    WC_RUNNING = 1,
+    WC_PAUSED = 2,
+    WC_TERMINATED = 3
+} widget_obj_state_e;
+
+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 _widget_class {
+       widget_instance_lifecycle_callback_s ops;
+       widget_obj_private_ops_s ops_private;
+};
+
+struct _widget_context {
+       char *id;
+       int state;
+       void *tag;
+       widget_instance_lifecycle_callback_s ops;
+       widget_obj_private_ops_s ops_private;
+};
+
+typedef struct _widget_class widget_class_s;
+typedef struct _widget_context widget_context_s;
+
+static widget_app_lifecycle_callback_s *app_ops = NULL;
+static void *app_user_data = NULL;
+static widget_class_factory_full_s factory;
+static widget_class_s *widget_class = NULL;
+static widget_class_s widget_class_tmp;
+static GList *contexts = NULL;
+static int is_init_provider = 0;
+static char *appid = NULL;
+static int is_background = -1;
+
+static gint __comp_by_id(gconstpointer a, gconstpointer b)
+{
+       widget_context_s *wc = (widget_context_s*)a;
+
+       return strcmp(wc->id, (const char*)b);
+}
+
+static void __check_status_for_cgroup(void)
+{
+       GList *iter = g_list_first(contexts);
+
+       while (iter != NULL) {
+               widget_context_s *cxt = (widget_context_s*) iter->data;
+
+               if (cxt->state != WC_PAUSED) {
+                       if (is_background != 0) {
+                               is_background = 0;
+                               _I("enter foreground group");
+                               //TODO: Do something to enter foreground group
+                       }
+                       return;
+               }
+               iter = g_list_next(iter);
+       }
+
+       if (g_list_length(contexts) > 0 && is_background == 0) {
+               is_background = 1;
+               _I("enter background group");
+               //TODO: DO something to enter background group
+       }
+}
+
+static widget_context_s* __find_context_by_id(const char *id)
+{
+       GList* ret = g_list_find_custom(contexts, id, __comp_by_id);
+
+       if ( ret == NULL)
+               return NULL;
+
+       return ret->data;
+}
+
+static int __provider_create_cb(const char *id, const char *content, int w,
+                                int h,
+                                void *data)
+{
+       int ret = WIDGET_ERROR_FAULT;
+       widget_context_s *wc = (widget_context_s*)malloc(sizeof(widget_context_s));
+       if (wc == NULL)
+               return WIDGET_ERROR_OUT_OF_MEMORY;
+
+       wc->id = strdup(id);
+       wc->state = WC_READY;
+       wc->tag = NULL;
+       wc->ops = widget_class->ops;
+       wc->ops_private = widget_class->ops_private;
+       contexts = g_list_append(contexts, wc);
+
+       if (wc->ops.create) {
+               bundle *b = bundle_decode((const bundle_raw*)content, strlen(content));
+               ret = wc->ops.create(wc, b,  w, h);
+               bundle_free(b);
+       }
+       _I("widget obj was created");
+
+       return ret;
+}
+
+static int __provider_resize_cb(const char *id, int w, int h, void *data)
+{
+       int ret = WIDGET_ERROR_FAULT;
+       widget_context_s *cxt = __find_context_by_id(id);
+
+       if (cxt) {
+               if (cxt->ops.resize)
+                       ret = cxt->ops.resize(cxt, w, h);
+               _I("received resizing signal");
+       } else {
+               _E("could not find widget obj : %s", __FUNCTION__);
+       }
+
+       return ret;
+}
+
+static int __provider_destroy_cb(const char *id, widget_destroy_type_e reason,
+                                 void *data)
+{
+       int ret = WIDGET_ERROR_FAULT;
+       widget_context_s *cxt = __find_context_by_id(id);
+
+       if (cxt) {
+               cxt->state = WC_TERMINATED;
+               if (cxt->ops.destroy) {
+                       bundle *b  = bundle_create();
+                       ret = cxt->ops.destroy(cxt,(widget_app_destroy_type_e)reason, b);
+
+                       bundle_raw *raw = NULL;
+                       int len;
+
+                       bundle_encode(b, &raw, &len);
+                       if (raw) {
+                               widget_provider_app_send_extra_info(id, (const char*)raw, NULL);
+                               free(raw);
+                       }
+
+                       bundle_free(b);
+                       contexts = g_list_remove(contexts, cxt);
+
+                       free(cxt->id);
+                       free(cxt);
+               }
+               _I("widget obj was deleted");
+       } else {
+               _E("could not find widget obj : %s", __FUNCTION__);
+       }
+
+       return ret;
+}
+
+static int __provider_update_cb(const char *id, const char *content, int force,
+                                void *data)
+{
+       int ret = WIDGET_ERROR_FAULT;
+       widget_context_s *cxt = __find_context_by_id(id);
+
+       if (cxt) {
+               if (cxt->ops.update) {
+                       bundle *b = bundle_decode((const bundle_raw*)content, strlen(content));
+                       ret = cxt->ops.update(cxt, b, force);
+                       bundle_free(b);
+               }
+               _I("received updating signal");
+       } else {
+               _E("could not find widget obj : %s", __FUNCTION__);
+       }
+
+       return ret;
+}
+
+static int __provider_pause_cb(const char *id, void *data)
+{
+       int ret = WIDGET_ERROR_FAULT;
+       widget_context_s *cxt = __find_context_by_id(id);
+
+       if (cxt) {
+               if (cxt->ops.pause)
+                       ret = cxt->ops.pause(cxt);
+               cxt->state = WC_PAUSED;
+               _I("widget obj was paused");
+       } else {
+               _E("could not find widget obj : %s", __FUNCTION__);
+       }
+
+       __check_status_for_cgroup();
+       return ret;
+}
+
+static int __provider_resume_cb(const char *id, void *data)
+{
+       int ret = WIDGET_ERROR_FAULT;
+       widget_context_s *cxt = __find_context_by_id(id);
+
+       if (cxt) {
+               if (cxt->ops.resume)
+                       ret = cxt->ops.resume(cxt);
+               cxt->state = WC_RUNNING;
+               _I("widget obj was resumed");
+       } else {
+               _E("could not find widget obj : %s", __FUNCTION__);
+       }
+
+       __check_status_for_cgroup();
+       return ret;
+}
+
+static int __provider_text_signal_cb(const char *id, const char *signal_name,
+                                     const char *source, struct widget_event_info *info, void *data)
+{
+       int ret = WIDGET_ERROR_FAULT;
+       widget_context_s *cxt = __find_context_by_id(id);
+
+       if (cxt) {
+               if (cxt->ops_private.text_signal) {
+                       ret = cxt->ops_private.text_signal(cxt, signal_name, source,
+                                                          (widget_obj_event_info_s*)info);
+               }
+               _I("received text signal");
+       } else {
+               _E("could not find widget obj : %s", __FUNCTION__);
+       }
+
+       return ret;
+}
+
+static const widget_class_factory_full_s*
+__widget_class_factory_override_text_signal(widget_instance_text_signal_cb op)
+{
+       widget_class_tmp.ops_private.text_signal = op;
+       return &factory;
+}
+
+static void __free_handler_cb(gpointer data)
+{
+       if (data)
+               free(data);
+}
+
+static void __free_handler_list(void)
+{
+       int i;
+
+       for (i = 0; i < WIDGET_APP_EVENT_MAX; i++) {
+               g_list_free_full(handler_list[i], __free_handler_cb);
+               handler_list[i] = NULL;
+       }
+}
+
+static void __control(bundle *b)
+{
+       app_control_h app_control;
+
+       if (is_init_provider) {
+               _E("already initialized");
+               return;
+       }
+
+       if (app_control_create_event(b, &app_control) != 0) {
+               _E("failed to get the app_control handle");
+               return;
+       }
+
+       char *op = NULL;
+       app_control_get_operation(app_control, &op);
+
+       if (op && strcmp(op, "http://tizen.org/appcontrol/operation/main") == 0) {
+               static struct widget_provider_event_callback cb = {
+                       .create = __provider_create_cb,
+                       .resize = __provider_resize_cb,
+                       .destroy = __provider_destroy_cb,
+
+                       .update = __provider_update_cb,
+                       .text_signal = __provider_text_signal_cb,
+
+                       .pause = __provider_pause_cb,
+                       .resume = __provider_resume_cb,
+
+                       .connected = NULL,
+                       .disconnected = NULL,
+
+                       .data = NULL,
+               };
+
+               if (widget_provider_app_init(app_control, &cb) == 0) {
+                       is_init_provider = 1;
+               }
+       }
+
+       app_control_destroy(app_control);
+       if (op)
+               free(op);
+}
+
+static void __pause_all()
+{
+       GList *iter = g_list_first(contexts);
+
+       while (iter != NULL) {
+               widget_context_s *cxt = (widget_context_s*) iter->data;
+               const char *id = cxt->id;
+
+               switch (cxt->state) {
+               case WC_READY:
+                       __provider_resume_cb(id, NULL);
+                       __provider_pause_cb(id, NULL);
+                       break;
+
+               case WC_RUNNING:
+                       __provider_pause_cb(id, NULL);
+                       break;
+               }
+               iter = g_list_next(iter);
+       }
+}
+
+static int __aul_handler(aul_type type, bundle *b, void *data)
+{
+       switch (type) {
+       case AUL_START:
+               __control(b);
+               break;
+       case AUL_RESUME:
+               break;
+       case AUL_TERMINATE:
+               widget_app_exit();
+               break;
+       default:
+               break;
+       }
+
+       return 0;
+}
+
+static char* __get_domain_name(const char *aid)
+{
+       char *name_token = NULL;
+
+       if (aid == NULL) {
+               _E("appid is NULL");
+               return NULL;
+       }
+
+       // com.vendor.name -> name
+       name_token = strrchr(aid, '.');
+
+       if (name_token == NULL) {
+               _E("appid is invalid");
+               return strdup(aid);
+       }
+
+       name_token++;
+
+       return strdup(name_token);
+}
+
+static int __before_loop(int argc, char **argv)
+{
+       int r;
+
+#if !(GLIB_CHECK_VERSION(2, 36, 0))
+       g_type_init();
+#endif
+
+       elm_init(argc, argv);
+
+       factory.override_text_signal = __widget_class_factory_override_text_signal;
+
+       r = aul_launch_init(__aul_handler, NULL);
+       if (r < 0) {
+               return widget_app_error(WIDGET_ERROR_INVALID_PARAMETER, __FUNCTION__,
+                                       "Fail to call the aul_launch_init");
+       }
+
+       r = aul_launch_argv_handler(argc, argv);
+       if (r < 0) {
+               return widget_app_error(WIDGET_ERROR_INVALID_PARAMETER, __FUNCTION__,
+                                       "Fail to call the aul_launch_argv_handler");
+       }
+
+       r = app_get_id(&appid);
+       if (r != APP_ERROR_NONE)
+               return r;
+
+       char *name = __get_domain_name(appid);
+
+       if (name == NULL) {
+               return widget_app_error(WIDGET_ERROR_INVALID_PARAMETER, __FUNCTION__,
+                                       "Fail to call __get_domain_name");
+       }
+
+       r = _set_i18n(name);
+
+       free(name);
+       if (r < 0) {
+               return widget_app_error(WIDGET_ERROR_INVALID_PARAMETER, __FUNCTION__,
+                                       "Fail to call _set_i18n");
+       }
+
+       widget_provider_app_create_app();
+
+       memset(&widget_class_tmp, 0, sizeof(widget_class_tmp));
+       widget_class = app_ops->create(app_user_data);
+       if (widget_class == NULL) {
+               return widget_app_error(WIDGET_ERROR_INVALID_PARAMETER, __FUNCTION__,
+                                       "widget_class is NULL");
+       }
+
+       return WIDGET_ERROR_NONE;
+}
+
+static void __after_loop()
+{
+       __pause_all();
+       widget_provider_app_terminate_app(WIDGET_DESTROY_TYPE_TEMPORARY, 1);
+
+       if (app_ops->terminate)
+               app_ops->terminate(app_user_data);
+
+       if (is_init_provider) {
+               widget_provider_app_fini();
+               is_init_provider = 0;
+       }
+       __free_handler_list();
+       elm_shutdown();
+       if (appid)
+               free(appid);
+       if (contexts)
+               g_list_free(contexts);
+       contexts = NULL;
+}
+
+static gboolean __finish_event_cb(gpointer user_data)
+{
+       if (user_data == NULL)
+               return FALSE;
+
+       widget_context_s *wc = (widget_context_s*) user_data;
+       const char* id = wc->id;
+
+       switch (wc->state) {
+       case WC_READY:
+               __provider_resume_cb(id, NULL);
+               __provider_pause_cb(id, NULL);
+               __provider_destroy_cb(id, WIDGET_DESTROY_TYPE_DEFAULT, NULL);
+               break;
+
+       case WC_RUNNING:
+               __provider_pause_cb(id, NULL);
+               __provider_destroy_cb(id, WIDGET_DESTROY_TYPE_DEFAULT, NULL);
+               break;
+
+       case WC_PAUSED:
+               __provider_destroy_cb(id, WIDGET_DESTROY_TYPE_DEFAULT, NULL);
+               break;
+       }
+
+       widget_provider_app_send_deleted(id);
+       return FALSE;
+}
+
+static void __on_low_memory(keynode_t *key, void *data)
+{
+       int val;
+
+       val = vconf_keynode_get_int(key);
+       if (val == VCONFKEY_SYSMAN_LOW_MEMORY_SOFT_WARNING) {
+               app_event_handler_h handler;
+               struct app_event_info event;
+
+               _I("widget_app_low_memory");
+
+               event.type = APP_EVENT_LOW_MEMORY;
+               event.value = (void*)&val;
+
+               GList *iter = g_list_first(handler_list[APP_EVENT_LOW_MEMORY]);
+
+               while (iter) {
+                       handler = (app_event_handler_h) iter->data;
+                       handler->cb(&event, handler->data);
+                       iter = g_list_next(iter);
+               }
+       }
+}
+
+static void __on_low_battery(keynode_t *key, void *data)
+{
+       int val;
+
+       val = vconf_keynode_get_int(key);
+       if (val <= VCONFKEY_SYSMAN_BAT_CRITICAL_LOW) {
+               app_event_handler_h handler;
+               struct app_event_info event;
+
+               _I("widget_app_low_battery");
+
+               event.type = APP_EVENT_LOW_BATTERY;
+               event.value = (void*)&val;
+
+               GList *iter = g_list_first(handler_list[APP_EVENT_LOW_BATTERY]);
+
+               while (iter) {
+                       handler = (app_event_handler_h) iter->data;
+                       handler->cb(&event, handler->data);
+                       iter = g_list_next(iter);
+               }
+       }
+}
+
+static void __on_lang_changed(keynode_t *key, void *data)
+{
+       char *val;
+
+       _update_lang();
+       val = vconf_keynode_get_str(key);
+
+       app_event_handler_h handler;
+       struct app_event_info event;
+
+       _I("widget_app_lang_changed");
+
+       event.type = APP_EVENT_LANGUAGE_CHANGED;
+       event.value = (void*)val;
+
+       GList *iter = g_list_first(handler_list[APP_EVENT_LANGUAGE_CHANGED]);
+
+       while (iter) {
+               handler = (app_event_handler_h) iter->data;
+               handler->cb(&event, handler->data);
+               iter = g_list_next(iter);
+       }
+}
+
+static void __on_region_changed(keynode_t *key, void *data)
+{
+       char *val;
+
+       _update_region();
+       val = vconf_keynode_get_str(key);
+
+       app_event_handler_h handler;
+       struct app_event_info event;
+
+       _I("widget_app_region_changed");
+
+       event.type = APP_EVENT_REGION_FORMAT_CHANGED;
+       event.value = (void*)val;
+
+       GList *iter = g_list_first(handler_list[APP_EVENT_REGION_FORMAT_CHANGED]);
+
+       while (iter) {
+               handler = (app_event_handler_h) iter->data;
+               handler->cb(&event, handler->data);
+               iter = g_list_next(iter);
+       }
+}
+
+static void __register_event(int event_type)
+{
+       switch (event_type) {
+       case APP_EVENT_LOW_MEMORY:
+               vconf_notify_key_changed(VCONFKEY_SYSMAN_LOW_MEMORY, __on_low_memory, NULL);
+               break;
+
+       case APP_EVENT_LOW_BATTERY:
+               vconf_notify_key_changed(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, __on_low_battery,
+                                        NULL);
+               break;
+
+       case APP_EVENT_LANGUAGE_CHANGED:
+               vconf_notify_key_changed(VCONFKEY_LANGSET, __on_lang_changed, NULL);
+               break;
+
+       case APP_EVENT_REGION_FORMAT_CHANGED:
+               vconf_notify_key_changed(VCONFKEY_REGIONFORMAT, __on_region_changed, NULL);
+               break;
+       }
+}
+
+static void __unregister_event(int event_type)
+{
+       switch (event_type) {
+       case APP_EVENT_LOW_MEMORY:
+               vconf_ignore_key_changed(VCONFKEY_SYSMAN_LOW_MEMORY, __on_low_memory);
+               break;
+
+       case APP_EVENT_LOW_BATTERY:
+               vconf_ignore_key_changed(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, __on_low_battery);
+               break;
+
+       case APP_EVENT_LANGUAGE_CHANGED:
+               vconf_ignore_key_changed(VCONFKEY_LANGSET, __on_lang_changed);
+               break;
+
+       case APP_EVENT_REGION_FORMAT_CHANGED:
+               vconf_ignore_key_changed(VCONFKEY_REGIONFORMAT, __on_region_changed);
+               break;
+       }
+}
+
+EXPORT_API int widget_app_main(int argc, char **argv,
+                               widget_app_lifecycle_callback_s *callback, void *user_data)
+{
+       int r;
+       bool feature;
+
+       r = system_info_get_platform_bool(FEATURE_SHELL_APPWIDGET, &feature);
+       if (r < 0)
+               return WIDGET_ERROR_FAULT;
+
+       if (!feature)
+               return WIDGET_ERROR_NOT_SUPPORTED;
+
+       if (argc <= 0 || argv == NULL || callback == NULL)
+               return widget_app_error(WIDGET_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
+
+       if (callback->create == NULL)
+               return widget_app_error(WIDGET_ERROR_INVALID_PARAMETER, __FUNCTION__, "widget_app_create_cb() callback must be registered");
+
+       app_ops = callback;
+       app_user_data = user_data;
+       r = __before_loop(argc, argv);
+       if (r < 0)
+               return r;
+
+       ecore_main_loop_begin();
+       //aul_status_update(STATUS_DYING);
+       __after_loop();
+
+       return WIDGET_ERROR_NONE;
+}
+
+EXPORT_API int widget_app_exit(void)
+{
+       int r;
+       bool feature;
+
+       r = system_info_get_platform_bool(FEATURE_SHELL_APPWIDGET, &feature);
+       if (r < 0)
+               return WIDGET_ERROR_FAULT;
+
+       if (!feature)
+               return WIDGET_ERROR_NOT_SUPPORTED;
+
+       ecore_main_loop_quit();
+
+       return WIDGET_ERROR_NONE;
+}
+
+EXPORT_API int widget_app_terminate_context(widget_context_h context)
+{
+       int r;
+       bool feature;
+
+       r = system_info_get_platform_bool(FEATURE_SHELL_APPWIDGET, &feature);
+       if (r < 0)
+               return WIDGET_ERROR_FAULT;
+
+       if (!feature)
+               return WIDGET_ERROR_NOT_SUPPORTED;
+
+       if (context == NULL) {
+               return widget_app_error(WIDGET_ERROR_INVALID_PARAMETER, __FUNCTION__,
+                                       "obj is NULL");
+       }
+
+       g_idle_add(__finish_event_cb, context);
+       return WIDGET_ERROR_NONE;
+}
+
+EXPORT_API int widget_app_foreach_context(widget_context_cb cb, void *data)
+{
+       int r;
+       bool feature;
+
+       r = system_info_get_platform_bool(FEATURE_SHELL_APPWIDGET, &feature);
+       if (r < 0)
+               return WIDGET_ERROR_FAULT;
+
+       if (!feature)
+               return WIDGET_ERROR_NOT_SUPPORTED;
+
+       if (cb == NULL)
+               return WIDGET_ERROR_INVALID_PARAMETER;
+
+       GList *iter = g_list_first(contexts);
+
+       while (iter != NULL) {
+               widget_context_s *cxt = (widget_context_s*) iter->data;
+               if ( !cb(cxt, data)) {
+                       return WIDGET_ERROR_CANCELED;
+               }
+
+               iter = g_list_next(iter);
+       }
+
+       return WIDGET_ERROR_NONE;
+}
+
+EXPORT_API int widget_app_add_event_handler(app_event_handler_h *event_handler,
+        app_event_type_e event_type, app_event_cb callback, void *user_data)
+{
+       int r;
+       bool feature;
+
+       r = system_info_get_platform_bool(FEATURE_SHELL_APPWIDGET, &feature);
+       if (r < 0)
+               return WIDGET_ERROR_FAULT;
+
+       if (!feature)
+               return WIDGET_ERROR_NOT_SUPPORTED;
+
+       app_event_handler_h handler;
+
+       if (event_handler == NULL || callback == NULL)
+               return widget_app_error(WIDGET_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
+
+       if (event_type < APP_EVENT_LOW_MEMORY
+           || event_type > APP_EVENT_REGION_FORMAT_CHANGED)
+               return widget_app_error(WIDGET_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
+
+       if (event_type == APP_EVENT_DEVICE_ORIENTATION_CHANGED)
+               return widget_app_error(WIDGET_ERROR_NOT_SUPPORTED, __FUNCTION__, NULL);
+
+       GList *iter = g_list_first(handler_list[event_type]);
+
+       while (iter) {
+               handler = (app_event_handler_h) iter->data;
+
+               if (handler->cb == callback)
+                       return widget_app_error(WIDGET_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
+               iter = g_list_next(iter);
+       }
+
+       handler = calloc(1, sizeof(struct app_event_handler));
+       if (!handler)
+               return widget_app_error(WIDGET_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL);
+
+       if (g_list_length(handler_list[event_type]) == 0) {
+               __register_event(event_type);
+       }
+
+       handler->type = event_type;
+       handler->cb = callback;
+       handler->data = user_data;
+       handler_list[event_type] = g_list_append(handler_list[event_type], handler);
+
+       *event_handler = handler;
+
+       return WIDGET_ERROR_NONE;
+}
+
+EXPORT_API int widget_app_remove_event_handler(app_event_handler_h
+        event_handler)
+{
+       int r;
+       bool feature;
+
+       r = system_info_get_platform_bool(FEATURE_SHELL_APPWIDGET, &feature);
+       if (r < 0)
+               return WIDGET_ERROR_FAULT;
+
+       if (!feature)
+               return WIDGET_ERROR_NOT_SUPPORTED;
+
+       app_event_type_e type;
+
+       if (event_handler == NULL)
+               return widget_app_error(WIDGET_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
+
+       type = event_handler->type;
+       if (type < APP_EVENT_LOW_MEMORY || type > APP_EVENT_REGION_FORMAT_CHANGED)
+               return widget_app_error(WIDGET_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
+
+       handler_list[type] = g_list_remove(handler_list[type], event_handler);
+       free(event_handler);
+
+       if (g_list_length(handler_list[type]) == 0)
+               __unregister_event(type);
+
+       return WIDGET_ERROR_NONE;
+}
+
+EXPORT_API const char* widget_app_get_id(widget_context_h context)
+{
+       int r;
+       bool feature;
+
+       r = system_info_get_platform_bool(FEATURE_SHELL_APPWIDGET, &feature);
+       if (r < 0) {
+               set_last_result(WIDGET_ERROR_FAULT);
+               return NULL;
+       }
+
+       if (!feature) {
+               set_last_result(WIDGET_ERROR_NOT_SUPPORTED);
+               return NULL;
+       }
+
+       if (context == NULL) {
+               set_last_result(WIDGET_ERROR_INVALID_PARAMETER);
+               return NULL;
+       }
+
+       widget_context_s *cxt = (widget_context_s*)context;
+
+       set_last_result(WIDGET_ERROR_NONE);
+       return cxt->id;
+}
+
+EXPORT_API int widget_app_get_elm_win(widget_context_h context,
+                                      Evas_Object **win)
+{
+       int r;
+       bool feature;
+
+       r = system_info_get_platform_bool(FEATURE_SHELL_APPWIDGET, &feature);
+       if (r < 0)
+               return WIDGET_ERROR_FAULT;
+
+       if (!feature)
+               return WIDGET_ERROR_NOT_SUPPORTED;
+
+       if (context == NULL || win == NULL) {
+               return widget_app_error(WIDGET_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
+       }
+
+       widget_context_s *cxt = (widget_context_s*)context;
+       Evas *evas;
+       Evas_Object *ret_win = NULL;
+
+       evas = widget_get_evas(cxt->id);
+       if (evas) {
+               Evas_Object *widget_parent;
+               widget_parent = evas_object_rectangle_add(evas);
+               if (widget_parent) {
+                       ret_win = elm_win_add(widget_parent, cxt->id, ELM_WIN_TIZEN_WIDGET);
+                       evas_object_del(widget_parent);
+                       if (ret_win == NULL) {
+                               _E("win is NULL");
+                               return widget_app_error(WIDGET_ERROR_FAULT, __FUNCTION__, NULL);
+                       }
+               } else {
+                       _E("Failed to get parent widget");
+                       return widget_app_error(WIDGET_ERROR_FAULT, __FUNCTION__, NULL);
+               }
+       } else {
+               _E("parent evas object is NULL");
+               return widget_app_error(WIDGET_ERROR_FAULT, __FUNCTION__, NULL);
+       }
+
+       *win = ret_win;
+       return WIDGET_ERROR_NONE;
+}
+
+EXPORT_API widget_class_h widget_app_class_create(widget_instance_lifecycle_callback_s callback)
+{
+       int r;
+       bool feature;
+
+       r = system_info_get_platform_bool(FEATURE_SHELL_APPWIDGET, &feature);
+       if (r < 0) {
+               set_last_result(WIDGET_ERROR_FAULT);
+               return NULL;
+       }
+
+       if (!feature) {
+               set_last_result(WIDGET_ERROR_NOT_SUPPORTED);
+               return NULL;
+       }
+
+       widget_class_s *wc = (widget_class_s*)malloc(sizeof(widget_class_s));
+
+       if (wc == NULL) {
+               _E("failed to malloc : %s", __FUNCTION__);
+               set_last_result(WIDGET_ERROR_OUT_OF_MEMORY);
+               return NULL;
+       }
+
+       wc->ops = callback;
+       wc->ops_private = widget_class_tmp.ops_private;
+       set_last_result(WIDGET_ERROR_NONE);
+       return wc;
+}
+
+EXPORT_API int widget_app_context_set_tag(widget_context_h context, void *tag)
+{
+       int r;
+       bool feature;
+
+       r = system_info_get_platform_bool(FEATURE_SHELL_APPWIDGET, &feature);
+       if (r < 0)
+               return WIDGET_ERROR_FAULT;
+
+       if (!feature)
+               return WIDGET_ERROR_NOT_SUPPORTED;
+
+       if (context == NULL) {
+               return widget_app_error(WIDGET_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
+       }
+
+       context->tag = tag;
+
+       return WIDGET_ERROR_NONE;
+}
+
+EXPORT_API int widget_app_context_get_tag(widget_context_h context, void **tag)
+{
+       int r;
+       bool feature;
+
+       r = system_info_get_platform_bool(FEATURE_SHELL_APPWIDGET, &feature);
+       if (r < 0)
+               return WIDGET_ERROR_FAULT;
+
+       if (!feature)
+               return WIDGET_ERROR_NOT_SUPPORTED;
+
+       if (context == NULL || tag == NULL) {
+               return widget_app_error(WIDGET_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
+       }
+
+       *tag = context->tag;
+
+       return WIDGET_ERROR_NONE;
+}
+
+EXPORT_API int widget_app_context_set_content_info(widget_context_h context, bundle *content_info)
+{
+       int r;
+       bool feature;
+
+       r = system_info_get_platform_bool(FEATURE_SHELL_APPWIDGET, &feature);
+       if (r < 0)
+               return WIDGET_ERROR_FAULT;
+
+       if (!feature)
+               return WIDGET_ERROR_NOT_SUPPORTED;
+
+       if (content_info == NULL)
+               return WIDGET_ERROR_INVALID_PARAMETER;
+
+       bundle_raw *raw = NULL;
+       int len;
+       int ret = WIDGET_ERROR_FAULT;
+
+       bundle_encode(content_info, &raw, &len);
+       if (raw) {
+               ret = widget_provider_app_send_extra_info(context->id, (const char*)raw, NULL);
+               free(raw);
+       }
+
+       return ret;
+}
+
+EXPORT_API int widget_app_context_set_title(widget_context_h context, const char *title)
+{
+       int r;
+       bool feature;
+
+       r = system_info_get_platform_bool(FEATURE_SHELL_APPWIDGET, &feature);
+       if (r < 0)
+               return WIDGET_ERROR_FAULT;
+
+       if (!feature)
+               return WIDGET_ERROR_NOT_SUPPORTED;
+
+       if (context == NULL)
+               return WIDGET_ERROR_INVALID_PARAMETER;
+
+       return widget_provider_app_send_extra_info(context->id, NULL, title);
+}
+
+// private API
+EXPORT_API const widget_class_factory_full_s* widget_app_get_class_factory(void)
+{
+       return &factory;
+}
diff --git a/src/widget_error.c b/src/widget_error.c
new file mode 100755 (executable)
index 0000000..390a820
--- /dev/null
@@ -0,0 +1,96 @@
+/*
+ * 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 <widget_errno.h>
+
+#include "widget-private.h"
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+
+#define LOG_TAG "CAPI_WIDGET_APPLICATIO"
+
+static const char* widget_app_error_to_string(widget_error_e error)
+{
+       switch (error) {
+       case WIDGET_ERROR_NONE:
+               return "NONE";
+
+       case WIDGET_ERROR_INVALID_PARAMETER:
+               return "INVALID_PARAMETER";
+
+       case WIDGET_ERROR_OUT_OF_MEMORY:
+               return "OUT_OF_MEMORY";
+
+       case WIDGET_ERROR_RESOURCE_BUSY:
+               return "RESOURCE_BUSY";
+
+       case WIDGET_ERROR_PERMISSION_DENIED:
+               return "PERMISSION_DENIED";
+
+       case WIDGET_ERROR_CANCELED:
+               return "CANCELED";
+
+       case WIDGET_ERROR_IO_ERROR:
+               return "IO_ERROR";
+
+       case WIDGET_ERROR_TIMED_OUT:
+               return "TIMED_OUT";
+
+       case WIDGET_ERROR_NOT_SUPPORTED:
+               return "NOT_SUPPORTED";
+
+       case WIDGET_ERROR_FILE_NO_SPACE_ON_DEVICE:
+               return "FILE_NO_SPACE_ON_DEVICE";
+
+       case WIDGET_ERROR_FAULT:
+               return "FAULT";
+
+       case WIDGET_ERROR_ALREADY_EXIST:
+               return "ALREADY_EXIST";
+
+       case WIDGET_ERROR_ALREADY_STARTED:
+               return "ALREADY_STARTED";
+
+       case WIDGET_ERROR_NOT_EXIST:
+               return "NOT_EXIST";
+
+       case WIDGET_ERROR_DISABLED:
+               return "DISABLED";
+
+       default :
+               return "UNKNOWN";
+       }
+}
+
+int widget_app_error(widget_error_e error, const char* function,
+                     const char *description)
+{
+       if (description) {
+               LOGE("[%s] %s(0x%08x) : %s", function, widget_app_error_to_string(error), error,
+                    description);
+       } else {
+               LOGE("[%s] %s(0x%08x)", function, widget_app_error_to_string(error), error);
+       }
+
+       return error;
+}