This is merely a historical archive of years 2008-2021, before the migration to mailman3.
A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.
neels gerrit-no-reply at lists.osmocom.orgneels has uploaded this change for review. ( https://gerrit.osmocom.org/c/libosmocore/+/25463 ) Change subject: stat_item: add osmo_stat_item_get() ...................................................................... stat_item: add osmo_stat_item_get() So far we often invoke a cascade of functions, one retrieving the group, the other the stat item within that group. To relieve that pain, provide a single function taking group name, index and stat name args. Since this is supposedly the canonical normal way of getting a handle on a stat item, and since most other useful names are already taken with more obscure functions, call this simply osmo_stat_item_get(). Similarly add osmo_stat_item_get_using_idxname(), which uses a group's object name (index-name) instead of the group index number. Again, better naming is obstructed by already existing names in the API. Related: SYS#5542 Change-Id: I58886ae8af6b1f770088410f63d27ac21bf979fb --- M include/osmocom/core/stat_item.h M src/stat_item.c M tests/stats/stats_test.c 3 files changed, 44 insertions(+), 0 deletions(-) git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/63/25463/1 diff --git a/include/osmocom/core/stat_item.h b/include/osmocom/core/stat_item.h index 402a7ae..c4e8332 100644 --- a/include/osmocom/core/stat_item.h +++ b/include/osmocom/core/stat_item.h @@ -93,6 +93,10 @@ void osmo_stat_item_dec(struct osmo_stat_item *item, int32_t value); void osmo_stat_item_set(struct osmo_stat_item *item, int32_t value); +struct osmo_stat_item *osmo_stat_item_get(const char *group_name, const unsigned int group_idx, const char *item_name); +struct osmo_stat_item *osmo_stat_item_get_using_idxname(const char *group_name, const char *group_idx_name, + const char *item_name); + int osmo_stat_item_init(void *tall_ctx); struct osmo_stat_item_group *osmo_stat_item_get_group_by_name_idx( diff --git a/src/stat_item.c b/src/stat_item.c index 1788746..aca8ba6 100644 --- a/src/stat_item.c +++ b/src/stat_item.c @@ -231,6 +231,38 @@ item->values[item->last_offs].id = id; } +/*! Retrieve a stat item struct. + * Shorthand for osmo_stat_item_get_by_name(osmo_stat_item_get_group_by_name_idx(group_name, group_idx), item_name), + * and returns a mutable (non-const) pointer. + * \param group_name Name of the stat group. + * \param group_idx Group index, i.e. pick a specific instance of a stat group. + * \param item_name Name of the stat item within the group. + * \return stat item pointer, or NULL if not found. + */ +struct osmo_stat_item *osmo_stat_item_get(const char *group_name, const unsigned int group_idx, const char *item_name) +{ + return (struct osmo_stat_item*)osmo_stat_item_get_by_name( + osmo_stat_item_get_group_by_name_idx(group_name, group_idx), + item_name); +} + +/*! Retrieve a stat item struct. + * Shorthand for + * osmo_stat_item_get_by_name(osmo_stat_item_get_group_by_name_idxname(group_name, group_idx_name), item_name), + * and returns a mutable (non-const) pointer. + * \param group_name Name of the stat group. + * \param group_idx_name Group index identified by name, i.e. pick a specific instance of a stat group. + * \param item_name Name of the stat item within the group. + * \return stat item pointer, or NULL if not found. + */ +struct osmo_stat_item *osmo_stat_item_get_using_idxname(const char *group_name, const char *group_idx_name, + const char *item_name) +{ + return (struct osmo_stat_item*)osmo_stat_item_get_by_name( + osmo_stat_item_get_group_by_name_idxname(group_name, group_idx_name), + item_name); +} + /*! Retrieve the next value from the osmo_stat_item object. * If a new value has been set, it is returned. The next_id is used to decide * which value to return. diff --git a/tests/stats/stats_test.c b/tests/stats/stats_test.c index 9489e60..ccb3f91 100644 --- a/tests/stats/stats_test.c +++ b/tests/stats/stats_test.c @@ -96,6 +96,8 @@ OSMO_ASSERT(statg != NULL); + osmo_stat_item_group_set_name(statg, "name-for-idx-0"); + sgrp2 = osmo_stat_item_get_group_by_name_idx("test.one", 0); OSMO_ASSERT(sgrp2 == statg); @@ -112,11 +114,17 @@ OSMO_ASSERT(sitem1 != NULL); OSMO_ASSERT(sitem1 == osmo_stat_item_group_get_item(statg, TEST_A_ITEM)); + OSMO_ASSERT(osmo_stat_item_get("test.one", 0, "item.a") == sitem1); + OSMO_ASSERT(osmo_stat_item_get_using_idxname("test.one", "name-for-idx-0", "item.a") == sitem1); + sitem2 = osmo_stat_item_get_by_name(statg, "item.b"); OSMO_ASSERT(sitem2 != NULL); OSMO_ASSERT(sitem2 != sitem1); OSMO_ASSERT(sitem2 == osmo_stat_item_group_get_item(statg, TEST_B_ITEM)); + OSMO_ASSERT(osmo_stat_item_get("test.one", 0, "item.b") == sitem2); + OSMO_ASSERT(osmo_stat_item_get_using_idxname("test.one", "name-for-idx-0", "item.b") == sitem2); + value = osmo_stat_item_get_last(osmo_stat_item_group_get_item(statg, TEST_A_ITEM)); OSMO_ASSERT(value == -1); -- To view, visit https://gerrit.osmocom.org/c/libosmocore/+/25463 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmocore Gerrit-Branch: master Gerrit-Change-Id: I58886ae8af6b1f770088410f63d27ac21bf979fb Gerrit-Change-Number: 25463 Gerrit-PatchSet: 1 Gerrit-Owner: neels <nhofmeyr at sysmocom.de> Gerrit-MessageType: newchange -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20210915/a4f8bddb/attachment.htm>