summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 8fbf7a3)
raw | patch | inline | side by side (parent: 8fbf7a3)
author | Florian Forster <ff@octo.it> | |
Tue, 15 Jun 2010 17:26:36 +0000 (19:26 +0200) | ||
committer | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Tue, 15 Jun 2010 17:26:36 +0000 (19:26 +0200) |
action_list_graphs.c | patch | blob | history | |
graph.c | patch | blob | history | |
graph.h | patch | blob | history | |
graph_def.c | patch | blob | history | |
graph_def.h | patch | blob | history | |
graph_ident.h | patch | blob | history | |
graph_instance.c | patch | blob | history | |
graph_instance.h | patch | blob | history | |
graph_list.c | patch | blob | history | |
graph_list.h | patch | blob | history | |
graph_types.h | [new file with mode: 0644] | patch | blob |
diff --git a/action_list_graphs.c b/action_list_graphs.c
index 29e3d8b887839b3c3424578280e38e68e89c691a..08d0eb49acac11af0bfb543bd037fb5ba593a9c4 100644 (file)
--- a/action_list_graphs.c
+++ b/action_list_graphs.c
#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 : */
index 1a8f327a13f992b4cbe8aa33ff07c798ec9a4b22..2809ebbe0b65f8a386e4dce4c8dfeffe40949a21 100644 (file)
--- a/graph.c
+++ b/graph.c
@@ -250,6 +250,57 @@ _Bool graph_matches (graph_config_t *cfg, const graph_ident_t *ident) /* {{{ */
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))
index 6e9ae07fb0e2cb03e459173bd3d6030c3d4c15ba..57a866f996cc090c2e392adb62b8f8be1c8d1b71 100644 (file)
--- a/graph.h
+++ b/graph.h
#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);
diff --git a/graph_def.c b/graph_def.c
index 4ea09661373f01224ba38ec24a61ead348201e77..a9ae806615926f79f43ceb4d50280f49c3afab08 100644 (file)
--- a/graph_def.c
+++ b/graph_def.c
#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));
diff --git a/graph_def.h b/graph_def.h
index b2cd2282c50a909d44aec56bb06cf9cf9fa2c8d3..a4bb7fde579b6844f3b691894de4d628f072abe3 100644 (file)
--- a/graph_def.h
+++ b/graph_def.h
#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"
diff --git a/graph_ident.h b/graph_ident.h
index 5107011ed3dec9d9848ee874895c3cdf32df9bd5..03a3c7212a06c3dde659959216dba3f8c81e64e8 100644 (file)
--- a/graph_ident.h
+++ b/graph_ident.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);
diff --git a/graph_instance.c b/graph_instance.c
index 103be23860ba2b913633a9c11a4018989e670b26..e1e0a362c96d917bceef9ebb9093134bf124f199 100644 (file)
--- a/graph_instance.c
+++ b/graph_instance.c
#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)
{
diff --git a/graph_instance.h b/graph_instance.h
index b90f98414d3f1c4e4b5e2e0648849af69577d656..f02901b36123b3ca0ba4674fe3ce1b84296a65ca 100644 (file)
--- a/graph_instance.h
+++ b/graph_instance.h
/*
* 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);
diff --git a/graph_list.c b/graph_list.c
index 965fcbac4f6caad5913b9a0097dd2937ec773ffb..3c8d375d1573eaa88ab7bc836ac06f0fd1ed20a9 100644 (file)
--- a/graph_list.c
+++ b/graph_list.c
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;
diff --git a/graph_list.h b/graph_list.h
index c17d6fc08c17c220c2e911eeb85f1e5cd0ff75f5..e6b6888cdbf528724ac18a310dd8a70f9d8fcfd8 100644 (file)
--- a/graph_list.h
+++ b/graph_list.h
#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_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);
diff --git a/graph_types.h b/graph_types.h
--- /dev/null
+++ b/graph_types.h
@@ -0,0 +1,35 @@
+#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 : */