summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 37a37e4)
raw | patch | inline | side by side (parent: 37a37e4)
author | Florian Forster <ff@octo.it> | |
Wed, 21 Jul 2010 11:42:02 +0000 (13:42 +0200) | ||
committer | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Wed, 21 Jul 2010 11:42:02 +0000 (13:42 +0200) |
src/graph_list.c | patch | blob | history |
diff --git a/src/graph_list.c b/src/graph_list.c
index d2416f4d4772c9fd07fd48b830a7bbb95b5cbed5..26e182bdc7bd8b6a9f89db82d6395ec50919bfbe 100644 (file)
--- a/src/graph_list.c
+++ b/src/graph_list.c
return (0);
} /* }}} int gl_clear_instances */
+static void gl_dump_cb (void *ctx, /* {{{ */
+ const char *str, unsigned int len)
+{
+ FILE *fh = ctx;
+
+ /* FIXME: Has everything been written? */
+ fwrite ((void *) str, /* size = */ 1, /* nmemb = */ len, fh);
+} /* }}} void gl_dump_cb */
+
+static int gl_dump (void) /* {{{ */
+{
+ FILE *fh;
+ yajl_gen handler;
+ yajl_gen_config handler_config = { /* pretty = */ 1, /* indent = */ " " };
+ size_t i;
+
+ /* FIXME: Lock the file */
+ fh = fopen ("/tmp/collection4.json", "w");
+ if (fh == NULL)
+ return (errno);
+
+ handler = yajl_gen_alloc2 (gl_dump_cb, &handler_config,
+ /* alloc funcs = */ NULL, /* ctx = */ fh);
+ if (handler == NULL)
+ {
+ fclose (fh);
+ return (-1);
+ }
+
+ yajl_gen_array_open (handler);
+
+ for (i = 0; i < gl_active_num; i++)
+ graph_to_json (gl_active[i], handler);
+
+ for (i = 0; i < gl_dynamic_num; i++)
+ graph_to_json (gl_dynamic[i], handler);
+
+ yajl_gen_array_close (handler);
+
+ yajl_gen_free (handler);
+ fclose (fh);
+
+ return (0);
+} /* }}} int gl_dump */
+
/*
* Global functions
*/
for (i = 0; i < gl_active_num; i++)
graph_sort_instances (gl_active[i]);
+ gl_dump ();
+
return (status);
} /* }}} int gl_update */