src/graph_instance.[ch]: Implement "inst_to_json".
authorFlorian Forster <ff@octo.it>
Wed, 21 Jul 2010 09:29:50 +0000 (11:29 +0200)
committerFlorian Forster <octo@leeloo.lan.home.verplant.org>
Wed, 21 Jul 2010 09:29:50 +0000 (11:29 +0200)
src/graph_instance.c
src/graph_instance.h

index 89fdcfb..5ca8c66 100644 (file)
@@ -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)
 {
index 249fe4d..5a9cd47 100644 (file)
@@ -26,6 +26,8 @@
 
 #include <time.h>
 
+#include <yajl/yajl_gen.h>
+
 #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);