From: Florian Forster Date: Wed, 21 Jul 2010 09:29:50 +0000 (+0200) Subject: src/graph_instance.[ch]: Implement "inst_to_json". X-Git-Tag: v4.0.0~83 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=8b73a514dab80ddf78435b9f80c1113aac384224;p=collection4.git src/graph_instance.[ch]: Implement "inst_to_json". --- diff --git a/src/graph_instance.c b/src/graph_instance.c index 89fdcfb..5ca8c66 100644 --- a/src/graph_instance.c +++ b/src/graph_instance.c @@ -534,6 +534,32 @@ _Bool inst_matches_field (graph_instance_t *inst, /* {{{ */ return (0); } /* }}} _Bool inst_matches_field */ +int inst_to_json (const graph_instance_t *inst, /* {{{ */ + yajl_gen handler) +{ + size_t i; + + if ((inst == NULL) || (handler == NULL)) + return (EINVAL); + + /* TODO: error handling */ + yajl_gen_map_open (handler); + yajl_gen_string (handler, + (unsigned char *) "select", + (unsigned int) strlen ("select")); + ident_to_json (inst->select, handler); + yajl_gen_string (handler, + (unsigned char *) "files", + (unsigned int) strlen ("files")); + yajl_gen_array_open (handler); + for (i = 0; i < inst->files_num; i++) + ident_to_json (inst->files[i], handler); + yajl_gen_array_close (handler); + yajl_gen_map_close (handler); + + return (0); +} /* }}} int inst_to_json */ + int inst_describe (graph_config_t *cfg, graph_instance_t *inst, /* {{{ */ char *buffer, size_t buffer_size) { diff --git a/src/graph_instance.h b/src/graph_instance.h index 249fe4d..5a9cd47 100644 --- a/src/graph_instance.h +++ b/src/graph_instance.h @@ -26,6 +26,8 @@ #include +#include + #include "graph_types.h" #include "graph_ident.h" #include "rrd_args.h" @@ -77,6 +79,8 @@ _Bool inst_matches_string (graph_config_t *cfg, graph_instance_t *inst, _Bool inst_matches_field (graph_instance_t *inst, graph_ident_field_t field, const char *field_value); +int inst_to_json (const graph_instance_t *inst, yajl_gen handler); + int inst_describe (graph_config_t *cfg, graph_instance_t *inst, char *buffer, size_t buffer_size);