Change in libosmocore[master]: stat, rate_ctr: Introduce new API to get counter at given index

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

pespin gerrit-no-reply at lists.osmocom.org
Mon May 31 11:43:42 UTC 2021


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


Change subject: stat,rate_ctr: Introduce new API to get counter at given index
......................................................................

stat,rate_ctr: Introduce new API to get counter at given index

Having this API and forcing apps to use it will allow easily adding new
members to the group structure without having so much impact in users of
this struct.

Related: SYS#5456
Change-Id: Iebbf401f11e36645f8964d389460918eb9e0910e
---
M include/osmocom/core/rate_ctr.h
M include/osmocom/core/stat_item.h
M src/rate_ctr.c
M src/stat_item.c
4 files changed, 24 insertions(+), 3 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/69/24469/1

diff --git a/include/osmocom/core/rate_ctr.h b/include/osmocom/core/rate_ctr.h
index 87895a3..0aaeacf 100644
--- a/include/osmocom/core/rate_ctr.h
+++ b/include/osmocom/core/rate_ctr.h
@@ -63,7 +63,7 @@
 	unsigned int idx;
 	/*! Optional string-based identifier to be used instead of index at report time */
 	char *name;
-	/*! Actual counter structures below */
+	/*! Actual counter structures below. Don't access it directly, use APIs below! */
 	struct rate_ctr ctr[0];
 };
 
@@ -76,6 +76,7 @@
 	grp->idx = idx;
 }
 void rate_ctr_group_set_name(struct rate_ctr_group *grp, const char *name);
+struct rate_ctr *rate_ctr_group_get_ctr(struct rate_ctr_group *grp, unsigned int idx);
 
 void rate_ctr_group_free(struct rate_ctr_group *grp);
 
@@ -96,7 +97,7 @@
  *  \param idx index into \a ctrg counter group */
 static inline void rate_ctr_inc2(struct rate_ctr_group *ctrg, unsigned int idx)
 {
-	rate_ctr_inc(&ctrg->ctr[idx]);
+	rate_ctr_inc(rate_ctr_group_get_ctr(ctrg, idx));
 }
 
 
diff --git a/include/osmocom/core/stat_item.h b/include/osmocom/core/stat_item.h
index cccb15a..0d8000c 100644
--- a/include/osmocom/core/stat_item.h
+++ b/include/osmocom/core/stat_item.h
@@ -82,7 +82,7 @@
 	grp->idx = idx;
 }
 void osmo_stat_item_group_set_name(struct osmo_stat_item_group *statg, const char *name);
-
+struct osmo_stat_item *osmo_stat_item_group_get_item(struct osmo_stat_item_group *grp, unsigned int idx);
 void osmo_stat_item_group_free(struct osmo_stat_item_group *statg);
 
 void osmo_stat_item_inc(struct osmo_stat_item *item, int32_t value);
diff --git a/src/rate_ctr.c b/src/rate_ctr.c
index 3384774..6e7d4be 100644
--- a/src/rate_ctr.c
+++ b/src/rate_ctr.c
@@ -273,6 +273,16 @@
 	osmo_talloc_replace_string(grp, &grp->name, name);
 }
 
+/*! Get rate counter from group, identified by index idx
+ *  \param[in] grp Rate counter group
+ *  \param[in] idx Index of the counter to retrieve
+ *  \returns rate counter requested
+ */
+struct rate_ctr *rate_ctr_group_get_ctr(struct rate_ctr_group *grp, unsigned int idx)
+{
+	return &grp->ctr[idx];
+}
+
 /*! Add a number to the counter */
 void rate_ctr_add(struct rate_ctr *ctr, int inc)
 {
diff --git a/src/stat_item.c b/src/stat_item.c
index 2a0eb23..c471c1a 100644
--- a/src/stat_item.c
+++ b/src/stat_item.c
@@ -177,6 +177,16 @@
 	osmo_talloc_replace_string(statg, &statg->name, name);
 }
 
+/*! Get statistics item from group, identified by index idx
+ *  \param[in] grp Rate counter group
+ *  \param[in] idx Index of the counter to retrieve
+ *  \returns rate counter requested
+ */
+struct osmo_stat_item *osmo_stat_item_group_get_item(struct osmo_stat_item_group *grp, unsigned int idx)
+{
+	return grp->items[idx];
+}
+
 /*! Increase the stat_item to the given value.
  *  This function adds a new value for the given stat_item at the end of
  *  the FIFO.

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

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: Iebbf401f11e36645f8964d389460918eb9e0910e
Gerrit-Change-Number: 24469
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <pespin at sysmocom.de>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20210531/eb3df049/attachment.htm>


More information about the gerrit-log mailing list