HACK: 1. try to match RowsetProperties
[wireshark-wip.git] / ui / gtk / fc_stat.c
blob45d54438869fb99628c76d431514129c1a9d3883
1 /* fc_stat.c
2 * fc_stat 2003 Ronnie Sahlberg
4 * $Id$
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 1998 Gerald Combs
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 #include "config.h"
27 #include <string.h>
29 #include <gtk/gtk.h>
31 #include <epan/packet_info.h>
32 #include <epan/epan.h>
33 #include <epan/value_string.h>
34 #include <epan/tap.h>
35 #include <epan/conversation.h>
36 #include <epan/dissectors/packet-scsi.h>
37 #include <epan/dissectors/packet-fc.h>
39 #include "ui/simple_dialog.h"
40 #include "../file.h"
41 #include "../stat_menu.h"
43 #include "ui/gtk/gui_utils.h"
44 #include "ui/gtk/dlg_utils.h"
45 #include "ui/gtk/service_response_time_table.h"
46 #include "ui/gtk/tap_param_dlg.h"
47 #include "ui/gtk/gtkglobals.h"
48 #include "ui/gtk/main.h"
50 #include "ui/gtk/old-gtk-compat.h"
52 /* used to keep track of the statistics for an entire program interface */
53 typedef struct _fcstat_t {
54 GtkWidget *win;
55 srt_stat_table fc_srt_table;
56 } fcstat_t;
58 static void
59 fcstat_set_title(fcstat_t *fc)
61 set_window_title(fc->win, "Fibre Channel Service Response Time statistics");
64 static void
65 fcstat_reset(void *pfc)
67 fcstat_t *fc=(fcstat_t *)pfc;
69 reset_srt_table_data(&fc->fc_srt_table);
70 fcstat_set_title(fc);
73 static int
74 fcstat_packet(void *pfc, packet_info *pinfo, epan_dissect_t *edt _U_, const void *psi)
76 const fc_hdr *fc=(fc_hdr *)psi;
77 fcstat_t *fs=(fcstat_t *)pfc;
79 /* we are only interested in reply packets */
80 if(!(fc->fctl&FC_FCTL_EXCHANGE_RESPONDER)){
81 return 0;
83 /* if we havnt seen the request, just ignore it */
84 if( (!fc->itlq) || (fc->itlq->first_exchange_frame==0) ){
85 return 0;
88 add_srt_table_data(&fs->fc_srt_table, fc->type, &fc->itlq->fc_time, pinfo);
90 return 1;
95 static void
96 fcstat_draw(void *pfc)
98 fcstat_t *fc=(fcstat_t *)pfc;
100 draw_srt_table_data(&fc->fc_srt_table);
104 static void
105 win_destroy_cb(GtkWindow *win _U_, gpointer data)
107 fcstat_t *fc=(fcstat_t *)data;
109 remove_tap_listener(fc);
111 free_srt_table_data(&fc->fc_srt_table);
112 g_free(fc);
116 static void
117 gtk_fcstat_init(const char *opt_arg, void *userdata _U_)
119 fcstat_t *fc;
120 const char *filter=NULL;
121 GtkWidget *label;
122 char *filter_string;
123 GString *error_string;
124 int i;
125 GtkWidget *vbox;
126 GtkWidget *bbox;
127 GtkWidget *close_bt;
129 if(!strncmp(opt_arg,"fc,srt,",7)){
130 filter=opt_arg+7;
131 } else {
132 filter=NULL;
135 fc=(fcstat_t *)g_malloc(sizeof(fcstat_t));
137 fc->win = dlg_window_new("fc-stat"); /* transient_for top_level */
138 gtk_window_set_destroy_with_parent (GTK_WINDOW(fc->win), TRUE);
140 gtk_window_set_default_size(GTK_WINDOW(fc->win), 550, 400);
141 fcstat_set_title(fc);
143 vbox=ws_gtk_box_new(GTK_ORIENTATION_VERTICAL, 3, FALSE);
144 gtk_container_add(GTK_CONTAINER(fc->win), vbox);
145 gtk_container_set_border_width(GTK_CONTAINER(vbox), 12);
147 label=gtk_label_new("Fibre Channel Service Response Time statistics");
148 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
150 filter_string = g_strdup_printf("Filter: %s", filter ? filter : "");
151 label=gtk_label_new(filter_string);
152 g_free(filter_string);
153 gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
154 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
156 label=gtk_label_new("Fibre Channel Types");
157 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
159 /* We must display TOP LEVEL Widget before calling init_srt_table() */
160 gtk_widget_show_all(fc->win);
162 init_srt_table(&fc->fc_srt_table, 256, vbox, NULL);
163 for(i=0;i<256;i++){
164 init_srt_table_row(&fc->fc_srt_table, i, val_to_str(i, fc_fc4_val, "Unknown(0x%02x)"));
168 error_string=register_tap_listener("fc", fc, filter, 0, fcstat_reset, fcstat_packet, fcstat_draw);
169 if(error_string){
170 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", error_string->str);
171 g_string_free(error_string, TRUE);
172 g_free(fc);
173 return;
176 /* Button row. */
177 bbox = dlg_button_row_new(GTK_STOCK_CLOSE, NULL);
178 gtk_box_pack_end(GTK_BOX(vbox), bbox, FALSE, FALSE, 0);
180 close_bt = (GtkWidget *)g_object_get_data(G_OBJECT(bbox), GTK_STOCK_CLOSE);
181 window_set_cancel_button(fc->win, close_bt, window_cancel_button_cb);
183 g_signal_connect(fc->win, "delete_event", G_CALLBACK(window_delete_event_cb), NULL);
184 g_signal_connect(fc->win, "destroy", G_CALLBACK(win_destroy_cb), fc);
186 gtk_widget_show_all(fc->win);
187 window_present(fc->win);
189 cf_retap_packets(&cfile);
190 gdk_window_raise(gtk_widget_get_window(fc->win));
193 static tap_param fc_stat_params[] = {
194 { PARAM_FILTER, "Filter", NULL }
197 static tap_param_dlg fc_stat_dlg = {
198 "Fibre Channel Service Response Time statistics",
199 "fc,srt",
200 gtk_fcstat_init,
202 G_N_ELEMENTS(fc_stat_params),
203 fc_stat_params
206 void
207 register_tap_listener_gtkfcstat(void)
209 register_param_stat(&fc_stat_dlg, "Fibre Channel",
210 REGISTER_STAT_GROUP_RESPONSE_TIME);