sq epan/dissectors/pidl/rcg/rcg.cnf
[wireshark-sm.git] / epan / stats_tree_priv.h
blobe1d8ba7010b0de338c11aff6336e84c182126df0
1 /** @file
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"
18 #ifdef __cplusplus
19 extern "C" {
20 #endif /* __cplusplus */
22 #define INDENT_MAX 32
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 {
42 int floor;
43 int ceil;
44 } range_pair_t;
46 typedef struct _burst_bucket burst_bucket;
47 struct _burst_bucket {
48 burst_bucket *next;
49 burst_bucket *prev;
50 int count;
51 double bucket_no;
52 double start_time;
55 struct _stat_node {
56 char* name;
57 int id;
58 stat_node_datatype datatype;
60 /** the counter it keeps */
61 int counter;
62 /** total of all values submitted - for computing averages */
63 union {
64 int64_t int_total;
65 double float_total;
66 } total;
67 union {
68 int int_min;
69 float float_min;
70 } minvalue;
71 union {
72 int int_max;
73 float float_max;
74 } maxvalue;
76 int st_flags;
78 /** fields for burst rate calculation */
79 int bcount;
80 burst_bucket *bh, *bt;
81 int max_burst;
82 double burst_time;
84 /** children nodes by name */
85 GHashTable *hash;
87 /** the owner of this node */
88 stats_tree *st;
90 /** relatives */
91 stat_node *parent;
92 stat_node *children;
93 stat_node *next;
95 /** used to check if value is within range */
96 range_pair_t *rng;
98 /** node presentation data */
99 st_node_pres *pr;
102 struct _stats_tree {
103 /** the "class" from which it's derived */
104 stats_tree_cfg *cfg;
106 char *filter;
108 /* times */
109 double start;
110 double elapsed;
111 double now;
113 int st_flags;
114 int num_columns;
115 char *display_name;
117 /** used to lookup named parents:
118 * key: parent node name
119 * value: parent node
121 GHashTable *names;
123 /** used for quicker lookups of parent nodes */
124 GPtrArray *parents;
127 * tree representation
128 * to be defined (if needed) by the implementations
130 tree_pres *pr;
132 /** every tree in nature has one */
133 stat_node root;
136 struct _stats_tree_cfg {
137 char *abbr;
138 char *path;
139 char *title;
140 char *tapname;
141 char *first_column_name;
142 register_stat_group_t stat_group;
144 bool plugin;
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 */
152 unsigned flags;
155 * node presentation callbacks
158 /** last to be called at node creation */
159 void (*setup_node_pr)(stat_node*);
162 * tree presentation callbacks
164 tree_cfg_pres *pr;
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 */
171 unsigned st_flags;
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*),
178 void *data);
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,
236 const stat_node *b,
237 int sort_column,
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,
242 const void *b,
243 void *user_data);
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,
248 int sort_column,
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,
253 GString *s,
254 st_format_type format_type,
255 unsigned indent,
256 const char *path,
257 int maxnamelen,
258 int sort_column,
259 bool sort_descending);
261 #ifdef __cplusplus
263 #endif /* __cplusplus */
265 #endif /* __STATS_TREE_PRIV_H */