forked from Mirror/frr
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:
parent
9bde0b2569
commit
8d869d378b
|
@ -162,12 +162,12 @@ static int nb_node_del_cb(const struct lys_node *snode, void *arg)
|
||||||
|
|
||||||
void nb_nodes_create(void)
|
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)
|
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)
|
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]);
|
nb_load_callbacks(modules[i]);
|
||||||
|
|
||||||
/* Validate northbound callbacks. */
|
/* Validate northbound callbacks. */
|
||||||
yang_snodes_iterate_all(nb_node_validate, 0, &errors);
|
yang_snodes_iterate(NULL, nb_node_validate, 0, &errors);
|
||||||
if (errors > 0) {
|
if (errors > 0) {
|
||||||
flog_err(
|
flog_err(
|
||||||
EC_LIB_NB_CBS_VALIDATION,
|
EC_LIB_NB_CBS_VALIDATION,
|
||||||
|
|
|
@ -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
|
* Iterate over all loaded YANG modules and subscribe to the paths
|
||||||
* referent to state data.
|
* 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. */
|
/* Register notification stream. */
|
||||||
memset(&ncbs, 0, sizeof(ncbs));
|
memset(&ncbs, 0, sizeof(ncbs));
|
||||||
|
@ -1430,7 +1430,7 @@ static int frr_confd_init(const char *program_name)
|
||||||
goto error;
|
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);
|
hook_register(nb_notification_send, frr_confd_notification_send);
|
||||||
|
|
||||||
|
|
|
@ -690,10 +690,10 @@ static int frr_sr_init(void)
|
||||||
int event_pipe;
|
int event_pipe;
|
||||||
|
|
||||||
frr_sr_subscribe_config(module);
|
frr_sr_subscribe_config(module);
|
||||||
yang_snodes_iterate_module(module->info, frr_sr_subscribe_state,
|
yang_snodes_iterate(module->info, frr_sr_subscribe_state, 0,
|
||||||
0, module);
|
module);
|
||||||
yang_snodes_iterate_module(module->info, frr_sr_subscribe_rpc,
|
yang_snodes_iterate(module->info, frr_sr_subscribe_rpc, 0,
|
||||||
0, module);
|
module);
|
||||||
|
|
||||||
/* Watch subscriptions. */
|
/* Watch subscriptions. */
|
||||||
ret = sr_get_event_pipe(module->sr_subscription, &event_pipe);
|
ret = sr_get_event_pipe(module->sr_subscription, &event_pipe);
|
||||||
|
|
23
lib/yang.c
23
lib/yang.c
|
@ -227,8 +227,8 @@ next:
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int yang_snodes_iterate_module(const struct lys_module *module,
|
int yang_snodes_iterate(const struct lys_module *module, yang_iterate_cb cb,
|
||||||
yang_iterate_cb cb, uint16_t flags, void *arg)
|
uint16_t flags, void *arg)
|
||||||
{
|
{
|
||||||
const struct lys_module *module_iter;
|
const struct lys_module *module_iter;
|
||||||
uint32_t idx = 0;
|
uint32_t idx = 0;
|
||||||
|
@ -252,25 +252,6 @@ int yang_snodes_iterate_module(const struct lys_module *module,
|
||||||
return ret;
|
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,
|
void yang_snode_get_path(const struct lys_node *snode, enum yang_path_type type,
|
||||||
char *xpath, size_t xpath_len)
|
char *xpath, size_t xpath_len)
|
||||||
{
|
{
|
||||||
|
|
28
lib/yang.h
28
lib/yang.h
|
@ -186,10 +186,11 @@ extern int yang_snodes_iterate_subtree(const struct lys_node *snode,
|
||||||
void *arg);
|
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
|
* module
|
||||||
* YANG module to operate on.
|
* When set, iterate over all nodes of the specified module only.
|
||||||
*
|
*
|
||||||
* cb
|
* cb
|
||||||
* Function to call with each schema node.
|
* Function to call with each schema node.
|
||||||
|
@ -203,27 +204,8 @@ extern int yang_snodes_iterate_subtree(const struct lys_node *snode,
|
||||||
* Returns:
|
* Returns:
|
||||||
* The return value of the last called callback.
|
* The return value of the last called callback.
|
||||||
*/
|
*/
|
||||||
extern int yang_snodes_iterate_module(const struct lys_module *module,
|
extern int yang_snodes_iterate(const struct lys_module *module,
|
||||||
yang_iterate_cb cb, uint16_t flags,
|
yang_iterate_cb cb, uint16_t flags, void *arg);
|
||||||
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);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Build schema path or data path of the schema node.
|
* Build schema path or data path of the schema node.
|
||||||
|
|
|
@ -469,12 +469,12 @@ static unsigned int yang_translator_validate(struct yang_translator *translator)
|
||||||
args.errors = 0;
|
args.errors = 0;
|
||||||
|
|
||||||
for (ALL_LIST_ELEMENTS_RO(translator->modules, ln, tmodule)) {
|
for (ALL_LIST_ELEMENTS_RO(translator->modules, ln, tmodule)) {
|
||||||
yang_snodes_iterate_module(
|
yang_snodes_iterate(tmodule->module,
|
||||||
tmodule->module, yang_translator_validate_cb,
|
yang_translator_validate_cb,
|
||||||
YANG_ITER_FILTER_NPCONTAINERS
|
YANG_ITER_FILTER_NPCONTAINERS
|
||||||
| YANG_ITER_FILTER_LIST_KEYS
|
| YANG_ITER_FILTER_LIST_KEYS
|
||||||
| YANG_ITER_FILTER_INPUT_OUTPUT,
|
| YANG_ITER_FILTER_INPUT_OUTPUT,
|
||||||
&args);
|
&args);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args.errors)
|
if (args.errors)
|
||||||
|
@ -500,11 +500,11 @@ static unsigned int yang_module_nodes_count(const struct lys_module *module)
|
||||||
{
|
{
|
||||||
unsigned int total = 0;
|
unsigned int total = 0;
|
||||||
|
|
||||||
yang_snodes_iterate_module(module, yang_module_nodes_count_cb,
|
yang_snodes_iterate(module, yang_module_nodes_count_cb,
|
||||||
YANG_ITER_FILTER_NPCONTAINERS
|
YANG_ITER_FILTER_NPCONTAINERS
|
||||||
| YANG_ITER_FILTER_LIST_KEYS
|
| YANG_ITER_FILTER_LIST_KEYS
|
||||||
| YANG_ITER_FILTER_INPUT_OUTPUT,
|
| YANG_ITER_FILTER_INPUT_OUTPUT,
|
||||||
&total);
|
&total);
|
||||||
|
|
||||||
return total;
|
return total;
|
||||||
}
|
}
|
||||||
|
|
|
@ -368,13 +368,12 @@ int main(int argc, char *argv[])
|
||||||
/* Generate callback prototypes. */
|
/* Generate callback prototypes. */
|
||||||
if (!static_cbs) {
|
if (!static_cbs) {
|
||||||
printf("/* prototypes */\n");
|
printf("/* prototypes */\n");
|
||||||
yang_snodes_iterate_module(module->info, generate_prototypes, 0,
|
yang_snodes_iterate(module->info, generate_prototypes, 0, NULL);
|
||||||
NULL);
|
|
||||||
printf("\n");
|
printf("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Generate callback functions. */
|
/* 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,
|
strlcpy(module_name_underscores, module->name,
|
||||||
sizeof(module_name_underscores));
|
sizeof(module_name_underscores));
|
||||||
|
@ -386,7 +385,7 @@ int main(int argc, char *argv[])
|
||||||
"\t.name = \"%s\",\n"
|
"\t.name = \"%s\",\n"
|
||||||
"\t.nodes = {\n",
|
"\t.nodes = {\n",
|
||||||
module_name_underscores, module->name);
|
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"
|
printf("\t\t{\n"
|
||||||
"\t\t\t.xpath = NULL,\n"
|
"\t\t\t.xpath = NULL,\n"
|
||||||
"\t\t},\n");
|
"\t\t},\n");
|
||||||
|
|
|
@ -71,8 +71,8 @@ int main(int argc, char *argv[])
|
||||||
module = yang_module_load(argv[0]);
|
module = yang_module_load(argv[0]);
|
||||||
|
|
||||||
/* Generate deviations. */
|
/* Generate deviations. */
|
||||||
yang_snodes_iterate_module(module->info, generate_yang_deviation,
|
yang_snodes_iterate(module->info, generate_yang_deviation,
|
||||||
YANG_ITER_FILTER_IMPLICIT, NULL);
|
YANG_ITER_FILTER_IMPLICIT, NULL);
|
||||||
|
|
||||||
/* Cleanup and exit. */
|
/* Cleanup and exit. */
|
||||||
yang_terminate();
|
yang_terminate();
|
||||||
|
|
Loading…
Reference in a new issue