Witness: enum witness_notifyResponse_type
[wireshark-wip.git] / ui / gtk / afp_stat.c
blob61258ea2d40fd3e5aa53fdde7796783a8a5122a6
1 /* afp_stat.c
2 * Based on
3 * smb_stat 2003 Ronnie Sahlberg
5 * $Id$
7 * Wireshark - Network traffic analyzer
8 * By Gerald Combs <gerald@wireshark.org>
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 #include "config.h"
28 #include <string.h>
30 #include <gtk/gtk.h>
32 #include <epan/packet_info.h>
33 #include <epan/epan.h>
34 #include <epan/value_string.h>
35 #include <epan/tap.h>
36 #include <epan/dissectors/packet-afp.h>
38 #include "../file.h"
39 #include "../stat_menu.h"
41 #include "ui/simple_dialog.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/main.h"
49 #include "ui/gtk/old-gtk-compat.h"
51 /* used to keep track of the statistics for an entire program interface */
52 typedef struct _afpstat_t {
53 GtkWidget *win;
54 srt_stat_table afp_srt_table;
55 } afpstat_t;
57 static void
58 afpstat_set_title(afpstat_t *ss)
60 set_window_title(ss->win, "AFP Service Response Time statistics");
63 static void
64 afpstat_reset(void *pss)
66 afpstat_t *ss=(afpstat_t *)pss;
68 reset_srt_table_data(&ss->afp_srt_table);
69 afpstat_set_title(ss);
72 static int
73 afpstat_packet(void *pss, packet_info *pinfo, epan_dissect_t *edt _U_, const void *prv)
75 afpstat_t *ss=(afpstat_t *)pss;
76 const afp_request_val *request_val=(const afp_request_val *)prv;
78 /* if we havnt seen the request, just ignore it */
79 if(!request_val){
80 return 0;
83 add_srt_table_data(&ss->afp_srt_table, request_val->command, &request_val->req_time, pinfo);
85 return 1;
90 static void
91 afpstat_draw(void *pss)
93 afpstat_t *ss=(afpstat_t *)pss;
95 draw_srt_table_data(&ss->afp_srt_table);
99 static void
100 win_destroy_cb(GtkWindow *win _U_, gpointer data)
102 afpstat_t *ss=(afpstat_t *)data;
104 remove_tap_listener(ss);
106 free_srt_table_data(&ss->afp_srt_table);
107 g_free(ss);
111 static void
112 gtk_afpstat_init(const char *opt_arg, void *userdata _U_)
114 afpstat_t *ss;
115 const char *filter=NULL;
116 GtkWidget *label;
117 char *filter_string;
118 GString *error_string;
119 int i;
120 GtkWidget *vbox;
121 GtkWidget *bbox;
122 GtkWidget *close_bt;
124 if(!strncmp(opt_arg,"afp,srt,",8)){
125 filter=opt_arg+8;
126 } else {
127 filter=NULL;
130 ss=(afpstat_t *)g_malloc(sizeof(afpstat_t));
132 ss->win=dlg_window_new("afp-stat"); /* transient_for top_level */
133 gtk_window_set_destroy_with_parent (GTK_WINDOW(ss->win), TRUE);
134 gtk_window_set_default_size(GTK_WINDOW(ss->win), 550, 600);
135 afpstat_set_title(ss);
137 vbox=ws_gtk_box_new(GTK_ORIENTATION_VERTICAL, 3, FALSE);
138 gtk_container_add(GTK_CONTAINER(ss->win), vbox);
139 gtk_container_set_border_width(GTK_CONTAINER(vbox), 12);
141 label=gtk_label_new("AFP Service Response Time statistics");
142 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
144 filter_string = g_strdup_printf("Filter: %s", filter ? filter : "");
145 label=gtk_label_new(filter_string);
146 gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
147 g_free(filter_string);
148 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
150 label=gtk_label_new("AFP Commands");
151 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
153 /* We must display TOP LEVEL Widget before calling init_srt_table() */
154 gtk_widget_show_all(ss->win);
156 init_srt_table(&ss->afp_srt_table, 256, vbox, "afp.command");
157 for(i=0;i<256;i++){
158 init_srt_table_row(&ss->afp_srt_table, i, val_to_str_ext(i, &CommandCode_vals_ext, "Unknown(%u)"));
162 error_string=register_tap_listener("afp", ss, filter, 0, afpstat_reset, afpstat_packet, afpstat_draw);
163 if(error_string){
164 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", error_string->str);
165 g_string_free(error_string, TRUE);
166 g_free(ss);
167 return;
170 /* Button row. */
171 bbox = dlg_button_row_new(GTK_STOCK_CLOSE, NULL);
172 gtk_box_pack_end(GTK_BOX(vbox), bbox, FALSE, FALSE, 0);
174 close_bt = (GtkWidget *)g_object_get_data(G_OBJECT(bbox), GTK_STOCK_CLOSE);
175 window_set_cancel_button(ss->win, close_bt, window_cancel_button_cb);
177 g_signal_connect(ss->win, "delete_event", G_CALLBACK(window_delete_event_cb), NULL);
178 g_signal_connect(ss->win, "destroy", G_CALLBACK(win_destroy_cb), ss);
180 gtk_widget_show_all(ss->win);
181 window_present(ss->win);
183 cf_retap_packets(&cfile);
184 gdk_window_raise(gtk_widget_get_window(ss->win));
187 static tap_param afp_stat_params[] = {
188 { PARAM_FILTER, "Filter", NULL }
191 static tap_param_dlg afp_stat_dlg = {
192 "AFP SRT Statistics",
193 "afp,srt",
194 gtk_afpstat_init,
196 G_N_ELEMENTS(afp_stat_params),
197 afp_stat_params
200 void
201 register_tap_listener_gtkafpstat(void)
203 register_param_stat(&afp_stat_dlg, "AFP",
204 REGISTER_STAT_GROUP_RESPONSE_TIME);