From 2d42ddeba37ed7e0d54bf10dc66b7549ad43bc5b Mon Sep 17 00:00:00 2001 From: Daniel Willmann Date: Fri, 8 Apr 2011 10:46:18 +0200 Subject: Add functions to search for rate counters by name * rate_ctr_get_group_by_name_idx, rate_ctr_get_by_name --- include/osmocom/core/rate_ctr.h | 2 ++ src/rate_ctr.c | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/include/osmocom/core/rate_ctr.h b/include/osmocom/core/rate_ctr.h index 9efc23db..63baa322 100644 --- a/include/osmocom/core/rate_ctr.h +++ b/include/osmocom/core/rate_ctr.h @@ -75,4 +75,6 @@ static inline void rate_ctr_inc(struct rate_ctr *ctr) /* Initialize the counter module */ int rate_ctr_init(void *tall_ctx); +struct rate_ctr_group *rate_ctr_get_group_by_name_idx(const char *name, const unsigned int idx); +struct rate_ctr *rate_ctr_get_by_name(const struct rate_ctr_group *ctrg, const char *name); #endif /* RATE_CTR_H */ diff --git a/src/rate_ctr.c b/src/rate_ctr.c index dd56e806..a7fc9496 100644 --- a/src/rate_ctr.c +++ b/src/rate_ctr.c @@ -125,3 +125,37 @@ int rate_ctr_init(void *tall_ctx) return 0; } + +struct rate_ctr_group *rate_ctr_get_group_by_name_idx(const char *name, const unsigned int idx) +{ + struct rate_ctr_group *ctrg; + + llist_for_each_entry(ctrg, &rate_ctr_groups, list) { + if (!ctrg->desc) + continue; + + if (!strcmp(ctrg->desc->group_name_prefix, name) && + ctrg->idx == idx) { + return ctrg; + } + } + return NULL; +} + +struct rate_ctr *rate_ctr_get_by_name(const struct rate_ctr_group *ctrg, const char *name) +{ + int i; + struct rate_ctr_desc *ctr_desc; + + if (!ctrg->desc) + return NULL; + + for (i = 0; i < ctrg->desc->num_ctr; i++) { + ctr_desc = &ctrg->desc->ctr_desc[i]; + + if (!strcmp(ctr_desc->name, name)) { + return &ctrg->ctr[i]; + } + } + return NULL; +} -- cgit v1.2.3