91ad3f0a |
1 | /* This file is part of the Linux Trace Toolkit viewer |
852f16bb |
2 | * Copyright (C) 2005 Simon Bouvier-Zappa |
91ad3f0a |
3 | * |
4 | * This program is free software; you can redistribute it and/or modify |
5 | * it under the terms of the GNU General Public License Version 2 as |
6 | * published by the Free Software Foundation; |
7 | * |
8 | * This program is distributed in the hope that it will be useful, |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 | * GNU General Public License for more details. |
12 | * |
13 | * You should have received a copy of the GNU General Public License |
14 | * along with this program; if not, write to the Free Software |
15 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, |
16 | * MA 02111-1307, USA. |
17 | */ |
18 | |
4e4d11b3 |
19 | #ifdef HAVE_CONFIG_H |
20 | #include <config.h> |
21 | #endif |
22 | |
91ad3f0a |
23 | #include <glib.h> |
24 | #include <string.h> |
25 | #include <gtk/gtk.h> |
26 | #include <gdk/gdk.h> |
27 | |
28 | #include <lttv/lttv.h> |
29 | #include <lttv/module.h> |
30 | #include <lttv/hook.h> |
31 | #include <lttv/filter.h> |
32 | |
33 | #include <lttvwindow/lttvwindow.h> |
34 | #include <lttvwindow/lttvwindowtraces.h> |
35 | |
36 | #include "hGuiFilterInsert.xpm" |
37 | |
0fc64e11 |
38 | |
39 | GSList *g_filter_list = NULL ; |
40 | |
7e7af7f2 |
41 | /*! \file lttv/modules/gui/filter/filter.c |
42 | * \brief Graphic filter interface. |
43 | * |
44 | * The gui filter facility gives the user an easy to use |
45 | * basic interface to construct and modify at will a filter |
46 | * expression. User may either decide to write it himself in |
47 | * expression text entry or add simple expressions using the |
48 | * many choices boxes. |
49 | * |
da2e1bfb |
50 | * \note The version of gtk-2.0 currently installed on |
7e7af7f2 |
51 | * my desktop misses some function of the newer |
da2e1bfb |
52 | * gtk+ api. For the time being, I'll use the older api |
7e7af7f2 |
53 | * to keep compatibility with most systems. |
2b715e58 |
54 | */ |
55 | |
91ad3f0a |
56 | typedef struct _FilterViewerData FilterViewerData; |
c2774e9d |
57 | typedef struct _FilterViewerDataLine FilterViewerDataLine; |
91ad3f0a |
58 | |
4ed9b7ba |
59 | /* |
60 | * Prototypes |
61 | */ |
91ad3f0a |
62 | GtkWidget *guifilter_get_widget(FilterViewerData *fvd); |
63 | FilterViewerData *gui_filter(Tab *tab); |
64 | void gui_filter_destructor(FilterViewerData *fvd); |
c2774e9d |
65 | FilterViewerDataLine* gui_filter_add_line(FilterViewerData *fvd); |
66 | void gui_filter_line_set_visible(FilterViewerDataLine *fvdl, gboolean v); |
67 | void gui_filter_line_reset(FilterViewerDataLine *fvdl); |
2b99ec10 |
68 | GtkWidget* h_guifilter(Tab *tab); |
c2774e9d |
69 | void filter_destroy_walk(gpointer data, gpointer user_data); |
91ad3f0a |
70 | |
c2774e9d |
71 | /* |
72 | * Callback functions |
73 | */ |
74 | void callback_process_button(GtkWidget *widget, gpointer data); |
75 | void callback_add_button(GtkWidget *widget, gpointer data); |
76 | void callback_logical_op_box(GtkWidget *widget, gpointer data); |
77 | void callback_expression_field(GtkWidget *widget, gpointer data); |
78 | |
852f16bb |
79 | /** |
80 | * @struct _FilterViewerDataLine |
81 | * |
82 | * @brief Defines a simple expression |
83 | * This structures defines a simple |
84 | * expression whithin the main filter |
85 | * viewer data |
86 | */ |
c2774e9d |
87 | struct _FilterViewerDataLine { |
7e7af7f2 |
88 | int row; /**< row number */ |
89 | gboolean visible; /**< visible state */ |
90 | GtkWidget *f_not_op_box; /**< '!' operator (GtkComboBox) */ |
91 | GtkWidget *f_logical_op_box; /**< '&,|,^' operators (GtkComboBox) */ |
92 | GtkWidget *f_field_box; /**< field types (GtkComboBox) */ |
93 | GtkWidget *f_math_op_box; /**< '>,>=,<,<=,=,!=' operators (GtkComboBox) */ |
94 | GtkWidget *f_value_field; /**< expression's value (GtkComboBox) */ |
c2774e9d |
95 | }; |
96 | |
97 | /** |
7e7af7f2 |
98 | * @struct _FilterViewerData |
99 | * |
100 | * @brief Main structure of gui filter |
101 | * Main struct for the filter gui module |
c2774e9d |
102 | */ |
91ad3f0a |
103 | struct _FilterViewerData { |
7e7af7f2 |
104 | Tab *tab; /**< current tab of module */ |
91ad3f0a |
105 | |
6a4f1205 |
106 | GtkWidget *f_window; /**< filter window */ |
107 | |
7e7af7f2 |
108 | GtkWidget *f_main_box; /**< main container */ |
4ed9b7ba |
109 | |
7e7af7f2 |
110 | GtkWidget *f_expression_field; /**< entire expression (GtkEntry) */ |
111 | GtkWidget *f_process_button; /**< process expression button (GtkButton) */ |
4ed9b7ba |
112 | |
7e7af7f2 |
113 | GtkWidget *f_logical_op_junction_box; /**< linking operator box (GtkComboBox) */ |
4ed9b7ba |
114 | |
7e7af7f2 |
115 | int rows; /**< number of rows */ |
116 | GPtrArray *f_lines; /**< array of FilterViewerDataLine */ |
2b715e58 |
117 | |
7e7af7f2 |
118 | GPtrArray *f_not_op_options; /**< array of operators types for not_op box */ |
119 | GPtrArray *f_logical_op_options; /**< array of operators types for logical_op box */ |
120 | GPtrArray *f_field_options; /**< array of field types for field box */ |
121 | GPtrArray *f_math_op_options; /**< array of operators types for math_op box */ |
2b715e58 |
122 | |
7e7af7f2 |
123 | GtkWidget *f_add_button; /**< add expression to current expression (GtkButton) */ |
6a4f1205 |
124 | |
125 | gchar *name; /**< Name of the window in the main window */ |
91ad3f0a |
126 | }; |
127 | |
c2774e9d |
128 | /** |
7e7af7f2 |
129 | * @fn GtkWidget* guifilter_get_widget(FilterViewerData*) |
852f16bb |
130 | * |
c2774e9d |
131 | * This function returns the current main widget |
132 | * used by this module |
133 | * @param fvd the module struct |
134 | * @return The main widget |
135 | */ |
7e7af7f2 |
136 | GtkWidget* |
137 | guifilter_get_widget(FilterViewerData *fvd) |
91ad3f0a |
138 | { |
01eb9889 |
139 | return fvd->f_window; |
91ad3f0a |
140 | } |
141 | |
142 | /** |
7e7af7f2 |
143 | * @fn FilterViewerData* gui_filter(Tab*) |
852f16bb |
144 | * |
145 | * Constructor is used to create FilterViewerData data structure. |
7e7af7f2 |
146 | * @param tab The tab structure used by the widget |
852f16bb |
147 | * @return The Filter viewer data created. |
91ad3f0a |
148 | */ |
149 | FilterViewerData* |
150 | gui_filter(Tab *tab) |
151 | { |
f88c5bfa |
152 | g_debug("filter::gui_filter()"); |
2b715e58 |
153 | |
154 | unsigned i; |
91ad3f0a |
155 | GtkCellRenderer *renderer; |
156 | GtkTreeViewColumn *column; |
157 | |
158 | FilterViewerData* fvd = g_new(FilterViewerData,1); |
159 | |
160 | fvd->tab = tab; |
161 | |
da2e1bfb |
162 | // lttvwindow_register_traceset_notify(fvd->tab, |
163 | // filter_traceset_changed, |
164 | // filter_viewer_data); |
91ad3f0a |
165 | // request_background_data(filter_viewer_data); |
4ed9b7ba |
166 | |
2b715e58 |
167 | /* |
168 | * Initiating items for |
169 | * combo boxes |
170 | */ |
1f7f7fe2 |
171 | fvd->f_not_op_options = g_ptr_array_new(); |
172 | g_ptr_array_add(fvd->f_not_op_options,(gpointer) g_string_new("")); |
173 | g_ptr_array_add(fvd->f_not_op_options,(gpointer) g_string_new("!")); |
174 | |
2b715e58 |
175 | fvd->f_logical_op_options = g_ptr_array_new(); //g_array_new(FALSE,FALSE,sizeof(gchar)); |
176 | g_ptr_array_add(fvd->f_logical_op_options,(gpointer) g_string_new("")); |
177 | g_ptr_array_add(fvd->f_logical_op_options,(gpointer) g_string_new("&")); |
178 | g_ptr_array_add(fvd->f_logical_op_options,(gpointer) g_string_new("|")); |
179 | g_ptr_array_add(fvd->f_logical_op_options,(gpointer) g_string_new("!")); |
180 | g_ptr_array_add(fvd->f_logical_op_options,(gpointer) g_string_new("^")); |
181 | |
182 | fvd->f_field_options = g_ptr_array_new(); //g_array_new(FALSE,FALSE,16); |
183 | g_ptr_array_add(fvd->f_field_options,(gpointer) g_string_new("")); |
184 | g_ptr_array_add(fvd->f_field_options,(gpointer) g_string_new("event.name")); |
185 | g_ptr_array_add(fvd->f_field_options,(gpointer) g_string_new("event.category")); |
186 | g_ptr_array_add(fvd->f_field_options,(gpointer) g_string_new("event.time")); |
187 | g_ptr_array_add(fvd->f_field_options,(gpointer) g_string_new("event.tsc")); |
188 | /* |
189 | * TODO: Add core.xml fields here ! |
190 | */ |
191 | g_ptr_array_add(fvd->f_field_options,(gpointer) g_string_new("tracefile.name")); |
192 | g_ptr_array_add(fvd->f_field_options,(gpointer) g_string_new("trace.name")); |
4f85064b |
193 | g_ptr_array_add(fvd->f_field_options,(gpointer) g_string_new("state.process_name")); |
2b715e58 |
194 | g_ptr_array_add(fvd->f_field_options,(gpointer) g_string_new("state.pid")); |
195 | g_ptr_array_add(fvd->f_field_options,(gpointer) g_string_new("state.ppid")); |
196 | g_ptr_array_add(fvd->f_field_options,(gpointer) g_string_new("state.creation_time")); |
197 | g_ptr_array_add(fvd->f_field_options,(gpointer) g_string_new("state.insertion_time")); |
198 | g_ptr_array_add(fvd->f_field_options,(gpointer) g_string_new("state.execution_mode")); |
199 | g_ptr_array_add(fvd->f_field_options,(gpointer) g_string_new("state.execution_submode")); |
200 | g_ptr_array_add(fvd->f_field_options,(gpointer) g_string_new("state.process_status")); |
201 | g_ptr_array_add(fvd->f_field_options,(gpointer) g_string_new("state.cpu")); |
202 | |
203 | fvd->f_math_op_options = g_ptr_array_new(); //g_array_new(FALSE,FALSE,7); |
204 | g_ptr_array_add(fvd->f_math_op_options,(gpointer) g_string_new("")); |
205 | g_ptr_array_add(fvd->f_math_op_options,(gpointer) g_string_new("=")); |
206 | g_ptr_array_add(fvd->f_math_op_options,(gpointer) g_string_new("!=")); |
207 | g_ptr_array_add(fvd->f_math_op_options,(gpointer) g_string_new("<")); |
208 | g_ptr_array_add(fvd->f_math_op_options,(gpointer) g_string_new("<=")); |
209 | g_ptr_array_add(fvd->f_math_op_options,(gpointer) g_string_new(">")); |
210 | g_ptr_array_add(fvd->f_math_op_options,(gpointer) g_string_new(">=")); |
211 | |
212 | |
6a4f1205 |
213 | fvd->f_window = gtk_window_new(GTK_WINDOW_TOPLEVEL); |
214 | |
4ed9b7ba |
215 | /* |
216 | * Initiating GtkTable layout |
217 | * starts with 2 rows and 5 columns and |
218 | * expands when expressions added |
219 | */ |
1f7f7fe2 |
220 | fvd->f_main_box = gtk_table_new(3,7,FALSE); |
4ed9b7ba |
221 | gtk_table_set_row_spacings(GTK_TABLE(fvd->f_main_box),5); |
222 | gtk_table_set_col_spacings(GTK_TABLE(fvd->f_main_box),5); |
91ad3f0a |
223 | |
6a4f1205 |
224 | gtk_container_add(GTK_CONTAINER(fvd->f_window), GTK_WIDGET(fvd->f_main_box)); |
225 | |
4ed9b7ba |
226 | /* |
227 | * First half of the filter window |
228 | * - textual entry of filter expression |
229 | * - processing button |
230 | */ |
231 | fvd->f_expression_field = gtk_entry_new(); //gtk_scrolled_window_new (NULL, NULL); |
c2774e9d |
232 | // gtk_entry_set_text(GTK_ENTRY(fvd->f_expression_field),"state.cpu>0"); |
4ed9b7ba |
233 | gtk_widget_show (fvd->f_expression_field); |
234 | |
c2774e9d |
235 | g_signal_connect (G_OBJECT (fvd->f_expression_field), "changed", |
236 | G_CALLBACK (callback_expression_field), (gpointer) fvd); |
237 | |
4ed9b7ba |
238 | fvd->f_process_button = gtk_button_new_with_label("Process"); |
239 | gtk_widget_show (fvd->f_process_button); |
240 | |
c2774e9d |
241 | g_signal_connect (G_OBJECT (fvd->f_process_button), "clicked", |
242 | G_CALLBACK (callback_process_button), (gpointer) fvd); |
243 | |
1f7f7fe2 |
244 | gtk_table_attach( GTK_TABLE(fvd->f_main_box),fvd->f_expression_field,0,6,0,1,GTK_FILL,GTK_FILL,0,0); |
245 | gtk_table_attach( GTK_TABLE(fvd->f_main_box),fvd->f_process_button,6,7,0,1,GTK_FILL,GTK_FILL,0,0); |
c2774e9d |
246 | |
247 | |
4ed9b7ba |
248 | |
249 | /* |
250 | * Second half of the filter window |
251 | * - combo boxes featuring filtering options added to the expression |
252 | */ |
c2774e9d |
253 | fvd->f_add_button = gtk_button_new_with_label("Add Expression"); |
254 | gtk_widget_show (fvd->f_add_button); |
255 | |
256 | g_signal_connect (G_OBJECT (fvd->f_add_button), "clicked", |
257 | G_CALLBACK (callback_add_button), (gpointer) fvd); |
4ed9b7ba |
258 | |
1f7f7fe2 |
259 | gtk_table_attach( GTK_TABLE(fvd->f_main_box),fvd->f_add_button,6,7,1,2,GTK_FILL,GTK_FILL,0,0); |
c2774e9d |
260 | |
261 | fvd->f_logical_op_junction_box = gtk_combo_box_new_text(); |
2b715e58 |
262 | for(i=0;i<fvd->f_logical_op_options->len;i++) { |
263 | GString* s = g_ptr_array_index(fvd->f_logical_op_options,i); |
264 | gtk_combo_box_append_text(GTK_COMBO_BOX(fvd->f_logical_op_junction_box), s->str); |
265 | } |
266 | gtk_combo_box_set_active(GTK_COMBO_BOX(fvd->f_logical_op_junction_box),0); |
267 | |
c2774e9d |
268 | //gtk_widget_show(fvd->f_logical_op_box); |
2b99ec10 |
269 | |
c2774e9d |
270 | gtk_table_attach( GTK_TABLE(fvd->f_main_box),fvd->f_logical_op_junction_box,0,1,1,2,GTK_SHRINK,GTK_FILL,0,0); |
271 | |
203eb6f7 |
272 | gtk_container_set_border_width(GTK_CONTAINER(fvd->f_main_box), 1); |
273 | |
c2774e9d |
274 | /* initialize a new line */ |
275 | fvd->f_lines = g_ptr_array_new(); |
276 | fvd->rows = 1; |
277 | FilterViewerDataLine* fvdl = gui_filter_add_line(fvd); |
278 | g_ptr_array_add(fvd->f_lines,(gpointer) fvdl); |
4ed9b7ba |
279 | |
c2774e9d |
280 | /* |
281 | * show main container |
282 | */ |
4ed9b7ba |
283 | gtk_widget_show(fvd->f_main_box); |
6a4f1205 |
284 | gtk_widget_show(fvd->f_window); |
4ed9b7ba |
285 | |
91ad3f0a |
286 | |
287 | g_object_set_data_full( |
288 | G_OBJECT(guifilter_get_widget(fvd)), |
289 | "filter_viewer_data", |
290 | fvd, |
291 | (GDestroyNotify)gui_filter_destructor); |
292 | |
0fc64e11 |
293 | g_filter_list = g_slist_append( |
294 | g_filter_list, |
295 | fvd); |
4ed9b7ba |
296 | |
91ad3f0a |
297 | return fvd; |
298 | } |
299 | |
c2774e9d |
300 | /** |
7e7af7f2 |
301 | * @fn FilterViewerDataLine* gui_filter_add_line(FilterViewerData*) |
852f16bb |
302 | * |
c2774e9d |
303 | * Adds a filter option line on the module tab |
304 | * @param fvd The filter module structure |
305 | * @return The line structure |
306 | */ |
307 | FilterViewerDataLine* |
308 | gui_filter_add_line(FilterViewerData* fvd) { |
309 | |
310 | FilterViewerDataLine* fvdl = g_new(FilterViewerDataLine,1); |
311 | |
2b715e58 |
312 | unsigned i; |
c2774e9d |
313 | fvdl->row = fvd->rows; |
314 | fvdl->visible = TRUE; |
2b715e58 |
315 | |
1f7f7fe2 |
316 | fvdl->f_not_op_box = gtk_combo_box_new_text(); |
317 | for(i=0;i<fvd->f_not_op_options->len;i++) { |
318 | GString* s = g_ptr_array_index(fvd->f_not_op_options,i); |
319 | gtk_combo_box_append_text(GTK_COMBO_BOX(fvdl->f_not_op_box), s->str); |
320 | } |
321 | |
2b715e58 |
322 | fvdl->f_field_box = gtk_combo_box_new_text(); |
323 | for(i=0;i<fvd->f_field_options->len;i++) { |
324 | GString* s = g_ptr_array_index(fvd->f_field_options,i); |
1f7f7fe2 |
325 | // g_print("String field: %s\n",s->str); |
2b715e58 |
326 | gtk_combo_box_append_text(GTK_COMBO_BOX(fvdl->f_field_box), s->str); |
327 | } |
328 | |
329 | fvdl->f_math_op_box = gtk_combo_box_new_text(); |
330 | for(i=0;i<fvd->f_math_op_options->len;i++) { |
331 | GString* s = g_ptr_array_index(fvd->f_math_op_options,i); |
332 | gtk_combo_box_append_text(GTK_COMBO_BOX(fvdl->f_math_op_box), s->str); |
333 | } |
334 | |
c2774e9d |
335 | fvdl->f_value_field = gtk_entry_new(); |
c2774e9d |
336 | |
337 | fvdl->f_logical_op_box = gtk_combo_box_new_text(); |
2b715e58 |
338 | for(i=0;i<fvd->f_logical_op_options->len;i++) { |
339 | GString* s = g_ptr_array_index(fvd->f_logical_op_options,i); |
340 | gtk_combo_box_append_text(GTK_COMBO_BOX(fvdl->f_logical_op_box), s->str); |
341 | } |
c2774e9d |
342 | gtk_widget_set_events(fvdl->f_logical_op_box, |
343 | GDK_ENTER_NOTIFY_MASK | |
344 | GDK_LEAVE_NOTIFY_MASK | |
345 | GDK_FOCUS_CHANGE_MASK); |
346 | |
347 | g_signal_connect (G_OBJECT (fvdl->f_logical_op_box), "changed", |
348 | G_CALLBACK (callback_logical_op_box), (gpointer) fvd); |
2b715e58 |
349 | |
350 | gui_filter_line_reset(fvdl); |
351 | gui_filter_line_set_visible(fvdl,TRUE); |
c2774e9d |
352 | |
1f7f7fe2 |
353 | gtk_table_attach( GTK_TABLE(fvd->f_main_box),fvdl->f_not_op_box,0,1,fvd->rows+1,fvd->rows+2,GTK_SHRINK,GTK_FILL,0,0); |
354 | gtk_table_attach( GTK_TABLE(fvd->f_main_box),fvdl->f_field_box,1,3,fvd->rows+1,fvd->rows+2,GTK_SHRINK,GTK_FILL,0,0); |
355 | gtk_table_attach( GTK_TABLE(fvd->f_main_box),fvdl->f_math_op_box,3,4,fvd->rows+1,fvd->rows+2,GTK_SHRINK,GTK_FILL,0,0); |
356 | gtk_table_attach( GTK_TABLE(fvd->f_main_box),fvdl->f_value_field,4,5,fvd->rows+1,fvd->rows+2,GTK_SHRINK,GTK_FILL,0,0); |
357 | gtk_table_attach( GTK_TABLE(fvd->f_main_box),fvdl->f_logical_op_box,5,6,fvd->rows+1,fvd->rows+2,GTK_SHRINK,GTK_FILL,0,0); |
c2774e9d |
358 | |
359 | return fvdl; |
360 | } |
361 | |
852f16bb |
362 | /** |
7e7af7f2 |
363 | * @fn void gui_filter_line_set_visible(FilterViewerDataLine*,gboolean) |
852f16bb |
364 | * |
365 | * Change visible state of current FilterViewerDataLine |
366 | * @param fvdl pointer to the current FilterViewerDataLine |
367 | * @param v TRUE: sets visible, FALSE: sets invisible |
368 | */ |
7e7af7f2 |
369 | void |
370 | gui_filter_line_set_visible(FilterViewerDataLine *fvdl, gboolean v) { |
c2774e9d |
371 | |
372 | fvdl->visible = v; |
373 | if(v) { |
1f7f7fe2 |
374 | gtk_widget_show(fvdl->f_not_op_box); |
2b715e58 |
375 | gtk_widget_show(fvdl->f_field_box); |
c2774e9d |
376 | gtk_widget_show(fvdl->f_math_op_box); |
377 | gtk_widget_show(fvdl->f_value_field); |
378 | gtk_widget_show(fvdl->f_logical_op_box); |
379 | } else { |
1f7f7fe2 |
380 | gtk_widget_hide(fvdl->f_not_op_box); |
2b715e58 |
381 | gtk_widget_hide(fvdl->f_field_box); |
c2774e9d |
382 | gtk_widget_hide(fvdl->f_math_op_box); |
383 | gtk_widget_hide(fvdl->f_value_field); |
384 | gtk_widget_hide(fvdl->f_logical_op_box); |
385 | } |
386 | |
387 | } |
388 | |
852f16bb |
389 | /** |
7e7af7f2 |
390 | * @fn void gui_filter_line_reset(FilterViewerDataLine*) |
852f16bb |
391 | * |
392 | * Sets selections of all boxes in current FilterViewerDataLine |
393 | * to default value (0) |
394 | * @param fvdl pointer to current FilterViewerDataLine |
395 | */ |
7e7af7f2 |
396 | void |
397 | gui_filter_line_reset(FilterViewerDataLine *fvdl) { |
c2774e9d |
398 | |
1f7f7fe2 |
399 | gtk_combo_box_set_active(GTK_COMBO_BOX(fvdl->f_not_op_box),0); |
2b715e58 |
400 | gtk_combo_box_set_active(GTK_COMBO_BOX(fvdl->f_field_box),0); |
c2774e9d |
401 | gtk_combo_box_set_active(GTK_COMBO_BOX(fvdl->f_math_op_box),0); |
da2e1bfb |
402 | gtk_entry_set_text(GTK_ENTRY(fvdl->f_value_field),""); |
c2774e9d |
403 | gtk_combo_box_set_active(GTK_COMBO_BOX(fvdl->f_logical_op_box),0); |
404 | } |
405 | |
406 | /** |
7e7af7f2 |
407 | * @fn void gui_filter_destructor(FilterViewerData*) |
852f16bb |
408 | * |
c2774e9d |
409 | * Destructor for the filter gui module |
410 | * @param fvd The module structure |
411 | */ |
91ad3f0a |
412 | void |
413 | gui_filter_destructor(FilterViewerData *fvd) |
414 | { |
415 | Tab *tab = fvd->tab; |
416 | |
417 | /* May already been done by GTK window closing */ |
418 | if(GTK_IS_WIDGET(guifilter_get_widget(fvd))){ |
419 | g_info("widget still exists"); |
420 | } |
da2e1bfb |
421 | // if(tab != NULL) { |
422 | // lttvwindow_unregister_traceset_notify(fvd->tab, |
423 | // filter_traceset_changed, |
424 | // filter_viewer_data); |
425 | // } |
91ad3f0a |
426 | lttvwindowtraces_background_notify_remove(fvd); |
0fc64e11 |
427 | |
428 | g_filter_list = g_slist_remove(g_filter_list, fvd); |
6a4f1205 |
429 | |
430 | main_window_remove_child_window(tab, fvd->name); |
431 | |
432 | g_free(fvd->name); |
0fc64e11 |
433 | |
91ad3f0a |
434 | g_free(fvd); |
435 | } |
436 | |
91ad3f0a |
437 | |
438 | /** |
7e7af7f2 |
439 | * @fn GtkWidget* h_guifilter(Tab*) |
852f16bb |
440 | * |
441 | * Filter Module's constructor hook |
91ad3f0a |
442 | * |
852f16bb |
443 | * This constructor is given as a parameter to the menuitem and toolbar button |
444 | * registration. It creates the list. |
445 | * @param tab A pointer to the parent window. |
446 | * @return The widget created. |
91ad3f0a |
447 | */ |
448 | GtkWidget * |
2b99ec10 |
449 | h_guifilter(Tab *tab) |
91ad3f0a |
450 | { |
451 | FilterViewerData* f = gui_filter(tab) ; |
6a4f1205 |
452 | f->name = g_new(gchar, 256); |
453 | |
454 | snprintf(f->name, 256, "guifilter %p", f); |
91ad3f0a |
455 | |
456 | if(f) |
6a4f1205 |
457 | main_window_add_child_window(tab, f, |
458 | f->name, (GDestroyNotify)gui_filter_destructor); |
459 | return NULL; |
91ad3f0a |
460 | |
461 | } |
462 | |
91ad3f0a |
463 | /** |
7e7af7f2 |
464 | * @fn static void init() |
852f16bb |
465 | * |
466 | * This function initializes the Filter Viewer functionnality through the |
467 | * gtkTraceSet API. |
91ad3f0a |
468 | */ |
469 | static void init() { |
470 | |
471 | lttvwindow_register_constructor("guifilter", |
472 | "/", |
473 | "Insert Filter Module", |
474 | hGuiFilterInsert_xpm, |
475 | "Insert Filter Module", |
2b99ec10 |
476 | h_guifilter); |
91ad3f0a |
477 | } |
478 | |
c2774e9d |
479 | /** |
7e7af7f2 |
480 | * @fn void filter_destroy_walk(gpointer,gpointer) |
852f16bb |
481 | * |
c2774e9d |
482 | * Initiate the destruction of the current gui module |
483 | * on the GTK Interface |
484 | */ |
7e7af7f2 |
485 | void |
486 | filter_destroy_walk(gpointer data, gpointer user_data) |
91ad3f0a |
487 | { |
488 | FilterViewerData *fvd = (FilterViewerData*)data; |
489 | |
c2774e9d |
490 | g_debug("CFV.c : filter_destroy_walk, %p", fvd); |
da2e1bfb |
491 | |
91ad3f0a |
492 | /* May already have been done by GTK window closing */ |
493 | if(GTK_IS_WIDGET(guifilter_get_widget(fvd))) |
494 | gtk_widget_destroy(guifilter_get_widget(fvd)); |
495 | } |
496 | |
497 | /** |
7e7af7f2 |
498 | * @fn static void destroy() |
852f16bb |
499 | * @brief plugin's destroy function |
91ad3f0a |
500 | * |
852f16bb |
501 | * This function releases the memory reserved by the module and unregisters |
502 | * everything that has been registered in the gtkTraceSet API. |
91ad3f0a |
503 | */ |
504 | static void destroy() { |
0fc64e11 |
505 | |
506 | g_slist_foreach(g_filter_list, filter_destroy_walk, NULL ); |
91ad3f0a |
507 | |
2b99ec10 |
508 | lttvwindow_unregister_constructor(h_guifilter); |
91ad3f0a |
509 | |
510 | } |
511 | |
c2774e9d |
512 | /** |
7e7af7f2 |
513 | * @fn void callback_process_button(GtkWidget*,gpointer) |
852f16bb |
514 | * |
c2774e9d |
515 | * The Process Button callback function |
516 | * @param widget The Button widget passed to the callback function |
517 | * @param data Data sent along with the callback function |
518 | */ |
7e7af7f2 |
519 | void |
520 | callback_process_button(GtkWidget *widget, gpointer data) { |
c2774e9d |
521 | |
da2e1bfb |
522 | g_debug("callback_process_button(): Processing expression"); |
523 | |
c2774e9d |
524 | FilterViewerData *fvd = (FilterViewerData*)data; |
525 | |
1f7f7fe2 |
526 | if(strlen(gtk_entry_get_text(GTK_ENTRY(fvd->f_expression_field))) !=0) { |
527 | LttvFilter* filter = lttv_filter_new(); |
da2e1bfb |
528 | GString* s = g_string_new(gtk_entry_get_text(GTK_ENTRY(fvd->f_expression_field))); |
529 | lttv_filter_append_expression(filter,s->str); |
530 | g_string_free(s,TRUE); |
a998b781 |
531 | //SetFilter(fvd->tab,filter); |
532 | lttvwindow_report_filter(fvd->tab, filter); |
1f7f7fe2 |
533 | } |
c2774e9d |
534 | } |
535 | |
536 | /** |
7e7af7f2 |
537 | * @fn void callback_expression_field(GtkWidget*,gpointer) |
852f16bb |
538 | * |
c2774e9d |
539 | * The Add Button callback function |
540 | * @param widget The Button widget passed to the callback function |
541 | * @param data Data sent along with the callback function |
542 | */ |
7e7af7f2 |
543 | void |
544 | callback_expression_field(GtkWidget *widget, gpointer data) { |
da2e1bfb |
545 | |
c2774e9d |
546 | FilterViewerData *fvd = (FilterViewerData*)data; |
547 | |
548 | if(strlen(gtk_entry_get_text(GTK_ENTRY(fvd->f_expression_field))) !=0) { |
549 | gtk_widget_show(fvd->f_logical_op_junction_box); |
550 | } else { |
551 | gtk_widget_hide(fvd->f_logical_op_junction_box); |
552 | } |
553 | } |
554 | |
555 | |
556 | /** |
7e7af7f2 |
557 | * @fn void callback_add_button(GtkWidget*,gpointer) |
852f16bb |
558 | * |
c2774e9d |
559 | * The Add Button callback function |
560 | * @param widget The Button widget passed to the callback function |
561 | * @param data Data sent along with the callback function |
562 | */ |
7e7af7f2 |
563 | void |
564 | callback_add_button(GtkWidget *widget, gpointer data) { |
c2774e9d |
565 | |
da2e1bfb |
566 | g_debug("callback_add_button(): processing simple expressions"); |
c2774e9d |
567 | |
da2e1bfb |
568 | unsigned i; |
569 | |
c2774e9d |
570 | FilterViewerData *fvd = (FilterViewerData*)data; |
571 | FilterViewerDataLine *fvdl = NULL; |
572 | GString* a_filter_string = g_string_new(""); |
2b715e58 |
573 | |
da2e1bfb |
574 | /* |
575 | * adding linking operator to |
576 | * string |
577 | */ |
2b715e58 |
578 | GString* s; |
579 | s = g_ptr_array_index(fvd->f_logical_op_options,gtk_combo_box_get_active(GTK_COMBO_BOX(fvd->f_logical_op_junction_box))); |
2b715e58 |
580 | g_string_append(a_filter_string,s->str); |
da2e1bfb |
581 | gtk_combo_box_set_active(GTK_COMBO_BOX(fvd->f_logical_op_junction_box),0); |
c2774e9d |
582 | |
da2e1bfb |
583 | /* begin expression */ |
2b715e58 |
584 | g_string_append_c(a_filter_string,'('); |
585 | |
da2e1bfb |
586 | /* |
587 | * For each simple expression, add the resulting string |
588 | * to the filter string |
589 | * |
590 | * Each simple expression takes the following schema |
591 | * [not operator '!',' '] [field type] [math operator '<','<=','>','>=','=','!='] [value] |
592 | */ |
c2774e9d |
593 | for(i=0;i<fvd->f_lines->len;i++) { |
594 | fvdl = (FilterViewerDataLine*)g_ptr_array_index(fvd->f_lines,i); |
1f7f7fe2 |
595 | |
596 | s = g_ptr_array_index(fvd->f_not_op_options,gtk_combo_box_get_active(GTK_COMBO_BOX(fvdl->f_not_op_box))); |
597 | g_string_append(a_filter_string,s->str); |
2b715e58 |
598 | |
599 | s = g_ptr_array_index(fvd->f_field_options,gtk_combo_box_get_active(GTK_COMBO_BOX(fvdl->f_field_box))); |
600 | g_string_append(a_filter_string,s->str); |
601 | |
602 | s = g_ptr_array_index(fvd->f_math_op_options,gtk_combo_box_get_active(GTK_COMBO_BOX(fvdl->f_math_op_box))); |
603 | g_string_append(a_filter_string,s->str); |
604 | |
605 | g_string_append(a_filter_string,gtk_entry_get_text(GTK_ENTRY(fvdl->f_value_field))); |
606 | |
607 | s = g_ptr_array_index(fvd->f_logical_op_options,gtk_combo_box_get_active(GTK_COMBO_BOX(fvdl->f_logical_op_box))); |
608 | g_string_append(a_filter_string,s->str); |
609 | |
da2e1bfb |
610 | /* |
611 | * resetting simple expression lines |
612 | */ |
c2774e9d |
613 | gui_filter_line_reset(fvdl); |
2b715e58 |
614 | if(i) gui_filter_line_set_visible(fvdl,FALSE); // Only keep the first line |
c2774e9d |
615 | } |
616 | |
da2e1bfb |
617 | /* end expression */ |
2b715e58 |
618 | g_string_append_c(a_filter_string,')'); |
c2774e9d |
619 | |
2b715e58 |
620 | g_string_prepend(a_filter_string,gtk_entry_get_text(GTK_ENTRY(fvd->f_expression_field))); |
621 | gtk_entry_set_text(GTK_ENTRY(fvd->f_expression_field),a_filter_string->str); |
c2774e9d |
622 | |
623 | } |
624 | |
625 | /** |
7e7af7f2 |
626 | * @fn void callback_logical_op_box(GtkWidget*,gpointer) |
852f16bb |
627 | * |
c2774e9d |
628 | * The logical op box callback function |
629 | * @param widget The Button widget passed to the callback function |
630 | * @param data Data sent along with the callback function |
631 | */ |
7e7af7f2 |
632 | void |
633 | callback_logical_op_box(GtkWidget *widget, gpointer data) { |
c2774e9d |
634 | |
da2e1bfb |
635 | g_debug("callback_logical_op_box(): adding new simple expression"); |
c2774e9d |
636 | |
637 | FilterViewerData *fvd = (FilterViewerData*)data; |
638 | FilterViewerDataLine *fvdl = NULL; |
639 | |
640 | int i; |
641 | for(i=0;i<fvd->f_lines->len;i++) { |
642 | fvdl = (FilterViewerDataLine*)g_ptr_array_index(fvd->f_lines,i); |
643 | if(fvdl->f_logical_op_box == widget) { |
da2e1bfb |
644 | if(gtk_combo_box_get_active(GTK_COMBO_BOX(fvdl->f_logical_op_box)) == 0) return; |
c2774e9d |
645 | if(i==fvd->f_lines->len-1) { /* create a new line */ |
646 | fvd->rows++; |
647 | FilterViewerDataLine* fvdl2 = gui_filter_add_line(fvd); |
648 | g_ptr_array_add(fvd->f_lines,(gpointer) fvdl2); |
649 | } else { |
650 | FilterViewerDataLine *fvdl2 = (FilterViewerDataLine*)g_ptr_array_index(fvd->f_lines,i+1); |
651 | if(!fvdl2->visible) gui_filter_line_set_visible(fvdl2,TRUE); |
652 | } |
653 | } |
654 | } |
655 | |
656 | } |
91ad3f0a |
657 | |
658 | LTTV_MODULE("guifilter", "Filter window", \ |
659 | "Graphical module that let user specify their filtering options", \ |
660 | init, destroy, "lttvwindow") |
661 | |