summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 8b73a51)
raw | patch | inline | side by side (parent: 8b73a51)
author | Florian Forster <ff@octo.it> | |
Wed, 21 Jul 2010 09:30:14 +0000 (11:30 +0200) | ||
committer | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Wed, 21 Jul 2010 09:30:14 +0000 (11:30 +0200) |
src/graph.c | patch | blob | history | |
src/graph.h | patch | blob | history |
diff --git a/src/graph.c b/src/graph.c
index 92fa02aaeb181f97fad0511034c923127546dfde..f664be1367adacda63196ff4d511006fabe48b5e 100644 (file)
--- a/src/graph.c
+++ b/src/graph.c
return (ident_compare (cfg->select, ident));
} /* }}} int graph_compare */
-static int graph_sort_instances_cb (const void *v0, const void *v1) /* {{{ */
-{
- return (inst_compare (*(graph_instance_t * const *) v0,
- *(graph_instance_t * const *) v1));
-} /* }}} int graph_sort_instances_cb */
-
size_t graph_num_instances (graph_config_t *cfg) /* {{{ */
{
if (cfg == NULL)
return (cfg->instances_num);
} /* }}} size_t graph_num_instances */
+int graph_to_json (const graph_config_t *cfg,
+ yajl_gen handler)
+{
+ size_t i;
+
+ if ((cfg == NULL) || (handler == NULL))
+ return (EINVAL);
+
+ yajl_gen_map_open (handler);
+ yajl_gen_string (handler,
+ (unsigned char *) "select",
+ (unsigned int) strlen ("select"));
+ ident_to_json (cfg->select, handler);
+ yajl_gen_array_open (handler);
+ for (i = 0; i < cfg->instances_num; i++)
+ inst_to_json (cfg->instances[i], handler);
+ yajl_gen_array_close (handler);
+ yajl_gen_map_close (handler);
+
+ return (0);
+}
+
+static int graph_sort_instances_cb (const void *v0, const void *v1) /* {{{ */
+{
+ return (inst_compare (*(graph_instance_t * const *) v0,
+ *(graph_instance_t * const *) v1));
+} /* }}} int graph_sort_instances_cb */
+
int graph_sort_instances (graph_config_t *cfg) /* {{{ */
{
if (cfg == NULL)
diff --git a/src/graph.h b/src/graph.h
index 7dca2cedb5755d31c93cc07c1a67bd59cc569cc7..0c4ff76b2e8ea14d3d0d94cc6b6371c0b8dcb044 100644 (file)
--- a/src/graph.h
+++ b/src/graph.h
#ifndef GRAPH_H
#define GRAPH_H 1
+#include <yajl/yajl_gen.h>
+
#include "graph_types.h"
#include "graph_ident.h"
#include "oconfig.h"
int graph_compare (graph_config_t *cfg, const graph_ident_t *ident);
+int graph_to_json (const graph_config_t *cfg, yajl_gen handler);
+
size_t graph_num_instances (graph_config_t *cfg);
int graph_sort_instances (graph_config_t *cfg);