#define RULE_INFO "{ \"templates\": [\
{\
\"name\": \"device/alarm\",\
- \"attributes\": [ { \"key\": \"TimeOfDay\", \"type\": 1, \"min\": 0, \"max\": 1439}, { \"key\": \"DayOfWeek\", \"type\": 2, \"acceptable\": [ \"Mon\", \"Tue\", \"Wed\", \"Thu\", \"Fri\", \"Sat\", \"Sun\", \"Weekday\", \"Weekend\" ] } ]\
+ \"attributes\": [ { \"key\": \"TimeOfDay\", \"type\": \"integer\", \"min\": 0, \"max\": 1439}, { \"key\": \"DayOfWeek\", \"type\": \"string\", \"values\": [ \"Mon\", \"Tue\", \"Wed\", \"Thu\", \"Fri\", \"Sat\", \"Sun\", \"Weekday\", \"Weekend\" ] } ]\
},\
{\
\"name\": \"device/time\",\
- \"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} ]\
+ \"attributes\": [ { \"key\": \"TimeOfDay\", \"type\": \"integer\", \"min\": 0, \"max\": 1439}, { \"key\": \"DayOfWeek\", \"type\": \"string\", \"values\": [ \"Mon\", \"Tue\", \"Wed\", \"Thu\", \"Fri\", \"Sat\", \"Sun\", \"Weekday\", \"Weekend\" ] }, { \"key\" : \"DayOfMonth\", \"type\": \"integer\", \"min\": 1, \"max\": 31} ]\
},\
{\
\"name\": \"system/battery\",\
- \"attributes\": [ { \"key\" : \"Level\", \"type\": 2, \"acceptable\": [ \"Empty\", \"Critical\", \"Low\", \"Normal\", \"High\", \"Full\" ] }, { \"key\": \"IsCharging\", \"type\": 1, \"min\": 0, \"max\": 1 } ]\
+ \"attributes\": [ { \"key\" : \"Level\", \"type\": \"string\", \"values\": [ \"Empty\", \"Critical\", \"Low\", \"Normal\", \"High\", \"Full\" ] }, { \"key\": \"IsCharging\", \"type\": \"integer\", \"min\": 0, \"max\": 1 } ]\
},\
{\
\"name\": \"system/charger\",\
- \"attributes\": [ { \"key\": \"IsConnected\", \"type\": 1, \"min\": 0, \"max\": 1 } ]\
+ \"attributes\": [ { \"key\": \"IsConnected\", \"type\": \"integer\", \"min\": 0, \"max\": 1 } ]\
},\
{\
\"name\": \"system/gps\",\
- \"attributes\": [ { \"key\" : \"State\", \"type\": 2, \"acceptable\": [ \"Disabled\", \"Searching\", \"Connected\" ] } ]\
+ \"attributes\": [ { \"key\" : \"State\", \"type\": \"string\", \"values\": [ \"Disabled\", \"Searching\", \"Connected\" ] } ]\
},\
{\
\"name\": \"system/headphone\",\
- \"attributes\": [{ \"key\": \"IsConnected\", \"type\": 1, \"min\": 0, \"max\": 1 }, { \"key\": \"Type\", \"type\": 2, \"acceptable\": [ \"Normal\", \"Headset\", \"Bluetooth\" ] } ]\
+ \"attributes\": [{ \"key\": \"IsConnected\", \"type\": \"integer\", \"min\": 0, \"max\": 1 }, { \"key\": \"Type\", \"type\": \"string\", \"values\": [ \"Normal\", \"Headset\", \"Bluetooth\" ] } ]\
},\
{\
\"name\": \"system/psmode\",\
- \"attributes\": [ { \"key\": \"IsEnabled\", \"type\": 1, \"min\": 0, \"max\": 1 } ]\
+ \"attributes\": [ { \"key\": \"IsEnabled\", \"type\": \"integer\", \"min\": 0, \"max\": 1 } ]\
},\
{\
\"name\": \"system/usb\",\
- \"attributes\": [ { \"key\": \"IsConnected\", \"type\": 1, \"min\": 0, \"max\": 1 } ]\
+ \"attributes\": [ { \"key\": \"IsConnected\", \"type\": \"integer\", \"min\": 0, \"max\": 1 } ]\
},\
{\
\"name\": \"system/wifi\",\
- \"attributes\": [ { \"key\" : \"State\", \"type\": 2, \"acceptable\": [ \"Disabled\", \"Unconnected\", \"Connected\" ] }, { \"key\": \"BSSID\", \"type\": 2, \"acceptable\": [ ] } ]\
+ \"attributes\": [ { \"key\" : \"State\", \"type\": \"string\", \"values\": [ \"Disabled\", \"Unconnected\", \"Connected\" ] }, { \"key\": \"BSSID\", \"type\": \"string\", \"values\": [ ] } ]\
},\
{\
\"name\": \"social/call\",\
- \"attributes\": [ { \"key\" : \"Medium\", \"type\": 2, \"acceptable\": [ \"Voice\", \"Video\" ] }, { \"key\" : \"State\", \"type\": 2, \"acceptable\": [ \"Idle\", \"Connecting\", \"Connected\" ] }, { \"key\": \"Address\", \"type\": 2, \"acceptable\": [ ] } ]\
+ \"attributes\": [ { \"key\" : \"Medium\", \"type\": \"string\", \"values\": [ \"Voice\", \"Video\" ] }, { \"key\" : \"State\", \"type\": \"string\", \"values\": [ \"Idle\", \"Connecting\", \"Connected\" ] }, { \"key\": \"Address\", \"type\": \"string\", \"values\": [ ] } ]\
},\
{\
\"name\": \"social/email\",\
- \"attributes\": [ { \"key\": \"Event\", \"type\": 2, \"acceptable\": [ \"Received\", \"Sent\" ] } ]\
+ \"attributes\": [ { \"key\": \"Event\", \"type\": \"string\", \"values\": [ \"Received\", \"Sent\" ] } ]\
},\
{\
\"name\": \"social/message\",\
- \"attributes\": [ { \"key\": \"Event\", \"type\": 2, \"acceptable\": [ \"Received\" ] } , { \"key\": \"Type\", \"type\": 2, \"acceptable\": [ \"SMS\", \"MMS\" ] }, { \"key\": \"Address\", \"type\": 2, \"acceptable\": [ ] } ]\
+ \"attributes\": [ { \"key\": \"Event\", \"type\": \"string\", \"values\": [ \"Received\" ] } , { \"key\": \"Type\", \"type\": \"string\", \"values\": [ \"SMS\", \"MMS\" ] }, { \"key\": \"Address\", \"type\": \"string\", \"values\": [ ] } ]\
},\
{\
\"name\": \"activity/stationary\",\
- \"attributes\": [ { \"key\": \"Event\", \"type\": 2, \"acceptable\": [ \"Detected\" ] }, { \"key\": \"Accuracy\", \"type\": 2, \"acceptable\": [ \"High\", \"Normal\", \"Low\" ] } ]\
+ \"attributes\": [ { \"key\": \"Event\", \"type\": \"string\", \"values\": [ \"Detected\" ] }, { \"key\": \"Accuracy\", \"type\": \"string\", \"values\": [ \"High\", \"Normal\", \"Low\" ] } ]\
},\
{\
\"name\": \"activity/walking\",\
- \"attributes\": [ { \"key\": \"Event\", \"type\": 2, \"acceptable\": [ \"Detected\" ] }, { \"key\": \"Accuracy\", \"type\": 2, \"acceptable\": [ \"High\", \"Normal\", \"Low\" ] } ]\
+ \"attributes\": [ { \"key\": \"Event\", \"type\": \"string\", \"values\": [ \"Detected\" ] }, { \"key\": \"Accuracy\", \"type\": \"string\", \"values\": [ \"High\", \"Normal\", \"Low\" ] } ]\
},\
{\
\"name\": \"activity/running\",\
- \"attributes\": [ { \"key\": \"Event\", \"type\": 2, \"acceptable\": [ \"Detected\" ] }, { \"key\": \"Accuracy\", \"type\": 2, \"acceptable\": [ \"High\", \"Normal\", \"Low\" ] } ]\
+ \"attributes\": [ { \"key\": \"Event\", \"type\": \"string\", \"values\": [ \"Detected\" ] }, { \"key\": \"Accuracy\", \"type\": \"string\", \"values\": [ \"High\", \"Normal\", \"Low\" ] } ]\
},\
{\
\"name\": \"activity/in_vehicle\",\
- \"attributes\": [ { \"key\": \"Event\", \"type\": 2, \"acceptable\": [ \"Detected\" ] }, { \"key\": \"Accuracy\", \"type\": 2, \"acceptable\": [ \"High\", \"Normal\", \"Low\" ] } ]\
+ \"attributes\": [ { \"key\": \"Event\", \"type\": \"string\", \"values\": [ \"Detected\" ] }, { \"key\": \"Accuracy\", \"type\": \"string\", \"values\": [ \"High\", \"Normal\", \"Low\" ] } ]\
},\
{\
\"name\": \"place/geofence\",\
- \"attributes\": [ { \"key\": \"Event\", \"type\": 2, \"acceptable\": [ \"In\", \"Out\" ] } ],\
- \"option\": [ { \"key\": \"PlaceId\", \"type\": 1, \"min\": 1, \"max\": -1 } ]\
+ \"attributes\": [ { \"key\": \"Event\", \"type\": \"string\", \"values\": [ \"In\", \"Out\" ] } ],\
+ \"option\": [ { \"key\": \"PlaceId\", \"type\": \"integer\", \"min\": 1, \"max\": -1 } ]\
},\
{\
\"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\" ] } ]\
+ \"attributes\": [ { \"key\": \"Rank\", \"type\": \"integer\", \"min\": 1, \"max\": -1 }, { \"key\": \"TotalCount\", \"type\": \"integer\", \"min\": 0, \"max\": -1 } ],\
+ \"option\": [ { \"key\": \"AppId\", \"type\": \"string\", \"values\": [ ] }, { \"key\": \"TimeOfDay\", \"type\": \"string\", \"values\": [ ] }, { \"key\": \"DayOfWeek\", \"type\": \"string\", \"values\": [ \"Mon\", \"Tue\", \"Wed\", \"Thu\", \"Fri\", \"Sat\", \"Sun\", \"Weekday\", \"Weekend\" ] } ]\
},\
{\
\"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\" ] } ]\
+ \"attributes\": [ { \"key\": \"Rank\", \"type\": \"integer\", \"min\": 1, \"max\": -1 }, { \"key\": \"TotalCount\", \"type\": \"integer\", \"min\": 0, \"max\": -1 } ],\
+ \"option\": [ { \"key\": \"Address\", \"type\": \"string\", \"values\": [ ] }, { \"key\": \"TimeOfDay\", \"type\": \"string\", \"values\": [ ] }, { \"key\": \"DayOfWeek\", \"type\": \"string\", \"values\": [ \"Mon\", \"Tue\", \"Wed\", \"Thu\", \"Fri\", \"Sat\", \"Sun\", \"Weekday\", \"Weekend\" ] } ]\
},\
{\
\"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\" ] } ]\
+ \"attributes\": [ { \"key\": \"TotalCount\", \"type\": \"integer\", \"min\": 0, \"max\": -1 } ],\
+ \"option\": [ { \"key\": \"TimeOfDay\", \"type\": \"string\", \"values\": [ ] }, { \"key\": \"DayOfWeek\", \"type\": \"string\", \"values\": [ \"Mon\", \"Tue\", \"Wed\", \"Thu\", \"Fri\", \"Sat\", \"Sun\", \"Weekday\", \"Weekend\" ] } ]\
},\
{\
\"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\" ] } ]\
+ \"attributes\": [ { \"key\": \"TotalCount\", \"type\": \"integer\", \"min\": 0, \"max\": -1 } ],\
+ \"option\": [ { \"key\": \"TimeOfDay\", \"type\": \"string\", \"values\": [ ] }, { \"key\": \"DayOfWeek\", \"type\": \"string\", \"values\": [ \"Mon\", \"Tue\", \"Wed\", \"Thu\", \"Fri\", \"Sat\", \"Sun\", \"Weekday\", \"Weekend\" ] } ]\
}\
]\
}"
#define KEY_TYPE "type"
#define KEY_MIN "min"
#define KEY_MAX "max"
-#define KEY_ACCEPTABLE "acceptable"
+#define KEY_VALUES "values"
#define NO_LIMIT -1
#define KEY_REF "ref"
// Err: Check if mandatory option is missed
std::string val_str;
int val;
- if (name.compare(CT_EVENT_PLACE) == 0) {
+ if (name == CT_EVENT_PLACE) {
if (!(item.get(CT_RULE_EVENT_OPTION, CONTEXT_TRIGGER_PLACE_ID, &val)))
return false;
- } else if (name.compare(CT_CONDITION_APP_USE_FREQUENCY) == 0) {
+ } else if (name == CT_CONDITION_APP_USE_FREQUENCY) {
if (!(item.get(CT_RULE_CONDITION_OPTION, CONTEXT_TRIGGER_APP_ID, &val_str)))
return false;
- } else if (name.compare(CT_CONDITION_COMMUNICATION_FREQUENCY) == 0) {
+ } else if (name == CT_CONDITION_COMMUNICATION_FREQUENCY) {
if (!(item.get(CT_RULE_CONDITION_OPTION, CONTEXT_TRIGGER_ADDRESS, &val_str)))
return 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;
+ std::string 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) {
+ if (t_key == key && t_type == TYPE_INT_STR) {
ret = true;
break;
}
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;
+ std::string 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) {
+ if (t_key == key && t_type == TYPE_STRING_STR) {
ret = true;
break;
}
// 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) {
+ if ((name == CT_CONDITION_APP_USE_FREQUENCY || name == CT_CONDITION_COMMUNICATION_FREQUENCY
+ || name == CT_CONDITION_MUSIC_PLAYBACK_FREQUENCY || name == CT_CONDITION_VIDEO_PLAYBACK_FREQUENCY)
+ && key == CONTEXT_TRIGGER_TIME_OF_DAY) {
std::size_t found = value.find("-");
if (found == std::string::npos) {
return 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;
+ std::string 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) {
+ if (t_key == key && t_type == TYPE_INT_STR) {
ret = true;
break;
}
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;
+ std::string 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) {
+ if (t_key == key && t_type == TYPE_STRING_STR) {
ret = true;
break;
}
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) {
+ if (t_key == key) {
ret = true;
break;
}
bool check_value_string(ctx::json& tempt, std::string value)
{
// case1: any value is accepted
- if (tempt.array_get_size(NULL, KEY_ACCEPTABLE) <= 0)
+ if (tempt.array_get_size(NULL, KEY_VALUES) <= 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)
+ for (int i = 0; tempt.get_array_elem(NULL, KEY_VALUES, i, &t_val); i++) {
+ if (t_val == value)
return true;
}
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;
+ std::string dt;
tempt.get(NULL, KEY_KEY, &k);
- if (key.compare(k) == 0) {
+ if (key == k) {
tempt.get(NULL, KEY_TYPE, &dt);
ctx::json temp;
}
// called by context_trigger_rule_entry_add_comparison()
-int ctx::rule_validator::get_data_type(int type, std::string name, std::string key)
+std::string ctx::rule_validator::get_data_type(int type, std::string name, std::string key)
{
init();
std::string k;
tempt.get(NULL, KEY_KEY, &k);
- if (key.compare(k) == 0) {
- int dt;
+ if (key == k) {
+ std::string dt;
tempt.get(NULL, KEY_TYPE, &dt);
return dt;
}
}
- return -1;
+ return "";
}
// called by context_trigger_rule_add_entry()
bool ctx::rule_validator::check_referential_data(std::string name, ctx::json& ref_info)
{
- std::map<std::string, int> type_map;
+ std::map<std::string, std::string> 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;
+ std::string cond_type;
ref_data.get(NULL, KEY_TYPE, &cond_type);
if (type_map.count(ref_key) == 0) {
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;
+ std::string cond_type;
ref_data.get(NULL, KEY_TYPE, &cond_type);
if (type_map.count(ref_key) == 0) {