Add support for PARAM_ENUM tap parameters, and use the tap_param_dlg
authorguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>
Mon, 6 Jun 2011 01:04:56 +0000 (01:04 +0000)
committerguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>
Mon, 6 Jun 2011 01:04:56 +0000 (01:04 +0000)
stuff for the SCSI SRT tap.

Get rid of include of gtk/filter_dlg.h in stats taps that don't need it.

git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@37562 f5534014-38df-0310-8fa8-9805f1628bb7

gtk/afp_stat.c
gtk/diameter_stat.c
gtk/fc_stat.c
gtk/gtp_stat.c
gtk/ldap_stat.c
gtk/ncp_stat.c
gtk/scsi_stat.c
gtk/smb2_stat.c
gtk/smb_stat.c
gtk/tap_param_dlg.c

index 09faea7ac6462453d86f6b510adc3ac944fbd51a..6479154a2a168f0b023cabe0dc340682f2e55ae2 100644 (file)
@@ -48,7 +48,6 @@
 
 #include "gtk/gui_utils.h"
 #include "gtk/dlg_utils.h"
-#include "gtk/filter_dlg.h"
 #include "gtk/service_response_time_table.h"
 #include "gtk/tap_param_dlg.h"
 #include "gtk/main.h"
index 39ee6f2f87c41eca1571c10312bda316f17a1010..0905f1d69499fb668225f7ea17112923bb69485d 100644 (file)
@@ -49,7 +49,6 @@
 
 #include "gtk/gui_utils.h"
 #include "gtk/dlg_utils.h"
-#include "gtk/filter_dlg.h"
 #include "gtk/service_response_time_table.h"
 #include "gtk/tap_param_dlg.h"
 #include "gtk/gtkglobals.h"
index 599a8dfe8e821b07d04ae915bdc1f13e75cfb07f..38618143371200c44bf31f25b27716df614e8e1c 100644 (file)
@@ -49,7 +49,6 @@
 
 #include "gtk/gui_utils.h"
 #include "gtk/dlg_utils.h"
-#include "gtk/filter_dlg.h"
 #include "gtk/service_response_time_table.h"
 #include "gtk/tap_param_dlg.h"
 #include "gtk/gtkglobals.h"
index 19574fcbf4f50a4198511d01b6a801330a7ab7d0..21b3f51d9eb889b990c59f9bc1dba58e8f229802 100644 (file)
@@ -48,7 +48,6 @@
 
 #include "gtk/gui_utils.h"
 #include "gtk/dlg_utils.h"
-#include "gtk/filter_dlg.h"
 #include "gtk/service_response_time_table.h"
 #include "gtk/tap_param_dlg.h"
 #include "gtk/gtkglobals.h"
index f9cf31e9884a60eeab9b1df154094278abf19aeb..8f235401e88bc7bbeca3e563268b5b03e5fa2597 100644 (file)
@@ -47,7 +47,6 @@
 
 #include "gtk/gui_utils.h"
 #include "gtk/dlg_utils.h"
-#include "gtk/filter_dlg.h"
 #include "gtk/service_response_time_table.h"
 #include "gtk/tap_param_dlg.h"
 #include "gtk/gtkglobals.h"
index 79f23307e9b9ec3600635449eb46109f5d960f0b..6940b78b67abd62c1cb6744a394d28da80c8013a 100644 (file)
@@ -47,7 +47,6 @@
 
 #include "gtk/gui_utils.h"
 #include "gtk/dlg_utils.h"
-#include "gtk/filter_dlg.h"
 #include "gtk/service_response_time_table.h"
 #include "gtk/tap_param_dlg.h"
 #include "gtk/gtkglobals.h"
index 84a288e5701cdb1cbe9eee6fbaa3ee08fdb54e54..ca9e80aa1aa881f408685fca21d559814a2c5be9 100644 (file)
 #include "gtk/gui_utils.h"
 #include "gtk/dlg_utils.h"
 #include "gtk/main.h"
-#include "gtk/filter_dlg.h"
-#include "gtk/stock_icons.h"
 #include "gtk/service_response_time_table.h"
+#include "gtk/tap_param_dlg.h"
 #include "gtk/gtkglobals.h"
-#include "gtk/filter_autocomplete.h"
 
 
-static GtkWidget *dlg=NULL;
-
 /* used to keep track of the statistics for an entire scsi command set */
 typedef struct _scsistat_t {
        GtkWidget *win;
@@ -73,7 +69,6 @@ typedef struct _scsistat_t {
 } scsistat_t;
 
 static guint8 scsi_program=0;
-static GtkWidget *filter_entry;
 
 enum
 {
@@ -113,34 +108,6 @@ scsistat_reset(void *arg)
 }
 
 
-static void
-dlg_destroy_cb(GtkWidget *w _U_, gpointer user_data _U_)
-{
-       dlg=NULL;
-}
-
-static void
-scsistat_program_select(GtkWidget *w, gpointer key _U_)
-{
-       int i;
-
-       i = gtk_combo_box_get_active (GTK_COMBO_BOX(w));
-       switch(i){
-               case SCSI_STAT_PROG_LABEL_SBC:
-                       scsi_program = SCSI_DEV_SBC;
-                       break;
-               case SCSI_STAT_PROG_LABEL_SSC:
-                       scsi_program = SCSI_DEV_SSC;
-                       break;
-               case SCSI_STAT_PROG_LABEL_MMC:
-                       scsi_program = SCSI_DEV_CDROM;
-                       break;
-               default:
-                       scsi_program = SCSI_DEV_SBC;
-                       break;
-       }
-}
-
 static int
 scsistat_packet(void *arg, packet_info *pinfo, epan_dissect_t *edt _U_, const void *arg2)
 {
@@ -313,146 +280,32 @@ gtk_scsistat_init(const char *optarg, void* userdata _U_)
        gdk_window_raise(rs->win->window);
 }
 
+static enum_val_t scsi_command_sets[] = {
+       { "sbc", "SBC (disk)", SCSI_DEV_SBC },
+       { "ssc", "SSC (tape)", SCSI_DEV_SSC },
+       { "mmc", "MMC (cd/dvd)", SCSI_DEV_CDROM },
+       { "smc", "SMC (tape robot)", SCSI_DEV_SMC },
+       { "osd", "OSD (object based)", SCSI_DEV_OSD },
+       { NULL, NULL, 0 }
+};
 
+static tap_param scsi_stat_params[] = {
+       { PARAM_ENUM, "Command set", scsi_command_sets },
+       { PARAM_FILTER, "Filter", NULL }
+};
 
-static void
-scsistat_start_button_clicked(GtkWidget *item _U_, gpointer data _U_)
-{
-       GString *str;
-       const char *filter;
-
-       str = g_string_new("scsi,srt");
-       g_string_append_printf(str, ",%d", scsi_program);
-       filter=gtk_entry_get_text(GTK_ENTRY(filter_entry));
-       if(filter[0]!=0){
-               g_string_append_printf(str, ",%s", filter);
-       }
-
-       gtk_scsistat_init(str->str,NULL);
-       g_string_free(str, TRUE);
-}
-
-static void
-gtk_scsistat_cb(GtkWidget *w _U_, gpointer d _U_)
-{
-       GtkWidget *prog_combo_box;
-       GtkWidget *dlg_box;
-       GtkWidget *prog_box, *prog_label;
-       GtkWidget *filter_box, *filter_bt;
-       GtkWidget *bbox, *start_button, *cancel_button;
-       const char *filter;
-       static construct_args_t args = {
-         "Service Response Time Statistics Filter",
-         TRUE,
-         FALSE,
-      FALSE
-       };
-
-       /* if the window is already open, bring it to front */
-       if(dlg){
-               gdk_window_raise(dlg->window);
-               return;
-       }
-
-       dlg=dlg_window_new("Wireshark: Compute SCSI SRT statistics");
-       gtk_window_set_default_size(GTK_WINDOW(dlg), 300, -1);
-
-       dlg_box=gtk_vbox_new(FALSE, 10);
-       gtk_container_set_border_width(GTK_CONTAINER(dlg_box), 10);
-       gtk_container_add(GTK_CONTAINER(dlg), dlg_box);
-       gtk_widget_show(dlg_box);
-
-       /* Program box */
-       prog_box=gtk_hbox_new(FALSE, 10);
-
-       /* Program label */
-       gtk_container_set_border_width(GTK_CONTAINER(prog_box), 10);
-       prog_label=gtk_label_new("Commandset:");
-       gtk_box_pack_start(GTK_BOX(prog_box), prog_label, FALSE, FALSE, 0);
-       gtk_widget_show(prog_label);
-
-       /* Program menu */
-       prog_combo_box = gtk_combo_box_new_text ();
-
-       /* SBC */
-       gtk_combo_box_append_text (GTK_COMBO_BOX (prog_combo_box), "SBC (disk)");
-       /* SSC */
-       gtk_combo_box_append_text (GTK_COMBO_BOX (prog_combo_box), "SSC (tape)");
-       /* MMC */
-       gtk_combo_box_append_text (GTK_COMBO_BOX (prog_combo_box), "MMC (cd/dvd)");
-
-       gtk_box_pack_start(GTK_BOX(prog_box), prog_combo_box, TRUE, TRUE, 0);
-       gtk_combo_box_set_active(GTK_COMBO_BOX(prog_combo_box), SCSI_DEV_SBC);
-       g_signal_connect(prog_combo_box, "changed", G_CALLBACK(scsistat_program_select), NULL);
-       gtk_widget_show(prog_combo_box);
-
-       gtk_box_pack_start(GTK_BOX(dlg_box), prog_box, TRUE, TRUE, 0);
-       gtk_widget_show(prog_box);
-
-       /* Filter box */
-       filter_box=gtk_hbox_new(FALSE, 3);
-
-       /* Filter label */
-       filter_bt=gtk_button_new_from_stock(WIRESHARK_STOCK_DISPLAY_FILTER_ENTRY);
-       g_signal_connect(filter_bt, "clicked", G_CALLBACK(display_filter_construct_cb), &args);
-       gtk_box_pack_start(GTK_BOX(filter_box), filter_bt, FALSE, FALSE, 0);
-       gtk_widget_show(filter_bt);
-
-       /* Filter entry */
-       filter_entry=gtk_entry_new();
-        g_signal_connect(filter_entry, "changed", G_CALLBACK(filter_te_syntax_check_cb), NULL);
-       g_object_set_data(G_OBJECT(filter_box), E_FILT_AUTOCOMP_PTR_KEY, NULL);
-       g_signal_connect(filter_entry, "key-press-event", G_CALLBACK (filter_string_te_key_pressed_cb), NULL);
-       g_signal_connect(dlg, "key-press-event", G_CALLBACK (filter_parent_dlg_key_pressed_cb), NULL);
-
-       /* filter prefs dialog */
-        g_object_set_data(G_OBJECT(filter_bt), E_FILT_TE_PTR_KEY, filter_entry);
-       /* filter prefs dialog */
-
-       gtk_box_pack_start(GTK_BOX(filter_box), filter_entry, TRUE, TRUE, 0);
-       filter=gtk_entry_get_text(GTK_ENTRY(main_display_filter_widget));
-       if(filter){
-               gtk_entry_set_text(GTK_ENTRY(filter_entry), filter);
-       } else {
-               colorize_filter_te_as_empty(filter_entry);
-       }
-       gtk_widget_show(filter_entry);
-
-       gtk_box_pack_start(GTK_BOX(dlg_box), filter_box, TRUE, TRUE, 0);
-       gtk_widget_show(filter_box);
-
-       /* button box */
-        bbox = dlg_button_row_new(WIRESHARK_STOCK_CREATE_STAT, GTK_STOCK_CANCEL, NULL);
-       gtk_box_pack_start(GTK_BOX(dlg_box), bbox, FALSE, FALSE, 0);
-        gtk_widget_show(bbox);
-
-        start_button = (GtkWidget *)g_object_get_data(G_OBJECT(bbox), WIRESHARK_STOCK_CREATE_STAT);
-        g_signal_connect_swapped(start_button, "clicked",
-                            G_CALLBACK(scsistat_start_button_clicked), NULL);
-
-        cancel_button = (GtkWidget *)g_object_get_data(G_OBJECT(bbox), GTK_STOCK_CANCEL);
-        window_set_cancel_button(dlg, cancel_button, window_cancel_button_cb);
-
-       /* Give the initial focus to the "Filter" entry box. */
-       gtk_widget_grab_focus(filter_entry);
-
-        gtk_widget_grab_default(start_button );
-
-        g_signal_connect(dlg, "delete_event", G_CALLBACK(window_delete_event_cb), NULL);
-       g_signal_connect(dlg, "destroy", G_CALLBACK(dlg_destroy_cb), NULL);
-
-        gtk_widget_show_all(dlg);
-        window_present(dlg);
-}
-
+static tap_param_dlg scsi_stat_dlg = {
+       "SCSI SRT Statistics",
+       "scsi,srt",
+       gtk_scsistat_init,
+       -1,
+       G_N_ELEMENTS(scsi_stat_params),
+       scsi_stat_params
+};
 
 void
 register_tap_listener_gtkscsistat(void)
 {
-       register_stat_cmd_arg("scsi,srt,", gtk_scsistat_init, NULL);
-
-       register_stat_menu_item("SCSI...", REGISTER_STAT_GROUP_RESPONSE_TIME,
-           gtk_scsistat_cb, NULL, NULL, NULL);
-
+       register_dfilter_stat(&scsi_stat_dlg, "SCSI",
+           REGISTER_STAT_GROUP_RESPONSE_TIME);
 }
-
index 3a327f30731cd99ac1d132bd5b61150e14ec352a..88bae52262177306f41412c5c62b89f961d5a029 100644 (file)
@@ -47,7 +47,6 @@
 
 #include "gtk/gui_utils.h"
 #include "gtk/dlg_utils.h"
-#include "gtk/filter_dlg.h"
 #include "gtk/service_response_time_table.h"
 #include "gtk/tap_param_dlg.h"
 #include "gtk/gtkglobals.h"
index e0d8808f4a41b8da9452146f815b2ce8b0918254..b4088b3452349aa4c8c9b2c4e775903aa8bcba1e 100644 (file)
@@ -47,7 +47,6 @@
 
 #include "gtk/gui_utils.h"
 #include "gtk/dlg_utils.h"
-#include "gtk/filter_dlg.h"
 #include "gtk/service_response_time_table.h"
 #include "gtk/tap_param_dlg.h"
 #include "gtk/gtkglobals.h"
index 05d32b8c74411705e6ccec354c7dd30e1837e077..2da60019ffd02981627ebcb475c376d01952a0dc 100644 (file)
@@ -57,7 +57,7 @@ typedef struct _tap_param_dlg_list_item {
     GtkWidget *dlg;
     tap_param_dlg cont;
     construct_args_t args;
-    GtkWidget **param_entries;    /* items for params */
+    GtkWidget **param_items;    /* items for params */
     struct _tap_param_dlg_list_item *next;
 } tap_param_dlg_list_item;
 
@@ -115,17 +115,30 @@ dlg_destroy_cb(GtkWidget *item _U_, gpointer dialog_data)
 static void
 tap_param_dlg_start_button_clicked(GtkWidget *item _U_, gpointer dialog_data)
 {
-    const char *value;
     GString *params;
     size_t i;
+    gint j;
     
     tap_param_dlg_list_item *dlg_data = (tap_param_dlg_list_item *) dialog_data;
 
     params = g_string_new(dlg_data->cont.init_string);
     for(i=0;i<dlg_data->cont.nparams;i++) {
-        value=gtk_entry_get_text(GTK_ENTRY(dlg_data->param_entries[i]));
-        params=g_string_append_c(params, ',');
-        params=g_string_append(params, value);
+        g_string_append_c(params, ',');
+        switch (dlg_data->cont.params[i].type) {
+
+        case PARAM_ENUM:
+            j = gtk_combo_box_get_active(GTK_COMBO_BOX(dlg_data->param_items[i]));
+            g_string_append_printf(params,"%d",
+                                   dlg_data->cont.params[i].enum_vals[j].value);
+            break;
+
+        case PARAM_UINT:
+        case PARAM_STRING:
+        case PARAM_FILTER:
+            g_string_append(params,
+                            gtk_entry_get_text(GTK_ENTRY(dlg_data->param_items[i])));
+            break;
+        }
     }
     (dlg_data->cont.tap_init_cb)(params->str,NULL);
     g_string_free(params, TRUE);
@@ -138,9 +151,10 @@ tap_param_dlg_cb(GtkWidget *w _U_, gpointer data)
     const char *filter;
     char *title;
     GtkWidget *dlg_box;
-    GtkWidget *item_box, *item_entry, *label, *filter_bt;
+    GtkWidget *item_box, *item, *label, *filter_bt;
     GtkWidget *bbox, *start_button, *cancel_button;
-    size_t i;
+    size_t i, j;
+    char *label_with_colon;
     
     tap_param_dlg *dlg_data = (tap_param_dlg *) data;
 
@@ -159,7 +173,7 @@ tap_param_dlg_cb(GtkWidget *w _U_, gpointer data)
             end_dlg_list = end_dlg_list->next;
         }
         end_dlg_list->dlg = NULL;
-        end_dlg_list->param_entries = g_malloc(dlg_data->nparams * sizeof (GtkWidget *));
+        end_dlg_list->param_items = g_malloc(dlg_data->nparams * sizeof (GtkWidget *));
         end_dlg_list->cont.win_title = dlg_data->win_title;
         end_dlg_list->cont.init_string = dlg_data->init_string;
         end_dlg_list->cont.tap_init_cb = dlg_data->tap_init_cb;
@@ -207,18 +221,36 @@ tap_param_dlg_cb(GtkWidget *w _U_, gpointer data)
         /* Item box */
         item_box=gtk_hbox_new(FALSE, 3);
 
-        /* Item entry */
-        item_entry=gtk_entry_new();
-        current_dlg->param_entries[i] = item_entry;
-
         switch (current_dlg->cont.params[i].type) {
 
         case PARAM_UINT:
         case PARAM_STRING:
             /* Label */
-            label=gtk_label_new(current_dlg->cont.params[i].title);
+            label_with_colon=g_strdup_printf("%s:", current_dlg->cont.params[i].title);
+            label=gtk_label_new(label_with_colon);
+            g_free(label_with_colon);
             gtk_box_pack_start(GTK_BOX(item_box), label, FALSE, TRUE, 0);
             gtk_widget_show(label);
+
+            /* Entry */
+            item=gtk_entry_new();
+            break;
+
+        case PARAM_ENUM:
+            /* Label */
+            label_with_colon=g_strdup_printf("%s:", current_dlg->cont.params[i].title);
+            label=gtk_label_new(label_with_colon);
+            g_free(label_with_colon);
+            gtk_box_pack_start(GTK_BOX(item_box), label, FALSE, TRUE, 0);
+            gtk_widget_show(label);
+
+            /* Combo box */
+            item=gtk_combo_box_new_text();
+            for (j = 0; current_dlg->cont.params[i].enum_vals[j].name != NULL;
+                 j++)
+                gtk_combo_box_append_text(GTK_COMBO_BOX(item),
+                                          current_dlg->cont.params[i].enum_vals[j].description);
+            gtk_combo_box_set_active(GTK_COMBO_BOX(item), 0);
             break;
 
         case PARAM_FILTER:
@@ -227,39 +259,31 @@ tap_param_dlg_cb(GtkWidget *w _U_, gpointer data)
             g_signal_connect(filter_bt, "clicked", G_CALLBACK(display_filter_construct_cb), &(current_dlg->args));
             gtk_box_pack_start(GTK_BOX(item_box), filter_bt, FALSE, TRUE, 0);
             gtk_widget_show(filter_bt);
-            g_signal_connect(item_entry, "changed", G_CALLBACK(filter_te_syntax_check_cb), NULL);
-            g_object_set_data(G_OBJECT(item_box), E_FILT_AUTOCOMP_PTR_KEY, NULL);
-            g_signal_connect(item_entry, "key-press-event", G_CALLBACK (filter_string_te_key_pressed_cb), NULL);
-            g_signal_connect(current_dlg->dlg, "key-press-event", G_CALLBACK (filter_parent_dlg_key_pressed_cb), NULL);
-
-            /* prefs dialog */
-            g_object_set_data(G_OBJECT(filter_bt), E_FILT_TE_PTR_KEY, item_entry);
-            /* prefs dialog */
-            break;
-
-        default:
-            /* XXX - fill me in */
-            break;
-        }
-    
-        gtk_box_pack_start(GTK_BOX(item_box), item_entry, TRUE, TRUE, 0);
-
-        switch(current_dlg->cont.params[i].type){
 
-        case PARAM_FILTER:
+            /* Entry */
+            item=gtk_entry_new();
             filter=gtk_entry_get_text(GTK_ENTRY(main_display_filter_widget));
             if(filter){
-                gtk_entry_set_text(GTK_ENTRY(item_entry), filter);
+                gtk_entry_set_text(GTK_ENTRY(item), filter);
             } else {
-                colorize_filter_te_as_empty(item_entry);
+                colorize_filter_te_as_empty(item);
             }
+            g_signal_connect(item, "changed", G_CALLBACK(filter_te_syntax_check_cb), NULL);
+            g_object_set_data(G_OBJECT(item_box), E_FILT_AUTOCOMP_PTR_KEY, NULL);
+            g_signal_connect(item, "key-press-event", G_CALLBACK (filter_string_te_key_pressed_cb), NULL);
+            g_signal_connect(current_dlg->dlg, "key-press-event", G_CALLBACK (filter_parent_dlg_key_pressed_cb), NULL);
+            g_object_set_data(G_OBJECT(filter_bt), E_FILT_TE_PTR_KEY, item);
             break;
 
         default:
-            /* XXX - anything to do here? */
+            g_assert_not_reached();
+            item=NULL;
             break;
         }
-        gtk_widget_show(item_entry);
+    
+        gtk_box_pack_start(GTK_BOX(item_box), item, TRUE, TRUE, 0);
+        current_dlg->param_items[i]=item;
+        gtk_widget_show(item);
 
         gtk_box_pack_start(GTK_BOX(dlg_box), item_box, TRUE, TRUE, 0);
         gtk_widget_show(item_box);
@@ -283,12 +307,22 @@ tap_param_dlg_cb(GtkWidget *w _U_, gpointer data)
        some widget that *doesn't* handle the Return key has the input
        focus. */
     for(i=0;i<current_dlg->cont.nparams;i++){
-        dlg_set_activate(current_dlg->param_entries[i], start_button);
+        switch (current_dlg->cont.params[i].type) {
+
+        case PARAM_ENUM:
+            break;
+
+        case PARAM_UINT:
+        case PARAM_STRING:
+        case PARAM_FILTER:
+            dlg_set_activate(current_dlg->param_items[i], start_button);
+            break;
+        }
     }
 
     /* Give the initial focus to the first entry box. */
     if(current_dlg->cont.nparams>0){
-        gtk_widget_grab_focus(current_dlg->param_entries[0]);
+        gtk_widget_grab_focus(current_dlg->param_items[0]);
     }
 
     gtk_widget_grab_default(start_button );