diff options
author | Martin Kaiser <wireshark@kaiser.cx> | 2020-12-15 17:20:48 +0100 |
---|---|---|
committer | AndersBroman <a.broman58@gmail.com> | 2021-01-28 13:41:08 +0000 |
commit | f4ac70818a145c9c6d9fccb3979f16d9c0c5b67a (patch) | |
tree | 0048acf82fbeec6a4e6eec37dbe94f67b2a54834 /epan | |
parent | 9fc1ce761020651ee3d296ffc1ee867afb9bdfa6 (diff) |
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.
Diffstat (limited to 'epan')
-rw-r--r-- | epan/dissectors/packet-ansi_a.c | 11 | ||||
-rw-r--r-- | epan/stat_tap_ui.c | 18 | ||||
-rw-r--r-- | epan/stat_tap_ui.h | 2 |
3 files changed, 27 insertions, 4 deletions
diff --git a/epan/dissectors/packet-ansi_a.c b/epan/dissectors/packet-ansi_a.c index dc00d680a5..3c83211b33 100644 --- a/epan/dissectors/packet-ansi_a.c +++ b/epan/dissectors/packet-ansi_a.c @@ -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; diff --git a/epan/stat_tap_ui.c b/epan/stat_tap_ui.c index f9e5100621..10400633e4 100644 --- a/epan/stat_tap_ui.c +++ b/epan/stat_tap_ui.c @@ -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) diff --git a/epan/stat_tap_ui.h b/epan/stat_tap_ui.h index 50391768b6..ef5425260c 100644 --- a/epan/stat_tap_ui.h +++ b/epan/stat_tap_ui.h @@ -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); |