2 * tethereal's tap implememntation of stats_tree
3 * 2005, Luis E. G. Ontanon
7 * Ethereal - Network traffic analyzer
8 * By Gerald Combs <gerald@ethereal.com>
9 * Copyright 1998 Gerald Combs
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.
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.
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.
33 #include <epan/stats_tree_priv.h>
34 #include <epan/stat_cmd_args.h>
35 #include <epan/report_err.h>
38 struct _st_node_pres {
46 struct _tree_cfg_pres {
50 static void draw_stats_tree(void *psp) {
56 s = g_string_new("\n===================================================================\n");
57 fmt = g_strdup_printf(" %%s%%-%us%%12s\t%%12s\t%%12s\n",stats_tree_branch_max_namelen(&st->root,0));
58 g_string_sprintfa(s,fmt,"",st->cfg->name,"value","rate","percent");
60 g_string_sprintfa(s,"-------------------------------------------------------------------\n");
62 for (child = st->root.children; child; child = child->next ) {
63 stats_tree_branch_to_str(child,s,0);
66 s = g_string_append(s,"\n===================================================================\n");
72 static void init_stats_tree(const char *optarg) {
73 guint8* abbr = stats_tree_get_abbr(optarg);
74 GString *error_string;
75 stats_tree_cfg *cfg = NULL;
76 stats_tree* st = NULL;
79 cfg = stats_tree_get_cfg_by_abbr(abbr);
82 if (strncmp (optarg, cfg->pr->init_string, strlen(cfg->pr->init_string)) == 0){
83 st = stats_tree_new(cfg,NULL,((guint8*)optarg)+strlen(cfg->pr->init_string));
88 report_failure("no such stats_tree (%s) found in stats_tree registry",abbr);
95 report_failure("could not obtain stats_tree abbr (%s) from optarg '%s'",abbr,optarg);
99 error_string = register_tap_listener( st->cfg->tapname,
107 report_failure("stats_tree for: %s failed to attach to the tap: %s",cfg->name,error_string->str);
111 if (cfg->init) cfg->init(st);
115 void register_stats_tree_tap (gpointer k _U_, gpointer v, gpointer p _U_) {
116 stats_tree_cfg* cfg = v;
118 cfg->pr = g_malloc(sizeof(tree_cfg_pres));
119 cfg->pr->init_string = g_strdup_printf("%s,tree",cfg->abbr);
121 register_stat_cmd_arg(cfg->pr->init_string, init_stats_tree);
125 static void free_tree_presentation(stats_tree* st) {
131 register_tap_listener_stats_tree_stat(void)
133 stats_tree_presentation(register_stats_tree_tap,
134 NULL, NULL, NULL, NULL, NULL,
135 free_tree_presentation, NULL, NULL, NULL);