diff options
author | Jinkun Jang <jinkun.jang@samsung.com> | 2013-03-13 01:45:44 +0900 |
---|---|---|
committer | Jinkun Jang <jinkun.jang@samsung.com> | 2013-03-13 01:45:44 +0900 |
commit | e3038c9c3c7a5c7843d872f2899ffa10abc03cb4 (patch) | |
tree | fd2d8b09ca59f58e8737588c77315595ce65e7eb | |
parent | 5611ff5660d14d0ea707447e84ee4c0626b71104 (diff) | |
download | application-e3038c9c3c7a5c7843d872f2899ffa10abc03cb4.tar.gz application-e3038c9c3c7a5c7843d872f2899ffa10abc03cb4.tar.bz2 application-e3038c9c3c7a5c7843d872f2899ffa10abc03cb4.zip |
Tizen 2.1 base
41 files changed, 9053 insertions, 0 deletions
@@ -0,0 +1,2 @@ +junghyuk park <junghyuk.park@samsung.com> + diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100755 index 0000000..72efefe --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,94 @@ +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(requires "dlog bundle appcore-common appcore-efl aul ail appsvc notification elementary capi-base-common alarm-service sqlite3") +SET(pc_requires "capi-base-common") + +INCLUDE(FindPkgConfig) +pkg_check_modules(${fw_name} REQUIRED ${requires}) +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}) + +SET_TARGET_PROPERTIES(${fw_name} + PROPERTIES + VERSION ${FULLVER} + SOVERSION ${MAJORVER} + CLEAN_DIRECT_OUTPUT 1 +) + +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 ${pc_requires}) +SET(PC_LDFLAGS -l${fw_name}) + +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) + @@ -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.manifest b/capi-appfw-application.manifest new file mode 100755 index 0000000..75b0fa5 --- /dev/null +++ b/capi-appfw-application.manifest @@ -0,0 +1,5 @@ +<manifest> + <request> + <domain name="_"/> + </request> +</manifest> diff --git a/capi-appfw-application.pc.in b/capi-appfw-application.pc.in new file mode 100755 index 0000000..f0c4fb4 --- /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} + 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 100644 index 0000000..c9b21d9 --- /dev/null +++ b/debian/changelog @@ -0,0 +1,246 @@ +capi-appfw-application (0.1.0-23) unstable; urgency=low + + * Updated UI Notification API + * Git: slp/api/application + * Tag: capi-appfw-application_0.1.0-23 + + -- Junghyuk Park <junghyuk.park@samsung.com> Thu, 31 May 2012 13:34:33 +0900 + +capi-appfw-application (0.1.0-22) unstable; urgency=low + + * Bug fixed : service_reply_cb() + * Git: slp/api/application + * Tag: capi-appfw-application_0.1.0-22 + + -- Junghyuk Park <junghyuk.park@samsung.com> Fri, 27 Apr 2012 14:56:37 +0900 + +capi-appfw-application (0.1.0-21) unstable; urgency=low + + * Changed the definitions of service operation and extra-data + * Git: slp/api/application + * Tag: capi-appfw-application_0.1.0-21 + + -- Junghyuk Park <junghyuk.park@samsung.com> Thu, 15 Mar 2012 16:09:18 +0900 + +capi-appfw-application (0.1.0-20) unstable; urgency=low + + * Updated for AIL API changes + * Git: slp/api/application + * Tag: capi-appfw-application_0.1.0-20 + + -- Junghyuk Park <junghyuk.park@samsung.com> Mon, 05 Mar 2012 19:09:02 +0900 + +capi-appfw-application (0.1.0-19) unstable; urgency=low + + * Code refactoring + * Git: slp/api/application + * Tag: capi-appfw-application_0.1.0-19 + + -- Junghyuk Park <junghyuk.park@samsung.com> Wed, 29 Feb 2012 15:29:59 +0900 + +capi-appfw-application (0.1.0-18) unstable; urgency=low + + * Bug fixed : service_foreach_extra_data() + * Git: slp/api/application + * Tag: capi-appfw-application_0.1.0-18 + + -- Junghyuk Park <junghyuk.park@samsung.com> Tue, 21 Feb 2012 14:34:01 +0900 + +capi-appfw-application (0.1.0-17) unstable; urgency=low + + * Added version numbering + * Git: slp/api/application + * Tag: capi-appfw-application_0.1.0-17 + + -- Junghyuk Park <junghyuk.park@samsung.com> Wed, 15 Feb 2012 10:43:30 +0900 + +capi-appfw-application (0.1.0-16) unstable; urgency=low + + * Refactoring code + * Add alarm_get_service() API + * Add ALARM_ERROR_OUT_OF_MEMORY error code + * Git: slp/api/application + * Tag: capi-appfw-application_0.1.0-16 + + -- Junghyuk Park <junghyuk.park@samsung.com> Mon, 13 Feb 2012 11:52:20 +0300 + +capi-appfw-application (0.1.0-15) unstable; urgency=low + + * Fixed invalid parameter + * Git: slp/api/application + * Tag: capi-appfw-application_0.1.0-15 + + -- Junghyuk Park <junghyuk.park@samsung.com> Mon, 30 Jan 2012 13:52:37 +0900 + +capi-appfw-application (0.1.0-14) unstable; urgency=low + + * Update UI-Notification API + * Git: slp/api/application + * Tag: capi-appfw-application_0.1.0-14 + + + -- Junghyuk Park <junghyuk.park@samsung.com> Thu, 26 Jan 2012 16:07:50 +0900 + +capi-appfw-application (0.1.0-13) unstable; urgency=low + + * Update alarm API Doc + * Git: slp/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: slp/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 + + * Application API : changed function prototype + * Git: slp/api/application + * Tag: capi-appfw-application_0.1.0-11 + + -- Junghyuk Park <junghyuk.park@samsung.com> Wed, 14 Dec 2011 14:30:35 +0900 + +capi-appfw-application (0.1.0-10) unstable; urgency=low + + * Fixed bug : Service API + * Git: slp-source.sec.samsung.net:slp/api/application + * Tag: capi-appfw-application_0.1.0-10 + + -- Junghyuk Park <junghyuk.park@samsung.com> Wed, 07 Dec 2011 10:30:11 +0900 + +capi-appfw-application (0.1.0-9) unstable; urgency=low + + * Alarm API : Update boilerplate + * Git: slp-source.sec.samsung.net:slp/api/application + * Tag: capi-appfw-application_0.1.0-9 + + -- Junghyuk Park <junghyuk.park@samsung.com> Tue, 06 Dec 2011 19:09:32 +0900 + +capi-appfw-application (0.1.0-8) unstable; urgency=low + + * Alarm API : update alarm-id + * Git: slp-source.sec.samsung.net:slp/api/application + * Tag: capi-appfw-application_0.1.0-8 + + -- Junghyuk Park <junghyuk.park@samsung.com> Sat, 26 Nov 2011 15:24:08 +0900 + +capi-appfw-application (0.1.0-7) unstable; urgency=low + + * SLP API is renamed Tizen API + * Git: slp-source.sec.samsung.net:slp/api/application + * Tag: capi-appfw-application_0.1.0-7 + + -- Junghyuk Park <junghyuk.park@samsung.com> Wed, 23 Nov 2011 13:48:00 +0900 + +capi-appfw-application (0.1.0-6) unstable; urgency=low + + * Add UI Notification API + * Git: slp-source.sec.samsung.net:slp/api/application + * Tag: capi-appfw-application_0.1.0-6 + + -- Junghyuk Park <junghyuk.park@samsung.com> Mon, 21 Nov 2011 20:54:00 +0900 + +capi-appfw-application (0.1.0-5) unstable; urgency=low + + * DTS : improve functional coverage and conditional coverage + * Git: slp-source.sec.samsung.net:slp/api/application + * Tag: capi-appfw-application_0.1.0-5 + + -- Junghyuk Park <junghyuk.park@samsung.com> Fri, 04 Nov 2011 14:39:01 +0900 + +capi-appfw-application (0.1.0-4) unstable; urgency=low + + * Application API : enum for device orientation is changed + * Service API : array data type is added to extra-data + * Git: slp-source.sec.samsung.net:slp/api/application + * Tag: capi-appfw-application_0.1.0-4 + + -- Junghyuk Park <junghyuk.park@samsung.com> Mon, 24 Oct 2011 20:40:23 +0900 + +capi-appfw-application (0.1.0-3) unstable; urgency=low + + * Alarm API : added application launch by Service API + * Git: slp-source.sec.samsung.net:slp/api/application + * Tag: capi-appfw-application_0.1.0-3 + + -- Junghyuk Park <junghyuk.park@samsung.com> Mon, 10 Oct 2011 15:47:18 +0900 + +capi-appfw-application (0.1.0-2) unstable; urgency=low + + * Fixed bug : service_clone() causes segfault + * Git: slp-source.sec.samsung.net:slp/api/application + * Tag: capi-appfw-application_0.1.0-2 + + -- Junghyuk Park <junghyuk.park@samsung.com> Wed, 05 Oct 2011 16:12:14 +0900 + +capi-appfw-application (0.1.0-1) unstable; urgency=low + + * capi-appfw-application_0.1.0-1 + * Git: slp-source.sec.samsung.net:slp/api/application + * Tag: capi-appfw-application_0.1.0-1 + + -- Junghyuk Park <junghyuk.park@samsung.com> Tue, 27 Sep 2011 21:30:36 +0900 + +capi-appfw-application (0.0.1-7) unstable; urgency=low + + * Service API is added + * Git: slp-source.sec.samsung.net:slp/api/application + * Tag: capi-appfw-application_0.0.1-7 + + -- Junghyuk Park <junghyuk.park@samsung.com> Mon, 26 Sep 2011 17:06:56 +0900 + +capi-appfw-application (0.0.1-6) unstable; urgency=low + * bug fixed : preference API + * Git: slp-source.sec.samsung.net:slp/api/application + * Tag: capi-appfw-application_0.0.1-6 + + -- Junghyuk Park <junghyuk.park@samsung.com> Mon, 05 Sep 2011 21:48:32 +0900 + +capi-appfw-application (0.0.1-5) unstable; urgency=low + + * lib dependecny is updated : sqlite3 + * Git: slp-source.sec.samsung.net:slp/api/application + * Tag: capi-appfw-application_0.0.1-5 + + -- Junghyuk Park <junghyuk.park@samsung.com> Mon, 05 Sep 2011 20:19:00 +0900 + +capi-appfw-application (0.0.1-4) unstable; urgency=low + + * Application API is updated to support Service API + * Storage API is updated to support various storage type + * The file name of each header file of Application FW is updated + + -- Junghyuk Park <junghyuk.park@samsung.com> Mon, 05 Sep 2011 19:29:52 +0900 + +capi-appfw-application (0.0.1-3) unstable; urgency=low + + * System event callbacks are updated to apply Service API changes + * Service API is added to provide application service framework + * Preference API is added to provide persistent application data + * Event Notification API is added to provide interaction between applications + * Git: slp-source.sec.samsung.net:slp/api/application + * Tag: capi-appfw-application_0.0.1-3 + + -- Junghyuk Park <junghyuk.park@samsung.com> Mon, 22 Aug 2011 20:21:28 +0900 + +capi-appfw-application (0.0.1-2) unstable; urgency=low + + * GNU gettext macro is added + * Git: slp-source.sec.samsung.net:slp/api/application + * Tag: capi-appfw-application_0.0.1-2 + + -- Woongsuk Cho <ws77.cho@samsung.com> Tue, 09 Aug 2011 17:52:09 +0900 + +capi-appfw-application (0.0.1-1) unstable; urgency=low + + * Initial upload + * Git: slp-source.sec.samsung.net:slp/api/application + * Tag: capi-appfw-application_0.0.1-1 + + -- Woongsuk Cho <ws77.cho@samsung.com> Thu, 04 Aug 2011 18:36:24 +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..264486a --- /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: ${shlibs: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}), capi-base-common-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..9313173 --- /dev/null +++ b/debian/rules @@ -0,0 +1,68 @@ +#!/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 + +FULLVER ?= $(shell dpkg-parsechangelog | grep Version: | cut -d ' ' -f 2 | cut -d '-' -f 1) +MAJORVER ?= $(shell echo $(FULLVER) | cut -d '.' -f 1) + +configure: configure-stamp +configure-stamp: + dh_testdir + mkdir -p $(CMAKE_BUILD_DIR) && cd $(CMAKE_BUILD_DIR) && cmake .. -DFULLVER=${FULLVER} -DMAJORVER=${MAJORVER} + 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..362178b --- /dev/null +++ b/include/app.h @@ -0,0 +1,400 @@ +/* + * 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 ID of the application. + * + * @remarks @a ID must be released with free() by you. + * + * @param [out] id The ID 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_id(char **id); + + +/** + * @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 pre-allocated 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 pre-allocated 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); + + +/** + * @brief Sets whether reclaiming system cache is enabled in the pause state. + * + * @details If the reclaiming system cache is enabled, the system caches are released as possible when the application's state changes to the pause state. + * + * @remarks The reclaiming system cache is enabled by default + * + * @param [in] enable whether reclaiming system cache is enabled + */ +void app_set_reclaiming_system_cache_on_pause(bool enable); + + +/** + * @} + */ + +#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..5dba683 --- /dev/null +++ b/include/app_alarm.h @@ -0,0 +1,284 @@ +/* + * 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 "http://tizen.org/appcontrol/data/alarm_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_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY /**< Out of memory */ +} 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); + + +/** + * @brief Gets the service to be invoked when the the alarm is triggered + * @remarks The @a service must be released with service_destroy() by you. + * @param[in] alarm_id The alarm ID uniquely identifies an alarm + * @param[out] service The service handle to launch when the alarm is triggered + * @return 0 on success, otherwise a negative error value. + * @retval #ALARM_ERROR_NONE Successful + * @retval #ALARM_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #ALARM_ERROR_OUT_OF_MEMORY Out of memory + * @see alarm_schedule_at_date() + * @see alarm_schedule_after_delay() + * @see alarm_schedule_with_recurrence_week_flag() + */ +int alarm_get_service(int alarm_id, service_h *service); + +/** + * @} + */ + +#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..aaf4a87 --- /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 (4096) + +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..795a642 --- /dev/null +++ b/include/app_private.h @@ -0,0 +1,63 @@ +/* + * 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/usr/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" + +#define PATH_FMT_RO_APP_ROOT "/usr/apps" +#define PATH_FMT_RO_RES_DIR PATH_FMT_RO_APP_ROOT "/%s/res" +#define PATH_FMT_RO_LOCALE_DIR PATH_FMT_RO_RES_DIR "/locale" + +typedef void (*app_finalizer_cb) (void *data); + +int app_error(app_error_e error, const char* function, const char *description); + +app_device_orientation_e app_convert_appcore_rm(enum appcore_rm rm); + +int app_get_package_app_name(const char *package, char **name); + +int app_finalizer_add(app_finalizer_cb callback, void *data); + +int app_finalizer_remove(app_finalizer_cb callback); + +void app_finalizer_execute(void); + +#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..85ac966 --- /dev/null +++ b/include/app_service.h @@ -0,0 +1,705 @@ +/* + * 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 <sys/types.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_LAUNCH_REJECTED = TIZEN_ERROR_UNKNOWN, /**< Internal launch error*/ +} 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 "http://tizen.org/appcontrol/operation/default" + + +/** + * @brief Service operation : provide explicit editable access to the given data. + */ +#define SERVICE_OPERATION_EDIT "http://tizen.org/appcontrol/operation/edit" + + +/** + * @brief Service operation : display the data. + */ +#define SERVICE_OPERATION_VIEW "http://tizen.org/appcontrol/operation/view" + + +/** + * @brief Service operation : pick an item from the data, returning what was selected. + */ +#define SERVICE_OPERATION_PICK "http://tizen.org/appcontrol/operation/pick" + + +/** + * @brief Service operation : create a content, returning what was created. + */ +#define SERVICE_OPERATION_CREATE_CONTENT "http://tizen.org/appcontrol/operation/create_content" + + +/** + * @brief Service operation : perform a call to someone specified by the data. + */ +#define SERVICE_OPERATION_CALL "http://tizen.org/appcontrol/operation/call" + + +/** + * @brief Service operation : deliver some data to someone else. + */ +#define SERVICE_OPERATION_SEND "http://tizen.org/appcontrol/operation/send" + + +/** + * @brief Service operation : deliver text data to someone else. + */ +#define SERVICE_OPERATION_SEND_TEXT "http://tizen.org/appcontrol/operation/send_text" + + +/** + * @brief Service operation : dial a number as specified by the data. + */ +#define SERVICE_OPERATION_DIAL "http://tizen.org/appcontrol/operation/dial" + + +/** + * @brief Service operation : perform a search. + */ +#define SERVICE_OPERATION_SEARCH "http://tizen.org/appcontrol/operation/search" + + +/** + * @brief Service optional data : the subject of a message. + */ +#define SERVICE_DATA_SUBJECT "http://tizen.org/appcontrol/data/subject" + + +/** + * @brief Service optional data : e-mail addresses. + */ +#define SERVICE_DATA_TO "http://tizen.org/appcontrol/data/to" + + +/** + * @brief Service optional data : e-mail addresses that should be carbon copied. + */ +#define SERVICE_DATA_CC "http://tizen.org/appcontrol/data/cc" + + +/** + * @brief Service optional data : e-mail addresses that should be blind carbon copied. + */ +#define SERVICE_DATA_BCC "http://tizen.org/appcontrol/data/bcc" + + +/** + * @brief Service optional data : the content of the data is associated with #SERVICE_OPERATION_SEND. + */ +#define SERVICE_DATA_TEXT "http://tizen.org/appcontrol/data/text" + + +/** + * @brief Service optional data : the title of the data + */ +#define SERVICE_DATA_TITLE "http://tizen.org/appcontrol/data/title" + + +/** + * @brief Service optional data : the path of selected item. + */ +#define SERVICE_DATA_SELECTED "http://tizen.org/appcontrol/data/selected" + + +/** + * @brief Called when the reply of the launch request is delivered. + * + * @remarks The @a request and @a reply must not be deallocated by an application. + * + * @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 *appid, 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 \n + * If the @a operation is NULL, it clears the previous value. + * @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 \n + * If the @a uri is NULL, it clears the previous value. + * @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 \n + * If the @a mime is NULL, it clears the previous value. + * @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 **mime); + + +/** + * @brief Sets the explicit category + * + * @param [in] service The service handle + * @param [in] category the explicit category + * If the @a category is NULL, it clears the previous value. + * @return 0 on success, otherwise a negative error value. + * @retval #SERVICE_ERROR_NONE Successful + * @retval #SERVICE_ERROR_INVALID_PARAMETER Invalid parameter + * @see service_get_category() + */ +int service_set_category(service_h service, const char *category); + + +/** + * @brief Gets the explicit category + * + * @remarks The @a category must be released with free() by you. + * @param [in] service The service handle + * @param [out] category The explicit category + * @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_category() + */ +int service_get_category(service_h service, char **category); + + +/** + * @brief Sets the package name of the application to explicitly launch + * + * @remark This function is @b deprecated. Use service_set_app_id() instead. + * @param [in] service The service handle + * @param [in] package The package name of the application to explicitly launch \n + * If the @a package is NULL, it clears the previous value. + * @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() + */ +/* Deprecated API */ +int service_set_package(service_h service, const char *package); // __attribute__((deprecated)); + + +/** + * @brief Gets the package name of the application to explicitly launch + * + * @remark This function is @b deprecated. Use service_get_app_id() instead. + * @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() + */ +/* Deprecated API */ +int service_get_package(service_h service, char **package); // __attribute__((deprecated)); + + +/** + * @brief Sets the ID of the application to explicitly launch + * + * @param [in] service The service handle + * @param [in] app_id The ID of the application to explicitly launch \n + * If the @a app_id is NULL, it clears the previous value. + * @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_app_id() + */ +int service_set_app_id(service_h service, const char *app_id); + + +/** + * @brief Gets the ID of the application to explicitly launch + * + * @remarks The @a app_id must be released with free() by you. + * @param [in] service The service handle + * @param [out] app_id The ID 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_app_id() + */ +int service_get_app_id(service_h service, char **app_id); + +/** + * @brief Sets the window id of the application + * + * @param [in] service The service handle + * @param [in] id the window id of caller application \n + * If the @a id is not positive, it clears the previous value. + * @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_window() + */ +int service_set_window(service_h service, unsigned int id); + + +/** +* @brief Gets the window id of the application +* +* @param [in] service The service handle +* @param [out] id The window id of caller application +* @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_app_id() +*/ +int service_get_window(service_h service, unsigned int *id); + + +/** + * @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 + * @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 application ID 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 + * @retval #SERVICE_ERROR_LAUNCH_REJECTED The application launch is rejected due to timeout, continuous launch request while launching and application hang + * @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); + + +/** + * @brief Gets the application ID of the caller from the launch request + * + * @remarks The @a service must be the launch reqeust from app_service_cb(). + * @remarks This function returns #SERVICE_ERROR_INVALID_PARAMETER if the given service is not the launch request. + * @remarks The @a id must be released with free() by you. + * @param [in] service The service handle from app_service_cb() + * @param [out] id The application ID of the caller + * @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 + */ +int service_get_caller(service_h service, char **id); + + +/** + * @brief Check whether the caller is requesting a reply from the launch reqeust + * + * @remarks The @a service must be the launch reqeust from app_service_cb(). + * @remarks This function returns #SERVICE_ERROR_INVALID_PARAMETER if the given service is not the launch request. + * @param [in] service The service handle from app_service_cb() + * @param [out] requested whether a reply is requested by the caller + * @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 + */ +int service_is_reply_requested(service_h service, bool *requested); + +/** + * @} + */ + +#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..6f71533 --- /dev/null +++ b/include/app_service_private.h @@ -0,0 +1,37 @@ +/* + * 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_create_request(bundle *data, service_h *service); + +int service_create_event(bundle *data, service_h *service); + +int service_to_bundle(service_h service, bundle **data); + +#ifdef __cplusplus +} +#endif + +#endif /* __TIZEN_APPFW_SERVICE_PRIVATE_H__ */ diff --git a/include/app_storage.h b/include/app_storage.h new file mode 100644 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..37a00bd --- /dev/null +++ b/include/app_ui_notification.h @@ -0,0 +1,474 @@ +/* + * 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_INVALID_STATE = TIZEN_ERROR_APPLICATION_CLASS | 0x32, /**< Invalid state */ +} 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 Called to retrieve the notifications posted. +* @remarks You should not free @a notification returned by this function. +* @param[in] notification The notification handle +* @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 ui_notification_foreach_notification_posted() will invoke this callback. +* @see ui_notification_foreach_notification_posted() +* @see ui_notification_clone() +*/ +typedef bool (*ui_notification_cb)(ui_notification_h notification, void *user_data); + +/** + * @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 Gets the identifier of the notification unique within the application + * @remarks The system assigns an unique identifier to the notification when it is posted. \n + * This function returns #UI_NOTIFICATION_ERROR_INVALID_STATE if the notification was not posted. + * @param[in] notification The notification handle + * @param[out] id The identifier for the notification unique within the application. + * @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_INVALID_STATE The notification was not posted. + * @see ui_notification_post() + */ +int ui_notification_get_id(ui_notification_h notification, int *id); + +/** + * @brief Checks whether the notification is ongoing or not + * @param[in] notification The notification handle + * @param[out] ongoing A boolean value that sets whether this is an ongoing notification. + * @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_is_ongoing(ui_notification_h notification, bool *ongoing); + +/** + * @brief Sets the full path of the icon image to display in the notification. + * @remarks The @a 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 or updating the notification (see ui_notification_post(), ui_notification_update()). + * @param[in] notification The notification handle + * @param[in] path The absolute path to the specified icon \n + * If the @a path is NULL, it clears the previous value. + * @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_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 or updating the notification (see ui_notification_post(), ui_notification_update()). + * @param[in] notification The notification handle + * @param[in] time The time that the notification occurred \n + * If the @a time is NULL, it clears the previous value. + * @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_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 or updating the notification (see ui_notification_post(), ui_notification_update()). + * @param[in] notification The notification handle + * @param[in] title The title to display in the notification \n + * If the @a title is NULL, it clears the previous value. + * @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_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 or updating the notification (see ui_notification_post(), ui_notification_update()). + * @param[in] notification The notification handle + * @param[in] content The content to display in the notification \n + * If the @a content is NULL, it clears the previous value. + * @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_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 path of sound file to play when the notification is shown. + * @remarks The @a path should be the absolute path. \n + * The sound file is only supported wave file format. \n + * This function should be called before posting or updating the notification (see ui_notification_post(), ui_notification_update()). + * @param[in] notification The notification handle + * @param[in] path The path of sound file to play when the notification is shown \n + * If the @a path is NULL, it clears the previous value. + * @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_get_sound() + */ +int ui_notification_set_sound(ui_notification_h notification, const char *path); + +/** + * @brief Gets the path of sound file to play when the notification is shown. + * @remarks The @a path must be released with free() by you. + * @param[in] notification The notification handle + * @param[out] path The path of sound file to play when the notification is shown \n + * @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_sound() + */ +int ui_notification_get_sound(ui_notification_h notification, char **path); + +/** + * @brief Sets whether to use vibration when the notification is shown. + * @remarks This function should be called before posting or updating the notification (see ui_notification_post(), ui_notification_update()). + * @param[in] notification The notification handle + * @param[in] value A boolean value that sets whether to use vibration. + * @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_get_vibration() + */ +int ui_notification_set_vibration(ui_notification_h notification, bool value); + +/** + * @brief Gets whether to use vibration when the notification is shown. + * @param[in] notification The notification handle + * @param[out] value A boolean value that sets whether to use vibration. + * @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_vibration() + */ +int ui_notification_get_vibration(ui_notification_h notification, bool *value); + +/** + * @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 or updating the notification (see ui_notification_post(), ui_notification_update()). + * @param[in] notification The notification handle + * @param[in] service The service handle to launch when the notification is selected \n + * If the @a service is NULL, it clears the previous value. + * @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_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 + * @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_INVALID_STATE The notification was already posted + * @post The posted notification can be canceled or updated. + * @see ui_notification_cancel() + * @see ui_notification_cancel_all() + * @see ui_notification_update() + * @see ui_notification_update_progress() + * @see ui_notification_foreach_notification_posted() + */ +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 + * @retval #UI_NOTIFICATION_ERROR_INVALID_STATE The notification was not posted or the notification was either cleared or canceled. + * @pre The notification must be posted before canceling it. + * @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. + * @see ui_notification_post() + * @see ui_notification_cancel() + */ +void ui_notification_cancel_all(void); + +/** + * @brief Cancels selected type of previously posted notifications by the current application. + * @details Selected type of previously posted notifications are removed from the notification tray and the status bar. + * @remarks The notifications posted by other applications are not cancelled from the notification tray and the status bar. + * @param[in] ongoing A boolean value that indicates whether the notification type is ongoing to cancel. + * @see ui_notification_post() + * @see ui_notification_cancel() + * @see ui_notification_cancel_all() + */ +void ui_notification_cancel_all_by_type(bool ongoing); + +/** + * @brief Cancels selected type of previously posted notifications by the given application. + * @details Selected type of previously posted notifications are removed from the notification tray and the status bar. + * @remark This function is @b deprecated. Use app_manager_app_context_cb() instead. + * @param[in] package The package name of the application to calcel the posted notifications. + * @param[in] ongoing A boolean value that indicates whether the notification type is ongoing to cancel. + * @see ui_notification_post() + * @see ui_notification_cancel() + * @see ui_notification_cancel_all() + */ +void ui_notification_cancel_all_by_package(const char *package, bool ongoing); + +/** + * @brief Cancels selected type of previously posted notifications by the given application ID. + * @details Selected type of previously posted notifications are removed from the notification tray and the status bar. + * @param[in] id The ID of the application to calcel the posted notifications. + * @param[in] ongoing A boolean value that indicates whether the notification type is ongoing to cancel. + * @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() + * @see ui_notification_cancel_all() + */ +int ui_notification_cancel_all_by_app_id(const char *app_id, bool ongoing); + +/** + * @brief Updates the notification posted. + * @remarks You cannot update the notification which was cleared or canceled. + * @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_INVALID_STATE The notification was not posted or the notification was either cleared or canceled. + * @pre The notification must be posted before updating it. + * @see ui_notification_post() + * @see ui_notification_update_progress() + */ +int ui_notification_update(ui_notification_h notification); + +/** + * @brief Updates the progress to the specified value + * @remarks You cannot update the notification which was cleared or canceled. + * @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 + * The @a value must be greater than or equal to zero. \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 + * @retval #UI_NOTIFICATION_ERROR_INVALID_STATE The notification was not posted or the notification was canceled. + * @pre The notification must be posted before updating the progress to the specified value + * @see ui_notification_create() + * @see ui_notification_post() + * @see ui_notification_update() + * @see #ui_notification_progress_type_e + */ +int ui_notification_update_progress(ui_notification_h notification, ui_notification_progress_type_e type, double value); + +/** + * @brief Retrieves all posted notifications. + * @details This function calls ui_notification_cb() once for each notification which was posted and is being shown. \n + * If ui_notification_cb() callback function returns false, then iteration will be finished. + * + * @param [in] ongoing A boolean value that sets whether the type is an ongoing notification. + * @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 #UI_NOTIFICATION_ERROR_NONE Successful + * @retval #UI_NOTIFICATION_ERROR_INVALID_PARAMETER Invalid parameter + * @post This function invokes ui_notification_cb(). + * @see ui_notification_cb() + */ +int ui_notification_foreach_notification_posted(bool ongoing, ui_notification_cb callback, void *user_data); + +/** + * @brief Creates and returns a copy of the given notification handle. + * + * @remarks A newly created notification handle should be destroyed by calling ui_notification_destroy() if it is no longer needed. + * + * @param [out] clone If successful, a newly created notification handle will be returned. + * @param [in] service 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_OUT_OF_MEMORY Out of memory + * @see ui_notification_create() + * @see ui_notification_destroy() + */ +int ui_notification_clone(ui_notification_h *clone, ui_notification_h notification); + + +/** + * @} + */ + +#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..af8f33a --- /dev/null +++ b/packaging/capi-appfw-application.spec @@ -0,0 +1,67 @@ +#sbs-git:slp/api/application capi-appfw-application 0.1.0 56d9b8e057f022f0e7fdb1853587158452e7ae1b +Name: capi-appfw-application +Summary: An Application library in SLP C API +Version: 0.1.0 +Release: 49 +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(notification) +BuildRequires: pkgconfig(elementary) +BuildRequires: pkgconfig(alarm-service) +BuildRequires: pkgconfig(capi-base-common) +BuildRequires: pkgconfig(sqlite3) + + +Requires(post): /sbin/ldconfig +Requires(postun): /sbin/ldconfig + +%description +An Application library in SLP C API + +%package devel +Summary: An Application library in SLP C API (Development) +Group: TO_BE/FILLED_IN +Requires: %{name} = %{version}-%{release} + +%description devel +An Application library in SLP C API (DEV) + +%prep +%setup -q + +%build +MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'` +cmake . -DCMAKE_INSTALL_PREFIX=/usr -DFULLVER=%{version} -DMAJORVER=${MAJORVER} + + +make %{?jobs:-j%jobs} + +%install +rm -rf %{buildroot} +%make_install + +%post -p /sbin/ldconfig + +%postun -p /sbin/ldconfig + + +%files +%{_libdir}/libcapi-appfw-application.so.* +%manifest capi-appfw-application.manifest + +%files devel +%{_includedir}/appfw/*.h +%{_libdir}/pkgconfig/*.pc +%{_libdir}/libcapi-appfw-application.so + + + diff --git a/src/alarm.c b/src/alarm.c new file mode 100755 index 0000000..5b787af --- /dev/null +++ b/src/alarm.c @@ -0,0 +1,586 @@ +/* + * 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 "CAPI_APPFW_APPLICATION_ALARM" + +typedef struct { + alarm_registered_alarm_cb cb; + void* user_data; + bool* foreach_break; +} alarm_foreach_item_cb_context; + +static void alarm_get_interval(alarm_entry_t *alarm_info, int day_week, int *repeat_interval) +{ + time_t due_time = 0; + time_t current_time = 0; + struct tm duetime_tm; + int wday; + int interval = 0; + + time(¤t_time); + localtime_r(¤t_time, &duetime_tm); + wday = duetime_tm.tm_wday; + + due_time = mktime(&duetime_tm); + wday = duetime_tm.tm_wday; + + if (due_time > current_time && day_week == 0) + return; + + if (!(day_week & 1 << wday)) { + int day = wday + 1; + int next_week = 0; + interval = 1; + /*this week */ + + if (day == 7) { + day = 0; + next_week = 1; + } + + while (!(day_week & 1 << day) + && interval < 8) { + day += 1; + interval += 1; + + if (day == 7) { + day = 0; + next_week = 1; + } + + } + *repeat_interval = interval; + } +} + +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); +} + +int alarm_get_scheduled_date(int alarm_id, struct tm* date) +{ + alarm_error_t result; + alarm_entry_t *entry = NULL; + alarm_date_t adate; + alarm_repeat_mode_t repeat=0; + int week_day=0; + int repeat_interval=0; + + if (date == NULL) + { + LOGE("INVALID_PARAMETER(0x%08x)", ALARM_ERROR_INVALID_PARAMETER); + return ALARM_ERROR_INVALID_PARAMETER; + } + + 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); + } + + result = alarmmgr_get_repeat_mode(entry, &repeat, &week_day); + + if (result != ALARMMGR_RESULT_SUCCESS) + { + if (entry != NULL) + { + alarmmgr_free_alarm(entry); + } + return convert_error_code_to_alarm(__FUNCTION__, result); + } + + if ( repeat == ALARM_REPEAT_MODE_WEEKLY) + alarm_get_interval(entry, week_day, &repeat_interval); + else + repeat_interval=0; + + alarm_get_current_time(date); + + date->tm_year = adate.year - 1900; + date->tm_mon = adate.month - 1; + date->tm_mday = adate.day + repeat_interval; + 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("INVALID_PARAMETER(0x%08x)", ALARM_ERROR_INVALID_PARAMETER); + return ALARM_ERROR_INVALID_PARAMETER; + } + + 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("INVALID_PARAMETER(0x%08x)", ALARM_ERROR_INVALID_PARAMETER); + return ALARM_ERROR_INVALID_PARAMETER; + } + + if (service_to_bundle(service, &bundle_data) != SERVICE_ERROR_NONE) + { + LOGE("INVALID_PARAMETER(0x%08x)", ALARM_ERROR_INVALID_PARAMETER); + return ALARM_ERROR_INVALID_PARAMETER; + } + + 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("INVALID_PARAMETER(0x%08x)", ALARM_ERROR_INVALID_PARAMETER); + return ALARM_ERROR_INVALID_PARAMETER; + } + + if (service_to_bundle(service, &bundle_data) != SERVICE_ERROR_NONE) + { + LOGE("INVALID_PARAMETER(0x%08x)", ALARM_ERROR_INVALID_PARAMETER); + return ALARM_ERROR_INVALID_PARAMETER; + } + + 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) + { + alarmmgr_free_alarm(alarm_info); + 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) + { + alarmmgr_free_alarm(alarm_info); + return convert_error_code_to_alarm(__FUNCTION__, result); + } + + result = alarmmgr_set_type(alarm_info, ALARM_TYPE_DEFAULT); + + if (result < 0) + { + alarmmgr_free_alarm(alarm_info); + return convert_error_code_to_alarm(__FUNCTION__, result); + } + + result = alarmmgr_add_alarm_appsvc_with_localtime(alarm_info, bundle_data, alarm_id); + + if (result < 0) + { + alarmmgr_free_alarm(alarm_info); + return convert_error_code_to_alarm(__FUNCTION__, result); + } + + alarmmgr_free_alarm(alarm_info); + return ALARM_ERROR_NONE; +} + +int alarm_cancel(int alarm_id) +{ + int result; + + result = alarmmgr_remove_alarm(alarm_id); + + return convert_error_code_to_alarm(__FUNCTION__, result); +} + +int alarm_cancel_all() +{ + int result; + + 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("INVALID_PARAMETER(0x%08x)", 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("INVALID_PARAMETER(0x%08x)", 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("INVALID_PARAMETER(0x%08x)", ALARM_ERROR_INVALID_PARAMETER); + return ALARM_ERROR_INVALID_PARAMETER; + } + + if (service_to_bundle(service, &bundle_data) != SERVICE_ERROR_NONE) + { + LOGE("INVALID_PARAMETER(0x%08x)", ALARM_ERROR_INVALID_PARAMETER); + return ALARM_ERROR_INVALID_PARAMETER; + } + + 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) + { + alarmmgr_free_alarm(alarm_info); + 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) + { + alarmmgr_free_alarm(alarm_info); + return convert_error_code_to_alarm(__FUNCTION__, result); + } + + result = alarmmgr_set_type(alarm_info, ALARM_TYPE_DEFAULT); + + if (result < 0) + { + alarmmgr_free_alarm(alarm_info); + return convert_error_code_to_alarm(__FUNCTION__, result); + } + + result = alarmmgr_add_alarm_appsvc_with_localtime(alarm_info, bundle_data, alarm_id); + + alarmmgr_free_alarm(alarm_info); + 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("INVALID_PARAMETER(0x%08x)", ALARM_ERROR_INVALID_PARAMETER); + return ALARM_ERROR_INVALID_PARAMETER; + } + + 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; +} + +int alarm_get_service(int alarm_id, service_h *service) +{ + bundle *b = NULL; + int error_code = 0; + + b = alarmmgr_get_alarm_appsvc_info(alarm_id, &error_code); + + if(error_code != ALARMMGR_RESULT_SUCCESS) + { + return convert_error_code_to_alarm(__FUNCTION__, error_code); + } + + if(b == NULL) + { + return ALARM_ERROR_INVALID_PARAMETER; + } + + error_code = service_create_request(b, service); + + if(error_code != SERVICE_ERROR_NONE) + { + return ALARM_ERROR_OUT_OF_MEMORY; + } + + bundle_free(b); + + return ALARM_ERROR_NONE; + +} diff --git a/src/app_device.c b/src/app_device.c new file mode 100755 index 0000000..8b6215d --- /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 "CAPI_APPFW_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_error.c b/src/app_error.c new file mode 100755 index 0000000..b3c8c0c --- /dev/null +++ b/src/app_error.c @@ -0,0 +1,72 @@ +/* + * 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 <dlog.h> + +#include <app_private.h> + +#ifdef LOG_TAG +#undef LOG_TAG +#endif + +#define LOG_TAG "CAPI_APPFW_APPLICATION" + +static const char* app_error_to_string(app_error_e error) +{ + switch (error) + { + case APP_ERROR_NONE: + return "NONE"; + + case APP_ERROR_INVALID_PARAMETER: + return "INVALID_PARAMETER"; + + case APP_ERROR_OUT_OF_MEMORY: + return "OUT_OF_MEMORY"; + + case APP_ERROR_INVALID_CONTEXT: + return "INVALID_CONTEXT"; + + case APP_ERROR_NO_SUCH_FILE: + return "NO_SUCH_FILE"; + + case APP_ERROR_ALREADY_RUNNING: + return "ALREADY_RUNNING"; + + default : + return "UNKNOWN"; + } +} + +int app_error(app_error_e error, const char* function, const char *description) +{ + if (description) + { + LOGE("[%s] %s(0x%08x) : %s", function, app_error_to_string(error), error, description); + } + else + { + LOGE("[%s] %s(0x%08x)", function, app_error_to_string(error), error); + } + + return error; +} diff --git a/src/app_finalizer.c b/src/app_finalizer.c new file mode 100755 index 0000000..ae0b41c --- /dev/null +++ b/src/app_finalizer.c @@ -0,0 +1,108 @@ +/* + * 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_private.h> + +typedef struct _app_finalizer_s_ { + app_finalizer_cb callback; + void *data; + struct _app_finalizer_s_ *next; +} app_finalizer_s; + +typedef app_finalizer_s *app_finalizer_h; + +static app_finalizer_s finalizer_head = { + .callback = NULL, + .data = NULL, + .next = NULL +}; + +int app_finalizer_add(app_finalizer_cb callback, void *data) +{ + app_finalizer_h finalizer_tail = &finalizer_head; + app_finalizer_h finalizer_new; + + finalizer_new = malloc(sizeof(app_finalizer_s)); + + if (finalizer_new == NULL) + { + return app_error(APP_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL); + } + + finalizer_new->callback = callback; + finalizer_new->data = data; + finalizer_new->next = NULL; + + while (finalizer_tail->next) + { + finalizer_tail = finalizer_tail->next; + } + + finalizer_tail->next = finalizer_new; + + return APP_ERROR_NONE; +} + +int app_finalizer_remove(app_finalizer_cb callback) +{ + app_finalizer_h finalizer_node = &finalizer_head; + + while (finalizer_node->next) + { + if (finalizer_node->next->callback == callback) + { + app_finalizer_h removed_node = finalizer_node->next; + finalizer_node->next = removed_node->next; + free(removed_node); + return APP_ERROR_NONE; + } + + finalizer_node = finalizer_node->next; + } + + return APP_ERROR_INVALID_PARAMETER; +} + +void app_finalizer_execute(void) +{ + app_finalizer_h finalizer_node = &finalizer_head; + app_finalizer_h finalizer_executed; + app_finalizer_cb finalizer_cb = NULL; + + if(finalizer_node) + finalizer_node = finalizer_node->next; + + while (finalizer_node) + { + finalizer_cb = finalizer_node->callback; + + finalizer_cb(finalizer_node->data); + + finalizer_executed = finalizer_node; + + finalizer_node = finalizer_node->next; + + free(finalizer_executed); + } + + finalizer_head.next = NULL; +} + diff --git a/src/app_main.c b/src/app_main.c new file mode 100755 index 0000000..81f4f5e --- /dev/null +++ b/src/app_main.c @@ -0,0 +1,401 @@ +/* + * 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 "CAPI_APPFW_APPLICATION" + +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 { + char *package; + char *app_name; + app_state_e state; + app_event_callback_s *callback; + void *data; +} app_context_s; + +typedef app_context_s *app_context_h; + +static int app_appcore_create(void *data); +static int app_appcore_pause(void *data); +static int app_appcore_resume(void *data); +static int app_appcore_terminate(void *data); +static int app_appcore_reset(bundle *appcore_bundle, void *data); + +static int app_appcore_low_memory(void *data); +static int app_appcore_low_battery(void *data); +static int app_appcore_rotation_event(enum appcore_rm rm, void *data); +static int app_appcore_lang_changed(void *data); +static int app_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); + + +int app_efl_main(int *argc, char ***argv, app_event_callback_s *callback, void *user_data) +{ + app_context_s app_context = { + .package = NULL, + .app_name = NULL, + .state = APP_STATE_NOT_RUNNING, + .callback = callback, + .data = user_data + }; + + struct appcore_ops appcore_context = { + .data = &app_context, + .create = app_appcore_create, + .terminate = app_appcore_terminate, + .pause = app_appcore_pause, + .resume = app_appcore_resume, + .reset = app_appcore_reset, + }; + + if (argc == NULL || argv == NULL || callback == NULL) + { + return app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); + } + + if (callback->create == NULL) + { + return app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, "app_create_cb() callback must be registered"); + } + + if (app_context.state != APP_STATE_NOT_RUNNING) + { + return app_error(APP_ERROR_ALREADY_RUNNING, __FUNCTION__, NULL); + } + + if (app_get_id(&(app_context.package)) != APP_ERROR_NONE) + { + return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "failed to get the package"); + } + + if (app_get_package_app_name(app_context.package, &(app_context.app_name)) != APP_ERROR_NONE) + { + return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "failed to get the package's app name"); + } + + app_context.state = APP_STATE_CREATING; + + appcore_efl_main(app_context.app_name, argc, argv, &appcore_context); + + free(app_context.package); + free(app_context.app_name); + + return APP_ERROR_NONE; +} + + +void app_efl_exit(void) +{ + elm_exit(); +} + + +int app_appcore_create(void *data) +{ + app_context_h app_context = data; + app_create_cb create_cb; + char locale_dir[TIZEN_PATH_MAX] = {0, }; + + if (app_context == NULL) + { + return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, NULL); + } + + app_set_appcore_event_cb(app_context); + + snprintf(locale_dir, TIZEN_PATH_MAX, PATH_FMT_LOCALE_DIR, app_context->package); + if (access(locale_dir, R_OK) != 0) { + snprintf(locale_dir, TIZEN_PATH_MAX, PATH_FMT_RO_LOCALE_DIR, app_context->package); + } + appcore_set_i18n(app_context->app_name, locale_dir); + + create_cb = app_context->callback->create; + + if (create_cb == NULL || create_cb(app_context->data) == false) + { + return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "app_create_cb() returns false"); + } + + app_context->state = APP_STATE_RUNNING; + + return APP_ERROR_NONE; +} + +int app_appcore_terminate(void *data) +{ + app_context_h app_context = data; + app_terminate_cb terminate_cb; + + if (app_context == NULL) + { + return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, NULL); + } + + terminate_cb = app_context->callback->terminate; + + if (terminate_cb != NULL) + { + terminate_cb(app_context->data); + } + + app_unset_appcore_event_cb(); + + app_finalizer_execute(); + + return APP_ERROR_NONE; +} + +int app_appcore_pause(void *data) +{ + app_context_h app_context = data; + app_pause_cb pause_cb; + + if (app_context == NULL) + { + return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, NULL); + } + + pause_cb = app_context->callback->pause; + + if (pause_cb != NULL) + { + pause_cb(app_context->data); + } + + return APP_ERROR_NONE; +} + +int app_appcore_resume(void *data) +{ + app_context_h app_context = data; + app_resume_cb resume_cb; + + if (app_context == NULL) + { + return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, NULL); + } + + resume_cb = app_context->callback->resume; + + if (resume_cb != NULL) + { + resume_cb(app_context->data); + } + + return APP_ERROR_NONE; +} + + +int app_appcore_reset(bundle *appcore_bundle, void *data) +{ + app_context_h app_context = data; + app_service_cb service_cb; + service_h service; + + if (app_context == NULL) + { + return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, NULL); + } + + if (service_create_event(appcore_bundle, &service) != APP_ERROR_NONE) + { + return app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, "failed to create a service handle from the bundle"); + } + + service_cb = app_context->callback->service; + + if (service_cb != NULL) + { + service_cb(service, app_context->data); + } + + service_destroy(service); + + return APP_ERROR_NONE; +} + + +int app_appcore_low_memory(void *data) +{ + app_context_h app_context = data; + app_low_memory_cb low_memory_cb; + + if (app_context == NULL) + { + return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, NULL); + } + + low_memory_cb = app_context->callback->low_memory; + + if (low_memory_cb != NULL) + { + low_memory_cb(app_context->data); + } + + return APP_ERROR_NONE; +} + +int app_appcore_low_battery(void *data) +{ + app_context_h app_context = data; + app_low_battery_cb low_battery_cb; + + if (app_context == NULL) + { + return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, NULL); + } + + low_battery_cb = app_context->callback->low_battery; + + if (low_battery_cb != NULL) + { + low_battery_cb(app_context->data); + } + + return APP_ERROR_NONE; +} + +int app_appcore_rotation_event(enum appcore_rm rm, void *data) +{ + app_context_h app_context = data; + app_device_orientation_cb device_orientation_cb; + + if (app_context == NULL) + { + return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, NULL); + } + + device_orientation_cb = app_context->callback->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->data); + } + + return APP_ERROR_NONE; +} + +int app_appcore_lang_changed(void *data) +{ + app_context_h app_context = data; + app_language_changed_cb lang_changed_cb; + + if (app_context == NULL) + { + return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, NULL); + } + + lang_changed_cb = app_context->callback->language_changed; + + if (lang_changed_cb != NULL) + { + lang_changed_cb(app_context->data); + } + + return APP_ERROR_NONE; +} + +int app_appcore_region_changed(void *data) +{ + app_context_h app_context = data; + app_region_format_changed_cb region_changed_cb; + + if (app_context == NULL) + { + return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, NULL); + } + + region_changed_cb = app_context->callback->region_format_changed; + + if (region_changed_cb != NULL) + { + region_changed_cb(app_context->data); + } + + return APP_ERROR_NONE; +} + + +void app_set_appcore_event_cb(app_context_h app_context) +{ + if (app_context->callback->low_memory != NULL) + { + appcore_set_event_callback(APPCORE_EVENT_LOW_MEMORY, app_appcore_low_memory, app_context); + } + + if (app_context->callback->low_battery != NULL) + { + appcore_set_event_callback(APPCORE_EVENT_LOW_BATTERY, app_appcore_low_battery, app_context); + } + + if (app_context->callback->device_orientation != NULL) + { + appcore_set_rotation_cb(app_appcore_rotation_event, app_context); + } + + if (app_context->callback->language_changed != NULL) + { + appcore_set_event_callback(APPCORE_EVENT_LANG_CHANGE, app_appcore_lang_changed, app_context); + } + + if (app_context->callback->region_format_changed != NULL) + { + appcore_set_event_callback(APPCORE_EVENT_REGION_CHANGE, app_appcore_region_changed, app_context); + } +} + +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); +} diff --git a/src/app_package.c b/src/app_package.c new file mode 100755 index 0000000..56893a1 --- /dev/null +++ b/src/app_package.c @@ -0,0 +1,188 @@ +/* + * 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 "CAPI_APPFW_APPLICATION" + +int app_get_package_app_name(const char *appid, char **name) +{ + char *name_token = NULL; + + if (appid == NULL) + { + return app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); + } + + // com.vendor.name -> name + name_token = strrchr(appid, '.'); + + if (name_token == NULL) + { + return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, NULL); + } + + name_token++; + + *name = strdup(name_token); + + if (*name == NULL) + { + return app_error(APP_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL); + } + + return APP_ERROR_NONE; +} + +int app_get_package(char **package) +{ + return app_get_id(package); +} + +int app_get_id(char **id) +{ + static char id_buf[TIZEN_PATH_MAX] = {0, }; + int ret = -1; + + if (id == NULL) + { + return app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); + } + + if (id_buf[0] == '\0') + { + ret = aul_app_get_appid_bypid(getpid(), id_buf, sizeof(id_buf)); + if (ret < 0) { + return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "failed to get the application ID"); + } + } + + if (id_buf[0] == '\0') + { + return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "failed to get the application ID"); + } + + *id = strdup(id_buf); + + if (*id == NULL) + { + return app_error(APP_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL); + } + + return APP_ERROR_NONE; +} + +static int app_get_appinfo(const char *package, const char *property, char **value) +{ + ail_appinfo_h appinfo; + char *appinfo_value; + char *appinfo_value_dup; + + if (ail_get_appinfo(package, &appinfo) != 0) + { + return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "failed to get app-info"); + } + + if (ail_appinfo_get_str(appinfo, property, &appinfo_value) != 0) + { + ail_destroy_appinfo(appinfo); + return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "failed to get app-property"); + } + + appinfo_value_dup = strdup(appinfo_value); + + ail_destroy_appinfo(appinfo); + + if (appinfo_value_dup == NULL) + { + return app_error(APP_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL); + } + + *value = appinfo_value_dup; + + return APP_ERROR_NONE; +} + +int app_get_name(char **name) +{ + char *package = NULL; + int retval; + + if(name == NULL) + { + return app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); + } + + if (app_get_id(&package) != 0) + { + return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "failed to get the package"); + } + + 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) + { + return app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); + } + + if (app_get_id(&package) != 0) + { + return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "failed to get the package"); + } + + 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..a3c2da5 --- /dev/null +++ b/src/app_resource.c @@ -0,0 +1,250 @@ +/* + * 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 <ail.h> + +#include <app_private.h> +#include <app_service_private.h> + +#ifdef LOG_TAG +#undef LOG_TAG +#endif + +#define LOG_TAG "CAPI_APPFW_APPLICATION" + +static const char *INSTALLED_PATH = "/opt/usr/apps"; +static const char *RO_INSTALLED_PATH = "/usr/apps"; +static const char *RES_DIRECTORY_NAME = "res"; +static const char *DATA_DIRECTORY_NAME = "data"; + +static char * app_get_root_directory(char *buffer, int size) +{ + char *appid = NULL; + char root_directory[TIZEN_PATH_MAX] = {0, }; + char bin_directory[TIZEN_PATH_MAX] = {0, }; + ail_appinfo_h ail_app_info; + char *pkgid; + + if (app_get_id(&appid) != APP_ERROR_NONE) + { + app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "failed to get the appid"); + return NULL; + } + + if (ail_get_appinfo(appid, &ail_app_info) != AIL_ERROR_OK) + { + app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "failed to get the appinfo"); + free(appid); + return NULL; + } + + if (ail_appinfo_get_str(ail_app_info, AIL_PROP_X_SLP_PKGID_STR, &pkgid) != AIL_ERROR_OK) + { + app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "failed to get the pkgid"); + free(appid); + ail_destroy_appinfo(ail_app_info); + return NULL; + } + + if(pkgid) + { + free(appid); + appid = strdup(pkgid); + } + + ail_destroy_appinfo(ail_app_info); + + snprintf(root_directory, sizeof(root_directory), "%s/%s", INSTALLED_PATH, appid); + snprintf(bin_directory, sizeof(bin_directory), "%s/bin", root_directory); + + if (access(bin_directory, R_OK) != 0) { + snprintf(root_directory, sizeof(root_directory), "%s/%s", RO_INSTALLED_PATH, appid); + } + + free(appid); + + if (size < strlen(root_directory)+1) + { + app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, "the buffer is not big enough"); + return NULL; + } + + snprintf(buffer, size, "%s", root_directory); + + return buffer; +} + +static char* app_get_resource_directory(char *buffer, int size) +{ + char root_directory[TIZEN_PATH_MAX] = {0, }; + char resource_directory[TIZEN_PATH_MAX] = {0, }; + + if (app_get_root_directory(root_directory, sizeof(root_directory)) == NULL) + { + app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "failed to get the root directory of the application"); + return NULL; + } + + snprintf(resource_directory, sizeof(resource_directory), "%s/%s", root_directory, RES_DIRECTORY_NAME); + + if (size < strlen(resource_directory) +1) + { + app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, "the buffer is not big enough"); + return NULL; + } + + snprintf(buffer, size, "%s", resource_directory); + + return buffer; +} + +char* app_get_data_directory(char *buffer, int size) +{ + static char data_directory[TIZEN_PATH_MAX] = {0, }; + static int data_directory_length = 0; + ail_appinfo_h ail_app_info; + char *pkgid; + + if (data_directory[0] == '\0') + { + char *root_directory = NULL; + char *appid = NULL; + + root_directory = calloc(1, TIZEN_PATH_MAX); + + if (root_directory == NULL) + { + app_error(APP_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL); + return NULL; + } + + if (app_get_id(&appid) != APP_ERROR_NONE) + { + app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "failed to get the package"); + free(root_directory); + return NULL; + } + + if (ail_get_appinfo(appid, &ail_app_info) != AIL_ERROR_OK) + { + app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "failed to get the package"); + free(root_directory); + free(appid); + return NULL; + } + + if (ail_appinfo_get_str(ail_app_info, AIL_PROP_X_SLP_PKGID_STR, &pkgid) != AIL_ERROR_OK) + { + app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "failed to get the package"); + free(root_directory); + free(appid); + ail_destroy_appinfo(ail_app_info); + return NULL; + } + + if(pkgid) + { + free(appid); + appid = strdup(pkgid); + } + + ail_destroy_appinfo(ail_app_info); + + snprintf(root_directory, TIZEN_PATH_MAX, "%s/%s", INSTALLED_PATH, appid); + + free(appid); + + snprintf(data_directory, sizeof(data_directory), "%s/%s", root_directory, DATA_DIRECTORY_NAME); + + data_directory_length = strlen(data_directory); + + free(root_directory); + } + + if (size < data_directory_length+1) + { + app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, "the buffer is not big enough"); + return NULL; + } + + snprintf(buffer, size, "%s", data_directory); + + return buffer; +} + +char* app_get_resource(const char *resource, char *buffer, int size) +{ + static char resource_directory[TIZEN_PATH_MAX] = {0, }; + static int resource_directory_length = 0; + + int resource_path_length = 0; + + if (resource == NULL) + { + app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); + return NULL; + } + + if (buffer == NULL || size <= 0) + { + app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); + return NULL; + } + + if (resource_directory[0] == '\0') + { + if (app_get_resource_directory(resource_directory, sizeof(resource_directory)) == NULL) + { + app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "failed to get the path to the resource directory"); + return NULL; + } + + resource_directory_length = strlen(resource_directory); + } + + resource_path_length = resource_directory_length + strlen("/") + strlen(resource); + + if (size < resource_path_length+1) + { + app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, "the buffer is not big enough"); + return NULL; + } + + snprintf(buffer, size, "%s/%s", resource_directory, resource); + + return buffer; +} + + +void app_set_reclaiming_system_cache_on_pause(bool enable) +{ + appcore_set_system_resource_reclaiming(enable); +} + 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..ad85562 --- /dev/null +++ b/src/preference.c @@ -0,0 +1,758 @@ +/* + * 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 "CAPI_APPFW_APPLICATION_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("IO_ERROR(0x%08x) : fail to get data directory", 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("IO_ERROR(0x%08x) : fail to open db(%s)", 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("IO_ERROR(0x%08x) : fail to create db table(%s)", PREFERENCE_ERROR_IO_ERROR, errmsg); + sqlite3_free(errmsg); + sqlite3_close(pref_db); + pref_db = NULL; + return PREFERENCE_ERROR_IO_ERROR; + } + + app_finalizer_add(_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("INVALID_PARAMETER(0x%08x)", 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 ('%q', '%q', '%q');", + PREF_TBL_NAME, PREF_F_KEY_NAME, PREF_F_TYPE_NAME, PREF_F_DATA_NAME, key, type, data); + } + + if (buf == NULL) + { + LOGE("IO_ERROR(0x%08x) : fail to create query string", 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("IO_ERROR(0x%08x): fail to write data(%s)", 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("INVALID_PARAMETER(0x%08x)", PREFERENCE_ERROR_INVALID_PARAMETER); + return PREFERENCE_ERROR_INVALID_PARAMETER; + } + + if (pref_db == NULL) + { + if (_initialize() != PREFERENCE_ERROR_NONE) + { + LOGE("IO_ERROR(0x%08x) : fail to initialize db", 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("IO_ERROR(0x%08x) : fail to create query string", 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("IO_ERROR(0x%08x) : fail to read data (%s)", PREFERENCE_ERROR_IO_ERROR, errmsg); + sqlite3_free(errmsg); + return PREFERENCE_ERROR_IO_ERROR; + } + + if (rows == 0) + { + LOGE("NO_KEY(0x%08x) : fail to find given key(%s)", PREFERENCE_ERROR_NO_KEY, key); + sqlite3_free_table(result); + return PREFERENCE_ERROR_NO_KEY; + } + + snprintf(type, 2, "%s", result[4]); // get type value + snprintf(data, BUF_LEN, "%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("INVALID_PARAMETER(0x%08x) : param type(%d)", 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("INVALID_PARAMETER(0x%08x) : param type(%d)", 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); + if (strlen(value) > (BUF_LEN-1)) + { + LOGE("INVALID_PARAMETER(0x%08x) : param type(%d)", PREFERENCE_ERROR_INVALID_PARAMETER, atoi(type)); + return PREFERENCE_ERROR_INVALID_PARAMETER; + } + 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("INVALID_PARAMETER(0x%08x)", 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("OUT_OF_MEMORY(0x%08x)", PREFERENCE_ERROR_OUT_OF_MEMORY); + return PREFERENCE_ERROR_OUT_OF_MEMORY; + } + } + else + { + LOGE("INVALID_PARAMETER(0x%08x) : param type(%d)", 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("INVALID_PARAMETER(0x%08x) : param type(%d)", 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("INVALID_PARAMETER(0x%08x)", PREFERENCE_ERROR_INVALID_PARAMETER); + return PREFERENCE_ERROR_INVALID_PARAMETER; + } + + if (pref_db == NULL) + { + if (_initialize() != PREFERENCE_ERROR_NONE) + { + LOGE("IO_ERROR(0x%08x) : fail to initialize db", 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("IO_ERROR(0x%08x) : fail to create query string", 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("IO_ERROR(0x%08x) : fail to read data(%s)", 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("INVALID_PARAMETER(0x%08x)", 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("OUT_OF_MEMORY(0x%08x)", 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("OUT_OF_MEMORY(0x%08x)", 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("INVALID_PARAMETER(0x%08x)", 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("given table name (%s) is not same", 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("fail to read data(%s)", 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("IO_ERROR(0x%08x) : fail to create query string", 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("IO_ERROR(0x%08x) : fail to delete data (%s)", 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("IO_ERROR(0x%08x) : fail to initialize db", 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("IO_ERROR(0x%08x) : fail to create query string", 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("IO_ERROR(0x%08x) : fail to delete data (%s)", 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("NO_KEY(0x%08x) : fail to find given key(%s)", 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("IO_ERROR(0x%08x) : fail to initialize db", PREFERENCE_ERROR_IO_ERROR); + return PREFERENCE_ERROR_IO_ERROR; + } + } + + if (callback == NULL) + { + LOGE("INVALID_PARAMETER(0x%08x)", 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("IO_ERROR(0x%08x) : fail to create query string", 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("IO_ERROR(0x%08x) : fail to read data (%s)", 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..73196b1 --- /dev/null +++ b/src/service.c @@ -0,0 +1,1285 @@ +/* + * 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> +#include <app_service_private.h> + +#ifdef LOG_TAG +#undef LOG_TAG +#endif + +#define LOG_TAG "CAPI_APPFW_APPLICATION_SERVICE" + +#ifndef TIZEN_PATH_MAX +#define TIZEN_PATH_MAX 1024 +#endif + +#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__" +#define BUNDLE_KEY_WINDOW "__APP_SVC_K_WIN_ID__" + + +typedef enum { + SERVICE_TYPE_REQUEST, + 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; + +extern int appsvc_allow_transient_app(bundle *b, unsigned int id); + +static int service_create_reply(bundle *data, struct service_s **service); + +static const char* service_error_to_string(service_error_e error) +{ + switch (error) + { + case SERVICE_ERROR_NONE: + return "NONE"; + + case SERVICE_ERROR_INVALID_PARAMETER: + return "INVALID_PARAMETER"; + + case SERVICE_ERROR_OUT_OF_MEMORY: + return "OUT_OF_MEMORY"; + + case SERVICE_ERROR_APP_NOT_FOUND: + return "APP_NOT_FOUND"; + + case SERVICE_ERROR_KEY_NOT_FOUND: + return "KEY_NOT_FOUND"; + + case SERVICE_ERROR_KEY_REJECTED: + return "KEY_REJECTED"; + + case SERVICE_ERROR_INVALID_DATA_TYPE: + return "INVALID_DATA_TYPE"; + + case SERVICE_ERROR_LAUNCH_REJECTED: + return "LAUNCH_REJECTED"; + + default : + return "UNKNOWN"; + } +} + +int service_error(service_error_e error, const char* function, const char *description) +{ + if (description) + { + LOGE("[%s] %s(0x%08x) : %s", function, service_error_to_string(error), error, description); + } + else + { + LOGE("[%s] %s(0x%08x)", function, service_error_to_string(error), error); + } + + return error; +} + +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 = NULL; + service_result_e result; + void *user_data; + service_reply_cb reply_cb; + + if (appsvc_data == NULL) + { + service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, "invalid service reply"); + return; + } + + if (service_create_reply(appsvc_bundle, &reply) != 0) + { + service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, "failed to create service reply"); + 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 + { + service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, "invalid callback "); + } + + service_destroy(reply); + + if (request_context->service != NULL) + { + service_destroy(request_context->service); + } + + free(request_context); +} + + +int service_create(service_h *service) +{ + return service_create_request(NULL, service); +} + +int service_create_request(bundle *data, service_h *service) +{ + struct service_s *service_request; + + if (service == NULL) + { + return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); + } + + service_request = malloc(sizeof(struct service_s)); + + if (service_request == NULL) + { + return service_error(SERVICE_ERROR_OUT_OF_MEMORY, __FUNCTION__, "failed to create a service handle"); + } + + service_request->type = SERVICE_TYPE_REQUEST; + + if (data != NULL) + { + service_request->data = bundle_dup(data); + } + else + { + service_request->data = bundle_create(); + } + + if (service_request->data == NULL) + { + free(service_request); + return service_error(SERVICE_ERROR_OUT_OF_MEMORY, __FUNCTION__, "failed to create a bundle"); + } + + 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) + { + return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); + } + + service_event = malloc(sizeof(struct service_s)); + + if (service_event == NULL) + { + return service_error(SERVICE_ERROR_OUT_OF_MEMORY, __FUNCTION__, "failed to create a service handle"); + } + + 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; +} + +static int service_create_reply(bundle *data, struct service_s **service) +{ + struct service_s *service_reply; + + if (data == NULL || service == NULL) + { + return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); + } + + service_reply = malloc(sizeof(struct service_s)); + + if (service_reply == NULL) + { + return service_error(SERVICE_ERROR_OUT_OF_MEMORY, __FUNCTION__, "failed to create a service handle"); + } + + 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)) + { + return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); + } + + 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) || data == NULL) + { + return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); + } + + *data = service->data; + + return SERVICE_ERROR_NONE; +} + +int service_set_operation(service_h service, const char *operation) +{ + if (service_valiate_service(service)) + { + return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); + } + + if (operation != NULL) + { + if (appsvc_set_operation(service->data, operation) != 0) + { + return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, "invalid operation"); + } + } + 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) || operation == NULL) + { + return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); + } + + 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)) + { + return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); + } + + if (uri != NULL) + { + if (appsvc_set_uri(service->data, uri) != 0) + { + return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, "invalid URI"); + } + } + 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) || uri == NULL) + { + return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); + } + + 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)) + { + return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); + } + + if (mime != NULL) + { + if (appsvc_set_mime(service->data, mime) != 0) + { + return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, "invalid MIME type"); + } + } + 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) || mime == NULL) + { + return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); + } + + 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_category(service_h service, const char *category) +{ + if (service_valiate_service(service)) + { + return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); + } + + if (category != NULL) + { + if (appsvc_set_category(service->data, category) != 0) + { + return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, "invalid MIME type"); + } + } + else + { + bundle_del(service->data, BUNDLE_KEY_MIME); + } + + return SERVICE_ERROR_NONE; +} + + +int service_get_category(service_h service, char **category) +{ + const char *category_value; + + if (service_valiate_service(service) || category == NULL) + { + return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); + } + + category_value = appsvc_get_category(service->data); + + if (category_value != NULL) + { + *category = strdup(category_value); + } + else + { + *category = NULL; + } + + return SERVICE_ERROR_NONE; +} + + +int service_set_package(service_h service, const char *package) +{ + // TODO: this function must be deprecated + return service_set_app_id(service, package); +} + +int service_get_package(service_h service, char **package) +{ + // TODO: this function must be deprecated + return service_get_app_id(service, package); +} + + +int service_set_app_id(service_h service, const char *app_id) +{ + if (service_valiate_service(service)) + { + return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); + } + + if (app_id != NULL) + { + if (appsvc_set_appid(service->data, app_id) != 0) + { + return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, "invalid application ID"); + } + } + else + { + bundle_del(service->data, BUNDLE_KEY_PACKAGE); + } + + return SERVICE_ERROR_NONE; +} + + +int service_get_app_id(service_h service, char **app_id) +{ + const char *app_id_value; + + if (service_valiate_service(service) || app_id == NULL) + { + return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); + } + + app_id_value = appsvc_get_appid(service->data); + + if (app_id_value != NULL) + { + *app_id = strdup(app_id_value); + } + else + { + *app_id = NULL; + } + + return SERVICE_ERROR_NONE; +} + +int service_set_window(service_h service, unsigned int id) +{ + if (service_valiate_service(service)) + { + return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); + } + + if (id > 0) + { + if (appsvc_allow_transient_app(service->data, id) != 0) + { + return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, "invalid id"); + } + } + else + { + bundle_del(service->data, BUNDLE_KEY_WINDOW); + } + + return SERVICE_ERROR_NONE; +} + +int service_get_window(service_h service, unsigned int *id) +{ + const char *window_id; + + if (service_valiate_service(service) || id == NULL) + { + return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); + } + + window_id = bundle_get_val(service->data, BUNDLE_KEY_WINDOW); + + if (window_id != NULL) + { + *id = atoi(window_id); + } + else + { + *id = 0; + } + + return SERVICE_ERROR_NONE; +} + +int service_clone(service_h *clone, service_h service) +{ + service_h service_clone; + + if (service_valiate_service(service) || clone == NULL) + { + return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); + } + + service_clone = malloc(sizeof(struct service_s)); + + if (service_clone == NULL) + { + return service_error(SERVICE_ERROR_OUT_OF_MEMORY, __FUNCTION__, "failed to create a service handle"); + } + + 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 *appid; + + bool implicit_default_operation = false; + int launch_pid; + + service_request_context_h request_context = NULL; + + if (service_valiate_service(service)) + { + return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); + } + + operation = appsvc_get_operation(service->data); + + if (operation == NULL) + { + implicit_default_operation = true; + operation = SERVICE_OPERATION_DEFAULT; + } + + appid = appsvc_get_appid(service->data); + + // operation : default + if (!strcmp(operation, SERVICE_OPERATION_DEFAULT)) + { + if (appid == NULL) + { + return service_error(SERVICE_ERROR_APP_NOT_FOUND, __FUNCTION__, "package must be specified if the operation is default value"); + } + } + + if (callback != NULL) + { + service_h request_clone = NULL; + + request_context = calloc(1, sizeof(struct service_request_context_s)); + + if (request_context == NULL) + { + return service_error(SERVICE_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL); + } + + request_context->reply_cb = callback; + + if (service_clone(&request_clone, service) != SERVICE_ERROR_NONE) + { + free(request_context); + return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, "failed to clone the service request handle"); + } + + request_context->service = request_clone; + 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) + { + if (launch_pid == APPSVC_RET_ENOMATCH) + { + return service_error(SERVICE_ERROR_APP_NOT_FOUND, __FUNCTION__, NULL); + } + else + { + return service_error(SERVICE_ERROR_LAUNCH_REJECTED, __FUNCTION__, NULL); + } + } + + return SERVICE_ERROR_NONE; +} + +static bool service_copy_reply_data_cb(service_h service, const char *key, void *user_data) +{ + bundle *reply_data = user_data; + char *value = NULL; + char **value_array = NULL; + int value_array_length = 0; + int value_array_index = 0; + + if (reply_data == NULL) + { + service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); + return false; + } + + if (appsvc_data_is_array(service->data, key)) + { + service_get_extra_data_array(service, key, &value_array, &value_array_length); + appsvc_add_data_array(reply_data, key, (const char**)value_array, value_array_length); + + for (value_array_index=0; value_array_index < value_array_length; value_array_index++) + { + free(value_array[value_array_index]); + } + + free(value_array); + } + else + { + service_get_extra_data(service, key, &value); + appsvc_add_data(reply_data, key, value); + free(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) || service_valiate_service(request)) + { + return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); + } + + if (appsvc_create_result_bundle(request->data, &reply_data) != 0) + { + return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, "failed to create a result bundle"); + } + + 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) || service_validate_extra_data(key) || service_validate_extra_data(value)) + { + return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); + } + + if (service_validate_internal_key(key)) + { + return service_error(SERVICE_ERROR_KEY_REJECTED, __FUNCTION__, "the given key is reserved as internal use"); + } + + 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) + { + return service_error(SERVICE_ERROR_KEY_REJECTED, __FUNCTION__, "failed to add data to the appsvc handle"); + } + + 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) || service_validate_extra_data(key)) + { + return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); + } + + if (value == NULL || length <= 0) + { + return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, "invalid array"); + } + + if (service_validate_internal_key(key)) + { + return service_error(SERVICE_ERROR_KEY_REJECTED, __FUNCTION__, "the given key is reserved as internal use"); + } + + 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) + { + return service_error(SERVICE_ERROR_KEY_REJECTED, __FUNCTION__, "failed to add array data to the appsvc handle"); + } + + return SERVICE_ERROR_NONE; +} + + +int service_remove_extra_data(service_h service, const char *key) +{ + if (service_valiate_service(service) || service_validate_extra_data(key)) + { + return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); + } + + if (service_validate_internal_key(key)) + { + return service_error(SERVICE_ERROR_KEY_REJECTED, __FUNCTION__, "the given key is reserved as internal use"); + } + + if (bundle_del(service->data, key)) + { + return service_error(SERVICE_ERROR_KEY_NOT_FOUND, __FUNCTION__, NULL); + } + + 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) || service_validate_extra_data(key) || value == NULL) + { + return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); + } + + + if (service_validate_internal_key(key)) + { + return service_error(SERVICE_ERROR_KEY_REJECTED, __FUNCTION__, "the given key is reserved as internal use"); + } + + data_value = appsvc_get_data(service->data, key); + + if (data_value == NULL) + { + if (errno == ENOTSUP) + { + return service_error(SERVICE_ERROR_INVALID_DATA_TYPE, __FUNCTION__, NULL); + } + else + { + return service_error(SERVICE_ERROR_KEY_NOT_FOUND, __FUNCTION__, NULL); + } + } + + *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) || service_validate_extra_data(key)) + { + return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); + } + + if (value == NULL || length == 0) + { + return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); + } + + if (service_validate_internal_key(key)) + { + return service_error(SERVICE_ERROR_KEY_REJECTED, __FUNCTION__, "the given key is reserved as internal use"); + } + + array_data = appsvc_get_data_array(service->data, key, &array_data_length); + + if (array_data == NULL) + { + if (errno == ENOTSUP) + { + return service_error(SERVICE_ERROR_INVALID_DATA_TYPE, __FUNCTION__, NULL); + } + else + { + return service_error(SERVICE_ERROR_KEY_NOT_FOUND, __FUNCTION__, NULL); + } + } + + array_data_clone = calloc(array_data_length, sizeof(char*)); + + if (array_data_clone == NULL) + { + return service_error(SERVICE_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL); + } + + 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) +{ + if (service_valiate_service(service) || service_validate_extra_data(key) || array == NULL) + { + return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); + } + + if (service_validate_internal_key(key)) + { + return service_error(SERVICE_ERROR_KEY_REJECTED, __FUNCTION__, "the given key is reserved as internal use"); +
} + + if (!appsvc_data_is_array(service->data, key)) + { + *array = false; + } + else + { + *array = true; + } + + 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_iterator(const char *key, const int type, const bundle_keyval_t *kv, void *user_data) +{ + foreach_context_extra_data_t* foreach_context = NULL; + service_extra_data_cb extra_data_cb; + + if (key == NULL || !(type == BUNDLE_TYPE_STR || type == BUNDLE_TYPE_STR_ARRAY)) + { + return; + } + + foreach_context = (foreach_context_extra_data_t*)user_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) +{ + foreach_context_extra_data_t foreach_context = { + .service = service, + .callback = callback, + .user_data = user_data, + .foreach_break = false + }; + + if (service_valiate_service(service) || callback == NULL) + { + return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); + } + + bundle_foreach(service->data, service_cb_broker_bundle_iterator, &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) + { + service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); + 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) +{ + foreach_context_launchable_app_t foreach_context = { + .service = service, + .callback = callback, + .user_data = user_data, + .foreach_break = false + }; + + if (service_valiate_service(service) || callback == NULL) + { + return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); + } + + appsvc_get_list(service->data, service_cb_broker_foreach_app_matched, &foreach_context); + + return SERVICE_ERROR_NONE; +} + + +int service_get_caller(service_h service, char **package) +{ + const char *bundle_value; + pid_t caller_pid; + char package_buf[TIZEN_PATH_MAX] = {0, }; + char *package_dup; + + if (service_valiate_service(service) || package == NULL) + { + return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); + } + + if (service->type != SERVICE_TYPE_EVENT) + { + return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, "invalid service handle type"); + } + + bundle_value = bundle_get_val(service->data, AUL_K_ORG_CALLER_PID); + + if (bundle_value == NULL) + { + bundle_value = bundle_get_val(service->data, AUL_K_CALLER_PID); + } + + if (bundle_value == NULL) + { + return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, "failed to retrieve the pid of the caller"); + } + + caller_pid = atoi(bundle_value); + + if (caller_pid <= 0) + { + return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, "invalid pid of the caller"); + } + + if (aul_app_get_appid_bypid(caller_pid, package_buf, sizeof(package_buf)) != AUL_R_OK) + { + return service_error(SERVICE_ERROR_APP_NOT_FOUND, __FUNCTION__, "failed to get the package name of the caller"); + } + + package_dup = strdup(package_buf); + + if (package_dup == NULL) + { + return service_error(SERVICE_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL); + } + + *package = package_dup; + + return SERVICE_ERROR_NONE; +} + + +int service_is_reply_requested(service_h service, bool *requested) +{ + const char *bundle_value; + + if (service_valiate_service(service) || requested == NULL) + { + return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); + } + + if (service->type != SERVICE_TYPE_EVENT) + { + return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, "invalid service handle type"); + } + + bundle_value = bundle_get_val(service->data, AUL_K_WAIT_RESULT); + + if (bundle_value != NULL) + { + *requested = true; + } + else + { + *requested = false; + } + + return SERVICE_ERROR_NONE; +} + +int service_import_from_bundle(service_h service, bundle *data) +{ + bundle *data_dup = NULL; + + if (service_valiate_service(service) || data == NULL) + { + return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); + } + + data_dup = bundle_dup(data); + + if (data_dup == NULL) + { + return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, "failed to duplicate the bundle"); + } + + if (service->data != NULL) + { + bundle_free(service->data); + } + + service->data = data_dup; + + return SERVICE_ERROR_NONE; +} + +int service_export_as_bundle(service_h service, bundle **data) +{ + bundle *data_dup = NULL; + + if (service_valiate_service(service) || data == NULL) + { + return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); + } + + data_dup = bundle_dup(service->data); + + if (data_dup == NULL) + { + return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, "failed to duplicate the bundle"); + } + + *data = data_dup; + + return SERVICE_ERROR_NONE; +} + diff --git a/src/storage.c b/src/storage.c new file mode 100755 index 0000000..a6f9202 --- /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 "CAPI_APPFW_APPLICATION_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("failed to register device : not enough device table"); + 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("INVALID_PARAMETER(0x%08x) : invalid callback", 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("INVALID_PARAMETER(0x%08x) : invalid output param", STORAGE_ERROR_INVALID_PARAMETER); + return STORAGE_ERROR_INVALID_PARAMETER; + } + + if (storage_get_storage(storage, &storage_info) != 0) + { + LOGE("NOT_SUPPORTED(0x%08x) : storage(%d)", 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("INVALID_PARAMETER(0x%08x) : invalid output param", STORAGE_ERROR_INVALID_PARAMETER); + return STORAGE_ERROR_INVALID_PARAMETER; + } + + if (storage_get_storage(storage, &storage_info) != 0) + { + LOGE("NOT_SUPPORTED(0x%08x) : storage(%d)", 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("INVALID_PARAMETER(0x%08x) : invalid output param", STORAGE_ERROR_INVALID_PARAMETER); + return STORAGE_ERROR_INVALID_PARAMETER; + } + + if (storage_get_storage(storage, &storage_info) != 0) + { + LOGE("NOT_SUPPORTED(0x%08x) : storage(%d)", STORAGE_ERROR_NOT_SUPPORTED, storage); + return STORAGE_ERROR_NOT_SUPPORTED; + } + + get_state = storage_info->device->get_state; + + if (get_state == NULL) + { + LOGE("NOT_SUPPORTED(0x%08x) : storage(%d)", 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("INVALID_PARAMETER(0x%08x) : invalid storage information", 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("INVALID_PARAMETER(0x%08x) : invalid callback", STORAGE_ERROR_INVALID_PARAMETER); + return STORAGE_ERROR_INVALID_PARAMETER; + } + + if (storage_get_storage(storage, &storage_info) != 0) + { + LOGE("NOT_SUPPORTED(0x%08x) : storage(%d)", 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("NOT_SUPPORTED(0x%08x) : storage(%d)", STORAGE_ERROR_NOT_SUPPORTED, storage); + return STORAGE_ERROR_NOT_SUPPORTED; + } + + if (set_state_cb(storage_info) != 0) + { + LOGE("NOT_SUPPORTED(0x%08x) : storage(%d)", 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("NOT_SUPPORTED(0x%08x) : storage(%d)", 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("INVALID_PARAMETER(0x%08x) : invalid output param", STORAGE_ERROR_INVALID_PARAMETER); + return STORAGE_ERROR_INVALID_PARAMETER; + } + + if (storage_get_storage(storage, &storage_info) != 0) + { + LOGE("NOT_SUPPORTED(0x%08x) : storage(%d)", STORAGE_ERROR_NOT_SUPPORTED, storage); + return STORAGE_ERROR_NOT_SUPPORTED; + } + + get_space = storage_info->device->get_space; + + if (get_space == NULL) + { + LOGE("NOT_SUPPORTED(0x%08x) : storage(%d)", STORAGE_ERROR_NOT_SUPPORTED, storage); + return STORAGE_ERROR_NOT_SUPPORTED; + } + + if (get_space(bytes, NULL) != 0) + { + LOGE("NOT_SUPPORTED(0x%08x) : storage(%d)", 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("INVALID_PARAMETER(0x%08x) : invalid output param", STORAGE_ERROR_INVALID_PARAMETER); + return STORAGE_ERROR_INVALID_PARAMETER; + } + + if (storage_get_storage(storage, &storage_info) != 0) + { + LOGE("NOT_SUPPORTED(0x%08x) : storage(%d)", STORAGE_ERROR_NOT_SUPPORTED, storage); + return STORAGE_ERROR_NOT_SUPPORTED; + } + + get_space = storage_info->device->get_space; + + if (get_space == NULL) + { + LOGE("NOT_SUPPORTED(0x%08x) : storage(%d)", STORAGE_ERROR_NOT_SUPPORTED, storage); + return STORAGE_ERROR_NOT_SUPPORTED; + } + + if (get_space(NULL, bytes) != 0) + { + LOGE("NOT_SUPPORTED(0x%08x) : storage(%d)", 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("statfs returns error(%d) directory(%s)\n", 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..c9e0b6d --- /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 "CAPI_APPFW_APPLICATION_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("OUT_OF_MEMORY(0x%08x)", 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..9dd9cb0 --- /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 "CAPI_APPFW_APPLICATION_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("OUT_OF_MEMORY(0x%08x)", 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..aba65c0 --- /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 "CAPI_APPFW_APPLICATION_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_SYSMAN_USB_HOST_DISCONNECTED: + return STORAGE_STATE_REMOVED; + + case VCONFKEY_SYSMAN_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("OUT_OF_MEMORY(0x%08x)", 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..1610d02 --- /dev/null +++ b/src/ui_notification.c @@ -0,0 +1,1179 @@ +/* + * 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 <unistd.h> +#include <fcntl.h> + +#include <dlog.h> +#include <notification.h> + +#include <app.h> +#include <app_service_private.h> + +#ifdef LOG_TAG +#undef LOG_TAG +#endif + +#define LOG_TAG "CAPI_APPFW_APPLICATION_UI_NOTIFICATION" + +struct ui_notification_s { + notification_h raw_handle; + bool ongoing; + bool posted; + bool removed; + char *icon; + struct tm *time; + char *title; + char *content; + service_h service; + char *sound; + bool vibration; +}; + +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: + case NOTIFICATION_ERROR_NOT_EXIST_ID: + retcode = UI_NOTIFICATION_ERROR_INVALID_STATE; + error_msg = "INVALID_STATE"; + 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("INVALID_PARAMETER(0x%08x) : invalid output param", UI_NOTIFICATION_ERROR_INVALID_PARAMETER); + return UI_NOTIFICATION_ERROR_INVALID_PARAMETER; + } + + notification_out = (ui_notification_h)calloc(1, sizeof(struct ui_notification_s)); + + if (notification_out == NULL) + { + LOGE("OUT_OF_MEMORY(0x%08x)", UI_NOTIFICATION_ERROR_OUT_OF_MEMORY); + return UI_NOTIFICATION_ERROR_OUT_OF_MEMORY; + } + + notification_out->raw_handle = NULL; + notification_out->ongoing = ongoing; + notification_out->posted = false; + notification_out->removed = false; + notification_out->icon = NULL; + notification_out->time = NULL; + notification_out->title = NULL; + notification_out->content = NULL; + notification_out->service = NULL; + notification_out->sound = NULL; + notification_out->vibration = false; + + *notification = notification_out; + + return UI_NOTIFICATION_ERROR_NONE; +} + +static int ui_notification_construct(bool ongoing, notification_h raw_handle, ui_notification_h *notification) +{ + int retcode; + ui_notification_h notification_out; + char *icon; + time_t time; + char *title; + char *content; + bundle *service_data; + const char *sound = NULL; + notification_sound_type_e sound_type; + notification_vibration_type_e vib_type; + + if (notification == NULL) + { + LOGE("INVALID_PARAMETER(0x%08x) : invalid output param", UI_NOTIFICATION_ERROR_INVALID_PARAMETER); + return UI_NOTIFICATION_ERROR_INVALID_PARAMETER; + } + + notification_out = (ui_notification_h)calloc(1, sizeof(struct ui_notification_s)); + + if (notification_out == NULL) + { + LOGE("OUT_OF_MEMORY(0x%08x)", UI_NOTIFICATION_ERROR_OUT_OF_MEMORY); + return UI_NOTIFICATION_ERROR_OUT_OF_MEMORY; + } + + retcode = ui_notification_error_handler(notification_clone(raw_handle, &(notification_out->raw_handle)),\ + __FUNCTION__, "failed to clone the notification handle"); + + if (retcode != NOTIFICATION_ERROR_NONE) + { + free(notification_out); + return retcode; + } + + notification_out->ongoing = ongoing; + + notification_out->posted = true; + + notification_out->removed = false; + + if (!notification_get_image(raw_handle, NOTIFICATION_IMAGE_TYPE_ICON, &icon) && icon) + { + notification_out->icon = strdup(icon); + } + + if (!notification_get_time(raw_handle, &time)) + { + notification_out->time = malloc(sizeof(struct tm)); + + if (notification_out->time == NULL) + { + ui_notification_destroy(notification_out); + LOGE("OUT_OF_MEMORY(0x%08x)", UI_NOTIFICATION_ERROR_OUT_OF_MEMORY); + return UI_NOTIFICATION_ERROR_OUT_OF_MEMORY; + } + + localtime_r(&time, notification_out->time); + } + + if (!notification_get_text(raw_handle, NOTIFICATION_TEXT_TYPE_TITLE, &title) && title) + { + notification_out->title = strdup(title); + } + + if (!notification_get_text(raw_handle, NOTIFICATION_TEXT_TYPE_CONTENT, &content) && content) + { + notification_out->content = strdup(content); + } + + if (!notification_get_sound(raw_handle, &sound_type, &sound) && sound) + { + notification_out->sound = strdup(sound); + } + + if (!notification_get_vibration(raw_handle, &vib_type, NULL)) + { + if (vib_type == NOTIFICATION_VIBRATION_TYPE_DEFAULT) + { + notification_out->vibration = true; + } + } + + if (!notification_get_execute_option(raw_handle, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, NULL, &service_data)) + { + service_h service; + + if (!service_create_request(service_data, &service)) + { + notification_out->service = service; + } + } + + *notification = notification_out; + + return UI_NOTIFICATION_ERROR_NONE; +} + +int ui_notification_destroy(ui_notification_h notification) +{ + if (notification == NULL) + { + LOGE("INVALID_PARAMETER(0x%08x) : invalid handle", UI_NOTIFICATION_ERROR_INVALID_PARAMETER); + return UI_NOTIFICATION_ERROR_INVALID_PARAMETER; + } + + if (notification->raw_handle) + notification_free(notification->raw_handle); + + 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->sound) + free(notification->sound); + + if (notification->service) + service_destroy(notification->service); + + free(notification); + + return UI_NOTIFICATION_ERROR_NONE; +} + +int ui_notification_get_id(ui_notification_h notification, int *id) +{ + notification_h raw_handle = NULL; + + if (notification == NULL || id == NULL) + { + LOGE("INVALID_PARAMETER(0x%08x)", UI_NOTIFICATION_ERROR_INVALID_PARAMETER); + return UI_NOTIFICATION_ERROR_INVALID_PARAMETER; + } + if (notification->raw_handle == NULL) + { + LOGE("INVALID_PARAMETER(0x%08x)", UI_NOTIFICATION_ERROR_INVALID_PARAMETER); + return UI_NOTIFICATION_ERROR_INVALID_PARAMETER; + } + + raw_handle = notification->raw_handle; + if (notification_get_id(raw_handle, NULL, id) != NOTIFICATION_ERROR_NONE) { + LOGE("INVALID_PARAMETER(0x%08x)", UI_NOTIFICATION_ERROR_INVALID_PARAMETER); + return UI_NOTIFICATION_ERROR_INVALID_PARAMETER; + } + + return UI_NOTIFICATION_ERROR_NONE; +} + +int ui_notification_clone(ui_notification_h *clone, ui_notification_h notification) +{ + ui_notification_h notification_out; + int retcode; + + if (clone == NULL || notification == NULL) + { + LOGE("INVALID_PARAMETER(0x%08x)", UI_NOTIFICATION_ERROR_INVALID_PARAMETER); + return UI_NOTIFICATION_ERROR_INVALID_PARAMETER; + } + + notification_out = (ui_notification_h)calloc(1, sizeof(struct ui_notification_s)); + + if (notification_out == NULL) + { + LOGE("OUT_OF_MEMORY(0x%08x)", UI_NOTIFICATION_ERROR_OUT_OF_MEMORY); + return UI_NOTIFICATION_ERROR_OUT_OF_MEMORY; + } + + if (notification->raw_handle != NULL) + { + retcode = notification_clone(notification->raw_handle, &(notification_out->raw_handle)); + + if (retcode) + { + free(notification_out); + return ui_notification_error_handler(retcode, __FUNCTION__, "failed to clone the handle"); + } + } + + notification_out->ongoing = notification->ongoing; + + notification_out->posted = notification->posted; + + notification_out->removed = notification->removed; + + if (notification->icon) + { + notification_out->icon = strdup(notification->icon); + } + + if (notification->time) + { + notification_out->time = malloc(sizeof(struct tm)); + if (notification_out->time != NULL) + { + memcpy(notification_out->time, notification->time, sizeof(struct tm)); + } + } + + if (notification->title) + { + notification_out->title = strdup(notification->title); + } + + if (notification->content) + { + notification_out->content = strdup(notification->content); + } + + if (notification->sound) + { + notification_out->sound = strdup(notification->sound); + } + + notification_out->vibration = notification->vibration; + + if (notification->service) + { + service_clone(&(notification_out->service), notification->service); + } + + *clone = notification_out; + + return UI_NOTIFICATION_ERROR_NONE; +} + +int ui_notification_is_ongoing(ui_notification_h notification, bool *ongoing) +{ + if (notification == NULL || ongoing == NULL) + { + LOGE("INVALID_PARAMETER(0x%08x)", UI_NOTIFICATION_ERROR_INVALID_PARAMETER); + return UI_NOTIFICATION_ERROR_INVALID_PARAMETER; + } + + *ongoing = notification->ongoing; + + return UI_NOTIFICATION_ERROR_NONE; +} + +int ui_notification_set_icon(ui_notification_h notification, const char *path) +{ + char *path_dup = NULL; + + if (notification == NULL) + { + LOGE("INVALID_PARAMETER(0x%08x)", UI_NOTIFICATION_ERROR_INVALID_PARAMETER); + return UI_NOTIFICATION_ERROR_INVALID_PARAMETER; + } + + if (path != NULL) + { + path_dup = strdup(path); + + if (path_dup == NULL) + { + LOGE("OUT_OF_MEMORY(0x%08x)", 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("INVALID_PARAMETER(0x%08x)", 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("OUT_OF_MEMORY(0x%08x)", 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 = NULL; + + if (notification == NULL) + { + LOGE("INVALID_PARAMETER(0x%08x)", UI_NOTIFICATION_ERROR_INVALID_PARAMETER); + return UI_NOTIFICATION_ERROR_INVALID_PARAMETER; + } + + if (time != NULL) + { + time_dup = malloc(sizeof(struct tm)); + + if (time_dup == NULL) + { + LOGE("OUT_OF_MEMORY(0x%08x)", 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("INVALID_PARAMETER(0x%08x)", 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("OUT_OF_MEMORY(0x%08x)", 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 = NULL; + + if (notification == NULL) + { + LOGE("INVALID_PARAMETER(0x%08x)", UI_NOTIFICATION_ERROR_INVALID_PARAMETER); + return UI_NOTIFICATION_ERROR_INVALID_PARAMETER; + } + + if (title != NULL) + { + title_dup = strdup(title); + + if (title_dup == NULL) + { + LOGE("OUT_OF_MEMORY(0x%08x)", 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("INVALID_PARAMETER(0x%08x)", 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("OUT_OF_MEMORY(0x%08x)", 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 = NULL; + + if (notification == NULL) + { + LOGE("INVALID_PARAMETER(0x%08x)", UI_NOTIFICATION_ERROR_INVALID_PARAMETER); + return UI_NOTIFICATION_ERROR_INVALID_PARAMETER; + } + + if (content != NULL) + { + content_dup = strdup(content); + + if (content_dup == NULL) + { + LOGE("OUT_OF_MEMORY(0x%08x)", 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("INVALID_PARAMETER(0x%08x)", 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("OUT_OF_MEMORY(0x%08x)", 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 = NULL; + + if (notification == NULL) + { + LOGE("INVALID_PARAMETER(0x%08x)", UI_NOTIFICATION_ERROR_INVALID_PARAMETER); + return UI_NOTIFICATION_ERROR_INVALID_PARAMETER; + } + + if (service != NULL) + { + retcode = service_clone(&service_dup, service); + + if (retcode != SERVICE_ERROR_NONE) + { + if (retcode == SERVICE_ERROR_OUT_OF_MEMORY) + { + LOGE("OUT_OF_MEMORY(0x%08x)", UI_NOTIFICATION_ERROR_OUT_OF_MEMORY); + return UI_NOTIFICATION_ERROR_OUT_OF_MEMORY; + } + else + { + LOGE("INVALID_PARAMETER(0x%08x) : invalid service handle", 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("INVALID_PARAMETER(0x%08x)", 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("OUT_OF_MEMORY(0x%08x)", UI_NOTIFICATION_ERROR_OUT_OF_MEMORY); + return UI_NOTIFICATION_ERROR_OUT_OF_MEMORY; + } + else + { + LOGE("INVALID_PARAMETER(0x%08x) : invalid service handle", UI_NOTIFICATION_ERROR_INVALID_PARAMETER); + return UI_NOTIFICATION_ERROR_INVALID_PARAMETER; + } + } + } + + *service = service_dup; + + return UI_NOTIFICATION_ERROR_NONE; +} + +int ui_notification_set_sound(ui_notification_h notification, const char *path) +{ + char *path_dup = NULL; + + if (notification == NULL) + { + LOGE("INVALID_PARAMETER(0x%08x)", UI_NOTIFICATION_ERROR_INVALID_PARAMETER); + return UI_NOTIFICATION_ERROR_INVALID_PARAMETER; + } + + if (path != NULL) + { + path_dup = strdup(path); + + if (path_dup == NULL) + { + LOGE("OUT_OF_MEMORY(0x%08x)", UI_NOTIFICATION_ERROR_OUT_OF_MEMORY); + return UI_NOTIFICATION_ERROR_OUT_OF_MEMORY; + } + } + + if (notification->sound != NULL) + { + free(notification->sound); + } + + notification->sound = path_dup; + + return UI_NOTIFICATION_ERROR_NONE; +} + +int ui_notification_get_sound(ui_notification_h notification, char **path) +{ + char *path_dup = NULL; + + if (notification == NULL || path == NULL) + { + LOGE("INVALID_PARAMETER(0x%08x)", UI_NOTIFICATION_ERROR_INVALID_PARAMETER); + return UI_NOTIFICATION_ERROR_INVALID_PARAMETER; + } + + if (notification->sound != NULL) + { + path_dup = strdup(notification->sound); + + if (path_dup == NULL) + { + LOGE("OUT_OF_MEMORY(0x%08x)", UI_NOTIFICATION_ERROR_OUT_OF_MEMORY); + *path = NULL; + + return UI_NOTIFICATION_ERROR_OUT_OF_MEMORY; + } + } + + *path = path_dup; + + return UI_NOTIFICATION_ERROR_NONE; +} + +int ui_notification_set_vibration(ui_notification_h notification, bool value) +{ + if (notification == NULL) + { + LOGE("INVALID_PARAMETER(0x%08x)", UI_NOTIFICATION_ERROR_INVALID_PARAMETER); + return UI_NOTIFICATION_ERROR_INVALID_PARAMETER; + } + + notification->vibration = value; + + return UI_NOTIFICATION_ERROR_NONE; +} + +int ui_notification_get_vibration(ui_notification_h notification, bool *value) +{ + if (notification == NULL || value == NULL) + { + LOGE("INVALID_PARAMETER(0x%08x)", UI_NOTIFICATION_ERROR_INVALID_PARAMETER); + return UI_NOTIFICATION_ERROR_INVALID_PARAMETER; + } + + *value = notification->vibration; + + return UI_NOTIFICATION_ERROR_NONE; +} + +static int ui_notification_build_attributes(ui_notification_h notification) +{ + bundle *service_data; + + if (notification == NULL) + { + LOGE("INVALID_PARAMETER(0x%08x) : invalid handle", UI_NOTIFICATION_ERROR_INVALID_PARAMETER); + return UI_NOTIFICATION_ERROR_INVALID_PARAMETER; + } + + if (notification->icon != NULL) + { + struct stat st; + + if (stat(notification->icon, &st) < 0) + { + LOGE("NO_SUCH_FILE(0x%08x) : invalid icon", UI_NOTIFICATION_ERROR_NO_SUCH_FILE); + return UI_NOTIFICATION_ERROR_NO_SUCH_FILE; + } + + notification_set_image(notification->raw_handle, NOTIFICATION_IMAGE_TYPE_ICON, notification->icon); + } + + if (notification->time != NULL) + { + notification_set_time(notification->raw_handle, mktime(notification->time)); + } + + if (notification->title != NULL) + { + notification_set_text(notification->raw_handle, NOTIFICATION_TEXT_TYPE_TITLE, notification->title, NULL, NOTIFICATION_VARIABLE_TYPE_NONE); + } + + if (notification->content != NULL) + { + notification_set_text(notification->raw_handle, NOTIFICATION_TEXT_TYPE_CONTENT, notification->content, NULL, NOTIFICATION_VARIABLE_TYPE_NONE); + } + + if (notification->service != NULL && service_to_bundle(notification->service, &service_data) == SERVICE_ERROR_NONE) + { + notification_set_property(notification->raw_handle, 0); + notification_set_execute_option(notification->raw_handle, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, NULL, NULL, service_data); + } + else + { + notification_set_property(notification->raw_handle, NOTIFICATION_PROP_DISABLE_APP_LAUNCH); + } + + if (notification->sound != NULL) + { + struct stat st; + + if (stat(notification->sound, &st) < 0) + { + LOGE("NO_SUCH_FILE(0x%08x) : invalid sound file", UI_NOTIFICATION_ERROR_NO_SUCH_FILE); + return UI_NOTIFICATION_ERROR_NO_SUCH_FILE; + } + notification_set_sound(notification->raw_handle, NOTIFICATION_SOUND_TYPE_USER_DATA, notification->sound); + } + + if (notification->vibration) + { + notification_set_vibration(notification->raw_handle, NOTIFICATION_VIBRATION_TYPE_DEFAULT, NULL); + } + + return UI_NOTIFICATION_ERROR_NONE; +} + +int ui_notification_post(ui_notification_h notification) +{ + int retcode; + + if (notification == NULL) + { + LOGE("INVALID_PARAMETER(0x%08x)", UI_NOTIFICATION_ERROR_INVALID_PARAMETER); + return UI_NOTIFICATION_ERROR_INVALID_PARAMETER; + } + + if (notification->posted == true) + { + LOGE("INVALID_STATE(0x%08x) : the notification was already posted", UI_NOTIFICATION_ERROR_INVALID_STATE); + return UI_NOTIFICATION_ERROR_INVALID_STATE; + } + + if (notification->ongoing == true) + { + notification->raw_handle = notification_new(NOTIFICATION_TYPE_ONGOING, NOTIFICATION_GROUP_ID_DEFAULT, NOTIFICATION_PRIV_ID_NONE); + } + else + { + notification->raw_handle = notification_new(NOTIFICATION_TYPE_NOTI, NOTIFICATION_GROUP_ID_DEFAULT, NOTIFICATION_PRIV_ID_NONE); + } + + if (notification->raw_handle == NULL) + { + LOGE("OUT_OF_MEMORY(0x%08x)", UI_NOTIFICATION_ERROR_OUT_OF_MEMORY); + return UI_NOTIFICATION_ERROR_OUT_OF_MEMORY; + } + + retcode = ui_notification_build_attributes(notification); + + if (retcode != UI_NOTIFICATION_ERROR_NONE) + { + return retcode; + } + + retcode = ui_notification_error_handler(notification_insert(notification->raw_handle, NULL), __FUNCTION__, "failed to post a notification"); + + if (retcode == UI_NOTIFICATION_ERROR_NONE) + { + notification->posted = true; + } + + return retcode; +} + +int ui_notification_update(ui_notification_h notification) +{ + int retcode; + + if (notification == NULL) + { + LOGE("INVALID_PARAMETER(0x%08x)", UI_NOTIFICATION_ERROR_INVALID_PARAMETER); + return UI_NOTIFICATION_ERROR_INVALID_PARAMETER; + } + + if (notification->posted == false) + { + LOGE("INVALID_STATE(0x%08x) : the notification was not posted", UI_NOTIFICATION_ERROR_INVALID_STATE); + return UI_NOTIFICATION_ERROR_INVALID_STATE; + } + + if (notification->removed == true) + { + LOGE("INVALID_STATE(0x%08x) : the notification was canceled or cleared", UI_NOTIFICATION_ERROR_INVALID_STATE); + return UI_NOTIFICATION_ERROR_INVALID_STATE; + } + + retcode = ui_notification_build_attributes(notification); + + if (retcode != UI_NOTIFICATION_ERROR_NONE) + { + return retcode; + } + + retcode = ui_notification_error_handler(notification_update(notification->raw_handle), __FUNCTION__, "failed to post a notification"); + + if (retcode == UI_NOTIFICATION_ERROR_INVALID_STATE) + { + notification->removed = 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("INVALID_PARAMETER(0x%08x)", UI_NOTIFICATION_ERROR_INVALID_PARAMETER); + return UI_NOTIFICATION_ERROR_INVALID_PARAMETER; + } + + if (notification->raw_handle == NULL) + { + LOGE("INVALID_PARAMETER(0x%08x) : invalid handle", UI_NOTIFICATION_ERROR_INVALID_PARAMETER); + return UI_NOTIFICATION_ERROR_INVALID_PARAMETER; + } + + if (notification->posted == false) + { + LOGE("INVALID_STATE(0x%08x) : the notification was not posted", UI_NOTIFICATION_ERROR_INVALID_STATE); + return UI_NOTIFICATION_ERROR_INVALID_STATE; + } + + if (notification->removed == true) + { + LOGE("INVALID_STATE(0x%08x) : the notification was canceled or cleared", UI_NOTIFICATION_ERROR_INVALID_STATE); + return UI_NOTIFICATION_ERROR_INVALID_STATE; + } + + if (value < 0) + { + LOGE("INVALID_PARAMETER(0x%08x) : the value must be greater than or equal to zero.", 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->raw_handle, 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->raw_handle, NOTIFICATION_PRIV_ID_NONE, value), + __FUNCTION__, "failed to update the progress"); + break; + + default: + LOGE("INVALID_PARAMETER(0x%08x) : invalid progress type", UI_NOTIFICATION_ERROR_INVALID_PARAMETER); + return UI_NOTIFICATION_ERROR_INVALID_PARAMETER; + } + + if (retcode == UI_NOTIFICATION_ERROR_INVALID_STATE) + { + notification->removed = true; + } + + return retcode; +} + +int ui_notification_cancel(ui_notification_h notification) +{ + int retcode; + + if (notification == NULL) + { + LOGE("INVALID_PARAMETER(0x%08x)", UI_NOTIFICATION_ERROR_INVALID_PARAMETER); + return UI_NOTIFICATION_ERROR_INVALID_PARAMETER; + } + + if (notification->raw_handle == NULL) + { + LOGE("INVALID_PARAMETER(0x%08x) : invalid handle", UI_NOTIFICATION_ERROR_INVALID_PARAMETER); + return UI_NOTIFICATION_ERROR_INVALID_PARAMETER; + } + + if (notification->posted == false) + { + LOGE("INVALID_STATE(0x%08x) : the notification was not posted", UI_NOTIFICATION_ERROR_INVALID_STATE); + return UI_NOTIFICATION_ERROR_INVALID_STATE; + } + + if (notification->removed == true) + { + LOGE("INVALID_STATE(0x%08x) : the notification was canceled or cleared", UI_NOTIFICATION_ERROR_INVALID_STATE); + return UI_NOTIFICATION_ERROR_INVALID_STATE; + } + + retcode = ui_notification_error_handler(notification_delete(notification->raw_handle), __FUNCTION__, "failed to cancel the notification"); + + if (retcode == UI_NOTIFICATION_ERROR_NONE) + { + notification->removed = true; + } + + return retcode; +} + +void ui_notification_cancel_all(void) +{ + notification_delete_all_by_type(NULL, NOTIFICATION_TYPE_NONE); +} + +void ui_notification_cancel_all_by_type(bool ongoing) +{ + notification_type_e type = NOTIFICATION_TYPE_NONE; + + if (ongoing) + type = NOTIFICATION_TYPE_ONGOING; + else + type = NOTIFICATION_TYPE_NOTI; + + notification_delete_all_by_type(NULL, type); +} + +void ui_notification_cancel_all_by_package(const char *package, bool ongoing) +{ + notification_type_e type = NOTIFICATION_TYPE_NONE; + + if (ongoing) + type = NOTIFICATION_TYPE_ONGOING; + else + type = NOTIFICATION_TYPE_NOTI; + + notification_delete_all_by_type(package, type); +} + +int ui_notification_cancel_all_by_app_id(const char *app_id, bool ongoing) +{ + notification_type_e type = NOTIFICATION_TYPE_NONE; + + if (app_id == NULL) + { + LOGE("INVALID_PARAMETER(0x%08x)", UI_NOTIFICATION_ERROR_INVALID_PARAMETER); + return UI_NOTIFICATION_ERROR_INVALID_PARAMETER; + } + + if (ongoing) + type = NOTIFICATION_TYPE_ONGOING; + else + type = NOTIFICATION_TYPE_NOTI; + + notification_delete_all_by_type(app_id, type); + + return UI_NOTIFICATION_ERROR_NONE; +} + +static bool ui_notification_package_equal(notification_h handle) +{ + char *package = NULL; + char *handle_package = NULL; + char cmdline[512] = {0,}; + char buf[64] = {0,}; + + if (notification_get_pkgname(handle, &handle_package)) + { + return false; + } + + if (app_get_package(&package)) + { + int ret = 0; + int fd = -1; + int pid = getpid(); + + snprintf(buf, sizeof(buf), "/proc/%d/cmdline", pid); + + fd = open(buf, O_RDONLY); + if (fd < 0) { + return false; + } + + ret = read(fd, cmdline, sizeof(cmdline) - 1); + if (ret <= 0) { + close(fd); + return false; + } + + cmdline[ret] = 0; + close(fd); + + if (strlen(cmdline) == strlen(handle_package)) + { + if (!strncmp(cmdline, handle_package, strlen(cmdline))) + { + return true; + } + } + } + else + { + if (strlen(package) == strlen(handle_package)) + { + if (!strncmp(package, handle_package, strlen(package))) + { + return true; + } + } + } + + return false; +} + +int ui_notification_foreach_notification_posted(bool ongoing, ui_notification_cb callback, void *user_data) +{ + notification_list_h raw_handle_list; + notification_h raw_handle; + notification_type_e notification_type = ongoing ? NOTIFICATION_TYPE_ONGOING : NOTIFICATION_TYPE_NOTI; + ui_notification_h notification = NULL; + bool iterate_next = true; + + if (callback == NULL) + { + LOGE("INVALID_PARAMETER(0x%08x)", UI_NOTIFICATION_ERROR_INVALID_PARAMETER); + return UI_NOTIFICATION_ERROR_INVALID_PARAMETER; + } + + if (notification_get_grouping_list(notification_type, -1, &raw_handle_list)) + { + LOGE("DB_FAILED(0x%08x) : failed to get a notification list", UI_NOTIFICATION_ERROR_DB_FAILED); + return UI_NOTIFICATION_ERROR_DB_FAILED; + } + + while (raw_handle_list != NULL) + { + raw_handle = notification_list_get_data(raw_handle_list); + + if (raw_handle != NULL && ui_notification_package_equal(raw_handle)) + { + if (!ui_notification_construct(ongoing, raw_handle, ¬ification)) + { + iterate_next = callback(notification, user_data); + + ui_notification_destroy(notification); + + if (iterate_next == false) + { + break; + } + } + } + + raw_handle_list = notification_list_get_next(raw_handle_list); + } + + notification_free_list(raw_handle_list); + + return UI_NOTIFICATION_ERROR_NONE; +} + |