Migrate from 2.4 code repo 88/41188/1
authorMu-Woong <muwoong.lee@samsung.com>
Thu, 11 Jun 2015 11:29:16 +0000 (20:29 +0900)
committerMu-Woong <muwoong.lee@samsung.com>
Thu, 11 Jun 2015 11:29:16 +0000 (20:29 +0900)
Change-Id: I430651c4e3b57a31110c17a3935e65a86ca89688
Signed-off-by: Mu-Woong <muwoong.lee@samsung.com>
29 files changed:
.gitignore [new file with mode: 0644]
AUTHORS [new file with mode: 0644]
CMakeLists.txt [new file with mode: 0644]
LICENSE [new file with mode: 0644]
context.pc.in [new file with mode: 0644]
doc/context_history_doc.h [new file with mode: 0644]
doc/context_trigger_doc.h [new file with mode: 0644]
include/context_history.h [new file with mode: 0644]
include/context_history_types_internal.h [new file with mode: 0644]
include/context_internal.h [new file with mode: 0644]
include/context_trigger.h [new file with mode: 0644]
include/context_trigger_types_internal.h [new file with mode: 0644]
internal/CMakeLists.txt [new file with mode: 0644]
internal/context_internal.cpp [new file with mode: 0644]
packaging/context.manifest [new file with mode: 0644]
packaging/context.spec [new file with mode: 0644]
src/context_history.cpp [new file with mode: 0644]
src/context_trigger.cpp [new file with mode: 0644]
src/priv_util.cpp [new file with mode: 0644]
src/priv_util.h [new file with mode: 0644]
src/rule_info.h [new file with mode: 0644]
src/rule_validator.cpp [new file with mode: 0644]
src/rule_validator.h [new file with mode: 0644]
test/CMakeLists.txt [new file with mode: 0644]
test/src/main.c [new file with mode: 0644]
test/src/utc_context_history.c [new file with mode: 0644]
test/src/utc_context_history.h [new file with mode: 0644]
test/src/utc_context_trigger.c [new file with mode: 0644]
test/src/utc_context_trigger.h [new file with mode: 0644]

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..a01ee28
--- /dev/null
@@ -0,0 +1 @@
+.*.swp
diff --git a/AUTHORS b/AUTHORS
new file mode 100644 (file)
index 0000000..d97a819
--- /dev/null
+++ b/AUTHORS
@@ -0,0 +1,3 @@
+Mu-Woong Lee <muwoong.lee@samsung.com>
+Jihoon Park  <jhp27.park@samsung.com>
+Somin Kim    <somin926.kim@samsung.com>
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644 (file)
index 0000000..6916b08
--- /dev/null
@@ -0,0 +1,82 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+PROJECT(context)
+INCLUDE(GNUInstallDirs)
+
+# Targets
+SET(target "context")
+
+# Source Lists
+FILE(GLOB_RECURSE SRCS src/*.cpp)
+MESSAGE("Sources: ${SRCS}")
+
+# Dependencies
+SET(DEPS "aul bundle pkgmgr-info capi-security-privilege-manager capi-appfw-app-control context-common")
+
+# Dependencies regarding profiles
+IF("${PROFILE}" STREQUAL "mobile")
+       ADD_DEFINITIONS("-D_MOBILE")
+ENDIF("${PROFILE}" STREQUAL "mobile")
+
+IF("${PROFILE}" STREQUAL "wearable")
+       ADD_DEFINITIONS("-D_WEARABLE")
+ENDIF("${PROFILE}" STREQUAL "wearable")
+
+# Target vs Emulator
+IF("${ARCH}" STREQUAL "arm")
+       ADD_DEFINITIONS("-D_TARGET")
+ELSE("${ARCH}" STREQUAL "arm")
+       ADD_DEFINITIONS("-D_EMULATOR")
+ENDIF("${ARCH}" STREQUAL "arm")
+
+# Common Options
+INCLUDE(FindPkgConfig)
+INCLUDE_DIRECTORIES(
+       ${CMAKE_SOURCE_DIR}/include
+)
+ADD_DEFINITIONS(-g -O2 -Wall -fPIC -fvisibility=hidden -Wl,--as-needed)
+
+# Building Library
+pkg_check_modules(api_pkg REQUIRED ${DEPS})
+
+FOREACH(flag ${api_pkg_CFLAGS})
+   SET(API_EXTRA_CFLAGS "${API_EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+ADD_LIBRARY(${target} SHARED ${SRCS})
+TARGET_LINK_LIBRARIES(${target} ${api_pkg_LDFLAGS})
+SET_TARGET_PROPERTIES(${target} PROPERTIES COMPILE_FLAGS ${API_EXTRA_CFLAGS})
+SET_TARGET_PROPERTIES(${target} PROPERTIES COMPILE_DEFINITIONS "LOG_TAG=\"CONTEXT-API\"")
+SET_TARGET_PROPERTIES(${target} PROPERTIES SOVERSION ${MAJORVER})
+SET_TARGET_PROPERTIES(${target} PROPERTIES VERSION ${FULLVER})
+
+# Installing
+INSTALL(TARGETS ${target} DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT RuntimeLibraries)
+INSTALL(
+       DIRECTORY ${CMAKE_SOURCE_DIR}/include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/context-service
+       FILES_MATCHING PATTERN "*.h"
+       PATTERN "*_internal.h" EXCLUDE
+)
+
+SET(VERSION ${FULLVER})
+SET(PREFIX ${CMAKE_INSTALL_PREFIX})
+SET(PC_NAME ${PROJECT_NAME})
+SET(PC_INCLUDE "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}/context-service")
+SET(PC_LIBDIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}")
+SET(PC_DESCRIPTION "Tizen Context Framework Native API")
+SET(PC_REQUIRED ${DEPS})
+SET(PC_LDFLAGS -l${target})
+SET(PC_CFLAGS -I\${includedir}/context-service)
+
+CONFIGURE_FILE(
+       ${PROJECT_NAME}.pc.in
+       ${CMAKE_SOURCE_DIR}/${PROJECT_NAME}.pc
+       @ONLY
+)
+INSTALL(FILES ${CMAKE_SOURCE_DIR}/${PROJECT_NAME}.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
+
+# Building internal test API
+ADD_SUBDIRECTORY(internal)
+
+#IF("${BINTYPE}" STREQUAL "engineer")  //TODO: Re-enabled later
+#      ADD_SUBDIRECTORY(test)
+#ENDIF("${BINTYPE}" STREQUAL "engineer")
diff --git a/LICENSE b/LICENSE
new file mode 100644 (file)
index 0000000..1da314d
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,204 @@
+Copyright (c) 2000 - 2014 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 (c) 2014 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.
+
diff --git a/context.pc.in b/context.pc.in
new file mode 100644 (file)
index 0000000..378b991
--- /dev/null
@@ -0,0 +1,13 @@
+#Package Information for pkg-config
+
+prefix=@PREFIX@
+exec_prefix=@PREFIX@
+libdir=@PC_LIBDIR@
+includedir=@PC_INCLUDE@
+
+Name: @PC_NAME@
+Description: @PC_DESCRIPTION@
+Version: @VERSION@
+Requires: @PC_REQUIRED@
+Libs: -L${libdir} @PC_LDFLAGS@
+Cflags: -I${includedir}
diff --git a/doc/context_history_doc.h b/doc/context_history_doc.h
new file mode 100644 (file)
index 0000000..c08d9ab
--- /dev/null
@@ -0,0 +1,910 @@
+/*
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * @ingroup            CAPI_CONTEXT_FRAMEWORK
+ * @defgroup   CAPI_CONTEXT_HISTORY_MODULE Contextual History
+ *
+ * @brief              The contextual history API provides functions for reading contextual history data.@n
+ *                             This API allows you to query statistics and patterns derived from contextual history data.
+ *
+ * @section            CAPI_CONTEXT_HISTORY_MODULE_HEADER Required Header
+ *                             \#include <context_history.h>
+ *
+ * @section            CAPI_CONTEXT_HISTORY_MODULE_OVERVIEW Overview
+ *
+ *
+ * @subsection CAPI_CONTEXT_HISTORY_MODULE_Get To get contextual history data
+ *The application can read derived contextual history data with <em>read</em> API provided by contextual history engine.
+ *The data is mainly categorized to <i>Application Usage</i>, <i>Peak Time of Activity</i> and <i>Common Setting for Activity</i>. @n
+ *To read desired data with contextual history API, you should set data type and filters to limit raw data set. Each data type has its corresponding possible filter types and result attributes. @n
+ *Each data type also requires different types of privilege.
+ *The following is the list of data type. An enumeration type is defined to #context_history_data_e.
+ *
+ *<ul>
+ *     <li>#CONTEXT_HISTORY_RECENTLY_USED_APP @n
+ *             Description : Returns recently used application list sorted by time in descending order. @n
+ *             Required privilege : <em> http://tizen.org/privilege/apphistory.read </em> @n
+ *             <table>
+ *             <caption> Table: Filters</caption>
+ *             <tr>
+ *                     <th> Filter </th>
+ *                     <th> Type </th>
+ *                     <th> Value </th>
+ *                     <th> Mandatory </th>
+ *             </tr>
+ *             <tr>
+ *                     <td> #CONTEXT_HISTORY_FILTER_TIME_SPAN </td>
+ *                     <td> integer </td>
+ *                     <td> Time span of data in days from today ( 1 ~ 90 ) </td>
+ *                     <td> O </td>
+ *             </tr>
+ *             <tr>
+ *                     <td> #CONTEXT_HISTORY_FILTER_RESULT_SIZE </td>
+ *                     <td> integer </td>
+ *                     <td> Result size of data set ( 1 ~ 50 ) </td>
+ *                     <td> O </td>
+ *             </tr>
+ *             <tr>
+ *                     <td> #CONTEXT_HISTORY_FILTER_START_TIME </td>
+ *                     <td> integer </td>
+ *                     <td> Start time in epoch time to load only data which is inserted after the specific time</td>
+ *                     <td> X </td>
+ *             </tr>
+ *             <tr>
+ *                     <td> #CONTEXT_HISTORY_FILTER_END_TIME </td>
+ *                     <td> integer </td>
+ *                     <td> End time in epoch time to load only data which is inserted before the specific time</td>
+ *                     <td> X </td>
+ *             </tr>
+ *             <tr>
+ *                     <td> #CONTEXT_HISTORY_FILTER_WIFI_BSSID </td>
+ *                     <td> string </td>
+ *                     <td> Wi-Fi BSSID value to filter </td>
+ *                     <td> X </td>
+ *             </tr>
+ *             <tr>
+ *                     <td> #CONTEXT_HISTORY_FILTER_AUDIO_JACK </td>
+ *                     <td> integer </td>
+ *                     <td> Audio jack status #context_history_filter_audio_jack_e </td>
+ *                     <td> X </td>
+ *             </tr>
+ *             </table>
+ *             <table>
+ *             <caption> Table: Attributes</caption>
+ *             <tr>
+ *                     <th> Attribute </th>
+ *                     <th> Type </th>
+ *                     <th> Value </th>
+ *             </tr>
+ *             <tr>
+ *                     <td> #CONTEXT_HISTORY_APP_ID </td>
+ *                     <td> string </td>
+ *                     <td> Application id </td>
+ *             </tr>
+ *             <tr>
+ *                     <td> #CONTEXT_HISTORY_TOTAL_COUNT </td>
+ *                     <td> integer </td>
+ *                     <td> Total used count </td>
+ *             </tr>
+ *             <tr>
+ *                     <td> #CONTEXT_HISTORY_TOTAL_DURATION </td>
+ *                     <td> integer </td>
+ *                     <td> Total used time in second </td>
+ *             </tr>
+ *             <tr>
+ *                     <td> #CONTEXT_HISTORY_LAST_TIME </td>
+ *                     <td> integer </td>
+ *                     <td> Last used time in epoch time </td>
+ *             </tr>
+ *             </table> @n
+ *     <li>#CONTEXT_HISTORY_FREQUENTLY_USED_APP @n
+ *             Description : Returns frequently used application list sorted by used count in descending order. @n
+ *             Required privilege : <em> http://tizen.org/privilege/apphistory.read </em> @n
+ *             <table>
+ *             <caption> Table: Filters</caption>
+ *             <tr>
+ *                     <th> Filter </th>
+ *                     <th> Type </th>
+ *                     <th> Value </th>
+ *                     <th> Mandatory </th>
+ *             </tr>
+ *             <tr>
+ *                     <td> #CONTEXT_HISTORY_FILTER_TIME_SPAN </td>
+ *                     <td> integer </td>
+ *                     <td> Time span of data in days from today ( 1 ~ 90 ) </td>
+ *                     <td> O </td>
+ *             </tr>
+ *             <tr>
+ *                     <td> #CONTEXT_HISTORY_FILTER_RESULT_SIZE </td>
+ *                     <td> integer </td>
+ *                     <td> Result size of data set ( 1 ~ 50 ) </td>
+ *                     <td> O </td>
+ *             </tr>
+ *             <tr>
+ *                     <td> #CONTEXT_HISTORY_FILTER_START_TIME </td>
+ *                     <td> integer </td>
+ *                     <td> Start time in epoch time to load only data which is inserted after the specific time</td>
+ *                     <td> X </td>
+ *             </tr>
+ *             <tr>
+ *                     <td> #CONTEXT_HISTORY_FILTER_END_TIME </td>
+ *                     <td> integer </td>
+ *                     <td> End time in epoch time to load only data which is inserted before the specific time</td>
+ *                     <td> X </td>
+ *             </tr>
+ *             <tr>
+ *                     <td> #CONTEXT_HISTORY_FILTER_WIFI_BSSID </td>
+ *                     <td> string </td>
+ *                     <td> Wi-Fi BSSID value to filter </td>
+ *                     <td> X </td>
+ *             </tr>
+ *             <tr>
+ *                     <td> #CONTEXT_HISTORY_FILTER_AUDIO_JACK </td>
+ *                     <td> integer </td>
+ *                     <td> Audio jack status #context_history_filter_audio_jack_e </td>
+ *                     <td> X </td>
+ *             </tr>
+ *             </table>
+ *             <table>
+ *             <caption> Table: Attributes</caption>
+ *             <tr>
+ *                     <th> Attribute </th>
+ *                     <th> Type </th>
+ *                     <th> Value </th>
+ *             </tr>
+ *             <tr>
+ *                     <td> #CONTEXT_HISTORY_APP_ID </td>
+ *                     <td> string </td>
+ *                     <td> Application id </td>
+ *             </tr>
+ *             <tr>
+ *                     <td> #CONTEXT_HISTORY_TOTAL_COUNT </td>
+ *                     <td> integer </td>
+ *                     <td> Total used count </td>
+ *             </tr>
+ *             <tr>
+ *                     <td> #CONTEXT_HISTORY_TOTAL_DURATION </td>
+ *                     <td> integer </td>
+ *                     <td> Total used time in second </td>
+ *             </tr>
+ *             <tr>
+ *                     <td> #CONTEXT_HISTORY_LAST_TIME </td>
+ *                     <td> integer </td>
+ *                     <td> Last used time in epoch time </td>
+ *             </tr>
+ *             </table> @n
+ *     <li>#CONTEXT_HISTORY_RARELY_USED_APP @n
+ *             Description : Returns rarely used application list sorted by time in descending order. @n
+ *             Required privilege : <em> http://tizen.org/privilege/apphistory.read </em> @n
+ *             <table>
+ *             <caption> Table: Filters</caption>
+ *             <tr>
+ *                     <th> Filter </th>
+ *                     <th> Type </th>
+ *                     <th> Value </th>
+ *                     <th> Mandatory </th>
+ *             </tr>
+ *             <tr>
+ *                     <td> #CONTEXT_HISTORY_FILTER_TIME_SPAN </td>
+ *                     <td> integer </td>
+ *                     <td> Time span of data in days from today ( 1 ~ 90 ) </td>
+ *                     <td> O </td>
+ *             </tr>
+ *             <tr>
+ *                     <td> #CONTEXT_HISTORY_FILTER_RESULT_SIZE </td>
+ *                     <td> integer </td>
+ *                     <td> Result size of data set ( 1 ~ 50 ) </td>
+ *                     <td> O </td>
+ *             </tr>
+ *             <tr>
+ *                     <td> #CONTEXT_HISTORY_FILTER_START_TIME </td>
+ *                     <td> integer </td>
+ *                     <td> Start time in epoch time to load only data which is inserted after the specific time</td>
+ *                     <td> X </td>
+ *             </tr>
+ *             <tr>
+ *                     <td> #CONTEXT_HISTORY_FILTER_END_TIME </td>
+ *                     <td> integer </td>
+ *                     <td> End time in epoch time to load only data which is inserted before the specific time</td>
+ *                     <td> X </td>
+ *             </tr>
+ *             </table>
+ *             <table>
+ *             <caption> Table: Attributes</caption>
+ *             <tr>
+ *                     <th> Attribute </th>
+ *                     <th> Type </th>
+ *                     <th> Value </th>
+ *             </tr>
+ *             <tr>
+ *                     <td> #CONTEXT_HISTORY_APP_ID </td>
+ *                     <td> string </td>
+ *                     <td> Application id </td>
+ *             </tr>
+ *             <tr>
+ *                     <td> #CONTEXT_HISTORY_TOTAL_COUNT </td>
+ *                     <td> integer </td>
+ *                     <td> Total used count </td>
+ *             </tr>
+ *             <tr>
+ *                     <td> #CONTEXT_HISTORY_TOTAL_DURATION </td>
+ *                     <td> integer </td>
+ *                     <td> Total used time in second </td>
+ *             </tr>
+ *             <tr>
+ *                     <td> #CONTEXT_HISTORY_LAST_TIME </td>
+ *                     <td> integer </td>
+ *                     <td> Last used time in epoch time </td>
+ *             </tr>
+ *             </table> @n
+ *     <li>#CONTEXT_HISTORY_PEAK_TIME_FOR_APP @n
+ *             Description : Returns peak time of application use list in hour sorted by used time in descending order. @n
+ *             Required privilege : <em> http://tizen.org/privilege/apphistory.read </em> @n
+ *             <table>
+ *             <caption> Table: Filters</caption>
+ *             <tr>
+ *                     <th> Filter </th>
+ *                     <th> Type </th>
+ *                     <th> Value </th>
+ *                     <th> Mandatory </th>
+ *             </tr>
+ *             <tr>
+ *                     <td> #CONTEXT_HISTORY_FILTER_TIME_SPAN </td>
+ *                     <td> integer </td>
+ *                     <td> Time span of data in days from today ( 1 ~ 90 ) </td>
+ *                     <td> O </td>
+ *             </tr>
+ *             <tr>
+ *                     <td> #CONTEXT_HISTORY_FILTER_RESULT_SIZE </td>
+ *                     <td> integer </td>
+ *                     <td> Result size of data set ( 1 ~ 50 ) </td>
+ *                     <td> O </td>
+ *             </tr>
+ *             <tr>
+ *                     <td> #CONTEXT_HISTORY_FILTER_START_TIME </td>
+ *                     <td> integer </td>
+ *                     <td> Start time in epoch time to load only data which is inserted after the specific time</td>
+ *                     <td> X </td>
+ *             </tr>
+ *             <tr>
+ *                     <td> #CONTEXT_HISTORY_FILTER_END_TIME </td>
+ *                     <td> integer </td>
+ *                     <td> End time in epoch time to load only data which is inserted before the specific time</td>
+ *                     <td> X </td>
+ *             </tr>
+ *             <tr>
+ *                     <td> #CONTEXT_HISTORY_FILTER_APP_ID </td>
+ *                     <td> string </td>
+ *                     <td> Application id to filter</td>
+ *                     <td> X </td>
+ *             </tr>
+ *             <tr>
+ *                     <td> #CONTEXT_HISTORY_FILTER_DAY_OF_WEEK </td>
+ *                     <td> integer </td>
+ *                     <td> Weekdays or weekends #context_history_filter_day_of_week_e </td>
+ *                     <td> X (Default : All days) </td>
+ *             </tr>
+ *             </table>
+ *             <table>
+ *             <caption> Table: Attributes</caption>
+ *             <tr>
+ *                     <th> Attribute </th>
+ *                     <th> Type </th>
+ *                     <th> Value </th>
+ *             </tr>
+ *             <tr>
+ *                     <td> #CONTEXT_HISTORY_HOUR_OF_DAY </td>
+ *                     <td> integer </td>
+ *                     <td> Hour of day value(0~24) based on local time </td>
+ *             </tr>
+ *             <tr>
+ *                     <td> #CONTEXT_HISTORY_TOTAL_COUNT </td>
+ *                     <td> integer </td>
+ *                     <td> Event count </td>
+ *             </tr>
+ *             </table> @n
+ *     <li>#CONTEXT_HISTORY_PEAK_TIME_FOR_MUSIC @n
+ *             Description : Returns peak time of listening music list in hour sorted by used time in descending order. @n
+ *             Required privilege : <em> http://tizen.org/privilege/mediahistory.read </em> @n
+ *             <table>
+ *             <caption> Table: Filters</caption>
+ *             <tr>
+ *                     <th> Filter </th>
+ *                     <th> Type </th>
+ *                     <th> Value </th>
+ *                     <th> Mandatory </th>
+ *             </tr>
+ *             <tr>
+ *                     <td> #CONTEXT_HISTORY_FILTER_TIME_SPAN </td>
+ *                     <td> integer </td>
+ *                     <td> Time span of data in days from today ( 1 ~ 90 ) </td>
+ *                     <td> O </td>
+ *             </tr>
+ *             <tr>
+ *                     <td> #CONTEXT_HISTORY_FILTER_RESULT_SIZE </td>
+ *                     <td> integer </td>
+ *                     <td> Result size of data set ( 1 ~ 50 ) </td>
+ *                     <td> O </td>
+ *             </tr>
+ *             <tr>
+ *                     <td> #CONTEXT_HISTORY_FILTER_START_TIME </td>
+ *                     <td> integer </td>
+ *                     <td> Start time in epoch time to load only data which is inserted after the specific time</td>
+ *                     <td> X </td>
+ *             </tr>
+ *             <tr>
+ *                     <td> #CONTEXT_HISTORY_FILTER_END_TIME </td>
+ *                     <td> integer </td>
+ *                     <td> End time in epoch time to load only data which is inserted before the specific time</td>
+ *                     <td> X </td>
+ *             </tr>
+ *             <tr>
+ *                     <td> #CONTEXT_HISTORY_FILTER_APP_ID </td>
+ *                     <td> string </td>
+ *                     <td> The player application's id to filter</td>
+ *                     <td> X </td>
+ *             </tr>
+ *             <tr>
+ *                     <td> #CONTEXT_HISTORY_FILTER_DAY_OF_WEEK </td>
+ *                     <td> integer </td>
+ *                     <td> Weekdays or weekends #context_history_filter_day_of_week_e </td>
+ *                     <td> X (Default : All days) </td>
+ *             </tr>
+ *             </table>
+ *             <table>
+ *             <caption> Table: Attributes</caption>
+ *             <tr>
+ *                     <th> Attribute </th>
+ *                     <th> Type </th>
+ *                     <th> Value </th>
+ *             </tr>
+ *             <tr>
+ *                     <td> #CONTEXT_HISTORY_HOUR_OF_DAY </td>
+ *                     <td> integer </td>
+ *                     <td> Hour of day value(0~24) based on local time </td>
+ *             </tr>
+ *             <tr>
+ *                     <td> #CONTEXT_HISTORY_TOTAL_COUNT </td>
+ *                     <td> integer </td>
+ *                     <td> Event count </td>
+ *             </tr>
+ *             </table> @n
+ *     <li>#CONTEXT_HISTORY_PEAK_TIME_FOR_VIDEO @n
+ *             Description : Returns peak time of watching video list in hour sorted by used time in descending order. @n
+ *             Required privilege : <em> http://tizen.org/privilege/mediahistory.read </em> @n
+ *             <table>
+ *             <caption> Table: Filters</caption>
+ *             <tr>
+ *                     <th> Filter </th>
+ *                     <th> Type </th>
+ *                     <th> Value </th>
+ *                     <th> Mandatory </th>
+ *             </tr>
+ *             <tr>
+ *                     <td> #CONTEXT_HISTORY_FILTER_TIME_SPAN </td>
+ *                     <td> integer </td>
+ *                     <td> Time span of data in days from today ( 1 ~ 90 ) </td>
+ *                     <td> O </td>
+ *             </tr>
+ *             <tr>
+ *                     <td> #CONTEXT_HISTORY_FILTER_RESULT_SIZE </td>
+ *                     <td> integer </td>
+ *                     <td> Result size of data set ( 1 ~ 50 ) </td>
+ *                     <td> O </td>
+ *             </tr>
+ *             <tr>
+ *                     <td> #CONTEXT_HISTORY_FILTER_START_TIME </td>
+ *                     <td> integer </td>
+ *                     <td> Start time in epoch time to load only data which is inserted after the specific time</td>
+ *                     <td> X </td>
+ *             </tr>
+ *             <tr>
+ *                     <td> #CONTEXT_HISTORY_FILTER_END_TIME </td>
+ *                     <td> integer </td>
+ *                     <td> End time in epoch time to load only data which is inserted before the specific time</td>
+ *                     <td> X </td>
+ *             </tr>
+ *             <tr>
+ *                     <td> #CONTEXT_HISTORY_FILTER_APP_ID </td>
+ *                     <td> string </td>
+ *                     <td> The player application's id to filter</td>
+ *                     <td> X </td>
+ *             </tr>
+ *             <tr>
+ *                     <td> #CONTEXT_HISTORY_FILTER_DAY_OF_WEEK </td>
+ *                     <td> integer </td>
+ *                     <td> Weekdays or weekends #context_history_filter_day_of_week_e </td>
+ *                     <td> X (Default : All days) </td>
+ *             </tr>
+ *             </table>
+ *             <table>
+ *             <caption> Table: Attributes</caption>
+ *             <tr>
+ *                     <th> Attribute </th>
+ *                     <th> Type </th>
+ *                     <th> Value </th>
+ *             </tr>
+ *             <tr>
+ *                     <td> #CONTEXT_HISTORY_HOUR_OF_DAY </td>
+ *                     <td> integer </td>
+ *                     <td> Hour of day value(0~24) based on local time </td>
+ *             </tr>
+ *             <tr>
+ *                     <td> #CONTEXT_HISTORY_TOTAL_COUNT </td>
+ *                     <td> integer </td>
+ *                     <td> Event count </td>
+ *             </tr>
+ *             </table> @n
+ *     <li>#CONTEXT_HISTORY_COMMON_SETTING_FOR_APP @n
+ *             Description : Returns the most common setting value of application use. This returns always 1 row of record@n
+ *             Required privilege : <em> http://tizen.org/privilege/apphistory.read </em> @n
+ *             <table>
+ *             <caption> Table: Filters</caption>
+ *             <tr>
+ *                     <th> Filter </th>
+ *                     <th> Type </th>
+ *                     <th> Value </th>
+ *                     <th> Mandatory </th>
+ *             </tr>
+ *             <tr>
+ *                     <td> #CONTEXT_HISTORY_FILTER_TIME_SPAN </td>
+ *                     <td> integer </td>
+ *                     <td> Time span of data in days from today ( 1 ~ 90 ) </td>
+ *                     <td> O </td>
+ *             </tr>
+ *             <tr>
+ *                     <td> #CONTEXT_HISTORY_FILTER_START_TIME </td>
+ *                     <td> integer </td>
+ *                     <td> Start time in epoch time to load only data which is inserted after the specific time</td>
+ *                     <td> X </td>
+ *             </tr>
+ *             <tr>
+ *                     <td> #CONTEXT_HISTORY_FILTER_END_TIME </td>
+ *                     <td> integer </td>
+ *                     <td> End time in epoch time to load only data which is inserted before the specific time</td>
+ *                     <td> X </td>
+ *             </tr>
+ *             <tr>
+ *                     <td> #CONTEXT_HISTORY_FILTER_APP_ID </td>
+ *                     <td> string </td>
+ *                     <td> Application id to filter</td>
+ *                     <td> X (Default : All applications) </td>
+ *             </tr>
+ *             </table>
+ *             <table>
+ *             <caption> Table: Attributes</caption>
+ *             <tr>
+ *                     <th> Attribute </th>
+ *                     <th> Type </th>
+ *                     <th> Value </th>
+ *             </tr>
+ *             <tr>
+ *                     <td> #CONTEXT_HISTORY_AUDIO_JACK </td>
+ *                     <td> integer </td>
+ *                     <td> The most common value of audio jack status </td>
+ *             </tr>
+ *             <tr>
+ *                     <td> #CONTEXT_HISTORY_SYSTEM_VOLUME </td>
+ *                     <td> integer </td>
+ *                     <td> The most common value of system volume  </td>
+ *             </tr>
+ *             <tr>
+ *                     <td> #CONTEXT_HISTORY_MEDIA_VOLUME </td>
+ *                     <td> integer </td>
+ *                     <td> The most common value of media volume </td>
+ *             </tr>
+ *             </table> @n
+ *     <li>#CONTEXT_HISTORY_COMMON_SETTING_FOR_MUSIC @n
+ *             Description : Returns the most common setting value of music playing. This returns always 1 row of record@n
+ *             Required privilege : <em> http://tizen.org/privilege/mediahistory.read </em> @n
+ *             <table>
+ *             <caption> Table: Filters</caption>
+ *             <tr>
+ *                     <th> Filter </th>
+ *                     <th> Type </th>
+ *                     <th> Value </th>
+ *                     <th> Mandatory </th>
+ *             </tr>
+ *             <tr>
+ *                     <td> #CONTEXT_HISTORY_FILTER_TIME_SPAN </td>
+ *                     <td> integer </td>
+ *                     <td> Time span of data in days from today ( 1 ~ 90 ) </td>
+ *                     <td> O </th>
+ *             </tr>
+ *             <tr>
+ *                     <td> #CONTEXT_HISTORY_FILTER_START_TIME </td>
+ *                     <td> integer </td>
+ *                     <td> Start time in epoch time to load only data which is inserted after the specific time</td>
+ *                     <td> X </td>
+ *             </tr>
+ *             <tr>
+ *                     <td> #CONTEXT_HISTORY_FILTER_END_TIME </td>
+ *                     <td> integer </td>
+ *                     <td> End time in epoch time to load only data which is inserted before the specific time</td>
+ *                     <td> X </td>
+ *             </tr>
+ *             <tr>
+ *                     <td> #CONTEXT_HISTORY_FILTER_APP_ID </td>
+ *                     <td> string </td>
+ *                     <td> Application id to filter</td>
+ *                     <td> X (Default : All applications) </td>
+ *             </tr>
+ *             </table>
+ *             <table>
+ *             <caption> Table: Attributes</caption>
+ *             <tr>
+ *                     <th> Attribute </th>
+ *                     <th> Type </th>
+ *                     <th> Value </th>
+ *             </tr>
+ *             <tr>
+ *                     <td> #CONTEXT_HISTORY_AUDIO_JACK </td>
+ *                     <td> integer </td>
+ *                     <td> The most common value of audio jack status </td>
+ *             </tr>
+ *             <tr>
+ *                     <td> #CONTEXT_HISTORY_SYSTEM_VOLUME </td>
+ *                     <td> integer </td>
+ *                     <td> The most common value of system volume  </td>
+ *             </tr>
+ *             <tr>
+ *                     <td> #CONTEXT_HISTORY_MEDIA_VOLUME </td>
+ *                     <td> integer </td>
+ *                     <td> The most common value of media volume </td>
+ *             </tr>
+ *             </table> @n
+ *     <li>#CONTEXT_HISTORY_COMMON_SETTING_FOR_VIDEO @n
+ *             Description : Returns the most common setting value of video watching. This returns always 1 row of record@n
+ *             Required privilege : <em> http://tizen.org/privilege/mediahistory.read </em> @n
+ *             <table>
+ *             <caption> Table: Filters</caption>
+ *             <tr>
+ *                     <th> Filter </th>
+ *                     <th> Type </th>
+ *                     <th> Value </th>
+ *                     <th> Mandatory </th>
+ *             </tr>
+ *             <tr>
+ *                     <td> #CONTEXT_HISTORY_FILTER_TIME_SPAN </td>
+ *                     <td> integer </td>
+ *                     <td> Time span of data in days from today ( 1 ~ 90 ) </td>
+ *                     <td> O </td>
+ *             </tr>
+ *             <tr>
+ *                     <td> #CONTEXT_HISTORY_FILTER_START_TIME </td>
+ *                     <td> integer </td>
+ *                     <td> Start time in epoch time to load only data which is inserted after the specific time</td>
+ *                     <td> X </td>
+ *             </tr>
+ *             <tr>
+ *                     <td> #CONTEXT_HISTORY_FILTER_END_TIME </td>
+ *                     <td> integer </td>
+ *                     <td> End time in epoch time to load only data which is inserted before the specific time</td>
+ *                     <td> X </td>
+ *             </tr>
+ *             <tr>
+ *                     <td> #CONTEXT_HISTORY_FILTER_APP_ID </td>
+ *                     <td> string </td>
+ *                     <td> Application id to filter</td>
+  *                    <td> X (Default : All applications) </td>
+ *             </tr>
+ *             </table>
+ *             <table>
+ *             <caption> Table: Attributes</caption>
+ *             <tr>
+ *                     <th> Attribute </th>
+ *                     <th> Type </th>
+ *                     <th> Value </th>
+ *             </tr>
+ *             <tr>
+ *                     <td> #CONTEXT_HISTORY_AUDIO_JACK </td>
+ *                     <td> integer </td>
+ *                     <td> The most common value of audio jack status </td>
+ *             </tr>
+ *             <tr>
+ *                     <td> #CONTEXT_HISTORY_SYSTEM_VOLUME </td>
+ *                     <td> integer </td>
+ *                     <td> The most common value of system volume  </td>
+ *             </tr>
+ *             <tr>
+ *                     <td> #CONTEXT_HISTORY_MEDIA_VOLUME </td>
+ *                     <td> integer </td>
+ *                     <td> The most common value of media volume </td>
+ *             </tr>
+ *             </table> @n
+ *     <li>#CONTEXT_HISTORY_FREQUENTLY_COMMUNICATED_ADDRESS @n
+ *             Description : Returns frequently communicated address list sorted by communicated count in descending order. @n
+ *             Required privilege : <em> http://tizen.org/privilege/callhistory.read </em> @n
+ *             <table>
+ *             <caption> Table: Filters</caption>
+ *             <tr>
+ *                     <th> Filter </th>
+ *                     <th> Type </th>
+ *                     <th> Value </th>
+ *                     <th> Mandatory </th>
+ *             </tr>
+ *             <tr>
+ *                     <td> #CONTEXT_HISTORY_FILTER_TIME_SPAN </td>
+ *                     <td> integer </td>
+ *                     <td> Time span of data in days from today ( 1 ~ 90 ) </td>
+ *                     <td> O </td>
+ *             </tr>
+ *             <tr>
+ *                     <td> #CONTEXT_HISTORY_FILTER_RESULT_SIZE </td>
+ *                     <td> integer </td>
+ *                     <td> Result size of data set ( 1 ~ 50 ) </td>
+ *                     <td> O </td>
+ *             </tr>
+ *             <tr>
+ *                     <td> #CONTEXT_HISTORY_FILTER_START_TIME </td>
+ *                     <td> integer </td>
+ *                     <td> Start time in epoch time to load only data which is inserted after the specific time</td>
+ *                     <td> X </td>
+ *             </tr>
+ *             <tr>
+ *                     <td> #CONTEXT_HISTORY_FILTER_END_TIME </td>
+ *                     <td> integer </td>
+ *                     <td> End time in epoch time to load only data which is inserted before the specific time</td>
+ *                     <td> X </td>
+ *             </tr>
+ *             <tr>
+ *                     <td> #CONTEXT_HISTORY_FILTER_COMMUNICATION_TYPE </td>
+ *                     <td> integer </td>
+ *                     <td> Call or message logs #context_history_filter_communication_type_e </td>
+ *                     <td> X </td>
+ *             </tr>
+ *             </table>
+ *             <table>
+ *             <caption> Table: Attributes</caption>
+ *             <tr>
+ *                     <th> Attribute </th>
+ *                     <th> Type </th>
+ *                     <th> Value </th>
+ *             </tr>
+ *             <tr>
+ *                     <td> #CONTEXT_HISTORY_ADDRESS </td>
+ *                     <td> string </td>
+ *                     <td> Address </td>
+ *             </tr>
+ *             <tr>
+ *                     <td> #CONTEXT_HISTORY_TOTAL_COUNT </td>
+ *                     <td> integer </td>
+ *                     <td> Total communication count </td>
+ *             </tr>
+ *             <tr>
+ *                     <td> #CONTEXT_HISTORY_TOTAL_DURATION </td>
+ *                     <td> integer </td>
+ *                     <td> Total communication duration </td>
+ *             </tr>
+ *             <tr>
+ *                     <td> #CONTEXT_HISTORY_LAST_TIME </td>
+ *                     <td> integer </td>
+ *                     <td> Last communication time in epoch time </td>
+ *             </tr>
+ *             </table> @n
+ *</ul>
+ *
+ *Sample code: @n
+ *the code below creates a handle and reads the data from contextual history engine.
+
+ \code
+// create a handle
+context_history_h handle = NULL;
+context_history_create(&handle);
+
+// create a filter
+context_history_filter_h filter;
+context_history_filter_create(&filter);
+
+// set filter values
+context_history_filter_set_int(filter, CONTEXT_HISTORY_FILTER_TIME_SPAN, 30);
+context_history_filter_set_int(filter, CONTEXT_HISTORY_FILTER_RESULT_SIZE, 5);
+context_history_filter_set_string(filter, CONTEXT_HISTORY_FILTER_APP_ID, "org.tizen.music");
+
+// set start and end time to query only data from 6:00 to 12:00
+
+i18n_ucalendar_h ucal = NULL;
+char *loc_default = NULL;
+i18n_udate time;
+int start_time_in_sec, end_time_in_sec;
+
+i18n_ulocale_get_default((const char **)&loc_default);
+i18n_ucalendar_create(NULL, -1, loc_default, I18N_UCALENDAR_GREGORIAN, &ucal);
+
+i18n_ucalendar_set(ucal, I18N_UCALENDAR_HOUR_OF_DAY, 6);
+i18n_ucalendar_set(ucal, I18N_UCALENDAR_MINUTE, 0);
+i18n_ucalendar_set(ucal, I18N_UCALENDAR_SECOND, 0);
+i18n_ucalendar_set(ucal, I18N_UCALENDAR_MILLISECOND, 0);
+i18n_ucalendar_get_milliseconds(ucal, &time);
+start_time_in_sec = time/1000;
+
+i18n_ucalendar_add(ucal, I18N_UCALENDAR_HOUR_OF_DAY, 6);
+i18n_ucalendar_get_milliseconds(ucal, &time);
+end_time_in_sec = time/1000;
+
+i18n_ucalendar_destroy(ucal);
+
+context_history_filter_set_int(filter, CONTEXT_HISTORY_FILTER_START_TIME, start_time_in_sec);
+context_history_filter_set_int(filter, CONTEXT_HISTORY_FILTER_END_TIME, end_time_in_sec);
+
+context_history_list_h list = NULL;
+
+// read data from contextual history engine
+context_history_get_list(handle, CONTEXT_HISTORY_COMMON_SETTING_FOR_APP, filter, &list);
+
+int size = 0;
+int media_volume;
+int audio_jack;
+context_history_list_get_count(list, &size);
+
+context_history_record_h record = NULL;
+
+// get current record
+context_history_list_get_current(list, &record);
+
+// get attributes
+context_history_record_get_int(record, CONTEXT_HISTORY_MEDIA_VOLUME, &media_volume);
+context_history_record_get_int(record, CONTEXT_HISTORY_AUDIO_JACK, &audio_jack);
+
+context_history_record_destroy(record);
+
+// to next position of the list
+context_history_list_move_next(list);
+
+// ...
+
+// destroy
+context_history_list_destroy(list);
+context_history_destroy(handle);
+context_history_filter_destroy(filter);
+ \endcode
+
+ * @internal
+ * <h2>To insert contextual event data to contextual history database</h2>
+ * The application can insert contextual event data into the contextual history database when a meaningful user event is generated.
+ * An <i>event data</i> usually contains a set of information regarding user's activities.
+ * It is used by contextual history engine to analyze user's behavioral patterns or characteristics. Each event type has different attributes and requires different privileges.@n
+ * The following is the list of event type can be used. An enumeration type is defined to #context_history_event_e.
+ *
+ *<ul>
+ *     <li>#CONTEXT_HISTORY_START_MUSIC @n
+ *             Description : The user started to listen to music. @n
+ *             Required privilege : <em> http://tizen.org/privilege/mediahistory.admin </em> @n
+ *             <table>
+ *             <caption> Table: Attributes</caption>
+ *             <tr>
+ *                     <th> Attribute </th>
+ *                     <th> Type </th>
+ *                     <th> Value </th>
+ *             </tr>
+ *             <tr>
+ *                     <td> #CONTEXT_HISTORY_URI </td>
+ *                     <td> string </td>
+ *                     <td> Uri of media file </td>
+ *             </tr>
+ *             <tr>
+ *                     <td> #CONTEXT_HISTORY_APP_ID </td>
+ *                     <td> string </td>
+ *                     <td> Application id that inserted event data </td>
+ *             </tr>
+ *             <tr>
+ *                     <td> #CONTEXT_HISTORY_LAST_POSITION </td>
+ *                     <td> integer </td>
+ *                     <td> The last played position of media file </td>
+ *             </tr>
+ *             </table> @n
+ *     <li>#CONTEXT_HISTORY_STOP_MUSIC @n
+ *             Description : The user stopped to listen to music. @n
+ *             Required privilege : <em> http://tizen.org/privilege/mediahistory.admin </em> @n
+ *             <table>
+ *             <caption> Table: Attributes</caption>
+ *             <tr>
+ *                     <th> Attribute </th>
+ *                     <th> Type </th>
+ *                     <th> Value </th>
+ *             </tr>
+ *             <tr>
+ *                     <td> #CONTEXT_HISTORY_URI </td>
+ *                     <td> string </td>
+ *                     <td> Uri of media file </td>
+ *             </tr>
+ *             <tr>
+ *                     <td> #CONTEXT_HISTORY_APP_ID </td>
+ *                     <td> string </td>
+ *                     <td> Application id that inserted event data </td>
+ *             </tr>
+ *             <tr>
+ *                     <td> #CONTEXT_HISTORY_LAST_POSITION </td>
+ *                     <td> integer </td>
+ *                     <td> The last played position of media file </td>
+ *             </tr>
+ *             </table> @n
+ *     <li>#CONTEXT_HISTORY_START_VIDEO @n
+ *             Description : The user started to watch a video. @n
+ *             Required privilege : <em> http://tizen.org/privilege/mediahistory.admin </em> @n
+ *             <table>
+ *             <caption> Table: Attributes</caption>
+ *             <tr>
+ *                     <th> Attribute </th>
+ *                     <th> Type </th>
+ *                     <th> Value </th>
+ *             </tr>
+ *             <tr>
+ *                     <td> #CONTEXT_HISTORY_URI </td>
+ *                     <td> string </td>
+ *                     <td> Uri of media file </td>
+ *             </tr>
+ *             <tr>
+ *                     <td> #CONTEXT_HISTORY_APP_ID </td>
+ *                     <td> string </td>
+ *                     <td> Application id that inserted event data </td>
+ *             </tr>
+ *             <tr>
+ *                     <td> #CONTEXT_HISTORY_LAST_POSITION </td>
+ *                     <td> integer </td>
+ *                     <td> The last played position of media file </td>
+ *             </tr>
+ *             </table> @n
+ *     <li>#CONTEXT_HISTORY_STOP_VIDEO @n
+ *             Description : The user stopped to watch the video. @n
+ *             Required privilege : <em> http://tizen.org/privilege/mediahistory.admin </em> @n
+ *             <table>
+ *             <caption> Table: Attributes</caption>
+ *             <tr>
+ *                     <th> Attribute </th>
+ *                     <th> Type </th>
+ *                     <th> Value </th>
+ *             </tr>
+ *             <tr>
+ *                     <td> #CONTEXT_HISTORY_URI </td>
+ *                     <td> string </td>
+ *                     <td> Uri of media file </td>
+ *             </tr>
+ *             <tr>
+ *                     <td> #CONTEXT_HISTORY_APP_ID </td>
+ *                     <td> string </td>
+ *                     <td> Application id that inserted event data </td>
+ *             </tr>
+ *             <tr>
+ *                     <td> #CONTEXT_HISTORY_LAST_POSITION </td>
+ *                     <td> integer </td>
+ *                     <td> The last played position of media file </td>
+ *             </tr>
+ *             </table> @n
+ *</ul>
+ *
+ *Sample code: @n
+ *the code below creates a record and inserts it into contextual history engine.
+
+
+ \code
+// create a record
+context_history_record_h record = NULL;
+context_history_record_create(&record);
+
+// set attributes to the record
+context_history_record_set_string(record, "Uri", media_info->uri);
+context_history_record_set_int(record, "LastPosition", media_info->last_position);
+
+// insert record to contextual history
+context_history_record_insert(record, CONTEXT_HISTORY_START_MUSIC);
+
+// destroy
+context_history_record_destroy(record);
+ \endcode
+
+ */
diff --git a/doc/context_trigger_doc.h b/doc/context_trigger_doc.h
new file mode 100644 (file)
index 0000000..5ed94ec
--- /dev/null
@@ -0,0 +1,495 @@
+/*
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * @ingroup            CAPI_CONTEXT_FRAMEWORK
+ * @defgroup   CAPI_CONTEXT_TRIGGER_MODULE Contextual Trigger
+ *
+ * @brief              The contextual trigger API provides a way to define rules,
+ *                             each of which can trigger a specified action when the rule is satisfied.
+ *
+ * @section            CAPI_CONTEXT_TRIGGER_MODULE_HEADER Required Header
+ *                             \#include <context_trigger.h>
+ *
+ * @section            CAPI_CONTEXT_TRIGGER_MODULE_OVERVIEW Overview
+ *
+ * The contextual trigger API provides a way to define trigger rules,
+ * each of which launches an application or posts a notification if it is satisfied.
+ *
+ * @subsection CAPI_CONTEXT_TRIGGER_MODULE_CODE_EXAMPLE Trigger Rule Creation and Activation
+ *
+ * To use this API, an application first needs to assemble a @em rule,
+ * which consists of the following three components:
+ *
+ <ol>
+       <li><b>An Event</b>:
+               The contextual trigger engine starts to verify if the rule is satisfied, when the event occurs.
+               As the name suggests, it is literally an event that can be recognized in the device,
+               e.g., changes of setting values or connections of peripherals.
+               See #context_trigger_event_e for all available event items.
+       <li><b>A Set of Conditions</b>:
+               If the event occurs, the trigger engine checks whether the conditions are satisfied or not.
+               The application can choose the way of combining conditions, i.e., logical conjunction or disjunction.
+               In case of logical conjunction, for example, the set of conditions is @c true if and only if
+               all conditions are @c true.
+               If no condition is set, i.e., the set of conditions is empty, the trigger engine
+               considers the set is satisfied, regardless of the current context.
+               See #context_trigger_condition_e for all available condition items.
+       <li><b>An Action</b>: If the conditions are satisfied, a designated action will be triggered.
+               The action can be an app launching request or a notification posting request.
+ </ol>
+ *
+ * As a case study, the below example code illustrates how to create and activate a rule,
+ * which can be described as
+ * "Notify if the battery is not charged enough and currently not charing,
+ * at 10 and 11 PM" in human language.
+
+ \code
+       // Creating a rule handle
+       context_trigger_rule_h rule = NULL;
+       context_trigger_rule_create(CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, &rule);
+
+       // Creating an event
+       context_trigger_rule_entry_h event = NULL;
+       context_trigger_rule_event_create(CONTEXT_TRIGGER_EVENT_ON_TIME,
+                       CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, &event);
+       context_trigger_rule_entry_add_key(event,
+                       CONTEXT_TRIGGER_LOGICAL_DISJUNCTION, CONTEXT_TRIGGER_TIME_OF_DAY);
+       context_trigger_rule_entry_add_comparison_int(event,
+                       CONTEXT_TRIGGER_TIME_OF_DAY, CONTEXT_TRIGGER_EQUAL_TO, 22);
+       context_trigger_rule_entry_add_comparison_int(event,
+                       CONTEXT_TRIGGER_TIME_OF_DAY, CONTEXT_TRIGGER_EQUAL_TO, 23);
+
+       // Adding the event to the rule and releasing the resource occupied.
+       context_trigger_rule_add_entry(rule, event);
+       context_trigger_rule_entry_destroy(event);
+ \endcode
+
+ * While creating a rule handle, the application chooses the logical operator,
+ * <em>logical conjunction</em> or <em>disjunction</em>,
+ * which will be applied to the conditions.@n
+ * Then some logical conditions can be added to the rule.
+ * Note that, adding conditions are not mandatory.
+
+ \code
+       // Creating a condition
+       context_trigger_rule_entry_h condition = NULL;
+       context_trigger_rule_condition_create(CONTEXT_TRIGGER_CONDITION_BATTERY,
+                       CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, &condition);
+       context_trigger_rule_entry_add_key(condition,
+                       CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, CONTEXT_TRIGGER_LEVEL);
+       context_trigger_rule_entry_add_comparison_string(condition,
+                       CONTEXT_TRIGGER_LEVEL, CONTEXT_TRIGGER_NOT_EQUAL_TO, CONTEXT_TRIGGER_FULL);
+       context_trigger_rule_entry_add_comparison_string(condition,
+                       CONTEXT_TRIGGER_LEVEL, CONTEXT_TRIGGER_NOT_EQUAL_TO, CONTEXT_TRIGGER_HIGH);
+       context_trigger_rule_entry_add_key(condition,
+                       CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, CONTEXT_TRIGGER_IS_CHARGING);
+       context_trigger_rule_entry_add_comparison_int(condition,
+                       CONTEXT_TRIGGER_IS_CHARGING, CONTEXT_TRIGGER_EQUAL_TO, CONTEXT_TRIGGER_FALSE);
+
+       // Adding the condition to the handle
+       context_trigger_rule_add_entry(rule, condition);
+       context_trigger_rule_entry_destroy(condition);
+ \endcode
+
+ * A app launching request or a notification posting request is set as the action,
+ * which will be triggered if the rule is satisfied.
+ * The below example shows how to register a notification posting request.
+
+ \code
+       // Setting a notification posting request
+       context_trigger_rule_set_action_notification(rule, "Battery Alert", "Charge your battery please.", NULL, NULL);
+ \endcode
+
+ * An app launching request is created and manipulated by the app control API.
+ * Please refer to the app control API for more details.@n
+ * Regarding the notification posting request, this API supports the very basic
+ * form of notifications only. To create a more sophisticated notification,
+ * the application needs to implement a service application that posts the notification.@n
+ * After creating a rule, to activate it, the rule needs to be registered and enabled explicitly.
+
+ \code
+       // Adding the rule to the engine
+       int rule_id;
+       context_trigger_add_rule(rule, &rule_id);
+
+       // Enabling the rule
+       context_trigger_enable_rule(rule_id)
+ \endcode
+
+ * Note that, a rule only can be managed by the application that has registered the rule.
+ *
+ * If the rule is not required anymore, it can be disabled and removed from the engine.
+ * Note that, rule activation, deactivation, and removals are only allowed to the
+ * owner application, which has registered the rule to the trigger engine.
+ * In the below example, the application queries its own rule IDs,
+ * deactivates enabled rules, and removes all rules from the trigger engine.
+
+ \code
+       context_trigger_disable_rule(rule_id)
+       context_trigger_remove_rule(rule_id);
+ \endcode
+
+ *
+ * @subsection CAPI_CONTEXT_TRIGGER_MODULE_DATA_FORMAT Supported Attribute Keys and Comparison Operators
+ *
+ * Each event or condition item may support different types of attribute keys,
+ * which are used as left operands of comparison operations.
+ * The supported attribute keys, their types, and acceptable values are summarized in the table below.
+ *
+
+<table>
+       <caption>Table: Supported Attribute Keys</caption>
+       <tr>
+               <th>Event/Condition</th>
+               <th>Attribute Key</th>
+               <th>Type</th>
+               <th>Acceptable Values</th>
+       </tr>
+       <tr>
+               <td rowspan=2>#CONTEXT_TRIGGER_EVENT_ON_TIME</td>
+               <td>#CONTEXT_TRIGGER_TIME_OF_DAY</td>
+               <td>Integer</td>
+               <td>From 0 to 23 (hour)</td>
+       </tr>
+       <tr>
+               <td>#CONTEXT_TRIGGER_DAY_OF_WEEK</td>
+               <td>String</td>
+               <td>
+                       #CONTEXT_TRIGGER_MON,<br>
+                       #CONTEXT_TRIGGER_TUE,<br>
+                       #CONTEXT_TRIGGER_WED,<br>
+                       #CONTEXT_TRIGGER_THU,<br>
+                       #CONTEXT_TRIGGER_FRI,<br>
+                       #CONTEXT_TRIGGER_SAT,<br>
+                       #CONTEXT_TRIGGER_SUN
+               </td>
+       </tr>
+       <tr>
+               <td>#CONTEXT_TRIGGER_CONDITION_TIME_OF_DAY</td>
+               <td>#CONTEXT_TRIGGER_TIME_OF_DAY</td>
+               <td>Integer</td>
+               <td>From 0 to 1439 (min)</td>
+       </tr>
+       <tr>
+               <td>#CONTEXT_TRIGGER_CONDITION_DAY_OF_WEEK</td>
+               <td>#CONTEXT_TRIGGER_DAY_OF_WEEK</td>
+               <td>String</td>
+               <td>
+                       #CONTEXT_TRIGGER_MON,<br>
+                       #CONTEXT_TRIGGER_TUE,<br>
+                       #CONTEXT_TRIGGER_WED,<br>
+                       #CONTEXT_TRIGGER_THU,<br>
+                       #CONTEXT_TRIGGER_FRI,<br>
+                       #CONTEXT_TRIGGER_SAT,<br>
+                       #CONTEXT_TRIGGER_SUN
+               </td>
+       </tr>
+       <tr>
+               <td>#CONTEXT_TRIGGER_CONDITION_DAY_OF_MONTH</td>
+               <td>#CONTEXT_TRIGGER_DAY_OF_MONTH</td>
+               <td>Integer</td>
+               <td>From 1 to 31</td>
+       </tr>
+       <tr>
+               <td>
+                       #CONTEXT_TRIGGER_EVENT_CHARGER<br>
+                       #CONTEXT_TRIGGER_EVENT_USB<br>
+                       #CONTEXT_TRIGGER_CONDITION_CHARGER<br>
+                       #CONTEXT_TRIGGER_CONDITION_USB
+               </td>
+               <td>#CONTEXT_TRIGGER_IS_CONNECTED</td>
+               <td>Integer</td>
+               <td>#CONTEXT_TRIGGER_TRUE,<br>#CONTEXT_TRIGGER_FALSE</td>
+       </tr>
+       <tr>
+               <td rowspan=2>
+                       #CONTEXT_TRIGGER_EVENT_BATTERY<br>
+                       #CONTEXT_TRIGGER_CONDITION_BATTERY
+               </td>
+               <td>#CONTEXT_TRIGGER_LEVEL</td>
+               <td>String</td>
+               <td>
+                       #CONTEXT_TRIGGER_EMPTY,<br>
+                       #CONTEXT_TRIGGER_CRITICAL,<br>
+                       #CONTEXT_TRIGGER_LOW,<br>
+                       #CONTEXT_TRIGGER_NORMAL,<br>
+                       #CONTEXT_TRIGGER_HIGH,<br>
+                       #CONTEXT_TRIGGER_FULL
+               </td>
+       </tr>
+       <tr>
+               <td>#CONTEXT_TRIGGER_IS_CHARGING</td>
+               <td>Integer</td>
+               <td>#CONTEXT_TRIGGER_TRUE,<br>#CONTEXT_TRIGGER_FALSE</td>
+       </tr>
+       <tr>
+               <td>
+                       #CONTEXT_TRIGGER_EVENT_FLIGHT_MODE<br>
+                       #CONTEXT_TRIGGER_EVENT_POWER_SAVING_MODE<br>
+                       #CONTEXT_TRIGGER_EVENT_SILENT_MODE<br>
+                       #CONTEXT_TRIGGER_EVENT_VIBRATION_MODE<br>
+                       #CONTEXT_TRIGGER_CONDITION_FLIGHT_MODE<br>
+                       #CONTEXT_TRIGGER_CONDITION_POWER_SAVING_MODE<br>
+                       #CONTEXT_TRIGGER_CONDITION_SILENT_MODE<br>
+                       #CONTEXT_TRIGGER_CONDITION_VIBRATION_MODE
+               </td>
+               <td>#CONTEXT_TRIGGER_IS_ENABLED</td>
+               <td>Integer</td>
+               <td>#CONTEXT_TRIGGER_TRUE,<br>#CONTEXT_TRIGGER_FALSE</td>
+       </tr>
+       <tr>
+               <td>
+                       #CONTEXT_TRIGGER_EVENT_GPS<br>
+                       #CONTEXT_TRIGGER_CONDITION_GPS
+               </td>
+               <td>#CONTEXT_TRIGGER_STATE</td>
+               <td>String</td>
+               <td>
+                       #CONTEXT_TRIGGER_DISABLED,<br>
+                       #CONTEXT_TRIGGER_SEARCHING,<br>
+                       #CONTEXT_TRIGGER_CONNECTED
+               </td>
+       </tr>
+       <tr>
+               <td rowspan=2>
+                       #CONTEXT_TRIGGER_EVENT_HEADPHONE<br>
+                       #CONTEXT_TRIGGER_CONDITION_HEADPHONE
+               </td>
+               <td>#CONTEXT_TRIGGER_IS_CONNECTED</td>
+               <td>Integer</td>
+               <td>#CONTEXT_TRIGGER_TRUE,<br>#CONTEXT_TRIGGER_FALSE</td>
+       </tr>
+       <tr>
+               <td>#CONTEXT_TRIGGER_TYPE</td>
+               <td>String</td>
+               <td>
+                       #CONTEXT_TRIGGER_NORMAL,<br>
+                       #CONTEXT_TRIGGER_HEADSET,<br>
+                       #CONTEXT_TRIGGER_BLUETOOTH
+               </td>
+       </tr>
+       <tr>
+               <td rowspan=2>
+                       #CONTEXT_TRIGGER_EVENT_WIFI<br>
+                       #CONTEXT_TRIGGER_CONDITION_WIFI
+               </td>
+               <td>#CONTEXT_TRIGGER_STATE</td>
+               <td>String</td>
+               <td>
+                       #CONTEXT_TRIGGER_DISABLED,<br>
+                       #CONTEXT_TRIGGER_CONNECTED,<br>
+                       #CONTEXT_TRIGGER_UNCONNECTED
+               </td>
+       </tr>
+       <tr>
+               <td>#CONTEXT_TRIGGER_BSSID</td>
+               <td>String</td>
+               <td>WiFi BSSID</td>
+       </tr>
+       <tr>
+               <td rowspan=3>
+                       #CONTEXT_TRIGGER_EVENT_CALL<br>
+                       #CONTEXT_TRIGGER_CONDITION_CALL
+               </td>
+               <td>#CONTEXT_TRIGGER_STATE</td>
+               <td>String</td>
+               <td>
+                       #CONTEXT_TRIGGER_IDLE,<br>
+                       #CONTEXT_TRIGGER_CONNECTING,<br>
+                       #CONTEXT_TRIGGER_CONNECTED
+               </td>
+       </tr>
+       <tr>
+               <td>#CONTEXT_TRIGGER_MEDIUM</td>
+               <td>String</td>
+               <td>#CONTEXT_TRIGGER_VOICE,<br>#CONTEXT_TRIGGER_VIDEO</td>
+       </tr>
+       <tr>
+               <td>#CONTEXT_TRIGGER_ADDRESS</td>
+               <td>String</td>
+               <td>Phone number</td>
+       </tr>
+       <tr>
+               <td>#CONTEXT_TRIGGER_EVENT_EMAIL</td>
+               <td>#CONTEXT_TRIGGER_EVENT</td>
+               <td>String</td>
+               <td>#CONTEXT_TRIGGER_RECEIVED,<br>#CONTEXT_TRIGGER_SENT</td>
+       </tr>
+       <tr>
+               <td rowspan=3>#CONTEXT_TRIGGER_EVENT_MESSAGE</td>
+               <td>#CONTEXT_TRIGGER_EVENT</td>
+               <td>String</td>
+               <td>#CONTEXT_TRIGGER_RECEIVED</td>
+       </tr>
+       <tr>
+               <td>#CONTEXT_TRIGGER_TYPE</td>
+               <td>String</td>
+               <td>#CONTEXT_TRIGGER_SMS,<br>#CONTEXT_TRIGGER_MMS</td>
+       </tr>
+       <tr>
+               <td>#CONTEXT_TRIGGER_ADDRESS</td>
+               <td>String</td>
+               <td>Phone number</td>
+       </tr>
+       <tr>
+               <td rowspan=2>
+                       #CONTEXT_TRIGGER_EVENT_ACTIVITY_STATIONARY,<br>
+                       #CONTEXT_TRIGGER_EVENT_ACTIVITY_WALKING,<br>
+                       #CONTEXT_TRIGGER_EVENT_ACTIVITY_RUNNING,<br>
+                       #CONTEXT_TRIGGER_EVENT_ACTIVITY_IN_VEHICLE
+               </td>
+               <td>#CONTEXT_TRIGGER_EVENT</td>
+               <td>String</td>
+               <td>#CONTEXT_TRIGGER_DETECTED</td>
+       </tr>
+       <tr>
+               <td>#CONTEXT_TRIGGER_ACCURACY</td>
+               <td>String</td>
+               <td>#CONTEXT_TRIGGER_HIGH,<br>#CONTEXT_TRIGGER_NORMAL,<br>#CONTEXT_TRIGGER_LOW</td>
+       </tr>
+       <tr>
+               <td>#CONTEXT_TRIGGER_EVENT_PLACE</td>
+               <td>#CONTEXT_TRIGGER_EVENT</td>
+               <td>String</td>
+               <td>#CONTEXT_TRIGGER_IN,<br>#CONTEXT_TRIGGER_OUT</td>
+       </tr>
+       <tr>
+               <td>
+                       #CONTEXT_TRIGGER_CONDITION_APP_USE_FREQUENCY,<br>
+                       #CONTEXT_TRIGGER_CONDITION_COMMUNICATION_FREQUENCY
+               </td>
+               <td>#CONTEXT_TRIGGER_RANK</td>
+               <td>Integer</td>
+               <td>Positive integer</td>
+       </tr>
+       <tr>
+               <td>
+                       #CONTEXT_TRIGGER_CONDITION_APP_USE_FREQUENCY,<br>
+                       #CONTEXT_TRIGGER_CONDITION_COMMUNICATION_FREQUENCY,<br>
+                       #CONTEXT_TRIGGER_CONDITION_MUSIC_PLAYBACK_FREQUENCY,<br>
+                       #CONTEXT_TRIGGER_CONDITION_VIDEO_PLAYBACK_FREQUENCY
+               </td>
+               <td>#CONTEXT_TRIGGER_TOTAL_COUNT</td>
+               <td>Integer</td>
+               <td>Nonnegative integer</td>
+       </tr>
+</table>
+
+ *
+ * For each type of attribute, as operators, the followings are allowed:
+ *
+
+<ul>
+       <li><i>For <b>integer</b> attributes</i>:<br>
+               #CONTEXT_TRIGGER_EQUAL_TO ("=="), #CONTEXT_TRIGGER_NOT_EQUAL_TO ("!="),<br>
+               #CONTEXT_TRIGGER_GREATER_THAN (">"), #CONTEXT_TRIGGER_GREATER_THAN_OR_EQUAL_TO (">="),<br>
+               #CONTEXT_TRIGGER_LESS_THAN ("<"), #CONTEXT_TRIGGER_LESS_THAN_OR_EQUAL_TO ("<=")
+       <li><i>For <b>string</b> attributes</i>:<br>
+               #CONTEXT_TRIGGER_EQUAL_TO ("=="), #CONTEXT_TRIGGER_NOT_EQUAL_TO ("!=")
+</ul>
+
+ *
+ * @subsection CAPI_CONTEXT_TRIGGER_MODULE_OPTION_FORMAT Supported Options Keys
+ *
+ * Certain events or conditions require to specify option values, which will be used
+ * to produce the output attribute values.
+ * For example, in case of #CONTEXT_TRIGGER_EVENT_PLACE,
+ * the target place id should be specified, by using context_trigger_rule_entry_add_option_int().
+ * The table below summarizes the supported option keys and acceptable values for each event or condition.
+ *
+
+<table>
+       <caption>Table: Supported Option Keys</caption>
+       <tr>
+               <th>Event/Condition</th>
+               <th>Option Key</th>
+               <th>Type</th>
+               <th>Acceptable Values</th>
+       </tr>
+       <tr>
+               <td>#CONTEXT_TRIGGER_EVENT_PLACE</td>
+               <td>#CONTEXT_TRIGGER_PLACE_ID</td>
+               <td>Integer</td>
+               <td>
+                       Place ID<br>
+                       See \ref CAPI_GEOFENCE_MANAGER_MODULE
+               </td>
+       </tr>
+       <tr>
+               <td>#CONTEXT_TRIGGER_CONDITION_APP_USE_FREQUENCY</td>
+               <td>#CONTEXT_TRIGGER_APP_ID</td>
+               <td>String</td>
+               <td>Application ID</td>
+       </tr>
+       <tr>
+               <td>#CONTEXT_TRIGGER_CONDITION_COMMUNICATION_FREQUENCY</td>
+               <td>#CONTEXT_TRIGGER_ADDRESS</td>
+               <td>String</td>
+               <td>Phone number</td>
+       </tr>
+       <tr>
+               <td rowspan=2>
+                       #CONTEXT_TRIGGER_CONDITION_APP_USE_FREQUENCY,<br>
+                       #CONTEXT_TRIGGER_CONDITION_COMMUNICATION_FREQUENCY,<br>
+                       #CONTEXT_TRIGGER_CONDITION_MUSIC_PLAYBACK_FREQUENCY,<br>
+                       #CONTEXT_TRIGGER_CONDITION_VIDEO_PLAYBACK_FREQUENCY
+               </td>
+               <td>#CONTEXT_TRIGGER_TIME_OF_DAY</td>
+               <td>String</td>
+               <td>
+                       Time interval of day, for example,<br>
+                       <b>"13-15"</b> denoting "from 1 PM to 3 PM".
+               </td>
+       </tr>
+       <tr>
+               <td>#CONTEXT_TRIGGER_DAY_OF_WEEK</td>
+               <td>String</td>
+               <td>
+                       #CONTEXT_TRIGGER_MON,<br>
+                       #CONTEXT_TRIGGER_TUE,<br>
+                       #CONTEXT_TRIGGER_WED,<br>
+                       #CONTEXT_TRIGGER_THU,<br>
+                       #CONTEXT_TRIGGER_FRI,<br>
+                       #CONTEXT_TRIGGER_SAT,<br>
+                       #CONTEXT_TRIGGER_SUN,<br>
+                       #CONTEXT_TRIGGER_WEEKDAY,<br>
+                       #CONTEXT_TRIGGER_WEEKEND
+               </td>
+       </tr>
+</table>
+
+ *
+ * @section CAPI_CONTEXT_TRIGGER_MODULE_FEATURE Related Features
+ *
+ * Some of the event and condition items in this API are related with one or the following features:@n
+ * - http://tizen.org/feature/network.telephony
+ * - http://tizen.org/feature/location.gps
+ * - http://tizen.org/feature/network.bluetooth
+ * - http://tizen.org/feature/network.wifi
+ *
+ * It is recommended to design feature related code in your application for reliability.@n
+ * For your convenience, context_trigger_rule_event_is_supported() and context_trigger_rule_condition_is_supported()
+ * are provided. Applications can use these functions to check the availability of a necessary event or condition,
+ * before registering a rule, to be sure that the rule is valid in the current device.
+ *
+ * In general, you can check if a device supports the related features for this API by using @ref CAPI_SYSTEM_SYSTEM_INFO_MODULE,
+ * thereby controlling the procedure of your application.
+ * To ensure your application is only running on the device with specific features,
+ * please define the features in your manifest file using the manifest editor in the SDK.
+ * More details on featuring your application can be found from
+ * <a href="../org.tizen.mobile.native.appprogramming/html/ide_sdk_tools/feature_element.htm"><b>Feature Element</b>.</a>
+ */
diff --git a/include/context_history.h b/include/context_history.h
new file mode 100644 (file)
index 0000000..74546a6
--- /dev/null
@@ -0,0 +1,543 @@
+/*
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ *
+ * 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_CONTEXT_HISTORY_H__
+#define __TIZEN_CONTEXT_HISTORY_H__
+
+
+#include <tizen_error.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif // __cplusplus
+
+/**
+ * @addtogroup CAPI_CONTEXT_HISTORY_MODULE
+ * @{
+ */
+
+/**
+ * @brief      The attribute key denoting "application id"
+ */
+#define CONTEXT_HISTORY_APP_ID "AppId"
+
+/**
+ * @brief      The attribute key denoting "total count"
+ */
+#define CONTEXT_HISTORY_TOTAL_COUNT "TotalCount"
+
+/**
+ * @brief      The attribute key denoting "total duration"
+ */
+#define CONTEXT_HISTORY_TOTAL_DURATION "TotalDuration"
+
+/**
+ * @brief      The attribute key denoting "last time"
+ */
+#define CONTEXT_HISTORY_LAST_TIME "LastTime"
+
+/**
+ * @brief      The attribute key denoting "hour of day"
+ */
+#define CONTEXT_HISTORY_HOUR_OF_DAY "HourOfDay"
+
+/**
+ * @brief      The attribute key denoting "audio jack status"
+ */
+#define CONTEXT_HISTORY_AUDIO_JACK "AudioJack"
+
+/**
+ * @brief      The attribute key denoting "system volume"
+ */
+#define CONTEXT_HISTORY_SYSTEM_VOLUME "SystemVolume"
+
+/**
+ * @brief      The attribute key denoting "media volume"
+ */
+#define CONTEXT_HISTORY_MEDIA_VOLUME "MediaVolume"
+
+/**
+ * @brief      The attribute key denoting "address"
+ */
+#define CONTEXT_HISTORY_ADDRESS "Address"
+
+/**
+ * @brief              Enumeration for errors.
+ * @since_tizen 2.4
+ */
+typedef enum {
+       CONTEXT_HISTORY_ERROR_NONE = TIZEN_ERROR_NONE,                                                  /**< Successful */
+       CONTEXT_HISTORY_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER,        /**< Invalid parameter */
+       CONTEXT_HISTORY_ERROR_PERMISSION_DENIED = TIZEN_ERROR_PERMISSION_DENIED,        /**< Permission denied */
+       CONTEXT_HISTORY_ERROR_NOT_SUPPORTED = TIZEN_ERROR_NOT_SUPPORTED,                        /**< Not supported */
+       CONTEXT_HISTORY_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY,                        /**< Memory allocation failed */
+       CONTEXT_HISTORY_ERROR_NO_DATA = TIZEN_ERROR_NO_DATA,                                            /**< No Data */
+       CONTEXT_HISTORY_ERROR_OUT_OF_RANGE = (TIZEN_ERROR_CONTEXT | 0x03),              /**< Out of range */
+       CONTEXT_HISTORY_ERROR_OPERATION_FAILED = (TIZEN_ERROR_CONTEXT | 0x04),  /**< Operation failed */
+} context_history_error_e;
+
+/**
+ * @brief              Enumeration for data types of statistics and patterns.
+ * @since_tizen 2.4
+ */
+typedef enum {
+       CONTEXT_HISTORY_RECENTLY_USED_APP = 1,  /**< Recently used application.@n Privilege : http://tizen.org/privilege/apphistory.read*/
+       CONTEXT_HISTORY_FREQUENTLY_USED_APP,    /**< Frequently used application.@n Privilege : http://tizen.org/privilege/apphistory.read*/
+       CONTEXT_HISTORY_RARELY_USED_APP,                /**< Rarely used application.@n Privilege : http://tizen.org/privilege/apphistory.read*/
+       CONTEXT_HISTORY_PEAK_TIME_FOR_APP,              /**< Peak time of application use activity.@n Privilege : http://tizen.org/privilege/apphistory.read*/
+       CONTEXT_HISTORY_PEAK_TIME_FOR_MUSIC,            /**< Peak time of music listening activity.@n Privilege : http://tizen.org/privilege/mediahistory.read*/
+       CONTEXT_HISTORY_PEAK_TIME_FOR_VIDEO,            /**< Peak time of video watching activity.@n Privilege : http://tizen.org/privilege/mediahistory.read*/
+       CONTEXT_HISTORY_COMMON_SETTING_FOR_APP,         /**< Common setting value of application use activity.@n Privilege : http://tizen.org/privilege/apphistory.read*/
+       CONTEXT_HISTORY_COMMON_SETTING_FOR_MUSIC,               /**< Common setting value of music listening activity.@n Privilege : http://tizen.org/privilege/mediahistory.read*/
+       CONTEXT_HISTORY_COMMON_SETTING_FOR_VIDEO,               /**< Common setting value of video watching activity.@n Privilege : http://tizen.org/privilege/mediahistory.read*/
+       CONTEXT_HISTORY_FREQUENTLY_COMMUNICATED_ADDRESS         /**< Frequently communicated address.@n Privilege : http://tizen.org/privilege/callhistory.read*/
+} context_history_data_e;
+
+/**
+ * @platform
+ * @brief              Enumeration for event types for logging.
+ * @since_tizen 2.4
+ */
+typedef enum {
+       CONTEXT_HISTORY_START_MUSIC = 1,        /**< @platform Start music event.@n Privilege : http://tizen.org/privilege/mediahistory.admin*/
+       CONTEXT_HISTORY_STOP_MUSIC,             /**< @platform Stop music event.@n Privilege : http://tizen.org/privilege/mediahistory.admin*/
+       CONTEXT_HISTORY_START_VIDEO,    /**< @platform Start video event.@n Privilege : http://tizen.org/privilege/mediahistory.admin*/
+       CONTEXT_HISTORY_STOP_VIDEO              /**< @platform Stop video event.@n Privilege : http://tizen.org/privilege/mediahistory.admin*/
+} context_history_event_e;
+
+/**
+ * @brief              Enumeration for filters of statistics and patterns.
+ * @since_tizen 2.4
+ */
+typedef enum {
+       CONTEXT_HISTORY_FILTER_TIME_SPAN = 1,           /**< Time span of data in days*/
+       CONTEXT_HISTORY_FILTER_RESULT_SIZE,                     /**< Result size of data records*/
+       CONTEXT_HISTORY_FILTER_APP_ID,                  /**< Application id*/
+       CONTEXT_HISTORY_FILTER_DAY_OF_WEEK,                     /**<  Weekdays, weekends*/
+       CONTEXT_HISTORY_FILTER_START_TIME,                      /**< Start time of data in epoch time*/
+       CONTEXT_HISTORY_FILTER_END_TIME,                        /**< End time of data in epoch time*/
+       CONTEXT_HISTORY_FILTER_WIFI_BSSID,                      /**< Wi-Fi BSSID value*/
+       CONTEXT_HISTORY_FILTER_AUDIO_JACK,                      /**< Audio jack status value*/
+       CONTEXT_HISTORY_FILTER_COMMUNICATION_TYPE                       /**< Type of phone log*/
+} context_history_filter_e;
+
+/**
+ * @brief              Enumeration for day of week filter.
+ * @since_tizen 2.4
+ */
+typedef enum {
+       CONTEXT_HISTORY_FILTER_DAY_OF_WEEK_WEEKDAYS = 1,                /**< Includes only weekdays*/
+       CONTEXT_HISTORY_FILTER_DAY_OF_WEEK_WEEKENDS,            /**< Includes only weekends*/
+       CONTEXT_HISTORY_FILTER_DAY_OF_WEEK_ALL                  /**< Includes all days*/
+} context_history_filter_day_of_week_e;
+
+/**
+ * @brief              Enumeration for audio jack filter.
+ * @since_tizen 2.4
+ */
+typedef enum {
+       CONTEXT_HISTORY_FILTER_AUDIO_JACK_NOT_CONNECTED = 0,            /**< Audio jack is not connected*/
+       CONTEXT_HISTORY_FILTER_AUDIO_JACK_CONNECTED                     /**< Audio jack is connected*/
+} context_history_filter_audio_jack_e;
+
+/**
+ * @brief              Enumeration for log type filter.
+ * @since_tizen 2.4
+ */
+typedef enum {
+       CONTEXT_HISTORY_FILTER_COMMUNICATION_TYPE_CALL = 1,             /**< Includes only call logs*/
+       CONTEXT_HISTORY_FILTER_COMMUNICATION_TYPE_MESSAGE,              /**< Includes only message logs*/
+       CONTEXT_HISTORY_FILTER_COMMUNICATION_TYPE_ALL                   /**< Includes all logs*/
+} context_history_filter_communication_type_e;
+
+/**
+ * @brief              Context history handle for retrieving statistics and patterns.
+ * @since_tizen 2.4
+ */
+typedef struct _context_history_handle_s* context_history_h;
+
+/**
+ * @brief              History filter handle to be used to compute statistics and patterns.
+ * @since_tizen 2.4
+ */
+typedef struct _context_history_filter_handle_s* context_history_filter_h;
+
+/**
+ * @brief              History list handle. It contains one or multiple records.
+ * @since_tizen 2.4
+ */
+typedef struct _context_history_list_handle_s* context_history_list_h;
+
+/**
+ * @brief              History record handle. It contains one or multiple attributes.
+ * @since_tizen 2.4
+ */
+typedef struct _context_history_record_handle_s* context_history_record_h;
+
+/**
+ * @brief              Creates a context history handle.
+ * @since_tizen 2.4
+ * @remarks            The @c handle must be released using context_history_destroy().
+ *
+ * @param[out] handle    Handle to be initialized
+ *
+ * @return             0 on success, otherwise a negative error value
+ * @retval             #CONTEXT_HISTORY_ERROR_NONE                                     Successful
+ * @retval             #CONTEXT_HISTORY_ERROR_INVALID_PARAMETER                Invalid parameter
+ * @retval             #CONTEXT_HISTORY_ERROR_OUT_OF_MEMORY                    Out of memory
+ *
+ * @see context_history_destroy()
+ */
+int context_history_create(context_history_h* handle);
+
+/**
+ * @brief              Releases the resources occupied by a handle.
+ * @details            This releases the memory allocated for the @c handle.
+ *
+ * @since_tizen 2.4
+ *
+ * @param[in]  handle   Handle to be released
+ *
+ * @return             0 on success, otherwise a negative error value
+ * @retval             #CONTEXT_HISTORY_ERROR_NONE                                     Successful
+ * @retval             #CONTEXT_HISTORY_ERROR_INVALID_PARAMETER                Invalid parameter
+ *
+ * @pre        context_history_create()
+ */
+int context_history_destroy(context_history_h handle);
+
+/**
+ * @brief              Creates a history filter.
+ * @since_tizen 2.4
+ * @remarks            The @c filter must be released using context_history_filter_destroy().
+ *
+ * @param[out] filter          Filter handle to be initialized
+ *
+ * @return             0 on success, otherwise a negative error value
+ * @retval             #CONTEXT_HISTORY_ERROR_NONE                                     Successful
+ * @retval             #CONTEXT_HISTORY_ERROR_INVALID_PARAMETER        Invalid parameter
+ * @retval             #CONTEXT_HISTORY_ERROR_OUT_OF_MEMORY            Memory allocation failed
+ *
+ * @see                context_history_filter_destroy()
+ */
+int context_history_filter_create(context_history_filter_h* filter);
+
+/**
+ * @brief              Releases the resources occupied by a filter.
+ * @details            This releases the memory allocated for the @c filter.
+ * @since_tizen 2.4
+ *
+ * @param[in]  filter          Filter handle to be released
+ *
+ * @return             0 on success, otherwise a negative error value
+ * @retval             #CONTEXT_HISTORY_ERROR_NONE                                     Successful
+ * @retval             #CONTEXT_HISTORY_ERROR_INVALID_PARAMETER        Invalid parameter
+ *
+ * @pre                context_history_filter_create()
+ */
+int context_history_filter_destroy(context_history_filter_h filter);
+
+/**
+ * @brief              Sets an integer value to a filter.
+ * @details            This sets the value to a filter.
+ * @since_tizen 2.4
+ *
+ * @param[in]  filter          The filter handle
+ * @param[in]  filter_type     The filter type to set
+ * @param[in]  value           The value to be set
+ *
+ * @return             0 on success, otherwise a negative error value
+ * @retval             #CONTEXT_HISTORY_ERROR_NONE                                     Successful
+ * @retval             #CONTEXT_HISTORY_ERROR_INVALID_PARAMETER        Invalid parameter
+ *
+ * @pre                context_history_filter_create()
+ * @see                context_history_filter_set_string()
+  */
+int context_history_filter_set_int(context_history_filter_h filter, context_history_filter_e filter_type, int value);
+
+/**
+ * @brief              Sets a string to a filter.
+ * @details            This sets the value to a filter.
+ * @since_tizen 2.4
+ *
+ * @param[in]  filter          The filter handle
+ * @param[in]  filter_type     The filter type to set
+ * @param[in]  value           The value to be set
+ *
+ * @return             0 on success, otherwise a negative error value
+ * @retval             #CONTEXT_HISTORY_ERROR_NONE                                     Successful
+ * @retval             #CONTEXT_HISTORY_ERROR_INVALID_PARAMETER        Invalid parameter
+ *
+ * @pre                context_history_filter_create()
+ * @see                context_history_filter_set_int()
+  */
+int context_history_filter_set_string(context_history_filter_h filter, context_history_filter_e filter_type, const char* value);
+
+/**
+ * @brief              Reads context statistics or patterns.
+ * @details            Retrieves a given type of context statistics or patterns list.
+ * @since_tizen 2.4
+ *
+ * @privlevel public
+ * @privilege  %http://tizen.org/privilege/apphistory.read
+ * @privilege   %http://tizen.org/privilege/mediahistory.read
+ *
+ * @remarks            The @c list must be released using context_history_list_destroy(). \n
+ *              %http://tizen.org/privilege/apphistory.read or %http://tizen.org/privilege/mediahistory.read is needed to retrieve data. It depends on context data type #context_history_data_e.
+ *
+ * @param[in]  handle      Handle for controlling the context history data requests
+ * @param[in]  data_type       Type of the history data
+ * @param[in]  filter          Filter to be used to compute statistics or patterns. This can not be @c NULL
+ * @param[out] list   History data retrieved. This should be freed after use
+ *
+ * @return             0 on success, otherwise a negative error value
+ * @retval             #CONTEXT_HISTORY_ERROR_NONE                                     Successful
+ * @retval             #CONTEXT_HISTORY_ERROR_INVALID_PARAMETER                Invalid parameter
+ * @retval             #CONTEXT_HISTORY_ERROR_OPERATION_FAILED         Operation failed
+ * @retval             #CONTEXT_HISTORY_ERROR_OUT_OF_MEMORY                    Out of memory
+ * @retval             #CONTEXT_HISTORY_ERROR_NO_DATA                  Requested data does not exist
+ *
+ * @pre context_history_create()
+ * @post context_history_list_destroy()
+ * @see context_history_get_list()
+ */
+int context_history_get_list(context_history_h handle, context_history_data_e data_type, context_history_filter_h filter, context_history_list_h* list);
+
+/**
+ * @brief              Retrieves the number of records in a list.
+ * @since_tizen 2.4
+ *
+ * @param[in]  list    The history data list handle
+ * @param[out] count   The count of the data list
+ *
+ * @return             0 on success, otherwise a negative error value
+ * @retval             #CONTEXT_HISTORY_ERROR_NONE                                     Successful
+ * @retval             #CONTEXT_HISTORY_ERROR_INVALID_PARAMETER                Invalid parameter
+ * @retval             #CONTEXT_HISTORY_ERROR_OPERATION_FAILED         Operation failed
+ *
+ * @pre context_history_get_list()
+ * @see context_history_list_move_first()
+ * @see context_history_list_move_next()
+ */
+int context_history_list_get_count(context_history_list_h list, int* count);
+
+/**
+ * @brief              Retrieves the current record from the history list.
+ * @details            The default current record is the first record.
+ * @since_tizen 2.4
+ * @remarks            The @c record must be released using context_history_record_destroy().
+ *
+ * @param[in]  list      The context history list handle
+ * @param[out] record   History data record retrieved
+ *
+ * @return             0 on success, otherwise a negative error value
+ * @retval             #CONTEXT_HISTORY_ERROR_NONE                                     Successful
+ * @retval             #CONTEXT_HISTORY_ERROR_INVALID_PARAMETER                Invalid parameter
+ * @retval             #CONTEXT_HISTORY_ERROR_OPERATION_FAILED         Operation failed
+ * @retval             #CONTEXT_HISTORY_ERROR_OUT_OF_MEMORY                    Out of memory
+ *
+ * @pre context_history_get_list()
+ * @post context_history_record_destroy()
+ */
+int context_history_list_get_current(context_history_list_h list, context_history_record_h* record);
+
+/**
+ * @brief              Moves a history data list to the first position.
+ * @since_tizen 2.4
+ *
+ * @param[in]  list    The context history list handle
+ *
+ * @return             0 on success, otherwise a negative error value
+ * @retval             #CONTEXT_HISTORY_ERROR_NONE                                     Successful
+ * @retval             #CONTEXT_HISTORY_ERROR_INVALID_PARAMETER                Invalid parameter
+ *
+ * @pre context_history_get_list()
+ * @see context_history_list_get_count()
+ * @see context_history_list_move_next()
+ */
+int context_history_list_move_first(context_history_list_h list);
+
+/**
+ * @brief              Moves a history data list to the next position.
+ * @since_tizen 2.4
+ *
+ * @param[in]  list    The context history list handle
+ *
+ * @return             0 on success, otherwise a negative error value
+ * @retval             #CONTEXT_HISTORY_ERROR_NONE                                     Successful
+ * @retval             #CONTEXT_HISTORY_ERROR_INVALID_PARAMETER                Invalid parameter
+ * @retval             #CONTEXT_HISTORY_ERROR_NO_DATA                  Requested data does not exist
+ *
+ * @pre context_history_get_list()
+ * @see context_history_list_get_count()
+ * @see context_history_list_move_first()
+ */
+int context_history_list_move_next(context_history_list_h list);
+
+/**
+ * @brief              Destroys a history list handle and release all its resources.
+ * @since_tizen 2.4
+ *
+ * @param[in]  list    The context history data handle
+ *
+ * @return             0 on success, otherwise a negative error value
+ * @retval             #CONTEXT_HISTORY_ERROR_NONE                                     Successful
+ * @retval             #CONTEXT_HISTORY_ERROR_INVALID_PARAMETER                Invalid parameter
+ *
+ * @pre context_history_get_list()
+ */
+int context_history_list_destroy(context_history_list_h list);
+
+/**
+ * @platform
+ * @brief              Creates a record handle.
+ * @since_tizen 2.4
+ * @remarks            The @c record must be released using context_history_record_destroy().
+ *
+ * @param[out] record          The record handle
+ *
+ * @return             0 on success, otherwise a negative error value
+ * @retval             #CONTEXT_HISTORY_ERROR_NONE                                     Successful
+ * @retval             #CONTEXT_HISTORY_ERROR_INVALID_PARAMETER        Invalid parameter
+ * @retval             #CONTEXT_HISTORY_ERROR_OPERATION_FAILED         Operation failed
+ * @retval             #CONTEXT_HISTORY_ERROR_OUT_OF_MEMORY                    Out of memory
+ *
+ * @post       context_history_record_destroy()
+ * @see                context_history_record_get_int()
+ * @see                context_history_record_get_string()
+ * @see                context_history_record_set_int()
+ * @see                context_history_record_set_string()
+ */
+int context_history_record_create(context_history_record_h* record);
+
+/**
+ * @brief              Gets an integer value from a record.
+ * @since_tizen 2.4
+ *
+ * @param[in]  record          The record handle
+ * @param[in]  key                     The key of attribute to get
+ * @param[out] value           The result value
+ *
+ * @return             0 on success, otherwise a negative error value
+ * @retval             #CONTEXT_HISTORY_ERROR_NONE                                     Successful
+ * @retval             #CONTEXT_HISTORY_ERROR_INVALID_PARAMETER        Invalid parameter
+ *
+ * @pre                context_history_list_get_current()
+ * @see                context_history_record_get_string()
+ */
+int context_history_record_get_int(context_history_record_h record,  const char* key, int* value);
+
+/**
+ * @brief              Gets a string from a record.
+ * @since_tizen 2.4
+ * @remarks            @c value must be released using free().
+ *
+ * @param[in]  record          The record handle
+ * @param[in]  key                     The key of attribute to get
+ * @param[out] value           The result value
+ *
+ * @return             0 on success, otherwise a negative error value
+ * @retval             #CONTEXT_HISTORY_ERROR_NONE                                     Successful
+ * @retval             #CONTEXT_HISTORY_ERROR_INVALID_PARAMETER        Invalid parameter
+ *
+ * @pre                context_history_list_get_current()
+ * @see                context_history_record_get_int()
+ */
+int context_history_record_get_string(context_history_record_h record, const char* key, char** value);
+
+/**
+ * @platform
+ * @brief              Sets an integer value to the record.
+ * @since_tizen 2.4
+ *
+ * @param[in]  record          The record handle
+ * @param[in]  key                     The key of attribute to set
+ * @param[in]  value           The value to be set
+ *
+ * @return             0 on success, otherwise a negative error value
+ * @retval             #CONTEXT_HISTORY_ERROR_NONE                                     Successful
+ * @retval             #CONTEXT_HISTORY_ERROR_INVALID_PARAMETER        Invalid parameter
+ *
+ * @pre                context_history_record_create()
+ * @see                context_history_record_set_string()
+ */
+int context_history_record_set_int(context_history_record_h record, const char* key, int value);
+
+/**
+ * @platform
+ * @brief              Sets a string to the record.
+ * @since_tizen 2.4
+ *
+ * @param[in]  record          The record handle
+ * @param[in]  key                     The key of attribute to set
+ * @param[in]  value           The value to be set
+ *
+ * @return             0 on success, otherwise a negative error value
+ * @retval             #CONTEXT_HISTORY_ERROR_NONE                                     Successful
+ * @retval             #CONTEXT_HISTORY_ERROR_INVALID_PARAMETER        Invalid parameter
+ *
+ * @pre                context_history_record_create()
+ * @see                context_history_record_set_int()
+ */
+int context_history_record_set_string(context_history_record_h record, const char* key, const char* value);
+
+/**
+ * @brief              Destroys a record handle and releases all its resources.
+ * @since_tizen 2.4
+ *
+ * @param[in]  record          The record handle
+ *
+ * @return             0 on success, otherwise a negative error value
+ * @retval             #CONTEXT_HISTORY_ERROR_NONE                                     Successful
+ * @retval             #CONTEXT_HISTORY_ERROR_INVALID_PARAMETER        Invalid parameter
+ *
+ * @pre                context_history_list_get_current()
+ */
+int context_history_record_destroy(context_history_record_h record);
+
+/**
+ * @platform
+ * @brief              Inserts a history event log.
+ * @since_tizen 2.4
+ *
+ * @privlevel platform
+ * @privilege %http://tizen.org/privilege/mediahistory.admin
+ *
+ * @remarks            Some mandatory attributes have to be set to record. Mandatory fields are described in overview.
+ *
+ * @param[in]  event_type      The history event type
+ * @param[in]  record          The record to be inserted
+ *
+ * @return             0 on success, otherwise a negative error value
+ * @retval             #CONTEXT_HISTORY_ERROR_NONE                                     Successful
+ * @retval             #CONTEXT_HISTORY_ERROR_INVALID_PARAMETER                Invalid parameter
+ * @retval             #CONTEXT_HISTORY_ERROR_OPERATION_FAILED         Operation failed
+ * @retval             #CONTEXT_HISTORY_ERROR_OUT_OF_MEMORY                    Out of memory
+ *
+ * @pre                context_history_record_create()
+ * @post       context_history_record_destroy()
+ */
+int context_history_record_insert(context_history_record_h record, context_history_event_e event_type);
+
+#ifdef __cplusplus
+}
+#endif // __cplusplus
+
+/**
+* @}
+*/
+
+#endif // __TIZEN_CONTEXT_HISTORY_H__
diff --git a/include/context_history_types_internal.h b/include/context_history_types_internal.h
new file mode 100644 (file)
index 0000000..fff24a2
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * 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_CONTEXT_HISTORY_TYPES_INTERNAL_H__
+#define __TIZEN_CONTEXT_HISTORY_TYPES_INTERNAL_H__
+
+#include <json.h>
+
+#define CONTEXT_HISTORY_DATA "QueryResult"
+
+#define CONTEXT_HISTORY_SUBJECT_RECENTLY_USED_APP "app/history/recently_used"
+#define CONTEXT_HISTORY_SUBJECT_FREQUENTLY_USED_APP "app/history/frequently_used"
+#define CONTEXT_HISTORY_SUBJECT_RARELY_USED_APP "app/history/rarely_used"
+#define CONTEXT_HISTORY_SUBJECT_PEAK_TIME_FOR_APP "app/history/peak_time"
+#define CONTEXT_HISTORY_SUBJECT_PEAK_TIME_FOR_MUSIC "music/history/peak_time"
+#define CONTEXT_HISTORY_SUBJECT_PEAK_TIME_FOR_VIDEO "video/history/peak_time"
+#define CONTEXT_HISTORY_SUBJECT_COMMON_SETTING_FOR_APP "app/history/common_setting"
+#define CONTEXT_HISTORY_SUBJECT_COMMON_SETTING_FOR_MUSIC "music/history/common_setting"
+#define CONTEXT_HISTORY_SUBJECT_COMMON_SETTING_FOR_VIDEO "video/history/common_setting"
+#define CONTEXT_HISTORY_SUBJECT_FREQUENTLY_COMMUNICATED_ADDRESS "social/history/frequently_communicated"
+
+#define CONTEXT_HISTORY_EVENT_START_MUSIC "music/event/start"
+#define CONTEXT_HISTORY_EVENT_STOP_MUSIC "music/event/stop"
+#define CONTEXT_HISTORY_EVENT_START_VIDEO "video/event/start"
+#define CONTEXT_HISTORY_EVENT_STOP_VIDEO "video/event/stop"
+
+#define CONTEXT_HISTORY_FILTER_KEY_TIME_SPAN "TimeSpan"
+#define CONTEXT_HISTORY_FILTER_KEY_RESULT_SIZE "ResultSize"
+#define CONTEXT_HISTORY_FILTER_KEY_APP_ID "AppId"
+#define CONTEXT_HISTORY_FILTER_KEY_DAY_OF_WEEK "DayOfWeek"
+#define CONTEXT_HISTORY_FILTER_KEY_START_TIME "StartTime"
+#define CONTEXT_HISTORY_FILTER_KEY_END_TIME "EndTime"
+#define CONTEXT_HISTORY_FILTER_KEY_AUDIO_JACK "AudioJack"
+#define CONTEXT_HISTORY_FILTER_KEY_WIFI_BSSID "BSSID"
+#define CONTEXT_HISTORY_FILTER_KEY_COMMUNICATION_TYPE "CommunicationType"
+
+#endif // __TIZEN_CONTEXT_HISTORY_TYPES_INTERNAL_H__
diff --git a/include/context_internal.h b/include/context_internal.h
new file mode 100644 (file)
index 0000000..97d085e
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * 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.
+ */
+
+/*
+ * This API set is only for testing purposes.
+ * Do not use any of this set for other purposes.
+ */
+
+#ifndef __TIZEN_CONTEXT_INTERNAL_TEST_API_H__
+#define __TIZEN_CONTEXT_INTERNAL_TEST_API_H__
+
+#include <tizen_error.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif // __cplusplus
+
+typedef void(* context_internal_subscribe_cb)(const char* item, int req_id, int error, const char* data, void *user_data);
+
+int context_internal_read(const char* item, const char* option, char** data);
+
+int context_internal_write(const char* item, const char* data, char** result);
+
+int context_internal_subscribe(const char* item, const char* option, context_internal_subscribe_cb callback, void *user_data);
+
+int context_internal_unsubscribe(int req_id);
+
+#ifdef __cplusplus
+}
+#endif // __cplusplus
+
+#endif
diff --git a/include/context_trigger.h b/include/context_trigger.h
new file mode 100644 (file)
index 0000000..113c2ef
--- /dev/null
@@ -0,0 +1,1065 @@
+/*
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ *
+ * 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_CONTEXT_CONTEXT_TRIGGER_H__
+#define __TIZEN_CONTEXT_CONTEXT_TRIGGER_H__
+
+/**
+ * @addtogroup CAPI_CONTEXT_TRIGGER_MODULE
+ * @{
+ */
+
+#include <tizen_error.h>
+#include <app_control.h>
+#include <stdbool.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif // __cplusplus
+
+/**
+ * @brief      The operator "is equal to".
+ * @details    This can be used as operators of context_trigger_rule_entry_add_comparison_int()
+ *                     and context_trigger_rule_entry_add_comparison_string().
+ * @since_tizen 2.4
+ */
+#define CONTEXT_TRIGGER_EQUAL_TO "=="
+
+/**
+ * @brief      The operator "is not equal to".
+ * @details    This can be used as operators of context_trigger_rule_entry_add_comparison_int()
+ *                     and context_trigger_rule_entry_add_comparison_string().
+ * @since_tizen 2.4
+ */
+#define CONTEXT_TRIGGER_NOT_EQUAL_TO "!="
+
+/**
+ * @brief      The operator "is greater than".
+ * @details    This can be used as operators of context_trigger_rule_entry_add_comparison_int().
+ * @since_tizen 2.4
+ */
+#define CONTEXT_TRIGGER_GREATER_THAN ">"
+
+/**
+ * @brief      The operator "is greater than or equal to".
+ * @details    This can be used as operators of context_trigger_rule_entry_add_comparison_int().
+ * @since_tizen 2.4
+ */
+#define CONTEXT_TRIGGER_GREATER_THAN_OR_EQUAL_TO ">="
+
+/**
+ * @brief      The operator "is less than".
+ * @details    This can be used as operators of context_trigger_rule_entry_add_comparison_int().
+ * @since_tizen 2.4
+ */
+#define CONTEXT_TRIGGER_LESS_THAN "<"
+
+/**
+ * @brief      The operator "is less than or equal to".
+ * @details    This can be used as operators of context_trigger_rule_entry_add_comparison_int().
+ * @since_tizen 2.4
+ */
+#define CONTEXT_TRIGGER_LESS_THAN_OR_EQUAL_TO "<="
+
+/**
+ * @brief      Logical true.
+ * @details    This can be used as right operands of context_trigger_rule_entry_add_comparison_int().
+ * @since_tizen 2.4
+ */
+#define CONTEXT_TRIGGER_TRUE 1
+
+/**
+ * @brief      Logical false.
+ * @details    This can be used as right operands of context_trigger_rule_entry_add_comparison_int().
+ * @since_tizen 2.4
+ */
+#define CONTEXT_TRIGGER_FALSE 0
+
+/**
+ * @brief      The attribute key denoting "time of day".
+ * @details    This can be used as left operands of context_trigger_rule_entry_add_comparison_int().@n
+ *                     When being used with #CONTEXT_TRIGGER_EVENT_ON_TIME, it's unit is "hour",
+ *                     the valid range of the corresponding right operands is thus from 0 (12:00 AM) to 23 (11:00 PM).@n
+ *                     When being used with #CONTEXT_TRIGGER_CONDITION_TIME_OF_DAY, it's unit is "minute",
+ *                     the valid range of the corresponding right operands is thus from 0 (12:00 AM) to 1439 (11:59 PM).
+ * @since_tizen 2.4
+ */
+#define CONTEXT_TRIGGER_TIME_OF_DAY "TimeOfDay"
+
+/**
+ * @brief      The attribute key denoting "day of week".
+ * @details    This can be used as left operands of context_trigger_rule_entry_add_comparison_string().@n
+ *                     As the right operands of this attribute, one of the following values are allowed:
+ *                     #CONTEXT_TRIGGER_MON, #CONTEXT_TRIGGER_TUE, #CONTEXT_TRIGGER_WED, #CONTEXT_TRIGGER_THU,
+ *                     #CONTEXT_TRIGGER_FRI, #CONTEXT_TRIGGER_SAT, and #CONTEXT_TRIGGER_SUN.
+ * @since_tizen 2.4
+ */
+#define CONTEXT_TRIGGER_DAY_OF_WEEK "DayOfWeek"
+
+/**
+ * @brief      The attribute key denoting "day of month".
+ * @details    This can be used as left operands of context_trigger_rule_entry_add_comparison_int().@n
+ *                     The valid range of the corresponding right operands is from 1 to 31.
+ * @since_tizen 2.4
+ */
+#define CONTEXT_TRIGGER_DAY_OF_MONTH "DayOfMonth"
+
+/**
+ * @brief      The attribute key denoting boolean states of "is connected".
+ * @details    This can be used as left operands of context_trigger_rule_entry_add_comparison_int().@n
+ *                     As the right operands of this attribute, one of the following values are allowed:
+ *                     #CONTEXT_TRIGGER_TRUE and #CONTEXT_TRIGGER_FALSE.
+ * @since_tizen 2.4
+ */
+#define CONTEXT_TRIGGER_IS_CONNECTED "IsConnected"
+
+/**
+ * @brief      The attribute key denoting boolean states of "is charging".
+ * @details    This can be used as left operands of context_trigger_rule_entry_add_comparison_int().@n
+ *                     As the right operands of this attribute, one of the following values are allowed:
+ *                     #CONTEXT_TRIGGER_TRUE and #CONTEXT_TRIGGER_FALSE.
+ * @since_tizen 2.4
+ */
+#define CONTEXT_TRIGGER_IS_CHARGING "IsCharging"
+
+/**
+ * @brief      The attribute key denoting boolean states of "is enabled".
+ * @details    This can be used as left operands of context_trigger_rule_entry_add_comparison_int().@n
+ *                     As the right operands of this attribute, one of the following values are allowed:
+ *                     #CONTEXT_TRIGGER_TRUE and #CONTEXT_TRIGGER_FALSE.
+ * @since_tizen 2.4
+ */
+#define CONTEXT_TRIGGER_IS_ENABLED "IsEnabled"
+
+/**
+ * @brief      The attribute key denoting "level".
+ * @details    This can be used as left operands of context_trigger_rule_entry_add_comparison_string().@n
+ *                     See \ref CAPI_CONTEXT_TRIGGER_MODULE_DATA_FORMAT to find available right operands values.
+ * @since_tizen 2.4
+ */
+#define CONTEXT_TRIGGER_LEVEL "Level"
+
+/**
+ * @brief      The attribute key denoting "state".
+ * @details    This can be used as left operands of context_trigger_rule_entry_add_comparison_string().@n
+ *                     See \ref CAPI_CONTEXT_TRIGGER_MODULE_DATA_FORMAT to find available right operands.
+ * @since_tizen 2.4
+ */
+#define CONTEXT_TRIGGER_STATE "State"
+
+/**
+ * @brief      The attribute key denoting "BSSID".
+ * @details    This can be used as left operands of context_trigger_rule_entry_add_comparison_string().@n
+ *                     See \ref CAPI_CONTEXT_TRIGGER_MODULE_DATA_FORMAT to find available right operands.
+ * @since_tizen 2.4
+ */
+#define CONTEXT_TRIGGER_BSSID "BSSID"
+
+/**
+ * @brief      The attribute key denoting "type".
+ * @details    This can be used as left operands of context_trigger_rule_entry_add_comparison_string().@n
+ *                     See \ref CAPI_CONTEXT_TRIGGER_MODULE_DATA_FORMAT to find available right operands.
+ * @since_tizen 2.4
+ */
+#define CONTEXT_TRIGGER_TYPE "Type"
+
+/**
+ * @brief      The attribute key denoting "event".
+ * @details    This can be used as left operands of context_trigger_rule_entry_add_comparison_string().@n
+ *                     See \ref CAPI_CONTEXT_TRIGGER_MODULE_DATA_FORMAT to find available right operands.
+ * @since_tizen 2.4
+ */
+#define CONTEXT_TRIGGER_EVENT "Event"
+
+/**
+ * @brief      The attribute key denoting "accuracy".
+ * @details    This can be used as left operands of context_trigger_rule_entry_add_comparison_string().@n
+ *                     See \ref CAPI_CONTEXT_TRIGGER_MODULE_DATA_FORMAT to find available right operands.
+ * @since_tizen 2.4
+ */
+#define CONTEXT_TRIGGER_ACCURACY "Accuracy"
+
+/**
+ * @brief      The attribute key denoting "medium".
+ * @details    This can be used as left operands of context_trigger_rule_entry_add_comparison_string().@n
+ *                     See \ref CAPI_CONTEXT_TRIGGER_MODULE_DATA_FORMAT to find available right operands.
+ * @since_tizen 2.4
+ */
+#define CONTEXT_TRIGGER_MEDIUM "Medium"
+
+/**
+ * @brief      The attribute key denoting "place id".
+ * @details    This can be used as a key of context_trigger_rule_entry_add_option_int().@n
+ *                     See \ref CAPI_CONTEXT_TRIGGER_MODULE_OPTION_FORMAT to find the corresponding trigger events.
+ * @since_tizen 2.4
+ */
+#define CONTEXT_TRIGGER_PLACE_ID "PlaceId"
+
+/**
+ * @brief      The attribute key denoting "application id".
+ * @details    This can be used as a key of context_trigger_rule_entry_add_option_string().@n
+ *                     See \ref CAPI_CONTEXT_TRIGGER_MODULE_OPTION_FORMAT to find the corresponding trigger events.
+ * @since_tizen 2.4
+ */
+#define CONTEXT_TRIGGER_APP_ID "AppId"
+
+/**
+ * @brief      The attribute key denoting "address".
+ * @details    This can be used as a key of context_trigger_rule_entry_add_option_string(),
+ *                     or context_trigger_rule_entry_add_comparison_string().@n
+ *                     See \ref CAPI_CONTEXT_TRIGGER_MODULE_DATA_FORMAT and CAPI_CONTEXT_TRIGGER_MODULE_OPTION_FORMAT to find the corresponding items.
+ * @since_tizen 2.4
+ */
+#define CONTEXT_TRIGGER_ADDRESS "Address"
+
+/**
+ * @brief      The attribute key denoting "rank".
+ * @details    This can be used as left operands of context_trigger_rule_entry_add_comparison_int().@n
+ *                     See \ref CAPI_CONTEXT_TRIGGER_MODULE_DATA_FORMAT to find available right operands.
+ * @since_tizen 2.4
+ */
+#define CONTEXT_TRIGGER_RANK "Rank"
+
+/**
+ * @brief      The attribute key denoting "total count".
+ * @details    This can be used as left operands of context_trigger_rule_entry_add_comparison_int().@n
+ *                     See \ref CAPI_CONTEXT_TRIGGER_MODULE_DATA_FORMAT to find available right operands.
+ * @since_tizen 2.4
+ */
+#define CONTEXT_TRIGGER_TOTAL_COUNT "TotalCount"
+
+/**
+ * @brief      The attribute value denoting Monday.
+ * @details    This can be used as right operands of context_trigger_rule_entry_add_comparison_string().@n
+ *                     See \ref CAPI_CONTEXT_TRIGGER_MODULE_DATA_FORMAT to find the corresponding left operand attribute keys.
+ * @since_tizen 2.4
+ */
+#define CONTEXT_TRIGGER_MON "Mon"
+
+/**
+ * @brief      The attribute value denoting Tuesday.
+ * @details    This can be used as right operands of context_trigger_rule_entry_add_comparison_string().@n
+ *                     See \ref CAPI_CONTEXT_TRIGGER_MODULE_DATA_FORMAT to find the corresponding left operand attribute keys.
+ * @since_tizen 2.4
+ */
+#define CONTEXT_TRIGGER_TUE "Tue"
+
+/**
+ * @brief      The attribute value denoting Wednesday.
+ * @details    This can be used as right operands of context_trigger_rule_entry_add_comparison_string().@n
+ *                     See \ref CAPI_CONTEXT_TRIGGER_MODULE_DATA_FORMAT to find the corresponding left operand attribute keys.
+ * @since_tizen 2.4
+ */
+#define CONTEXT_TRIGGER_WED "Wed"
+
+/**
+ * @brief      The attribute value denoting Thursday.
+ * @details    This can be used as right operands of context_trigger_rule_entry_add_comparison_string().@n
+ *                     See \ref CAPI_CONTEXT_TRIGGER_MODULE_DATA_FORMAT to find the corresponding left operand attribute keys.
+ * @since_tizen 2.4
+ */
+#define CONTEXT_TRIGGER_THU "Thu"
+
+/**
+ * @brief      The attribute value denoting Friday.
+ * @details    This can be used as right operands of context_trigger_rule_entry_add_comparison_string().@n
+ *                     See \ref CAPI_CONTEXT_TRIGGER_MODULE_DATA_FORMAT to find the corresponding left operand attribute keys.
+ * @since_tizen 2.4
+ */
+#define CONTEXT_TRIGGER_FRI "Fri"
+
+/**
+ * @brief      The attribute value denoting Saturday.
+ * @details    This can be used as right operands of context_trigger_rule_entry_add_comparison_string().@n
+ *                     See \ref CAPI_CONTEXT_TRIGGER_MODULE_DATA_FORMAT to find the corresponding left operand attribute keys.
+ * @since_tizen 2.4
+ */
+#define CONTEXT_TRIGGER_SAT "Sat"
+
+/**
+ * @brief      The attribute value denoting Sunday.
+ * @details    This can be used as right operands of context_trigger_rule_entry_add_comparison_string().@n
+ *                     See \ref CAPI_CONTEXT_TRIGGER_MODULE_DATA_FORMAT to find the corresponding left operand attribute keys.
+ * @since_tizen 2.4
+ */
+#define CONTEXT_TRIGGER_SUN "Sun"
+
+/**
+ * @brief      The attribute value denoting Weekdays.
+ * @details    This can be used as right operands of context_trigger_rule_entry_add_comparison_string().@n
+ *                     See \ref CAPI_CONTEXT_TRIGGER_MODULE_DATA_FORMAT to find the corresponding left operand attribute keys.
+ * @since_tizen 2.4
+ */
+#define CONTEXT_TRIGGER_WEEKDAY "Weekday"
+
+/**
+ * @brief      The attribute value denoting Weekends.
+ * @details    This can be used as right operands of context_trigger_rule_entry_add_comparison_string().@n
+ *                     See \ref CAPI_CONTEXT_TRIGGER_MODULE_DATA_FORMAT to find the corresponding left operand attribute keys.
+ * @since_tizen 2.4
+ */
+#define CONTEXT_TRIGGER_WEEKEND "Weekend"
+
+/**
+ * @brief      The attribute value denoting the "empty" state.
+ * @details    This can be used as right operands of context_trigger_rule_entry_add_comparison_string().@n
+ *                     See \ref CAPI_CONTEXT_TRIGGER_MODULE_DATA_FORMAT to find the corresponding left operand attribute keys.
+ * @since_tizen 2.4
+ */
+#define CONTEXT_TRIGGER_EMPTY "Empty"
+
+/**
+ * @brief      The attribute value denoting the "critical" state.
+ * @details    This can be used as right operands of context_trigger_rule_entry_add_comparison_string().@n
+ *                     See \ref CAPI_CONTEXT_TRIGGER_MODULE_DATA_FORMAT to find the corresponding left operand attribute keys.
+ * @since_tizen 2.4
+ */
+#define CONTEXT_TRIGGER_CRITICAL "Critical"
+
+/**
+ * @brief      The attribute value denoting the "low" state.
+ * @details    This can be used as right operands of context_trigger_rule_entry_add_comparison_string().@n
+ *                     See \ref CAPI_CONTEXT_TRIGGER_MODULE_DATA_FORMAT to find the corresponding left operand attribute keys.
+ * @since_tizen 2.4
+ */
+#define CONTEXT_TRIGGER_LOW "Low"
+
+/**
+ * @brief      The attribute value denoting the "normal" state.
+ * @details    This can be used as right operands of context_trigger_rule_entry_add_comparison_string().@n
+ *                     See \ref CAPI_CONTEXT_TRIGGER_MODULE_DATA_FORMAT to find the corresponding left operand attribute keys.
+ * @since_tizen 2.4
+ */
+#define CONTEXT_TRIGGER_NORMAL "Normal"
+
+/**
+ * @brief      The attribute value denoting the "high" state.
+ * @details    This can be used as right operands of context_trigger_rule_entry_add_comparison_string().@n
+ *                     See \ref CAPI_CONTEXT_TRIGGER_MODULE_DATA_FORMAT to find the corresponding left operand attribute keys.
+ * @since_tizen 2.4
+ */
+#define CONTEXT_TRIGGER_HIGH "High"
+
+/**
+ * @brief      The attribute value denoting the "full" state.
+ * @details    This can be used as right operands of context_trigger_rule_entry_add_comparison_string().@n
+ *                     See \ref CAPI_CONTEXT_TRIGGER_MODULE_DATA_FORMAT to find the corresponding left operand attribute keys.
+ * @since_tizen 2.4
+ */
+#define CONTEXT_TRIGGER_FULL "Full"
+
+/**
+ * @brief      The attribute value denoting the "disabled" state.
+ * @details    This can be used as right operands of context_trigger_rule_entry_add_comparison_string().@n
+ *                     See \ref CAPI_CONTEXT_TRIGGER_MODULE_DATA_FORMAT to find the corresponding left operand attribute keys.
+ * @since_tizen 2.4
+ */
+#define CONTEXT_TRIGGER_DISABLED "Disabled"
+
+/**
+ * @brief      The attribute value denoting the "searching" state.
+ * @details    This can be used as right operands of context_trigger_rule_entry_add_comparison_string().@n
+ *                     See \ref CAPI_CONTEXT_TRIGGER_MODULE_DATA_FORMAT to find the corresponding left operand attribute keys.
+ * @since_tizen 2.4
+ */
+#define CONTEXT_TRIGGER_SEARCHING "Searching"
+
+/**
+ * @brief      The attribute value denoting the "connecting" state.
+ * @details    This can be used as right operands of context_trigger_rule_entry_add_comparison_string().@n
+ *                     See \ref CAPI_CONTEXT_TRIGGER_MODULE_DATA_FORMAT to find the corresponding left operand attribute keys.
+ * @since_tizen 2.4
+ */
+#define CONTEXT_TRIGGER_CONNECTING "Connecting"
+
+/**
+ * @brief      The attribute value denoting the "connected" state.
+ * @details    This can be used as right operands of context_trigger_rule_entry_add_comparison_string().@n
+ *                     See \ref CAPI_CONTEXT_TRIGGER_MODULE_DATA_FORMAT to find the corresponding left operand attribute keys.
+ * @since_tizen 2.4
+ */
+#define CONTEXT_TRIGGER_CONNECTED "Connected"
+
+/**
+ * @brief      The attribute value denoting the "unconnected" state.
+ * @details    This can be used as right operands of context_trigger_rule_entry_add_comparison_string().@n
+ *                     See \ref CAPI_CONTEXT_TRIGGER_MODULE_DATA_FORMAT to find the corresponding left operand attribute keys.
+ * @since_tizen 2.4
+ */
+#define CONTEXT_TRIGGER_UNCONNECTED "Unconnected"
+
+/**
+ * @brief      The attribute value denoting the "idle" state.
+ * @details    This can be used as right operands of context_trigger_rule_entry_add_comparison_string().@n
+ *                     See \ref CAPI_CONTEXT_TRIGGER_MODULE_DATA_FORMAT to find the corresponding left operand attribute keys.
+ * @since_tizen 2.4
+ */
+#define CONTEXT_TRIGGER_IDLE "Idle"
+
+/**
+ * @brief      The attribute value denoting the "voice" type.
+ * @details    This can be used as right operands of context_trigger_rule_entry_add_comparison_string().@n
+ *                     See \ref CAPI_CONTEXT_TRIGGER_MODULE_DATA_FORMAT to find the corresponding left operand attribute keys.
+ * @since_tizen 2.4
+ */
+#define CONTEXT_TRIGGER_VOICE "Voice"
+
+/**
+ * @brief      The attribute value denoting the "video" type.
+ * @details    This can be used as right operands of context_trigger_rule_entry_add_comparison_string().@n
+ *                     See \ref CAPI_CONTEXT_TRIGGER_MODULE_DATA_FORMAT to find the corresponding left operand attribute keys.
+ * @since_tizen 2.4
+ */
+#define CONTEXT_TRIGGER_VIDEO "Video"
+
+/**
+ * @brief      The attribute value denoting the "headset" type.
+ * @details    This can be used as right operands of context_trigger_rule_entry_add_comparison_string().@n
+ *                     See \ref CAPI_CONTEXT_TRIGGER_MODULE_DATA_FORMAT to find the corresponding left operand attribute keys.
+ * @since_tizen 2.4
+ */
+#define CONTEXT_TRIGGER_HEADSET "Headset"
+
+/**
+ * @brief      The attribute value denoting the "bluetooth" type.
+ * @details    This can be used as right operands of context_trigger_rule_entry_add_comparison_string().@n
+ *                     See \ref CAPI_CONTEXT_TRIGGER_MODULE_DATA_FORMAT to find the corresponding left operand attribute keys.
+ * @since_tizen 2.4
+ */
+#define CONTEXT_TRIGGER_BLUETOOTH "Bluetooth"
+
+/**
+ * @brief      The attribute value denoting the "received" event.
+ * @details    This can be used as right operands of context_trigger_rule_entry_add_comparison_string().@n
+ *                     See \ref CAPI_CONTEXT_TRIGGER_MODULE_DATA_FORMAT to find the corresponding left operand attribute keys.
+ * @since_tizen 2.4
+ */
+#define CONTEXT_TRIGGER_RECEIVED "Received"
+
+/**
+ * @brief      The attribute value denoting the "sent" event.
+ * @details    This can be used as right operands of context_trigger_rule_entry_add_comparison_string().@n
+ *                     See \ref CAPI_CONTEXT_TRIGGER_MODULE_DATA_FORMAT to find the corresponding left operand attribute keys.
+ * @since_tizen 2.4
+ */
+#define CONTEXT_TRIGGER_SENT "Sent"
+
+/**
+ * @brief      The attribute value denoting the "SMS" type.
+ * @details    This can be used as right operands of context_trigger_rule_entry_add_comparison_string().@n
+ *                     See \ref CAPI_CONTEXT_TRIGGER_MODULE_DATA_FORMAT to find the corresponding left operand attribute keys.
+ * @since_tizen 2.4
+ */
+#define CONTEXT_TRIGGER_SMS "SMS"
+
+/**
+ * @brief      The attribute value denoting the "MMS" type.
+ * @details    This can be used as right operands of context_trigger_rule_entry_add_comparison_string().@n
+ *                     See \ref CAPI_CONTEXT_TRIGGER_MODULE_DATA_FORMAT to find the corresponding left operand attribute keys.
+ * @since_tizen 2.4
+ */
+#define CONTEXT_TRIGGER_MMS "MMS"
+
+/**
+ * @brief      The attribute value denoting the "detected" event.
+ * @details    This can be used as right operands of context_trigger_rule_entry_add_comparison_string().@n
+ *                     See \ref CAPI_CONTEXT_TRIGGER_MODULE_DATA_FORMAT to find the corresponding left operand attribute keys.
+ * @since_tizen 2.4
+ */
+#define CONTEXT_TRIGGER_DETECTED "Detected"
+
+/**
+ * @brief      The attribute value denoting the "in" event.
+ * @details    This can be used as right operands of context_trigger_rule_entry_add_comparison_string().@n
+ *                     See \ref CAPI_CONTEXT_TRIGGER_MODULE_DATA_FORMAT to find the corresponding left operand attribute keys.
+ * @since_tizen 2.4
+ */
+#define CONTEXT_TRIGGER_IN "In"
+
+/**
+ * @brief      The attribute value denoting the "out" event.
+ * @details    This can be used as right operands of context_trigger_rule_entry_add_comparison_string().@n
+ *                     See \ref CAPI_CONTEXT_TRIGGER_MODULE_DATA_FORMAT to find the corresponding left operand attribute keys.
+ * @since_tizen 2.4
+ */
+#define CONTEXT_TRIGGER_OUT "Out"
+
+/**
+ * @brief      Enumeration of error codes for context trigger API.
+ * @since_tizen 2.4
+ */
+typedef enum {
+       CONTEXT_TRIGGER_ERROR_NONE                              = TIZEN_ERROR_NONE,                                             /**< Successful */
+       CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER,                /**< Invalid function parameter */
+       CONTEXT_TRIGGER_ERROR_OUT_OF_MEMORY             = TIZEN_ERROR_OUT_OF_MEMORY,                    /**< Out of memory */
+       CONTEXT_TRIGGER_ERROR_PERMISSION_DENIED = TIZEN_ERROR_PERMISSION_DENIED,                /**< Permission denied */
+       CONTEXT_TRIGGER_ERROR_NOT_SUPPORTED             = TIZEN_ERROR_NOT_SUPPORTED,                    /**< Not supported */
+       CONTEXT_TRIGGER_ERROR_NO_DATA                   = TIZEN_ERROR_NO_DATA,                                  /**< No data */
+       CONTEXT_TRIGGER_ERROR_OPERATION_FAILED  = (TIZEN_ERROR_CONTEXT | 0x04),                 /**< Operation failed */
+       CONTEXT_TRIGGER_ERROR_RULE_ENABLED              = (TIZEN_ERROR_CONTEXT | 0X05),                 /**< Rule is enabled */
+       CONTEXT_TRIGGER_ERROR_RULE_NOT_ENABLED  = (TIZEN_ERROR_CONTEXT | 0X06),                 /**< Rule is not enabled */
+       CONTEXT_TRIGGER_ERROR_INVALID_RULE              = (TIZEN_ERROR_CONTEXT | 0X07),                 /**< Invalid rule */
+       CONTEXT_TRIGGER_ERROR_RULE_NOT_EXIST    = (TIZEN_ERROR_CONTEXT | 0X08),                 /**< Rule does not exist */
+} context_trigger_error_e;
+
+/**
+ * @brief              Enumeration for event types.
+ * @since_tizen 2.4
+ */
+typedef enum {
+       CONTEXT_TRIGGER_EVENT_TIME              = 0x10001,      /**< At certain times of day and days of week @n Privilege: http://tizen.org/privilege/alarm.set */
+       CONTEXT_TRIGGER_EVENT_BATTERY   = 0x10100,      /**< Battery level changed */
+       CONTEXT_TRIGGER_EVENT_CHARGER,                          /**< Charger connected/disconnected */
+       CONTEXT_TRIGGER_EVENT_GPS,                                      /**< GPS state changed */
+       CONTEXT_TRIGGER_EVENT_HEADPHONE,                        /**< Headphone connected/disconnected */
+       CONTEXT_TRIGGER_EVENT_USB,                                      /**< USB connected/disconnected */
+       CONTEXT_TRIGGER_EVENT_WIFI,                                     /**< WiFi state changed @n Privilege: http://tizen.org/privilege/network.get */
+       CONTEXT_TRIGGER_EVENT_POWER_SAVING_MODE = 0x10200,      /**< Power saving mode enabled/disabled */
+       CONTEXT_TRIGGER_EVENT_CALL              = 0x10300,      /**< Call state changed @n Privilege: http://tizen.org/privilege/telephony */
+       CONTEXT_TRIGGER_EVENT_EMAIL,                            /**< Email sent/received */
+       CONTEXT_TRIGGER_EVENT_MESSAGE,                          /**< Message sent/received @n Privilege: http://tizen.org/privilege/message.read */
+       CONTEXT_TRIGGER_EVENT_ACTIVITY_STATIONARY       = 0x10400,      /**< 'Stationary' activity detected */
+       CONTEXT_TRIGGER_EVENT_ACTIVITY_WALKING,         /**< 'Walking' activity detected */
+       CONTEXT_TRIGGER_EVENT_ACTIVITY_RUNNING,         /**< 'Running' activity detected */
+       CONTEXT_TRIGGER_EVENT_ACTIVITY_IN_VEHICLE,      /**< 'In vehicle' activity detected */
+       CONTEXT_TRIGGER_EVENT_PLACE             = 0x10500,      /**< Get in/out to/from a specific user place @n Privilege: http://tizen.org/privilege/location */
+} context_trigger_event_e;
+
+/**
+ * @brief              Enumeration for condition types.
+ * @since_tizen 2.4
+ */
+typedef enum {
+       CONTEXT_TRIGGER_CONDITION_TIME          = 0x20001,      /**< Time of day */
+       CONTEXT_TRIGGER_CONDITION_BATTERY       = 0x20100,      /**< Battery level */
+       CONTEXT_TRIGGER_CONDITION_CHARGER,                              /**< Charger connection */
+       CONTEXT_TRIGGER_CONDITION_GPS,                                  /**< GPS state */
+       CONTEXT_TRIGGER_CONDITION_HEADPHONE,                    /**< Headphone connection */
+       CONTEXT_TRIGGER_CONDITION_USB,                                  /**< USB connection */
+       CONTEXT_TRIGGER_CONDITION_WIFI,                                 /**< WiFi state @n Privilege: http://tizen.org/privilege/network.get */
+       CONTEXT_TRIGGER_CONDITION_POWER_SAVING_MODE     = 0x20200,      /**< Power saving mode setting */
+       CONTEXT_TRIGGER_CONDITION_CALL          = 0x20300,      /**< Call state @n Privilege: http://tizen.org/privilege/telephony */
+       CONTEXT_TRIGGER_CONDITION_APP_USE_FREQUENCY     = 0x20600,      /**< Frequency of app use @n Privilege: http://tizen.org/privilege/apphistory.read  */
+       CONTEXT_TRIGGER_CONDITION_COMMUNICATION_FREQUENCY,              /**< Frequency of communication via call or message @n Privilege: http://tizen.org/privilege/callhistory.read */
+       CONTEXT_TRIGGER_CONDITION_MUSIC_PLAYBACK_FREQUENCY,             /**< Frequency of music playback @n Privilege: http://tizen.org/privilege/mediahistory.read */
+       CONTEXT_TRIGGER_CONDITION_VIDEO_PLAYBACK_FREQUENCY,             /**< Frequency of video playback @n Privilege: http://tizen.org/privilege/mediahistory.read */
+} context_trigger_condition_e;
+
+/**
+ * @brief              Enumeration for logical operation types.
+ * @since_tizen 2.4
+ */
+typedef enum {
+       CONTEXT_TRIGGER_LOGICAL_CONJUNCTION = 1,        /**< Logical conjunction */
+       CONTEXT_TRIGGER_LOGICAL_DISJUNCTION,            /**< Logical disjunction */
+} context_trigger_logical_type_e;
+
+/**
+ * @brief              Handle for editing a trigger rule.
+ * @since_tizen 2.4
+ */
+typedef struct _context_trigger_rule_s* context_trigger_rule_h;
+
+/**
+ * @brief              Handle for editing an event or a condition, which is added to a rule.
+ * @since_tizen 2.4
+ */
+typedef struct _context_trigger_rule_entry_s* context_trigger_rule_entry_h;
+
+/**
+ * @brief              Registers a rule.
+ * @details            Using this, applications can register a rule and get the ID of the registered rule.@n
+ *                             A rule only can be enabled, disabled, or removed by the application that has registered the rule.
+ * @since_tizen 2.4
+ *
+ * @privlevel  public
+ * @privilege  http://tizen.org/privilege/alarm.set @n
+ *                             http://tizen.org/privilege/telephony @n
+ *                             http://tizen.org/privilege/message.read @n
+ *                             http://tizen.org/privilege/network.get
+ *
+ * @remarks            When registering a new rule,
+ *                             regarding the event and condition items used to compose the rule,
+ *                             the application may require one or more privileges.
+ *                             If the application does not have a necessary privilege,
+ *                             #CONTEXT_TRIGGER_ERROR_PERMISSION_DENIED is returned.
+ *
+ * @param[in]  rule            The rule to register
+ * @param[out] rule_id         The ID assigned to the @c rule
+ *
+ * @return             0 on success, otherwise a negative error value
+ * @retval             #CONTEXT_TRIGGER_ERROR_NONE                                     Successful
+ * @retval             #CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER        Invalid parameter
+ * @retval             #CONTEXT_TRIGGER_ERROR_PERMISSION_DENIED        Permission denied
+ * @retval             #CONTEXT_TRIGGER_ERROR_NOT_SUPPORTED            Unsupported event/condition contained
+ * @retval             #CONTEXT_TRIGGER_ERROR_OUT_OF_MEMORY            Out of memory
+ * @retval             #CONTEXT_TRIGGER_ERROR_OPERATION_FAILED         Operation failed
+ * @retval             #CONTEXT_TRIGGER_ERROR_INVALID_RULE                     Invalid rule
+ *
+ * @see                        context_trigger_remove_rule()
+ */
+int context_trigger_add_rule(context_trigger_rule_h rule, int* rule_id);
+
+/**
+ * @brief              Removes a rule.
+ * @details            This removes the rule designated by the @c rule_id, which is owned by the application.
+ * @since_tizen 2.4
+ *
+ * @remarks            If the rule has been activated, it should be disabled through context_trigger_disable_rule() in advance.
+ *
+ * @param[in]  rule_id         The ID of the rule to be removed
+ *
+ * @return             0 on success, otherwise a negative error value
+ * @retval             #CONTEXT_TRIGGER_ERROR_NONE                                     Successful
+ * @retval             #CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER        Invalid parameter
+ * @retval             #CONTEXT_TRIGGER_ERROR_OUT_OF_MEMORY            Out of memory
+ * @retval             #CONTEXT_TRIGGER_ERROR_OPERATION_FAILED         Operation failed
+ * @retval             #CONTEXT_TRIGGER_ERROR_RULE_ENABLED                     Rule is enabled already
+ * @retval             #CONTEXT_TRIGGER_ERROR_RULE_NOT_EXIST           Rule does not exist
+ *
+ * @see                        context_trigger_add_rule()
+ */
+int context_trigger_remove_rule(int rule_id);
+
+/**
+ * @brief              Enables a rule.
+ * @details            This activates the rule designated by the @c rule_id, which is owned by the application.
+ * @since_tizen 2.4
+ *
+ * @param[in]  rule_id         The ID of the rule to be enabled
+ *
+ * @return             0 on success, otherwise a negative error value
+ * @retval             #CONTEXT_TRIGGER_ERROR_NONE                                     Successful
+ * @retval             #CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER        Invalid parameter
+ * @retval             #CONTEXT_TRIGGER_ERROR_OUT_OF_MEMORY            Out of memory
+ * @retval             #CONTEXT_TRIGGER_ERROR_OPERATION_FAILED         Operation failed
+ * @retval             #CONTEXT_TRIGGER_ERROR_RULE_ENABLED                     Rule is enabled already
+ * @retval             #CONTEXT_TRIGGER_ERROR_RULE_NOT_EXIST           Rule does not exist
+ *
+ * @see                        context_trigger_disable_rule()
+ */
+int context_trigger_enable_rule(int rule_id);
+
+/**
+ * @brief              Disables a rule.
+ * @details            This deactivates the rule designated by the @c rule_id, which is owned by the application.
+ * @since_tizen 2.4
+ *
+ * @param[in]  rule_id         The ID of the rule to be disabled
+ *
+ * @return             0 on success, otherwise a negative error value
+ * @retval             #CONTEXT_TRIGGER_ERROR_NONE                                     Successful
+ * @retval             #CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER        Invalid parameter
+ * @retval             #CONTEXT_TRIGGER_ERROR_OUT_OF_MEMORY            Out of memory
+ * @retval             #CONTEXT_TRIGGER_ERROR_OPERATION_FAILED         Operation failed
+ * @retval             #CONTEXT_TRIGGER_ERROR_RULE_NOT_ENABLED         Rule is not enabled
+ * @retval             #CONTEXT_TRIGGER_ERROR_RULE_NOT_EXIST           Rule does not exist
+ *
+ * @see                        context_trigger_enable_rule()
+ */
+int context_trigger_disable_rule(int rule_id);
+
+/**
+ * @brief              Gets the IDs of the rules owned by the current application.
+ * @since_tizen 2.4
+ *
+ * @remarks            The arrays @c enabled_rule_ids and @c disabled_rule_ids must be released using @c free().
+ *
+ * @param[out] enabled_rule_ids        The IDs of the active rules
+ * @param[out] enabled_rule_count      The number of the active rules
+ * @param[out] disabled_rule_ids       The IDs of the inactive rules
+ * @param[out] disabled_rule_count     The number of the inactive rules
+ *
+ * @return             0 on success, otherwise a negative error value
+ * @retval             #CONTEXT_TRIGGER_ERROR_NONE                                     Successful
+ * @retval             #CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER        Invalid parameter
+ * @retval             #CONTEXT_TRIGGER_ERROR_OUT_OF_MEMORY            Out of memory
+ * @retval             #CONTEXT_TRIGGER_ERROR_OPERATION_FAILED         Operation failed
+ *
+ */
+int context_trigger_get_own_rule_ids(int** enabled_rule_ids, int* enabled_rule_count, int** disabled_rule_ids, int* disabled_rule_count);
+
+/**
+ * @brief              Gets a rule stored in the system by rule ID.
+ * @since_tizen 2.4
+ *
+ * @remarks            The @c rule must be released using context_trigger_rule_entry_destroy().
+ *
+ * @param[in]  rule_id         The ID of the rule to be retrieved
+ * @param[out] rule            The rule retrieved
+ *
+ * @return             0 on success, otherwise a negative error value
+ * @retval             #CONTEXT_TRIGGER_ERROR_NONE                                     Successful
+ * @retval             #CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER        Invalid parameter
+ * @retval             #CONTEXT_TRIGGER_ERROR_OUT_OF_MEMORY            Out of memory
+ * @retval             #CONTEXT_TRIGGER_ERROR_OPERATION_FAILED         Operation failed
+ * @retval             #CONTEXT_TRIGGER_ERROR_RULE_NOT_EXIST           Rule does not exist
+ */
+int context_trigger_get_rule_by_id(int rule_id, context_trigger_rule_h* rule);
+
+/**
+ * @brief              Creates an empty rule.
+ * @details            An empty rule container is created. When using this,
+ *                             a logical operator, one of #context_trigger_logical_type_e, needs to be designated.@n
+ *                             In case of #CONTEXT_TRIGGER_LOGICAL_CONJUNCTION,
+ *                             the rule can be satisfied only if all conditions are true.
+ *                             Otherwise, in case of #CONTEXT_TRIGGER_LOGICAL_DISJUNCTION,
+ *                             the rule can be satisfied if at least one is true.
+ * @since_tizen 2.4
+ *
+ * @remarks            The @c rule must be released using context_trigger_rule_destroy().
+ *
+ * @param[in]  logical_type    The logical operator
+ * @param[out] rule                    The rule handle to be initialized
+ *
+ * @return             0 on success, otherwise a negative error value
+ * @retval             #CONTEXT_TRIGGER_ERROR_NONE                                     Successful
+ * @retval             #CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER        Invalid parameter
+ * @retval             #CONTEXT_TRIGGER_ERROR_OUT_OF_MEMORY            Memory allocation failed
+ */
+int context_trigger_rule_create(context_trigger_logical_type_e logical_type, context_trigger_rule_h* rule);
+
+/**
+ * @brief              Releases the resources occupied by a rule handle.
+ * @since_tizen 2.4
+ *
+ * @param[in]  rule            The rule handle to be released
+ *
+ * @return             0 on success, otherwise a negative error value
+ * @retval             #CONTEXT_TRIGGER_ERROR_NONE                                     Successful
+ * @retval             #CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER        Invalid parameter
+ *
+ * @see                        context_trigger_rule_create()
+ * @see                        context_Trigger_get_rule_by_id()
+ */
+int context_trigger_rule_destroy(context_trigger_rule_h rule);
+
+/**
+ * @brief              Adds an event or a condition to a rule.
+ * @since_tizen 2.4
+ *
+ * @param[in]  rule            The rule
+ * @param[in]  entry           The event or condition entry to be added to the rule
+ *
+ * @return             0 on success, otherwise a negative error value
+ * @retval             #CONTEXT_TRIGGER_ERROR_NONE                                     Successful
+ * @retval             #CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER        Invalid parameter
+ * @retval             #CONTEXT_TRIGGER_ERROR_OUT_OF_MEMORY            Out of memory
+ * @retval             #CONTEXT_TRIGGER_ERROR_OPERATION_FAILED         Operation failed
+ * @retval             #CONTEXT_TRIGGER_ERROR_INVALID_RULE                     Invalid rule
+ */
+int context_trigger_rule_add_entry(context_trigger_rule_h rule, context_trigger_rule_entry_h entry);
+
+/**
+ * @brief              Sets a app launching request as the action of a rule.
+ * @details            Contextual Trigger accepts an App Control as the action of a rule,
+ *                             an application thus can be launched when the rule is satisfied.@n
+ * @since_tizen 2.4
+ *
+ * @privlevel  public
+ * @privilege  http://tizen.org/privilege/appmanager.launch @n
+ *                             http://tizen.org/privilege/call
+ *
+ * @remarks            In addition to the privilege http://tizen.org/privilege/appmanager.launch,
+ *                             if it is an App Control that makes a call to someone,
+ *                             the privilege http://tizen.org/privilege/call is also required.
+ *
+ * @param[in]  rule                    The rule
+ * @param[in]  app_control             The App Control, which will be used to launch an application
+ *
+ * @return             0 on success, otherwise a negative error value
+ * @retval             #CONTEXT_TRIGGER_ERROR_NONE                                     Successful
+ * @retval             #CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER        Invalid parameter
+ * @retval             #CONTEXT_TRIGGER_ERROR_PERMISSION_DENIED        Permission denied
+ * @retval             #CONTEXT_TRIGGER_ERROR_OUT_OF_MEMORY            Out of memory
+ * @retval             #CONTEXT_TRIGGER_ERROR_OPERATION_FAILED         Operation failed
+ */
+int context_trigger_rule_set_action_app_control(context_trigger_rule_h rule, app_control_h app_control);
+
+/**
+ * @brief              Sets a notification posting request as the action of a rule.
+ * @details            A basic notification can be posted when the rule is satisfied,
+ *                             which consists of the title, a content body text, an icon, and an App Control.
+ * @since_tizen 2.4
+ *
+ * @privlevel  public
+ * @privilege  http://tizen.org/privilege/notification
+ *
+ * @remarks            The @c app_control can be @c NULL. In that case, no application will be launched via the notification.
+ *
+ * @param[in]  rule                    The rule
+ * @param[in]  title                   The title text
+ * @param[in]  content                 The content body text
+ * @param[in]  icon_path               The icon file path
+ * @param[in]  app_control             The app control
+ *
+ * @return             0 on success, otherwise a negative error value
+ * @retval             #CONTEXT_TRIGGER_ERROR_NONE                                     Successful
+ * @retval             #CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER        Invalid parameter
+ * @retval             #CONTEXT_TRIGGER_ERROR_PERMISSION_DENIED        Permission denied
+ * @retval             #CONTEXT_TRIGGER_ERROR_OUT_OF_MEMORY            Out of memory
+ * @retval             #CONTEXT_TRIGGER_ERROR_OPERATION_FAILED         Operation failed
+ */
+int context_trigger_rule_set_action_notification(context_trigger_rule_h rule, const char* title, const char* content, const char* icon_path, app_control_h app_control);
+
+/**
+ * @brief              Sets the description of a rule.
+ * @since_tizen 2.4
+ *
+ * @param[in]  rule                    The rule
+ * @param[in]  description             The description to be set
+ *
+ * @return             0 on success, otherwise a negative error value
+ * @retval             #CONTEXT_TRIGGER_ERROR_NONE                                     Successful
+ * @retval             #CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER        Invalid parameter
+ * @retval             #CONTEXT_TRIGGER_ERROR_OUT_OF_MEMORY            Out of memory
+ * @retval             #CONTEXT_TRIGGER_ERROR_OPERATION_FAILED         Operation failed
+ */
+int context_trigger_rule_set_description(context_trigger_rule_h rule, const char* description);
+
+/**
+ * @brief              Gets the description of a rule.
+ * @since_tizen 2.4
+ *
+ * @remarks            The @c description must be released using @c free().
+ *
+ * @param[in]  rule                    The rule
+ * @param[out] description             The description of the rule
+ *
+ * @return             0 on success, otherwise a negative error value
+ * @retval             #CONTEXT_TRIGGER_ERROR_NONE                                     Successful
+ * @retval             #CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER        Invalid parameter
+ * @retval             #CONTEXT_TRIGGER_ERROR_OUT_OF_MEMORY            Out of memory
+ * @retval             #CONTEXT_TRIGGER_ERROR_OPERATION_FAILED         Operation failed
+ */
+int context_trigger_rule_get_description(context_trigger_rule_h rule, char** description);
+
+/**
+ * @brief              Creates an event entry.
+ * @details            An event of a contextual event item, which will be monitored by the system, is created.
+ * @since_tizen 2.4
+ *
+ * @remarks            The @c entry must be released using context_trigger_rule_entry_destroy().
+ *
+ * @param[in]  event_item              The contextual event item
+ * @param[in]  logical_type    The logical operator
+ * @param[out] entry                   The event entry to be initialized
+ *
+ * @return             0 on success, otherwise a negative error value
+ * @retval             #CONTEXT_TRIGGER_ERROR_NONE                                     Successful
+ * @retval             #CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER        Invalid parameter
+ * @retval             #CONTEXT_TRIGGER_ERROR_OUT_OF_MEMORY            Memory allocation failed
+ */
+int context_trigger_rule_event_create(context_trigger_event_e event_item, context_trigger_logical_type_e logical_type, context_trigger_rule_entry_h* entry);
+
+/**
+ * @brief              Checks whether a contextual event is supported in the current device.
+ * @since_tizen 2.4
+ *
+ * @param[in]  event_item              The contextual event item
+ * @param[out] supported               If supported, @c true; Otherwise, @c false
+ *
+ * @return             0 on success, otherwise a negative error value
+ * @retval             #CONTEXT_TRIGGER_ERROR_NONE                                     Successful
+ * @retval             #CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER        Invalid parameter
+ * @retval             #CONTEXT_TRIGGER_ERROR_OPERATION_FAILED         Operation failed
+ */
+int context_trigger_rule_event_is_supported(context_trigger_event_e event_item, bool* supported);
+
+/**
+ * @brief              Creates a condition entry.
+ * @details            A condition of a contextual condition item is created.
+ * @since_tizen 2.4
+ *
+ * @remarks            The @c entry must be released using context_trigger_rule_entry_destroy().
+ *
+ * @param[in]  condition_item  The contextual condition item
+ * @param[in]  logical_type    The logical operator
+ * @param[out] entry                   The condition entry to be initialized
+ *
+ * @return             0 on success, otherwise a negative error value
+ * @retval             #CONTEXT_TRIGGER_ERROR_NONE                                     Successful
+ * @retval             #CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER        Invalid parameter
+ * @retval             #CONTEXT_TRIGGER_ERROR_OUT_OF_MEMORY            Memory allocation failed
+ */
+int context_trigger_rule_condition_create(context_trigger_condition_e condition_item, context_trigger_logical_type_e logical_type, context_trigger_rule_entry_h* entry);
+
+/**
+ * @brief              Checks whether a contextual condition is supported in the current device.
+ * @since_tizen 2.4
+ *
+ * @param[in]  condition_item  The contextual condition item
+ * @param[out] supported               If supported, @c true; Otherwise, @c false
+ *
+ * @return             0 on success, otherwise a negative error value
+ * @retval             #CONTEXT_TRIGGER_ERROR_NONE                                     Successful
+ * @retval             #CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER        Invalid parameter
+ * @retval             #CONTEXT_TRIGGER_ERROR_OPERATION_FAILED         Operation failed
+ */
+int context_trigger_rule_condition_is_supported(context_trigger_condition_e condition_item, bool* supported);
+
+/**
+ * @brief              Releases the resource occupied by an entry.
+ * @since_tizen 2.4
+ *
+ * @param[in]  entry           The event or condition entry
+ *
+ * @return             0 on success, otherwise a negative error value
+ * @retval             #CONTEXT_TRIGGER_ERROR_NONE                                     Successful
+ * @retval             #CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER        Invalid parameter
+ *
+ * @see                        context_trigger_rule_event_create()
+ * @see                        context_trigger_rule_condition_create()
+ */
+int context_trigger_rule_entry_destroy(context_trigger_rule_entry_h entry);
+
+/**
+ * @brief              Sets an integer type option to an event or condition entry.
+ * @details            See \ref CAPI_CONTEXT_TRIGGER_MODULE_OPTION_FORMAT to find available option keys for each event/condition item.
+ * @since_tizen 2.4
+ *
+ * @param[in]  entry                   The event or condition entry
+ * @param[in]  option_key              The option key
+ * @param[in]  value                   The option value
+ *
+ * @return             0 on success, otherwise a negative error value
+ * @retval             #CONTEXT_TRIGGER_ERROR_NONE                                     Successful
+ * @retval             #CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER        Invalid parameter
+ * @retval             #CONTEXT_TRIGGER_ERROR_OUT_OF_MEMORY            Out of memory
+ * @retval             #CONTEXT_TRIGGER_ERROR_INVALID_RULE                     Invalid rule
+ */
+int context_trigger_rule_entry_add_option_int(context_trigger_rule_entry_h entry, const char* option_key, int value);
+
+/**
+ * @brief              Sets a string type option to an event or condition entry.
+ * @details            See \ref CAPI_CONTEXT_TRIGGER_MODULE_OPTION_FORMAT to find available option keys for each event/condition item.
+ * @since_tizen 2.4
+ *
+ * @param[in]  entry                   The event or condition entry
+ * @param[in]  option_key              The option key
+ * @param[in]  value                   The option value
+ *
+ * @return             0 on success, otherwise a negative error value
+ * @retval             #CONTEXT_TRIGGER_ERROR_NONE                                     Successful
+ * @retval             #CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER        Invalid parameter
+ * @retval             #CONTEXT_TRIGGER_ERROR_OUT_OF_MEMORY            Out of memory
+ * @retval             #CONTEXT_TRIGGER_ERROR_INVALID_RULE                     Invalid rule
+ */
+int context_trigger_rule_entry_add_option_string(context_trigger_rule_entry_h entry, const char* option_key, const char* value);
+
+/**
+ * @brief              Sets an option to a condition entry, which references an attribute that will be extracted from the event.
+ * @details            See \ref CAPI_CONTEXT_TRIGGER_MODULE_OPTION_FORMAT to find available option keys for each condition item.
+ * @since_tizen 2.4
+ *
+ * @param[in]  entry                   The condition entry
+ * @param[in]  option_key              The option key
+ * @param[in]  event_data_key  The event data key of which the corresponding data value will be used as the option parameter
+ *
+ * @return             0 on success, otherwise a negative error value
+ * @retval             #CONTEXT_TRIGGER_ERROR_NONE                                     Successful
+ * @retval             #CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER        Invalid parameter
+ * @retval             #CONTEXT_TRIGGER_ERROR_OUT_OF_MEMORY            Out of memory
+ * @retval             #CONTEXT_TRIGGER_ERROR_INVALID_RULE                     Invalid rule
+ */
+int context_trigger_rule_entry_add_option(context_trigger_rule_entry_h entry, const char* option_key, const char* event_data_key);
+
+/**
+ * @brief              Adds an attribute key to an entry.
+ * @details            The key will be used as the left operand of comparisons.
+ *                             See \ref CAPI_CONTEXT_TRIGGER_MODULE_DATA_FORMAT to find available attribute keys for each event/condition item.
+ * @since_tizen 2.4
+ *
+ * @param[in]  entry                   The event or condition entry
+ * @param[in]  logical_type    The logical operator
+ * @param[in]  key                             The attribute key
+ *
+ * @return             0 on success, otherwise a negative error value
+ * @retval             #CONTEXT_TRIGGER_ERROR_NONE                                     Successful
+ * @retval             #CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER        Invalid parameter
+ * @retval             #CONTEXT_TRIGGER_ERROR_OUT_OF_MEMORY            Out of memory
+ * @retval             #CONTEXT_TRIGGER_ERROR_INVALID_RULE                     Invalid rule
+ */
+int context_trigger_rule_entry_add_key(context_trigger_rule_entry_h entry, context_trigger_logical_type_e logical_type, const char* key);
+
+/**
+ * @brief              Adds a comparison between an attribute key and an integer.
+ * @details            The key needs to be registered in advance, via context_trigger_rule_entry_add_key().
+ *                             As the comparison operator, one of the following operators is allowed: "==", "!=", "<", ">", "<=", and ">=".
+ * @since_tizen 2.4
+ *
+ * @param[in]  entry                   The event or condition entry
+ * @param[in]  key                             The attribute key, which will be used as the left operand
+ * @param[in]  comp_operator   The comparison operator
+ * @param[in]  value                   The right operand value
+ *
+ * @return             0 on success, otherwise a negative error value
+ * @retval             #CONTEXT_TRIGGER_ERROR_NONE                                     Successful
+ * @retval             #CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER        Invalid parameter
+ * @retval             #CONTEXT_TRIGGER_ERROR_OUT_OF_MEMORY            Out of memory
+ * @retval             #CONTEXT_TRIGGER_ERROR_NO_DATA                          The key was not added in the entry
+ * @retval             #CONTEXT_TRIGGER_ERROR_INVALID_RULE                     Invalid rule
+ */
+int context_trigger_rule_entry_add_comparison_int(context_trigger_rule_entry_h entry, const char* key, const char* comp_operator, int  value);
+
+/**
+ * @brief              Adds a comparison between an attribute key and a string.
+ * @details            The key needs to be registered in advance, via context_trigger_rule_entry_add_key().
+ *                             As the comparison operator, one of the following operators is allowed: "==" and "!=".
+ * @since_tizen 2.4
+ *
+ * @param[in]  entry                   The event or condition entry
+ * @param[in]  key                             The attribute key, which will be used as the left operand
+ * @param[in]  comp_operator   The comparison operator
+ * @param[in]  value                   The right operand value
+ *
+ * @return             0 on success, otherwise a negative error value
+ * @retval             #CONTEXT_TRIGGER_ERROR_NONE                                     Successful
+ * @retval             #CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER        Invalid parameter
+ * @retval             #CONTEXT_TRIGGER_ERROR_OUT_OF_MEMORY            Out of memory
+ * @retval             #CONTEXT_TRIGGER_ERROR_NO_DATA                          The key was not added in the entry
+ * @retval             #CONTEXT_TRIGGER_ERROR_INVALID_RULE                     Invalid rule
+ */
+int context_trigger_rule_entry_add_comparison_string(context_trigger_rule_entry_h entry, const char* key, const char* comp_operator, const char* value);
+
+/**
+ * @brief              Adds a comparison between an attribute of a condition and an attribute extracted from the event.
+ * @details            The key needs to be registered in advance, via context_trigger_rule_entry_add_key().
+ * @since_tizen 2.4
+ *
+ * @param[in]  entry                   The condition entry
+ * @param[in]  key                             The attribute key of the condition, which will be used as the left operand
+ * @param[in]  comp_operator   The comparison operator
+ * @param[in]  event_data_key  The event data key of which the corresponding data value will be used as the right operand
+ *
+ * @return             0 on success, otherwise a negative error value
+ * @retval             #CONTEXT_TRIGGER_ERROR_NONE                                     Successful
+ * @retval             #CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER        Invalid parameter
+ * @retval             #CONTEXT_TRIGGER_ERROR_OUT_OF_MEMORY            Out of memory
+ * @retval             #CONTEXT_TRIGGER_ERROR_NO_DATA                          The key was not added in the entry
+ * @retval             #CONTEXT_TRIGGER_ERROR_INVALID_RULE                     Invalid rule
+ */
+int context_trigger_rule_entry_add_comparison(context_trigger_rule_entry_h entry, const char* key, const char* comp_operator, const char* event_data_key);
+
+#ifdef __cplusplus
+}
+#endif // __cplusplus
+
+/**
+* @}
+*/
+
+#endif // __TIZEN_CONTEXT_CONTEXT_TRIGGER_H__
diff --git a/include/context_trigger_types_internal.h b/include/context_trigger_types_internal.h
new file mode 100644 (file)
index 0000000..763cf04
--- /dev/null
@@ -0,0 +1,108 @@
+/*
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ *
+ * 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_CONTEXT_CONTEXT_TRIGGER_TYPES_INTERNAL_H__
+#define __TIZEN_CONTEXT_CONTEXT_TRIGGER_TYPES_INTERNAL_H__
+
+#define CONTEXT_TRIGGER_SUBJECT_ADD "context_trigger/add"
+#define CONTEXT_TRIGGER_SUBJECT_REMOVE "context_trigger/remove"
+#define CONTEXT_TRIGGER_SUBJECT_ENABLE "context_trigger/enable"
+#define CONTEXT_TRIGGER_SUBJECT_DISABLE "context_trigger/disable"
+#define CONTEXT_TRIGGER_SUBJECT_GET "context_trigger/get"
+#define CONTEXT_TRIGGER_SUBJECT_GET_RULE_IDS "context_trigger/get_rule_ids"
+
+#define CT_RULE_ARRAY_ENABLED "ARRAY_ENABLED"
+#define CT_RULE_ARRAY_DISABLED "ARRAY_DISABLED"
+
+#define CT_RULE_ACTION_TYPE_APP_CONTROL "app_control"
+#define CT_RULE_ACTION_TYPE_NOTIFICATION "notification"
+
+#define CT_RULE_ID "ID"
+#define CT_RULE_DESCRIPTION "DESCRIPTION"
+#define CT_RULE_DETAILS "DETAILS"
+#define CT_RULE_EVENT "EVENT"
+#define CT_RULE_EVENT_ITEM "ITEM_NAME"
+#define CT_RULE_EVENT_OPERATOR "ITEM_OPERATOR"
+#define CT_RULE_EVENT_OPTION "OPTION"
+#define CT_RULE_OPERATOR "OPERATOR"
+#define CT_RULE_CONDITION "CONDITION"
+#define CT_RULE_CONDITION_ITEM "ITEM_NAME"
+#define CT_RULE_CONDITION_OPERATOR "ITEM_OPERATOR"
+#define CT_RULE_CONDITION_OPTION "OPTION"
+#define CT_RULE_DATA_ARR "DATA_ARR"
+#define CT_RULE_DATA_KEY "DATA_KEY"
+#define CT_RULE_DATA_KEY_OPERATOR "DATA_KEY_OPERATOR"
+#define CT_RULE_DATA_VALUE_ARR "DATA_VALUE_ARR"
+#define CT_RULE_DATA_VALUE_OPERATOR_ARR "DATA_VALUE_OPER_ARR"
+#define CT_RULE_ACTION "ACTION"
+#define CT_RULE_ACTION_TYPE "ACTION_TYPE"
+#define CT_RULE_ACTION_APP_CONTROL "ACTION_APP_CONTROL"
+#define CT_RULE_ACTION_NOTI_TITLE "ACTION_NOTI_TITLE"
+#define CT_RULE_ACTION_NOTI_CONTENT "ACTION_NOTI_CONTENT"
+#define CT_RULE_ACTION_NOTI_ICON_PATH "ACTION_NOTI_ICON_PATH"
+
+#define CT_RESPONSE "RES"
+
+#define        CT_EVENT_TIME "timer/event"
+#define CT_EVENT_BATTERY "system/state/battery"
+#define CT_EVENT_CHARGER "system/state/charger"
+#define CT_EVENT_FLIGHT_MODE "system/state/flight_mode"
+#define CT_EVENT_GPS "system/state/gps"
+#define CT_EVENT_HEADPHONE "system/state/headphone"
+#define CT_EVENT_POWER_SAVING_MODE "system/state/ps_mode"
+#define CT_EVENT_SILENT_MODE "system/state/silent_mode"
+#define CT_EVENT_VIBRATION_MODE "system/state/vibration_mode"
+#define CT_EVENT_USB "system/state/usb"
+#define CT_EVENT_WIFI "system/state/wifi"
+#define CT_EVENT_CALL "social/state/call"
+#define CT_EVENT_EMAIL "social/event/email"
+#define CT_EVENT_MESSAGE "social/event/message"
+#define CT_EVENT_ACTIVITY_STATIONARY "activity/event/stationary"
+#define CT_EVENT_ACTIVITY_WALKING "activity/event/walking"
+#define CT_EVENT_ACTIVITY_RUNNING "activity/event/running"
+#define CT_EVENT_ACTIVITY_IN_VEHICLE "activity/event/in_vehicle"
+#define CT_EVENT_PLACE "place/event/geofence"
+#define CT_CONDITION_TIME "timer/state"
+#define CT_CONDITION_BATTERY "system/state/battery"
+#define CT_CONDITION_CHARGER "system/state/charger"
+#define CT_CONDITION_FLIGHT_MODE "system/state/flight_mode"
+#define CT_CONDITION_GPS "system/state/gps"
+#define CT_CONDITION_HEADPHONE "system/state/headphone"
+#define CT_CONDITION_POWER_SAVING_MODE "system/state/ps_mode"
+#define CT_CONDITION_SILENT_MODE "system/state/silent_mode"
+#define CT_CONDITION_VIBRATION_MODE "system/state/vibration_mode"
+#define CT_CONDITION_USB "system/state/usb"
+#define CT_CONDITION_WIFI "system/state/wifi"
+#define CT_CONDITION_CALL "social/state/call"
+#define CT_CONDITION_APP_USE_FREQUENCY "app/history/use_freq"
+#define CT_CONDITION_COMMUNICATION_FREQUENCY "contact/history/comm_freq"
+#define CT_CONDITION_MUSIC_PLAYBACK_FREQUENCY "music/history/play_freq"
+#define CT_CONDITION_VIDEO_PLAYBACK_FREQUENCY "video/history/play_freq"
+
+#define TYPE_EVENT 1
+#define TYPE_CONDITION 2
+
+#define TYPE_OPTION 1
+#define TYPE_ATTR 2
+
+#define TYPE_INT 1
+#define TYPE_STRING 2
+
+#define TYPE_OPTION_STR "option"
+#define TYPE_ATTR_STR "attributes"
+
+
+#endif // __TIZEN_CONTEXT_CONTEXT_TRIGGER_TYPES_INTERNAL_H__
diff --git a/internal/CMakeLists.txt b/internal/CMakeLists.txt
new file mode 100644 (file)
index 0000000..061a20d
--- /dev/null
@@ -0,0 +1,49 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+PROJECT(context-internal)
+
+# Targets
+SET(target_internal "context-internal")
+
+# Source Lists
+FILE(GLOB_RECURSE SRCS_INTERNAL *.cpp)
+
+# Dependencies
+SET(DEPS_INTERNAL "context-common")
+
+# Building Library
+pkg_check_modules(api_internal_pkg REQUIRED ${DEPS_INTERNAL})
+
+FOREACH(flag ${api_internal_pkg_CFLAGS})
+   SET(API_INTERNAL_EXTRA_CFLAGS "${API_INTERNAL_EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+ADD_LIBRARY(${target_internal} SHARED ${SRCS_INTERNAL})
+TARGET_LINK_LIBRARIES(${target_internal} ${api_internal_pkg_LDFLAGS})
+SET_TARGET_PROPERTIES(${target_internal} PROPERTIES COMPILE_FLAGS ${API_INTERNAL_EXTRA_CFLAGS})
+SET_TARGET_PROPERTIES(${target_internal} PROPERTIES COMPILE_DEFINITIONS "LOG_TAG=\"CONTEXT-API\"")
+SET_TARGET_PROPERTIES(${target_internal} PROPERTIES SOVERSION ${MAJORVER})
+SET_TARGET_PROPERTIES(${target_internal} PROPERTIES VERSION ${FULLVER})
+
+# Installing
+INSTALL(TARGETS ${target_internal} DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT RuntimeLibraries)
+INSTALL(
+       DIRECTORY ${CMAKE_SOURCE_DIR}/include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/context-service/internal
+       FILES_MATCHING PATTERN "*_internal.h"
+)
+
+SET(VERSION ${FULLVER})
+SET(PREFIX ${CMAKE_INSTALL_PREFIX})
+SET(PC_NAME ${target_internal})
+SET(PC_INCLUDE "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}/context-service/internal")
+SET(PC_LIBDIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}")
+SET(PC_DESCRIPTION "Tizen Context Framework Native Test API")
+SET(PC_REQUIRED ${DEPS_INTERNAL})
+SET(PC_LDFLAGS -l${target_internal})
+SET(PC_CFLAGS -I\${includedir}/context-service/internal)
+
+CONFIGURE_FILE(
+       ${CMAKE_SOURCE_DIR}/context.pc.in
+       ${CMAKE_SOURCE_DIR}/${target_internal}.pc
+       @ONLY
+)
+INSTALL(FILES ${CMAKE_SOURCE_DIR}/${target_internal}.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
diff --git a/internal/context_internal.cpp b/internal/context_internal.cpp
new file mode 100644 (file)
index 0000000..36ce9d5
--- /dev/null
@@ -0,0 +1,84 @@
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <string>
+#include <map>
+#include <json.h>
+#include <types_internal.h>
+#include <request_handler.h>
+#include <context_internal.h>
+
+typedef std::map<int, context_internal_subscribe_cb> callback_map_t;
+static callback_map_t callback_map;
+
+static void internal_domain_cb(const char* item, int req_id, int error, ctx::json data)
+{
+       callback_map_t::iterator cb = callback_map.find(req_id);
+       IF_FAIL_VOID_TAG(cb != callback_map.end(), _W, "No callback found");
+
+       // user_data pointer is not supported
+       cb->second(item, req_id, error, data.str().c_str(), NULL);
+}
+
+EXTAPI int context_internal_read(const char* item, const char* option, char** data)
+{
+       int req_id;
+       ctx::json jdata;
+       ctx::json joption = option;
+
+       int error = ctx::request_handler::read_sync(item, &joption, &req_id, &jdata);
+       IF_FAIL_RETURN_TAG(error == ERR_NONE, error, _E, "read_sync error");
+
+       *data = jdata.dup_cstr();
+
+       return ERR_NONE;
+}
+
+EXTAPI int context_internal_write(const char* item, const char* data, char** result)
+{
+       ctx::json jdata = data;
+       ctx::json jresult;
+
+       int error = ctx::request_handler::write_with_reply(item, &jdata, &jresult);
+       IF_FAIL_RETURN_TAG(error == ERR_NONE, error, _E, "write_with_reply error");
+
+       *result = jresult.dup_cstr();
+
+       return ERR_NONE;
+}
+
+EXTAPI int context_internal_subscribe(const char* item, const char* option, context_internal_subscribe_cb callback, void *user_data)
+{
+       ctx::request_handler::register_callback(item, internal_domain_cb);
+
+       int req_id;
+       ctx::json jresult;
+       ctx::json joption = option;
+
+       int error = ctx::request_handler::subscribe(item, &joption, &req_id, &jresult);
+       IF_FAIL_RETURN(error == ERR_NONE, error);
+
+       _J("Request Result:", jresult);
+
+       callback_map[req_id] = callback;
+       return req_id;
+}
+
+EXTAPI int context_internal_unsubscribe(int req_id)
+{
+       callback_map.erase(req_id);
+       return ctx::request_handler::unsubscribe(req_id);
+}
diff --git a/packaging/context.manifest b/packaging/context.manifest
new file mode 100644 (file)
index 0000000..a76fdba
--- /dev/null
@@ -0,0 +1,5 @@
+<manifest>
+       <request>
+               <domain name="_" />
+       </request>
+</manifest>
diff --git a/packaging/context.spec b/packaging/context.spec
new file mode 100644 (file)
index 0000000..5c47e8d
--- /dev/null
@@ -0,0 +1,95 @@
+Name:       context
+Summary:    Tizen Context Framework Native API
+Version:    0.4.2
+Release:    1
+Group:      Framework/system
+License:    Apache-2.0
+Source0:    %{name}-%{version}.tar.gz
+
+BuildRequires: cmake
+BuildRequires: pkgconfig(aul)
+BuildRequires: pkgconfig(bundle)
+BuildRequires: pkgconfig(capi-appfw-app-control)
+BuildRequires: pkgconfig(pkgmgr-info)
+BuildRequires: pkgconfig(capi-security-privilege-manager)
+BuildRequires: pkgconfig(context-common)
+
+%ifarch %{arm}
+%define ARCH arm
+%else
+%define ARCH i586
+%endif
+
+%description
+Tizen Context Framework Native API
+
+%prep
+%setup -q
+
+%build
+MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'`
+
+export   CFLAGS+=" -Wextra -Wcast-align -Wcast-qual -Wshadow -Wwrite-strings -Wswitch-default"
+export CXXFLAGS+=" -Wextra -Wcast-align -Wcast-qual -Wshadow -Wwrite-strings -Wswitch-default -Wnon-virtual-dtor -Wno-c++0x-compat"
+
+export   CFLAGS+=" -Wno-unused-parameter -Wno-empty-body"
+export CXXFLAGS+=" -Wno-unused-parameter -Wno-empty-body"
+
+export   CFLAGS+=" -fno-omit-frame-pointer -fno-optimize-sibling-calls -fno-strict-aliasing -fno-unroll-loops -fsigned-char -fstrict-overflow -fno-common"
+export CXXFLAGS+=" -fno-omit-frame-pointer -fno-optimize-sibling-calls -fno-strict-aliasing -fno-unroll-loops -fsigned-char -fstrict-overflow"
+
+%define BINTYPE engineer
+export   CFLAGS+=" -DTIZEN_ENGINEER_MODE"
+export CXXFLAGS+=" -DTIZEN_ENGINEER_MODE"
+export   FFLAGS+=" -DTIZEN_ENGINEER_MODE"
+
+cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} -DARCH=%{ARCH} -DMAJORVER=${MAJORVER} -DFULLVER=%{version} -DPROFILE=%{?tizen_profile_name} -DBINTYPE=%{BINTYPE}
+make %{?jobs:-j%jobs}
+
+%install
+rm -rf %{buildroot}
+%make_install
+
+mkdir -p %{buildroot}/usr/share/license
+cp LICENSE %{buildroot}/usr/share/license/%{name}
+
+%post
+/sbin/ldconfig
+
+%postun
+/sbin/ldconfig
+
+%files
+%manifest packaging/%{name}.manifest
+%defattr(-,root,root,-)
+%{_libdir}/*.so*
+/usr/share/license/%{name}
+#%if %{BINTYPE} == "engineer"
+#/usr/bin/*
+#%endif
+
+%package devel
+Summary:    Tizen Context Framework Native API (Development)
+Group:      Framework/system
+Requires:      %{name} = %{version}-%{release}
+
+%description devel
+Tizen Context Framework Native API (Development)
+
+%files devel
+%defattr(-,root,root,-)
+%{_includedir}/context-service/*.h
+%{_libdir}/pkgconfig/%{name}.pc
+
+%package internal
+Summary:    Tizen Context Framework Internal Headers
+Group:      Framework/system
+Requires:      %{name} = %{version}-%{release}
+
+%description internal
+Tizen Context Framework Internal Headers
+
+%files internal
+%defattr(-,root,root,-)
+%{_includedir}/context-service/internal/*.h
+%{_libdir}/pkgconfig/context-internal.pc
diff --git a/src/context_history.cpp b/src/context_history.cpp
new file mode 100644 (file)
index 0000000..6ecac10
--- /dev/null
@@ -0,0 +1,569 @@
+/*
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ *
+ * 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 <map>
+#include <json.h>
+#include <request_handler.h>
+#include <context_history.h>
+#include <context_history_types_internal.h>
+
+#define TYPE_INT 0
+#define TYPE_STRING 1
+
+#define GROUP_COMMON 0
+#define GROUP1 1
+#define GROUP2 2
+#define GROUP3 3
+#define GROUP4 4
+#define GROUP5 5
+
+// handles
+typedef struct _context_history_handle_s {
+       /* At this point, this handle has no purpose.
+          But, it will be used to support other functionalities later,
+          e.g., async read or session management. */
+       int tmp;
+} _cx_history_handle;
+
+typedef struct _context_history_filter_handle_s {
+       ctx::json jfilter;
+} _cx_history_filter_handle;
+
+typedef struct _context_history_list_handle_s {
+       ctx::json jlist;
+       int current;
+       _context_history_list_handle_s()
+       {
+               current = 0;
+       }
+} _cx_history_list_handle;
+
+typedef struct _context_history_record_handle_s {
+       ctx::json jrecord;
+} _cx_history_record_handle;
+
+static std::string convert_filter_to_string(context_history_filter_e filter_type);
+static std::string convert_data_to_string(context_history_data_e data_type);
+static std::string convert_event_to_string(context_history_event_e event_type);
+static bool check_record_key_data_type(int type, std::string key);
+static bool check_filter_data_int(context_history_filter_e filter_type, int val);
+static bool check_filter_data_string(context_history_filter_e filter_type, const char* val);
+static bool check_invalid_filter(context_history_data_e data_type, context_history_filter_h filter);
+
+// life-cycle
+EXTAPI int context_history_create(context_history_h* handle)
+{
+       ASSERT_NOT_NULL(handle);
+
+       *handle = new(std::nothrow) _cx_history_handle();
+       ASSERT_ALLOC(*handle);
+
+       return CONTEXT_HISTORY_ERROR_NONE;
+}
+
+EXTAPI int context_history_destroy(context_history_h handle)
+{
+       ASSERT_NOT_NULL(handle);
+       delete handle;
+       return CONTEXT_HISTORY_ERROR_NONE;
+}
+
+// Read filter manipulation
+EXTAPI int context_history_filter_create(context_history_filter_h* filter)
+{
+       ASSERT_NOT_NULL(filter);
+
+       *filter = new(std::nothrow) _cx_history_filter_handle();
+       ASSERT_ALLOC(*filter);
+
+       return CONTEXT_HISTORY_ERROR_NONE;
+}
+
+EXTAPI int context_history_filter_destroy(context_history_filter_h filter)
+{
+       ASSERT_NOT_NULL(filter);
+       delete filter;
+
+       return CONTEXT_HISTORY_ERROR_NONE;
+}
+
+EXTAPI int context_history_filter_set_int(context_history_filter_h filter, context_history_filter_e filter_type, int val)
+{
+       ASSERT_NOT_NULL(filter);
+
+       std::string filter_str = convert_filter_to_string(filter_type);
+       if (filter_str.empty()) {
+               return CONTEXT_HISTORY_ERROR_INVALID_PARAMETER;
+       }
+
+       // Check filter and its data type
+       IF_FAIL_RETURN_TAG(check_filter_data_int(filter_type, val), CONTEXT_HISTORY_ERROR_INVALID_PARAMETER, _E, "Filter type mismatched");
+
+       filter->jfilter.set(NULL, filter_str.c_str(), val);
+
+       return CONTEXT_HISTORY_ERROR_NONE;
+}
+
+EXTAPI int context_history_filter_set_string(context_history_filter_h filter, context_history_filter_e filter_type, const char* val)
+{
+       ASSERT_NOT_NULL(filter);
+       ASSERT_NOT_NULL(val);
+
+       std::string filter_str = convert_filter_to_string(filter_type);
+       if (filter_str.empty()) {
+               return CONTEXT_HISTORY_ERROR_INVALID_PARAMETER;
+       }
+
+       // Check filter and its data type
+       IF_FAIL_RETURN_TAG(check_filter_data_string(filter_type, val), CONTEXT_HISTORY_ERROR_INVALID_PARAMETER, _E, "Filter type mismatched");
+
+       filter->jfilter.set(NULL, filter_str.c_str(), val);
+
+       return CONTEXT_HISTORY_ERROR_NONE;
+}
+
+EXTAPI int context_history_get_list(context_history_h handle, context_history_data_e data_type, context_history_filter_h filter, context_history_list_h* list)
+{
+       ASSERT_NOT_NULL(handle);
+       ASSERT_NOT_NULL(list);
+       *list = NULL;
+
+       /*TODO: Boundary check for filter values has to be done*/
+
+       std::string data_type_str = convert_data_to_string(data_type);
+       if (data_type_str.empty()) {
+               return CONTEXT_HISTORY_ERROR_INVALID_PARAMETER;
+       }
+
+       // Check data type & filter
+       if (filter)
+               IF_FAIL_RETURN_TAG(check_invalid_filter(data_type, filter), CONTEXT_HISTORY_ERROR_INVALID_PARAMETER, _E, "Invalid filter key");
+
+       int req_id;
+       ctx::json tmp_list;
+       int err = ctx::request_handler::read_sync(data_type_str.c_str(), (filter)? &filter->jfilter : NULL, &req_id, &tmp_list);
+       IF_FAIL_RETURN_TAG(err==ERR_NONE, err, _E, "Getting list failed");
+
+       _J("Read response", tmp_list);
+
+       IF_FAIL_RETURN_TAG(tmp_list.array_get_size(NULL, CONTEXT_HISTORY_DATA) > 0, CONTEXT_HISTORY_ERROR_NO_DATA, _D, "No data");
+
+       *list = new(std::nothrow) _cx_history_list_handle();
+       ASSERT_ALLOC(*list);
+       (*list)->jlist = tmp_list;
+       (*list)->current = 0;
+
+       return CONTEXT_HISTORY_ERROR_NONE;
+}
+
+// Data object manipulation
+EXTAPI int context_history_list_get_count(context_history_list_h list, int* count)
+{
+       ASSERT_NOT_NULL(list);
+       ASSERT_NOT_NULL(count);
+       *count = 0;
+
+       int result = list->jlist.array_get_size(NULL, CONTEXT_HISTORY_DATA);
+       IF_FAIL_RETURN(result > 0, CONTEXT_HISTORY_ERROR_OPERATION_FAILED);
+
+       *count = result;
+
+       return CONTEXT_HISTORY_ERROR_NONE;
+}
+
+EXTAPI int context_history_list_get_current(context_history_list_h list, context_history_record_h* record)
+{
+       ASSERT_NOT_NULL(list);
+       ASSERT_NOT_NULL(record);
+       *record = NULL;
+
+       ctx::json tmp_record;
+       int error = list->jlist.get_array_elem(NULL, CONTEXT_HISTORY_DATA, list->current, &tmp_record);
+       IF_FAIL_RETURN_TAG(error, CONTEXT_HISTORY_ERROR_OPERATION_FAILED, _E, "Record load failed");
+
+       *record = new(std::nothrow) _cx_history_record_handle();
+       ASSERT_ALLOC(*record);
+       (*record)->jrecord = tmp_record;
+
+       return CONTEXT_HISTORY_ERROR_NONE;
+}
+
+
+EXTAPI int context_history_list_move_first(context_history_list_h list)
+{
+       ASSERT_NOT_NULL(list);
+
+       list->current = 0;
+
+       return CONTEXT_HISTORY_ERROR_NONE;
+}
+
+EXTAPI int context_history_list_move_next(context_history_list_h list)
+{
+       ASSERT_NOT_NULL(list);
+
+       IF_FAIL_RETURN_TAG(list->current+1 < list->jlist.array_get_size(NULL, CONTEXT_HISTORY_DATA), CONTEXT_HISTORY_ERROR_NO_DATA, _D, "End of list");
+
+       list->current++;
+
+       return CONTEXT_HISTORY_ERROR_NONE;
+}
+
+EXTAPI int context_history_list_destroy(context_history_list_h list)
+{
+       ASSERT_NOT_NULL(list);
+
+       delete list;
+
+       return CONTEXT_HISTORY_ERROR_NONE;
+}
+
+// Log data manipulation
+EXTAPI int context_history_record_create(context_history_record_h* record)
+{
+       ASSERT_NOT_NULL(record);
+
+       *record = new(std::nothrow) _cx_history_record_handle();
+       ASSERT_ALLOC(*record);
+
+       return CONTEXT_HISTORY_ERROR_NONE;
+}
+
+EXTAPI int context_history_record_get_int(context_history_record_h record, const char* key, int* val)
+{
+       ASSERT_NOT_NULL(record && val && key);
+
+       // Check key and data type
+       IF_FAIL_RETURN_TAG(check_record_key_data_type(TYPE_INT, key), CONTEXT_HISTORY_ERROR_INVALID_PARAMETER, _E, "Data type mismatched");
+
+       std::list<std::string> key_list;
+       record->jrecord.get_keys(&key_list);
+       IF_FAIL_RETURN_TAG(key_list.size() > 0, CONTEXT_HISTORY_ERROR_NO_DATA, _E, "No data");
+
+       // Check invalid record key
+       IF_FAIL_RETURN_TAG(record->jrecord.get(NULL, key, val), CONTEXT_HISTORY_ERROR_INVALID_PARAMETER, _E, "Invalid record key");
+
+       return CONTEXT_HISTORY_ERROR_NONE;
+}
+
+EXTAPI int context_history_record_get_string(context_history_record_h record, const char* key, char** val)
+{
+       ASSERT_NOT_NULL(record && val && key);
+
+       // Check key and data type
+       IF_FAIL_RETURN_TAG(check_record_key_data_type(TYPE_STRING, key), CONTEXT_HISTORY_ERROR_INVALID_PARAMETER, _E, "Data type mismatched");
+
+       std::list<std::string> key_list;
+       record->jrecord.get_keys(&key_list);
+       IF_FAIL_RETURN_TAG(key_list.size() > 0, CONTEXT_HISTORY_ERROR_NO_DATA, _E, "No data");
+
+       // Check Invalid record key
+       std::string str;
+       IF_FAIL_RETURN_TAG(record->jrecord.get(NULL, key, &str), CONTEXT_HISTORY_ERROR_INVALID_PARAMETER, _E, "Value load failed");
+
+       *val = g_strdup(str.c_str());
+       ASSERT_ALLOC(*val);
+
+       return CONTEXT_HISTORY_ERROR_NONE;
+}
+
+EXTAPI int context_history_record_set_int(context_history_record_h record, const char* key, int val)
+{
+       ASSERT_NOT_NULL(record && key);
+
+       record->jrecord.set(NULL, key, val);
+
+       return CONTEXT_HISTORY_ERROR_NONE;
+}
+
+EXTAPI int context_history_record_set_string(context_history_record_h record, const char* key, const char* val)
+{
+       ASSERT_NOT_NULL(record && val && key);
+
+       record->jrecord.set(NULL, key, val);
+
+       return CONTEXT_HISTORY_ERROR_NONE;
+}
+
+EXTAPI int context_history_record_destroy(context_history_record_h record)
+{
+       ASSERT_NOT_NULL(record);
+       delete record;
+
+       return CONTEXT_HISTORY_ERROR_NONE;
+}
+
+// Write
+EXTAPI int context_history_record_insert(context_history_record_h record, context_history_event_e event_type)
+{
+       ASSERT_NOT_NULL(record);
+       IF_FAIL_RETURN(event_type > 0, CONTEXT_HISTORY_ERROR_INVALID_PARAMETER);
+
+       std::string event_type_str = convert_event_to_string(event_type);
+       if (event_type_str.empty()) {
+               return CONTEXT_HISTORY_ERROR_INVALID_PARAMETER;
+       }
+
+       record->jrecord.set(NULL, COMMON_ATTR_CLIENT_APP_ID, "");
+       int error = ctx::request_handler::write(event_type_str.c_str(), &record->jrecord);
+
+       return error;
+}
+
+std::string convert_filter_to_string(context_history_filter_e filter_type)
+{
+       std::string str;
+       switch (filter_type) {
+       case CONTEXT_HISTORY_FILTER_TIME_SPAN:
+               str = CONTEXT_HISTORY_FILTER_KEY_TIME_SPAN;
+               break;
+       case CONTEXT_HISTORY_FILTER_RESULT_SIZE:
+               str = CONTEXT_HISTORY_FILTER_KEY_RESULT_SIZE;
+               break;
+       case CONTEXT_HISTORY_FILTER_APP_ID:
+               str = CONTEXT_HISTORY_FILTER_KEY_APP_ID;
+               break;
+       case CONTEXT_HISTORY_FILTER_DAY_OF_WEEK:
+               str = CONTEXT_HISTORY_FILTER_KEY_DAY_OF_WEEK;
+               break;
+       case CONTEXT_HISTORY_FILTER_START_TIME:
+               str = CONTEXT_HISTORY_FILTER_KEY_START_TIME;
+               break;
+       case CONTEXT_HISTORY_FILTER_END_TIME:
+               str = CONTEXT_HISTORY_FILTER_KEY_END_TIME;
+               break;
+       case CONTEXT_HISTORY_FILTER_WIFI_BSSID:
+               str = CONTEXT_HISTORY_FILTER_KEY_WIFI_BSSID;
+               break;
+       case CONTEXT_HISTORY_FILTER_AUDIO_JACK:
+               str = CONTEXT_HISTORY_FILTER_KEY_AUDIO_JACK;
+               break;
+       case CONTEXT_HISTORY_FILTER_COMMUNICATION_TYPE:
+               str = CONTEXT_HISTORY_FILTER_KEY_COMMUNICATION_TYPE;
+               break;
+       default:
+               break;
+       }
+       return str;
+}
+
+std::string convert_data_to_string(context_history_data_e data_type)
+{
+       std::string str;
+       switch (data_type) {
+       case CONTEXT_HISTORY_RECENTLY_USED_APP:
+               str = CONTEXT_HISTORY_SUBJECT_RECENTLY_USED_APP;
+               break;
+       case CONTEXT_HISTORY_FREQUENTLY_USED_APP:
+               str = CONTEXT_HISTORY_SUBJECT_FREQUENTLY_USED_APP;
+               break;
+       case CONTEXT_HISTORY_RARELY_USED_APP:
+               str = CONTEXT_HISTORY_SUBJECT_RARELY_USED_APP;
+               break;
+       case CONTEXT_HISTORY_PEAK_TIME_FOR_APP:
+               str = CONTEXT_HISTORY_SUBJECT_PEAK_TIME_FOR_APP;
+               break;
+       case CONTEXT_HISTORY_PEAK_TIME_FOR_MUSIC:
+               str = CONTEXT_HISTORY_SUBJECT_PEAK_TIME_FOR_MUSIC;
+               break;
+       case CONTEXT_HISTORY_PEAK_TIME_FOR_VIDEO:
+               str = CONTEXT_HISTORY_SUBJECT_PEAK_TIME_FOR_VIDEO;
+               break;
+       case CONTEXT_HISTORY_COMMON_SETTING_FOR_APP:
+               str = CONTEXT_HISTORY_SUBJECT_COMMON_SETTING_FOR_APP;
+               break;
+       case CONTEXT_HISTORY_COMMON_SETTING_FOR_MUSIC:
+               str = CONTEXT_HISTORY_SUBJECT_COMMON_SETTING_FOR_MUSIC;
+               break;
+       case CONTEXT_HISTORY_COMMON_SETTING_FOR_VIDEO:
+               str = CONTEXT_HISTORY_SUBJECT_COMMON_SETTING_FOR_VIDEO;
+               break;
+       case CONTEXT_HISTORY_FREQUENTLY_COMMUNICATED_ADDRESS:
+               str = CONTEXT_HISTORY_SUBJECT_FREQUENTLY_COMMUNICATED_ADDRESS;
+               break;
+       default:
+               break;
+       }
+       return str;
+}
+
+std::string convert_event_to_string(context_history_event_e event_type)
+{
+       std::string str;
+       switch (event_type) {
+       case CONTEXT_HISTORY_START_MUSIC:
+               str = CONTEXT_HISTORY_EVENT_START_MUSIC;
+               break;
+       case CONTEXT_HISTORY_STOP_MUSIC:
+               str = CONTEXT_HISTORY_EVENT_STOP_MUSIC;
+               break;
+       case CONTEXT_HISTORY_START_VIDEO:
+               str = CONTEXT_HISTORY_EVENT_START_VIDEO;
+               break;
+       case CONTEXT_HISTORY_STOP_VIDEO:
+               str = CONTEXT_HISTORY_EVENT_STOP_VIDEO;
+               break;
+       default:
+               break;
+       }
+       return str;
+}
+
+bool check_record_key_data_type(int type, std::string key)
+{
+       if ((key.compare(CONTEXT_HISTORY_APP_ID) == 0) ||
+                       key.compare(CONTEXT_HISTORY_ADDRESS) == 0) {
+               return (type == TYPE_STRING);
+       }
+
+       if ((key.compare(CONTEXT_HISTORY_TOTAL_COUNT) == 0) ||
+                       key.compare(CONTEXT_HISTORY_TOTAL_DURATION) == 0 ||
+                       key.compare(CONTEXT_HISTORY_LAST_TIME) == 0 ||
+                       key.compare(CONTEXT_HISTORY_HOUR_OF_DAY) == 0 ||
+                       key.compare(CONTEXT_HISTORY_AUDIO_JACK) == 0 ||
+                       key.compare(CONTEXT_HISTORY_SYSTEM_VOLUME) == 0 ||
+                       key.compare(CONTEXT_HISTORY_MEDIA_VOLUME) == 0) {
+               return (type == TYPE_INT);
+       }
+
+       return false;
+}
+
+bool check_filter_data_int(context_history_filter_e filter_type, int val)
+{
+       switch (filter_type) {
+       case CONTEXT_HISTORY_FILTER_TIME_SPAN:
+       case CONTEXT_HISTORY_FILTER_RESULT_SIZE:
+       case CONTEXT_HISTORY_FILTER_START_TIME:
+       case CONTEXT_HISTORY_FILTER_END_TIME:
+               if (val > 0 )
+                       return true;
+               break;
+       case CONTEXT_HISTORY_FILTER_DAY_OF_WEEK:
+               if (val == CONTEXT_HISTORY_FILTER_DAY_OF_WEEK_WEEKDAYS ||
+                       val == CONTEXT_HISTORY_FILTER_DAY_OF_WEEK_WEEKENDS ||
+                       val == CONTEXT_HISTORY_FILTER_DAY_OF_WEEK_ALL)
+                       return true;
+               break;
+       case CONTEXT_HISTORY_FILTER_AUDIO_JACK:
+               if (val == CONTEXT_HISTORY_FILTER_AUDIO_JACK_NOT_CONNECTED ||
+                       val == CONTEXT_HISTORY_FILTER_AUDIO_JACK_CONNECTED)
+                       return true;
+               break;
+       case CONTEXT_HISTORY_FILTER_COMMUNICATION_TYPE:
+               if (val == CONTEXT_HISTORY_FILTER_COMMUNICATION_TYPE_CALL ||
+                       val == CONTEXT_HISTORY_FILTER_COMMUNICATION_TYPE_MESSAGE ||
+                       val == CONTEXT_HISTORY_FILTER_COMMUNICATION_TYPE_ALL)
+                       return true;
+               break;
+       default:
+               return false;
+       }
+       return false;
+}
+
+bool check_filter_data_string(context_history_filter_e filter_type, const char* val)
+{
+       switch (filter_type) {
+       case CONTEXT_HISTORY_FILTER_APP_ID:
+       case CONTEXT_HISTORY_FILTER_WIFI_BSSID:
+               if (val)
+                       return true;
+               break;
+       default:
+               return false;
+       }
+       return false;
+}
+
+bool check_invalid_filter(context_history_data_e data_type, context_history_filter_h filter)
+{
+       static const char* group_common[] = {CONTEXT_HISTORY_FILTER_KEY_TIME_SPAN, NULL};
+       static const char* group1[] = {CONTEXT_HISTORY_FILTER_KEY_RESULT_SIZE, CONTEXT_HISTORY_FILTER_KEY_START_TIME,
+                                                                       CONTEXT_HISTORY_FILTER_KEY_END_TIME, CONTEXT_HISTORY_FILTER_KEY_WIFI_BSSID,
+                                                                       CONTEXT_HISTORY_FILTER_KEY_AUDIO_JACK, NULL};
+       static const char* group2[] = {CONTEXT_HISTORY_FILTER_KEY_RESULT_SIZE, CONTEXT_HISTORY_FILTER_KEY_START_TIME,
+                                                                       CONTEXT_HISTORY_FILTER_KEY_END_TIME, NULL};
+       static const char* group3[] = {CONTEXT_HISTORY_FILTER_KEY_RESULT_SIZE, CONTEXT_HISTORY_FILTER_KEY_START_TIME,
+                                                                       CONTEXT_HISTORY_FILTER_KEY_END_TIME, CONTEXT_HISTORY_FILTER_KEY_APP_ID,
+                                                                       CONTEXT_HISTORY_FILTER_KEY_DAY_OF_WEEK, NULL};
+       static const char* group4[] = {CONTEXT_HISTORY_FILTER_KEY_START_TIME, CONTEXT_HISTORY_FILTER_KEY_END_TIME,
+                                                                       CONTEXT_HISTORY_FILTER_KEY_APP_ID, NULL};
+       static const char* group5[] = {CONTEXT_HISTORY_FILTER_KEY_RESULT_SIZE, CONTEXT_HISTORY_FILTER_KEY_START_TIME,
+                                                                       CONTEXT_HISTORY_FILTER_KEY_END_TIME, CONTEXT_HISTORY_FILTER_KEY_COMMUNICATION_TYPE, NULL};
+       static const char** const filter_arr[] = {group_common, group1, group2, group3, group4, group5};
+
+       int group;
+       switch (data_type) {
+       // Group1
+       case CONTEXT_HISTORY_RECENTLY_USED_APP:
+       case CONTEXT_HISTORY_FREQUENTLY_USED_APP:
+               group = GROUP1;
+               break;
+       // Group2
+       case CONTEXT_HISTORY_RARELY_USED_APP:
+               group = GROUP2;
+               break;
+       // Group3
+       case CONTEXT_HISTORY_PEAK_TIME_FOR_APP:
+       case CONTEXT_HISTORY_PEAK_TIME_FOR_MUSIC:
+       case CONTEXT_HISTORY_PEAK_TIME_FOR_VIDEO:
+               group = GROUP3;
+               break;
+       // Group4
+       case CONTEXT_HISTORY_COMMON_SETTING_FOR_APP:
+       case CONTEXT_HISTORY_COMMON_SETTING_FOR_MUSIC:
+       case CONTEXT_HISTORY_COMMON_SETTING_FOR_VIDEO:
+               group = GROUP4;
+               break;
+       // Group5
+       case CONTEXT_HISTORY_FREQUENTLY_COMMUNICATED_ADDRESS:
+               group = GROUP5;
+               break;
+       default:
+               return false;
+       }
+
+       bool found = true;
+       std::list<std::string> keys;
+       filter->jfilter.get_keys(&keys);
+
+       for (std::list<std::string>::iterator it = keys.begin(); it != keys.end(); ++it) {
+               std::string key = (*it);
+               found = false;
+               for (int i = 0; filter_arr[GROUP_COMMON][i] != NULL; i++) {
+                       if (key.compare(filter_arr[GROUP_COMMON][i]) == 0) {
+                               found = true;
+                               break;
+                       }
+               }
+               if (found == true) {
+                       continue;
+               }
+
+               for (int i = 0; filter_arr[group][i] != NULL; i++) {
+                       if (key.compare(filter_arr[group][i]) == 0) {
+                               found = true;
+                               break;
+                       }
+               }
+               if (found == false) {
+                       break;
+               }
+       }
+
+       return found;
+}
diff --git a/src/context_trigger.cpp b/src/context_trigger.cpp
new file mode 100644 (file)
index 0000000..4867e99
--- /dev/null
@@ -0,0 +1,955 @@
+/*
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ *
+ * 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 <sstream>
+//#include <iomanip>
+#include <types_internal.h>
+#include <json.h>
+#include <app_control_internal.h>
+#include <bundle.h>
+#include <bundle_internal.h>
+#include <context_trigger.h>
+#include <context_trigger_types_internal.h>
+#include <request_handler.h>
+#include "rule_validator.h"
+#include "priv_util.h"
+
+#define INITIAL_RULE "{ \"ID\" : -1, \"DESCRIPTION\" : \"\", \"DETAILS\" : {  } }"
+#define INITIAL_ENTRY "{ \"DATA_ARR\" : [ ] }"
+#define INITIAL_REF "{ \"option\" : [ ], \"attributes\" : [ ] }"
+#define QUOTATION_MARK_STRING std::string("\"")
+#define EVENT_DATA_KEY_PREFIX_STR std::string("?")
+//#define DOUBLE_PRECISION 2
+
+static std::string convert_event_to_string(context_trigger_event_e item);
+static std::string convert_condition_to_string(context_trigger_condition_e item);
+static std::string convert_logical_type_to_string(context_trigger_logical_type_e logical_type);
+static int convert_operator(std::string type, std::string op, std::string* converted_op);
+static std::string int_to_string(int value);
+//static std::string double_to_string(int value);
+
+typedef struct _context_trigger_rule_s {
+       ctx::json jrule;        // rule_id, description, details(event, condition[])
+       ctx::json jref;
+
+       _context_trigger_rule_s()
+       {
+               jrule = INITIAL_RULE;
+               jref = INITIAL_REF;
+       }
+} _context_trigger_rule_h;
+
+typedef struct _context_trigger_rule_entry_s {
+       ctx::json jentry;       // key, value, operator
+       int type;
+       ctx::json jref;
+
+       _context_trigger_rule_entry_s(int t): type(t)
+       {
+               jentry = INITIAL_ENTRY;
+
+               if (t == TYPE_CONDITION) {
+                       jref = INITIAL_REF;
+               }
+       }
+} _context_trigger_rule_entry_h;
+
+// Add a rule
+EXTAPI int context_trigger_add_rule(context_trigger_rule_h rule, int* rule_id)
+{
+       _D("BEGIN");
+       ASSERT_NOT_NULL(rule && rule_id);
+
+       // Err: No event
+       std::string ename;
+       bool ret = (rule->jrule).get(CT_RULE_DETAILS"."CT_RULE_EVENT, CT_RULE_EVENT_ITEM, &ename);
+       if (!ret)
+               return CONTEXT_TRIGGER_ERROR_INVALID_RULE;
+
+       // Err: No action added
+       std::string type;
+       ret = (rule->jrule).get(CT_RULE_DETAILS"."CT_RULE_ACTION, CT_RULE_ACTION_TYPE, &type);
+       if (!ret)
+               return CONTEXT_TRIGGER_ERROR_INVALID_RULE;
+
+       ctx::json jrule_id;
+       int error = ctx::request_handler::write_with_reply(CONTEXT_TRIGGER_SUBJECT_ADD, &(rule->jrule), &jrule_id);
+
+       if (error == ERR_NONE) {
+               jrule_id.get(NULL, CT_RULE_ID, rule_id);
+               (rule->jrule).set(NULL, CT_RULE_ID, *rule_id);
+       }
+
+       return error;
+}
+
+// Remove a rule
+EXTAPI int context_trigger_remove_rule(int rule_id)
+{
+       _D("BEGIN");
+       if (rule_id <= 0)
+               return CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER;
+
+       ctx::json jrule_id;
+       jrule_id.set(NULL, CT_RULE_ID, rule_id);
+       int error = ctx::request_handler::write_with_reply(CONTEXT_TRIGGER_SUBJECT_REMOVE, &jrule_id, NULL);
+
+       if (error == ERR_ALREADY_STARTED) {     // Rule is still enabled.
+               return CONTEXT_TRIGGER_ERROR_RULE_ENABLED;
+       } else if (error == ERR_NO_DATA) {
+               return CONTEXT_TRIGGER_ERROR_RULE_NOT_EXIST;
+       }
+
+       return error;
+}
+
+// Enable a rule
+EXTAPI int context_trigger_enable_rule(int rule_id)
+{
+       _D("BEGIN");
+       if (rule_id <= 0)
+               return CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER;
+
+       ctx::json jrule_id;
+       jrule_id.set(NULL, CT_RULE_ID, rule_id);
+
+       int req_id;     // Useless in context_trigger
+       int error = ctx::request_handler::subscribe(CONTEXT_TRIGGER_SUBJECT_ENABLE, &jrule_id, &req_id, NULL);
+
+       if (error == ERR_NO_DATA) {
+               return CONTEXT_TRIGGER_ERROR_RULE_NOT_EXIST;
+       }
+
+       return error;
+}
+
+// Disable a rule
+EXTAPI int context_trigger_disable_rule(int rule_id)
+{
+       _D("BEGIN");
+       if (rule_id <= 0)
+               return CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER;
+
+       ctx::json jrule_id;
+       jrule_id.set(NULL, CT_RULE_ID, rule_id);
+       int error = ctx::request_handler::write_with_reply(CONTEXT_TRIGGER_SUBJECT_DISABLE, &jrule_id, NULL);
+
+       if (error == ERR_NO_DATA) {
+               return CONTEXT_TRIGGER_ERROR_RULE_NOT_EXIST;
+       }
+
+       return error;
+}
+
+EXTAPI int context_trigger_get_own_rule_ids(int** enabled_rule_ids, int* enabled_rule_count, int** disabled_rule_ids, int* disabled_rule_count)
+{
+       _D("BEGIN");
+       ASSERT_NOT_NULL(enabled_rule_ids && enabled_rule_count && disabled_rule_ids && disabled_rule_count);
+
+       int req_id;
+       ctx::json data_read;
+       int error = ctx::request_handler::read_sync(CONTEXT_TRIGGER_SUBJECT_GET_RULE_IDS, NULL, &req_id, &data_read);
+
+       if (error != ERR_NONE) {
+               return error;
+       }
+
+       // Enabled rules
+       int* e_arr = NULL;
+       *enabled_rule_count = data_read.array_get_size(NULL, CT_RULE_ARRAY_ENABLED);
+
+       if (*enabled_rule_count > 0) {
+               e_arr = static_cast<int*>(g_malloc((*enabled_rule_count) * sizeof(int)));
+               IF_FAIL_RETURN_TAG(e_arr, CONTEXT_TRIGGER_ERROR_OUT_OF_MEMORY, _E, "Memory allocation failed");
+
+               int id;
+               for (int i = 0; data_read.get_array_elem(NULL, CT_RULE_ARRAY_ENABLED, i, &id); i++) {
+                       *(e_arr + i) = id;
+               }
+       }
+       *enabled_rule_ids = e_arr;
+
+       // Disabled rules
+       int* d_arr = NULL;
+       *disabled_rule_count = data_read.array_get_size(NULL, CT_RULE_ARRAY_DISABLED);
+
+       if (*disabled_rule_count > 0) {
+               d_arr = static_cast<int*>(g_malloc((*disabled_rule_count) * sizeof(int)));
+               IF_FAIL_RETURN_TAG(d_arr, CONTEXT_TRIGGER_ERROR_OUT_OF_MEMORY, _E, "Memory allocation failed");
+
+               int id;
+               for (int i = 0; data_read.get_array_elem(NULL, CT_RULE_ARRAY_DISABLED, i, &id); i++) {
+                       *(d_arr + i) = id;
+               }
+       }
+       *disabled_rule_ids = d_arr;
+
+       return error;
+}
+
+EXTAPI int context_trigger_get_rule_by_id(int rule_id, context_trigger_rule_h* rule)
+{
+       _D("BEGIN");
+       ASSERT_NOT_NULL(rule);
+       if (rule_id <= 0)
+               return CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER;
+
+       ctx::json option;
+       option.set(NULL, CT_RULE_ID, rule_id);
+
+       int req_id;
+       ctx::json data_read;
+       int error = ctx::request_handler::read_sync(CONTEXT_TRIGGER_SUBJECT_GET, &option, &req_id, &data_read);
+
+       if (error == ERR_NO_DATA) {
+               return CONTEXT_TRIGGER_ERROR_RULE_NOT_EXIST;
+       } else if (error != ERR_NONE) {
+               return error;
+       }
+
+       *rule = new(std::nothrow) _context_trigger_rule_h();
+       (*rule)->jrule = data_read;
+
+       return ERR_NONE;
+}
+
+// Rule creation
+EXTAPI int context_trigger_rule_create(context_trigger_logical_type_e logical_type, context_trigger_rule_h* rule)
+{
+       _D("BEGIN");
+       ASSERT_NOT_NULL(rule);
+
+       std::string logical_str = convert_logical_type_to_string(logical_type);
+       if (logical_str.empty()) {
+               return CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER;
+       }
+
+       *rule = new(std::nothrow) _context_trigger_rule_h();
+       (*rule)->jrule.set(CT_RULE_DETAILS, CT_RULE_OPERATOR, logical_str);
+
+       return ERR_NONE;
+}
+
+// Rule deletion
+EXTAPI int context_trigger_rule_destroy(context_trigger_rule_h rule)
+{
+       _D("BEGIN");
+       ASSERT_NOT_NULL(rule);
+       delete rule;
+
+       return CONTEXT_TRIGGER_ERROR_NONE;
+}
+
+
+EXTAPI int context_trigger_rule_add_entry(context_trigger_rule_h rule, context_trigger_rule_entry_h entry)
+{
+       _D("BEGIN");
+       ASSERT_NOT_NULL(rule && entry);
+
+       std::string des;
+       bool ret = (rule->jrule).get(NULL, CT_RULE_DESCRIPTION, &des);
+       IF_FAIL_RETURN(ret, CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER);
+
+       if (entry->type == TYPE_EVENT) {
+               // Err: More than one event
+               ctx::json elem;
+               if ((rule->jrule).get(CT_RULE_DETAILS, CT_RULE_EVENT, &elem)) {
+                       return CONTEXT_TRIGGER_ERROR_INVALID_RULE;
+               }
+
+               // Err: Check if all the mandatory options are added
+               ret = ctx::rule_validator::check_option(entry->jentry);
+               IF_FAIL_RETURN(ret, CONTEXT_TRIGGER_ERROR_INVALID_RULE);
+
+               // Err: If referential conditions are registered priviously, check them
+               std::string ename;
+               (entry->jentry).get(NULL, CT_RULE_EVENT_ITEM, &ename);
+               ret = ctx::rule_validator::check_referential_data(ename, rule->jref);
+               IF_FAIL_RETURN(ret, CONTEXT_TRIGGER_ERROR_INVALID_RULE);
+
+               ctx::json temp = (entry->jentry).str();
+               ret = (rule->jrule).set(CT_RULE_DETAILS, CT_RULE_EVENT, temp);
+       } else if (entry->type == TYPE_CONDITION) {
+               // Err: Condition without comparison data
+               if ((entry->jentry).array_get_size(NULL, CT_RULE_DATA_ARR) < 1) {
+                       return CONTEXT_TRIGGER_ERROR_INVALID_RULE;
+               }
+
+               ctx::json elem;
+               for (int i = 0; (entry->jentry).get_array_elem(NULL, CT_RULE_DATA_ARR, i, &elem); i++) {
+                       int val_arr_size = elem.array_get_size(NULL, CT_RULE_DATA_VALUE_ARR);
+                       int op_arr_size = elem.array_get_size(NULL, CT_RULE_DATA_VALUE_OPERATOR_ARR);
+
+                       // Err: Condition without comparison data
+                       if (val_arr_size != op_arr_size || val_arr_size < 1 || op_arr_size < 1) {
+                               return CONTEXT_TRIGGER_ERROR_INVALID_RULE;
+                       }
+
+                       // Err: Check if all the mandatory options are added
+                       ret = ctx::rule_validator::check_option(entry->jentry);
+                       IF_FAIL_RETURN(ret, CONTEXT_TRIGGER_ERROR_INVALID_RULE);
+
+                       // If event is already added ....
+                       std::string ename;
+                       ret = (rule->jrule).get(CT_RULE_DETAILS "." CT_RULE_EVENT, CT_RULE_EVENT_ITEM, &ename);
+                       if (ret) {
+                               // Err: Check referential information if exists
+                               ret = ctx::rule_validator::check_referential_data(ename, entry->jref);
+                               IF_FAIL_RETURN(ret, CONTEXT_TRIGGER_ERROR_INVALID_RULE);
+                       } else {
+                               // If not, copy referential information to rule entry
+                               ctx::json info;
+                               for (int j = 0; (entry->jref).get_array_elem(NULL, TYPE_OPTION_STR, j, &info); j++) {
+                                       (rule->jref).array_append(NULL, TYPE_OPTION_STR, info);
+                               }
+
+                               for (int j = 0; (entry->jref).get_array_elem(NULL, TYPE_ATTR_STR, j, &info); j++) {
+                                       (rule->jref).array_append(NULL, TYPE_ATTR_STR, info);
+                               }
+                       }
+               }
+
+               ctx::json temp = (entry->jentry).str();
+               ret = (rule->jrule).array_append(CT_RULE_DETAILS, CT_RULE_CONDITION, temp);
+       } else {
+               // Entry is not created
+               return CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER;
+       }
+
+       IF_FAIL_RETURN(ret, CONTEXT_TRIGGER_ERROR_OPERATION_FAILED);
+       return CONTEXT_TRIGGER_ERROR_NONE;
+}
+
+static bool is_call_operation(app_control_h app_control)
+{
+       char *op = NULL;
+       int err = app_control_get_operation(app_control, &op);
+       IF_FAIL_RETURN_TAG(err == APP_CONTROL_ERROR_NONE, false, _W, "Getting operation of app control failed");
+
+       bool ret = STR_EQ(op, APP_CONTROL_OPERATION_CALL);
+       g_free(op);
+
+       return ret;
+}
+
+EXTAPI int context_trigger_rule_set_action_app_control(context_trigger_rule_h rule, app_control_h app_control)
+{
+       _D("BEGIN");
+       ASSERT_NOT_NULL(rule && app_control);
+       int error;
+
+       // Privilege check
+       error = ctx::privilege_util::is_allowed("http://tizen.org/privilege/appmanager.launch");
+       IF_FAIL_RETURN_TAG(error == ERR_NONE, error, _E, "Privilege checking failed (%#x)", error);
+
+       if (is_call_operation(app_control)) {
+               error = ctx::privilege_util::is_allowed("http://tizen.org/privilege/call");
+               IF_FAIL_RETURN_TAG(error == ERR_NONE, error, _E, "Privilege checking failed (%#x)", error);
+       }
+
+       // Err: if action arleady exists
+       std::string type;
+       if ((rule->jrule).get(CT_RULE_DETAILS"."CT_RULE_ACTION, CT_RULE_ACTION_TYPE, &type)) {
+               return CONTEXT_TRIGGER_ERROR_INVALID_RULE;
+       }
+
+       (rule->jrule).set(CT_RULE_DETAILS"."CT_RULE_ACTION, CT_RULE_ACTION_TYPE, CT_RULE_ACTION_TYPE_APP_CONTROL);
+
+       // Set app control
+       bundle* appctl_bundle = NULL;
+       error = app_control_to_bundle(app_control, &appctl_bundle);
+       IF_FAIL_RETURN_TAG(error == ERR_NONE, CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER, _E, "App_control to bundle failed");
+
+       bundle_raw* appctl_raw;
+       int raw_length;
+       error = bundle_encode(appctl_bundle, &appctl_raw, &raw_length);
+       IF_FAIL_RETURN_TAG(error == ERR_NONE, CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER, _E, "Bundle encode failed");
+
+       std::string appctl_str = reinterpret_cast<const char*>(appctl_raw);
+       (rule->jrule).set(CT_RULE_DETAILS"."CT_RULE_ACTION, CT_RULE_ACTION_APP_CONTROL, appctl_str);
+
+       bundle_free_encoded_rawdata(&appctl_raw);
+
+       return CONTEXT_TRIGGER_ERROR_NONE;
+}
+
+EXTAPI int context_trigger_rule_set_action_notification(context_trigger_rule_h rule, const char* title, const char* content, const char* icon_path, app_control_h app_control)
+{
+       _D("BEGIN");
+       ASSERT_NOT_NULL(rule && title && content);
+
+       // Privilege check
+       int error = ctx::privilege_util::is_allowed("http://tizen.org/privilege/notification");
+       IF_FAIL_RETURN_TAG(error == ERR_NONE, error, _E, "Privilege checking failed (%#x)", error);
+
+       // if action arleady exists
+       std::string type;
+       if ((rule->jrule).get(CT_RULE_DETAILS"."CT_RULE_ACTION, CT_RULE_ACTION_TYPE, &type)) {
+               return CONTEXT_TRIGGER_ERROR_INVALID_RULE;
+       }
+
+       // Set title, content
+       (rule->jrule).set(CT_RULE_DETAILS"."CT_RULE_ACTION, CT_RULE_ACTION_TYPE, CT_RULE_ACTION_TYPE_NOTIFICATION);
+       (rule->jrule).set(CT_RULE_DETAILS"."CT_RULE_ACTION, CT_RULE_ACTION_NOTI_TITLE, title);
+       (rule->jrule).set(CT_RULE_DETAILS"."CT_RULE_ACTION, CT_RULE_ACTION_NOTI_CONTENT, content);
+
+       // Set icon path
+       if (icon_path) {
+               (rule->jrule).set(CT_RULE_DETAILS"."CT_RULE_ACTION, CT_RULE_ACTION_NOTI_ICON_PATH, icon_path);
+       }
+
+       // Set app control
+       if (app_control) {
+               bundle* appctl_bundle = NULL;
+               error = app_control_to_bundle(app_control, &appctl_bundle);
+               IF_FAIL_RETURN_TAG(error == ERR_NONE, CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER, _E, "App_control to bundle failed");
+
+               bundle_raw* appctl_raw;
+               int raw_length;
+               error = bundle_encode(appctl_bundle, &appctl_raw, &raw_length);
+               IF_FAIL_RETURN_TAG(error == ERR_NONE, CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER, _E, "Bundle encode failed");
+
+               std::string appctl_str = reinterpret_cast<const char*>(appctl_raw);
+               (rule->jrule).set(CT_RULE_DETAILS"."CT_RULE_ACTION, CT_RULE_ACTION_APP_CONTROL, appctl_str);
+
+               bundle_free_encoded_rawdata(&appctl_raw);
+       }
+
+       return CONTEXT_TRIGGER_ERROR_NONE;
+}
+
+// Set description
+EXTAPI int context_trigger_rule_set_description(context_trigger_rule_h rule, const char* description)
+{
+       _D("BEGIN");
+       ASSERT_NOT_NULL(rule);
+
+       (rule->jrule).set(NULL, CT_RULE_DESCRIPTION, description);
+
+       return CONTEXT_TRIGGER_ERROR_NONE;
+}
+
+// Get rule description
+EXTAPI int context_trigger_rule_get_description(context_trigger_rule_h rule, char** description)
+{
+       _D("BEGIN");
+       ASSERT_NOT_NULL(rule && description);
+
+       std::string val;
+       (rule->jrule).get(NULL, CT_RULE_DESCRIPTION, &val);
+
+       *description = strdup(val.c_str());
+
+       return CONTEXT_TRIGGER_ERROR_NONE;
+}
+
+// Event creation
+EXTAPI int context_trigger_rule_event_create(context_trigger_event_e event_item, context_trigger_logical_type_e logical_type, context_trigger_rule_entry_h* entry)
+{
+       _D("BEGIN");
+       ASSERT_NOT_NULL(entry);
+
+       std::string eitem_str = convert_event_to_string(event_item);
+       if (eitem_str.empty()) {
+               return CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER;
+       }
+
+       std::string logical_str = convert_logical_type_to_string(logical_type);
+       if (logical_str.empty()) {
+               return CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER;
+       }
+
+       *entry = new(std::nothrow) _context_trigger_rule_entry_h(TYPE_EVENT);
+       (*entry)->jentry.set(NULL, CT_RULE_EVENT_ITEM, eitem_str);
+       (*entry)->jentry.set(NULL, CT_RULE_EVENT_OPERATOR, logical_str);
+
+       return CONTEXT_TRIGGER_ERROR_NONE;
+}
+
+// Event availability check
+EXTAPI int context_trigger_rule_event_is_supported(context_trigger_event_e event_item, bool* supported)
+{
+       _D("BEGIN");
+       ASSERT_NOT_NULL(supported);
+
+       if (event_item == CONTEXT_TRIGGER_EVENT_TIME) {
+               *supported = true;
+               return CONTEXT_TRIGGER_ERROR_NONE;
+       }
+
+       *supported = false;
+
+       std::string eitem_str = convert_event_to_string(event_item);
+       if (eitem_str.empty()) {
+               return CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER;
+       }
+
+       int error = ctx::request_handler::is_supported(eitem_str.c_str());
+
+       if (error == ERR_NONE)
+               *supported = true;
+
+       if (error == ERR_NOT_SUPPORTED)
+               return ERR_NONE;
+
+       return error;
+}
+
+// Condition creation
+EXTAPI int context_trigger_rule_condition_create(context_trigger_condition_e condition_item, context_trigger_logical_type_e logical_type, context_trigger_rule_entry_h* entry)
+{
+       _D("BEGIN");
+       ASSERT_NOT_NULL(entry);
+
+       std::string citem_str = convert_condition_to_string(condition_item);
+       if (citem_str.empty()) {
+               return CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER;
+       }
+
+       std::string logical_str = convert_logical_type_to_string(logical_type);
+       if (logical_str.empty()) {
+               return CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER;
+       }
+
+       *entry = new(std::nothrow) _context_trigger_rule_entry_h(TYPE_CONDITION);
+       (*entry)->jentry.set(NULL, CT_RULE_CONDITION_ITEM, citem_str);
+       (*entry)->jentry.set(NULL, CT_RULE_CONDITION_OPERATOR, logical_str);
+
+       return CONTEXT_TRIGGER_ERROR_NONE;
+}
+
+// Condition availability check
+EXTAPI int context_trigger_rule_condition_is_supported(context_trigger_condition_e condition_item, bool* supported)
+{
+       _D("BEGIN");
+       ASSERT_NOT_NULL(supported);
+
+       if (condition_item == CONTEXT_TRIGGER_CONDITION_TIME) {
+               *supported = true;
+               return CONTEXT_TRIGGER_ERROR_NONE;
+       }
+
+       *supported = false;
+
+       std::string citem_str = convert_condition_to_string(condition_item);
+       if (citem_str.empty()) {
+               return CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER;
+       }
+
+       int error = ctx::request_handler::is_supported(citem_str.c_str());
+
+       if (error == ERR_NONE)
+               *supported = true;
+
+       if (error == ERR_NOT_SUPPORTED)
+               return ERR_NONE;
+
+       return error;
+}
+
+// Rule data deletion
+EXTAPI int context_trigger_rule_entry_destroy(context_trigger_rule_entry_h entry)
+{
+       _D("BEGIN");
+       ASSERT_NOT_NULL(entry);
+       delete entry;
+
+       return CONTEXT_TRIGGER_ERROR_NONE;
+}
+
+EXTAPI int context_trigger_rule_entry_add_option_int(context_trigger_rule_entry_h entry, const char* option_key, int value)
+{
+       _D("BEGIN");
+       ASSERT_NOT_NULL(entry && option_key);
+
+       bool ret = true;
+       std::string name;
+       (entry->jentry).get(NULL, CT_RULE_CONDITION_ITEM, &name);
+       ret = ctx::rule_validator::check_option_int(name, option_key, value);
+       if (!ret) {
+               return CONTEXT_TRIGGER_ERROR_INVALID_RULE;
+       }
+
+       (entry->jentry).set(CT_RULE_CONDITION_OPTION, option_key, value);
+
+       return CONTEXT_TRIGGER_ERROR_NONE;
+}
+
+EXTAPI int context_trigger_rule_entry_add_option_string(context_trigger_rule_entry_h entry, const char* option_key, const char* value)
+{
+       _D("BEGIN");
+       ASSERT_NOT_NULL(entry && option_key && value);
+
+       bool ret = true;
+       std::string name;
+       (entry->jentry).get(NULL, CT_RULE_CONDITION_ITEM, &name);
+       ret = ctx::rule_validator::check_option_string(name, option_key, value);
+       if (!ret) {
+               return CONTEXT_TRIGGER_ERROR_INVALID_RULE;
+       }
+
+       (entry->jentry).set(CT_RULE_CONDITION_OPTION, option_key, value);
+
+       return CONTEXT_TRIGGER_ERROR_NONE;
+}
+
+EXTAPI int context_trigger_rule_entry_add_option(context_trigger_rule_entry_h entry, const char* option_key, const char* event_data_key)
+{
+       _D("BEGIN");
+       ASSERT_NOT_NULL(entry && option_key && event_data_key);
+
+       // Err: Only conditin can reference data from event
+       if (entry->type != TYPE_CONDITION) {
+               return CONTEXT_TRIGGER_ERROR_INVALID_RULE;
+       }
+
+       std::string name;
+       (entry->jentry).get(NULL, CT_RULE_CONDITION_ITEM, &name);
+
+       // Err: Check if key is valid
+       bool ret = ctx::rule_validator::check_valid_key(TYPE_OPTION, name, option_key);
+       IF_FAIL_RETURN(ret, CONTEXT_TRIGGER_ERROR_INVALID_RULE);
+
+       // Set reference information
+       ret = ctx::rule_validator::set_ref_info(TYPE_OPTION, &(entry->jref), name, option_key, event_data_key);
+       IF_FAIL_RETURN(ret, CONTEXT_TRIGGER_ERROR_OPERATION_FAILED);
+
+       (entry->jentry).set(CT_RULE_CONDITION_OPTION, option_key, EVENT_DATA_KEY_PREFIX_STR + std::string(event_data_key));
+
+       return CONTEXT_TRIGGER_ERROR_NONE;
+}
+
+EXTAPI int context_trigger_rule_entry_add_key(context_trigger_rule_entry_h entry, context_trigger_logical_type_e logical_type, const char* key)
+{
+       _D("BEGIN");
+       ASSERT_NOT_NULL(entry && key);
+
+       std::string logical_str = convert_logical_type_to_string(logical_type);
+       if (logical_str.empty()) {
+               return CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER;
+       }
+
+       // Err: Check if key is valid
+       std::string name;
+       (entry->jentry).get(NULL, CT_RULE_EVENT_ITEM, &name);
+       bool ret = ctx::rule_validator::check_valid_key(TYPE_ATTR, name, key);
+       IF_FAIL_RETURN(ret, CONTEXT_TRIGGER_ERROR_INVALID_RULE);
+
+       ctx::json elem;
+       for (int i = 0; (entry->jentry).get_array_elem(NULL, CT_RULE_DATA_ARR, i, &elem); i++) {
+               std::string elem_item;
+               elem.get(NULL, CT_RULE_DATA_KEY, &elem_item);
+               // Err: Comparison key is already added
+               if (elem_item.compare(key) == 0) {
+                       return CONTEXT_TRIGGER_ERROR_INVALID_RULE;
+               }
+       }
+
+       ctx::json data;
+       data.set(NULL, CT_RULE_DATA_KEY, key);
+       data.set(NULL, CT_RULE_DATA_KEY_OPERATOR, logical_str);
+       (entry->jentry).array_append(NULL, CT_RULE_DATA_ARR, data);
+
+       return CONTEXT_TRIGGER_ERROR_NONE;
+}
+
+static int context_trigger_rule_entry_add_comparison_internal(context_trigger_rule_entry_h entry, const char* key, std::string op, std::string value)
+{
+       ctx::json elem;
+       for (int i = 0; (entry->jentry).get_array_elem(NULL, CT_RULE_DATA_ARR, i, &elem); i++) {
+               std::string elem_item;
+               elem.get(NULL, CT_RULE_DATA_KEY, &elem_item);
+
+               if (elem_item.compare(key) == 0) {
+                       std::string elem_val;
+                       std::string elem_op;
+                       for (int j = 0; elem.get_array_elem(NULL, CT_RULE_DATA_VALUE_ARR, j, &elem_val); j++) {
+                               elem.get_array_elem(NULL, CT_RULE_DATA_VALUE_OPERATOR_ARR, j, &elem_op);
+
+                               // Err: Duplicated <operator, value>
+                               if (elem_val.compare(value) == 0 && elem_op.compare(op) == 0) {
+                                       return CONTEXT_TRIGGER_ERROR_INVALID_RULE;
+                               }
+                       }
+                       elem.array_append(NULL, CT_RULE_DATA_VALUE_ARR, value.c_str());
+                       elem.array_append(NULL, CT_RULE_DATA_VALUE_OPERATOR_ARR, op);
+                       (entry->jentry).array_set_at(NULL, CT_RULE_DATA_ARR, i, elem);
+
+                       return CONTEXT_TRIGGER_ERROR_NONE;
+               }
+       }
+
+       // Comparison key not exist
+       return CONTEXT_TRIGGER_ERROR_NO_DATA;
+}
+
+EXTAPI int context_trigger_rule_entry_add_comparison(context_trigger_rule_entry_h entry, const char* key, const char* op, const char* event_data_key)
+{
+       _D("BEGIN");
+       ASSERT_NOT_NULL(entry && key && op && event_data_key);
+
+       // Err: Only condition can reference data from event
+       if (entry->type != TYPE_CONDITION) {
+               return CONTEXT_TRIGGER_ERROR_INVALID_RULE;
+       }
+
+       std::string name;
+       (entry->jentry).get(NULL, CT_RULE_CONDITION_ITEM, &name);
+
+       // Err: Check if key is valid
+       bool ret = ctx::rule_validator::check_valid_key(TYPE_ATTR, name, key);
+       IF_FAIL_RETURN(ret, CONTEXT_TRIGGER_ERROR_INVALID_RULE);
+
+       int type = ctx::rule_validator::get_data_type(TYPE_ATTR, name, key);
+       std::string type_str = (type == TYPE_INT)? "int" : "string";
+
+       int error;
+       std::string converted_op;
+       error = convert_operator(type_str, op, &converted_op);  // Err: Invalid operator
+       if (error != ERR_NONE){
+               return error;
+       }
+
+       error = context_trigger_rule_entry_add_comparison_internal(entry, key, converted_op, EVENT_DATA_KEY_PREFIX_STR + std::string(event_data_key));
+       if (error != ERR_NONE)
+               return error;
+
+       // Set reference information
+       ret = ctx::rule_validator::set_ref_info(TYPE_ATTR, &(entry->jref), name, key, event_data_key);
+       IF_FAIL_RETURN(ret, CONTEXT_TRIGGER_ERROR_OPERATION_FAILED);
+
+       return CONTEXT_TRIGGER_ERROR_NONE;
+}
+
+EXTAPI int context_trigger_rule_entry_add_comparison_int(context_trigger_rule_entry_h entry, const char* key, const char* op, int value)
+{
+       _D("BEGIN");
+       ASSERT_NOT_NULL(entry && key && op);
+
+       int error;
+       std::string converted_op;
+
+       std::string name;
+       (entry->jentry).get(NULL, CT_RULE_EVENT_ITEM, &name);
+
+       bool ret = ctx::rule_validator::check_comparison_int(name, key, op, value);
+       IF_FAIL_RETURN(ret, CONTEXT_TRIGGER_ERROR_INVALID_RULE);
+
+       error = convert_operator("int", op, &converted_op);     // Err: Invalid operator
+       if (error != ERR_NONE){
+               return error;
+       }
+
+       error = context_trigger_rule_entry_add_comparison_internal(entry, key, converted_op, int_to_string(value));
+       return error;
+}
+/*
+EXTAPI int context_trigger_rule_entry_add_comparison_double(context_trigger_rule_entry_h entry, const char* key, const char* op, double value)
+{
+       ASSERT_NOT_NULL(entry && key && op);
+
+       int error;
+       std::string converted_op;
+
+       error = convert_operator("double", op, &converted_op);  // Err: Invalid operator
+       if (error != ERR_NONE){
+               return error;
+       }
+
+       error = context_trigger_rule_entry_add_comparison_internal(entry, key, converted_op, double_to_string(value));
+       return error;
+}
+*/
+EXTAPI int context_trigger_rule_entry_add_comparison_string(context_trigger_rule_entry_h entry, const char* key, const char* op, const char* value)
+{
+       _D("BEGIN");
+       ASSERT_NOT_NULL(entry && key && op && value);
+
+       int error;
+       std::string converted_op;
+
+       std::string name;
+       (entry->jentry).get(NULL, CT_RULE_EVENT_ITEM, &name);
+
+       bool ret = ctx::rule_validator::check_comparison_string(name, key, op, value);
+       IF_FAIL_RETURN(ret, CONTEXT_TRIGGER_ERROR_INVALID_RULE);
+
+       error = convert_operator("string", op, &converted_op);  // Err: Invalid operator
+       if (error != ERR_NONE){
+               return error;
+       }
+
+       error = context_trigger_rule_entry_add_comparison_internal(entry, key, converted_op, QUOTATION_MARK_STRING + value + QUOTATION_MARK_STRING);
+       return error;
+}
+
+std::string convert_event_to_string(context_trigger_event_e item)
+{
+       std::string str;
+       switch (item) {
+       case CONTEXT_TRIGGER_EVENT_TIME:
+               str = CT_EVENT_TIME;
+               break;
+       case CONTEXT_TRIGGER_EVENT_BATTERY:
+               str = CT_EVENT_BATTERY;
+               break;
+       case CONTEXT_TRIGGER_EVENT_CHARGER:
+               str = CT_EVENT_CHARGER;
+               break;
+       case CONTEXT_TRIGGER_EVENT_GPS:
+               str = CT_EVENT_GPS;
+               break;
+       case CONTEXT_TRIGGER_EVENT_HEADPHONE:
+               str = CT_EVENT_HEADPHONE;
+               break;
+       case CONTEXT_TRIGGER_EVENT_POWER_SAVING_MODE:
+               str = CT_EVENT_POWER_SAVING_MODE;
+               break;
+       case CONTEXT_TRIGGER_EVENT_USB:
+               str = CT_EVENT_USB;
+               break;
+       case CONTEXT_TRIGGER_EVENT_WIFI:
+               str = CT_EVENT_WIFI;
+               break;
+       case CONTEXT_TRIGGER_EVENT_CALL:
+               str = CT_EVENT_CALL;
+               break;
+       case CONTEXT_TRIGGER_EVENT_EMAIL:
+               str = CT_EVENT_EMAIL;
+               break;
+       case CONTEXT_TRIGGER_EVENT_MESSAGE:
+               str = CT_EVENT_MESSAGE;
+               break;
+       case CONTEXT_TRIGGER_EVENT_ACTIVITY_STATIONARY:
+               str = CT_EVENT_ACTIVITY_STATIONARY;
+               break;
+       case CONTEXT_TRIGGER_EVENT_ACTIVITY_WALKING:
+               str = CT_EVENT_ACTIVITY_WALKING;
+               break;
+       case CONTEXT_TRIGGER_EVENT_ACTIVITY_RUNNING:
+               str = CT_EVENT_ACTIVITY_RUNNING;
+               break;
+       case CONTEXT_TRIGGER_EVENT_ACTIVITY_IN_VEHICLE:
+               str = CT_EVENT_ACTIVITY_IN_VEHICLE;
+               break;
+       case CONTEXT_TRIGGER_EVENT_PLACE:
+               str = CT_EVENT_PLACE;
+               break;
+       default:
+               break;
+       }
+       return str;
+}
+
+std::string convert_condition_to_string(context_trigger_condition_e item)
+{
+       std::string str;
+       switch (item) {
+       case CONTEXT_TRIGGER_CONDITION_TIME:
+               str = CT_CONDITION_TIME;
+               break;
+       case CONTEXT_TRIGGER_CONDITION_BATTERY:
+               str = CT_CONDITION_BATTERY;
+               break;
+       case CONTEXT_TRIGGER_CONDITION_CHARGER:
+               str = CT_CONDITION_CHARGER;
+               break;
+       case CONTEXT_TRIGGER_CONDITION_GPS:
+               str = CT_CONDITION_GPS;
+               break;
+       case CONTEXT_TRIGGER_CONDITION_HEADPHONE:
+               str = CT_CONDITION_HEADPHONE;
+               break;
+       case CONTEXT_TRIGGER_CONDITION_POWER_SAVING_MODE:
+               str = CT_CONDITION_POWER_SAVING_MODE;
+               break;
+       case CONTEXT_TRIGGER_CONDITION_USB:
+               str = CT_CONDITION_USB;
+               break;
+       case CONTEXT_TRIGGER_CONDITION_WIFI:
+               str = CT_CONDITION_WIFI;
+               break;
+       case CONTEXT_TRIGGER_CONDITION_CALL:
+               str = CT_CONDITION_CALL;
+               break;
+       case CONTEXT_TRIGGER_CONDITION_APP_USE_FREQUENCY:
+               str = CT_CONDITION_APP_USE_FREQUENCY;
+               break;
+       case CONTEXT_TRIGGER_CONDITION_COMMUNICATION_FREQUENCY:
+               str = CT_CONDITION_COMMUNICATION_FREQUENCY;
+               break;
+       case CONTEXT_TRIGGER_CONDITION_MUSIC_PLAYBACK_FREQUENCY:
+               str = CT_CONDITION_MUSIC_PLAYBACK_FREQUENCY;
+               break;
+       case CONTEXT_TRIGGER_CONDITION_VIDEO_PLAYBACK_FREQUENCY:
+               str = CT_CONDITION_VIDEO_PLAYBACK_FREQUENCY;
+               break;
+       default:
+               break;
+       }
+       return str;
+}
+
+std::string convert_logical_type_to_string(context_trigger_logical_type_e logical_type)
+{
+       std::string str;
+       switch (logical_type) {
+       case CONTEXT_TRIGGER_LOGICAL_CONJUNCTION:
+               str = "and";
+               break;
+       case CONTEXT_TRIGGER_LOGICAL_DISJUNCTION:
+               str = "or";
+               break;
+       default:
+               break;
+       }
+       return str;
+}
+
+int convert_operator(std::string type, std::string op, std::string* converted_op)
+{
+       if (op.compare("==") == 0) {
+               *converted_op = "eq";
+               return CONTEXT_TRIGGER_ERROR_NONE;
+       } else if(op.compare("!=") == 0) {
+               *converted_op = "neq";
+               return CONTEXT_TRIGGER_ERROR_NONE;
+       }
+
+       if (type.compare("int") == 0 || type.compare("double") == 0) {
+               if (op.compare("<") == 0 || op.compare("<=") == 0 || op.compare(">") == 0 || op.compare(">=") == 0) {
+                       *converted_op = op;
+                       return CONTEXT_TRIGGER_ERROR_NONE;
+               }
+       }
+
+       return CONTEXT_TRIGGER_ERROR_INVALID_RULE;
+}
+
+std::string int_to_string(int value)
+{
+       std::ostringstream ostr;
+       ostr << value;
+       return ostr.str();
+}
+/*
+std::string double_to_string(int value)
+{
+       std::ostringstream ostr;
+       ostr.imbue(std::locale("C"));
+       ostr << std::setprecision(DOUBLE_PRECISION) << std::fixed << value;
+       return ostr.str();
+}*/
diff --git a/src/priv_util.cpp b/src/priv_util.cpp
new file mode 100644 (file)
index 0000000..ffee54b
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ *
+ * 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 <sys/types.h>
+#include <unistd.h>
+#include <aul.h>
+#include <pkgmgr-info.h>
+#include <privilege_checker.h>
+
+#include <types_internal.h>
+#include "priv_util.h"
+
+int ctx::privilege_util::is_allowed(const char* priv)
+{
+       int error;
+       char app_id[256];
+       error = aul_app_get_appid_bypid(getpid(), app_id, sizeof(app_id));
+       IF_FAIL_RETURN_TAG(error == AUL_R_OK, ERR_OPERATION_FAILED, _E, "Getting AppId failed");
+
+       pkgmgrinfo_appinfo_h app_info;
+       error = pkgmgrinfo_appinfo_get_appinfo(app_id, &app_info);
+       IF_FAIL_RETURN_TAG(error == PMINFO_R_OK, ERR_OPERATION_FAILED, _E, "Failed to get app_info");
+
+       char *pkg_name = NULL;
+       error = pkgmgrinfo_appinfo_get_pkgname(app_info, &pkg_name);
+       if (error != PMINFO_R_OK || pkg_name == NULL) {
+               pkgmgrinfo_appinfo_destroy_appinfo(app_info);
+               _E("Failed to get package name");
+               return ERR_OPERATION_FAILED;
+       }
+
+       error = privilege_checker_check_package_privilege(pkg_name, priv);
+       pkgmgrinfo_appinfo_destroy_appinfo(app_info);
+
+       _D("Privilege checking result: %d", error);
+
+       if (error == PRIV_CHECKER_ERR_NONE) {
+               return ERR_NONE;
+       }
+
+       if (error == PRIV_CHECKER_ERR_INVALID_PRIVILEGE) {
+               return ERR_PERMISSION_DENIED;
+       }
+
+       return ERR_OPERATION_FAILED;
+}
diff --git a/src/priv_util.h b/src/priv_util.h
new file mode 100644 (file)
index 0000000..6ef1109
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ *
+ * 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 __CONTEXT_PRIVILEGE_UTIL_H__
+#define __CONTEXT_PRIVILEGE_UTIL_H__
+
+#include <string>
+
+namespace ctx {
+       namespace privilege_util {
+
+               int is_allowed(const char* priv);
+
+       }
+}      /* namespace ctx */
+
+#endif /* __CONTEXT_PRIVILEGE_UTIL_H__ */
diff --git a/src/rule_info.h b/src/rule_info.h
new file mode 100644 (file)
index 0000000..aaac67c
--- /dev/null
@@ -0,0 +1,129 @@
+/*
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ *
+ * 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 __CONTEXT_RULE_INFO_H__
+#define __CONTEXT_RULE_INFO_H__
+
+#define RULE_INFO "{ \"templates\": [\
+               {\
+                       \"name\": \"timer/event\",\
+                       \"attributes\": [ { \"key\": \"TimeOfDay\", \"type\": 1, \"min\": 0, \"max\": 1439}, { \"key\": \"DayOfWeek\", \"type\": 2, \"acceptable\": [ \"Mon\", \"Tue\", \"Wed\", \"Thu\", \"Fri\", \"Sat\", \"Sun\", \"Weekday\", \"Weekend\" ] } ]\
+               },\
+               {\
+                       \"name\": \"timer/state\",\
+                       \"attributes\": [ { \"key\": \"TimeOfDay\", \"type\": 1, \"min\": 0, \"max\": 1439}, { \"key\": \"DayOfWeek\", \"type\": 2, \"acceptable\": [ \"Mon\", \"Tue\", \"Wed\", \"Thu\", \"Fri\", \"Sat\", \"Sun\", \"Weekday\", \"Weekend\" ] }, { \"key\" : \"DayOfMonth\", \"type\": 1, \"min\": 1, \"max\": 31} ]\
+               },\
+               {\
+                       \"name\": \"system/state/battery\",\
+                       \"attributes\": [ { \"key\" : \"Level\", \"type\": 2, \"acceptable\": [ \"Empty\", \"Critical\", \"Low\", \"Normal\", \"High\", \"Full\" ] }, { \"key\": \"IsCharging\", \"type\": 1, \"min\": 0, \"max\": 1 } ]\
+               },\
+               {\
+                       \"name\": \"system/state/charger\",\
+                       \"attributes\": [ { \"key\": \"IsConnected\", \"type\": 1, \"min\": 0, \"max\": 1 } ]\
+               },\
+               {\
+                       \"name\": \"system/state/flight_mode\",\
+                       \"attributes\": [ { \"key\": \"IsEnabled\", \"type\": 1, \"min\": 0, \"max\": 1 } ]\
+               },\
+               {\
+                       \"name\": \"system/state/gps\",\
+                       \"attributes\": [ { \"key\" : \"State\", \"type\": 2, \"acceptable\": [ \"Disabled\", \"Searching\", \"Connected\" ] } ]\
+               },\
+               {\
+                       \"name\": \"system/state/headphone\",\
+                       \"attributes\": [{ \"key\": \"IsConnected\", \"type\": 1, \"min\": 0, \"max\": 1 }, { \"key\": \"Type\", \"type\": 2, \"acceptable\": [ \"Normal\", \"Headset\", \"Bluetooth\" ] } ]\
+               },\
+               {\
+                       \"name\": \"system/state/ps_mode\",\
+                       \"attributes\": [ { \"key\": \"IsEnabled\", \"type\": 1, \"min\": 0, \"max\": 1 } ]\
+               },\
+               {\
+                       \"name\": \"system/state/silent_mode\",\
+                       \"attributes\": [ { \"key\": \"IsEnabled\", \"type\": 1, \"min\": 0, \"max\": 1 } ]\
+               },\
+               {\
+                       \"name\": \"system/state/vibration_mode\",\
+                       \"attributes\": [ { \"key\": \"IsEnabled\", \"type\": 1, \"min\": 0, \"max\": 1 } ]\
+               },\
+               {\
+                       \"name\": \"system/state/usb\",\
+                       \"attributes\": [ { \"key\": \"IsConnected\", \"type\": 1, \"min\": 0, \"max\": 1 } ]\
+               },\
+               {\
+                       \"name\": \"system/state/wifi\",\
+                       \"attributes\": [ { \"key\" : \"State\", \"type\": 2, \"acceptable\": [ \"Disabled\", \"Unconnected\", \"Connected\" ] }, { \"key\": \"BSSID\", \"type\": 2, \"acceptable\": [ ] } ]\
+               },\
+               {\
+                       \"name\": \"social/state/call\",\
+                       \"attributes\": [ { \"key\" : \"Medium\", \"type\": 2, \"acceptable\": [ \"Voice\", \"Video\" ] }, { \"key\" : \"State\", \"type\": 2, \"acceptable\": [ \"Idle\", \"Connecting\", \"Connected\" ] }, { \"key\": \"Address\", \"type\": 2, \"acceptable\": [ ] } ]\
+               },\
+               {\
+                       \"name\": \"social/event/email\",\
+                       \"attributes\": [ { \"key\": \"Event\", \"type\": 2, \"acceptable\": [ \"Received\", \"Sent\" ] } ]\
+               },\
+               {\
+                       \"name\": \"social/event/message\",\
+                       \"attributes\": [ { \"key\": \"Event\", \"type\": 2, \"acceptable\": [ \"Received\" ] } , { \"key\": \"Type\", \"type\": 2, \"acceptable\": [ \"SMS\", \"MMS\" ] }, { \"key\": \"Address\", \"type\": 2, \"acceptable\": [ ] } ]\
+               },\
+               {\
+                       \"name\": \"activity/event/stationary\",\
+                       \"attributes\": [ { \"key\": \"Event\", \"type\": 2, \"acceptable\": [ \"Detected\" ] }, { \"key\": \"Accuracy\", \"type\": 2, \"acceptable\": [ \"High\", \"Normal\", \"Low\" ] } ]\
+               },\
+               {\
+                       \"name\": \"activity/event/walking\",\
+                       \"attributes\": [ { \"key\": \"Event\", \"type\": 2, \"acceptable\": [ \"Detected\" ] }, { \"key\": \"Accuracy\", \"type\": 2, \"acceptable\": [ \"High\", \"Normal\", \"Low\" ] } ]\
+               },\
+               {\
+                       \"name\": \"activity/event/running\",\
+                       \"attributes\": [ { \"key\": \"Event\", \"type\": 2, \"acceptable\": [ \"Detected\" ] }, { \"key\": \"Accuracy\", \"type\": 2, \"acceptable\": [ \"High\", \"Normal\", \"Low\" ] } ]\
+               },\
+               {\
+                       \"name\": \"activity/event/in_vehicle\",\
+                       \"attributes\": [ { \"key\": \"Event\", \"type\": 2, \"acceptable\": [ \"Detected\" ] }, { \"key\": \"Accuracy\", \"type\": 2, \"acceptable\": [ \"High\", \"Normal\", \"Low\" ] } ]\
+               },\
+               {\
+                       \"name\": \"place/event/geofence\",\
+                       \"attributes\": [ { \"key\": \"Event\", \"type\": 2, \"acceptable\": [ \"In\", \"Out\" ] } ],\
+                       \"option\": [ { \"key\": \"PlaceId\", \"type\": 1, \"min\": 1, \"max\": -1 } ]\
+               },\
+               {\
+                       \"name\": \"app/history/use_freq\",\
+                       \"attributes\": [ { \"key\": \"Rank\", \"type\": 1, \"min\": 1, \"max\": -1 }, { \"key\": \"TotalCount\", \"type\": 1, \"min\": 0, \"max\": -1 } ],\
+                       \"option\": [  { \"key\": \"AppId\", \"type\": 2, \"acceptable\": [ ] }, { \"key\": \"TimeOfDay\", \"type\": 2, \"acceptable\": [ ] }, { \"key\": \"DayOfWeek\", \"type\": 2, \"acceptable\": [ \"Mon\", \"Tue\", \"Wed\", \"Thu\", \"Fri\", \"Sat\", \"Sun\", \"Weekday\", \"Weekend\" ] } ]\
+               },\
+               {\
+                       \"name\": \"contact/history/comm_freq\",\
+                       \"attributes\": [ { \"key\": \"Rank\", \"type\": 1, \"min\": 1, \"max\": -1 }, { \"key\": \"TotalCount\", \"type\": 1, \"min\": 0, \"max\": -1 } ],\
+                       \"option\": [  { \"key\": \"Address\", \"type\": 2, \"acceptable\": [ ] }, { \"key\": \"TimeOfDay\", \"type\": 2, \"acceptable\": [ ] }, { \"key\": \"DayOfWeek\", \"type\": 2, \"acceptable\": [ \"Mon\", \"Tue\", \"Wed\", \"Thu\", \"Fri\", \"Sat\", \"Sun\", \"Weekday\", \"Weekend\" ] } ]\
+               },\
+               {\
+                       \"name\": \"music/history/play_freq\",\
+                       \"attributes\": [ { \"key\": \"TotalCount\", \"type\": 1, \"min\": 0, \"max\": -1 } ],\
+                       \"option\": [ { \"key\": \"TimeOfDay\", \"type\": 2, \"acceptable\": [ ] }, { \"key\": \"DayOfWeek\", \"type\": 2, \"acceptable\": [ \"Mon\", \"Tue\", \"Wed\", \"Thu\", \"Fri\", \"Sat\", \"Sun\", \"Weekday\", \"Weekend\" ] } ]\
+               },\
+               {\
+                       \"name\": \"video/history/play_freq\",\
+                       \"attributes\": [ { \"key\": \"TotalCount\", \"type\": 1, \"min\": 0, \"max\": -1 } ],\
+                       \"option\": [ { \"key\": \"TimeOfDay\", \"type\": 2, \"acceptable\": [ ] }, { \"key\": \"DayOfWeek\", \"type\": 2, \"acceptable\": [ \"Mon\", \"Tue\", \"Wed\", \"Thu\", \"Fri\", \"Sat\", \"Sun\", \"Weekday\", \"Weekend\" ] } ]\
+               }\
+       ]\
+}"
+
+
+namespace ctx {
+}      /* namespace ctx */
+
+#endif /* __CONTEXT_RULE_INFO_H__ */
diff --git a/src/rule_validator.cpp b/src/rule_validator.cpp
new file mode 100644 (file)
index 0000000..129bede
--- /dev/null
@@ -0,0 +1,403 @@
+/*
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ *
+ * 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 <sstream>
+#include <string>
+#include <map>
+#include <types_internal.h>
+#include <context_trigger.h>
+#include <context_trigger_types_internal.h>
+#include "rule_info.h"
+#include "rule_validator.h"
+
+#define KEY_TEMPLATE "templates"
+#define KEY_NAME "name"
+#define KEY_OPTION TYPE_OPTION_STR
+#define KEY_ATTR TYPE_ATTR_STR
+#define KEY_KEY "key"
+#define KEY_TYPE "type"
+#define KEY_MIN "min"
+#define KEY_MAX "max"
+#define KEY_ACCEPTABLE "acceptable"
+#define NO_LIMIT -1
+#define KEY_REF "ref"
+
+typedef std::map<std::string, ctx::json> template_map_t;
+template_map_t template_map;   // <name, template>
+
+static void init(void);
+static int string_to_int(std::string str);
+static bool check_value_int(ctx::json& tempt, int value);
+static bool check_value_string(ctx::json& tempt, std::string value);
+
+int string_to_int(std::string str)
+{
+       int i;
+       std::istringstream convert(str);
+
+       if (!(convert >> i))
+               i = 0;
+
+       return i;
+}
+
+void init(void)
+{
+       static bool initialized = false;
+       if (initialized)
+               return;
+
+       // Load from Data
+       ctx::json t = ctx::json(static_cast<const char*>(RULE_INFO));
+
+       ctx::json elem;
+       for (int i = 0; t.get_array_elem(NULL, "templates", i, &elem); i++) {
+               std::string name;
+               elem.get(NULL, "name", &name);
+
+               template_map[name] = elem;
+       }
+
+       initialized = true;
+}
+
+// called by context_trigger_rule_add_entry()
+bool ctx::rule_validator::check_option(ctx::json& item)
+{
+       init();
+
+       std::string name;
+       item.get(NULL, CT_RULE_EVENT_ITEM, &name);
+
+       // No option needed
+       if (template_map[name].array_get_size(NULL, KEY_OPTION) <= 0)
+               return true;
+
+       // Err: Check if mandatory option is missed
+       std::string val_str;
+       int val;
+       if (name.compare(CT_EVENT_PLACE) == 0) {
+               if (!(item.get(CT_RULE_EVENT_OPTION, CONTEXT_TRIGGER_PLACE_ID, &val)))
+                       return false;
+       } else if (name.compare(CT_CONDITION_APP_USE_FREQUENCY) == 0) {
+               if (!(item.get(CT_RULE_CONDITION_OPTION, CONTEXT_TRIGGER_APP_ID, &val_str)))
+                       return false;
+       } else if (name.compare(CT_CONDITION_COMMUNICATION_FREQUENCY) == 0) {
+               if (!(item.get(CT_RULE_CONDITION_OPTION, CONTEXT_TRIGGER_ADDRESS, &val_str)))
+                       return false;
+       }
+
+       return true;
+}
+
+// called by context_trigger_rule_entry_add_option_int()
+bool ctx::rule_validator::check_option_int(std::string name, std::string key, int value)
+{
+       init();
+
+       // Err: Item with no option
+       if (template_map[name].array_get_size(NULL, KEY_OPTION) <= 0) {
+               return false;
+       }
+
+       // Err: Invalid option key or Invalid value type
+       bool ret = false;
+       ctx::json opt_tempt;
+       for (int i = 0; template_map[name].get_array_elem(NULL, KEY_OPTION, i, &opt_tempt); i++) {
+               std::string t_key;
+               int t_type;
+               opt_tempt.get(NULL, KEY_KEY, &t_key);
+               opt_tempt.get(NULL, KEY_TYPE, &t_type);
+               if (t_key.compare(key) == 0 && t_type == TYPE_INT) {
+                       ret = true;
+                       break;
+               }
+       }
+       IF_FAIL_RETURN(ret, false);
+
+       // Err: Inappropriate value
+       //   a. normal case
+       ret = check_value_int(opt_tempt, value);
+       IF_FAIL_RETURN(ret, false);
+
+       return true;
+}
+
+// called by context_trigger_rule_entry_add_option_string()
+bool ctx::rule_validator::check_option_string(std::string name, std::string key, std::string value)
+{
+       init();
+
+       // Err: Item with no option
+       if (template_map[name].array_get_size(NULL, KEY_OPTION) <= 0) {
+               return false;
+       }
+
+       // Err: Invalid option key or Invalid value type
+       bool ret = false;
+       ctx::json opt_tempt;
+       for (int i = 0; template_map[name].get_array_elem(NULL, KEY_OPTION, i, &opt_tempt); i++) {
+               std::string t_key;
+               int t_type;
+               opt_tempt.get(NULL, KEY_KEY, &t_key);
+               opt_tempt.get(NULL, KEY_TYPE, &t_type);
+               if (t_key.compare(key) == 0 && t_type == TYPE_STRING) {
+                       ret = true;
+                       break;
+               }
+       }
+       IF_FAIL_RETURN(ret, false);
+
+       // Err: Inappropriate value
+       //   a. spacial case
+       if ((name.compare(CT_CONDITION_APP_USE_FREQUENCY) == 0 || name.compare(CT_CONDITION_COMMUNICATION_FREQUENCY) == 0
+                       || name.compare(CT_CONDITION_MUSIC_PLAYBACK_FREQUENCY) == 0 || name.compare(CT_CONDITION_VIDEO_PLAYBACK_FREQUENCY) == 0)
+                       && key.compare(CONTEXT_TRIGGER_TIME_OF_DAY) == 0) {
+               std::size_t found = value.find("-");
+               if (found == std::string::npos) {
+                       return false;
+               }
+
+               int t1 = string_to_int(value.substr(0, found-1));
+               int t2 = string_to_int(value.substr(found+1, value.length()-1));
+
+               if (!(t1 >= 0 && t1 < 24) || !(t2 >= 0 && t2 < 24)) {
+                       return false;
+               }
+
+               if (t1 >= t2) {
+                       return false;
+               }
+
+               return true;
+       }
+
+       //   b. normal case
+       ret = check_value_string(opt_tempt, value);
+       IF_FAIL_RETURN(ret, false);
+
+       return true;
+}
+
+// called by context_trigger_rule_entry_add_comparison_int()
+bool ctx::rule_validator::check_comparison_int(std::string name, std::string key, std::string op, int value)
+{
+       init();
+
+       // Err: Invalid attribute key or Invalid value type
+       bool ret = false;
+       ctx::json attr_tempt;
+       for (int i = 0; template_map[name].get_array_elem(NULL, KEY_ATTR, i, &attr_tempt); i++) {
+               std::string t_key;
+               int t_type;
+               attr_tempt.get(NULL, KEY_KEY, &t_key);
+               attr_tempt.get(NULL, KEY_TYPE, &t_type);
+               if (t_key.compare(key) == 0 && t_type == TYPE_INT) {
+                       ret = true;
+                       break;
+               }
+       }
+       IF_FAIL_RETURN(ret, false);
+
+       // Err: Invalid operator for the value
+
+       // Err: Inappropriate value
+       //    a. normal case
+       ret = check_value_int(attr_tempt, value);
+       IF_FAIL_RETURN(ret, false);
+
+       return true;
+}
+
+// called by context_trigger_rule_entry_add_comparison_string()
+bool ctx::rule_validator::check_comparison_string(std::string name, std::string key, std::string op, std::string value)
+{
+       init();
+
+       // Err: Invalid attribute key or Invalid value type
+       bool ret = false;
+       ctx::json attr_tempt;
+       for (int i = 0; template_map[name].get_array_elem(NULL, KEY_ATTR, i, &attr_tempt); i++) {
+               std::string t_key;
+               int t_type;
+               attr_tempt.get(NULL, KEY_KEY, &t_key);
+               attr_tempt.get(NULL, KEY_TYPE, &t_type);
+               if (t_key.compare(key) == 0 && t_type == TYPE_STRING) {
+                       ret = true;
+                       break;
+               }
+       }
+       IF_FAIL_RETURN(ret, false);
+
+       // Err: Invalid operator for the value
+
+       // Err: Inappropriate value
+       //    a. normal case
+       ret = check_value_string(attr_tempt, value);
+       IF_FAIL_RETURN(ret, false);
+
+       return true;
+}
+
+// called by context_trigger_rule_entry_add_comparison_string()
+bool ctx::rule_validator::check_valid_key(int type, std::string name, std::string key)
+{
+       init();
+       std::string json_key = (type == TYPE_OPTION)? KEY_OPTION : KEY_ATTR;
+
+       // Err: Invalid key
+       bool ret = false;
+       ctx::json tempt;
+       for (int i = 0; template_map[name].get_array_elem(NULL, json_key.c_str(), i, &tempt); i++) {
+               std::string t_key;
+               tempt.get(NULL, KEY_KEY, &t_key);
+               if (t_key.compare(key) == 0) {
+                       ret = true;
+                       break;
+               }
+       }
+       IF_FAIL_RETURN(ret, false);
+
+       return true;
+}
+
+bool check_value_int(ctx::json& tempt, int value)
+{
+       int min, max;
+       tempt.get(NULL, KEY_MIN, &min);
+       tempt.get(NULL, KEY_MAX, &max);
+
+       if (min != NO_LIMIT && value < min)
+               return false;
+
+       if (max != NO_LIMIT && value > max)
+               return false;
+
+       return true;
+}
+
+bool check_value_string(ctx::json& tempt, std::string value)
+{
+       // case1: any value is accepted
+       if (tempt.array_get_size(NULL, KEY_ACCEPTABLE) <= 0)
+               return true;
+
+       // case2: check acceptable value
+       std::string t_val;
+       for (int i = 0; tempt.get_array_elem(NULL, KEY_ACCEPTABLE, i, &t_val); i++) {
+               if (t_val.compare(value) == 0)
+                       return true;
+       }
+
+       return false;
+}
+
+// called by context_trigger_rule_entry_add_comparison()
+// called by context_trigger_rule_entry_add_option()
+bool ctx::rule_validator::set_ref_info(int type, ctx::json* jref, std::string name, std::string key, std::string ref_data)
+{
+       init();
+
+       std::string json_key = (type == TYPE_OPTION)? KEY_OPTION : KEY_ATTR;
+
+       ctx::json tempt;
+       for (int i = 0; template_map[name].get_array_elem(NULL, json_key.c_str(), i, &tempt); i++) {
+               std::string k;
+               int dt;
+               tempt.get(NULL, KEY_KEY, &k);
+
+               if (key.compare(k) == 0) {
+                       tempt.get(NULL, KEY_TYPE, &dt);
+
+                       ctx::json temp;
+                       temp.set(NULL, KEY_NAME, name);
+                       temp.set(NULL, KEY_KEY, key);
+                       temp.set(NULL, KEY_TYPE, dt);
+                       temp.set(NULL, KEY_REF, ref_data);
+
+                       if (type == TYPE_OPTION) {
+                               jref->array_append(NULL, KEY_OPTION, temp);
+                       } else if (type == TYPE_ATTR) {
+                               jref->array_append(NULL, KEY_ATTR, temp);
+                       } else {
+                               return false;
+                       }
+                       return true;
+               }
+       }
+       return false;
+}
+
+// called by context_trigger_rule_entry_add_comparison()
+int ctx::rule_validator::get_data_type(int type, std::string name, std::string key)
+{
+       init();
+
+       std::string json_key = (type == TYPE_OPTION)? KEY_OPTION : KEY_ATTR;
+
+       ctx::json tempt;
+       for (int i = 0; template_map[name].get_array_elem(NULL, json_key.c_str(), i, &tempt); i++) {
+               std::string k;
+               tempt.get(NULL, KEY_KEY, &k);
+
+               if (key.compare(k) == 0) {
+                       int dt;
+                       tempt.get(NULL, KEY_TYPE, &dt);
+                       return dt;
+               }
+       }
+
+       return -1;
+}
+
+// called by context_trigger_rule_add_entry()
+bool ctx::rule_validator::check_referential_data(std::string name, ctx::json& ref_info)
+{
+       std::map<std::string, int> type_map;
+
+       ctx::json ref_data;
+       for (int i = 0; ref_info.get_array_elem(NULL, KEY_OPTION, i, &ref_data); i++) {
+               std::string ref_key;
+               ref_data.get(NULL, KEY_REF, &ref_key);
+               int cond_type;
+               ref_data.get(NULL, KEY_TYPE, &cond_type);
+
+               if (type_map.count(ref_key) == 0) {
+                       type_map[ref_key] = get_data_type(TYPE_ATTR, name, ref_key); // -1, if invalid key
+               }
+
+               // Err: Invalid key or Value type not matched
+               if (cond_type != type_map[ref_key])
+                       return false;
+       }
+
+       for (int i = 0; ref_info.get_array_elem(NULL, KEY_ATTR, i, &ref_data); i++) {
+               std::string ref_key;
+               ref_data.get(NULL, KEY_REF, &ref_key);
+               int cond_type;
+               ref_data.get(NULL, KEY_TYPE, &cond_type);
+
+               if (type_map.count(ref_key) == 0) {
+                       type_map[ref_key] = get_data_type(TYPE_ATTR, name, ref_key); // -1, if invalid key
+               }
+
+               // Err: Invalid key or Value type not matched
+               if (cond_type != type_map[ref_key])
+                       return false;
+       }
+
+       return true;
+}
diff --git a/src/rule_validator.h b/src/rule_validator.h
new file mode 100644 (file)
index 0000000..cdda646
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ *
+ * 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 __CONTEXT_RULE_VALIDATOR_H__
+#define __CONTEXT_RULE_VALIDATOR_H__
+
+#include <json.h>
+
+namespace ctx {
+       namespace rule_validator {
+
+               bool check_option(ctx::json& item);
+               bool check_option_int(std::string name, std::string key, int value);
+               bool check_option_string(std::string name, std::string key, std::string value);
+               bool check_option_reference(std::string event, ctx::json& item);
+               bool check_comparison_int(std::string name, std::string key, std::string op, int value);
+               bool check_comparison_string(std::string name, std::string key, std::string op, std::string value);
+               bool check_valid_key(int type, std::string name, std::string key);
+
+               bool set_ref_info(int type, ctx::json* jref, std::string name, std::string key, std::string ref_key);
+               int get_data_type(int type, std::string name, std::string key);
+               bool check_referential_data(std::string name, ctx::json& ref_info);
+
+       }
+}      /* namespace ctx */
+
+#endif /* __CONTEXT_RULE_VALIDATOR_H__ */
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
new file mode 100644 (file)
index 0000000..95d23f3
--- /dev/null
@@ -0,0 +1,40 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+PROJECT(context-test)
+SET(EXEC context-test)
+
+# Source List
+FILE(GLOB_RECURSE UTC_SRCS src/*.c)
+MESSAGE("UTC Sources: ${UTC_SRCS}")
+
+INCLUDE_DIRECTORIES(
+       /usr/include
+       /usr/include/glib-2.0
+       ${CMAKE_SOURCE_DIR}/include
+)
+
+INCLUDE(FindPkgConfig)
+pkg_check_modules(pkgs REQUIRED
+       dlog
+       glib-2.0
+       capi-base-common
+       capi-appfw-app-control
+)
+
+SET(EXTRA_CFLAGS -fPIE)
+FOREACH(flag ${pkgs_CFLAGS})
+       SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+# for Emulator
+IF("${ARCH}" STREQUAL "arm")
+       ADD_DEFINITIONS("-DTARGET")
+ELSE("${ARCH}" STREQUAL "arm")
+       ADD_DEFINITIONS("-DEMULATOR")
+ENDIF("${ARCH}" STREQUAL "arm")
+
+ADD_EXECUTABLE(${EXEC} ${UTC_SRCS})
+TARGET_LINK_LIBRARIES(${EXEC} ${pkgs_LDFLAGS} ${target} -pie)
+SET_TARGET_PROPERTIES(${EXEC} PROPERTIES COMPILE_FLAGS ${EXTRA_CFLAGS})
+SET_TARGET_PROPERTIES(${EXEC} PROPERTIES COMPILE_DEFINITIONS "LOG_TAG=\"CONTEXT-TEST\"")
+
+INSTALL(TARGETS ${EXEC} DESTINATION /usr/bin)
diff --git a/test/src/main.c b/test/src/main.c
new file mode 100644 (file)
index 0000000..8eada05
--- /dev/null
@@ -0,0 +1,145 @@
+/*
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stdlib.h>
+#include <glib.h>
+#include <glib-object.h>
+#include <glib/gprintf.h>
+
+#include "utc_context_trigger.h"
+#include "utc_context_history.h"
+
+#define RED(X) "\033[1;31m"X"\033[0m"
+
+static void signal_handler(int signo)
+{
+       g_print(RED("\nSIGNAL %d received\n"), signo);
+       exit(EXIT_SUCCESS);
+}
+
+int main(int argc, char** argv)
+{
+       signal(SIGINT,  signal_handler);
+       signal(SIGHUP,  signal_handler);
+       signal(SIGTERM, signal_handler);
+       signal(SIGQUIT, signal_handler);
+       signal(SIGABRT, signal_handler);
+
+       g_print("\n");
+       g_print("***********************************\n");
+       g_print("* Context Service Unit Test Cases *\n");
+       g_print("***********************************\n");
+       g_print("\n");
+
+#if !defined(GLIB_VERSION_2_36)
+       g_type_init();
+#endif
+       g_test_init(&argc, &argv, NULL);
+
+       g_test_add_func("/context_trigger/initialize", initialize);
+       g_test_add_func("/context_trigger/utc_context_trigger_create_p", utc_context_trigger_create_p);
+       g_test_add_func("/context_trigger/utc_context_trigger_create_n", utc_context_trigger_create_n);
+       g_test_add_func("/context_trigger/utc_context_trigger_destroy_p", utc_context_trigger_destroy_p);
+       g_test_add_func("/context_trigger/utc_context_trigger_destroy_n", utc_context_trigger_destroy_n);
+       g_test_add_func("/context_trigger/utc_context_trigger_set_callback_p", utc_context_trigger_set_callback_p);
+       g_test_add_func("/context_trigger/utc_context_trigger_set_callback_n", utc_context_trigger_set_callback_n);
+       g_test_add_func("/context_trigger/utc_context_trigger_add_rule_p", utc_context_trigger_add_rule_p);
+       g_test_add_func("/context_trigger/utc_context_trigger_add_rule_n", utc_context_trigger_add_rule_n);
+       g_test_add_func("/context_trigger/utc_context_trigger_remove_rule_p", utc_context_trigger_remove_rule_p);
+       g_test_add_func("/context_trigger/utc_context_trigger_remove_rule_n", utc_context_trigger_remove_rule_n);
+       g_test_add_func("/context_trigger/utc_context_trigger_enable_rule_p", utc_context_trigger_enable_rule_p);
+       g_test_add_func("/context_trigger/utc_context_trigger_enable_rule_n", utc_context_trigger_enable_rule_n);
+       g_test_add_func("/context_trigger/utc_context_trigger_disable_rule_p", utc_context_trigger_disable_rule_p);
+       g_test_add_func("/context_trigger/utc_context_trigger_disable_rule_n", utc_context_trigger_disable_rule_n);
+       g_test_add_func("/context_trigger/utc_context_trigger_get_own_rule_ids_p", utc_context_trigger_get_own_rule_ids_p);
+       g_test_add_func("/context_trigger/utc_context_trigger_get_own_rule_ids_n", utc_context_trigger_get_own_rule_ids_n);
+       g_test_add_func("/context_trigger/utc_context_trigger_get_rule_by_id_p", utc_context_trigger_get_rule_by_id_p);
+       g_test_add_func("/context_trigger/utc_context_trigger_get_rule_by_id_n", utc_context_trigger_get_rule_by_id_n);
+       g_test_add_func("/context_trigger/utc_context_trigger_rule_create_p", utc_context_trigger_rule_create_p);
+       g_test_add_func("/context_trigger/utc_context_trigger_rule_create_n", utc_context_trigger_rule_create_n);
+       g_test_add_func("/context_trigger/utc_context_trigger_rule_destroy_p", utc_context_trigger_rule_destroy_p);
+       g_test_add_func("/context_trigger/utc_context_trigger_rule_destroy_n", utc_context_trigger_rule_destroy_n);
+       g_test_add_func("/context_trigger/utc_context_trigger_rule_add_entry_p", utc_context_trigger_rule_add_entry_p);
+       g_test_add_func("/context_trigger/utc_context_trigger_rule_add_entry_n", utc_context_trigger_rule_add_entry_n);
+       g_test_add_func("/context_trigger/utc_context_trigger_rule_set_action_app_control_p", utc_context_trigger_rule_set_action_app_control_p);
+       g_test_add_func("/context_trigger/utc_context_trigger_rule_set_action_app_control_n", utc_context_trigger_rule_set_action_app_control_n);
+       g_test_add_func("/context_trigger/utc_context_trigger_rule_set_action_notification_p", utc_context_trigger_rule_set_action_notification_p);
+       g_test_add_func("/context_trigger/utc_context_trigger_rule_set_action_notification_n", utc_context_trigger_rule_set_action_notification_n);
+       g_test_add_func("/context_trigger/utc_context_trigger_rule_set_description_p", utc_context_trigger_rule_set_description_p);
+       g_test_add_func("/context_trigger/utc_context_trigger_rule_set_description_n", utc_context_trigger_rule_set_description_n);
+       g_test_add_func("/context_trigger/utc_context_trigger_rule_get_description_p", utc_context_trigger_rule_get_description_p);
+       g_test_add_func("/context_trigger/utc_context_trigger_rule_get_description_n", utc_context_trigger_rule_get_description_n);
+       g_test_add_func("/context_trigger/utc_context_trigger_rule_event_create_p", utc_context_trigger_rule_event_create_p);
+       g_test_add_func("/context_trigger/utc_context_trigger_rule_event_create_n", utc_context_trigger_rule_event_create_n);
+       g_test_add_func("/context_trigger/utc_context_trigger_rule_event_is_supported_p", utc_context_trigger_rule_event_is_supported_p);
+       g_test_add_func("/context_trigger/utc_context_trigger_rule_event_is_supported_n", utc_context_trigger_rule_event_is_supported_n);
+       g_test_add_func("/context_trigger/utc_context_trigger_rule_condition_create_p", utc_context_trigger_rule_condition_create_p);
+       g_test_add_func("/context_trigger/utc_context_trigger_rule_condition_create_n", utc_context_trigger_rule_condition_create_n);
+       g_test_add_func("/context_trigger/utc_context_trigger_rule_condition_is_supported_p", utc_context_trigger_rule_condition_is_supported_p);
+       g_test_add_func("/context_trigger/utc_context_trigger_rule_condition_is_supported_n", utc_context_trigger_rule_condition_is_supported_n);
+       g_test_add_func("/context_trigger/utc_context_trigger_rule_entry_destroy_p", utc_context_trigger_rule_entry_destroy_p);
+       g_test_add_func("/context_trigger/utc_context_trigger_rule_entry_destroy_n", utc_context_trigger_rule_entry_destroy_n);
+       g_test_add_func("/context_trigger/utc_context_trigger_rule_entry_add_key_p", utc_context_trigger_rule_entry_add_key_p);
+       g_test_add_func("/context_trigger/utc_context_trigger_rule_entry_add_key_n", utc_context_trigger_rule_entry_add_key_n);
+       g_test_add_func("/context_trigger/utc_context_trigger_rule_entry_add_comparison_int_p", utc_context_trigger_rule_entry_add_comparison_int_p);
+       g_test_add_func("/context_trigger/utc_context_trigger_rule_entry_add_comparison_int_n", utc_context_trigger_rule_entry_add_comparison_int_n);
+//     g_test_add_func("/context_trigger/utc_context_trigger_rule_entry_add_comparison_double_p", utc_context_trigger_rule_entry_add_comparison_double_p);
+//     g_test_add_func("/context_trigger/utc_context_trigger_rule_entry_add_comparison_double_n", utc_context_trigger_rule_entry_add_comparison_double_n);
+       g_test_add_func("/context_trigger/utc_context_trigger_rule_entry_add_comparison_string_p", utc_context_trigger_rule_entry_add_comparison_string_p);
+       g_test_add_func("/context_trigger/utc_context_trigger_rule_entry_add_comparison_string_n", utc_context_trigger_rule_entry_add_comparison_string_n);
+       g_test_add_func("/context_trigger/release", release);
+
+       g_test_add_func("/context_history/utc_context_history_create_p", utc_context_history_create_p);
+       g_test_add_func("/context_history/utc_context_history_create_n", utc_context_history_create_n);
+       g_test_add_func("/context_history/utc_context_history_destroy_p", utc_context_history_destroy_p);
+       g_test_add_func("/context_history/utc_context_history_destroy_n", utc_context_history_destroy_n);
+       g_test_add_func("/context_history/utc_context_history_filter_create_p", utc_context_history_filter_create_p);
+       g_test_add_func("/context_history/utc_context_history_filter_create_n", utc_context_history_filter_create_n);
+       g_test_add_func("/context_history/utc_context_history_filter_destroy_p", utc_context_history_filter_destroy_p);
+       g_test_add_func("/context_history/utc_context_history_filter_destroy_n", utc_context_history_filter_destroy_n);
+       g_test_add_func("/context_history/utc_context_history_filter_set_int_p", utc_context_history_filter_set_int_p);
+       g_test_add_func("/context_history/utc_context_history_filter_set_int_n", utc_context_history_filter_set_int_n);
+       g_test_add_func("/context_history/utc_context_history_filter_set_string_p", utc_context_history_filter_set_string_p);
+       g_test_add_func("/context_history/utc_context_history_filter_set_string_n", utc_context_history_filter_set_string_n);
+       g_test_add_func("/context_history/utc_context_history_get_list_p", utc_context_history_get_list_p);
+       g_test_add_func("/context_history/utc_context_history_get_list_n", utc_context_history_get_list_n);
+       g_test_add_func("/context_history/utc_context_history_list_get_count_p", utc_context_history_list_get_count_p);
+       g_test_add_func("/context_history/utc_context_history_list_get_count_n", utc_context_history_list_get_count_n);
+       g_test_add_func("/context_history/utc_context_history_list_get_current_p", utc_context_history_list_get_current_p);
+       g_test_add_func("/context_history/utc_context_history_list_get_current_n", utc_context_history_list_get_current_n);
+       g_test_add_func("/context_history/utc_context_history_list_move_first_p", utc_context_history_list_move_first_p);
+       g_test_add_func("/context_history/utc_context_history_list_move_first_n", utc_context_history_list_move_first_n);
+       g_test_add_func("/context_history/utc_context_history_list_move_next_p", utc_context_history_list_move_next_p);
+       g_test_add_func("/context_history/utc_context_history_list_move_next_n", utc_context_history_list_move_next_n);
+       g_test_add_func("/context_history/utc_context_history_list_destroy_p", utc_context_history_list_destroy_p);
+       g_test_add_func("/context_history/utc_context_history_list_destroy_n", utc_context_history_list_destroy_n);
+       g_test_add_func("/context_history/utc_context_history_record_create_p", utc_context_history_record_create_p);
+       g_test_add_func("/context_history/utc_context_history_record_create_n", utc_context_history_record_create_n);
+       g_test_add_func("/context_history/utc_context_history_record_get_int_p", utc_context_history_record_get_int_p);
+       g_test_add_func("/context_history/utc_context_history_record_get_int_n", utc_context_history_record_get_int_n);
+       g_test_add_func("/context_history/utc_context_history_record_get_string_p", utc_context_history_record_get_string_p);
+       g_test_add_func("/context_history/utc_context_history_record_get_string_n", utc_context_history_record_get_string_n);
+       g_test_add_func("/context_history/utc_context_history_record_set_int_p", utc_context_history_record_set_int_p);
+       g_test_add_func("/context_history/utc_context_history_record_set_int_n", utc_context_history_record_set_int_n);
+       g_test_add_func("/context_history/utc_context_history_record_set_string_p", utc_context_history_record_set_string_p);
+       g_test_add_func("/context_history/utc_context_history_record_set_string_p", utc_context_history_record_set_string_n);
+       g_test_add_func("/context_history/utc_context_history_record_destroy_p", utc_context_history_record_destroy_p);
+       g_test_add_func("/context_history/utc_context_history_record_destroy_n", utc_context_history_record_destroy_n);
+       g_test_add_func("/context_history/utc_context_history_record_insert_p", utc_context_history_record_insert_p);
+       g_test_add_func("/context_history/utc_context_history_record_insert_n", utc_context_history_record_insert_n);
+
+       return g_test_run();
+}
diff --git a/test/src/utc_context_history.c b/test/src/utc_context_history.c
new file mode 100644 (file)
index 0000000..54ad3a5
--- /dev/null
@@ -0,0 +1,586 @@
+/*
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ *
+ * 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 <glib.h>
+#include <dlog.h>
+#include <context_history.h>
+#include "utc_context_history.h"
+#include <stdlib.h>
+
+#define RED(X)         "\033[1;31m"X"\033[0m"
+#define GREEN(X)       "\033[1;32m"X"\033[0m"
+#define YELLOW(X)      "\033[1;33m"X"\033[0m"
+#define BLUE(X)                "\033[1;34m"X"\033[0m"
+
+void utc_context_history_create_p(void)
+{
+       int error = CONTEXT_HISTORY_ERROR_NONE;
+       context_history_h handle = NULL;
+
+       error = context_history_create(&handle);
+       g_assert_cmpint(error, ==, CONTEXT_HISTORY_ERROR_NONE);
+
+       context_history_destroy(handle);
+}
+
+void utc_context_history_create_n(void)
+{
+       int error = CONTEXT_HISTORY_ERROR_NONE;
+
+       error = context_history_create(NULL);
+       g_assert_cmpint(error, ==, CONTEXT_HISTORY_ERROR_INVALID_PARAMETER);
+}
+
+
+void utc_context_history_destroy_p(void)
+{
+       int error = CONTEXT_HISTORY_ERROR_NONE;
+       context_history_h handle;
+
+       context_history_create(&handle);
+       error = context_history_destroy(handle);
+
+       g_assert_cmpint(error, ==, CONTEXT_HISTORY_ERROR_NONE);
+}
+
+void utc_context_history_destroy_n(void)
+{
+       int error = CONTEXT_HISTORY_ERROR_NONE;
+
+       error = context_history_destroy(NULL);
+       g_assert_cmpint(error, ==, CONTEXT_HISTORY_ERROR_INVALID_PARAMETER);
+}
+
+void utc_context_history_filter_create_p(void)
+{
+       int error = CONTEXT_HISTORY_ERROR_NONE;
+       context_history_filter_h filter = NULL;
+
+       error = context_history_filter_create(&filter);
+       g_assert_cmpint(error, ==, CONTEXT_HISTORY_ERROR_NONE);
+
+       context_history_filter_destroy(filter);
+}
+
+void utc_context_history_filter_create_n(void)
+{
+       int error = CONTEXT_HISTORY_ERROR_NONE;
+
+       error = context_history_filter_create(NULL);
+       g_assert_cmpint(error, ==, CONTEXT_HISTORY_ERROR_INVALID_PARAMETER);
+}
+
+void utc_context_history_filter_destroy_p(void)
+{
+       int error = CONTEXT_HISTORY_ERROR_NONE;
+       context_history_filter_h filter;
+
+       context_history_filter_create(&filter);
+       error = context_history_filter_destroy(filter);
+
+       g_assert_cmpint(error, ==, CONTEXT_HISTORY_ERROR_NONE);
+}
+
+void utc_context_history_filter_destroy_n(void)
+{
+       int error = CONTEXT_HISTORY_ERROR_NONE;
+
+       error = context_history_filter_destroy(NULL);
+       g_assert_cmpint(error, ==, CONTEXT_HISTORY_ERROR_INVALID_PARAMETER);
+}
+
+void utc_context_history_filter_set_int_p(void)
+{
+       int error = CONTEXT_HISTORY_ERROR_NONE;
+       context_history_filter_h filter = NULL;
+
+       context_history_filter_create(&filter);
+
+       error = context_history_filter_set_int(filter, CONTEXT_HISTORY_FILTER_TIME_SPAN, 10);
+       g_assert_cmpint(error, ==, CONTEXT_HISTORY_ERROR_NONE);
+
+       context_history_filter_destroy(filter);
+}
+
+void utc_context_history_filter_set_int_n(void)
+{
+       int error = CONTEXT_HISTORY_ERROR_NONE;
+
+       error = context_history_filter_set_int(NULL, CONTEXT_HISTORY_FILTER_TIME_SPAN, 10);
+       g_assert_cmpint(error, ==, CONTEXT_HISTORY_ERROR_INVALID_PARAMETER);
+}
+
+void utc_context_history_filter_set_string_p(void)
+{
+       int error = CONTEXT_HISTORY_ERROR_NONE;
+       context_history_filter_h filter = NULL;
+
+       context_history_filter_create(&filter);
+
+       error = context_history_filter_set_string(filter, CONTEXT_HISTORY_FILTER_APP_ID, "org.tizen.sample");
+       g_assert_cmpint(error, ==, CONTEXT_HISTORY_ERROR_NONE);
+
+       context_history_filter_destroy(filter);
+}
+
+void utc_context_history_filter_set_string_n(void)
+{
+       int error = CONTEXT_HISTORY_ERROR_NONE;
+
+       error = context_history_filter_set_string(NULL, CONTEXT_HISTORY_FILTER_APP_ID, "org.tizen.sample");
+       g_assert_cmpint(error, ==, CONTEXT_HISTORY_ERROR_INVALID_PARAMETER);
+}
+
+void utc_context_history_get_list_p(void)
+{
+       int error = CONTEXT_HISTORY_ERROR_NONE;
+       context_history_h handle = NULL;
+       context_history_filter_h filter = NULL;
+       context_history_list_h list = NULL;
+
+       context_history_create(&handle);
+
+       context_history_filter_create(&filter);
+       context_history_filter_set_int(filter, CONTEXT_HISTORY_FILTER_TIME_SPAN, 30);
+       context_history_filter_set_int(filter, CONTEXT_HISTORY_FILTER_RESULT_SIZE, 10);
+
+       error = context_history_get_list(handle, CONTEXT_HISTORY_FREQUENTLY_USED_APP, filter, &list);
+       g_assert_cmpint(error, ==, CONTEXT_HISTORY_ERROR_NONE);
+
+       context_history_list_destroy(list);
+       context_history_filter_destroy(filter);
+       context_history_destroy(handle);
+}
+
+void utc_context_history_get_list_n(void)
+{
+       int error = CONTEXT_HISTORY_ERROR_NONE;
+       context_history_h handle = NULL;
+       context_history_list_h list = NULL;
+
+       context_history_create(&handle);
+
+       error = context_history_get_list(handle, CONTEXT_HISTORY_FREQUENTLY_USED_APP, NULL, &list);
+       g_assert_cmpint(error, ==, CONTEXT_HISTORY_ERROR_INVALID_PARAMETER);
+
+       context_history_list_destroy(list);
+       context_history_destroy(handle);
+}
+
+void utc_context_history_list_get_count_p(void)
+{
+       int error = CONTEXT_HISTORY_ERROR_NONE;
+       int count;
+       context_history_h handle = NULL;
+       context_history_filter_h filter = NULL;
+       context_history_list_h list = NULL;
+
+       context_history_create(&handle);
+
+       context_history_filter_create(&filter);
+       context_history_filter_set_int(filter, CONTEXT_HISTORY_FILTER_TIME_SPAN, 30);
+       context_history_filter_set_int(filter, CONTEXT_HISTORY_FILTER_RESULT_SIZE, 10);
+
+       context_history_get_list(handle, CONTEXT_HISTORY_FREQUENTLY_USED_APP, filter, &list);
+
+       error = context_history_list_get_count(list, &count);
+       g_assert_cmpint(error, ==, CONTEXT_HISTORY_ERROR_NONE);
+
+       context_history_list_destroy(list);
+       context_history_filter_destroy(filter);
+       context_history_destroy(handle);
+}
+
+void utc_context_history_list_get_count_n(void)
+{
+       int error = CONTEXT_HISTORY_ERROR_NONE;
+       context_history_h handle = NULL;
+       context_history_filter_h filter = NULL;
+       context_history_list_h list = NULL;
+
+       context_history_create(&handle);
+
+       context_history_filter_create(&filter);
+       context_history_filter_set_int(filter, CONTEXT_HISTORY_FILTER_TIME_SPAN, 30);
+       context_history_filter_set_int(filter, CONTEXT_HISTORY_FILTER_RESULT_SIZE, 10);
+
+       context_history_get_list(handle, CONTEXT_HISTORY_FREQUENTLY_USED_APP, filter, &list);
+
+       error = context_history_list_get_count(list, NULL);
+       g_assert_cmpint(error, ==, CONTEXT_HISTORY_ERROR_INVALID_PARAMETER);
+
+       context_history_list_destroy(list);
+       context_history_filter_destroy(filter);
+       context_history_destroy(handle);
+}
+
+void utc_context_history_list_get_current_p(void)
+{
+       int error = CONTEXT_HISTORY_ERROR_NONE;
+       context_history_h handle = NULL;
+       context_history_filter_h filter = NULL;
+       context_history_list_h list = NULL;
+       context_history_record_h record = NULL;
+
+       context_history_create(&handle);
+
+       context_history_filter_create(&filter);
+       context_history_filter_set_int(filter, CONTEXT_HISTORY_FILTER_TIME_SPAN, 30);
+       context_history_filter_set_int(filter, CONTEXT_HISTORY_FILTER_RESULT_SIZE, 10);
+
+       context_history_get_list(handle, CONTEXT_HISTORY_FREQUENTLY_USED_APP, filter, &list);
+
+       error = context_history_list_get_current(list, &record);
+       g_assert_cmpint(error, ==, CONTEXT_HISTORY_ERROR_NONE);
+
+       context_history_record_destroy(record);
+       context_history_list_destroy(list);
+       context_history_filter_destroy(filter);
+       context_history_destroy(handle);
+}
+
+void utc_context_history_list_get_current_n(void)
+{
+       int error = CONTEXT_HISTORY_ERROR_NONE;
+       context_history_h handle = NULL;
+       context_history_filter_h filter = NULL;
+       context_history_list_h list = NULL;
+
+       context_history_create(&handle);
+
+       context_history_filter_create(&filter);
+       context_history_filter_set_int(filter, CONTEXT_HISTORY_FILTER_TIME_SPAN, 30);
+       context_history_filter_set_int(filter, CONTEXT_HISTORY_FILTER_RESULT_SIZE, 10);
+
+       context_history_get_list(handle, CONTEXT_HISTORY_FREQUENTLY_USED_APP, filter, &list);
+
+       error = context_history_list_get_current(list, NULL);
+       g_assert_cmpint(error, ==, CONTEXT_HISTORY_ERROR_INVALID_PARAMETER);
+
+       context_history_list_destroy(list);
+       context_history_filter_destroy(filter);
+       context_history_destroy(handle);
+}
+
+void utc_context_history_list_move_first_p(void)
+{
+       int error = CONTEXT_HISTORY_ERROR_NONE;
+       context_history_h handle = NULL;
+       context_history_filter_h filter = NULL;
+       context_history_list_h list = NULL;
+
+       context_history_create(&handle);
+
+       context_history_filter_create(&filter);
+       context_history_filter_set_int(filter, CONTEXT_HISTORY_FILTER_TIME_SPAN, 30);
+       context_history_filter_set_int(filter, CONTEXT_HISTORY_FILTER_RESULT_SIZE, 10);
+
+       context_history_get_list(handle, CONTEXT_HISTORY_FREQUENTLY_USED_APP, filter, &list);
+
+       error = context_history_list_move_first(list);
+       g_assert_cmpint(error, ==, CONTEXT_HISTORY_ERROR_NONE);
+
+       context_history_list_destroy(list);
+       context_history_filter_destroy(filter);
+       context_history_destroy(handle);
+}
+
+void utc_context_history_list_move_first_n(void)
+{
+       int error = CONTEXT_HISTORY_ERROR_NONE;
+
+       error = context_history_list_move_first(NULL);
+       g_assert_cmpint(error, ==, CONTEXT_HISTORY_ERROR_INVALID_PARAMETER);
+}
+
+void utc_context_history_list_move_next_p(void)
+{
+       int error = CONTEXT_HISTORY_ERROR_NONE;
+       context_history_h handle = NULL;
+       context_history_filter_h filter = NULL;
+       context_history_list_h list = NULL;
+
+       context_history_create(&handle);
+
+       context_history_filter_create(&filter);
+       context_history_filter_set_int(filter, CONTEXT_HISTORY_FILTER_TIME_SPAN, 30);
+       context_history_filter_set_int(filter, CONTEXT_HISTORY_FILTER_RESULT_SIZE, 10);
+
+       context_history_get_list(handle, CONTEXT_HISTORY_FREQUENTLY_USED_APP, filter, &list);
+
+       error = context_history_list_move_next(list);
+       g_assert_cmpint(error, ==, CONTEXT_HISTORY_ERROR_NONE);
+
+       context_history_list_destroy(list);
+       context_history_filter_destroy(filter);
+       context_history_destroy(handle);
+}
+
+void utc_context_history_list_move_next_n(void)
+{
+       int error = CONTEXT_HISTORY_ERROR_NONE;
+
+       error = context_history_list_move_next(NULL);
+       g_assert_cmpint(error, ==, CONTEXT_HISTORY_ERROR_INVALID_PARAMETER);
+}
+
+void utc_context_history_list_destroy_p(void)
+{
+       int error = CONTEXT_HISTORY_ERROR_NONE;
+       context_history_h handle = NULL;
+       context_history_filter_h filter = NULL;
+       context_history_list_h list = NULL;
+
+       context_history_create(&handle);
+
+       context_history_filter_create(&filter);
+       context_history_filter_set_int(filter, CONTEXT_HISTORY_FILTER_TIME_SPAN, 30);
+       context_history_filter_set_int(filter, CONTEXT_HISTORY_FILTER_RESULT_SIZE, 10);
+
+       context_history_get_list(handle, CONTEXT_HISTORY_FREQUENTLY_USED_APP, filter, &list);
+
+       error =  context_history_list_destroy(list);
+       g_assert_cmpint(error, ==, CONTEXT_HISTORY_ERROR_NONE);
+
+       context_history_filter_destroy(filter);
+       context_history_destroy(handle);
+}
+
+void utc_context_history_list_destroy_n(void)
+{
+       int error = CONTEXT_HISTORY_ERROR_NONE;
+
+       error = context_history_list_destroy(NULL);
+       g_assert_cmpint(error, ==, CONTEXT_HISTORY_ERROR_INVALID_PARAMETER);
+}
+
+void utc_context_history_record_create_p(void)
+{
+       int error = CONTEXT_HISTORY_ERROR_NONE;
+       context_history_record_h record = NULL;
+
+       error =  context_history_record_create(&record);
+       g_assert_cmpint(error, ==, CONTEXT_HISTORY_ERROR_NONE);
+
+       context_history_record_destroy(record);
+}
+
+void utc_context_history_record_create_n(void)
+{
+       int error = CONTEXT_HISTORY_ERROR_NONE;
+
+       error =  context_history_record_create(NULL);
+       g_assert_cmpint(error, ==, CONTEXT_HISTORY_ERROR_INVALID_PARAMETER);
+}
+
+void utc_context_history_record_get_int_p(void)
+{
+       int error = CONTEXT_HISTORY_ERROR_NONE;
+       int value;
+       context_history_h handle = NULL;
+       context_history_filter_h filter = NULL;
+       context_history_list_h list = NULL;
+       context_history_record_h record = NULL;
+
+       context_history_create(&handle);
+
+       context_history_filter_create(&filter);
+       context_history_filter_set_int(filter, CONTEXT_HISTORY_FILTER_TIME_SPAN, 30);
+       context_history_filter_set_int(filter, CONTEXT_HISTORY_FILTER_RESULT_SIZE, 10);
+
+       context_history_get_list(handle, CONTEXT_HISTORY_FREQUENTLY_USED_APP, filter, &list);
+
+       context_history_list_get_current(list, &record);
+
+       error = context_history_record_get_int(record, "UsedCount", &value);
+       g_assert_cmpint(error, ==, CONTEXT_HISTORY_ERROR_NONE);
+
+       context_history_record_destroy(record);
+       context_history_list_destroy(list);
+       context_history_filter_destroy(filter);
+       context_history_destroy(handle);
+}
+
+void utc_context_history_record_get_int_n(void)
+{
+       int error = CONTEXT_HISTORY_ERROR_NONE;
+       context_history_h handle = NULL;
+       context_history_filter_h filter = NULL;
+       context_history_list_h list = NULL;
+       context_history_record_h record = NULL;
+
+       context_history_create(&handle);
+
+       context_history_filter_create(&filter);
+       context_history_filter_set_int(filter, CONTEXT_HISTORY_FILTER_TIME_SPAN, 30);
+       context_history_filter_set_int(filter, CONTEXT_HISTORY_FILTER_RESULT_SIZE, 10);
+
+       context_history_get_list(handle, CONTEXT_HISTORY_FREQUENTLY_USED_APP, filter, &list);
+
+       context_history_list_get_current(list, &record);
+
+       error = context_history_record_get_int(record, "UsedCount", NULL);
+       g_assert_cmpint(error, ==, CONTEXT_HISTORY_ERROR_INVALID_PARAMETER);
+
+       context_history_record_destroy(record);
+       context_history_list_destroy(list);
+       context_history_filter_destroy(filter);
+       context_history_destroy(handle);
+}
+
+void utc_context_history_record_get_string_p(void)
+{
+       int error = CONTEXT_HISTORY_ERROR_NONE;
+       char *value = NULL;
+       context_history_h handle = NULL;
+       context_history_filter_h filter = NULL;
+       context_history_list_h list = NULL;
+       context_history_record_h record = NULL;
+
+       context_history_create(&handle);
+
+       context_history_filter_create(&filter);
+       context_history_filter_set_int(filter, CONTEXT_HISTORY_FILTER_TIME_SPAN, 30);
+       context_history_filter_set_int(filter, CONTEXT_HISTORY_FILTER_RESULT_SIZE, 10);
+
+       context_history_get_list(handle, CONTEXT_HISTORY_FREQUENTLY_USED_APP, filter, &list);
+
+       context_history_list_get_current(list, &record);
+
+       error = context_history_record_get_string(record, "AppId", &value);
+       g_assert_cmpint(error, ==, CONTEXT_HISTORY_ERROR_NONE);
+
+       g_free(value);
+
+       context_history_record_destroy(record);
+       context_history_list_destroy(list);
+       context_history_filter_destroy(filter);
+       context_history_destroy(handle);
+}
+
+void utc_context_history_record_get_string_n(void)
+{
+       int error = CONTEXT_HISTORY_ERROR_NONE;
+       context_history_h handle = NULL;
+       context_history_filter_h filter = NULL;
+       context_history_list_h list = NULL;
+       context_history_record_h record = NULL;
+
+       context_history_create(&handle);
+
+       context_history_filter_create(&filter);
+       context_history_filter_set_int(filter, CONTEXT_HISTORY_FILTER_TIME_SPAN, 30);
+       context_history_filter_set_int(filter, CONTEXT_HISTORY_FILTER_RESULT_SIZE, 10);
+
+       context_history_get_list(handle, CONTEXT_HISTORY_FREQUENTLY_USED_APP, filter, &list);
+
+       context_history_list_get_current(list, &record);
+
+       error = context_history_record_get_string(record, "AppId", NULL);
+       g_assert_cmpint(error, ==, CONTEXT_HISTORY_ERROR_INVALID_PARAMETER);
+
+       context_history_record_destroy(record);
+       context_history_list_destroy(list);
+       context_history_filter_destroy(filter);
+       context_history_destroy(handle);
+}
+
+void utc_context_history_record_set_int_p(void)
+{
+       int error = CONTEXT_HISTORY_ERROR_NONE;
+       context_history_record_h record = NULL;
+
+       context_history_record_create(&record);
+
+       error =  context_history_record_set_int(record, "LastPosition", 200);
+       g_assert_cmpint(error, ==, CONTEXT_HISTORY_ERROR_NONE);
+
+       context_history_record_destroy(record);
+}
+
+void utc_context_history_record_set_int_n(void)
+{
+       int error = CONTEXT_HISTORY_ERROR_NONE;
+
+       error =  context_history_record_set_int(NULL, "LastPosition", 200);
+       g_assert_cmpint(error, ==, CONTEXT_HISTORY_ERROR_INVALID_PARAMETER);
+}
+
+void utc_context_history_record_set_string_p(void)
+{
+       int error = CONTEXT_HISTORY_ERROR_NONE;
+       context_history_record_h record = NULL;
+
+       context_history_record_create(&record);
+
+       error =  context_history_record_set_string(record, "AppId", "org.tizen.sample");
+       g_assert_cmpint(error, ==, CONTEXT_HISTORY_ERROR_NONE);
+
+       context_history_record_destroy(record);
+}
+
+void utc_context_history_record_set_string_n(void)
+{
+       int error = CONTEXT_HISTORY_ERROR_NONE;
+
+       error =  context_history_record_set_string(NULL, "AppId", "org.tizen.sample");
+       g_assert_cmpint(error, ==, CONTEXT_HISTORY_ERROR_INVALID_PARAMETER);
+}
+
+void utc_context_history_record_destroy_p(void)
+{
+       int error = CONTEXT_HISTORY_ERROR_NONE;
+       context_history_record_h record = NULL;
+
+       context_history_record_create(&record);
+
+       error = context_history_record_destroy(record);
+       g_assert_cmpint(error, ==, CONTEXT_HISTORY_ERROR_NONE);
+}
+
+void utc_context_history_record_destroy_n(void)
+{
+       int error = CONTEXT_HISTORY_ERROR_NONE;
+
+       error = context_history_record_destroy(NULL);
+       g_assert_cmpint(error, ==, CONTEXT_HISTORY_ERROR_INVALID_PARAMETER);
+}
+
+void utc_context_history_record_insert_p(void)
+{
+       int error = CONTEXT_HISTORY_ERROR_NONE;
+       context_history_record_h record = NULL;
+
+       context_history_record_create(&record);
+
+       context_history_record_set_string(record, "AppId", "org.tizen.sample");
+       context_history_record_set_int(NULL, "LastPosition", 200);
+
+       error = context_history_record_insert(record, CONTEXT_HISTORY_START_MUSIC);
+       g_assert_cmpint(error, ==, CONTEXT_HISTORY_ERROR_NONE);
+
+       context_history_record_destroy(record);
+}
+
+void utc_context_history_record_insert_n(void)
+{
+       int error = CONTEXT_HISTORY_ERROR_NONE;
+
+       error = context_history_record_insert(NULL, CONTEXT_HISTORY_START_MUSIC);
+       g_assert_cmpint(error, ==, CONTEXT_HISTORY_ERROR_INVALID_PARAMETER);
+}
+
+
diff --git a/test/src/utc_context_history.h b/test/src/utc_context_history.h
new file mode 100644 (file)
index 0000000..492c018
--- /dev/null
@@ -0,0 +1,77 @@
+/*
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ *
+ * 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 __CONTEXT_CONTEXT_HISTORY_API_TEST_H__
+#define __CONTEXT_CONTEXT_HISTORY_API_TEST_H__
+
+void utc_context_history_create_p(void);
+void utc_context_history_create_n(void);
+
+void utc_context_history_destroy_p(void);
+void utc_context_history_destroy_n(void);
+
+void utc_context_history_filter_create_p(void);
+void utc_context_history_filter_create_n(void);
+
+void utc_context_history_filter_destroy_p(void);
+void utc_context_history_filter_destroy_n(void);
+
+void utc_context_history_filter_set_int_p(void);
+void utc_context_history_filter_set_int_n(void);
+
+void utc_context_history_filter_set_string_p(void);
+void utc_context_history_filter_set_string_n(void);
+
+void utc_context_history_get_list_p(void);
+void utc_context_history_get_list_n(void);
+
+void utc_context_history_list_get_count_p(void);
+void utc_context_history_list_get_count_n(void);
+
+void utc_context_history_list_get_current_p(void);
+void utc_context_history_list_get_current_n(void);
+
+void utc_context_history_list_move_first_p(void);
+void utc_context_history_list_move_first_n(void);
+
+void utc_context_history_list_move_next_p(void);
+void utc_context_history_list_move_next_n(void);
+
+void utc_context_history_list_destroy_p(void);
+void utc_context_history_list_destroy_n(void);
+
+void utc_context_history_record_create_p(void);
+void utc_context_history_record_create_n(void);
+
+void utc_context_history_record_get_int_p(void);
+void utc_context_history_record_get_int_n(void);
+
+void utc_context_history_record_get_string_p(void);
+void utc_context_history_record_get_string_n(void);
+
+void utc_context_history_record_set_int_p(void);
+void utc_context_history_record_set_int_n(void);
+
+void utc_context_history_record_set_string_p(void);
+void utc_context_history_record_set_string_n(void);
+
+void utc_context_history_record_destroy_p(void);
+void utc_context_history_record_destroy_n(void);
+
+void utc_context_history_record_insert_p(void);
+void utc_context_history_record_insert_n(void);
+
+#endif /* __CONTEXT_CONTEXT_HISTORY_API_TEST_H__ */
diff --git a/test/src/utc_context_trigger.c b/test/src/utc_context_trigger.c
new file mode 100644 (file)
index 0000000..d407bf9
--- /dev/null
@@ -0,0 +1,1187 @@
+/*
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ *
+ * 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 <glib.h>
+#include <dlog.h>
+#include <context_trigger.h>
+#include <context_trigger_internal.h>
+#include "utc_context_trigger.h"
+#include <stdlib.h>
+
+#define RED(X)         "\033[1;31m"X"\033[0m"
+#define GREEN(X)       "\033[1;32m"X"\033[0m"
+#define YELLOW(X)      "\033[1;33m"X"\033[0m"
+#define BLUE(X)                "\033[1;34m"X"\033[0m"
+
+static GMainLoop *mainloop = NULL;
+static int rid;
+
+app_control_h app;
+
+void initialize(void)
+{
+       g_print("Initialize");
+
+       int ret = app_control_create(&app);
+       g_assert_cmpint(ret, ==, APP_CONTROL_ERROR_NONE);
+
+       ret = app_control_set_operation(app, APP_CONTROL_OPERATION_DEFAULT);
+       g_assert_cmpint(ret, ==, APP_CONTROL_ERROR_NONE);
+
+       ret = app_control_set_app_id (app, "org.tizen.setting");
+       g_assert_cmpint(ret, ==, APP_CONTROL_ERROR_NONE);
+}
+
+void release(void)
+{
+       g_print("Release");
+
+       int ret = app_control_destroy(app);
+       g_assert_cmpint(ret, ==, APP_CONTROL_ERROR_NONE);
+}
+
+static void triggered_cb(int rule_id, context_trigger_error_e error, void* user_data)
+{
+       g_print(GREEN("#ContextTrigger# Rule%d triggered. error = %d\n"), rule_id, error);
+
+       g_main_loop_quit(mainloop);
+
+       g_assert_cmpint(error, == , CONTEXT_TRIGGER_ERROR_NONE);
+       g_assert_cmpint(error, == , CONTEXT_TRIGGER_ERROR_NONE);
+       g_assert_cmpint(rid, ==, rule_id);
+       rid = 0;
+}
+
+void utc_context_trigger_create_p(void)
+{
+       int error = CONTEXT_TRIGGER_ERROR_NONE;
+       context_trigger_h handle = NULL;
+
+       error = context_trigger_create(&handle);
+       g_assert_cmpint(error, ==, CONTEXT_TRIGGER_ERROR_NONE);
+
+       context_trigger_destroy(handle);
+}
+
+void utc_context_trigger_create_n(void)
+{
+       int error = CONTEXT_TRIGGER_ERROR_NONE;
+
+       error = context_trigger_create(NULL);
+       g_assert_cmpint(error, ==, CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER);
+}
+
+void utc_context_trigger_destroy_p(void)
+{
+       int error = CONTEXT_TRIGGER_ERROR_NONE;
+       context_trigger_h handle;
+
+       context_trigger_create(&handle);
+       error = context_trigger_destroy(handle);
+
+       g_assert_cmpint(error, ==, CONTEXT_TRIGGER_ERROR_NONE);
+}
+
+void utc_context_trigger_destroy_n(void)
+{
+       int error = CONTEXT_TRIGGER_ERROR_NONE;
+
+       error = context_trigger_destroy(NULL);
+       g_assert_cmpint(error, ==, CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER);
+}
+
+void utc_context_trigger_set_callback_p(void)
+{
+       int error = CONTEXT_TRIGGER_ERROR_NONE;
+       context_trigger_h handle = NULL;
+
+       error = context_trigger_create(&handle);
+
+       error = context_trigger_set_callback(handle, triggered_cb);
+       g_assert_cmpint(error, ==, CONTEXT_TRIGGER_ERROR_NONE);
+
+       context_trigger_destroy(handle);
+}
+
+void utc_context_trigger_set_callback_n(void)
+{
+       int error = CONTEXT_TRIGGER_ERROR_NONE;
+       context_trigger_h handle = NULL;
+
+       error = context_trigger_create(&handle);
+
+       error = context_trigger_set_callback(NULL, triggered_cb);
+       g_assert_cmpint(error, ==, CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER);
+
+       error = context_trigger_set_callback(handle, NULL);
+       g_assert_cmpint(error, ==, CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER);
+
+       context_trigger_destroy(handle);
+}
+
+void utc_context_trigger_add_rule_p(void)
+{
+       int error = CONTEXT_TRIGGER_ERROR_NONE;
+       context_trigger_rule_h rule = NULL;
+       context_trigger_rule_h rule2 = NULL;
+       context_trigger_rule_entry_h event = NULL;
+       context_trigger_rule_entry_h event2 = NULL;
+       context_trigger_rule_entry_h condition = NULL;
+       context_trigger_rule_entry_h condition2 = NULL;
+       context_trigger_rule_entry_h condition3 = NULL;
+       int rule_id;
+       int rule_id2;
+
+       context_trigger_rule_condition_create(CONTEXT_TRIGGER_CONDITION_DAY_OF_WEEK, CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, &condition3);
+       context_trigger_rule_entry_add_key(condition3, CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, "DayOfWeek");
+       context_trigger_rule_entry_add_comparison_string(condition3, "DayOfWeek", "==", "Mon");
+
+       context_trigger_rule_create(CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, &rule);
+       context_trigger_rule_event_create(CONTEXT_TRIGGER_EVENT_SYSTEM_HEADPHONE, CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, &event);
+       context_trigger_rule_entry_add_key(event, CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, "IsConnected");
+       context_trigger_rule_entry_add_comparison_int(event, "IsConnected", "==", CONTEXT_TRIGGER_TRUE);
+       context_trigger_rule_condition_create(CONTEXT_TRIGGER_CONDITION_SYSTEM_BATTERY, CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, &condition);
+       context_trigger_rule_entry_add_key(condition, CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, "Level");
+       context_trigger_rule_entry_add_comparison_string(condition, "Level", "==", "Normal");
+       context_trigger_rule_add_entry(rule, event);
+       context_trigger_rule_add_entry(rule, condition);
+       context_trigger_rule_add_entry(rule, condition3);
+       context_trigger_rule_set_action_app_control(rule, app);
+
+       error = context_trigger_add_rule(rule, &rule_id);
+       g_assert_cmpint(error, ==, CONTEXT_TRIGGER_ERROR_NONE);
+       g_assert_cmpint(rule_id, >, 0);
+
+       context_trigger_rule_create(CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, &rule2);
+       context_trigger_rule_event_create(CONTEXT_TRIGGER_EVENT_SYSTEM_HEADPHONE, CONTEXT_TRIGGER_LOGICAL_DISJUNCTION, &event2);
+       context_trigger_rule_entry_add_key(event2, CONTEXT_TRIGGER_LOGICAL_DISJUNCTION, "IsConnected");
+       context_trigger_rule_entry_add_comparison_int(event2, "IsConnected", "==", CONTEXT_TRIGGER_TRUE);
+       context_trigger_rule_condition_create(CONTEXT_TRIGGER_CONDITION_SYSTEM_BATTERY, CONTEXT_TRIGGER_LOGICAL_DISJUNCTION, &condition2);
+       context_trigger_rule_entry_add_key(condition2, CONTEXT_TRIGGER_LOGICAL_DISJUNCTION, "Level");
+       context_trigger_rule_entry_add_comparison_string(condition2, "Level", "==", "Normal");
+       context_trigger_rule_add_entry(rule2, event2);
+       context_trigger_rule_add_entry(rule2, condition3);
+       context_trigger_rule_add_entry(rule2, condition2);
+       context_trigger_rule_set_action_app_control(rule2, app);
+
+       error = context_trigger_add_rule(rule2, &rule_id2);
+       g_assert_cmpint(error, ==, CONTEXT_TRIGGER_ERROR_NONE);
+       g_assert_cmpint(rule_id, ==, rule_id2);
+
+       context_trigger_remove_rule(rule_id);
+       context_trigger_rule_entry_destroy(event);
+       context_trigger_rule_entry_destroy(condition);
+       context_trigger_rule_entry_destroy(event2);
+       context_trigger_rule_entry_destroy(condition2);
+       context_trigger_rule_entry_destroy(condition3);
+       context_trigger_rule_destroy(rule);
+       context_trigger_rule_destroy(rule2);
+}
+
+void utc_context_trigger_add_rule_n(void)
+{
+       int error = CONTEXT_TRIGGER_ERROR_NONE;
+       context_trigger_rule_h rule = NULL;
+       context_trigger_rule_entry_h event = NULL;
+       context_trigger_rule_entry_h condition = NULL;
+       int rule_id;
+
+       context_trigger_rule_create(CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, &rule);
+       context_trigger_rule_event_create(CONTEXT_TRIGGER_EVENT_SYSTEM_HEADPHONE, CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, &event);
+       context_trigger_rule_entry_add_key(event, CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, "IsConnected");
+       context_trigger_rule_entry_add_comparison_int(event, "IsConnected", "==", CONTEXT_TRIGGER_TRUE);
+       context_trigger_rule_condition_create(CONTEXT_TRIGGER_CONDITION_SYSTEM_BATTERY, CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, &condition);
+       context_trigger_rule_entry_add_key(condition, CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, "Level");
+       context_trigger_rule_entry_add_comparison_string(condition, "Level", "==", "Normal");
+       context_trigger_rule_add_entry(rule, condition);
+
+       error = context_trigger_add_rule(rule, &rule_id);
+       g_assert_cmpint(error, ==, CONTEXT_TRIGGER_ERROR_INVALID_RULE);
+
+       context_trigger_rule_add_entry(rule, event);
+
+       error = context_trigger_add_rule(rule, &rule_id);
+       g_assert_cmpint(error, ==, CONTEXT_TRIGGER_ERROR_INVALID_RULE);
+
+       context_trigger_rule_set_action_app_control(rule, app);
+
+       error = context_trigger_add_rule(NULL, &rule_id);
+       g_assert_cmpint(error, ==, CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER);
+
+       error = context_trigger_add_rule(rule, NULL);
+       g_assert_cmpint(error, ==, CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER);
+
+       context_trigger_rule_entry_destroy(event);
+       context_trigger_rule_entry_destroy(condition);
+       context_trigger_rule_destroy(rule);
+}
+
+void utc_context_trigger_remove_rule_p(void)
+{
+       int error = CONTEXT_TRIGGER_ERROR_NONE;
+       context_trigger_rule_h rule = NULL;
+       context_trigger_rule_entry_h event = NULL;
+       int rule_id;
+
+       context_trigger_rule_create(CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, &rule);
+       context_trigger_rule_event_create(CONTEXT_TRIGGER_EVENT_SYSTEM_HEADPHONE, CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, &event);
+       context_trigger_rule_add_entry(rule, event);
+       context_trigger_rule_set_action_app_control(rule, app);
+       context_trigger_add_rule(rule, &rule_id);
+
+       error = context_trigger_remove_rule(rule_id);
+       g_assert_cmpint(error, ==, CONTEXT_TRIGGER_ERROR_NONE);
+
+       context_trigger_rule_entry_destroy(event);
+       context_trigger_rule_destroy(rule);
+}
+
+void utc_context_trigger_remove_rule_n(void)
+{
+       int error = CONTEXT_TRIGGER_ERROR_NONE;
+       context_trigger_h handle = NULL;
+       context_trigger_rule_h rule = NULL;
+       context_trigger_rule_entry_h event = NULL;
+       int rule_id;
+
+       context_trigger_create(&handle);
+       context_trigger_rule_create(CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, &rule);
+       context_trigger_rule_event_create(CONTEXT_TRIGGER_EVENT_SYSTEM_HEADPHONE, CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, &event);
+       context_trigger_rule_add_entry(rule, event);
+       context_trigger_rule_set_action_app_control(rule, app);
+       context_trigger_add_rule(rule, &rule_id);
+       context_trigger_set_callback(handle, triggered_cb);
+       context_trigger_enable_rule_with_handle(handle, rule_id, NULL);
+
+       error = context_trigger_remove_rule(-1);
+       g_assert_cmpint(error, ==, CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER);
+
+       error = context_trigger_remove_rule(rule_id);
+       g_assert_cmpint(error, ==, CONTEXT_TRIGGER_ERROR_RULE_ENABLED);
+
+       error = context_trigger_remove_rule(rule_id + 1);
+       g_assert_cmpint(error, ==, CONTEXT_TRIGGER_ERROR_RULE_NOT_EXIST);
+
+       context_trigger_disable_rule_with_handle(handle, rule_id);
+       context_trigger_remove_rule(rule_id);
+       context_trigger_rule_entry_destroy(event);
+       context_trigger_rule_destroy(rule);
+       context_trigger_destroy(handle);
+}
+
+void utc_context_trigger_enable_rule_p(void)
+{
+       int error = CONTEXT_TRIGGER_ERROR_NONE;
+       context_trigger_h handle = NULL;
+       context_trigger_rule_h rule = NULL;
+       context_trigger_rule_entry_h event = NULL;
+       context_trigger_rule_entry_h condition = NULL;
+       int rule_id;
+
+       context_trigger_create(&handle);
+       context_trigger_rule_create(CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, &rule);
+       context_trigger_rule_event_create(CONTEXT_TRIGGER_EVENT_SYSTEM_HEADPHONE, CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, &event);
+       context_trigger_rule_entry_add_key(event, CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, "IsConnected");
+       context_trigger_rule_entry_add_comparison_int(event, "IsConnected", "==", CONTEXT_TRIGGER_TRUE);
+       context_trigger_rule_condition_create(CONTEXT_TRIGGER_CONDITION_SYSTEM_BATTERY, CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, &condition);
+       context_trigger_rule_entry_add_key(condition, CONTEXT_TRIGGER_LOGICAL_DISJUNCTION, "Level");
+       context_trigger_rule_entry_add_comparison_string(condition, "Level", "==", "Normal");
+       context_trigger_rule_entry_add_comparison_string(condition, "Level", "==", "High");
+       context_trigger_rule_entry_add_comparison_string(condition, "Level", "==", "Full");
+
+       context_trigger_rule_add_entry(rule, event);
+       context_trigger_rule_add_entry(rule, condition);
+       context_trigger_rule_set_action_app_control(rule, app);
+       context_trigger_add_rule(rule, &rule_id);
+       context_trigger_set_callback(handle, triggered_cb);
+       rid = rule_id;
+
+       error = context_trigger_enable_rule_with_handle(handle, rule_id, NULL);
+       g_assert_cmpint(error, ==, CONTEXT_TRIGGER_ERROR_NONE);
+
+       g_print(YELLOW("\n#ContextTrigger# When any type of headphone is connected, if battery is normal, high, or full...\n"));
+       mainloop = g_main_loop_new(NULL, FALSE);
+       g_main_loop_run(mainloop);
+
+       g_main_loop_unref(mainloop);
+
+       context_trigger_disable_rule_with_handle(handle, rule_id);
+       context_trigger_remove_rule(rule_id);
+       context_trigger_rule_entry_destroy(event);
+       context_trigger_rule_entry_destroy(condition);
+       context_trigger_rule_destroy(rule);
+       context_trigger_destroy(handle);
+}
+
+void utc_context_trigger_enable_rule_n(void)
+{
+       int error = CONTEXT_TRIGGER_ERROR_NONE;
+       context_trigger_h handle = NULL;
+       context_trigger_rule_h rule = NULL;
+       context_trigger_rule_entry_h event = NULL;
+       int rule_id;
+
+       context_trigger_create(&handle);
+       context_trigger_rule_create(CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, &rule);
+       context_trigger_rule_event_create(CONTEXT_TRIGGER_EVENT_SYSTEM_HEADPHONE, CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, &event);
+       context_trigger_rule_add_entry(rule, event);
+       context_trigger_rule_set_action_app_control(rule, app);
+       context_trigger_add_rule(rule, &rule_id);
+
+       error = context_trigger_enable_rule_with_handle(NULL, rule_id, NULL);
+       g_assert_cmpint(error, ==, CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER);
+
+       error = context_trigger_enable_rule_with_handle(handle, -1, NULL);
+       g_assert_cmpint(error, ==, CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER);
+
+       error = context_trigger_enable_rule_with_handle(handle, rule_id, NULL);
+       g_assert_cmpint(error, ==, CONTEXT_TRIGGER_ERROR_CALLBACK_NOT_REGISTERED);
+
+       context_trigger_set_callback(handle, triggered_cb);
+
+       error = context_trigger_enable_rule_with_handle(handle, rule_id+1, NULL);
+       g_assert_cmpint(error, ==, CONTEXT_TRIGGER_ERROR_RULE_NOT_EXIST);
+
+       context_trigger_enable_rule_with_handle(handle, rule_id, NULL);
+
+       error = context_trigger_enable_rule_with_handle(handle, rule_id, NULL);
+       g_assert_cmpint(error, ==, CONTEXT_TRIGGER_ERROR_RULE_ENABLED);
+
+       context_trigger_disable_rule_with_handle(handle, rule_id);
+       context_trigger_remove_rule(rule_id);
+       context_trigger_rule_entry_destroy(event);
+       context_trigger_rule_destroy(rule);
+       context_trigger_destroy(handle);
+}
+
+void utc_context_trigger_disable_rule_p(void)
+{
+       int error = CONTEXT_TRIGGER_ERROR_NONE;
+       context_trigger_h handle = NULL;
+       context_trigger_rule_h rule = NULL;
+       context_trigger_rule_entry_h event = NULL;
+       int rule_id;
+
+       context_trigger_create(&handle);
+       context_trigger_rule_create(CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, &rule);
+       context_trigger_rule_event_create(CONTEXT_TRIGGER_EVENT_SYSTEM_HEADPHONE, CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, &event);
+       context_trigger_rule_add_entry(rule, event);
+       context_trigger_rule_set_action_app_control(rule, app);
+       context_trigger_add_rule(rule, &rule_id);
+       context_trigger_set_callback(handle, triggered_cb);
+       context_trigger_enable_rule_with_handle(handle, rule_id, NULL);
+
+       error = context_trigger_disable_rule_with_handle(handle, rule_id);
+       g_assert_cmpint(error, ==, CONTEXT_TRIGGER_ERROR_NONE);
+
+       context_trigger_remove_rule(rule_id);
+       context_trigger_rule_entry_destroy(event);
+       context_trigger_rule_destroy(rule);
+       context_trigger_destroy(handle);
+}
+
+void utc_context_trigger_disable_rule_n(void)
+{
+       int error = CONTEXT_TRIGGER_ERROR_NONE;
+       context_trigger_h handle = NULL;
+       context_trigger_rule_h rule = NULL;
+       context_trigger_rule_entry_h event = NULL;
+       int rule_id;
+
+       context_trigger_create(&handle);
+       context_trigger_rule_create(CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, &rule);
+       context_trigger_rule_event_create(CONTEXT_TRIGGER_EVENT_SYSTEM_HEADPHONE, CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, &event);
+       context_trigger_rule_add_entry(rule, event);
+       context_trigger_rule_set_action_app_control(rule, app);
+       context_trigger_add_rule(rule, &rule_id);
+       context_trigger_set_callback(handle, triggered_cb);
+       context_trigger_enable_rule_with_handle(handle, rule_id, NULL);
+
+       error = context_trigger_disable_rule_with_handle(NULL, rule_id);
+       g_assert_cmpint(error, ==, CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER);
+
+       error = context_trigger_disable_rule_with_handle(handle, -1);
+       g_assert_cmpint(error, ==, CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER);
+
+       error = context_trigger_disable_rule_with_handle(handle, rule_id + 1);
+       g_assert_cmpint(error, ==, CONTEXT_TRIGGER_ERROR_RULE_NOT_EXIST);
+
+       context_trigger_disable_rule_with_handle(handle, rule_id);
+
+       error = context_trigger_disable_rule_with_handle(handle, rule_id);
+       g_assert_cmpint(error, ==, CONTEXT_TRIGGER_ERROR_RULE_NOT_ENABLED);
+
+       context_trigger_remove_rule(rule_id);
+       context_trigger_rule_entry_destroy(event);
+       context_trigger_rule_destroy(rule);
+       context_trigger_destroy(handle);
+}
+
+void utc_context_trigger_get_own_rule_ids_p(void)
+{
+       int error = CONTEXT_TRIGGER_ERROR_NONE;
+       context_trigger_h handle = NULL;
+       context_trigger_rule_h rule1 = NULL;
+       context_trigger_rule_h rule2 = NULL;
+       context_trigger_rule_entry_h event1 = NULL;
+       context_trigger_rule_entry_h event2 = NULL;
+       int rule_id1;
+       int rule_id2;
+       int* enabled_arr;
+       int enabled_count;
+       int* disabled_arr;
+       int disabled_count;
+
+       error = context_trigger_get_own_rule_ids(&enabled_arr, &enabled_count, &disabled_arr, &disabled_count);
+       g_assert_cmpint(error, ==, CONTEXT_TRIGGER_ERROR_NONE);
+       g_assert_cmpint(enabled_count, ==, 0);
+       g_assert_cmpint(disabled_count, ==, 0);
+
+       if (enabled_arr) {
+               free(enabled_arr);
+               enabled_arr = NULL;
+       }
+
+       if (disabled_arr) {
+               free(disabled_arr);
+               disabled_arr = NULL;
+       }
+
+       context_trigger_create(&handle);
+       context_trigger_set_callback(handle, triggered_cb);
+       context_trigger_rule_create(CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, &rule1);
+       context_trigger_rule_event_create(CONTEXT_TRIGGER_EVENT_SYSTEM_HEADPHONE, CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, &event1);
+       context_trigger_rule_add_entry(rule1, event1);
+       context_trigger_rule_set_action_app_control(rule1, app);
+       context_trigger_add_rule(rule1, &rule_id1);
+       context_trigger_enable_rule_with_handle(handle, rule_id1, NULL);
+
+       context_trigger_rule_create(CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, &rule2);
+       context_trigger_rule_event_create(CONTEXT_TRIGGER_EVENT_SYSTEM_BATTERY, CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, &event2);
+       context_trigger_rule_add_entry(rule2, event2);
+       context_trigger_rule_set_action_app_control(rule2, app);
+       context_trigger_add_rule(rule2, &rule_id2);
+
+       error = context_trigger_get_own_rule_ids(&enabled_arr, &enabled_count, &disabled_arr, &disabled_count);
+       g_assert_cmpint(error, ==, CONTEXT_TRIGGER_ERROR_NONE);
+       g_assert_cmpint(enabled_count, ==, 1);
+       g_assert_cmpint(disabled_count, ==, 1);
+       g_assert_cmpint(rule_id1, ==, enabled_arr[0]);
+       g_assert_cmpint(rule_id2, ==, disabled_arr[0]);
+
+       if (enabled_arr) {
+               free(enabled_arr);
+               enabled_arr = NULL;
+       }
+
+       if (disabled_arr) {
+               free(disabled_arr);
+               disabled_arr = NULL;
+       }
+
+       context_trigger_disable_rule_with_handle(handle, rule_id1);
+       context_trigger_remove_rule(rule_id1);
+       context_trigger_remove_rule(rule_id2);
+       context_trigger_rule_entry_destroy(event1);
+       context_trigger_rule_entry_destroy(event2);
+       context_trigger_rule_destroy(rule1);
+       context_trigger_rule_destroy(rule2);
+       context_trigger_destroy(handle);
+}
+
+void utc_context_trigger_get_own_rule_ids_n(void)
+{
+       int error = CONTEXT_TRIGGER_ERROR_NONE;
+       int* arr1;
+       int count1;
+       int* arr2;
+       int count2;
+
+       error = context_trigger_get_own_rule_ids(&arr1, NULL, NULL, NULL);
+       g_assert_cmpint(error, ==, CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER);
+
+       error = context_trigger_get_own_rule_ids(NULL, &count1, NULL, NULL);
+       g_assert_cmpint(error, ==, CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER);
+
+       error = context_trigger_get_own_rule_ids(NULL, NULL, &arr2, NULL);
+       g_assert_cmpint(error, ==, CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER);
+
+       error = context_trigger_get_own_rule_ids(NULL, NULL, NULL, &count2);
+       g_assert_cmpint(error, ==, CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER);
+
+       error = context_trigger_get_own_rule_ids(&arr1, &count1, &arr2, NULL);
+       g_assert_cmpint(error, ==, CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER);
+
+       error = context_trigger_get_own_rule_ids(&arr1, &count1, NULL, &count2);
+       g_assert_cmpint(error, ==, CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER);
+
+       error = context_trigger_get_own_rule_ids(NULL, &count1, &arr2, &count2);
+       g_assert_cmpint(error, ==, CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER);
+
+       error = context_trigger_get_own_rule_ids(&arr1, NULL, &arr2, &count2);
+       g_assert_cmpint(error, ==, CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER);
+}
+
+void utc_context_trigger_get_rule_by_id_p(void)
+{
+       int error = CONTEXT_TRIGGER_ERROR_NONE;
+       context_trigger_rule_h rule = NULL;
+       context_trigger_rule_entry_h event = NULL;
+       int rule_id;
+       context_trigger_rule_h rule_result = NULL;
+
+       context_trigger_rule_create(CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, &rule);
+       context_trigger_rule_event_create(CONTEXT_TRIGGER_EVENT_SYSTEM_HEADPHONE, CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, &event);
+       context_trigger_rule_add_entry(rule, event);
+       context_trigger_rule_set_action_app_control(rule, app);
+       context_trigger_add_rule(rule, &rule_id);
+
+       error = context_trigger_get_rule_by_id(rule_id, &rule_result);
+       g_assert_cmpint(error, ==, CONTEXT_TRIGGER_ERROR_NONE);
+
+       context_trigger_remove_rule(rule_id);
+       context_trigger_rule_entry_destroy(event);
+       context_trigger_rule_destroy(rule);
+       context_trigger_rule_destroy(rule_result);
+}
+
+void utc_context_trigger_get_rule_by_id_n(void)
+{
+       int error = CONTEXT_TRIGGER_ERROR_NONE;
+       context_trigger_rule_h rule = NULL;
+       context_trigger_rule_entry_h event = NULL;
+       int rule_id;
+       context_trigger_rule_h rule_result = NULL;
+
+       error = context_trigger_get_rule_by_id(0, &rule_result);
+       g_assert_cmpint(error, ==, CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER);
+
+       context_trigger_rule_create(CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, &rule);
+       context_trigger_rule_event_create(CONTEXT_TRIGGER_EVENT_SYSTEM_HEADPHONE, CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, &event);
+       context_trigger_rule_add_entry(rule, event);
+       context_trigger_rule_set_action_app_control(rule, app);
+       context_trigger_add_rule(rule, &rule_id);
+
+       error = context_trigger_get_rule_by_id(rule_id, NULL);
+       g_assert_cmpint(error, ==, CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER);
+
+       error = context_trigger_get_rule_by_id(rule_id + 1, &rule_result);
+       g_assert_cmpint(error, ==, CONTEXT_TRIGGER_ERROR_RULE_NOT_EXIST);
+
+       context_trigger_remove_rule(rule_id);
+       context_trigger_rule_entry_destroy(event);
+       context_trigger_rule_destroy(rule);
+}
+
+void utc_context_trigger_rule_create_p(void)
+{
+       int error = CONTEXT_TRIGGER_ERROR_NONE;
+       context_trigger_rule_h rule = NULL;
+
+       error = context_trigger_rule_create(CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, &rule);
+       g_assert_cmpint(error, ==, CONTEXT_TRIGGER_ERROR_NONE);
+
+       context_trigger_rule_destroy(rule);
+}
+
+void utc_context_trigger_rule_create_n(void)
+{
+       int error = CONTEXT_TRIGGER_ERROR_NONE;
+       context_trigger_rule_h rule = NULL;
+
+       error = context_trigger_rule_create(-1, &rule);
+       g_assert_cmpint(error, ==, CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER);
+
+       error = context_trigger_rule_create(CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, NULL);
+       g_assert_cmpint(error, ==, CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER);
+}
+
+void utc_context_trigger_rule_destroy_p(void)
+{
+       int error = CONTEXT_TRIGGER_ERROR_NONE;
+       context_trigger_rule_h rule = NULL;
+
+       context_trigger_rule_create(CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, &rule);
+
+       error = context_trigger_rule_destroy(rule);
+       g_assert_cmpint(error, ==, CONTEXT_TRIGGER_ERROR_NONE);
+}
+
+void utc_context_trigger_rule_destroy_n(void)
+{
+       int error = CONTEXT_TRIGGER_ERROR_NONE;
+
+       error = context_trigger_rule_destroy(NULL);
+       g_assert_cmpint(error, ==, CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER);
+}
+
+void utc_context_trigger_rule_add_entry_p(void)
+{
+       int error = CONTEXT_TRIGGER_ERROR_NONE;
+       context_trigger_rule_h rule = NULL;
+       context_trigger_rule_entry_h event = NULL;
+       context_trigger_rule_entry_h condition = NULL;
+
+       context_trigger_rule_create(CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, &rule);
+       context_trigger_rule_event_create(CONTEXT_TRIGGER_EVENT_SYSTEM_HEADPHONE, CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, &event);
+       context_trigger_rule_condition_create(CONTEXT_TRIGGER_CONDITION_SYSTEM_BATTERY, CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, &condition);
+       context_trigger_rule_entry_add_key(condition, CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, "Level");
+       context_trigger_rule_entry_add_comparison_string(condition, "Level", "==", "Normal");
+
+       error = context_trigger_rule_add_entry(rule, event);
+       g_assert_cmpint(error, ==, CONTEXT_TRIGGER_ERROR_NONE);
+
+       error = context_trigger_rule_add_entry(rule, condition);
+       g_assert_cmpint(error, ==, CONTEXT_TRIGGER_ERROR_NONE);
+
+       context_trigger_rule_entry_destroy(event);
+       context_trigger_rule_entry_destroy(condition);
+       context_trigger_rule_destroy(rule);
+}
+
+void utc_context_trigger_rule_add_entry_n(void)
+{
+       int error = CONTEXT_TRIGGER_ERROR_NONE;
+       context_trigger_rule_h rule = NULL;
+       context_trigger_rule_entry_h event = NULL;
+       context_trigger_rule_entry_h event2 = NULL;
+       context_trigger_rule_entry_h condition = NULL;
+
+       context_trigger_rule_create(CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, &rule);
+       context_trigger_rule_event_create(CONTEXT_TRIGGER_EVENT_SYSTEM_HEADPHONE, CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, &event);
+       context_trigger_rule_event_create(CONTEXT_TRIGGER_EVENT_SYSTEM_BATTERY, CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, &event2);
+       context_trigger_rule_condition_create(CONTEXT_TRIGGER_CONDITION_DAY_OF_WEEK, CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, &condition);
+
+       error = context_trigger_rule_add_entry(NULL, event);
+       g_assert_cmpint(error, ==, CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER);
+
+       error = context_trigger_rule_add_entry(rule, NULL);
+       g_assert_cmpint(error, ==, CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER);
+
+       error = context_trigger_rule_add_entry(rule, event);
+       g_assert_cmpint(error, ==, CONTEXT_TRIGGER_ERROR_NONE);
+
+       error = context_trigger_rule_add_entry(rule, event2);
+       g_assert_cmpint(error, ==, CONTEXT_TRIGGER_ERROR_INVALID_RULE);
+
+       error = context_trigger_rule_add_entry(rule, condition);
+       g_assert_cmpint(error, ==, CONTEXT_TRIGGER_ERROR_NONE);
+
+       error = context_trigger_rule_add_entry(rule, condition);
+       g_assert_cmpint(error, ==, CONTEXT_TRIGGER_ERROR_INVALID_RULE);
+
+       context_trigger_rule_entry_destroy(event);
+       context_trigger_rule_entry_destroy(event2);
+       context_trigger_rule_entry_destroy(condition);
+       context_trigger_rule_destroy(rule);
+}
+
+void utc_context_trigger_rule_set_action_app_control_p(void)
+{
+       int error = CONTEXT_TRIGGER_ERROR_NONE;
+       context_trigger_h handle = NULL;
+       context_trigger_rule_h rule = NULL;
+       context_trigger_rule_entry_h event = NULL;
+       context_trigger_rule_entry_h condition = NULL;
+       int rule_id;
+
+       context_trigger_create(&handle);
+       context_trigger_rule_create(CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, &rule);
+       context_trigger_rule_event_create(CONTEXT_TRIGGER_EVENT_SYSTEM_HEADPHONE, CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, &event);
+       context_trigger_rule_entry_add_key(event, CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, "IsConnected");
+       context_trigger_rule_entry_add_comparison_int(event, "IsConnected", "==", CONTEXT_TRIGGER_TRUE);
+       context_trigger_rule_condition_create(CONTEXT_TRIGGER_CONDITION_SYSTEM_BATTERY, CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, &condition);
+       context_trigger_rule_entry_add_key(condition, CONTEXT_TRIGGER_LOGICAL_DISJUNCTION, "Level");
+       context_trigger_rule_entry_add_comparison_string(condition, "Level", "==", "Normal");
+       context_trigger_rule_entry_add_comparison_string(condition, "Level", "==", "High");
+       context_trigger_rule_entry_add_comparison_string(condition, "Level", "==", "Full");
+
+       context_trigger_rule_add_entry(rule, event);
+       context_trigger_rule_add_entry(rule, condition);
+
+       error = context_trigger_rule_set_action_app_control(rule, app);
+       g_assert_cmpint(error, ==, CONTEXT_TRIGGER_ERROR_NONE);
+
+       context_trigger_add_rule(rule, &rule_id);
+       context_trigger_set_callback(handle, triggered_cb);
+
+       error = context_trigger_enable_rule_with_handle(handle, rule_id, NULL);
+       g_assert_cmpint(error, ==, CONTEXT_TRIGGER_ERROR_NONE);
+       rid = rule_id;
+
+       g_print(YELLOW("\n#ContextTrigger# When any type of headphone is connected, if battery is normal, high, or full.... setting app will be executed...\n"));
+       mainloop = g_main_loop_new(NULL, FALSE);
+       g_main_loop_run(mainloop);
+
+       g_main_loop_unref(mainloop);
+
+       context_trigger_disable_rule_with_handle(handle, rule_id);
+       context_trigger_remove_rule(rule_id);
+       context_trigger_rule_entry_destroy(event);
+       context_trigger_rule_entry_destroy(condition);
+       context_trigger_rule_destroy(rule);
+       context_trigger_destroy(handle);
+}
+
+void utc_context_trigger_rule_set_action_app_control_n(void)
+{
+       int error = CONTEXT_TRIGGER_ERROR_NONE;
+
+       error = context_trigger_rule_set_action_app_control(NULL, app);
+       g_assert_cmpint(error, == , CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER);
+
+       context_trigger_rule_h rule = NULL;
+       context_trigger_rule_create(CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, &rule);
+       app_control_h invalid_app = NULL;
+
+       error = context_trigger_rule_set_action_app_control(rule, invalid_app);
+       g_assert_cmpint(error, == , CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER);
+
+       context_trigger_rule_destroy(rule);
+}
+
+void utc_context_trigger_rule_set_action_notification_p(void)
+{
+       int error = CONTEXT_TRIGGER_ERROR_NONE;
+       context_trigger_h handle = NULL;
+       context_trigger_rule_h rule = NULL;
+       context_trigger_rule_entry_h event = NULL;
+       context_trigger_rule_entry_h condition = NULL;
+       int rule_id;
+
+       context_trigger_create(&handle);
+       context_trigger_rule_create(CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, &rule);
+       context_trigger_rule_event_create(CONTEXT_TRIGGER_EVENT_SYSTEM_HEADPHONE, CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, &event);
+       context_trigger_rule_entry_add_key(event, CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, "IsConnected");
+       context_trigger_rule_entry_add_comparison_int(event, "IsConnected", "==", CONTEXT_TRIGGER_TRUE);
+       context_trigger_rule_condition_create(CONTEXT_TRIGGER_CONDITION_SYSTEM_BATTERY, CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, &condition);
+       context_trigger_rule_entry_add_key(condition, CONTEXT_TRIGGER_LOGICAL_DISJUNCTION, "Level");
+       context_trigger_rule_entry_add_comparison_string(condition, "Level", "==", "Normal");
+       context_trigger_rule_entry_add_comparison_string(condition, "Level", "==", "High");
+       context_trigger_rule_entry_add_comparison_string(condition, "Level", "==", "Full");
+
+       context_trigger_rule_add_entry(rule, event);
+       context_trigger_rule_add_entry(rule, condition);
+
+       error = context_trigger_rule_set_action_notification(rule, "Notification title", "Notification content", NULL, app);
+       g_assert_cmpint(error, ==, CONTEXT_TRIGGER_ERROR_NONE);
+
+       context_trigger_add_rule(rule, &rule_id);
+       context_trigger_set_callback(handle, triggered_cb);
+
+       error = context_trigger_enable_rule_with_handle(handle, rule_id, NULL);
+       g_assert_cmpint(error, ==, CONTEXT_TRIGGER_ERROR_NONE);
+       rid = rule_id;
+
+       g_print(YELLOW("\n#ContextTrigger# When any type of headphone is connected, if battery is normal, high, or full.... notification will be posted...\n"));
+       mainloop = g_main_loop_new(NULL, FALSE);
+       g_main_loop_run(mainloop);
+
+       g_main_loop_unref(mainloop);
+
+       context_trigger_disable_rule_with_handle(handle, rule_id);
+       context_trigger_remove_rule(rule_id);
+       context_trigger_rule_entry_destroy(event);
+       context_trigger_rule_entry_destroy(condition);
+       context_trigger_rule_destroy(rule);
+       context_trigger_destroy(handle);
+}
+
+void utc_context_trigger_rule_set_action_notification_n(void)
+{
+       int error = CONTEXT_TRIGGER_ERROR_NONE;
+
+       error = context_trigger_rule_set_action_notification(NULL, "Notification title", "Notification content", NULL, NULL);
+       g_assert_cmpint(error, == , CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER);
+
+       context_trigger_rule_h rule = NULL;
+       context_trigger_rule_create(CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, &rule);
+
+       error = context_trigger_rule_set_action_notification(rule, NULL, "Notification content", NULL, NULL);
+       g_assert_cmpint(error, == , CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER);
+
+       error = context_trigger_rule_set_action_notification(rule, "Notification title", NULL, NULL, NULL);
+       g_assert_cmpint(error, == , CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER);
+
+       context_trigger_rule_destroy(rule);
+}
+
+void utc_context_trigger_rule_set_description_p(void)
+{
+       int error = CONTEXT_TRIGGER_ERROR_NONE;
+       context_trigger_rule_h rule = NULL;
+
+       context_trigger_rule_create(CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, &rule);
+
+       error = context_trigger_rule_set_description(rule, "Rule description test");
+       g_assert_cmpint(error, ==, CONTEXT_TRIGGER_ERROR_NONE);
+
+       context_trigger_rule_destroy(rule);
+}
+
+void utc_context_trigger_rule_set_description_n(void)
+{
+       int error = CONTEXT_TRIGGER_ERROR_NONE;
+
+       error = context_trigger_rule_set_description(NULL, "Rule description test");
+       g_assert_cmpint(error, ==, CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER);
+}
+
+void utc_context_trigger_rule_get_description_p(void)
+{
+       int error = CONTEXT_TRIGGER_ERROR_NONE;
+       context_trigger_rule_h rule = NULL;
+       context_trigger_rule_entry_h event = NULL;
+       int rule_id;
+       context_trigger_rule_h rule_result = NULL;
+       const char* description = "When Headphone state changed";
+       char* des_result;
+
+       context_trigger_rule_create(CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, &rule);
+       context_trigger_rule_set_description(rule, description);
+       context_trigger_rule_event_create(CONTEXT_TRIGGER_EVENT_SYSTEM_HEADPHONE, CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, &event);
+       context_trigger_rule_add_entry(rule, event);
+       context_trigger_rule_set_action_app_control(rule, app);
+       context_trigger_add_rule(rule, &rule_id);
+       context_trigger_get_rule_by_id(rule_id, &rule_result);
+
+       error = context_trigger_rule_get_description(rule_result, &des_result);
+       g_assert_cmpint(error, ==, CONTEXT_TRIGGER_ERROR_NONE);
+       g_assert_cmpstr(des_result, ==, description);
+
+       if (des_result) {
+               free(des_result);
+               des_result = NULL;
+       }
+       context_trigger_remove_rule(rule_id);
+       context_trigger_rule_entry_destroy(event);
+       context_trigger_rule_destroy(rule);
+       context_trigger_rule_destroy(rule_result);
+}
+
+void utc_context_trigger_rule_get_description_n(void)
+{
+       int error = CONTEXT_TRIGGER_ERROR_NONE;
+       context_trigger_rule_h rule = NULL;
+       context_trigger_rule_entry_h event = NULL;
+       int rule_id;
+       context_trigger_rule_h rule_result = NULL;
+       const char* description = "When Headphone state changed";
+       char* des_result;
+
+       context_trigger_rule_create(CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, &rule);
+       context_trigger_rule_set_description(rule, description);
+       context_trigger_rule_event_create(CONTEXT_TRIGGER_EVENT_SYSTEM_HEADPHONE, CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, &event);
+       context_trigger_rule_add_entry(rule, event);
+       context_trigger_rule_set_action_app_control(rule, app);
+       context_trigger_add_rule(rule, &rule_id);
+       context_trigger_get_rule_by_id(rule_id, &rule_result);
+
+       error = context_trigger_rule_get_description(NULL, &des_result);
+       g_assert_cmpint(error, ==, CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER);
+
+       error = context_trigger_rule_get_description(rule_result, NULL);
+       g_assert_cmpint(error, ==, CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER);
+
+       context_trigger_remove_rule(rule_id);
+       context_trigger_rule_entry_destroy(event);
+       context_trigger_rule_destroy(rule);
+       context_trigger_rule_destroy(rule_result);
+}
+
+void utc_context_trigger_rule_event_create_p(void)
+{
+       int error = CONTEXT_TRIGGER_ERROR_NONE;
+       context_trigger_rule_entry_h event = NULL;
+
+       error = context_trigger_rule_event_create(CONTEXT_TRIGGER_EVENT_SYSTEM_HEADPHONE, CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, &event);
+       g_assert_cmpint(error, ==, CONTEXT_TRIGGER_ERROR_NONE);
+
+       context_trigger_rule_entry_destroy(event);
+}
+
+void utc_context_trigger_rule_event_create_n(void)
+{
+       int error = CONTEXT_TRIGGER_ERROR_NONE;
+       context_trigger_rule_entry_h event = NULL;
+
+       error = context_trigger_rule_event_create(-1, CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, &event);
+       g_assert_cmpint(error, ==, CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER);
+
+       error = context_trigger_rule_event_create(CONTEXT_TRIGGER_EVENT_SYSTEM_HEADPHONE, -1, &event);
+       g_assert_cmpint(error, ==, CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER);
+
+       error = context_trigger_rule_event_create(CONTEXT_TRIGGER_EVENT_SYSTEM_HEADPHONE, CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, NULL);
+       g_assert_cmpint(error, ==, CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER);
+}
+
+void utc_context_trigger_rule_event_is_supported_p(void)
+{
+       int error = CONTEXT_TRIGGER_ERROR_NONE;
+       bool supported;
+
+       error = context_trigger_rule_event_is_supported(CONTEXT_TRIGGER_EVENT_SYSTEM_HEADPHONE, &supported);
+       g_assert_cmpint(error, ==, CONTEXT_TRIGGER_ERROR_NONE);
+       g_assert(supported);
+
+       error = context_trigger_rule_event_is_supported(CONTEXT_TRIGGER_EVENT_ON_TIME, &supported);
+       g_assert_cmpint(error, ==, CONTEXT_TRIGGER_ERROR_NONE);
+       g_assert(supported);
+}
+
+void utc_context_trigger_rule_event_is_supported_n(void)
+{
+       int error = CONTEXT_TRIGGER_ERROR_NONE;
+       bool supported;
+
+       error = context_trigger_rule_event_is_supported(CONTEXT_TRIGGER_EVENT_SYSTEM_HEADPHONE, NULL);
+       g_assert_cmpint(error, ==, CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER);
+
+       error = context_trigger_rule_event_is_supported(-1, &supported);
+       g_assert_cmpint(error, ==, CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER);
+}
+
+void utc_context_trigger_rule_condition_create_p(void)
+{
+       int error = CONTEXT_TRIGGER_ERROR_NONE;
+       context_trigger_rule_entry_h condition = NULL;
+
+       error = context_trigger_rule_condition_create(CONTEXT_TRIGGER_CONDITION_SYSTEM_HEADPHONE, CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, &condition);
+       g_assert_cmpint(error, ==, CONTEXT_TRIGGER_ERROR_NONE);
+
+       context_trigger_rule_entry_destroy(condition);
+}
+
+void utc_context_trigger_rule_condition_create_n(void)
+{
+       int error = CONTEXT_TRIGGER_ERROR_NONE;
+       context_trigger_rule_entry_h condition = NULL;
+
+       error = context_trigger_rule_condition_create(-1, CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, &condition);
+       g_assert_cmpint(error, ==, CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER);
+
+       error = context_trigger_rule_condition_create(CONTEXT_TRIGGER_CONDITION_SYSTEM_HEADPHONE, -1, &condition);
+       g_assert_cmpint(error, ==, CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER);
+
+       error = context_trigger_rule_condition_create(CONTEXT_TRIGGER_CONDITION_SYSTEM_HEADPHONE, CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, NULL);
+       g_assert_cmpint(error, ==, CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER);
+}
+
+void utc_context_trigger_rule_condition_is_supported_p(void)
+{
+       int error = CONTEXT_TRIGGER_ERROR_NONE;
+       bool supported;
+
+       error = context_trigger_rule_condition_is_supported(CONTEXT_TRIGGER_CONDITION_SYSTEM_HEADPHONE, &supported);
+       g_assert_cmpint(error, ==, CONTEXT_TRIGGER_ERROR_NONE);
+       g_assert(supported);
+
+       error = context_trigger_rule_condition_is_supported(CONTEXT_TRIGGER_CONDITION_DAY_OF_MONTH, &supported);
+       g_assert_cmpint(error, ==, CONTEXT_TRIGGER_ERROR_NONE);
+       g_assert(supported);
+}
+
+void utc_context_trigger_rule_condition_is_supported_n(void)
+{
+       int error = CONTEXT_TRIGGER_ERROR_NONE;
+       bool supported;
+
+       error = context_trigger_rule_condition_is_supported(CONTEXT_TRIGGER_CONDITION_SYSTEM_HEADPHONE, NULL);
+       g_assert_cmpint(error, ==, CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER);
+
+       error = context_trigger_rule_condition_is_supported(-1, &supported);
+       g_assert_cmpint(error, ==, CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER);
+}
+
+void utc_context_trigger_rule_entry_destroy_p(void)
+{
+       int error = CONTEXT_TRIGGER_ERROR_NONE;
+       context_trigger_rule_entry_h event = NULL;
+       context_trigger_rule_entry_h condition = NULL;
+
+       context_trigger_rule_event_create(CONTEXT_TRIGGER_EVENT_SYSTEM_HEADPHONE, CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, &event);
+       context_trigger_rule_condition_create(CONTEXT_TRIGGER_CONDITION_SYSTEM_BATTERY, CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, &condition);
+
+       error = context_trigger_rule_entry_destroy(event);
+       g_assert_cmpint(error, ==, CONTEXT_TRIGGER_ERROR_NONE);
+
+       error = context_trigger_rule_entry_destroy(condition);
+       g_assert_cmpint(error, ==, CONTEXT_TRIGGER_ERROR_NONE);
+}
+
+void utc_context_trigger_rule_entry_destroy_n(void)
+{
+       int error = CONTEXT_TRIGGER_ERROR_NONE;
+
+       error = context_trigger_rule_entry_destroy(NULL);
+       g_assert_cmpint(error, ==, CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER);
+}
+
+void utc_context_trigger_rule_entry_add_key_p(void)
+{
+       int error = CONTEXT_TRIGGER_ERROR_NONE;
+       context_trigger_rule_entry_h event = NULL;
+
+       context_trigger_rule_event_create(CONTEXT_TRIGGER_EVENT_SYSTEM_HEADPHONE, CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, &event);
+
+       error = context_trigger_rule_entry_add_key(event, CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, "IsConnected");
+       g_assert_cmpint(error, ==, CONTEXT_TRIGGER_ERROR_NONE);
+
+       context_trigger_rule_entry_destroy(event);
+}
+
+void utc_context_trigger_rule_entry_add_key_n(void)
+{
+       int error = CONTEXT_TRIGGER_ERROR_NONE;
+       context_trigger_rule_entry_h event = NULL;
+
+       context_trigger_rule_event_create(CONTEXT_TRIGGER_EVENT_SYSTEM_HEADPHONE, CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, &event);
+
+       error = context_trigger_rule_entry_add_key(NULL, CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, "IsConnected");
+       g_assert_cmpint(error, ==, CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER);
+
+       error = context_trigger_rule_entry_add_key(event, -1, "IsConnected");
+       g_assert_cmpint(error, ==, CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER);
+
+       error = context_trigger_rule_entry_add_key(event, CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, NULL);
+       g_assert_cmpint(error, ==, CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER);
+
+       context_trigger_rule_entry_destroy(event);
+}
+
+void utc_context_trigger_rule_entry_add_comparison_int_p(void)
+{
+       int error = CONTEXT_TRIGGER_ERROR_NONE;
+       context_trigger_rule_entry_h event = NULL;
+
+       context_trigger_rule_event_create(CONTEXT_TRIGGER_EVENT_ON_TIME, CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, &event);
+       context_trigger_rule_entry_add_key(event, CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, "TimeOfDay");
+
+       error = context_trigger_rule_entry_add_comparison_int(event, "TimeOfDay", "==", 16);
+       g_assert_cmpint(error, ==, CONTEXT_TRIGGER_ERROR_NONE);
+
+       context_trigger_rule_entry_destroy(event);
+}
+
+void utc_context_trigger_rule_entry_add_comparison_int_n(void)
+{
+       int error = CONTEXT_TRIGGER_ERROR_NONE;
+       context_trigger_rule_entry_h event = NULL;
+
+       context_trigger_rule_event_create(CONTEXT_TRIGGER_EVENT_ON_TIME, CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, &event);
+
+       error = context_trigger_rule_entry_add_comparison_int(event, "TimeOfDay", "==", 16);
+       g_assert_cmpint(error, ==, CONTEXT_TRIGGER_ERROR_NO_DATA);
+
+       context_trigger_rule_entry_add_key(event, CONTEXT_TRIGGER_LOGICAL_DISJUNCTION, "TimeOfDay");
+
+       error = context_trigger_rule_entry_add_comparison_int(NULL, "TimeOfDay", "==", 16);
+       g_assert_cmpint(error, ==, CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER);
+
+       error = context_trigger_rule_entry_add_comparison_int(event, NULL, "==", 16);
+       g_assert_cmpint(error, ==, CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER);
+
+       error = context_trigger_rule_entry_add_comparison_int(event, "TimeOfDay", NULL, 16);
+       g_assert_cmpint(error, ==, CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER);
+
+       error = context_trigger_rule_entry_add_comparison_int(event, "TimeOfDay", "and", 16);
+       g_assert_cmpint(error, ==, CONTEXT_TRIGGER_ERROR_INVALID_RULE);
+
+       context_trigger_rule_entry_destroy(event);
+}
+
+/*
+void utc_context_trigger_rule_entry_add_comparison_double_p(void)
+{
+       int error = CONTEXT_TRIGGER_ERROR_NONE;
+       context_trigger_rule_entry_h event = NULL;
+
+       context_trigger_rule_event_create(CONTEXT_TRIGGER_EVENT_SYSTEM_BATTERY, CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, &event);
+
+       context_trigger_rule_entry_add_key(event, CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, "res");
+
+       error = context_trigger_rule_entry_add_comparison_double(event, "res", "==", 1);
+       g_assert_cmpint(error, ==, CONTEXT_TRIGGER_ERROR_NONE);
+
+       context_trigger_rule_entry_destroy(event);
+}
+
+void utc_context_trigger_rule_entry_add_comparison_double_n(void)
+{
+       int error = CONTEXT_TRIGGER_ERROR_NONE;
+       context_trigger_rule_entry_h event = NULL;
+
+       context_trigger_rule_event_create(CONTEXT_TRIGGER_EVENT_SYSTEM_BATTERY, CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, &event);
+
+       error = context_trigger_rule_entry_add_comparison_double(event, "res", "==", 1);
+       g_assert_cmpint(error, ==, CONTEXT_TRIGGER_ERROR_NO_DATA);
+
+       context_trigger_rule_entry_add_key(event, CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, "res");
+
+       error = context_trigger_rule_entry_add_comparison_double(NULL, "res", "==", 1);
+       g_assert_cmpint(error, ==, CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER);
+
+       error = context_trigger_rule_entry_add_comparison_double(event, NULL, "==", 1);
+       g_assert_cmpint(error, ==, CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER);
+
+       error = context_trigger_rule_entry_add_comparison_double(event, "res", NULL, 1);
+       g_assert_cmpint(error, ==, CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER);
+
+       error = context_trigger_rule_entry_add_comparison_double(event, "res", "and", 1);
+       g_assert_cmpint(error, ==, CONTEXT_TRIGGER_ERROR_INVALID_RULE);
+
+       context_trigger_rule_entry_destroy(event);
+}
+*/
+void utc_context_trigger_rule_entry_add_comparison_string_p(void)
+{
+       int error = CONTEXT_TRIGGER_ERROR_NONE;
+       context_trigger_rule_entry_h event = NULL;
+
+       context_trigger_rule_event_create(CONTEXT_TRIGGER_EVENT_SYSTEM_BATTERY, CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, &event);
+       context_trigger_rule_entry_add_key(event, CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, "Level");
+
+       error = context_trigger_rule_entry_add_comparison_string(event, "Level", "==", "Normal");
+       g_assert_cmpint(error, ==, CONTEXT_TRIGGER_ERROR_NONE);
+
+       context_trigger_rule_entry_destroy(event);
+}
+
+void utc_context_trigger_rule_entry_add_comparison_string_n(void)
+{
+       int error = CONTEXT_TRIGGER_ERROR_NONE;
+       context_trigger_rule_entry_h event = NULL;
+
+       context_trigger_rule_event_create(CONTEXT_TRIGGER_EVENT_SYSTEM_BATTERY, CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, &event);
+       error = context_trigger_rule_entry_add_comparison_string(event, "Level", "==", "Normal");
+       g_assert_cmpint(error, ==, CONTEXT_TRIGGER_ERROR_NO_DATA);
+
+       context_trigger_rule_entry_add_key(event, CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, "Level");
+
+       error = context_trigger_rule_entry_add_comparison_string(NULL, "Level", "==", "Normal");
+       g_assert_cmpint(error, ==, CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER);
+
+       error = context_trigger_rule_entry_add_comparison_string(event, NULL, "==", "Normal");
+       g_assert_cmpint(error, ==, CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER);
+
+       error = context_trigger_rule_entry_add_comparison_string(event, "Level", NULL, "Normal");
+       g_assert_cmpint(error, ==, CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER);
+
+       error = context_trigger_rule_entry_add_comparison_string(event, "Level", "and", "Normal");
+       g_assert_cmpint(error, ==, CONTEXT_TRIGGER_ERROR_INVALID_RULE);
+
+       context_trigger_rule_entry_destroy(event);
+}
diff --git a/test/src/utc_context_trigger.h b/test/src/utc_context_trigger.h
new file mode 100644 (file)
index 0000000..df262b6
--- /dev/null
@@ -0,0 +1,98 @@
+/*
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ *
+ * 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 __CONTEXT_CONTEXT_TRIGGER_API_TEST_H__
+#define __CONTEXT_CONTEXT_TRIGGER_API_TEST_H__
+
+void initialize(void);
+void release(void);
+
+void utc_context_trigger_create_p(void);
+void utc_context_trigger_create_n(void);
+
+void utc_context_trigger_destroy_p(void);
+void utc_context_trigger_destroy_n(void);
+
+void utc_context_trigger_set_callback_p(void);
+void utc_context_trigger_set_callback_n(void);
+
+void utc_context_trigger_add_rule_p(void);
+void utc_context_trigger_add_rule_n(void);
+
+void utc_context_trigger_remove_rule_p(void);
+void utc_context_trigger_remove_rule_n(void);
+
+void utc_context_trigger_enable_rule_p(void);
+void utc_context_trigger_enable_rule_n(void);
+
+void utc_context_trigger_disable_rule_p(void);
+void utc_context_trigger_disable_rule_n(void);
+
+void utc_context_trigger_get_own_rule_ids_p(void);
+void utc_context_trigger_get_own_rule_ids_n(void);
+
+void utc_context_trigger_get_rule_by_id_p(void);
+void utc_context_trigger_get_rule_by_id_n(void);
+
+void utc_context_trigger_rule_create_p(void);
+void utc_context_trigger_rule_create_n(void);
+
+void utc_context_trigger_rule_destroy_p(void);
+void utc_context_trigger_rule_destroy_n(void);
+
+void utc_context_trigger_rule_add_entry_p(void);
+void utc_context_trigger_rule_add_entry_n(void);
+
+void utc_context_trigger_rule_set_action_app_control_p(void);
+void utc_context_trigger_rule_set_action_app_control_n(void);
+
+void utc_context_trigger_rule_set_action_notification_p(void);
+void utc_context_trigger_rule_set_action_notification_n(void);
+
+void utc_context_trigger_rule_set_description_p(void);
+void utc_context_trigger_rule_set_description_n(void);
+
+void utc_context_trigger_rule_get_description_p(void);
+void utc_context_trigger_rule_get_description_n(void);
+
+void utc_context_trigger_rule_event_create_p(void);
+void utc_context_trigger_rule_event_create_n(void);
+
+void utc_context_trigger_rule_event_is_supported_p(void);
+void utc_context_trigger_rule_event_is_supported_n(void);
+
+void utc_context_trigger_rule_condition_create_p(void);
+void utc_context_trigger_rule_condition_create_n(void);
+
+void utc_context_trigger_rule_condition_is_supported_p(void);
+void utc_context_trigger_rule_condition_is_supported_n(void);
+
+void utc_context_trigger_rule_entry_destroy_p(void);
+void utc_context_trigger_rule_entry_destroy_n(void);
+
+void utc_context_trigger_rule_entry_add_key_p(void);
+void utc_context_trigger_rule_entry_add_key_n(void);
+
+void utc_context_trigger_rule_entry_add_comparison_int_p(void);
+void utc_context_trigger_rule_entry_add_comparison_int_n(void);
+/*
+void utc_context_trigger_rule_entry_add_comparison_double_p(void);
+void utc_context_trigger_rule_entry_add_comparison_double_n(void);
+*/
+void utc_context_trigger_rule_entry_add_comparison_string_p(void);
+void utc_context_trigger_rule_entry_add_comparison_string_n(void);
+
+#endif /* __CONTEXT_CONTEXT_TRIGGER_API_TEST_H__ */