There was a design flaw that caused a crash on windows and
[obnox/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  * $Id$
6  *
7  * Ethereal - Network traffic analyzer
8  * By Gerald Combs <gerald@ethereal.com>
9  * Copyright 1998 Gerald Combs
10  * 
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.
15  * 
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.
20  * 
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.
24  */
25
26 #ifndef __STATS_TREE_PRIV_H
27 #define  __STATS_TREE_PRIV_H
28
29 #include "stats_tree.h"
30
31 #define INDENT_MAX 32
32 #define NUM_BUF_SIZE 32
33
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;
37
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;
41
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;
45
46
47 typedef struct _stat_node stat_node;
48 typedef struct _stats_tree_cfg stats_tree_cfg;
49
50 typedef struct _range_pair {
51         gint floor;
52         gint ceil;
53 } range_pair_t;
54
55 struct _stat_node {
56         gchar*                  name;
57         int                             id;
58         
59         /* the counter it keeps */
60         gint                    counter;
61
62         /* children nodes by name */
63         GHashTable*             hash;
64         
65         /* the owner of this node */
66         stats_tree*     st;
67         
68         /* relatives */
69         stat_node*      parent;
70         stat_node*      children;
71         stat_node*      next;
72
73         /* used to check if value is within range */
74         range_pair_t* rng;
75         
76         /* node presentation data */
77         st_node_pres* pr;
78 };
79
80 struct _stats_tree {
81         /* the "class" from which it's derived */
82         stats_tree_cfg* cfg;
83         
84         char*                   filter;
85         
86         /* times */
87         float                   start;
88         float                   elapsed;
89
90    /* used to lookup named parents:
91         *    key: parent node name
92         *  value: parent node
93         */
94         GHashTable*                     names;
95         
96    /* used for quicker lookups of parent nodes */
97         GPtrArray*                      parents;
98                 
99         /*
100          *  tree representation
101          *      to be defined (if needed) by the implementations
102          */
103         tree_pres* pr;
104         
105         /* every tree in nature has one */
106         stat_node       root;
107 };
108
109 struct _stats_tree_cfg {
110         guint8*                 abbr;
111         guint8*                 name;
112         guint8*                 tapname;
113         
114         
115         /* dissector defined callbacks */
116         stat_tree_packet_cb packet;
117         stat_tree_init_cb init;
118
119         
120         /*
121          * node presentation callbacks
122          */
123
124         /* last to be called at node creation */
125         void (*setup_node_pr)(stat_node*);
126         
127         /* last to be called at node destruction */
128         void (*free_node_pr)(stat_node*);
129         
130         /* to be called for every node in the tree */
131         void (*draw_node)(stat_node*);
132         void (*reset_node)(stat_node*);
133         
134         /*
135          * tree presentation callbacks
136          */
137         tree_cfg_pres* pr;
138         
139         
140         tree_pres* (*new_tree_pr)(stats_tree*);
141         void (*free_tree_pr)(stats_tree*);
142         void (*draw_tree)(stats_tree*);
143         void (*reset_tree)(stats_tree*);
144 };
145
146 /* guess what, this is it! */
147 extern void stats_tree_presentation(void (*registry_iterator)(gpointer,gpointer,gpointer),
148                                                                         void (*setup_node_pr)(stat_node*),
149                                                                         void (*free_node_pr)(stat_node*),
150                                                                         void (*draw_node)(stat_node*),
151                                                                         void (*reset_node)(stat_node*),
152                                                                         tree_pres* (*new_tree_pr)(stats_tree*),
153                                                                         void (*free_tree_pr)(stats_tree*),
154                                                                         void (*draw_tree)(stats_tree*),
155                                                                         void (*reset_tree)(stats_tree*),
156                                                                         void* data);
157
158 extern stats_tree* new_stats_tree(stats_tree_cfg* cfg, tree_pres* pr, char* filter);
159
160 /* callback for taps */
161 extern int  stats_tree_packet(void*, packet_info*, epan_dissect_t*, const void *);
162
163 /* callback for reset */
164 extern void reset_stats_tree(void* p_st);
165
166 /* callback for clear */
167 extern void reinit_stats_tree(void* p_st);
168
169 /* callback for destoy */
170 extern void free_stats_tree(stats_tree* st);
171
172 /* given an optarg splits the abbr part
173    and returns a newly allocated buffer containing it */
174 extern guint8* get_st_abbr(const guint8* optarg);
175
176 /* obtains a stats tree from the registry given its abbr */
177 extern stats_tree_cfg* get_stats_tree_by_abbr(guint8* abbr);
178
179 /* extracts node data as strings from a stat_node into
180    the buffers given by value, rate and precent
181    if NULL they are ignored */
182 extern void get_strings_from_node(const stat_node* node,
183                                                                   guint8* value,
184                                                                   guint8* rate,
185                                                                   guint8* percent);
186
187 /* populates the given GString with a tree representation of a branch given by node,
188    using indent spaces as indentation */
189 extern void stat_branch_to_str(const stat_node* node,
190                                                            GString* s,
191                                                            guint indent);
192
193 /* used to calcuate the size of the indentation and the longest string */
194 extern guint stats_branch_max_name_len(const stat_node* node, guint indent);
195
196 /* a text representation of a node,
197    if buffer is NULL returns a newly allocated string */
198 extern guint8* stat_node_to_str(const stat_node* node,
199                                                                 guint8* buffer, guint len);
200
201 /* destroys the stats_tree */
202 extern void free_stats_tree(stats_tree* st);
203
204 #endif /* __STATS_TREE_PRIV_H */