e7c8534e |
1 | /* This file is part of the Linux Trace Toolkit viewer |
2 | * Copyright (C) 2005 Mathieu Desnoyers |
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 | |
19 | #ifdef HAVE_CONFIG_H |
20 | #include <config.h> |
21 | #endif |
22 | |
23 | #include <glib.h> |
24 | #include <string.h> |
25 | #include <gtk/gtk.h> |
26 | #include <gdk/gdk.h> |
27 | #include <gdk/gdkkeysyms.h> |
28 | |
29 | #include <lttv/lttv.h> |
30 | #include <lttv/module.h> |
31 | #include <lttv/hook.h> |
32 | #include <lttv/filter.h> |
33 | |
34 | #include <lttvwindow/lttvwindow.h> |
35 | #include <lttvwindow/lttvwindowtraces.h> |
36 | |
37 | #include "hTraceControlInsert.xpm" |
381229ee |
38 | #include "TraceControlStart.xpm" |
39 | #include "TraceControlPause.xpm" |
40 | #include "TraceControlStop.xpm" |
e7c8534e |
41 | |
42 | |
43 | GSList *g_control_list = NULL ; |
44 | |
45 | /*! \file lttv/modules/gui/tracecontrol/tracecontrol.c |
46 | * \brief Graphic trace start/stop control interface. |
47 | * |
48 | * This plugin interacts with lttctl to start/stop tracing. It needs to take the |
49 | * root password to be able to interact with lttctl. |
50 | * |
51 | */ |
52 | |
53 | typedef struct _ControlData ControlData; |
54 | |
55 | /* |
56 | * Prototypes |
57 | */ |
58 | GtkWidget *guicontrol_get_widget(ControlData *tcd); |
59 | ControlData *gui_control(Tab *tab); |
60 | void gui_control_destructor(ControlData *tcd); |
61 | GtkWidget* h_guicontrol(Tab *tab); |
62 | void control_destroy_walk(gpointer data, gpointer user_data); |
63 | |
64 | /* |
65 | * Callback functions |
66 | */ |
67 | |
68 | |
69 | /** |
70 | * @struct _ControlData |
71 | * |
72 | * @brief Main structure of gui filter |
73 | * Main struct for the filter gui module |
74 | */ |
75 | struct _ControlData { |
76 | Tab *tab; /**< current tab of module */ |
77 | |
78 | GtkWidget *f_window; /**< filter window */ |
79 | |
80 | GtkWidget *f_main_box; /**< main container */ |
81 | |
82 | }; |
83 | |
84 | /** |
85 | * @fn GtkWidget* guicontrol_get_widget(ControlData*) |
86 | * |
87 | * This function returns the current main widget |
88 | * used by this module |
89 | * @param tcd the module struct |
90 | * @return The main widget |
91 | */ |
92 | GtkWidget* |
93 | guicontrol_get_widget(ControlData *tcd) |
94 | { |
95 | return tcd->f_window; |
96 | } |
97 | |
98 | /** |
99 | * @fn ControlData* gui_control(Tab*) |
100 | * |
101 | * Constructor is used to create ControlData data structure. |
102 | * @param tab The tab structure used by the widget |
103 | * @return The Filter viewer data created. |
104 | */ |
105 | ControlData* |
106 | gui_control(Tab *tab) |
107 | { |
108 | g_debug("filter::gui_control()"); |
109 | |
110 | unsigned i; |
111 | GtkCellRenderer *renderer; |
112 | GtkTreeViewColumn *column; |
113 | |
114 | ControlData* tcd = g_new(ControlData,1); |
115 | |
116 | tcd->tab = tab; |
117 | |
118 | tcd->f_window = gtk_window_new(GTK_WINDOW_TOPLEVEL); |
119 | gtk_window_set_title(GTK_WINDOW(tcd->f_window), "LTTng Trace Control"); |
120 | /* |
121 | * Initiating GtkTable layout |
122 | * starts with 2 rows and 5 columns and |
123 | * expands when expressions added |
124 | */ |
381229ee |
125 | tcd->f_main_box = gtk_table_new(14,7,FALSE); |
e7c8534e |
126 | gtk_table_set_row_spacings(GTK_TABLE(tcd->f_main_box),5); |
127 | gtk_table_set_col_spacings(GTK_TABLE(tcd->f_main_box),5); |
128 | |
129 | gtk_container_add(GTK_CONTAINER(tcd->f_window), GTK_WIDGET(tcd->f_main_box)); |
130 | |
381229ee |
131 | /* |
132 | * start/pause/stop buttons |
133 | */ |
134 | GdkPixbuf *pixbuf; |
135 | GtkWidget *image; |
136 | pixbuf = gdk_pixbuf_new_from_xpm_data((const char **)TraceControlStart_xpm); |
137 | image = gtk_image_new_from_pixbuf(pixbuf); |
138 | GtkWidget *start_button = gtk_button_new_with_label("start"); |
139 | gtk_button_set_image(GTK_BUTTON(start_button), image); |
140 | gtk_button_set_alignment(GTK_BUTTON(start_button), 0.0, 0.0); |
141 | gtk_widget_show (start_button); |
142 | gtk_table_attach( GTK_TABLE(tcd->f_main_box),start_button,6,7,0,1,GTK_FILL,GTK_FILL,2,2); |
143 | |
144 | pixbuf = gdk_pixbuf_new_from_xpm_data((const char **)TraceControlPause_xpm); |
145 | image = gtk_image_new_from_pixbuf(pixbuf); |
146 | GtkWidget *pause_button = gtk_button_new_with_label("pause"); |
147 | gtk_button_set_image(GTK_BUTTON(pause_button), image); |
148 | gtk_button_set_alignment(GTK_BUTTON(pause_button), 0.0, 0.0); |
149 | gtk_widget_show (pause_button); |
150 | gtk_table_attach( GTK_TABLE(tcd->f_main_box),pause_button,6,7,1,2,GTK_FILL,GTK_FILL,2,2); |
151 | |
152 | pixbuf = gdk_pixbuf_new_from_xpm_data((const char **)TraceControlStop_xpm); |
153 | image = gtk_image_new_from_pixbuf(pixbuf); |
154 | GtkWidget *stop_button = gtk_button_new_with_label("stop"); |
155 | gtk_button_set_image(GTK_BUTTON(stop_button), image); |
156 | gtk_button_set_alignment(GTK_BUTTON(stop_button), 0.0, 0.0); |
157 | gtk_widget_show (stop_button); |
158 | gtk_table_attach( GTK_TABLE(tcd->f_main_box),stop_button,6,7,2,3,GTK_FILL,GTK_FILL,2,2); |
159 | |
e7c8534e |
160 | /* |
161 | * First half of the filter window |
162 | * - textual entry of filter expression |
163 | * - processing button |
164 | */ |
165 | GtkWidget *username_label = gtk_label_new("Username:"); |
166 | gtk_widget_show (username_label); |
167 | GtkWidget *username_entry = gtk_entry_new(); |
168 | gtk_entry_set_text(GTK_ENTRY(username_entry),"root"); |
e7c8534e |
169 | gtk_widget_show (username_entry); |
381229ee |
170 | gtk_table_attach( GTK_TABLE(tcd->f_main_box),username_label,0,2,0,1,GTK_FILL,GTK_FILL,2,2); |
171 | gtk_table_attach( GTK_TABLE(tcd->f_main_box),username_entry,2,6,0,1,GTK_FILL|GTK_EXPAND|GTK_SHRINK,GTK_FILL,0,0); |
172 | |
173 | |
174 | |
175 | GtkWidget *password_label = gtk_label_new("Password:"); |
176 | gtk_widget_show (password_label); |
177 | GtkWidget *password_entry = gtk_entry_new(); |
178 | gtk_entry_set_visibility(GTK_ENTRY(password_entry), FALSE); |
179 | gtk_widget_show (password_entry); |
180 | gtk_table_attach( GTK_TABLE(tcd->f_main_box),password_label,0,2,1,2,GTK_FILL,GTK_FILL,2,2); |
181 | gtk_table_attach( GTK_TABLE(tcd->f_main_box),password_entry,2,6,1,2,GTK_FILL|GTK_EXPAND|GTK_SHRINK,GTK_FILL,0,0); |
182 | |
183 | |
184 | GtkWidget *channel_dir_label = gtk_label_new("Channel directory:"); |
185 | gtk_widget_show (channel_dir_label); |
186 | GtkWidget *channel_dir_entry = gtk_entry_new(); |
187 | gtk_entry_set_text(GTK_ENTRY(channel_dir_entry),"/mnt/relayfs/ltt"); |
188 | gtk_widget_show (channel_dir_entry); |
189 | gtk_table_attach( GTK_TABLE(tcd->f_main_box),channel_dir_label,0,2,2,3,GTK_FILL,GTK_FILL,2,2); |
190 | gtk_table_attach( GTK_TABLE(tcd->f_main_box),channel_dir_entry,2,6,2,3,GTK_FILL|GTK_EXPAND|GTK_SHRINK,GTK_FILL,0,0); |
e7c8534e |
191 | |
381229ee |
192 | GtkWidget *trace_dir_label = gtk_label_new("Trace directory:"); |
193 | gtk_widget_show (trace_dir_label); |
194 | GtkWidget *trace_dir_entry = gtk_entry_new(); |
195 | gtk_entry_set_text(GTK_ENTRY(trace_dir_entry),"/tmp/trace1"); |
196 | gtk_widget_show (trace_dir_entry); |
197 | gtk_table_attach( GTK_TABLE(tcd->f_main_box),trace_dir_label,0,2,3,4,GTK_FILL,GTK_FILL,2,2); |
198 | gtk_table_attach( GTK_TABLE(tcd->f_main_box),trace_dir_entry,2,6,3,4,GTK_FILL|GTK_EXPAND|GTK_SHRINK,GTK_FILL,0,0); |
199 | |
200 | GtkWidget *trace_name_label = gtk_label_new("Trace name:"); |
201 | gtk_widget_show (trace_name_label); |
202 | GtkWidget *trace_name_entry = gtk_entry_new(); |
203 | gtk_entry_set_text(GTK_ENTRY(trace_name_entry),"trace"); |
204 | gtk_widget_show (trace_name_entry); |
205 | gtk_table_attach( GTK_TABLE(tcd->f_main_box),trace_name_label,0,2,4,5,GTK_FILL,GTK_FILL,2,2); |
206 | gtk_table_attach( GTK_TABLE(tcd->f_main_box),trace_name_entry,2,6,4,5,GTK_FILL|GTK_EXPAND|GTK_SHRINK,GTK_FILL,0,0); |
207 | |
208 | GtkWidget *trace_mode_label = gtk_label_new("Trace mode "); |
209 | gtk_widget_show (trace_mode_label); |
210 | GtkWidget *trace_mode_combo = gtk_combo_box_new_text(); |
211 | gtk_combo_box_append_text(GTK_COMBO_BOX(trace_mode_combo), |
212 | "normal"); |
213 | gtk_combo_box_append_text(GTK_COMBO_BOX(trace_mode_combo), |
214 | "flight recorder"); |
215 | gtk_combo_box_set_active(GTK_COMBO_BOX(trace_mode_combo), 0); |
216 | gtk_widget_show (trace_mode_combo); |
217 | gtk_table_attach( GTK_TABLE(tcd->f_main_box),trace_mode_label,0,2,5,6,GTK_FILL,GTK_FILL,2,2); |
218 | gtk_table_attach( GTK_TABLE(tcd->f_main_box),trace_mode_combo,2,6,5,6,GTK_FILL|GTK_EXPAND|GTK_SHRINK,GTK_FILL,0,0); |
219 | |
220 | GtkWidget *start_daemon_label = gtk_label_new("Start daemon "); |
221 | gtk_widget_show (start_daemon_label); |
222 | GtkWidget *start_daemon_check = gtk_check_button_new(); |
223 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(start_daemon_check), TRUE); |
224 | gtk_widget_show (start_daemon_check); |
225 | gtk_table_attach( GTK_TABLE(tcd->f_main_box),start_daemon_label,0,2,6,7,GTK_FILL,GTK_FILL,2,2); |
226 | gtk_table_attach( GTK_TABLE(tcd->f_main_box),start_daemon_check,2,6,6,7,GTK_FILL,GTK_FILL,0,0); |
227 | |
228 | GtkWidget *optional_label = gtk_label_new("Optional fields "); |
229 | gtk_widget_show (optional_label); |
230 | gtk_table_attach( GTK_TABLE(tcd->f_main_box),optional_label,0,6,7,8,GTK_FILL,GTK_FILL,2,2); |
231 | |
232 | GtkWidget *subbuf_size_label = gtk_label_new("Subbuffer size:"); |
233 | gtk_widget_show (subbuf_size_label); |
234 | GtkWidget *subbuf_size_entry = gtk_entry_new(); |
235 | gtk_widget_show (subbuf_size_entry); |
236 | gtk_table_attach( GTK_TABLE(tcd->f_main_box),subbuf_size_label,0,2,8,9,GTK_FILL,GTK_FILL,2,2); |
237 | gtk_table_attach( GTK_TABLE(tcd->f_main_box),subbuf_size_entry,2,6,8,9,GTK_FILL|GTK_EXPAND|GTK_SHRINK,GTK_FILL,0,0); |
238 | |
239 | GtkWidget *subbuf_num_label = gtk_label_new("Number of subbuffers:"); |
240 | gtk_widget_show (subbuf_num_label); |
241 | GtkWidget *subbuf_num_entry = gtk_entry_new(); |
242 | gtk_widget_show (subbuf_num_entry); |
243 | gtk_table_attach( GTK_TABLE(tcd->f_main_box),subbuf_num_label,0,2,9,10,GTK_FILL,GTK_FILL,2,2); |
244 | gtk_table_attach( GTK_TABLE(tcd->f_main_box),subbuf_num_entry,2,6,9,10,GTK_FILL|GTK_EXPAND|GTK_SHRINK,GTK_FILL,0,0); |
245 | |
246 | GtkWidget *lttctl_path_label = gtk_label_new("path to lttctl:"); |
247 | gtk_widget_show (lttctl_path_label); |
248 | GtkWidget *lttctl_path_entry = gtk_entry_new(); |
249 | gtk_widget_show (lttctl_path_entry); |
250 | gtk_table_attach( GTK_TABLE(tcd->f_main_box),lttctl_path_label,0,2,10,11,GTK_FILL,GTK_FILL,2,2); |
251 | gtk_table_attach( GTK_TABLE(tcd->f_main_box),lttctl_path_entry,2,6,10,11,GTK_FILL|GTK_EXPAND|GTK_SHRINK,GTK_FILL,0,0); |
252 | |
253 | |
254 | GtkWidget *lttd_path_label = gtk_label_new("path to lttd:"); |
255 | gtk_widget_show (lttd_path_label); |
256 | GtkWidget *lttd_path_entry = gtk_entry_new(); |
257 | gtk_widget_show (lttd_path_entry); |
258 | gtk_table_attach( GTK_TABLE(tcd->f_main_box),lttd_path_label,0,2,11,12,GTK_FILL,GTK_FILL,2,2); |
259 | gtk_table_attach( GTK_TABLE(tcd->f_main_box),lttd_path_entry,2,6,11,12,GTK_FILL|GTK_EXPAND|GTK_SHRINK,GTK_FILL,0,0); |
260 | |
261 | |
262 | GtkWidget *fac_path_label = gtk_label_new("path to facilities:"); |
263 | gtk_widget_show (fac_path_label); |
264 | GtkWidget *fac_path_entry = gtk_entry_new(); |
265 | gtk_entry_set_text(GTK_ENTRY(fac_path_entry),"/usr/share/LinuxTraceToolkitViewer/facilities"); |
266 | gtk_widget_set_size_request(fac_path_entry, 250, -1); |
267 | gtk_widget_show (fac_path_entry); |
268 | gtk_table_attach( GTK_TABLE(tcd->f_main_box),fac_path_label,0,2,12,13,GTK_FILL,GTK_FILL,2,2); |
269 | gtk_table_attach( GTK_TABLE(tcd->f_main_box),fac_path_entry,2,6,12,13,GTK_FILL|GTK_EXPAND|GTK_SHRINK,GTK_FILL,0,0); |
e7c8534e |
270 | |
271 | |
272 | /* |
273 | * show main container |
274 | */ |
275 | gtk_widget_show(tcd->f_main_box); |
276 | gtk_widget_show(tcd->f_window); |
277 | |
278 | |
279 | g_object_set_data_full( |
280 | G_OBJECT(guifilter_get_widget(tcd)), |
281 | "filter_viewer_data", |
282 | tcd, |
283 | (GDestroyNotify)gui_control_destructor); |
284 | |
285 | g_control_list = g_slist_append( |
286 | g_control_list, |
287 | tcd); |
288 | |
289 | return tcd; |
290 | } |
291 | |
292 | |
293 | /** |
294 | * @fn void gui_control_destructor(ControlData*) |
295 | * |
296 | * Destructor for the filter gui module |
297 | * @param tcd The module structure |
298 | */ |
299 | void |
300 | gui_control_destructor(ControlData *tcd) |
301 | { |
302 | Tab *tab = tcd->tab; |
303 | |
304 | /* May already been done by GTK window closing */ |
305 | if(GTK_IS_WIDGET(guifilter_get_widget(tcd))){ |
306 | g_info("widget still exists"); |
307 | } |
308 | // if(tab != NULL) { |
309 | // lttvwindow_unregister_traceset_notify(tcd->tab, |
310 | // filter_traceset_changed, |
311 | // filter_viewer_data); |
312 | // } |
313 | lttvwindowtraces_background_notify_remove(tcd); |
314 | |
315 | g_control_list = g_slist_remove(g_control_list, tcd); |
316 | |
317 | g_free(tcd); |
318 | } |
319 | |
320 | |
321 | /** |
322 | * @fn GtkWidget* h_guicontrol(Tab*) |
323 | * |
324 | * Control Module's constructor hook |
325 | * |
326 | * This constructor is given as a parameter to the menuitem and toolbar button |
327 | * registration. It creates the list. |
328 | * @param tab A pointer to the parent window. |
329 | * @return The widget created. |
330 | */ |
331 | GtkWidget * |
332 | h_guicontrol(Tab *tab) |
333 | { |
334 | ControlData* f = gui_control(tab) ; |
335 | |
336 | return NULL; |
337 | } |
338 | |
339 | /** |
340 | * @fn static void init() |
341 | * |
342 | * This function initializes the Filter Viewer functionnality through the |
343 | * gtkTraceSet API. |
344 | */ |
345 | static void init() { |
346 | |
347 | lttvwindow_register_constructor("guicontrol", |
348 | "/", |
349 | "Insert Tracing Control Module", |
350 | hTraceControlInsert_xpm, |
351 | "Insert Tracing Control Module", |
352 | h_guicontrol); |
353 | } |
354 | |
355 | /** |
356 | * @fn void control_destroy_walk(gpointer,gpointer) |
357 | * |
358 | * Initiate the destruction of the current gui module |
359 | * on the GTK Interface |
360 | */ |
361 | void |
362 | control_destroy_walk(gpointer data, gpointer user_data) |
363 | { |
364 | ControlData *tcd = (ControlData*)data; |
365 | |
366 | g_debug("traceontrol.c : control_destroy_walk, %p", tcd); |
367 | |
368 | /* May already have been done by GTK window closing */ |
369 | if(GTK_IS_WIDGET(guicontrol_get_widget(tcd))) |
370 | gtk_widget_destroy(guicontrol_get_widget(tcd)); |
371 | } |
372 | |
373 | /** |
374 | * @fn static void destroy() |
375 | * @brief plugin's destroy function |
376 | * |
377 | * This function releases the memory reserved by the module and unregisters |
378 | * everything that has been registered in the gtkTraceSet API. |
379 | */ |
380 | static void destroy() { |
381 | |
382 | g_slist_foreach(g_control_list, control_destroy_walk, NULL ); |
383 | |
384 | lttvwindow_unregister_constructor(h_guicontrol); |
385 | |
386 | } |
387 | |
388 | |
389 | LTTV_MODULE("guitracecontrol", "Trace Control Window", \ |
390 | "Graphical module that let user control kernel tracing", \ |
391 | init, destroy, "lttvwindow") |
392 | |