summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 3791b9f)
raw | patch | inline | side by side (parent: 3791b9f)
author | Florian Forster <octo@verplant.org> | |
Wed, 8 Sep 2010 08:44:54 +0000 (10:44 +0200) | ||
committer | Florian Forster <octo@verplant.org> | |
Wed, 8 Sep 2010 08:44:54 +0000 (10:44 +0200) |
src/graph_def.c | patch | blob | history | |
src/graph_def.h | patch | blob | history |
diff --git a/src/graph_def.c b/src/graph_def.c
index b3589059a5b3b57f6bb24c436152f0356e4563fc..7ac8dac51920fa2b7f70f87a2155fade131d2684 100644 (file)
--- a/src/graph_def.c
+++ b/src/graph_def.c
return (def);
} /* }}} graph_def_t *def_config_get_obj */
+static int def_to_json_recursive (const graph_def_t *def, /* {{{ */
+ yajl_gen handler)
+{
+ char color[16];
+
+ if (def == NULL)
+ return (0);
+
+ snprintf (color, sizeof (color), "%06"PRIx32, def->color);
+ color[sizeof (color) - 1] = 0;
+
+ yajl_gen_map_open (handler);
+
+#define yajl_gen_string_cast(h,p,l) \
+ yajl_gen_string (h, (unsigned char *) p, (unsigned int) l)
+
+ yajl_gen_string_cast (handler, "select", strlen ("select"));
+ ident_to_json (def->select, handler);
+ yajl_gen_string_cast (handler, "ds_name", strlen ("ds_name"));
+ yajl_gen_string_cast (handler, def->ds_name, strlen (def->ds_name));
+ yajl_gen_string_cast (handler, "legend", strlen ("legend"));
+ yajl_gen_string_cast (handler, def->legend, strlen (def->legend));
+ yajl_gen_string_cast (handler, "color", strlen ("color"));
+ yajl_gen_string_cast (handler, color, strlen (color));
+ yajl_gen_string_cast (handler, "stack", strlen ("stack"));
+ yajl_gen_bool (handler, def->stack);
+ yajl_gen_string_cast (handler, "area", strlen ("area"));
+ yajl_gen_bool (handler, def->area);
+ yajl_gen_string_cast (handler, "format", strlen ("format"));
+ yajl_gen_string_cast (handler, def->format, strlen (def->format));
+
+ yajl_gen_map_close (handler);
+
+ return (def_to_json_recursive (def->next, handler));
+} /* }}} int def_to_json_recursive */
+
/*
* Public functions
*/
return (0);
} /* }}} int def_get_rrdargs */
+int def_to_json (const graph_def_t *def, /* {{{ */
+ yajl_gen handler)
+{
+ if (handler == NULL)
+ return (EINVAL);
+
+ yajl_gen_array_open (handler);
+ def_to_json_recursive (def, handler);
+ yajl_gen_array_close (handler);
+
+ return (0);
+} /* }}} int def_to_json */
+
/* vim: set sw=2 sts=2 et fdm=marker : */
diff --git a/src/graph_def.h b/src/graph_def.h
index 7c3e9feab9d52f4abfbb0cd53e5d9c9342f24efb..ed9a24c11b28ed800466fbf94a23b8d009cdff2f 100644 (file)
--- a/src/graph_def.h
+++ b/src/graph_def.h
#ifndef GRAPH_DEF_H
#define GRAPH_DEF_H 1
+#include <yajl/yajl_gen.h>
+
#include "graph_types.h"
#include "utils_array.h"
#include "oconfig.h"
int def_get_rrdargs (graph_def_t *def, graph_ident_t *ident,
rrd_args_t *args);
+int def_to_json (const graph_def_t *def, yajl_gen handler);
+
/* vim: set sw=2 sts=2 et fdm=marker : */
#endif