libosmocore
0.9.3
Osmocom core library
|
00001 #pragma once 00002 00009 #include <stdint.h> 00010 00011 #include <osmocom/core/linuxlist.h> 00012 00013 struct osmo_stat_item_desc; 00014 00015 #define STAT_ITEM_NOVALUE_ID 0 00016 00017 struct osmo_stat_item_value { 00018 int32_t id; 00019 int32_t value; 00020 }; 00021 00023 struct osmo_stat_item { 00024 const struct osmo_stat_item_desc *desc; 00026 int32_t last_value_index; 00028 int16_t last_offs; 00030 struct osmo_stat_item_value values[0]; 00031 }; 00032 00034 struct osmo_stat_item_desc { 00035 const char *name; 00036 const char *description; 00037 const char *unit; 00038 unsigned int num_values; 00039 int32_t default_value; 00040 }; 00041 00043 struct osmo_stat_item_group_desc { 00045 const char *group_name_prefix; 00047 const char *group_description; 00049 int class_id; 00051 const unsigned int num_items; 00053 const struct osmo_stat_item_desc *item_desc; 00054 }; 00055 00057 struct osmo_stat_item_group { 00059 struct llist_head list; 00061 const struct osmo_stat_item_group_desc *desc; 00063 unsigned int idx; 00065 struct osmo_stat_item *items[0]; 00066 }; 00067 00068 struct osmo_stat_item_group *osmo_stat_item_group_alloc( 00069 void *ctx, 00070 const struct osmo_stat_item_group_desc *desc, 00071 unsigned int idx); 00072 00073 static inline void osmo_stat_item_group_udp_idx( 00074 struct osmo_stat_item_group *grp, unsigned int idx) 00075 { 00076 grp->idx = idx; 00077 } 00078 00079 void osmo_stat_item_group_free(struct osmo_stat_item_group *statg); 00080 00081 void osmo_stat_item_set(struct osmo_stat_item *item, int32_t value); 00082 00083 int osmo_stat_item_init(void *tall_ctx); 00084 00085 struct osmo_stat_item_group *osmo_stat_item_get_group_by_name_idx( 00086 const char *name, const unsigned int idx); 00087 00088 const struct osmo_stat_item *osmo_stat_item_get_by_name( 00089 const struct osmo_stat_item_group *statg, const char *name); 00090 00107 int osmo_stat_item_get_next(const struct osmo_stat_item *item, int32_t *idx, int32_t *value); 00108 00110 static int32_t osmo_stat_item_get_last(const struct osmo_stat_item *item); 00111 00113 int osmo_stat_item_discard(const struct osmo_stat_item *item, int32_t *idx); 00114 00116 int osmo_stat_item_discard_all(int32_t *idx); 00117 00118 typedef int (*osmo_stat_item_handler_t)( 00119 struct osmo_stat_item_group *, struct osmo_stat_item *, void *); 00120 00121 typedef int (*osmo_stat_item_group_handler_t)(struct osmo_stat_item_group *, void *); 00122 00127 int osmo_stat_item_for_each_item(struct osmo_stat_item_group *statg, 00128 osmo_stat_item_handler_t handle_item, void *data); 00129 00130 int osmo_stat_item_for_each_group(osmo_stat_item_group_handler_t handle_group, void *data); 00131 00132 static inline int32_t osmo_stat_item_get_last(const struct osmo_stat_item *item) 00133 { 00134 return item->values[item->last_offs].value; 00135 }