aboutsummaryrefslogtreecommitdiffstats
path: root/epan/stat_tap_ui.c
diff options
context:
space:
mode:
authorMichael Mann <mmann78@netscape.net>2015-06-23 08:53:17 -0400
committerMichael Mann <mmann78@netscape.net>2015-07-03 23:08:28 +0000
commita8ff1e2778b22ca55db752264eaf864d720ca8dc (patch)
tree1b7182449a95437aa6a0419519c92fcc08ca3aa0 /epan/stat_tap_ui.c
parent09ea473cee9ef37335f2ef8247da94bc71d12bba (diff)
Create very basic "generic" stat tap API to create a "GUI" independent table.
A few sample tap/dissectors (ANSI/A, ANSI MAP) are also included to test the API. The "GUI output" is a bit raw and could use some "prettying up", but all the basic hooks are there. Telephony "stat grouping" needs to be better alphabetized to properly populate menu (on GTK, probably Qt) Change-Id: I98514171f69c4ab3a304dccb26c71d629703c9ab Reviewed-on: https://code.wireshark.org/review/9110 Reviewed-by: Michael Mann <mmann78@netscape.net>
Diffstat (limited to 'epan/stat_tap_ui.c')
-rw-r--r--epan/stat_tap_ui.c155
1 files changed, 155 insertions, 0 deletions
diff --git a/epan/stat_tap_ui.c b/epan/stat_tap_ui.c
index b963e2398d..61f909f5c7 100644
--- a/epan/stat_tap_ui.c
+++ b/epan/stat_tap_ui.c
@@ -128,6 +128,161 @@ start_requested_stats(void)
}
}
+static GSList *registered_stat_tables = NULL;
+
+static gint
+insert_sorted_by_cli_string(gconstpointer aparam, gconstpointer bparam)
+{
+ const new_stat_tap_ui *a = (new_stat_tap_ui *)aparam;
+ const new_stat_tap_ui *b = (new_stat_tap_ui *)bparam;
+
+ return g_ascii_strcasecmp(a->cli_string, b->cli_string);
+}
+
+void register_new_stat_tap_ui(new_stat_tap_ui *ui)
+{
+ registered_stat_tables = g_slist_insert_sorted(registered_stat_tables, ui, insert_sorted_by_cli_string);
+}
+
+void new_stat_tap_iterate_tables(GFunc func, gpointer user_data)
+{
+ g_slist_foreach(registered_stat_tables, func, user_data);
+}
+
+void new_stat_tap_get_filter(new_stat_tap_ui* new_stat, const char *opt_arg, const char **filter, char** err)
+{
+ guint len = (guint) strlen(new_stat->cli_string);
+ *filter=NULL;
+ *err=NULL;
+
+ if (!strncmp(opt_arg, new_stat->cli_string, len))
+ {
+ if (opt_arg[len] == ',')
+ {
+ *filter = opt_arg + len+1;
+ }
+ }
+
+ if (new_stat->new_stat_filter_check_cb)
+ new_stat->new_stat_filter_check_cb(opt_arg, filter, err);
+}
+
+new_stat_tap_table* new_stat_tap_init_table(const char *name, int num_fields, int num_elements,
+ const char *filter_string, new_stat_tap_gui_init_cb gui_callback, void* gui_data)
+{
+ new_stat_tap_table* new_table = g_new0(new_stat_tap_table, 1);
+
+ new_table->title = name;
+ new_table->num_elements = num_elements;
+ new_table->num_fields = num_fields;
+ new_table->filter_string = filter_string;
+ new_table->elements = g_new0(stat_tap_table_item_type*, num_elements);
+
+ if (gui_callback)
+ gui_callback(new_table, gui_data);
+
+ return new_table;
+}
+
+void new_stat_tap_add_table(new_stat_tap_ui* new_stat, new_stat_tap_table* table)
+{
+ if (new_stat->tables == NULL)
+ new_stat->tables = g_array_new(FALSE, TRUE, sizeof(new_stat_tap_table*));
+
+ g_array_insert_val(new_stat->tables, new_stat->tables->len, table);
+}
+
+void new_stat_tap_init_table_row(new_stat_tap_table *stat_table, guint table_index, guint num_fields, stat_tap_table_item_type* fields)
+{
+ /* we have discovered a new procedure. Extend the table accordingly */
+ if(table_index>=stat_table->num_elements){
+ guint old_num_elements=stat_table->num_elements;
+ guint i;
+
+ stat_table->num_elements=table_index+1;
+ stat_table->elements = (stat_tap_table_item_type**)g_realloc(stat_table->elements, sizeof(stat_tap_table_item_type*)*(stat_table->num_elements));
+ for(i=old_num_elements;i<stat_table->num_elements;i++){
+ stat_table->elements[i] = g_new0(stat_tap_table_item_type, stat_table->num_fields);
+ }
+ }
+ memcpy(stat_table->elements[table_index], fields, num_fields*sizeof(stat_tap_table_item_type));
+
+}
+
+stat_tap_table_item_type* new_stat_tap_get_field_data(new_stat_tap_table *stat_table, guint table_index, guint field_index)
+{
+ stat_tap_table_item_type* field_value;
+ g_assert(table_index < stat_table->num_elements);
+
+ field_value = stat_table->elements[table_index];
+
+ g_assert(field_index < stat_table->num_fields);
+
+ return &field_value[field_index];
+}
+
+void new_stat_tap_set_field_data(new_stat_tap_table *stat_table, guint table_index, guint field_index, stat_tap_table_item_type* field_data)
+{
+ stat_tap_table_item_type* field_value;
+ g_assert(table_index < stat_table->num_elements);
+
+ field_value = stat_table->elements[table_index];
+
+ g_assert(field_index < stat_table->num_fields);
+
+ field_value[field_index] = *field_data;
+}
+
+void reset_stat_table(new_stat_tap_ui* new_stat, new_stat_tap_gui_reset_cb gui_callback, void *callback_data)
+{
+ guint i = 0;
+ new_stat_tap_table *stat_table;
+
+ for (i = 0; i < new_stat->tables->len; i++)
+ {
+ stat_table = g_array_index(new_stat->tables, new_stat_tap_table*, i);
+
+ /* Give GUI the first crack at it before we clean up */
+ if (gui_callback)
+ gui_callback(stat_table, callback_data);
+
+ if (new_stat->stat_tap_reset_table_cb)
+ new_stat->stat_tap_reset_table_cb(stat_table);
+ }
+}
+
+void free_stat_table(new_stat_tap_ui* new_stat, new_stat_tap_gui_free_cb gui_callback, void *callback_data)
+{
+ guint i = 0, element, field_index;
+ new_stat_tap_table *stat_table;
+ stat_tap_table_item_type* field_data;
+
+ for (i = 0; i < new_stat->tables->len; i++)
+ {
+ stat_table = g_array_index(new_stat->tables, new_stat_tap_table*, i);
+
+ /* Give GUI the first crack at it before we clean up */
+ if (gui_callback)
+ gui_callback(stat_table, callback_data);
+
+ for (element = 0; element < stat_table->num_elements; element++)
+ {
+ for (field_index = 0; field_index < stat_table->num_fields; field_index++)
+ {
+ field_data = new_stat_tap_get_field_data(stat_table, element, field_index);
+ /* Give dissector a crack at it */
+ if (new_stat->stat_tap_free_table_item_cb)
+ new_stat->stat_tap_free_table_item_cb(stat_table, element, field_index, field_data);
+ }
+
+ g_free(stat_table->elements[element]);
+ }
+
+ g_free(stat_table->elements);
+ }
+}
+
+
/*
* Editor modelines
*