Assume I have the following data model, value of a, b and c will be changed frequently(so, trans.init() is suitable for fetching values), we have a function get_ct(&ct_info) to fetch the value of a,b,and c, value of a, b, and c must be grouped.
container ct {
leaf a;
leaf b;
leaf c;
}
the show command is
# show ct
ct a xxxx
ct b xxxx
ct c xxxx
I register the get_elem callback for container ct
int get_elem_ct(struct confd_trans_ctx *tctx, wconfd_hkeypath_t *kp)
{
confd_value_t v;
ct_info_t ct_info;
switch(CONFD_GET_XMLTAG(&kp->v[0][0])
{
case _a:
get_ct_info(&ct_info);
CONFD_SET_STR(&v, ct_info.a);
free_ct_info(&ct_info);
break;
case _b:
get_ct_info(&ct_info);
CONFD_SET_STR(&v, ct_info.b);
free_ct_info(&ct_info);
break;
case _c:
get_ct_info(&ct_info);
CONFD_SET_STR(&v, ct_info.c);
free_ct_info(&ct_info);
break;
}
confd_data_reply_value(tctx, &v);
return CONFD_OK;
}
First because values are changed frequently I couldn’t cached them in global var I must fetch each time show command called, second, because I couldn’t fill all the leafs value in one swoop, the guide says that get_object() callback will only be called for list entries. I have to write code to fill each leaf like above. The problem is
-
a, b, c values are not grouped any more. for example we call get_ct_info() there times
call_id a b c
1 1 2 3
2 4 5 6
3 7 8 9show ct
ct a 1
ct b 5
ct c 9
this is the wrong result, which should be
ct a 1
ct b 2
ct c 3
or
ct a 4
ct b 5
ct c 6
or
ct a 7
ct b 8
ct c 9
- we invoke get_ct_info() too many times, assume get_ct_info() should connect to other process by tcp, if the resource need much time and memory we couldn’t accept this thing happens.
Is there a way for us to prepare resource at the beginning of show command, and release the resource at the end of show command.