*
* $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
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
- *
+ *
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
# include "config.h"
#endif
-#include <string.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <math.h>
#include <gtk/gtk.h>
-#include "compat_macros.h"
-#include "epan/packet_info.h"
-#include "service_response_time_table.h"
-#include "image/clist_ascend.xpm"
-#include "image/clist_descend.xpm"
-#include "simple_dialog.h"
-#include "globals.h"
-#include "gtk/find_dlg.h"
-#include "color.h"
-#include "gtk/color_dlg.h"
-#include "main.h"
-#include "gui_utils.h"
-#include "gtkglobals.h"
-
+#include <stdio.h>
-#define GTK_MENU_FUNC(a) ((GtkItemFactoryCallback)(a))
+#include "epan/packet_info.h"
+#include "../simple_dialog.h"
-typedef struct column_arrows {
- GtkWidget *table;
- GtkWidget *ascend_pm;
- GtkWidget *descend_pm;
-} column_arrows;
+#include "gtk/service_response_time_table.h"
+#include "gtk/filter_utils.h"
+#include "gtk/gui_utils.h"
+#include "gtk/utf8_entities.h"
+#define NANOSECS_PER_SEC 1000000000
-static void
-srt_click_column_cb(GtkCList *clist, gint column, gpointer data)
+enum
{
- column_arrows *col_arrows = (column_arrows *) data;
- int i;
-
- gtk_clist_freeze(clist);
-
- for (i = 0; i < 6; i++) {
- gtk_widget_hide(col_arrows[i].ascend_pm);
- gtk_widget_hide(col_arrows[i].descend_pm);
- }
-
- if (column == clist->sort_column) {
- if (clist->sort_type == GTK_SORT_ASCENDING) {
- clist->sort_type = GTK_SORT_DESCENDING;
- gtk_widget_show(col_arrows[column].descend_pm);
- } else {
- clist->sort_type = GTK_SORT_ASCENDING;
- gtk_widget_show(col_arrows[column].ascend_pm);
- }
- } else {
- /* Columns 2-5 Count, Min, Max, Avg are sorted in descending
- order by default.
- Columns 0 and 1 sort by ascending order by default
- */
- if(column>=2){
- clist->sort_type = GTK_SORT_DESCENDING;
- gtk_widget_show(col_arrows[column].descend_pm);
- } else {
- clist->sort_type = GTK_SORT_ASCENDING;
- gtk_widget_show(col_arrows[column].ascend_pm);
- }
- gtk_clist_set_sort_column(clist, column);
- }
- gtk_clist_thaw(clist);
-
- gtk_clist_sort(clist);
-}
-
-static gint
-srt_sort_column(GtkCList *clist, gconstpointer ptr1, gconstpointer ptr2)
-{
- char *text1 = NULL;
- char *text2 = NULL;
- int i1, i2;
- float f1,f2;
-
- const GtkCListRow *row1 = ptr1;
- const GtkCListRow *row2 = ptr2;
-
- text1 = GTK_CELL_TEXT (row1->cell[clist->sort_column])->text;
- text2 = GTK_CELL_TEXT (row2->cell[clist->sort_column])->text;
-
- switch(clist->sort_column){
- case 1:
- return strcmp (text1, text2);
- case 0:
- case 2:
- i1=atoi(text1);
- i2=atoi(text2);
- return i1-i2;
- case 3:
- case 4:
- case 5:
- sscanf(text1,"%f",&f1);
- sscanf(text2,"%f",&f2);
- if(fabs(f1-f2)<0.000005)
- return 0;
- if(f1>f2)
- return 1;
- return -1;
- }
- g_assert_not_reached();
- return 0;
-}
-
-
+ INDEX_COLUMN,
+ PROCEDURE_COLUMN,
+ CALLS_COLUMN,
+ MIN_SRT_COLUMN,
+ MAX_SRT_COLUMN,
+ AVG_SRT_COLUMN,
+ N_COLUMNS
+};
-/* action is encoded as
- filter_action*256+filter_type
- filter_action:
- 0: Match
- 1: Prepare
- 2: Find Frame
- 3: Find Next
- 4: Find Previous
- 5: Colorize Procedure
- filter_type:
- 0: Selected
- 1: Not Selected
- 2: And Selected
- 3: Or Selected
- 4: And Not Selected
- 5: Or Not Selected
-*/
static void
srt_select_filter_cb(GtkWidget *widget _U_, gpointer callback_data, guint callback_action)
{
- int action, type, selection;
srt_stat_table *rst = (srt_stat_table *)callback_data;
- char str[256];
- const char *current_filter;
-
+ char *str = NULL;
+ GtkTreeIter iter;
+ GtkTreeModel *model;
+ GtkTreeSelection *sel;
+ int selection;
if(rst->filter_string==NULL){
return;
}
- action=(callback_action>>8)&0xff;
- type=callback_action&0xff;
+ sel = gtk_tree_view_get_selection (GTK_TREE_VIEW(rst->table));
+
+ if (!gtk_tree_selection_get_selected(sel, &model, &iter))
+ return;
- selection=GPOINTER_TO_INT(g_list_nth_data(GTK_CLIST(rst->table)->selection, 0));
+ gtk_tree_model_get (model, &iter, INDEX_COLUMN, &selection, -1);
if(selection>=(int)rst->num_procs){
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "No procedure selected");
return;
}
- /* translate it back from row index to index in procedures array */
- selection=GPOINTER_TO_INT(gtk_clist_get_row_data(rst->table, selection));
-
- current_filter=gtk_entry_get_text(GTK_ENTRY(main_display_filter_widget));
-
- switch(type){
- case 0:
- /* selected */
- g_snprintf(str, 255, "%s==%d", rst->filter_string, selection);
- break;
- case 1:
- /* not selected */
- g_snprintf(str, 255, "!(%s==%d)", rst->filter_string, selection);
- break;
- case 2:
- /* and selected */
- g_snprintf(str, 255, "(%s) && (%s==%d)", current_filter, rst->filter_string, selection);
- break;
- case 3:
- /* or selected */
- g_snprintf(str, 255, "(%s) || (%s==%d)", current_filter, rst->filter_string, selection);
- break;
- case 4:
- /* and not selected */
- g_snprintf(str, 255, "(%s) && !(%s==%d)", current_filter, rst->filter_string, selection);
- break;
- case 5:
- /* or not selected */
- g_snprintf(str, 255, "(%s) || !(%s==%d)", current_filter, rst->filter_string, selection);
- break;
- }
- gtk_entry_set_text(GTK_ENTRY(main_display_filter_widget), str);
-
- switch(action){
- case 0:
- /* match */
- main_filter_packets(&cfile, str, FALSE);
- case 1:
- /* prepare */
- /* do nothing */
- break;
- case 2:
- /* find frame */
- find_frame_with_filter(str);
- break;
- case 3:
- /* find next */
- find_previous_next_frame_with_filter(str, FALSE);
- break;
- case 4:
- /* find previous */
- find_previous_next_frame_with_filter(str, TRUE);
- break;
- case 5:
- /* colorize procedure */
- color_display_with_filter(str);
- break;
- }
+ str = g_strdup_printf("%s==%d", rst->filter_string, selection);
+
+ apply_selected_filter (callback_action, str);
+ g_free(str);
}
-static gint
+static gboolean
srt_show_popup_menu_cb(void *widg _U_, GdkEvent *event, srt_stat_table *rst)
{
GdkEventButton *bevent = (GdkEventButton *)event;
if(event->type==GDK_BUTTON_PRESS && bevent->button==3){
- gtk_menu_popup(GTK_MENU(rst->menu), NULL, NULL, NULL, NULL,
+ gtk_menu_popup(GTK_MENU(rst->menu), NULL, NULL, NULL, NULL,
bevent->button, bevent->time);
}
return FALSE;
}
-static GtkItemFactoryEntry srt_list_menu_items[] =
-{
- /* Match */
- ITEM_FACTORY_ENTRY("/Apply as Filter", NULL, NULL, 0, "<Branch>", NULL),
- ITEM_FACTORY_ENTRY("/Apply as Filter/Selected", NULL,
- srt_select_filter_cb, 0*256+0, NULL, NULL),
- ITEM_FACTORY_ENTRY("/Apply as Filter/... not Selected", NULL,
- srt_select_filter_cb, 0*256+1, NULL, NULL),
- ITEM_FACTORY_ENTRY("/Apply as Filter/.. and Selected", NULL,
- srt_select_filter_cb, 0*256+2, NULL, NULL),
- ITEM_FACTORY_ENTRY("/Apply as Filter/... or Selected", NULL,
- srt_select_filter_cb, 0*256+3, NULL, NULL),
- ITEM_FACTORY_ENTRY("/Apply as Filter/... and not Selected", NULL,
- srt_select_filter_cb, 0*256+4, NULL, NULL),
- ITEM_FACTORY_ENTRY("/Apply as Filter/... or not Selected", NULL,
- srt_select_filter_cb, 0*256+5, NULL, NULL),
-
- /* Prepare */
- ITEM_FACTORY_ENTRY("/Prepare a Filter", NULL, NULL, 0, "<Branch>", NULL),
- ITEM_FACTORY_ENTRY("/Prepare a Filter/Selected", NULL,
- srt_select_filter_cb, 1*256+0, NULL, NULL),
- ITEM_FACTORY_ENTRY("/Prepare a Filter/Not Selected", NULL,
- srt_select_filter_cb, 1*256+1, NULL, NULL),
- ITEM_FACTORY_ENTRY("/Prepare a Filter/... and Selected", NULL,
- srt_select_filter_cb, 1*256+2, NULL, NULL),
- ITEM_FACTORY_ENTRY("/Prepare a Filter/... or Selected", NULL,
- srt_select_filter_cb, 1*256+3, NULL, NULL),
- ITEM_FACTORY_ENTRY("/Prepare a Filter/... and not Selected", NULL,
- srt_select_filter_cb, 1*256+4, NULL, NULL),
- ITEM_FACTORY_ENTRY("/Prepare a Filter/... or not Selected", NULL,
- srt_select_filter_cb, 1*256+5, NULL, NULL),
-
- /* Find Frame */
- ITEM_FACTORY_ENTRY("/Find Frame", NULL, NULL, 0, "<Branch>", NULL),
- ITEM_FACTORY_ENTRY("/Find Frame/Find Frame", NULL, NULL, 0, "<Branch>", NULL),
- ITEM_FACTORY_ENTRY("/Find Frame/Find Frame/Selected", NULL,
- srt_select_filter_cb, 2*256+0, NULL, NULL),
- ITEM_FACTORY_ENTRY("/Find Frame/Find Frame/Not Selected", NULL,
- srt_select_filter_cb, 2*256+1, NULL, NULL),
- /* Find Next */
- ITEM_FACTORY_ENTRY("/Find Frame/Find Next", NULL, NULL, 0, "<Branch>", NULL),
- ITEM_FACTORY_ENTRY("/Find Frame/Find Next/Selected", NULL,
- srt_select_filter_cb, 3*256+0, NULL, NULL),
- ITEM_FACTORY_ENTRY("/Find Frame/Find Next/Not Selected", NULL,
- srt_select_filter_cb, 3*256+1, NULL, NULL),
-
- /* Find Previous */
- ITEM_FACTORY_ENTRY("/Find Frame/Find Previous", NULL, NULL, 0, "<Branch>", NULL),
- ITEM_FACTORY_ENTRY("/Find Frame/Find Previous/Selected", NULL,
- srt_select_filter_cb, 4*256+0, NULL, NULL),
- ITEM_FACTORY_ENTRY("/Find Frame/Find Previous/Not Selected", NULL,
- srt_select_filter_cb, 4*256+1, NULL, NULL),
-
- /* Colorize Procedure */
- ITEM_FACTORY_ENTRY("/Colorize Procedure", NULL, NULL, 0, "<Branch>", NULL),
- ITEM_FACTORY_ENTRY("/Colorize Procedure/Selected", NULL,
- srt_select_filter_cb, 5*256+0, NULL, NULL),
- ITEM_FACTORY_ENTRY("/Colorize Procedure/Not Selected", NULL,
- srt_select_filter_cb, 5*256+1, NULL, NULL),
+/* Action callbacks */
+static void
+apply_as_selected_cb(GtkWidget *widget, gpointer user_data)
+{
+ srt_select_filter_cb( widget , user_data, CALLBACK_MATCH(ACTYPE_SELECTED, 0));
+}
+static void
+apply_as_not_selected_cb(GtkWidget *widget, gpointer user_data)
+{
+ srt_select_filter_cb( widget , user_data, CALLBACK_MATCH(ACTYPE_NOT_SELECTED, 0));
+}
+static void
+apply_as_and_selected_cb(GtkWidget *widget, gpointer user_data)
+{
+ srt_select_filter_cb( widget , user_data, CALLBACK_MATCH(ACTYPE_AND_SELECTED, 0));
+}
+static void
+apply_as_or_selected_cb(GtkWidget *widget, gpointer user_data)
+{
+ srt_select_filter_cb( widget , user_data, CALLBACK_MATCH(ACTYPE_OR_SELECTED, 0));
+}
+static void
+apply_as_and_not_selected_cb(GtkWidget *widget, gpointer user_data)
+{
+ srt_select_filter_cb( widget , user_data, CALLBACK_MATCH(ACTYPE_AND_NOT_SELECTED, 0));
+}
+static void
+apply_as_or_not_selected_cb(GtkWidget *widget, gpointer user_data)
+{
+ srt_select_filter_cb( widget , user_data, CALLBACK_MATCH(ACTYPE_OR_NOT_SELECTED, 0));
+}
+
+static void
+prep_as_selected_cb(GtkWidget *widget, gpointer user_data)
+{
+ srt_select_filter_cb( widget , user_data, CALLBACK_PREPARE(ACTYPE_SELECTED, 0));
+}
+static void
+prep_as_not_selected_cb(GtkWidget *widget, gpointer user_data)
+{
+ srt_select_filter_cb( widget , user_data, CALLBACK_PREPARE(ACTYPE_NOT_SELECTED, 0));
+}
+static void
+prep_as_and_selected_cb(GtkWidget *widget, gpointer user_data)
+{
+ srt_select_filter_cb( widget , user_data, CALLBACK_PREPARE(ACTYPE_AND_SELECTED, 0));
+}
+static void
+prep_as_or_selected_cb(GtkWidget *widget, gpointer user_data)
+{
+ srt_select_filter_cb( widget , user_data, CALLBACK_PREPARE(ACTYPE_OR_SELECTED, 0));
+}
+static void
+prep_as_and_not_selected_cb(GtkWidget *widget, gpointer user_data)
+{
+ srt_select_filter_cb( widget , user_data, CALLBACK_PREPARE(ACTYPE_AND_NOT_SELECTED, 0));
+}
+static void
+prep_as_or_not_selected_cb(GtkWidget *widget, gpointer user_data)
+{
+ srt_select_filter_cb( widget , user_data, CALLBACK_PREPARE(ACTYPE_OR_NOT_SELECTED, 0));
+}
+
+static void
+find_selected_cb(GtkWidget *widget, gpointer user_data)
+{
+ srt_select_filter_cb( widget , user_data, CALLBACK_FIND_FRAME(ACTYPE_SELECTED, 0));
+}
+static void
+find_not_selected_cb(GtkWidget *widget, gpointer user_data)
+{
+ srt_select_filter_cb( widget , user_data, CALLBACK_FIND_FRAME(ACTYPE_NOT_SELECTED, 0));
+}
+static void
+find_prev_selected_cb(GtkWidget *widget, gpointer user_data)
+{
+ srt_select_filter_cb( widget , user_data, CALLBACK_FIND_PREVIOUS(ACTYPE_SELECTED, 0));
+}
+static void
+find_prev_not_selected_cb(GtkWidget *widget, gpointer user_data)
+{
+ srt_select_filter_cb( widget , user_data, CALLBACK_FIND_PREVIOUS(ACTYPE_NOT_SELECTED, 0));
+}
+static void
+find_next_selected_cb(GtkWidget *widget, gpointer user_data)
+{
+ srt_select_filter_cb( widget , user_data, CALLBACK_FIND_NEXT(ACTYPE_SELECTED, 0));
+}
+static void
+find_next_not_selected_cb(GtkWidget *widget, gpointer user_data)
+{
+ srt_select_filter_cb( widget , user_data, CALLBACK_FIND_NEXT(ACTYPE_NOT_SELECTED, 0));
+}
+static void
+color_selected_cb(GtkWidget *widget, gpointer user_data)
+{
+ srt_select_filter_cb( widget , user_data, CALLBACK_COLORIZE(ACTYPE_SELECTED, 0));
+}
+static void
+color_not_selected_cb(GtkWidget *widget, gpointer user_data)
+{
+ srt_select_filter_cb( widget , user_data, CALLBACK_COLORIZE(ACTYPE_SELECTED, 0));
+}
+
+static const char *ui_desc_service_resp_t_filter_popup =
+"<ui>\n"
+" <popup name='ServiceRespTFilterPopup'>\n"
+" <menu action='/Apply as Filter'>\n"
+" <menuitem action='/Apply as Filter/Selected'/>\n"
+" <menuitem action='/Apply as Filter/" UTF8_HORIZONTAL_ELLIPSIS " not Selected'/>\n"
+" <menuitem action='/Apply as Filter/" UTF8_HORIZONTAL_ELLIPSIS " and Selected'/>\n"
+" <menuitem action='/Apply as Filter/" UTF8_HORIZONTAL_ELLIPSIS " or Selected'/>\n"
+" <menuitem action='/Apply as Filter/" UTF8_HORIZONTAL_ELLIPSIS " and not Selected'/>\n"
+" <menuitem action='/Apply as Filter/" UTF8_HORIZONTAL_ELLIPSIS " or not Selected'/>\n"
+" </menu>\n"
+" <menu action='/Prepare a Filter'>\n"
+" <menuitem action='/Prepare a Filter/Selected'/>\n"
+" <menuitem action='/Prepare a Filter/" UTF8_HORIZONTAL_ELLIPSIS " not Selected'/>\n"
+" <menuitem action='/Prepare a Filter/" UTF8_HORIZONTAL_ELLIPSIS " and Selected'/>\n"
+" <menuitem action='/Prepare a Filter/" UTF8_HORIZONTAL_ELLIPSIS " or Selected'/>\n"
+" <menuitem action='/Prepare a Filter/" UTF8_HORIZONTAL_ELLIPSIS " and not Selected'/>\n"
+" <menuitem action='/Prepare a Filter/" UTF8_HORIZONTAL_ELLIPSIS " or not Selected'/>\n"
+" </menu>\n"
+" <menu action='/Find Frame'>\n"
+" <menu action='/Find Frame/Find Frame'>\n"
+" <menuitem action='/Find Frame/Selected'/>\n"
+" <menuitem action='/Find Frame/Not Selected'/>\n"
+" </menu>\n"
+" <menu action='/Find Frame/Find Next'>\n"
+" <menuitem action='/Find Next/Selected'/>\n"
+" <menuitem action='/Find Next/Not Selected'/>\n"
+" </menu>\n"
+" <menu action='/Find Frame/Find Previous'>\n"
+" <menuitem action='/Find Previous/Selected'/>\n"
+" <menuitem action='/Find Previous/Not Selected'/>\n"
+" </menu>\n"
+" </menu>\n"
+" <menu action='/Colorize Procedure'>\n"
+" <menuitem action='/Colorize Procedure/Selected'/>\n"
+" <menuitem action='/Colorize Procedure/Not Selected'/>\n"
+" </menu>\n"
+" </popup>\n"
+"</ui>\n";
+
+/*
+ * GtkActionEntry
+ * typedef struct {
+ * const gchar *name;
+ * const gchar *stock_id;
+ * const gchar *label;
+ * const gchar *accelerator;
+ * const gchar *tooltip;
+ * GCallback callback;
+ * } GtkActionEntry;
+ * const gchar *name; The name of the action.
+ * const gchar *stock_id; The stock id for the action, or the name of an icon from the icon theme.
+ * const gchar *label; The label for the action. This field should typically be marked for translation,
+ * see gtk_action_group_set_translation_domain().
+ * If label is NULL, the label of the stock item with id stock_id is used.
+ * const gchar *accelerator; The accelerator for the action, in the format understood by gtk_accelerator_parse().
+ * const gchar *tooltip; The tooltip for the action. This field should typically be marked for translation,
+ * see gtk_action_group_set_translation_domain().
+ * GCallback callback; The function to call when the action is activated.
+ *
+ */
+static const GtkActionEntry service_resp_t__popup_entries[] = {
+ { "/Apply as Filter", NULL, "Apply as Filter", NULL, NULL, NULL },
+ { "/Prepare a Filter", NULL, "Prepare a Filter", NULL, NULL, NULL },
+ { "/Find Frame", NULL, "Find Frame", NULL, NULL, NULL },
+ { "/Find Frame/Find Frame", NULL, "Find Frame", NULL, NULL, NULL },
+ { "/Find Frame/Find Next", NULL, "Find Next" , NULL, NULL, NULL },
+ { "/Find Frame/Find Previous", NULL, "Find Previous", NULL, NULL, NULL },
+ { "/Colorize Procedure", NULL, "Colorize Procedure", NULL, NULL, NULL },
+ { "/Apply as Filter/Selected", NULL, "Selected", NULL, "Selected", G_CALLBACK(apply_as_selected_cb) },
+ { "/Apply as Filter/" UTF8_HORIZONTAL_ELLIPSIS " not Selected", NULL, UTF8_HORIZONTAL_ELLIPSIS " not Selected", NULL, UTF8_HORIZONTAL_ELLIPSIS " not Selected", G_CALLBACK(apply_as_not_selected_cb) },
+ { "/Apply as Filter/" UTF8_HORIZONTAL_ELLIPSIS " and Selected", NULL, UTF8_HORIZONTAL_ELLIPSIS " and Selected", NULL, UTF8_HORIZONTAL_ELLIPSIS " and Selected", G_CALLBACK(apply_as_and_selected_cb) },
+ { "/Apply as Filter/" UTF8_HORIZONTAL_ELLIPSIS " or Selected", NULL, UTF8_HORIZONTAL_ELLIPSIS " or Selected", NULL, UTF8_HORIZONTAL_ELLIPSIS " or Selected", G_CALLBACK(apply_as_or_selected_cb) },
+ { "/Apply as Filter/" UTF8_HORIZONTAL_ELLIPSIS " and not Selected", NULL, UTF8_HORIZONTAL_ELLIPSIS " and not Selected", NULL, UTF8_HORIZONTAL_ELLIPSIS " and not Selected", G_CALLBACK(apply_as_and_not_selected_cb) },
+ { "/Apply as Filter/" UTF8_HORIZONTAL_ELLIPSIS " or not Selected", NULL, UTF8_HORIZONTAL_ELLIPSIS " or not Selected", NULL, UTF8_HORIZONTAL_ELLIPSIS " or not Selected", G_CALLBACK(apply_as_or_not_selected_cb) },
+ { "/Prepare a Filter/Selected", NULL, "Selected", NULL, "selcted", G_CALLBACK(prep_as_selected_cb) },
+ { "/Prepare a Filter/" UTF8_HORIZONTAL_ELLIPSIS " not Selected", NULL, UTF8_HORIZONTAL_ELLIPSIS " not Selected", NULL, UTF8_HORIZONTAL_ELLIPSIS " not Selected", G_CALLBACK(prep_as_not_selected_cb) },
+ { "/Prepare a Filter/" UTF8_HORIZONTAL_ELLIPSIS " and Selected", NULL, UTF8_HORIZONTAL_ELLIPSIS " and Selected", NULL, UTF8_HORIZONTAL_ELLIPSIS " and Selected", G_CALLBACK(prep_as_and_selected_cb) },
+ { "/Prepare a Filter/" UTF8_HORIZONTAL_ELLIPSIS " or Selected", NULL, UTF8_HORIZONTAL_ELLIPSIS " or Selected", NULL, UTF8_HORIZONTAL_ELLIPSIS " or Selected", G_CALLBACK(prep_as_or_selected_cb) },
+ { "/Prepare a Filter/" UTF8_HORIZONTAL_ELLIPSIS " and not Selected", NULL, UTF8_HORIZONTAL_ELLIPSIS " and not Selected", NULL, UTF8_HORIZONTAL_ELLIPSIS " and not Selected", G_CALLBACK(prep_as_and_not_selected_cb) },
+ { "/Prepare a Filter/" UTF8_HORIZONTAL_ELLIPSIS " or not Selected", NULL, UTF8_HORIZONTAL_ELLIPSIS " or not Selected", NULL, UTF8_HORIZONTAL_ELLIPSIS " or not Selected", G_CALLBACK(prep_as_or_not_selected_cb) },
+ { "/Find Frame/Selected", NULL, "Selected", NULL, "Selected", G_CALLBACK(find_selected_cb) },
+ { "/Find Frame/Not Selected", NULL, "Not Selected", NULL, "Not Selected", G_CALLBACK(find_not_selected_cb) },
+ { "/Find Previous/Selected", NULL, "Selected", NULL, "Selected", G_CALLBACK(find_prev_selected_cb) },
+ { "/Find Previous/Not Selected", NULL, "Not Selected", NULL, "Not Selected", G_CALLBACK(find_prev_not_selected_cb) },
+ { "/Find Next/Selected", NULL, "Selected", NULL, "Selected", G_CALLBACK(find_next_selected_cb) },
+ { "/Find Next/Not Selected", NULL, "Not Selected", NULL, "Not Selected", G_CALLBACK(find_next_not_selected_cb) },
+ { "/Colorize Procedure/Selected", NULL, "Selected", NULL, "Selected", G_CALLBACK(color_selected_cb) },
+ { "/Colorize Procedure/Not Selected", NULL, "Not Selected", NULL, "Not Selected", G_CALLBACK(color_not_selected_cb) },
};
static void
srt_create_popup_menu(srt_stat_table *rst)
{
- GtkItemFactory *item_factory;
+ GtkUIManager *ui_manager;
+ GtkActionGroup *action_group;
+ GError *error = NULL;
+
+ action_group = gtk_action_group_new ("ServiceRespTFilterPopupActionGroup");
+ gtk_action_group_add_actions (action_group, /* the action group */
+ service_resp_t__popup_entries, /* an array of action descriptions */
+ G_N_ELEMENTS(service_resp_t__popup_entries), /* the number of entries */
+ rst); /* data to pass to the action callbacks */
+
+ ui_manager = gtk_ui_manager_new ();
+ gtk_ui_manager_insert_action_group (ui_manager,
+ action_group,
+ 0); /* the position at which the group will be inserted */
+ gtk_ui_manager_add_ui_from_string (ui_manager,ui_desc_service_resp_t_filter_popup, -1, &error);
+ if (error != NULL)
+ {
+ fprintf (stderr, "Warning: building service response time filter popup failed: %s\n",
+ error->message);
+ g_error_free (error);
+ error = NULL;
+ }
+ rst->menu = gtk_ui_manager_get_widget(ui_manager, "/ServiceRespTFilterPopup");
+ g_signal_connect(rst->table, "button_press_event", G_CALLBACK(srt_show_popup_menu_cb), rst);
- item_factory = gtk_item_factory_new(GTK_TYPE_MENU, "<main>", NULL);
+}
- gtk_item_factory_create_items_ac(item_factory, sizeof(srt_list_menu_items)/sizeof(srt_list_menu_items[0]), srt_list_menu_items, rst, 2);
+/* ---------------- */
+static void
+srt_time_func (GtkTreeViewColumn *column _U_,
+ GtkCellRenderer *renderer,
+ GtkTreeModel *model,
+ GtkTreeIter *iter,
+ gpointer user_data)
+{
+ gchar *str;
+ nstime_t *data;
+
+ /* The col to get data from is in userdata */
+ gint data_column = GPOINTER_TO_INT(user_data);
+
+ gtk_tree_model_get(model, iter, data_column, &data, -1);
+ if (!data) {
+ g_object_set(renderer, "text", "", NULL);
+ return;
+ }
+ str = g_strdup_printf("%3d.%06d", (int)data->secs, (data->nsecs+500)/1000);
+ g_object_set(renderer, "text", str, NULL);
+ g_free(str);
+}
+
+static void
+srt_avg_func (GtkTreeViewColumn *column _U_,
+ GtkCellRenderer *renderer,
+ GtkTreeModel *model,
+ GtkTreeIter *iter,
+ gpointer user_data)
+{
+ gchar *str;
+ guint64 td;
+ gint data_column = GPOINTER_TO_INT(user_data);
- rst->menu = gtk_item_factory_get_widget(item_factory, "<main>");
- SIGNAL_CONNECT(rst->table, "button_press_event", srt_show_popup_menu_cb, rst);
+ gtk_tree_model_get(model, iter, data_column, &td, -1);
+ str=g_strdup_printf("%3d.%06d",
+ (int)(td/1000000), (int)(td%1000000));
+ g_object_set(renderer, "text", str, NULL);
+ g_free(str);
}
+static gint
+srt_time_sort_func(GtkTreeModel *model,
+ GtkTreeIter *a,
+ GtkTreeIter *b,
+ gpointer user_data)
+{
+ nstime_t *ns_a;
+ nstime_t *ns_b;
+ gint ret = 0;
+ gint data_column = GPOINTER_TO_INT(user_data);
+
+ gtk_tree_model_get(model, a, data_column, &ns_a, -1);
+ gtk_tree_model_get(model, b, data_column, &ns_b, -1);
+
+ if (ns_a == ns_b) {
+ ret = 0;
+ }
+ else if (ns_a == NULL || ns_b == NULL) {
+ ret = (ns_a == NULL) ? -1 : 1;
+ }
+ else {
+ ret = nstime_cmp(ns_a,ns_b);
+ }
+ return ret;
+}
+/*
+ XXX Resizable columns are ugly when there's more than on table cf. SMB
+*/
void
init_srt_table(srt_stat_table *rst, int num_procs, GtkWidget *vbox, const char *filter_string)
{
- int i, j;
- column_arrows *col_arrows;
- GdkBitmap *ascend_bm, *descend_bm;
- GdkPixmap *ascend_pm, *descend_pm;
- GtkStyle *win_style;
- GtkWidget *column_lb;
+ int i;
+ GtkListStore *store;
+ GtkWidget *tree;
+ GtkTreeViewColumn *column;
+ GtkCellRenderer *renderer;
+ GtkTreeSortable *sortable;
+ GtkTreeSelection *sel;
+
const char *default_titles[] = { "Index", "Procedure", "Calls", "Min SRT", "Max SRT", "Avg SRT" };
+ /* Create the store */
+ store = gtk_list_store_new (N_COLUMNS, /* Total number of columns */
+ G_TYPE_INT, /* Index */
+ G_TYPE_STRING, /* Procedure */
+ G_TYPE_UINT, /* Calls */
+ G_TYPE_POINTER, /* Min SRT */
+ G_TYPE_POINTER, /* Max SRT */
+ G_TYPE_UINT64); /* Avg SRT */
+
+ /* Create a view */
+ tree = gtk_tree_view_new_with_model (GTK_TREE_MODEL (store));
+ rst->table = GTK_TREE_VIEW(tree);
+ sortable = GTK_TREE_SORTABLE(store);
+
+ /* The view now holds a reference. We can get rid of our own reference */
+ g_object_unref (G_OBJECT (store));
if(filter_string){
rst->filter_string=g_strdup(filter_string);
} else {
rst->filter_string=NULL;
}
- rst->scrolled_window=scrolled_window_new(NULL, NULL);
- gtk_box_pack_start(GTK_BOX(vbox), rst->scrolled_window, TRUE, TRUE, 0);
-
- rst->table=(GtkCList *)gtk_clist_new(6);
-
- gtk_widget_show(GTK_WIDGET(rst->table));
- gtk_widget_show(rst->scrolled_window);
+ for (i = 0; i < N_COLUMNS; i++) {
+ renderer = gtk_cell_renderer_text_new ();
+ if (i != PROCEDURE_COLUMN) {
+ /* right align numbers */
+ g_object_set(G_OBJECT(renderer), "xalign", 1.0, NULL);
+ }
+ g_object_set(renderer, "ypad", 0, NULL);
+ switch (i) {
+ case MIN_SRT_COLUMN:
+ case MAX_SRT_COLUMN:
+ column = gtk_tree_view_column_new_with_attributes (default_titles[i], renderer, NULL);
+ gtk_tree_view_column_set_cell_data_func(column, renderer, srt_time_func, GINT_TO_POINTER(i), NULL);
+ gtk_tree_sortable_set_sort_func(sortable, i, srt_time_sort_func, GINT_TO_POINTER(i), NULL);
+ break;
+ case AVG_SRT_COLUMN:
+ column = gtk_tree_view_column_new_with_attributes (default_titles[i], renderer, NULL);
+ gtk_tree_view_column_set_cell_data_func(column, renderer, srt_avg_func, GINT_TO_POINTER(i), NULL);
+ break;
+ default:
+ column = gtk_tree_view_column_new_with_attributes (default_titles[i], renderer, "text",
+ i, NULL);
+ break;
+ }
- col_arrows = (column_arrows *) g_malloc(sizeof(column_arrows) * 6);
- win_style = gtk_widget_get_style(rst->scrolled_window);
- ascend_pm = gdk_pixmap_create_from_xpm_d(rst->scrolled_window->window,
- &ascend_bm,
- &win_style->bg[GTK_STATE_NORMAL],
- (gchar **)clist_ascend_xpm);
- descend_pm = gdk_pixmap_create_from_xpm_d(rst->scrolled_window->window,
- &descend_bm,
- &win_style->bg[GTK_STATE_NORMAL],
- (gchar **)clist_descend_xpm);
- for (i = 0; i < 6; i++) {
- col_arrows[i].table = gtk_table_new(2, 2, FALSE);
- gtk_table_set_col_spacings(GTK_TABLE(col_arrows[i].table), 5);
- column_lb = gtk_label_new(default_titles[i]);
- gtk_table_attach(GTK_TABLE(col_arrows[i].table), column_lb, 0, 1, 0, 2, GTK_SHRINK, GTK_SHRINK, 0, 0);
- gtk_widget_show(column_lb);
-
- col_arrows[i].ascend_pm = gtk_pixmap_new(ascend_pm, ascend_bm);
- gtk_table_attach(GTK_TABLE(col_arrows[i].table), col_arrows[i].ascend_pm, 1, 2, 1, 2, GTK_SHRINK, GTK_SHRINK, 0, 0);
- col_arrows[i].descend_pm = gtk_pixmap_new(descend_pm, descend_bm);
- gtk_table_attach(GTK_TABLE(col_arrows[i].table), col_arrows[i].descend_pm, 1, 2, 0, 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
- if (i == 2) {
- gtk_widget_show(col_arrows[i].descend_pm);
+ gtk_tree_view_column_set_sort_column_id(column, i);
+ gtk_tree_view_column_set_resizable(column, TRUE);
+ gtk_tree_view_append_column (rst->table, column);
+ if (i == CALLS_COLUMN) {
+ /* XXX revert order sort */
+ gtk_tree_view_column_clicked(column);
+ gtk_tree_view_column_clicked(column);
}
- gtk_clist_set_column_widget(GTK_CLIST(rst->table), i, col_arrows[i].table);
- gtk_widget_show(col_arrows[i].table);
}
- gtk_clist_column_titles_show(GTK_CLIST(rst->table));
-
- gtk_clist_set_compare_func(rst->table, srt_sort_column);
- gtk_clist_set_sort_column(rst->table, 2);
- gtk_clist_set_sort_type(rst->table, GTK_SORT_DESCENDING);
-
- /*XXX instead of this we should probably have some code to
- dynamically adjust the width of the columns */
- gtk_clist_set_column_width(rst->table, 0, 32);
- gtk_clist_set_column_width(rst->table, 1, 160);
- gtk_clist_set_column_width(rst->table, 2, 50);
- gtk_clist_set_column_width(rst->table, 3, 60);
- gtk_clist_set_column_width(rst->table, 4, 60);
- gtk_clist_set_column_width(rst->table, 5, 60);
-
- gtk_clist_set_shadow_type(rst->table, GTK_SHADOW_IN);
- gtk_clist_column_titles_show(rst->table);
- gtk_container_add(GTK_CONTAINER(rst->scrolled_window), (GtkWidget *)rst->table);
+ rst->scrolled_window=scrolled_window_new(NULL, NULL);
+ gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(rst->scrolled_window),
+ GTK_SHADOW_IN);
+ gtk_container_add(GTK_CONTAINER(rst->scrolled_window), GTK_WIDGET (rst->table));
+ gtk_box_pack_start(GTK_BOX(vbox), rst->scrolled_window, TRUE, TRUE, 0);
- SIGNAL_CONNECT(rst->table, "click-column", srt_click_column_cb, col_arrows);
+ gtk_tree_view_set_reorderable (rst->table, FALSE);
+ /* Now enable the sorting of each column */
+ gtk_tree_view_set_rules_hint(rst->table, TRUE);
+ gtk_tree_view_set_headers_clickable(rst->table, TRUE);
- gtk_widget_show(GTK_WIDGET(rst->table));
gtk_widget_show(rst->scrolled_window);
-
rst->num_procs=num_procs;
rst->procedures=g_malloc(sizeof(srt_procedure_t)*num_procs);
for(i=0;i<num_procs;i++){
- rst->procedures[i].num=0;
- rst->procedures[i].min.secs=0;
- rst->procedures[i].min.nsecs=0;
- rst->procedures[i].max.secs=0;
- rst->procedures[i].max.nsecs=0;
- rst->procedures[i].tot.secs=0;
- rst->procedures[i].tot.nsecs=0;
- for(j=0;j<6;j++){
- rst->procedures[i].entries[j]=NULL;
- }
+ time_stat_init(&rst->procedures[i].stats);
+ rst->procedures[i].index = 0;
+ rst->procedures[i].procedure = NULL;
}
+ sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(rst->table));
+ gtk_tree_selection_set_mode(sel, GTK_SELECTION_SINGLE);
/* create popup menu for this table */
if(rst->filter_string){
srt_create_popup_menu(rst);
void
init_srt_table_row(srt_stat_table *rst, int index, const char *procedure)
{
- char str[10];
-
/* we have discovered a new procedure. Extend the table accordingly */
if(index>=rst->num_procs){
int old_num_procs=rst->num_procs;
- int i,j;
+ int i;
+
rst->num_procs=index+1;
rst->procedures=g_realloc(rst->procedures, sizeof(srt_procedure_t)*(rst->num_procs));
for(i=old_num_procs;i<rst->num_procs;i++){
- rst->procedures[i].num=0;
- rst->procedures[i].min.secs=0;
- rst->procedures[i].min.nsecs=0;
- rst->procedures[i].max.secs=0;
- rst->procedures[i].max.nsecs=0;
- rst->procedures[i].tot.secs=0;
- rst->procedures[i].tot.nsecs=0;
- for(j=0;j<6;j++){
- rst->procedures[i].entries[j]=NULL;
- }
+ time_stat_init(&rst->procedures[i].stats);
+ rst->procedures[i].index = i;
+ rst->procedures[i].procedure=NULL;
}
}
- g_snprintf(str, 10, "%d",index);
- rst->procedures[index].entries[0]=g_strdup(str);
-
- rst->procedures[index].entries[1]=g_strdup(procedure);
-
- rst->procedures[index].entries[2]=g_strdup("0");
- rst->procedures[index].entries[3]=g_strdup("0");
- rst->procedures[index].entries[4]=g_strdup("0");
- rst->procedures[index].entries[5]=g_strdup("0");
-
- gtk_clist_insert(rst->table, index, rst->procedures[index].entries);
- gtk_clist_set_row_data(rst->table, index, (gpointer) index);
+ rst->procedures[index].index = index;
+ rst->procedures[index].procedure=g_strdup(procedure);
}
void
add_srt_table_data(srt_stat_table *rst, int index, const nstime_t *req_time, packet_info *pinfo)
{
srt_procedure_t *rp;
- nstime_t delta;
+ nstime_t t, delta;
+ g_assert(index >= 0 && index < rst->num_procs);
rp=&rst->procedures[index];
- /* calculate time delta between request and reply */
- delta.secs=pinfo->fd->abs_secs-req_time->secs;
- delta.nsecs=pinfo->fd->abs_usecs*1000-req_time->nsecs;
- if(delta.nsecs<0){
- delta.nsecs+=1000000000;
- delta.secs--;
- }
-
- if(rp->num==0){
- rp->max.secs=delta.secs;
- rp->max.nsecs=delta.nsecs;
- }
-
- if(rp->num==0){
- rp->min.secs=delta.secs;
- rp->min.nsecs=delta.nsecs;
- }
-
- if( (delta.secs<rp->min.secs)
- ||( (delta.secs==rp->min.secs)
- &&(delta.nsecs<rp->min.nsecs) ) ){
- rp->min.secs=delta.secs;
- rp->min.nsecs=delta.nsecs;
+ /*
+ * If the count of calls for this procedure is currently zero, it's
+ * going to become non-zero, so add a row for it (we don't want
+ * rows for procedures that have no calls - especially if the
+ * procedure has no calls because the index doesn't correspond
+ * to a procedure, but is an unused/reserved value).
+ *
+ * (Yes, this means that the rows aren't in order by anything
+ * interesting. That's why we have the table sorted by a column.)
+ */
+
+ if (rp->stats.num==0){
+ GtkListStore *store = GTK_LIST_STORE(gtk_tree_view_get_model(rst->table));
+ gtk_list_store_append(store, &rp->iter);
+ gtk_list_store_set(store, &rp->iter,
+ INDEX_COLUMN, rp->index,
+ PROCEDURE_COLUMN, rp->procedure,
+ CALLS_COLUMN, rp->stats.num,
+ MIN_SRT_COLUMN, NULL,
+ MAX_SRT_COLUMN, NULL,
+ AVG_SRT_COLUMN, (guint64)0,
+ -1);
}
- if( (delta.secs>rp->max.secs)
- ||( (delta.secs==rp->max.secs)
- &&(delta.nsecs>rp->max.nsecs) ) ){
- rp->max.secs=delta.secs;
- rp->max.nsecs=delta.nsecs;
- }
-
- rp->tot.secs += delta.secs;
- rp->tot.nsecs += delta.nsecs;
- if(rp->tot.nsecs>1000000000){
- rp->tot.nsecs-=1000000000;
- rp->tot.secs++;
- }
+ /* calculate time delta between request and reply */
+ t=pinfo->fd->abs_ts;
+ nstime_delta(&delta, &t, req_time);
- rp->num++;
+ time_stat_update(&rp->stats, &delta, pinfo);
}
void
draw_srt_table_data(srt_stat_table *rst)
{
- int i,j;
-#ifdef G_HAVE_UINT64
+ int i;
guint64 td;
-#else
- guint32 td;
-#endif
- char str[256], *strp;
+ GtkListStore *store = GTK_LIST_STORE(gtk_tree_view_get_model(rst->table));
for(i=0;i<rst->num_procs;i++){
- /* scale it to units of 10us.*/
- /* for long captures with a large tot time, this can overflow on 32bit */
- td=(int)rst->procedures[i].tot.secs;
- td=td*100000+(int)rst->procedures[i].tot.nsecs/10000;
- if(rst->procedures[i].num){
- td/=rst->procedures[i].num;
- } else {
- td=0;
+ /* ignore procedures with no calls (they don't have rows) */
+ if(rst->procedures[i].stats.num==0){
+ continue;
}
-
- j=gtk_clist_find_row_from_data(rst->table, (gpointer)i);
- g_snprintf(str, 256, "%d", rst->procedures[i].num);
- strp=g_strdup(str);
- gtk_clist_set_text(rst->table, j, 2, strp);
- g_free(rst->procedures[i].entries[2]);
- rst->procedures[i].entries[2]=strp;
-
-
- g_snprintf(str, 256, "%3d.%05d", (int)rst->procedures[i].min.secs,rst->procedures[i].min.nsecs/10000);
- strp=g_strdup(str);
- gtk_clist_set_text(rst->table, j, 3, strp);
- g_free(rst->procedures[i].entries[3]);
- rst->procedures[i].entries[3]=strp;
-
-
- g_snprintf(str, 256, "%3d.%05d", (int)rst->procedures[i].max.secs,rst->procedures[i].max.nsecs/10000);
- strp=g_strdup(str);
- gtk_clist_set_text(rst->table, j, 4, strp);
- g_free(rst->procedures[i].entries[4]);
- rst->procedures[i].entries[4]=strp;
-
- g_snprintf(str, 256, "%3d.%05d", td/100000, td%100000);
- strp=g_strdup(str);
- gtk_clist_set_text(rst->table, j, 5, strp);
- g_free(rst->procedures[i].entries[5]);
- rst->procedures[i].entries[5]=strp;
+ /* Scale the average SRT in units of 1us and round to the nearest us.
+ tot.secs is a time_t which may be 32 or 64 bits (or even floating)
+ depending uon the platform. After casting tot.secs to 64 bits, it
+ would take a capture with a duration of over 136 *years* to
+ overflow the secs portion of td. */
+ td = ((guint64)(rst->procedures[i].stats.tot.secs))*NANOSECS_PER_SEC + rst->procedures[i].stats.tot.nsecs;
+ td = ((td / rst->procedures[i].stats.num) + 500) / 1000;
+
+ gtk_list_store_set(store, &rst->procedures[i].iter,
+ CALLS_COLUMN, rst->procedures[i].stats.num,
+ MIN_SRT_COLUMN, &rst->procedures[i].stats.min,
+ MAX_SRT_COLUMN, &rst->procedures[i].stats.max,
+ AVG_SRT_COLUMN, td,
+ -1);
}
-
- gtk_clist_sort(rst->table);
}
reset_srt_table_data(srt_stat_table *rst)
{
int i;
+ GtkListStore *store;
for(i=0;i<rst->num_procs;i++){
- rst->procedures[i].num=0;
- rst->procedures[i].min.secs=0;
- rst->procedures[i].min.nsecs=0;
- rst->procedures[i].max.secs=0;
- rst->procedures[i].max.nsecs=0;
- rst->procedures[i].tot.secs=0;
- rst->procedures[i].tot.nsecs=0;
+ time_stat_init(&rst->procedures[i].stats);
}
+ store = GTK_LIST_STORE(gtk_tree_view_get_model(rst->table));
+ gtk_list_store_clear(store);
}
void
free_srt_table_data(srt_stat_table *rst)
{
- int i,j;
+ int i;
for(i=0;i<rst->num_procs;i++){
- for(j=0;j<6;j++){
- if(rst->procedures[i].entries[j]){
- g_free(rst->procedures[i].entries[j]);
- rst->procedures[i].entries[j]=NULL;
- }
- }
+ g_free(rst->procedures[i].procedure);
+ rst->procedures[i].procedure=NULL;
}
g_free(rst->filter_string);
rst->filter_string=NULL;