qt: move free_stat_tables from SimpleStatisticsDialog::fillTree to ~SimpleStatisticsD...
[metze/wireshark/wip.git] / epan / stat_tap_ui.h
1 /* stat_tap_ui.h
2  * Declarations of routines to register UI information for stats
3  *
4  * Wireshark - Network traffic analyzer
5  * By Gerald Combs <gerald@wireshark.org>
6  * Copyright 1998 Gerald Combs
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21  */
22
23 #ifndef __STAT_TAP_UI_H__
24 #define __STAT_TAP_UI_H__
25
26 #include "ws_symbol_export.h"
27
28 #ifdef __cplusplus
29 extern "C" {
30 #endif /* __cplusplus */
31
32 /*
33  * Parameters for taps.
34  */
35
36 #include <epan/params.h>
37 #include <epan/stat_groups.h>
38 #include <epan/packet_info.h>
39 #include <epan/tap.h>
40
41 typedef enum {
42     PARAM_UINT,   /* Unused? */
43     PARAM_STRING, /* Unused? */
44     PARAM_ENUM,   /* SCSI SRT */
45     PARAM_UUID,   /* DCE-RPC. Unused? */
46     PARAM_FILTER
47 } param_type;
48
49 typedef struct _tap_param {
50     param_type        type;      /* type of parameter */
51     const char       *name;      /* name to use in error messages */
52     const char       *title;     /* title to use in GUI widgets */
53     const enum_val_t *enum_vals; /* values for PARAM_ENUM */
54     gboolean          optional;  /* TRUE if the parameter is optional */
55 } tap_param;
56
57 /*
58  * UI information for a tap.
59  */
60 typedef void (* stat_tap_init_cb)(const char *, void*);
61 typedef struct _stat_tap_ui {
62     register_stat_group_t  group;      /* group to which statistic belongs */
63     const char            *title;      /* title of statistic */
64     const char            *cli_string; /* initial part of the "-z" argument for statistic */
65     stat_tap_init_cb tap_init_cb;      /* callback to init function of the tap */
66     size_t                 nparams;    /* number of parameters */
67     tap_param             *params;     /* pointer to table of parameter info */
68 } stat_tap_ui;
69
70 typedef enum {
71     TABLE_ITEM_NONE = 0,
72     TABLE_ITEM_UINT,
73     TABLE_ITEM_INT,
74     TABLE_ITEM_STRING,
75     TABLE_ITEM_FLOAT,
76     TABLE_ITEM_ENUM
77 } stat_tap_table_item_enum;
78
79 typedef struct _stat_tap_table_item_type
80 {
81     stat_tap_table_item_enum type;
82     union
83     {
84         guint uint_value;
85         gint  int_value;
86         const char* string_value;
87         double float_value;
88         gint enum_value;
89     } value;
90     /* Scratch space for the dissector. Alternatively we could also add support
91      * for hidden columns. */
92     union
93     {
94         guint uint_value;
95         gint  int_value;
96         const char* string_value;
97         double float_value;
98         gint enum_value;
99         void* ptr_value;
100     } user_data;
101 } stat_tap_table_item_type;
102
103 /* Possible alignments */
104 typedef enum {
105     TAP_ALIGN_LEFT = 0,
106     TAP_ALIGN_RIGHT
107 } tap_alignment_type;
108
109 typedef struct _stat_tap_table_item
110 {
111     stat_tap_table_item_enum type;
112     tap_alignment_type align;
113     const char* column_name;
114     const char* field_format; /* printf style formating of field. Currently unused? */
115
116 } stat_tap_table_item;
117
118
119 /* Description of a UI table */
120 typedef struct _stat_tap_table
121 {
122     const char* title;
123     const char *filter_string;        /**< append procedure number (%d) to this string to create a display filter */
124     guint num_fields;
125     guint num_elements;
126     stat_tap_table_item_type **elements;
127
128 } stat_tap_table;
129
130 typedef void (*new_stat_tap_gui_init_cb)(stat_tap_table* stat_table, void* gui_data); /* GTK+ only? */
131 typedef void (*new_stat_tap_gui_reset_cb)(stat_tap_table* stat_table, void* gui_data); /* GTK+ only? */
132 typedef void (*new_stat_tap_gui_free_cb)(stat_tap_table* stat_table, void* gui_data); /* GTK+ only? */
133
134 /*
135  * UI information for a tap with a table-based UI.
136  */
137 typedef struct _stat_tap_table_ui {
138     register_stat_group_t  group;      /* group to which statistic belongs */
139     const char            *title;      /* title of statistic */
140     const char            *tap_name;
141     const char            *cli_string; /* initial part of the "-z" argument for statistic */
142     void (* stat_tap_init_cb)(struct _stat_tap_table_ui* new_stat, new_stat_tap_gui_init_cb gui_callback, void* gui_data);
143     tap_packet_cb packet_func;
144     void (* stat_tap_reset_table_cb)(stat_tap_table* table);
145     void (* stat_tap_free_table_item_cb)(stat_tap_table* table, guint row, guint column, stat_tap_table_item_type* field_data);
146     void (* stat_filter_check_cb)(const char *opt_arg, const char **filter, char** err); /* Dissector chance to reject filter */
147     size_t                 nfields;    /* number of fields */
148     stat_tap_table_item*   fields;
149     size_t                 nparams;    /* number of parameters */
150     tap_param             *params;     /* pointer to table of parameter info */
151     GArray                *tables;     /* An array of stat_tap_table* */
152     guint                  refcount;   /* a reference count for deallocation */
153 } stat_tap_table_ui;
154
155
156 /** tap data
157  */
158 typedef struct _new_stat_data_t {
159     stat_tap_table_ui *stat_tap_data;
160     void        *user_data;       /**< "GUI" specifics (if necessary) */
161 } new_stat_data_t;
162
163
164 /** Register UI information for a tap.
165  *
166  * @param ui UI information for the tap.
167  * @param userdata Additional data for the init routine.
168  */
169 WS_DLL_PUBLIC void register_stat_tap_ui(stat_tap_ui *ui, void *userdata);
170
171 WS_DLL_PUBLIC void register_stat_tap_table_ui(stat_tap_table_ui *ui);
172 WS_DLL_PUBLIC void new_stat_tap_iterate_tables(GFunc func, gpointer user_data);
173 WS_DLL_PUBLIC void new_stat_tap_get_filter(stat_tap_table_ui* new_stat, const char *opt_arg, const char **filter, char** err);
174 WS_DLL_PUBLIC stat_tap_table* new_stat_tap_init_table(const char *name, int num_fields, int num_elements,
175                 const char *filter_string, new_stat_tap_gui_init_cb gui_callback, void* gui_data);
176 WS_DLL_PUBLIC void new_stat_tap_add_table(stat_tap_table_ui* new_stat, stat_tap_table* table);
177
178 WS_DLL_PUBLIC void new_stat_tap_init_table_row(stat_tap_table *stat_table, guint table_index, guint num_fields, const stat_tap_table_item_type* fields);
179 WS_DLL_PUBLIC stat_tap_table_item_type* new_stat_tap_get_field_data(const stat_tap_table *stat_table, guint table_index, guint field_index);
180 WS_DLL_PUBLIC void new_stat_tap_set_field_data(stat_tap_table *stat_table, guint table_index, guint field_index, stat_tap_table_item_type* field_data);
181 WS_DLL_PUBLIC void reset_stat_table(stat_tap_table_ui* new_stat, new_stat_tap_gui_reset_cb gui_callback, void *callback_data);
182
183 /** Free all of the tables associated with a stat_tap_table_ui.
184  *
185  * Frees data created by stat_tap_ui.stat_tap_init_cb.
186  * stat_tap_table_ui.stat_tap_free_table_item_cb is called for each index in each
187  * row.
188  *
189  * @param new_stat Parent stat_tap_table_ui struct, provided by the dissector.
190  * @param gui_callback Per-table callback, run before rows are removed.
191  * Provided by the UI.
192  * @param callback_data Data for the per-table callback.
193  */
194 WS_DLL_PUBLIC void free_stat_tables(stat_tap_table_ui* new_stat, new_stat_tap_gui_free_cb gui_callback, void *callback_data);
195
196
197 WS_DLL_PUBLIC gboolean process_stat_cmd_arg(char *optstr);
198
199 WS_DLL_PUBLIC void list_stat_cmd_args(void);
200
201 WS_DLL_PUBLIC void start_requested_stats(void);
202
203 #ifdef __cplusplus
204 }
205 #endif /* __cplusplus */
206
207 #endif
208
209 /*
210  * Editor modelines
211  *
212  * Local Variables:
213  * c-basic-offset: 4
214  * tab-width: 8
215  * indent-tabs-mode: nil
216  * End:
217  *
218  * ex: set shiftwidth=4 tabstop=8 expandtab:
219  * :indentSize=4:tabSize=8:noTabs=true:
220  */