2 * collection4 - action_show_graph_json.c
3 * Copyright (C) 2010 Florian octo Forster
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301 USA
21 * Florian octo Forster <ff at octo.it>
32 #include "action_show_graph_json.h"
35 #include "graph_ident.h"
36 #include "graph_instance.h"
37 #include "graph_list.h"
38 #include "utils_cgi.h"
41 #include <fcgi_stdio.h>
43 struct show_graph_data_s
48 typedef struct show_graph_data_s show_graph_data_t;
50 static int show_instance_cb (graph_instance_t *inst, /* {{{ */
53 show_graph_data_t *data = user_data;
57 ident = inst_get_selector (inst);
61 ident_json = ident_to_json (ident);
62 if (ident_json == NULL)
64 ident_destroy (ident);
72 printf (" %s", ident_json);
75 ident_destroy (ident);
77 } /* }}} int show_instance_cb */
79 int action_show_graph_json (void) /* {{{ */
81 show_graph_data_t data;
86 memset (&data, 0, sizeof (data));
88 data.cfg = gl_graph_get_selected ();
92 ident = graph_get_selector (data.cfg);
96 ident_json = ident_to_json (ident);
97 if (ident_json == NULL)
99 ident_destroy (ident);
103 printf ("Content-Type: text/plain\n\n");
105 memset (title, 0, sizeof (title));
106 graph_get_title (data.cfg, title, sizeof (title));
107 json_escape_buffer (title, sizeof (title));
110 printf (" \"title\": \"%s\",\n", title);
111 printf (" \"selector\": %s,\n", ident_json);
112 printf (" \"instances\":\n");
114 graph_inst_foreach (data.cfg, show_instance_cb, &data);
115 printf ("\n ]\n}\n");
118 ident_destroy (ident);
120 } /* }}} int action_show_graph_json */
122 /* vim: set sw=2 sts=2 et fdm=marker : */