From c6a7108828bf98ebcaf31d24bd8d789afdd4da94 Mon Sep 17 00:00:00 2001 From: Jacob Erlbeck Date: Mon, 19 Oct 2015 14:04:38 +0200 Subject: stats: Add stat_item_for_each functions This commit adds the following functions: stat_item_for_each_group Call a handler for each group stat_item_for_each_item Call a handler for each item of a group Sponsored-by: On-Waves ehf --- src/stat_item.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'src') diff --git a/src/stat_item.c b/src/stat_item.c index 1e283d48..525a94b9 100644 --- a/src/stat_item.c +++ b/src/stat_item.c @@ -235,4 +235,34 @@ const struct stat_item *stat_item_get_by_name( return NULL; } +int stat_item_for_each_item(struct stat_item_group *statg, + stat_item_handler_t handle_item, void *data) +{ + int rc = 0; + int i; + + for (i = 0; i < statg->desc->num_items; i++) { + struct stat_item *item = statg->items[i]; + rc = handle_item(statg, item, data); + if (rc < 0) + return rc; + } + + return rc; +} + +int stat_item_for_each_group(stat_item_group_handler_t handle_group, void *data) +{ + struct stat_item_group *statg; + int rc = 0; + + llist_for_each_entry(statg, &stat_item_groups, list) { + rc = handle_group(statg, data); + if (rc < 0) + return rc; + } + + return rc; +} + /*! @} */ -- cgit v1.2.3