2 * implementor's API for stats_tree
3 * 2005, Luis E. G. Ontanon
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26 #ifndef __STATS_TREE_PRIV_H
27 #define __STATS_TREE_PRIV_H
29 #include "stats_tree.h"
32 #define NUM_BUF_SIZE 32
34 /** implementations should define this to contain its own node related data
35 * as well as some operations on it */
36 typedef struct _st_node_pres st_node_pres;
38 /** implementations should define this to contain its own dynamic tree related data
39 * as well as some operations on it */
40 typedef struct _tree_pres tree_pres;
42 /** implementations should define this to contain its own static tree related data
43 * as well as some operations on it */
44 typedef struct _tree_cfg_pres tree_cfg_pres;
47 typedef struct _stat_node stat_node;
48 typedef struct _stats_tree_cfg stats_tree_cfg;
50 typedef struct _range_pair {
59 /** the counter it keeps */
62 /** children nodes by name */
65 /** the owner of this node */
73 /** used to check if value is within range */
76 /** node presentation data */
81 /** the "class" from which it's derived */
90 /** used to lookup named parents:
91 * key: parent node name
96 /** used for quicker lookups of parent nodes */
100 * tree representation
101 * to be defined (if needed) by the implementations
105 /** every tree in nature has one */
109 struct _stats_tree_cfg {
113 register_stat_group_t stat_group;
117 /** dissector defined callbacks */
118 stat_tree_packet_cb packet;
119 stat_tree_init_cb init;
120 stat_tree_cleanup_cb cleanup;
122 /** tap listener flags for the per-packet callback */
126 * node presentation callbacks
129 /** last to be called at node creation */
130 void (*setup_node_pr)(stat_node*);
132 /** last to be called at node destruction */
133 void (*free_node_pr)(stat_node*);
135 /** to be called for every node in the tree */
136 void (*draw_node)(stat_node*);
137 void (*reset_node)(stat_node*);
140 * tree presentation callbacks
145 tree_pres *(*new_tree_pr)(stats_tree*);
146 void (*free_tree_pr)(stats_tree*);
147 void (*draw_tree)(stats_tree*);
148 void (*reset_tree)(stats_tree*);
151 /* guess what, this is it! */
152 extern void stats_tree_presentation(void (*registry_iterator)(gpointer,gpointer,gpointer),
153 void (*setup_node_pr)(stat_node*),
154 void (*free_node_pr)(stat_node*),
155 void (*draw_node)(stat_node*),
156 void (*reset_node)(stat_node*),
157 tree_pres *(*new_tree_pr)(stats_tree*),
158 void (*free_tree_pr)(stats_tree*),
159 void (*draw_tree)(stats_tree*),
160 void (*reset_tree)(stats_tree*),
163 extern stats_tree *stats_tree_new(stats_tree_cfg *cfg, tree_pres *pr, const char *filter);
165 /** callback for taps */
166 extern int stats_tree_packet(void*, packet_info*, epan_dissect_t*, const void *);
168 /** callback for reset */
169 extern void stats_tree_reset(void *p_st);
171 /** callback for clear */
172 extern void stats_tree_reinit(void *p_st);
174 /* callback for destoy */
175 extern void stats_tree_free(stats_tree *st);
177 /** given an optarg splits the abbr part
178 and returns a newly allocated buffer containing it */
179 extern gchar *stats_tree_get_abbr(const gchar *optarg);
181 /** obtains a stats tree from the registry given its abbr */
182 extern stats_tree_cfg *stats_tree_get_cfg_by_abbr(gchar *abbr);
184 /** extracts node data as strings from a stat_node into
185 the buffers given by value, rate and precent
186 if NULL they are ignored */
187 extern void stats_tree_get_strs_from_node(const stat_node *node,
192 /** populates the given GString with a tree representation of a branch given by node,
193 using indent spaces as indentation */
194 extern void stats_tree_branch_to_str(const stat_node *node,
198 /** used to calcuate the size of the indentation and the longest string */
199 extern guint stats_tree_branch_max_namelen(const stat_node *node, guint indent);
201 /** a text representation of a node,
202 if buffer is NULL returns a newly allocated string */
203 extern gchar *stats_tree_node_to_str(const stat_node *node,
204 gchar *buffer, guint len);
206 #endif /* __STATS_TREE_PRIV_H */