*
* $Id$
*
- * Ethereal - Network traffic analyzer
- * By Gerald Combs <gerald@ethereal.com>
+ * Wireshark - Network traffic analyzer
+ * By Gerald Combs <gerald@wireshark.org>
* Copyright 1998 Gerald Combs
*
* This program is free software; you can redistribute it and/or
#include <gtk/gtk.h>
#include <epan/stats_tree_priv.h>
+#include <epan/report_err.h>
#include "simple_dialog.h"
#include "globals.h"
-#include "tap_menu.h"
-#include "ui_util.h"
+#include "gui_utils.h"
#include "dlg_utils.h"
#include "compat_macros.h"
-#include "tap_dfilter_dlg.h"
+#include "../stat_menu.h"
#include "../tap_dfilter_dlg.h"
struct _st_node_pres {
static gchar percent[NUM_BUF_SIZE];
stat_node* child;
- stats_tree_get_strs_from_node(node, value, rate, percent);
+ stats_tree_get_strs_from_node(node, value, rate,
+ percent);
#if GTK_MAJOR_VERSION >= 2
- if (node->st->pr->store) {
+ if (node->st->pr->store && node->pr->iter) {
gtk_tree_store_set(node->st->pr->store, node->pr->iter,
RATE_COLUMN, rate,
COUNT_COLUMN, value,
draw_gtk_node(child);
#if GTK_MAJOR_VERSION >= 2
- gtk_tree_view_expand_row(GTK_TREE_VIEW(st->pr->tree),
+ if (child->pr->iter && st->pr->store) {
+ gtk_tree_view_expand_row(GTK_TREE_VIEW(st->pr->tree),
gtk_tree_model_get_path(GTK_TREE_MODEL(st->pr->store),
child->pr->iter),
FALSE);
+ }
#endif
}
st->root.pr->iter = NULL;
#endif
+ st->cfg->in_use = FALSE;
stats_tree_free(st);
}
+static void clear_node_pr(stat_node* n) {
+ stat_node* c;
+ for (c = n->children; c; c = c->next) {
+ clear_node_pr(c);
+ }
+
+#if GTK_MAJOR_VERSION >= 2
+ if (n->pr->iter) {
+ gtk_tree_store_remove(n->st->pr->store, n->pr->iter);
+ n->pr->iter = NULL;
+ }
+#else
+ if (n->pr->node) {
+ gtk_ctree_remove_node(GTK_CTREE(n->st->pr->ctree),n->pr->node);
+ n->pr->node = NULL;
+ }
+#endif
+
+}
+
+static void reset_tap(void* p) {
+ stats_tree* st = p;
+ stat_node* c;
+ for (c = st->root.children; c; c = c->next) {
+ clear_node_pr(c);
+ }
+
+ st->cfg->init(st);
+}
/* initializes the stats_tree window */
-static void init_gtk_tree(const char* optarg) {
+static void init_gtk_tree(const char* optarg, void *userdata _U_) {
guint8* abbr = stats_tree_get_abbr(optarg);
stats_tree* st = NULL;
stats_tree_cfg* cfg = NULL;
tree_pres* pr = g_malloc(sizeof(tree_pres));
- guint8* title = NULL;
- guint8* window_name = NULL;
+ gchar* title = NULL;
+ gchar* window_name = NULL;
GString* error_string;
GtkWidget *scr_win;
guint init_strlen;
if (abbr) {
cfg = stats_tree_get_cfg_by_abbr(abbr);
+ if (cfg && cfg->in_use) {
+ /* XXX: ! */
+ report_failure("cannot open more than one tree of the same type at once");
+ return;
+ }
+
if (cfg != NULL) {
init_strlen = strlen(cfg->pr->stat_dlg->init_string);
if (init_strlen == strlen(optarg)) {
st = stats_tree_new(cfg,pr,NULL);
} else {
- st = stats_tree_new(cfg,pr,((guint8*)optarg)+init_strlen+1);
+ st = stats_tree_new(cfg,pr,(char*)optarg+init_strlen+1);
}
} else {
st = stats_tree_new(cfg,pr,NULL);
}
} else {
- g_error("no such stats_tree (%s) found in stats_tree registry",abbr);
+ report_failure("no such stats_tree (%s) in stats_tree registry",abbr);
+ g_free(abbr);
+ return;
}
g_free(abbr);
} else {
- g_error("could not obtain stats_tree abbr from optarg");
+ report_failure("could not obtain stats_tree abbr from optarg");
+ g_free(pr);
+ return;
}
+ cfg->in_use = TRUE;
+
window_name = g_strdup_printf("%s Stats Tree", cfg->name);
st->pr->win = window_new_with_geom(GTK_WINDOW_TOPLEVEL,window_name,window_name);
gtk_container_add( GTK_CONTAINER(main_vb), scr_win);
error_string = register_tap_listener( cfg->tapname,
- st,
- st->filter,
- NULL,
- stats_tree_packet,
- draw_gtk_tree);
+ st,
+ st->filter,
+ reset_tap,
+ stats_tree_packet,
+ draw_gtk_tree);
if (error_string) {
/* error, we failed to attach to the tap. clean up */
simple_dialog( ESD_TYPE_ERROR, ESD_BTN_OK, error_string->str );
/* destroy_stat_tree_window(st); */
- g_error("stats_tree for: %s failed to attach to the tap: %s",cfg->name,error_string->str);
+ report_failure("stats_tree for: %s failed to attach to the tap: %s",cfg->name,error_string->str);
g_string_free(error_string, TRUE);
}
gtk_tree_view_set_model(GTK_TREE_VIEW(st->pr->tree),GTK_TREE_MODEL(st->pr->store));
#endif
- st->cfg->init(st);
-
- cf_retap_packets(&cfile);
+ cf_retap_packets(&cfile, FALSE);
}
static void register_gtk_stats_tree_tap (gpointer k _U_, gpointer v, gpointer p _U_) {
stats_tree_cfg* cfg = v;
- guint8* s;
- s = g_strdup_printf("%s,tree",cfg->abbr);
-
- register_tap_listener_cmd_arg(s, init_gtk_tree);
-
cfg->pr = g_malloc(sizeof(tree_pres));
cfg->pr->stat_dlg = g_malloc(sizeof(tap_dfilter_dlg));
cfg->pr->stat_dlg->tap_init_cb = init_gtk_tree;
cfg->pr->stat_dlg->index = -1;
- register_tap_menu_item(cfg->name, REGISTER_TAP_GROUP_NONE,
- gtk_tap_dfilter_dlg_cb, NULL, NULL, cfg->pr->stat_dlg);
+ register_dfilter_stat(cfg->pr->stat_dlg, cfg->name,
+ REGISTER_STAT_GROUP_NONE);
}
static void free_tree_presentation(stats_tree* st) {
{
stats_tree_presentation(register_gtk_stats_tree_tap,
- setup_gtk_node_pr, NULL,
+ setup_gtk_node_pr,
+ NULL,
+ NULL,
NULL,
- NULL, NULL, free_tree_presentation, NULL, NULL, NULL);
+ NULL,
+ free_tree_presentation,
+ NULL,
+ NULL,
+ NULL);
}