Add TapParameterDialog.
[metze/wireshark/wip.git] / epan / stats_tree_priv.h
1 /* stats_tree_priv.h
2  * implementor's API for stats_tree
3  * 2005, Luis E. G. Ontanon
4  *
5  * Wireshark - Network traffic analyzer
6  * By Gerald Combs <gerald@wireshark.org>
7  * Copyright 1998 Gerald Combs
8  *
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.
13  *
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.
18  *
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.
22  */
23
24 #ifndef __STATS_TREE_PRIV_H
25 #define  __STATS_TREE_PRIV_H
26
27 #include "stats_tree.h"
28 #include "ws_symbol_export.h"
29
30 #ifdef __cplusplus
31 extern "C" {
32 #endif /* __cplusplus */
33
34 #define INDENT_MAX 32
35 #define NUM_BUF_SIZE 32
36
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;
40
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;
44
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;
48
49
50 typedef struct _stat_node stat_node;
51 typedef struct _stats_tree_cfg stats_tree_cfg;
52
53 typedef struct _range_pair {
54         gint floor;
55         gint ceil;
56 } range_pair_t;
57
58 typedef struct _burst_bucket burst_bucket;
59 struct _burst_bucket {
60         burst_bucket    *next;
61         burst_bucket    *prev;
62         gint                    count;
63         double                  bucket_no;
64         double                  start_time;
65 };
66
67 struct _stat_node {
68         gchar*                  name;
69         int                     id;
70
71         /** the counter it keeps */
72         gint                    counter;
73         /** total of all values submitted - for computing averages */
74         gint64                  total;
75         gint                    minvalue;
76         gint                    maxvalue;
77         int                             st_flags;
78
79         /** fields for burst rate calculation */
80         gint                    bcount;
81         burst_bucket    *bh, *bt;
82         gint                    max_burst;
83         double                  burst_time;
84
85         /** children nodes by name */
86         GHashTable              *hash;
87
88         /** the owner of this node */
89         stats_tree              *st;
90
91         /** relatives */
92         stat_node               *parent;
93         stat_node               *children;
94         stat_node               *next;
95
96         /** used to check if value is within range */
97         range_pair_t            *rng;
98
99         /** node presentation data */
100         st_node_pres            *pr;
101 };
102
103 struct _stats_tree {
104         /** the "class" from which it's derived */
105         stats_tree_cfg          *cfg;
106
107         char                    *filter;
108
109         /* times */
110         double                  start;
111         double                  elapsed;
112         double                  now;
113
114         int                             st_flags;
115         gint                    num_columns;
116         gchar                   *display_name;
117
118    /** used to lookup named parents:
119         *    key: parent node name
120         *  value: parent node
121         */
122         GHashTable              *names;
123
124    /** used for quicker lookups of parent nodes */
125         GPtrArray               *parents;
126
127         /**
128          *  tree representation
129          *      to be defined (if needed) by the implementations
130          */
131         tree_pres               *pr;
132
133         /** every tree in nature has one */
134         stat_node               root;
135 };
136
137 struct _stats_tree_cfg {
138         gchar*                  abbr;
139         gchar*                  name;
140         gchar*                  tapname;
141         register_stat_group_t   stat_group;
142
143         gboolean in_use; /* GTK+ only */
144         gboolean plugin;
145
146         /** dissector defined callbacks */
147         stat_tree_packet_cb packet;
148         stat_tree_init_cb init;
149         stat_tree_cleanup_cb cleanup;
150
151         /** tap listener flags for the per-packet callback */
152         guint flags;
153
154         /*
155          * node presentation callbacks
156          */
157
158         /** last to be called at node creation */
159         void (*setup_node_pr)(stat_node*);
160
161         /**
162          * tree presentation callbacks
163          */
164         tree_cfg_pres *pr;
165
166
167         tree_pres *(*new_tree_pr)(stats_tree*);
168         void (*free_tree_pr)(stats_tree*);
169
170         /** flags for the stats tree (sorting etc.) default values to new trees */
171         guint st_flags;
172 };
173
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*),
178                                     void *data);
179
180 WS_DLL_PUBLIC stats_tree *stats_tree_new(stats_tree_cfg *cfg, tree_pres *pr, const char *filter);
181
182 /** callback for taps */
183 WS_DLL_PUBLIC int  stats_tree_packet(void*, packet_info*, epan_dissect_t*, const void *);
184
185 /** callback for reset */
186 WS_DLL_PUBLIC void stats_tree_reset(void *p_st);
187
188 /** callback for clear */
189 WS_DLL_PUBLIC void stats_tree_reinit(void *p_st);
190
191 /* callback for destoy */
192 WS_DLL_PUBLIC void stats_tree_free(stats_tree *st);
193
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);
197
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);
200
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);
204
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);
207
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);
212
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);
217
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);
220
221 /** returns the default sort order to use */
222 WS_DLL_PUBLIC gboolean stats_tree_is_default_sort_DESC (stats_tree *st);
223
224 /** returns the column name for a given column index */
225 WS_DLL_PUBLIC const gchar* stats_tree_get_column_name (gint index);
226
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);
229
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);
233
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,
236                                         const stat_node *b,
237                                         gint sort_column,
238                                         gboolean sort_descending);
239
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,
242                                         gconstpointer b,
243                                         gpointer user_data);
244
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,
248                                         gint sort_column,
249                                         gboolean sort_descending);
250
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                                         guint indent,
256                                         const gchar *path,
257                                         gint maxnamelen,
258                                         gint sort_column,
259                                         gboolean sort_descending);
260
261 #ifdef __cplusplus
262 }
263 #endif /* __cplusplus */
264
265 #endif /* __STATS_TREE_PRIV_H */