Try to fix Windows compilation
[metze/wireshark/wip.git] / epan / stats_tree.h
1 /* stats_tree.h
2  * A counter tree API for Wireshark dissectors
3  * 2005, Luis E. G. Ontanon
4  *
5  * $Id$
6  *
7  * Wireshark - Network traffic analyzer
8  * By Gerald Combs <gerald@wireshark.org>
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24  */
25 #ifndef __STATS_TREE_H
26 #define __STATS_TREE_H
27
28 #include <glib.h>
29 #include <epan/epan.h>
30 #include <epan/packet_info.h>
31 #include <epan/to_str.h>
32 #include <epan/tap.h>
33 #include "../stat_menu.h"
34 #include "../register.h"
35
36 #define STAT_TREE_ROOT "root"
37
38 /* obscure information regarding the stats_tree */
39 typedef struct _stats_tree stats_tree;
40
41 /* tap packet callback for stats_tree */
42 typedef int  (*stat_tree_packet_cb)(stats_tree*,
43                                     packet_info*,
44                                     epan_dissect_t*,
45                                     const void *);
46
47 /* stats_tree initialization callback */
48 typedef void  (*stat_tree_init_cb)(stats_tree*);
49
50 /* stats_tree cleanup callback */
51 typedef void  (*stat_tree_cleanup_cb)(stats_tree*);
52
53 /* registers a new stats tree with default group REGISTER_STAT_GROUP_UNSORTED
54  * abbr: protocol abbr
55  * name: protocol display name
56  * flags: tap listener flags for per-packet callback
57  * packet: per packet callback
58  * init: tree initialization callback
59  * cleanup: cleanup callback
60  */
61 extern void stats_tree_register(const gchar *tapname,
62                                 const gchar *abbr,
63                                 const gchar *name,
64                                 guint flags,
65                                 stat_tree_packet_cb packet,
66                                 stat_tree_init_cb init,
67                                 stat_tree_cleanup_cb cleanup);
68
69 /* registers a new stats tree with default group REGISTER_STAT_GROUP_UNSORTED from a plugin
70  * abbr: protocol abbr
71  * name: protocol display name
72  * flags: tap listener flags for per-packet callback
73  * packet: per packet callback
74  * init: tree initialization callback
75  * cleanup: cleanup callback
76  */
77 extern void stats_tree_register_plugin(const gchar *tapname,
78                                 const gchar *abbr,
79                                 const gchar *name,
80                                 guint flags,
81                                 stat_tree_packet_cb packet,
82                                 stat_tree_init_cb init,
83                                 stat_tree_cleanup_cb cleanup);
84
85 /* registers a new stats tree
86  * abbr: protocol abbr
87  * name: protocol display name
88  * flags: tap listener flags for per-packet callback
89  * packet: per packet callback
90  * init: tree initialization callback
91  * cleanup: cleanup callback
92  * stat_group: the group this stat belongs to
93  */
94 extern void stats_tree_register_with_group(const gchar *tapname,
95                                 const gchar *abbr,
96                                 const gchar *name,
97                                 guint flags,
98                                 stat_tree_packet_cb packet,
99                                 stat_tree_init_cb init,
100                                 stat_tree_cleanup_cb cleanup,
101                                 register_stat_group_t stat_group);
102
103 extern int stats_tree_parent_id_by_name(stats_tree *st, const gchar *parent_name);
104
105 /* Creates a node in the tree (to be used in the in init_cb)
106 * st: the stats_tree in which to create it
107 * name: the name of the new node
108 * parent_name: the name of the parent_node (NULL for root)
109 * with_children: TRUE if this node will have "dynamically created" children
110 */
111 extern int stats_tree_create_node(stats_tree *st,
112                                   const gchar *name,
113                                   int parent_id,
114                                   gboolean with_children);
115
116 /* creates a node using it's parent's tree name */
117 extern int stats_tree_create_node_by_pname(stats_tree *st,
118                                            const gchar *name,
119                                            const gchar *parent_name,
120                                            gboolean with_children);
121
122 /* creates a node in the tree, that will contain a ranges list.
123  example:
124  stats_tree_create_range_node(st,name,parent,
125                               "-99","100-199","200-299","300-399","400-", NULL);
126 */
127 extern int stats_tree_create_range_node(stats_tree *st,
128                                         const gchar *name,
129                                         int parent_id,
130                                         ...);
131
132 extern int stats_tree_create_range_node_string(stats_tree *st,
133                                         const gchar *name,
134                                         int parent_id,
135                                         int num_str_ranges,
136                                         gchar** str_ranges);
137
138 extern int stats_tree_range_node_with_pname(stats_tree *st,
139                                             const gchar *name,
140                                             const gchar *parent_name,
141                                             ...);
142
143 /* increases by one the ranged node and the sub node to whose range the value belongs */
144 extern int stats_tree_tick_range(stats_tree *st,
145                                  const gchar *name,
146                                  int parent_id,
147                                  int value_in_range);
148
149 #define stats_tree_tick_range_by_pname(st,name,parent_name,value_in_range) \
150      stats_tree_tick_range((st),(name),stats_tree_parent_id_by_name((st),(parent_name),(value_in_range))
151
152 /* */
153 extern int stats_tree_create_pivot(stats_tree *st,
154                                    const gchar *name,
155                                    int parent_id);
156
157 extern int stats_tree_create_pivot_by_pname(stats_tree *st,
158                                             const gchar *name,
159                                             const gchar *parent_name);
160
161 extern int stats_tree_tick_pivot(stats_tree *st,
162                                  int pivot_id,
163                                  const gchar *pivot_value);
164
165 /*
166  * manipulates the value of the node whose name is given
167  * if the node does not exist yet it's created (with counter=1)
168  * using parent_name as parent node (NULL for root).
169  * with_children=TRUE to indicate that the created node will be a parent
170  */
171 typedef enum _manip_node_mode { MN_INCREASE, MN_SET } manip_node_mode;
172 extern int stats_tree_manip_node(manip_node_mode mode,
173                                  stats_tree *st,
174                                  const gchar *name,
175                                  int parent_id,
176                                  gboolean with_children,
177                                  gint value);
178
179 #define increase_stat_node(st,name,parent_id,with_children,value) \
180 (stats_tree_manip_node(MN_INCREASE,(st),(name),(parent_id),(with_children),(value)))
181
182 #define tick_stat_node(st,name,parent_id,with_children) \
183 (stats_tree_manip_node(MN_INCREASE,(st),(name),(parent_id),(with_children),1))
184
185 #define set_stat_node(st,name,parent_id,with_children,value) \
186 (stats_tree_manip_node(MN_SET,(st),(name),(parent_id),(with_children),value))
187
188 #define zero_stat_node(st,name,parent_id,with_children) \
189 (stats_tree_manip_node(MN_SET,(st),(name),(parent_id),(with_children),0))
190
191 #endif /* __STATS_TREE_H */