DMLEAF structure: delete 'default_value' argument

This commit is contained in:
Amin Ben Romdhane 2023-08-09 11:07:29 +02:00
parent 35c0bf6ad0
commit 70a0917cc4
3 changed files with 11 additions and 19 deletions

View file

@ -122,7 +122,6 @@ typedef struct dm_leaf_s {
int (*setvalue)(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action);
int bbfdm_type;
char version[10] __attribute__((deprecated));
char *default_value;
} DMLEAF;
typedef struct dm_obj_s {

View file

@ -1419,10 +1419,7 @@ static int get_value_param(DMPARAM_ARGS)
if (value && *value) {
value = check_value_by_type(value, leaf->type);
} else {
if (leaf->default_value)
value = check_value_by_type(leaf->default_value, leaf->type);
else
value = get_default_value_by_type(leaf->type);
value = get_default_value_by_type(leaf->type);
}
add_list_parameter(dmctx, full_param, value, DMT_TYPE[leaf->type], NULL);
@ -1467,10 +1464,7 @@ static int mparam_get_value_in_param(DMPARAM_ARGS)
if (value && *value) {
value = check_value_by_type(value, leaf->type);
} else {
if (leaf->default_value)
value = check_value_by_type(leaf->default_value, leaf->type);
else
value = get_default_value_by_type(leaf->type);
value = get_default_value_by_type(leaf->type);
}
add_list_parameter(dmctx, full_param, value, DMT_TYPE[leaf->type], NULL);

View file

@ -851,11 +851,18 @@ end:
static char *get_value_from_mapping(json_object *param_obj, int json_version, char *refparam, struct dmctx *ctx, void *data, char *instance)
{
struct json_object *mapping_arr = NULL, *mapping = NULL;
struct json_object *mapping_arr = NULL, *mapping = NULL, *def_value = NULL;
if (!param_obj)
return "";
// Check if default value option exists
json_object_object_get_ex(param_obj, "default", &def_value);
if (def_value) {
char *val = json_object_get_string(def_value);
return val ? dm_dynamic_strdup(&json_memhead, val) : "";
}
json_object_object_get_ex(param_obj, "mapping", &mapping_arr);
if (mapping_arr && json_object_get_type(mapping_arr) == json_type_array) {
@ -1605,7 +1612,7 @@ static char** fill_unique_keys(size_t count, struct json_object *obj)
static void parse_param(char *object, char *param, json_object *jobj, DMLEAF *pleaf, int i, int json_version, struct list_head *list)
{
/* PARAM, permission, type, getvalue, setvalue, bbfdm_type(6)*/
struct json_object *type = NULL, *protocols = NULL, *write = NULL, *async = NULL, *def_value = NULL;
struct json_object *type = NULL, *protocols = NULL, *write = NULL, *async = NULL;
char full_param[512] = {0};
size_t n_proto;
char **in_p = NULL, **out_p = NULL, **ev_arg = NULL, **tmp = NULL;
@ -1653,14 +1660,6 @@ static void parse_param(char *object, char *param, json_object *jobj, DMLEAF *pl
pleaf[i].permission = (write && json_object_get_boolean(write)) ? &DMWRITE : &DMREAD;
}
//default value
json_object_object_get_ex(jobj, "default", &def_value);
char *val = json_object_get_string(def_value);
if (val != NULL)
pleaf[i].default_value = dm_dynamic_strdup(&json_memhead, val);
else
pleaf[i].default_value = NULL;
//getvalue
if (pleaf[i].type == DMT_EVENT) {
int param_count = 0;