summaryrefslogtreecommitdiffstats
path: root/lib/yang.h
diff options
context:
space:
mode:
authorRenato Westphal <renato@opensourcerouting.org>2018-11-03 00:56:26 +0100
committerRenato Westphal <renato@opensourcerouting.org>2018-11-26 20:38:08 +0100
commite0ccfad220d80c1d02b327fd0ee24faf6a8d2bd4 (patch)
treefcfd051fb691b38b615c3c77631dcf4e876060f5 /lib/yang.h
parentlib: introduce function that loads all FRR native YANG modules (diff)
downloadfrr-e0ccfad220d80c1d02b327fd0ee24faf6a8d2bd4.tar.xz
frr-e0ccfad220d80c1d02b327fd0ee24faf6a8d2bd4.zip
lib: rework the yang schema node iteration functions
* Rename yang_snodes_iterate() to yang_snodes_iterate_subtree() and expose it in the public API. * Rename yang_module_snodes_iterate() to yang_snodes_iterate_module(). * Rename yang_all_snodes_iterate() to yang_snodes_iterate_all(). * Make it possible to stop the iteration at any time by returning YANG_ITER_STOP in the iteration callbacks. * Make the iteration callbacks accept only one user argument and not two. Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
Diffstat (limited to 'lib/yang.h')
-rw-r--r--lib/yang.h86
1 files changed, 59 insertions, 27 deletions
diff --git a/lib/yang.h b/lib/yang.h
index aa08654ab..940f5d38e 100644
--- a/lib/yang.h
+++ b/lib/yang.h
@@ -86,14 +86,26 @@ enum yang_path_type {
YANG_PATH_DATA,
};
-/* Filter non-presence containers. */
-#define YANG_ITER_FILTER_NPCONTAINERS 0x0001
-/* Filter list keys (leafs). */
-#define YANG_ITER_FILTER_LIST_KEYS 0x0002
-/* Filter RPC input/output nodes. */
-#define YANG_ITER_FILTER_INPUT_OUTPUT 0x0004
-/* Filter implicitely created nodes. */
-#define YANG_ITER_FILTER_IMPLICIT 0x0008
+enum yang_iter_flags {
+ /* Filter non-presence containers. */
+ YANG_ITER_FILTER_NPCONTAINERS = (1<<0),
+
+ /* Filter list keys (leafs). */
+ YANG_ITER_FILTER_LIST_KEYS = (1<<1),
+
+ /* Filter RPC input/output nodes. */
+ YANG_ITER_FILTER_INPUT_OUTPUT = (1<<2),
+
+ /* Filter implicitely created nodes. */
+ YANG_ITER_FILTER_IMPLICIT = (1<<3),
+};
+
+/* Callback used by the yang_snodes_iterate_*() family of functions. */
+typedef int (*yang_iterate_cb)(const struct lys_node *snode, void *arg);
+
+/* Return values of the 'yang_iterate_cb' callback. */
+#define YANG_ITER_CONTINUE 0
+#define YANG_ITER_STOP -1
/* Global libyang context for native FRR models. */
extern struct ly_ctx *ly_native_ctx;
@@ -141,46 +153,66 @@ extern struct yang_module *yang_module_find(const char *module_name);
extern void yang_module_embed(struct yang_module_embed *embed);
/*
+ * Iterate recursively over all children of a schema node.
+ *
+ * snode
+ * YANG schema node to operate on.
+ *
+ * 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_subtree(const struct lys_node *snode,
+ yang_iterate_cb cb, uint16_t flags,
+ void *arg);
+
+/*
* Iterate over all libyang schema nodes from the given YANG module.
*
* module
* YANG module to operate on.
*
- * func
+ * cb
* Function to call with each schema node.
*
* flags
- * YANG_ITER_FILTER_* flags to specify node types that should be filtered.
+ * YANG_ITER_* flags to control how the iteration is performed.
*
- * arg1
- * Arbitrary argument passed as the second parameter in each call to 'func'.
+ * arg
+ * Arbitrary argument passed as the second parameter in each call to 'cb'.
*
- * arg2
- * Arbitrary argument passed as the third parameter in each call to 'func'.
+ * Returns:
+ * The return value of the last called callback.
*/
-extern void yang_module_snodes_iterate(const struct lys_module *module,
- void (*func)(const struct lys_node *,
- void *, void *),
- uint16_t flags, void *arg1, void *arg2);
+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.
*
- * func
+ * cb
* Function to call with each schema node.
*
* flags
- * YANG_ITER_FILTER_* flags to specify node types that should be filtered.
+ * YANG_ITER_* flags to control how the iteration is performed.
*
- * arg1
- * Arbitrary argument passed as the second parameter in each call to 'func'.
+ * arg
+ * Arbitrary argument passed as the second parameter in each call to 'cb'.
*
- * arg2
- * Arbitrary argument passed as the third parameter in each call to 'func'.
+ * Returns:
+ * The return value of the last called callback.
*/
-extern void yang_all_snodes_iterate(void (*func)(const struct lys_node *,
- void *, void *),
- uint16_t flags, void *arg1, void *arg2);
+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.