diff options
authorNeels Hofmeyr <nhofmeyr@sysmocom.de>2021-09-05 16:22:23 +0200
committerNeels Hofmeyr <nhofmeyr@sysmocom.de>2021-09-14 10:28:02 +0200
commit7fcfefbcf77025d1efc1196e84e17a5423e4112d (patch)
parent47773344fb20bb25b68d5e0b91d76ed781da140d (diff)
add osmo_stat_item_get_group_by_name_idxname()
Add "missing" API for looking up a stat_item_group by its index-name. A subsequent patch, which adds stat_items to the CTRL interface, will use this to look up stat item groups by object name. In stat item groups, there are group names, having a number of indexes denoting different objects. An object can have, besides the index, also a name that is equivalent to the index. Apologies for the weird function name, it's still the best one I could come up with: "group_by_name" refers to the group name, and "idxname" refers to the name that the object index is associated with. We already have osmo_stat_item_get_group_by_name_idx(). Other contestants for name of this new function were: - osmo_stat_item_get_group_by_name_name() because there is a "name" instead of "idx", but I find it confusing. - osmo_stat_item_get_group_by_name_idx_name() but I find that the last "name" should be closer to the "idx". Related: SYS#5542 Change-Id: Ia1a77a1e4657ba624dd4f4bf7ad274e7751d0141
2 files changed, 21 insertions, 0 deletions
diff --git a/include/osmocom/core/stat_item.h b/include/osmocom/core/stat_item.h
index 332bbe92..402a7aec 100644
--- a/include/osmocom/core/stat_item.h
+++ b/include/osmocom/core/stat_item.h
@@ -97,6 +97,7 @@ int osmo_stat_item_init(void *tall_ctx);
struct osmo_stat_item_group *osmo_stat_item_get_group_by_name_idx(
const char *name, const unsigned int idx);
+struct osmo_stat_item_group *osmo_stat_item_get_group_by_name_idxname(const char *group_name, const char *idx_name);
const struct osmo_stat_item *osmo_stat_item_get_by_name(
const struct osmo_stat_item_group *statg, const char *name);
diff --git a/src/stat_item.c b/src/stat_item.c
index 55aa9510..87cbfea7 100644
--- a/src/stat_item.c
+++ b/src/stat_item.c
@@ -333,6 +333,26 @@ struct osmo_stat_item_group *osmo_stat_item_get_group_by_name_idx(
return NULL;
+/*! Search for item group based on group name and index's name.
+ * \param[in] name Name of stats_item_group we want to find.
+ * \param[in] idx_name Index of the group we want to find, by the index's name (osmo_stat_item_group->name).
+ * \returns pointer to group, if found; NULL otherwise. */
+struct osmo_stat_item_group *osmo_stat_item_get_group_by_name_idxname(const char *group_name, const char *idx_name)
+ struct osmo_stat_item_group *statg;
+ llist_for_each_entry(statg, &osmo_stat_item_groups, list) {
+ if (!statg->desc || !statg->name)
+ continue;
+ if (strcmp(statg->desc->group_name_prefix, group_name))
+ continue;
+ if (strcmp(statg->name, idx_name))
+ continue;
+ return statg;
+ }
+ return NULL;
/*! Search for item based on group + item name
* \param[in] statg group in which to search for the item
* \param[in] name name of item to search within \a statg