From: Florian Forster Date: Tue, 15 Jun 2010 12:18:32 +0000 (+0200) Subject: graph_instance.[ch]: Implement "inst_describe". X-Git-Tag: v4.0.0~255 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=57811ec03166433462141458b43b1347199e0519;p=collection4.git graph_instance.[ch]: Implement "inst_describe". --- diff --git a/action_list_graphs.c b/action_list_graphs.c index 4ec9a30..d7cea47 100644 --- a/action_list_graphs.c +++ b/action_list_graphs.c @@ -66,12 +66,16 @@ static int print_graph_inst_html (graph_config_t *cfg, /* {{{ */ graph_instance_t *inst, __attribute__((unused)) void *user_data) { - char buffer[1024]; + char params[1024]; + char desc[1024]; - memset (buffer, 0, sizeof (buffer)); - inst_get_params (cfg, inst, buffer, sizeof (buffer)); + memset (params, 0, sizeof (params)); + inst_get_params (cfg, inst, params, sizeof (params)); + + memset (desc, 0, sizeof (desc)); + inst_describe (cfg, inst, desc, sizeof (desc)); - printf ("
  • %s
  • \n", buffer, buffer); + printf ("
  • %s
  • \n", params, desc); return (0); } /* }}} int print_graph_inst_html */ diff --git a/graph_ident.c b/graph_ident.c index 454cc1a..b008a56 100644 --- a/graph_ident.c +++ b/graph_ident.c @@ -8,9 +8,6 @@ #include "common.h" #include "filesystem.h" -#define IS_ANY(str) (((str) != NULL) && (strcasecmp (ANY_TOKEN, (str)) == 0)) -#define IS_ALL(str) (((str) != NULL) && (strcasecmp (ALL_TOKEN, (str)) == 0)) - /* * Data types */ diff --git a/graph_ident.h b/graph_ident.h index 442bcfe..5107011 100644 --- a/graph_ident.h +++ b/graph_ident.h @@ -4,6 +4,9 @@ #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; diff --git a/graph_instance.c b/graph_instance.c index 11629a5..d9821d0 100644 --- a/graph_instance.c +++ b/graph_instance.c @@ -440,4 +440,47 @@ graph_instance_t *inst_find_matching (graph_instance_t *inst, /* {{{ */ return (NULL); } /* }}} graph_instance_t *inst_find_matching */ +int inst_describe (graph_config_t *cfg, graph_instance_t *inst, /* {{{ */ + char *buffer, size_t buffer_size) +{ + graph_ident_t *cfg_select; + + if ((cfg == NULL) || (inst == NULL) + || (buffer == NULL) || (buffer_size < 2)) + return (EINVAL); + + cfg_select = graph_get_selector (cfg); + if (cfg_select == NULL) + { + fprintf (stderr, "inst_describe: graph_get_selector failed\n"); + return (-1); + } + + buffer[0] = 0; + +#define CHECK_FIELD(field) do { \ + if (IS_ANY (ident_get_##field (cfg_select))) \ + { \ + if (buffer[0] != 0) \ + strlcat (buffer, "/", buffer_size); \ + strlcat (buffer, ident_get_##field (inst->select), buffer_size); \ + } \ +} while (0) + + CHECK_FIELD (host); + CHECK_FIELD (plugin); + CHECK_FIELD (plugin_instance); + CHECK_FIELD (type); + CHECK_FIELD (type_instance); + +#undef CHECK_FIELD + + if (buffer[0] == 0) + strlcat (buffer, "default", buffer_size); + + ident_destroy (cfg_select); + + return (0); +} /* }}} int inst_describe */ + /* vim: set sw=2 sts=2 et fdm=marker : */ diff --git a/graph_instance.h b/graph_instance.h index 39cb4c9..b90f984 100644 --- a/graph_instance.h +++ b/graph_instance.h @@ -43,5 +43,8 @@ int inst_foreach (graph_instance_t *inst, graph_instance_t *inst_find_matching (graph_instance_t *inst, const graph_ident_t *ident); +int inst_describe (graph_config_t *cfg, graph_instance_t *inst, + char *buffer, size_t buffer_size); + #endif /* GRAPH_INSTANCE_H */ /* vim: set sw=2 sts=2 et fdm=marker : */