]> git.proxmox.com Git - mirror_iproute2.git/blob - include/json_print.h
45a817ce6b9a9ac8be363191e2c2564235521b01
[mirror_iproute2.git] / include / json_print.h
1 /*
2 * json_print.h "print regular or json output, based on json_writer".
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version
7 * 2 of the License, or (at your option) any later version.
8 *
9 * Authors: Julien Fortin, <julien@cumulusnetworks.com>
10 */
11
12 #ifndef _JSON_PRINT_H_
13 #define _JSON_PRINT_H_
14
15 #include "json_writer.h"
16 #include "color.h"
17
18 extern int show_pretty;
19
20 json_writer_t *get_json_writer(void);
21
22 /*
23 * use:
24 * - PRINT_ANY for context based output
25 * - PRINT_FP for non json specific output
26 * - PRINT_JSON for json specific output
27 */
28 enum output_type {
29 PRINT_FP = 1,
30 PRINT_JSON = 2,
31 PRINT_ANY = 4,
32 };
33
34 void new_json_obj(int json);
35 void delete_json_obj(void);
36
37 bool is_json_context(void);
38
39 void fflush_fp(void);
40
41 void open_json_object(const char *str);
42 void close_json_object(void);
43 void open_json_array(enum output_type type, const char *delim);
44 void close_json_array(enum output_type type, const char *delim);
45
46 #define _PRINT_FUNC(type_name, type) \
47 void print_color_##type_name(enum output_type t, \
48 enum color_attr color, \
49 const char *key, \
50 const char *fmt, \
51 type value); \
52 \
53 static inline void print_##type_name(enum output_type t, \
54 const char *key, \
55 const char *fmt, \
56 type value) \
57 { \
58 print_color_##type_name(t, COLOR_NONE, key, fmt, value); \
59 }
60 _PRINT_FUNC(int, int);
61 _PRINT_FUNC(bool, bool);
62 _PRINT_FUNC(null, const char*);
63 _PRINT_FUNC(string, const char*);
64 _PRINT_FUNC(uint, uint64_t);
65 _PRINT_FUNC(hu, unsigned short);
66 _PRINT_FUNC(hex, unsigned int);
67 _PRINT_FUNC(0xhex, unsigned int);
68 _PRINT_FUNC(lluint, unsigned long long int);
69 _PRINT_FUNC(float, double);
70 #undef _PRINT_FUNC
71
72 #endif /* _JSON_PRINT_H_ */