summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 9c30407)
raw | patch | inline | side by side (parent: 9c30407)
author | Florian Forster <octo@huhu.verplant.org> | |
Wed, 27 Feb 2008 09:07:57 +0000 (10:07 +0100) | ||
committer | Florian Forster <octo@huhu.verplant.org> | |
Wed, 27 Feb 2008 09:07:57 +0000 (10:07 +0100) |
This functions allows to get values from the cache without creating a
`value_list_t' and `data_set_t' first. The existing function `uc_get_rate' has
been changed to use this function, too.
`value_list_t' and `data_set_t' first. The existing function `uc_get_rate' has
been changed to use this function, too.
src/utils_cache.c | patch | blob | history | |
src/utils_cache.h | patch | blob | history |
diff --git a/src/utils_cache.c b/src/utils_cache.c
index 0d6961e7372a1d6d949e1d0ca45520616ff7f0ad..e7ab03cda324a446aa06a4d82e43ab16d78fe26b 100644 (file)
--- a/src/utils_cache.c
+++ b/src/utils_cache.c
return (0);
} /* int uc_insert */
-gauge_t *uc_get_rate (const data_set_t *ds, const value_list_t *vl)
+int uc_get_rate_by_name (const char *name, gauge_t **ret_values, size_t *ret_values_num)
{
- char name[6 * DATA_MAX_NAME_LEN];
gauge_t *ret = NULL;
+ size_t ret_num = 0;
cache_entry_t *ce = NULL;
-
- if (FORMAT_VL (name, sizeof (name), vl, ds) != 0)
- {
- ERROR ("uc_insert: FORMAT_VL failed.");
- return (NULL);
- }
+ int status = 0;
pthread_mutex_lock (&cache_lock);
if (c_avl_get (cache_tree, name, (void *) &ce) == 0)
{
assert (ce != NULL);
- assert (ce->values_num == ds->ds_num);
- ret = (gauge_t *) malloc (ce->values_num * sizeof (gauge_t));
+ ret_num = ce->values_num;
+ ret = (gauge_t *) malloc (ret_num * sizeof (gauge_t));
if (ret == NULL)
{
- ERROR ("uc_get_rate: malloc failed.");
+ ERROR ("utils_cache: uc_get_rate_by_name: malloc failed.");
+ status = -1;
}
else
{
- memcpy (ret, ce->values_gauge, ce->values_num * sizeof (gauge_t));
+ memcpy (ret, ce->values_gauge, ret_num * sizeof (gauge_t));
}
}
+ else
+ {
+ DEBUG ("utils_cache: uc_get_rate_by_name: No such value: %s", name);
+ status = -1;
+ }
pthread_mutex_unlock (&cache_lock);
+ if (status == 0)
+ {
+ *ret_values = ret;
+ *ret_values_num = ret_num;
+ }
+
+ return (status);
+} /* gauge_t *uc_get_rate_by_name */
+
+gauge_t *uc_get_rate (const data_set_t *ds, const value_list_t *vl)
+{
+ char name[6 * DATA_MAX_NAME_LEN];
+ gauge_t *ret = NULL;
+ size_t ret_num = 0;
+ int status;
+
+ if (FORMAT_VL (name, sizeof (name), vl, ds) != 0)
+ {
+ ERROR ("uc_insert: FORMAT_VL failed.");
+ return (NULL);
+ }
+
+ status = uc_get_rate_by_name (name, &ret, &ret_num);
+ if (status != 0)
+ return (NULL);
+
+ /* This is important - the caller has no other way of knowing how many
+ * values are returned. */
+ if (ret_num != ds->ds_num)
+ {
+ ERROR ("utils_cache: uc_get_rate: ds[%s] has %i values, "
+ "but uc_get_rate_by_name returned %i.",
+ ds->type, ds->ds_num, ret_num);
+ sfree (ret);
+ return (NULL);
+ }
+
return (ret);
} /* gauge_t *uc_get_rate */
diff --git a/src/utils_cache.h b/src/utils_cache.h
index d6a56ab4659a2e7a5205f2ac0f1243537975f59b..ed6830b646b57cf370ec3868831a20f6492c6e89 100644 (file)
--- a/src/utils_cache.h
+++ b/src/utils_cache.h
int uc_init (void);
int uc_check_timeout (void);
int uc_update (const data_set_t *ds, const value_list_t *vl);
+int uc_get_rate_by_name (const char *name, gauge_t **ret_values, size_t *ret_values_num);
gauge_t *uc_get_rate (const data_set_t *ds, const value_list_t *vl);
int uc_get_state (const data_set_t *ds, const value_list_t *vl);