From b7ca116dda4330f8356bc60e16d202093bca0323 Mon Sep 17 00:00:00 2001 From: Mu-Woong Date: Thu, 11 Jun 2015 20:29:16 +0900 Subject: [PATCH 01/16] Migrate from 2.4 code repo Change-Id: I430651c4e3b57a31110c17a3935e65a86ca89688 Signed-off-by: Mu-Woong --- .gitignore | 1 + AUTHORS | 3 + CMakeLists.txt | 82 +++ LICENSE | 204 +++++ context.pc.in | 13 + doc/context_history_doc.h | 910 +++++++++++++++++++++++ doc/context_trigger_doc.h | 495 +++++++++++++ include/context_history.h | 543 ++++++++++++++ include/context_history_types_internal.h | 50 ++ include/context_internal.h | 45 ++ include/context_trigger.h | 1065 +++++++++++++++++++++++++++ include/context_trigger_types_internal.h | 108 +++ internal/CMakeLists.txt | 49 ++ internal/context_internal.cpp | 84 +++ packaging/context.manifest | 5 + packaging/context.spec | 95 +++ src/context_history.cpp | 569 ++++++++++++++ src/context_trigger.cpp | 955 ++++++++++++++++++++++++ src/priv_util.cpp | 59 ++ src/priv_util.h | 30 + src/rule_info.h | 129 ++++ src/rule_validator.cpp | 403 ++++++++++ src/rule_validator.h | 40 + test/CMakeLists.txt | 40 + test/src/main.c | 145 ++++ test/src/utc_context_history.c | 586 +++++++++++++++ test/src/utc_context_history.h | 77 ++ test/src/utc_context_trigger.c | 1187 ++++++++++++++++++++++++++++++ test/src/utc_context_trigger.h | 98 +++ 29 files changed, 8070 insertions(+) create mode 100644 .gitignore create mode 100644 AUTHORS create mode 100644 CMakeLists.txt create mode 100644 LICENSE create mode 100644 context.pc.in create mode 100644 doc/context_history_doc.h create mode 100644 doc/context_trigger_doc.h create mode 100644 include/context_history.h create mode 100644 include/context_history_types_internal.h create mode 100644 include/context_internal.h create mode 100644 include/context_trigger.h create mode 100644 include/context_trigger_types_internal.h create mode 100644 internal/CMakeLists.txt create mode 100644 internal/context_internal.cpp create mode 100644 packaging/context.manifest create mode 100644 packaging/context.spec create mode 100644 src/context_history.cpp create mode 100644 src/context_trigger.cpp create mode 100644 src/priv_util.cpp create mode 100644 src/priv_util.h create mode 100644 src/rule_info.h create mode 100644 src/rule_validator.cpp create mode 100644 src/rule_validator.h create mode 100644 test/CMakeLists.txt create mode 100644 test/src/main.c create mode 100644 test/src/utc_context_history.c create mode 100644 test/src/utc_context_history.h create mode 100644 test/src/utc_context_trigger.c create mode 100644 test/src/utc_context_trigger.h diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a01ee28 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.*.swp diff --git a/AUTHORS b/AUTHORS new file mode 100644 index 0000000..d97a819 --- /dev/null +++ b/AUTHORS @@ -0,0 +1,3 @@ +Mu-Woong Lee +Jihoon Park +Somin Kim diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..6916b08 --- /dev/null +++ b/CMakeLists.txt @@ -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 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 index 0000000..378b991 --- /dev/null +++ b/context.pc.in @@ -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 index 0000000..c08d9ab --- /dev/null +++ b/doc/context_history_doc.h @@ -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 + * + * @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 read API provided by contextual history engine. + *The data is mainly categorized to Application Usage, Peak Time of Activity and Common Setting for Activity. @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. + * + *
    + *
  • #CONTEXT_HISTORY_RECENTLY_USED_APP @n + * Description : Returns recently used application list sorted by time in descending order. @n + * Required privilege : http://tizen.org/privilege/apphistory.read @n + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
    Table: Filters
    Filter Type Value Mandatory
    #CONTEXT_HISTORY_FILTER_TIME_SPAN integer Time span of data in days from today ( 1 ~ 90 ) O
    #CONTEXT_HISTORY_FILTER_RESULT_SIZE integer Result size of data set ( 1 ~ 50 ) O
    #CONTEXT_HISTORY_FILTER_START_TIME integer Start time in epoch time to load only data which is inserted after the specific time X
    #CONTEXT_HISTORY_FILTER_END_TIME integer End time in epoch time to load only data which is inserted before the specific time X
    #CONTEXT_HISTORY_FILTER_WIFI_BSSID string Wi-Fi BSSID value to filter X
    #CONTEXT_HISTORY_FILTER_AUDIO_JACK integer Audio jack status #context_history_filter_audio_jack_e X
    + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
    Table: Attributes
    Attribute Type Value
    #CONTEXT_HISTORY_APP_ID string Application id
    #CONTEXT_HISTORY_TOTAL_COUNT integer Total used count
    #CONTEXT_HISTORY_TOTAL_DURATION integer Total used time in second
    #CONTEXT_HISTORY_LAST_TIME integer Last used time in epoch time
    @n + *
  • #CONTEXT_HISTORY_FREQUENTLY_USED_APP @n + * Description : Returns frequently used application list sorted by used count in descending order. @n + * Required privilege : http://tizen.org/privilege/apphistory.read @n + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
    Table: Filters
    Filter Type Value Mandatory
    #CONTEXT_HISTORY_FILTER_TIME_SPAN integer Time span of data in days from today ( 1 ~ 90 ) O
    #CONTEXT_HISTORY_FILTER_RESULT_SIZE integer Result size of data set ( 1 ~ 50 ) O
    #CONTEXT_HISTORY_FILTER_START_TIME integer Start time in epoch time to load only data which is inserted after the specific time X
    #CONTEXT_HISTORY_FILTER_END_TIME integer End time in epoch time to load only data which is inserted before the specific time X
    #CONTEXT_HISTORY_FILTER_WIFI_BSSID string Wi-Fi BSSID value to filter X
    #CONTEXT_HISTORY_FILTER_AUDIO_JACK integer Audio jack status #context_history_filter_audio_jack_e X
    + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
    Table: Attributes
    Attribute Type Value
    #CONTEXT_HISTORY_APP_ID string Application id
    #CONTEXT_HISTORY_TOTAL_COUNT integer Total used count
    #CONTEXT_HISTORY_TOTAL_DURATION integer Total used time in second
    #CONTEXT_HISTORY_LAST_TIME integer Last used time in epoch time
    @n + *
  • #CONTEXT_HISTORY_RARELY_USED_APP @n + * Description : Returns rarely used application list sorted by time in descending order. @n + * Required privilege : http://tizen.org/privilege/apphistory.read @n + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
    Table: Filters
    Filter Type Value Mandatory
    #CONTEXT_HISTORY_FILTER_TIME_SPAN integer Time span of data in days from today ( 1 ~ 90 ) O
    #CONTEXT_HISTORY_FILTER_RESULT_SIZE integer Result size of data set ( 1 ~ 50 ) O
    #CONTEXT_HISTORY_FILTER_START_TIME integer Start time in epoch time to load only data which is inserted after the specific time X
    #CONTEXT_HISTORY_FILTER_END_TIME integer End time in epoch time to load only data which is inserted before the specific time X
    + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
    Table: Attributes
    Attribute Type Value
    #CONTEXT_HISTORY_APP_ID string Application id
    #CONTEXT_HISTORY_TOTAL_COUNT integer Total used count
    #CONTEXT_HISTORY_TOTAL_DURATION integer Total used time in second
    #CONTEXT_HISTORY_LAST_TIME integer Last used time in epoch time
    @n + *
  • #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 : http://tizen.org/privilege/apphistory.read @n + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
    Table: Filters
    Filter Type Value Mandatory
    #CONTEXT_HISTORY_FILTER_TIME_SPAN integer Time span of data in days from today ( 1 ~ 90 ) O
    #CONTEXT_HISTORY_FILTER_RESULT_SIZE integer Result size of data set ( 1 ~ 50 ) O
    #CONTEXT_HISTORY_FILTER_START_TIME integer Start time in epoch time to load only data which is inserted after the specific time X
    #CONTEXT_HISTORY_FILTER_END_TIME integer End time in epoch time to load only data which is inserted before the specific time X
    #CONTEXT_HISTORY_FILTER_APP_ID string Application id to filter X
    #CONTEXT_HISTORY_FILTER_DAY_OF_WEEK integer Weekdays or weekends #context_history_filter_day_of_week_e X (Default : All days)
    + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
    Table: Attributes
    Attribute Type Value
    #CONTEXT_HISTORY_HOUR_OF_DAY integer Hour of day value(0~24) based on local time
    #CONTEXT_HISTORY_TOTAL_COUNT integer Event count
    @n + *
  • #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 : http://tizen.org/privilege/mediahistory.read @n + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
    Table: Filters
    Filter Type Value Mandatory
    #CONTEXT_HISTORY_FILTER_TIME_SPAN integer Time span of data in days from today ( 1 ~ 90 ) O
    #CONTEXT_HISTORY_FILTER_RESULT_SIZE integer Result size of data set ( 1 ~ 50 ) O
    #CONTEXT_HISTORY_FILTER_START_TIME integer Start time in epoch time to load only data which is inserted after the specific time X
    #CONTEXT_HISTORY_FILTER_END_TIME integer End time in epoch time to load only data which is inserted before the specific time X
    #CONTEXT_HISTORY_FILTER_APP_ID string The player application's id to filter X
    #CONTEXT_HISTORY_FILTER_DAY_OF_WEEK integer Weekdays or weekends #context_history_filter_day_of_week_e X (Default : All days)
    + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
    Table: Attributes
    Attribute Type Value
    #CONTEXT_HISTORY_HOUR_OF_DAY integer Hour of day value(0~24) based on local time
    #CONTEXT_HISTORY_TOTAL_COUNT integer Event count
    @n + *
  • #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 : http://tizen.org/privilege/mediahistory.read @n + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
    Table: Filters
    Filter Type Value Mandatory
    #CONTEXT_HISTORY_FILTER_TIME_SPAN integer Time span of data in days from today ( 1 ~ 90 ) O
    #CONTEXT_HISTORY_FILTER_RESULT_SIZE integer Result size of data set ( 1 ~ 50 ) O
    #CONTEXT_HISTORY_FILTER_START_TIME integer Start time in epoch time to load only data which is inserted after the specific time X
    #CONTEXT_HISTORY_FILTER_END_TIME integer End time in epoch time to load only data which is inserted before the specific time X
    #CONTEXT_HISTORY_FILTER_APP_ID string The player application's id to filter X
    #CONTEXT_HISTORY_FILTER_DAY_OF_WEEK integer Weekdays or weekends #context_history_filter_day_of_week_e X (Default : All days)
    + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
    Table: Attributes
    Attribute Type Value
    #CONTEXT_HISTORY_HOUR_OF_DAY integer Hour of day value(0~24) based on local time
    #CONTEXT_HISTORY_TOTAL_COUNT integer Event count
    @n + *
  • #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 : http://tizen.org/privilege/apphistory.read @n + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
    Table: Filters
    Filter Type Value Mandatory
    #CONTEXT_HISTORY_FILTER_TIME_SPAN integer Time span of data in days from today ( 1 ~ 90 ) O
    #CONTEXT_HISTORY_FILTER_START_TIME integer Start time in epoch time to load only data which is inserted after the specific time X
    #CONTEXT_HISTORY_FILTER_END_TIME integer End time in epoch time to load only data which is inserted before the specific time X
    #CONTEXT_HISTORY_FILTER_APP_ID string Application id to filter X (Default : All applications)
    + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
    Table: Attributes
    Attribute Type Value
    #CONTEXT_HISTORY_AUDIO_JACK integer The most common value of audio jack status
    #CONTEXT_HISTORY_SYSTEM_VOLUME integer The most common value of system volume
    #CONTEXT_HISTORY_MEDIA_VOLUME integer The most common value of media volume
    @n + *
  • #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 : http://tizen.org/privilege/mediahistory.read @n + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
    Table: Filters
    Filter Type Value Mandatory
    #CONTEXT_HISTORY_FILTER_TIME_SPAN integer Time span of data in days from today ( 1 ~ 90 ) O + *
    #CONTEXT_HISTORY_FILTER_START_TIME integer Start time in epoch time to load only data which is inserted after the specific time X
    #CONTEXT_HISTORY_FILTER_END_TIME integer End time in epoch time to load only data which is inserted before the specific time X
    #CONTEXT_HISTORY_FILTER_APP_ID string Application id to filter X (Default : All applications)
    + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
    Table: Attributes
    Attribute Type Value
    #CONTEXT_HISTORY_AUDIO_JACK integer The most common value of audio jack status
    #CONTEXT_HISTORY_SYSTEM_VOLUME integer The most common value of system volume
    #CONTEXT_HISTORY_MEDIA_VOLUME integer The most common value of media volume
    @n + *
  • #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 : http://tizen.org/privilege/mediahistory.read @n + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
    Table: Filters
    Filter Type Value Mandatory
    #CONTEXT_HISTORY_FILTER_TIME_SPAN integer Time span of data in days from today ( 1 ~ 90 ) O
    #CONTEXT_HISTORY_FILTER_START_TIME integer Start time in epoch time to load only data which is inserted after the specific time X
    #CONTEXT_HISTORY_FILTER_END_TIME integer End time in epoch time to load only data which is inserted before the specific time X
    #CONTEXT_HISTORY_FILTER_APP_ID string Application id to filter X (Default : All applications)
    + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
    Table: Attributes
    Attribute Type Value
    #CONTEXT_HISTORY_AUDIO_JACK integer The most common value of audio jack status
    #CONTEXT_HISTORY_SYSTEM_VOLUME integer The most common value of system volume
    #CONTEXT_HISTORY_MEDIA_VOLUME integer The most common value of media volume
    @n + *
  • #CONTEXT_HISTORY_FREQUENTLY_COMMUNICATED_ADDRESS @n + * Description : Returns frequently communicated address list sorted by communicated count in descending order. @n + * Required privilege : http://tizen.org/privilege/callhistory.read @n + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
    Table: Filters
    Filter Type Value Mandatory
    #CONTEXT_HISTORY_FILTER_TIME_SPAN integer Time span of data in days from today ( 1 ~ 90 ) O
    #CONTEXT_HISTORY_FILTER_RESULT_SIZE integer Result size of data set ( 1 ~ 50 ) O
    #CONTEXT_HISTORY_FILTER_START_TIME integer Start time in epoch time to load only data which is inserted after the specific time X
    #CONTEXT_HISTORY_FILTER_END_TIME integer End time in epoch time to load only data which is inserted before the specific time X
    #CONTEXT_HISTORY_FILTER_COMMUNICATION_TYPE integer Call or message logs #context_history_filter_communication_type_e X
    + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
    Table: Attributes
    Attribute Type Value
    #CONTEXT_HISTORY_ADDRESS string Address
    #CONTEXT_HISTORY_TOTAL_COUNT integer Total communication count
    #CONTEXT_HISTORY_TOTAL_DURATION integer Total communication duration
    #CONTEXT_HISTORY_LAST_TIME integer Last communication time in epoch time
    @n + *
+ * + *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 + *

To insert contextual event data to contextual history database

+ * The application can insert contextual event data into the contextual history database when a meaningful user event is generated. + * An event data 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. + * + *
    + *
  • #CONTEXT_HISTORY_START_MUSIC @n + * Description : The user started to listen to music. @n + * Required privilege : http://tizen.org/privilege/mediahistory.admin @n + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
    Table: Attributes
    Attribute Type Value
    #CONTEXT_HISTORY_URI string Uri of media file
    #CONTEXT_HISTORY_APP_ID string Application id that inserted event data
    #CONTEXT_HISTORY_LAST_POSITION integer The last played position of media file
    @n + *
  • #CONTEXT_HISTORY_STOP_MUSIC @n + * Description : The user stopped to listen to music. @n + * Required privilege : http://tizen.org/privilege/mediahistory.admin @n + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
    Table: Attributes
    Attribute Type Value
    #CONTEXT_HISTORY_URI string Uri of media file
    #CONTEXT_HISTORY_APP_ID string Application id that inserted event data
    #CONTEXT_HISTORY_LAST_POSITION integer The last played position of media file
    @n + *
  • #CONTEXT_HISTORY_START_VIDEO @n + * Description : The user started to watch a video. @n + * Required privilege : http://tizen.org/privilege/mediahistory.admin @n + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
    Table: Attributes
    Attribute Type Value
    #CONTEXT_HISTORY_URI string Uri of media file
    #CONTEXT_HISTORY_APP_ID string Application id that inserted event data
    #CONTEXT_HISTORY_LAST_POSITION integer The last played position of media file
    @n + *
  • #CONTEXT_HISTORY_STOP_VIDEO @n + * Description : The user stopped to watch the video. @n + * Required privilege : http://tizen.org/privilege/mediahistory.admin @n + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
    Table: Attributes
    Attribute Type Value
    #CONTEXT_HISTORY_URI string Uri of media file
    #CONTEXT_HISTORY_APP_ID string Application id that inserted event data
    #CONTEXT_HISTORY_LAST_POSITION integer The last played position of media file
    @n + *
+ * + *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 index 0000000..5ed94ec --- /dev/null +++ b/doc/context_trigger_doc.h @@ -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 + * + * @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: + * +
    +
  1. An Event: + 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. +
  2. A Set of Conditions: + 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. +
  3. An Action: If the conditions are satisfied, a designated action will be triggered. + The action can be an app launching request or a notification posting request. +
+ * + * 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, + * logical conjunction or disjunction, + * 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: Supported Attribute Keys
Event/ConditionAttribute KeyTypeAcceptable Values
#CONTEXT_TRIGGER_EVENT_ON_TIME#CONTEXT_TRIGGER_TIME_OF_DAYIntegerFrom 0 to 23 (hour)
#CONTEXT_TRIGGER_DAY_OF_WEEKString + #CONTEXT_TRIGGER_MON,
+ #CONTEXT_TRIGGER_TUE,
+ #CONTEXT_TRIGGER_WED,
+ #CONTEXT_TRIGGER_THU,
+ #CONTEXT_TRIGGER_FRI,
+ #CONTEXT_TRIGGER_SAT,
+ #CONTEXT_TRIGGER_SUN +
#CONTEXT_TRIGGER_CONDITION_TIME_OF_DAY#CONTEXT_TRIGGER_TIME_OF_DAYIntegerFrom 0 to 1439 (min)
#CONTEXT_TRIGGER_CONDITION_DAY_OF_WEEK#CONTEXT_TRIGGER_DAY_OF_WEEKString + #CONTEXT_TRIGGER_MON,
+ #CONTEXT_TRIGGER_TUE,
+ #CONTEXT_TRIGGER_WED,
+ #CONTEXT_TRIGGER_THU,
+ #CONTEXT_TRIGGER_FRI,
+ #CONTEXT_TRIGGER_SAT,
+ #CONTEXT_TRIGGER_SUN +
#CONTEXT_TRIGGER_CONDITION_DAY_OF_MONTH#CONTEXT_TRIGGER_DAY_OF_MONTHIntegerFrom 1 to 31
+ #CONTEXT_TRIGGER_EVENT_CHARGER
+ #CONTEXT_TRIGGER_EVENT_USB
+ #CONTEXT_TRIGGER_CONDITION_CHARGER
+ #CONTEXT_TRIGGER_CONDITION_USB +
#CONTEXT_TRIGGER_IS_CONNECTEDInteger#CONTEXT_TRIGGER_TRUE,
#CONTEXT_TRIGGER_FALSE
+ #CONTEXT_TRIGGER_EVENT_BATTERY
+ #CONTEXT_TRIGGER_CONDITION_BATTERY +
#CONTEXT_TRIGGER_LEVELString + #CONTEXT_TRIGGER_EMPTY,
+ #CONTEXT_TRIGGER_CRITICAL,
+ #CONTEXT_TRIGGER_LOW,
+ #CONTEXT_TRIGGER_NORMAL,
+ #CONTEXT_TRIGGER_HIGH,
+ #CONTEXT_TRIGGER_FULL +
#CONTEXT_TRIGGER_IS_CHARGINGInteger#CONTEXT_TRIGGER_TRUE,
#CONTEXT_TRIGGER_FALSE
+ #CONTEXT_TRIGGER_EVENT_FLIGHT_MODE
+ #CONTEXT_TRIGGER_EVENT_POWER_SAVING_MODE
+ #CONTEXT_TRIGGER_EVENT_SILENT_MODE
+ #CONTEXT_TRIGGER_EVENT_VIBRATION_MODE
+ #CONTEXT_TRIGGER_CONDITION_FLIGHT_MODE
+ #CONTEXT_TRIGGER_CONDITION_POWER_SAVING_MODE
+ #CONTEXT_TRIGGER_CONDITION_SILENT_MODE
+ #CONTEXT_TRIGGER_CONDITION_VIBRATION_MODE +
#CONTEXT_TRIGGER_IS_ENABLEDInteger#CONTEXT_TRIGGER_TRUE,
#CONTEXT_TRIGGER_FALSE
+ #CONTEXT_TRIGGER_EVENT_GPS
+ #CONTEXT_TRIGGER_CONDITION_GPS +
#CONTEXT_TRIGGER_STATEString + #CONTEXT_TRIGGER_DISABLED,
+ #CONTEXT_TRIGGER_SEARCHING,
+ #CONTEXT_TRIGGER_CONNECTED +
+ #CONTEXT_TRIGGER_EVENT_HEADPHONE
+ #CONTEXT_TRIGGER_CONDITION_HEADPHONE +
#CONTEXT_TRIGGER_IS_CONNECTEDInteger#CONTEXT_TRIGGER_TRUE,
#CONTEXT_TRIGGER_FALSE
#CONTEXT_TRIGGER_TYPEString + #CONTEXT_TRIGGER_NORMAL,
+ #CONTEXT_TRIGGER_HEADSET,
+ #CONTEXT_TRIGGER_BLUETOOTH +
+ #CONTEXT_TRIGGER_EVENT_WIFI
+ #CONTEXT_TRIGGER_CONDITION_WIFI +
#CONTEXT_TRIGGER_STATEString + #CONTEXT_TRIGGER_DISABLED,
+ #CONTEXT_TRIGGER_CONNECTED,
+ #CONTEXT_TRIGGER_UNCONNECTED +
#CONTEXT_TRIGGER_BSSIDStringWiFi BSSID
+ #CONTEXT_TRIGGER_EVENT_CALL
+ #CONTEXT_TRIGGER_CONDITION_CALL +
#CONTEXT_TRIGGER_STATEString + #CONTEXT_TRIGGER_IDLE,
+ #CONTEXT_TRIGGER_CONNECTING,
+ #CONTEXT_TRIGGER_CONNECTED +
#CONTEXT_TRIGGER_MEDIUMString#CONTEXT_TRIGGER_VOICE,
#CONTEXT_TRIGGER_VIDEO
#CONTEXT_TRIGGER_ADDRESSStringPhone number
#CONTEXT_TRIGGER_EVENT_EMAIL#CONTEXT_TRIGGER_EVENTString#CONTEXT_TRIGGER_RECEIVED,
#CONTEXT_TRIGGER_SENT
#CONTEXT_TRIGGER_EVENT_MESSAGE#CONTEXT_TRIGGER_EVENTString#CONTEXT_TRIGGER_RECEIVED
#CONTEXT_TRIGGER_TYPEString#CONTEXT_TRIGGER_SMS,
#CONTEXT_TRIGGER_MMS
#CONTEXT_TRIGGER_ADDRESSStringPhone number
+ #CONTEXT_TRIGGER_EVENT_ACTIVITY_STATIONARY,
+ #CONTEXT_TRIGGER_EVENT_ACTIVITY_WALKING,
+ #CONTEXT_TRIGGER_EVENT_ACTIVITY_RUNNING,
+ #CONTEXT_TRIGGER_EVENT_ACTIVITY_IN_VEHICLE +
#CONTEXT_TRIGGER_EVENTString#CONTEXT_TRIGGER_DETECTED
#CONTEXT_TRIGGER_ACCURACYString#CONTEXT_TRIGGER_HIGH,
#CONTEXT_TRIGGER_NORMAL,
#CONTEXT_TRIGGER_LOW
#CONTEXT_TRIGGER_EVENT_PLACE#CONTEXT_TRIGGER_EVENTString#CONTEXT_TRIGGER_IN,
#CONTEXT_TRIGGER_OUT
+ #CONTEXT_TRIGGER_CONDITION_APP_USE_FREQUENCY,
+ #CONTEXT_TRIGGER_CONDITION_COMMUNICATION_FREQUENCY +
#CONTEXT_TRIGGER_RANKIntegerPositive integer
+ #CONTEXT_TRIGGER_CONDITION_APP_USE_FREQUENCY,
+ #CONTEXT_TRIGGER_CONDITION_COMMUNICATION_FREQUENCY,
+ #CONTEXT_TRIGGER_CONDITION_MUSIC_PLAYBACK_FREQUENCY,
+ #CONTEXT_TRIGGER_CONDITION_VIDEO_PLAYBACK_FREQUENCY +
#CONTEXT_TRIGGER_TOTAL_COUNTIntegerNonnegative integer
+ + * + * For each type of attribute, as operators, the followings are allowed: + * + +
    +
  • For integer attributes:
    + #CONTEXT_TRIGGER_EQUAL_TO ("=="), #CONTEXT_TRIGGER_NOT_EQUAL_TO ("!="),
    + #CONTEXT_TRIGGER_GREATER_THAN (">"), #CONTEXT_TRIGGER_GREATER_THAN_OR_EQUAL_TO (">="),
    + #CONTEXT_TRIGGER_LESS_THAN ("<"), #CONTEXT_TRIGGER_LESS_THAN_OR_EQUAL_TO ("<=") +
  • For string attributes:
    + #CONTEXT_TRIGGER_EQUAL_TO ("=="), #CONTEXT_TRIGGER_NOT_EQUAL_TO ("!=") +
+ + * + * @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: Supported Option Keys
Event/ConditionOption KeyTypeAcceptable Values
#CONTEXT_TRIGGER_EVENT_PLACE#CONTEXT_TRIGGER_PLACE_IDInteger + Place ID
+ See \ref CAPI_GEOFENCE_MANAGER_MODULE +
#CONTEXT_TRIGGER_CONDITION_APP_USE_FREQUENCY#CONTEXT_TRIGGER_APP_IDStringApplication ID
#CONTEXT_TRIGGER_CONDITION_COMMUNICATION_FREQUENCY#CONTEXT_TRIGGER_ADDRESSStringPhone number
+ #CONTEXT_TRIGGER_CONDITION_APP_USE_FREQUENCY,
+ #CONTEXT_TRIGGER_CONDITION_COMMUNICATION_FREQUENCY,
+ #CONTEXT_TRIGGER_CONDITION_MUSIC_PLAYBACK_FREQUENCY,
+ #CONTEXT_TRIGGER_CONDITION_VIDEO_PLAYBACK_FREQUENCY +
#CONTEXT_TRIGGER_TIME_OF_DAYString + Time interval of day, for example,
+ "13-15" denoting "from 1 PM to 3 PM". +
#CONTEXT_TRIGGER_DAY_OF_WEEKString + #CONTEXT_TRIGGER_MON,
+ #CONTEXT_TRIGGER_TUE,
+ #CONTEXT_TRIGGER_WED,
+ #CONTEXT_TRIGGER_THU,
+ #CONTEXT_TRIGGER_FRI,
+ #CONTEXT_TRIGGER_SAT,
+ #CONTEXT_TRIGGER_SUN,
+ #CONTEXT_TRIGGER_WEEKDAY,
+ #CONTEXT_TRIGGER_WEEKEND +
+ + * + * @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 + * Feature Element. + */ diff --git a/include/context_history.h b/include/context_history.h new file mode 100644 index 0000000..74546a6 --- /dev/null +++ b/include/context_history.h @@ -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 + +#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 index 0000000..fff24a2 --- /dev/null +++ b/include/context_history_types_internal.h @@ -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 + +#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 index 0000000..97d085e --- /dev/null +++ b/include/context_internal.h @@ -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 + +#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 index 0000000..113c2ef --- /dev/null +++ b/include/context_trigger.h @@ -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 +#include +#include + +#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 index 0000000..763cf04 --- /dev/null +++ b/include/context_trigger_types_internal.h @@ -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 index 0000000..061a20d --- /dev/null +++ b/internal/CMakeLists.txt @@ -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 index 0000000..36ce9d5 --- /dev/null +++ b/internal/context_internal.cpp @@ -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 +#include +#include +#include +#include +#include + +typedef std::map 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 index 0000000..a76fdba --- /dev/null +++ b/packaging/context.manifest @@ -0,0 +1,5 @@ + + + + + diff --git a/packaging/context.spec b/packaging/context.spec new file mode 100644 index 0000000..5c47e8d --- /dev/null +++ b/packaging/context.spec @@ -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 index 0000000..6ecac10 --- /dev/null +++ b/src/context_history.cpp @@ -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 +#include +#include +#include +#include + +#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 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 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 keys; + filter->jfilter.get_keys(&keys); + + for (std::list::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 index 0000000..4867e99 --- /dev/null +++ b/src/context_trigger.cpp @@ -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 +//#include +#include +#include +#include +#include +#include +#include +#include +#include +#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(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(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(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(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 + 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 index 0000000..ffee54b --- /dev/null +++ b/src/priv_util.cpp @@ -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 +#include +#include +#include +#include + +#include +#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 index 0000000..6ef1109 --- /dev/null +++ b/src/priv_util.h @@ -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 + +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 index 0000000..aaac67c --- /dev/null +++ b/src/rule_info.h @@ -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 index 0000000..129bede --- /dev/null +++ b/src/rule_validator.cpp @@ -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 +#include +#include +#include +#include +#include +#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 template_map_t; +template_map_t template_map; // + +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(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 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 index 0000000..cdda646 --- /dev/null +++ b/src/rule_validator.h @@ -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 + +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 index 0000000..95d23f3 --- /dev/null +++ b/test/CMakeLists.txt @@ -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 index 0000000..8eada05 --- /dev/null +++ b/test/src/main.c @@ -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 +#include +#include +#include + +#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 index 0000000..54ad3a5 --- /dev/null +++ b/test/src/utc_context_history.c @@ -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 +#include +#include +#include "utc_context_history.h" +#include + +#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 index 0000000..492c018 --- /dev/null +++ b/test/src/utc_context_history.h @@ -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 index 0000000..d407bf9 --- /dev/null +++ b/test/src/utc_context_trigger.c @@ -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 +#include +#include +#include +#include "utc_context_trigger.h" +#include + +#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 index 0000000..df262b6 --- /dev/null +++ b/test/src/utc_context_trigger.h @@ -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__ */ -- 2.7.4 From c89e4d77b2ce097780a5ad840ea0bf3feb4157a9 Mon Sep 17 00:00:00 2001 From: Mu-Woong Date: Fri, 12 Jun 2015 11:40:10 +0900 Subject: [PATCH 02/16] Update the domain tag Change-Id: I645444fdcd8bd90707416acf3a2346ba10f92c8e Signed-off-by: Mu-Woong --- packaging/context.spec | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packaging/context.spec b/packaging/context.spec index 5c47e8d..4393dfc 100644 --- a/packaging/context.spec +++ b/packaging/context.spec @@ -2,7 +2,7 @@ Name: context Summary: Tizen Context Framework Native API Version: 0.4.2 Release: 1 -Group: Framework/system +Group: System/API License: Apache-2.0 Source0: %{name}-%{version}.tar.gz @@ -70,7 +70,7 @@ cp LICENSE %{buildroot}/usr/share/license/%{name} %package devel Summary: Tizen Context Framework Native API (Development) -Group: Framework/system +Group: System/API Requires: %{name} = %{version}-%{release} %description devel @@ -83,7 +83,7 @@ Tizen Context Framework Native API (Development) %package internal Summary: Tizen Context Framework Internal Headers -Group: Framework/system +Group: System/API Requires: %{name} = %{version}-%{release} %description internal -- 2.7.4 From c0f98552fee63333ca32b8e92f0c6bf9d3c52924 Mon Sep 17 00:00:00 2001 From: Mu-Woong Date: Mon, 29 Jun 2015 17:34:59 +0900 Subject: [PATCH 03/16] Integrate changes from Tizen 2.4 - Remove redundant doxygen comments. All detailed descriptions are inlcuded in the programming guide and the tutorial. - Remove history record insertion APIs - Apply Tizen coding rules to the header files - Refactor history item - filter key pair validation routine - Remove context_internal API set. - Replace security-privilege-checker with libsmack - Replace deprecated privilege_checker_check_package_privilege() Change-Id: I2b8a0b505917f5e01cd8977d21b7dca39f83a8f2 Signed-off-by: Mu-Woong --- CMakeLists.txt | 10 +- doc/context_history_doc.h | 889 +--------------------- doc/context_trigger_doc.h | 418 +---------- include/context_history.h | 100 +-- include/context_history_types_internal.h | 7 +- include/context_internal.h | 45 -- include/context_trigger.h | 106 ++- include/context_trigger_types_internal.h | 2 +- internal/CMakeLists.txt | 49 -- internal/context_internal.cpp | 84 --- packaging/context.spec | 15 +- src/context_history.cpp | 162 ++-- src/context_trigger.cpp | 6 +- src/priv_util.cpp | 42 +- src/rule_validator.h | 8 +- test/CMakeLists.txt | 40 - test/src/main.c | 145 ---- test/src/utc_context_history.c | 586 --------------- test/src/utc_context_history.h | 77 -- test/src/utc_context_trigger.c | 1187 ------------------------------ test/src/utc_context_trigger.h | 98 --- 21 files changed, 139 insertions(+), 3937 deletions(-) delete mode 100644 include/context_internal.h delete mode 100644 internal/CMakeLists.txt delete mode 100644 internal/context_internal.cpp delete mode 100644 test/CMakeLists.txt delete mode 100644 test/src/main.c delete mode 100644 test/src/utc_context_history.c delete mode 100644 test/src/utc_context_history.h delete mode 100644 test/src/utc_context_trigger.c delete mode 100644 test/src/utc_context_trigger.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 6916b08..1c80c4d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,7 +10,7 @@ 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") +SET(DEPS "aul bundle pkgmgr-info libsmack capi-appfw-app-control context-common") # Dependencies regarding profiles IF("${PROFILE}" STREQUAL "mobile") @@ -54,7 +54,6 @@ INSTALL(TARGETS ${target} DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT RuntimeL INSTALL( DIRECTORY ${CMAKE_SOURCE_DIR}/include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/context-service FILES_MATCHING PATTERN "*.h" - PATTERN "*_internal.h" EXCLUDE ) SET(VERSION ${FULLVER}) @@ -73,10 +72,3 @@ CONFIGURE_FILE( @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/doc/context_history_doc.h b/doc/context_history_doc.h index c08d9ab..617d984 100644 --- a/doc/context_history_doc.h +++ b/doc/context_history_doc.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * 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. @@ -26,885 +26,12 @@ * * @section CAPI_CONTEXT_HISTORY_MODULE_OVERVIEW Overview * + * An application can retrieve the user's device usages statistics and patterns via the contextual history API. + * This API mainly provides three categories of statistical usage patterns, including + * application usage, peak time of activities, and common setting for activities. + * See #context_history_data_e for all available statistic items. + * After choosing a statistic item to retrieve, a @em filter can be set to narrow down to the data you need.@n + * For more details about the available filter keys, and the data attributes provided by each item, + * please refer the programming guide and the tutorial. * - * @subsection CAPI_CONTEXT_HISTORY_MODULE_Get To get contextual history data - *The application can read derived contextual history data with read API provided by contextual history engine. - *The data is mainly categorized to Application Usage, Peak Time of Activity and Common Setting for Activity. @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. - * - *
    - *
  • #CONTEXT_HISTORY_RECENTLY_USED_APP @n - * Description : Returns recently used application list sorted by time in descending order. @n - * Required privilege : http://tizen.org/privilege/apphistory.read @n - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - *
    Table: Filters
    Filter Type Value Mandatory
    #CONTEXT_HISTORY_FILTER_TIME_SPAN integer Time span of data in days from today ( 1 ~ 90 ) O
    #CONTEXT_HISTORY_FILTER_RESULT_SIZE integer Result size of data set ( 1 ~ 50 ) O
    #CONTEXT_HISTORY_FILTER_START_TIME integer Start time in epoch time to load only data which is inserted after the specific time X
    #CONTEXT_HISTORY_FILTER_END_TIME integer End time in epoch time to load only data which is inserted before the specific time X
    #CONTEXT_HISTORY_FILTER_WIFI_BSSID string Wi-Fi BSSID value to filter X
    #CONTEXT_HISTORY_FILTER_AUDIO_JACK integer Audio jack status #context_history_filter_audio_jack_e X
    - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - *
    Table: Attributes
    Attribute Type Value
    #CONTEXT_HISTORY_APP_ID string Application id
    #CONTEXT_HISTORY_TOTAL_COUNT integer Total used count
    #CONTEXT_HISTORY_TOTAL_DURATION integer Total used time in second
    #CONTEXT_HISTORY_LAST_TIME integer Last used time in epoch time
    @n - *
  • #CONTEXT_HISTORY_FREQUENTLY_USED_APP @n - * Description : Returns frequently used application list sorted by used count in descending order. @n - * Required privilege : http://tizen.org/privilege/apphistory.read @n - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - *
    Table: Filters
    Filter Type Value Mandatory
    #CONTEXT_HISTORY_FILTER_TIME_SPAN integer Time span of data in days from today ( 1 ~ 90 ) O
    #CONTEXT_HISTORY_FILTER_RESULT_SIZE integer Result size of data set ( 1 ~ 50 ) O
    #CONTEXT_HISTORY_FILTER_START_TIME integer Start time in epoch time to load only data which is inserted after the specific time X
    #CONTEXT_HISTORY_FILTER_END_TIME integer End time in epoch time to load only data which is inserted before the specific time X
    #CONTEXT_HISTORY_FILTER_WIFI_BSSID string Wi-Fi BSSID value to filter X
    #CONTEXT_HISTORY_FILTER_AUDIO_JACK integer Audio jack status #context_history_filter_audio_jack_e X
    - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - *
    Table: Attributes
    Attribute Type Value
    #CONTEXT_HISTORY_APP_ID string Application id
    #CONTEXT_HISTORY_TOTAL_COUNT integer Total used count
    #CONTEXT_HISTORY_TOTAL_DURATION integer Total used time in second
    #CONTEXT_HISTORY_LAST_TIME integer Last used time in epoch time
    @n - *
  • #CONTEXT_HISTORY_RARELY_USED_APP @n - * Description : Returns rarely used application list sorted by time in descending order. @n - * Required privilege : http://tizen.org/privilege/apphistory.read @n - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - *
    Table: Filters
    Filter Type Value Mandatory
    #CONTEXT_HISTORY_FILTER_TIME_SPAN integer Time span of data in days from today ( 1 ~ 90 ) O
    #CONTEXT_HISTORY_FILTER_RESULT_SIZE integer Result size of data set ( 1 ~ 50 ) O
    #CONTEXT_HISTORY_FILTER_START_TIME integer Start time in epoch time to load only data which is inserted after the specific time X
    #CONTEXT_HISTORY_FILTER_END_TIME integer End time in epoch time to load only data which is inserted before the specific time X
    - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - *
    Table: Attributes
    Attribute Type Value
    #CONTEXT_HISTORY_APP_ID string Application id
    #CONTEXT_HISTORY_TOTAL_COUNT integer Total used count
    #CONTEXT_HISTORY_TOTAL_DURATION integer Total used time in second
    #CONTEXT_HISTORY_LAST_TIME integer Last used time in epoch time
    @n - *
  • #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 : http://tizen.org/privilege/apphistory.read @n - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - *
    Table: Filters
    Filter Type Value Mandatory
    #CONTEXT_HISTORY_FILTER_TIME_SPAN integer Time span of data in days from today ( 1 ~ 90 ) O
    #CONTEXT_HISTORY_FILTER_RESULT_SIZE integer Result size of data set ( 1 ~ 50 ) O
    #CONTEXT_HISTORY_FILTER_START_TIME integer Start time in epoch time to load only data which is inserted after the specific time X
    #CONTEXT_HISTORY_FILTER_END_TIME integer End time in epoch time to load only data which is inserted before the specific time X
    #CONTEXT_HISTORY_FILTER_APP_ID string Application id to filter X
    #CONTEXT_HISTORY_FILTER_DAY_OF_WEEK integer Weekdays or weekends #context_history_filter_day_of_week_e X (Default : All days)
    - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - *
    Table: Attributes
    Attribute Type Value
    #CONTEXT_HISTORY_HOUR_OF_DAY integer Hour of day value(0~24) based on local time
    #CONTEXT_HISTORY_TOTAL_COUNT integer Event count
    @n - *
  • #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 : http://tizen.org/privilege/mediahistory.read @n - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - *
    Table: Filters
    Filter Type Value Mandatory
    #CONTEXT_HISTORY_FILTER_TIME_SPAN integer Time span of data in days from today ( 1 ~ 90 ) O
    #CONTEXT_HISTORY_FILTER_RESULT_SIZE integer Result size of data set ( 1 ~ 50 ) O
    #CONTEXT_HISTORY_FILTER_START_TIME integer Start time in epoch time to load only data which is inserted after the specific time X
    #CONTEXT_HISTORY_FILTER_END_TIME integer End time in epoch time to load only data which is inserted before the specific time X
    #CONTEXT_HISTORY_FILTER_APP_ID string The player application's id to filter X
    #CONTEXT_HISTORY_FILTER_DAY_OF_WEEK integer Weekdays or weekends #context_history_filter_day_of_week_e X (Default : All days)
    - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - *
    Table: Attributes
    Attribute Type Value
    #CONTEXT_HISTORY_HOUR_OF_DAY integer Hour of day value(0~24) based on local time
    #CONTEXT_HISTORY_TOTAL_COUNT integer Event count
    @n - *
  • #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 : http://tizen.org/privilege/mediahistory.read @n - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - *
    Table: Filters
    Filter Type Value Mandatory
    #CONTEXT_HISTORY_FILTER_TIME_SPAN integer Time span of data in days from today ( 1 ~ 90 ) O
    #CONTEXT_HISTORY_FILTER_RESULT_SIZE integer Result size of data set ( 1 ~ 50 ) O
    #CONTEXT_HISTORY_FILTER_START_TIME integer Start time in epoch time to load only data which is inserted after the specific time X
    #CONTEXT_HISTORY_FILTER_END_TIME integer End time in epoch time to load only data which is inserted before the specific time X
    #CONTEXT_HISTORY_FILTER_APP_ID string The player application's id to filter X
    #CONTEXT_HISTORY_FILTER_DAY_OF_WEEK integer Weekdays or weekends #context_history_filter_day_of_week_e X (Default : All days)
    - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - *
    Table: Attributes
    Attribute Type Value
    #CONTEXT_HISTORY_HOUR_OF_DAY integer Hour of day value(0~24) based on local time
    #CONTEXT_HISTORY_TOTAL_COUNT integer Event count
    @n - *
  • #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 : http://tizen.org/privilege/apphistory.read @n - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - *
    Table: Filters
    Filter Type Value Mandatory
    #CONTEXT_HISTORY_FILTER_TIME_SPAN integer Time span of data in days from today ( 1 ~ 90 ) O
    #CONTEXT_HISTORY_FILTER_START_TIME integer Start time in epoch time to load only data which is inserted after the specific time X
    #CONTEXT_HISTORY_FILTER_END_TIME integer End time in epoch time to load only data which is inserted before the specific time X
    #CONTEXT_HISTORY_FILTER_APP_ID string Application id to filter X (Default : All applications)
    - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - *
    Table: Attributes
    Attribute Type Value
    #CONTEXT_HISTORY_AUDIO_JACK integer The most common value of audio jack status
    #CONTEXT_HISTORY_SYSTEM_VOLUME integer The most common value of system volume
    #CONTEXT_HISTORY_MEDIA_VOLUME integer The most common value of media volume
    @n - *
  • #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 : http://tizen.org/privilege/mediahistory.read @n - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - *
    Table: Filters
    Filter Type Value Mandatory
    #CONTEXT_HISTORY_FILTER_TIME_SPAN integer Time span of data in days from today ( 1 ~ 90 ) O - *
    #CONTEXT_HISTORY_FILTER_START_TIME integer Start time in epoch time to load only data which is inserted after the specific time X
    #CONTEXT_HISTORY_FILTER_END_TIME integer End time in epoch time to load only data which is inserted before the specific time X
    #CONTEXT_HISTORY_FILTER_APP_ID string Application id to filter X (Default : All applications)
    - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - *
    Table: Attributes
    Attribute Type Value
    #CONTEXT_HISTORY_AUDIO_JACK integer The most common value of audio jack status
    #CONTEXT_HISTORY_SYSTEM_VOLUME integer The most common value of system volume
    #CONTEXT_HISTORY_MEDIA_VOLUME integer The most common value of media volume
    @n - *
  • #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 : http://tizen.org/privilege/mediahistory.read @n - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - *
    Table: Filters
    Filter Type Value Mandatory
    #CONTEXT_HISTORY_FILTER_TIME_SPAN integer Time span of data in days from today ( 1 ~ 90 ) O
    #CONTEXT_HISTORY_FILTER_START_TIME integer Start time in epoch time to load only data which is inserted after the specific time X
    #CONTEXT_HISTORY_FILTER_END_TIME integer End time in epoch time to load only data which is inserted before the specific time X
    #CONTEXT_HISTORY_FILTER_APP_ID string Application id to filter X (Default : All applications)
    - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - *
    Table: Attributes
    Attribute Type Value
    #CONTEXT_HISTORY_AUDIO_JACK integer The most common value of audio jack status
    #CONTEXT_HISTORY_SYSTEM_VOLUME integer The most common value of system volume
    #CONTEXT_HISTORY_MEDIA_VOLUME integer The most common value of media volume
    @n - *
  • #CONTEXT_HISTORY_FREQUENTLY_COMMUNICATED_ADDRESS @n - * Description : Returns frequently communicated address list sorted by communicated count in descending order. @n - * Required privilege : http://tizen.org/privilege/callhistory.read @n - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - *
    Table: Filters
    Filter Type Value Mandatory
    #CONTEXT_HISTORY_FILTER_TIME_SPAN integer Time span of data in days from today ( 1 ~ 90 ) O
    #CONTEXT_HISTORY_FILTER_RESULT_SIZE integer Result size of data set ( 1 ~ 50 ) O
    #CONTEXT_HISTORY_FILTER_START_TIME integer Start time in epoch time to load only data which is inserted after the specific time X
    #CONTEXT_HISTORY_FILTER_END_TIME integer End time in epoch time to load only data which is inserted before the specific time X
    #CONTEXT_HISTORY_FILTER_COMMUNICATION_TYPE integer Call or message logs #context_history_filter_communication_type_e X
    - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - *
    Table: Attributes
    Attribute Type Value
    #CONTEXT_HISTORY_ADDRESS string Address
    #CONTEXT_HISTORY_TOTAL_COUNT integer Total communication count
    #CONTEXT_HISTORY_TOTAL_DURATION integer Total communication duration
    #CONTEXT_HISTORY_LAST_TIME integer Last communication time in epoch time
    @n - *
- * - *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 - *

To insert contextual event data to contextual history database

- * The application can insert contextual event data into the contextual history database when a meaningful user event is generated. - * An event data 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. - * - *
    - *
  • #CONTEXT_HISTORY_START_MUSIC @n - * Description : The user started to listen to music. @n - * Required privilege : http://tizen.org/privilege/mediahistory.admin @n - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - *
    Table: Attributes
    Attribute Type Value
    #CONTEXT_HISTORY_URI string Uri of media file
    #CONTEXT_HISTORY_APP_ID string Application id that inserted event data
    #CONTEXT_HISTORY_LAST_POSITION integer The last played position of media file
    @n - *
  • #CONTEXT_HISTORY_STOP_MUSIC @n - * Description : The user stopped to listen to music. @n - * Required privilege : http://tizen.org/privilege/mediahistory.admin @n - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - *
    Table: Attributes
    Attribute Type Value
    #CONTEXT_HISTORY_URI string Uri of media file
    #CONTEXT_HISTORY_APP_ID string Application id that inserted event data
    #CONTEXT_HISTORY_LAST_POSITION integer The last played position of media file
    @n - *
  • #CONTEXT_HISTORY_START_VIDEO @n - * Description : The user started to watch a video. @n - * Required privilege : http://tizen.org/privilege/mediahistory.admin @n - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - *
    Table: Attributes
    Attribute Type Value
    #CONTEXT_HISTORY_URI string Uri of media file
    #CONTEXT_HISTORY_APP_ID string Application id that inserted event data
    #CONTEXT_HISTORY_LAST_POSITION integer The last played position of media file
    @n - *
  • #CONTEXT_HISTORY_STOP_VIDEO @n - * Description : The user stopped to watch the video. @n - * Required privilege : http://tizen.org/privilege/mediahistory.admin @n - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - *
    Table: Attributes
    Attribute Type Value
    #CONTEXT_HISTORY_URI string Uri of media file
    #CONTEXT_HISTORY_APP_ID string Application id that inserted event data
    #CONTEXT_HISTORY_LAST_POSITION integer The last played position of media file
    @n - *
- * - *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 index 5ed94ec..c2e0f39 100644 --- a/doc/context_trigger_doc.h +++ b/doc/context_trigger_doc.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * 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. @@ -29,8 +29,6 @@ * 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: * @@ -52,84 +50,6 @@ The action can be an app launching request or a notification posting request. * - * 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, - * logical conjunction or disjunction, - * 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. @@ -137,345 +57,13 @@ * 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. + * For more details, please see the programming guide and the tutorial. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Table: Supported Attribute Keys
Event/ConditionAttribute KeyTypeAcceptable Values
#CONTEXT_TRIGGER_EVENT_ON_TIME#CONTEXT_TRIGGER_TIME_OF_DAYIntegerFrom 0 to 23 (hour)
#CONTEXT_TRIGGER_DAY_OF_WEEKString - #CONTEXT_TRIGGER_MON,
- #CONTEXT_TRIGGER_TUE,
- #CONTEXT_TRIGGER_WED,
- #CONTEXT_TRIGGER_THU,
- #CONTEXT_TRIGGER_FRI,
- #CONTEXT_TRIGGER_SAT,
- #CONTEXT_TRIGGER_SUN -
#CONTEXT_TRIGGER_CONDITION_TIME_OF_DAY#CONTEXT_TRIGGER_TIME_OF_DAYIntegerFrom 0 to 1439 (min)
#CONTEXT_TRIGGER_CONDITION_DAY_OF_WEEK#CONTEXT_TRIGGER_DAY_OF_WEEKString - #CONTEXT_TRIGGER_MON,
- #CONTEXT_TRIGGER_TUE,
- #CONTEXT_TRIGGER_WED,
- #CONTEXT_TRIGGER_THU,
- #CONTEXT_TRIGGER_FRI,
- #CONTEXT_TRIGGER_SAT,
- #CONTEXT_TRIGGER_SUN -
#CONTEXT_TRIGGER_CONDITION_DAY_OF_MONTH#CONTEXT_TRIGGER_DAY_OF_MONTHIntegerFrom 1 to 31
- #CONTEXT_TRIGGER_EVENT_CHARGER
- #CONTEXT_TRIGGER_EVENT_USB
- #CONTEXT_TRIGGER_CONDITION_CHARGER
- #CONTEXT_TRIGGER_CONDITION_USB -
#CONTEXT_TRIGGER_IS_CONNECTEDInteger#CONTEXT_TRIGGER_TRUE,
#CONTEXT_TRIGGER_FALSE
- #CONTEXT_TRIGGER_EVENT_BATTERY
- #CONTEXT_TRIGGER_CONDITION_BATTERY -
#CONTEXT_TRIGGER_LEVELString - #CONTEXT_TRIGGER_EMPTY,
- #CONTEXT_TRIGGER_CRITICAL,
- #CONTEXT_TRIGGER_LOW,
- #CONTEXT_TRIGGER_NORMAL,
- #CONTEXT_TRIGGER_HIGH,
- #CONTEXT_TRIGGER_FULL -
#CONTEXT_TRIGGER_IS_CHARGINGInteger#CONTEXT_TRIGGER_TRUE,
#CONTEXT_TRIGGER_FALSE
- #CONTEXT_TRIGGER_EVENT_FLIGHT_MODE
- #CONTEXT_TRIGGER_EVENT_POWER_SAVING_MODE
- #CONTEXT_TRIGGER_EVENT_SILENT_MODE
- #CONTEXT_TRIGGER_EVENT_VIBRATION_MODE
- #CONTEXT_TRIGGER_CONDITION_FLIGHT_MODE
- #CONTEXT_TRIGGER_CONDITION_POWER_SAVING_MODE
- #CONTEXT_TRIGGER_CONDITION_SILENT_MODE
- #CONTEXT_TRIGGER_CONDITION_VIBRATION_MODE -
#CONTEXT_TRIGGER_IS_ENABLEDInteger#CONTEXT_TRIGGER_TRUE,
#CONTEXT_TRIGGER_FALSE
- #CONTEXT_TRIGGER_EVENT_GPS
- #CONTEXT_TRIGGER_CONDITION_GPS -
#CONTEXT_TRIGGER_STATEString - #CONTEXT_TRIGGER_DISABLED,
- #CONTEXT_TRIGGER_SEARCHING,
- #CONTEXT_TRIGGER_CONNECTED -
- #CONTEXT_TRIGGER_EVENT_HEADPHONE
- #CONTEXT_TRIGGER_CONDITION_HEADPHONE -
#CONTEXT_TRIGGER_IS_CONNECTEDInteger#CONTEXT_TRIGGER_TRUE,
#CONTEXT_TRIGGER_FALSE
#CONTEXT_TRIGGER_TYPEString - #CONTEXT_TRIGGER_NORMAL,
- #CONTEXT_TRIGGER_HEADSET,
- #CONTEXT_TRIGGER_BLUETOOTH -
- #CONTEXT_TRIGGER_EVENT_WIFI
- #CONTEXT_TRIGGER_CONDITION_WIFI -
#CONTEXT_TRIGGER_STATEString - #CONTEXT_TRIGGER_DISABLED,
- #CONTEXT_TRIGGER_CONNECTED,
- #CONTEXT_TRIGGER_UNCONNECTED -
#CONTEXT_TRIGGER_BSSIDStringWiFi BSSID
- #CONTEXT_TRIGGER_EVENT_CALL
- #CONTEXT_TRIGGER_CONDITION_CALL -
#CONTEXT_TRIGGER_STATEString - #CONTEXT_TRIGGER_IDLE,
- #CONTEXT_TRIGGER_CONNECTING,
- #CONTEXT_TRIGGER_CONNECTED -
#CONTEXT_TRIGGER_MEDIUMString#CONTEXT_TRIGGER_VOICE,
#CONTEXT_TRIGGER_VIDEO
#CONTEXT_TRIGGER_ADDRESSStringPhone number
#CONTEXT_TRIGGER_EVENT_EMAIL#CONTEXT_TRIGGER_EVENTString#CONTEXT_TRIGGER_RECEIVED,
#CONTEXT_TRIGGER_SENT
#CONTEXT_TRIGGER_EVENT_MESSAGE#CONTEXT_TRIGGER_EVENTString#CONTEXT_TRIGGER_RECEIVED
#CONTEXT_TRIGGER_TYPEString#CONTEXT_TRIGGER_SMS,
#CONTEXT_TRIGGER_MMS
#CONTEXT_TRIGGER_ADDRESSStringPhone number
- #CONTEXT_TRIGGER_EVENT_ACTIVITY_STATIONARY,
- #CONTEXT_TRIGGER_EVENT_ACTIVITY_WALKING,
- #CONTEXT_TRIGGER_EVENT_ACTIVITY_RUNNING,
- #CONTEXT_TRIGGER_EVENT_ACTIVITY_IN_VEHICLE -
#CONTEXT_TRIGGER_EVENTString#CONTEXT_TRIGGER_DETECTED
#CONTEXT_TRIGGER_ACCURACYString#CONTEXT_TRIGGER_HIGH,
#CONTEXT_TRIGGER_NORMAL,
#CONTEXT_TRIGGER_LOW
#CONTEXT_TRIGGER_EVENT_PLACE#CONTEXT_TRIGGER_EVENTString#CONTEXT_TRIGGER_IN,
#CONTEXT_TRIGGER_OUT
- #CONTEXT_TRIGGER_CONDITION_APP_USE_FREQUENCY,
- #CONTEXT_TRIGGER_CONDITION_COMMUNICATION_FREQUENCY -
#CONTEXT_TRIGGER_RANKIntegerPositive integer
- #CONTEXT_TRIGGER_CONDITION_APP_USE_FREQUENCY,
- #CONTEXT_TRIGGER_CONDITION_COMMUNICATION_FREQUENCY,
- #CONTEXT_TRIGGER_CONDITION_MUSIC_PLAYBACK_FREQUENCY,
- #CONTEXT_TRIGGER_CONDITION_VIDEO_PLAYBACK_FREQUENCY -
#CONTEXT_TRIGGER_TOTAL_COUNTIntegerNonnegative integer
- - * - * For each type of attribute, as operators, the followings are allowed: - * - -
    -
  • For integer attributes:
    - #CONTEXT_TRIGGER_EQUAL_TO ("=="), #CONTEXT_TRIGGER_NOT_EQUAL_TO ("!="),
    - #CONTEXT_TRIGGER_GREATER_THAN (">"), #CONTEXT_TRIGGER_GREATER_THAN_OR_EQUAL_TO (">="),
    - #CONTEXT_TRIGGER_LESS_THAN ("<"), #CONTEXT_TRIGGER_LESS_THAN_OR_EQUAL_TO ("<=") -
  • For string attributes:
    - #CONTEXT_TRIGGER_EQUAL_TO ("=="), #CONTEXT_TRIGGER_NOT_EQUAL_TO ("!=") -
- - * - * @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: Supported Option Keys
Event/ConditionOption KeyTypeAcceptable Values
#CONTEXT_TRIGGER_EVENT_PLACE#CONTEXT_TRIGGER_PLACE_IDInteger - Place ID
- See \ref CAPI_GEOFENCE_MANAGER_MODULE -
#CONTEXT_TRIGGER_CONDITION_APP_USE_FREQUENCY#CONTEXT_TRIGGER_APP_IDStringApplication ID
#CONTEXT_TRIGGER_CONDITION_COMMUNICATION_FREQUENCY#CONTEXT_TRIGGER_ADDRESSStringPhone number
- #CONTEXT_TRIGGER_CONDITION_APP_USE_FREQUENCY,
- #CONTEXT_TRIGGER_CONDITION_COMMUNICATION_FREQUENCY,
- #CONTEXT_TRIGGER_CONDITION_MUSIC_PLAYBACK_FREQUENCY,
- #CONTEXT_TRIGGER_CONDITION_VIDEO_PLAYBACK_FREQUENCY -
#CONTEXT_TRIGGER_TIME_OF_DAYString - Time interval of day, for example,
- "13-15" denoting "from 1 PM to 3 PM". -
#CONTEXT_TRIGGER_DAY_OF_WEEKString - #CONTEXT_TRIGGER_MON,
- #CONTEXT_TRIGGER_TUE,
- #CONTEXT_TRIGGER_WED,
- #CONTEXT_TRIGGER_THU,
- #CONTEXT_TRIGGER_FRI,
- #CONTEXT_TRIGGER_SAT,
- #CONTEXT_TRIGGER_SUN,
- #CONTEXT_TRIGGER_WEEKDAY,
- #CONTEXT_TRIGGER_WEEKEND -
- * * @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 + * Some of the event and condition items in this API are related with one of the following features:@n * - http://tizen.org/feature/network.telephony * - http://tizen.org/feature/location.gps * - http://tizen.org/feature/network.bluetooth diff --git a/include/context_history.h b/include/context_history.h index 74546a6..f368993 100644 --- a/include/context_history.h +++ b/include/context_history.h @@ -22,7 +22,7 @@ #ifdef __cplusplus extern "C" { -#endif // __cplusplus +#endif /* __cplusplus */ /** * @addtogroup CAPI_CONTEXT_HISTORY_MODULE @@ -107,18 +107,6 @@ typedef enum { } 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 */ @@ -402,28 +390,6 @@ int context_history_list_move_next(context_history_list_h 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 * @@ -459,42 +425,6 @@ int context_history_record_get_int(context_history_record_h record, const char* 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 * @@ -508,36 +438,12 @@ int context_history_record_set_string(context_history_record_h record, const cha */ 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 /* __cplusplus */ /** * @} */ -#endif // __TIZEN_CONTEXT_HISTORY_H__ +#endif /* __TIZEN_CONTEXT_HISTORY_H__ */ diff --git a/include/context_history_types_internal.h b/include/context_history_types_internal.h index fff24a2..e240cf1 100644 --- a/include/context_history_types_internal.h +++ b/include/context_history_types_internal.h @@ -32,11 +32,6 @@ #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" @@ -47,4 +42,4 @@ #define CONTEXT_HISTORY_FILTER_KEY_WIFI_BSSID "BSSID" #define CONTEXT_HISTORY_FILTER_KEY_COMMUNICATION_TYPE "CommunicationType" -#endif // __TIZEN_CONTEXT_HISTORY_TYPES_INTERNAL_H__ +#endif /* __TIZEN_CONTEXT_HISTORY_TYPES_INTERNAL_H__ */ diff --git a/include/context_internal.h b/include/context_internal.h deleted file mode 100644 index 97d085e..0000000 --- a/include/context_internal.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * 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 - -#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 index 113c2ef..d0d5d93 100644 --- a/include/context_trigger.h +++ b/include/context_trigger.h @@ -28,7 +28,7 @@ #ifdef __cplusplus extern "C" { -#endif // __cplusplus +#endif /* __cplusplus */ /** * @brief The operator "is equal to". @@ -91,9 +91,7 @@ extern "C" { /** * @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", + * When being used with #CONTEXT_TRIGGER_EVENT_TIME or #CONTEXT_TRIGGER_CONDITION_TIME, 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 */ @@ -147,7 +145,7 @@ extern "C" { /** * @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. + * See the programming guide to find available right operands values. * @since_tizen 2.4 */ #define CONTEXT_TRIGGER_LEVEL "Level" @@ -155,7 +153,7 @@ extern "C" { /** * @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. + * See the programming guide to find available right operands. * @since_tizen 2.4 */ #define CONTEXT_TRIGGER_STATE "State" @@ -163,7 +161,7 @@ extern "C" { /** * @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. + * See the programming guide to find available right operands. * @since_tizen 2.4 */ #define CONTEXT_TRIGGER_BSSID "BSSID" @@ -171,7 +169,7 @@ extern "C" { /** * @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. + * See the programming guide to find available right operands. * @since_tizen 2.4 */ #define CONTEXT_TRIGGER_TYPE "Type" @@ -179,7 +177,7 @@ extern "C" { /** * @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. + * See the programming guide to find available right operands. * @since_tizen 2.4 */ #define CONTEXT_TRIGGER_EVENT "Event" @@ -187,7 +185,7 @@ extern "C" { /** * @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. + * See the programming guide to find available right operands. * @since_tizen 2.4 */ #define CONTEXT_TRIGGER_ACCURACY "Accuracy" @@ -195,7 +193,7 @@ extern "C" { /** * @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. + * See the programming guide to find available right operands. * @since_tizen 2.4 */ #define CONTEXT_TRIGGER_MEDIUM "Medium" @@ -203,7 +201,7 @@ extern "C" { /** * @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. + * See the programming guide to find the corresponding trigger events. * @since_tizen 2.4 */ #define CONTEXT_TRIGGER_PLACE_ID "PlaceId" @@ -211,7 +209,7 @@ extern "C" { /** * @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. + * See the programming guide to find the corresponding trigger events. * @since_tizen 2.4 */ #define CONTEXT_TRIGGER_APP_ID "AppId" @@ -220,7 +218,7 @@ extern "C" { * @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. + * See the programming guide and CAPI_CONTEXT_TRIGGER_MODULE_OPTION_FORMAT to find the corresponding items. * @since_tizen 2.4 */ #define CONTEXT_TRIGGER_ADDRESS "Address" @@ -228,7 +226,7 @@ extern "C" { /** * @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. + * See the programming guide to find available right operands. * @since_tizen 2.4 */ #define CONTEXT_TRIGGER_RANK "Rank" @@ -236,7 +234,7 @@ extern "C" { /** * @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. + * See the programming guide to find available right operands. * @since_tizen 2.4 */ #define CONTEXT_TRIGGER_TOTAL_COUNT "TotalCount" @@ -244,7 +242,7 @@ extern "C" { /** * @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. + * See the programming guide to find the corresponding left operand attribute keys. * @since_tizen 2.4 */ #define CONTEXT_TRIGGER_MON "Mon" @@ -252,7 +250,7 @@ extern "C" { /** * @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. + * See the programming guide to find the corresponding left operand attribute keys. * @since_tizen 2.4 */ #define CONTEXT_TRIGGER_TUE "Tue" @@ -260,7 +258,7 @@ extern "C" { /** * @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. + * See the programming guide to find the corresponding left operand attribute keys. * @since_tizen 2.4 */ #define CONTEXT_TRIGGER_WED "Wed" @@ -268,7 +266,7 @@ extern "C" { /** * @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. + * See the programming guide to find the corresponding left operand attribute keys. * @since_tizen 2.4 */ #define CONTEXT_TRIGGER_THU "Thu" @@ -276,7 +274,7 @@ extern "C" { /** * @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. + * See the programming guide to find the corresponding left operand attribute keys. * @since_tizen 2.4 */ #define CONTEXT_TRIGGER_FRI "Fri" @@ -284,7 +282,7 @@ extern "C" { /** * @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. + * See the programming guide to find the corresponding left operand attribute keys. * @since_tizen 2.4 */ #define CONTEXT_TRIGGER_SAT "Sat" @@ -292,7 +290,7 @@ extern "C" { /** * @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. + * See the programming guide to find the corresponding left operand attribute keys. * @since_tizen 2.4 */ #define CONTEXT_TRIGGER_SUN "Sun" @@ -300,7 +298,7 @@ extern "C" { /** * @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. + * See the programming guide to find the corresponding left operand attribute keys. * @since_tizen 2.4 */ #define CONTEXT_TRIGGER_WEEKDAY "Weekday" @@ -308,7 +306,7 @@ extern "C" { /** * @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. + * See the programming guide to find the corresponding left operand attribute keys. * @since_tizen 2.4 */ #define CONTEXT_TRIGGER_WEEKEND "Weekend" @@ -316,7 +314,7 @@ extern "C" { /** * @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. + * See the programming guide to find the corresponding left operand attribute keys. * @since_tizen 2.4 */ #define CONTEXT_TRIGGER_EMPTY "Empty" @@ -324,7 +322,7 @@ extern "C" { /** * @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. + * See the programming guide to find the corresponding left operand attribute keys. * @since_tizen 2.4 */ #define CONTEXT_TRIGGER_CRITICAL "Critical" @@ -332,7 +330,7 @@ extern "C" { /** * @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. + * See the programming guide to find the corresponding left operand attribute keys. * @since_tizen 2.4 */ #define CONTEXT_TRIGGER_LOW "Low" @@ -340,7 +338,7 @@ extern "C" { /** * @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. + * See the programming guide to find the corresponding left operand attribute keys. * @since_tizen 2.4 */ #define CONTEXT_TRIGGER_NORMAL "Normal" @@ -348,7 +346,7 @@ extern "C" { /** * @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. + * See the programming guide to find the corresponding left operand attribute keys. * @since_tizen 2.4 */ #define CONTEXT_TRIGGER_HIGH "High" @@ -356,7 +354,7 @@ extern "C" { /** * @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. + * See the programming guide to find the corresponding left operand attribute keys. * @since_tizen 2.4 */ #define CONTEXT_TRIGGER_FULL "Full" @@ -364,7 +362,7 @@ extern "C" { /** * @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. + * See the programming guide to find the corresponding left operand attribute keys. * @since_tizen 2.4 */ #define CONTEXT_TRIGGER_DISABLED "Disabled" @@ -372,7 +370,7 @@ extern "C" { /** * @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. + * See the programming guide to find the corresponding left operand attribute keys. * @since_tizen 2.4 */ #define CONTEXT_TRIGGER_SEARCHING "Searching" @@ -380,7 +378,7 @@ extern "C" { /** * @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. + * See the programming guide to find the corresponding left operand attribute keys. * @since_tizen 2.4 */ #define CONTEXT_TRIGGER_CONNECTING "Connecting" @@ -388,7 +386,7 @@ extern "C" { /** * @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. + * See the programming guide to find the corresponding left operand attribute keys. * @since_tizen 2.4 */ #define CONTEXT_TRIGGER_CONNECTED "Connected" @@ -396,7 +394,7 @@ extern "C" { /** * @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. + * See the programming guide to find the corresponding left operand attribute keys. * @since_tizen 2.4 */ #define CONTEXT_TRIGGER_UNCONNECTED "Unconnected" @@ -404,7 +402,7 @@ extern "C" { /** * @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. + * See the programming guide to find the corresponding left operand attribute keys. * @since_tizen 2.4 */ #define CONTEXT_TRIGGER_IDLE "Idle" @@ -412,7 +410,7 @@ extern "C" { /** * @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. + * See the programming guide to find the corresponding left operand attribute keys. * @since_tizen 2.4 */ #define CONTEXT_TRIGGER_VOICE "Voice" @@ -420,7 +418,7 @@ extern "C" { /** * @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. + * See the programming guide to find the corresponding left operand attribute keys. * @since_tizen 2.4 */ #define CONTEXT_TRIGGER_VIDEO "Video" @@ -428,7 +426,7 @@ extern "C" { /** * @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. + * See the programming guide to find the corresponding left operand attribute keys. * @since_tizen 2.4 */ #define CONTEXT_TRIGGER_HEADSET "Headset" @@ -436,7 +434,7 @@ extern "C" { /** * @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. + * See the programming guide to find the corresponding left operand attribute keys. * @since_tizen 2.4 */ #define CONTEXT_TRIGGER_BLUETOOTH "Bluetooth" @@ -444,7 +442,7 @@ extern "C" { /** * @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. + * See the programming guide to find the corresponding left operand attribute keys. * @since_tizen 2.4 */ #define CONTEXT_TRIGGER_RECEIVED "Received" @@ -452,7 +450,7 @@ extern "C" { /** * @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. + * See the programming guide to find the corresponding left operand attribute keys. * @since_tizen 2.4 */ #define CONTEXT_TRIGGER_SENT "Sent" @@ -460,7 +458,7 @@ extern "C" { /** * @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. + * See the programming guide to find the corresponding left operand attribute keys. * @since_tizen 2.4 */ #define CONTEXT_TRIGGER_SMS "SMS" @@ -468,7 +466,7 @@ extern "C" { /** * @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. + * See the programming guide to find the corresponding left operand attribute keys. * @since_tizen 2.4 */ #define CONTEXT_TRIGGER_MMS "MMS" @@ -476,7 +474,7 @@ extern "C" { /** * @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. + * See the programming guide to find the corresponding left operand attribute keys. * @since_tizen 2.4 */ #define CONTEXT_TRIGGER_DETECTED "Detected" @@ -484,7 +482,7 @@ extern "C" { /** * @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. + * See the programming guide to find the corresponding left operand attribute keys. * @since_tizen 2.4 */ #define CONTEXT_TRIGGER_IN "In" @@ -492,7 +490,7 @@ extern "C" { /** * @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. + * See the programming guide to find the corresponding left operand attribute keys. * @since_tizen 2.4 */ #define CONTEXT_TRIGGER_OUT "Out" @@ -928,7 +926,7 @@ 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. + * @details See the programming guide to find available option keys for each event/condition item. * @since_tizen 2.4 * * @param[in] entry The event or condition entry @@ -945,7 +943,7 @@ int context_trigger_rule_entry_add_option_int(context_trigger_rule_entry_h entry /** * @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. + * @details See the programming guide to find available option keys for each event/condition item. * @since_tizen 2.4 * * @param[in] entry The event or condition entry @@ -962,7 +960,7 @@ int context_trigger_rule_entry_add_option_string(context_trigger_rule_entry_h en /** * @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. + * @details See the programming guide to find available option keys for each condition item. * @since_tizen 2.4 * * @param[in] entry The condition entry @@ -980,7 +978,7 @@ int context_trigger_rule_entry_add_option(context_trigger_rule_entry_h entry, co /** * @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. + * See the programming guide to find available attribute keys for each event/condition item. * @since_tizen 2.4 * * @param[in] entry The event or condition entry @@ -1056,10 +1054,10 @@ int context_trigger_rule_entry_add_comparison(context_trigger_rule_entry_h entry #ifdef __cplusplus } -#endif // __cplusplus +#endif /* __cplusplus */ /** * @} */ -#endif // __TIZEN_CONTEXT_CONTEXT_TRIGGER_H__ +#endif /* __TIZEN_CONTEXT_CONTEXT_TRIGGER_H__ */ diff --git a/include/context_trigger_types_internal.h b/include/context_trigger_types_internal.h index 763cf04..dcdf1d4 100644 --- a/include/context_trigger_types_internal.h +++ b/include/context_trigger_types_internal.h @@ -105,4 +105,4 @@ #define TYPE_ATTR_STR "attributes" -#endif // __TIZEN_CONTEXT_CONTEXT_TRIGGER_TYPES_INTERNAL_H__ +#endif /* __TIZEN_CONTEXT_CONTEXT_TRIGGER_TYPES_INTERNAL_H__ */ diff --git a/internal/CMakeLists.txt b/internal/CMakeLists.txt deleted file mode 100644 index 061a20d..0000000 --- a/internal/CMakeLists.txt +++ /dev/null @@ -1,49 +0,0 @@ -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 deleted file mode 100644 index 36ce9d5..0000000 --- a/internal/context_internal.cpp +++ /dev/null @@ -1,84 +0,0 @@ -/* - * 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 -#include -#include -#include -#include -#include - -typedef std::map 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.spec b/packaging/context.spec index 4393dfc..7e2f4cc 100644 --- a/packaging/context.spec +++ b/packaging/context.spec @@ -11,7 +11,7 @@ BuildRequires: pkgconfig(aul) BuildRequires: pkgconfig(bundle) BuildRequires: pkgconfig(capi-appfw-app-control) BuildRequires: pkgconfig(pkgmgr-info) -BuildRequires: pkgconfig(capi-security-privilege-manager) +BuildRequires: pkgconfig(libsmack) BuildRequires: pkgconfig(context-common) %ifarch %{arm} @@ -80,16 +80,3 @@ Tizen Context Framework Native API (Development) %defattr(-,root,root,-) %{_includedir}/context-service/*.h %{_libdir}/pkgconfig/%{name}.pc - -%package internal -Summary: Tizen Context Framework Internal Headers -Group: System/API -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 index 6ecac10..b7b451b 100644 --- a/src/context_history.cpp +++ b/src/context_history.cpp @@ -22,6 +22,7 @@ #define TYPE_INT 0 #define TYPE_STRING 1 +#define FILTER_KEY_LIMIT 10 #define GROUP_COMMON 0 #define GROUP1 1 @@ -57,7 +58,6 @@ typedef struct _context_history_record_handle_s { 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); @@ -231,17 +231,6 @@ EXTAPI int context_history_list_destroy(context_history_list_h 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); @@ -280,24 +269,6 @@ EXTAPI int context_history_record_get_string(context_history_record_h record, co 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); @@ -306,23 +277,6 @@ EXTAPI int context_history_record_destroy(context_history_record_h 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; @@ -400,28 +354,6 @@ std::string convert_data_to_string(context_history_data_e data_type) 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) || @@ -477,62 +409,75 @@ bool check_filter_data_int(context_history_filter_e filter_type, int val) bool check_filter_data_string(context_history_filter_e filter_type, const char* val) { + IF_FAIL_RETURN(val, false); + switch (filter_type) { case CONTEXT_HISTORY_FILTER_APP_ID: case CONTEXT_HISTORY_FILTER_WIFI_BSSID: - if (val) - return true; - break; + return true; + 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; + /* This should be aligned with context_history_filter_e */ + static const char *filter_key[FILTER_KEY_LIMIT] = { + NULL, + CONTEXT_HISTORY_FILTER_KEY_TIME_SPAN, + CONTEXT_HISTORY_FILTER_KEY_RESULT_SIZE, + CONTEXT_HISTORY_FILTER_KEY_APP_ID, + CONTEXT_HISTORY_FILTER_KEY_DAY_OF_WEEK, + CONTEXT_HISTORY_FILTER_KEY_START_TIME, + CONTEXT_HISTORY_FILTER_KEY_END_TIME, + CONTEXT_HISTORY_FILTER_KEY_WIFI_BSSID, + CONTEXT_HISTORY_FILTER_KEY_AUDIO_JACK, + CONTEXT_HISTORY_FILTER_KEY_COMMUNICATION_TYPE, + }; + + bool allowed[FILTER_KEY_LIMIT] = {false}; + + allowed[CONTEXT_HISTORY_FILTER_TIME_SPAN] = true; + allowed[CONTEXT_HISTORY_FILTER_START_TIME] = true; + allowed[CONTEXT_HISTORY_FILTER_END_TIME] = true; + allowed[CONTEXT_HISTORY_FILTER_RESULT_SIZE] = true; + switch (data_type) { - // Group1 case CONTEXT_HISTORY_RECENTLY_USED_APP: case CONTEXT_HISTORY_FREQUENTLY_USED_APP: - group = GROUP1; + allowed[CONTEXT_HISTORY_FILTER_WIFI_BSSID] = true; + allowed[CONTEXT_HISTORY_FILTER_AUDIO_JACK] = true; break; - // Group2 + case CONTEXT_HISTORY_RARELY_USED_APP: - group = GROUP2; break; - // Group3 + case CONTEXT_HISTORY_PEAK_TIME_FOR_APP: + allowed[CONTEXT_HISTORY_FILTER_APP_ID] = true; + allowed[CONTEXT_HISTORY_FILTER_DAY_OF_WEEK] = true; + break; + case CONTEXT_HISTORY_PEAK_TIME_FOR_MUSIC: case CONTEXT_HISTORY_PEAK_TIME_FOR_VIDEO: - group = GROUP3; + allowed[CONTEXT_HISTORY_FILTER_DAY_OF_WEEK] = true; break; - // Group4 + case CONTEXT_HISTORY_COMMON_SETTING_FOR_APP: + allowed[CONTEXT_HISTORY_FILTER_RESULT_SIZE] = false; + allowed[CONTEXT_HISTORY_FILTER_APP_ID] = true; + break; + case CONTEXT_HISTORY_COMMON_SETTING_FOR_MUSIC: case CONTEXT_HISTORY_COMMON_SETTING_FOR_VIDEO: - group = GROUP4; + allowed[CONTEXT_HISTORY_FILTER_RESULT_SIZE] = false; break; - // Group5 + case CONTEXT_HISTORY_FREQUENTLY_COMMUNICATED_ADDRESS: - group = GROUP5; + allowed[CONTEXT_HISTORY_FILTER_COMMUNICATION_TYPE] = true; break; + default: return false; } @@ -544,26 +489,17 @@ bool check_invalid_filter(context_history_data_e data_type, context_history_filt for (std::list::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) { + for (int i = 1; i < FILTER_KEY_LIMIT; ++i) { + if (allowed[i] && key == filter_key[i]) { found = true; break; } } - if (found == true) { + 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 false; } - return found; + return true; } diff --git a/src/context_trigger.cpp b/src/context_trigger.cpp index 4867e99..7f57b89 100644 --- a/src/context_trigger.cpp +++ b/src/context_trigger.cpp @@ -352,11 +352,11 @@ EXTAPI int context_trigger_rule_set_action_app_control(context_trigger_rule_h ru int error; // Privilege check - error = ctx::privilege_util::is_allowed("http://tizen.org/privilege/appmanager.launch"); + error = ctx::privilege_util::is_allowed("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"); + error = ctx::privilege_util::is_allowed("call"); IF_FAIL_RETURN_TAG(error == ERR_NONE, error, _E, "Privilege checking failed (%#x)", error); } @@ -392,7 +392,7 @@ EXTAPI int context_trigger_rule_set_action_notification(context_trigger_rule_h r ASSERT_NOT_NULL(rule && title && content); // Privilege check - int error = ctx::privilege_util::is_allowed("http://tizen.org/privilege/notification"); + int error = ctx::privilege_util::is_allowed("notification"); IF_FAIL_RETURN_TAG(error == ERR_NONE, error, _E, "Privilege checking failed (%#x)", error); // if action arleady exists diff --git a/src/priv_util.cpp b/src/priv_util.cpp index ffee54b..a9cb03b 100644 --- a/src/priv_util.cpp +++ b/src/priv_util.cpp @@ -14,46 +14,30 @@ * limitations under the License. */ -#include -#include -#include -#include -#include - +#include +#include +#include #include #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; - } + IF_FAIL_RETURN_TAG(priv, ERR_OPERATION_FAILED, _E, "Invalid parameter"); - error = privilege_checker_check_package_privilege(pkg_name, priv); - pkgmgrinfo_appinfo_destroy_appinfo(app_info); + char *subject = NULL; + int ret = smack_new_label_from_self(&subject); + IF_FAIL_RETURN_TAG(ret == 0 && subject != NULL, ERR_OPERATION_FAILED, _E, "Getting smack label failed"); - _D("Privilege checking result: %d", error); + std::string priv_name = "privilege::tizen::"; + priv_name += priv; + ret = smack_have_access(subject, priv_name.c_str(), "rw"); + g_free(subject); - if (error == PRIV_CHECKER_ERR_NONE) { + if (ret == 1) return ERR_NONE; - } - if (error == PRIV_CHECKER_ERR_INVALID_PRIVILEGE) { + if (ret == 0) return ERR_PERMISSION_DENIED; - } return ERR_OPERATION_FAILED; } diff --git a/src/rule_validator.h b/src/rule_validator.h index cdda646..9d34b42 100644 --- a/src/rule_validator.h +++ b/src/rule_validator.h @@ -22,17 +22,17 @@ namespace ctx { namespace rule_validator { - bool check_option(ctx::json& item); + 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_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); + 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); + bool check_referential_data(std::string name, ctx::json &ref_info); } } /* namespace ctx */ diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt deleted file mode 100644 index 95d23f3..0000000 --- a/test/CMakeLists.txt +++ /dev/null @@ -1,40 +0,0 @@ -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 deleted file mode 100644 index 8eada05..0000000 --- a/test/src/main.c +++ /dev/null @@ -1,145 +0,0 @@ -/* - * 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 -#include -#include -#include - -#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 deleted file mode 100644 index 54ad3a5..0000000 --- a/test/src/utc_context_history.c +++ /dev/null @@ -1,586 +0,0 @@ -/* - * 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 -#include -#include -#include "utc_context_history.h" -#include - -#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 deleted file mode 100644 index 492c018..0000000 --- a/test/src/utc_context_history.h +++ /dev/null @@ -1,77 +0,0 @@ -/* - * 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 deleted file mode 100644 index d407bf9..0000000 --- a/test/src/utc_context_trigger.c +++ /dev/null @@ -1,1187 +0,0 @@ -/* - * 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 -#include -#include -#include -#include "utc_context_trigger.h" -#include - -#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 deleted file mode 100644 index df262b6..0000000 --- a/test/src/utc_context_trigger.h +++ /dev/null @@ -1,98 +0,0 @@ -/* - * 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__ */ -- 2.7.4 From 51d8d4f9b74a68c12451116e2b5e029daf06a42e Mon Sep 17 00:00:00 2001 From: Mu-Woong Date: Mon, 29 Jun 2015 21:04:10 +0900 Subject: [PATCH 04/16] Cleanup the build script Change-Id: Id4a77ec7c309386791b0b1ef524329aef9ed27d8 Signed-off-by: Mu-Woong --- CMakeLists.txt | 16 ---------------- packaging/context.spec | 14 ++------------ 2 files changed, 2 insertions(+), 28 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1c80c4d..1975ded 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,22 +12,6 @@ MESSAGE("Sources: ${SRCS}") # Dependencies SET(DEPS "aul bundle pkgmgr-info libsmack 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( diff --git a/packaging/context.spec b/packaging/context.spec index 7e2f4cc..2769739 100644 --- a/packaging/context.spec +++ b/packaging/context.spec @@ -1,6 +1,6 @@ Name: context Summary: Tizen Context Framework Native API -Version: 0.4.2 +Version: 0.5.0 Release: 1 Group: System/API License: Apache-2.0 @@ -14,12 +14,6 @@ BuildRequires: pkgconfig(pkgmgr-info) BuildRequires: pkgconfig(libsmack) BuildRequires: pkgconfig(context-common) -%ifarch %{arm} -%define ARCH arm -%else -%define ARCH i586 -%endif - %description Tizen Context Framework Native API @@ -38,12 +32,11 @@ 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} +cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} -DMAJORVER=${MAJORVER} -DFULLVER=%{version} make %{?jobs:-j%jobs} %install @@ -64,9 +57,6 @@ cp LICENSE %{buildroot}/usr/share/license/%{name} %defattr(-,root,root,-) %{_libdir}/*.so* /usr/share/license/%{name} -#%if %{BINTYPE} == "engineer" -#/usr/bin/* -#%endif %package devel Summary: Tizen Context Framework Native API (Development) -- 2.7.4 From 6d12567e8e1d12057c3eef30d70212671f8aa831 Mon Sep 17 00:00:00 2001 From: Mu-Woong Date: Mon, 13 Jul 2015 14:46:20 +0900 Subject: [PATCH 05/16] Update date of all license boilerplate Change-Id: I49d2d86d08b2444601324506f21144b154975fe1 Signed-off-by: Mu-Woong --- AUTHORS | 6 +++--- LICENSE | 5 ++--- include/context_history.h | 2 +- include/context_trigger.h | 2 +- include/context_trigger_types_internal.h | 2 +- src/context_history.cpp | 2 +- src/context_trigger.cpp | 2 +- src/priv_util.cpp | 2 +- src/priv_util.h | 2 +- src/rule_info.h | 2 +- src/rule_validator.cpp | 2 +- src/rule_validator.h | 2 +- 12 files changed, 15 insertions(+), 16 deletions(-) diff --git a/AUTHORS b/AUTHORS index d97a819..3060048 100644 --- a/AUTHORS +++ b/AUTHORS @@ -1,3 +1,3 @@ -Mu-Woong Lee -Jihoon Park -Somin Kim +Mu-Woong Lee +Somin Kim +Kyoung-Mook Choi diff --git a/LICENSE b/LICENSE index 1da314d..1aea19e 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. +Copyright (c) 2015 Samsung Electronics Co., Ltd. All rights reserved. Apache License Version 2.0, January 2004 @@ -188,7 +188,7 @@ Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. same "printed page" as the copyright notice for easier identification within third-party archives. - Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved + Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -201,4 +201,3 @@ Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. 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/include/context_history.h b/include/context_history.h index f368993..6f2e729 100644 --- a/include/context_history.h +++ b/include/context_history.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * 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. diff --git a/include/context_trigger.h b/include/context_trigger.h index d0d5d93..abc6137 100644 --- a/include/context_trigger.h +++ b/include/context_trigger.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * 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. diff --git a/include/context_trigger_types_internal.h b/include/context_trigger_types_internal.h index dcdf1d4..90b4803 100644 --- a/include/context_trigger_types_internal.h +++ b/include/context_trigger_types_internal.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * 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. diff --git a/src/context_history.cpp b/src/context_history.cpp index b7b451b..41f986d 100644 --- a/src/context_history.cpp +++ b/src/context_history.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * 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. diff --git a/src/context_trigger.cpp b/src/context_trigger.cpp index 7f57b89..9b1f8f4 100644 --- a/src/context_trigger.cpp +++ b/src/context_trigger.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * 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. diff --git a/src/priv_util.cpp b/src/priv_util.cpp index a9cb03b..d81479f 100644 --- a/src/priv_util.cpp +++ b/src/priv_util.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * 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. diff --git a/src/priv_util.h b/src/priv_util.h index 6ef1109..7e51066 100644 --- a/src/priv_util.h +++ b/src/priv_util.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * 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. diff --git a/src/rule_info.h b/src/rule_info.h index aaac67c..def2da9 100644 --- a/src/rule_info.h +++ b/src/rule_info.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * 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. diff --git a/src/rule_validator.cpp b/src/rule_validator.cpp index 129bede..0ed5d4a 100644 --- a/src/rule_validator.cpp +++ b/src/rule_validator.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * 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. diff --git a/src/rule_validator.h b/src/rule_validator.h index 9d34b42..e4a60b0 100644 --- a/src/rule_validator.h +++ b/src/rule_validator.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * 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. -- 2.7.4 From 5b7279532f4c8212b597bc0b1d6d14ef2bc92f4c Mon Sep 17 00:00:00 2001 From: Mu-Woong Date: Mon, 13 Jul 2015 14:47:37 +0900 Subject: [PATCH 06/16] Disable client smack rule checker. It needs to be re-implemented using Cynara. Change-Id: I01ddc61cfe001f95c64cf0e3d9f01746772c0d27 Signed-off-by: Mu-Woong --- CMakeLists.txt | 2 +- packaging/context.spec | 1 - src/priv_util.cpp | 5 ++++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1975ded..888350b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,7 +10,7 @@ FILE(GLOB_RECURSE SRCS src/*.cpp) MESSAGE("Sources: ${SRCS}") # Dependencies -SET(DEPS "aul bundle pkgmgr-info libsmack capi-appfw-app-control context-common") +SET(DEPS "aul bundle pkgmgr-info capi-appfw-app-control context-common") # Common Options INCLUDE(FindPkgConfig) diff --git a/packaging/context.spec b/packaging/context.spec index 2769739..cbfc747 100644 --- a/packaging/context.spec +++ b/packaging/context.spec @@ -11,7 +11,6 @@ BuildRequires: pkgconfig(aul) BuildRequires: pkgconfig(bundle) BuildRequires: pkgconfig(capi-appfw-app-control) BuildRequires: pkgconfig(pkgmgr-info) -BuildRequires: pkgconfig(libsmack) BuildRequires: pkgconfig(context-common) %description diff --git a/src/priv_util.cpp b/src/priv_util.cpp index d81479f..6f42557 100644 --- a/src/priv_util.cpp +++ b/src/priv_util.cpp @@ -15,13 +15,14 @@ */ #include -#include #include #include #include "priv_util.h" int ctx::privilege_util::is_allowed(const char* priv) { + /* TODO: Re-implement using Cynara */ +#if 0 IF_FAIL_RETURN_TAG(priv, ERR_OPERATION_FAILED, _E, "Invalid parameter"); char *subject = NULL; @@ -40,4 +41,6 @@ int ctx::privilege_util::is_allowed(const char* priv) return ERR_PERMISSION_DENIED; return ERR_OPERATION_FAILED; +#endif + return ERR_NONE; } -- 2.7.4 From e3fe7a40a3af3e58da73366b0f8a7570301de401 Mon Sep 17 00:00:00 2001 From: Mu-Woong Date: Tue, 21 Jul 2015 14:32:22 +0900 Subject: [PATCH 07/16] Version 0.5.3 Change-Id: I633123eca0707a1f5e16ea0c3cfac0663507225d Signed-off-by: Mu-Woong --- packaging/context.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/context.spec b/packaging/context.spec index cbfc747..c924694 100644 --- a/packaging/context.spec +++ b/packaging/context.spec @@ -1,6 +1,6 @@ Name: context Summary: Tizen Context Framework Native API -Version: 0.5.0 +Version: 0.5.3 Release: 1 Group: System/API License: Apache-2.0 -- 2.7.4 From 96aaefcaebc6a70a59ec995c3327b5e9a97a2355 Mon Sep 17 00:00:00 2001 From: Mu-Woong Date: Tue, 4 Aug 2015 20:58:24 +0900 Subject: [PATCH 08/16] Merge Version 0.5.5 - Remove unnecessary dependency to pkgmgr-info - Disable internal 'dbus call' trigger action api - Add an internal function to set 'dbus call' action Change-Id: I8ba890181055753371538192e824645a87d21704 Signed-off-by: Mu-Woong --- CMakeLists.txt | 6 +++-- include/context_trigger_internal.h | 45 ++++++++++++++++++++++++++++++++ include/context_trigger_types_internal.h | 7 +++++ packaging/context.spec | 3 +-- src/context_trigger.cpp | 24 +++++++++++++++++ 5 files changed, 81 insertions(+), 4 deletions(-) create mode 100644 include/context_trigger_internal.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 888350b..d8935ad 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,7 +10,7 @@ FILE(GLOB_RECURSE SRCS src/*.cpp) MESSAGE("Sources: ${SRCS}") # Dependencies -SET(DEPS "aul bundle pkgmgr-info capi-appfw-app-control context-common") +SET(DEPS "aul bundle capi-appfw-app-control context-common") # Common Options INCLUDE(FindPkgConfig) @@ -37,7 +37,9 @@ SET_TARGET_PROPERTIES(${target} PROPERTIES VERSION ${FULLVER}) 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" + FILES_MATCHING + PATTERN "context_trigger_internal.h" EXCLUDE + PATTERN "*.h" ) SET(VERSION ${FULLVER}) diff --git a/include/context_trigger_internal.h b/include/context_trigger_internal.h new file mode 100644 index 0000000..93f24f3 --- /dev/null +++ b/include/context_trigger_internal.h @@ -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. + */ + +#ifndef __TIZEN_CONTEXT_CONTEXT_TRIGGER_INTERNAL_H__ +#define __TIZEN_CONTEXT_CONTEXT_TRIGGER_INTERNAL_H__ + +#include + +/** + * @brief Sets a D-Bus method call as the action of a rule. + * @since_tizen 2.4 + * + * @param[in] rule The rule to set the action on + * @param[in] bus_name Destination remote bus name + * @param[in] object_path Path of the remote object + * @param[in] interface_name D-Bus interface to invoke method on + * @param[in] method_name The name of the method to invoke + * @param[in] user_data A user-defined string to be delivered as the first parameter of the method. + * @c NULL if not passing any values. + * + * @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_dbus_call(context_trigger_rule_h rule, + const char *bus_name, const char *object_path, const char *interface_name, + const char *method_name, const char *user_data); + +#endif diff --git a/include/context_trigger_types_internal.h b/include/context_trigger_types_internal.h index 90b4803..94e5e0f 100644 --- a/include/context_trigger_types_internal.h +++ b/include/context_trigger_types_internal.h @@ -29,6 +29,7 @@ #define CT_RULE_ACTION_TYPE_APP_CONTROL "app_control" #define CT_RULE_ACTION_TYPE_NOTIFICATION "notification" +#define CT_RULE_ACTION_TYPE_DBUS_CALL "dbus_call" #define CT_RULE_ID "ID" #define CT_RULE_DESCRIPTION "DESCRIPTION" @@ -54,6 +55,12 @@ #define CT_RULE_ACTION_NOTI_CONTENT "ACTION_NOTI_CONTENT" #define CT_RULE_ACTION_NOTI_ICON_PATH "ACTION_NOTI_ICON_PATH" +#define CT_RULE_ACTION_DBUS_NAME "ACTION_DBUS_NAME" +#define CT_RULE_ACTION_DBUS_OBJECT "ACTION_DBUS_OBJ" +#define CT_RULE_ACTION_DBUS_INTERFACE "ACTION_DBUS_IFACE" +#define CT_RULE_ACTION_DBUS_METHOD "ACTION_DBUS_METHOD" +#define CT_RULE_ACTION_DBUS_USER_DATA "ACTION_DBUS_USERDATA" + #define CT_RESPONSE "RES" #define CT_EVENT_TIME "timer/event" diff --git a/packaging/context.spec b/packaging/context.spec index c924694..56d5752 100644 --- a/packaging/context.spec +++ b/packaging/context.spec @@ -1,6 +1,6 @@ Name: context Summary: Tizen Context Framework Native API -Version: 0.5.3 +Version: 0.5.5 Release: 1 Group: System/API License: Apache-2.0 @@ -10,7 +10,6 @@ BuildRequires: cmake BuildRequires: pkgconfig(aul) BuildRequires: pkgconfig(bundle) BuildRequires: pkgconfig(capi-appfw-app-control) -BuildRequires: pkgconfig(pkgmgr-info) BuildRequires: pkgconfig(context-common) %description diff --git a/src/context_trigger.cpp b/src/context_trigger.cpp index 9b1f8f4..dbf366d 100644 --- a/src/context_trigger.cpp +++ b/src/context_trigger.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include "rule_validator.h" @@ -431,6 +432,29 @@ EXTAPI int context_trigger_rule_set_action_notification(context_trigger_rule_h r return CONTEXT_TRIGGER_ERROR_NONE; } +#if 0 +EXTAPI int context_trigger_rule_set_action_dbus_call(context_trigger_rule_h rule, + const char *bus_name, const char *object_path, const char *interface_name, const char *method_name, const char *user_data) +{ + ASSERT_NOT_NULL(rule && bus_name && object_path && interface_name && method_name); + + // 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 D-Bus info + (rule->jrule).set(CT_RULE_DETAILS "." CT_RULE_ACTION, CT_RULE_ACTION_TYPE, CT_RULE_ACTION_TYPE_DBUS_CALL); + (rule->jrule).set(CT_RULE_DETAILS "." CT_RULE_ACTION, CT_RULE_ACTION_DBUS_NAME, bus_name); + (rule->jrule).set(CT_RULE_DETAILS "." CT_RULE_ACTION, CT_RULE_ACTION_DBUS_OBJECT, object_path); + (rule->jrule).set(CT_RULE_DETAILS "." CT_RULE_ACTION, CT_RULE_ACTION_DBUS_INTERFACE, interface_name); + (rule->jrule).set(CT_RULE_DETAILS "." CT_RULE_ACTION, CT_RULE_ACTION_DBUS_METHOD, method_name); + (rule->jrule).set(CT_RULE_DETAILS "." CT_RULE_ACTION, CT_RULE_ACTION_DBUS_USER_DATA, (user_data ? user_data : "")); + + return CONTEXT_TRIGGER_ERROR_NONE; +} +#endif + // Set description EXTAPI int context_trigger_rule_set_description(context_trigger_rule_h rule, const char* description) { -- 2.7.4 From 48b638c4f9f9a3afc5828f9e611c701257645e97 Mon Sep 17 00:00:00 2001 From: Mu-Woong Date: Mon, 17 Aug 2015 21:57:55 +0900 Subject: [PATCH 09/16] Sync with Tizen 2.4 - Cleanup history/trigger item names Change-Id: I3ffdb0e74a43bfeebef5ef714e6bbd9eb553aded Signed-off-by: Mu-Woong --- include/context_history_types_internal.h | 40 ++++++++--------- include/context_trigger_types_internal.h | 76 +++++++++++++++----------------- src/context_history.cpp | 56 +++++++++++------------ src/rule_info.h | 54 +++++++++-------------- 4 files changed, 104 insertions(+), 122 deletions(-) diff --git a/include/context_history_types_internal.h b/include/context_history_types_internal.h index e240cf1..57a0a8b 100644 --- a/include/context_history_types_internal.h +++ b/include/context_history_types_internal.h @@ -19,27 +19,27 @@ #include -#define CONTEXT_HISTORY_DATA "QueryResult" +#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 SUBJ_RECENTLY_USED_APP "stats/app/recently" +#define SUBJ_FREQUENTLY_USED_APP "stats/app/often" +#define SUBJ_RARELY_USED_APP "stats/app/rarely" +#define SUBJ_PEAK_TIME_FOR_APP "stats/app/peak_time" +#define SUBJ_PEAK_TIME_FOR_MUSIC "stats/music/peak_time" +#define SUBJ_PEAK_TIME_FOR_VIDEO "stats/video/peak_time" +#define SUBJ_COMMON_SETTING_FOR_APP "stats/app/setting" +#define SUBJ_COMMON_SETTING_FOR_MUSIC "stats/music/setting" +#define SUBJ_COMMON_SETTING_FOR_VIDEO "stats/video/setting" +#define SUBJ_FREQUENTLY_COMMUNICATED_ADDRESS "stats/contact/often" -#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" +#define FILTER_TIME_SPAN "TimeSpan" +#define FILTER_RESULT_SIZE "ResultSize" +#define FILTER_APP_ID "AppId" +#define FILTER_DAY_OF_WEEK "DayOfWeek" +#define FILTER_START_TIME "StartTime" +#define FILTER_END_TIME "EndTime" +#define FILTER_AUDIO_JACK "AudioJack" +#define FILTER_WIFI_BSSID "BSSID" +#define FILTER_COMMUNICATION_TYPE "CommunicationType" #endif /* __TIZEN_CONTEXT_HISTORY_TYPES_INTERNAL_H__ */ diff --git a/include/context_trigger_types_internal.h b/include/context_trigger_types_internal.h index 94e5e0f..5b584b2 100644 --- a/include/context_trigger_types_internal.h +++ b/include/context_trigger_types_internal.h @@ -17,12 +17,12 @@ #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 CONTEXT_TRIGGER_SUBJECT_ADD "trigger/add" +#define CONTEXT_TRIGGER_SUBJECT_REMOVE "trigger/remove" +#define CONTEXT_TRIGGER_SUBJECT_ENABLE "trigger/enable" +#define CONTEXT_TRIGGER_SUBJECT_DISABLE "trigger/disable" +#define CONTEXT_TRIGGER_SUBJECT_GET "trigger/get" +#define CONTEXT_TRIGGER_SUBJECT_GET_RULE_IDS "trigger/get_rule_ids" #define CT_RULE_ARRAY_ENABLED "ARRAY_ENABLED" #define CT_RULE_ARRAY_DISABLED "ARRAY_DISABLED" @@ -63,41 +63,35 @@ #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 CT_EVENT_TIME "time/alarm" +#define CT_EVENT_BATTERY "system/battery" +#define CT_EVENT_CHARGER "system/charger" +#define CT_EVENT_GPS "system/gps" +#define CT_EVENT_HEADPHONE "system/headphone" +#define CT_EVENT_POWER_SAVING_MODE "system/psmode" +#define CT_EVENT_USB "system/usb" +#define CT_EVENT_WIFI "system/wifi" +#define CT_EVENT_CALL "social/call" +#define CT_EVENT_EMAIL "social/email" +#define CT_EVENT_MESSAGE "social/message" +#define CT_EVENT_ACTIVITY_STATIONARY "activity/stationary" +#define CT_EVENT_ACTIVITY_WALKING "activity/walking" +#define CT_EVENT_ACTIVITY_RUNNING "activity/running" +#define CT_EVENT_ACTIVITY_IN_VEHICLE "activity/in_vehicle" +#define CT_EVENT_PLACE "place/geofence" +#define CT_CONDITION_TIME "time/now" +#define CT_CONDITION_BATTERY "system/battery" +#define CT_CONDITION_CHARGER "system/charger" +#define CT_CONDITION_GPS "system/gps" +#define CT_CONDITION_HEADPHONE "system/headphone" +#define CT_CONDITION_POWER_SAVING_MODE "system/psmode" +#define CT_CONDITION_USB "system/usb" +#define CT_CONDITION_WIFI "system/wifi" +#define CT_CONDITION_CALL "social/call" +#define CT_CONDITION_APP_USE_FREQUENCY "stats/app/frequency" +#define CT_CONDITION_COMMUNICATION_FREQUENCY "stats/contact/frequency" +#define CT_CONDITION_MUSIC_PLAYBACK_FREQUENCY "stats/music/frequency" +#define CT_CONDITION_VIDEO_PLAYBACK_FREQUENCY "stats/video/frequency" #define TYPE_EVENT 1 #define TYPE_CONDITION 2 diff --git a/src/context_history.cpp b/src/context_history.cpp index 41f986d..8e3d99c 100644 --- a/src/context_history.cpp +++ b/src/context_history.cpp @@ -282,31 +282,31 @@ 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; + str = FILTER_TIME_SPAN; break; case CONTEXT_HISTORY_FILTER_RESULT_SIZE: - str = CONTEXT_HISTORY_FILTER_KEY_RESULT_SIZE; + str = FILTER_RESULT_SIZE; break; case CONTEXT_HISTORY_FILTER_APP_ID: - str = CONTEXT_HISTORY_FILTER_KEY_APP_ID; + str = FILTER_APP_ID; break; case CONTEXT_HISTORY_FILTER_DAY_OF_WEEK: - str = CONTEXT_HISTORY_FILTER_KEY_DAY_OF_WEEK; + str = FILTER_DAY_OF_WEEK; break; case CONTEXT_HISTORY_FILTER_START_TIME: - str = CONTEXT_HISTORY_FILTER_KEY_START_TIME; + str = FILTER_START_TIME; break; case CONTEXT_HISTORY_FILTER_END_TIME: - str = CONTEXT_HISTORY_FILTER_KEY_END_TIME; + str = FILTER_END_TIME; break; case CONTEXT_HISTORY_FILTER_WIFI_BSSID: - str = CONTEXT_HISTORY_FILTER_KEY_WIFI_BSSID; + str = FILTER_WIFI_BSSID; break; case CONTEXT_HISTORY_FILTER_AUDIO_JACK: - str = CONTEXT_HISTORY_FILTER_KEY_AUDIO_JACK; + str = FILTER_AUDIO_JACK; break; case CONTEXT_HISTORY_FILTER_COMMUNICATION_TYPE: - str = CONTEXT_HISTORY_FILTER_KEY_COMMUNICATION_TYPE; + str = FILTER_COMMUNICATION_TYPE; break; default: break; @@ -319,34 +319,34 @@ 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; + str = SUBJ_RECENTLY_USED_APP; break; case CONTEXT_HISTORY_FREQUENTLY_USED_APP: - str = CONTEXT_HISTORY_SUBJECT_FREQUENTLY_USED_APP; + str = SUBJ_FREQUENTLY_USED_APP; break; case CONTEXT_HISTORY_RARELY_USED_APP: - str = CONTEXT_HISTORY_SUBJECT_RARELY_USED_APP; + str = SUBJ_RARELY_USED_APP; break; case CONTEXT_HISTORY_PEAK_TIME_FOR_APP: - str = CONTEXT_HISTORY_SUBJECT_PEAK_TIME_FOR_APP; + str = SUBJ_PEAK_TIME_FOR_APP; break; case CONTEXT_HISTORY_PEAK_TIME_FOR_MUSIC: - str = CONTEXT_HISTORY_SUBJECT_PEAK_TIME_FOR_MUSIC; + str = SUBJ_PEAK_TIME_FOR_MUSIC; break; case CONTEXT_HISTORY_PEAK_TIME_FOR_VIDEO: - str = CONTEXT_HISTORY_SUBJECT_PEAK_TIME_FOR_VIDEO; + str = SUBJ_PEAK_TIME_FOR_VIDEO; break; case CONTEXT_HISTORY_COMMON_SETTING_FOR_APP: - str = CONTEXT_HISTORY_SUBJECT_COMMON_SETTING_FOR_APP; + str = SUBJ_COMMON_SETTING_FOR_APP; break; case CONTEXT_HISTORY_COMMON_SETTING_FOR_MUSIC: - str = CONTEXT_HISTORY_SUBJECT_COMMON_SETTING_FOR_MUSIC; + str = SUBJ_COMMON_SETTING_FOR_MUSIC; break; case CONTEXT_HISTORY_COMMON_SETTING_FOR_VIDEO: - str = CONTEXT_HISTORY_SUBJECT_COMMON_SETTING_FOR_VIDEO; + str = SUBJ_COMMON_SETTING_FOR_VIDEO; break; case CONTEXT_HISTORY_FREQUENTLY_COMMUNICATED_ADDRESS: - str = CONTEXT_HISTORY_SUBJECT_FREQUENTLY_COMMUNICATED_ADDRESS; + str = SUBJ_FREQUENTLY_COMMUNICATED_ADDRESS; break; default: break; @@ -426,15 +426,15 @@ bool check_invalid_filter(context_history_data_e data_type, context_history_filt /* This should be aligned with context_history_filter_e */ static const char *filter_key[FILTER_KEY_LIMIT] = { NULL, - CONTEXT_HISTORY_FILTER_KEY_TIME_SPAN, - CONTEXT_HISTORY_FILTER_KEY_RESULT_SIZE, - CONTEXT_HISTORY_FILTER_KEY_APP_ID, - CONTEXT_HISTORY_FILTER_KEY_DAY_OF_WEEK, - CONTEXT_HISTORY_FILTER_KEY_START_TIME, - CONTEXT_HISTORY_FILTER_KEY_END_TIME, - CONTEXT_HISTORY_FILTER_KEY_WIFI_BSSID, - CONTEXT_HISTORY_FILTER_KEY_AUDIO_JACK, - CONTEXT_HISTORY_FILTER_KEY_COMMUNICATION_TYPE, + FILTER_TIME_SPAN, + FILTER_RESULT_SIZE, + FILTER_APP_ID, + FILTER_DAY_OF_WEEK, + FILTER_START_TIME, + FILTER_END_TIME, + FILTER_WIFI_BSSID, + FILTER_AUDIO_JACK, + FILTER_COMMUNICATION_TYPE, }; bool allowed[FILTER_KEY_LIMIT] = {false}; diff --git a/src/rule_info.h b/src/rule_info.h index def2da9..2c3b0cb 100644 --- a/src/rule_info.h +++ b/src/rule_info.h @@ -19,103 +19,91 @@ #define RULE_INFO "{ \"templates\": [\ {\ - \"name\": \"timer/event\",\ + \"name\": \"time/alarm\",\ \"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\",\ + \"name\": \"time/now\",\ \"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\",\ + \"name\": \"system/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\",\ + \"name\": \"system/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\",\ + \"name\": \"system/gps\",\ \"attributes\": [ { \"key\" : \"State\", \"type\": 2, \"acceptable\": [ \"Disabled\", \"Searching\", \"Connected\" ] } ]\ },\ {\ - \"name\": \"system/state/headphone\",\ + \"name\": \"system/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\",\ + \"name\": \"system/psmode\",\ \"attributes\": [ { \"key\": \"IsEnabled\", \"type\": 1, \"min\": 0, \"max\": 1 } ]\ },\ {\ - \"name\": \"system/state/usb\",\ + \"name\": \"system/usb\",\ \"attributes\": [ { \"key\": \"IsConnected\", \"type\": 1, \"min\": 0, \"max\": 1 } ]\ },\ {\ - \"name\": \"system/state/wifi\",\ + \"name\": \"system/wifi\",\ \"attributes\": [ { \"key\" : \"State\", \"type\": 2, \"acceptable\": [ \"Disabled\", \"Unconnected\", \"Connected\" ] }, { \"key\": \"BSSID\", \"type\": 2, \"acceptable\": [ ] } ]\ },\ {\ - \"name\": \"social/state/call\",\ + \"name\": \"social/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\",\ + \"name\": \"social/email\",\ \"attributes\": [ { \"key\": \"Event\", \"type\": 2, \"acceptable\": [ \"Received\", \"Sent\" ] } ]\ },\ {\ - \"name\": \"social/event/message\",\ + \"name\": \"social/message\",\ \"attributes\": [ { \"key\": \"Event\", \"type\": 2, \"acceptable\": [ \"Received\" ] } , { \"key\": \"Type\", \"type\": 2, \"acceptable\": [ \"SMS\", \"MMS\" ] }, { \"key\": \"Address\", \"type\": 2, \"acceptable\": [ ] } ]\ },\ {\ - \"name\": \"activity/event/stationary\",\ + \"name\": \"activity/stationary\",\ \"attributes\": [ { \"key\": \"Event\", \"type\": 2, \"acceptable\": [ \"Detected\" ] }, { \"key\": \"Accuracy\", \"type\": 2, \"acceptable\": [ \"High\", \"Normal\", \"Low\" ] } ]\ },\ {\ - \"name\": \"activity/event/walking\",\ + \"name\": \"activity/walking\",\ \"attributes\": [ { \"key\": \"Event\", \"type\": 2, \"acceptable\": [ \"Detected\" ] }, { \"key\": \"Accuracy\", \"type\": 2, \"acceptable\": [ \"High\", \"Normal\", \"Low\" ] } ]\ },\ {\ - \"name\": \"activity/event/running\",\ + \"name\": \"activity/running\",\ \"attributes\": [ { \"key\": \"Event\", \"type\": 2, \"acceptable\": [ \"Detected\" ] }, { \"key\": \"Accuracy\", \"type\": 2, \"acceptable\": [ \"High\", \"Normal\", \"Low\" ] } ]\ },\ {\ - \"name\": \"activity/event/in_vehicle\",\ + \"name\": \"activity/in_vehicle\",\ \"attributes\": [ { \"key\": \"Event\", \"type\": 2, \"acceptable\": [ \"Detected\" ] }, { \"key\": \"Accuracy\", \"type\": 2, \"acceptable\": [ \"High\", \"Normal\", \"Low\" ] } ]\ },\ {\ - \"name\": \"place/event/geofence\",\ + \"name\": \"place/geofence\",\ \"attributes\": [ { \"key\": \"Event\", \"type\": 2, \"acceptable\": [ \"In\", \"Out\" ] } ],\ \"option\": [ { \"key\": \"PlaceId\", \"type\": 1, \"min\": 1, \"max\": -1 } ]\ },\ {\ - \"name\": \"app/history/use_freq\",\ + \"name\": \"stats/app/frequency\",\ \"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\",\ + \"name\": \"stats/contact/frequency\",\ \"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\",\ + \"name\": \"stats/music/frequency\",\ \"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\",\ + \"name\": \"stats/video/frequency\",\ \"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\" ] } ]\ }\ -- 2.7.4 From 479039ca5a905a5a68b730f7ad644e8c3c35e2ce Mon Sep 17 00:00:00 2001 From: Mu-Woong Date: Tue, 18 Aug 2015 11:57:24 +0900 Subject: [PATCH 10/16] Version 0.6.0 Change-Id: I4e6a59fbd7828540bd3abf83cce3e7f1619bcc31 Signed-off-by: Mu-Woong --- packaging/context.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/context.spec b/packaging/context.spec index 56d5752..35d5746 100644 --- a/packaging/context.spec +++ b/packaging/context.spec @@ -1,6 +1,6 @@ Name: context Summary: Tizen Context Framework Native API -Version: 0.5.5 +Version: 0.6.0 Release: 1 Group: System/API License: Apache-2.0 -- 2.7.4 From 7bd4506b1fcf6499cdf36e35936bcb4aac185c35 Mon Sep 17 00:00:00 2001 From: Somin Kim Date: Tue, 8 Sep 2015 15:56:54 +0900 Subject: [PATCH 11/16] Modified to restrict service application launch request Change-Id: I0fd57efdaaed657b6bb23a4ab2e507c29baf8dd6 Signed-off-by: Somin Kim --- CMakeLists.txt | 2 +- include/context_trigger.h | 5 +++++ packaging/context.spec | 1 + src/context_trigger.cpp | 33 +++++++++++++++++++++++++++++++++ 4 files changed, 40 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d8935ad..ed69fdc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,7 +10,7 @@ FILE(GLOB_RECURSE SRCS src/*.cpp) MESSAGE("Sources: ${SRCS}") # Dependencies -SET(DEPS "aul bundle capi-appfw-app-control context-common") +SET(DEPS "aul bundle capi-appfw-app-control context-common pkgmgr-info") # Common Options INCLUDE(FindPkgConfig) diff --git a/include/context_trigger.h b/include/context_trigger.h index abc6137..33087c2 100644 --- a/include/context_trigger.h +++ b/include/context_trigger.h @@ -774,6 +774,9 @@ int context_trigger_rule_add_entry(context_trigger_rule_h rule, context_trigger_ * @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. + * @remarks The launch request of the service application is restricted. + * The function will return #CONTEXT_TRIGGER_ERROR_INVALID_RULE, + * if the launch request is for the service application. * * @param[in] rule The rule * @param[in] app_control The App Control, which will be used to launch an application @@ -784,6 +787,7 @@ int context_trigger_rule_add_entry(context_trigger_rule_h rule, context_trigger_ * @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 + * @retval #CONTEXT_TRIGGER_ERROR_INVALID_RULE Invalid rule */ int context_trigger_rule_set_action_app_control(context_trigger_rule_h rule, app_control_h app_control); @@ -810,6 +814,7 @@ int context_trigger_rule_set_action_app_control(context_trigger_rule_h rule, app * @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 + * @retval #CONTEXT_TRIGGER_ERROR_INVALID_RULE Invalid rule */ 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); diff --git a/packaging/context.spec b/packaging/context.spec index 35d5746..5e5a1e6 100644 --- a/packaging/context.spec +++ b/packaging/context.spec @@ -11,6 +11,7 @@ BuildRequires: pkgconfig(aul) BuildRequires: pkgconfig(bundle) BuildRequires: pkgconfig(capi-appfw-app-control) BuildRequires: pkgconfig(context-common) +BuildRequires: pkgconfig(pkgmgr-info) %description Tizen Context Framework Native API diff --git a/src/context_trigger.cpp b/src/context_trigger.cpp index dbf366d..b050f68 100644 --- a/src/context_trigger.cpp +++ b/src/context_trigger.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include #include "rule_validator.h" #include "priv_util.h" @@ -367,6 +368,26 @@ EXTAPI int context_trigger_rule_set_action_app_control(context_trigger_rule_h ru return CONTEXT_TRIGGER_ERROR_INVALID_RULE; } + // Err: service app + char* app_id = NULL; + error = app_control_get_app_id(app_control, &app_id); + IF_FAIL_RETURN_TAG(error == ERR_NONE, error, _E, "Failed to get app id"); + + pkgmgrinfo_appinfo_h app_info; + error = pkgmgrinfo_appinfo_get_appinfo(app_id, &app_info); + g_free(app_id); + IF_FAIL_RETURN_TAG(error == PMINFO_R_OK, CONTEXT_TRIGGER_ERROR_INVALID_RULE, _E, "No such app"); + + char *app_type = NULL; + pkgmgrinfo_appinfo_get_component_type(app_info, &app_type); + if (!strcmp(app_type, "svcapp")) { + _E("Service application is restricted"); + pkgmgrinfo_appinfo_destroy_appinfo(app_info); + return CONTEXT_TRIGGER_ERROR_INVALID_RULE; + } + pkgmgrinfo_appinfo_destroy_appinfo(app_info); + + // Set action type (rule->jrule).set(CT_RULE_DETAILS"."CT_RULE_ACTION, CT_RULE_ACTION_TYPE, CT_RULE_ACTION_TYPE_APP_CONTROL); // Set app control @@ -402,6 +423,18 @@ EXTAPI int context_trigger_rule_set_action_notification(context_trigger_rule_h r return CONTEXT_TRIGGER_ERROR_INVALID_RULE; } + // Err: App control check + if (app_control) { + char* app_id = NULL; + error = app_control_get_app_id(app_control, &app_id); + IF_FAIL_RETURN_TAG(error == ERR_NONE, error, _E, "Failed to get app id"); + + pkgmgrinfo_appinfo_h app_info; + error = pkgmgrinfo_appinfo_get_appinfo(app_id, &app_info); + g_free(app_id); + IF_FAIL_RETURN_TAG(error == PMINFO_R_OK, CONTEXT_TRIGGER_ERROR_INVALID_RULE, _E, "No such app"); + } + // 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); -- 2.7.4 From 8818fd6e9159487a77e65d79ff44f686a58cd988 Mon Sep 17 00:00:00 2001 From: Somin Kim Date: Tue, 8 Sep 2015 16:16:38 +0900 Subject: [PATCH 12/16] Allow service app launching triggers in TV profile Change-Id: Ia4dab92dc3b10819c2930c48e7cc2c06d7546d9f Signed-off-by: Mu-Woong Signed-off-by: Somin Kim --- packaging/context.spec | 9 ++++++++- src/context_trigger.cpp | 2 ++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/packaging/context.spec b/packaging/context.spec index 5e5a1e6..d806c83 100644 --- a/packaging/context.spec +++ b/packaging/context.spec @@ -6,6 +6,8 @@ Group: System/API License: Apache-2.0 Source0: %{name}-%{version}.tar.gz +%define BUILD_PROFILE %{?profile}%{!?profile:%{?tizen_profile_name}} + BuildRequires: cmake BuildRequires: pkgconfig(aul) BuildRequires: pkgconfig(bundle) @@ -35,7 +37,12 @@ export CFLAGS+=" -DTIZEN_ENGINEER_MODE" export CXXFLAGS+=" -DTIZEN_ENGINEER_MODE" export FFLAGS+=" -DTIZEN_ENGINEER_MODE" -cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} -DMAJORVER=${MAJORVER} -DFULLVER=%{version} +%if "%{?BUILD_PROFILE}" == "tv" +export CFLAGS+=" -D_ALLOW_SERVICE_APP_TRIGGER_" +export CXXFLAGS+=" -D_ALLOW_SERVICE_APP_TRIGGER_" +%endif + +cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} -DMAJORVER=${MAJORVER} -DFULLVER=%{version} -DPROFILE=%{?BUILD_PROFILE} make %{?jobs:-j%jobs} %install diff --git a/src/context_trigger.cpp b/src/context_trigger.cpp index b050f68..c74bfbd 100644 --- a/src/context_trigger.cpp +++ b/src/context_trigger.cpp @@ -378,6 +378,7 @@ EXTAPI int context_trigger_rule_set_action_app_control(context_trigger_rule_h ru g_free(app_id); IF_FAIL_RETURN_TAG(error == PMINFO_R_OK, CONTEXT_TRIGGER_ERROR_INVALID_RULE, _E, "No such app"); +#ifndef _ALLOW_SERVICE_APP_TRIGGER_ char *app_type = NULL; pkgmgrinfo_appinfo_get_component_type(app_info, &app_type); if (!strcmp(app_type, "svcapp")) { @@ -385,6 +386,7 @@ EXTAPI int context_trigger_rule_set_action_app_control(context_trigger_rule_h ru pkgmgrinfo_appinfo_destroy_appinfo(app_info); return CONTEXT_TRIGGER_ERROR_INVALID_RULE; } +#endif pkgmgrinfo_appinfo_destroy_appinfo(app_info); // Set action type -- 2.7.4 From 88775e7cdf9bf30f6e0066bdccb8e0d8ec362eb2 Mon Sep 17 00:00:00 2001 From: Somin Kim Date: Tue, 8 Sep 2015 16:17:15 +0900 Subject: [PATCH 13/16] Enable dbus action in trigger Change-Id: Id99453d0e9ae4c0a09b6aee328d81426e65963ff Signed-off-by: Mu-Woong Signed-off-by: Somin Kim --- CMakeLists.txt | 1 - include/context_trigger_internal.h | 7 ++++--- include/context_trigger_types_internal.h | 2 +- src/context_trigger.cpp | 15 +++++++++------ 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ed69fdc..6207e59 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -38,7 +38,6 @@ INSTALL(TARGETS ${target} DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT RuntimeL INSTALL( DIRECTORY ${CMAKE_SOURCE_DIR}/include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/context-service FILES_MATCHING - PATTERN "context_trigger_internal.h" EXCLUDE PATTERN "*.h" ) diff --git a/include/context_trigger_internal.h b/include/context_trigger_internal.h index 93f24f3..23b5146 100644 --- a/include/context_trigger_internal.h +++ b/include/context_trigger_internal.h @@ -17,6 +17,7 @@ #ifndef __TIZEN_CONTEXT_CONTEXT_TRIGGER_INTERNAL_H__ #define __TIZEN_CONTEXT_CONTEXT_TRIGGER_INTERNAL_H__ +#include #include /** @@ -28,8 +29,8 @@ * @param[in] object_path Path of the remote object * @param[in] interface_name D-Bus interface to invoke method on * @param[in] method_name The name of the method to invoke - * @param[in] user_data A user-defined string to be delivered as the first parameter of the method. - * @c NULL if not passing any values. + * @param[in] param Tuple with parameters for the method, + * or @c NULL if not passing parameters. * * @return 0 on success, otherwise a negative error value * @retval #CONTEXT_TRIGGER_ERROR_NONE Successful @@ -40,6 +41,6 @@ */ int context_trigger_rule_set_action_dbus_call(context_trigger_rule_h rule, const char *bus_name, const char *object_path, const char *interface_name, - const char *method_name, const char *user_data); + const char *method_name, GVariant *param); #endif diff --git a/include/context_trigger_types_internal.h b/include/context_trigger_types_internal.h index 5b584b2..6c0913e 100644 --- a/include/context_trigger_types_internal.h +++ b/include/context_trigger_types_internal.h @@ -59,7 +59,7 @@ #define CT_RULE_ACTION_DBUS_OBJECT "ACTION_DBUS_OBJ" #define CT_RULE_ACTION_DBUS_INTERFACE "ACTION_DBUS_IFACE" #define CT_RULE_ACTION_DBUS_METHOD "ACTION_DBUS_METHOD" -#define CT_RULE_ACTION_DBUS_USER_DATA "ACTION_DBUS_USERDATA" +#define CT_RULE_ACTION_DBUS_PARAMETER "ACTION_DBUS_PARAM" #define CT_RESPONSE "RES" diff --git a/src/context_trigger.cpp b/src/context_trigger.cpp index c74bfbd..bd04e14 100644 --- a/src/context_trigger.cpp +++ b/src/context_trigger.cpp @@ -467,28 +467,31 @@ EXTAPI int context_trigger_rule_set_action_notification(context_trigger_rule_h r return CONTEXT_TRIGGER_ERROR_NONE; } -#if 0 EXTAPI int context_trigger_rule_set_action_dbus_call(context_trigger_rule_h rule, - const char *bus_name, const char *object_path, const char *interface_name, const char *method_name, const char *user_data) + const char *bus_name, const char *object_path, const char *interface_name, const char *method_name, GVariant *param) { ASSERT_NOT_NULL(rule && bus_name && object_path && interface_name && method_name); - // if action arleady exists + /* 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 D-Bus info + /* Set action type */ (rule->jrule).set(CT_RULE_DETAILS "." CT_RULE_ACTION, CT_RULE_ACTION_TYPE, CT_RULE_ACTION_TYPE_DBUS_CALL); + + /* Set basic dbus method call info */ (rule->jrule).set(CT_RULE_DETAILS "." CT_RULE_ACTION, CT_RULE_ACTION_DBUS_NAME, bus_name); (rule->jrule).set(CT_RULE_DETAILS "." CT_RULE_ACTION, CT_RULE_ACTION_DBUS_OBJECT, object_path); (rule->jrule).set(CT_RULE_DETAILS "." CT_RULE_ACTION, CT_RULE_ACTION_DBUS_INTERFACE, interface_name); (rule->jrule).set(CT_RULE_DETAILS "." CT_RULE_ACTION, CT_RULE_ACTION_DBUS_METHOD, method_name); - (rule->jrule).set(CT_RULE_DETAILS "." CT_RULE_ACTION, CT_RULE_ACTION_DBUS_USER_DATA, (user_data ? user_data : "")); + + /* Set the parameters */ + if (param) + (rule->jrule).set(CT_RULE_DETAILS "." CT_RULE_ACTION, CT_RULE_ACTION_DBUS_PARAMETER, param); return CONTEXT_TRIGGER_ERROR_NONE; } -#endif // Set description EXTAPI int context_trigger_rule_set_description(context_trigger_rule_h rule, const char* description) -- 2.7.4 From 9f12c288cc1b1c9931dd8250d5d515c14ee215ef Mon Sep 17 00:00:00 2001 From: Somin Kim Date: Tue, 8 Sep 2015 16:18:00 +0900 Subject: [PATCH 14/16] Version 0.6.2 Change-Id: I20431d5527e2066fcab96f43a7717e1a6e1cbc96 Signed-off-by: Mu-Woong Signed-off-by: Somin Kim --- packaging/context.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/context.spec b/packaging/context.spec index d806c83..8cb9b7a 100644 --- a/packaging/context.spec +++ b/packaging/context.spec @@ -1,6 +1,6 @@ Name: context Summary: Tizen Context Framework Native API -Version: 0.6.0 +Version: 0.6.2 Release: 1 Group: System/API License: Apache-2.0 -- 2.7.4 From 6167b3e9e8dcb9deee47e769962f889001eaec9c Mon Sep 17 00:00:00 2001 From: Somin Kim Date: Tue, 8 Sep 2015 19:57:32 +0900 Subject: [PATCH 15/16] Fixed to use pkgmgrinfo_appinfo_get_usr_appinfo() Change-Id: Ic1e5dbeace61fb7d71d2034d60f12760024ef8a4 Signed-off-by: Somin Kim --- src/context_trigger.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/context_trigger.cpp b/src/context_trigger.cpp index bd04e14..fa2cd58 100644 --- a/src/context_trigger.cpp +++ b/src/context_trigger.cpp @@ -374,7 +374,7 @@ EXTAPI int context_trigger_rule_set_action_app_control(context_trigger_rule_h ru IF_FAIL_RETURN_TAG(error == ERR_NONE, error, _E, "Failed to get app id"); pkgmgrinfo_appinfo_h app_info; - error = pkgmgrinfo_appinfo_get_appinfo(app_id, &app_info); + error = pkgmgrinfo_appinfo_get_usr_appinfo(app_id, getuid(), &app_info); g_free(app_id); IF_FAIL_RETURN_TAG(error == PMINFO_R_OK, CONTEXT_TRIGGER_ERROR_INVALID_RULE, _E, "No such app"); @@ -432,7 +432,7 @@ EXTAPI int context_trigger_rule_set_action_notification(context_trigger_rule_h r IF_FAIL_RETURN_TAG(error == ERR_NONE, error, _E, "Failed to get app id"); pkgmgrinfo_appinfo_h app_info; - error = pkgmgrinfo_appinfo_get_appinfo(app_id, &app_info); + error = pkgmgrinfo_appinfo_get_usr_appinfo(app_id, getuid(), &app_info); g_free(app_id); IF_FAIL_RETURN_TAG(error == PMINFO_R_OK, CONTEXT_TRIGGER_ERROR_INVALID_RULE, _E, "No such app"); } -- 2.7.4 From d770c5148dbe74c8be9f491d2964bbb7fcdd7b63 Mon Sep 17 00:00:00 2001 From: Mu-Woong Date: Thu, 24 Sep 2015 15:00:56 +0900 Subject: [PATCH 16/16] Merge changes from Tizen 2.4 - Fix a broken link in trigger doc - Check string in-params to prevent SQL injections Change-Id: Ic99af23dafb59a65f27feb9bdd1303dae5d347e6 Signed-off-by: Mu-Woong --- doc/context_trigger_doc.h | 2 +- src/context_history.cpp | 2 +- src/rule_validator.cpp | 6 ++++++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/doc/context_trigger_doc.h b/doc/context_trigger_doc.h index c2e0f39..8d84f5b 100644 --- a/doc/context_trigger_doc.h +++ b/doc/context_trigger_doc.h @@ -79,5 +79,5 @@ * 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 - * Feature Element. + * Feature Element. */ diff --git a/src/context_history.cpp b/src/context_history.cpp index 8e3d99c..eea980e 100644 --- a/src/context_history.cpp +++ b/src/context_history.cpp @@ -414,7 +414,7 @@ bool check_filter_data_string(context_history_filter_e filter_type, const char* switch (filter_type) { case CONTEXT_HISTORY_FILTER_APP_ID: case CONTEXT_HISTORY_FILTER_WIFI_BSSID: - return true; + return (g_strstr_len(val, -1, ";") == NULL); default: return false; diff --git a/src/rule_validator.cpp b/src/rule_validator.cpp index 0ed5d4a..1356ef5 100644 --- a/src/rule_validator.cpp +++ b/src/rule_validator.cpp @@ -141,6 +141,9 @@ bool ctx::rule_validator::check_option_string(std::string name, std::string key, { init(); + // Err: ';' for SQL injection + IF_FAIL_RETURN(value.find(';') == std::string::npos, false); + // Err: Item with no option if (template_map[name].array_get_size(NULL, KEY_OPTION) <= 0) { return false; @@ -227,6 +230,9 @@ bool ctx::rule_validator::check_comparison_string(std::string name, std::string { init(); + // Err: ';' for SQL injection + IF_FAIL_RETURN(value.find(';') == std::string::npos, false); + // Err: Invalid attribute key or Invalid value type bool ret = false; ctx::json attr_tempt; -- 2.7.4