The linked-list in graph_instance_t has been removed.
graph_def_t *defs;
- graph_instance_t *instances;
+ graph_instance_t **instances;
+ size_t instances_num;
}; /* }}} struct graph_config_s */
/*
* Private functions
*/
-static graph_instance_t *graph_find_instance (graph_config_t *cfg, /* {{{ */
- const graph_ident_t *ident)
-{
- if ((cfg == NULL) || (ident == NULL))
- return (NULL);
-
- return (inst_find_matching (cfg->instances, ident));
-} /* }}} graph_instance_t *graph_find_instance */
/*
* Config functions
void graph_destroy (graph_config_t *cfg) /* {{{ */
{
+ size_t i;
+
if (cfg == NULL)
return;
free (cfg->vertical_label);
def_destroy (cfg->defs);
- inst_destroy (cfg->instances);
+
+ for (i = 0; i < cfg->instances_num; i++)
+ inst_destroy (cfg->instances[i]);
+ free (cfg->instances);
} /* }}} void graph_destroy */
int graph_config_add (const oconfig_item_t *ci) /* {{{ */
{
graph_instance_t *inst;
- inst = graph_find_instance (cfg, file);
+ inst = graph_inst_find_matching (cfg, file);
if (inst == NULL)
{
+ graph_instance_t **tmp;
+
+ tmp = realloc (cfg->instances,
+ sizeof (*cfg->instances) * (cfg->instances_num + 1));
+ if (tmp == NULL)
+ return (ENOMEM);
+ cfg->instances = tmp;
+
inst = inst_create (cfg, file);
if (inst == NULL)
return (ENOMEM);
- if (cfg->instances == NULL)
- cfg->instances = inst;
- else
- inst_append (cfg->instances, inst);
+ cfg->instances[cfg->instances_num] = inst;
+ cfg->instances_num++;
}
return (inst_add_file (inst, file));
return (ident_clone (cfg->select));
} /* }}} graph_ident_t *graph_get_selector */
-graph_instance_t *graph_get_instances (graph_config_t *cfg) /* {{{ */
-{
- if (cfg == NULL)
- return (NULL);
-
- return (cfg->instances);
-} /* }}} graph_instance_t *graph_get_instances */
-
graph_def_t *graph_get_defs (graph_config_t *cfg) /* {{{ */
{
if (cfg == NULL)
return (ident_matches (cfg->select, ident));
} /* }}} _Bool graph_matches */
-struct graph_search_data_s
+int graph_inst_foreach (graph_config_t *cfg, /* {{{ */
+ inst_callback_t cb, void *user_data)
{
- graph_config_t *cfg;
- graph_inst_callback_t callback;
- void *user_data;
-};
-typedef struct graph_search_data_s graph_search_data_t;
+ size_t i;
+ int status;
-static int graph_search_submit (graph_instance_t *inst, /* {{{ */
- void *user_data)
+ for (i = 0; i < cfg->instances_num; i++)
+ {
+ status = (*cb) (cfg->instances[i], user_data);
+ if (status != 0)
+ return (status);
+ }
+
+ return (0);
+} /* }}} int graph_inst_foreach */
+
+graph_instance_t *graph_inst_find_exact (graph_config_t *cfg, /* {{{ */
+ graph_ident_t *ident)
{
- graph_search_data_t *data = user_data;
+ size_t i;
- if ((inst == NULL) || (data == NULL))
- return (EINVAL);
+ if ((cfg == NULL) || (ident == NULL))
+ return (NULL);
- return ((*data->callback) (data->cfg, inst, data->user_data));
-} /* }}} int graph_search_submit */
+ for (i = 0; i < cfg->instances_num; i++)
+ if (inst_compare_ident (cfg->instances[i], ident) == 0)
+ return (cfg->instances[i]);
-int graph_inst_foreach (graph_config_t *cfg, /* {{{ */
- inst_callback_t cb, void *user_data)
+ return (NULL);
+} /* }}} graph_instance_t *graph_inst_find_exact */
+
+graph_instance_t *graph_inst_find_matching (graph_config_t *cfg, /* {{{ */
+ const graph_ident_t *ident)
{
- return (inst_foreach (cfg->instances, cb, user_data));
-} /* }}} int graph_inst_foreach */
+ size_t i;
+
+ if ((cfg == NULL) || (ident == NULL))
+ return (NULL);
+
+ for (i = 0; i < cfg->instances_num; i++)
+ if (inst_matches_ident (cfg->instances[i], ident))
+ return (cfg->instances[i]);
+
+ return (NULL);
+} /* }}} graph_instance_t *graph_inst_find_matching */
-int graph_search (graph_config_t *cfg, const char *term, /* {{{ */
- graph_inst_callback_t callback,
+int graph_inst_search (graph_config_t *cfg, const char *term, /* {{{ */
+ graph_inst_callback_t cb,
void *user_data)
{
- graph_search_data_t data = { cfg, callback, user_data };
char buffer[1024];
int status;
+ size_t i;
status = graph_get_title (cfg, buffer, sizeof (buffer));
if (status != 0)
{
- fprintf (stderr, "graph_search: graph_get_title failed\n");
+ fprintf (stderr, "graph_inst_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);
+ for (i = 0; i < cfg->instances_num; i++)
+ {
+ status = (*cb) (cfg, cfg->instances[i], user_data);
+ if (status != 0)
+ return (status);
+ }
}
else
{
- status = inst_search (cfg, cfg->instances, term,
- graph_search_submit, &data);
- if (status != 0)
- return (status);
+ for (i = 0; i < cfg->instances_num; i++)
+ {
+ if (inst_matches_string (cfg, cfg->instances[i], term))
+ {
+ status = (*cb) (cfg, cfg->instances[i], user_data);
+ if (status != 0)
+ return (status);
+ }
+ }
}
return (0);
-} /* }}} int graph_search */
+} /* }}} int graph_inst_search */
int graph_compare (graph_config_t *cfg, const graph_ident_t *ident) /* {{{ */
{
int graph_clear_instances (graph_config_t *cfg) /* {{{ */
{
+ size_t i;
+
if (cfg == NULL)
return (EINVAL);
- inst_destroy (cfg->instances);
+ for (i = 0; i < cfg->instances_num; i++)
+ inst_destroy (cfg->instances[i]);
+ free (cfg->instances);
cfg->instances = NULL;
+ cfg->instances_num = 0;
return (0);
} /* }}} int graph_clear_instances */
graph_ident_t *graph_get_selector (graph_config_t *cfg);
-graph_instance_t *graph_get_instances (graph_config_t *cfg);
-
graph_def_t *graph_get_defs (graph_config_t *cfg);
int graph_add_def (graph_config_t *cfg, graph_def_t *def);
_Bool graph_matches (graph_config_t *cfg, const graph_ident_t *ident);
int graph_inst_foreach (graph_config_t *cfg,
- inst_callback_t cb, void *user_data);
+ inst_callback_t cb, void *user_data);
+
+graph_instance_t *graph_inst_find_exact (graph_config_t *cfg,
+ graph_ident_t *ident);
+
+graph_instance_t *graph_inst_find_matching (graph_config_t *cfg,
+ const graph_ident_t *ident);
-int graph_search (graph_config_t *cfg, const char *term,
+int graph_inst_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);
graph_ident_t **files;
size_t files_num;
-
- graph_instance_t *next;
}; /* }}} struct graph_instance_s */
struct def_callback_data_s
i->files = NULL;
i->files_num = 0;
- i->next = NULL;
-
return (i);
} /* }}} graph_instance_t *inst_create */
void inst_destroy (graph_instance_t *inst) /* {{{ */
{
- graph_instance_t *next;
size_t i;
if (inst == NULL)
return;
- next = inst->next;
-
ident_destroy (inst->select);
for (i = 0; i < inst->files_num; i++)
free (inst->files);
free (inst);
-
- inst_destroy (next);
} /* }}} void inst_destroy */
int inst_add_file (graph_instance_t *inst, /* {{{ */
{
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 *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");
+ const char *type_instance = get_part_from_param ("inst_type_instance",
+ "type_instance");
+
graph_ident_t *ident;
graph_instance_t *inst;
}
ident = ident_create (host, plugin, plugin_instance, type, type_instance);
-
- for (inst = graph_get_instances (cfg); inst != NULL; inst = inst->next)
+ if (ident == NULL)
{
- if (ident_compare (ident, inst->select) != 0)
- continue;
-
- ident_destroy (ident);
- return (inst);
+ fprintf (stderr, "inst_get_selected: ident_create failed\n");
+ return (NULL);
}
- DEBUG ("inst_get_selected: No match found.\n");
+ inst = graph_inst_find_exact (cfg, ident);
ident_destroy (ident);
- return (NULL);
+
+ return (inst);
} /* }}} graph_instance_t *inst_get_selected */
int inst_get_rrdargs (graph_config_t *cfg, /* {{{ */
return (0);
} /* }}} int inst_get_params */
-int inst_append (graph_instance_t *head, graph_instance_t *inst) /* {{{ */
+int inst_compare_ident (graph_instance_t *inst, /* {{{ */
+ const graph_ident_t *ident)
{
- graph_instance_t *ptr;
-
- if ((head == NULL) || (inst == NULL))
- return (EINVAL);
-
- ptr = head;
- while (ptr->next != NULL)
- ptr = ptr->next;
-
- ptr->next = inst;
+ if ((inst == NULL) || (ident == NULL))
+ return (0);
- return (0);
-} /* }}} int inst_append */
+ return (ident_compare (inst->select, ident));
+} /* }}} int inst_compare_ident */
-int inst_foreach (graph_instance_t *inst, /* {{{ */
- inst_callback_t cb, void *user_data)
+_Bool inst_matches_ident (graph_instance_t *inst, /* {{{ */
+ const graph_ident_t *ident)
{
- graph_instance_t *ptr;
-
- if ((inst == NULL) || (cb == NULL))
- return (EINVAL);
-
- for (ptr = inst; ptr != NULL; ptr = ptr->next)
- {
- int status;
-
- status = (*cb) (ptr, user_data);
- if (status != 0)
- return (status);
- }
+ if ((inst == NULL) || (ident == NULL))
+ return (0);
- return (0);
-} /* }}} int inst_foreach */
+ return (ident_matches (inst->select, ident));
+} /* }}} _Bool inst_matches_ident */
-int inst_search (graph_config_t *cfg, graph_instance_t *inst, /* {{{ */
- const char *term, inst_callback_t cb, void *user_data)
+_Bool inst_matches_string (graph_config_t *cfg, /* {{{ */
+ graph_instance_t *inst,
+ const char *term)
{
- graph_instance_t *ptr;
char buffer[1024];
int status;
- if ((inst == NULL) || (cb == NULL))
- return (EINVAL);
+ if ((cfg == NULL) || (inst == NULL) || (term == NULL))
+ return (0);
- for (ptr = inst; ptr != NULL; ptr = ptr->next)
+ status = inst_describe (cfg, inst, buffer, sizeof (buffer));
+ if (status != 0)
{
- status = inst_describe (cfg, ptr, buffer, sizeof (buffer));
- if (status != 0)
- {
- fprintf (stderr, "inst_search: inst_describe failed\n");
- return (status);
- }
-
- strtolower (buffer);
-
- /* no match */
- if (strstr (buffer, term) == NULL)
- continue;
-
- /* match */
- status = (*cb) (ptr, user_data);
- if (status != 0)
- return (status);
+ fprintf (stderr, "inst_matches_string: inst_describe failed\n");
+ return (status);
}
- return (0);
-} /* }}} int inst_search */
+ strtolower (buffer);
-graph_instance_t *inst_find_matching (graph_instance_t *inst, /* {{{ */
- const graph_ident_t *ident)
-{
- graph_instance_t *ptr;
-
- if ((inst == NULL) || (ident == NULL))
- return (NULL);
-
- for (ptr = inst; ptr != NULL; ptr = ptr->next)
- if (ident_matches (ptr->select, ident))
- return (ptr);
+ /* no match */
+ if (strstr (buffer, term) == NULL)
+ return (0);
- return (NULL);
-} /* }}} graph_instance_t *inst_find_matching */
+ return (1);
+} /* }}} _Bool inst_matches_string */
int inst_describe (graph_config_t *cfg, graph_instance_t *inst, /* {{{ */
char *buffer, size_t buffer_size)
graph_ident_t *inst_get_selector (graph_instance_t *inst);
-int inst_append (graph_instance_t *head, graph_instance_t *inst);
+int inst_compare_ident (graph_instance_t *inst, const graph_ident_t *ident);
-int inst_foreach (graph_instance_t *inst,
- inst_callback_t cb, void *user_data);
+_Bool inst_matches_ident (graph_instance_t *inst, const graph_ident_t *ident);
-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);
+_Bool inst_matches_string (graph_config_t *cfg, graph_instance_t *inst,
+ const char *term);
int inst_describe (graph_config_t *cfg, graph_instance_t *inst,
char *buffer, size_t buffer_size);
{
int status;
- status = graph_search (gl_active[i], term,
+ status = graph_inst_search (gl_active[i], term,
/* callback = */ callback,
/* user data = */ user_data);
if (status != 0)