summaryrefslogtreecommitdiffstats
path: root/tools/gen_northbound_callbacks.c
diff options
context:
space:
mode:
authorRafael Zalamena <rzalamena@opensourcerouting.org>2019-07-30 00:30:33 +0200
committerRafael Zalamena <rzalamena@opensourcerouting.org>2019-07-30 20:39:34 +0200
commitc681616f87b4b1571c458a12c4fac6379fd47a13 (patch)
tree0ddb48bf19f643214fc465c69a759b4d5e0be37c /tools/gen_northbound_callbacks.c
parenttools: generate northbound code without warnings (diff)
downloadfrr-c681616f87b4b1571c458a12c4fac6379fd47a13.tar.xz
frr-c681616f87b4b1571c458a12c4fac6379fd47a13.zip
tools: generate code that handles all cases
Help developers to start implementing northbound with more complete callbacks. Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
Diffstat (limited to 'tools/gen_northbound_callbacks.c')
-rw-r--r--tools/gen_northbound_callbacks.c39
1 files changed, 31 insertions, 8 deletions
diff --git a/tools/gen_northbound_callbacks.c b/tools/gen_northbound_callbacks.c
index ade5b3e22..14f648e8d 100644
--- a/tools/gen_northbound_callbacks.c
+++ b/tools/gen_northbound_callbacks.c
@@ -153,6 +153,36 @@ static void generate_callback_name(struct lys_node *snode,
replace_hyphens_by_underscores(buffer);
}
+static void generate_callback(const struct nb_callback_info *ncinfo,
+ const char *cb_name)
+{
+ printf("static %s%s(%s)\n{\n",
+ ncinfo->return_type, cb_name, ncinfo->arguments);
+
+ switch (ncinfo->operation) {
+ case NB_OP_CREATE:
+ case NB_OP_MODIFY:
+ case NB_OP_DESTROY:
+ case NB_OP_MOVE:
+ printf("\tswitch (event) {\n"
+ "\tcase NB_EV_VALIDATE:\n"
+ "\tcase NB_EV_PREPARE:\n"
+ "\tcase NB_EV_ABORT:\n"
+ "\tcase NB_EV_APPLY:\n"
+ "\t\t/* TODO: implement me. */\n"
+ "\t\tbreak;\n"
+ "\t}\n\n"
+ );
+ break;
+
+ default:
+ printf("\t/* TODO: implement me. */\n");
+ break;
+ }
+
+ printf("\treturn %s;\n}\n\n", ncinfo->return_value);
+}
+
static int generate_callbacks(const struct lys_node *snode, void *arg)
{
bool first = true;
@@ -192,14 +222,7 @@ static int generate_callbacks(const struct lys_node *snode, void *arg)
generate_callback_name((struct lys_node *)snode, cb->operation,
cb_name, sizeof(cb_name));
- printf("static %s%s(%s)\n"
- "{\n"
- "\t/* TODO: implement me. */\n"
- "\treturn %s;\n"
- "}\n\n",
- nb_callbacks[cb->operation].return_type, cb_name,
- nb_callbacks[cb->operation].arguments,
- nb_callbacks[cb->operation].return_value);
+ generate_callback(cb, cb_name);
}
return YANG_ITER_CONTINUE;