Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 1 | /** |
| 2 | * @file printer.h |
| 3 | * @author Radek Krejci <rkrejci@cesnet.cz> |
| 4 | * @brief Printers for libyang |
| 5 | * |
| 6 | * Copyright (c) 2015 CESNET, z.s.p.o. |
| 7 | * |
| 8 | * Redistribution and use in source and binary forms, with or without |
| 9 | * modification, are permitted provided that the following conditions |
| 10 | * are met: |
| 11 | * 1. Redistributions of source code must retain the above copyright |
| 12 | * notice, this list of conditions and the following disclaimer. |
| 13 | * 2. Redistributions in binary form must reproduce the above copyright |
| 14 | * notice, this list of conditions and the following disclaimer in |
| 15 | * the documentation and/or other materials provided with the |
| 16 | * distribution. |
| 17 | * 3. Neither the name of the Company nor the names of its contributors |
| 18 | * may be used to endorse or promote products derived from this |
| 19 | * software without specific prior written permission. |
| 20 | */ |
| 21 | |
| 22 | #ifndef LY_PRINTER_H_ |
| 23 | #define LY_PRINTER_H_ |
| 24 | |
| 25 | #include "libyang.h" |
| 26 | #include "tree_schema.h" |
| 27 | #include "tree_internal.h" |
| 28 | |
| 29 | typedef enum LYOUT_TYPE { |
| 30 | LYOUT_FD, /**< file descriptor */ |
Radek Krejci | 6140e4e | 2015-10-09 15:50:55 +0200 | [diff] [blame] | 31 | LYOUT_STREAM, /**< FILE stream */ |
| 32 | LYOUT_CALLBACK /**< print via provided callback */ |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 33 | } LYOUT_TYPE; |
| 34 | |
| 35 | struct lyout { |
| 36 | LYOUT_TYPE type; |
| 37 | union { |
| 38 | int fd; |
| 39 | FILE *f; |
Radek Krejci | 6140e4e | 2015-10-09 15:50:55 +0200 | [diff] [blame] | 40 | ssize_t (*writeclb)(const void *buf, size_t count); |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 41 | } method; |
| 42 | }; |
| 43 | |
| 44 | /** |
| 45 | * @brief Generic printer, replacement for printf() / write() / etc |
| 46 | */ |
| 47 | int ly_print(struct lyout *out, const char *format, ...); |
| 48 | int ly_write(struct lyout *out, const char *buf, size_t count); |
| 49 | |
| 50 | int yang_print_model(struct lyout *out, struct lys_module *module); |
| 51 | int tree_print_model(struct lyout *out, struct lys_module *module); |
| 52 | int info_print_model(struct lyout *out, struct lys_module *module, const char *target_node); |
| 53 | |
| 54 | int json_print_data(struct lyout *out, struct lyd_node *root); |
Radek Krejci | bac8176 | 2015-10-09 10:19:52 +0200 | [diff] [blame] | 55 | int xml_print_data(struct lyout *out, struct lyd_node *root, int format); |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 56 | |
| 57 | #endif /* LY_PRINTER_H_ */ |