pmqos: parser: Distinguish mandatory property or optional with get_property 48/277248/8
authorChanwoo Choi <cw00.choi@samsung.com>
Sun, 3 Jul 2022 17:20:04 +0000 (02:20 +0900)
committerChanwoo Choi <cw00.choi@samsung.com>
Tue, 5 Jul 2022 03:50:40 +0000 (12:50 +0900)
Change-Id: Ifef64ee85c00f4c7a2b695aa5edf80ac6e42c824
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
src/pmqos/pmqos-parser.c

index 26d6a95..7cc5a80 100644 (file)
  */
 static int pmqos_parse_scenario(json_object *obj, struct scenario *scenario)
 {
-       const char *name;
+       char name[BUFF_MAX] = {};
        int max_duration_ms;
        int support;
+       int ret = 0;
 
        /* Get property values */
-       name = get_string_from_object(obj, "name");
-       max_duration_ms = get_int_from_object(obj, "max_duration_ms");
-       support = get_boolean_from_object(obj, "support");
-
-       /* Check the mandatory property values are valid or not */
-       if (!name) {
-               _E("Failed to get 'name' property of scenario section\n");
+       ret += get_property(obj, "name", DATA_TYPE_STRING, true,
+                               (void *)name);
+       ret += get_property(obj, "support", DATA_TYPE_BOOLEAN, false,
+                               (void *)&support);
+       ret += get_property(obj, "max_duration_ms", DATA_TYPE_INT, false,
+                               (void *)&max_duration_ms);
+
+       /* Check whether the mandatory properties are included or not */
+       if (ret < 0) {
+               _E("Failed to get the mandatory properties in pmqos scenario\n");
                return -EINVAL;
        }
 
@@ -89,12 +93,19 @@ static int pmqos_load_config(json_object *obj, struct pmqos_scenario *scenarios)
        int num_scenarios = 0, ret, i;
 
        /* Get property values */
-       pmqos_support = get_boolean_from_object(obj, "pmqos_support");
+       ret = get_property(obj, "pmqos_support", DATA_TYPE_BOOLEAN, false,
+                               (void *)&pmqos_support);
        if (json_object_object_get_ex(obj, "pmqos_scenario_list",
                                &pmqos_scenario_list))
                num_scenarios = json_object_array_length(pmqos_scenario_list);
 
-       /* Check the mandatory property values are valid or not */
+       /* Check whether the mandatory properties are included or not */
+       if (ret < 0) {
+               _E("Failed to get the mandatory properties in pmqos config\n");
+               return -EINVAL;
+       }
+
+       /* Check the validation of property value */
        if (pmqos_support <= 0 || num_scenarios <= 0) {
                _I("Disable PMQOS module\n");
                return 0;