From: Somin Kim Date: Mon, 22 Aug 2016 07:25:02 +0000 (+0900) Subject: History types internal & trigger types internal removed X-Git-Tag: accepted/tizen/common/20160907.154906^2~4 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=28a91d687d1f0cf01bdf9060736e195a45a0690e;p=platform%2Fcore%2Fapi%2Fcontext.git History types internal & trigger types internal removed Change-Id: I478a5657b51c0920db41bcb9103c880f731b6357 Signed-off-by: Somin Kim --- diff --git a/include/context_history_types_internal.h b/include/context_history_types_internal.h deleted file mode 100644 index ae548f7..0000000 --- a/include/context_history_types_internal.h +++ /dev/null @@ -1,43 +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. - */ - -#ifndef __TIZEN_CONTEXT_HISTORY_TYPES_INTERNAL_H__ -#define __TIZEN_CONTEXT_HISTORY_TYPES_INTERNAL_H__ - -#define CONTEXT_HISTORY_DATA "QueryResult" - -#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 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 deleted file mode 100644 index ca01dcc..0000000 --- a/include/context_trigger_types_internal.h +++ /dev/null @@ -1,129 +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. - */ - -#ifndef __TIZEN_CONTEXT_CONTEXT_TRIGGER_TYPES_INTERNAL_H__ -#define __TIZEN_CONTEXT_CONTEXT_TRIGGER_TYPES_INTERNAL_H__ - -#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 CONTEXT_TRIGGER_SUBJECT_GET_TEMPLATE "trigger/tepmlate/get" -#define CONTEXT_TRIGGER_SUBJECT_CUSTOM "custom" - -#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_ACTION_TYPE_DBUS_CALL "dbus_call" - -#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_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_PARAMETER "ACTION_DBUS_PARAM" - -#define CT_RESPONSE "RES" - -#define CT_EVENT_TIME "device/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_CONTACTS "social/contacts" -#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 "device/time" -#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 CT_CUSTOM CONTEXT_TRIGGER_SUBJECT_CUSTOM -#define CT_CUSTOM_REQ "req" -#define CT_CUSTOM_ADD "add" -#define CT_CUSTOM_REMOVE "remove" -#define CT_CUSTOM_PUBLISH "publish" - -#define CT_CUSTOM_NAME "name" -#define CT_CUSTOM_ATTRIBUTES "attributes" -#define CT_CUSTOM_FACT "fact" -#define CT_CUSTOM_TYPE "type" -#define CT_CUSTOM_INT "integer" -#define CT_CUSTOM_STRING "string" -#define CT_CUSTOM_ENUM "enum" -#define CT_CUSTOM_MIN "minimum" -#define CT_CUSTOM_MAX "maximum" -#define CT_CUSTOM_SUBJECT "subject" - -#define TYPE_EVENT 1 -#define TYPE_CONDITION 2 - -#define TYPE_INT_STR "integer" -#define TYPE_STRING_STR "string" -#define TYPE_ENUM_STR "enum" -#define TYPE_DOUBLE_STR "double" - -#define TYPE_OPTION_STR "options" -#define TYPE_ATTR_STR "attributes" -#define SUBJECT_STR "subject" - - -#endif /* __TIZEN_CONTEXT_CONTEXT_TRIGGER_TYPES_INTERNAL_H__ */ diff --git a/src/context_history.cpp b/src/context_history.cpp index 5f6a3a3..ff04836 100644 --- a/src/context_history.cpp +++ b/src/context_history.cpp @@ -18,20 +18,13 @@ #include #include #include +#include #include -#include #define TYPE_INT 0 #define TYPE_STRING 1 #define FILTER_KEY_LIMIT 10 -#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. @@ -161,7 +154,7 @@ SO_EXPORT int context_history_get_list(context_history_h handle, context_history _J("Read response", tmp_list); - IF_FAIL_RETURN_TAG(tmp_list.getSize(NULL, CONTEXT_HISTORY_DATA) > 0, CONTEXT_HISTORY_ERROR_NO_DATA, _D, "No data"); + IF_FAIL_RETURN_TAG(tmp_list.getSize(NULL, KEY_QUERY_RESULT) > 0, CONTEXT_HISTORY_ERROR_NO_DATA, _D, "No data"); *list = new(std::nothrow) _cx_history_list_handle(); ASSERT_ALLOC(*list); @@ -178,7 +171,7 @@ SO_EXPORT int context_history_list_get_count(context_history_list_h list, int* c ASSERT_NOT_NULL(count); *count = 0; - int result = list->jlist.getSize(NULL, CONTEXT_HISTORY_DATA); + int result = list->jlist.getSize(NULL, KEY_QUERY_RESULT); IF_FAIL_RETURN(result > 0, CONTEXT_HISTORY_ERROR_OPERATION_FAILED); *count = result; @@ -193,7 +186,7 @@ SO_EXPORT int context_history_list_get_current(context_history_list_h list, cont *record = NULL; ctx::Json tmp_record; - int error = list->jlist.getAt(NULL, CONTEXT_HISTORY_DATA, list->current, &tmp_record); + int error = list->jlist.getAt(NULL, KEY_QUERY_RESULT, 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(); @@ -217,7 +210,7 @@ SO_EXPORT int context_history_list_move_next(context_history_list_h list) { ASSERT_NOT_NULL(list); - IF_FAIL_RETURN_TAG(list->current+1 < list->jlist.getSize(NULL, CONTEXT_HISTORY_DATA), CONTEXT_HISTORY_ERROR_NO_DATA, _D, "End of list"); + IF_FAIL_RETURN_TAG(list->current+1 < list->jlist.getSize(NULL, KEY_QUERY_RESULT), CONTEXT_HISTORY_ERROR_NO_DATA, _D, "End of list"); list->current++; @@ -284,31 +277,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 = FILTER_TIME_SPAN; + str = KEY_TIME_SPAN; break; case CONTEXT_HISTORY_FILTER_RESULT_SIZE: - str = FILTER_RESULT_SIZE; + str = KEY_RESULT_SIZE; break; case CONTEXT_HISTORY_FILTER_APP_ID: - str = FILTER_APP_ID; + str = KEY_APP_ID; break; case CONTEXT_HISTORY_FILTER_DAY_OF_WEEK: - str = FILTER_DAY_OF_WEEK; + str = KEY_DAY_OF_WEEK; break; case CONTEXT_HISTORY_FILTER_START_TIME: - str = FILTER_START_TIME; + str = KEY_START_TIME; break; case CONTEXT_HISTORY_FILTER_END_TIME: - str = FILTER_END_TIME; + str = KEY_END_TIME; break; case CONTEXT_HISTORY_FILTER_WIFI_BSSID: - str = FILTER_WIFI_BSSID; + str = KEY_BSSID; break; case CONTEXT_HISTORY_FILTER_AUDIO_JACK: - str = FILTER_AUDIO_JACK; + str = KEY_AUDIO_JACK; break; case CONTEXT_HISTORY_FILTER_COMMUNICATION_TYPE: - str = FILTER_COMMUNICATION_TYPE; + str = KEY_COMMUNICATION_TYPE; break; default: break; @@ -321,34 +314,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 = SUBJ_RECENTLY_USED_APP; + str = SUBJ_APP_RECENTLY_USED; break; case CONTEXT_HISTORY_FREQUENTLY_USED_APP: - str = SUBJ_FREQUENTLY_USED_APP; + str = SUBJ_APP_FREQUENTLY_USED; break; case CONTEXT_HISTORY_RARELY_USED_APP: - str = SUBJ_RARELY_USED_APP; + str = SUBJ_APP_RARELY_USED; break; case CONTEXT_HISTORY_PEAK_TIME_FOR_APP: - str = SUBJ_PEAK_TIME_FOR_APP; + str = SUBJ_APP_PEAK_TIME; break; case CONTEXT_HISTORY_PEAK_TIME_FOR_MUSIC: - str = SUBJ_PEAK_TIME_FOR_MUSIC; + str = SUBJ_MUSIC_PEAK_TIME; break; case CONTEXT_HISTORY_PEAK_TIME_FOR_VIDEO: - str = SUBJ_PEAK_TIME_FOR_VIDEO; + str = SUBJ_VIDEO_PEAK_TIME; break; case CONTEXT_HISTORY_COMMON_SETTING_FOR_APP: - str = SUBJ_COMMON_SETTING_FOR_APP; + str = SUBJ_APP_COMMON_SETTING; break; case CONTEXT_HISTORY_COMMON_SETTING_FOR_MUSIC: - str = SUBJ_COMMON_SETTING_FOR_MUSIC; + str = SUBJ_MUSIC_COMMON_SETTING; break; case CONTEXT_HISTORY_COMMON_SETTING_FOR_VIDEO: - str = SUBJ_COMMON_SETTING_FOR_VIDEO; + str = SUBJ_VIDEO_COMMON_SETTING; break; case CONTEXT_HISTORY_FREQUENTLY_COMMUNICATED_ADDRESS: - str = SUBJ_FREQUENTLY_COMMUNICATED_ADDRESS; + str = SUBJ_SOCIAL_FREQ_ADDRESS; break; default: break; @@ -428,15 +421,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, - 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, + KEY_TIME_SPAN, + KEY_RESULT_SIZE, + KEY_APP_ID, + KEY_DAY_OF_WEEK, + KEY_START_TIME, + KEY_END_TIME, + KEY_BSSID, + KEY_AUDIO_JACK, + KEY_COMMUNICATION_TYPE, }; bool allowed[FILTER_KEY_LIMIT] = {false}; diff --git a/src/context_trigger.cpp b/src/context_trigger.cpp index 5b3ca48..ba1decc 100644 --- a/src/context_trigger.cpp +++ b/src/context_trigger.cpp @@ -29,15 +29,19 @@ #include #include -#include +#include +#include #include #include "rule_validator.h" -#define INITIAL_RULE "{ \"ID\" : -1, \"DESCRIPTION\" : \"\", \"DETAILS\" : { } }" -#define INITIAL_ENTRY "{ \"DATA_ARR\" : [ ] }" -#define INITIAL_REF "{ \"option\" : [ ], \"attributes\" : [ ] }" -#define EVENT_DATA_KEY_PREFIX_STR std::string("?") //#define DOUBLE_PRECISION 2 +#define TYPE_EVENT 1 +#define TYPE_CONDITION 2 +#define TYPE_OPTION TRIG_TMPL_KEY_OPTION +#define TYPE_ATTRIBUTE TRIG_TMPL_KEY_ATTRIBUTE +#define INITIAL_RULE "{ \"" TRIG_RULE_DESCRIPTION "\" : \"\", \"" TRIG_RULE_DETAILS "\" : { } }" +#define INITIAL_ENTRY "{ \"" TRIG_RULE_DATA_ARR "\" : [ ] }" +#define INITIAL_REF "{ \"" TRIG_TMPL_KEY_OPTION "\" : [ ], \"" TRIG_TMPL_KEY_ATTRIBUTE "\" : [ ] }" static ctx::DBusClient __dbusClient; @@ -83,22 +87,22 @@ SO_EXPORT int context_trigger_add_rule(context_trigger_rule_h rule, int* rule_id // Err: No event std::string ename; - bool ret = (rule->jrule).get(CT_RULE_DETAILS "." CT_RULE_EVENT, CT_RULE_EVENT_ITEM, &ename); + bool ret = (rule->jrule).get(TRIG_RULE_DETAILS "." TRIG_RULE_EVENT, TRIG_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); + ret = (rule->jrule).get(TRIG_RULE_DETAILS "." TRIG_RULE_ACTION, TRIG_RULE_ACTION_TYPE, &type); if (!ret) return CONTEXT_TRIGGER_ERROR_INVALID_RULE; ctx::Json jrule_id; - int error = __dbusClient.write(CONTEXT_TRIGGER_SUBJECT_ADD, rule->jrule, &jrule_id); + int error = __dbusClient.write(SUBJ_TRIGGER_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); + jrule_id.get(NULL, TRIG_KEY_RULE_ID, rule_id); + (rule->jrule).set(NULL, TRIG_KEY_RULE_ID, *rule_id); } return error; @@ -112,8 +116,8 @@ SO_EXPORT int context_trigger_remove_rule(int rule_id) return CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER; ctx::Json jrule_id; - jrule_id.set(NULL, CT_RULE_ID, rule_id); - int error = __dbusClient.write(CONTEXT_TRIGGER_SUBJECT_REMOVE, jrule_id, NULL); + jrule_id.set(NULL, TRIG_KEY_RULE_ID, rule_id); + int error = __dbusClient.write(SUBJ_TRIGGER_REMOVE, jrule_id, NULL); if (error == ERR_ALREADY_STARTED) { // Rule is still enabled. return CONTEXT_TRIGGER_ERROR_RULE_ENABLED; @@ -132,10 +136,10 @@ SO_EXPORT int context_trigger_enable_rule(int rule_id) return CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER; ctx::Json jrule_id; - jrule_id.set(NULL, CT_RULE_ID, rule_id); + jrule_id.set(NULL, TRIG_KEY_RULE_ID, rule_id); int req_id; // Useless in context_trigger - int error = __dbusClient.subscribe(CONTEXT_TRIGGER_SUBJECT_ENABLE, jrule_id, &req_id, NULL); + int error = __dbusClient.subscribe(SUBJ_TRIGGER_ENABLE, jrule_id, &req_id, NULL); if (error == ERR_NO_DATA) { return CONTEXT_TRIGGER_ERROR_RULE_NOT_EXIST; @@ -152,8 +156,8 @@ SO_EXPORT int context_trigger_disable_rule(int rule_id) return CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER; ctx::Json jrule_id; - jrule_id.set(NULL, CT_RULE_ID, rule_id); - int error = __dbusClient.write(CONTEXT_TRIGGER_SUBJECT_DISABLE, jrule_id, NULL); + jrule_id.set(NULL, TRIG_KEY_RULE_ID, rule_id); + int error = __dbusClient.write(SUBJ_TRIGGER_DISABLE, jrule_id, NULL); if (error == ERR_NO_DATA) { return CONTEXT_TRIGGER_ERROR_RULE_NOT_EXIST; @@ -169,7 +173,7 @@ SO_EXPORT int context_trigger_get_own_rule_ids(int** enabled_rule_ids, int* enab int req_id; ctx::Json data_read; - int error = __dbusClient.readSync(CONTEXT_TRIGGER_SUBJECT_GET_RULE_IDS, NULL, &req_id, &data_read); + int error = __dbusClient.readSync(SUBJ_TRIGGER_GET_RULE_IDS, NULL, &req_id, &data_read); if (error != ERR_NONE) { return error; @@ -177,14 +181,14 @@ SO_EXPORT int context_trigger_get_own_rule_ids(int** enabled_rule_ids, int* enab // Enabled rules int* e_arr = NULL; - *enabled_rule_count = data_read.getSize(NULL, CT_RULE_ARRAY_ENABLED); + *enabled_rule_count = data_read.getSize(NULL, TRIG_KEY_ENABLED_IDS); 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.getAt(NULL, CT_RULE_ARRAY_ENABLED, i, &id); i++) { + for (int i = 0; data_read.getAt(NULL, TRIG_KEY_ENABLED_IDS, i, &id); i++) { *(e_arr + i) = id; } } @@ -192,14 +196,14 @@ SO_EXPORT int context_trigger_get_own_rule_ids(int** enabled_rule_ids, int* enab // Disabled rules int* d_arr = NULL; - *disabled_rule_count = data_read.getSize(NULL, CT_RULE_ARRAY_DISABLED); + *disabled_rule_count = data_read.getSize(NULL, TRIG_KEY_DISABLED_IDS); 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.getAt(NULL, CT_RULE_ARRAY_DISABLED, i, &id); i++) { + for (int i = 0; data_read.getAt(NULL, TRIG_KEY_DISABLED_IDS, i, &id); i++) { *(d_arr + i) = id; } } @@ -216,11 +220,11 @@ SO_EXPORT int context_trigger_get_rule_by_id(int rule_id, context_trigger_rule_h return CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER; ctx::Json option; - option.set(NULL, CT_RULE_ID, rule_id); + option.set(NULL, TRIG_KEY_RULE_ID, rule_id); int req_id; ctx::Json data_read; - int error = __dbusClient.readSync(CONTEXT_TRIGGER_SUBJECT_GET, option, &req_id, &data_read); + int error = __dbusClient.readSync(SUBJ_TRIGGER_GET, option, &req_id, &data_read); if (error == ERR_NO_DATA) { return CONTEXT_TRIGGER_ERROR_RULE_NOT_EXIST; @@ -246,7 +250,7 @@ SO_EXPORT int context_trigger_rule_create(context_trigger_logical_type_e logical } *rule = new(std::nothrow) _context_trigger_rule_h(); - (*rule)->jrule.set(CT_RULE_DETAILS, CT_RULE_OPERATOR, logical_str); + (*rule)->jrule.set(TRIG_RULE_DETAILS, TRIG_RULE_OPERATOR, logical_str); return ERR_NONE; } @@ -268,13 +272,13 @@ SO_EXPORT int context_trigger_rule_add_entry(context_trigger_rule_h rule, contex ASSERT_NOT_NULL(rule && entry); std::string des; - bool ret = (rule->jrule).get(NULL, CT_RULE_DESCRIPTION, &des); + bool ret = (rule->jrule).get(NULL, TRIG_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)) { + if ((rule->jrule).get(TRIG_RULE_DETAILS, TRIG_RULE_EVENT, &elem)) { return CONTEXT_TRIGGER_ERROR_INVALID_RULE; } @@ -284,22 +288,22 @@ SO_EXPORT int context_trigger_rule_add_entry(context_trigger_rule_h rule, contex // Err: If referential conditions are registered priviously, check them std::string ename; - (entry->jentry).get(NULL, CT_RULE_EVENT_ITEM, &ename); + (entry->jentry).get(NULL, TRIG_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); + ret = (rule->jrule).set(TRIG_RULE_DETAILS, TRIG_RULE_EVENT, temp); } else if (entry->type == TYPE_CONDITION) { // Err: Condition without comparison data - if ((entry->jentry).getSize(NULL, CT_RULE_DATA_ARR) < 1) { + if ((entry->jentry).getSize(NULL, TRIG_RULE_DATA_ARR) < 1) { return CONTEXT_TRIGGER_ERROR_INVALID_RULE; } ctx::Json elem; - for (int i = 0; (entry->jentry).getAt(NULL, CT_RULE_DATA_ARR, i, &elem); i++) { - int val_arr_size = elem.getSize(NULL, CT_RULE_DATA_VALUE_ARR); - int op_arr_size = elem.getSize(NULL, CT_RULE_DATA_VALUE_OPERATOR_ARR); + for (int i = 0; (entry->jentry).getAt(NULL, TRIG_RULE_DATA_ARR, i, &elem); i++) { + int val_arr_size = elem.getSize(NULL, TRIG_RULE_DATA_VALUE_ARR); + int op_arr_size = elem.getSize(NULL, TRIG_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) { @@ -312,7 +316,7 @@ SO_EXPORT int context_trigger_rule_add_entry(context_trigger_rule_h rule, contex // If event is already added .... std::string ename; - ret = (rule->jrule).get(CT_RULE_DETAILS "." CT_RULE_EVENT, CT_RULE_EVENT_ITEM, &ename); + ret = (rule->jrule).get(TRIG_RULE_DETAILS "." TRIG_RULE_EVENT, TRIG_RULE_EVENT_ITEM, &ename); if (ret) { // Err: Check referential information if exists ret = ctx::rule_validator::check_referential_data(ename, entry->jref); @@ -320,18 +324,18 @@ SO_EXPORT int context_trigger_rule_add_entry(context_trigger_rule_h rule, contex } else { // If not, copy referential information to rule entry ctx::Json info; - for (int j = 0; (entry->jref).getAt(NULL, TYPE_OPTION_STR, j, &info); j++) { - (rule->jref).append(NULL, TYPE_OPTION_STR, info); + for (int j = 0; (entry->jref).getAt(NULL, TYPE_OPTION, j, &info); j++) { + (rule->jref).append(NULL, TYPE_OPTION, info); } - for (int j = 0; (entry->jref).getAt(NULL, TYPE_ATTR_STR, j, &info); j++) { - (rule->jref).append(NULL, TYPE_ATTR_STR, info); + for (int j = 0; (entry->jref).getAt(NULL, TYPE_ATTRIBUTE, j, &info); j++) { + (rule->jref).append(NULL, TYPE_ATTRIBUTE, info); } } } ctx::Json temp = (entry->jentry).str(); - ret = (rule->jrule).append(CT_RULE_DETAILS, CT_RULE_CONDITION, temp); + ret = (rule->jrule).append(TRIG_RULE_DETAILS, TRIG_RULE_CONDITION, temp); } else { // Entry is not created return CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER; @@ -370,7 +374,7 @@ SO_EXPORT int context_trigger_rule_set_action_app_control(context_trigger_rule_h // Err: if action arleady exists std::string type; - if ((rule->jrule).get(CT_RULE_DETAILS "." CT_RULE_ACTION, CT_RULE_ACTION_TYPE, &type)) { + if ((rule->jrule).get(TRIG_RULE_DETAILS "." TRIG_RULE_ACTION, TRIG_RULE_ACTION_TYPE, &type)) { return CONTEXT_TRIGGER_ERROR_INVALID_RULE; } @@ -400,7 +404,7 @@ SO_EXPORT int context_trigger_rule_set_action_app_control(context_trigger_rule_h 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); + (rule->jrule).set(TRIG_RULE_DETAILS "." TRIG_RULE_ACTION, TRIG_RULE_ACTION_TYPE, TRIG_RULE_ACTION_TYPE_APP_CONTROL); // Set app control bundle* appctl_bundle = NULL; @@ -413,7 +417,7 @@ SO_EXPORT int context_trigger_rule_set_action_app_control(context_trigger_rule_h 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); + (rule->jrule).set(TRIG_RULE_DETAILS "." TRIG_RULE_ACTION, TRIG_RULE_ACTION_APP_CONTROL, appctl_str); bundle_free_encoded_rawdata(&appctl_raw); @@ -431,7 +435,7 @@ SO_EXPORT int context_trigger_rule_set_action_notification(context_trigger_rule_ // if action arleady exists std::string type; - if ((rule->jrule).get(CT_RULE_DETAILS "." CT_RULE_ACTION, CT_RULE_ACTION_TYPE, &type)) { + if ((rule->jrule).get(TRIG_RULE_DETAILS "." TRIG_RULE_ACTION, TRIG_RULE_ACTION_TYPE, &type)) { return CONTEXT_TRIGGER_ERROR_INVALID_RULE; } @@ -452,13 +456,13 @@ SO_EXPORT int context_trigger_rule_set_action_notification(context_trigger_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); + (rule->jrule).set(TRIG_RULE_DETAILS "." TRIG_RULE_ACTION, TRIG_RULE_ACTION_TYPE, TRIG_RULE_ACTION_TYPE_NOTIFICATION); + (rule->jrule).set(TRIG_RULE_DETAILS "." TRIG_RULE_ACTION, TRIG_RULE_ACTION_NOTI_TITLE, title); + (rule->jrule).set(TRIG_RULE_DETAILS "." TRIG_RULE_ACTION, TRIG_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); + (rule->jrule).set(TRIG_RULE_DETAILS "." TRIG_RULE_ACTION, TRIG_RULE_ACTION_NOTI_ICON_PATH, icon_path); } // Set app control @@ -473,7 +477,7 @@ SO_EXPORT int context_trigger_rule_set_action_notification(context_trigger_rule_ 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); + (rule->jrule).set(TRIG_RULE_DETAILS "." TRIG_RULE_ACTION, TRIG_RULE_ACTION_APP_CONTROL, appctl_str); bundle_free_encoded_rawdata(&appctl_raw); } @@ -488,21 +492,21 @@ SO_EXPORT int context_trigger_rule_set_action_dbus_call(context_trigger_rule_h r /* if action arleady exists */ std::string type; - if ((rule->jrule).get(CT_RULE_DETAILS "." CT_RULE_ACTION, CT_RULE_ACTION_TYPE, &type)) + if ((rule->jrule).get(TRIG_RULE_DETAILS "." TRIG_RULE_ACTION, TRIG_RULE_ACTION_TYPE, &type)) return CONTEXT_TRIGGER_ERROR_INVALID_RULE; /* Set action type */ - (rule->jrule).set(CT_RULE_DETAILS "." CT_RULE_ACTION, CT_RULE_ACTION_TYPE, CT_RULE_ACTION_TYPE_DBUS_CALL); + (rule->jrule).set(TRIG_RULE_DETAILS "." TRIG_RULE_ACTION, TRIG_RULE_ACTION_TYPE, TRIG_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(TRIG_RULE_DETAILS "." TRIG_RULE_ACTION, TRIG_RULE_ACTION_DBUS_NAME, bus_name); + (rule->jrule).set(TRIG_RULE_DETAILS "." TRIG_RULE_ACTION, TRIG_RULE_ACTION_DBUS_OBJECT, object_path); + (rule->jrule).set(TRIG_RULE_DETAILS "." TRIG_RULE_ACTION, TRIG_RULE_ACTION_DBUS_INTERFACE, interface_name); + (rule->jrule).set(TRIG_RULE_DETAILS "." TRIG_RULE_ACTION, TRIG_RULE_ACTION_DBUS_METHOD, method_name); /* Set the parameters */ if (param) - (rule->jrule).set(CT_RULE_DETAILS "." CT_RULE_ACTION, CT_RULE_ACTION_DBUS_PARAMETER, param); + (rule->jrule).set(TRIG_RULE_DETAILS "." TRIG_RULE_ACTION, TRIG_RULE_ACTION_DBUS_PARAMETER, param); return CONTEXT_TRIGGER_ERROR_NONE; } @@ -513,7 +517,7 @@ SO_EXPORT int context_trigger_rule_set_description(context_trigger_rule_h rule, _D("BEGIN"); ASSERT_NOT_NULL(rule); - (rule->jrule).set(NULL, CT_RULE_DESCRIPTION, description); + (rule->jrule).set(NULL, TRIG_RULE_DESCRIPTION, description); return CONTEXT_TRIGGER_ERROR_NONE; } @@ -525,7 +529,7 @@ SO_EXPORT int context_trigger_rule_get_description(context_trigger_rule_h rule, ASSERT_NOT_NULL(rule && description); std::string val; - (rule->jrule).get(NULL, CT_RULE_DESCRIPTION, &val); + (rule->jrule).get(NULL, TRIG_RULE_DESCRIPTION, &val); *description = strdup(val.c_str()); @@ -583,8 +587,8 @@ int context_trigger_rule_event_create_internal(const char* event_item, context_t IF_FAIL_RETURN_TAG(error == ERR_NONE, error, _E, "Failed to request template: %#x", error); *entry = new(std::nothrow) _context_trigger_rule_entry_h(TYPE_EVENT); - (*entry)->jentry.set(NULL, CT_RULE_EVENT_ITEM, event_item); - (*entry)->jentry.set(NULL, CT_RULE_EVENT_OPERATOR, logical_str); + (*entry)->jentry.set(NULL, TRIG_RULE_EVENT_ITEM, event_item); + (*entry)->jentry.set(NULL, TRIG_RULE_EVENT_OPERATOR, logical_str); return CONTEXT_TRIGGER_ERROR_NONE; } @@ -662,8 +666,8 @@ int context_trigger_rule_condition_create_internal(const char* condition_item, c IF_FAIL_RETURN_TAG(error == ERR_NONE, error, _E, "Failed to request template: %#x", error); *entry = new(std::nothrow) _context_trigger_rule_entry_h(TYPE_CONDITION); - (*entry)->jentry.set(NULL, CT_RULE_CONDITION_ITEM, condition_item); - (*entry)->jentry.set(NULL, CT_RULE_CONDITION_OPERATOR, logical_str); + (*entry)->jentry.set(NULL, TRIG_RULE_CONDITION_ITEM, condition_item); + (*entry)->jentry.set(NULL, TRIG_RULE_CONDITION_OPERATOR, logical_str); return CONTEXT_TRIGGER_ERROR_NONE; } @@ -709,13 +713,13 @@ SO_EXPORT int context_trigger_rule_entry_add_option_int(context_trigger_rule_ent bool ret = true; std::string name; - (entry->jentry).get(NULL, CT_RULE_CONDITION_ITEM, &name); + (entry->jentry).get(NULL, TRIG_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); + (entry->jentry).set(TRIG_RULE_CONDITION_OPTION, option_key, value); return CONTEXT_TRIGGER_ERROR_NONE; } @@ -727,13 +731,13 @@ SO_EXPORT int context_trigger_rule_entry_add_option_string(context_trigger_rule_ bool ret = true; std::string name; - (entry->jentry).get(NULL, CT_RULE_CONDITION_ITEM, &name); + (entry->jentry).get(NULL, TRIG_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); + (entry->jentry).set(TRIG_RULE_CONDITION_OPTION, option_key, value); return CONTEXT_TRIGGER_ERROR_NONE; } @@ -749,17 +753,17 @@ SO_EXPORT int context_trigger_rule_entry_add_option(context_trigger_rule_entry_h } std::string name; - (entry->jentry).get(NULL, CT_RULE_CONDITION_ITEM, &name); + (entry->jentry).get(NULL, TRIG_RULE_CONDITION_ITEM, &name); // Err: Check if key is valid - bool ret = ctx::rule_validator::check_valid_key(TYPE_OPTION_STR, name, option_key); + 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_STR, &(entry->jref), name, option_key, event_data_key); + 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)); + (entry->jentry).set(TRIG_RULE_CONDITION_OPTION, option_key, std::string(TRIG_RULE_REF_KEY_PREFIX) + std::string(event_data_key)); return CONTEXT_TRIGGER_ERROR_NONE; } @@ -776,14 +780,14 @@ SO_EXPORT int context_trigger_rule_entry_add_key(context_trigger_rule_entry_h en // 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_STR, name, key); + (entry->jentry).get(NULL, TRIG_RULE_EVENT_ITEM, &name); + bool ret = ctx::rule_validator::check_valid_key(TYPE_ATTRIBUTE, name, key); IF_FAIL_RETURN(ret, CONTEXT_TRIGGER_ERROR_INVALID_RULE); ctx::Json elem; - for (int i = 0; (entry->jentry).getAt(NULL, CT_RULE_DATA_ARR, i, &elem); i++) { + for (int i = 0; (entry->jentry).getAt(NULL, TRIG_RULE_DATA_ARR, i, &elem); i++) { std::string elem_item; - elem.get(NULL, CT_RULE_DATA_KEY, &elem_item); + elem.get(NULL, TRIG_RULE_DATA_KEY, &elem_item); // Err: Comparison key is already added if (elem_item.compare(key) == 0) { return CONTEXT_TRIGGER_ERROR_INVALID_RULE; @@ -791,9 +795,9 @@ SO_EXPORT int context_trigger_rule_entry_add_key(context_trigger_rule_entry_h en } ctx::Json data; - data.set(NULL, CT_RULE_DATA_KEY, key); - data.set(NULL, CT_RULE_DATA_KEY_OPERATOR, logical_str); - (entry->jentry).append(NULL, CT_RULE_DATA_ARR, data); + data.set(NULL, TRIG_RULE_DATA_KEY, key); + data.set(NULL, TRIG_RULE_DATA_KEY_OPERATOR, logical_str); + (entry->jentry).append(NULL, TRIG_RULE_DATA_ARR, data); return CONTEXT_TRIGGER_ERROR_NONE; } @@ -801,24 +805,24 @@ SO_EXPORT int context_trigger_rule_entry_add_key(context_trigger_rule_entry_h en static int context_trigger_rule_entry_add_comparison_string_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).getAt(NULL, CT_RULE_DATA_ARR, i, &elem); i++) { + for (int i = 0; (entry->jentry).getAt(NULL, TRIG_RULE_DATA_ARR, i, &elem); i++) { std::string elem_item; - elem.get(NULL, CT_RULE_DATA_KEY, &elem_item); + elem.get(NULL, TRIG_RULE_DATA_KEY, &elem_item); if (elem_item.compare(key) == 0) { std::string elem_val; std::string elem_op; - for (int j = 0; elem.getAt(NULL, CT_RULE_DATA_VALUE_ARR, j, &elem_val); j++) { - elem.getAt(NULL, CT_RULE_DATA_VALUE_OPERATOR_ARR, j, &elem_op); + for (int j = 0; elem.getAt(NULL, TRIG_RULE_DATA_VALUE_ARR, j, &elem_val); j++) { + elem.getAt(NULL, TRIG_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.append(NULL, CT_RULE_DATA_VALUE_ARR, value.c_str()); - elem.append(NULL, CT_RULE_DATA_VALUE_OPERATOR_ARR, op); - (entry->jentry).setAt(NULL, CT_RULE_DATA_ARR, i, elem); + elem.append(NULL, TRIG_RULE_DATA_VALUE_ARR, value.c_str()); + elem.append(NULL, TRIG_RULE_DATA_VALUE_OPERATOR_ARR, op); + (entry->jentry).setAt(NULL, TRIG_RULE_DATA_ARR, i, elem); return CONTEXT_TRIGGER_ERROR_NONE; } @@ -831,24 +835,24 @@ static int context_trigger_rule_entry_add_comparison_string_internal(context_tri static int context_trigger_rule_entry_add_comparison_int_internal(context_trigger_rule_entry_h entry, const char* key, std::string op, int value) { ctx::Json elem; - for (int i = 0; (entry->jentry).getAt(NULL, CT_RULE_DATA_ARR, i, &elem); i++) { + for (int i = 0; (entry->jentry).getAt(NULL, TRIG_RULE_DATA_ARR, i, &elem); i++) { std::string elem_item; - elem.get(NULL, CT_RULE_DATA_KEY, &elem_item); + elem.get(NULL, TRIG_RULE_DATA_KEY, &elem_item); if (elem_item.compare(key) == 0) { int elem_val; std::string elem_op; - for (int j = 0; elem.getAt(NULL, CT_RULE_DATA_VALUE_ARR, j, &elem_val); j++) { - elem.getAt(NULL, CT_RULE_DATA_VALUE_OPERATOR_ARR, j, &elem_op); + for (int j = 0; elem.getAt(NULL, TRIG_RULE_DATA_VALUE_ARR, j, &elem_val); j++) { + elem.getAt(NULL, TRIG_RULE_DATA_VALUE_OPERATOR_ARR, j, &elem_op); // Err: Duplicated if (elem_val == value && elem_op.compare(op) == 0) { return CONTEXT_TRIGGER_ERROR_INVALID_RULE; } } - elem.append(NULL, CT_RULE_DATA_VALUE_ARR, value); - elem.append(NULL, CT_RULE_DATA_VALUE_OPERATOR_ARR, op); - (entry->jentry).setAt(NULL, CT_RULE_DATA_ARR, i, elem); + elem.append(NULL, TRIG_RULE_DATA_VALUE_ARR, value); + elem.append(NULL, TRIG_RULE_DATA_VALUE_OPERATOR_ARR, op); + (entry->jentry).setAt(NULL, TRIG_RULE_DATA_ARR, i, elem); return CONTEXT_TRIGGER_ERROR_NONE; } @@ -869,22 +873,22 @@ SO_EXPORT int context_trigger_rule_entry_add_comparison(context_trigger_rule_ent } std::string name; - (entry->jentry).get(NULL, CT_RULE_CONDITION_ITEM, &name); + (entry->jentry).get(NULL, TRIG_RULE_CONDITION_ITEM, &name); // Err: Check if key is valid - bool ret = ctx::rule_validator::check_valid_key(TYPE_ATTR_STR, name, key); + bool ret = ctx::rule_validator::check_valid_key(TYPE_ATTRIBUTE, name, key); IF_FAIL_RETURN(ret, CONTEXT_TRIGGER_ERROR_INVALID_RULE); // Err: Invalid operator - std::string type = ctx::rule_validator::get_data_type_from_template(TYPE_ATTR_STR, name, key); + std::string type = ctx::rule_validator::get_data_type_from_template(TYPE_ATTRIBUTE, name, key); ret = ctx::rule_validator::is_valid_operator(type, op); IF_FAIL_RETURN(ret, CONTEXT_TRIGGER_ERROR_INVALID_RULE); - int error = context_trigger_rule_entry_add_comparison_string_internal(entry, key, op, EVENT_DATA_KEY_PREFIX_STR + std::string(event_data_key)); + int error = context_trigger_rule_entry_add_comparison_string_internal(entry, key, op, std::string(TRIG_RULE_REF_KEY_PREFIX) + std::string(event_data_key)); IF_FAIL_RETURN(error == ERR_NONE, error); // Set reference information - ret = ctx::rule_validator::set_ref_info(TYPE_ATTR_STR, &(entry->jref), name, key, event_data_key); + ret = ctx::rule_validator::set_ref_info(TYPE_ATTRIBUTE, &(entry->jref), name, key, event_data_key); IF_FAIL_RETURN(ret, CONTEXT_TRIGGER_ERROR_OPERATION_FAILED); return CONTEXT_TRIGGER_ERROR_NONE; @@ -896,7 +900,7 @@ SO_EXPORT int context_trigger_rule_entry_add_comparison_int(context_trigger_rule ASSERT_NOT_NULL(entry && key && op); std::string name; - (entry->jentry).get(NULL, CT_RULE_EVENT_ITEM, &name); + (entry->jentry).get(NULL, TRIG_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); @@ -911,7 +915,7 @@ SO_EXPORT int context_trigger_rule_entry_add_comparison_double(context_trigger_r ASSERT_NOT_NULL(entry && key && op); std::string name; - (entry->jentry).get(NULL, CT_RULE_EVENT_ITEM, &name); + (entry->jentry).get(NULL, TRIG_RULE_EVENT_ITEM, &name); // TODO: check_comparison_double() bool ret = ctx::rule_validator::check_comparison_double(name, key, op, value); @@ -927,7 +931,7 @@ SO_EXPORT int context_trigger_rule_entry_add_comparison_string(context_trigger_r ASSERT_NOT_NULL(entry && key && op && value); std::string name; - (entry->jentry).get(NULL, CT_RULE_EVENT_ITEM, &name); + (entry->jentry).get(NULL, TRIG_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); @@ -950,11 +954,11 @@ SO_EXPORT int context_trigger_custom_register(const char* name, const char* attr IF_FAIL_RETURN_TAG(ret, CONTEXT_TRIGGER_ERROR_INVALID_DATA, _E, "Invalid template"); ctx::Json data; - data.set(NULL, CT_CUSTOM_REQ, CT_CUSTOM_ADD); - data.set(NULL, CT_CUSTOM_NAME, name); - data.set(NULL, CT_CUSTOM_ATTRIBUTES, jattr_template); + data.set(NULL, TRIG_CUSTOM_KEY_REQ, TRIG_CUSTOM_REQ_ADD); + data.set(NULL, TRIG_CUSTOM_KEY_NAME, name); + data.set(NULL, TRIG_TMPL_KEY_ATTRIBUTE, jattr_template); - int error = __dbusClient.write(CONTEXT_TRIGGER_SUBJECT_CUSTOM, data, NULL); + int error = __dbusClient.write(SUBJ_TRIGGER_CUSTOM, data, NULL); IF_FAIL_RETURN_TAG(error == ERR_NONE, error, _E, "Failed to add custom item: %#x", error); return error; @@ -966,15 +970,15 @@ SO_EXPORT int context_trigger_custom_unregister(const char* name) ASSERT_NOT_NULL(name); ctx::Json data; - data.set(NULL, CT_CUSTOM_REQ, CT_CUSTOM_REMOVE); - data.set(NULL, CT_CUSTOM_NAME, name); + data.set(NULL, TRIG_CUSTOM_KEY_REQ, TRIG_CUSTOM_REQ_REMOVE); + data.set(NULL, TRIG_CUSTOM_KEY_NAME, name); ctx::Json subj; - int error = __dbusClient.write(CONTEXT_TRIGGER_SUBJECT_CUSTOM, data, &subj); + int error = __dbusClient.write(SUBJ_TRIGGER_CUSTOM, data, &subj); IF_FAIL_RETURN_TAG(error == ERR_NONE, error, _E, "Failed to remove custom item: %#x", error); std::string subject; - subj.get(NULL, CT_CUSTOM_SUBJECT, &subject); + subj.get(NULL, TRIG_TMPL_KEY_SUBJECT, &subject); ctx::rule_validator::remove_template(subject); return error; @@ -990,11 +994,11 @@ SO_EXPORT int context_trigger_custom_publish(const char* name, const char* fact) IF_FAIL_RETURN_TAG(jfact.valid(), CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER, _E, "Cannot parse fact Json"); ctx::Json data; - data.set(NULL, CT_CUSTOM_REQ, CT_CUSTOM_PUBLISH); - data.set(NULL, CT_CUSTOM_NAME, name); - data.set(NULL, CT_CUSTOM_FACT, jfact); + data.set(NULL, TRIG_CUSTOM_KEY_REQ, TRIG_CUSTOM_REQ_PUBLISH); + data.set(NULL, TRIG_CUSTOM_KEY_NAME, name); + data.set(NULL, TRIG_CUSTOM_KEY_FACT, jfact); - int error = __dbusClient.write(CONTEXT_TRIGGER_SUBJECT_CUSTOM, data, NULL); + int error = __dbusClient.write(SUBJ_TRIGGER_CUSTOM, data, NULL); IF_FAIL_RETURN_TAG(error == ERR_NONE, error, _E, "Failed to publish custom data"); return error; @@ -1005,55 +1009,55 @@ 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; + str = SUBJ_STATE_ALARM; break; case CONTEXT_TRIGGER_EVENT_BATTERY: - str = CT_EVENT_BATTERY; + str = SUBJ_STATE_BATTERY; break; case CONTEXT_TRIGGER_EVENT_CHARGER: - str = CT_EVENT_CHARGER; + str = SUBJ_STATE_CHARGER; break; case CONTEXT_TRIGGER_EVENT_GPS: - str = CT_EVENT_GPS; + str = SUBJ_STATE_GPS; break; case CONTEXT_TRIGGER_EVENT_HEADPHONE: - str = CT_EVENT_HEADPHONE; + str = SUBJ_STATE_HEADPHONE; break; case CONTEXT_TRIGGER_EVENT_POWER_SAVING_MODE: - str = CT_EVENT_POWER_SAVING_MODE; + str = SUBJ_STATE_PSMODE; break; case CONTEXT_TRIGGER_EVENT_USB: - str = CT_EVENT_USB; + str = SUBJ_STATE_USB; break; case CONTEXT_TRIGGER_EVENT_WIFI: - str = CT_EVENT_WIFI; + str = SUBJ_STATE_WIFI; break; case CONTEXT_TRIGGER_EVENT_CALL: - str = CT_EVENT_CALL; + str = SUBJ_STATE_CALL; break; case CONTEXT_TRIGGER_EVENT_EMAIL: - str = CT_EVENT_EMAIL; + str = SUBJ_STATE_EMAIL; break; case CONTEXT_TRIGGER_EVENT_MESSAGE: - str = CT_EVENT_MESSAGE; + str = SUBJ_STATE_MESSAGE; break; case CONTEXT_TRIGGER_EVENT_CONTACTS: - str = CT_EVENT_CONTACTS; + str = SUBJ_STATE_CONTACTS; break; case CONTEXT_TRIGGER_EVENT_ACTIVITY_STATIONARY: - str = CT_EVENT_ACTIVITY_STATIONARY; + str = SUBJ_ACTIVITY_STATIONARY; break; case CONTEXT_TRIGGER_EVENT_ACTIVITY_WALKING: - str = CT_EVENT_ACTIVITY_WALKING; + str = SUBJ_ACTIVITY_WALKING; break; case CONTEXT_TRIGGER_EVENT_ACTIVITY_RUNNING: - str = CT_EVENT_ACTIVITY_RUNNING; + str = SUBJ_ACTIVITY_RUNNING; break; case CONTEXT_TRIGGER_EVENT_ACTIVITY_IN_VEHICLE: - str = CT_EVENT_ACTIVITY_IN_VEHICLE; + str = SUBJ_ACTIVITY_IN_VEHICLE; break; case CONTEXT_TRIGGER_EVENT_PLACE: - str = CT_EVENT_PLACE; + str = SUBJ_PLACE_GEOFENCE; break; default: break; @@ -1066,43 +1070,43 @@ 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; + str = SUBJ_STATE_TIME; break; case CONTEXT_TRIGGER_CONDITION_BATTERY: - str = CT_CONDITION_BATTERY; + str = SUBJ_STATE_BATTERY; break; case CONTEXT_TRIGGER_CONDITION_CHARGER: - str = CT_CONDITION_CHARGER; + str = SUBJ_STATE_CHARGER; break; case CONTEXT_TRIGGER_CONDITION_GPS: - str = CT_CONDITION_GPS; + str = SUBJ_STATE_GPS; break; case CONTEXT_TRIGGER_CONDITION_HEADPHONE: - str = CT_CONDITION_HEADPHONE; + str = SUBJ_STATE_HEADPHONE; break; case CONTEXT_TRIGGER_CONDITION_POWER_SAVING_MODE: - str = CT_CONDITION_POWER_SAVING_MODE; + str = SUBJ_STATE_PSMODE; break; case CONTEXT_TRIGGER_CONDITION_USB: - str = CT_CONDITION_USB; + str = SUBJ_STATE_USB; break; case CONTEXT_TRIGGER_CONDITION_WIFI: - str = CT_CONDITION_WIFI; + str = SUBJ_STATE_WIFI; break; case CONTEXT_TRIGGER_CONDITION_CALL: - str = CT_CONDITION_CALL; + str = SUBJ_STATE_CALL; break; case CONTEXT_TRIGGER_CONDITION_APP_USE_FREQUENCY: - str = CT_CONDITION_APP_USE_FREQUENCY; + str = SUBJ_APP_FREQUENCY; break; case CONTEXT_TRIGGER_CONDITION_COMMUNICATION_FREQUENCY: - str = CT_CONDITION_COMMUNICATION_FREQUENCY; + str = SUBJ_SOCIAL_FREQUENCY; break; case CONTEXT_TRIGGER_CONDITION_MUSIC_PLAYBACK_FREQUENCY: - str = CT_CONDITION_MUSIC_PLAYBACK_FREQUENCY; + str = SUBJ_MUSIC_FREQUENCY; break; case CONTEXT_TRIGGER_CONDITION_VIDEO_PLAYBACK_FREQUENCY: - str = CT_CONDITION_VIDEO_PLAYBACK_FREQUENCY; + str = SUBJ_VIDEO_FREQUENCY; break; default: break; @@ -1115,10 +1119,10 @@ std::string convert_logical_type_to_string(context_trigger_logical_type_e logica std::string str; switch (logical_type) { case CONTEXT_TRIGGER_LOGICAL_CONJUNCTION: - str = "and"; + str = TRIG_RULE_LOGICAL_CONJUNCTION; break; case CONTEXT_TRIGGER_LOGICAL_DISJUNCTION: - str = "or"; + str = TRIG_RULE_LOGICAL_CONJUNCTION; break; default: break; @@ -1128,7 +1132,7 @@ std::string convert_logical_type_to_string(context_trigger_logical_type_e logica std::string get_custom_item_subject(const char* provider, const char* item) { - std::string subject_name = CT_CUSTOM + std::string("/") + provider + std::string("/") + item; + std::string subject_name = std::string(TRIG_CUSTOM_PREFIX TRIG_SUBJECT_SEPERATOR) + provider + std::string(TRIG_SUBJECT_SEPERATOR) + item; return subject_name; } diff --git a/src/rule_validator.cpp b/src/rule_validator.cpp index fd0aa9e..f2dd096 100644 --- a/src/rule_validator.cpp +++ b/src/rule_validator.cpp @@ -19,12 +19,13 @@ #include #include #include -#include +#include +#include #include "DBusClient.h" #include "rule_validator.h" -#define KEY_KEY "key" -#define KEY_REF "ref" +#define RV_KEY_KEY "key" +#define RV_KEY_REF "ref" typedef std::map template_map_t; template_map_t template_map; // @@ -66,12 +67,12 @@ int ctx::rule_validator::request_template(std::string name, bool mandatory) // Request template ctx::Json request; - request.set(NULL, SUBJECT_STR, name); + request.set(NULL, TRIG_TMPL_KEY_SUBJECT, name); int req_id; ctx::Json tmpl; ctx::DBusClient dbusClient; - int error = dbusClient.readSync(CONTEXT_TRIGGER_SUBJECT_GET_TEMPLATE, request, &req_id, &tmpl); + int error = dbusClient.readSync(SUBJ_TRIGGER_GET_TEMPLATE, request, &req_id, &tmpl); if (error == ERR_NOT_SUPPORTED) { template_map.erase(name); _E("Failed to get request: not supported"); @@ -93,14 +94,14 @@ void ctx::rule_validator::remove_template(std::string name) bool ctx::rule_validator::check_option(ctx::Json& item) { std::string name; - item.get(NULL, CT_RULE_EVENT_ITEM, &name); + item.get(NULL, TRIG_RULE_EVENT_ITEM, &name); ctx::Json tmpl = get_template(name); IF_FAIL_RETURN(tmpl != EMPTY_JSON_OBJECT, false); // No option needed ctx::Json opt_tmpl; - tmpl.get(NULL, TYPE_OPTION_STR, &opt_tmpl); + tmpl.get(NULL, TRIG_TMPL_KEY_OPTION, &opt_tmpl); std::list opt_keys; IF_FAIL_RETURN(opt_tmpl.getKeys(&opt_keys), false); @@ -111,14 +112,14 @@ bool ctx::rule_validator::check_option(ctx::Json& item) // Err: Check if mandatory option is missed std::string val_str; int val; - if (name == CT_EVENT_PLACE) { - if (!(item.get(CT_RULE_EVENT_OPTION, CONTEXT_TRIGGER_PLACE_ID, &val))) + if (name == SUBJ_PLACE_GEOFENCE) { + if (!(item.get(TRIG_RULE_EVENT_OPTION, CONTEXT_TRIGGER_PLACE_ID, &val))) return false; - } else if (name == CT_CONDITION_APP_USE_FREQUENCY) { - if (!(item.get(CT_RULE_CONDITION_OPTION, CONTEXT_TRIGGER_APP_ID, &val_str))) + } else if (name == SUBJ_APP_FREQUENCY) { + if (!(item.get(TRIG_RULE_CONDITION_OPTION, CONTEXT_TRIGGER_APP_ID, &val_str))) return false; - } else if (name == CT_CONDITION_COMMUNICATION_FREQUENCY) { - if (!(item.get(CT_RULE_CONDITION_OPTION, CONTEXT_TRIGGER_ADDRESS, &val_str))) + } else if (name == SUBJ_SOCIAL_FREQUENCY) { + if (!(item.get(TRIG_RULE_CONDITION_OPTION, CONTEXT_TRIGGER_ADDRESS, &val_str))) return false; } @@ -132,7 +133,7 @@ bool ctx::rule_validator::check_option_int(std::string name, std::string key, in IF_FAIL_RETURN(tmpl != EMPTY_JSON_OBJECT, false); ctx::Json opt_tmpl; - tmpl.get(NULL, TYPE_OPTION_STR, &opt_tmpl); + tmpl.get(NULL, TRIG_TMPL_KEY_OPTION, &opt_tmpl); // Err: Item with no option std::list opt_keys; @@ -141,7 +142,7 @@ bool ctx::rule_validator::check_option_int(std::string name, std::string key, in // Err: Invalid option key or Invalid value type std::string t_type = get_data_type(opt_tmpl, key); - IF_FAIL_RETURN(t_type == TYPE_INT_STR, false); + IF_FAIL_RETURN(t_type == TRIG_TMPL_TYPE_INTEGER, false); // Err: Inappropriate value // a. normal case @@ -158,7 +159,7 @@ bool ctx::rule_validator::check_option_string(std::string name, std::string key, IF_FAIL_RETURN(tmpl != EMPTY_JSON_OBJECT, false); ctx::Json opt_tmpl; - tmpl.get(NULL, TYPE_OPTION_STR, &opt_tmpl); + tmpl.get(NULL, TRIG_TMPL_KEY_OPTION, &opt_tmpl); // Err: ';' for SQL injection IF_FAIL_RETURN(value.find(';') == std::string::npos, false); @@ -170,12 +171,12 @@ bool ctx::rule_validator::check_option_string(std::string name, std::string key, // Err: Invalid option key or Invalid value type std::string t_type = get_data_type(opt_tmpl, key); - IF_FAIL_RETURN(t_type == TYPE_STRING_STR || t_type == TYPE_ENUM_STR, false); + IF_FAIL_RETURN(t_type == TRIG_TMPL_TYPE_STRING || t_type == TRIG_TMPL_TYPE_ENUM, false); // Err: Inappropriate value // a. spacial case - if (t_type == TYPE_STRING_STR && (name == CT_CONDITION_APP_USE_FREQUENCY || name == CT_CONDITION_COMMUNICATION_FREQUENCY - || name == CT_CONDITION_MUSIC_PLAYBACK_FREQUENCY || name == CT_CONDITION_VIDEO_PLAYBACK_FREQUENCY) + if (t_type == TRIG_TMPL_TYPE_STRING && (name == SUBJ_APP_FREQUENCY || name == SUBJ_SOCIAL_FREQUENCY + || name == SUBJ_MUSIC_FREQUENCY || name == SUBJ_VIDEO_FREQUENCY) && key == CONTEXT_TRIGGER_TIME_OF_DAY) { std::size_t found = value.find("-"); if (found == std::string::npos) { @@ -198,9 +199,9 @@ bool ctx::rule_validator::check_option_string(std::string name, std::string key, // b. normal case bool ret = false; - if (t_type == TYPE_STRING_STR) { + if (t_type == TRIG_TMPL_TYPE_STRING) { ret = check_value_string(opt_tmpl, key, value); - } else if (t_type == TYPE_ENUM_STR) { + } else if (t_type == TRIG_TMPL_TYPE_ENUM) { ret = check_value_enum(opt_tmpl, key, value); } @@ -214,18 +215,18 @@ bool ctx::rule_validator::check_comparison_int(std::string name, std::string key IF_FAIL_RETURN(tmpl != EMPTY_JSON_OBJECT, false); ctx::Json attr_tmpl; - tmpl.get(NULL, TYPE_ATTR_STR, &attr_tmpl); + tmpl.get(NULL, TRIG_TMPL_KEY_ATTRIBUTE, &attr_tmpl); // Err: Invalid attribute key or Invalid value type std::string t_type = get_data_type(attr_tmpl, key); - IF_FAIL_RETURN(t_type == TYPE_INT_STR, false); + IF_FAIL_RETURN(t_type == TRIG_TMPL_TYPE_INTEGER, false); // Err: Invalid operator for the value // a. normal case - bool ret = is_valid_operator(TYPE_INT_STR, op); + bool ret = is_valid_operator(TRIG_TMPL_TYPE_INTEGER, op); IF_FAIL_RETURN(ret, false); // b. special case - if (name == CT_EVENT_TIME && key == CONTEXT_TRIGGER_TIME_OF_DAY) { + if (name == SUBJ_STATE_ALARM && key == CONTEXT_TRIGGER_TIME_OF_DAY) { IF_FAIL_RETURN(op == CONTEXT_TRIGGER_EQUAL_TO, false); } @@ -244,14 +245,14 @@ bool ctx::rule_validator::check_comparison_string(std::string name, std::string IF_FAIL_RETURN(tmpl != ctx::Json(EMPTY_JSON_OBJECT), false); ctx::Json attr_tmpl; - tmpl.get(NULL, TYPE_ATTR_STR, &attr_tmpl); + tmpl.get(NULL, TRIG_TMPL_KEY_ATTRIBUTE, &attr_tmpl); // Err: ';' for SQL injection IF_FAIL_RETURN(value.find(';') == std::string::npos, false); // Err: Invalid option key or Invalid value type std::string t_type = get_data_type(attr_tmpl, key); - IF_FAIL_RETURN(t_type == TYPE_STRING_STR || t_type == TYPE_ENUM_STR, false); + IF_FAIL_RETURN(t_type == TRIG_TMPL_TYPE_STRING || t_type == TRIG_TMPL_TYPE_ENUM, false); // Err: Invalid operator for the value bool ret = is_valid_operator(t_type, op); @@ -259,10 +260,10 @@ bool ctx::rule_validator::check_comparison_string(std::string name, std::string // Err: Inappropriate value // a. normal case - if (t_type == TYPE_STRING_STR) { + if (t_type == TRIG_TMPL_TYPE_STRING) { ret = check_value_string(attr_tmpl, key, value); IF_FAIL_RETURN(ret, false); - } else if (t_type == TYPE_ENUM_STR) { + } else if (t_type == TRIG_TMPL_TYPE_ENUM) { ret = check_value_enum(attr_tmpl, key, value); IF_FAIL_RETURN(ret, false); } @@ -287,11 +288,11 @@ bool check_value_int(ctx::Json& tmpl, std::string key, int value) { int min, max; - if (tmpl.get(key.c_str(), CT_CUSTOM_MIN, &min)) { + if (tmpl.get(key.c_str(), TRIG_TMPL_KEY_MIN, &min)) { IF_FAIL_RETURN(value >= min, false); } - if (tmpl.get(key.c_str(), CT_CUSTOM_MAX, &max)) { + if (tmpl.get(key.c_str(), TRIG_TMPL_KEY_MAX, &max)) { IF_FAIL_RETURN(value <= max, false); } @@ -306,7 +307,7 @@ bool check_value_string(ctx::Json& tmpl, std::string key, std::string value) bool check_value_enum(ctx::Json& tmpl, std::string key, std::string value) { std::string t_val; - for (int i = 0; tmpl.getAt(key.c_str(), CT_CUSTOM_ENUM, i, &t_val); i++) { + for (int i = 0; tmpl.getAt(key.c_str(), TRIG_TMPL_TYPE_ENUM, i, &t_val); i++) { if (t_val == value) return true; } @@ -325,18 +326,18 @@ bool ctx::rule_validator::set_ref_info(std::string type, ctx::Json* jref, std::s tmpl.get(NULL, type.c_str(), &detailed_tmpl); std::string dt = get_data_type(detailed_tmpl, key); - IF_FAIL_RETURN(dt == TYPE_INT_STR || dt == TYPE_STRING_STR || dt == TYPE_ENUM_STR, false); + IF_FAIL_RETURN(dt == TRIG_TMPL_TYPE_INTEGER || dt == TRIG_TMPL_TYPE_STRING || dt == TRIG_TMPL_TYPE_ENUM, false); ctx::Json temp; - temp.set(NULL, CT_CUSTOM_NAME, name); - temp.set(NULL, KEY_KEY, key); - temp.set(NULL, CT_CUSTOM_TYPE, dt); - temp.set(NULL, KEY_REF, ref_data); - - if (type == TYPE_OPTION_STR) { - jref->append(NULL, TYPE_OPTION_STR, temp); - } else if (type == TYPE_ATTR_STR) { - jref->append(NULL, TYPE_ATTR_STR, temp); + temp.set(NULL, TRIG_CUSTOM_KEY_NAME, name); + temp.set(NULL, RV_KEY_KEY, key); + temp.set(NULL, TRIG_TMPL_KEY_TYPE, dt); + temp.set(NULL, RV_KEY_REF, ref_data); + + if (type == TRIG_TMPL_KEY_OPTION) { + jref->append(NULL, TRIG_TMPL_KEY_OPTION, temp); + } else if (type == TRIG_TMPL_KEY_ATTRIBUTE) { + jref->append(NULL, TRIG_TMPL_KEY_ATTRIBUTE, temp); } else { return false; } @@ -347,13 +348,13 @@ bool ctx::rule_validator::set_ref_info(std::string type, ctx::Json* jref, std::s std::string get_data_type(ctx::Json& elem, std::string& key) { std::string data_type; - bool ret = elem.get(key.c_str(), CT_CUSTOM_TYPE, &data_type); + bool ret = elem.get(key.c_str(), TRIG_TMPL_KEY_TYPE, &data_type); if (!ret) { - int size = elem.getSize(key.c_str(), CT_CUSTOM_ENUM); + int size = elem.getSize(key.c_str(), TRIG_TMPL_TYPE_ENUM); IF_FAIL_RETURN(size > 0, ""); - data_type = TYPE_ENUM_STR; + data_type = TRIG_TMPL_TYPE_ENUM; } - IF_FAIL_RETURN(data_type == TYPE_INT_STR || data_type == TYPE_STRING_STR || data_type == TYPE_ENUM_STR, ""); + IF_FAIL_RETURN(data_type == TRIG_TMPL_TYPE_INTEGER || data_type == TRIG_TMPL_TYPE_STRING || data_type == TRIG_TMPL_TYPE_ENUM, ""); return data_type; } @@ -376,28 +377,28 @@ bool ctx::rule_validator::check_referential_data(std::string name, ctx::Json& re std::map type_map; ctx::Json ref_data; - for (int i = 0; ref_info.getAt(NULL, TYPE_OPTION_STR, i, &ref_data); i++) { + for (int i = 0; ref_info.getAt(NULL, TRIG_TMPL_KEY_OPTION, i, &ref_data); i++) { std::string ref_key; - ref_data.get(NULL, KEY_REF, &ref_key); + ref_data.get(NULL, RV_KEY_REF, &ref_key); std::string cond_type; - ref_data.get(NULL, CT_CUSTOM_TYPE, &cond_type); + ref_data.get(NULL, TRIG_TMPL_KEY_TYPE, &cond_type); if (type_map.count(ref_key) == 0) { - type_map[ref_key] = get_data_type_from_template(TYPE_ATTR_STR, name, ref_key); // "", if invalid key + type_map[ref_key] = get_data_type_from_template(TRIG_TMPL_KEY_ATTRIBUTE, name, ref_key); // "", if invalid key } // Err: Invalid key or Value type not matched IF_FAIL_RETURN(is_equal_type(cond_type, type_map[ref_key]), false); } - for (int i = 0; ref_info.getAt(NULL, TYPE_ATTR_STR, i, &ref_data); i++) { + for (int i = 0; ref_info.getAt(NULL, TRIG_TMPL_KEY_ATTRIBUTE, i, &ref_data); i++) { std::string ref_key; - ref_data.get(NULL, KEY_REF, &ref_key); + ref_data.get(NULL, RV_KEY_REF, &ref_key); std::string cond_type; - ref_data.get(NULL, CT_CUSTOM_TYPE, &cond_type); + ref_data.get(NULL, TRIG_TMPL_KEY_TYPE, &cond_type); if (type_map.count(ref_key) == 0) { - type_map[ref_key] = get_data_type_from_template(TYPE_ATTR_STR, name, ref_key); // "", if invalid key + type_map[ref_key] = get_data_type_from_template(TRIG_TMPL_KEY_ATTRIBUTE, name, ref_key); // "", if invalid key } // Err: Invalid key or Value type not matched @@ -409,12 +410,12 @@ bool ctx::rule_validator::check_referential_data(std::string name, ctx::Json& re bool is_equal_type(std::string& type1, std::string& type2) { - // This function regards TYPE_ENUM_STR as TYPE_STRING_STR for referential data + // This function regards TRIG_TMPL_TYPE_ENUM as TRIG_TMPL_TYPE_STRING for referential data if (type1 == type2) { return true; } - if ((type1 == TYPE_STRING_STR || type1 == TYPE_ENUM_STR) && (type2 == TYPE_STRING_STR || type2 == TYPE_ENUM_STR)) { + if ((type1 == TRIG_TMPL_TYPE_STRING || type1 == TRIG_TMPL_TYPE_ENUM) && (type2 == TRIG_TMPL_TYPE_STRING || type2 == TRIG_TMPL_TYPE_ENUM)) { return true; } @@ -427,7 +428,7 @@ bool ctx::rule_validator::is_valid_operator(std::string type, std::string op) return true; } - if (type == TYPE_INT_STR || type == TYPE_DOUBLE_STR) { + if (type == TRIG_TMPL_TYPE_INTEGER || type == TRIG_TMPL_TYPE_DOUBLE) { if (op == CONTEXT_TRIGGER_GREATER_THAN || op == CONTEXT_TRIGGER_GREATER_THAN_OR_EQUAL_TO || op == CONTEXT_TRIGGER_LESS_THAN || op == CONTEXT_TRIGGER_LESS_THAN_OR_EQUAL_TO) { return true; @@ -450,18 +451,18 @@ bool ctx::rule_validator::is_valid_template(ctx::Json& attr_template) std::string key = *it; std::string type = get_data_type(attr_template, key); - IF_FAIL_RETURN_TAG(type == CT_CUSTOM_INT || type == CT_CUSTOM_STRING || type == CT_CUSTOM_ENUM, + IF_FAIL_RETURN_TAG(type == TRIG_TMPL_TYPE_INTEGER || type == TRIG_TMPL_TYPE_STRING || type == TRIG_TMPL_TYPE_ENUM, false, _E, "Custom template: invalid data type"); ctx::Json elem; attr_template.get(NULL, key.c_str(), &elem); - if (type == CT_CUSTOM_INT) { + if (type == TRIG_TMPL_TYPE_INTEGER) { ret = check_template_int(elem); IF_FAIL_RETURN(ret, false); - } else if (type == CT_CUSTOM_STRING) { + } else if (type == TRIG_TMPL_TYPE_STRING) { ret = check_template_string(elem); IF_FAIL_RETURN(ret, false); - } else if (type == CT_CUSTOM_ENUM) { + } else if (type == TRIG_TMPL_TYPE_ENUM) { ret = check_template_enum(elem); IF_FAIL_RETURN(ret, false); } @@ -482,14 +483,14 @@ bool check_template_int(ctx::Json& elem) for (std::list::iterator it2 = elem_keys.begin(); it2 != elem_keys.end(); it2++) { std::string elem_key = *it2; - if (elem_key == CT_CUSTOM_MIN) { + if (elem_key == TRIG_TMPL_KEY_MIN) { min = elem.get(NULL, elem_key.c_str(), &min_val); IF_FAIL_RETURN_TAG(min, false, _E, "Custom template: failed to get integer type value"); - } else if (elem_key == CT_CUSTOM_MAX) { + } else if (elem_key == TRIG_TMPL_KEY_MAX) { max = elem.get(NULL, elem_key.c_str(), &max_val); IF_FAIL_RETURN_TAG(max, false, _E, "Custom template: failed to get integer type value"); } else { - IF_FAIL_RETURN_TAG(elem_key == CT_CUSTOM_TYPE, false, _E, "Custom template: invalid key"); + IF_FAIL_RETURN_TAG(elem_key == TRIG_TMPL_KEY_TYPE, false, _E, "Custom template: invalid key"); } } @@ -508,7 +509,7 @@ bool check_template_string(ctx::Json& elem) for (std::list::iterator it2 = elem_keys.begin(); it2 != elem_keys.end(); it2++) { std::string elem_key = *it2; _D("SOM TEST >>> elem key (%s)", elem_key.c_str()); - IF_FAIL_RETURN_TAG(elem_key == CT_CUSTOM_TYPE, false, _E, "Custom template: invalid key"); + IF_FAIL_RETURN_TAG(elem_key == TRIG_TMPL_KEY_TYPE, false, _E, "Custom template: invalid key"); } return true; @@ -522,17 +523,17 @@ bool check_template_enum(ctx::Json& elem) for (std::list::iterator it2 = elem_keys.begin(); it2 != elem_keys.end(); it2++) { std::string elem_key = *it2; - if (elem_key == CT_CUSTOM_ENUM) { - int size = elem.getSize(NULL, CT_CUSTOM_ENUM); + if (elem_key == TRIG_TMPL_TYPE_ENUM) { + int size = elem.getSize(NULL, TRIG_TMPL_TYPE_ENUM); IF_FAIL_RETURN_TAG(size > 0, false, _E, "Custom template: invalid enum"); std::string val_str; for (int i = 0; i < size; i++) { - bool ret = elem.getAt(NULL, CT_CUSTOM_ENUM, i, &val_str); + bool ret = elem.getAt(NULL, TRIG_TMPL_TYPE_ENUM, i, &val_str); IF_FAIL_RETURN_TAG(ret, false, _E, "Custom template: failed to get string type value"); } } else { - IF_FAIL_RETURN_TAG(elem_key == CT_CUSTOM_TYPE, false, _E, "Custom template: invalid key"); + IF_FAIL_RETURN_TAG(elem_key == TRIG_TMPL_KEY_TYPE, false, _E, "Custom template: invalid key"); } } diff --git a/testsuite/src/history/history.cpp b/testsuite/src/history/history.cpp index c49401a..41184f2 100644 --- a/testsuite/src/history/history.cpp +++ b/testsuite/src/history/history.cpp @@ -15,7 +15,7 @@ */ #include -#include +#include #include "../shared.h" #include "history.h" @@ -189,12 +189,12 @@ bool _history_app_recently() const char *int_attr[] = {CONTEXT_HISTORY_TOTAL_COUNT, CONTEXT_HISTORY_TOTAL_DURATION, CONTEXT_HISTORY_LAST_TIME, NULL}; const char *str_attr[] = {CONTEXT_HISTORY_APP_ID, NULL}; - __filter_set_int(CONTEXT_HISTORY_FILTER_RESULT_SIZE, FILTER_RESULT_SIZE); - __filter_set_int(CONTEXT_HISTORY_FILTER_TIME_SPAN, FILTER_TIME_SPAN); - __filter_set_int(CONTEXT_HISTORY_FILTER_START_TIME, FILTER_START_TIME); - __filter_set_int(CONTEXT_HISTORY_FILTER_END_TIME, FILTER_END_TIME); - __filter_set_int(CONTEXT_HISTORY_FILTER_AUDIO_JACK, FILTER_AUDIO_JACK); - __filter_set_str(CONTEXT_HISTORY_FILTER_WIFI_BSSID, FILTER_WIFI_BSSID); + __filter_set_int(CONTEXT_HISTORY_FILTER_RESULT_SIZE, KEY_RESULT_SIZE); + __filter_set_int(CONTEXT_HISTORY_FILTER_TIME_SPAN, KEY_TIME_SPAN); + __filter_set_int(CONTEXT_HISTORY_FILTER_START_TIME, KEY_START_TIME); + __filter_set_int(CONTEXT_HISTORY_FILTER_END_TIME, KEY_END_TIME); + __filter_set_int(CONTEXT_HISTORY_FILTER_AUDIO_JACK, KEY_AUDIO_JACK); + __filter_set_str(CONTEXT_HISTORY_FILTER_WIFI_BSSID, KEY_BSSID); bool_val = __get_list(CONTEXT_HISTORY_RECENTLY_USED_APP); IF_FAIL_RETURN(bool_val, false); @@ -210,12 +210,12 @@ bool _history_app_frequently() const char *int_attr[] = {CONTEXT_HISTORY_TOTAL_COUNT, CONTEXT_HISTORY_TOTAL_DURATION, CONTEXT_HISTORY_LAST_TIME, NULL}; const char *str_attr[] = {CONTEXT_HISTORY_APP_ID, NULL}; - __filter_set_int(CONTEXT_HISTORY_FILTER_RESULT_SIZE, FILTER_RESULT_SIZE); - __filter_set_int(CONTEXT_HISTORY_FILTER_TIME_SPAN, FILTER_TIME_SPAN); - __filter_set_int(CONTEXT_HISTORY_FILTER_START_TIME, FILTER_START_TIME); - __filter_set_int(CONTEXT_HISTORY_FILTER_END_TIME, FILTER_END_TIME); - __filter_set_int(CONTEXT_HISTORY_FILTER_AUDIO_JACK, FILTER_AUDIO_JACK); - __filter_set_str(CONTEXT_HISTORY_FILTER_WIFI_BSSID, FILTER_WIFI_BSSID); + __filter_set_int(CONTEXT_HISTORY_FILTER_RESULT_SIZE, KEY_RESULT_SIZE); + __filter_set_int(CONTEXT_HISTORY_FILTER_TIME_SPAN, KEY_TIME_SPAN); + __filter_set_int(CONTEXT_HISTORY_FILTER_START_TIME, KEY_START_TIME); + __filter_set_int(CONTEXT_HISTORY_FILTER_END_TIME, KEY_END_TIME); + __filter_set_int(CONTEXT_HISTORY_FILTER_AUDIO_JACK, KEY_AUDIO_JACK); + __filter_set_str(CONTEXT_HISTORY_FILTER_WIFI_BSSID, KEY_BSSID); bool_val = __get_list(CONTEXT_HISTORY_FREQUENTLY_USED_APP); IF_FAIL_RETURN(bool_val, false); @@ -231,10 +231,10 @@ bool _history_app_rarely() const char *int_attr[] = {CONTEXT_HISTORY_TOTAL_COUNT, CONTEXT_HISTORY_TOTAL_DURATION, CONTEXT_HISTORY_LAST_TIME, NULL}; const char *str_attr[] = {CONTEXT_HISTORY_APP_ID, NULL}; - __filter_set_int(CONTEXT_HISTORY_FILTER_RESULT_SIZE, FILTER_RESULT_SIZE); - __filter_set_int(CONTEXT_HISTORY_FILTER_TIME_SPAN, FILTER_TIME_SPAN); - __filter_set_int(CONTEXT_HISTORY_FILTER_START_TIME, FILTER_START_TIME); - __filter_set_int(CONTEXT_HISTORY_FILTER_END_TIME, FILTER_END_TIME); + __filter_set_int(CONTEXT_HISTORY_FILTER_RESULT_SIZE, KEY_RESULT_SIZE); + __filter_set_int(CONTEXT_HISTORY_FILTER_TIME_SPAN, KEY_TIME_SPAN); + __filter_set_int(CONTEXT_HISTORY_FILTER_START_TIME, KEY_START_TIME); + __filter_set_int(CONTEXT_HISTORY_FILTER_END_TIME, KEY_END_TIME); bool_val = __get_list(CONTEXT_HISTORY_RARELY_USED_APP); IF_FAIL_RETURN(bool_val, false); @@ -250,12 +250,12 @@ bool _history_app_peak_time() const char *int_attr[] = {CONTEXT_HISTORY_HOUR_OF_DAY, CONTEXT_HISTORY_TOTAL_COUNT, NULL}; const char *str_attr[] = {NULL}; - __filter_set_int(CONTEXT_HISTORY_FILTER_RESULT_SIZE, FILTER_RESULT_SIZE); - __filter_set_int(CONTEXT_HISTORY_FILTER_TIME_SPAN, FILTER_TIME_SPAN); - __filter_set_int(CONTEXT_HISTORY_FILTER_START_TIME, FILTER_START_TIME); - __filter_set_int(CONTEXT_HISTORY_FILTER_END_TIME, FILTER_END_TIME); - __filter_set_int(CONTEXT_HISTORY_FILTER_DAY_OF_WEEK, FILTER_DAY_OF_WEEK); - __filter_set_str(CONTEXT_HISTORY_FILTER_APP_ID, FILTER_APP_ID); + __filter_set_int(CONTEXT_HISTORY_FILTER_RESULT_SIZE, KEY_RESULT_SIZE); + __filter_set_int(CONTEXT_HISTORY_FILTER_TIME_SPAN, KEY_TIME_SPAN); + __filter_set_int(CONTEXT_HISTORY_FILTER_START_TIME, KEY_START_TIME); + __filter_set_int(CONTEXT_HISTORY_FILTER_END_TIME, KEY_END_TIME); + __filter_set_int(CONTEXT_HISTORY_FILTER_DAY_OF_WEEK, KEY_DAY_OF_WEEK); + __filter_set_str(CONTEXT_HISTORY_FILTER_APP_ID, KEY_APP_ID); bool_val = __get_list(CONTEXT_HISTORY_PEAK_TIME_FOR_APP); IF_FAIL_RETURN(bool_val, false); @@ -271,10 +271,10 @@ bool _history_app_setting() const char *int_attr[] = {CONTEXT_HISTORY_AUDIO_JACK, CONTEXT_HISTORY_SYSTEM_VOLUME, CONTEXT_HISTORY_MEDIA_VOLUME, NULL}; const char *str_attr[] = {NULL}; - __filter_set_int(CONTEXT_HISTORY_FILTER_TIME_SPAN, FILTER_TIME_SPAN); - __filter_set_int(CONTEXT_HISTORY_FILTER_START_TIME, FILTER_START_TIME); - __filter_set_int(CONTEXT_HISTORY_FILTER_END_TIME, FILTER_END_TIME); - __filter_set_str(CONTEXT_HISTORY_FILTER_APP_ID, FILTER_APP_ID); + __filter_set_int(CONTEXT_HISTORY_FILTER_TIME_SPAN, KEY_TIME_SPAN); + __filter_set_int(CONTEXT_HISTORY_FILTER_START_TIME, KEY_START_TIME); + __filter_set_int(CONTEXT_HISTORY_FILTER_END_TIME, KEY_END_TIME); + __filter_set_str(CONTEXT_HISTORY_FILTER_APP_ID, KEY_APP_ID); bool_val = __get_list(CONTEXT_HISTORY_COMMON_SETTING_FOR_APP); IF_FAIL_RETURN(bool_val, false); @@ -290,11 +290,11 @@ bool _history_music_peak_time() const char *int_attr[] = {CONTEXT_HISTORY_HOUR_OF_DAY, CONTEXT_HISTORY_TOTAL_COUNT, NULL}; const char *str_attr[] = {NULL}; - __filter_set_int(CONTEXT_HISTORY_FILTER_RESULT_SIZE, FILTER_RESULT_SIZE); - __filter_set_int(CONTEXT_HISTORY_FILTER_TIME_SPAN, FILTER_TIME_SPAN); - __filter_set_int(CONTEXT_HISTORY_FILTER_START_TIME, FILTER_START_TIME); - __filter_set_int(CONTEXT_HISTORY_FILTER_END_TIME, FILTER_END_TIME); - __filter_set_int(CONTEXT_HISTORY_FILTER_DAY_OF_WEEK, FILTER_DAY_OF_WEEK); + __filter_set_int(CONTEXT_HISTORY_FILTER_RESULT_SIZE, KEY_RESULT_SIZE); + __filter_set_int(CONTEXT_HISTORY_FILTER_TIME_SPAN, KEY_TIME_SPAN); + __filter_set_int(CONTEXT_HISTORY_FILTER_START_TIME, KEY_START_TIME); + __filter_set_int(CONTEXT_HISTORY_FILTER_END_TIME, KEY_END_TIME); + __filter_set_int(CONTEXT_HISTORY_FILTER_DAY_OF_WEEK, KEY_DAY_OF_WEEK); bool_val = __get_list(CONTEXT_HISTORY_PEAK_TIME_FOR_MUSIC); IF_FAIL_RETURN(bool_val, false); @@ -310,9 +310,9 @@ bool _history_music_setting() const char *int_attr[] = {CONTEXT_HISTORY_AUDIO_JACK, CONTEXT_HISTORY_SYSTEM_VOLUME, CONTEXT_HISTORY_MEDIA_VOLUME, NULL}; const char *str_attr[] = {NULL}; - __filter_set_int(CONTEXT_HISTORY_FILTER_TIME_SPAN, FILTER_TIME_SPAN); - __filter_set_int(CONTEXT_HISTORY_FILTER_START_TIME, FILTER_START_TIME); - __filter_set_int(CONTEXT_HISTORY_FILTER_END_TIME, FILTER_END_TIME); + __filter_set_int(CONTEXT_HISTORY_FILTER_TIME_SPAN, KEY_TIME_SPAN); + __filter_set_int(CONTEXT_HISTORY_FILTER_START_TIME, KEY_START_TIME); + __filter_set_int(CONTEXT_HISTORY_FILTER_END_TIME, KEY_END_TIME); bool_val = __get_list(CONTEXT_HISTORY_COMMON_SETTING_FOR_MUSIC); IF_FAIL_RETURN(bool_val, false); @@ -328,11 +328,11 @@ bool _history_video_peak_time() const char *int_attr[] = {CONTEXT_HISTORY_HOUR_OF_DAY, CONTEXT_HISTORY_TOTAL_COUNT, NULL}; const char *str_attr[] = {NULL}; - __filter_set_int(CONTEXT_HISTORY_FILTER_RESULT_SIZE, FILTER_RESULT_SIZE); - __filter_set_int(CONTEXT_HISTORY_FILTER_TIME_SPAN, FILTER_TIME_SPAN); - __filter_set_int(CONTEXT_HISTORY_FILTER_START_TIME, FILTER_START_TIME); - __filter_set_int(CONTEXT_HISTORY_FILTER_END_TIME, FILTER_END_TIME); - __filter_set_int(CONTEXT_HISTORY_FILTER_DAY_OF_WEEK, FILTER_DAY_OF_WEEK); + __filter_set_int(CONTEXT_HISTORY_FILTER_RESULT_SIZE, KEY_RESULT_SIZE); + __filter_set_int(CONTEXT_HISTORY_FILTER_TIME_SPAN, KEY_TIME_SPAN); + __filter_set_int(CONTEXT_HISTORY_FILTER_START_TIME, KEY_START_TIME); + __filter_set_int(CONTEXT_HISTORY_FILTER_END_TIME, KEY_END_TIME); + __filter_set_int(CONTEXT_HISTORY_FILTER_DAY_OF_WEEK, KEY_DAY_OF_WEEK); bool_val = __get_list(CONTEXT_HISTORY_PEAK_TIME_FOR_VIDEO); IF_FAIL_RETURN(bool_val, false); @@ -348,9 +348,9 @@ bool _history_video_setting() const char *int_attr[] = {CONTEXT_HISTORY_AUDIO_JACK, CONTEXT_HISTORY_SYSTEM_VOLUME, CONTEXT_HISTORY_MEDIA_VOLUME, NULL}; const char *str_attr[] = {NULL}; - __filter_set_int(CONTEXT_HISTORY_FILTER_TIME_SPAN, FILTER_TIME_SPAN); - __filter_set_int(CONTEXT_HISTORY_FILTER_START_TIME, FILTER_START_TIME); - __filter_set_int(CONTEXT_HISTORY_FILTER_END_TIME, FILTER_END_TIME); + __filter_set_int(CONTEXT_HISTORY_FILTER_TIME_SPAN, KEY_TIME_SPAN); + __filter_set_int(CONTEXT_HISTORY_FILTER_START_TIME, KEY_START_TIME); + __filter_set_int(CONTEXT_HISTORY_FILTER_END_TIME, KEY_END_TIME); bool_val = __get_list(CONTEXT_HISTORY_COMMON_SETTING_FOR_VIDEO); IF_FAIL_RETURN(bool_val, false); @@ -366,11 +366,11 @@ bool _history_comm_frequently() const char *int_attr[] = {CONTEXT_HISTORY_TOTAL_COUNT, CONTEXT_HISTORY_TOTAL_DURATION, CONTEXT_HISTORY_LAST_TIME, NULL}; const char *str_attr[] = {CONTEXT_HISTORY_ADDRESS, NULL}; - __filter_set_int(CONTEXT_HISTORY_FILTER_RESULT_SIZE, FILTER_RESULT_SIZE); - __filter_set_int(CONTEXT_HISTORY_FILTER_TIME_SPAN, FILTER_TIME_SPAN); - __filter_set_int(CONTEXT_HISTORY_FILTER_START_TIME, FILTER_START_TIME); - __filter_set_int(CONTEXT_HISTORY_FILTER_END_TIME, FILTER_END_TIME); - __filter_set_int(CONTEXT_HISTORY_FILTER_COMMUNICATION_TYPE, FILTER_COMMUNICATION_TYPE); + __filter_set_int(CONTEXT_HISTORY_FILTER_RESULT_SIZE, KEY_RESULT_SIZE); + __filter_set_int(CONTEXT_HISTORY_FILTER_TIME_SPAN, KEY_TIME_SPAN); + __filter_set_int(CONTEXT_HISTORY_FILTER_START_TIME, KEY_START_TIME); + __filter_set_int(CONTEXT_HISTORY_FILTER_END_TIME, KEY_END_TIME); + __filter_set_int(CONTEXT_HISTORY_FILTER_COMMUNICATION_TYPE, KEY_COMMUNICATION_TYPE); bool_val = __get_list(CONTEXT_HISTORY_FREQUENTLY_COMMUNICATED_ADDRESS); IF_FAIL_RETURN(bool_val, false); diff --git a/testsuite/src/trigger/condition.cpp b/testsuite/src/trigger/condition.cpp index 5ee470f..3efb31a 100644 --- a/testsuite/src/trigger/condition.cpp +++ b/testsuite/src/trigger/condition.cpp @@ -15,8 +15,8 @@ */ #include -#include #include +#include #include "../shared.h" #include "request_handler.h" @@ -76,7 +76,7 @@ bool _trigger_cond_battery() { if (!__support(CONTEXT_TRIGGER_CONDITION_BATTERY)) return false; - err = ctx::request_handler::read_sync(CT_CONDITION_BATTERY, NULL, &req_id, &json_val); + err = ctx::request_handler::read_sync(SUBJ_STATE_BATTERY, NULL, &req_id, &json_val); ASSERT_CMPINT(err, ==, ERR_NONE); ASSERT_CONTAIN_STR(json_val, CONTEXT_TRIGGER_LEVEL); @@ -89,7 +89,7 @@ bool _trigger_cond_charger() { if (!__support(CONTEXT_TRIGGER_CONDITION_CHARGER)) return false; - err = ctx::request_handler::read_sync(CT_CONDITION_CHARGER, NULL, &req_id, &json_val); + err = ctx::request_handler::read_sync(SUBJ_STATE_CHARGER, NULL, &req_id, &json_val); ASSERT_CMPINT(err, ==, ERR_NONE); ASSERT_CONTAIN_INT(json_val, CONTEXT_TRIGGER_IS_CONNECTED); @@ -100,7 +100,7 @@ bool _trigger_cond_gps() { if (!__support(CONTEXT_TRIGGER_CONDITION_GPS)) return false; - err = ctx::request_handler::read_sync(CT_CONDITION_GPS, NULL, &req_id, &json_val); + err = ctx::request_handler::read_sync(SUBJ_STATE_GPS, NULL, &req_id, &json_val); ASSERT_CMPINT(err, ==, ERR_NONE); ASSERT_CONTAIN_STR(json_val, CONTEXT_TRIGGER_STATE); @@ -112,7 +112,7 @@ bool _trigger_cond_headphone() { if (!__support(CONTEXT_TRIGGER_CONDITION_HEADPHONE)) return false; - err = ctx::request_handler::read_sync(CT_CONDITION_HEADPHONE, NULL, &req_id, &json_val); + err = ctx::request_handler::read_sync(SUBJ_STATE_HEADPHONE, NULL, &req_id, &json_val); ASSERT_CMPINT(err, ==, ERR_NONE); ASSERT_CONTAIN_INT(json_val, CONTEXT_TRIGGER_IS_CONNECTED); @@ -127,7 +127,7 @@ bool _trigger_cond_usb() { if (!__support(CONTEXT_TRIGGER_CONDITION_USB)) return false; - err = ctx::request_handler::read_sync(CT_CONDITION_USB, NULL, &req_id, &json_val); + err = ctx::request_handler::read_sync(SUBJ_STATE_USB, NULL, &req_id, &json_val); ASSERT_CMPINT(err, ==, ERR_NONE); ASSERT_CONTAIN_INT(json_val, CONTEXT_TRIGGER_IS_CONNECTED); @@ -139,7 +139,7 @@ bool _trigger_cond_wifi() { if (!__support(CONTEXT_TRIGGER_CONDITION_WIFI)) return false; - err = ctx::request_handler::read_sync(CT_CONDITION_WIFI, NULL, &req_id, &json_val); + err = ctx::request_handler::read_sync(SUBJ_STATE_WIFI, NULL, &req_id, &json_val); ASSERT_CMPINT(err, ==, ERR_NONE); ASSERT_CONTAIN_STR(json_val, CONTEXT_TRIGGER_STATE); @@ -154,7 +154,7 @@ bool _trigger_cond_psmode() { if (!__support(CONTEXT_TRIGGER_CONDITION_POWER_SAVING_MODE)) return false; - err = ctx::request_handler::read_sync(CT_CONDITION_POWER_SAVING_MODE, NULL, &req_id, &json_val); + err = ctx::request_handler::read_sync(SUBJ_STATE_PSMODE, NULL, &req_id, &json_val); ASSERT_CMPINT(err, ==, ERR_NONE); ASSERT_CONTAIN_INT(json_val, CONTEXT_TRIGGER_IS_ENABLED); @@ -166,7 +166,7 @@ bool _trigger_cond_call() { if (!__support(CONTEXT_TRIGGER_CONDITION_CALL)) return false; - err = ctx::request_handler::read_sync(CT_CONDITION_CALL, NULL, &req_id, &json_val); + err = ctx::request_handler::read_sync(SUBJ_STATE_CALL, NULL, &req_id, &json_val); ASSERT_CMPINT(err, ==, ERR_NONE); ASSERT_CONTAIN_STR(json_val, CONTEXT_TRIGGER_STATE); @@ -182,7 +182,7 @@ bool _trigger_cond_time() { if (!__support(CONTEXT_TRIGGER_CONDITION_TIME)) return false; - err = ctx::request_handler::read_sync(CT_CONDITION_TIME, NULL, &req_id, &json_val); + err = ctx::request_handler::read_sync(SUBJ_STATE_TIME, NULL, &req_id, &json_val); ASSERT_CMPINT(err, ==, ERR_NONE); ASSERT_CONTAIN_INT(json_val, CONTEXT_TRIGGER_TIME_OF_DAY); @@ -236,7 +236,7 @@ static bool __trigger_cond_app_use_freq_base(ctx::Json option) { if (!__support(CONTEXT_TRIGGER_CONDITION_APP_USE_FREQUENCY)) return false; - err = ctx::request_handler::read_sync(CT_CONDITION_APP_USE_FREQUENCY, &option, &req_id, &json_val); + err = ctx::request_handler::read_sync(SUBJ_APP_FREQUENCY, &option, &req_id, &json_val); if (err == ERR_NO_DATA) { g_print(RED("No Data ")); return true; @@ -334,7 +334,7 @@ static bool __trigger_cond_comm_freq_base(ctx::Json option) { if (!__support(CONTEXT_TRIGGER_CONDITION_COMMUNICATION_FREQUENCY)) return false; - err = ctx::request_handler::read_sync(CT_CONDITION_COMMUNICATION_FREQUENCY, &option, &req_id, &json_val); + err = ctx::request_handler::read_sync(SUBJ_SOCIAL_FREQUENCY, &option, &req_id, &json_val); if (err == ERR_NO_DATA) { g_print(RED("No Data ")); return true; @@ -409,7 +409,7 @@ bool _trigger_cond_music_freq1() return __trigger_cond_media_freq_base( CONTEXT_TRIGGER_CONDITION_MUSIC_PLAYBACK_FREQUENCY, - CT_CONDITION_MUSIC_PLAYBACK_FREQUENCY, option); + SUBJ_MUSIC_FREQUENCY, option); } bool _trigger_cond_music_freq2() @@ -419,7 +419,7 @@ bool _trigger_cond_music_freq2() return __trigger_cond_media_freq_base( CONTEXT_TRIGGER_CONDITION_MUSIC_PLAYBACK_FREQUENCY, - CT_CONDITION_MUSIC_PLAYBACK_FREQUENCY, option); + SUBJ_MUSIC_FREQUENCY, option); } bool _trigger_cond_music_freq3() @@ -429,7 +429,7 @@ bool _trigger_cond_music_freq3() return __trigger_cond_media_freq_base( CONTEXT_TRIGGER_CONDITION_MUSIC_PLAYBACK_FREQUENCY, - CT_CONDITION_MUSIC_PLAYBACK_FREQUENCY, option); + SUBJ_MUSIC_FREQUENCY, option); } bool _trigger_cond_music_freq4() @@ -440,7 +440,7 @@ bool _trigger_cond_music_freq4() return __trigger_cond_media_freq_base( CONTEXT_TRIGGER_CONDITION_MUSIC_PLAYBACK_FREQUENCY, - CT_CONDITION_MUSIC_PLAYBACK_FREQUENCY, option); + SUBJ_MUSIC_FREQUENCY, option); } bool _trigger_cond_video_freq1() @@ -449,7 +449,7 @@ bool _trigger_cond_video_freq1() return __trigger_cond_media_freq_base( CONTEXT_TRIGGER_CONDITION_VIDEO_PLAYBACK_FREQUENCY, - CT_CONDITION_VIDEO_PLAYBACK_FREQUENCY, option); + SUBJ_VIDEO_FREQUENCY, option); } bool _trigger_cond_video_freq2() @@ -459,7 +459,7 @@ bool _trigger_cond_video_freq2() return __trigger_cond_media_freq_base( CONTEXT_TRIGGER_CONDITION_VIDEO_PLAYBACK_FREQUENCY, - CT_CONDITION_VIDEO_PLAYBACK_FREQUENCY, option); + SUBJ_VIDEO_FREQUENCY, option); } bool _trigger_cond_video_freq3() @@ -469,7 +469,7 @@ bool _trigger_cond_video_freq3() return __trigger_cond_media_freq_base( CONTEXT_TRIGGER_CONDITION_VIDEO_PLAYBACK_FREQUENCY, - CT_CONDITION_VIDEO_PLAYBACK_FREQUENCY, option); + SUBJ_VIDEO_FREQUENCY, option); } bool _trigger_cond_video_freq4() @@ -480,5 +480,5 @@ bool _trigger_cond_video_freq4() return __trigger_cond_media_freq_base( CONTEXT_TRIGGER_CONDITION_VIDEO_PLAYBACK_FREQUENCY, - CT_CONDITION_VIDEO_PLAYBACK_FREQUENCY, option); + SUBJ_VIDEO_FREQUENCY, option); } diff --git a/testsuite/src/trigger/event.cpp b/testsuite/src/trigger/event.cpp index 0dee837..a59f564 100644 --- a/testsuite/src/trigger/event.cpp +++ b/testsuite/src/trigger/event.cpp @@ -16,7 +16,7 @@ #include #include -#include +#include #include "../shared.h" #include "request_handler.h" @@ -38,22 +38,22 @@ int test_trigger_event(int *argc, char ***argv) { g_test_init(argc, argv, NULL); - ctx::request_handler::register_callback(CT_EVENT_BATTERY, __domain_cb); - ctx::request_handler::register_callback(CT_EVENT_CHARGER, __domain_cb); - ctx::request_handler::register_callback(CT_EVENT_GPS, __domain_cb); - ctx::request_handler::register_callback(CT_EVENT_HEADPHONE, __domain_cb); - ctx::request_handler::register_callback(CT_EVENT_POWER_SAVING_MODE, __domain_cb); - ctx::request_handler::register_callback(CT_EVENT_USB, __domain_cb); - ctx::request_handler::register_callback(CT_EVENT_WIFI, __domain_cb); - ctx::request_handler::register_callback(CT_EVENT_CALL, __domain_cb); - ctx::request_handler::register_callback(CT_EVENT_TIME, __domain_cb); - ctx::request_handler::register_callback(CT_EVENT_EMAIL, __domain_cb); - ctx::request_handler::register_callback(CT_EVENT_MESSAGE, __domain_cb); - ctx::request_handler::register_callback(CT_EVENT_ACTIVITY_STATIONARY, __domain_cb); - ctx::request_handler::register_callback(CT_EVENT_ACTIVITY_WALKING, __domain_cb); - ctx::request_handler::register_callback(CT_EVENT_ACTIVITY_RUNNING, __domain_cb); - ctx::request_handler::register_callback(CT_EVENT_ACTIVITY_IN_VEHICLE, __domain_cb); - ctx::request_handler::register_callback(CT_EVENT_PLACE, __domain_cb); + ctx::request_handler::register_callback(SUBJ_STATE_BATTERY, __domain_cb); + ctx::request_handler::register_callback(SUBJ_STATE_CHARGER, __domain_cb); + ctx::request_handler::register_callback(SUBJ_STATE_GPS, __domain_cb); + ctx::request_handler::register_callback(SUBJ_STATE_HEADPHONE, __domain_cb); + ctx::request_handler::register_callback(SUBJ_STATE_PSMODE, __domain_cb); + ctx::request_handler::register_callback(SUBJ_STATE_USB, __domain_cb); + ctx::request_handler::register_callback(SUBJ_STATE_WIFI, __domain_cb); + ctx::request_handler::register_callback(SUBJ_STATE_CALL, __domain_cb); + ctx::request_handler::register_callback(SUBJ_STATE_ALARM, __domain_cb); + ctx::request_handler::register_callback(SUBJ_STATE_EMAIL, __domain_cb); + ctx::request_handler::register_callback(SUBJ_STATE_MESSAGE, __domain_cb); + ctx::request_handler::register_callback(SUBJ_ACTIVITY_STATIONARY, __domain_cb); + ctx::request_handler::register_callback(SUBJ_ACTIVITY_WALKING, __domain_cb); + ctx::request_handler::register_callback(SUBJ_ACTIVITY_RUNNING, __domain_cb); + ctx::request_handler::register_callback(SUBJ_ACTIVITY_IN_VEHICLE, __domain_cb); + ctx::request_handler::register_callback(SUBJ_PLACE_GEOFENCE, __domain_cb); run_testcase("/trigger/event/battery", _trigger_event_battery); run_testcase("/trigger/event/charger", _trigger_event_charger); @@ -89,13 +89,13 @@ bool _trigger_event_battery() { if (!__support(CONTEXT_TRIGGER_EVENT_BATTERY)) return false; - err = ctx::request_handler::subscribe(CT_EVENT_BATTERY, NULL, &req_id, NULL); + err = ctx::request_handler::subscribe(SUBJ_STATE_BATTERY, NULL, &req_id, NULL); ASSERT_CMPINT(err, ==, ERR_NONE); g_print("\n> Change the battery lavel (or charging status) %d times.\n", CALLBACK_COUNT); start_mainloop(); - ctx::request_handler::unsubscribe(CT_EVENT_BATTERY, req_id); + ctx::request_handler::unsubscribe(SUBJ_STATE_BATTERY, req_id); ASSERT_CONTAIN_STR(json_val, CONTEXT_TRIGGER_LEVEL); ASSERT_CONTAIN_INT(json_val, CONTEXT_TRIGGER_IS_CHARGING); @@ -107,13 +107,13 @@ bool _trigger_event_charger() { if (!__support(CONTEXT_TRIGGER_EVENT_CHARGER)) return false; - err = ctx::request_handler::subscribe(CT_EVENT_CHARGER, NULL, &req_id, NULL); + err = ctx::request_handler::subscribe(SUBJ_STATE_CHARGER, NULL, &req_id, NULL); ASSERT_CMPINT(err, ==, ERR_NONE); g_print("\n> Change the charger connection state %d times.\n", CALLBACK_COUNT); start_mainloop(); - ctx::request_handler::unsubscribe(CT_EVENT_CHARGER, req_id); + ctx::request_handler::unsubscribe(SUBJ_STATE_CHARGER, req_id); ASSERT_CONTAIN_INT(json_val, CONTEXT_TRIGGER_IS_CONNECTED); @@ -124,13 +124,13 @@ bool _trigger_event_gps() { if (!__support(CONTEXT_TRIGGER_EVENT_GPS)) return false; - err = ctx::request_handler::subscribe(CT_EVENT_GPS, NULL, &req_id, NULL); + err = ctx::request_handler::subscribe(SUBJ_STATE_GPS, NULL, &req_id, NULL); ASSERT_CMPINT(err, ==, ERR_NONE); g_print("\n> Change the GPS status %d times.\n", CALLBACK_COUNT); start_mainloop(); - ctx::request_handler::unsubscribe(CT_EVENT_GPS, req_id); + ctx::request_handler::unsubscribe(SUBJ_STATE_GPS, req_id); ASSERT_CONTAIN_STR(json_val, CONTEXT_TRIGGER_STATE); @@ -141,13 +141,13 @@ bool _trigger_event_headphone() { if (!__support(CONTEXT_TRIGGER_EVENT_HEADPHONE)) return false; - err = ctx::request_handler::subscribe(CT_EVENT_HEADPHONE, NULL, &req_id, NULL); + err = ctx::request_handler::subscribe(SUBJ_STATE_HEADPHONE, NULL, &req_id, NULL); ASSERT_CMPINT(err, ==, ERR_NONE); g_print("\n> Connect/disconnect a headphone %d times.\n", CALLBACK_COUNT); start_mainloop(); - ctx::request_handler::unsubscribe(CT_EVENT_HEADPHONE, req_id); + ctx::request_handler::unsubscribe(SUBJ_STATE_HEADPHONE, req_id); ASSERT_CONTAIN_INT(json_val, CONTEXT_TRIGGER_IS_CONNECTED); if (int_val == CONTEXT_TRIGGER_FALSE) return true; @@ -161,13 +161,13 @@ bool _trigger_event_usb() { if (!__support(CONTEXT_TRIGGER_EVENT_USB)) return false; - err = ctx::request_handler::subscribe(CT_EVENT_USB, NULL, &req_id, NULL); + err = ctx::request_handler::subscribe(SUBJ_STATE_USB, NULL, &req_id, NULL); ASSERT_CMPINT(err, ==, ERR_NONE); g_print("\n> Connect/disconnect USB %d times.\n", CALLBACK_COUNT); start_mainloop(); - ctx::request_handler::unsubscribe(CT_EVENT_USB, req_id); + ctx::request_handler::unsubscribe(SUBJ_STATE_USB, req_id); ASSERT_CONTAIN_INT(json_val, CONTEXT_TRIGGER_IS_CONNECTED); @@ -178,13 +178,13 @@ bool _trigger_event_wifi() { if (!__support(CONTEXT_TRIGGER_EVENT_WIFI)) return false; - err = ctx::request_handler::subscribe(CT_EVENT_WIFI, NULL, &req_id, NULL); + err = ctx::request_handler::subscribe(SUBJ_STATE_WIFI, NULL, &req_id, NULL); ASSERT_CMPINT(err, ==, ERR_NONE); g_print("\n> Change the WiFi state %d times.\n", CALLBACK_COUNT); start_mainloop(); - ctx::request_handler::unsubscribe(CT_EVENT_WIFI, req_id); + ctx::request_handler::unsubscribe(SUBJ_STATE_WIFI, req_id); ASSERT_CONTAIN_STR(json_val, CONTEXT_TRIGGER_STATE); @@ -198,13 +198,13 @@ bool _trigger_event_psmode() { if (!__support(CONTEXT_TRIGGER_EVENT_POWER_SAVING_MODE)) return false; - err = ctx::request_handler::subscribe(CT_EVENT_POWER_SAVING_MODE, NULL, &req_id, NULL); + err = ctx::request_handler::subscribe(SUBJ_STATE_PSMODE, NULL, &req_id, NULL); ASSERT_CMPINT(err, ==, ERR_NONE); g_print("\n> Turn on/off the power-saving mode %d times.\n", CALLBACK_COUNT); start_mainloop(); - ctx::request_handler::unsubscribe(CT_EVENT_POWER_SAVING_MODE, req_id); + ctx::request_handler::unsubscribe(SUBJ_STATE_PSMODE, req_id); ASSERT_CONTAIN_INT(json_val, CONTEXT_TRIGGER_IS_ENABLED); @@ -215,13 +215,13 @@ bool _trigger_event_call() { if (!__support(CONTEXT_TRIGGER_EVENT_CALL)) return false; - err = ctx::request_handler::subscribe(CT_EVENT_CALL, NULL, &req_id, NULL); + err = ctx::request_handler::subscribe(SUBJ_STATE_CALL, NULL, &req_id, NULL); ASSERT_CMPINT(err, ==, ERR_NONE); g_print("\n> Make a phone call to this device to change call state %d times.\n", CALLBACK_COUNT); start_mainloop(); - ctx::request_handler::unsubscribe(CT_EVENT_CALL, req_id); + ctx::request_handler::unsubscribe(SUBJ_STATE_CALL, req_id); ASSERT_CONTAIN_STR(json_val, CONTEXT_TRIGGER_STATE); if (str_val == CONTEXT_TRIGGER_IDLE) return true; @@ -276,14 +276,14 @@ bool _trigger_event_time() option.append(NULL, CONTEXT_TRIGGER_DAY_OF_WEEK, dow_str); option.append(NULL, CONTEXT_TRIGGER_TIME_OF_DAY, tod); - err = ctx::request_handler::subscribe(CT_EVENT_TIME, &option, &req_id, NULL); + err = ctx::request_handler::subscribe(SUBJ_STATE_ALARM, &option, &req_id, NULL); ASSERT_CMPINT(err, ==, ERR_NONE); callback_count = 1; g_print("\n> Wait until %02d:%02d %s.\n", tod / 60, tod % 60, dow_str.c_str()); start_mainloop(); - ctx::request_handler::unsubscribe(CT_EVENT_CALL, req_id); + ctx::request_handler::unsubscribe(SUBJ_STATE_CALL, req_id); ASSERT_CONTAIN_INT(json_val, CONTEXT_TRIGGER_TIME_OF_DAY); ASSERT_CONTAIN_STR(json_val, CONTEXT_TRIGGER_DAY_OF_WEEK); @@ -295,13 +295,13 @@ bool _trigger_event_email() { if (!__support(CONTEXT_TRIGGER_EVENT_EMAIL)) return false; - err = ctx::request_handler::subscribe(CT_EVENT_EMAIL, NULL, &req_id, NULL); + err = ctx::request_handler::subscribe(SUBJ_STATE_EMAIL, NULL, &req_id, NULL); ASSERT_CMPINT(err, ==, ERR_NONE); g_print("\n> Send/receive emails %d times.\n", CALLBACK_COUNT); start_mainloop(); - ctx::request_handler::unsubscribe(CT_EVENT_EMAIL, req_id); + ctx::request_handler::unsubscribe(SUBJ_STATE_EMAIL, req_id); ASSERT_CONTAIN_STR(json_val, CONTEXT_TRIGGER_EVENT); @@ -312,13 +312,13 @@ bool _trigger_event_message() { if (!__support(CONTEXT_TRIGGER_EVENT_MESSAGE)) return false; - err = ctx::request_handler::subscribe(CT_EVENT_MESSAGE, NULL, &req_id, NULL); + err = ctx::request_handler::subscribe(SUBJ_STATE_MESSAGE, NULL, &req_id, NULL); ASSERT_CMPINT(err, ==, ERR_NONE); g_print("\n> Receive SMS/MMS %d times.\n", CALLBACK_COUNT); start_mainloop(); - ctx::request_handler::unsubscribe(CT_EVENT_MESSAGE, req_id); + ctx::request_handler::unsubscribe(SUBJ_STATE_MESSAGE, req_id); ASSERT_CONTAIN_STR(json_val, CONTEXT_TRIGGER_EVENT); ASSERT_CONTAIN_STR(json_val, CONTEXT_TRIGGER_TYPE); @@ -335,25 +335,25 @@ bool _trigger_event_activity() int req_ids[4]; - err = ctx::request_handler::subscribe(CT_EVENT_ACTIVITY_STATIONARY, NULL, &req_ids[0], NULL); + err = ctx::request_handler::subscribe(SUBJ_ACTIVITY_STATIONARY, NULL, &req_ids[0], NULL); ASSERT_CMPINT(err, ==, ERR_NONE); - err = ctx::request_handler::subscribe(CT_EVENT_ACTIVITY_WALKING, NULL, &req_ids[1], NULL); + err = ctx::request_handler::subscribe(SUBJ_ACTIVITY_WALKING, NULL, &req_ids[1], NULL); ASSERT_CMPINT(err, ==, ERR_NONE); - err = ctx::request_handler::subscribe(CT_EVENT_ACTIVITY_RUNNING, NULL, &req_ids[2], NULL); + err = ctx::request_handler::subscribe(SUBJ_ACTIVITY_RUNNING, NULL, &req_ids[2], NULL); ASSERT_CMPINT(err, ==, ERR_NONE); - err = ctx::request_handler::subscribe(CT_EVENT_ACTIVITY_IN_VEHICLE, NULL, &req_ids[3], NULL); + err = ctx::request_handler::subscribe(SUBJ_ACTIVITY_IN_VEHICLE, NULL, &req_ids[3], NULL); ASSERT_CMPINT(err, ==, ERR_NONE); g_print("\n> Mimic any type of activity %d times.\n", CALLBACK_COUNT); start_mainloop(); - ctx::request_handler::unsubscribe(CT_EVENT_ACTIVITY_STATIONARY, req_ids[0]); - ctx::request_handler::unsubscribe(CT_EVENT_ACTIVITY_WALKING, req_ids[1]); - ctx::request_handler::unsubscribe(CT_EVENT_ACTIVITY_RUNNING, req_ids[2]); - ctx::request_handler::unsubscribe(CT_EVENT_ACTIVITY_IN_VEHICLE, req_ids[3]); + ctx::request_handler::unsubscribe(SUBJ_ACTIVITY_STATIONARY, req_ids[0]); + ctx::request_handler::unsubscribe(SUBJ_ACTIVITY_WALKING, req_ids[1]); + ctx::request_handler::unsubscribe(SUBJ_ACTIVITY_RUNNING, req_ids[2]); + ctx::request_handler::unsubscribe(SUBJ_ACTIVITY_IN_VEHICLE, req_ids[3]); ASSERT_CONTAIN_STR(json_val, CONTEXT_TRIGGER_EVENT); ASSERT_CONTAIN_STR(json_val, CONTEXT_TRIGGER_ACCURACY); @@ -368,13 +368,13 @@ bool _trigger_event_place() ctx::Json option; option.set(NULL, CONTEXT_TRIGGER_PLACE_ID, 2); /* 2 => office */ - err = ctx::request_handler::subscribe(CT_EVENT_PLACE, &option, &req_id, NULL); + err = ctx::request_handler::subscribe(SUBJ_PLACE_GEOFENCE, &option, &req_id, NULL); ASSERT_CMPINT(err, ==, ERR_NONE); g_print("\n> Mimic fence in/out event to office %d times.\n", CALLBACK_COUNT); start_mainloop(); - ctx::request_handler::unsubscribe(CT_EVENT_PLACE, req_id); + ctx::request_handler::unsubscribe(SUBJ_PLACE_GEOFENCE, req_id); ASSERT_CONTAIN_STR(json_val, CONTEXT_TRIGGER_EVENT);