libosmocore  0.9.3
Osmocom core library
stat_item.h
Go to the documentation of this file.
1 #pragma once
2 
9 #include <stdint.h>
10 
11 #include <osmocom/core/linuxlist.h>
12 
13 struct osmo_stat_item_desc;
14 
15 #define STAT_ITEM_NOVALUE_ID 0
16 
18  int32_t id;
19  int32_t value;
20 };
21 
24  const struct osmo_stat_item_desc *desc;
28  int16_t last_offs;
31 };
32 
35  const char *name;
36  const char *description;
37  const char *unit;
38  unsigned int num_values;
39  int32_t default_value;
40 };
41 
45  const char *group_name_prefix;
47  const char *group_description;
49  int class_id;
51  const unsigned int num_items;
54 };
55 
59  struct llist_head list;
63  unsigned int idx;
65  struct osmo_stat_item *items[0];
66 };
67 
69  void *ctx,
70  const struct osmo_stat_item_group_desc *desc,
71  unsigned int idx);
72 
73 static inline void osmo_stat_item_group_udp_idx(
74  struct osmo_stat_item_group *grp, unsigned int idx)
75 {
76  grp->idx = idx;
77 }
78 
80 
81 void osmo_stat_item_set(struct osmo_stat_item *item, int32_t value);
82 
83 int osmo_stat_item_init(void *tall_ctx);
84 
86  const char *name, const unsigned int idx);
87 
89  const struct osmo_stat_item_group *statg, const char *name);
90 
107 int osmo_stat_item_get_next(const struct osmo_stat_item *item, int32_t *idx, int32_t *value);
108 
110 static int32_t osmo_stat_item_get_last(const struct osmo_stat_item *item);
111 
113 int osmo_stat_item_discard(const struct osmo_stat_item *item, int32_t *idx);
114 
116 int osmo_stat_item_discard_all(int32_t *idx);
117 
118 typedef int (*osmo_stat_item_handler_t)(
119  struct osmo_stat_item_group *, struct osmo_stat_item *, void *);
120 
121 typedef int (*osmo_stat_item_group_handler_t)(struct osmo_stat_item_group *, void *);
122 
128  osmo_stat_item_handler_t handle_item, void *data);
129 
130 int osmo_stat_item_for_each_group(osmo_stat_item_group_handler_t handle_group, void *data);
131 
132 static inline int32_t osmo_stat_item_get_last(const struct osmo_stat_item *item)
133 {
134  return item->values[item->last_offs].value;
135 }