Remove svn:executable
[obnox/wireshark/wip.git] / tap-stats_tree.c
1 /* tap-stats_tree.c
2  * tethereal's tap implememntation of 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 #ifdef HAVE_CONFIG_H
27 #include "config.h"
28 #endif
29
30 #include <string.h>
31 #include <stdio.h>
32 #include <glib.h>
33 #include <epan/stats_tree_priv.h>
34
35 /* actually unused */
36 struct _st_node_pres {
37         void* dummy;
38 };
39
40 struct _tree_pres {
41         void* dummy;
42 };
43
44 struct _tree_cfg_pres {
45         guint8* init_string;    
46 };
47
48 static void draw_stats_tree(void *psp) {
49         stats_tree *st = psp;
50         GString* s;
51         gchar* fmt;
52         stat_node* child;
53         
54         s = g_string_new("\n===================================================================\n");
55         fmt = g_strdup_printf(" %%s%%-%us%%12s\t%%12s\t%%12s\n",stats_tree_branch_max_namelen(&st->root,0));
56         g_string_sprintfa(s,fmt,"",st->cfg->name,"value","rate","percent");
57         g_free(fmt);
58         g_string_sprintfa(s,"-------------------------------------------------------------------\n");
59         
60         for (child = st->root.children; child; child = child->next ) {
61                 stats_tree_branch_to_str(child,s,0);
62         }
63         
64         s = g_string_append(s,"\n===================================================================\n");
65         
66         printf("%s",s->str);
67         
68 }
69
70 static void  init_stats_tree(char *optarg) {
71         guint8* abbr = stats_tree_get_abbr(optarg);
72         GString *error_string;
73         stats_tree_cfg *cfg = NULL;
74         stats_tree* st = NULL;
75         
76         if (abbr) {
77                 cfg = stats_tree_get_cfg_by_abbr(abbr);
78
79                 if (cfg != NULL) {
80                         if (strncmp (optarg, cfg->pr->init_string, strlen(cfg->pr->init_string)) == 0){
81                                 st = stats_tree_new(cfg,NULL,((guint8*)optarg)+strlen(cfg->pr->init_string));
82                         } else {
83                                 st->filter=NULL;
84                         }
85                 } else {
86                         g_error("no such stats_tree (%s) found in stats_tree registry",abbr);
87                 }
88                 
89                 g_free(abbr);
90                 
91         } else {
92                 g_error("could not obtain stats_tree abbr (%s) from optarg '%s'",abbr,optarg);          
93         }
94         
95         error_string = register_tap_listener( st->cfg->tapname,
96                                                                                   st,
97                                                                                   st->filter,
98                                                                                   stats_tree_reset,
99                                                                                   stats_tree_packet,
100                                                                                   draw_stats_tree);
101         
102         if (error_string) {
103                 g_error("stats_tree for: %s failed to attach to the tap: %s",cfg->name,error_string->str);
104         }
105
106         if (cfg->init) cfg->init(st);
107
108 }
109
110 void register_stats_tree_tap (gpointer k _U_, gpointer v, gpointer p _U_) {
111         stats_tree_cfg* cfg = v;
112         
113         cfg->pr = g_malloc(sizeof(tree_cfg_pres));
114         cfg->pr->init_string = g_strdup_printf("%s,tree",cfg->abbr);
115
116         register_tap_listener_cmd_arg(cfg->pr->init_string, init_stats_tree);
117         
118 }
119
120 static void free_tree_presentation(stats_tree* st) {
121         g_free(st->pr);
122 }
123
124
125 void
126 register_tap_listener_stats_tree_stat(void)
127 {
128         stats_tree_presentation(register_stats_tree_tap,
129                                                         NULL, NULL, NULL, NULL, NULL,
130                                                         free_tree_presentation, NULL, NULL, NULL);
131 }