libosmocore  0.9.3.20160317
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 OSMO_STAT_ITEM_NOVALUE_ID 0
16 #define OSMO_STAT_ITEM_NO_UNIT NULL
17 
19  int32_t id;
20  int32_t value;
21 };
22 
25  const struct osmo_stat_item_desc *desc;
29  int16_t last_offs;
32 };
33 
36  const char *name;
37  const char *description;
38  const char *unit;
39  unsigned int num_values;
40  int32_t default_value;
41 };
42 
46  const char *group_name_prefix;
48  const char *group_description;
50  int class_id;
52  const unsigned int num_items;
55 };
56 
60  struct llist_head list;
64  unsigned int idx;
66  struct osmo_stat_item *items[0];
67 };
68 
70  void *ctx,
71  const struct osmo_stat_item_group_desc *desc,
72  unsigned int idx);
73 
74 static inline void osmo_stat_item_group_udp_idx(
75  struct osmo_stat_item_group *grp, unsigned int idx)
76 {
77  grp->idx = idx;
78 }
79 
81 
82 void osmo_stat_item_set(struct osmo_stat_item *item, int32_t value);
83 
84 int osmo_stat_item_init(void *tall_ctx);
85 
87  const char *name, const unsigned int idx);
88 
90  const struct osmo_stat_item_group *statg, const char *name);
91 
108 int osmo_stat_item_get_next(const struct osmo_stat_item *item, int32_t *idx, int32_t *value);
109 
111 static int32_t osmo_stat_item_get_last(const struct osmo_stat_item *item);
112 
114 int osmo_stat_item_discard(const struct osmo_stat_item *item, int32_t *idx);
115 
117 int osmo_stat_item_discard_all(int32_t *idx);
118 
119 typedef int (*osmo_stat_item_handler_t)(
120  struct osmo_stat_item_group *, struct osmo_stat_item *, void *);
121 
122 typedef int (*osmo_stat_item_group_handler_t)(struct osmo_stat_item_group *, void *);
123 
129  osmo_stat_item_handler_t handle_item, void *data);
130 
131 int osmo_stat_item_for_each_group(osmo_stat_item_group_handler_t handle_group, void *data);
132 
133 static inline int32_t osmo_stat_item_get_last(const struct osmo_stat_item *item)
134 {
135  return item->values[item->last_offs].value;
136 }