#include "action_list_graphs.h"
#include "graph.h"
+#include "graph_ident.h"
#include "graph_list.h"
#include "utils_params.h"
return (0);
} /* }}} int list_graphs_json */
+struct callback_data_s
+{
+ graph_config_t *cfg;
+};
+typedef struct callback_data_s callback_data_t;
+
static int print_graph_inst_html (graph_config_t *cfg, /* {{{ */
graph_instance_t *inst,
- __attribute__((unused)) void *user_data)
+ void *user_data)
{
+ callback_data_t *data = user_data;
char params[1024];
char desc[1024];
+ if (data->cfg != cfg)
+ {
+ if (data->cfg != NULL)
+ printf (" </ul></li>\n");
+
+ memset (desc, 0, sizeof (desc));
+ graph_get_title (cfg, desc, sizeof (desc));
+
+ printf (" <li>%s\n <ul>\n", desc);
+
+ data->cfg = cfg;
+ }
+
memset (params, 0, sizeof (params));
inst_get_params (cfg, inst, params, sizeof (params));
return (0);
} /* }}} int print_graph_inst_html */
-static int print_graph_html (graph_config_t *cfg, /* {{{ */
- __attribute__((unused)) void *user_data)
-{
- char buffer[1024];
-
- memset (buffer, 0, sizeof (buffer));
- graph_get_title (cfg, buffer, sizeof (buffer));
-
- printf (" <li>%s\n <ul>\n", buffer);
- gl_graph_instance_get_all (cfg, print_graph_inst_html, /* user_data = */ NULL);
- printf (" </ul></li>\n");
-
- return (0);
-} /* }}} int print_graph_html */
-
-static int list_graphs_html (void) /* {{{ */
+static int list_graphs_html (const char *term) /* {{{ */
{
+ callback_data_t data = { NULL };
printf ("Content-Type: text/html\n\n");
printf ("<ul>\n");
- gl_graph_get_all (print_graph_html, /* user_data = */ NULL);
+ if (term == NULL)
+ gl_instance_get_all (print_graph_inst_html, /* user_data = */ &data);
+ else
+ gl_search (term, print_graph_inst_html, /* user_data = */ &data);
+
+ if (data.cfg != NULL)
+ printf (" </ul></li>\n");
+
printf ("</ul>\n");
return (0);
if (strcmp ("json", format) == 0)
return (list_graphs_json ());
else
- return (list_graphs_html ());
+ return (list_graphs_html (param ("search")));
} /* }}} int action_list_graphs */
/* vim: set sw=2 sts=2 et fdm=marker : */
return (ident_matches (cfg->select, ident));
} /* }}} _Bool graph_matches */
+struct graph_search_data_s
+{
+ graph_config_t *cfg;
+ graph_inst_callback_t callback;
+ void *user_data;
+};
+typedef struct graph_search_data_s graph_search_data_t;
+
+static int graph_search_submit (graph_instance_t *inst, /* {{{ */
+ void *user_data)
+{
+ graph_search_data_t *data = user_data;
+
+ if ((inst == NULL) || (data == NULL))
+ return (EINVAL);
+
+ return ((*data->callback) (data->cfg, inst, data->user_data));
+} /* }}} int graph_search_submit */
+
+int graph_search (graph_config_t *cfg, const char *term, /* {{{ */
+ graph_inst_callback_t callback,
+ void *user_data)
+{
+ graph_search_data_t data = { cfg, callback, user_data };
+ char buffer[1024];
+ int status;
+
+ status = graph_get_title (cfg, buffer, sizeof (buffer));
+ if (status != 0)
+ {
+ fprintf (stderr, "graph_search: graph_get_title failed\n");
+ return (status);
+ }
+
+ if (strstr (buffer, term) != NULL)
+ {
+ status = inst_foreach (cfg->instances, graph_search_submit, &data);
+ if (status != 0)
+ return (status);
+ }
+ else
+ {
+ status = inst_search (cfg, cfg->instances, term,
+ graph_search_submit, &data);
+ if (status != 0)
+ return (status);
+ }
+
+ return (0);
+} /* }}} int graph_search */
+
int graph_compare (graph_config_t *cfg, const graph_ident_t *ident) /* {{{ */
{
if ((cfg == NULL) || (ident == NULL))
#ifndef GRAPH_H
#define GRAPH_H 1
-/*
- * Data types
- */
-struct graph_config_s;
-typedef struct graph_config_s graph_config_t;
-
-#include "graph_def.h"
-#include "graph_ident.h"
-#include "graph_instance.h"
+#include "graph_types.h"
#include "oconfig.h"
#include "utils_array.h"
_Bool graph_matches (graph_config_t *cfg, const graph_ident_t *ident);
+int graph_search (graph_config_t *cfg, const char *term,
+ graph_inst_callback_t callback, void *user_data);
+
int graph_compare (graph_config_t *cfg, const graph_ident_t *ident);
int graph_clear_instances (graph_config_t *cfg);
#include "graph_def.h"
#include "graph.h"
#include "graph_config.h"
+#include "graph_ident.h"
#include "common.h"
#include "oconfig.h"
graph_config_get_bool (child, &def->area);
else if (strcasecmp ("Format", child->key) == 0)
graph_config_get_string (child, &def->format);
+#if 0
else
- fprintf (stderr, "def_config: Ignoring unknown config option \"%s\"",
+ fprintf (stderr, "def_config: Ignoring unknown config option \"%s\"\n",
child->key);
+#endif
}
return (graph_add_def (cfg, def));
#ifndef GRAPH_DEF_H
#define GRAPH_DEF_H 1
-struct graph_def_s;
-typedef struct graph_def_s graph_def_t;
-
-typedef int (*def_callback_t) (graph_def_t *def,
- void *user_data);
-
-#include "graph.h"
-#include "graph_ident.h"
+#include "graph_types.h"
#include "utils_array.h"
#include "oconfig.h"
#ifndef GRAPH_IDENT_H
#define GRAPH_IDENT_H 1
+#include "graph_types.h"
+
#define ANY_TOKEN "/any/"
#define ALL_TOKEN "/all/"
#define IS_ANY(str) (((str) != NULL) && (strcasecmp (ANY_TOKEN, (str)) == 0))
#define IS_ALL(str) (((str) != NULL) && (strcasecmp (ALL_TOKEN, (str)) == 0))
-struct graph_ident_s;
-typedef struct graph_ident_s graph_ident_t;
-
graph_ident_t *ident_create (const char *host,
const char *plugin, const char *plugin_instance,
const char *type, const char *type_instance);
const graph_ident_t *i1);
_Bool ident_matches (const graph_ident_t *selector,
- const graph_ident_t *ident);
+ const graph_ident_t *ident);
char *ident_to_string (const graph_ident_t *ident);
char *ident_to_file (const graph_ident_t *ident);
#include <errno.h>
#include "graph_instance.h"
+#include "graph_def.h"
#include "graph_ident.h"
#include "graph_list.h"
#include "common.h"
return (0);
} /* }}} int inst_foreach */
+int inst_search (graph_config_t *cfg, graph_instance_t *inst, /* {{{ */
+ const char *term, inst_callback_t cb, void *user_data)
+{
+ graph_instance_t *ptr;
+ char buffer[1024];
+ int status;
+
+ if ((inst == NULL) || (cb == NULL))
+ return (EINVAL);
+
+ for (ptr = inst; ptr != NULL; ptr = ptr->next)
+ {
+ status = inst_describe (cfg, ptr, buffer, sizeof (buffer));
+ if (status != 0)
+ {
+ fprintf (stderr, "inst_search: inst_describe failed\n");
+ return (status);
+ }
+
+ /* no match */
+ if (strstr (buffer, term) == NULL)
+ continue;
+
+ /* match */
+ status = (*cb) (ptr, user_data);
+ if (status != 0)
+ return (status);
+ }
+
+ return (0);
+} /* }}} int inst_search */
+
graph_instance_t *inst_find_matching (graph_instance_t *inst, /* {{{ */
const graph_ident_t *ident)
{
/*
* Data types
*/
-struct graph_instance_s;
-typedef struct graph_instance_s graph_instance_t;
-
-typedef int (*inst_callback_t) (graph_instance_t *inst, void *user_data);
-
-#include "graph.h"
+#include "graph_types.h"
#include "utils_array.h"
/*
int inst_foreach (graph_instance_t *inst,
inst_callback_t cb, void *user_data);
+int inst_search (graph_config_t *cfg, graph_instance_t *inst,
+ const char *term, inst_callback_t cb,
+ void *user_data);
+
graph_instance_t *inst_find_matching (graph_instance_t *inst,
const graph_ident_t *ident);
return (0);
} /* }}} int graph_config_submit */
-int gl_graph_get_all (gl_cfg_callback callback, /* {{{ */
+int gl_graph_get_all (graph_callback_t callback, /* {{{ */
void *user_data)
{
size_t i;
struct gl_inst_callback_data /* {{{ */
{
graph_config_t *cfg;
- gl_inst_callback callback;
+ graph_inst_callback_t callback;
void *user_data;
}; /* }}} struct gl_inst_callback_data */
} /* }}} int gl_inst_callback_handler */
int gl_graph_instance_get_all (graph_config_t *cfg, /* {{{ */
- gl_inst_callback callback, void *user_data)
+ graph_inst_callback_t callback, void *user_data)
{
struct gl_inst_callback_data data =
{
gl_inst_callback_handler, &data));
} /* }}} int gl_graph_instance_get_all */
-int gl_instance_get_all (gl_inst_callback callback, /* {{{ */
+int gl_instance_get_all (graph_inst_callback_t callback, /* {{{ */
void *user_data)
{
size_t i;
} /* }}} int gl_instance_get_all */
/* }}} gl_instance_get_all, gl_graph_instance_get_all */
+int gl_search (const char *term, graph_inst_callback_t callback, /* {{{ */
+ void *user_data)
+{
+ size_t i;
+
+ for (i = 0; i < gl_active_num; i++)
+ {
+ int status;
+
+ status = graph_search (gl_active[i], term,
+ /* callback = */ callback,
+ /* user data = */ user_data);
+ if (status != 0)
+ return (status);
+ }
+
+ return (0);
+} /* }}} int gl_search */
+
int gl_update (void) /* {{{ */
{
time_t now;
#ifndef GRAPH_LIST_H
#define GRAPH_LIST_H 1
+#include "graph_types.h"
+#include "graph.h"
#include "graph_instance.h"
/*
- * Callback types
- */
-typedef int (*gl_cfg_callback) (graph_config_t *cfg,
- void *user_data);
-
-typedef int (*gl_inst_callback) (graph_config_t *cfg,
- graph_instance_t *inst, void *user_data);
-
-/*
* Functions
*/
int gl_add_graph (graph_config_t *cfg);
int gl_config_submit (void);
-int gl_graph_get_all (gl_cfg_callback callback,
- void *user_data);
-
graph_config_t *gl_graph_get_selected (void);
-int gl_graph_instance_get_all (graph_config_t *cfg,
- gl_inst_callback callback, void *user_data);
+int gl_graph_get_all (graph_callback_t callback, void *user_data);
+
+int gl_graph_instance_get_all (graph_config_t *cfg, graph_inst_callback_t callback,
+ void *user_data);
+
+int gl_instance_get_all (graph_inst_callback_t callback, void *user_data);
-int gl_instance_get_all (gl_inst_callback callback,
+int gl_search (const char *search, graph_inst_callback_t callback,
void *user_data);
int gl_update (void);
--- /dev/null
+#ifndef GRAPH_TYPES_H
+#define GRAPH_TYPES_H 1
+
+/*
+ * Opaque types
+ */
+struct graph_config_s;
+typedef struct graph_config_s graph_config_t;
+
+struct graph_def_s;
+typedef struct graph_def_s graph_def_t;
+
+struct graph_ident_s;
+typedef struct graph_ident_s graph_ident_t;
+
+struct graph_instance_s;
+typedef struct graph_instance_s graph_instance_t;
+
+/*
+ * Callback types
+ */
+typedef int (*graph_callback_t) (graph_config_t *cfg,
+ void *user_data);
+
+typedef int (*graph_inst_callback_t) (graph_config_t *cfg,
+ graph_instance_t *inst, void *user_data);
+
+typedef int (*def_callback_t) (graph_def_t *def,
+ void *user_data);
+
+typedef int (*inst_callback_t) (graph_instance_t *inst,
+ void *user_data);
+
+#endif /* GRAPH_TYPES_H */
+/* vim: set sw=2 sts=2 et fdm=marker : */