Initial checkin of the stats-tree tap API
[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  * $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 tree related data
39 * as well as some operations on it */
40 typedef struct _tree_pres tree_pres;
41
42 typedef struct _stat_node stat_node;
43
44
45 typedef struct _range_pair {
46         gint floor;
47         gint ceil;
48 } range_pair_t;
49
50 struct _stat_node {
51         gchar*                  name;
52         int                             id;
53         
54         /* the counter it keeps */
55         gint                    counter;
56
57         /* children nodes by name */
58         GHashTable*             hash;
59         
60         /* the owner of this node */
61         stats_tree*             st;
62         
63         /* relatives */
64         stat_node*      parent;
65         stat_node*      children;
66         stat_node*      next;
67
68         /* used to check if value is within range */
69         range_pair_t* rng;
70         
71         /* node presentation data */
72         st_node_pres* pr;
73 } ;
74
75 struct _stats_tree {
76         guint8*                 abbr;
77         guint8*                 name;
78         
79         /* is this realy needed? */
80         char*                   filter;
81         
82         /* times */
83         float                   start;
84         float                   elapsed;
85                 
86
87            /* used to lookup named parents:
88                 *    key: parent node name
89                 *  value: parent node
90                 */
91         GHashTable*                     names;
92         
93            /* used for quicker lookups of parent nodes */
94         GPtrArray*                      parents;
95         
96         /* every tree in nature has one */
97         stat_node       root;
98         
99         /* dissector defined callbacks */
100         stat_tree_packet_cb packet;
101         stat_tree_init_cb init;
102
103         /**** tree representation
104          *      to be defined (if needed) by the implementations
105          */
106         tree_pres* pr;
107         
108         /*  node presentation callbacks
109          */
110                 
111         /* last to be called at node creation */
112         void (*setup_node_pr)(stat_node*);
113         
114         /* last to be called at node destruction */
115         void (*free_node_pr)(stat_node*);
116         
117         /* to be called for every node in the tree */
118         void (*draw_node)(stat_node*);
119         void (*reset_node)(stat_node*);
120         
121         /* tree presentation callbacks */
122         
123         tree_pres* (*new_tree_pr)(stats_tree*);
124         void (*free_tree_pr)(stats_tree*);
125         void (*draw_tree)(stats_tree*);
126         void (*reset_tree)(stats_tree*);
127 };
128
129 /* guess what, this is it! */
130 extern void stats_tree_presentation(void (*registry_iterator)(gpointer,gpointer,gpointer),
131                                                                         void (*setup_node_pr)(stat_node*),
132                                                                         void (*free_node_pr)(stat_node*),
133                                                                         void (*draw_node)(stat_node*),
134                                                                         void (*reset_node)(stat_node*),
135                                                                         tree_pres* (*new_tree_pr)(stats_tree*),
136                                                                         void (*free_tree_pr)(stats_tree*),
137                                                                         void (*draw_tree)(stats_tree*),
138                                                                         void (*reset_tree)(stats_tree*),
139                                                                         void* data);
140
141 /* callback for taps */
142 extern int  stats_tree_packet(void*, packet_info*, epan_dissect_t*, const void *);
143
144 /* callback for reset */
145 extern void reset_stats_tree(void*);
146
147 /* callback for destoy */
148 extern void free_stats_tree(stats_tree* st);
149
150 /* given an optarg splits the abbr part
151    and returns a newly allocated buffer containing it */
152 extern guint8* get_st_abbr(const guint8* optarg);
153
154 /* obtains a stats tree from the registry given its abbr */
155 extern stats_tree* get_stats_tree_by_abbr(guint8* abbr);
156
157 /* extracts node data as strings from a stat_node into
158    the buffers given by value, rate and precent
159    if NULL they are ignored */
160 extern void get_strings_from_node(const stat_node* node,
161                                                                   guint8* value,
162                                                                   guint8* rate,
163                                                                   guint8* percent);
164
165 /* populates the given GString with a tree representation of a branch given by node,
166    using indent spaces as indentation */
167 extern void stat_branch_to_str(const stat_node* node,
168                                                            GString* s,
169                                                            guint indent);
170
171 /* a text representation of a node,
172    if buffer is NULL returns a newly allocated string */
173 extern guint8* stat_node_to_str(const stat_node* node,
174                                                                 guint8* buffer, guint len);
175
176 /* destroys the stats_tree */
177 extern void free_stats_tree(stats_tree* st);
178
179 #endif /* __STATS_TREE_PRIV_H */