Radek Krejci | f8d7f9a | 2021-03-10 14:32:36 +0100 | [diff] [blame] | 1 | /** |
| 2 | * @file plugins_exts_print.h |
| 3 | * @author Radek Krejci <rkrejci@cesnet.cz> |
| 4 | * @brief libyang support for YANG extensions implementation - schema print related items. |
| 5 | * |
| 6 | * Copyright (c) 2015 - 2021 CESNET, z.s.p.o. |
| 7 | * |
| 8 | * This source code is licensed under BSD 3-Clause License (the "License"). |
| 9 | * You may not use this file except in compliance with the License. |
| 10 | * You may obtain a copy of the License at |
| 11 | * |
| 12 | * https://opensource.org/licenses/BSD-3-Clause |
| 13 | */ |
| 14 | |
| 15 | #ifndef LY_PLUGINS_EXTS_PRINT_H_ |
| 16 | #define LY_PLUGINS_EXTS_PRINT_H_ |
| 17 | |
| 18 | #include <stdint.h> |
| 19 | |
Jan Kundrát | c53a7ec | 2021-12-09 16:01:19 +0100 | [diff] [blame] | 20 | #include "config.h" |
| 21 | |
Radek Krejci | f8d7f9a | 2021-03-10 14:32:36 +0100 | [diff] [blame] | 22 | #ifdef __cplusplus |
| 23 | extern "C" { |
| 24 | #endif |
| 25 | |
| 26 | /** |
Radek Krejci | 7510412 | 2021-04-01 15:37:45 +0200 | [diff] [blame] | 27 | * @defgroup pluginsExtensionsPrint Plugins: Extensions printer support |
| 28 | * @ingroup pluginsExtensions |
| 29 | * |
| 30 | * Helper functions to implement extension plugin's sprinter callback. |
Radek Krejci | f8d7f9a | 2021-03-10 14:32:36 +0100 | [diff] [blame] | 31 | * |
| 32 | * @{ |
| 33 | */ |
| 34 | |
| 35 | /** |
Radek Krejci | 0b01330 | 2021-03-29 15:22:32 +0200 | [diff] [blame] | 36 | * @brief YANG printer context for use in ::lyplg_ext_schema_printer_clb callback implementation. |
Radek Krejci | f8d7f9a | 2021-03-10 14:32:36 +0100 | [diff] [blame] | 37 | * |
| 38 | * The structure provides basic information how the compiled schema is supposed to be printed and where. In the most simple |
| 39 | * case, the provided context is just passed into ::lysc_print_extension_instance() function which handles printing the |
| 40 | * extension's substatements in the standard way. |
| 41 | * |
| 42 | * To access various items from the context, use some of the following lys_ypr_ctx_get_* getters. |
| 43 | */ |
| 44 | struct lyspr_ctx; |
| 45 | |
| 46 | /** |
| 47 | * @brief YANG printer context getter for output handler. |
| 48 | * @param[in] ctx YANG printer context. |
| 49 | * @return Output handler where the data are being printed. Note that the address of the handler pointer in the context is |
| 50 | * returned to allow to modify the handler. |
| 51 | */ |
Jan Kundrát | c53a7ec | 2021-12-09 16:01:19 +0100 | [diff] [blame] | 52 | LIBYANG_API_DECL struct ly_out **lys_ypr_ctx_get_out(const struct lyspr_ctx *ctx); |
Radek Krejci | f8d7f9a | 2021-03-10 14:32:36 +0100 | [diff] [blame] | 53 | |
| 54 | /** |
| 55 | * @brief YANG printer context getter for printer options. |
| 56 | * @param[in] ctx YANG printer context. |
| 57 | * @return pointer to the printer options to allow modifying them with @ref schemaprinterflags values. |
| 58 | */ |
Jan Kundrát | c53a7ec | 2021-12-09 16:01:19 +0100 | [diff] [blame] | 59 | LIBYANG_API_DECL uint32_t *lys_ypr_ctx_get_options(const struct lyspr_ctx *ctx); |
Radek Krejci | f8d7f9a | 2021-03-10 14:32:36 +0100 | [diff] [blame] | 60 | |
| 61 | /** |
| 62 | * @brief YANG printer context getter for printer indentation level. |
| 63 | * @param[in] ctx YANG printer context. |
| 64 | * @return pointer to the printer's indentation level to allow modifying its value. |
| 65 | */ |
Jan Kundrát | c53a7ec | 2021-12-09 16:01:19 +0100 | [diff] [blame] | 66 | LIBYANG_API_DECL uint16_t *lys_ypr_ctx_get_level(const struct lyspr_ctx *ctx); |
Radek Krejci | f8d7f9a | 2021-03-10 14:32:36 +0100 | [diff] [blame] | 67 | |
| 68 | /** |
| 69 | * @brief Print substatements of an extension instance |
| 70 | * |
Radek Krejci | 0b01330 | 2021-03-29 15:22:32 +0200 | [diff] [blame] | 71 | * Generic function to access YANG printer functions from the extension plugins (::lyplg_ext_schema_printer_clb). |
Radek Krejci | f8d7f9a | 2021-03-10 14:32:36 +0100 | [diff] [blame] | 72 | * |
| 73 | * @param[in] ctx YANG printer context to provide output handler and other information for printing. |
| 74 | * @param[in] ext The compiled extension instance to access the extensions and substatements data. |
| 75 | * @param[in, out] flag Flag to be shared with the caller regarding the opening brackets - 0 if the '{' not yet printed, |
| 76 | * 1 otherwise. |
| 77 | */ |
Jan Kundrát | c53a7ec | 2021-12-09 16:01:19 +0100 | [diff] [blame] | 78 | LIBYANG_API_DECL void lysc_print_extension_instance(struct lyspr_ctx *ctx, const struct lysc_ext_instance *ext, ly_bool *flag); |
Radek Krejci | f8d7f9a | 2021-03-10 14:32:36 +0100 | [diff] [blame] | 79 | |
Radek Krejci | 7510412 | 2021-04-01 15:37:45 +0200 | [diff] [blame] | 80 | /** @} pluginsExtensionsPrint */ |
Radek Krejci | f8d7f9a | 2021-03-10 14:32:36 +0100 | [diff] [blame] | 81 | |
| 82 | #ifdef __cplusplus |
| 83 | } |
| 84 | #endif |
| 85 | |
| 86 | #endif /* LY_PLUGINS_EXTS_PRINT_H_ */ |