2 * implementor's API for stats_tree
3 * 2005, Luis E. G. Ontanon
5 * Wireshark - Network traffic analyzer
6 * By Gerald Combs <gerald@wireshark.org>
7 * Copyright 1998 Gerald Combs
9 * SPDX-License-Identifier: GPL-2.0-or-later
12 #ifndef __STATS_TREE_PRIV_H
13 #define __STATS_TREE_PRIV_H
15 #include "stats_tree.h"
16 #include "ws_symbol_export.h"
20 #endif /* __cplusplus */
23 #define NUM_BUF_SIZE 32
25 /** implementations should define this to contain its own node related data
26 * as well as some operations on it */
27 typedef struct _st_node_pres st_node_pres
;
29 /** implementations should define this to contain its own dynamic tree related data
30 * as well as some operations on it */
31 typedef struct _tree_pres tree_pres
;
33 /** implementations should define this to contain its own static tree related data
34 * as well as some operations on it */
35 typedef struct _tree_cfg_pres tree_cfg_pres
;
38 typedef struct _stat_node stat_node
;
39 typedef struct _stats_tree_cfg stats_tree_cfg
;
41 typedef struct _range_pair
{
46 typedef struct _burst_bucket burst_bucket
;
47 struct _burst_bucket
{
58 stat_node_datatype datatype
;
60 /** the counter it keeps */
62 /** total of all values submitted - for computing averages */
78 /** fields for burst rate calculation */
80 burst_bucket
*bh
, *bt
;
84 /** children nodes by name */
87 /** the owner of this node */
95 /** used to check if value is within range */
98 /** node presentation data */
103 /** the "class" from which it's derived */
117 /** used to lookup named parents:
118 * key: parent node name
123 /** used for quicker lookups of parent nodes */
127 * tree representation
128 * to be defined (if needed) by the implementations
132 /** every tree in nature has one */
136 struct _stats_tree_cfg
{
141 char *first_column_name
;
142 register_stat_group_t stat_group
;
146 /** dissector defined callbacks */
147 stat_tree_packet_cb packet
;
148 stat_tree_init_cb init
;
149 stat_tree_cleanup_cb cleanup
;
151 /** tap listener flags for the per-packet callback */
155 * node presentation callbacks
158 /** last to be called at node creation */
159 void (*setup_node_pr
)(stat_node
*);
162 * tree presentation callbacks
167 tree_pres
*(*new_tree_pr
)(stats_tree
*);
168 void (*free_tree_pr
)(stats_tree
*);
170 /** flags for the stats tree (sorting etc.) default values to new trees */
174 /* guess what, this is it! */
175 WS_DLL_PUBLIC
void stats_tree_presentation(void (*registry_iterator
)(void *,void *,void *),
176 void (*setup_node_pr
)(stat_node
*),
177 void (*free_tree_pr
)(stats_tree
*),
180 WS_DLL_PUBLIC stats_tree
*stats_tree_new(stats_tree_cfg
*cfg
, tree_pres
*pr
, const char *filter
);
182 /** callback for taps */
183 WS_DLL_PUBLIC tap_packet_status
stats_tree_packet(void*, packet_info
*, epan_dissect_t
*, const void *, tap_flags_t flags
);
185 /** callback for reset */
186 WS_DLL_PUBLIC
void stats_tree_reset(void *p_st
);
188 /** callback for clear */
189 WS_DLL_PUBLIC
void stats_tree_reinit(void *p_st
);
191 /* callback for destroy */
192 WS_DLL_PUBLIC
void stats_tree_free(stats_tree
*st
);
194 /** given an ws_optarg splits the abbr part
195 and returns a newly allocated buffer containing it */
196 WS_DLL_PUBLIC
char *stats_tree_get_abbr(const char *ws_optarg
);
198 /** obtains a stats tree from the registry given its abbr */
199 WS_DLL_PUBLIC stats_tree_cfg
*stats_tree_get_cfg_by_abbr(const char *abbr
);
201 /** obtains a stats tree list from the registry
202 caller should free returned list with g_list_free() */
203 WS_DLL_PUBLIC GList
*stats_tree_get_cfg_list(void);
205 /** used to calculate the size of the indentation and the longest string */
206 WS_DLL_PUBLIC
unsigned stats_tree_branch_max_namelen(const stat_node
*node
, unsigned indent
);
208 /** a text representation of a node,
209 if buffer is NULL returns a newly allocated string */
210 WS_DLL_PUBLIC
char *stats_tree_node_to_str(const stat_node
*node
,
211 char *buffer
, unsigned len
);
213 /** get the display name for the stats_tree (or node name) based on the
214 st_sort_showfullname preference. If not set remove everything before
215 last unescaped backslash. Caller must free the result */
216 WS_DLL_PUBLIC
char* stats_tree_get_displayname (char* fullname
);
218 /** returns the column number of the default column to sort on */
219 WS_DLL_PUBLIC
int stats_tree_get_default_sort_col (stats_tree
*st
);
221 /** returns the default sort order to use */
222 WS_DLL_PUBLIC
bool stats_tree_is_default_sort_DESC (stats_tree
*st
);
224 /** returns the column name for a given column index */
225 WS_DLL_PUBLIC
const char* stats_tree_get_column_name (stats_tree_cfg
*st_config
, int col_index
);
227 /** returns the maximum number of characters in the value of a column */
228 WS_DLL_PUBLIC
int stats_tree_get_column_size (int col_index
);
230 /** returns the formatted column values for the current node
231 as array of char*. Caller must free entries and free array */
232 WS_DLL_PUBLIC
char** stats_tree_get_values_from_node (const stat_node
* node
);
234 /** function to compare two nodes for sort, based on sort_column. */
235 WS_DLL_PUBLIC
int stats_tree_sort_compare (const stat_node
*a
,
238 bool sort_descending
);
240 /** wrapper for stats_tree_sort_compare() function that can be called from array sort. */
241 WS_DLL_PUBLIC
int stat_node_array_sortcmp (const void *a
,
245 /** function to copy stats_tree into GString. format determines output format */
246 WS_DLL_PUBLIC GString
* stats_tree_format_as_str(const stats_tree
* st
,
247 st_format_type format_type
,
249 bool sort_descending
);
251 /** helper funcation to add note to formatted stats_tree */
252 WS_DLL_PUBLIC
void stats_tree_format_node_as_str(const stat_node
*node
,
254 st_format_type format_type
,
259 bool sort_descending
);
263 #endif /* __cplusplus */
265 #endif /* __STATS_TREE_PRIV_H */