From: Chanwoo Choi Date: Sun, 3 Jul 2022 17:17:18 +0000 (+0900) Subject: thermal: parser: Distinguish mandatory property or optional with get_property X-Git-Tag: submit/tizen/20220707.024120~4 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1b6275df78a04b77b799c160f419cc8f9a407ce0;p=platform%2Fcore%2Fsystem%2Fpass.git thermal: parser: Distinguish mandatory property or optional with get_property Change-Id: I301aefac2dd006b6ba4406b0e813947c949aa490 Signed-off-by: Chanwoo Choi --- diff --git a/src/thermal/thermal-parser.c b/src/thermal/thermal-parser.c index 2b49774..c1660b4 100644 --- a/src/thermal/thermal-parser.c +++ b/src/thermal/thermal-parser.c @@ -49,16 +49,19 @@ */ 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;