HACK: pinfo->private_data points to smb_info again
[wireshark-wip.git] / epan / stats_tree_priv.h
blob2a2fadf139e77821c7fe960d13603cc2ba762d31
1 /* stats_tree_priv.h
2 * implementor's API for stats_tree
3 * 2005, Luis E. G. Ontanon
5 * $Id$
7 * Wireshark - Network traffic analyzer
8 * By Gerald Combs <gerald@wireshark.org>
9 * Copyright 1998 Gerald Combs
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 #ifndef __STATS_TREE_PRIV_H
27 #define __STATS_TREE_PRIV_H
29 #include "stats_tree.h"
30 #include "ws_symbol_export.h"
32 #define INDENT_MAX 32
33 #define NUM_BUF_SIZE 32
35 /** implementations should define this to contain its own node related data
36 * as well as some operations on it */
37 typedef struct _st_node_pres st_node_pres;
39 /** implementations should define this to contain its own dynamic tree related data
40 * as well as some operations on it */
41 typedef struct _tree_pres tree_pres;
43 /** implementations should define this to contain its own static tree related data
44 * as well as some operations on it */
45 typedef struct _tree_cfg_pres tree_cfg_pres;
48 typedef struct _stat_node stat_node;
49 typedef struct _stats_tree_cfg stats_tree_cfg;
51 typedef struct _range_pair {
52 gint floor;
53 gint ceil;
54 } range_pair_t;
56 struct _stat_node {
57 gchar* name;
58 int id;
60 /** the counter it keeps */
61 gint counter;
63 /** children nodes by name */
64 GHashTable *hash;
66 /** the owner of this node */
67 stats_tree *st;
69 /** relatives */
70 stat_node *parent;
71 stat_node *children;
72 stat_node *next;
74 /** used to check if value is within range */
75 range_pair_t *rng;
77 /** node presentation data */
78 st_node_pres *pr;
81 struct _stats_tree {
82 /** the "class" from which it's derived */
83 stats_tree_cfg *cfg;
85 char *filter;
87 /* times */
88 double start;
89 double elapsed;
91 /** used to lookup named parents:
92 * key: parent node name
93 * value: parent node
95 GHashTable *names;
97 /** used for quicker lookups of parent nodes */
98 GPtrArray *parents;
101 * tree representation
102 * to be defined (if needed) by the implementations
104 tree_pres *pr;
106 /** every tree in nature has one */
107 stat_node root;
110 struct _stats_tree_cfg {
111 gchar* abbr;
112 gchar* name;
113 gchar* tapname;
114 register_stat_group_t stat_group;
116 gboolean in_use;
117 gboolean plugin;
119 /** dissector defined callbacks */
120 stat_tree_packet_cb packet;
121 stat_tree_init_cb init;
122 stat_tree_cleanup_cb cleanup;
124 /** tap listener flags for the per-packet callback */
125 guint flags;
128 * node presentation callbacks
131 /** last to be called at node creation */
132 void (*setup_node_pr)(stat_node*);
134 /** last to be called at node destruction */
135 void (*free_node_pr)(stat_node*);
137 /** to be called for every node in the tree */
138 void (*draw_node)(stat_node*);
139 void (*reset_node)(stat_node*);
142 * tree presentation callbacks
144 tree_cfg_pres *pr;
147 tree_pres *(*new_tree_pr)(stats_tree*);
148 void (*free_tree_pr)(stats_tree*);
149 void (*draw_tree)(stats_tree*);
150 void (*reset_tree)(stats_tree*);
153 /* guess what, this is it! */
154 WS_DLL_PUBLIC void stats_tree_presentation(void (*registry_iterator)(gpointer,gpointer,gpointer),
155 void (*setup_node_pr)(stat_node*),
156 void (*free_node_pr)(stat_node*),
157 void (*draw_node)(stat_node*),
158 void (*reset_node)(stat_node*),
159 tree_pres *(*new_tree_pr)(stats_tree*),
160 void (*free_tree_pr)(stats_tree*),
161 void (*draw_tree)(stats_tree*),
162 void (*reset_tree)(stats_tree*),
163 void *data);
165 WS_DLL_PUBLIC stats_tree *stats_tree_new(stats_tree_cfg *cfg, tree_pres *pr, const char *filter);
167 /** callback for taps */
168 WS_DLL_PUBLIC int stats_tree_packet(void*, packet_info*, epan_dissect_t*, const void *);
170 /** callback for reset */
171 WS_DLL_PUBLIC void stats_tree_reset(void *p_st);
173 /** callback for clear */
174 WS_DLL_PUBLIC void stats_tree_reinit(void *p_st);
176 /* callback for destoy */
177 WS_DLL_PUBLIC void stats_tree_free(stats_tree *st);
179 /** given an optarg splits the abbr part
180 and returns a newly allocated buffer containing it */
181 WS_DLL_PUBLIC gchar *stats_tree_get_abbr(const gchar *optarg);
183 /** obtains a stats tree from the registry given its abbr */
184 WS_DLL_PUBLIC stats_tree_cfg *stats_tree_get_cfg_by_abbr(gchar *abbr);
186 /** obtains a stats tree list from the registry
187 caller should free returned list with g_list_free() */
188 WS_DLL_PUBLIC GList *stats_tree_get_cfg_list(void);
190 /** extracts node data as strings from a stat_node into
191 the buffers given by value, rate and precent
192 if NULL they are ignored */
193 WS_DLL_PUBLIC void stats_tree_get_strs_from_node(const stat_node *node,
194 gchar *value,
195 gchar *rate,
196 gchar *percent);
198 /** populates the given GString with a tree representation of a branch given by node,
199 using indent spaces as indentation */
200 WS_DLL_PUBLIC void stats_tree_branch_to_str(const stat_node *node,
201 GString *s,
202 guint indent);
204 /** used to calcuate the size of the indentation and the longest string */
205 WS_DLL_PUBLIC guint stats_tree_branch_max_namelen(const stat_node *node, guint indent);
207 /** a text representation of a node,
208 if buffer is NULL returns a newly allocated string */
209 WS_DLL_PUBLIC gchar *stats_tree_node_to_str(const stat_node *node,
210 gchar *buffer, guint len);
212 #endif /* __STATS_TREE_PRIV_H */