sms: SMS where cropped (from VTY), concatenation of SMS where not possible
[osmocom-bb.git] / src / rate_ctr.c
index f58b5c4..6d771a4 100644 (file)
  */
 
 #include <stdint.h>
-#include <inttypes.h>
 #include <string.h>
 
-#include <osmocore/utils.h>
-#include <osmocore/linuxlist.h>
-#include <osmocore/talloc.h>
-#include <osmocore/timer.h>
-#include <osmocore/rate_ctr.h>
+#include <osmocom/core/utils.h>
+#include <osmocom/core/linuxlist.h>
+#include <osmocom/core/talloc.h>
+#include <osmocom/core/timer.h>
+#include <osmocom/core/rate_ctr.h>
 
 static LLIST_HEAD(rate_ctr_groups);
 
@@ -83,7 +82,7 @@ static void interval_expired(struct rate_ctr *ctr, enum rate_ctr_intv intv)
                ctr->intv[intv+1].rate += ctr->intv[intv].rate;
 }
 
-static struct timer_list rate_ctr_timer;
+static struct osmo_timer_list rate_ctr_timer;
 static uint64_t timer_ticks;
 
 /* The one-second interval has expired */
@@ -115,14 +114,48 @@ static void rate_ctr_timer_cb(void *data)
        llist_for_each_entry(ctrg, &rate_ctr_groups, list)
                rate_ctr_group_intv(ctrg);
 
-       bsc_schedule_timer(&rate_ctr_timer, 1, 0);
+       osmo_timer_schedule(&rate_ctr_timer, 1, 0);
 }
 
 int rate_ctr_init(void *tall_ctx)
 {
        tall_rate_ctr_ctx = tall_ctx;
        rate_ctr_timer.cb = rate_ctr_timer_cb;
-       bsc_schedule_timer(&rate_ctr_timer, 1, 0);
+       osmo_timer_schedule(&rate_ctr_timer, 1, 0);
 
        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;
+}
+
+const struct rate_ctr *rate_ctr_get_by_name(const struct rate_ctr_group *ctrg, const char *name)
+{
+       int i;
+       const 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;
+}