Change in libosmocore[master]: stat_item: Add function to reset stat items and groups

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/.

daniel gerrit-no-reply at lists.osmocom.org
Thu Jul 16 10:44:14 UTC 2020


daniel has uploaded this change for review. ( https://gerrit.osmocom.org/c/libosmocore/+/19295 )


Change subject: stat_item: Add function to reset stat items and groups
......................................................................

stat_item: Add function to reset stat items and groups

Change-Id: I80fc0ea8865ec4efdcd4c982e69d863275fd9919
Related: SYS#4877
---
M TODO-RELEASE
M include/osmocom/core/stat_item.h
M src/stat_item.c
3 files changed, 37 insertions(+), 1 deletion(-)



  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/95/19295/1

diff --git a/TODO-RELEASE b/TODO-RELEASE
index 61fd1cf..9700f58 100644
--- a/TODO-RELEASE
+++ b/TODO-RELEASE
@@ -15,4 +15,5 @@
 gsm		API/ABI change		add new member to lapd_datalink
 gsm		new API			new gsm0808_create_common_id()
 gb		new API			new bssgp_tx_bvc_reset2()
-core		net API			new rate_ctr_reset_{ctr,group}()
+core		new API			new rate_ctr_reset_{ctr,group}()
+core		new API			new osmo_stat_item_reset_{item,group}()
diff --git a/include/osmocom/core/stat_item.h b/include/osmocom/core/stat_item.h
index 806173a..9858ca1 100644
--- a/include/osmocom/core/stat_item.h
+++ b/include/osmocom/core/stat_item.h
@@ -114,4 +114,8 @@
 {
 	return item->values[item->last_offs].value;
 }
+
+void osmo_stat_item_reset_item(struct osmo_stat_item *item);
+void osmo_stat_item_reset_group(struct osmo_stat_item_group *statg);
+
 /*! @} */
diff --git a/src/stat_item.c b/src/stat_item.c
index 6716575..660abfb 100644
--- a/src/stat_item.c
+++ b/src/stat_item.c
@@ -356,4 +356,35 @@
 	return rc;
 }
 
+
+/*! Remove all values of a stat item
+ *  \param[in] item stat item to reset
+ */
+void osmo_stat_item_reset_item(struct osmo_stat_item *item)
+{
+	unsigned int i;
+
+	item->last_offs = item->desc->num_values - 1;
+	item->last_value_index = -1;
+
+	for (i = 0; i <= item->last_offs; i++) {
+		item->values[i].value = item->desc->default_value;
+		item->values[i].id = OSMO_STAT_ITEM_NOVALUE_ID;
+	}
+}
+
+static int reset_osmo_stat_item_handler(
+	struct osmo_stat_item_group *statg_, struct osmo_stat_item *item, void *sctx_)
+{
+        osmo_stat_item_reset_item(item);
+        return 0;
+}
+
+/*! Reset all osmo stat items in a group
+ *  \param[in] statg stat item group to reset
+ */
+void osmo_stat_item_reset_group(struct osmo_stat_item_group *statg)
+{
+        osmo_stat_item_for_each_item(statg, reset_osmo_stat_item_handler, NULL);
+}
 /*! @} */

-- 
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/19295
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: I80fc0ea8865ec4efdcd4c982e69d863275fd9919
Gerrit-Change-Number: 19295
Gerrit-PatchSet: 1
Gerrit-Owner: daniel <dwillmann at sysmocom.de>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20200716/eafd542b/attachment.htm>


More information about the gerrit-log mailing list