+_Bool inst_matches_field (graph_instance_t *inst, /* {{{ */
+ graph_ident_field_t field, const char *field_value)
+{
+ const char *selector_field;
+ size_t i;
+
+ if ((inst == NULL) || (field_value == NULL))
+ return (0);
+
+ selector_field = ident_get_field (inst->select, field);
+ if (selector_field == NULL)
+ return (0);
+
+ assert (!IS_ANY (selector_field));
+ if (!IS_ALL (selector_field))
+ {
+ if (strcasecmp (selector_field, field_value) == 0)
+ return (1);
+ else
+ return (0);
+ }
+
+ /* The selector field is an ALL selector
+ * => we need to check the files to see if the instance matches. */
+ for (i = 0; i < inst->files_num; i++)
+ {
+ selector_field = ident_get_field (inst->files[i], field);
+ if (selector_field == NULL)
+ continue;
+
+ assert (!IS_ANY (selector_field));
+ assert (!IS_ALL (selector_field));
+
+ if (strcasecmp (selector_field, field_value) == 0)
+ return (1);
+ } /* for files */
+
+ 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_data_to_json (const graph_instance_t *inst, /* {{{ */
+ dp_time_t begin, dp_time_t end, dp_time_t res,
+ yajl_gen handler)
+{
+ size_t i;
+
+ yajl_gen_array_open (handler);
+ for (i = 0; i < inst->files_num; i++)
+ ident_data_to_json (inst->files[i], begin, end, res, handler);
+ yajl_gen_array_close (handler);
+
+ return (0);
+} /* }}} int inst_data_to_json */
+