Clear up the code.
[obnox/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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, 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 "../register.h"
34
35 #define STAT_TREE_ROOT "root"
36
37 /* obscure information regarding the stats_tree */ 
38 typedef struct _stats_tree stats_tree;
39
40 /* tap packet callback for stats_tree */
41 typedef int  (*stat_tree_packet_cb)(stats_tree*,
42                                     packet_info*,
43                                     epan_dissect_t*,
44                                     const void *);
45
46 /* stats_tree initialization callback */
47 typedef void  (*stat_tree_init_cb)(stats_tree*);
48
49 /* stats_tree cleanup callback */
50 typedef void  (*stat_tree_cleanup_cb)(stats_tree*);
51
52 /* registers a new stats tree 
53  * abbr: protocol abbr
54  * name: protocol display name
55  * packet: per packet callback
56  * init: tree initialization callback
57  */
58 extern void stats_tree_register(const gchar *tapname,
59                                 const gchar *abbr, 
60                                 const gchar *name,
61                                 stat_tree_packet_cb packet,
62                                 stat_tree_init_cb init,
63                                 stat_tree_cleanup_cb cleanup);
64
65 extern int stats_tree_parent_id_by_name(stats_tree *st, const gchar *parent_name);
66
67 /* Creates a node in the tree (to be used in the in init_cb)
68 * st: the stats_tree in which to create it
69 * name: the name of the new node
70 * parent_name: the name of the parent_node (NULL for root)
71 * with_children: TRUE if this node will have "dynamically created" children
72 */
73 extern int stats_tree_create_node(stats_tree *st,
74                                   const gchar *name,
75                                   int parent_id,
76                                   gboolean with_children);
77
78 /* creates a node using it's parent's tree name */ 
79 extern int stats_tree_create_node_by_pname(stats_tree *st,
80                                            const gchar *name,
81                                            const gchar *parent_name,
82                                            gboolean with_children);
83
84 /* creates a node in the tree, that will contain a ranges list.
85  example:
86  stats_tree_create_range_node(st,name,parent,
87                               "-99","100-199","200-299","300-399","400-", NULL);
88 */
89 extern int stats_tree_create_range_node(stats_tree *st,
90                                         const gchar *name,
91                                         int parent_id,
92                                         ...);
93
94 extern int stats_tree_range_node_with_pname(stats_tree *st,
95                                             const gchar *name,
96                                             const gchar *parent_name,
97                                             ...);
98
99 /* increases by one the ranged node and the sub node to whose range the value belongs */
100 extern int stats_tree_tick_range(stats_tree *st,
101                                  const gchar *name,
102                                  int parent_id,
103                                  int value_in_range);
104
105 #define stats_tree_tick_range_by_pname(st,name,parent_name,value_in_range) \
106      stats_tree_tick_range((st),(name),stats_tree_parent_id_by_name((st),(parent_name),(value_in_range))
107
108 /* */
109 extern int stats_tree_create_pivot(stats_tree *st,
110                                    const gchar *name,
111                                    int parent_id);
112
113 extern int stats_tree_create_pivot_by_pname(stats_tree *st,
114                                             const gchar *name,
115                                             const gchar *parent_name);
116
117 extern int stats_tree_tick_pivot(stats_tree *st,
118                                  int pivot_id,
119                                  const gchar *pivot_value);
120
121 /*
122  * manipulates the value of the node whose name is given
123  * if the node does not exist yet it's created (with counter=1)
124  * using parent_name as parent node (NULL for root).
125  * with_children=TRUE to indicate that the created node will be a parent
126  */
127 typedef enum _manip_node_mode { MN_INCREASE, MN_SET } manip_node_mode;
128 extern int stats_tree_manip_node(manip_node_mode mode,
129                                  stats_tree *st,
130                                  const gchar *name,
131                                  int parent_id,
132                                  gboolean with_children,
133                                  gint value);
134
135 #define increase_stat_node(st,name,parent_id,with_children,value) \
136 (stats_tree_manip_node(MN_INCREASE,(st),(name),(parent_id),(with_children),(value)))
137
138 #define tick_stat_node(st,name,parent_id,with_children) \
139 (stats_tree_manip_node(MN_INCREASE,(st),(name),(parent_id),(with_children),1))
140
141 #define set_stat_node(st,name,parent_id,with_children,value) \
142 (stats_tree_manip_node(MN_SET,(st),(name),(parent_id),(with_children),value))
143
144 #define zero_stat_node(st,name,parent_id,with_children) \
145 (stats_tree_manip_node(MN_SET,(st),(name),(parent_id),(with_children),0))
146
147 #endif /* __STATS_TREE_H */