stat_tap_table_ui: create tables only once during init

If you load a capture file and open any statistics dialog, you'll see the
list of collected items. Each time you press the Apply button (without entering a
display filter) another list of items will be created as a top-level entry
of the statistics tree. Only the first list will have the correct values,
all subsequent lists will not be populated.

Each statistic module defines a stat_tap_table_ui structure that contains a
stat_tap_init_cb function. This init function is called by
SimpleStatisticsDialog::fillTree before the tap listener is registered. This
happens each time we collect the statistics.

However, it seems that all init functions create a new stat_tap_table each
time they are called, even if they already have an existing stat_tap_table
of the same name.

This patch adds a stat_tap_find_table function to find a table by name.

As a first step, we update the ANSI A-I/F BSMAP Statistics to check if its
table is already registered. If it is, the table will not be created again.
This commit is contained in:
Martin Kaiser 2020-12-15 17:20:48 +01:00 committed by AndersBroman
parent 9fc1ce7610
commit f4ac70818a
4 changed files with 28 additions and 4 deletions

View File

@ -1519,6 +1519,7 @@ libwireshark.so.0 libwireshark0 #MINVER#
stat_node_array_sortcmp@Base 1.12.0~rc1
stat_tap_add_table@Base 2.5.1
stat_tap_by_name@Base 2.5.1
stat_tap_find_table@Base 3.5.0
stat_tap_get_field_data@Base 2.5.1
stat_tap_get_filter@Base 2.5.1
stat_tap_init_table@Base 2.5.1

View File

@ -10643,14 +10643,19 @@ static stat_tap_table_item bsmap_stat_fields[] = {{TABLE_ITEM_UINT, TAP_ALIGN_RI
static void ansi_a_bsmap_stat_init(stat_tap_table_ui* new_stat)
{
const char *table_name = "ANSI A-I/F BSMAP Statistics";
int num_fields = sizeof(bsmap_stat_fields)/sizeof(stat_tap_table_item);
stat_tap_table* table = stat_tap_init_table("ANSI A-I/F BSMAP Statistics", num_fields, 0, NULL);
stat_tap_table *table;
int i = 0;
stat_tap_table_item_type items[sizeof(bsmap_stat_fields)/sizeof(stat_tap_table_item)];
stat_tap_add_table(new_stat, table);
table = stat_tap_find_table(new_stat, table_name);
if (!table) {
table = stat_tap_init_table(table_name, num_fields, 0, NULL);
stat_tap_add_table(new_stat, table);
}
/* Add a fow for each value type */
/* Add a row for each value type */
while (ansi_a_bsmap_strings[i].strptr)
{
items[IEI_COLUMN].type = TABLE_ITEM_UINT;

View File

@ -192,6 +192,24 @@ stat_tap_table* stat_tap_init_table(const char *name, int num_fields, int num_el
return new_table;
}
stat_tap_table *stat_tap_find_table(stat_tap_table_ui *ui, const char *name)
{
guint i = 0;
stat_tap_table *stat_table;
if (ui->tables == NULL)
return NULL;
for (i = 0; i < ui->tables->len; i++) {
stat_table = g_array_index(ui->tables, stat_tap_table *, i);
if (!g_strcmp0(stat_table->title, name)) {
return stat_table;
}
}
return NULL;
}
void stat_tap_add_table(stat_tap_table_ui* new_stat, stat_tap_table* table)
{
if (new_stat->tables == NULL)

View File

@ -159,7 +159,7 @@ WS_DLL_PUBLIC void stat_tap_get_filter(stat_tap_table_ui* new_stat, const char *
WS_DLL_PUBLIC stat_tap_table* stat_tap_init_table(const char *name, int num_fields, int num_elements,
const char *filter_string);
WS_DLL_PUBLIC void stat_tap_add_table(stat_tap_table_ui* new_stat, stat_tap_table* table);
WS_DLL_PUBLIC stat_tap_table *stat_tap_find_table(stat_tap_table_ui *ui, const char *name);
WS_DLL_PUBLIC void stat_tap_init_table_row(stat_tap_table *stat_table, guint table_index, guint num_fields, const stat_tap_table_item_type* fields);
WS_DLL_PUBLIC stat_tap_table_item_type* stat_tap_get_field_data(const stat_tap_table *stat_table, guint table_index, guint field_index);
WS_DLL_PUBLIC void stat_tap_set_field_data(stat_tap_table *stat_table, guint table_index, guint field_index, stat_tap_table_item_type* field_data);