summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKibum Kim <kb0929.kim@samsung.com>2012-01-07 00:42:11 +0900
committerKibum Kim <kb0929.kim@samsung.com>2012-01-07 00:42:11 +0900
commitefd542635a7e63f4b4250c5dbd223498defc379e (patch)
tree6f5a5c11c33c7b9f2259474c8be4ef42c259d642
parent5611ff5660d14d0ea707447e84ee4c0626b71104 (diff)
downloadapplication-efd542635a7e63f4b4250c5dbd223498defc379e.tar.gz
application-efd542635a7e63f4b4250c5dbd223498defc379e.tar.bz2
application-efd542635a7e63f4b4250c5dbd223498defc379e.zip
Git init
-rwxr-xr-xAUTHORS2
-rwxr-xr-xCMakeLists.txt87
-rwxr-xr-xLICENSE206
-rw-r--r--capi-appfw-application.pc.in15
-rw-r--r--debian/README0
-rw-r--r--debian/capi-appfw-application-dev.install4
-rw-r--r--debian/capi-appfw-application-dev.postinst1
-rw-r--r--debian/capi-appfw-application.install1
-rw-r--r--debian/capi-appfw-application.postinst1
-rwxr-xr-xdebian/changelog21
-rw-r--r--debian/compat1
-rwxr-xr-xdebian/control22
-rwxr-xr-xdebian/rules65
-rwxr-xr-xinclude/app.h371
-rwxr-xr-xinclude/app_alarm.h267
-rwxr-xr-xinclude/app_i18n.h59
-rwxr-xr-xinclude/app_preference.h295
-rwxr-xr-xinclude/app_preference_private.h52
-rwxr-xr-xinclude/app_private.h59
-rwxr-xr-xinclude/app_service.h577
-rwxr-xr-xinclude/app_service_private.h35
-rwxr-xr-xinclude/app_storage.h226
-rwxr-xr-xinclude/app_storage_private.h60
-rwxr-xr-xinclude/app_ui_notification.h287
-rwxr-xr-xpackaging/capi-appfw-application.spec60
-rwxr-xr-xsrc/alarm.c566
-rwxr-xr-xsrc/app_device.c83
-rwxr-xr-xsrc/app_main.c506
-rwxr-xr-xsrc/app_package.c192
-rwxr-xr-xsrc/app_resource.c169
-rwxr-xr-xsrc/i18n.c29
-rwxr-xr-xsrc/preference.c752
-rwxr-xr-xsrc/service.c1145
-rwxr-xr-xsrc/storage.c397
-rwxr-xr-xsrc/storage_internal.c79
-rwxr-xr-xsrc/storage_sdcard.c125
-rwxr-xr-xsrc/storage_usbhost.c125
-rwxr-xr-xsrc/ui_notification.c637
38 files changed, 7579 insertions, 0 deletions
diff --git a/AUTHORS b/AUTHORS
new file mode 100755
index 0000000..a228ba0
--- /dev/null
+++ b/AUTHORS
@@ -0,0 +1,2 @@
+junghyuk park <junghyuk.park@samsung.com>
+
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100755
index 0000000..23f92f2
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,87 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+SET(fw_name "capi-appfw-application")
+
+PROJECT(${fw_name})
+
+SET(CMAKE_INSTALL_PREFIX /usr)
+SET(PREFIX ${CMAKE_INSTALL_PREFIX})
+
+SET(INC_DIR include)
+INCLUDE_DIRECTORIES(${INC_DIR})
+
+SET(dependents "dlog bundle appcore-common appcore-efl aul ail appsvc notification elementary capi-base-common alarm-service sqlite3")
+
+INCLUDE(FindPkgConfig)
+pkg_check_modules(${fw_name} REQUIRED ${dependents})
+FOREACH(flag ${${fw_name}_CFLAGS})
+ SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -fPIC -Wall -Werror")
+SET(CMAKE_C_FLAGS_DEBUG "-O0 -g")
+
+IF("${ARCH}" STREQUAL "arm")
+ ADD_DEFINITIONS("-DTARGET")
+ENDIF("${ARCH}" STREQUAL "arm")
+
+ADD_DEFINITIONS("-DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"")
+ADD_DEFINITIONS("-DSLP_DEBUG")
+
+SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -Wl,--rpath=/usr/lib")
+
+aux_source_directory(src SOURCES)
+ADD_LIBRARY(${fw_name} SHARED ${SOURCES})
+
+TARGET_LINK_LIBRARIES(${fw_name} ${${fw_name}_LDFLAGS})
+
+INSTALL(TARGETS ${fw_name} DESTINATION lib)
+INSTALL(
+ DIRECTORY ${INC_DIR}/ DESTINATION include/appfw
+ FILES_MATCHING
+ PATTERN "*_private.h" EXCLUDE
+ PATTERN "${INC_DIR}/*.h"
+ )
+
+SET(PC_NAME ${fw_name})
+SET(PC_REQUIRED ${dependents})
+SET(PC_LDFLAGS -l${fw_name})
+SET(PC_CFLAGS -I\${includedir}/appfw)
+
+CONFIGURE_FILE(
+ capi-appfw-application.pc.in
+ ${CMAKE_CURRENT_SOURCE_DIR}/${fw_name}.pc
+ @ONLY
+)
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${fw_name}.pc DESTINATION lib/pkgconfig)
+
+IF(UNIX)
+
+ADD_CUSTOM_TARGET (distclean @echo cleaning for source distribution)
+ADD_CUSTOM_COMMAND(
+ DEPENDS clean
+ COMMENT "distribution clean"
+ COMMAND find
+ ARGS .
+ -not -name config.cmake -and \(
+ -name tester.c -or
+ -name Testing -or
+ -name CMakeFiles -or
+ -name cmake.depends -or
+ -name cmake.check_depends -or
+ -name CMakeCache.txt -or
+ -name cmake.check_cache -or
+ -name *.cmake -or
+ -name Makefile -or
+ -name core -or
+ -name core.* -or
+ -name gmon.out -or
+ -name install_manifest.txt -or
+ -name *.pc -or
+ -name *~ \)
+ | grep -v TC | xargs rm -rf
+ TARGET distclean
+ VERBATIM
+)
+
+ENDIF(UNIX)
+
diff --git a/LICENSE b/LICENSE
new file mode 100755
index 0000000..bbe9d02
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,206 @@
+Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ 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.
+
+
+
diff --git a/capi-appfw-application.pc.in b/capi-appfw-application.pc.in
new file mode 100644
index 0000000..0a03940
--- /dev/null
+++ b/capi-appfw-application.pc.in
@@ -0,0 +1,15 @@
+
+# Package Information for pkg-config
+
+prefix=@PREFIX@
+exec_prefix=/usr
+libdir=/usr/lib
+includedir=/usr/include/appfw
+
+Name: @PC_NAME@
+Description: @PACKAGE_DESCRIPTION@
+Version: @VERSION@
+Requires: @PC_REQUIRED@
+Libs: -L${libdir} @PC_LDFLAGS@
+Cflags: -I${includedir} @PC_CFLAGS@
+
diff --git a/debian/README b/debian/README
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/debian/README
diff --git a/debian/capi-appfw-application-dev.install b/debian/capi-appfw-application-dev.install
new file mode 100644
index 0000000..761a28b
--- /dev/null
+++ b/debian/capi-appfw-application-dev.install
@@ -0,0 +1,4 @@
+/usr/include/*
+/usr/include/*/*
+/usr/lib/pkgconfig/*.pc
+
diff --git a/debian/capi-appfw-application-dev.postinst b/debian/capi-appfw-application-dev.postinst
new file mode 100644
index 0000000..1a24852
--- /dev/null
+++ b/debian/capi-appfw-application-dev.postinst
@@ -0,0 +1 @@
+#!/bin/sh
diff --git a/debian/capi-appfw-application.install b/debian/capi-appfw-application.install
new file mode 100644
index 0000000..4a755a4
--- /dev/null
+++ b/debian/capi-appfw-application.install
@@ -0,0 +1 @@
+/usr/lib/lib*.so*
diff --git a/debian/capi-appfw-application.postinst b/debian/capi-appfw-application.postinst
new file mode 100644
index 0000000..1a24852
--- /dev/null
+++ b/debian/capi-appfw-application.postinst
@@ -0,0 +1 @@
+#!/bin/sh
diff --git a/debian/changelog b/debian/changelog
new file mode 100755
index 0000000..9ebfa2c
--- /dev/null
+++ b/debian/changelog
@@ -0,0 +1,21 @@
+capi-appfw-application (0.1.0-13) unstable; urgency=low
+
+ * Update alarm API Doc
+ * Git: api/application
+ * Tag: capi-appfw-application_0.1.0-13
+
+ -- Junghyuk Park <junghyuk.park@samsung.com> Thu, 22 Dec 2011 11:01:24 +0300
+
+capi-appfw-application (0.1.0-12) unstable; urgency=low
+
+ * Fixed memory leak
+ * Git: api/application
+ * Tag: capi-appfw-application_0.1.0-12
+
+ -- Junghyuk Park <junghyuk.park@samsung.com> Wed, 21 Dec 2011 13:27:10 +0900
+
+capi-appfw-application (0.1.0-11) unstable; urgency=low
+
+ * Initial release.
+
+ -- Junghyuk Park <junghyuk.park@samsung.com> Wed, 07 Dec 2011 11:35:51 +0900
diff --git a/debian/compat b/debian/compat
new file mode 100644
index 0000000..7ed6ff8
--- /dev/null
+++ b/debian/compat
@@ -0,0 +1 @@
+5
diff --git a/debian/control b/debian/control
new file mode 100755
index 0000000..c40dadb
--- /dev/null
+++ b/debian/control
@@ -0,0 +1,22 @@
+
+Source: capi-appfw-application
+Section: libs
+Priority: extra
+Maintainer: Woongsuk Cho <ws77.cho@samsung.com>, junghyuk park <junghyuk.park@samsung.com>
+Build-Depends: debhelper (>= 5), dlog-dev, libbundle-dev, libappcore-common-dev, libappcore-efl-dev, libaul-1-dev, libail-0-dev, libappsvc-dev, libnotification-dev, libelm-dev, capi-base-common-dev, libalarm-dev, libsqlite3-dev
+
+Package: capi-appfw-application
+Architecture: any
+Depends: ${shilbs:Depends}, ${misc:Depends}
+Description: An Application library in Tizen C API
+
+Package: capi-appfw-application-dev
+Architecture: any
+Depends: ${shlibs:Depends}, ${misc:Depends}, capi-appfw-application (= ${Source-Version}), dlog-dev, libbundle-dev, libappcore-common-dev, libappcore-efl-dev, libaul-1-dev, libail-0-dev, libappsvc-dev, libnotification-dev, libelm-dev, capi-base-common-dev, libalarm-dev, libsqlite3-dev
+Description: An Application library in Tizen C API (DEV)
+
+Package: capi-appfw-application-dbg
+Architecture: any
+Depends: ${shlibs:Depends}, ${misc:Depends}, capi-appfw-application (= ${Source-Version})
+Description: An Application library in Tizen C API (DBG)
+
diff --git a/debian/rules b/debian/rules
new file mode 100755
index 0000000..7d6131a
--- /dev/null
+++ b/debian/rules
@@ -0,0 +1,65 @@
+#!/usr/bin/make -f
+
+CFLAGS = -Wall -g
+
+ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
+ CFLAGS += -O0
+else
+ CFLAGS += -O2
+endif
+CMAKE_ROOT_DIR ?= $(CURDIR)
+CMAKE_BUILD_DIR ?= $(CURDIR)/cmake_build_tmp
+
+configure: configure-stamp
+configure-stamp:
+ dh_testdir
+ mkdir -p $(CMAKE_BUILD_DIR) && cd $(CMAKE_BUILD_DIR) && cmake ..
+ touch configure-stamp
+
+
+build: build-stamp
+build-stamp: configure-stamp
+ dh_testdir
+ cd $(CMAKE_BUILD_DIR) && $(MAKE)
+ touch $@
+
+clean:
+ cd $(CMAKE_ROOT_DIR)
+ dh_testdir
+ dh_testroot
+ rm -f build-stamp configure-stamp
+ rm -f `find . -name *.pc`
+ rm -rf $(CMAKE_BUILD_DIR)
+ dh_clean
+
+install: build
+ dh_testdir
+ dh_testroot
+ dh_clean -k
+ dh_installdirs
+
+ cd $(CMAKE_BUILD_DIR) && $(MAKE) DESTDIR=$(CURDIR)/debian/tmp install
+
+binary-indep: build install
+
+binary-arch: build install
+ dh_testdir
+ dh_testroot
+ dh_installchangelogs
+ dh_installdocs
+ dh_installexamples
+ dh_install --sourcedir=debian/tmp
+ dh_installman
+ dh_link
+ dh_strip --dbg-package=capi-appfw-application-dbg
+ dh_fixperms
+ dh_makeshlibs
+ dh_installdeb
+ dh_shlibdeps
+ dh_gencontrol
+ dh_md5sums
+ dh_builddeb
+
+binary: binary-indep binary-arch
+.PHONY: build clean binary-indep binary-arch binary install configure
+
diff --git a/include/app.h b/include/app.h
new file mode 100755
index 0000000..565ac7f
--- /dev/null
+++ b/include/app.h
@@ -0,0 +1,371 @@
+/*
+ * Copyright (c) 2011 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_APP_H__
+#define __TIZEN_APPFW_APP_H__
+
+#include <tizen.h>
+#include <app_service.h>
+#include <app_alarm.h>
+#include <app_preference.h>
+#include <app_storage.h>
+#include <app_i18n.h>
+#include <app_ui_notification.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @addtogroup CAPI_APPLICATION_MODULE
+ * @{
+ */
+
+
+/**
+ * @brief Enumerations of error code for Application.
+ */
+typedef enum
+{
+ APP_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */
+ APP_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */
+ APP_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory */
+ APP_ERROR_INVALID_CONTEXT = TIZEN_ERROR_NOT_PERMITTED, /**< Invalid application context */
+ APP_ERROR_NO_SUCH_FILE = TIZEN_ERROR_NO_SUCH_FILE, /**< No such file or directory */
+ APP_ERROR_ALREADY_RUNNING = TIZEN_ERROR_ALREADY_IN_PROGRESS, /**< Application is already running */
+} app_error_e;
+
+
+/**
+ * @brief Enumerations of the device orientation.
+ */
+typedef enum
+{
+ APP_DEVICE_ORIENTATION_0 = 0, /**< The device is oriented in natural position */
+ APP_DEVICE_ORIENTATION_90 = 90, /**< The device's left side is at the top */
+ APP_DEVICE_ORIENTATION_180 = 180, /**< The device is upside down */
+ APP_DEVICE_ORIENTATION_270 = 270, /**<The device's right side is to the top */
+} app_device_orientation_e;
+
+
+/**
+ * @brief Called at the start of the application.
+ *
+ * @details The callback function is called before the main loop of application starts.
+ * In this callback you can initialize application resources like window creation, data structure, etc.
+ * After this callback function returns @c true, the main loop starts up and app_service_cb() is subsequently called.
+ * If this callback function returns @c false, the main loop doesn't start and app_terminate_cb() is subsequently called.
+ *
+ * @param[in] user_data The user data passed from the callback registration function
+ * @return @c true on success, otherwise @c false
+ * @pre app_efl_main() will invoke this callback function.
+ * @see app_efl_main()
+ * @see #app_event_callback_s
+ */
+typedef bool (*app_create_cb) (void *user_data);
+
+
+/**
+ * @brief Called when the application is completely obscured by another application and becomes invisible.
+ *
+ * @details The application is not terminated and still running in paused state.
+ *
+ * @param[in] user_data The user data passed from the callback registration function
+ * @see app_efl_main()
+ * @see #app_event_callback_s
+ */
+typedef void (*app_pause_cb) (void *user_data);
+
+
+/**
+ * @brief Called when the application becomes visible.
+ *
+ * @remarks This callback function is not called when the application moved from created state to running state.
+ *
+ * @param[in] user_data The user data passed from the callback registration function
+ * @see app_efl_main()
+ * @see #app_event_callback_s
+ */
+typedef void (*app_resume_cb) (void *user_data);
+
+
+/**
+ * @brief Called once after the main loop of application exits.
+ * @details You should release the application's resources in this function.
+ *
+ * @param[in] user_data The user data passed from the callback registration function
+ * @see app_efl_main()
+ * @see #app_event_callback_s
+ */
+typedef void (*app_terminate_cb) (void *user_data);
+
+
+/**
+ * @brief Called when other application send the launch request to the application.
+ *
+ * @details When the application is launched, this callback function is called after the main loop of application starts up.
+ * The passed service handle describes the launch request and contains the information about why the application is launched.
+ * If the launch request is sent to the application on running or pause state,
+ * this callback function can be called again to notify that the application is asked to be launched.
+ *
+ * The application could be explicitly launched by the user from the application launcher or be launched to perform the specific operation by other application.
+ * The application is responsible for handling the each launch request and responding appropriately.
+ * Using the Service API, the application can get the information what has to perform.
+ * If the application is launched from the application launcher or explicitly launched by other application,
+ * the passed service handle may include only the default operation (#SERVICE_OPERATION_DEFAULT) without any data
+ * For more information, see The @ref CAPI_SERVICE_MODULE API description.
+ *
+ * @param[in] service The handle to the service
+ * @param[in] user_data The user data passed from the callback registration function
+ * @see app_efl_main()
+ * @see #app_event_callback_s
+ * @see @ref CAPI_SERVICE_MODULE API
+ */
+typedef void (*app_service_cb) (service_h service, void *user_data);
+
+
+/**
+ * @brief Called when the system memory is running low.
+ *
+ * @details
+ * When low memory event is dispatched, the application should immediately save state and release resources to save as much memory as possible. \n
+ * If enough memory is not reclaimed during low memory conditions, the system will terminate some of the applications to reclaim the memory.
+ *
+ * @param[in] user_data The user data passed from the callback registration function
+ * @see app_efl_main()
+ * @see #app_event_callback_s
+ */
+typedef void (*app_low_memory_cb) (void *user_data);
+
+
+/**
+ * @brief Called when the battery power is running low.
+ * @details When the battery level falls below 5%, it is called.
+ *
+ * @param[in] user_data The user data passed from the callback registration function
+ * @see app_efl_main()
+ * @see #app_event_callback_s
+ */
+typedef void (*app_low_battery_cb) (void *user_data);
+
+
+/**
+ * @brief Called when the orientation of device changes.
+ *
+ * @param[in] orientation The orientation of device
+ * @param[in] user_data The user data passed from the callback registration function
+ * @see app_efl_main()
+ * @see #app_event_callback_s
+ */
+typedef void (*app_device_orientation_cb) (app_device_orientation_e orientation, void *user_data);
+
+
+/**
+ * @brief Called when language setting changes.
+ *
+ * @param [in] user_data The user data passed from the callback registration function
+ * @see app_efl_main()
+ * @see #app_event_callback_s
+ */
+typedef void (*app_language_changed_cb) (void *user_data);
+
+
+/**
+ * @brief Called when region format setting changes.
+ *
+ * @param [in] user_data The user data passed from the callback registration function
+ * @see app_efl_main()
+ * @see #app_event_callback_s
+ */
+typedef void (*app_region_format_changed_cb) (void *user_data);
+
+
+/**
+ * @brief The structure type to contain the set of callback functions for handling application events.
+ * @details It is one of the input parameters of the app_efl_main() function.
+ *
+ * @see app_efl_main()
+ * @see app_create_cb()
+ * @see app_pause_cb()
+ * @see app_resume_cb()
+ * @see app_terminate_cb()
+ * @see app_service_cb()
+ * @see app_low_memory_cb()
+ * @see app_low_battery_cb()
+ * @see app_device_orientation_cb()
+ * @see app_language_changed_cb()
+ * @see app_region_format_changed_cb()
+ */
+typedef struct
+{
+ app_create_cb create; /**< This callback function is called at the start of the application. */
+ app_terminate_cb terminate; /**< This callback function is called once after the main loop of application exits. */
+ 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. */
+ app_resume_cb resume; /**< This callback function is called each time the application becomes visible to the user. */
+ app_service_cb service; /**< This callback function is called when other application send the launch request to the application. */
+ app_low_memory_cb low_memory; /**< The registered callback function is called when the system runs low on memory. */
+ app_low_battery_cb low_battery; /**< The registered callback function is called when battery is low. */
+ app_device_orientation_cb device_orientation; /**< The registered callback function is called when the orientation of device changes */
+ app_language_changed_cb language_changed; /**< The registered callback function is called when language setting changes. */
+ app_region_format_changed_cb region_format_changed; /**< The registered callback function is called when region format setting is changes. */
+} app_event_callback_s;
+
+
+/**
+ * @brief Runs the main loop of application until app_efl_exit() is called
+ *
+ * @details This function is the main entry point of the Tizen application.
+ * The app_create_cb() callback function is called to initialize the application before the main loop of application starts up.
+ * After the app_create_cb() callback function returns true, the main loop starts up and the app_service_cb() callback function is subsequently called.
+ * If the app_create_cb() callback function returns false, the main loop doesn't start up and app_terminate_cb() callback function is called
+ *
+ * @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 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 already starts
+ *
+ * @see app_create_cb()
+ * @see app_terminate_cb()
+ * @see app_pause_cb()
+ * @see app_resume_cb()
+ * @see app_service_cb()
+ * @see app_low_memory_cb()
+ * @see app_low_battery_cb()
+ * @see app_device_orientation_cb()
+ * @see app_language_changed_cb()
+ * @see app_region_format_changed_cb()
+ * @see app_efl_exit()
+ * @see #app_event_callback_s
+ */
+int app_efl_main(int *argc, char ***argv, app_event_callback_s *callback, void *user_data);
+
+
+/**
+ * @brief Exits the main loop of application.
+ *
+ * @details The main loop of application stops and app_terminate_cb() is invoked
+ * @see app_efl_main()
+ * @see app_terminate_cb()
+ */
+void app_efl_exit(void);
+
+
+/**
+ * @brief Gets the name of the application package.
+ *
+ * @remarks @a package must be released with free() by you.
+ *
+ * @param [out] package The name of the application package
+ *
+ * @return 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_OUT_OF_MEMORY Out of memory
+ */
+int app_get_package(char **package);
+
+
+/**
+ * @brief Gets the localized name of the application.
+ *
+ * @remarks @a name must be released with free() by you.
+ *
+ * @param [out] name The name of the application
+ *
+ * @return 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_OUT_OF_MEMORY Out of memory
+ */
+int app_get_name(char **name);
+
+
+/**
+ * @brief Gets the version of the application package.
+ *
+ * @remarks @a version must be released with free() by you.
+ *
+ * @param [out] version The version of the application
+ *
+ * @return 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_OUT_OF_MEMORY Out of memory
+ */
+int app_get_version(char **version);
+
+
+/**
+ * @brief Gets the absolute path to the resource included in application package
+ *
+ * @details The application cannot write and modify any resource files.
+ *
+ * @remarks This function stores the absolute path into the @a buffer at most one less than @a size bytes
+ * and a null character is appended in @a buffer after the path stored.
+ *
+ * @param [in] resource The resource's path relative to the resource directory of the application package (e.g. edje/app.edj or images/background.png)
+ * @param [in] buffer The buffer where the absolute path to the resource is stored.
+ * @param [in] size The size of @a buffer in bytes
+ * @return @a buffer on success, otherwise null.
+ */
+char* app_get_resource(const char *resource, char *buffer, int size);
+
+
+/**
+ * @brief Gets the absolute path to the application's data directory.
+ *
+ * @details An application can read and write its own data files in the application's data directory.
+ *
+ * @remarks This function stores the absolute path into the @a buffer at most one less than @a size bytes
+ * and a null character is appended in @a buffer after the path stored.
+ *
+ * @param [in] buffer The buffer where the absolute path to the application data directory
+ * @param [in] size The size of @a buffer in bytes
+ * @return @a buffer on success, otherwise null.
+ */
+char* app_get_data_directory(char *buffer, int size);
+
+
+/**
+ * @brief Gets the current device orientation.
+ *
+ * @return The current device orientation
+ */
+app_device_orientation_e app_get_device_orientation(void);
+
+
+/**
+ * @}
+ */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __TIZEN_APPFW_APP_H__ */
diff --git a/include/app_alarm.h b/include/app_alarm.h
new file mode 100755
index 0000000..2002e93
--- /dev/null
+++ b/include/app_alarm.h
@@ -0,0 +1,267 @@
+/*
+ * Copyright (c) 2011 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_ALARM_H__
+#define __TIZEN_APPFW_ALARM_H__
+
+#include <tizen.h>
+#include <time.h>
+#include <app_service.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @addtogroup CAPI_ALARM_MODULE
+ * @{
+ */
+
+/**
+ * @brief Service extra data : the id of the alarm registered
+ */
+#define SERVICE_DATA_ALARM_ID "slp.alarm.data.ID"
+
+/**
+ * @brief Enumerations of error codes for the alarm
+ */
+typedef enum
+{
+ ALARM_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */
+ ALARM_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */
+ ALARM_ERROR_INVALID_TIME = TIZEN_ERROR_APPLICATION_CLASS | 0x05, /**< Invalid time */
+ ALARM_ERROR_INVALID_DATE = TIZEN_ERROR_APPLICATION_CLASS | 0x06, /**< Invalid date */
+ ALARM_ERROR_CONNECTION_FAIL = TIZEN_ERROR_APPLICATION_CLASS | 0x07 /**< The alarm service connection failed */
+} alarm_error_e;
+
+
+/**
+ * @brief Enumerations of the days of the week.
+ */
+typedef enum
+{
+ ALARM_WEEK_FLAG_SUNDAY = 0x01, /**< Sunday */
+ ALARM_WEEK_FLAG_MONDAY = 0x02, /**< Monday */
+ ALARM_WEEK_FLAG_TUESDAY = 0x04, /**< Tuesday */
+ ALARM_WEEK_FLAG_WEDNESDAY = 0x08, /**< Wednesday */
+ ALARM_WEEK_FLAG_THURSDAY = 0x10, /**< Thursday */
+ ALARM_WEEK_FLAG_FRIDAY = 0x20, /**< Friday */
+ ALARM_WEEK_FLAG_SATURDAY = 0x40 /**< Saturday */
+} alarm_week_flag_e;
+
+/**
+ * @brief Called once for each scheduled alarm to get the alarm ID.
+ *
+ * @param[in] alarm_id The alarm ID returned when the alarm is scheduled
+ * @param[in] user_data The user data passed from the foreach function
+ * @return @c true to continue with the next iteration of the loop, \n @c false to break out of the loop.
+ * @pre alarm_foreach_registered_alarm() will invoke this callback to get all registered alarm IDs.
+ * @see alarm_foreach_registered_alarm()
+ */
+typedef bool (*alarm_registered_alarm_cb)(int alarm_id, void *user_data);
+
+/**
+ * @brief Sets an alarm to be triggered after specific time.
+ * @details The alarm will first go off @a delay seconds later and then will go off every certain amount of time defined using @a period seconds.
+ * If @a period is bigger than 0, the alarm will be scheduled after the @a period time.
+ * If @a period is set to 0, the alarm will go off just once without repetition.
+ * To cancel the alarm, call alarm_cancel() with @alarm_id
+ *
+ * @remarks If application is uninstalled after setting an alarm, the alarm is canceled automatically.
+ *
+ * @param[in] service The destination service to perform specific work when the alarm is triggered.
+ * @param[in] delay The amount of time before first execution(in second)
+ * @param[in] period The amount of time between subsequent alarms(in second)
+ * @param[out] alarm_id The alarm ID uniquely identifies an alarm
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #ALARM_ERROR_NONE Successful
+ * @retval #ALARM_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #ALARM_ERROR_INVALID_TIME Triggered time is invalid
+ * @retval #ALARM_ERROR_CONNECTION_FAIL Failed to connect to an alarm server
+ * @see alarm_cancel()
+ * @see alarm_cancel_all()
+ * @see alarm_get_scheduled_date()
+ * @see alarm_get_scheduled_period()
+ */
+int alarm_schedule_after_delay(service_h service, int delay, int period, int *alarm_id);
+
+
+/**
+ * @brief Sets an alarm to be triggered at a specific time.
+ * @details
+ * The @a date describes the time of first occurrence.
+ * If @a period is bigger than 0, the alarm will be scheduled after the @a period time.
+ * If @a period is set to 0, the alarm will go off just once without repetition.
+ * To cancel the alarm, call alarm_cancel() with alarm id
+ *
+ * @remarks If application is uninstalled after setting an alarm, the alarm is canceled automatically.
+ *
+ * @param[in] service The destination service to perform specific work when the alarm is triggered
+ * @param[in] date The first active alarm time
+ * @param[in] period The amount of time between subsequent alarms(in second)
+ * @param[out] alarm_id The alarm ID uniquely identifies an alarm
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #ALARM_ERROR_NONE Successful
+ * @retval #ALARM_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #ALARM_ERROR_INVALID_DATE Triggered date is invalid
+ * @retval #ALARM_ERROR_CONNECTION_FAIL Failed to connect to an alarm server
+ * @see alarm_cancel()
+ * @see alarm_cancel_all()
+ * @see alarm_get_scheduled_date()
+ * @see alarm_get_scheduled_period()
+ */
+int alarm_schedule_at_date(service_h service, struct tm *date, int period, int *alarm_id);
+
+
+/**
+ * @brief Sets an alarm to be triggered at a specific time with recurrence repeat.
+ * @details
+ * The @a date describes the time of first occurrence.
+ * @a week_flag is the repeat value of days of the week. If @a week_flag is #ALARM_WEEK_FLAG_TUESDAY, the alarm will repeat at every Tuesday specific time.
+ * To cancel the alarm, call alarm_cancel() with the @alarm_id
+ * @remarks If application is uninstalled after setting an alarm, the alarm is canceled automatically.
+ *
+ * @param[in] service The destination service to perform specific work when the alarm is triggered.
+ * @param[in] date The first active alarm time
+ * @param[in] week_flag The day of the week, @a week_flag may be a combination of days, like #ALARM_WEEK_FLAG_TUESDAY | #ALARM_WEEK_FLAG_FRIDAY.
+ * @param[out] alarm_id The alarm ID uniquely identifies an alarm
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #ALARM_ERROR_NONE Successful
+ * @retval #ALARM_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #ALARM_ERROR_INVALID_DATE Triggered date is invalid
+ * @retval #ALARM_ERROR_CONNECTION_FAIL Failed to connect to an alarm server
+ * @see alarm_cancel()
+ * @see alarm_cancel_all()
+ * @see alarm_get_scheduled_recurrence_week_flag()
+ * @see alarm_get_scheduled_recurrence_week_flag()
+ * @see alarm_get_scheduled_date()
+ * @see #alarm_week_flag_e
+ */
+int alarm_schedule_with_recurrence_week_flag(service_h service, struct tm *date, int week_flag,int *alarm_id);
+
+
+/**
+ * @brief Gets the recurrence days of the week.
+ * @remarks If the given @a alarm_id is not obtained by using the alarm_schedule_with_recurrence_week_flag() function,
+ * an error (error code #ALARM_ERROR_INVALID_PARAMETER) will occur because this alarm is scheduled with no recurrence.
+ * @param[in] alarm_id The alarm ID returned when the alarm is scheduled
+ * @param[out] week_flag The recurrence days of the week, @a week_flag may be a combination of days, like #ALARM_WEEK_FLAG_TUESDAY | #ALARM_WEEK_FLAG_FRIDAY.
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #ALARM_ERROR_NONE Successful
+ * @retval #ALARM_ERROR_INVALID_PARAMETER Invalid parameter
+ * @see alarm_schedule_with_recurrence_week_flag()
+ * @see #alarm_week_flag_e
+ */
+int alarm_get_scheduled_recurrence_week_flag(int alarm_id, int *week_flag);
+
+
+/**
+ * @brief Cancels the alarm with the specific alarm ID.
+ * @param[in] alarm_id The alarm ID that will be canceled
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #ALARM_ERROR_NONE Successful
+ * @retval #ALARM_ERROR_CONNECTION_FAIL Failed to connect to an alarm server
+ * @see alarm_schedule_at_date()
+ * @see alarm_schedule_after_delay()
+ * @see alarm_schedule_with_recurrence_week_flag()
+ * @see alarm_cancel_all()
+ */
+int alarm_cancel(int alarm_id);
+
+
+/**
+ * @brief Cancels all alarms scheduled.
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #ALARM_ERROR_NONE Successful
+ * @retval #ALARM_ERROR_CONNECTION_FAIL Failed to connect to an alarm server
+ * @see alarm_schedule_at_date()
+ * @see alarm_schedule_after_delay()
+ * @see alarm_schedule_with_recurrence_week_flag()
+ * @see alarm_cancel()
+ */
+int alarm_cancel_all(void);
+
+
+/**
+ * @brief Retrieves the IDs of all registered alarms by invoking callback once for each scheduled alarm.
+ *
+ * @param[in] callback The callback function to invoke
+ * @param[in] user_data The user data to be passed to the callback function
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #ALARM_ERROR_NONE Successful
+ * @retval #ALARM_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #ALARM_ERROR_CONNECTION_FAIL Failed to connect to an alarm server
+ * @post This function invokes alarm_registered_alarm_cb() repeatedly for each registered alarm.
+ * @see alarm_registered_alarm_cb()
+ */
+int alarm_foreach_registered_alarm(alarm_registered_alarm_cb callback, void *user_data);
+
+
+/**
+ * @brief Gets the scheduled time from the given alarm ID in C standard time struct.
+ *
+ * @param[in] alarm_id The alarm ID returned when the alarm is scheduled
+ * @param[out] date The time value of next alarm event
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #ALARM_ERROR_NONE Successful
+ * @retval #ALARM_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #ALARM_ERROR_CONNECTION_FAIL Failed to connect to an alarm server
+ * @see alarm_schedule_at_date()
+ * @see alarm_schedule_after_delay()
+ * @see alarm_schedule_with_recurrence_week_flag()
+ */
+int alarm_get_scheduled_date(int alarm_id, struct tm *date);
+
+
+/**
+ * @brief Gets the period of time between the recurrent alarms.
+ * @remarks If the given @a alarm_id is not obtained by using the alarm_get_scheduled_date() or alarm_schedule_after_delay() function,
+ * an error (error code #ALARM_ERROR_INVALID_PARAMETER) will occur.
+ * @param[in] alarm_id The alarm ID returned when the alarm is scheduled
+ * @param[out] period The period of time between recurrent alarms in seconds
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #ALARM_ERROR_NONE Successful
+ * @retval #ALARM_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #ALARM_ERROR_CONNECTION_FAIL Failed to connect to an alarm server
+ * @see alarm_schedule_at_date()
+ * @see alarm_schedule_after_delay()
+ * @see alarm_schedule_with_recurrence_week_flag()
+ */
+int alarm_get_scheduled_period(int alarm_id, int *period);
+
+
+/**
+ * @brief Gets the current system time using C standard time struct.
+ *
+ * @param[out] date The current system time
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #ALARM_ERROR_NONE Successful
+ * @retval #ALARM_ERROR_INVALID_PARAMETER Invalid parameter
+ */
+int alarm_get_current_time(struct tm *date);
+
+/**
+ * @}
+ */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __TIZEN_APPFW_ALARM_H__ */
+
diff --git a/include/app_i18n.h b/include/app_i18n.h
new file mode 100755
index 0000000..d6f1e81
--- /dev/null
+++ b/include/app_i18n.h
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2011 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_I18N_H__
+#define __TIZEN_APPFW_I18N_H__
+
+#include <tizen.h>
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /**
+ * @addtogroup CAPI_I18N_MODULE
+ * @{
+ */
+
+/**
+ * @brief Marks a string for translation, gets replaced with the translated string at runtime.
+ * @param [in] msg The string to be translated.
+ */
+#define _(msg) i18n_get_text(msg)
+
+/**
+ * @brief Gets the localized translation for the specified string.
+ *
+ * @details If a translation was not found in the localization file(.po file), @a message is returned.
+ *
+ * @remarks Do not free returned value
+ *
+ * @param [in] message The string to be translated
+ * @return The localized translation for the given @a message on success, otherwise the given @a message.
+ */
+char* i18n_get_text(const char *message);
+
+/**
+ * @}
+ */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __TIZEN_APPFW_I18N_H__ */
diff --git a/include/app_preference.h b/include/app_preference.h
new file mode 100755
index 0000000..9aeb3af
--- /dev/null
+++ b/include/app_preference.h
@@ -0,0 +1,295 @@
+/*
+ * Copyright (c) 2011 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_PREFERENCE_H__
+#define __TIZEN_APPFW_PREFERENCE_H__
+
+#include <tizen.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @addtogroup CAPI_PREFERENCE_MODULE
+ * @{
+ */
+
+
+/**
+ * @brief Enumerations of error code for Preference.
+ */
+typedef enum
+{
+ PREFERENCE_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */
+ PREFERENCE_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */
+ PREFERENCE_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory */
+ PREFERENCE_ERROR_NO_KEY = TIZEN_ERROR_KEY_NOT_AVAILABLE, /**< Required key not available */
+ PREFERENCE_ERROR_IO_ERROR = TIZEN_ERROR_IO_ERROR , /**< Internal I/O Error */
+} preference_error_e;
+
+
+/**
+ * @brief Called when the given key's value in the preference changes.
+ *
+ * @details When the @a key is added or removed, this callback function is skipped. (only update can be handled)
+ *
+ * @param [in] key The name of the key in the preference
+ * @param [in] user_data The user data passed from the callback registration function
+ * @pre This function is invoked when the value of the key is overwritten after you register this callback using preference_set_changed_cb()
+ * @see preference_set_changed_cb()
+ * @see preference_unset_changed_cb()
+ * @see preference_set_boolean()
+ * @see preference_set_int()
+ * @see preference_set_string()
+ * @see preference_set_double()
+ */
+typedef void (*preference_changed_cb) (const char *key, void *user_data);
+
+
+/**
+* @brief Called to get key string once for each key-value pair in the preference.
+*
+* @remarks You should not free @a key returned by this function.
+*
+* @param [in] key The key of the value added to the preference
+* @param [in] value The value associated with the key
+* @param [in] user_data The user data passed from the foreach function
+* @return @c true to continue with the next iteration of the loop, \n @c false to break out of the loop.
+* @pre preference_foreach_item() will invoke this callback function.
+* @see preference_foreach_item()
+*/
+typedef bool (*preference_item_cb)(const char *key, void *user_data);
+
+
+/**
+ * @brief Sets an integer value in the preference.
+ *
+ * @param [in] key The name of the key to modify
+ * @param [in] value The new @c int value for the given key
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #PREFERENCE_ERROR_NONE Successful
+ * @retval #PREFERENCE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #PREFERENCE_ERROR_IO_ERROR Internal I/O Error
+ * @see preference_get_int()
+ *
+ */
+int preference_set_int(const char *key, int value);
+
+
+/**
+ * @brief Gets a integer value from the preference.
+ *
+ * @param [in] key The name of the key to retrieve
+ * @param [out] value The @c int value for the given key
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #PREFERENCE_ERROR_NONE Successful
+ * @retval #PREFERENCE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #PREFERENCE_ERROR_NO_KEY Required key not available
+ * @retval #PREFERENCE_ERROR_IO_ERROR Internal I/O Error
+ * @see preference_set_int()
+ */
+int preference_get_int(const char *key, int *value);
+
+
+/**
+ * @brief Sets a double value in the preference.
+ *
+ * @param [in] key The name of the key to modify
+ * @param [in] value The new @c double value associated with given key
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #PREFERENCE_ERROR_NONE Successful
+ * @retval #PREFERENCE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #PREFERENCE_ERROR_IO_ERROR Internal I/O Error
+ * @see preference_get_double()
+ *
+ */
+int preference_set_double(const char *key, double value);
+
+
+/**
+ * @brief Gets a double value from the preference.
+ *
+ * @param [in] key The name of the key to retrieve
+ * @param [out] value The @c double value associated with given key
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #PREFERENCE_ERROR_NONE Successful
+ * @retval #PREFERENCE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #PREFERENCE_ERROR_NO_KEY Required key not available
+ * @retval #PREFERENCE_ERROR_IO_ERROR Internal I/O Error
+ * @see preference_set_double()
+ *
+ */
+int preference_get_double(const char *key, double *value);
+
+
+/**
+ * @brief Sets a string value in the preference.
+ *
+ * @details It makes a deep copy of the added string value.
+ *
+ * @param [in] key The name of the key to modify
+ * @param [in] value The new @c string value associated with given key
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #PREFERENCE_ERROR_NONE Successful
+ * @retval #PREFERENCE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #PREFERENCE_ERROR_IO_ERROR Internal I/O Error
+ * @see preference_get_string()
+ *
+ */
+int preference_set_string(const char *key, const char *value);
+
+
+/**
+ * @brief Gets a string value from the preference.
+ *
+ * @remarks @a value must be released with free() by you.
+ * @param [in] key The name of the key to retrieve
+ * @param [out] value The @c string value associated with given key
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #PREFERENCE_ERROR_NONE Successful
+ * @retval #PREFERENCE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #PREFERENCE_ERROR_OUT_OF_MEMORY Out of memory
+ * @retval #PREFERENCE_ERROR_NO_KEY Required key not available
+ * @retval #PREFERENCE_ERROR_IO_ERROR Internal I/O Error
+ * @see preference_set_string()
+ */
+int preference_get_string(const char *key, char **value);
+
+
+/**
+ * @brief Sets a boolean value in the preference.
+ *
+ * @param [in] key The name of the key to modify
+ * @param [in] value The new boolean @c value associated with given key
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #PREFERENCE_ERROR_NONE Successful
+ * @retval #PREFERENCE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #PREFERENCE_ERROR_IO_ERROR Internal I/O Error
+ * @see preference_get_boolean()
+ */
+int preference_set_boolean(const char *key, bool value);
+
+
+/**
+ * @brief Gets a boolean value from the preference.
+ *
+ * @param [in] key The name of the key to retrieve
+ * @param [out] value The boolean @c value associated with given key
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #PREFERENCE_ERROR_NONE Successful
+ * @retval #PREFERENCE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #PREFERENCE_ERROR_NO_KEY Required key not available
+ * @retval #PREFERENCE_ERROR_IO_ERROR Internal I/O Error
+ * @see preference_set_boolean()
+ */
+int preference_get_boolean(const char *key, bool *value);
+
+
+/**
+ * @brief Removes any value with the given @a key from the preference.
+ *
+ * @param [in] key The name of the key to remove
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #PREFERENCE_ERROR_NONE Successful
+ * @retval #PREFERENCE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #PREFERENCE_ERROR_IO_ERROR Internal I/O Error
+ *
+ */
+int preference_remove(const char *key);
+
+
+/**
+ * @brief Checks whether if the given @a key exists in the preference.
+ *
+ * @param [in] key The name of the key to check
+ * @param [out] existing @c true if the @a key exists in the preference, otherwise @c false
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #PREFERENCE_ERROR_NONE Successful
+ * @retval #PREFERENCE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #PREFERENCE_ERROR_IO_ERROR Internal I/O Error
+ */
+int preference_is_existing(const char *key, bool *existing);
+
+
+/**
+ * @brief Removes all key-value pairs from the preference.
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #PREFERENCE_ERROR_NONE Successful
+ * @retval #PREFERENCE_ERROR_IO_ERROR Internal I/O Error
+ * @see preference_remove()
+ */
+int preference_remove_all(void);
+
+
+/**
+ * @brief Registers a callback function to be invoked when value of the given key in the preference changes.
+ *
+ * @param [in] key The name of the key to monitor
+ * @param [in] callback The callback function to register
+ * @param [in] user_data The user data to be passed to the callback function
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #PREFERENCE_ERROR_NONE Successful
+ * @retval #PREFERENCE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #PREFERENCE_ERROR_OUT_OF_MEMORY Out of memory
+ * @retval #PREFERENCE_ERROR_NO_KEY Required key not available
+ * @retval #PREFERENCE_ERROR_IO_ERROR Internal I/O Error
+ * @post preference_changed_cb() will be invoked.
+ * @see preference_unset_changed_cb()
+ * @see preference_changed_cb()
+ */
+int preference_set_changed_cb(const char *key, preference_changed_cb callback, void *user_data);
+
+
+/**
+ * @brief Unregisters the callback function.
+ *
+ * @param [in] key The name of the key to monitor
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #PREFERENCE_ERROR_NONE Successful
+ * @retval #PREFERENCE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #PREFERENCE_ERROR_IO_ERROR Internal I/O Error
+ * @see preference_set_changed_cb()
+ */
+int preference_unset_changed_cb(const char *key);
+
+
+/**
+ * @brief Retrieves all key-value pairs in the preference by invoking the callback function.
+ *
+ * @param [in] callback The callback function to get key value once for each key-value pair in the preference
+ * @param [in] user_data The user data to be passed to the callback function
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #PREFERENCE_ERROR_NONE Successful
+ * @retval #PREFERENCE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #PREFERENCE_ERROR_IO_ERROR Internal I/O Error
+ * @post This function invokes preference_item_cb() repeatedly to get each key-value pair in the preference.
+ * @see preference_item_cb()
+ */
+int preference_foreach_item(preference_item_cb callback, void *user_data);
+
+
+/**
+ * @}
+ */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __TIZEN_APPFW_PREFERENCE_H__ */
diff --git a/include/app_preference_private.h b/include/app_preference_private.h
new file mode 100755
index 0000000..76000ad
--- /dev/null
+++ b/include/app_preference_private.h
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2011 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_PREFERENCE_PRIVATE_H__
+#define __TIZEN_APPFW_PREFERENCE_PRIVATE_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define PREF_DB_NAME ".pref.db"
+#define PREF_TBL_NAME "pref"
+#define PREF_F_KEY_NAME "pref_key"
+#define PREF_F_TYPE_NAME "pref_type"
+#define PREF_F_DATA_NAME "pref_data"
+#define BUF_LEN (1024)
+
+typedef enum
+{
+ PREFERENCE_TYPE_INT = 1,
+ PREFERENCE_TYPE_BOOLEAN,
+ PREFERENCE_TYPE_DOUBLE,
+ PREFERENCE_TYPE_STRING
+} preference_type_e;
+
+typedef struct _pref_changed_cb_node_t{
+ char *key;
+ preference_changed_cb cb;
+ void *user_data;
+ struct _pref_changed_cb_node_t *prev;
+ struct _pref_changed_cb_node_t *next;
+} pref_changed_cb_node_t;
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __TIZEN_APPFW_PREFERENCE_PRIVATE_H__ */
diff --git a/include/app_private.h b/include/app_private.h
new file mode 100755
index 0000000..58be329
--- /dev/null
+++ b/include/app_private.h
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2011 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_APP_PRIVATE_H__
+#define __TIZEN_APPFW_APP_PRIVATE_H__
+
+#include <appcore-common.h>
+
+// GNU gettext macro is already defined at appcore-common.h
+#ifdef _
+#undef _
+#endif
+
+#include <app.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define TIZEN_PATH_MAX 1024
+
+#define PATH_FMT_APP_ROOT "/opt/apps"
+#define PATH_FMT_RES_DIR PATH_FMT_APP_ROOT "/%s/res"
+#define PATH_FMT_LOCALE_DIR PATH_FMT_RES_DIR "/locale"
+#define PATH_FMT_DATA_DIR PATH_FMT_APP_ROOT "/%s/data"
+
+typedef void (*app_terminate_task_cb) (void *data);
+
+typedef struct app_terminate_task_s
+{
+ app_terminate_task_cb cb;
+ void *data;
+} app_terminate_task_t;
+
+int app_add_terminate_task(app_terminate_task_cb callback, void *data);
+
+app_device_orientation_e app_convert_appcore_rm(enum appcore_rm rm);
+
+int app_get_project_name(const char *package, char **name);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __TIZEN_APPFW_APP_PRIVATE_H__ */
diff --git a/include/app_service.h b/include/app_service.h
new file mode 100755
index 0000000..6e853ad
--- /dev/null
+++ b/include/app_service.h
@@ -0,0 +1,577 @@
+/*
+ * Copyright (c) 2011 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_SERVICE_H__
+#define __TIZEN_APPFW_SERVICE_H__
+
+#include <tizen.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @addtogroup CAPI_SERVICE_MODULE
+ * @{
+ */
+
+
+/**
+ * @brief Service handle.
+ */
+typedef struct service_s *service_h;
+
+
+/**
+ * @brief Enumerations of error code for Service.
+ */
+typedef enum
+{
+ SERVICE_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */
+ SERVICE_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */
+ SERVICE_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory */
+ SERVICE_ERROR_APP_NOT_FOUND = TIZEN_ERROR_APPLICATION_CLASS | 0x21, /**< The application was not found */
+ SERVICE_ERROR_KEY_NOT_FOUND = TIZEN_ERROR_KEY_NOT_AVAILABLE, /**< Specified key not found */
+ SERVICE_ERROR_KEY_REJECTED = TIZEN_ERROR_KEY_REJECTED, /**< Not available key */
+ SERVICE_ERROR_INVALID_DATA_TYPE = TIZEN_ERROR_APPLICATION_CLASS | 0x22, /**< Invalid data type */
+} service_error_e;
+
+
+/**
+ * @brief Enumeration of service result.
+ */
+typedef enum
+{
+ SERVICE_RESULT_SUCCEEDED = 0, /**< Operation succeeded */
+ SERVICE_RESULT_FAILED = -1, /**< Operation failed by the callee */
+ SERVICE_RESULT_CANCELED = -2, /**< Operation canceled by the framework */
+} service_result_e;
+
+
+/**
+ * @brief Service operation : default operation for explicit launch
+ */
+#define SERVICE_OPERATION_DEFAULT "slp.appsvc.operation.DEFAULT"
+
+
+/**
+ * @brief Service operation : provide explicit editable access to the given data.
+ */
+#define SERVICE_OPERATION_EDIT "slp.appsvc.operation.EDIT"
+
+
+/**
+ * @brief Service operation : display the data.
+ */
+#define SERVICE_OPERATION_VIEW "slp.appsvc.operation.VIEW"
+
+
+/**
+ * @brief Service operation : pick an item from the data, returning what was selected.
+ */
+#define SERVICE_OPERATION_PICK "slp.appsvc.operation.PICK"
+
+
+/**
+ * @brief Service operation : create a content, returning what was created.
+ */
+#define SERVICE_OPERATION_CREATE_CONTENT "slp.appsvc.operation.CREATE_CONTENT"
+
+
+/**
+ * @brief Service operation : perform a call to someone specified by the data.
+ */
+#define SERVICE_OPERATION_CALL "slp.appsvc.operation.CALL"
+
+
+/**
+ * @brief Service operation : deliver some data to someone else.
+ */
+#define SERVICE_OPERATION_SEND "slp.appsvc.operation.SEND"
+
+
+/**
+ * @brief Service operation : deliver text data to someone else.
+ */
+#define SERVICE_OPERATION_SEND_TEXT "slp.appsvc.operation.SEND_TEXT"
+
+
+/**
+ * @brief Service operation : dial a number as specified by the data.
+ */
+#define SERVICE_OPERATION_DIAL "slp.appsvc.operation.DIAL"
+
+
+/**
+ * @brief Service operation : perform a search.
+ */
+#define SERVICE_OPERATION_SEARCH "slp.appsvc.operation.SEARCH"
+
+
+/**
+ * @brief Service optional data : the subject of a message.
+ */
+#define SERVICE_DATA_SUBJECT "slp.appsvc.data.SUBJECT"
+
+
+/**
+ * @brief Service optional data : e-mail addresses.
+ */
+#define SERVICE_DATA_TO "slp.appsvc.data.TO"
+
+
+/**
+ * @brief Service optional data : e-mail addresses that should be carbon copied.
+ */
+#define SERVICE_DATA_CC "slp.appsvc.data.CC"
+
+
+/**
+ * @brief Service optional data : e-mail addresses that should be blind carbon copied.
+ */
+#define SERVICE_DATA_BCC "slp.appsvc.data.BCC"
+
+
+/**
+ * @brief Service optional data : the content of the data is associated with #SERVICE_OPERATION_SEND.
+ */
+#define SERVICE_DATA_TEXT "slp.appsvc.data.TEXT"
+
+
+/**
+ * @brief Service optional data : the title of the data
+ */
+#define SERVICE_DATA_TITLE "slp.appsvc.data.TITLE"
+
+
+/**
+ * @brief Service optional data : the path of selected item.
+ */
+#define SERVICE_DATA_SELECTED "slp.appsvc.data.SELECTED"
+
+
+/**
+ * @brief Called when the reply of the launch request is delivered.
+ *
+ * @param [in] request The service handle of the launch request that has sent
+ * @param [in] reply The service handle in which the results of the callee are contained
+ * @param [in] result The result code of the launch request
+ * @param [in] user_data The user data passed from the callback registration function
+ * @pre When the callee replies to the launch request, this callback will be invoked.
+ * @see service_send_launch_request()
+ * @see service_reply_to_launch_request()
+ */
+typedef void (*service_reply_cb) (service_h request, service_h reply, service_result_e result, void *user_data);
+
+
+/**
+* @brief Called to retrieve the extra data that are contained in the service
+*
+* @remarks The @a key must not be deallocated by an application.
+*
+* @param[in] service The service handle
+* @param[in] key The key of the value contained in the service
+* @param[in] user_data The user data passed from the foreach function
+* @return @c true to continue with the next iteration of the loop, \n @c false to break out of the loop.
+* @pre service_foreach_extra_data() will invoke this callback.
+* @see service_foreach_extra_data()
+*/
+typedef bool (*service_extra_data_cb)(service_h service, const char *key, void *user_data);
+
+
+/**
+* @brief Called once for each matched application that can be launched to handle the given service request.
+*
+* @param [in] service The service handle
+* @param [in] package The package name of the application that can handle the launch request of the given service.
+* @param [in] user_data The user data passed from the foreach function
+* @return @c true to continue with the next iteration of the loop, \n @c false to break out of the loop.
+* @pre service_foreach_app_matched() will invoke this callback.
+* @see service_foreach_app_matched()
+*/
+typedef bool (*service_app_matched_cb)(service_h service, const char *package, void *user_data);
+
+
+/**
+ * @brief Creates a service handle.
+ *
+ * @remarks The @a service must be released with service_destroy() by you.
+ * @param [out] service A service handle to be newly created on success
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #SERVICE_ERROR_NONE Successful
+ * @retval #SERVICE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #SERVICE_ERROR_OUT_OF_MEMORY Out of memory
+ * @see service_destroy()
+ */
+int service_create(service_h *service);
+
+
+/**
+ * @brief Destroys the service handle and releases all its resources.
+ *
+ * @param [in] service The service handle
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #SERVICE_ERROR_NONE Successful
+ * @retval #SERVICE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #SERVICE_ERROR_OUT_OF_MEMORY Out of memory
+ * @see service_create()
+ */
+int service_destroy(service_h service);
+
+
+/**
+ * @brief Sets the operation to be performed.
+ *
+ * @details The @a operation is the mandatory information for the launch request.
+ * If the operation is not specified, #SERVICE_OPERATION_DEFAULT is used for the launch request.
+ * If the operation is #SERVICE_OPERATION_DEFAULT, the package information is mandatory to explicitly launch the application
+ * @param [in] service The service handle
+ * @param [in] operation The operation to be performed
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #SERVICE_ERROR_NONE Successful
+ * @retval #SERVICE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @see service_get_operation()
+ * @see SERVICE_OPERATION_DEFAULT
+ * @see SERVICE_OPERATION_EDIT
+ * @see SERVICE_OPERATION_VIEW
+ * @see SERVICE_OPERATION_PICK
+ * @see SERVICE_OPERATION_CREATE_CONTENT
+ * @see SERVICE_OPERATION_CALL
+ * @see SERVICE_OPERATION_SEND
+ * @see SERVICE_OPERATION_SEND_TEXT
+ * @see SERVICE_OPERATION_DIAL
+ * @see SERVICE_OPERATION_SEARCH
+ */
+int service_set_operation(service_h service, const char *operation);
+
+
+/**
+ * @brief Gets the operation to be performed.
+ *
+ * @remarks The @a operation must be released with free() by you.
+ * @param [in] service The service handle
+ * @param [out] operation The operation to be performed
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #SERVICE_ERROR_NONE Successful
+ * @retval #SERVICE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #SERVICE_ERROR_OUT_OF_MEMORY Out of memory
+ * @see service_set_operation()
+ */
+int service_get_operation(service_h service, char **operation);
+
+
+/**
+ * @brief Sets the URI of the data.
+ *
+ * @param [in] service The service handle
+ * @param [in] uri The URI of the data this service is operating on
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #SERVICE_ERROR_NONE Successful
+ * @retval #SERVICE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @see service_get_uri()
+ */
+int service_set_uri(service_h service, const char *uri);
+
+
+/**
+ * @brief Gets the URI of the data.
+ *
+ * @remarks The @a uri must be released with free() by you.
+ * @param [in] service The service handle
+ * @param [out] uri The URI of the data this service is operating on
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #SERVICE_ERROR_NONE Successful
+ * @retval #SERVICE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #SERVICE_ERROR_OUT_OF_MEMORY Out of memory
+ * @see service_set_uri()
+ */
+int service_get_uri(service_h service, char **uri);
+
+
+/**
+ * @brief Sets the explicit MIME type of the data
+ *
+ * @param [in] service The service handle
+ * @param [in] mime the explicit MIME type of the data this service is operating on
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #SERVICE_ERROR_NONE Successful
+ * @retval #SERVICE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @see service_get_mime()
+ */
+int service_set_mime(service_h service, const char *mime);
+
+
+/**
+ * @brief Gets the explicit MIME type of the data.
+ *
+ * @remarks The @a uri must be released with free() by you.
+ * @param [in] service The service handle
+ * @param [out] mime The explicit MIME type of the data this service is operating on
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #SERVICE_ERROR_NONE Successful
+ * @retval #SERVICE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #SERVICE_ERROR_OUT_OF_MEMORY Out of memory
+ * @see service_set_mime()
+ */
+int service_get_mime(service_h service, char **uri);
+
+
+/**
+ * @brief Sets the package name of the application to explicitly launch
+ *
+ * @param [in] service The service handle
+ * @param [in] package The package name of the application to explicitly launch
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #SERVICE_ERROR_NONE Successful
+ * @retval #SERVICE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #SERVICE_ERROR_OUT_OF_MEMORY Out of memory
+ * @see service_get_package()
+ */
+int service_set_package(service_h service, const char *package);
+
+
+/**
+ * @brief Gets the package name of the application to explicitly launch
+ *
+ * @remarks The @a package must be released with free() by you.
+ * @param [in] service The service handle
+ * @param [out] package The package name of the application to explicitly launch
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #SERVICE_ERROR_NONE Successful
+ * @retval #SERVICE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #SERVICE_ERROR_OUT_OF_MEMORY Out of memory
+ * @see service_set_package()
+ */
+int service_get_package(service_h service, char **package);
+
+
+/**
+ * @brief Adds the extra data to the service.
+ *
+ * @remarks The function replaces any existing value for the given key.
+ * @remarks The function returns #SERVICE_ERROR_INVALID_PARAMETER if key or value is zero-length string.
+ * @remarks The function returns #SERVICE_ERROR_KEY_REJECTED if the application tries to use same key with system-defined key
+ * @param [in] service The service handle
+ * @param [in] key The name of the extra data
+ * @param [in] value The value associated with given key
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #SERVICE_ERROR_NONE Successful
+ * @retval #SERVICE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #SERVICE_ERROR_KEY_REJECTED Not available key
+ * @see service_add_extra_data_array()
+ * @see service_remove_extra_data()
+ * @see service_get_extra_data()
+ */
+int service_add_extra_data(service_h service, const char *key, const char *value);
+
+
+/**
+ * @brief Adds the extra data array to the service.
+ *
+ * @remarks The function replaces any existing value for the given key.
+ * @remarks The function returns #SERVICE_ERROR_INVALID_PARAMETER if key is zero-length string.
+ * @remarks The function returns #SERVICE_ERROR_KEY_REJECTED if the application tries to use same key with system-defined key
+ * @param [in] service The service handle
+ * @param [in] key The name of the extra data
+ * @param [in] value The array value associated with given key
+ * @param [in] length The length of the array
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #SERVICE_ERROR_NONE Successful
+ * @retval #SERVICE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #SERVICE_ERROR_KEY_REJECTED Not available key
+ * @see service_add_extra_data()
+ * @see service_remove_extra_data()
+ * @see service_get_extra_data()
+ */
+int service_add_extra_data_array(service_h service, const char *key, const char* value[], int length);
+
+
+/**
+ * @brief Removes the extra data from the service.
+ *
+ * @param [in] service The service handle
+ * @param [in] key The name of the extra data
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #SERVICE_ERROR_NONE Successful
+ * @retval #SERVICE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #SERVICE_ERROR_KEY_NOT_FOUND Specified key not found
+ * @see service_add_extra_data()
+ * @see service_add_extra_data_array()
+ * @see service_get_extra_data()
+ */
+int service_remove_extra_data(service_h service, const char *key);
+
+
+/**
+ * @brief Gets the extra data from the service.
+ *
+ * @remarks The @a value must be released with free() by you.
+ * @remarks The function returns #SERVICE_ERROR_INVALID_DATA_TYPE if the value is array data type.
+ * @param [in] service The service handle
+ * @param [int] key The name of the extra data
+ * @param [out] value The value associated with given key
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #SERVICE_ERROR_NONE Successful
+ * @retval #SERVICE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #SERVICE_ERROR_KEY_NOT_FOUND Specified key not found
+ * @retval #SERVICE_ERROR_OUT_OF_MEMORY Out of memory
+ * @retval #SERVICE_ERROR_INVALID_DATA_TYPE Invalid data type
+ * @see service_add_extra_data()
+ * @see service_add_extra_data_array()
+ * @see service_get_extra_data()
+ * @see service_remove_extra_data()
+ * @see service_foreach_extra_data()
+ */
+int service_get_extra_data(service_h service, const char *key, char **value);
+
+
+/**
+ * @brief Gets the extra data array from the service.
+ *
+ * @remarks The @a value must be released with free() by you.
+ * @remarks The function returns #SERVICE_ERROR_INVALID_DATA_TYPE if the value is not array data type.
+ * @param [in] service The service handle
+ * @param [int] key The name of the extra data
+ * @param [out] value The array value associated with given key
+ * @param [out] length The length of the array
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #SERVICE_ERROR_NONE Successful
+ * @retval #SERVICE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #SERVICE_ERROR_KEY_NOT_FOUND Specified key not found
+ * @retval #SERVICE_ERROR_OUT_OF_MEMORY Out of memory
+ * @retval #SERVICE_ERROR_INVALID_DATA_TYPE Invalid data type
+ * @see service_add_extra_data()
+ * @see service_add_extra_data_array()
+ * @see service_remove_extra_data()
+ * @see service_foreach_extra_data()
+ */
+int service_get_extra_data_array(service_h service, const char *key, char ***value, int *length);
+
+
+/**
+ * @brief Checks whether if the extra data associated with given @a key is array data type.
+ *
+ * @param [in] service The service handle
+ * @param [int] key The name of the extra data
+ * @param [out] array @c True if the extra data is array data type, otherwise @c false
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #SERVICE_ERROR_NONE Successful
+ * @retval #SERVICE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #SERVICE_ERROR_KEY_NOT_FOUND Specified key not found
+ * @see service_add_extra_data()
+ * @see service_add_extra_data_array()
+ * @see service_remove_extra_data()
+ * @see service_foreach_extra_data()
+ */
+int service_is_extra_data_array(service_h service, const char *key, bool *array);
+
+
+/**
+ * @brief Retrieves all extra data contained in service.
+ * @details This function calls service_extra_data_cb() once for each key-value pair for extra data contained in service. \n
+ * If service_extra_data_cb() callback function returns false, then iteration will be finished.
+ *
+ * @param [in] service The service handle
+ * @param [in] callback The iteration 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 #SERVICE_ERROR_NONE Successful
+ * @retval #SERVICE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @post This function invokes service_extra_data_cb().
+ * @see service_extra_data_cb()
+ */
+int service_foreach_extra_data(service_h service, service_extra_data_cb callback, void *user_data);
+
+
+/**
+ * @brief Retrieves all applications that can be launched to handle the given service request.
+ *
+ * @param [in] service The service handle
+ * @param [in] callback The iteration 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 #SERVICE_ERROR_NONE Success
+ * @retval #SERVICE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @post This function invokes service_app_matched_cb().
+ * @see service_app_matched_cb()
+ */
+int service_foreach_app_matched(service_h service, service_app_matched_cb callback, void *user_data);
+
+
+/**
+ * @brief Sends the launch request.
+ *
+ * @details The operation is mandatory information for the launch request. \n
+ * If the operation is not specified, #SERVICE_OPERATION_DEFAULT is used by default.
+ * If the operation is #SERVICE_OPERATION_DEFAULT, the package information is mandatory to explicitly launch the application
+ * @param [in] service The service handle
+ * @param [in] callback The callback function to be called when the reply is delivered
+ * @param [in] user_data The user data to be passed to the callback function
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #SERVICE_ERROR_NONE Successful
+ * @retval #SERVICE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #SERVICE_ERROR_OUT_OF_MEMORY Out of memory
+ * @retval #SERVICE_ERROR_APP_NOT_FOUND The application was not found to run the given launch request
+ * @post If the launch request is sent for the result, the result will come back through service_reply_cb() from the callee application
+ * @see service_reply_to_launch_request()
+ * @see service_reply_cb()
+ */
+int service_send_launch_request(service_h service, service_reply_cb callback, void *user_data);
+
+
+/**
+ * @brief Replies to the launch request that the caller sent
+ * @details If the caller application sent the launch request to receive the result, the callee application can return the result back to the caller.
+ *
+ * @param [in] reply The service handle in which the results of the callee are contained
+ * @param [in] request The service handle that the caller sent
+ * @param [in] result The result code of the launch request
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #SERVICE_ERROR_NONE Successful
+ * @retval #SERVICE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #SERVICE_ERROR_OUT_OF_MEMORY Out of memory
+ * @see service_send_launch_request()
+ */
+int service_reply_to_launch_request(service_h reply, service_h request, service_result_e result);
+
+
+/**
+ * @brief Creates and returns a copy of the given service handle.
+ *
+ * @remarks A newly created service should be destroyed by calling service_destroy() if it is no longer needed.
+ *
+ * @param [out] clone If successful, a newly created service handle will be returned.
+ * @param [in] service The service handle
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #SERVICE_ERROR_NONE Successful
+ * @retval #SERVICE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #SERVICE_ERROR_OUT_OF_MEMORY Out of memory
+ * @see service_destroy()
+ */
+int service_clone(service_h *clone, service_h service);
+
+
+
+/**
+ * @}
+ */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __TIZEN_APPFW_SERVICE_H__ */
diff --git a/include/app_service_private.h b/include/app_service_private.h
new file mode 100755
index 0000000..172c823
--- /dev/null
+++ b/include/app_service_private.h
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2011 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_SERVICE_PRIVATE_H__
+#define __TIZEN_APPFW_SERVICE_PRIVATE_H__
+
+#include <bundle.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int service_to_bundle(service_h service, bundle **data);
+
+int service_create_event(bundle *data, service_h *service);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __TIZEN_APPFW_SERVICE_PRIVATE_H__ */
diff --git a/include/app_storage.h b/include/app_storage.h
new file mode 100755
index 0000000..0afe823
--- /dev/null
+++ b/include/app_storage.h
@@ -0,0 +1,226 @@
+/*
+ * Copyright (c) 2011 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_STORAGE_H__
+#define __TIZEN_APPFW_STORAGE_H__
+
+#include <tizen.h>
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /**
+ * @addtogroup CAPI_STORAGE_MODULE
+ * @{
+ */
+
+
+/**
+ * @brief Enumerations of error code for Storage.
+ */
+typedef enum
+{
+ STORAGE_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */
+ STORAGE_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */
+ STORAGE_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory */
+ STORAGE_ERROR_NOT_SUPPORTED = TIZEN_ERROR_NO_SUCH_DEVICE /**< Not supported storage */
+} storage_error_e;
+
+
+/**
+ * @brief Enumerations of the storage type.
+ */
+typedef enum
+{
+ STORAGE_TYPE_INTERNAL, /**< Internal device storage (built-in storage in a device, non-removable) */
+ STORAGE_TYPE_EXTERNAL, /**< External storage */
+} storage_type_e;
+
+
+/**
+ * @brief Enumerations of the state of storage device.
+ */
+typedef enum
+{
+ STORAGE_STATE_UNMOUNTABLE = -2, /**< Storage is present but cannot be mounted. Typically it happens if the file system of the storage is corrupted. */
+ STORAGE_STATE_REMOVED = -1, /**< Storage is not present. */
+ STORAGE_STATE_MOUNTED = 0, /**< Storage is present and mounted with read/write access. */
+ STORAGE_STATE_MOUNTED_READ_ONLY = 1, /**< Storage is present and mounted with read only access. */
+} storage_state_e;
+
+
+/**
+* @brief Called to get information once for each supported storage.
+*
+* @param [in] storage The unique storage ID
+* @param [in] type The type of the storage
+* @param [in] state The current state of the storage
+* @param [in] path The absolute path to the root directory of the @a storage
+* @param [in] user_data The user data passed from the foreach function
+* @return @c true to continue with the next iteration of the loop, \n @c false to break out of the loop.
+* @pre storage_foreach_device_supported() will invoke this callback function.
+* @see storage_foreach_device_supported()
+*/
+typedef bool (*storage_device_supported_cb)(int storage, storage_type_e type, storage_state_e state, const char *path, void *user_data);
+
+
+/**
+* @brief Called when the state of storage changes
+*
+* @param [in] storage The unique storage ID
+* @param [in] state The current state of the storage
+* @param [in] user_data The user data passed from the foreach function
+* @pre storage_set_state_changed_cb() will invoke this callback function.
+* @see storage_set_state_changed_cb()
+* @see storage_unset_state_changed_cb()
+*/
+typedef void (*storage_state_changed_cb)(int storage, storage_state_e state, void *user_data);
+
+
+/**
+ * @brief Retrieves all storage in device.
+ * @details This function invokes the callback function once for each @a storage in device. \n
+ * If storage_device_supported_cb() returns @c false, then iteration will be finished.
+ *
+ * @param [in] callback The iteration 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 #STORAGE_ERROR_NONE Successful
+ * @retval #STORAGE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @post This function invokes storage_device_supported_cb() repeatedly for each supported device.
+ * @see storage_device_supported_cb()
+ */
+int storage_foreach_device_supported(storage_device_supported_cb callback, void *user_data);
+
+
+/**
+ * @brief Gets the absolute path to the root directory of the given @a storage.
+ * @details
+ * Files saved on the internal/external storage are readable or writeable by all applications.
+ * When an application is uninstalled, the files written by that application are not removed from the internal/external storage.
+ *
+ * @remarks @a path must be released with free() by you.
+ *
+ * @param[in] storage The storage device
+ * @param[out] path The absolute path to the storage directory
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #STORAGE_ERROR_NONE Successful
+ * @retval #STORAGE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #STORAGE_ERROR_OUT_OF_MEMORY Out of memory
+ * @retval #STORAGE_ERROR_NOT_SUPPORTED Not supported storage
+ * @see storage_get_state()
+ */
+int storage_get_root_directory(int storage, char **path);
+
+
+/**
+ * @brief Gets the type of the given @a storage.
+ *
+ * @param[in] storage The storage device
+ * @param[out] type The type of the storage
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #STORAGE_ERROR_NONE Successful
+ * @retval #STORAGE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #STORAGE_ERROR_NOT_SUPPORTED Not supported storage
+ */
+int storage_get_type(int storage, storage_type_e *type);
+
+
+/**
+ * @brief Gets the current state of the given @a storage.
+ *
+ * @param[in] storage The storage device
+ * @param[out] state The current state of the storage,
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #STORAGE_ERROR_NONE Successful
+ * @retval #STORAGE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #STORAGE_ERROR_NOT_SUPPORTED Not supported storage
+ * @see storage_get_root_directory()
+ * @see storage_get_total_space()
+ * @see storage_get_available_space()
+ */
+int storage_get_state(int storage, storage_state_e *state);
+
+
+/**
+ * @brief Registers a callback function to be invoked when the state of the storage changes.
+ *
+ * @param[in] storage The storage device
+ * @param[in] callback The callback function to register
+ * @param[in] user_data The user data to be passed to the callback function
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #STORAGE_ERROR_NONE Successful
+ * @retval #STORAGE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #STORAGE_ERROR_NOT_SUPPORTED Not supported storage
+ * @post storage_state_changed_cb() will be invoked if the state of registered storage changes.
+ * @see storage_state_changed_cb()
+ * @see storage_unset_state_changed_cb()
+ */
+int storage_set_state_changed_cb(int storage, storage_state_changed_cb callback, void *user_data);
+
+
+/**
+ * @brief Unregisters the callback function.
+ *
+ * @param [in] storage The storage device to monitor
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #STORAGE_ERROR_NONE Successful
+ * @retval #STORAGE_ERROR_NOT_SUPPORTED Not supported storage
+ * @see storage_state_changed_cb()
+ * @see storage_set_state_changed_cb()
+ */
+int storage_unset_state_changed_cb(int storage);
+
+/**
+ * @brief Gets the total space of the given @a storage in bytes.
+ *
+ * @param[in] storage The storage device
+ * @param[out] bytes The total space size of the storage (bytes)
+ * @return 0 on success, otherwise a negative error value
+ * @retval #STORAGE_ERROR_NONE Successful
+ * @retval #STORAGE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #STORAGE_ERROR_NOT_SUPPORTED Not supported storage
+ * @see storage_get_state()
+ * @see storage_get_available_space()
+ */
+int storage_get_total_space(int storage, unsigned long long *bytes);
+
+/**
+ * @brief Gets the available space size of the given @a storage in bytes.
+ *
+ * @param[in] storage The storage device
+ * @param[out] bytes The available space size of the storage (bytes)
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #STORAGE_ERROR_NONE Successful
+ * @retval #STORAGE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #STORAGE_ERROR_NOT_SUPPORTED Not supported storage
+
+ * @see storage_get_state()
+ * @see storage_get_total_space()
+ */
+int storage_get_available_space(int storage, unsigned long long *bytes);
+
+/**
+ * @}
+ */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __TIZEN_APPFW_STORAGE_H__ */
diff --git a/include/app_storage_private.h b/include/app_storage_private.h
new file mode 100755
index 0000000..e5bf36c
--- /dev/null
+++ b/include/app_storage_private.h
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2011 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_STORAGE_PRIVATE_H__
+#define __TIZEN_APPFW_STORAGE_PRIVATE_H__
+
+#include <tizen.h>
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+typedef int (*storage_dev_get_state)(void);
+typedef int (*storage_dev_set_state_cb)(void *data);
+typedef void (*storage_dev_unset_state_cb)(void);
+typedef int (*storage_dev_get_space)(unsigned long long *total, unsigned long long *available);
+
+typedef struct storage_device_s
+{
+ storage_type_e type;
+ char *path;
+ storage_dev_get_state get_state;
+ storage_dev_set_state_cb set_state_cb;
+ storage_dev_unset_state_cb unset_state_cb;
+ storage_dev_get_space get_space;
+} *storage_device_h;
+
+typedef struct storage_info_s
+{
+ int id;
+ storage_device_h device;
+ storage_state_e state;
+ storage_state_changed_cb state_cb;
+ void *state_cb_data;
+} *storage_info_h;
+
+void storage_dispatch_state_event(storage_state_e state, void* data);
+
+int storage_statfs(const char *directory, unsigned long long *total, unsigned long long *available);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __TIZEN_APPFW_STORAGE_PRIVATE_H__ */
diff --git a/include/app_ui_notification.h b/include/app_ui_notification.h
new file mode 100755
index 0000000..f8edbe9
--- /dev/null
+++ b/include/app_ui_notification.h
@@ -0,0 +1,287 @@
+/*
+ * Copyright (c) 2011 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_UI_NOTIFICATION_H__
+#define __TIZEN_APPFW_UI_NOTIFICATION_H__
+
+#include <tizen.h>
+#include <time.h>
+#include <app_service.h>
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /**
+ * @addtogroup CAPI_UI_NOTIFICATION_MODULE
+ * @{
+ */
+
+/**
+ * @brief Notification handle.
+ */
+typedef struct ui_notification_s *ui_notification_h;
+
+/**
+ * @brief Enumerations of error code for notification.
+ */
+typedef enum {
+ UI_NOTIFICATION_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */
+ UI_NOTIFICATION_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */
+ UI_NOTIFICATION_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory */
+ UI_NOTIFICATION_ERROR_DB_FAILED = TIZEN_ERROR_APPLICATION_CLASS | 0x31, /**< DB operation failed */
+ UI_NOTIFICATION_ERROR_NO_SUCH_FILE = TIZEN_ERROR_NO_SUCH_FILE, /**< No such file */
+ UI_NOTIFICATION_ERROR_ALREADY_POSTED = TIZEN_ERROR_ALREADY_IN_PROGRESS, /**< Notification is already posted */
+} ui_notification_error_e;
+
+/**
+ * @brief Enumeration of progress type for ongoing notification
+ */
+typedef enum {
+ UI_NOTIFICATION_PROGRESS_TYPE_SIZE, /**< Size in bytes */
+ UI_NOTIFICATION_PROGRESS_TYPE_PERCENTAGE, /**< Percentage (between 0.0 and 1.0) */
+} ui_notification_progress_type_e;
+
+/**
+ * @brief Creates a notification handle.
+ * @remarks The @a notification must be released with ui_notification_destroy() by you.
+ * @param[in] ongoing A boolean value that sets whether this is an ongoing notification.
+ * @param[out] notification A UI notification handle to be newly created on success
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #UI_NOTIFICATION_ERROR_NONE Successful
+ * @retval #UI_NOTIFICATION_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #UI_NOTIFICATION_ERROR_OUT_OF_MEMORY Out of memory
+ * @see ui_notification_destroy()
+ */
+int ui_notification_create(bool ongoing, ui_notification_h *notification);
+
+/**
+ * @brief Destroys the notification handle and releases all its resources.
+ * @param[in] notification The notification handle
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #UI_NOTIFICATION_ERROR_NONE Successful
+ * @retval #UI_NOTIFICATION_ERROR_INVALID_PARAMETER Invalid parameter
+ * @see ui_notification_create()
+ */
+int ui_notification_destroy(ui_notification_h notification);
+
+/**
+ * @brief Sets the full path of the icon image to display in the notification.
+ * @remarks The @path should be the absolute path. If the icon is not set, the icon of the application will be displayed. \n
+ * This function should be called before posting (see ui_notification_post()).
+ * @param[in] notification The notification handle
+ * @param[in] path The absolute path to the specified icon
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #UI_NOTIFICATION_ERROR_NONE Successful
+ * @retval #UI_NOTIFICATION_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #UI_NOTIFICATION_ERROR_OUT_OF_MEMORY Out of memory
+ * @retval #UI_NOTIFICATION_ERROR_ALREADY_POSTED Notification is already posted
+ * @see ui_notification_get_icon()
+ */
+int ui_notification_set_icon(ui_notification_h notification, const char *path);
+
+/**
+ * @brief Gets the absolute path to the icon to display in the notification.
+ * @remarks The @a path must be released with free() by you.
+ * @param[in] notification The notification handle
+ * @param[out] path The absolute path to the icon
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #UI_NOTIFICATION_ERROR_NONE Successful
+ * @retval #UI_NOTIFICATION_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #UI_NOTIFICATION_ERROR_OUT_OF_MEMORY Out of memory
+ * @see ui_notification_set_icon()
+ */
+int ui_notification_get_icon(ui_notification_h notification, char **path);
+
+/**
+ * @brief Sets the time that the notification occurred.
+ * @remarks This function should be called before posting (see ui_notification_post()).
+ * @param[in] notification The notification handle
+ * @param[in] time The time that the notification occurred
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #UI_NOTIFICATION_ERROR_NONE Successful
+ * @retval #UI_NOTIFICATION_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #UI_NOTIFICATION_ERROR_OUT_OF_MEMORY Out of memory
+ * @retval #UI_NOTIFICATION_ERROR_ALREADY_POSTED Notification is already posted
+ * @see ui_notification_get_time()
+ */
+int ui_notification_set_time(ui_notification_h notification, struct tm *time);
+
+/**
+ * @brief Gets the time that the notification occured.
+ * @param[in] notification The notification handle
+ * @param[out] time The time that the notification occured
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #UI_NOTIFICATION_ERROR_NONE Successful
+ * @retval #UI_NOTIFICATION_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #UI_NOTIFICATION_ERROR_OUT_OF_MEMORY Out of memory
+ * @see ui_notification_set_time()
+ */
+int ui_notification_get_time(ui_notification_h notification, struct tm **time);
+
+/**
+ * @brief Sets the title to display in the notification.
+ * @remarks If the title is not set, the name of the application will be displayed. \n
+ * This function should be called before posting (see ui_notification_post()).
+ * @param[in] notification The notification handle
+ * @param[in] title The title to display in the notification
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #UI_NOTIFICATION_ERROR_NONE Successful
+ * @retval #UI_NOTIFICATION_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #UI_NOTIFICATION_ERROR_OUT_OF_MEMORY Out of memory
+ * @retval #UI_NOTIFICATION_ERROR_ALREADY_POSTED Notification is already posted
+ * @see ui_notification_get_title()
+ */
+int ui_notification_set_title(ui_notification_h notification, const char *title);
+
+/**
+ * @brief Gets the title to display in the notification.
+ * @remarks The @a title must be released with free() by you.
+ * @param[in] notification The notification handle
+ * @param[out] title The title to display in the notification
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #UI_NOTIFICATION_ERROR_NONE Successful
+ * @retval #UI_NOTIFICATION_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #UI_NOTIFICATION_ERROR_OUT_OF_MEMORY Out of memory
+ * @see ui_notification_set_title()
+ */
+int ui_notification_get_title(ui_notification_h notification, char **title);
+
+/**
+ * @brief Sets the content to display in the notification
+ * @remarks This function should be called before posting (see ui_notification_post()).
+ * @param[in] notification The notification handle
+ * @param[in] content The content to display in the notification
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #UI_NOTIFICATION_ERROR_NONE Successful
+ * @retval #UI_NOTIFICATION_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #UI_NOTIFICATION_ERROR_OUT_OF_MEMORY Out of memory
+ * @retval #UI_NOTIFICATION_ERROR_ALREADY_POSTED Notification is already posted
+ * @see ui_notification_get_content()
+ */
+int ui_notification_set_content(ui_notification_h notification, const char *content);
+
+/**
+ * @brief Gets the content to display in the notification
+ * @remarks The @a content must be released with free() by you.
+ * @param[in] notification The notification handle
+ * @param[out] content The content to display in the notification
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #UI_NOTIFICATION_ERROR_NONE Successful
+ * @retval #UI_NOTIFICATION_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #UI_NOTIFICATION_ERROR_OUT_OF_MEMORY Out of memory
+ * @see ui_notification_set_content()
+ */
+int ui_notification_get_content(ui_notification_h notification, char **content);
+
+/**
+ * @brief Sets the service to launch when the notification is selected from the notification tray.
+ * @details When the notification is selected from the notification tray, the application which is described by the specified service is launched. \n
+ * If you want to launch the current application, use the explicit launch of the @ref CAPI_SERVICE_MODULE API
+ * @remarks If the service is not set, the selected notification will be cleared from both the notification tray and the status bar without any action. \n
+ * This function should be called before posting (see ui_notification_post()).
+ * @param[in] notification The notification handle
+ * @param[in] service The service handle to launch when the notification is selected
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #UI_NOTIFICATION_ERROR_NONE Successful
+ * @retval #UI_NOTIFICATION_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #UI_NOTIFICATION_ERROR_OUT_OF_MEMORY Out of memory
+ * @retval #UI_NOTIFICATION_ERROR_ALREADY_POSTED Notification is already posted
+ * @see ui_notification_get_service()
+ * @see service_create()
+ */
+int ui_notification_set_service(ui_notification_h notification, service_h service);
+
+/**
+ * @brief Gets the service to launch when the notification is selected from the notification tray
+ * @remarks The @a service must be released with service_destroy() by you.
+ * @param[in] notification The notification handle
+ * @param[out] service The service handle to launch when the notification is selected
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #UI_NOTIFICATION_ERROR_NONE Successful
+ * @retval #UI_NOTIFICATION_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #UI_NOTIFICATION_ERROR_OUT_OF_MEMORY Out of memory
+ * @see ui_notification_set_service()
+ */
+int ui_notification_get_service(ui_notification_h notification, service_h *service);
+
+/**
+ * @brief Posts the notification to display in the notification tray and the status bar
+ * @remarks You cannot alter the icon, time, title, content, and service after posting the notification.
+ * @param[in] notification The notification handle
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #UI_NOTIFICATION_ERROR_NONE Successful
+ * @retval #UI_NOTIFICATION_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #UI_NOTIFICATION_ERROR_DB_FAILED DB failed
+ * @retval #UI_NOTIFICATION_ERROR_NO_SUCH_FILE DB No such icon file
+ * @retval #UI_NOTIFICATION_ERROR_ALREADY_POSTED Notification is already posted
+ * @see ui_notification_remove()
+ * @see ui_notification_remove_all()
+ */
+int ui_notification_post(ui_notification_h notification);
+
+/**
+ * @brief Cancels the previously posted notification.
+ * @details The previously posted notification is removed from the notification tray and the status bar.
+ * @remarks The canceled @a notification is not be released automatically, must be released with ui_notification_destroy() by you
+ * @param[in] notification The notification handle
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #UI_NOTIFICATION_ERROR_NONE Successful
+ * @retval #UI_NOTIFICATION_ERROR_INVALID_PARAMETER Invalid parameter
+ * @see ui_notification_post()
+ * @see ui_notification_cancel_all()
+ */
+int ui_notification_cancel(ui_notification_h notification);
+
+/**
+ * @brief Cancels all previously posted notifications by the current application.
+ * @details All previously posted notifications are removed from the notification tray and the status bar.
+ * @remarks The notifications posted by other applications are not canceled from the notification tray and the status bar
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #UI_NOTIFICATION_ERROR_NONE Successful
+ * @see ui_notification_post()
+ * @see ui_notification_cancel()
+ */
+int ui_notification_cancel_all(void);
+
+/**
+ * @brief Updates the progress to the specified value
+ * @param[in] notification The notification handle \n
+ * It must be ongoing notification. \n
+ * If not, #UI_NOTIFICATION_ERROR_INVALID_PARAMETER will occur
+ * @param[in] type The progress type
+ * @param[in] value The value of the progress \n
+ * if @a type is #UI_NOTIFICATION_PROGRESS_TYPE_SIZE, it must be in bytes. \n
+ * If @a type is #UI_NOTIFICATION_PROGRESS_TYPE_PERCENTAGE, It must be a floating-point value between 0.0 and 1.0.
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #UI_NOTIFICATION_ERROR_NONE Successful
+ * @retval #UI_NOTIFICATION_ERROR_INVALID_PARAMETER Invalid parameter
+ * @see ui_notification_create()
+ * @see #ui_notification_progress_type_e
+ */
+int ui_notification_update_progress(ui_notification_h notification, ui_notification_progress_type_e type, double value);
+
+/**
+ * @}
+ */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __TIZEN_APPFW_UI_NOTIFICATION_H__ */
diff --git a/packaging/capi-appfw-application.spec b/packaging/capi-appfw-application.spec
new file mode 100755
index 0000000..2654621
--- /dev/null
+++ b/packaging/capi-appfw-application.spec
@@ -0,0 +1,60 @@
+Name: capi-appfw-application
+Summary: An Application library in Tizen C API
+Version: 0.0.1
+Release: 1
+Group: TO_BE/FILLED_IN
+License: TO BE FILLED IN
+Source0: %{name}-%{version}.tar.gz
+BuildRequires: cmake
+BuildRequires: pkgconfig(dlog)
+BuildRequires: pkgconfig(bundle)
+BuildRequires: pkgconfig(appcore-common)
+BuildRequires: pkgconfig(appcore-efl)
+BuildRequires: pkgconfig(aul)
+BuildRequires: pkgconfig(ail)
+BuildRequires: pkgconfig(appsvc)
+BuildRequires: pkgconfig(heynoti)
+BuildRequires: pkgconfig(elementary)
+BuildRequires: pkgconfig(alarm-service)
+BuildRequires: pkgconfig(capi-base-common)
+Requires(post): /sbin/ldconfig
+Requires(postun): /sbin/ldconfig
+
+%description
+An Application library in Tizen C API
+
+%package devel
+Summary: An Application library in Tizen C API (Development)
+Group: TO_BE/FILLED_IN
+Requires: %{name} = %{version}-%{release}
+
+%description devel
+An Application library in Tizen C API (DEV)
+
+%prep
+%setup -q
+
+
+%build
+cmake . -DCMAKE_INSTALL_PREFIX=/usr
+
+
+make %{?jobs:-j%jobs}
+
+%install
+rm -rf %{buildroot}
+%make_install
+
+%post -p /sbin/ldconfig
+
+%postun -p /sbin/ldconfig
+
+
+%files
+%{_libdir}/libcapi-appfw-application.so
+
+%files devel
+%{_includedir}/appfw/*.h
+%{_libdir}/pkgconfig/*.pc
+
+
diff --git a/src/alarm.c b/src/alarm.c
new file mode 100755
index 0000000..960e949
--- /dev/null
+++ b/src/alarm.c
@@ -0,0 +1,566 @@
+/*
+ * Copyright (c) 2011 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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <time.h>
+
+#include <aul.h>
+#include <alarm.h>
+#include <dlog.h>
+
+#include <app_private.h>
+#include <app_alarm.h>
+#include <app_service_private.h>
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+
+#define LOG_TAG "TIZEN_N_ALARM"
+
+typedef struct {
+ alarm_registered_alarm_cb cb;
+ void* user_data;
+ bool* foreach_break;
+} alarm_foreach_item_cb_context;
+
+static int alarm_registered_alarm_cb_broker(int alarm_id, void *user_data)
+{
+ alarm_foreach_item_cb_context* foreach_cb_context = NULL;
+
+ if (user_data == NULL)
+ {
+ return 0;
+ }
+
+ foreach_cb_context = (alarm_foreach_item_cb_context*)user_data;
+
+ if (foreach_cb_context != NULL && *(foreach_cb_context->foreach_break) == false)
+ {
+ if (foreach_cb_context->cb(alarm_id, foreach_cb_context->user_data) == false)
+ {
+ *(foreach_cb_context->foreach_break) = true;
+ }
+ }
+
+ return 0;
+}
+
+static int convert_error_code_to_alarm(const char* function, alarm_error_t alarm_error)
+{
+ switch(alarm_error)
+ {
+ case ERR_ALARM_INVALID_PARAM:
+ case ERR_ALARM_INVALID_REPEAT:
+ LOGE("[%s] INVALID_PARAMETER(0x%08x)", function, ALARM_ERROR_INVALID_PARAMETER);
+ return ALARM_ERROR_INVALID_PARAMETER;
+ break;
+
+ case ERR_ALARM_INVALID_ID:
+ LOGE("[%s] INVALID_PARAMETER(0x%08x)", function, ALARM_ERROR_INVALID_PARAMETER);
+ return ALARM_ERROR_INVALID_PARAMETER;
+ break;
+
+ case ERR_ALARM_INVALID_TIME:
+ LOGE("[%s] INVALID_TIME(0x%08x)", function, ALARM_ERROR_INVALID_TIME);
+ return ALARM_ERROR_INVALID_TIME;
+ break;
+
+ case ERR_ALARM_INVALID_DATE:
+ LOGE("[%s] INVALID_DATE(0x%08x)", function, ALARM_ERROR_INVALID_DATE);
+ return ALARM_ERROR_INVALID_DATE;
+ break;
+
+ case ERR_ALARM_NO_SERVICE_NAME:
+ LOGE("[%s] INVALID_PARAMETER(0x%08x)", function, ALARM_ERROR_INVALID_PARAMETER);
+ return ALARM_ERROR_INVALID_PARAMETER;
+ break;
+
+ case ERR_ALARM_SYSTEM_FAIL:
+ LOGE("[%s] CONNECTION_FAIL(0x%08x)", function, ALARM_ERROR_CONNECTION_FAIL);
+ return ALARM_ERROR_CONNECTION_FAIL;
+ break;
+
+ case ALARMMGR_RESULT_SUCCESS:
+ return ALARM_ERROR_NONE;
+ break;
+
+ default:
+ return ALARM_ERROR_INVALID_PARAMETER;
+ }
+
+}
+
+static int _remove_alarm_cb(alarm_id_t alarm_id, void* user_param)
+{
+ return alarmmgr_remove_alarm(alarm_id);
+}
+
+static int alarm_init()
+{
+ static bool is_alarm_init = false;
+
+ if (is_alarm_init == false)
+ {
+ char *package = NULL;
+ int errnum;
+
+ if (app_get_package(&package) != 0)
+ {
+ return -1;
+ }
+
+ errnum = alarmmgr_init(package);
+
+ if (package != NULL)
+ {
+ free(package);
+ }
+
+ if (errnum != ALARMMGR_RESULT_SUCCESS)
+ {
+ return -1;
+ }
+
+ is_alarm_init = true;
+ }
+
+ return 0;
+}
+
+int alarm_get_scheduled_date(int alarm_id, struct tm* date)
+{
+ alarm_error_t result;
+ alarm_entry_t *entry = NULL;
+ alarm_date_t adate;
+
+ if (date == NULL)
+ {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x)", __FUNCTION__, ALARM_ERROR_INVALID_PARAMETER);
+ return ALARM_ERROR_INVALID_PARAMETER;
+ }
+
+ if (alarm_init() != 0)
+ {
+ LOGE("[%s] CONNECTION_FAIL(0x%08x)", __FUNCTION__, ALARM_ERROR_CONNECTION_FAIL);
+ return ALARM_ERROR_CONNECTION_FAIL;
+ }
+
+ entry = alarmmgr_create_alarm();
+
+ result = alarmmgr_get_info(alarm_id, entry);
+ if (result != ALARMMGR_RESULT_SUCCESS)
+ {
+ if (entry != NULL) {
+ alarmmgr_free_alarm(entry);
+ }
+ return convert_error_code_to_alarm(__FUNCTION__, result);
+ }
+
+ result = alarmmgr_get_time(entry, &adate);
+ if (result != ALARMMGR_RESULT_SUCCESS)
+ {
+ if (entry != NULL)
+ {
+ alarmmgr_free_alarm(entry);
+ }
+ return convert_error_code_to_alarm(__FUNCTION__, result);
+ }
+
+
+ alarm_get_current_time(date);
+
+ date->tm_year = adate.year - 1900;
+ date->tm_mon = adate.month - 1;
+ date->tm_mday = adate.day;
+ date->tm_hour = adate.hour;
+ date->tm_min = adate.min;
+ date->tm_sec = adate.sec;
+
+ mktime(date);
+
+ result = alarmmgr_free_alarm(entry);
+ if (result != ALARMMGR_RESULT_SUCCESS)
+ {
+ return convert_error_code_to_alarm(__FUNCTION__, result);
+ }
+
+ return ALARM_ERROR_NONE;
+
+}
+
+int alarm_get_scheduled_period(int alarm_id, int* period)
+{
+ alarm_error_t result;
+ alarm_entry_t *entry = NULL;
+ alarm_repeat_mode_t mode;
+ int value;
+
+ if (period == NULL)
+ {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x)", __FUNCTION__, ALARM_ERROR_INVALID_PARAMETER);
+ return ALARM_ERROR_INVALID_PARAMETER;
+ }
+
+ if (alarm_init() != 0)
+ {
+ LOGE("[%s] CONNECTION_FAIL(0x%08x)", __FUNCTION__, ALARM_ERROR_CONNECTION_FAIL);
+ return ALARM_ERROR_CONNECTION_FAIL;
+ }
+
+ entry = alarmmgr_create_alarm();
+
+ result = alarmmgr_get_info(alarm_id, entry);
+ if (result != ALARMMGR_RESULT_SUCCESS)
+ {
+ if (entry != NULL)
+ {
+ alarmmgr_free_alarm(entry);
+ }
+ return convert_error_code_to_alarm(__FUNCTION__, result);
+ }
+
+ result = alarmmgr_get_repeat_mode(entry, &mode, &value);
+ if (result != ALARMMGR_RESULT_SUCCESS)
+ {
+ if (entry != NULL)
+ {
+ alarmmgr_free_alarm(entry);
+ }
+ return convert_error_code_to_alarm(__FUNCTION__, result);
+ }
+
+ result = alarmmgr_free_alarm(entry);
+ if(result != ALARMMGR_RESULT_SUCCESS)
+ {
+ if (entry != NULL)
+ {
+ alarmmgr_free_alarm(entry);
+ }
+ return convert_error_code_to_alarm(__FUNCTION__, result);
+ }
+
+ (*period) = value;
+
+ return ALARM_ERROR_NONE;
+
+}
+
+int alarm_schedule_after_delay(service_h service, int delay, int period, int *alarm_id)
+{
+ bundle *bundle_data;
+ int result = 0;
+
+ if (service == NULL)
+ {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x)", __FUNCTION__, ALARM_ERROR_INVALID_PARAMETER);
+ return ALARM_ERROR_INVALID_PARAMETER;
+ }
+
+ if (service_to_bundle(service, &bundle_data) != SERVICE_ERROR_NONE)
+ {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x)", __FUNCTION__, ALARM_ERROR_INVALID_PARAMETER);
+ return ALARM_ERROR_INVALID_PARAMETER;
+ }
+
+ if (alarm_init() != 0)
+ {
+ LOGE("[%s] CONNECTION_FAIL(0x%08x)", __FUNCTION__, ALARM_ERROR_CONNECTION_FAIL);
+ return ALARM_ERROR_CONNECTION_FAIL;
+ }
+
+ result = alarmmgr_add_alarm_appsvc(ALARM_TYPE_DEFAULT, delay, period, bundle_data, alarm_id);
+
+ return convert_error_code_to_alarm(__FUNCTION__, result);
+}
+
+int alarm_schedule_at_date(service_h service, struct tm *date, int period_in_second, int *alarm_id)
+{
+ alarm_date_t internal_time;
+ alarm_entry_t* alarm_info;
+ bundle *bundle_data;
+ int result;
+
+ if (service == NULL || date == NULL)
+ {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x)", __FUNCTION__, ALARM_ERROR_INVALID_PARAMETER);
+ return ALARM_ERROR_INVALID_PARAMETER;
+ }
+
+ if (service_to_bundle(service, &bundle_data) != SERVICE_ERROR_NONE)
+ {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x)", __FUNCTION__, ALARM_ERROR_INVALID_PARAMETER);
+ return ALARM_ERROR_INVALID_PARAMETER;
+ }
+
+ if (alarm_init() != 0)
+ {
+ LOGE("[%s] CONNECTION_FAIL(0x%08x)", __FUNCTION__, ALARM_ERROR_CONNECTION_FAIL);
+ return ALARM_ERROR_CONNECTION_FAIL;
+ }
+
+ alarm_info = alarmmgr_create_alarm();
+
+ internal_time.year = date->tm_year + 1900;
+ internal_time.month = date->tm_mon +1;
+ internal_time.day = date->tm_mday;
+
+ internal_time.hour = date->tm_hour;
+ internal_time.min = date->tm_min;
+ internal_time.sec = date->tm_sec;
+
+ result = alarmmgr_set_time(alarm_info,internal_time);
+
+ if (result < 0)
+ {
+ return convert_error_code_to_alarm(__FUNCTION__, result);
+ }
+
+
+ if (period_in_second > 0)
+ {
+ result = alarmmgr_set_repeat_mode(alarm_info, ALARM_REPEAT_MODE_REPEAT, period_in_second);
+ }
+ else
+ {
+ result = alarmmgr_set_repeat_mode(alarm_info, ALARM_REPEAT_MODE_ONCE, period_in_second);
+ }
+
+ if (result < 0)
+ {
+ return convert_error_code_to_alarm(__FUNCTION__, result);
+ }
+
+ result = alarmmgr_set_type(alarm_info, ALARM_TYPE_DEFAULT);
+
+ if (result < 0)
+ {
+ return convert_error_code_to_alarm(__FUNCTION__, result);
+ }
+
+ result = alarmmgr_add_alarm_appsvc_with_localtime(alarm_info, bundle_data, alarm_id);
+
+ if (result < 0)
+ {
+ return convert_error_code_to_alarm(__FUNCTION__, result);
+ }
+
+ return ALARM_ERROR_NONE;
+}
+
+int alarm_cancel(int alarm_id)
+{
+ int result;
+
+ if (alarm_init() != 0)
+ {
+ LOGE("[%s] CONNECTION_FAIL(0x%08x)", __FUNCTION__, ALARM_ERROR_CONNECTION_FAIL);
+ return ALARM_ERROR_CONNECTION_FAIL;
+ }
+
+ result = alarmmgr_remove_alarm(alarm_id);
+
+ return convert_error_code_to_alarm(__FUNCTION__, result);
+}
+
+int alarm_cancel_all()
+{
+ int result;
+
+ if (alarm_init() != 0)
+ {
+ LOGE("[%s] CONNECTION_FAIL(0x%08x)", __FUNCTION__, ALARM_ERROR_CONNECTION_FAIL);
+ return ALARM_ERROR_CONNECTION_FAIL;
+ }
+
+ result = alarmmgr_enum_alarm_ids( _remove_alarm_cb, NULL);
+
+ return convert_error_code_to_alarm(__FUNCTION__, result);
+}
+
+int alarm_foreach_registered_alarm(alarm_registered_alarm_cb callback, void* user_data)
+{
+ int result;
+ bool foreach_break = false;
+
+ if (callback == NULL)
+ {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x)", __FUNCTION__, ALARM_ERROR_INVALID_PARAMETER);
+ return ALARM_ERROR_INVALID_PARAMETER;
+ }
+
+ //alarm_registered_alarm_cb_broker
+ alarm_foreach_item_cb_context foreach_cb_context = {
+ .cb = callback,
+ .user_data = user_data,
+ .foreach_break = &foreach_break
+ };
+
+ result = alarmmgr_enum_alarm_ids(alarm_registered_alarm_cb_broker, &foreach_cb_context);
+
+ return convert_error_code_to_alarm(__FUNCTION__, result);
+}
+
+int alarm_get_current_time(struct tm* date)
+{
+ time_t now;
+
+ if (date == NULL)
+ {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x)", __FUNCTION__, ALARM_ERROR_INVALID_PARAMETER);
+ return ALARM_ERROR_INVALID_PARAMETER;
+ }
+
+ time(&now);
+ localtime_r(&now, date);
+ return ALARM_ERROR_NONE;
+}
+
+
+int alarm_schedule_with_recurrence_week_flag(service_h service, struct tm *date, int week_flag,int *alarm_id)
+{
+ alarm_date_t internal_time;
+ alarm_entry_t* alarm_info;
+ bundle *bundle_data;
+ int result;
+
+ if (service == NULL || date == NULL)
+ {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x)", __FUNCTION__, ALARM_ERROR_INVALID_PARAMETER);
+ return ALARM_ERROR_INVALID_PARAMETER;
+ }
+
+ if (service_to_bundle(service, &bundle_data) != SERVICE_ERROR_NONE)
+ {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x)", __FUNCTION__, ALARM_ERROR_INVALID_PARAMETER);
+ return ALARM_ERROR_INVALID_PARAMETER;
+ }
+
+ if (alarm_init() != 0)
+ {
+ LOGE("[%s] CONNECTION_FAIL(0x%08x)", __FUNCTION__, ALARM_ERROR_CONNECTION_FAIL);
+ return ALARM_ERROR_CONNECTION_FAIL;
+ }
+
+ alarm_info = alarmmgr_create_alarm();
+
+ internal_time.year = date->tm_year + 1900;
+ internal_time.month = date->tm_mon +1;
+ internal_time.day = date->tm_mday;
+
+ internal_time.hour = date->tm_hour;
+ internal_time.min = date->tm_min;
+ internal_time.sec = date->tm_sec;
+
+ result = alarmmgr_set_time(alarm_info,internal_time);
+
+ if (result < 0)
+ {
+ return convert_error_code_to_alarm(__FUNCTION__, result);
+ }
+
+ if (week_flag > 0)
+ {
+ result = alarmmgr_set_repeat_mode(alarm_info, ALARM_REPEAT_MODE_WEEKLY, week_flag);
+ }
+
+ if (result < 0)
+ {
+ return convert_error_code_to_alarm(__FUNCTION__, result);
+ }
+
+ result = alarmmgr_set_type(alarm_info, ALARM_TYPE_DEFAULT);
+
+ if (result < 0)
+ {
+ return convert_error_code_to_alarm(__FUNCTION__, result);
+ }
+
+ result = alarmmgr_add_alarm_appsvc_with_localtime(alarm_info, bundle_data, alarm_id);
+
+ return convert_error_code_to_alarm(__FUNCTION__, result);
+}
+
+int alarm_get_scheduled_recurrence_week_flag(int alarm_id, int *week_flag)
+{
+ alarm_error_t result;
+ alarm_entry_t *entry = NULL;
+ alarm_repeat_mode_t mode;
+ int value;
+
+ if(week_flag == NULL)
+ {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x)", __FUNCTION__, ALARM_ERROR_INVALID_PARAMETER);
+ return ALARM_ERROR_INVALID_PARAMETER;
+ }
+
+ if (alarm_init() != 0)
+ {
+ LOGE("[%s] CONNECTION_FAIL(0x%08x)", __FUNCTION__, ALARM_ERROR_CONNECTION_FAIL);
+ return ALARM_ERROR_CONNECTION_FAIL;
+ }
+
+ entry = alarmmgr_create_alarm();
+
+ result = alarmmgr_get_info(alarm_id, entry);
+ if(result != ALARMMGR_RESULT_SUCCESS)
+ {
+ if (entry != NULL)
+ {
+ alarmmgr_free_alarm(entry);
+ }
+ return convert_error_code_to_alarm(__FUNCTION__, result);
+ }
+
+ result = alarmmgr_get_repeat_mode(entry, &mode, &value);
+
+ if(mode != ALARM_REPEAT_MODE_WEEKLY)
+ {
+ if (entry != NULL)
+ {
+ alarmmgr_free_alarm(entry);
+ }
+ return ALARM_ERROR_INVALID_PARAMETER;
+ }
+
+ if(result != ALARMMGR_RESULT_SUCCESS)
+ {
+ if (entry != NULL)
+ {
+ alarmmgr_free_alarm(entry);
+ }
+ return convert_error_code_to_alarm(__FUNCTION__, result);
+ }
+
+ result = alarmmgr_free_alarm(entry);
+ if(result != ALARMMGR_RESULT_SUCCESS)
+ {
+ if (entry != NULL)
+ {
+ alarmmgr_free_alarm(entry);
+ }
+ return convert_error_code_to_alarm(__FUNCTION__, result);
+ }
+
+ (*week_flag) = value;
+
+ return ALARM_ERROR_NONE;
+}
+
diff --git a/src/app_device.c b/src/app_device.c
new file mode 100755
index 0000000..936b625
--- /dev/null
+++ b/src/app_device.c
@@ -0,0 +1,83 @@
+/*
+ * Copyright (c) 2011 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 <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
+#include <bundle.h>
+#include <appcore-common.h>
+#include <aul.h>
+#include <dlog.h>
+#include <vconf.h>
+
+#include <app_private.h>
+#include <app_service_private.h>
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+
+#define LOG_TAG "TIZEN_N_APPLICATION"
+
+app_device_orientation_e app_convert_appcore_rm(enum appcore_rm rm)
+{
+ app_device_orientation_e dev_orientation;
+
+ switch (rm)
+ {
+ case APPCORE_RM_PORTRAIT_NORMAL:
+ dev_orientation = APP_DEVICE_ORIENTATION_0;
+ break;
+
+ case APPCORE_RM_PORTRAIT_REVERSE:
+ dev_orientation = APP_DEVICE_ORIENTATION_180;
+ break;
+
+ case APPCORE_RM_LANDSCAPE_NORMAL:
+ dev_orientation = APP_DEVICE_ORIENTATION_270;
+ break;
+
+ case APPCORE_RM_LANDSCAPE_REVERSE:
+ dev_orientation = APP_DEVICE_ORIENTATION_90;
+ break;
+
+ default:
+ dev_orientation = APP_DEVICE_ORIENTATION_0;
+ break;
+ }
+
+ return dev_orientation;
+}
+
+app_device_orientation_e app_get_device_orientation(void)
+{
+ enum appcore_rm rm;
+ app_device_orientation_e dev_orientation = APP_DEVICE_ORIENTATION_0;
+
+ if (appcore_get_rotation_state(&rm) == 0)
+ {
+ dev_orientation = app_convert_appcore_rm(rm);
+ }
+
+ return dev_orientation;
+}
+
diff --git a/src/app_main.c b/src/app_main.c
new file mode 100755
index 0000000..dd715e1
--- /dev/null
+++ b/src/app_main.c
@@ -0,0 +1,506 @@
+/*
+ * Copyright (c) 2011 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 <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
+#include <bundle.h>
+#include <appcore-common.h>
+#include <appcore-efl.h>
+#include <aul.h>
+#include <dlog.h>
+
+#include <Elementary.h>
+
+#include <app_private.h>
+#include <app_service_private.h>
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+
+#define LOG_TAG "TIZEN_N_APPLICATION"
+
+#define TERMINATE_TASK_MAX 8
+
+typedef enum {
+ APP_STATE_NOT_RUNNING, // The application has been launched or was running but was terminated
+ APP_STATE_CREATING, // The application is initializing the resources on app_create_cb callback
+ APP_STATE_RUNNING, // The application is running in the foreground and background
+} app_state_e;
+
+typedef struct app_context_s {
+ struct appcore_ops appcore;
+ char *package;
+ char *project_name;
+ app_event_callback_s *callbacks;
+ app_state_e state;
+ void *user_data;
+ app_terminate_task_t terminate_task[TERMINATE_TASK_MAX];
+} *app_context_h;
+
+static int app_cb_broker_appcore_create(void *data);
+static int app_cb_broker_appcore_pause(void *data);
+static int app_cb_broker_appcore_resume(void *data);
+static int app_cb_broker_appcore_terminate(void *data);
+static int app_cb_broker_appcore_reset(bundle *appcore_bundle, void *data);
+
+static int app_cb_broker_appcore_low_memory(void *data);
+static int app_cb_broker_appcore_low_battery(void *data);
+static int app_cb_broker_appcore_rotation_event(enum appcore_rm rm, void *data);
+static int app_cb_broker_appcore_lang_changed(void *data);
+static int app_cb_broker_appcore_region_changed(void *data);
+
+static void app_set_appcore_event_cb(app_context_h app_context);
+static void app_unset_appcore_event_cb(void);
+
+static struct app_context_s app_context = {
+ .appcore.create = app_cb_broker_appcore_create,
+ .appcore.terminate = app_cb_broker_appcore_terminate,
+ .appcore.pause = app_cb_broker_appcore_pause,
+ .appcore.resume = app_cb_broker_appcore_resume,
+ .appcore.reset = app_cb_broker_appcore_reset,
+ .package = NULL,
+ .callbacks = NULL,
+ .state = APP_STATE_NOT_RUNNING,
+ .user_data = NULL
+};
+
+
+static void app_reset_app_context()
+{
+ int i;
+
+ if (app_context.package != NULL)
+ {
+ free(app_context.package);
+ }
+
+ if (app_context.project_name != NULL)
+ {
+ free(app_context.project_name);
+ }
+
+ app_context.callbacks = NULL;
+ app_context.user_data = NULL;
+ app_context.state = APP_STATE_NOT_RUNNING;
+
+ for (i=0; i<TERMINATE_TASK_MAX; i++)
+ {
+ app_context.terminate_task[i].cb = NULL;
+ app_context.terminate_task[i].data = NULL;
+ }
+}
+
+
+int app_efl_main(int *argc, char ***argv, app_event_callback_s *callback, void *user_data)
+{
+ char *package = NULL;;
+ char *project_name = NULL;
+
+ // STEP 1 : input parameter
+ if (argc == NULL || argv == NULL || callback == NULL)
+ {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x)", __FUNCTION__, APP_ERROR_INVALID_PARAMETER);
+ return APP_ERROR_INVALID_PARAMETER;
+ }
+
+ if (callback->create == NULL)
+ {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x)", __FUNCTION__, APP_ERROR_INVALID_PARAMETER);
+ return APP_ERROR_INVALID_PARAMETER;
+ }
+
+ // STEP 2 : app-state
+ if (app_context.state != APP_STATE_NOT_RUNNING)
+ {
+ LOGE("[%s] ALREADY_RUNNING(0x%08x)", __FUNCTION__, APP_ERROR_ALREADY_RUNNING);
+ return APP_ERROR_ALREADY_RUNNING;
+ }
+
+ // STEP 3 : package. project_name
+ if (app_get_package(&package) != 0)
+ {
+ LOGE("[%s] INVALID_CONTEXT(0x%08x)", __FUNCTION__, APP_ERROR_INVALID_CONTEXT);
+ return APP_ERROR_INVALID_CONTEXT;
+ }
+
+ app_context.package = package;
+
+ if (app_get_project_name(package, &project_name) != 0)
+ {
+ LOGE("[%s] INVALID_CONTEXT(0x%08x)", __FUNCTION__, APP_ERROR_INVALID_CONTEXT);
+ return APP_ERROR_INVALID_CONTEXT;
+ }
+
+ app_context.project_name = project_name;
+
+ // STEP 4 : set app-context
+ app_context.state = APP_STATE_CREATING;
+ app_context.callbacks = callback;
+ app_context.user_data = user_data;
+ app_context.appcore.data = &app_context;
+
+ // STEP 5 : start appcore-main
+ appcore_efl_main(app_context.project_name, argc, argv, &(app_context.appcore));
+
+ // STEP 6 : reset app-context
+ app_reset_app_context();
+
+ return APP_ERROR_NONE;
+}
+
+void app_efl_exit(void)
+{
+ elm_exit();
+}
+
+static void app_set_appcore_event_cb(app_context_h app_context)
+{
+ if (app_context->callbacks->low_memory != NULL)
+ {
+ appcore_set_event_callback(APPCORE_EVENT_LOW_MEMORY, app_cb_broker_appcore_low_memory, app_context);
+ }
+
+ if (app_context->callbacks->low_battery != NULL)
+ {
+ appcore_set_event_callback(APPCORE_EVENT_LOW_BATTERY, app_cb_broker_appcore_low_battery, app_context);
+ }
+
+ if (app_context->callbacks->device_orientation != NULL)
+ {
+ appcore_set_rotation_cb(app_cb_broker_appcore_rotation_event, app_context);
+ }
+
+ if (app_context->callbacks->language_changed != NULL)
+ {
+ appcore_set_event_callback(APPCORE_EVENT_LANG_CHANGE, app_cb_broker_appcore_lang_changed, app_context);
+ }
+
+ if (app_context->callbacks->region_format_changed != NULL)
+ {
+ appcore_set_event_callback(APPCORE_EVENT_REGION_CHANGE, app_cb_broker_appcore_region_changed, app_context);
+ }
+}
+
+static void app_unset_appcore_event_cb(void)
+{
+ appcore_set_event_callback(APPCORE_EVENT_LOW_MEMORY, NULL, NULL);
+ appcore_set_event_callback(APPCORE_EVENT_LOW_BATTERY, NULL, NULL);
+ appcore_unset_rotation_cb();
+ appcore_set_event_callback(APPCORE_EVENT_LANG_CHANGE, NULL, NULL);
+ appcore_set_event_callback(APPCORE_EVENT_REGION_CHANGE, NULL, NULL);
+}
+
+
+int app_cb_broker_appcore_create(void *data)
+{
+ app_context_h app_context;
+ app_create_cb create_cb;
+ char locale_dir[TIZEN_PATH_MAX] = {0, };
+
+ app_context = (app_context_h)data;
+
+ if (app_context == NULL)
+ {
+ LOGE("[%s] invalid app-context", __FUNCTION__);
+ return -1;
+ }
+
+ app_set_appcore_event_cb(app_context);
+
+ snprintf(locale_dir, TIZEN_PATH_MAX, PATH_FMT_LOCALE_DIR, app_context->package);
+ appcore_set_i18n(app_context->project_name, locale_dir);
+
+ create_cb = app_context->callbacks->create;
+
+ if (create_cb != NULL && create_cb(app_context->user_data) == true)
+ {
+ app_context->state = APP_STATE_RUNNING;
+ return 0;
+ }
+
+ return -1;
+}
+
+int app_cb_broker_appcore_terminate(void *data)
+{
+ app_context_h app_context;
+ app_terminate_cb terminate_cb;
+ int i;
+
+ app_context = (app_context_h)data;
+
+ if (app_context == NULL)
+ {
+ LOGE("[%s] invalid app-context", __FUNCTION__);
+ return -1;
+ }
+
+ // STEP 1 : user event-callback
+ terminate_cb = app_context->callbacks->terminate;
+
+ if (terminate_cb != NULL)
+ {
+ terminate_cb(app_context->user_data);
+ }
+
+ // STEP 2 : appcore event-callback
+ app_unset_appcore_event_cb();
+
+ // STEP 3 : terminate task
+ for (i=0; i<TERMINATE_TASK_MAX; i++)
+ {
+ if (app_context->terminate_task[i].cb != NULL)
+ {
+ app_terminate_task_cb task_cb;
+
+ task_cb = app_context->terminate_task[i].cb;
+
+ if (task_cb != NULL)
+ {
+ task_cb(app_context->terminate_task[i].data);
+ }
+ }
+ }
+
+ return 0;
+}
+
+int app_cb_broker_appcore_pause(void *data)
+{
+ app_context_h app_context;
+ app_pause_cb pause_cb;
+
+ app_context = (app_context_h)data;
+
+ if (app_context == NULL)
+ {
+ LOGE("[%s] invalid app-context", __FUNCTION__);
+ return -1;
+ }
+
+ pause_cb = app_context->callbacks->pause;
+
+ if (pause_cb != NULL)
+ {
+ pause_cb(app_context->user_data);
+ }
+
+ return 0;
+}
+
+int app_cb_broker_appcore_resume(void *data)
+{
+ app_context_h app_context;
+ app_resume_cb resume_cb;
+
+ app_context = (app_context_h)data;
+
+ if (app_context == NULL)
+ {
+ LOGE("[%s] invalid app-context", __FUNCTION__);
+ return -1;
+ }
+
+ resume_cb = app_context->callbacks->resume;
+
+ if (resume_cb != NULL)
+ {
+ resume_cb(app_context->user_data);
+ }
+
+ return 0;
+}
+
+
+int app_cb_broker_appcore_reset(bundle *appcore_bundle, void *data)
+{
+ app_context_h app_context;
+ app_service_cb service_cb;
+ service_h service;
+
+ app_context = (app_context_h)data;
+
+ if (app_context == NULL)
+ {
+ LOGE("[%s] invalid app-context", __FUNCTION__);
+ return -1;
+ }
+
+ if (service_create_event(appcore_bundle, &service) != 0)
+ {
+ LOGE("[%s] fail to create service handle from bundle", __FUNCTION__);
+ return -1;
+ }
+
+ service_cb = app_context->callbacks->service;
+
+ if (service_cb != NULL)
+ {
+ service_cb(service, app_context->user_data);
+ }
+
+ service_destroy(service);
+
+ return 0;
+}
+
+
+int app_cb_broker_appcore_low_memory(void *data)
+{
+ app_context_h app_context;
+ app_low_memory_cb low_memory_cb;
+
+ app_context = (app_context_h)data;
+
+ if (app_context == NULL)
+ {
+ LOGE("[%s] invalid app-context", __FUNCTION__);
+ return -1;
+ }
+
+ low_memory_cb = app_context->callbacks->low_memory;
+
+ if (low_memory_cb != NULL)
+ {
+ low_memory_cb(app_context->user_data);
+ }
+
+ return 0;
+}
+
+int app_cb_broker_appcore_low_battery(void *data)
+{
+ app_context_h app_context;
+ app_low_battery_cb low_battery_cb;
+
+ app_context = (app_context_h)data;
+
+ if (app_context == NULL)
+ {
+ LOGE("[%s] invalid app-context", __FUNCTION__);
+ return -1;
+ }
+
+ low_battery_cb = app_context->callbacks->low_battery;
+
+ if (low_battery_cb != NULL)
+ {
+ low_battery_cb(app_context->user_data);
+ }
+
+ return 0;
+}
+
+int app_cb_broker_appcore_rotation_event(enum appcore_rm rm, void *data)
+{
+ app_context_h app_context;
+ app_device_orientation_cb device_orientation_cb;
+
+ app_context = (app_context_h)data;
+
+ if (app_context == NULL)
+ {
+ LOGE("[%s] invalid app-context", __FUNCTION__);
+ return -1;
+ }
+
+ device_orientation_cb = app_context->callbacks->device_orientation;
+
+ if (device_orientation_cb != NULL)
+ {
+ app_device_orientation_e dev_orientation;
+
+ dev_orientation = app_convert_appcore_rm(rm);
+
+ device_orientation_cb(dev_orientation, app_context->user_data);
+ }
+
+ return 0;
+}
+
+int app_cb_broker_appcore_lang_changed(void *data)
+{
+ app_context_h app_context;
+ app_language_changed_cb lang_changed_cb;
+
+ app_context = (app_context_h)data;
+
+ if (app_context == NULL)
+ {
+ LOGE("[%s] invalid app-context", __FUNCTION__);
+ return -1;
+ }
+
+ lang_changed_cb = app_context->callbacks->language_changed;
+
+ if (lang_changed_cb != NULL)
+ {
+ lang_changed_cb(app_context->user_data);
+ }
+
+ return 0;
+}
+
+int app_cb_broker_appcore_region_changed(void *data)
+{
+ app_context_h app_context;
+ app_region_format_changed_cb region_changed_cb;
+
+ app_context = (app_context_h)data;
+
+ if (app_context == NULL)
+ {
+ LOGE("[%s] invalid app-context", __FUNCTION__);
+ return -1;
+ }
+
+ region_changed_cb = app_context->callbacks->region_format_changed;
+
+ if (region_changed_cb != NULL)
+ {
+ region_changed_cb(app_context->user_data);
+ }
+
+ return 0;
+}
+
+
+int app_add_terminate_task(app_terminate_task_cb callback, void *data)
+{
+ int i;
+
+ for (i=0; i<TERMINATE_TASK_MAX; i++)
+ {
+ if (app_context.terminate_task[i].cb == NULL)
+ {
+ app_context.terminate_task[i].cb = callback;
+ app_context.terminate_task[i].data = data;
+ return 0;
+ }
+ }
+
+ LOGE("[%s] fail to add terminate-task", __FUNCTION__);
+
+ return -1;
+}
diff --git a/src/app_package.c b/src/app_package.c
new file mode 100755
index 0000000..6ff776f
--- /dev/null
+++ b/src/app_package.c
@@ -0,0 +1,192 @@
+/*
+ * Copyright (c) 2011 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 <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
+#include <bundle.h>
+#include <appcore-common.h>
+#include <aul.h>
+#include <ail.h>
+#include <dlog.h>
+
+#include <app_private.h>
+#include <app_service_private.h>
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+
+#define LOG_TAG "TIZEN_N_APPLICATION"
+
+int app_get_project_name(const char *package, char **name)
+{
+ char *name_token = NULL;
+
+ if (package == NULL)
+ {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x)", __FUNCTION__, APP_ERROR_INVALID_PARAMETER);
+ return APP_ERROR_INVALID_PARAMETER;
+ }
+
+ // com.vendor.name -> name
+ name_token = strrchr(package, '.');
+
+ if (name_token == NULL)
+ {
+ LOGE("[%s] INVALID_CONTEXT(0x%08x)", __FUNCTION__, APP_ERROR_INVALID_CONTEXT);
+ return APP_ERROR_INVALID_CONTEXT;
+ }
+
+ name_token++;
+
+ *name = strdup(name_token);
+
+ if (*name == NULL)
+ {
+ LOGE("[%s] OUT_OF_MEMORY(0x%08x)", __FUNCTION__, APP_ERROR_OUT_OF_MEMORY);
+ return APP_ERROR_OUT_OF_MEMORY;
+ }
+
+ return APP_ERROR_NONE;
+}
+
+int app_get_package(char **package)
+{
+ static char package_buf[TIZEN_PATH_MAX] = {0, };
+
+ if (package == NULL)
+ {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x)", __FUNCTION__, APP_ERROR_INVALID_PARAMETER);
+ return APP_ERROR_INVALID_PARAMETER;
+ }
+
+ if (package_buf[0] == '\0')
+ {
+ aul_app_get_pkgname_bypid(getpid(), package_buf, sizeof(package_buf));
+ }
+
+ if (package_buf[0] == '\0')
+ {
+ LOGE("[%s] INVALID_CONTEXT(0x%08x) : failed to get the package of the application", __FUNCTION__, APP_ERROR_INVALID_CONTEXT);
+ return APP_ERROR_INVALID_CONTEXT;
+ }
+
+ *package = strdup(package_buf);
+
+ if (*package == NULL)
+ {
+ LOGE("[%s] OUT_OF_MEMORY(0x%08x)", __FUNCTION__, APP_ERROR_OUT_OF_MEMORY);
+ return APP_ERROR_OUT_OF_MEMORY;
+ }
+
+ return APP_ERROR_NONE;
+}
+
+static int app_get_appinfo(const char *package, ail_prop_str_e property, char **value)
+{
+ ail_appinfo_h appinfo;
+ char *appinfo_value;
+ char *appinfo_value_dup;
+
+ if (ail_package_get_appinfo(package, &appinfo) != 0)
+ {
+ LOGE("[%s] INVALID_CONTEXT(0x%08x) : failed to get app-info", __FUNCTION__, APP_ERROR_INVALID_CONTEXT);
+ return APP_ERROR_INVALID_CONTEXT;
+ }
+
+ if (ail_appinfo_get_str(appinfo, property, &appinfo_value) != 0)
+ {
+ ail_package_destroy_appinfo(appinfo);
+ LOGE("[%s] INVALID_CONTEXT(0x%08x) : failed to get app-property", __FUNCTION__, APP_ERROR_INVALID_CONTEXT);
+ return APP_ERROR_INVALID_CONTEXT;
+ }
+
+ appinfo_value_dup = strdup(appinfo_value);
+
+ ail_package_destroy_appinfo(appinfo);
+
+ if (appinfo_value_dup == NULL)
+ {
+ LOGE("[%s] OUT_OF_MEMORY(0x%08x)", __FUNCTION__, APP_ERROR_OUT_OF_MEMORY);
+ return APP_ERROR_OUT_OF_MEMORY;
+ }
+
+ *value = appinfo_value_dup;
+
+ return APP_ERROR_NONE;
+}
+
+int app_get_name(char **name)
+{
+ char *package = NULL;
+ int retval;
+
+ if(name == NULL)
+ {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x)", __FUNCTION__, APP_ERROR_INVALID_PARAMETER);
+ return APP_ERROR_INVALID_PARAMETER;
+ }
+
+ if (app_get_package(&package) != 0)
+ {
+ LOGE("[%s] INVALID_CONTEXT(0x%08x)", __FUNCTION__, APP_ERROR_INVALID_CONTEXT);
+ return APP_ERROR_INVALID_CONTEXT;
+ }
+
+ retval = app_get_appinfo(package, AIL_PROP_NAME_STR, name);
+
+ if (package != NULL)
+ {
+ free(package);
+ }
+
+ return retval;
+}
+
+int app_get_version(char **version)
+{
+ char *package;
+ int retval;
+
+ if(version == NULL)
+ {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x)", __FUNCTION__, APP_ERROR_INVALID_PARAMETER);
+ return APP_ERROR_INVALID_PARAMETER;
+ }
+
+ if (app_get_package(&package) != 0)
+ {
+ LOGE("[%s] INVALID_CONTEXT(0x%08x)", __FUNCTION__, APP_ERROR_INVALID_CONTEXT);
+ return APP_ERROR_INVALID_CONTEXT;
+ }
+
+ retval = app_get_appinfo(package, AIL_PROP_VERSION_STR, version);
+
+ if (package != NULL)
+ {
+ free(package);
+ }
+
+ return retval;
+}
+
diff --git a/src/app_resource.c b/src/app_resource.c
new file mode 100755
index 0000000..4a78ee3
--- /dev/null
+++ b/src/app_resource.c
@@ -0,0 +1,169 @@
+/*
+ * Copyright (c) 2011 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 <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
+#include <bundle.h>
+#include <appcore-common.h>
+#include <aul.h>
+#include <dlog.h>
+
+#include <app_private.h>
+#include <app_service_private.h>
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+
+#define LOG_TAG "TIZEN_N_APPLICATION"
+
+static char* app_get_resource_directory()
+{
+ static char *resource_directory = NULL;
+
+ if (resource_directory == NULL)
+ {
+ char *resource_directory_tmp;
+ char *package = NULL;
+
+ if (app_get_package(&package) != APP_ERROR_NONE)
+ {
+ LOGE("[%s] INVALID_CONTEXT(0x%08x)", __FUNCTION__, APP_ERROR_INVALID_CONTEXT);
+ return NULL;
+ }
+
+ resource_directory_tmp = calloc(1, sizeof(char) * TIZEN_PATH_MAX);
+
+ if (resource_directory_tmp == NULL)
+ {
+ LOGE("[%s] OUT_OF_MEMORY(0x%08x)", __FUNCTION__, APP_ERROR_OUT_OF_MEMORY);
+ return NULL;
+ }
+
+ snprintf(resource_directory_tmp, TIZEN_PATH_MAX, PATH_FMT_RES_DIR, package);
+
+ if (package != NULL)
+ {
+ free(package);
+ }
+
+ resource_directory = resource_directory_tmp;
+ }
+
+ return resource_directory;
+}
+
+char* app_get_resource(const char *resource, char *buffer, int size)
+{
+ char *resource_directory;
+ int abs_path_size;
+
+ if (resource == NULL)
+ {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid resource", __FUNCTION__, APP_ERROR_INVALID_PARAMETER);
+ return NULL;
+ }
+
+ if (buffer == NULL || size <= 0)
+ {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid buffer", __FUNCTION__, APP_ERROR_INVALID_PARAMETER);
+ return NULL;
+ }
+
+ resource_directory = app_get_resource_directory();
+
+ if (resource_directory == NULL)
+ {
+ LOGE("[%s] INVALID_CONTEXT(0x%08x) : failed to get the path to the resource directory", __FUNCTION__, APP_ERROR_INVALID_CONTEXT);
+ return NULL;
+ }
+
+ abs_path_size = strlen(resource_directory)+ strlen("/") + strlen(resource);
+
+ if (size <= abs_path_size)
+ {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x) : the buffer is not big enough", __FUNCTION__, APP_ERROR_INVALID_PARAMETER);
+ return NULL;
+ }
+
+ snprintf(buffer, size, "%s/%s", resource_directory, resource);
+
+ return buffer;
+}
+
+char* app_get_data_directory(char *buffer, int size)
+{
+ static char *abs_path = NULL;
+
+ if (buffer == NULL || size <= 0)
+ {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid buffer", __FUNCTION__, APP_ERROR_INVALID_PARAMETER);
+ return NULL;
+ }
+
+ if (abs_path == NULL)
+ {
+ char *package;
+ char *abs_path_tmp;
+
+ if (app_get_package(&package) != 0)
+ {
+ LOGE("[%s] INVALID_CONTEXT(0x%08x)", __FUNCTION__, APP_ERROR_INVALID_CONTEXT);
+ return NULL;
+ }
+
+ abs_path_tmp = calloc(1, sizeof(char) * TIZEN_PATH_MAX);
+
+ if (abs_path_tmp == NULL)
+ {
+ LOGE("[%s] OUT_OF_MEMORY(0x%08x)", __FUNCTION__, APP_ERROR_OUT_OF_MEMORY);
+ return NULL;
+ }
+
+ snprintf(abs_path_tmp, TIZEN_PATH_MAX, PATH_FMT_DATA_DIR, package);
+
+ if (package != NULL)
+ {
+ free(package);
+ }
+
+ abs_path = abs_path_tmp;
+ }
+
+ if (abs_path == NULL)
+ {
+ LOGE("[%s] INVALID_CONTEXT(0x%08x) : failed to get the absolute path to the data directory", __FUNCTION__, APP_ERROR_INVALID_CONTEXT);
+ return NULL;
+ }
+
+ if (size <= strlen(abs_path))
+ {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x) : the buffer is not big enough", __FUNCTION__, APP_ERROR_INVALID_PARAMETER);
+ return NULL;
+ }
+
+ snprintf(buffer, size, "%s", abs_path);
+
+ return buffer;
+}
+
diff --git a/src/i18n.c b/src/i18n.c
new file mode 100755
index 0000000..a1ca9e3
--- /dev/null
+++ b/src/i18n.c
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2011 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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <libintl.h>
+
+#include <app_i18n.h>
+
+char* i18n_get_text(const char *message)
+{
+ return gettext(message);
+}
+
diff --git a/src/preference.c b/src/preference.c
new file mode 100755
index 0000000..73c7871
--- /dev/null
+++ b/src/preference.c
@@ -0,0 +1,752 @@
+/*
+ * Copyright (c) 2011 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 <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <sqlite3.h>
+
+#include <app_private.h>
+
+#include <app_preference.h>
+#include <app_preference_private.h>
+
+#include <dlog.h>
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+
+#define LOG_TAG "TIZEN_N_PREFERENCE"
+#define DBG_MODE (1)
+
+static sqlite3 *pref_db = NULL;
+static bool is_update_hook_registered = false;
+static pref_changed_cb_node_t *head = NULL;
+
+static void _finish(void *data)
+{
+ if (pref_db != NULL)
+ {
+ sqlite3_close(pref_db);
+ pref_db = NULL;
+ }
+}
+
+static int _initialize(void)
+{
+ char data_path[TIZEN_PATH_MAX] = {0, };
+ char db_path[TIZEN_PATH_MAX] = {0, };
+ int ret;
+ char *errmsg;
+
+ if (app_get_data_directory(data_path, sizeof(data_path)) == NULL)
+ {
+ LOGE("[%s] IO_ERROR(0x%08x) : fail to get data directory", __FUNCTION__, PREFERENCE_ERROR_IO_ERROR);
+ return PREFERENCE_ERROR_IO_ERROR;
+ }
+ snprintf(db_path, sizeof(db_path), "%s/%s", data_path, PREF_DB_NAME);
+
+ ret = sqlite3_open(db_path, &pref_db);
+ if (ret != SQLITE_OK)
+ {
+ LOGE("[%s] IO_ERROR(0x%08x) : fail to open db(%s)", __FUNCTION__, PREFERENCE_ERROR_IO_ERROR, sqlite3_errmsg(pref_db));
+ pref_db = NULL;
+ return PREFERENCE_ERROR_IO_ERROR;
+ }
+
+ ret = sqlite3_exec(pref_db, "CREATE TABLE IF NOT EXISTS pref ( pref_key TEXT PRIMARY KEY, pref_type TEXT, pref_data TEXT)",
+ NULL, NULL, &errmsg);
+ if (ret != SQLITE_OK)
+ {
+ LOGE("[%s] IO_ERROR(0x%08x) : fail to create db table(%s)", __FUNCTION__, PREFERENCE_ERROR_IO_ERROR, errmsg);
+ sqlite3_free(errmsg);
+ sqlite3_close(pref_db);
+ pref_db = NULL;
+ return PREFERENCE_ERROR_IO_ERROR;
+ }
+
+ app_add_terminate_task(_finish, NULL);
+
+ return PREFERENCE_ERROR_NONE;
+}
+
+//static int _write_data(const char *key, preference_type_e type, const char *data)
+static int _write_data(const char *key, const char *type, const char *data)
+{
+ int ret;
+ char *buf;
+ char *errmsg;
+ bool exist = false;
+
+ if (key == NULL || key[0] == '\0' || data == NULL)
+ {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x)", __FUNCTION__, PREFERENCE_ERROR_INVALID_PARAMETER);
+ return PREFERENCE_ERROR_INVALID_PARAMETER;
+ }
+
+ /* insert data or update data if data already exist */
+ ret = preference_is_existing(key, &exist);
+ if (ret != PREFERENCE_ERROR_NONE)
+ {
+ return ret;
+ }
+
+ // to use sqlite3_update_hook, we have to use INSERT/UPDATE operation instead of REPLACE operation
+ if (exist)
+ {
+ buf = sqlite3_mprintf("UPDATE %s SET %s='%s', %s='%s' WHERE %s='%s';",
+ PREF_TBL_NAME, PREF_F_TYPE_NAME, type, PREF_F_DATA_NAME, data, PREF_F_KEY_NAME, key);
+ }
+ else
+ {
+ buf = sqlite3_mprintf("INSERT INTO %s (%s, %s, %s) values ('%s', '%s', '%s');",
+ PREF_TBL_NAME, PREF_F_KEY_NAME, PREF_F_TYPE_NAME, PREF_F_DATA_NAME, key, type, data);
+ }
+
+ if (buf == NULL)
+ {
+ LOGE("[%s] IO_ERROR(0x%08x) : fail to create query string", __FUNCTION__, PREFERENCE_ERROR_IO_ERROR);
+ return PREFERENCE_ERROR_IO_ERROR;
+ }
+
+ ret = sqlite3_exec(pref_db, buf, NULL, NULL, &errmsg);
+ sqlite3_free(buf);
+ if (ret != SQLITE_OK)
+ {
+ LOGE("[%s] IO_ERROR(0x%08x): fail to write data(%s)", __FUNCTION__, PREFERENCE_ERROR_IO_ERROR, errmsg);
+ sqlite3_free(errmsg);
+ return PREFERENCE_ERROR_IO_ERROR;
+ }
+
+ return PREFERENCE_ERROR_NONE;
+}
+
+//static int _read_data(const char *key, preference_type_e *type, char *data)
+static int _read_data(const char *key, char *type, char *data)
+{
+ int ret;
+ char *buf;
+ char **result;
+ int rows;
+ int columns;
+ char *errmsg;
+
+ if (key == NULL || key[0] == '\0' || data == NULL)
+ {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x)", __FUNCTION__, PREFERENCE_ERROR_INVALID_PARAMETER);
+ return PREFERENCE_ERROR_INVALID_PARAMETER;
+ }
+
+ if (pref_db == NULL)
+ {
+ if (_initialize() != PREFERENCE_ERROR_NONE)
+ {
+ LOGE("[%s] IO_ERROR(0x%08x) : fail to initialize db", __FUNCTION__, PREFERENCE_ERROR_IO_ERROR);
+ return PREFERENCE_ERROR_IO_ERROR;
+ }
+ }
+
+ buf = sqlite3_mprintf("SELECT %s, %s, %s FROM %s WHERE %s='%q';",
+ PREF_F_KEY_NAME, PREF_F_TYPE_NAME, PREF_F_DATA_NAME, PREF_TBL_NAME, PREF_F_KEY_NAME, key);
+
+ if (buf == NULL)
+ {
+ LOGE("[%s] IO_ERROR(0x%08x) : fail to create query string", __FUNCTION__, PREFERENCE_ERROR_IO_ERROR);
+ return PREFERENCE_ERROR_IO_ERROR;
+ }
+
+ ret = sqlite3_get_table(pref_db, buf, &result, &rows, &columns, &errmsg);
+ sqlite3_free(buf);
+ if (ret != SQLITE_OK)
+ {
+ LOGE("[%s] IO_ERROR(0x%08x) : fail to read data (%s)", __FUNCTION__, PREFERENCE_ERROR_IO_ERROR, errmsg);
+ sqlite3_free(errmsg);
+ return PREFERENCE_ERROR_IO_ERROR;
+ }
+
+ if (rows == 0)
+ {
+ LOGE("[%s] NO_KEY(0x%08x) : fail to find given key(%s)", __FUNCTION__, PREFERENCE_ERROR_NO_KEY, key);
+ sqlite3_free_table(result);
+ return PREFERENCE_ERROR_NO_KEY;
+ }
+
+ snprintf(type, strlen(result[4]) + 1, "%s", result[4]); // get type value
+ snprintf(data, strlen(result[5]) + 1, "%s", result[5]); // get data value
+
+ sqlite3_free_table(result);
+
+ return PREFERENCE_ERROR_NONE;
+}
+
+
+int preference_set_int(const char *key, int value)
+{
+ char type[2];
+ char data[BUF_LEN];
+ snprintf(type, 2, "%d", PREFERENCE_TYPE_INT);
+ snprintf(data, BUF_LEN, "%d", value);
+ return _write_data(key, type, data);
+}
+
+int preference_get_int(const char *key, int *value)
+{
+ char type[2];
+ char data[BUF_LEN];
+ int ret;
+
+ ret = _read_data(key, type, data);
+ if (ret == PREFERENCE_ERROR_NONE)
+ {
+ if (atoi(type) == PREFERENCE_TYPE_INT)
+ {
+ *value = atoi(data);
+ }
+ else
+ {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x) : param type(%d)", __FUNCTION__, PREFERENCE_ERROR_INVALID_PARAMETER, atoi(type));
+ return PREFERENCE_ERROR_INVALID_PARAMETER;
+ }
+ }
+
+ return ret;
+}
+
+int preference_set_double(const char *key, double value)
+{
+ char type[2];
+ char data[BUF_LEN];
+ snprintf(type, 2, "%d", PREFERENCE_TYPE_DOUBLE);
+ snprintf(data, BUF_LEN, "%f", value);
+ return _write_data(key, type, data);
+}
+
+int preference_get_double(const char *key, double *value)
+{
+ char type[2];
+ char data[BUF_LEN];
+
+ int ret;
+
+ ret = _read_data(key, type, data);
+ if (ret == PREFERENCE_ERROR_NONE)
+ {
+ if (atoi(type) == PREFERENCE_TYPE_DOUBLE)
+ {
+ *value = atof(data);
+ }
+ else
+ {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x) : param type(%d)", __FUNCTION__, PREFERENCE_ERROR_INVALID_PARAMETER, atoi(type));
+ return PREFERENCE_ERROR_INVALID_PARAMETER;
+ }
+ }
+
+ return ret;
+}
+
+int preference_set_string(const char *key, const char *value)
+{
+ char type[2];
+ snprintf(type, 2, "%d", PREFERENCE_TYPE_STRING);
+ return _write_data(key, type, value);
+}
+
+int preference_get_string(const char *key, char **value)
+{
+ char type[2];
+ char data[BUF_LEN];
+
+ int ret;
+
+ if (value == NULL)
+ {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x)", __FUNCTION__, PREFERENCE_ERROR_INVALID_PARAMETER);
+ return PREFERENCE_ERROR_INVALID_PARAMETER;
+ }
+
+ ret = _read_data(key, type, data);
+ if (ret == PREFERENCE_ERROR_NONE)
+ {
+ if (atoi(type) == PREFERENCE_TYPE_STRING)
+ {
+ *value = strdup(data);
+ if (value == NULL)
+ {
+ LOGE("[%s] OUT_OF_MEMORY(0x%08x)", __FUNCTION__, PREFERENCE_ERROR_OUT_OF_MEMORY);
+ return PREFERENCE_ERROR_OUT_OF_MEMORY;
+ }
+ }
+ else
+ {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x) : param type(%d)", __FUNCTION__, PREFERENCE_ERROR_INVALID_PARAMETER, atoi(type));
+ return PREFERENCE_ERROR_INVALID_PARAMETER;
+ }
+ }
+
+ return ret;
+}
+
+int preference_set_boolean(const char *key, bool value)
+{
+ char type[2];
+ char data[BUF_LEN];
+ snprintf(type, 2, "%d", PREFERENCE_TYPE_BOOLEAN);
+ snprintf(data, BUF_LEN, "%d", value);
+ return _write_data(key, type, data);
+}
+
+int preference_get_boolean(const char *key, bool *value)
+{
+ char type[2];
+ char data[BUF_LEN];
+
+ int ret;
+
+ ret = _read_data(key, type, data);
+ if (ret == PREFERENCE_ERROR_NONE)
+ {
+ if (atoi(type) == PREFERENCE_TYPE_BOOLEAN)
+ {
+ *value = (bool)atoi(data);
+ }
+ else
+ {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x) : param type(%d)", __FUNCTION__, PREFERENCE_ERROR_INVALID_PARAMETER, atoi(type));
+ return PREFERENCE_ERROR_INVALID_PARAMETER;
+ }
+ }
+
+ return ret;
+}
+
+
+// TODO: below operation is too heavy, let's find the light way to check.
+int preference_is_existing(const char *key, bool *exist)
+{
+ int ret;
+ char *buf;
+ char **result;
+ int rows;
+ int columns;
+ char *errmsg;
+
+ if (key == NULL || key[0] == '\0' || exist == NULL)
+ {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x)", __FUNCTION__, PREFERENCE_ERROR_INVALID_PARAMETER);
+ return PREFERENCE_ERROR_INVALID_PARAMETER;
+ }
+
+ if (pref_db == NULL)
+ {
+ if (_initialize() != PREFERENCE_ERROR_NONE)
+ {
+ LOGE("[%s] IO_ERROR(0x%08x) : fail to initialize db", __FUNCTION__, PREFERENCE_ERROR_IO_ERROR);
+ return PREFERENCE_ERROR_IO_ERROR;
+ }
+ }
+
+ /* check data is exist */
+ buf = sqlite3_mprintf("SELECT %s FROM %s WHERE %s='%q';", PREF_F_KEY_NAME, PREF_TBL_NAME, PREF_F_KEY_NAME, key);
+
+ if (buf == NULL)
+ {
+ LOGE("[%s] IO_ERROR(0x%08x) : fail to create query string", __FUNCTION__, PREFERENCE_ERROR_IO_ERROR);
+ return PREFERENCE_ERROR_IO_ERROR;
+ }
+
+ ret = sqlite3_get_table(pref_db, buf, &result, &rows, &columns, &errmsg);
+ sqlite3_free(buf);
+ if (ret != SQLITE_OK)
+ {
+ LOGE("[%s] IO_ERROR(0x%08x) : fail to read data(%s)", __FUNCTION__, PREFERENCE_ERROR_IO_ERROR, errmsg);
+ sqlite3_free(errmsg);
+ return PREFERENCE_ERROR_IO_ERROR;
+ }
+
+ if (rows > 0)
+ {
+ *exist = true;
+ }
+ else
+ {
+ *exist = false;
+ }
+
+ sqlite3_free_table(result);
+ return PREFERENCE_ERROR_NONE;
+}
+
+static pref_changed_cb_node_t* _find_node(const char *key)
+{
+ pref_changed_cb_node_t *tmp_node;
+
+ if (key == NULL || key[0] == '\0' )
+ {
+ return NULL;
+ }
+
+ tmp_node = head;
+
+ while (tmp_node)
+ {
+ if (strcmp(tmp_node->key, key) == 0)
+ {
+ break;
+ }
+ tmp_node = tmp_node->next;
+ }
+
+ return tmp_node;
+}
+
+
+static int _add_node(const char *key, preference_changed_cb cb, void *user_data)
+{
+ pref_changed_cb_node_t *tmp_node;
+
+ if (key == NULL || key[0] == '\0' || cb == NULL)
+ {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x)", __FUNCTION__, PREFERENCE_ERROR_INVALID_PARAMETER);
+ return PREFERENCE_ERROR_INVALID_PARAMETER;
+ }
+
+ tmp_node = _find_node(key);
+
+ if (tmp_node != NULL)
+ {
+ tmp_node->cb = cb;
+ tmp_node->user_data = user_data;
+ }
+ else
+ {
+ tmp_node = (pref_changed_cb_node_t*)malloc(sizeof(pref_changed_cb_node_t));
+ if (tmp_node == NULL)
+ {
+ LOGE("[%s] OUT_OF_MEMORY(0x%08x)", __FUNCTION__, PREFERENCE_ERROR_OUT_OF_MEMORY);
+ return PREFERENCE_ERROR_OUT_OF_MEMORY;
+ }
+
+ tmp_node->key = strdup(key);
+ if (tmp_node->key == NULL)
+ {
+ free(tmp_node);
+ LOGE("[%s] OUT_OF_MEMORY(0x%08x)", __FUNCTION__, PREFERENCE_ERROR_OUT_OF_MEMORY);
+ return PREFERENCE_ERROR_OUT_OF_MEMORY;
+ }
+ tmp_node->cb = cb;
+ tmp_node->user_data = user_data;
+ tmp_node->prev = NULL;
+ tmp_node->next = head;
+ head = tmp_node;
+ }
+
+ return PREFERENCE_ERROR_NONE;
+}
+
+static int _remove_node(const char *key)
+{
+ pref_changed_cb_node_t *tmp_node;
+
+ if (key == NULL || key[0] == '\0' )
+ {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x)", __FUNCTION__, PREFERENCE_ERROR_INVALID_PARAMETER);
+ return PREFERENCE_ERROR_INVALID_PARAMETER;
+ }
+
+ tmp_node = _find_node(key);
+
+ if (tmp_node == NULL)
+ {
+ return PREFERENCE_ERROR_NONE;
+ }
+
+ if (tmp_node->prev != NULL)
+ {
+ tmp_node->prev->next = tmp_node->next;
+ }
+ else
+ {
+ head = tmp_node->next;
+ }
+
+ if (tmp_node->next != NULL)
+ {
+ tmp_node->next->prev = tmp_node->prev;
+ }
+
+ if (tmp_node->key)
+ {
+ free(tmp_node->key);
+ }
+
+ free(tmp_node);
+
+ return PREFERENCE_ERROR_NONE;
+}
+
+
+static void _remove_all_node(void)
+{
+ pref_changed_cb_node_t *tmp_node;
+
+ while (head)
+ {
+ tmp_node = head;
+ head = tmp_node->next;
+
+ if (tmp_node->key)
+ {
+ free(tmp_node->key);
+ }
+
+ free(tmp_node);
+ }
+}
+
+
+static void _update_cb(void *data, int action, char const *db_name, char const *table_name, sqlite_int64 rowid)
+{
+ int ret;
+ char *buf;
+ char **result;
+ int rows;
+ int columns;
+ char *errmsg;
+ pref_changed_cb_node_t *tmp_node;
+
+ // skip INSERT/DELETE event
+ if (action != SQLITE_UPDATE)
+ {
+ return;
+ }
+
+ if (strcmp(table_name, PREF_TBL_NAME) != 0)
+ {
+ LOGI("[%s] given table name (%s) is not same", __FUNCTION__, table_name);
+ return;
+ }
+
+ buf = sqlite3_mprintf("SELECT %s FROM %s WHERE rowid='%lld';", PREF_F_KEY_NAME, PREF_TBL_NAME, rowid);
+ if (buf == NULL)
+ {
+ return;
+ }
+ ret = sqlite3_get_table(pref_db, buf, &result, &rows, &columns, &errmsg);
+ sqlite3_free(buf);
+ if (ret != SQLITE_OK)
+ {
+ LOGI("[%s] fail to read data(%s)", __FUNCTION__, errmsg);
+ sqlite3_free(errmsg);
+ return;
+ }
+
+ if (rows == 0)
+ {
+ sqlite3_free_table(result);
+ return;
+ }
+
+ tmp_node = _find_node(result[1]);
+
+ if (tmp_node != NULL && tmp_node->cb != NULL)
+ {
+ tmp_node->cb(result[1], tmp_node->user_data);
+ }
+
+ sqlite3_free_table(result);
+}
+
+
+int preference_remove(const char *key)
+{
+ int ret;
+ char *buf;
+ char *errmsg;
+ bool exist;
+
+ ret = preference_is_existing(key, &exist);
+ if (ret != PREFERENCE_ERROR_NONE)
+ {
+ return ret;
+ }
+
+ if (!exist)
+ {
+ return PREFERENCE_ERROR_NONE;
+ }
+
+ /* insert data or update data if data already exist */
+ buf = sqlite3_mprintf("DELETE FROM %s WHERE %s = '%s';",
+ PREF_TBL_NAME, PREF_F_KEY_NAME, key);
+
+ if (buf == NULL)
+ {
+ LOGE("[%s] IO_ERROR(0x%08x) : fail to create query string", __FUNCTION__, PREFERENCE_ERROR_IO_ERROR);
+ return PREFERENCE_ERROR_IO_ERROR;
+ }
+
+ ret = sqlite3_exec(pref_db, buf, NULL, NULL, &errmsg);
+ sqlite3_free(buf);
+ if (ret != SQLITE_OK)
+ {
+ LOGE("[%s] IO_ERROR(0x%08x) : fail to delete data (%s)", __FUNCTION__, PREFERENCE_ERROR_IO_ERROR, errmsg);
+ sqlite3_free(errmsg);
+ return PREFERENCE_ERROR_IO_ERROR;
+ }
+
+ // if exist, remove changed cb
+ _remove_node(key);
+
+ return PREFERENCE_ERROR_NONE;
+}
+
+
+int preference_remove_all(void)
+{
+ int ret;
+ char *buf;
+ char *errmsg;
+
+ if (pref_db == NULL)
+ {
+ if (_initialize() != PREFERENCE_ERROR_NONE)
+ {
+ LOGE("[%s] IO_ERROR(0x%08x) : fail to initialize db", __FUNCTION__, PREFERENCE_ERROR_IO_ERROR);
+ return PREFERENCE_ERROR_IO_ERROR;
+ }
+ }
+
+ /* insert data or update data if data already exist */
+ buf = sqlite3_mprintf("DELETE FROM %s;", PREF_TBL_NAME);
+ if (buf == NULL)
+ {
+ LOGE("[%s] IO_ERROR(0x%08x) : fail to create query string", __FUNCTION__, PREFERENCE_ERROR_IO_ERROR);
+ return PREFERENCE_ERROR_IO_ERROR;
+ }
+
+ ret = sqlite3_exec(pref_db, buf, NULL, NULL, &errmsg);
+ sqlite3_free(buf);
+ if (ret != SQLITE_OK)
+ {
+ LOGE("[%s] IO_ERROR(0x%08x) : fail to delete data (%s)", __FUNCTION__, PREFERENCE_ERROR_IO_ERROR, errmsg);
+ sqlite3_free(errmsg);
+ return PREFERENCE_ERROR_IO_ERROR;
+ }
+
+ // if exist, remove changed cb
+ _remove_all_node();
+
+ return PREFERENCE_ERROR_NONE;
+}
+
+
+int preference_set_changed_cb(const char *key, preference_changed_cb callback, void *user_data)
+{
+ int ret;
+ bool exist;
+
+ ret = preference_is_existing(key, &exist);
+ if (ret != PREFERENCE_ERROR_NONE)
+ {
+ return ret;
+ }
+
+ if (!exist)
+ {
+ LOGE("[%s] NO_KEY(0x%08x) : fail to find given key(%s)", __FUNCTION__, PREFERENCE_ERROR_NO_KEY, key);
+ return PREFERENCE_ERROR_NO_KEY;
+ }
+
+ if (!is_update_hook_registered)
+ {
+ sqlite3_update_hook(pref_db, _update_cb, NULL);
+ is_update_hook_registered = true;
+ }
+
+ return _add_node(key, callback, user_data);
+}
+
+int preference_unset_changed_cb(const char *key)
+{
+ if (pref_db == NULL)
+ {
+ if (_initialize() != PREFERENCE_ERROR_NONE)
+ {
+ return PREFERENCE_ERROR_IO_ERROR;
+ }
+ }
+
+ return _remove_node(key);
+}
+
+int preference_foreach_item(preference_item_cb callback, void *user_data)
+{
+ int ret;
+ char *buf;
+ char **result;
+ int rows;
+ int columns;
+ char *errmsg;
+ int i;
+
+ if (pref_db == NULL)
+ {
+ if (_initialize() != PREFERENCE_ERROR_NONE)
+ {
+ LOGE("[%s] IO_ERROR(0x%08x) : fail to initialize db", __FUNCTION__, PREFERENCE_ERROR_IO_ERROR);
+ return PREFERENCE_ERROR_IO_ERROR;
+ }
+ }
+
+ if (callback == NULL)
+ {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x)", __FUNCTION__, PREFERENCE_ERROR_INVALID_PARAMETER);
+ return PREFERENCE_ERROR_INVALID_PARAMETER;
+ }
+
+ buf = sqlite3_mprintf("SELECT %s FROM %s;", PREF_F_KEY_NAME, PREF_TBL_NAME);
+ if (buf == NULL)
+ {
+ LOGE("[%s] IO_ERROR(0x%08x) : fail to create query string", __FUNCTION__, PREFERENCE_ERROR_IO_ERROR);
+ return PREFERENCE_ERROR_IO_ERROR;
+ }
+
+ ret = sqlite3_get_table(pref_db, buf, &result, &rows, &columns, &errmsg);
+ sqlite3_free(buf);
+ if (ret != SQLITE_OK)
+ {
+ LOGE("[%s] IO_ERROR(0x%08x) : fail to read data (%s)", __FUNCTION__, PREFERENCE_ERROR_IO_ERROR, errmsg);
+ sqlite3_free(errmsg);
+ return PREFERENCE_ERROR_IO_ERROR;
+ }
+
+ for (i = 1; i <= rows; i++)
+ {
+ if (callback(result[i], user_data) != true)
+ {
+ break;
+ }
+ }
+
+ sqlite3_free_table(result);
+
+ return PREFERENCE_ERROR_NONE;
+}
+
diff --git a/src/service.c b/src/service.c
new file mode 100755
index 0000000..3220161
--- /dev/null
+++ b/src/service.c
@@ -0,0 +1,1145 @@
+/*
+ * Copyright (c) 2011 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 <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <errno.h>
+
+#include <bundle.h>
+#include <aul.h>
+#include <appsvc.h>
+#include <dlog.h>
+
+#include <app_service.h>
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+
+#define LOG_TAG "TIZEN_N_SERVICE"
+
+#define BUNDLE_KEY_PREFIX_AUL "__AUL_"
+#define BUNDLE_KEY_PREFIX_SERVICE "__APP_SVC_"
+
+#define BUNDLE_KEY_OPERATION "__APP_SVC_OP_TYPE__"
+#define BUNDLE_KEY_URI "__APP_SVC_URI__"
+#define BUNDLE_KEY_MIME "__APP_SVC_MIME_TYPE__"
+#define BUNDLE_KEY_DATA "__APP_SVC_DATA__"
+#define BUNDLE_KEY_PACKAGE "__APP_SVC_PKG_NAME__"
+
+typedef enum {
+ SERVICE_TYPE_USER,
+ SERVICE_TYPE_EVENT,
+ SERVICE_TYPE_REPLY,
+} service_type_e;
+
+struct service_s {
+ int id;
+ service_type_e type;
+ bundle *data;
+};
+
+typedef struct service_request_context_s {
+ service_h service;
+ service_reply_cb reply_cb;
+ void *user_data;
+} *service_request_context_h;
+
+static int service_create_request(service_h *service);
+
+static int service_create_reply(bundle *data, struct service_s **service);
+
+static int service_validate_extra_data(const char *data)
+{
+ if (data == NULL || data[0] == '\0')
+ {
+ return SERVICE_ERROR_INVALID_PARAMETER;
+ }
+
+ return SERVICE_ERROR_NONE;
+}
+
+static int service_valiate_service(service_h service)
+{
+ if (service == NULL || service->data == NULL)
+ {
+ return SERVICE_ERROR_INVALID_PARAMETER;
+ }
+
+ return SERVICE_ERROR_NONE;
+}
+
+static int service_new_id()
+{
+ static int sid = 0;
+ return sid++;
+}
+
+int service_validate_internal_key(const char *key)
+{
+ if (strncmp(BUNDLE_KEY_PREFIX_AUL, key, strlen(BUNDLE_KEY_PREFIX_AUL)) == 0)
+ {
+ return -1;
+ }
+
+ if (strncmp(BUNDLE_KEY_PREFIX_SERVICE, key, strlen(BUNDLE_KEY_PREFIX_SERVICE)) == 0)
+ {
+ return -1;
+ }
+
+ return 0;
+}
+
+static void service_request_result_broker(bundle *appsvc_bundle, int appsvc_request_code, appsvc_result_val appsvc_result, void *appsvc_data)
+{
+ service_request_context_h request_context;
+ service_h request;
+ service_h reply;
+ service_result_e result;
+ void *user_data;
+ service_reply_cb reply_cb;
+
+ if (appsvc_data == NULL)
+ {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid service reply", __FUNCTION__, SERVICE_ERROR_INVALID_PARAMETER);
+ return;
+ }
+
+ if (service_create_reply(appsvc_bundle, &reply) != 0)
+ {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x) : failed to create service reply", __FUNCTION__, SERVICE_ERROR_INVALID_PARAMETER);
+ return;
+ }
+
+ request_context = appsvc_data;
+ request = request_context->service;
+
+ switch (appsvc_result)
+ {
+ case APPSVC_RES_OK:
+ result = SERVICE_RESULT_SUCCEEDED;
+ break;
+
+ case APPSVC_RES_NOT_OK:
+ result = SERVICE_RESULT_FAILED;
+ break;
+
+ case APPSVC_RES_CANCEL:
+ result = SERVICE_RESULT_CANCELED;
+ break;
+
+ default:
+ result = SERVICE_RESULT_CANCELED;
+ break;
+ }
+
+ user_data = request_context->user_data;
+
+ reply_cb = request_context->reply_cb;
+
+ if (reply_cb != NULL)
+ {
+ reply_cb(request, reply, result, user_data);
+ }
+ else
+ {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid callback", __FUNCTION__, SERVICE_ERROR_INVALID_PARAMETER);
+ }
+
+}
+
+
+int service_create(service_h *service)
+{
+ return service_create_request(service);
+}
+
+static int service_create_request(service_h *service)
+{
+ struct service_s *service_request;
+
+ if (service == NULL)
+ {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x)", __FUNCTION__, SERVICE_ERROR_INVALID_PARAMETER);
+ return SERVICE_ERROR_INVALID_PARAMETER;
+ }
+
+ service_request = malloc(sizeof(struct service_s));
+
+ if (service_request == NULL)
+ {
+ LOGE("[%s] OUT_OF_MEMORY(0x%08x) : failed to create a service handle", __FUNCTION__, SERVICE_ERROR_OUT_OF_MEMORY);
+ return SERVICE_ERROR_OUT_OF_MEMORY;
+ }
+
+ service_request->type = SERVICE_TYPE_USER;
+
+ service_request->data = bundle_create();
+
+ if (service_request->data == NULL)
+ {
+ free(service_request);
+ LOGE("[%s] OUT_OF_MEMORY(0x%08x) : failed to create a bundle handle", __FUNCTION__);
+ return SERVICE_ERROR_OUT_OF_MEMORY;
+ }
+
+ service_request->id = service_new_id();
+
+ *service = service_request;
+
+ return SERVICE_ERROR_NONE;
+}
+
+int service_create_event(bundle *data, struct service_s **service)
+{
+ struct service_s *service_event;
+
+ const char *operation;
+
+ if (data == NULL || service == NULL)
+ {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x)", __FUNCTION__, SERVICE_ERROR_INVALID_PARAMETER);
+ return SERVICE_ERROR_INVALID_PARAMETER;
+ }
+
+ service_event = malloc(sizeof(struct service_s));
+
+ if (service_event == NULL)
+ {
+ LOGE("[%s] OUT_OF_MEMORY(0x%08x) : failed to create a service handle", __FUNCTION__, SERVICE_ERROR_OUT_OF_MEMORY);
+ return SERVICE_ERROR_OUT_OF_MEMORY;
+ }
+
+ service_event->type = SERVICE_TYPE_EVENT;
+ service_event->data = bundle_dup(data);
+ service_event->id = service_new_id();
+
+ operation = appsvc_get_operation(service_event->data);
+
+ if (operation == NULL)
+ {
+ appsvc_set_operation(service_event->data, SERVICE_OPERATION_DEFAULT);
+ }
+
+ *service = service_event;
+
+ return SERVICE_ERROR_NONE;
+}
+
+int service_impl_create_event(bundle *data, struct service_s **service)
+{
+ return service_create_event(data, service);
+}
+
+static int service_create_reply(bundle *data, struct service_s **service)
+{
+ struct service_s *service_reply;
+
+ if (data == NULL || service == NULL)
+ {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x)", __FUNCTION__, SERVICE_ERROR_INVALID_PARAMETER);
+ return SERVICE_ERROR_INVALID_PARAMETER;
+ }
+
+ service_reply = malloc(sizeof(struct service_s));
+
+ if (service_reply == NULL)
+ {
+ LOGE("[%s] OUT_OF_MEMORY(0x%08x) : failed to create a service handle", __FUNCTION__, SERVICE_ERROR_OUT_OF_MEMORY);
+ return SERVICE_ERROR_OUT_OF_MEMORY;
+ }
+
+ service_reply->type = SERVICE_TYPE_REPLY;
+ service_reply->data = bundle_dup(data);
+ service_reply->id = service_new_id();
+
+ *service = service_reply;
+
+ return SERVICE_ERROR_NONE;
+}
+
+int service_destroy(service_h service)
+{
+ if (service_valiate_service(service))
+ {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid handle", __FUNCTION__, SERVICE_ERROR_INVALID_PARAMETER);
+ return SERVICE_ERROR_INVALID_PARAMETER;
+ }
+
+ bundle_free(service->data);
+ service->data = NULL;
+ free(service);
+
+ return SERVICE_ERROR_NONE;
+}
+
+int service_to_bundle(service_h service, bundle **data)
+{
+ if (service_valiate_service(service))
+ {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid handle", __FUNCTION__, SERVICE_ERROR_INVALID_PARAMETER);
+ return SERVICE_ERROR_INVALID_PARAMETER;
+ }
+
+ if (data == NULL)
+ {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid output param", __FUNCTION__, SERVICE_ERROR_INVALID_PARAMETER);
+ return SERVICE_ERROR_INVALID_PARAMETER;
+ }
+
+ *data = service->data;
+
+ return SERVICE_ERROR_NONE;
+}
+
+int service_set_operation(service_h service, const char *operation)
+{
+ if (service_valiate_service(service))
+ {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid handle", __FUNCTION__, SERVICE_ERROR_INVALID_PARAMETER);
+ return SERVICE_ERROR_INVALID_PARAMETER;
+ }
+
+ if (operation != NULL)
+ {
+ if (appsvc_set_operation(service->data, operation) != 0)
+ {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid operation", __FUNCTION__, SERVICE_ERROR_INVALID_PARAMETER);
+ return SERVICE_ERROR_INVALID_PARAMETER;
+ }
+ }
+ else
+ {
+ bundle_del(service->data, BUNDLE_KEY_OPERATION);
+ }
+
+ return SERVICE_ERROR_NONE;
+}
+
+int service_get_operation(service_h service, char **operation)
+{
+ const char *operation_value;
+
+ if (service_valiate_service(service))
+ {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid handle", __FUNCTION__, SERVICE_ERROR_INVALID_PARAMETER);
+ return SERVICE_ERROR_INVALID_PARAMETER;
+ }
+
+ if (operation == NULL)
+ {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid operation", __FUNCTION__, SERVICE_ERROR_INVALID_PARAMETER);
+ return SERVICE_ERROR_INVALID_PARAMETER;
+ }
+
+ operation_value = appsvc_get_operation(service->data);
+
+ if (operation_value != NULL)
+ {
+ *operation = strdup(operation_value);
+ }
+ else
+ {
+ *operation = NULL;
+ }
+
+ return SERVICE_ERROR_NONE;
+}
+
+
+int service_set_uri(service_h service, const char *uri)
+{
+ if (service_valiate_service(service))
+ {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid handle", __FUNCTION__, SERVICE_ERROR_INVALID_PARAMETER);
+ return SERVICE_ERROR_INVALID_PARAMETER;
+ }
+
+ if (uri != NULL)
+ {
+ if (appsvc_set_uri(service->data, uri) != 0)
+ {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x : invalid URI)", __FUNCTION__, SERVICE_ERROR_INVALID_PARAMETER);
+ return SERVICE_ERROR_INVALID_PARAMETER;
+ }
+ }
+ else
+ {
+ bundle_del(service->data, BUNDLE_KEY_URI);
+ }
+
+ return SERVICE_ERROR_NONE;
+}
+
+
+int service_get_uri(service_h service, char **uri)
+{
+ const char *uri_value;
+
+ if (service_valiate_service(service))
+ {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid handle", __FUNCTION__, SERVICE_ERROR_INVALID_PARAMETER);
+ return SERVICE_ERROR_INVALID_PARAMETER;
+ }
+
+ if (uri == NULL)
+ {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid URI", __FUNCTION__, SERVICE_ERROR_INVALID_PARAMETER);
+ return SERVICE_ERROR_INVALID_PARAMETER;
+ }
+
+ uri_value = appsvc_get_uri(service->data);
+
+ if (uri_value != NULL)
+ {
+ *uri = strdup(uri_value);
+ }
+ else
+ {
+ *uri = NULL;
+ }
+
+ return SERVICE_ERROR_NONE;
+}
+
+
+int service_set_mime(service_h service, const char *mime)
+{
+ if (service_valiate_service(service))
+ {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid handle", __FUNCTION__, SERVICE_ERROR_INVALID_PARAMETER);
+ return SERVICE_ERROR_INVALID_PARAMETER;
+ }
+
+ if (mime != NULL)
+ {
+ if (appsvc_set_mime(service->data, mime) != 0)
+ {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid MIME type", __FUNCTION__, SERVICE_ERROR_INVALID_PARAMETER);
+ return SERVICE_ERROR_INVALID_PARAMETER;
+ }
+ }
+ else
+ {
+ bundle_del(service->data, BUNDLE_KEY_MIME);
+ }
+
+ return SERVICE_ERROR_NONE;
+}
+
+
+int service_get_mime(service_h service, char **mime)
+{
+ const char *mime_value;
+
+ if (service_valiate_service(service))
+ {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid handle", __FUNCTION__, SERVICE_ERROR_INVALID_PARAMETER);
+ return SERVICE_ERROR_INVALID_PARAMETER;
+ }
+
+ if (mime == NULL)
+ {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid MIME type", __FUNCTION__, SERVICE_ERROR_INVALID_PARAMETER);
+ return SERVICE_ERROR_INVALID_PARAMETER;
+ }
+
+ mime_value = appsvc_get_mime(service->data);
+
+ if (mime_value != NULL)
+ {
+ *mime = strdup(mime_value);
+ }
+ else
+ {
+ *mime = NULL;
+ }
+
+ return SERVICE_ERROR_NONE;
+}
+
+
+int service_set_package(service_h service, const char *package)
+{
+ if (service_valiate_service(service))
+ {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid handle", __FUNCTION__, SERVICE_ERROR_INVALID_PARAMETER);
+ return SERVICE_ERROR_INVALID_PARAMETER;
+ }
+
+ if (package != NULL)
+ {
+ if (appsvc_set_pkgname(service->data, package) != 0)
+ {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid package", __FUNCTION__, SERVICE_ERROR_INVALID_PARAMETER);
+ return SERVICE_ERROR_INVALID_PARAMETER;
+ }
+ }
+ else
+ {
+ bundle_del(service->data, BUNDLE_KEY_PACKAGE);
+ }
+
+ return SERVICE_ERROR_NONE;
+}
+
+int service_get_package(service_h service, char **package)
+{
+ const char *package_value;
+
+ if (service_valiate_service(service))
+ {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid handle", __FUNCTION__, SERVICE_ERROR_INVALID_PARAMETER);
+ return SERVICE_ERROR_INVALID_PARAMETER;
+ }
+
+ if (package == NULL)
+ {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid package", __FUNCTION__, SERVICE_ERROR_INVALID_PARAMETER);
+ return SERVICE_ERROR_INVALID_PARAMETER;
+ }
+
+ package_value = appsvc_get_pkgname(service->data);
+
+ if (package_value != NULL)
+ {
+ *package = strdup(package_value);
+ }
+ else
+ {
+ *package = NULL;
+ }
+
+ return SERVICE_ERROR_NONE;
+}
+
+int service_clone(service_h *clone, service_h service)
+{
+ service_h service_clone;
+
+ if (service_valiate_service(service))
+ {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid handle", __FUNCTION__, SERVICE_ERROR_INVALID_PARAMETER);
+ return SERVICE_ERROR_INVALID_PARAMETER;
+ }
+
+ if (clone == NULL)
+ {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid handle", __FUNCTION__, SERVICE_ERROR_INVALID_PARAMETER);
+ return SERVICE_ERROR_INVALID_PARAMETER;
+ }
+
+ service_clone = malloc(sizeof(struct service_s));
+
+ if (service_clone == NULL)
+ {
+ LOGE("[%s] OUT_OF_MEMORY(0x%08x) : failed to create a service handle", __FUNCTION__, SERVICE_ERROR_OUT_OF_MEMORY);
+ return SERVICE_ERROR_OUT_OF_MEMORY;
+ }
+
+ service_clone->id = service_new_id();
+ service_clone->type = service->type;
+ service_clone->data = bundle_dup(service->data);
+
+ *clone = service_clone;
+
+ return SERVICE_ERROR_NONE;
+}
+
+
+int service_send_launch_request(service_h service, service_reply_cb callback, void *user_data)
+{
+ const char *operation;
+ const char *uri;
+ const char *mime;
+ const char *package;
+
+ bool implicit_default_operation = false;
+ int launch_pid;
+
+ if (service_valiate_service(service))
+ {
+ LOGE("[%s] INVALID_PARAMETER : invalid handle", __FUNCTION__);
+ return SERVICE_ERROR_INVALID_PARAMETER;
+ }
+
+ operation = appsvc_get_operation(service->data);
+
+ if (operation == NULL)
+ {
+ implicit_default_operation = true;
+ operation = SERVICE_OPERATION_DEFAULT;
+ }
+
+ uri = appsvc_get_uri(service->data);
+ mime = appsvc_get_mime(service->data);
+ package = appsvc_get_pkgname(service->data);
+
+ // operation : default
+ if (!strcmp(operation, SERVICE_OPERATION_DEFAULT))
+ {
+ if (package == NULL || package[0] == '\0')
+ {
+ LOGE("[%s] APP_NOT_FOUND(0x%08x) : package must be specified if the operation is default", __FUNCTION__, SERVICE_ERROR_APP_NOT_FOUND);
+ return SERVICE_ERROR_APP_NOT_FOUND;
+ }
+ }
+
+ if (package != NULL && package[0] != '\0')
+ {
+ if (aul_app_is_running(package))
+ {
+ if (aul_open_app(package) <= 0)
+ {
+ LOGE("[%s] APP_NOT_FOUND(0x%08x) : resume the application(%s)", __FUNCTION__, SERVICE_ERROR_APP_NOT_FOUND, package);
+ return SERVICE_ERROR_APP_NOT_FOUND;
+ }
+ }
+ }
+
+ service_request_context_h request_context = NULL;
+
+ if (callback != NULL)
+ {
+ request_context = calloc(1, sizeof(struct service_request_context_s));
+ // request_context will be deallocated from service_request_result_broker()
+
+ if (request_context == NULL)
+ {
+ LOGE("[%s] OUT_OF_MEMORY(0x%08x)", __FUNCTION__, SERVICE_ERROR_OUT_OF_MEMORY);
+ return SERVICE_ERROR_OUT_OF_MEMORY;
+ }
+
+ request_context->reply_cb = callback;
+ request_context->service = service;
+ request_context->user_data = user_data;
+ }
+
+ if (implicit_default_operation == true)
+ {
+ appsvc_set_operation(service->data, SERVICE_OPERATION_DEFAULT);
+ }
+
+ launch_pid = appsvc_run_service(service->data, service->id, callback ? service_request_result_broker : NULL, request_context);
+
+ if (implicit_default_operation == true)
+ {
+ bundle_del(service->data, BUNDLE_KEY_OPERATION);
+ }
+
+ if (launch_pid < 0)
+ {
+ LOGE("[%s] APP_NOT_FOUND(0x%08x) : operation(%s) package(%s) uri(%s) mime(%s)",
+ __FUNCTION__, SERVICE_ERROR_APP_NOT_FOUND, operation, package, uri, mime);
+ return SERVICE_ERROR_APP_NOT_FOUND;
+ }
+
+ return SERVICE_ERROR_NONE;
+}
+
+static bool service_copy_reply_data_cb(service_h service, const char *key, void *user_data)
+{
+ bundle *reply_data;
+ char *value;
+
+ if (user_data == NULL)
+ {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x)", __FUNCTION__, SERVICE_ERROR_INVALID_PARAMETER);
+ return false;
+ }
+
+ reply_data = user_data;
+
+ service_get_extra_data(service, key, &value);
+
+ appsvc_add_data(reply_data, key, value);
+
+ return true;
+}
+
+int service_reply_to_launch_request(service_h reply, service_h request, service_result_e result)
+{
+ bundle *reply_data;
+ int appsvc_result;
+
+ if (service_valiate_service(reply))
+ {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid reply handle", __FUNCTION__, SERVICE_ERROR_INVALID_PARAMETER);
+ return SERVICE_ERROR_INVALID_PARAMETER;
+ }
+
+ if (service_valiate_service(request))
+ {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid request handle", __FUNCTION__, SERVICE_ERROR_INVALID_PARAMETER);
+ return SERVICE_ERROR_INVALID_PARAMETER;
+ }
+
+ if (appsvc_create_result_bundle(request->data, &reply_data) != 0)
+ {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x) : failed to create result bundle", __FUNCTION__, SERVICE_ERROR_INVALID_PARAMETER);
+ return SERVICE_ERROR_INVALID_PARAMETER;
+ }
+
+ service_foreach_extra_data(reply, service_copy_reply_data_cb, reply_data);
+
+ switch (result)
+ {
+ case SERVICE_RESULT_SUCCEEDED:
+ appsvc_result = APPSVC_RES_OK;
+ break;
+
+ case SERVICE_RESULT_FAILED:
+ appsvc_result = APPSVC_RES_NOT_OK;
+ break;
+
+ case SERVICE_RESULT_CANCELED:
+ appsvc_result = APPSVC_RES_CANCEL;
+ break;
+
+ default:
+ appsvc_result = APPSVC_RES_CANCEL;
+ break;
+ }
+
+ appsvc_send_result(reply_data, appsvc_result);
+
+ return SERVICE_ERROR_NONE;
+}
+
+
+int service_add_extra_data(service_h service, const char *key, const char *value)
+{
+ if (service_valiate_service(service))
+ {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid handle", __FUNCTION__, SERVICE_ERROR_INVALID_PARAMETER);
+ return SERVICE_ERROR_INVALID_PARAMETER;
+ }
+
+ if (service_validate_extra_data(key))
+ {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid key", __FUNCTION__, SERVICE_ERROR_INVALID_PARAMETER);
+ return SERVICE_ERROR_INVALID_PARAMETER;
+ }
+
+ if (service_validate_internal_key(key))
+ {
+ LOGE("[%s] KEY_REJECTED(0x%08x) : key(%s) rejected", __FUNCTION__, SERVICE_ERROR_KEY_REJECTED, key);
+ return SERVICE_ERROR_KEY_REJECTED;
+ }
+
+ if (service_validate_extra_data(value))
+ {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid value", __FUNCTION__, SERVICE_ERROR_INVALID_PARAMETER);
+ return SERVICE_ERROR_INVALID_PARAMETER;
+ }
+
+ if (appsvc_get_data(service->data, key) != NULL)
+ {
+ // overwrite any existing value
+ bundle_del(service->data, key);
+ }
+
+ if (appsvc_add_data(service->data, key, value) != 0)
+ {
+ LOGE("[%s] KEY_REJECTED(0x%08x) : key(%s)/value(%s) is rejected from appsvc",
+ __FUNCTION__, SERVICE_ERROR_KEY_REJECTED, key, value);
+ return SERVICE_ERROR_KEY_REJECTED;
+ }
+
+ return SERVICE_ERROR_NONE;
+}
+
+
+int service_add_extra_data_array(service_h service, const char *key, const char* value[], int length)
+{
+ if (service_valiate_service(service))
+ {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid handle", __FUNCTION__, SERVICE_ERROR_INVALID_PARAMETER);
+ return SERVICE_ERROR_INVALID_PARAMETER;
+ }
+
+ if (service_validate_extra_data(key))
+ {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid key", __FUNCTION__, SERVICE_ERROR_INVALID_PARAMETER);
+ return SERVICE_ERROR_INVALID_PARAMETER;
+ }
+
+ if (service_validate_internal_key(key))
+ {
+ LOGE("[%s] KEY_REJECTED(0x%08x) : key(%s) rejected", __FUNCTION__, SERVICE_ERROR_INVALID_PARAMETER, key);
+ return SERVICE_ERROR_KEY_REJECTED;
+ }
+
+ if (value == NULL || length <= 0)
+ {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid array", __FUNCTION__, SERVICE_ERROR_INVALID_PARAMETER);
+ return SERVICE_ERROR_INVALID_PARAMETER;
+ }
+
+ if (appsvc_get_data_array(service->data, key, NULL) != NULL)
+ {
+ // overwrite any existing value
+ bundle_del(service->data,key);
+ }
+
+ if (appsvc_add_data_array(service->data, key, value, length) != 0)
+ {
+ LOGE("[%s] KEY_REJECTED(0x%08x) : key(%s) is rejected from appsvc", __FUNCTION__, SERVICE_ERROR_KEY_REJECTED, key);
+ return SERVICE_ERROR_KEY_REJECTED;
+ }
+
+ return SERVICE_ERROR_NONE;
+}
+
+
+int service_remove_extra_data(service_h service, const char *key)
+{
+ if (service_valiate_service(service))
+ {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid handle", __FUNCTION__, SERVICE_ERROR_INVALID_PARAMETER);
+ return SERVICE_ERROR_INVALID_PARAMETER;
+ }
+
+ if (service_validate_extra_data(key))
+ {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid key", __FUNCTION__, SERVICE_ERROR_INVALID_PARAMETER);
+ return SERVICE_ERROR_INVALID_PARAMETER;
+ }
+
+ if (service_validate_internal_key(key))
+ {
+ LOGE("[%s] KEY_REJECTED(0x%08x) : key(%s) rejected", __FUNCTION__, SERVICE_ERROR_KEY_REJECTED, key);
+ return SERVICE_ERROR_KEY_REJECTED;
+ }
+
+ if (bundle_del(service->data, key))
+ {
+ LOGE("[%s] KEY_NOT_FOUND(0x%08x) : key(%s)", __FUNCTION__, SERVICE_ERROR_KEY_NOT_FOUND, key);
+ return SERVICE_ERROR_KEY_NOT_FOUND;
+ }
+
+ return SERVICE_ERROR_NONE;
+}
+
+
+int service_get_extra_data(service_h service, const char *key, char **value)
+{
+ const char *data_value;
+
+ if (service_valiate_service(service))
+ {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid handle", __FUNCTION__, SERVICE_ERROR_INVALID_PARAMETER);
+ return SERVICE_ERROR_INVALID_PARAMETER;
+ }
+
+ if (service_validate_extra_data(key))
+ {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid key", __FUNCTION__, SERVICE_ERROR_INVALID_PARAMETER);
+ return SERVICE_ERROR_INVALID_PARAMETER;
+ }
+
+ if (service_validate_internal_key(key))
+ {
+ LOGE("[%s] KEY_REJECTED(0x%08x) : key(%s) rejected", __FUNCTION__, SERVICE_ERROR_KEY_REJECTED, key);
+ return SERVICE_ERROR_KEY_REJECTED;
+ }
+
+ if (value == NULL)
+ {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid value", __FUNCTION__, SERVICE_ERROR_INVALID_PARAMETER);
+ return SERVICE_ERROR_INVALID_PARAMETER;
+ }
+
+ data_value = appsvc_get_data(service->data, key);
+
+ if (data_value == NULL)
+ {
+ if (errno == ENOTSUP)
+ {
+ LOGE("[%s] INVALID_DATA_TYPE(0x%08x) : key(%s)", __FUNCTION__, SERVICE_ERROR_INVALID_DATA_TYPE, key);
+ return SERVICE_ERROR_INVALID_DATA_TYPE;
+ }
+ else
+ {
+ LOGE("[%s] KEY_NOT_FOUND(0x%08x) : key(%s)", __FUNCTION__, SERVICE_ERROR_INVALID_DATA_TYPE, key);
+ return SERVICE_ERROR_KEY_NOT_FOUND;
+ }
+ }
+
+ *value = strdup(data_value);
+
+ return SERVICE_ERROR_NONE;
+}
+
+
+int service_get_extra_data_array(service_h service, const char *key, char ***value, int *length)
+{
+ const char **array_data;
+ int array_data_length;
+ char **array_data_clone;
+ int i;
+
+ if (service_valiate_service(service))
+ {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid handle", __FUNCTION__, SERVICE_ERROR_INVALID_PARAMETER);
+ return SERVICE_ERROR_INVALID_PARAMETER;
+ }
+
+ if (service_validate_extra_data(key))
+ {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid key", __FUNCTION__, SERVICE_ERROR_INVALID_PARAMETER);
+ return SERVICE_ERROR_INVALID_PARAMETER;
+ }
+
+ if (service_validate_internal_key(key))
+ {
+ LOGE("[%s] KEY_REJECTED(0x%08x) : key(%s) rejected", __FUNCTION__, SERVICE_ERROR_KEY_REJECTED, key);
+ return SERVICE_ERROR_KEY_REJECTED;
+ }
+
+ if (value == NULL || length == 0)
+ {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid value", __FUNCTION__, SERVICE_ERROR_INVALID_PARAMETER);
+ return SERVICE_ERROR_INVALID_PARAMETER;
+ }
+
+ array_data = appsvc_get_data_array(service->data, key, &array_data_length);
+
+ if (array_data == NULL)
+ {
+ if (errno == ENOTSUP)
+ {
+ LOGE("[%s] INVALID_DATA_TYPE(0x%08x) : key(%s)", __FUNCTION__, SERVICE_ERROR_INVALID_DATA_TYPE, key);
+ return SERVICE_ERROR_INVALID_DATA_TYPE;
+ }
+ else
+ {
+ LOGE("[%s] KEY_NOT_FOUND(0x%08x) : key(%s)", __FUNCTION__, SERVICE_ERROR_KEY_NOT_FOUND, key);
+ return SERVICE_ERROR_KEY_NOT_FOUND;
+ }
+ }
+
+ array_data_clone = calloc(array_data_length, sizeof(char*));
+
+ if (array_data_clone == NULL)
+ {
+ LOGE("[%s] OUT_OF_MEMORY(0x%08x)", __FUNCTION__, SERVICE_ERROR_OUT_OF_MEMORY);
+ return SERVICE_ERROR_OUT_OF_MEMORY;
+ }
+
+ for (i=0; i<array_data_length; i++)
+ {
+ if (array_data[i] != NULL)
+ {
+ array_data_clone[i] = strdup(array_data[i]);
+ }
+ }
+
+ *value = array_data_clone;
+ *length = array_data_length;
+
+ return SERVICE_ERROR_NONE;
+}
+
+
+int service_is_extra_data_array(service_h service, const char *key, bool *array)
+{
+ int retval;
+
+ if (service_valiate_service(service))
+ {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid handle", __FUNCTION__, SERVICE_ERROR_INVALID_PARAMETER);
+ return SERVICE_ERROR_INVALID_PARAMETER;
+ }
+
+ if (service_validate_extra_data(key))
+ {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid key", __FUNCTION__, SERVICE_ERROR_INVALID_PARAMETER);
+ return SERVICE_ERROR_INVALID_PARAMETER;
+ }
+
+ if (array == NULL)
+ {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid output param", __FUNCTION__, SERVICE_ERROR_INVALID_PARAMETER);
+ return SERVICE_ERROR_INVALID_PARAMETER;
+ }
+
+ if (service_validate_internal_key(key))
+ {
+ LOGE("[%s] KEY_REJECTED(0x%08x) : key(%s) rejected", __FUNCTION__, SERVICE_ERROR_KEY_REJECTED, key);
+ return SERVICE_ERROR_KEY_REJECTED;
+ }
+
+ retval = appsvc_data_is_array(service->data, key);
+
+ if (retval == 0)
+ {
+ *array = false;
+ }
+ else if (retval == 1)
+ {
+ *array = true;
+ }
+ else
+ {
+ LOGE("[%s] KEY_NOT_FOUND(0x%08x) : key(%s)", __FUNCTION__, SERVICE_ERROR_KEY_NOT_FOUND, key);
+ return SERVICE_ERROR_KEY_NOT_FOUND;
+ }
+
+ return SERVICE_ERROR_NONE;
+}
+
+
+typedef struct {
+ service_h service;
+ service_extra_data_cb callback;
+ void* user_data;
+ bool* foreach_break;
+} foreach_context_extra_data_t;
+
+static void service_cb_broker_bundle_iterate(const char *key, const char *val, void *data)
+{
+ foreach_context_extra_data_t* foreach_context = NULL;
+ service_extra_data_cb extra_data_cb;
+
+ if (key == NULL || val == NULL || data == NULL)
+ {
+ return;
+ }
+
+ foreach_context = (foreach_context_extra_data_t*)data;
+
+ if ( *(foreach_context->foreach_break) == true)
+ {
+ return;
+ }
+
+ if (service_validate_internal_key(key))
+ {
+ return;
+ }
+
+ extra_data_cb = foreach_context->callback;
+
+ if (extra_data_cb != NULL)
+ {
+ bool stop_foreach = false;
+
+ stop_foreach = !extra_data_cb(foreach_context->service, key, foreach_context->user_data);
+
+ *(foreach_context->foreach_break) = stop_foreach;
+ }
+
+}
+
+int service_foreach_extra_data(service_h service, service_extra_data_cb callback, void *user_data)
+{
+ bool foreach_break = false;
+
+ if (service_valiate_service(service))
+ {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid handle", __FUNCTION__, SERVICE_ERROR_INVALID_PARAMETER);
+ return SERVICE_ERROR_INVALID_PARAMETER;
+ }
+
+ if (callback == NULL)
+ {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid callback", __FUNCTION__, SERVICE_ERROR_INVALID_PARAMETER);
+ return SERVICE_ERROR_INVALID_PARAMETER;
+ }
+
+ foreach_context_extra_data_t foreach_context = {
+ .service = service,
+ .callback = callback,
+ .user_data = user_data,
+ .foreach_break = &foreach_break
+ };
+
+ bundle_iterate(service->data, service_cb_broker_bundle_iterate, &foreach_context);
+
+ return SERVICE_ERROR_NONE;
+}
+
+typedef struct {
+ service_h service;
+ service_app_matched_cb callback;
+ void* user_data;
+ bool* foreach_break;
+} foreach_context_launchable_app_t;
+
+int service_cb_broker_foreach_app_matched(const char *package, void *data)
+{
+ foreach_context_launchable_app_t *foreach_context;
+ service_app_matched_cb app_matched_cb;
+
+ if (package == NULL || data == NULL)
+ {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x)", __FUNCTION__, SERVICE_ERROR_INVALID_PARAMETER);
+ return -1;
+ }
+
+ foreach_context = (foreach_context_launchable_app_t*)data;
+
+ if ( *(foreach_context->foreach_break) == true)
+ {
+ return -1;
+ }
+
+ app_matched_cb = foreach_context->callback;
+
+ if (app_matched_cb != NULL)
+ {
+ bool stop_foreach = false;
+
+ stop_foreach = !app_matched_cb(foreach_context->service, package, foreach_context->user_data);
+
+ *(foreach_context->foreach_break) = stop_foreach;
+ }
+
+ return 0;
+}
+
+int service_foreach_app_matched(service_h service, service_app_matched_cb callback, void *user_data)
+{
+ bool foreach_break = false;
+
+ if (service_valiate_service(service))
+ {
+ LOGE( "[%s] INVALID_PARAMETER(0x%08x) : invalid handle", __FUNCTION__, SERVICE_ERROR_INVALID_PARAMETER);
+ return SERVICE_ERROR_INVALID_PARAMETER;
+ }
+
+ if (callback == NULL)
+ {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid callback", __FUNCTION__, SERVICE_ERROR_INVALID_PARAMETER);
+ return SERVICE_ERROR_INVALID_PARAMETER;
+ }
+
+ foreach_context_launchable_app_t foreach_context = {
+ .service = service,
+ .callback = callback,
+ .user_data = user_data,
+ .foreach_break = &foreach_break
+ };
+
+ appsvc_get_list(service->data, service_cb_broker_foreach_app_matched, &foreach_context);
+
+ return SERVICE_ERROR_NONE;
+}
+
diff --git a/src/storage.c b/src/storage.c
new file mode 100755
index 0000000..e5b4a44
--- /dev/null
+++ b/src/storage.c
@@ -0,0 +1,397 @@
+/*
+ * Copyright (c) 2011 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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/vfs.h>
+
+#include <aul.h>
+#include <dlog.h>
+#include <vconf.h>
+
+#include <app_storage.h>
+#include <app_storage_private.h>
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+
+#define LOG_TAG "TIZEN_N_STORAGE"
+
+static int storage_initialize();
+static int storage_register_device(storage_device_h device);
+static int storage_get_storage(int id, storage_info_h* storage_info);
+
+extern storage_device_h storage_internal_device();
+extern storage_device_h storage_sdcard_device();
+extern storage_device_h storage_usbhost_device();
+
+
+#define STORAGE_MAX 3
+static struct storage_info_s storage_info_table[STORAGE_MAX];
+static int storage_num = 0;
+
+static int storage_register_device(storage_device_h device)
+{
+ if (device == NULL)
+ {
+ return -1;
+ }
+
+ if (storage_num >= STORAGE_MAX)
+ {
+ LOGE("[%s] failed to register device : not enough device table", __FUNCTION__);
+ return -1;
+ }
+
+ storage_info_table[storage_num].id = storage_num;
+ storage_info_table[storage_num].device = device;
+ storage_info_table[storage_num].state = device->get_state();
+ storage_info_table[storage_num].state_cb = NULL;
+ storage_info_table[storage_num].state_cb_data = NULL;
+
+ storage_num++;
+
+ return 0;
+}
+
+static int storage_initialize()
+{
+ storage_device_h dev_internal;
+ storage_device_h dev_sdcard;
+ storage_device_h dev_usbhost;
+
+ dev_internal = storage_internal_device();
+ storage_register_device(dev_internal);
+
+ dev_sdcard = storage_sdcard_device();
+ storage_register_device( dev_sdcard);
+
+ dev_usbhost = storage_usbhost_device();
+ storage_register_device(dev_usbhost);
+
+ return 0;
+}
+
+
+static int storage_get_storage(int id, storage_info_h* storage_info)
+{
+ if (storage_num < 1)
+ {
+ if (storage_initialize() != 0)
+ {
+ return STORAGE_ERROR_NOT_SUPPORTED;
+ }
+ }
+
+ if (id <0 || id >= storage_num)
+ {
+ return STORAGE_ERROR_NOT_SUPPORTED;
+ }
+
+ *storage_info = &(storage_info_table[id]);
+
+ return STORAGE_ERROR_NONE;
+}
+
+
+int storage_foreach_device_supported(storage_device_supported_cb callback, void *user_data)
+{
+ int storage_id = 0;
+ storage_info_h storage_info = NULL;
+ bool foreach_next = false;
+
+ if (callback == NULL)
+ {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid callback", __FUNCTION__, STORAGE_ERROR_INVALID_PARAMETER);
+ return STORAGE_ERROR_INVALID_PARAMETER;
+ }
+
+ while (true)
+ {
+ if (storage_get_storage(storage_id, &storage_info) != 0)
+ {
+ break;
+ }
+
+ storage_id++;
+
+ foreach_next = callback(storage_info->id, storage_info->device->type, storage_info->state, storage_info->device->path, user_data);
+
+ if (foreach_next == false)
+ {
+ break;
+ }
+ }
+
+ return STORAGE_ERROR_NONE;
+}
+
+
+int storage_get_root_directory(int storage, char **path)
+{
+ storage_info_h storage_info;
+
+ if (path == NULL)
+ {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid output param", __FUNCTION__, STORAGE_ERROR_INVALID_PARAMETER);
+ return STORAGE_ERROR_INVALID_PARAMETER;
+ }
+
+ if (storage_get_storage(storage, &storage_info) != 0)
+ {
+ LOGE("[%s] NOT_SUPPORTED(0x%08x) : storage(%d)", __FUNCTION__, STORAGE_ERROR_NOT_SUPPORTED, storage);
+ return STORAGE_ERROR_NOT_SUPPORTED;
+ }
+
+ *path = strdup(storage_info->device->path);
+
+ return STORAGE_ERROR_NONE;
+}
+
+
+int storage_get_type(int storage, storage_type_e *type)
+{
+ storage_info_h storage_info;
+
+ if (type == NULL)
+ {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid output param", __FUNCTION__, STORAGE_ERROR_INVALID_PARAMETER);
+ return STORAGE_ERROR_INVALID_PARAMETER;
+ }
+
+ if (storage_get_storage(storage, &storage_info) != 0)
+ {
+ LOGE("[%s] NOT_SUPPORTED(0x%08x) : storage(%d)", __FUNCTION__, STORAGE_ERROR_NOT_SUPPORTED, storage);
+ return STORAGE_ERROR_NOT_SUPPORTED;
+ }
+
+ *type = storage_info->device->type;
+
+ return STORAGE_ERROR_NONE;
+}
+
+
+int storage_get_state(int storage, storage_state_e *state)
+{
+ storage_info_h storage_info;
+ storage_dev_get_state get_state;
+
+ if (state == NULL)
+ {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid output param", __FUNCTION__, STORAGE_ERROR_INVALID_PARAMETER);
+ return STORAGE_ERROR_INVALID_PARAMETER;
+ }
+
+ if (storage_get_storage(storage, &storage_info) != 0)
+ {
+ LOGE("[%s] NOT_SUPPORTED(0x%08x) : storage(%d)", __FUNCTION__, STORAGE_ERROR_NOT_SUPPORTED, storage);
+ return STORAGE_ERROR_NOT_SUPPORTED;
+ }
+
+ get_state = storage_info->device->get_state;
+
+ if (get_state == NULL)
+ {
+ LOGE("[%s] NOT_SUPPORTED(0x%08x) : storage(%d)", __FUNCTION__, STORAGE_ERROR_NOT_SUPPORTED, storage);
+ return STORAGE_ERROR_NOT_SUPPORTED;
+ }
+
+ storage_info->state = get_state();
+
+ *state = storage_info->state;
+
+ return STORAGE_ERROR_NONE;
+}
+
+
+void storage_dispatch_state_event(storage_state_e state, void* data)
+{
+ storage_info_h storage_info;
+ storage_state_changed_cb state_cb;
+
+ storage_info = data;
+
+ if (storage_info == NULL)
+ {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid storage information", __FUNCTION__, STORAGE_ERROR_INVALID_PARAMETER);
+ return;
+ }
+
+ storage_info->state = state;
+ state_cb = storage_info->state_cb;
+
+ if (state_cb != NULL)
+ {
+ state_cb(storage_info->id, state, storage_info->state_cb_data);
+ }
+}
+
+
+int storage_set_state_changed_cb(int storage, storage_state_changed_cb callback, void *user_data)
+{
+ storage_info_h storage_info;
+ storage_dev_set_state_cb set_state_cb;
+
+ if (callback == NULL)
+ {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid callback", __FUNCTION__, STORAGE_ERROR_INVALID_PARAMETER);
+ return STORAGE_ERROR_INVALID_PARAMETER;
+ }
+
+ if (storage_get_storage(storage, &storage_info) != 0)
+ {
+ LOGE("[%s] NOT_SUPPORTED(0x%08x) : storage(%d)", __FUNCTION__, STORAGE_ERROR_NOT_SUPPORTED, storage);
+ return STORAGE_ERROR_NOT_SUPPORTED;
+ }
+
+ storage_info->state_cb = callback;
+ storage_info->state_cb_data = user_data;
+
+ set_state_cb = storage_info->device->set_state_cb;
+
+ if (set_state_cb == NULL)
+ {
+ LOGE("[%s] NOT_SUPPORTED(0x%08x) : storage(%d)", __FUNCTION__, STORAGE_ERROR_NOT_SUPPORTED, storage);
+ return STORAGE_ERROR_NOT_SUPPORTED;
+ }
+
+ if (set_state_cb(storage_info) != 0)
+ {
+ LOGE("[%s] NOT_SUPPORTED(0x%08x) : storage(%d)", __FUNCTION__, STORAGE_ERROR_NOT_SUPPORTED, storage);
+ return STORAGE_ERROR_NOT_SUPPORTED;
+ }
+
+ return STORAGE_ERROR_NONE;
+}
+
+
+int storage_unset_state_changed_cb(int storage)
+{
+ storage_info_h storage_info;
+ storage_dev_unset_state_cb unset_state_cb;
+
+ if (storage_get_storage(storage, &storage_info) != 0)
+ {
+ LOGE("[%s] NOT_SUPPORTED(0x%08x) : storage(%d)", __FUNCTION__, STORAGE_ERROR_NOT_SUPPORTED, storage);
+ return STORAGE_ERROR_NOT_SUPPORTED;
+ }
+
+ storage_info->state_cb = NULL;
+ unset_state_cb = storage_info->device->unset_state_cb;
+
+ if (unset_state_cb != NULL)
+ {
+ unset_state_cb();
+ }
+
+ return STORAGE_ERROR_NONE;
+}
+
+
+int storage_get_total_space(int storage, unsigned long long *bytes)
+{
+ storage_info_h storage_info;
+ storage_dev_get_space get_space;
+
+ if (bytes == NULL)
+ {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid output param", __FUNCTION__, STORAGE_ERROR_INVALID_PARAMETER);
+ return STORAGE_ERROR_INVALID_PARAMETER;
+ }
+
+ if (storage_get_storage(storage, &storage_info) != 0)
+ {
+ LOGE("[%s] NOT_SUPPORTED(0x%08x) : storage(%d)", __FUNCTION__, STORAGE_ERROR_NOT_SUPPORTED, storage);
+ return STORAGE_ERROR_NOT_SUPPORTED;
+ }
+
+ get_space = storage_info->device->get_space;
+
+ if (get_space == NULL)
+ {
+ LOGE("[%s] NOT_SUPPORTED(0x%08x) : storage(%d)", __FUNCTION__, STORAGE_ERROR_NOT_SUPPORTED, storage);
+ return STORAGE_ERROR_NOT_SUPPORTED;
+ }
+
+ if (get_space(bytes, NULL) != 0)
+ {
+ LOGE("[%s] NOT_SUPPORTED(0x%08x) : storage(%d)", __FUNCTION__, STORAGE_ERROR_NOT_SUPPORTED, storage);
+ return STORAGE_ERROR_NOT_SUPPORTED;
+ }
+
+ return STORAGE_ERROR_NONE;
+}
+
+int storage_get_available_space(int storage, unsigned long long *bytes)
+{
+ storage_info_h storage_info;
+ storage_dev_get_space get_space;
+
+ if (bytes == NULL)
+ {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid output param", __FUNCTION__, STORAGE_ERROR_INVALID_PARAMETER);
+ return STORAGE_ERROR_INVALID_PARAMETER;
+ }
+
+ if (storage_get_storage(storage, &storage_info) != 0)
+ {
+ LOGE("[%s] NOT_SUPPORTED(0x%08x) : storage(%d)", __FUNCTION__, STORAGE_ERROR_NOT_SUPPORTED, storage);
+ return STORAGE_ERROR_NOT_SUPPORTED;
+ }
+
+ get_space = storage_info->device->get_space;
+
+ if (get_space == NULL)
+ {
+ LOGE("[%s] NOT_SUPPORTED(0x%08x) : storage(%d)", __FUNCTION__, STORAGE_ERROR_NOT_SUPPORTED, storage);
+ return STORAGE_ERROR_NOT_SUPPORTED;
+ }
+
+ if (get_space(NULL, bytes) != 0)
+ {
+ LOGE("[%s] NOT_SUPPORTED(0x%08x) : storage(%d)", __FUNCTION__, STORAGE_ERROR_NOT_SUPPORTED, storage);
+ return STORAGE_ERROR_NOT_SUPPORTED;
+ }
+
+ return STORAGE_ERROR_NONE;
+}
+
+int storage_statfs(const char *directory, unsigned long long *total, unsigned long long *available)
+{
+ struct statfs fs;
+
+ if (statfs(directory, &fs) < 0)
+ {
+ LOGE("[%s] statfs returns error(%d) directory(%s)\n", __FUNCTION__, errno, directory);
+ return -1;
+ }
+
+ if (total != NULL)
+ {
+ *total = fs.f_bsize * fs.f_blocks;
+ }
+
+ if (available != NULL)
+ {
+ *available = fs.f_bsize * fs.f_bavail;
+ }
+
+ return 0;
+}
+
diff --git a/src/storage_internal.c b/src/storage_internal.c
new file mode 100755
index 0000000..003ed4d
--- /dev/null
+++ b/src/storage_internal.c
@@ -0,0 +1,79 @@
+/*
+ * Copyright (c) 2011 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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/vfs.h>
+
+#include <aul.h>
+#include <dlog.h>
+#include <vconf.h>
+
+#include <app_storage.h>
+#include <app_storage_private.h>
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+
+#define LOG_TAG "TIZEN_N_STORAGE"
+
+#define INTERNAL_MEMORY_PATH "/opt/media"
+
+static int storage_internal_get_state()
+{
+ return STORAGE_STATE_MOUNTED;
+}
+
+static int storage_internal_set_state_cb(void *data)
+{
+ return 0;
+}
+
+static void storage_internal_unset_state_cb()
+{
+ // empty function
+}
+
+int storage_internal_get_space(unsigned long long *total, unsigned long long *available)
+{
+ return storage_statfs(INTERNAL_MEMORY_PATH, total, available);
+}
+
+storage_device_h storage_internal_device()
+{
+ storage_device_h device;
+
+ device = calloc(1, sizeof(struct storage_device_s));
+
+ if (device == NULL)
+ {
+ LOGE("[%s] OUT_OF_MEMORY(0x%08x)", __FUNCTION__, STORAGE_ERROR_OUT_OF_MEMORY);
+ return NULL;
+ }
+
+ device->type = STORAGE_TYPE_INTERNAL;
+ device->path = INTERNAL_MEMORY_PATH;
+ device->get_state = storage_internal_get_state;
+ device->set_state_cb = storage_internal_set_state_cb;
+ device->unset_state_cb = storage_internal_unset_state_cb;
+ device->get_space = storage_internal_get_space;
+
+ return device;
+}
+
diff --git a/src/storage_sdcard.c b/src/storage_sdcard.c
new file mode 100755
index 0000000..c984ee5
--- /dev/null
+++ b/src/storage_sdcard.c
@@ -0,0 +1,125 @@
+/*
+ * Copyright (c) 2011 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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/vfs.h>
+
+#include <aul.h>
+#include <dlog.h>
+#include <vconf.h>
+
+#include <app_storage.h>
+#include <app_storage_private.h>
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+
+#define LOG_TAG "TIZEN_N_STORAGE"
+
+#define SDCARD_PATH "/opt/storage/sdcard"
+
+static int storage_sdcard_get_state()
+{
+ int sdcard_state = 0;
+
+ vconf_get_int(VCONFKEY_SYSMAN_MMC_STATUS, &sdcard_state);
+
+ switch (sdcard_state)
+ {
+ case VCONFKEY_SYSMAN_MMC_REMOVED:
+ return STORAGE_STATE_REMOVED;
+
+ case VCONFKEY_SYSMAN_MMC_MOUNTED:
+ return STORAGE_STATE_MOUNTED;
+
+ case VCONFKEY_SYSMAN_MMC_INSERTED_NOT_MOUNTED:
+ return STORAGE_STATE_UNMOUNTABLE;
+
+ default:
+ return STORAGE_STATE_REMOVED;
+ }
+}
+
+static void storage_sdcard_state_cb_broker(keynode_t* key, void* data)
+{
+ storage_state_e state;
+ state = storage_sdcard_get_state();
+
+ storage_dispatch_state_event(state, data);
+}
+
+static int storage_sdcard_set_state_cb(void *data)
+{
+ vconf_notify_key_changed(VCONFKEY_SYSMAN_MMC_STATUS, storage_sdcard_state_cb_broker, data);
+ return 0;
+}
+
+static void storage_sdcard_unset_state_cb()
+{
+ vconf_ignore_key_changed(VCONFKEY_SYSMAN_MMC_STATUS, storage_sdcard_state_cb_broker);
+}
+
+static int storage_sdcard_get_space(unsigned long long *total, unsigned long long *available)
+{
+ storage_state_e state;
+ state = storage_sdcard_get_state();
+
+ if (state < STORAGE_STATE_MOUNTED)
+ {
+ if (total != NULL)
+ {
+ *total = 0;
+ }
+
+ if (available != NULL)
+ {
+ *available = 0;
+ }
+
+ return 0;
+ }
+ else
+ {
+ return storage_statfs(SDCARD_PATH, total, available);
+ }
+}
+
+storage_device_h storage_sdcard_device()
+{
+ storage_device_h device;
+
+ device = calloc(1, sizeof(struct storage_device_s));
+
+ if (device == NULL)
+ {
+ LOGE("[%s] OUT_OF_MEMORY(0x%08x)", __FUNCTION__, STORAGE_ERROR_OUT_OF_MEMORY);
+ return NULL;
+ }
+
+ device->type = STORAGE_TYPE_EXTERNAL;
+ device->path = SDCARD_PATH;
+ device->get_state = storage_sdcard_get_state;
+ device->set_state_cb = storage_sdcard_set_state_cb;
+ device->unset_state_cb = storage_sdcard_unset_state_cb;
+ device->get_space = storage_sdcard_get_space;
+
+ return device;
+}
+
diff --git a/src/storage_usbhost.c b/src/storage_usbhost.c
new file mode 100755
index 0000000..b686440
--- /dev/null
+++ b/src/storage_usbhost.c
@@ -0,0 +1,125 @@
+/*
+ * Copyright (c) 2011 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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/vfs.h>
+
+#include <aul.h>
+#include <dlog.h>
+#include <vconf.h>
+
+#include <app_storage.h>
+#include <app_storage_private.h>
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+
+#define LOG_TAG "TIZEN_N_STORAGE"
+
+#define USBHOST_PATH "/opt/storage/usb"
+
+static int storage_usbhost_get_state()
+{
+ int usbhost_state = 0;
+
+ vconf_get_int(VCONFKEY_SYSMAN_USB_HOST_STATUS, &usbhost_state);
+
+ switch (usbhost_state)
+ {
+ case VCONFKEY_SYSMEN_USB_HOST_DISCONNECTED:
+ return STORAGE_STATE_REMOVED;
+
+ case VCONFKEY_SYSMEN_USB_HOST_CONNECTED:
+ return STORAGE_STATE_MOUNTED;
+
+ default:
+ return STORAGE_STATE_REMOVED;
+ }
+}
+
+static void storage_usbhost_state_cb_broker(keynode_t* key, void* data)
+{
+ storage_state_e state;
+
+ state = storage_usbhost_get_state();
+
+ storage_dispatch_state_event(state, data);
+}
+
+static int storage_usbhost_set_state_cb(void *data)
+{
+ vconf_notify_key_changed(VCONFKEY_SYSMAN_USB_HOST_STATUS, storage_usbhost_state_cb_broker, data);
+ return 0;
+}
+
+static void storage_usbhost_unset_state_cb()
+{
+ vconf_ignore_key_changed(VCONFKEY_SYSMAN_USB_HOST_STATUS, storage_usbhost_state_cb_broker);
+}
+
+
+static int storage_usbhost_get_space(unsigned long long *total, unsigned long long *available)
+{
+ storage_state_e state;
+ state = storage_usbhost_get_state();
+
+ if (state < STORAGE_STATE_MOUNTED)
+ {
+ if (total != NULL)
+ {
+ *total = 0;
+ }
+
+ if (available != NULL)
+ {
+ *available = 0;
+ }
+
+ return 0;
+ }
+ else
+ {
+ return storage_statfs(USBHOST_PATH, total, available);
+ }
+}
+
+
+storage_device_h storage_usbhost_device()
+{
+ storage_device_h device;
+
+ device = calloc(1, sizeof(struct storage_device_s));
+
+ if (device == NULL)
+ {
+ LOGE("[%s] OUT_OF_MEMORY(0x%08x)", __FUNCTION__, STORAGE_ERROR_OUT_OF_MEMORY);
+ return NULL;
+ }
+
+ device->type = STORAGE_TYPE_EXTERNAL;
+ device->path = USBHOST_PATH;
+ device->get_state = storage_usbhost_get_state;
+ device->set_state_cb = storage_usbhost_set_state_cb;
+ device->unset_state_cb = storage_usbhost_unset_state_cb;
+ device->get_space = storage_usbhost_get_space;
+
+ return device;
+}
+
diff --git a/src/ui_notification.c b/src/ui_notification.c
new file mode 100755
index 0000000..0de048a
--- /dev/null
+++ b/src/ui_notification.c
@@ -0,0 +1,637 @@
+/*
+ * Copyright (c) 2011 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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdarg.h>
+#include <sys/stat.h>
+
+#include <dlog.h>
+#include <notification.h>
+
+#include <app_service.h>
+#include <app_service_private.h>
+#include <app_ui_notification.h>
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+
+#define LOG_TAG "TIZEN_N_UI_NOTIFICATION"
+
+struct ui_notification_s {
+ notification_h core;
+ bool ongoing;
+ bool posted;
+ char *icon;
+ struct tm *time;
+ char *title;
+ char *content;
+ service_h service;
+};
+
+static int ui_notification_error_handler(int error, const char *func, const char *on_error)
+{
+ int retcode;
+ char *error_msg;
+
+ switch (error)
+ {
+ case NOTIFICATION_ERROR_NONE:
+ retcode = UI_NOTIFICATION_ERROR_NONE;
+ break;
+
+ case NOTIFICATION_ERROR_INVALID_DATA:
+ retcode = UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
+ error_msg = "INVALID_PARAMETER";
+ break;
+
+ case NOTIFICATION_ERROR_NO_MEMORY:
+ retcode = UI_NOTIFICATION_ERROR_OUT_OF_MEMORY;
+ error_msg = "OUT_OF_MEMORY";
+ break;
+
+ case NOTIFICATION_ERROR_FROM_DB:
+ retcode = UI_NOTIFICATION_ERROR_DB_FAILED;
+ error_msg = "DB_FAILED";
+ break;
+
+ case NOTIFICATION_ERROR_ALREADY_EXIST_ID:
+ retcode = UI_NOTIFICATION_ERROR_ALREADY_POSTED;
+ error_msg = "ALREADY_POSTED";
+ break;
+
+ default:
+ retcode = UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
+ error_msg = "INVALID_PARAMETER";
+ }
+
+ if (retcode != UI_NOTIFICATION_ERROR_NONE)
+ {
+ LOGE("[%s] %s(0x%08x) : %s", func, error_msg, retcode, on_error);
+ }
+
+ return retcode;
+}
+
+
+int ui_notification_create(bool ongoing, ui_notification_h *notification)
+{
+ ui_notification_h notification_out;
+
+ if (notification == NULL)
+ {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid output param", __FUNCTION__, UI_NOTIFICATION_ERROR_INVALID_PARAMETER);
+ return UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
+ }
+
+ notification_out = (ui_notification_h)malloc(sizeof(struct ui_notification_s));
+
+ if (notification_out == NULL)
+ {
+ LOGE("[%s] OUT_OF_MEMORY(0x%08x)", __FUNCTION__, UI_NOTIFICATION_ERROR_OUT_OF_MEMORY);
+ return UI_NOTIFICATION_ERROR_OUT_OF_MEMORY;
+ }
+
+ notification_out->ongoing = ongoing;
+ notification_out->posted = false;
+ notification_out->icon = NULL;
+ notification_out->time = NULL;
+ notification_out->title = NULL;
+ notification_out->content = NULL;
+ notification_out->service = NULL;
+
+ *notification = notification_out;
+
+ return UI_NOTIFICATION_ERROR_NONE;
+}
+
+int ui_notification_destroy(ui_notification_h notification)
+{
+ if (notification == NULL)
+ {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid handle", __FUNCTION__, UI_NOTIFICATION_ERROR_INVALID_PARAMETER);
+ return UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
+ }
+
+ if (notification->core)
+ notification_free(notification->core);
+
+ if (notification->icon)
+ free(notification->icon);
+
+ if (notification->time)
+ free(notification->time);
+
+ if (notification->title)
+ free(notification->title);
+
+ if (notification->content)
+ free(notification->content);
+
+ if (notification->service)
+ service_destroy(notification->service);
+
+ free(notification);
+
+ return UI_NOTIFICATION_ERROR_NONE;
+}
+
+
+int ui_notification_set_icon(ui_notification_h notification, const char *path)
+{
+ char *path_dup;
+
+ if (notification == NULL || path == NULL)
+ {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x)", __FUNCTION__, UI_NOTIFICATION_ERROR_INVALID_PARAMETER);
+ return UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
+ }
+
+ if (notification->posted == true)
+ {
+ LOGE("[%s] ALREADY_POSTED(0x%08x) : unable to change the notification", __FUNCTION__, UI_NOTIFICATION_ERROR_ALREADY_POSTED);
+ return UI_NOTIFICATION_ERROR_ALREADY_POSTED;
+ }
+
+ path_dup = strdup(path);
+
+ if (path_dup == NULL)
+ {
+ LOGE("[%s] OUT_OF_MEMORY(0x%08x)", __FUNCTION__, UI_NOTIFICATION_ERROR_OUT_OF_MEMORY);
+ return UI_NOTIFICATION_ERROR_OUT_OF_MEMORY;
+ }
+
+ if (notification->icon != NULL)
+ {
+ free(notification->icon);
+ }
+
+ notification->icon = path_dup;
+
+ return UI_NOTIFICATION_ERROR_NONE;
+}
+
+int ui_notification_get_icon(ui_notification_h notification, char **path)
+{
+ char *path_dup = NULL;
+
+ if (notification == NULL || path == NULL)
+ {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x)", __FUNCTION__, UI_NOTIFICATION_ERROR_INVALID_PARAMETER);
+ return UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
+ }
+
+ if (notification->icon != NULL)
+ {
+ path_dup = strdup(notification->icon);
+
+ if (path_dup == NULL)
+ {
+ LOGE("[%s] OUT_OF_MEMORY(0x%08x)", __FUNCTION__, UI_NOTIFICATION_ERROR_OUT_OF_MEMORY);
+ return UI_NOTIFICATION_ERROR_OUT_OF_MEMORY;
+ }
+ }
+
+ *path = path_dup;
+
+ return UI_NOTIFICATION_ERROR_NONE;
+}
+
+int ui_notification_set_time(ui_notification_h notification, struct tm *time)
+{
+ struct tm *time_dup;
+
+ if (notification == NULL || time == NULL)
+ {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x)", __FUNCTION__, UI_NOTIFICATION_ERROR_INVALID_PARAMETER);
+ return UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
+ }
+
+ if (notification->posted == true)
+ {
+ LOGE("[%s] ALREADY_POSTED(0x%08x) : unable to change the notification", __FUNCTION__, UI_NOTIFICATION_ERROR_ALREADY_POSTED);
+ return UI_NOTIFICATION_ERROR_ALREADY_POSTED;
+ }
+
+ time_dup = malloc(sizeof(struct tm));
+
+ if (time_dup == NULL)
+ {
+ LOGE("[%s] OUT_OF_MEMORY(0x%08x)", __FUNCTION__, UI_NOTIFICATION_ERROR_OUT_OF_MEMORY);
+ return UI_NOTIFICATION_ERROR_OUT_OF_MEMORY;
+ }
+
+ memcpy(time_dup, time, sizeof(struct tm));
+
+ if (notification->time != NULL)
+ {
+ free(notification->time);
+ }
+
+ notification->time = time_dup;
+
+ return UI_NOTIFICATION_ERROR_NONE;
+}
+
+int ui_notification_get_time(ui_notification_h notification, struct tm **time)
+{
+ struct tm *time_dup = NULL;
+
+ if (notification == NULL || time == NULL)
+ {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x)", __FUNCTION__, UI_NOTIFICATION_ERROR_INVALID_PARAMETER);
+ return UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
+ }
+
+ if (notification->time != NULL)
+ {
+ time_dup = malloc(sizeof(struct tm));
+
+ if (time_dup == NULL)
+ {
+ LOGE("[%s] OUT_OF_MEMORY(0x%08x)", __FUNCTION__, UI_NOTIFICATION_ERROR_OUT_OF_MEMORY);
+ return UI_NOTIFICATION_ERROR_OUT_OF_MEMORY;
+ }
+
+ memcpy(time_dup, notification->time, sizeof(struct tm));
+ }
+
+ *time = time_dup;
+
+ return UI_NOTIFICATION_ERROR_NONE;
+}
+
+int ui_notification_set_title(ui_notification_h notification, const char *title)
+{
+ char *title_dup;
+
+ if (notification == NULL || title == NULL)
+ {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x)", __FUNCTION__, UI_NOTIFICATION_ERROR_INVALID_PARAMETER);
+ return UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
+ }
+
+ if (notification->posted == true)
+ {
+ LOGE("[%s] ALREADY_POSTED(0x%08x) : unable to change the notification", __FUNCTION__, UI_NOTIFICATION_ERROR_ALREADY_POSTED);
+ return UI_NOTIFICATION_ERROR_ALREADY_POSTED;
+ }
+
+ title_dup = strdup(title);
+
+ if (title_dup == NULL)
+ {
+ LOGE("[%s] OUT_OF_MEMORY(0x%08x)", __FUNCTION__, UI_NOTIFICATION_ERROR_OUT_OF_MEMORY);
+ return UI_NOTIFICATION_ERROR_OUT_OF_MEMORY;
+ }
+
+ if (notification->title != NULL)
+ {
+ free(notification->title);
+ }
+
+ notification->title = title_dup;
+
+ return UI_NOTIFICATION_ERROR_NONE;
+}
+
+int ui_notification_get_title(ui_notification_h notification, char **title)
+{
+ char *title_dup = NULL;
+
+ if (notification == NULL || title == NULL)
+ {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x)", __FUNCTION__, UI_NOTIFICATION_ERROR_INVALID_PARAMETER);
+ return UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
+ }
+
+ if (notification->title != NULL)
+ {
+ title_dup = strdup(notification->title);
+
+ if (title_dup == NULL)
+ {
+ LOGE("[%s] OUT_OF_MEMORY(0x%08x)", __FUNCTION__, UI_NOTIFICATION_ERROR_OUT_OF_MEMORY);
+ return UI_NOTIFICATION_ERROR_OUT_OF_MEMORY;
+ }
+ }
+
+ *title = title_dup;
+
+ return UI_NOTIFICATION_ERROR_NONE;
+}
+
+
+int ui_notification_set_content(ui_notification_h notification, const char *content)
+{
+ char *content_dup;
+
+ if (notification == NULL || content == NULL)
+ {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x)", __FUNCTION__, UI_NOTIFICATION_ERROR_INVALID_PARAMETER);
+ return UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
+ }
+
+ if (notification->posted == true)
+ {
+ LOGE("[%s] ALREADY_POSTED(0x%08x) : unable to change the notification", __FUNCTION__, UI_NOTIFICATION_ERROR_ALREADY_POSTED);
+ return UI_NOTIFICATION_ERROR_ALREADY_POSTED;
+ }
+
+ content_dup = strdup(content);
+
+ if (content_dup == NULL)
+ {
+ LOGE("[%s] OUT_OF_MEMORY(0x%08x)", __FUNCTION__, UI_NOTIFICATION_ERROR_OUT_OF_MEMORY);
+ return UI_NOTIFICATION_ERROR_OUT_OF_MEMORY;
+ }
+
+ if (notification->content != NULL)
+ {
+ free(notification->content);
+ }
+
+ notification->content = content_dup;
+
+ return UI_NOTIFICATION_ERROR_NONE;
+}
+
+int ui_notification_get_content(ui_notification_h notification, char **content)
+{
+ char *content_dup = NULL;
+
+ if (notification == NULL || content == NULL)
+ {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x)", __FUNCTION__, UI_NOTIFICATION_ERROR_INVALID_PARAMETER);
+ return UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
+ }
+
+ if (notification->content != NULL)
+ {
+ content_dup = strdup(notification->content);
+
+ if (content_dup == NULL)
+ {
+ LOGE("[%s] OUT_OF_MEMORY(0x%08x)", __FUNCTION__, UI_NOTIFICATION_ERROR_OUT_OF_MEMORY);
+ return UI_NOTIFICATION_ERROR_OUT_OF_MEMORY;
+ }
+ }
+
+ *content = content_dup;
+
+ return UI_NOTIFICATION_ERROR_NONE;
+}
+
+
+int ui_notification_set_service(ui_notification_h notification, service_h service)
+{
+ int retcode;
+ service_h service_dup;
+
+ if (notification == NULL || service == NULL)
+ {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x)", __FUNCTION__, UI_NOTIFICATION_ERROR_INVALID_PARAMETER);
+ return UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
+ }
+
+ if (notification->posted == true)
+ {
+ LOGE("[%s] ALREADY_POSTED(0x%08x) : unable to change the notification", __FUNCTION__, UI_NOTIFICATION_ERROR_ALREADY_POSTED);
+ return UI_NOTIFICATION_ERROR_ALREADY_POSTED;
+ }
+
+ retcode = service_clone(&service_dup, service);
+
+ if (retcode != SERVICE_ERROR_NONE)
+ {
+ if (retcode == SERVICE_ERROR_OUT_OF_MEMORY)
+ {
+ LOGE("[%s] OUT_OF_MEMORY(0x%08x)", __FUNCTION__, UI_NOTIFICATION_ERROR_OUT_OF_MEMORY);
+ return UI_NOTIFICATION_ERROR_OUT_OF_MEMORY;
+ }
+ else
+ {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid service handle", __FUNCTION__, UI_NOTIFICATION_ERROR_INVALID_PARAMETER);
+ return UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
+ }
+ }
+
+ if (notification->service != NULL)
+ {
+ service_destroy(notification->service);
+ }
+
+ notification->service = service_dup;
+
+ return UI_NOTIFICATION_ERROR_NONE;
+}
+
+int ui_notification_get_service(ui_notification_h notification, service_h *service)
+{
+ int retcode;
+ service_h service_dup = NULL;
+
+ if (notification == NULL || service == NULL)
+ {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x)", __FUNCTION__, UI_NOTIFICATION_ERROR_INVALID_PARAMETER);
+ return UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
+ }
+
+ if (notification->service != NULL)
+ {
+ retcode = service_clone(&service_dup, notification->service);
+
+ if (retcode != SERVICE_ERROR_NONE)
+ {
+ if (retcode == SERVICE_ERROR_OUT_OF_MEMORY)
+ {
+ LOGE("[%s] OUT_OF_MEMORY(0x%08x)", __FUNCTION__, UI_NOTIFICATION_ERROR_OUT_OF_MEMORY);
+ return UI_NOTIFICATION_ERROR_OUT_OF_MEMORY;
+ }
+ else
+ {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid service handle", __FUNCTION__, UI_NOTIFICATION_ERROR_INVALID_PARAMETER);
+ return UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
+ }
+ }
+ }
+
+ *service = service_dup;
+
+ return UI_NOTIFICATION_ERROR_NONE;
+}
+
+
+int ui_notification_post(ui_notification_h notification)
+{
+ int retcode;
+ notification_h core;
+ bundle *service_data;
+
+ if (notification == NULL)
+ {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x)", __FUNCTION__, UI_NOTIFICATION_ERROR_INVALID_PARAMETER);
+ return UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
+ }
+
+ if (notification->posted == true)
+ {
+ LOGE("[%s] ALREADY_POSTED(0x%08x) : unable to change the notification", __FUNCTION__, UI_NOTIFICATION_ERROR_ALREADY_POSTED);
+ return UI_NOTIFICATION_ERROR_ALREADY_POSTED;
+ }
+
+ // STEP 1: core handle
+ if (notification->ongoing == true)
+ {
+ core = notification_new(NOTIFICATION_TYPE_ONGOING, NOTIFICATION_GROUP_ID_DEFAULT, NOTIFICATION_PRIV_ID_NONE);
+ }
+ else
+ {
+ core = notification_new(NOTIFICATION_TYPE_NOTI, NOTIFICATION_GROUP_ID_DEFAULT, NOTIFICATION_PRIV_ID_NONE);
+ }
+
+ if (core == NULL)
+ {
+ LOGE("[%s] OUT_OF_MEMORY(0x%08x)", __FUNCTION__, UI_NOTIFICATION_ERROR_OUT_OF_MEMORY);
+ return UI_NOTIFICATION_ERROR_OUT_OF_MEMORY;
+ }
+
+ notification->core = core;
+
+ // STEP 2: icon
+ if (notification->icon != NULL)
+ {
+ struct stat st;
+
+ if (stat(notification->icon, &st) < 0)
+ {
+ LOGE("[%s] NO_SUCH_FILE(0x%08x) : invalid icon", __FUNCTION__, UI_NOTIFICATION_ERROR_NO_SUCH_FILE);
+ return UI_NOTIFICATION_ERROR_NO_SUCH_FILE;
+ }
+
+ notification_set_image(core, NOTIFICATION_IMAGE_TYPE_ICON, notification->icon);
+ }
+
+ // STEP 3: time
+ if (notification->time != NULL)
+ {
+ notification_set_time(core, mktime(notification->time));
+ }
+
+ // STEP 4: title
+ if (notification->title != NULL)
+ {
+ notification_set_text(core, NOTIFICATION_TEXT_TYPE_TITLE, notification->title, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
+ }
+
+ // STEP 5: content
+ if (notification->content != NULL)
+ {
+ notification_set_text(core, NOTIFICATION_TEXT_TYPE_CONTENT, notification->content, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
+ }
+
+ // STEP 6: service
+ if (notification->service != NULL && service_to_bundle(notification->service, &service_data) == SERVICE_ERROR_NONE)
+ {
+ notification_set_execute_option(core, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, NULL, NULL, service_data);
+ }
+ else
+ {
+ notification_set_property(core, NOTIFICATION_PROP_DISABLE_APP_LAUNCH);
+ }
+
+ // STEP 7: insert
+ retcode = ui_notification_error_handler(notification_insert(core, NULL), __FUNCTION__, "failed to post a notification");
+
+ if (retcode == UI_NOTIFICATION_ERROR_NONE)
+ {
+ notification->posted = true;
+ }
+
+ return retcode;
+}
+
+int ui_notification_update_progress(ui_notification_h notification, ui_notification_progress_type_e type, double value)
+{
+ int retcode;
+
+ if (notification == NULL)
+ {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x)", __FUNCTION__, UI_NOTIFICATION_ERROR_INVALID_PARAMETER);
+ return UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
+ }
+
+ if (notification->core == NULL || notification->posted == false)
+ {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid handle", __FUNCTION__, UI_NOTIFICATION_ERROR_INVALID_PARAMETER);
+ return UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
+ }
+
+ switch (type)
+ {
+ case UI_NOTIFICATION_PROGRESS_TYPE_SIZE:
+ retcode = ui_notification_error_handler(
+ notification_update_size(notification->core, NOTIFICATION_PRIV_ID_NONE, value),
+ __FUNCTION__, "failed to update the progress");
+ break;
+
+ case UI_NOTIFICATION_PROGRESS_TYPE_PERCENTAGE:
+ retcode = ui_notification_error_handler(
+ notification_update_progress(notification->core, NOTIFICATION_PRIV_ID_NONE, value),
+ __FUNCTION__, "failed to update the progress");
+ break;
+
+ default:
+ LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid progress type", __FUNCTION__, UI_NOTIFICATION_ERROR_INVALID_PARAMETER);
+ return UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
+ }
+
+ return retcode;
+}
+
+int ui_notification_cancel(ui_notification_h notification)
+{
+ int retcode;
+
+ if (notification == NULL)
+ {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x)", __FUNCTION__, UI_NOTIFICATION_ERROR_INVALID_PARAMETER);
+ return UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
+ }
+
+ if (notification->core == NULL || notification->posted == false)
+ {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid handle", __FUNCTION__, UI_NOTIFICATION_ERROR_INVALID_PARAMETER);
+ return UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
+ }
+
+ retcode = ui_notification_error_handler(
+ notification_delete(notification->core),
+ __FUNCTION__, "failed to cancel the notification");
+
+ return retcode;
+}
+
+int ui_notification_cancel_all(void)
+{
+ return ui_notification_error_handler(
+ notification_delete_all_by_type(NULL, NOTIFICATION_TYPE_NONE),
+ __FUNCTION__, "failed to cancel the notification");
+}
+