thermal: parser: Distinguish mandatory property or optional with get_property 47/277247/8
authorChanwoo Choi <cw00.choi@samsung.com>
Sun, 3 Jul 2022 17:17:18 +0000 (02:17 +0900)
committerChanwoo Choi <cw00.choi@samsung.com>
Tue, 5 Jul 2022 03:47:37 +0000 (12:47 +0900)
Change-Id: I301aefac2dd006b6ba4406b0e813947c949aa490
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
src/thermal/thermal-parser.c

index 2b49774..c1660b4 100644 (file)
  */
 static int thermal_parse_scenario(json_object *obj, struct scenario *scenario)
 {
-       const char *name;
+       char name[BUFF_MAX] = {};
        int support;
+       int ret = 0;
 
        /* Get property values */
-       name = get_string_from_object(obj, "name");
-       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);
+
+       /* Check whether the mandatory properties are included or not */
+       if (ret < 0) {
+               _E("Failed to get the mandatory properties in thermal scenario\n");
                return -EINVAL;
        }
 
@@ -80,15 +83,22 @@ static int thermal_load_config(json_object *obj, struct thermal_scenario *scenar
 {
        int thermal_support;
        json_object *thermal_scenario_list = NULL;
-       int num_scenarios = 0, ret, i;
+       int num_scenarios = 0, ret = 0, i;
 
        /* Get property values */
-       thermal_support = get_boolean_from_object(obj, "thermal_support");
+       ret = get_property(obj, "thermal_support", DATA_TYPE_BOOLEAN, false,
+                               (void *)&thermal_support);
        if (json_object_object_get_ex(obj, "thermal_scenario_list",
                                &thermal_scenario_list))
                num_scenarios = json_object_array_length(thermal_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 thermal config\n");
+               return -EINVAL;
+       }
+
+       /* Check the validation of property value */
        if (thermal_support <= 0 || num_scenarios <= 0) {
                _I("Disable thermal module\n");
                return 0;