3 * Copyright 2003, Michael Lum <mlum [AT] telostech.com>
4 * In association with Telos Technology Inc.
6 * MUCH code modified from service_response_time_table.c.
8 * $Id: ansi_map_stat.c,v 1.16 2004/02/11 04:28:47 guy Exp $
10 * Ethereal - Network traffic analyzer
11 * By Gerald Combs <gerald@ethereal.com>
12 * Copyright 1998 Gerald Combs
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
30 * This TAP provides statistics for ANSI MAP:
40 #include "epan/packet_info.h"
41 #include "epan/epan.h"
42 #include "epan/value_string.h"
44 #include "image/clist_ascend.xpm"
45 #include "image/clist_descend.xpm"
46 #include "simple_dialog.h"
47 #include "dlg_utils.h"
49 #include "../register.h"
50 #include "../globals.h"
51 #include "filter_prefs.h"
52 #include "compat_macros.h"
53 #include "packet-ansi_map.h"
57 typedef struct column_arrows {
60 GtkWidget *descend_pm;
63 typedef struct _ansi_map_stat_dlg_t {
65 GtkWidget *scrolled_win;
68 } ansi_map_stat_dlg_t;
70 #define N_MESSAGE_TYPES 256
72 typedef struct _ansi_map_stat_t {
73 int message_type[N_MESSAGE_TYPES];
76 static ansi_map_stat_dlg_t dlg;
77 static ansi_map_stat_t stat;
86 memset((void *) &stat, 0, sizeof(ansi_map_stat_t));
94 epan_dissect_t *edt _U_,
97 ansi_map_tap_rec_t *data_p = data;
103 #if 0 /* always false because message_type is 8 bit value */
104 if (data_p->message_type >= N_MESSAGE_TYPES)
107 * unknown PDU type !!!
113 stat.message_type[data_p->message_type]++;
124 char str[256], *strp;
133 while (ansi_map_opr_code_strings[i].strptr)
135 j = gtk_clist_find_row_from_data(GTK_CLIST(dlg.table), (gpointer) i);
138 stat.message_type[ansi_map_opr_code_strings[i].value]);
139 strp = g_strdup(str);
140 gtk_clist_set_text(GTK_CLIST(dlg.table), j, 2, strp);
146 gtk_clist_sort(GTK_CLIST(dlg.table));
152 ansi_map_stat_gtk_click_column_cb(
157 column_arrows *col_arrows = (column_arrows *) data;
161 gtk_clist_freeze(clist);
163 for (i=0; i < 3; i++)
165 gtk_widget_hide(col_arrows[i].ascend_pm);
166 gtk_widget_hide(col_arrows[i].descend_pm);
169 if (column == clist->sort_column)
171 if (clist->sort_type == GTK_SORT_ASCENDING)
173 clist->sort_type = GTK_SORT_DESCENDING;
174 gtk_widget_show(col_arrows[column].descend_pm);
178 clist->sort_type = GTK_SORT_ASCENDING;
179 gtk_widget_show(col_arrows[column].ascend_pm);
185 * Columns 0-1 sorted in descending order by default
186 * Columns 2 sorted in ascending order by default
190 clist->sort_type = GTK_SORT_ASCENDING;
191 gtk_widget_show(col_arrows[column].ascend_pm);
195 clist->sort_type = GTK_SORT_DESCENDING;
196 gtk_widget_show(col_arrows[column].descend_pm);
199 gtk_clist_set_sort_column(clist, column);
202 gtk_clist_thaw(clist);
203 gtk_clist_sort(clist);
208 ansi_map_stat_gtk_sort_column(
213 GtkCListRow *row1 = (GtkCListRow *) ptr1;
214 GtkCListRow *row2 = (GtkCListRow *) ptr2;
219 text1 = GTK_CELL_TEXT(row1->cell[clist->sort_column])->text;
220 text2 = GTK_CELL_TEXT(row2->cell[clist->sort_column])->text;
222 switch (clist->sort_column)
228 i1 = strtol(text1, NULL, 0);
229 i2 = strtol(text2, NULL, 0);
233 return(strcmp(text1, text2));
236 g_assert_not_reached();
243 ansi_map_stat_gtk_dlg_close_cb(
244 GtkButton *button _U_,
245 gpointer user_data _U_)
247 ansi_map_stat_dlg_t *dlg_p = user_data;
249 gtk_grab_remove(GTK_WIDGET(dlg_p->win));
250 gtk_widget_destroy(GTK_WIDGET(dlg_p->win));
255 ansi_map_stat_gtk_win_destroy_cb(
257 gpointer user_data _U_)
259 memset((void *) user_data, 0, sizeof(ansi_map_stat_dlg_t));
264 ansi_map_stat_gtk_win_create(
265 ansi_map_stat_dlg_t *dlg_p,
268 #define INIT_TABLE_NUM_COLUMNS 3
269 char *default_titles[] = { "Op Code", "Operation Name", "Count" };
271 column_arrows *col_arrows;
272 GdkBitmap *ascend_bm, *descend_bm;
273 GdkPixmap *ascend_pm, *descend_pm;
275 GtkWidget *column_lb;
279 GtkWidget *dialog_vbox;
280 GtkWidget *dialog_action_area;
283 dlg_p->win = gtk_dialog_new();
284 gtk_window_set_default_size(GTK_WINDOW(dlg_p->win), 500, 450);
285 gtk_window_set_title(GTK_WINDOW(dlg_p->win), title);
286 SIGNAL_CONNECT(dlg_p->win, "destroy", ansi_map_stat_gtk_win_destroy_cb, dlg_p);
288 dialog_vbox = GTK_DIALOG(dlg_p->win)->vbox;
289 gtk_widget_show(dialog_vbox);
291 dialog_action_area = GTK_DIALOG(dlg_p->win)->action_area;
292 gtk_widget_show(dialog_action_area);
293 gtk_container_set_border_width(GTK_CONTAINER(dialog_action_area), 10);
295 bbox = dlg_button_row_new(GTK_STOCK_CLOSE, NULL);
296 gtk_box_pack_start(GTK_BOX(dialog_action_area), bbox, FALSE, FALSE, 0);
297 gtk_widget_show(bbox);
299 bt_close = OBJECT_GET_DATA(bbox, GTK_STOCK_CLOSE);
300 gtk_widget_grab_default(bt_close);
301 SIGNAL_CONNECT(bt_close, "clicked", ansi_map_stat_gtk_dlg_close_cb, dlg_p);
303 vbox = gtk_vbox_new(FALSE, 0);
304 gtk_widget_ref(vbox);
305 OBJECT_SET_DATA_FULL(dlg_p->win, "vbox", vbox, gtk_widget_unref);
306 gtk_widget_show(vbox);
307 gtk_box_pack_start(GTK_BOX(dialog_vbox), vbox, TRUE, TRUE, 0);
308 gtk_container_set_border_width(GTK_CONTAINER(vbox), 8);
310 dlg_p->scrolled_win = scrolled_window_new(NULL, NULL);
311 gtk_widget_ref(dlg_p->scrolled_win);
312 OBJECT_SET_DATA_FULL(dlg_p->win, "scrolled_win", dlg_p->scrolled_win,
314 gtk_widget_show(dlg_p->scrolled_win);
315 gtk_box_pack_start(GTK_BOX(vbox), dlg_p->scrolled_win, TRUE, TRUE, 0);
317 dlg_p->table = gtk_clist_new(INIT_TABLE_NUM_COLUMNS);
318 gtk_widget_ref(dlg_p->table);
319 OBJECT_SET_DATA_FULL(dlg_p->win, "table", dlg_p->table, gtk_widget_unref);
320 gtk_widget_show(dlg_p->table);
322 gtk_widget_show(dlg_p->win);
325 (column_arrows *) g_malloc(sizeof(column_arrows) * INIT_TABLE_NUM_COLUMNS);
328 gtk_widget_get_style(dlg_p->scrolled_win);
331 gdk_pixmap_create_from_xpm_d(dlg_p->scrolled_win->window,
333 &win_style->bg[GTK_STATE_NORMAL],
334 (gchar **) clist_ascend_xpm);
337 gdk_pixmap_create_from_xpm_d(dlg_p->scrolled_win->window,
339 &win_style->bg[GTK_STATE_NORMAL],
340 (gchar **)clist_descend_xpm);
342 for (i = 0; i < INIT_TABLE_NUM_COLUMNS; i++)
344 col_arrows[i].table = gtk_table_new(2, 2, FALSE);
346 gtk_table_set_col_spacings(GTK_TABLE(col_arrows[i].table), 5);
348 column_lb = gtk_label_new(default_titles[i]);
350 gtk_table_attach(GTK_TABLE(col_arrows[i].table), column_lb,
351 0, 1, 0, 2, GTK_SHRINK, GTK_SHRINK, 0, 0);
353 gtk_widget_show(column_lb);
355 col_arrows[i].ascend_pm =
356 gtk_pixmap_new(ascend_pm, ascend_bm);
358 gtk_table_attach(GTK_TABLE(col_arrows[i].table), col_arrows[i].ascend_pm,
359 1, 2, 1, 2, GTK_SHRINK, GTK_SHRINK, 0, 0);
361 col_arrows[i].descend_pm =
362 gtk_pixmap_new(descend_pm, descend_bm);
364 gtk_table_attach(GTK_TABLE(col_arrows[i].table), col_arrows[i].descend_pm,
365 1, 2, 0, 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
369 /* default column sorting */
370 gtk_widget_show(col_arrows[i].ascend_pm);
373 gtk_clist_set_column_widget(GTK_CLIST(dlg_p->table), i, col_arrows[i].table);
374 gtk_widget_show(col_arrows[i].table);
376 gtk_clist_column_titles_show(GTK_CLIST(dlg_p->table));
378 gtk_clist_set_compare_func(GTK_CLIST(dlg_p->table), ansi_map_stat_gtk_sort_column);
379 gtk_clist_set_sort_column(GTK_CLIST(dlg_p->table), 0);
380 gtk_clist_set_sort_type(GTK_CLIST(dlg_p->table), GTK_SORT_ASCENDING);
382 gtk_clist_set_column_width(GTK_CLIST(dlg_p->table), 0, 60);
383 gtk_clist_set_column_width(GTK_CLIST(dlg_p->table), 1, 290);
384 gtk_clist_set_column_width(GTK_CLIST(dlg_p->table), 2, 50);
386 gtk_clist_set_shadow_type(GTK_CLIST(dlg_p->table), GTK_SHADOW_IN);
387 gtk_clist_column_titles_show(GTK_CLIST(dlg_p->table));
388 gtk_container_add(GTK_CONTAINER(dlg_p->scrolled_win), dlg_p->table);
390 SIGNAL_CONNECT(dlg_p->table, "click-column", ansi_map_stat_gtk_click_column_cb, col_arrows);
395 * Never gets called ?
398 ansi_map_stat_gtk_init(
401 /* does not appear to be called */
408 ansi_map_stat_gtk_cb(
417 * if the window is already open, bring it to front
421 gdk_window_raise(dlg.win->window);
425 ansi_map_stat_gtk_win_create(&dlg, "ANSI MAP Operation Statistics");
428 while (ansi_map_opr_code_strings[i].strptr)
430 sprintf(str, "0x%02x", ansi_map_opr_code_strings[i].value);
431 dlg.entries[0] = g_strdup(str);
433 dlg.entries[1] = g_strdup(ansi_map_opr_code_strings[i].strptr);
435 dlg.entries[2] = g_strdup("0");
437 gtk_clist_insert(GTK_CLIST(dlg.table), i, dlg.entries);
438 gtk_clist_set_row_data(GTK_CLIST(dlg.table), i, (gpointer) i);
443 ansi_map_stat_draw(NULL);
448 register_tap_listener_gtkansi_map_stat(void)
453 register_ethereal_tap("ansi_map,", ansi_map_stat_gtk_init);
455 memset((void *) &stat, 0, sizeof(ansi_map_stat_t));
458 register_tap_listener("ansi_map", NULL, NULL,
460 ansi_map_stat_packet,
465 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, err_p->str);
466 g_string_free(err_p, TRUE);
474 register_tap_menu_gtkansi_map_stat(void)
476 register_tap_menu_item("_Statistics/ANSI MAP Operation", ansi_map_stat_gtk_cb, NULL, NULL, NULL);