Modified template format in rule_info to match server-side template style 83/56583/1
authorSomin Kim <somin926.kim@samsung.com>
Mon, 11 Jan 2016 09:06:57 +0000 (18:06 +0900)
committerSomin Kim <somin926.kim@samsung.com>
Mon, 11 Jan 2016 09:06:57 +0000 (18:06 +0900)
Change-Id: I191bcad2f09aa667f855bc6c4f80f132cd37e12d
Signed-off-by: Somin Kim <somin926.kim@samsung.com>
include/context_trigger_types_internal.h
src/context_trigger.cpp
src/rule_info.h
src/rule_validator.cpp
src/rule_validator.h

index b28c179..6509245 100644 (file)
@@ -99,8 +99,9 @@
 #define TYPE_OPTION 1
 #define TYPE_ATTR 2
 
-#define TYPE_INT 1
-#define TYPE_STRING 2
+#define TYPE_INT_STR "integer"
+#define TYPE_STRING_STR "string"
+#define TYPE_DOUBLE_STR "double"
 
 #define TYPE_OPTION_STR "option"
 #define TYPE_ATTR_STR "attributes"
index cb623ad..87df89d 100644 (file)
@@ -794,12 +794,11 @@ EXTAPI int context_trigger_rule_entry_add_comparison(context_trigger_rule_entry_
        bool ret = ctx::rule_validator::check_valid_key(TYPE_ATTR, name, key);
        IF_FAIL_RETURN(ret, CONTEXT_TRIGGER_ERROR_INVALID_RULE);
 
-       int type = ctx::rule_validator::get_data_type(TYPE_ATTR, name, key);
-       std::string type_str = (type == TYPE_INT)? "int" : "string";
+       std::string type = ctx::rule_validator::get_data_type(TYPE_ATTR, name, key);
 
        int error;
        std::string converted_op;
-       error = convert_operator(type_str, op, &converted_op);  // Err: Invalid operator
+       error = convert_operator(type, op, &converted_op);      // Err: Invalid operator
        if (error != ERR_NONE){
                return error;
        }
@@ -829,7 +828,7 @@ EXTAPI int context_trigger_rule_entry_add_comparison_int(context_trigger_rule_en
        bool ret = ctx::rule_validator::check_comparison_int(name, key, op, value);
        IF_FAIL_RETURN(ret, CONTEXT_TRIGGER_ERROR_INVALID_RULE);
 
-       error = convert_operator("int", op, &converted_op);     // Err: Invalid operator
+       error = convert_operator(TYPE_INT_STR, op, &converted_op);      // Err: Invalid operator
        if (error != ERR_NONE){
                return error;
        }
@@ -868,7 +867,7 @@ EXTAPI int context_trigger_rule_entry_add_comparison_string(context_trigger_rule
        bool ret = ctx::rule_validator::check_comparison_string(name, key, op, value);
        IF_FAIL_RETURN(ret, CONTEXT_TRIGGER_ERROR_INVALID_RULE);
 
-       error = convert_operator("string", op, &converted_op);  // Err: Invalid operator
+       error = convert_operator(TYPE_STRING_STR, op, &converted_op);   // Err: Invalid operator
        if (error != ERR_NONE){
                return error;
        }
@@ -1010,7 +1009,7 @@ int convert_operator(std::string type, std::string op, std::string* converted_op
                return CONTEXT_TRIGGER_ERROR_NONE;
        }
 
-       if (type.compare("int") == 0 || type.compare("double") == 0) {
+       if (type.compare(TYPE_INT_STR) == 0 || type.compare(TYPE_DOUBLE_STR) == 0) {
                if (op.compare("<") == 0 || op.compare("<=") == 0 || op.compare(">") == 0 || op.compare(">=") == 0) {
                        *converted_op = op;
                        return CONTEXT_TRIGGER_ERROR_NONE;
index 3636779..3e84945 100644 (file)
 #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\" ] } ]\
                }\
        ]\
 }"
index 1356ef5..a94fa74 100644 (file)
@@ -31,7 +31,7 @@
 #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"
 
@@ -89,13 +89,13 @@ bool ctx::rule_validator::check_option(ctx::json& item)
        // 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;
        }
@@ -118,10 +118,10 @@ bool ctx::rule_validator::check_option_int(std::string name, std::string key, in
        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;
                }
@@ -154,10 +154,10 @@ bool ctx::rule_validator::check_option_string(std::string name, std::string key,
        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;
                }
@@ -166,9 +166,9 @@ bool ctx::rule_validator::check_option_string(std::string name, std::string key,
 
        // 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;
@@ -205,10 +205,10 @@ bool ctx::rule_validator::check_comparison_int(std::string name, std::string key
        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;
                }
@@ -238,10 +238,10 @@ bool ctx::rule_validator::check_comparison_string(std::string name, std::string
        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;
                }
@@ -270,7 +270,7 @@ bool ctx::rule_validator::check_valid_key(int type, std::string name, std::strin
        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;
                }
@@ -298,13 +298,13 @@ bool check_value_int(ctx::json& tempt, int value)
 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;
        }
 
@@ -322,10 +322,10 @@ bool ctx::rule_validator::set_ref_info(int type, ctx::json* jref, std::string na
        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;
@@ -348,7 +348,7 @@ bool ctx::rule_validator::set_ref_info(int type, ctx::json* jref, std::string na
 }
 
 // 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();
 
@@ -359,26 +359,26 @@ int ctx::rule_validator::get_data_type(int type, std::string name, std::string k
                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) {
@@ -393,7 +393,7 @@ bool ctx::rule_validator::check_referential_data(std::string name, ctx::json& re
        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) {
index e4a60b0..eb7a8cc 100644 (file)
@@ -31,7 +31,7 @@ namespace ctx {
                bool check_valid_key(int type, std::string name, std::string key);
 
                bool set_ref_info(int type, ctx::json *jref, std::string name, std::string key, std::string ref_key);
-               int get_data_type(int type, std::string name, std::string key);
+               std::string get_data_type(int type, std::string name, std::string key);
                bool check_referential_data(std::string name, ctx::json &ref_info);
 
        }