lib: combine two YANG schema iteration functions into one

Combine yang_snodes_iterate_module() and yang_snodes_iterate_all()
into an unified yang_snodes_iterate() function, where the first
"module" parameter is optional. There's no point in having two
separate YANG schema iteration functions anymore now that they are
too similar.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
This commit is contained in:
Renato Westphal 2020-10-22 22:19:10 -03:00
parent 9bde0b2569
commit 8d869d378b
8 changed files with 32 additions and 70 deletions

View file

@ -162,12 +162,12 @@ static int nb_node_del_cb(const struct lys_node *snode, void *arg)
void nb_nodes_create(void)
{
yang_snodes_iterate_all(nb_node_new_cb, 0, NULL);
yang_snodes_iterate(NULL, nb_node_new_cb, 0, NULL);
}
void nb_nodes_delete(void)
{
yang_snodes_iterate_all(nb_node_del_cb, 0, NULL);
yang_snodes_iterate(NULL, nb_node_del_cb, 0, NULL);
}
struct nb_node *nb_node_find(const char *xpath)
@ -2254,7 +2254,7 @@ void nb_init(struct thread_master *tm,
nb_load_callbacks(modules[i]);
/* Validate northbound callbacks. */
yang_snodes_iterate_all(nb_node_validate, 0, &errors);
yang_snodes_iterate(NULL, nb_node_validate, 0, &errors);
if (errors > 0) {
flog_err(
EC_LIB_NB_CBS_VALIDATION,

View file

@ -1279,7 +1279,7 @@ static int frr_confd_init_dp(const char *program_name)
* Iterate over all loaded YANG modules and subscribe to the paths
* referent to state data.
*/
yang_snodes_iterate_all(frr_confd_subscribe_state, 0, &data_cbs);
yang_snodes_iterate(NULL, frr_confd_subscribe_state, 0, &data_cbs);
/* Register notification stream. */
memset(&ncbs, 0, sizeof(ncbs));
@ -1430,7 +1430,7 @@ static int frr_confd_init(const char *program_name)
goto error;
}
yang_snodes_iterate_all(frr_confd_calculate_snode_hash, 0, NULL);
yang_snodes_iterate(NULL, frr_confd_calculate_snode_hash, 0, NULL);
hook_register(nb_notification_send, frr_confd_notification_send);

View file

@ -690,10 +690,10 @@ static int frr_sr_init(void)
int event_pipe;
frr_sr_subscribe_config(module);
yang_snodes_iterate_module(module->info, frr_sr_subscribe_state,
0, module);
yang_snodes_iterate_module(module->info, frr_sr_subscribe_rpc,
0, module);
yang_snodes_iterate(module->info, frr_sr_subscribe_state, 0,
module);
yang_snodes_iterate(module->info, frr_sr_subscribe_rpc, 0,
module);
/* Watch subscriptions. */
ret = sr_get_event_pipe(module->sr_subscription, &event_pipe);

View file

@ -227,8 +227,8 @@ next:
return ret;
}
int yang_snodes_iterate_module(const struct lys_module *module,
yang_iterate_cb cb, uint16_t flags, void *arg)
int yang_snodes_iterate(const struct lys_module *module, yang_iterate_cb cb,
uint16_t flags, void *arg)
{
const struct lys_module *module_iter;
uint32_t idx = 0;
@ -252,25 +252,6 @@ int yang_snodes_iterate_module(const struct lys_module *module,
return ret;
}
int yang_snodes_iterate_all(yang_iterate_cb cb, uint16_t flags, void *arg)
{
struct yang_module *module;
int ret = YANG_ITER_CONTINUE;
RB_FOREACH (module, yang_modules, &yang_modules) {
struct lys_node *snode;
LY_TREE_FOR (module->info->data, snode) {
ret = yang_snodes_iterate_subtree(snode, NULL, cb,
flags, arg);
if (ret == YANG_ITER_STOP)
return ret;
}
}
return ret;
}
void yang_snode_get_path(const struct lys_node *snode, enum yang_path_type type,
char *xpath, size_t xpath_len)
{

View file

@ -186,10 +186,11 @@ extern int yang_snodes_iterate_subtree(const struct lys_node *snode,
void *arg);
/*
* Iterate over all libyang schema nodes from the given YANG module.
* Iterate over all libyang schema nodes from all loeaded modules of from the
* given YANG module.
*
* module
* YANG module to operate on.
* When set, iterate over all nodes of the specified module only.
*
* cb
* Function to call with each schema node.
@ -203,27 +204,8 @@ extern int yang_snodes_iterate_subtree(const struct lys_node *snode,
* Returns:
* The return value of the last called callback.
*/
extern int yang_snodes_iterate_module(const struct lys_module *module,
yang_iterate_cb cb, uint16_t flags,
void *arg);
/*
* Iterate over all libyang schema nodes from all loaded YANG modules.
*
* cb
* Function to call with each schema node.
*
* flags
* YANG_ITER_* flags to control how the iteration is performed.
*
* arg
* Arbitrary argument passed as the second parameter in each call to 'cb'.
*
* Returns:
* The return value of the last called callback.
*/
extern int yang_snodes_iterate_all(yang_iterate_cb cb, uint16_t flags,
void *arg);
extern int yang_snodes_iterate(const struct lys_module *module,
yang_iterate_cb cb, uint16_t flags, void *arg);
/*
* Build schema path or data path of the schema node.

View file

@ -469,12 +469,12 @@ static unsigned int yang_translator_validate(struct yang_translator *translator)
args.errors = 0;
for (ALL_LIST_ELEMENTS_RO(translator->modules, ln, tmodule)) {
yang_snodes_iterate_module(
tmodule->module, yang_translator_validate_cb,
YANG_ITER_FILTER_NPCONTAINERS
| YANG_ITER_FILTER_LIST_KEYS
| YANG_ITER_FILTER_INPUT_OUTPUT,
&args);
yang_snodes_iterate(tmodule->module,
yang_translator_validate_cb,
YANG_ITER_FILTER_NPCONTAINERS
| YANG_ITER_FILTER_LIST_KEYS
| YANG_ITER_FILTER_INPUT_OUTPUT,
&args);
}
if (args.errors)
@ -500,11 +500,11 @@ static unsigned int yang_module_nodes_count(const struct lys_module *module)
{
unsigned int total = 0;
yang_snodes_iterate_module(module, yang_module_nodes_count_cb,
YANG_ITER_FILTER_NPCONTAINERS
| YANG_ITER_FILTER_LIST_KEYS
| YANG_ITER_FILTER_INPUT_OUTPUT,
&total);
yang_snodes_iterate(module, yang_module_nodes_count_cb,
YANG_ITER_FILTER_NPCONTAINERS
| YANG_ITER_FILTER_LIST_KEYS
| YANG_ITER_FILTER_INPUT_OUTPUT,
&total);
return total;
}

View file

@ -368,13 +368,12 @@ int main(int argc, char *argv[])
/* Generate callback prototypes. */
if (!static_cbs) {
printf("/* prototypes */\n");
yang_snodes_iterate_module(module->info, generate_prototypes, 0,
NULL);
yang_snodes_iterate(module->info, generate_prototypes, 0, NULL);
printf("\n");
}
/* Generate callback functions. */
yang_snodes_iterate_module(module->info, generate_callbacks, 0, NULL);
yang_snodes_iterate(module->info, generate_callbacks, 0, NULL);
strlcpy(module_name_underscores, module->name,
sizeof(module_name_underscores));
@ -386,7 +385,7 @@ int main(int argc, char *argv[])
"\t.name = \"%s\",\n"
"\t.nodes = {\n",
module_name_underscores, module->name);
yang_snodes_iterate_module(module->info, generate_nb_nodes, 0, NULL);
yang_snodes_iterate(module->info, generate_nb_nodes, 0, NULL);
printf("\t\t{\n"
"\t\t\t.xpath = NULL,\n"
"\t\t},\n");

View file

@ -71,8 +71,8 @@ int main(int argc, char *argv[])
module = yang_module_load(argv[0]);
/* Generate deviations. */
yang_snodes_iterate_module(module->info, generate_yang_deviation,
YANG_ITER_FILTER_IMPLICIT, NULL);
yang_snodes_iterate(module->info, generate_yang_deviation,
YANG_ITER_FILTER_IMPLICIT, NULL);
/* Cleanup and exit. */
yang_terminate();