blob: dc4d2bb3ba59a70e8eeeb2e8be9228dbcab245c2 [file] [log] [blame]
Daniel Borkmann0b4b35e2017-09-21 10:42:28 +02001/*
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
18json_writer_t *get_json_writer(void);
19
20/*
21 * use:
22 * - PRINT_ANY for context based output
23 * - PRINT_FP for non json specific output
24 * - PRINT_JSON for json specific output
25 */
26enum output_type {
27 PRINT_FP = 1,
28 PRINT_JSON = 2,
29 PRINT_ANY = 4,
30};
31
Julien Fortin429f3142017-09-26 16:45:39 -070032void new_json_obj(int json);
Daniel Borkmann0b4b35e2017-09-21 10:42:28 +020033void delete_json_obj(void);
34
35bool is_json_context(void);
36
Daniel Borkmann0b4b35e2017-09-21 10:42:28 +020037void fflush_fp(void);
38
39void open_json_object(const char *str);
40void close_json_object(void);
41void open_json_array(enum output_type type, const char *delim);
42void close_json_array(enum output_type type, const char *delim);
43
44#define _PRINT_FUNC(type_name, type) \
45 void print_color_##type_name(enum output_type t, \
46 enum color_attr color, \
47 const char *key, \
48 const char *fmt, \
49 type value); \
50 \
51 static inline void print_##type_name(enum output_type t, \
52 const char *key, \
53 const char *fmt, \
54 type value) \
55 { \
Petr Vorel4b73d522017-10-13 15:57:19 +020056 print_color_##type_name(t, COLOR_NONE, key, fmt, value); \
Daniel Borkmann0b4b35e2017-09-21 10:42:28 +020057 }
58_PRINT_FUNC(int, int);
59_PRINT_FUNC(bool, bool);
60_PRINT_FUNC(null, const char*);
61_PRINT_FUNC(string, const char*);
62_PRINT_FUNC(uint, uint64_t);
63_PRINT_FUNC(hu, unsigned short);
64_PRINT_FUNC(hex, unsigned int);
65_PRINT_FUNC(0xhex, unsigned int);
66_PRINT_FUNC(lluint, unsigned long long int);
67#undef _PRINT_FUNC
68
69#endif /* _JSON_PRINT_H_ */