Skip to content

Commit 6ed821c

Browse files
committed
printer tree UPDATE refactored, without callbacks
1 parent 6cb2e0b commit 6ed821c

File tree

17 files changed

+2859
-3810
lines changed

17 files changed

+2859
-3810
lines changed

src/plugins_exts.c

Lines changed: 0 additions & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -434,133 +434,6 @@ lyplg_ext_print_get_level(const struct lyspr_ctx *ctx)
434434
return &((struct lyspr_ctx *)ctx)->level;
435435
}
436436

437-
LIBYANG_API_DEF LY_ERR
438-
lyplg_ext_sprinter_ctree_add_ext_nodes(const struct lyspr_tree_ctx *ctx, struct lysc_ext_instance *ext,
439-
lyplg_ext_sprinter_ctree_override_clb clb)
440-
{
441-
LY_ERR rc = LY_SUCCESS;
442-
uint32_t i;
443-
struct lysc_node *schema;
444-
445-
LY_CHECK_ARG_RET(NULL, ctx, ext, LY_EINVAL);
446-
447-
LY_ARRAY_FOR(ext->substmts, i) {
448-
switch (ext->substmts[i].stmt) {
449-
case LY_STMT_NOTIFICATION:
450-
case LY_STMT_INPUT:
451-
case LY_STMT_OUTPUT:
452-
case LY_STMT_ACTION:
453-
case LY_STMT_RPC:
454-
case LY_STMT_ANYDATA:
455-
case LY_STMT_ANYXML:
456-
case LY_STMT_CASE:
457-
case LY_STMT_CHOICE:
458-
case LY_STMT_CONTAINER:
459-
case LY_STMT_LEAF:
460-
case LY_STMT_LEAF_LIST:
461-
case LY_STMT_LIST:
462-
schema = *ext->substmts[i].storage_p;
463-
if (schema) {
464-
rc = lyplg_ext_sprinter_ctree_add_nodes(ctx, schema, clb);
465-
return rc;
466-
}
467-
default:
468-
break;
469-
}
470-
}
471-
472-
return rc;
473-
}
474-
475-
LIBYANG_API_DEF LY_ERR
476-
lyplg_ext_sprinter_ptree_add_ext_nodes(const struct lyspr_tree_ctx *ctx, struct lysp_ext_instance *ext,
477-
lyplg_ext_sprinter_ptree_override_clb clb)
478-
{
479-
LY_ERR rc = LY_SUCCESS;
480-
uint32_t i;
481-
struct lysp_node *schema;
482-
483-
LY_CHECK_ARG_RET(NULL, ctx, ext, LY_EINVAL);
484-
485-
LY_ARRAY_FOR(ext->substmts, i) {
486-
switch (ext->substmts[i].stmt) {
487-
case LY_STMT_NOTIFICATION:
488-
case LY_STMT_INPUT:
489-
case LY_STMT_OUTPUT:
490-
case LY_STMT_ACTION:
491-
case LY_STMT_RPC:
492-
case LY_STMT_ANYDATA:
493-
case LY_STMT_ANYXML:
494-
case LY_STMT_CASE:
495-
case LY_STMT_CHOICE:
496-
case LY_STMT_CONTAINER:
497-
case LY_STMT_LEAF:
498-
case LY_STMT_LEAF_LIST:
499-
case LY_STMT_LIST:
500-
schema = *ext->substmts[i].storage_p;
501-
if (schema) {
502-
rc = lyplg_ext_sprinter_ptree_add_nodes(ctx, schema, clb);
503-
return rc;
504-
}
505-
default:
506-
break;
507-
}
508-
}
509-
510-
return rc;
511-
}
512-
513-
LIBYANG_API_DEF LY_ERR
514-
lyplg_ext_sprinter_ctree_add_nodes(const struct lyspr_tree_ctx *ctx, struct lysc_node *nodes,
515-
lyplg_ext_sprinter_ctree_override_clb clb)
516-
{
517-
struct lyspr_tree_schema *new;
518-
519-
LY_CHECK_ARG_RET(NULL, ctx, LY_EINVAL);
520-
521-
if (!nodes) {
522-
return LY_SUCCESS;
523-
}
524-
525-
LY_ARRAY_NEW_RET(NULL, ((struct lyspr_tree_ctx *)ctx)->schemas, new, LY_EMEM);
526-
new->compiled = 1;
527-
new->ctree = nodes;
528-
new->cn_overr = clb;
529-
530-
return LY_SUCCESS;
531-
}
532-
533-
LIBYANG_API_DEF LY_ERR
534-
lyplg_ext_sprinter_ptree_add_nodes(const struct lyspr_tree_ctx *ctx, struct lysp_node *nodes,
535-
lyplg_ext_sprinter_ptree_override_clb clb)
536-
{
537-
struct lyspr_tree_schema *new;
538-
539-
LY_CHECK_ARG_RET(NULL, ctx, LY_EINVAL);
540-
541-
if (!nodes) {
542-
return LY_SUCCESS;
543-
}
544-
545-
LY_ARRAY_NEW_RET(NULL, ((struct lyspr_tree_ctx *)ctx)->schemas, new, LY_EMEM);
546-
new->compiled = 0;
547-
new->ptree = nodes;
548-
new->pn_overr = clb;
549-
550-
return LY_SUCCESS;
551-
}
552-
553-
LIBYANG_API_DEF LY_ERR
554-
lyplg_ext_sprinter_tree_set_priv(const struct lyspr_tree_ctx *ctx, void *plugin_priv, void (*free_clb)(void *plugin_priv))
555-
{
556-
LY_CHECK_ARG_RET(NULL, ctx, LY_EINVAL);
557-
558-
((struct lyspr_tree_ctx *)ctx)->plugin_priv = plugin_priv;
559-
((struct lyspr_tree_ctx *)ctx)->free_plugin_priv = free_clb;
560-
561-
return LY_SUCCESS;
562-
}
563-
564437
LIBYANG_API_DEF int
565438
lyplg_ext_compiled_stmts_storage_size(const struct lysc_ext_substmt *substmts, struct ly_ht *addr_ht)
566439
{

src/plugins_exts.h

Lines changed: 1 addition & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,6 @@ extern "C" {
7777
* [helper functions](@ref pluginsExtensionsSprinterInfo) to access printer's context and to print standard YANG statements
7878
* placed in the extension instance by libyang itself.
7979
*
80-
* The ::lyplg_ext.printer_ctree and ::lyplg_ext.printer_ptree callbacks implement printing of YANG tree diagrams
81-
* (RFC 8340) for extension instance data. These callbacks are called for extension instances that have
82-
* parents of type ::LY_STMT_MODULE, ::LY_STMT_SUBMODULE. Or these callbacks are called if the printer_tree finds
83-
* a compiled/parsed data-node containing an extension instance. The callbacks should then decide which nodes
84-
* should be printed within the extension instance. In addition, it is possible to register additional callbacks
85-
* to the printer_tree context to override the form of the each node in the extension instance.
86-
*
8780
* The last callback, ::lyplg_ext.cfree, is supposed to free all the data allocated by the ::lyplg_ext.compile callback.
8881
* To free the data created by helper function ::lyplg_ext_compile_extension_instance(), the plugin can used
8982
* ::lyplg_ext_cfree_instance_substatements().
@@ -109,7 +102,7 @@ extern "C" {
109102
/**
110103
* @brief Extensions API version
111104
*/
112-
#define LYPLG_EXT_API_VERSION 11
105+
#define LYPLG_EXT_API_VERSION 12
113106

114107
/**
115108
* @brief Mask for an operation statement.
@@ -729,109 +722,6 @@ LIBYANG_API_DECL void lyplg_ext_print_info_extension_instance(struct lyspr_ctx *
729722

730723
/** @} pluginsExtensionsSprinterInfo */
731724

732-
/**
733-
* @defgroup pluginsExtensionsSprinterTree Plugins: Extensions schema parsed and compiled tree printer support
734-
* @ingroup pluginsExtensions
735-
*
736-
* Implementing extension plugin schema parsed and compiled tree printer callback.
737-
*
738-
* @{
739-
*/
740-
741-
/**
742-
* @brief Callback to print parent node of @p ext or to print the contents of the extension.
743-
*
744-
* Function is called in two different cases. If the printer_tree needs the tree-diagram form of a parent node,
745-
* then @p ctx is set to NULL. In the second case, if printer_tree needs to print the contents of the extension,
746-
* then @p ctx is set and function must prepare the nodes that should be printed using the
747-
* lyplg_ext_sprinter_tree* functions.
748-
*
749-
* @param[in] ext Extension instance.
750-
* @param[in,out] ctx Context for the tree printer. Extension contents can be inserted into it by functions
751-
* lyplg_ext_sprinter_ctree_add_ext_nodes(), lyplg_ext_sprinter_ctree_add_nodes() or by their ptree alternatives.
752-
* It parameter is set to NULL, then @p flags and @p add_opts are used by printer_tree.
753-
* @param[out] flags Optional override tree-diagram \<flags\> in a parent node. If @p ctx is set, ignore this parameter.
754-
* @param[out] add_opts Additional tree-diagram \<opts\> string in a parent node which is printed before \<opts\>. If @p ctx
755-
* is set, ignore this parameter.
756-
* @return LY_ERR value.
757-
*/
758-
typedef LY_ERR (*lyplg_ext_sprinter_ctree_clb)(struct lysc_ext_instance *ext, const struct lyspr_tree_ctx *ctx,
759-
const char **flags, const char **add_opts);
760-
761-
/**
762-
* @brief Callback for rewriting the tree-diagram form of a specific node.
763-
*
764-
* If this callback is set, then it is called for each node that belongs to the extension instance.
765-
*
766-
* @param[in] node Node whose tree-diagram form can be modified by the function.
767-
* @param[in,out] plugin_priv Private context set by plugin.
768-
* @param[out] skip Flag set to 1 removes the node from printed diagram.
769-
* @param[out] flags Override tree-diagram \<flags\> string in the @p node.
770-
* @param[out] add_opts Additional tree-diagram \<opts\> string in the @p node which is printed before \<opts\>.
771-
* @return LY_ERR value.
772-
*/
773-
typedef LY_ERR (*lyplg_ext_sprinter_ctree_override_clb)(const struct lysc_node *node, const void *plugin_priv,
774-
ly_bool *skip, const char **flags, const char **add_opts);
775-
776-
/**
777-
* @brief Registration of printing a group of nodes, which is already in the extension.
778-
*
779-
* @param[in] ctx Context of printer_tree in which the group of nodes is saved and later printed.
780-
* @param[in] ext Extension in which the group of nodes will be searched.
781-
* @param[in] clb Override function that will be applied to each delivered node.
782-
* @return LY_ERR value.
783-
*/
784-
LIBYANG_API_DECL LY_ERR lyplg_ext_sprinter_ctree_add_ext_nodes(const struct lyspr_tree_ctx *ctx,
785-
struct lysc_ext_instance *ext, lyplg_ext_sprinter_ctree_override_clb clb);
786-
787-
/**
788-
* @brief Registration of printing the group of nodes which were defined in the plugin.
789-
*
790-
* @param[in] ctx Context of printer_tree in which the group of nodes is saved and later printed.
791-
* @param[in] nodes Points to the first node in group.
792-
* @param[in] clb Override function that will be applied to each delivered node.
793-
* @return LY_ERR value.
794-
*/
795-
LIBYANG_API_DECL LY_ERR lyplg_ext_sprinter_ctree_add_nodes(const struct lyspr_tree_ctx *ctx, struct lysc_node *nodes,
796-
lyplg_ext_sprinter_ctree_override_clb clb);
797-
798-
/**
799-
* @brief Registration of plugin-private data defined by the plugin that is shared between override_clb calls.
800-
*
801-
* @param[in] ctx Context of printer_tree in which plugin-private data will be saved.
802-
* @param[in] plugin_priv Plugin-private data shared between oberride_clb calls.
803-
* @param[in] free_clb Release function for @p plugin_priv.
804-
* @return LY_ERR value.
805-
*/
806-
LIBYANG_API_DECL LY_ERR lyplg_ext_sprinter_tree_set_priv(const struct lyspr_tree_ctx *ctx, void *plugin_priv,
807-
void (*free_clb)(void *plugin_priv));
808-
809-
/**
810-
* @copydoc lyplg_ext_sprinter_ctree_clb
811-
*/
812-
typedef LY_ERR (*lyplg_ext_sprinter_ptree_clb)(struct lysp_ext_instance *ext, const struct lyspr_tree_ctx *ctx,
813-
const char **flags, const char **add_opts);
814-
815-
/**
816-
* @copydoc lyplg_ext_sprinter_ctree_override_clb
817-
*/
818-
typedef LY_ERR (*lyplg_ext_sprinter_ptree_override_clb)(const struct lysp_node *node, const void *plugin_priv,
819-
ly_bool *skip, const char **flags, const char **add_opts);
820-
821-
/**
822-
* @copydoc lyplg_ext_sprinter_ctree_add_ext_nodes
823-
*/
824-
LIBYANG_API_DECL LY_ERR lyplg_ext_sprinter_ptree_add_ext_nodes(const struct lyspr_tree_ctx *ctx,
825-
struct lysp_ext_instance *ext, lyplg_ext_sprinter_ptree_override_clb clb);
826-
827-
/**
828-
* @copydoc lyplg_ext_sprinter_ctree_add_nodes
829-
*/
830-
LIBYANG_API_DECL LY_ERR lyplg_ext_sprinter_ptree_add_nodes(const struct lyspr_tree_ctx *ctx, struct lysp_node *nodes,
831-
lyplg_ext_sprinter_ptree_override_clb clb);
832-
833-
/** @} pluginsExtensionsSprinterTree */
834-
835725
/*
836726
* node xpath
837727
*/
@@ -1077,8 +967,6 @@ struct lyplg_ext {
1077967
lyplg_ext_parse_clb parse; /**< callback to parse the extension instance substatements */
1078968
lyplg_ext_compile_clb compile; /**< callback to compile extension instance from the parsed data */
1079969
lyplg_ext_sprinter_info_clb printer_info; /**< callback to print the compiled content (info format) */
1080-
lyplg_ext_sprinter_ctree_clb printer_ctree; /**< callback to print tree format of a compiled node */
1081-
lyplg_ext_sprinter_ptree_clb printer_ptree; /**< callback to print tree format of a parsed node */
1082970
lyplg_ext_node_xpath_clb node_xpath; /**< callback to get first XPath document root data child node */
1083971
lyplg_ext_snode_xpath_clb snode_xpath; /**< callback to get first XPath document root schema child node */
1084972
lyplg_ext_data_snode_clb snode; /**< callback to get schema node in various use-cases */

src/plugins_exts/metadata.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,6 @@ const struct lyplg_ext_record plugins_metadata[] = {
262262
.plugin.parse = annotation_parse,
263263
.plugin.compile = annotation_compile,
264264
.plugin.printer_info = annotation_printer_info,
265-
.plugin.printer_ctree = NULL,
266-
.plugin.printer_ptree = NULL,
267265
.plugin.node_xpath = NULL,
268266
.plugin.snode_xpath = NULL,
269267
.plugin.snode = NULL,

src/plugins_exts/nacm.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,6 @@ const struct lyplg_ext_record plugins_nacm[] = {
183183
.plugin.parse = nacm_parse,
184184
.plugin.compile = nacm_compile,
185185
.plugin.printer_info = NULL,
186-
.plugin.printer_ctree = NULL,
187-
.plugin.printer_ptree = NULL,
188186
.plugin.node_xpath = NULL,
189187
.plugin.snode_xpath = NULL,
190188
.plugin.snode = NULL,
@@ -202,8 +200,6 @@ const struct lyplg_ext_record plugins_nacm[] = {
202200
.plugin.parse = nacm_parse,
203201
.plugin.compile = nacm_compile,
204202
.plugin.printer_info = NULL,
205-
.plugin.printer_ctree = NULL,
206-
.plugin.printer_ptree = NULL,
207203
.plugin.node_xpath = NULL,
208204
.plugin.snode_xpath = NULL,
209205
.plugin.snode = NULL,
@@ -221,8 +217,6 @@ const struct lyplg_ext_record plugins_nacm[] = {
221217
.plugin.parse = nacm_parse,
222218
.plugin.compile = nacm_compile,
223219
.plugin.printer_info = NULL,
224-
.plugin.printer_ctree = NULL,
225-
.plugin.printer_ptree = NULL,
226220
.plugin.node_xpath = NULL,
227221
.plugin.snode_xpath = NULL,
228222
.plugin.snode = NULL,
@@ -240,8 +234,6 @@ const struct lyplg_ext_record plugins_nacm[] = {
240234
.plugin.parse = nacm_parse,
241235
.plugin.compile = nacm_compile,
242236
.plugin.printer_info = NULL,
243-
.plugin.printer_ctree = NULL,
244-
.plugin.printer_ptree = NULL,
245237
.plugin.node_xpath = NULL,
246238
.plugin.snode_xpath = NULL,
247239
.plugin.snode = NULL,

src/plugins_exts/openconfig.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,6 @@ const struct lyplg_ext_record plugins_openconfig[] = {
169169
.plugin.parse = regexp_posix_parse,
170170
.plugin.compile = NULL,
171171
.plugin.printer_info = NULL,
172-
.plugin.printer_ctree = NULL,
173-
.plugin.printer_ptree = NULL,
174172
.plugin.node_xpath = NULL,
175173
.plugin.snode_xpath = NULL,
176174
.plugin.snode = NULL,
@@ -188,8 +186,6 @@ const struct lyplg_ext_record plugins_openconfig[] = {
188186
.plugin.parse = posix_pattern_parse,
189187
.plugin.compile = posix_pattern_compile,
190188
.plugin.printer_info = NULL,
191-
.plugin.printer_ctree = NULL,
192-
.plugin.printer_ptree = NULL,
193189
.plugin.node_xpath = NULL,
194190
.plugin.snode_xpath = NULL,
195191
.plugin.snode = NULL,

src/plugins_exts/schema_mount.c

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,6 @@ struct lyplg_ext_sm {
6161
} inln; /**< inline mount points */
6262
};
6363

64-
struct sprinter_tree_priv {
65-
struct ly_ctx *ext_ctx;
66-
struct ly_set *refs;
67-
};
68-
6964
#define EXT_LOGERR_MEM_RET(cctx, ext) \
7065
lyplg_ext_compile_log(cctx, ext, LY_LLERR, LY_EMEM, "Memory allocation failed (%s:%d).", __FILE__, __LINE__); \
7166
return LY_EMEM
@@ -1451,38 +1446,6 @@ lyplg_ext_schema_mount_create_context(const struct lysc_ext_instance *ext, const
14511446
return rc;
14521447
}
14531448

1454-
/**
1455-
* @brief Schema mount schema parsed tree printer.
1456-
*
1457-
* Implementation of ::lyplg_ext_sprinter_ptree_clb callback set as lyext_plugin::printer_ptree.
1458-
*/
1459-
static LY_ERR
1460-
schema_mount_sprinter_ptree(struct lysp_ext_instance *UNUSED(ext), const struct lyspr_tree_ctx *ctx,
1461-
const char **flags, const char **UNUSED(add_opts))
1462-
{
1463-
if (!ctx) {
1464-
*flags = "mp";
1465-
}
1466-
1467-
return LY_SUCCESS;
1468-
}
1469-
1470-
/**
1471-
* @brief Schema mount schema compiled tree printer.
1472-
*
1473-
* Implementation of ::lyplg_ext_sprinter_ctree_clb callback set as lyext_plugin::printer_ctree.
1474-
*/
1475-
static LY_ERR
1476-
schema_mount_sprinter_ctree(struct lysc_ext_instance *UNUSED(ext), const struct lyspr_tree_ctx *ctx,
1477-
const char **flags, const char **UNUSED(add_opts))
1478-
{
1479-
if (!ctx) {
1480-
*flags = "mp";
1481-
}
1482-
1483-
return LY_SUCCESS;
1484-
}
1485-
14861449
static int
14871450
schema_mount_compiled_size(const struct lysc_ext_instance *ext, struct ly_ht *addr_ht)
14881451
{
@@ -1596,8 +1559,6 @@ const struct lyplg_ext_record plugins_schema_mount[] = {
15961559
.plugin.parse = schema_mount_parse,
15971560
.plugin.compile = schema_mount_compile,
15981561
.plugin.printer_info = NULL,
1599-
.plugin.printer_ctree = schema_mount_sprinter_ctree,
1600-
.plugin.printer_ptree = schema_mount_sprinter_ptree,
16011562
.plugin.node_xpath = NULL,
16021563
.plugin.snode_xpath = schema_mount_snode_xpath,
16031564
.plugin.snode = schema_mount_snode,

0 commit comments

Comments
 (0)