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 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 #ifndef __STATS_TREE_PRIV_H
25 #define __STATS_TREE_PRIV_H
27 #include "stats_tree.h"
28 #include "ws_symbol_export.h"
32 #endif /* __cplusplus */
35 #define NUM_BUF_SIZE 32
37 /** implementations should define this to contain its own node related data
38 * as well as some operations on it */
39 typedef struct _st_node_pres st_node_pres;
41 /** implementations should define this to contain its own dynamic tree related data
42 * as well as some operations on it */
43 typedef struct _tree_pres tree_pres;
45 /** implementations should define this to contain its own static tree related data
46 * as well as some operations on it */
47 typedef struct _tree_cfg_pres tree_cfg_pres;
50 typedef struct _stat_node stat_node;
51 typedef struct _stats_tree_cfg stats_tree_cfg;
53 typedef struct _range_pair {
58 typedef struct _burst_bucket burst_bucket;
59 struct _burst_bucket {
71 /** the counter it keeps */
73 /** total of all values submitted - for computing averages */
79 /** fields for burst rate calculation */
81 burst_bucket *bh, *bt;
85 /** children nodes by name */
88 /** the owner of this node */
96 /** used to check if value is within range */
99 /** node presentation data */
104 /** the "class" from which it's derived */
118 /** used to lookup named parents:
119 * key: parent node name
124 /** used for quicker lookups of parent nodes */
128 * tree representation
129 * to be defined (if needed) by the implementations
133 /** every tree in nature has one */
137 struct _stats_tree_cfg {
141 register_stat_group_t stat_group;
143 gboolean in_use; /* GTK+ only */
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)(gpointer,gpointer,gpointer),
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 int stats_tree_packet(void*, packet_info*, epan_dissect_t*, const void *);
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 destoy */
192 WS_DLL_PUBLIC void stats_tree_free(stats_tree *st);
194 /** given an optarg splits the abbr part
195 and returns a newly allocated buffer containing it */
196 WS_DLL_PUBLIC gchar *stats_tree_get_abbr(const gchar *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 calcuate the size of the indentation and the longest string */
206 WS_DLL_PUBLIC guint stats_tree_branch_max_namelen(const stat_node *node, guint indent);
208 /** a text representation of a node,
209 if buffer is NULL returns a newly allocated string */
210 WS_DLL_PUBLIC gchar *stats_tree_node_to_str(const stat_node *node,
211 gchar *buffer, guint 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 gchar* stats_tree_get_displayname (gchar* fullname);
218 /** returns the column number of the default column to sort on */
219 WS_DLL_PUBLIC gint stats_tree_get_default_sort_col (stats_tree *st);
221 /** returns the default sort order to use */
222 WS_DLL_PUBLIC gboolean stats_tree_is_default_sort_DESC (stats_tree *st);
224 /** returns the column name for a given column index */
225 WS_DLL_PUBLIC const gchar* stats_tree_get_column_name (gint index);
227 /** returns the maximum number of characters in the value of a column */
228 WS_DLL_PUBLIC gint stats_tree_get_column_size (gint index);
230 /** returns the formatted column values for the current node
231 as array of gchar*. Caller must free entries and free array */
232 WS_DLL_PUBLIC gchar** 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 gint stats_tree_sort_compare (const stat_node *a,
238 gboolean sort_descending);
240 /** wrapper for stats_tree_sort_compare() function that can be called from array sort. */
241 WS_DLL_PUBLIC gint stat_node_array_sortcmp (gconstpointer a,
245 /** function to copy stats_tree into GString. format deternmines output format */
246 WS_DLL_PUBLIC GString* stats_tree_format_as_str(const stats_tree* st,
247 st_format_type format_type,
249 gboolean 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 gboolean sort_descending);
263 #endif /* __cplusplus */
265 #endif /* __STATS_TREE_PRIV_H */