Blame include/json_print.h

Packit d3f73b
/*
Packit d3f73b
 * json_print.h		"print regular or json output, based on json_writer".
Packit d3f73b
 *
Packit d3f73b
 *             This program is free software; you can redistribute it and/or
Packit d3f73b
 *             modify it under the terms of the GNU General Public License
Packit d3f73b
 *             as published by the Free Software Foundation; either version
Packit d3f73b
 *             2 of the License, or (at your option) any later version.
Packit d3f73b
 *
Packit d3f73b
 * Authors:    Julien Fortin, <julien@cumulusnetworks.com>
Packit d3f73b
 */
Packit d3f73b
Packit d3f73b
#ifndef _JSON_PRINT_H_
Packit d3f73b
#define _JSON_PRINT_H_
Packit d3f73b
Packit d3f73b
#include "json_writer.h"
Packit d3f73b
#include "color.h"
Packit d3f73b
Packit d3f73b
json_writer_t *get_json_writer(void);
Packit d3f73b
Packit d3f73b
/*
Packit d3f73b
 * use:
Packit d3f73b
 *      - PRINT_ANY for context based output
Packit d3f73b
 *      - PRINT_FP for non json specific output
Packit d3f73b
 *      - PRINT_JSON for json specific output
Packit d3f73b
 */
Packit d3f73b
enum output_type {
Packit d3f73b
	PRINT_FP = 1,
Packit d3f73b
	PRINT_JSON = 2,
Packit d3f73b
	PRINT_ANY = 4,
Packit d3f73b
};
Packit d3f73b
Packit d3f73b
void new_json_obj(int json);
Packit d3f73b
void delete_json_obj(void);
Packit d3f73b
Packit d3f73b
bool is_json_context(void);
Packit d3f73b
Packit d3f73b
void fflush_fp(void);
Packit d3f73b
Packit d3f73b
void open_json_object(const char *str);
Packit d3f73b
void close_json_object(void);
Packit d3f73b
void open_json_array(enum output_type type, const char *delim);
Packit d3f73b
void close_json_array(enum output_type type, const char *delim);
Packit d3f73b
Packit d3f73b
void print_nl(void);
Packit d3f73b
Packit d3f73b
#define _PRINT_FUNC(type_name, type)					\
Packit d3f73b
	void print_color_##type_name(enum output_type t,		\
Packit d3f73b
				     enum color_attr color,		\
Packit d3f73b
				     const char *key,			\
Packit d3f73b
				     const char *fmt,			\
Packit d3f73b
				     type value);			\
Packit d3f73b
									\
Packit d3f73b
	static inline void print_##type_name(enum output_type t,	\
Packit d3f73b
					     const char *key,		\
Packit d3f73b
					     const char *fmt,		\
Packit d3f73b
					     type value)		\
Packit d3f73b
	{								\
Packit d3f73b
		print_color_##type_name(t, COLOR_NONE, key, fmt, value);	\
Packit d3f73b
	}
Packit d3f73b
Packit d3f73b
_PRINT_FUNC(int, int)
Packit d3f73b
_PRINT_FUNC(s64, int64_t)
Packit d3f73b
_PRINT_FUNC(bool, bool)
Packit d3f73b
_PRINT_FUNC(null, const char*)
Packit d3f73b
_PRINT_FUNC(string, const char*)
Packit d3f73b
_PRINT_FUNC(uint, unsigned int)
Packit d3f73b
_PRINT_FUNC(u64, uint64_t)
Packit d3f73b
_PRINT_FUNC(hhu, unsigned char)
Packit d3f73b
_PRINT_FUNC(hu, unsigned short)
Packit d3f73b
_PRINT_FUNC(hex, unsigned int)
Packit d3f73b
_PRINT_FUNC(0xhex, unsigned long long)
Packit d3f73b
_PRINT_FUNC(luint, unsigned long)
Packit d3f73b
_PRINT_FUNC(lluint, unsigned long long)
Packit d3f73b
_PRINT_FUNC(float, double)
Packit d3f73b
#undef _PRINT_FUNC
Packit d3f73b
Packit d3f73b
#endif /* _JSON_PRINT_H_ */