X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fgraph_instance.c;h=5431589cfa9f4ed4f1c3074c8734f0065f8cc7be;hb=15279357255dbcccab890a29c7ceecc144ba3e63;hp=109316fb992ef2284ec2f31267c42e4dc6a91ab1;hpb=ef431f56a6cfd1361bc1f37006532137cf49a165;p=collection4.git diff --git a/src/graph_instance.c b/src/graph_instance.c index 109316f..5431589 100644 --- a/src/graph_instance.c +++ b/src/graph_instance.c @@ -2,8 +2,10 @@ #include #include #include +#include #include "graph_instance.h" +#include "graph.h" #include "graph_def.h" #include "graph_ident.h" #include "graph_list.h" @@ -149,6 +151,36 @@ static const char *get_part_from_param (const char *prim_key, /* {{{ */ return (param (sec_key)); } /* }}} const char *get_part_from_param */ +static graph_ident_t *inst_get_selector_from_params (void) /* {{{ */ +{ + const char *host = get_part_from_param ("inst_host", "host"); + const char *plugin = get_part_from_param ("inst_plugin", "plugin"); + const char *plugin_instance = get_part_from_param ("inst_plugin_instance", + "plugin_instance"); + const char *type = get_part_from_param ("inst_type", "type"); + const char *type_instance = get_part_from_param ("inst_type_instance", + "type_instance"); + + graph_ident_t *ident; + + if ((host == NULL) + || (plugin == NULL) || (plugin_instance == NULL) + || (type == NULL) || (type_instance == NULL)) + { + fprintf (stderr, "inst_get_selected: A parameter is NULL\n"); + return (NULL); + } + + ident = ident_create (host, plugin, plugin_instance, type, type_instance); + if (ident == NULL) + { + fprintf (stderr, "inst_get_selected: ident_create failed\n"); + return (NULL); + } + + return (ident); +} /* }}} graph_ident_t *inst_get_selector_from_params */ + /* * Public functions */ @@ -229,14 +261,6 @@ int inst_add_file (graph_instance_t *inst, /* {{{ */ graph_instance_t *inst_get_selected (graph_config_t *cfg) /* {{{ */ { - const char *host = get_part_from_param ("inst_host", "host"); - const char *plugin = get_part_from_param ("inst_plugin", "plugin"); - const char *plugin_instance = get_part_from_param ("inst_plugin_instance", - "plugin_instance"); - const char *type = get_part_from_param ("inst_type", "type"); - const char *type_instance = get_part_from_param ("inst_type_instance", - "type_instance"); - graph_ident_t *ident; graph_instance_t *inst; @@ -249,15 +273,7 @@ graph_instance_t *inst_get_selected (graph_config_t *cfg) /* {{{ */ return (NULL); } - if ((host == NULL) - || (plugin == NULL) || (plugin_instance == NULL) - || (type == NULL) || (type_instance == NULL)) - { - DEBUG ("inst_get_selected: A parameter is NULL.\n"); - return (NULL); - } - - ident = ident_create (host, plugin, plugin_instance, type, type_instance); + ident = inst_get_selector_from_params (); if (ident == NULL) { fprintf (stderr, "inst_get_selected: ident_create failed\n"); @@ -265,11 +281,34 @@ graph_instance_t *inst_get_selected (graph_config_t *cfg) /* {{{ */ } inst = graph_inst_find_exact (cfg, ident); - ident_destroy (ident); + ident_destroy (ident); return (inst); } /* }}} graph_instance_t *inst_get_selected */ +int inst_get_all_selected (graph_config_t *cfg, /* {{{ */ + graph_inst_callback_t callback, void *user_data) +{ + graph_ident_t *ident; + int status; + + if ((cfg == NULL) || (callback == NULL)) + return (EINVAL); + + ident = inst_get_selector_from_params (); + if (ident == NULL) + { + fprintf (stderr, "inst_get_all_selected: " + "inst_get_selector_from_params failed\n"); + return (EINVAL); + } + + status = graph_inst_find_all_matching (cfg, ident, callback, user_data); + + ident_destroy (ident); + return (status); +} /* }}} int inst_get_all_selected */ + int inst_get_rrdargs (graph_config_t *cfg, /* {{{ */ graph_instance_t *inst, str_array_t *args) @@ -380,13 +419,22 @@ int inst_compare_ident (graph_instance_t *inst, /* {{{ */ return (ident_compare (inst->select, ident)); } /* }}} int inst_compare_ident */ -_Bool inst_matches_ident (graph_instance_t *inst, /* {{{ */ +_Bool inst_ident_matches (graph_instance_t *inst, /* {{{ */ const graph_ident_t *ident) { if ((inst == NULL) || (ident == NULL)) return (0); return (ident_matches (inst->select, ident)); +} /* }}} _Bool inst_ident_matches */ + +_Bool inst_matches_ident (graph_instance_t *inst, /* {{{ */ + const graph_ident_t *ident) +{ + if ((inst == NULL) || (ident == NULL)) + return (0); + + return (ident_matches (ident, inst->select)); } /* }}} _Bool inst_matches_ident */ _Bool inst_matches_string (graph_config_t *cfg, /* {{{ */