mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-08-08 07:27:50 +00:00
tools: update the northbound callbacks generator
Add a new '-s' option which controls whether the generated northbound callbacks are declared with the 'static' specifier or not. If not (the default), a prototype is generated for each callback before their declarations. It's suggested that daemons shouldn't use the '-s' option so that their northbound callbacks can be implemented in different files according to their class (config, state, rpc or notification). libfrr commands, on the other hand, can use the '-s' option when their associated YANG module is too small and putting all callbacks in the same file is desirable. Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
This commit is contained in:
parent
6c57402944
commit
f5f0a0e302
@ -26,10 +26,12 @@
|
|||||||
#include "yang.h"
|
#include "yang.h"
|
||||||
#include "northbound.h"
|
#include "northbound.h"
|
||||||
|
|
||||||
|
static bool static_cbs;
|
||||||
|
|
||||||
static void __attribute__((noreturn)) usage(int status)
|
static void __attribute__((noreturn)) usage(int status)
|
||||||
{
|
{
|
||||||
extern const char *__progname;
|
extern const char *__progname;
|
||||||
fprintf(stderr, "usage: %s [-h] [-p path] MODULE\n", __progname);
|
fprintf(stderr, "usage: %s [-h] [-s] [-p path] MODULE\n", __progname);
|
||||||
exit(status);
|
exit(status);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -153,10 +155,46 @@ static void generate_callback_name(struct lys_node *snode,
|
|||||||
replace_hyphens_by_underscores(buffer);
|
replace_hyphens_by_underscores(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void generate_prototype(const struct nb_callback_info *ncinfo,
|
||||||
|
const char *cb_name)
|
||||||
|
{
|
||||||
|
printf("%s%s(%s);\n", ncinfo->return_type, cb_name, ncinfo->arguments);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int generate_prototypes(const struct lys_node *snode, void *arg)
|
||||||
|
{
|
||||||
|
switch (snode->nodetype) {
|
||||||
|
case LYS_CONTAINER:
|
||||||
|
case LYS_LEAF:
|
||||||
|
case LYS_LEAFLIST:
|
||||||
|
case LYS_LIST:
|
||||||
|
case LYS_NOTIF:
|
||||||
|
case LYS_RPC:
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return YANG_ITER_CONTINUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (struct nb_callback_info *cb = &nb_callbacks[0];
|
||||||
|
cb->operation != -1; cb++) {
|
||||||
|
char cb_name[BUFSIZ];
|
||||||
|
|
||||||
|
if (cb->optional
|
||||||
|
|| !nb_operation_is_valid(cb->operation, snode))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
generate_callback_name((struct lys_node *)snode, cb->operation,
|
||||||
|
cb_name, sizeof(cb_name));
|
||||||
|
generate_prototype(cb, cb_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
return YANG_ITER_CONTINUE;
|
||||||
|
}
|
||||||
|
|
||||||
static void generate_callback(const struct nb_callback_info *ncinfo,
|
static void generate_callback(const struct nb_callback_info *ncinfo,
|
||||||
const char *cb_name)
|
const char *cb_name)
|
||||||
{
|
{
|
||||||
printf("static %s%s(%s)\n{\n",
|
printf("%s%s%s(%s)\n{\n", static_cbs ? "static " : "",
|
||||||
ncinfo->return_type, cb_name, ncinfo->arguments);
|
ncinfo->return_type, cb_name, ncinfo->arguments);
|
||||||
|
|
||||||
switch (ncinfo->operation) {
|
switch (ncinfo->operation) {
|
||||||
@ -287,7 +325,7 @@ int main(int argc, char *argv[])
|
|||||||
struct stat st;
|
struct stat st;
|
||||||
int opt;
|
int opt;
|
||||||
|
|
||||||
while ((opt = getopt(argc, argv, "hp:")) != -1) {
|
while ((opt = getopt(argc, argv, "hp:s")) != -1) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 'h':
|
case 'h':
|
||||||
usage(EXIT_SUCCESS);
|
usage(EXIT_SUCCESS);
|
||||||
@ -307,6 +345,9 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
search_path = optarg;
|
search_path = optarg;
|
||||||
break;
|
break;
|
||||||
|
case 's':
|
||||||
|
static_cbs = true;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
usage(EXIT_FAILURE);
|
usage(EXIT_FAILURE);
|
||||||
/* NOTREACHED */
|
/* NOTREACHED */
|
||||||
@ -332,6 +373,14 @@ int main(int argc, char *argv[])
|
|||||||
/* Create a nb_node for all YANG schema nodes. */
|
/* Create a nb_node for all YANG schema nodes. */
|
||||||
nb_nodes_create();
|
nb_nodes_create();
|
||||||
|
|
||||||
|
/* Generate callback prototypes. */
|
||||||
|
if (!static_cbs) {
|
||||||
|
printf("/* prototypes */\n");
|
||||||
|
yang_snodes_iterate_module(module->info, generate_prototypes, 0,
|
||||||
|
NULL);
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
|
||||||
/* Generate callback functions. */
|
/* Generate callback functions. */
|
||||||
yang_snodes_iterate_module(module->info, generate_callbacks, 0, NULL);
|
yang_snodes_iterate_module(module->info, generate_callbacks, 0, NULL);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user