Port lttvwindow_process_pending_requests
[lttv.git] / lttv / modules / gui / lttvwindow / lttvwindow / callbacks.c
CommitLineData
e076699e 1/* This file is part of the Linux Trace Toolkit viewer
b052368a 2 * Copyright (C) 2003-2004 XangXiu Yang, Mathieu Desnoyers
e076699e 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
561eba2a 19#ifdef HAVE_CONFIG_H
20# include <config.h>
21#endif
22
a1a2b649 23#include <limits.h> // for PATH_MAX
24#include <stdlib.h>
f02b5e22 25#include <ctype.h>
26#include <string.h>
27#include <stdlib.h>
a1a2b649 28
561eba2a 29#include <gtk/gtk.h>
561eba2a 30
31#include "callbacks.h"
32#include "interface.h"
33#include "support.h"
a43d67ba 34#include <ltt/trace.h>
a43d67ba 35#include <ltt/time.h>
36#include <ltt/event.h>
2a2fa4f0 37#include <lttv/lttv.h>
a43d67ba 38#include <lttv/module.h>
39#include <lttv/iattribute.h>
451aaf27
FD
40#include <lttv/traceset.h>
41#ifdef BABEL_CLEANUP
a43d67ba 42#include <lttv/stats.h>
2f076594 43#include <lttv/sync/sync_chain_lttv.h>
451aaf27
FD
44#endif /* BABEL_CLEANUP */
45#include <lttv/filter.h>
13f86ce2 46#include <lttvwindow/mainwindow.h>
2d262115 47#include <lttvwindow/mainwindow-private.h>
13f86ce2 48#include <lttvwindow/menu.h>
4172f013 49#include <lttvwindow/timebar.h>
13f86ce2 50#include <lttvwindow/toolbar.h>
501e4e70 51#include <lttvwindow/lttvwindow.h>
a1a2b649 52#include <lttvwindow/lttvwindowtraces.h>
e433e6d6 53#include <lttvwindow/lttv_plugin_tab.h>
a1a2b649 54
451aaf27
FD
55#include <babeltrace/babeltrace.h>
56#include <babeltrace/ctf/events.h>
57#include <babeltrace/ctf/iterator.h>
58
6c35c853 59static LttTime lttvwindow_default_time_width = { 1, 0 };
f02b5e22 60#define CLIP_BUF 256 // size of clipboard buffer
f7afe191 61
49bf71b5 62extern LttvTrace *g_init_trace ;
561eba2a 63
ec25ff5e 64
65/** Array containing instanced objects. */
68b48a45 66extern GSList * g_main_window_list;
561eba2a 67
a43d67ba 68/** MD : keep old directory. */
a1a2b649 69static char remember_plugins_dir[PATH_MAX] = "";
70static char remember_trace_dir[PATH_MAX] = "";
6fbb1ddf 71
e433e6d6 72void tab_destructor(LttvPluginTab * ptab);
6fbb1ddf 73
bca3b81f 74MainWindow * get_window_data_struct(GtkWidget * widget);
93ac601b 75char * get_load_module(MainWindow *mw,
76 char ** load_module_name, int nb_module);
77char * get_unload_module(MainWindow *mw,
78 char ** loaded_module_name, int nb_module);
79char * get_remove_trace(MainWindow *mw, char ** all_trace_name, int nb_trace);
80char * get_selection(MainWindow *mw,
81 char ** all_name, int nb, char *title, char * column_title);
e433e6d6 82void init_tab(Tab *tab, MainWindow * mw, Tab *copy_tab,
716e4367 83 GtkNotebook * notebook, char * label);
561eba2a 84
68764dff
AM
85int update_traceset(Tab *tab, LttvTraceset *traceset);
86
2d262115 87static void insert_viewer(GtkWidget* widget, lttvwindow_viewer_constructor constructor);
49bf71b5 88
e433e6d6 89LttvPluginTab *create_new_tab(GtkWidget* widget, gpointer user_data);
49bf71b5 90
501e4e70 91static gboolean lttvwindow_process_pending_requests(Tab *tab);
202f6c8f 92
4172f013
YB
93static void on_timebar_starttime_changed(Timebar *timebar,
94 gpointer user_data);
95static void on_timebar_endtime_changed(Timebar *timebar,
96 gpointer user_data);
97static void on_timebar_currenttime_changed(Timebar *timebar,
98 gpointer user_data);
99
49bf71b5 100enum {
101 CHECKBOX_COLUMN,
102 NAME_COLUMN,
103 TOTAL_COLUMNS
104};
561eba2a 105
36b3c068 106enum
107{
108 MODULE_COLUMN,
109 N_COLUMNS
110};
111
f02b5e22 112
e433e6d6 113#if 0
114static void on_top_notify(GObject *gobject,
115 GParamSpec *arg1,
116 gpointer user_data)
117{
118 Tab *tab = (Tab*)user_data;
119 g_message("in on_top_notify.\n");
f02b5e22 120
e433e6d6 121}
122#endif //0
b052368a 123static gboolean viewer_grab_focus(GtkWidget *widget, GdkEventButton *event,
124 gpointer data)
125{
f37a2002 126 GtkWidget *viewer = GTK_WIDGET(data);
127 GtkWidget *viewer_container = gtk_widget_get_parent(viewer);
b052368a 128
129 g_debug("FOCUS GRABBED");
f37a2002 130 g_object_set_data(G_OBJECT(viewer_container), "focused_viewer", viewer);
131 return 0;
b052368a 132}
133
f02b5e22 134
f37a2002 135static void connect_focus_recursive(GtkWidget *widget,
136 GtkWidget *viewer)
137{
138 if(GTK_IS_CONTAINER(widget)) {
139 gtk_container_forall(GTK_CONTAINER(widget),
140 (GtkCallback)connect_focus_recursive,
141 viewer);
1818a315 142
143 }
144 if(GTK_IS_TREE_VIEW(widget)) {
2eef04b5 145 gtk_tree_view_set_headers_clickable(GTK_TREE_VIEW(widget), TRUE);
f37a2002 146 }
147 gtk_widget_add_events(widget, GDK_BUTTON_PRESS_MASK);
148 g_signal_connect (G_OBJECT(widget),
149 "button-press-event",
150 G_CALLBACK (viewer_grab_focus),
151 (gpointer)viewer);
152}
b052368a 153
d27948a3 154/* Stop all the processings and call gtk_main_quit() */
155static void mainwindow_quit()
156{
157 lttvwindowtraces_unregister_requests(g_quark_from_string("stats"));
158 lttvwindowtraces_unregister_requests(g_quark_from_string("state"));
159 lttvwindowtraces_unregister_computation_hooks(g_quark_from_string("stats"));
160 lttvwindowtraces_unregister_computation_hooks(g_quark_from_string("state"));
161
162 gtk_main_quit();
163}
164
165
abe346a3 166/* insert_viewer function constructs an instance of a viewer first,
167 * then inserts the widget of the instance into the container of the
168 * main window
169 */
170
561eba2a 171void
606309a4 172insert_viewer_wrap(GtkWidget *menuitem, gpointer user_data)
561eba2a 173{
42fcbb71 174 insert_viewer((GtkWidget*)menuitem, (lttvwindow_viewer_constructor)user_data);
561eba2a 175}
176
561eba2a 177
178/* internal functions */
2d262115 179void insert_viewer(GtkWidget* widget, lttvwindow_viewer_constructor constructor)
561eba2a 180{
b052368a 181 GtkWidget * viewer_container;
6ced96ef 182 GtkWidget * notebook = lookup_widget(widget, "MNotebook");
f9334f6f 183 GtkWidget * viewer;
6ced96ef 184 GtkWidget *page = gtk_notebook_get_nth_page(GTK_NOTEBOOK(notebook),
185 gtk_notebook_get_current_page(GTK_NOTEBOOK(notebook)));
e433e6d6 186 LttvPluginTab *ptab;
6ced96ef 187 Tab *tab;
188
189 if(!page) {
e433e6d6 190 ptab = create_new_tab(widget, NULL);
6ced96ef 191 } else {
e433e6d6 192 ptab = (LttvPluginTab *)g_object_get_data(G_OBJECT(page), "Tab_Plugin");
47cd8a09 193 }
e433e6d6 194 tab = ptab->tab;
47cd8a09 195
b052368a 196 viewer_container = tab->viewer_container;
561eba2a 197
7d0aa40c 198 viewer = (GtkWidget*)constructor(&ptab->parent);
f9334f6f 199 if(viewer)
f0d936c0 200 {
b052368a 201 //gtk_multivpaned_widget_add(GTK_MULTIVPANED(multivpaned), viewer);
202
203 gtk_box_pack_end(GTK_BOX(viewer_container),
204 viewer,
205 TRUE,
206 TRUE,
207 0);
208
f37a2002 209 /* We want to connect the viewer_grab_focus to EVERY
210 * child of this widget. The little trick is to get each child
211 * of each GTK_CONTAINER, even subchildren.
212 */
0f9d55ef 213 connect_focus_recursive(viewer, viewer);
f0d936c0 214 }
561eba2a 215}
216
313bd6fc 217/**
218 * Function to set/update traceset for the viewers
219 * @param tab viewer's tab
220 * @param traceset traceset of the main window.
221 * return value :
222 * 0 : traceset updated
223 * 1 : no traceset hooks to update; not an error.
224 */
225
226int SetTraceset(Tab * tab, LttvTraceset *traceset)
227{
451aaf27 228
482fe481
BP
229 TimeInterval time_span;
230 TimeWindow new_time_window;
231 LttTime new_current_time;
d26f0474 232
451aaf27 233#ifdef BABEL_CLEANUP
482fe481 234 // Perform time synchronization on the traces
665fdbb7 235 if (syncTraceset(tsc))
482fe481
BP
236 {
237 /* There is some time-dependant information that was calculated during
238 * context initialization. Destroy the old contexts and initialize new
239 * ones.
240 * Modified from lttvwindow_add_trace()
241 */
242 // Keep a reference to the traces so they are not freed
243 for(i = 0; i < lttv_traceset_number(traceset); i++)
244 {
245 LttvTrace *trace = lttv_traceset_get(traceset, i);
246 lttv_trace_ref(trace);
247 }
248
249 // Remove state update hooks
250 lttv_state_remove_event_hooks(
251 (LttvTracesetState*)tab->traceset_info->traceset_context);
252
253 lttv_context_fini(LTTV_TRACESET_CONTEXT(
254 tab->traceset_info->traceset_context));
255 g_object_unref(tab->traceset_info->traceset_context);
256
257 for(i = 0; i < lttv_traceset_number(traceset); i++)
258 {
259 LttvTrace *trace = lttv_traceset_get(traceset, i);
260 lttvwindowtraces_remove_trace(trace);
261 lttvwindowtraces_add_trace(trace);
262 }
263
264 // Create new context
265 tab->traceset_info->traceset_context =
266 g_object_new(LTTV_TRACESET_STATS_TYPE, NULL);
267 lttv_context_init(LTTV_TRACESET_CONTEXT(tab->traceset_info->
268 traceset_context), traceset);
269
270 // Add state update hooks
271 lttv_state_add_event_hooks(
272 (LttvTracesetState*)tab->traceset_info->traceset_context);
273
274 // Remove local reference to the traces
275 for(i=0; i<lttv_traceset_number(traceset); i++)
276 {
277 LttvTrace *trace = lttv_traceset_get(traceset, i);
278 lttv_trace_unref(trace);
279 }
280
281 tsc = LTTV_TRACESET_CONTEXT(tab->traceset_info->traceset_context);
282 }
451aaf27 283#endif /*BABEL_CLEANUP*/
482fe481 284
9aaa78dc 285 time_span = lttv_traceset_get_time_span(traceset);
451aaf27
FD
286
287 tab->traceset_info->traceset = traceset;
288
289 new_time_window = tab->time_window;
290 new_current_time = tab->current_time;
291
1ba187d3 292 /* Set the tab's time window and current time if
293 * out of bounds */
294 if(ltt_time_compare(tab->time_window.start_time, time_span.start_time) < 0
6f26fc38 295 || ltt_time_compare(tab->time_window.end_time,
1ba187d3 296 time_span.end_time) > 0) {
e800cf84 297 new_time_window.start_time = time_span.start_time;
298
299 new_current_time = time_span.start_time;
1ba187d3 300
301 LttTime tmp_time;
6c35c853 302
303 if(ltt_time_compare(lttvwindow_default_time_width,
4249a3e8 304 ltt_time_sub(time_span.end_time, time_span.start_time)) < 0
305 ||
306 ltt_time_compare(time_span.end_time, time_span.start_time) == 0)
6c35c853 307 tmp_time = lttvwindow_default_time_width;
1ba187d3 308 else
6c35c853 309 tmp_time = time_span.end_time;
310
e800cf84 311 new_time_window.time_width = tmp_time ;
a18124ff 312 new_time_window.time_width_double = ltt_time_to_double(tmp_time);
6f26fc38 313 new_time_window.end_time = ltt_time_add(new_time_window.start_time,
314 new_time_window.time_width) ;
1ba187d3 315 }
e800cf84 316
1ba187d3 317 /* Finally, call the update hooks of the viewers */
68764dff 318 gint retval = update_traceset(tab, traceset);
1ba187d3 319
4249a3e8 320 time_change_manager(tab, new_time_window);
321 current_time_change_manager(tab, new_current_time);
322
b052368a 323 return retval;
451aaf27 324
313bd6fc 325}
326
327/**
328 * Function to set/update filter for the viewers
329 * @param tab viewer's tab
330 * @param filter filter of the main window.
331 * return value :
332 * -1 : error
333 * 0 : filters updated
334 * 1 : no filter hooks to update; not an error.
335 */
a998b781 336#if 0
313bd6fc 337int SetFilter(Tab * tab, gpointer filter)
338{
339 LttvHooks * tmp;
340 LttvAttributeValue value;
341
342 g_assert(lttv_iattribute_find_by_path(tab->attributes,
343 "hooks/updatefilter", LTTV_POINTER, &value));
344
345 tmp = (LttvHooks*)*(value.v_pointer);
346
347 if(tmp == NULL) return 1;
348 lttv_hooks_call(tmp,filter);
349
350 return 0;
351}
a998b781 352#endif //0
313bd6fc 353
354
355/**
356 * Function to redraw each viewer belonging to the current tab
357 * @param tab viewer's tab
358 */
359
1e3594a3 360int update_traceset(Tab *tab, LttvTraceset *traceset)
313bd6fc 361{
362 LttvAttributeValue value;
363 LttvHooks * tmp;
8f318283
BP
364 gboolean retval;
365
366 retval= lttv_iattribute_find_by_path(tab->attributes,
1e3594a3
YB
367 "hooks/updatetraceset",
368 LTTV_POINTER,
369 &value);
8f318283 370 g_assert(retval);
313bd6fc 371 tmp = (LttvHooks*)*(value.v_pointer);
1e3594a3
YB
372 if(tmp == NULL) {
373 retval = 1;
374 } else {
375 lttv_hooks_call(tmp, traceset);
376 }
377 return retval;
313bd6fc 378}
379
1e3594a3
YB
380/**
381 Call hooks register to get update on traceset time span changes
382*/
383int notify_time_span_changed(Tab *tab)
384{
385 LttvAttributeValue value;
386 LttvHooks * tmp;
387 gboolean retval;
388
389 retval= lttv_iattribute_find_by_path(tab->attributes,
390 "hooks/updatetimespan",
391 LTTV_POINTER,
392 &value);
393 g_assert(retval);
394 tmp = (LttvHooks*)*(value.v_pointer);
395 if(tmp == NULL) {
396 retval = 1;
397 } else {
398 lttv_hooks_call(tmp, NULL);
399 }
400 return retval;
401}
abe346a3 402
403/* get_label function is used to get user input, it displays an input
404 * box, which allows user to input a string
405 */
406
561eba2a 407void get_label_string (GtkWidget * text, gchar * label)
408{
409 GtkEntry * entry = (GtkEntry*)text;
410 if(strlen(gtk_entry_get_text(entry))!=0)
411 strcpy(label,gtk_entry_get_text(entry));
412}
413
eb38aea5 414gboolean get_label(MainWindow * mw, gchar * str, gchar* dialogue_title, gchar * label_str)
561eba2a 415{
416 GtkWidget * dialogue;
417 GtkWidget * text;
418 GtkWidget * label;
419 gint id;
420
5723fa24 421 dialogue = gtk_dialog_new_with_buttons(dialogue_title,NULL,
561eba2a 422 GTK_DIALOG_MODAL,
423 GTK_STOCK_OK,GTK_RESPONSE_ACCEPT,
424 GTK_STOCK_CANCEL,GTK_RESPONSE_REJECT,
425 NULL);
426
6b1d3120 427 label = gtk_label_new(label_str);
561eba2a 428 gtk_widget_show(label);
429
430 text = gtk_entry_new();
431 gtk_widget_show(text);
432
433 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialogue)->vbox), label,TRUE, TRUE,0);
434 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialogue)->vbox), text,FALSE, FALSE,0);
435
436 id = gtk_dialog_run(GTK_DIALOG(dialogue));
437 switch(id){
438 case GTK_RESPONSE_ACCEPT:
439 get_label_string(text,str);
440 gtk_widget_destroy(dialogue);
441 break;
442 case GTK_RESPONSE_REJECT:
443 default:
444 gtk_widget_destroy(dialogue);
eb38aea5 445 return FALSE;
561eba2a 446 }
eb38aea5 447 return TRUE;
561eba2a 448}
449
abe346a3 450
451/* get_window_data_struct function is actually a lookup function,
452 * given a widget which is in the tree of the main window, it will
453 * return the MainWindow data structure associated with main window
454 */
455
bca3b81f 456MainWindow * get_window_data_struct(GtkWidget * widget)
561eba2a 457{
458 GtkWidget * mw;
bca3b81f 459 MainWindow * mw_data;
561eba2a 460
461 mw = lookup_widget(widget, "MWindow");
462 if(mw == NULL){
56e5a0f7 463 g_info("Main window does not exist\n");
2d262115 464 return NULL;
561eba2a 465 }
466
2d262115 467 mw_data = (MainWindow *) g_object_get_data(G_OBJECT(mw),"main_window_data");
68b48a45 468 if(mw_data == NULL){
2eef04b5 469 g_warning("Main window data does not exist\n");
2d262115 470 return NULL;
561eba2a 471 }
68b48a45 472 return mw_data;
561eba2a 473}
474
abe346a3 475
476/* create_new_window function, just constructs a new main window
477 */
478
68b48a45 479void create_new_window(GtkWidget* widget, gpointer user_data, gboolean clone)
561eba2a 480{
bca3b81f 481 MainWindow * parent = get_window_data_struct(widget);
561eba2a 482
561eba2a 483 if(clone){
56e5a0f7 484 g_info("Clone : use the same traceset\n");
08b1c66e 485 construct_main_window(parent);
561eba2a 486 }else{
56e5a0f7 487 g_info("Empty : traceset is set to NULL\n");
08b1c66e 488 construct_main_window(NULL);
561eba2a 489 }
490}
491
0f9d55ef 492/* Get the currently focused viewer.
493 * If no viewer is focused, use the first one.
494 *
495 * If no viewer available, return NULL.
496 */
b052368a 497GtkWidget *viewer_container_focus(GtkWidget *container)
498{
499 GtkWidget *widget;
500
501 widget = (GtkWidget*)g_object_get_data(G_OBJECT(container),
bb574a9c 502 "focused_viewer");
b052368a 503
0f9d55ef 504 if(widget == NULL) {
505 g_debug("no widget focused");
506 GList *children = gtk_container_get_children(GTK_CONTAINER(container));
507
508 if(children != NULL)
509 widget = GTK_WIDGET(children->data);
bb574a9c 510 g_object_set_data(G_OBJECT(container),
511 "focused_viewer",
512 widget);
0f9d55ef 513 }
514
b052368a 515 return widget;
516
517
518}
519
520gint viewer_container_position(GtkWidget *container, GtkWidget *child)
521{
522
523 if(child == NULL) return -1;
524
525 gint pos;
2eef04b5 526 GValue value;
527 memset(&value, 0, sizeof(GValue));
b052368a 528 g_value_init(&value, G_TYPE_INT);
529 gtk_container_child_get_property(GTK_CONTAINER(container),
530 child,
531 "position",
532 &value);
533 pos = g_value_get_int(&value);
534
535 return pos;
536}
537
abe346a3 538
539/* move_*_viewer functions move the selected view up/down in
540 * the current tab
541 */
542
b052368a 543void move_down_viewer(GtkWidget * widget, gpointer user_data)
561eba2a 544{
6ced96ef 545 GtkWidget * notebook = lookup_widget(widget, "MNotebook");
546
547 GtkWidget *page = gtk_notebook_get_nth_page(GTK_NOTEBOOK(notebook),
548 gtk_notebook_get_current_page(GTK_NOTEBOOK(notebook)));
549
550 Tab *tab;
6ced96ef 551 if(!page) {
552 return;
553 } else {
e433e6d6 554 LttvPluginTab *ptab;
43ed82b5 555 ptab = g_object_get_data(G_OBJECT(page), "Tab_Plugin");
e433e6d6 556 tab = ptab->tab;
6ced96ef 557 }
558
b052368a 559 //gtk_multivpaned_widget_move_up(GTK_MULTIVPANED(tab->multivpaned));
560
561 /* change the position in the vbox */
562 GtkWidget *focus_widget;
563 gint position;
564 focus_widget = viewer_container_focus(tab->viewer_container);
565 position = viewer_container_position(tab->viewer_container, focus_widget);
566
567 if(position > 0) {
568 /* can move up one position */
569 gtk_box_reorder_child(GTK_BOX(tab->viewer_container),
570 focus_widget,
571 position-1);
572 }
573
561eba2a 574}
575
b052368a 576void move_up_viewer(GtkWidget * widget, gpointer user_data)
561eba2a 577{
6ced96ef 578 GtkWidget * notebook = lookup_widget(widget, "MNotebook");
579
580 GtkWidget *page = gtk_notebook_get_nth_page(GTK_NOTEBOOK(notebook),
581 gtk_notebook_get_current_page(GTK_NOTEBOOK(notebook)));
582 Tab *tab;
583
584 if(!page) {
585 return;
586 } else {
e433e6d6 587 LttvPluginTab *ptab;
588 ptab = (LttvPluginTab *)g_object_get_data(G_OBJECT(page), "Tab_Plugin");
589 tab = ptab->tab;
6ced96ef 590 }
591
b052368a 592 //gtk_multivpaned_widget_move_down(GTK_MULTIVPANED(tab->multivpaned));
593 /* change the position in the vbox */
594 GtkWidget *focus_widget;
595 gint position;
596 focus_widget = viewer_container_focus(tab->viewer_container);
597 position = viewer_container_position(tab->viewer_container, focus_widget);
598
599 if(position != -1 &&
600 position <
601 g_list_length(gtk_container_get_children(
602 GTK_CONTAINER(tab->viewer_container)))-1
603 ) {
604 /* can move down one position */
605 gtk_box_reorder_child(GTK_BOX(tab->viewer_container),
606 focus_widget,
607 position+1);
608 }
609
561eba2a 610}
611
abe346a3 612
613/* delete_viewer deletes the selected viewer in the current tab
614 */
615
561eba2a 616void delete_viewer(GtkWidget * widget, gpointer user_data)
617{
6ced96ef 618 GtkWidget * notebook = lookup_widget(widget, "MNotebook");
619
620 GtkWidget *page = gtk_notebook_get_nth_page(GTK_NOTEBOOK(notebook),
621 gtk_notebook_get_current_page(GTK_NOTEBOOK(notebook)));
622 Tab *tab;
623
624 if(!page) {
625 return;
626 } else {
e433e6d6 627 LttvPluginTab *ptab;
43ed82b5 628 ptab = g_object_get_data(G_OBJECT(page), "Tab_Plugin");
e433e6d6 629 tab = ptab->tab;
6ced96ef 630 }
631
b052368a 632 //gtk_multivpaned_widget_delete(GTK_MULTIVPANED(tab->multivpaned));
633
634 GtkWidget *focus_widget = viewer_container_focus(tab->viewer_container);
635
636 if(focus_widget != NULL)
637 gtk_widget_destroy(focus_widget);
638
639 g_object_set_data(G_OBJECT(tab->viewer_container), "focused_viewer", NULL);
561eba2a 640}
641
e865422c
YB
642#if UNFINISHED_FEATURE
643/* TODO ybrosseau 2012-03-15: Function is half implemented. Should be removed */
abe346a3 644/* open_traceset will open a traceset saved in a file
645 * Right now, it is not finished yet, (not working)
a43d67ba 646 * FIXME
abe346a3 647 */
648
561eba2a 649void open_traceset(GtkWidget * widget, gpointer user_data)
650{
2176f952 651 char ** dir;
652 gint id;
653 LttvTraceset * traceset;
bca3b81f 654 MainWindow * mw_data = get_window_data_struct(widget);
68b48a45 655 GtkFileSelection * file_selector =
2176f952 656 (GtkFileSelection *)gtk_file_selection_new("Select a traceset");
657
68b48a45 658 gtk_file_selection_hide_fileop_buttons(file_selector);
c64c7ea1 659
93ac601b 660 gtk_window_set_transient_for(GTK_WINDOW(file_selector),
661 GTK_WINDOW(mw_data->mwindow));
662
68b48a45 663 id = gtk_dialog_run(GTK_DIALOG(file_selector));
2176f952 664 switch(id){
665 case GTK_RESPONSE_ACCEPT:
666 case GTK_RESPONSE_OK:
68b48a45 667 dir = gtk_file_selection_get_selections (file_selector);
2176f952 668 traceset = lttv_traceset_load(dir[0]);
56e5a0f7 669 g_info("Open a trace set %s\n", dir[0]);
2176f952 670 //Not finished yet
671 g_strfreev(dir);
672 case GTK_RESPONSE_REJECT:
673 case GTK_RESPONSE_CANCEL:
674 default:
68b48a45 675 gtk_widget_destroy((GtkWidget*)file_selector);
2176f952 676 break;
677 }
c64c7ea1 678
561eba2a 679}
e865422c 680#endif
501e4e70 681/* lttvwindow_process_pending_requests
d389bc8d 682 *
683 * Process requests for parts of the trace from viewers.
684 *
685 * These requests are made by lttvwindow_events_request().
501e4e70 686 *
687 * This internal function gets called by g_idle, taking care of the pending
688 * requests. It is responsible for concatenation of time intervals and position
689 * requests. It does it with the following algorithm organizing process traceset
690 * calls. Here is the detailed description of the way it works :
691 *
692 * - Events Requests Servicing Algorithm
693 *
694 * Data structures necessary :
695 *
696 * List of requests added to context : list_in
697 * List of requests not added to context : list_out
698 *
699 * Initial state :
700 *
701 * list_in : empty
702 * list_out : many events requests
703 *
704 * FIXME : insert rest of algorithm here
705 *
abe346a3 706 */
707
6ea08962 708#define list_out tab->events_requests
a43d67ba 709
501e4e70 710gboolean lttvwindow_process_pending_requests(Tab *tab)
a8c0f09d 711{
ff5c41f1
YB
712
713 LttvTraceset *ts;
714
501e4e70 715 GSList *list_in = NULL;
716 LttTime end_time;
717 guint end_nb_events;
2d262115 718 guint count;
ff5c41f1 719 LttvTracesetPosition *end_position;
a43d67ba 720
3c456a8a 721 if(lttvwindow_preempt_count > 0) return TRUE;
722
b052368a 723 if(tab == NULL) {
724 g_critical("Foreground processing : tab does not exist. Processing removed.");
501e4e70 725 return FALSE;
b052368a 726 }
a43d67ba 727
501e4e70 728 /* There is no events requests pending : we should never have been called! */
6ea08962 729 g_assert(g_slist_length(list_out) != 0);
a43d67ba 730
ff5c41f1 731 ts = tab->traceset_info->traceset;
a8c0f09d 732
abe346a3 733 //set the cursor to be X shape, indicating that the computer is busy in doing its job
a0577796 734#if 0
a8c0f09d 735 new = gdk_cursor_new(GDK_X_CURSOR);
2d262115 736 widget = lookup_widget(tab->mw->mwindow, "MToolbar1");
a8c0f09d 737 win = gtk_widget_get_parent_window(widget);
738 gdk_window_set_cursor(win, new);
739 gdk_cursor_unref(new);
740 gdk_window_stick(win);
741 gdk_window_unstick(win);
a0577796 742#endif //0
a43d67ba 743
6ea08962 744 g_debug("SIZE events req len : %d", g_slist_length(list_out));
745
746 /* Preliminary check for no trace in traceset */
747 /* Unregister the routine if empty, empty list_out too */
ff5c41f1 748 if(lttv_traceset_number(ts) == 0) {
6ea08962 749
750 /* - For each req in list_out */
751 GSList *iter = list_out;
752
753 while(iter != NULL) {
754
755 gboolean remove = FALSE;
756 gboolean free_data = FALSE;
757 EventsRequest *events_request = (EventsRequest *)iter->data;
758
759 /* - Call end request for req */
760 if(events_request->servicing == TRUE)
ff5c41f1 761 lttv_hooks_call(events_request->after_request, (gpointer)ts);
6ea08962 762
763 /* - remove req from list_out */
764 /* Destroy the request */
765 remove = TRUE;
766 free_data = TRUE;
ff5c41f1 767 //TODO ybrosseau: This if is always true
6ea08962 768 /* Go to next */
769 if(remove)
770 {
771 GSList *remove_iter = iter;
772
773 iter = g_slist_next(iter);
b052368a 774 if(free_data) events_request_free((EventsRequest*)remove_iter->data);
6ea08962 775 list_out = g_slist_remove_link(list_out, remove_iter);
776 } else { // not remove
777 iter = g_slist_next(iter);
778 }
779 }
780 }
088f6772 781
b052368a 782 /* 0.1 Lock Traces */
783 {
784 guint iter_trace=0;
785
786 for(iter_trace=0;
ff5c41f1 787 iter_trace<lttv_traceset_number(ts);
b052368a 788 iter_trace++) {
ff5c41f1 789 LttvTrace *trace_v = lttv_traceset_get(ts, iter_trace);
b052368a 790
791 if(lttvwindowtraces_lock(trace_v) != 0) {
792 g_critical("Foreground processing : Unable to get trace lock");
793 return TRUE; /* Cannot get lock, try later */
794 }
795 }
796 }
797
798 /* 0.2 Seek tracefiles positions to context position */
ff5c41f1 799#ifdef BABEL_CLEANUP
088f6772 800 //g_assert(lttv_process_traceset_seek_position(tsc, sync_position) == 0);
b052368a 801 lttv_process_traceset_synchronize_tracefiles(tsc);
ff5c41f1 802#endif
b052368a 803
501e4e70 804 /* Events processing algorithm implementation */
dd316a11 805 /* Warning : the gtk_events_pending takes a LOT of cpu time. So what we do
806 * instead is to leave the control to GTK and take it back.
807 */
501e4e70 808 /* A. Servicing loop */
dd316a11 809 //while( (g_slist_length(list_in) != 0 || g_slist_length(list_out) != 0)) {
3bafb436 810 if((g_slist_length(list_in) != 0 || g_slist_length(list_out) != 0)) {
811 /* Servicing */
812 /* 1. If list_in is empty (need a seek) */
813 if( g_slist_length(list_in) == 0 ) {
501e4e70 814
3bafb436 815 /* list in is empty, need a seek */
dd316a11 816 {
3bafb436 817 /* 1.1 Add requests to list_in */
818 GSList *ltime = NULL;
819 GSList *lpos = NULL;
820 GSList *iter = NULL;
501e4e70 821
3bafb436 822 /* 1.1.1 Find all time requests with the lowest start time in list_out
823 * (ltime)
824 */
825 if(g_slist_length(list_out) > 0)
826 ltime = g_slist_append(ltime, g_slist_nth_data(list_out, 0));
827 for(iter=g_slist_nth(list_out,1);iter!=NULL;iter=g_slist_next(iter)) {
828 /* Find all time requests with the lowest start time in list_out */
3bafb436 829 EventsRequest *event_request_ltime = (EventsRequest*)g_slist_nth_data(ltime, 0);
830 EventsRequest *event_request_list_out = (EventsRequest*)iter->data;
831
832 int comp;
833 comp = ltt_time_compare(event_request_ltime->start_time,
834 event_request_list_out->start_time);
835 if(comp == 0)
836 ltime = g_slist_append(ltime, event_request_list_out);
837 else if(comp > 0) {
838 /* Remove all elements from ltime, and add current */
839 while(ltime != NULL)
840 ltime = g_slist_delete_link(ltime, g_slist_nth(ltime, 0));
841 ltime = g_slist_append(ltime, event_request_list_out);
842 }
501e4e70 843 }
844
3bafb436 845 /* 1.1.2 Find all position requests with the lowest position in list_out
846 * (lpos)
847 */
848 if(g_slist_length(list_out) > 0)
849 lpos = g_slist_append(lpos, g_slist_nth_data(list_out, 0));
850 for(iter=g_slist_nth(list_out,1);iter!=NULL;iter=g_slist_next(iter)) {
851 /* Find all position requests with the lowest position in list_out */
852 EventsRequest *event_request_lpos = (EventsRequest*)g_slist_nth_data(lpos, 0);
853 EventsRequest *event_request_list_out = (EventsRequest*)iter->data;
854
855 int comp;
856 if(event_request_lpos->start_position != NULL
857 && event_request_list_out->start_position != NULL)
858 {
ff5c41f1
YB
859 //TODO ybrosseau: this compare is in fact an equal, so the behavior might not be right.
860 comp = lttv_traceset_position_time_compare
3bafb436 861 (event_request_lpos->start_position,
862 event_request_list_out->start_position);
863 } else {
864 comp = -1;
553d1e7b 865 }
3bafb436 866 if(comp == 0)
867 lpos = g_slist_append(lpos, event_request_list_out);
868 else if(comp > 0) {
869 /* Remove all elements from lpos, and add current */
870 while(lpos != NULL)
871 lpos = g_slist_delete_link(lpos, g_slist_nth(lpos, 0));
872 lpos = g_slist_append(lpos, event_request_list_out);
501e4e70 873 }
874 }
3bafb436 875
876 {
877 EventsRequest *event_request_lpos = (EventsRequest*)g_slist_nth_data(lpos, 0);
878 EventsRequest *event_request_ltime = (EventsRequest*)g_slist_nth_data(ltime, 0);
879 LttTime lpos_start_time;
dd316a11 880
3bafb436 881 if(event_request_lpos != NULL
882 && event_request_lpos->start_position != NULL) {
ff5c41f1 883 lpos_start_time = lttv_traceset_position_get_time(
3bafb436 884 event_request_lpos->start_position);
885 }
886
887 /* 1.1.3 If lpos.start time < ltime */
888 if(event_request_lpos != NULL
889 && event_request_lpos->start_position != NULL
890 && ltt_time_compare(lpos_start_time,
891 event_request_ltime->start_time)<0) {
892 /* Add lpos to list_in, remove them from list_out */
893 for(iter=lpos;iter!=NULL;iter=g_slist_next(iter)) {
894 /* Add to list_in */
895 EventsRequest *event_request_lpos =
896 (EventsRequest*)iter->data;
897
898 list_in = g_slist_append(list_in, event_request_lpos);
899 /* Remove from list_out */
900 list_out = g_slist_remove(list_out, event_request_lpos);
901 }
902 } else {
903 /* 1.1.4 (lpos.start time >= ltime) */
904 /* Add ltime to list_in, remove them from list_out */
905
906 for(iter=ltime;iter!=NULL;iter=g_slist_next(iter)) {
907 /* Add to list_in */
908 EventsRequest *event_request_ltime =
909 (EventsRequest*)iter->data;
910
911 list_in = g_slist_append(list_in, event_request_ltime);
912 /* Remove from list_out */
913 list_out = g_slist_remove(list_out, event_request_ltime);
914 }
915 }
dd316a11 916 }
3bafb436 917 g_slist_free(lpos);
918 g_slist_free(ltime);
dd316a11 919 }
dd316a11 920
3bafb436 921 /* 1.2 Seek */
922 {
ff5c41f1 923
3bafb436 924 g_assert(g_slist_length(list_in)>0);
925 EventsRequest *events_request = g_slist_nth_data(list_in, 0);
e865422c 926#ifdef DEBUG
3bafb436 927 guint seek_count;
e865422c 928#endif
3bafb436 929
930 /* 1.2.1 If first request in list_in is a time request */
931 if(events_request->start_position == NULL) {
932 /* - If first req in list_in start time != current time */
ff5c41f1
YB
933 //TODO ybrosseau: if commented out, since it was only affecting the g_debug
934 //if(tfc == NULL || ltt_time_compare(events_request->start_time,
935 // tfc->timestamp) != 0)
3bafb436 936 /* - Seek to that time */
937 g_debug("SEEK TIME : %lu, %lu", events_request->start_time.tv_sec,
938 events_request->start_time.tv_nsec);
939 //lttv_process_traceset_seek_time(tsc, events_request->start_time);
ff5c41f1 940 lttv_process_traceset_seek_time(ts,
3bafb436 941 events_request->start_time);
942
943 /* Process the traceset with only state hooks */
e865422c 944#ifdef DEBUG
3bafb436 945 seek_count =
e865422c 946#endif //DEBUG
ff5c41f1 947 lttv_process_traceset_middle(ts,
3bafb436 948 events_request->start_time,
949 G_MAXUINT, NULL);
f4b88a7d 950#ifdef DEBUG
951 g_assert(seek_count < LTTV_STATE_SAVE_INTERVAL);
952#endif //DEBUG
6ea08962 953
a43d67ba 954
3bafb436 955 } else {
ff5c41f1
YB
956 //LttTime pos_time;
957 //LttvTracefileContext *tfc =
958 // lttv_traceset_context_get_current_tfc(tsc);
3bafb436 959 /* Else, the first request in list_in is a position request */
960 /* If first req in list_in pos != current pos */
961 g_assert(events_request->start_position != NULL);
962 g_debug("SEEK POS time : %lu, %lu",
ff5c41f1 963 lttv_traceset_position_get_time(
3bafb436 964 events_request->start_position).tv_sec,
ff5c41f1 965 lttv_traceset_position_get_time(
3bafb436 966 events_request->start_position).tv_nsec);
2a7a425c 967
ff5c41f1
YB
968 /*if(tfc) {*/ if(0) {
969 /* g_debug("SEEK POS context time : %lu, %lu",
970 tfc->timestamp.tv_sec,
971 tfc->timestamp.tv_nsec); */
2a7a425c 972 } else {
973 g_debug("SEEK POS context time : %lu, %lu",
974 ltt_time_infinite.tv_sec,
975 ltt_time_infinite.tv_nsec);
976 }
3bafb436 977 g_assert(events_request->start_position != NULL);
ff5c41f1
YB
978 //TODO ybrosseau: for now, always seek
979 if(/*lttv_traceset_context_ctx_pos_compare(tsc,
980 events_request->start_position) != 0*/1) {
3bafb436 981 /* 1.2.2.1 Seek to that position */
982 g_debug("SEEK POSITION");
983 //lttv_process_traceset_seek_position(tsc, events_request->start_position);
ff5c41f1
YB
984 //pos_time = lttv_traceset_position_get_time(
985 // events_request->start_position);
986 //
987 //lttv_state_traceset_seek_time(ts,
988 // pos_time);
989 lttv_traceset_seek_to_position( events_request->start_position);
3bafb436 990
991 /* Process the traceset with only state hooks */
e865422c 992#ifdef DEBUG
3bafb436 993 seek_count =
9a366873 994
ff5c41f1 995 lttv_process_traceset_middle(ts,
3bafb436 996 ltt_time_infinite,
997 G_MAXUINT,
998 events_request->start_position);
9a366873 999#endif
ff5c41f1
YB
1000 //g_assert(lttv_traceset_context_ctx_pos_compare(tsc,
1001 // events_request->start_position) == 0);
dd316a11 1002
dd316a11 1003
3bafb436 1004 }
1005 }
1006 }
2d262115 1007
3bafb436 1008 /* 1.3 Add hooks and call before request for all list_in members */
1009 {
1010 GSList *iter = NULL;
dd316a11 1011
3bafb436 1012 for(iter=list_in;iter!=NULL;iter=g_slist_next(iter)) {
1013 EventsRequest *events_request = (EventsRequest*)iter->data;
1014 /* 1.3.1 If !servicing */
2d262115 1015 if(events_request->servicing == FALSE) {
1016 /* - begin request hooks called
1017 * - servicing = TRUE
1018 */
ff5c41f1 1019 lttv_hooks_call(events_request->before_request, (gpointer)ts);
2d262115 1020 events_request->servicing = TRUE;
1021 }
3bafb436 1022 /* 1.3.2 call before chunk
1023 * 1.3.3 events hooks added
2d262115 1024 */
ff5c41f1
YB
1025 //TODO ybrosseau 2012-07-10: || TRUE added since we only support
1026 // traceset wide requests
1027 if(events_request->trace == -1 || TRUE)
1028 lttv_process_traceset_begin(ts,
54d8f654 1029 events_request->before_chunk_traceset,
1030 events_request->before_chunk_trace,
ff5c41f1
YB
1031 events_request->event
1032 );
54d8f654 1033 else {
ff5c41f1 1034 guint nb_trace = lttv_traceset_number(ts);
2eef04b5 1035 g_assert((guint)events_request->trace < nb_trace &&
54d8f654 1036 events_request->trace > -1);
ff5c41f1 1037 LttvTrace *trace = lttv_traceset_get(ts, events_request->trace);
54d8f654 1038
ff5c41f1 1039 lttv_hooks_call(events_request->before_chunk_traceset, ts);
54d8f654 1040
ff5c41f1 1041 lttv_trace_add_hooks(trace,
54d8f654 1042 events_request->before_chunk_trace,
ff5c41f1
YB
1043
1044 events_request->event
1045 );
54d8f654 1046 }
501e4e70 1047 }
3bafb436 1048 }
1049 } else {
1050 /* 2. Else, list_in is not empty, we continue a read */
1051
1052 {
1053 /* 2.0 For each req of list_in */
1054 GSList *iter = list_in;
1055
1056 while(iter != NULL) {
2d262115 1057
3bafb436 1058 EventsRequest *events_request = (EventsRequest *)iter->data;
1059
1060 /* - Call before chunk
1061 * - events hooks added
1062 */
ff5c41f1
YB
1063 //TODO ybrosseau 2012-07-10: || TRUE added since we only support
1064 // traceset wide requests
1065 if(events_request->trace == -1 || TRUE)
1066 lttv_process_traceset_begin(ts,
54d8f654 1067 events_request->before_chunk_traceset,
1068 events_request->before_chunk_trace,
ff5c41f1
YB
1069 events_request->event
1070 );
54d8f654 1071 else {
ff5c41f1 1072 guint nb_trace = lttv_traceset_number(ts);
2eef04b5 1073 g_assert((guint)events_request->trace < nb_trace &&
54d8f654 1074 events_request->trace > -1);
ff5c41f1 1075 LttvTrace *trace = lttv_traceset_get(ts, events_request->trace);
54d8f654 1076
ff5c41f1 1077 lttv_hooks_call(events_request->before_chunk_traceset, ts);
54d8f654 1078
ff5c41f1 1079 lttv_trace_add_hooks(trace,
3bafb436 1080 events_request->before_chunk_trace,
ff5c41f1
YB
1081
1082 events_request->event
1083 );
54d8f654 1084 }
6ea08962 1085
1086 iter = g_slist_next(iter);
1087 }
1088 }
1089
3bafb436 1090 {
ff5c41f1 1091
3bafb436 1092
1093 /* 2.1 For each req of list_out */
1094 GSList *iter = list_out;
553d1e7b 1095
3bafb436 1096 while(iter != NULL) {
6ea08962 1097
3bafb436 1098 gboolean remove = FALSE;
1099 gboolean free_data = FALSE;
1100 EventsRequest *events_request = (EventsRequest *)iter->data;
1101
1102 /* if req.start time == current context time
1103 * or req.start position == current position*/
ff5c41f1 1104 /* if( ltt_time_compare(events_request->start_time,
3bafb436 1105 tfc->timestamp) == 0
1106 ||
1107 (events_request->start_position != NULL
1108 &&
1109 lttv_traceset_context_ctx_pos_compare(tsc,
1110 events_request->start_position) == 0)
1111 ) {
ff5c41f1
YB
1112 */
1113 if(lttv_traceset_position_compare_current(ts, events_request->start_position) == 0) {
1114
3bafb436 1115 /* - Add to list_in, remove from list_out */
1116 list_in = g_slist_append(list_in, events_request);
1117 remove = TRUE;
1118 free_data = FALSE;
1119
1120 /* - If !servicing */
1121 if(events_request->servicing == FALSE) {
1122 /* - begin request hooks called
1123 * - servicing = TRUE
1124 */
ff5c41f1 1125 lttv_hooks_call(events_request->before_request, (gpointer)ts);
3bafb436 1126 events_request->servicing = TRUE;
1127 }
1128 /* call before chunk
1129 * events hooks added
1130 */
ff5c41f1
YB
1131 //TODO ybrosseau 2012-07-10: || TRUE added since we only support
1132 // traceset wide requests
1133 if(events_request->trace == -1 || TRUE)
1134 lttv_process_traceset_begin(ts,
54d8f654 1135 events_request->before_chunk_traceset,
1136 events_request->before_chunk_trace,
ff5c41f1
YB
1137 events_request->event
1138 );
54d8f654 1139 else {
ff5c41f1 1140 guint nb_trace = lttv_traceset_number(ts);
2eef04b5 1141 g_assert((guint)events_request->trace < nb_trace &&
54d8f654 1142 events_request->trace > -1);
ff5c41f1 1143 LttvTrace* trace = lttv_traceset_get(ts,events_request->trace);
54d8f654 1144
ff5c41f1 1145 lttv_hooks_call(events_request->before_chunk_traceset, ts);
54d8f654 1146
ff5c41f1
YB
1147 lttv_trace_add_hooks(trace,
1148 events_request->before_chunk_trace,
1149
1150 events_request->event);
1151
54d8f654 1152 }
1153
1154
3bafb436 1155 }
501e4e70 1156
3bafb436 1157 /* Go to next */
1158 if(remove)
1159 {
1160 GSList *remove_iter = iter;
2d262115 1161
3bafb436 1162 iter = g_slist_next(iter);
1163 if(free_data) events_request_free((EventsRequest*)remove_iter->data);
1164 list_out = g_slist_remove_link(list_out, remove_iter);
1165 } else { // not remove
1166 iter = g_slist_next(iter);
1167 }
1168 }
1169 }
1170 }
8f2872f4 1171
3bafb436 1172 /* 3. Find end criterions */
1173 {
1174 /* 3.1 End time */
1175 GSList *iter;
1176
1177 /* 3.1.1 Find lowest end time in list_in */
1178 g_assert(g_slist_length(list_in)>0);
1179 end_time = ((EventsRequest*)g_slist_nth_data(list_in,0))->end_time;
1180
1181 for(iter=g_slist_nth(list_in,1);iter!=NULL;iter=g_slist_next(iter)) {
1182 EventsRequest *events_request = (EventsRequest*)iter->data;
501e4e70 1183
3bafb436 1184 if(ltt_time_compare(events_request->end_time,
1185 end_time) < 0)
1186 end_time = events_request->end_time;
1187 }
1188
1189 /* 3.1.2 Find lowest start time in list_out */
1190 for(iter=list_out;iter!=NULL;iter=g_slist_next(iter)) {
1191 EventsRequest *events_request = (EventsRequest*)iter->data;
2d262115 1192
3bafb436 1193 if(ltt_time_compare(events_request->start_time,
1194 end_time) < 0)
1195 end_time = events_request->start_time;
1196 }
501e4e70 1197 }
1198
3bafb436 1199 {
1200 /* 3.2 Number of events */
dd316a11 1201
3bafb436 1202 /* 3.2.1 Find lowest number of events in list_in */
1203 GSList *iter;
501e4e70 1204
3bafb436 1205 end_nb_events = ((EventsRequest*)g_slist_nth_data(list_in,0))->num_events;
501e4e70 1206
3bafb436 1207 for(iter=g_slist_nth(list_in,1);iter!=NULL;iter=g_slist_next(iter)) {
1208 EventsRequest *events_request = (EventsRequest*)iter->data;
501e4e70 1209
3bafb436 1210 if(events_request->num_events < end_nb_events)
1211 end_nb_events = events_request->num_events;
1212 }
501e4e70 1213
3bafb436 1214 /* 3.2.2 Use min(CHUNK_NUM_EVENTS, min num events in list_in) as
1215 * num_events */
1216
1217 end_nb_events = MIN(CHUNK_NUM_EVENTS, end_nb_events);
501e4e70 1218 }
501e4e70 1219
3bafb436 1220 {
1221 /* 3.3 End position */
501e4e70 1222
3bafb436 1223 /* 3.3.1 Find lowest end position in list_in */
1224 GSList *iter;
6ea08962 1225
3bafb436 1226 end_position =((EventsRequest*)g_slist_nth_data(list_in,0))->end_position;
6ea08962 1227
3bafb436 1228 for(iter=g_slist_nth(list_in,1);iter!=NULL;iter=g_slist_next(iter)) {
1229 EventsRequest *events_request = (EventsRequest*)iter->data;
dd316a11 1230
3bafb436 1231 if(events_request->end_position != NULL && end_position != NULL &&
ff5c41f1 1232 lttv_traceset_position_time_compare(events_request->end_position,
3bafb436 1233 end_position) <0)
1234 end_position = events_request->end_position;
1235 }
1236 }
1237
1238 {
1239 /* 3.3.2 Find lowest start position in list_out */
1240 GSList *iter;
dd316a11 1241
3bafb436 1242 for(iter=list_out;iter!=NULL;iter=g_slist_next(iter)) {
1243 EventsRequest *events_request = (EventsRequest*)iter->data;
dd316a11 1244
3bafb436 1245 if(events_request->end_position != NULL && end_position != NULL &&
ff5c41f1 1246 lttv_traceset_position_time_compare(events_request->end_position,
3bafb436 1247 end_position) <0)
1248 end_position = events_request->end_position;
dd316a11 1249 }
2d262115 1250 }
3bafb436 1251
2d262115 1252 {
3bafb436 1253 /* 4. Call process traceset middle */
ff5c41f1
YB
1254 g_debug("Calling process traceset middle with %p, %lu sec %lu nsec, %u nb ev, %p end pos", ts, end_time.tv_sec, end_time.tv_nsec, end_nb_events, end_position);
1255 count = lttv_process_traceset_middle(ts, end_time, end_nb_events, end_position);
2d262115 1256
ff5c41f1 1257#ifdef BABEL_CLEANUP
3bafb436 1258 tfc = lttv_traceset_context_get_current_tfc(tsc);
1259 if(tfc != NULL)
1260 g_debug("Context time after middle : %lu, %lu", tfc->timestamp.tv_sec,
1261 tfc->timestamp.tv_nsec);
1262 else
1263 g_debug("End of trace reached after middle.");
ff5c41f1 1264#endif
3bafb436 1265 }
ff5c41f1 1266
3bafb436 1267 {
1268 /* 5. After process traceset middle */
3bafb436 1269
ff5c41f1 1270 LttTime curTime = lttv_traceset_get_current_time(ts);
3bafb436 1271 /* - if current context time > traceset.end time */
ff5c41f1
YB
1272 if(ltt_time_compare(curTime,
1273 lttv_traceset_get_time_span_real(ts).end_time) > 0) {
3bafb436 1274 /* - For each req in list_in */
1275 GSList *iter = list_in;
1276
1277 while(iter != NULL) {
1278
1279 gboolean remove = FALSE;
1280 gboolean free_data = FALSE;
1281 EventsRequest *events_request = (EventsRequest *)iter->data;
1282
1283 /* - Remove events hooks for req
1284 * - Call end chunk for req
1285 */
ff5c41f1
YB
1286 //TODO ybrosseau 2012-07-10: || TRUE added since we only support
1287 // traceset wide requests
1288 if(events_request->trace == -1 || TRUE)
1289 lttv_process_traceset_end(ts,
54d8f654 1290 events_request->after_chunk_traceset,
3bafb436 1291 events_request->after_chunk_trace,
ff5c41f1
YB
1292
1293 events_request->event);
54d8f654 1294
1295 else {
ff5c41f1 1296 guint nb_trace = lttv_traceset_number(ts);
54d8f654 1297 g_assert(events_request->trace < nb_trace &&
1298 events_request->trace > -1);
ff5c41f1 1299 LttvTrace *trace = lttv_traceset_get(ts,events_request->trace);
54d8f654 1300
ff5c41f1 1301 lttv_trace_remove_hooks(trace,
54d8f654 1302 events_request->after_chunk_trace,
ff5c41f1
YB
1303
1304 events_request->event);
1305
1306 lttv_hooks_call(events_request->after_chunk_traceset, ts);
54d8f654 1307
1308
1309 }
1310
3bafb436 1311 /* - Call end request for req */
ff5c41f1 1312 lttv_hooks_call(events_request->after_request, (gpointer)ts);
3bafb436 1313
2d262115 1314 /* - remove req from list_in */
1315 /* Destroy the request */
1316 remove = TRUE;
1317 free_data = TRUE;
3bafb436 1318
1319 /* Go to next */
1320 if(remove)
1321 {
1322 GSList *remove_iter = iter;
1323
1324 iter = g_slist_next(iter);
1325 if(free_data) events_request_free((EventsRequest*)remove_iter->data);
1326 list_in = g_slist_remove_link(list_in, remove_iter);
1327 } else { // not remove
1328 iter = g_slist_next(iter);
1329 }
2d262115 1330 }
3bafb436 1331 }
1332 {
1333 /* 5.1 For each req in list_in */
1334 GSList *iter = list_in;
1335
1336 while(iter != NULL) {
501e4e70 1337
3bafb436 1338 gboolean remove = FALSE;
1339 gboolean free_data = FALSE;
1340 EventsRequest *events_request = (EventsRequest *)iter->data;
1341
1342 /* - Remove events hooks for req
1343 * - Call end chunk for req
1344 */
ff5c41f1
YB
1345 //TODO ybrosseau 2012-07-10: || TRUE added since we only support
1346 // traceset wide requests
1347 if(events_request->trace == -1 || TRUE)
1348 lttv_process_traceset_end(ts,
54d8f654 1349 events_request->after_chunk_traceset,
3bafb436 1350 events_request->after_chunk_trace,
ff5c41f1
YB
1351
1352 events_request->event);
1353
3bafb436 1354
54d8f654 1355 else {
ff5c41f1 1356 guint nb_trace = lttv_traceset_number(ts);
54d8f654 1357 g_assert(events_request->trace < nb_trace &&
1358 events_request->trace > -1);
ff5c41f1 1359 LttvTrace *trace = lttv_traceset_get(ts, events_request->trace);
54d8f654 1360
ff5c41f1 1361 lttv_trace_remove_hooks(trace,
54d8f654 1362 events_request->after_chunk_trace,
54d8f654 1363
ff5c41f1
YB
1364 events_request->event);
1365
1366
1367 lttv_hooks_call(events_request->after_chunk_traceset, ts);
54d8f654 1368 }
1369
3bafb436 1370 /* - req.num -= count */
1371 g_assert(events_request->num_events >= count);
1372 events_request->num_events -= count;
1373
ff5c41f1 1374 //g_assert(tfc != NULL);
3bafb436 1375 /* - if req.num == 0
1376 * or
1377 * current context time >= req.end time
1378 * or
1379 * req.end pos == current pos
1380 * or
1381 * req.stop_flag == TRUE
1382 */
1383 if( events_request->num_events == 0
1384 ||
1385 events_request->stop_flag == TRUE
1386 ||
ff5c41f1 1387 ltt_time_compare(lttv_traceset_get_current_time(ts),
3bafb436 1388 events_request->end_time) >= 0
1389 ||
1390 (events_request->end_position != NULL
1391 &&
ff5c41f1 1392 lttv_traceset_position_compare_current(ts,
3bafb436 1393 events_request->end_position) == 0)
1394
1395 ) {
1396 g_assert(events_request->servicing == TRUE);
1397 /* - Call end request for req
1398 * - remove req from list_in */
ff5c41f1 1399 lttv_hooks_call(events_request->after_request, (gpointer)ts);
3bafb436 1400 /* - remove req from list_in */
1401 /* Destroy the request */
1402 remove = TRUE;
1403 free_data = TRUE;
1404 }
1405
1406 /* Go to next */
1407 if(remove)
1408 {
1409 GSList *remove_iter = iter;
1410
1411 iter = g_slist_next(iter);
1412 if(free_data) events_request_free((EventsRequest*)remove_iter->data);
1413 list_in = g_slist_remove_link(list_in, remove_iter);
1414 } else { // not remove
1415 iter = g_slist_next(iter);
1416 }
2d262115 1417 }
1418 }
1419 }
501e4e70 1420 }
dd316a11 1421 /* End of removed servicing loop : leave control to GTK instead. */
1422 // if(gtk_events_pending()) break;
1423 //}
1424
2d262115 1425 /* B. When interrupted between chunks */
501e4e70 1426
501e4e70 1427 {
1428 GSList *iter = list_in;
1429
2d262115 1430 /* 1. for each request in list_in */
501e4e70 1431 while(iter != NULL) {
1432
1433 gboolean remove = FALSE;
1434 gboolean free_data = FALSE;
2d262115 1435 EventsRequest *events_request = (EventsRequest *)iter->data;
501e4e70 1436
1437 /* 1.1. Use current postition as start position */
a1a2b649 1438 if(events_request->start_position != NULL)
ff5c41f1
YB
1439 lttv_traceset_destroy_position(events_request->start_position);
1440 events_request->start_position = lttv_traceset_create_current_position(ts);
1441
501e4e70 1442
1443 /* 1.2. Remove start time */
0aa6c3a1 1444 events_request->start_time = ltt_time_infinite;
501e4e70 1445
2d262115 1446 /* 1.3. Move from list_in to list_out */
501e4e70 1447 remove = TRUE;
1448 free_data = FALSE;
1449 list_out = g_slist_append(list_out, events_request);
1450
501e4e70 1451 /* Go to next */
1452 if(remove)
8f2872f4 1453 {
501e4e70 1454 GSList *remove_iter = iter;
1455
1456 iter = g_slist_next(iter);
b052368a 1457 if(free_data) events_request_free((EventsRequest*)remove_iter->data);
501e4e70 1458 list_in = g_slist_remove_link(list_in, remove_iter);
1459 } else { // not remove
1460 iter = g_slist_next(iter);
8f2872f4 1461 }
1462 }
a43d67ba 1463
501e4e70 1464
1465 }
b052368a 1466 /* C Unlock Traces */
1467 {
ff5c41f1 1468#ifdef BABEL_CLEANUP
088f6772 1469 lttv_process_traceset_get_sync_data(tsc);
ff5c41f1 1470#endif
088f6772 1471 //lttv_traceset_context_position_save(tsc, sync_position);
b052368a 1472
1473 guint iter_trace;
1474
1475 for(iter_trace=0;
ff5c41f1 1476 iter_trace<lttv_traceset_number(ts);
b052368a 1477 iter_trace++) {
ff5c41f1 1478 LttvTrace *trace_v = lttv_traceset_get(ts, iter_trace);
b052368a 1479
1480 lttvwindowtraces_unlock(trace_v);
1481 }
1482 }
a0577796 1483#if 0
abe346a3 1484 //set the cursor back to normal
a8c0f09d 1485 gdk_window_set_cursor(win, NULL);
a0577796 1486#endif //0
501e4e70 1487
2d262115 1488 g_assert(g_slist_length(list_in) == 0);
6ea08962 1489
2d262115 1490 if( g_slist_length(list_out) == 0 ) {
501e4e70 1491 /* Put tab's request pending flag back to normal */
2d262115 1492 tab->events_request_pending = FALSE;
b052368a 1493 g_debug("remove the idle fct");
501e4e70 1494 return FALSE; /* Remove the idle function */
1495 }
b052368a 1496 g_debug("leave the idle fct");
501e4e70 1497 return TRUE; /* Leave the idle function */
b052368a 1498
1499 /* We do not use simili-round-robin, it may require to read 1 meg buffers
1500 * again and again if many tracesets use the same tracefiles. */
1501 /* Hack for round-robin idle functions */
1502 /* It will put the idle function at the end of the pool */
1503 /*g_idle_add_full((G_PRIORITY_HIGH_IDLE + 21),
1504 (GSourceFunc)execute_events_requests,
1505 tab,
1506 NULL);
1507 return FALSE;
1508 */
451aaf27 1509
ff5c41f1 1510
202f6c8f 1511}
1512
6ea08962 1513#undef list_out
1e3594a3
YB
1514/**
1515 Manage the periodic update of a live trace
1516*/
1517static gboolean
1518live_trace_update_handler(Tab *tab)
1519{
451aaf27 1520#ifdef BABEL_CLEANUP
9a366873 1521 unsigned int updated_count;
1e3594a3
YB
1522 LttvTracesetContext *tsc = LTTV_TRACESET_CONTEXT(tab->traceset_info->traceset_context);
1523 TimeInterval initial_time_span = tsc->time_span;
1524 TimeInterval updated_time_span;
1525
1526 updated_count = lttv_process_traceset_update(tsc);
1527
1528 /* TODO ybrosseau 2011-01-12: Add trace resynchronization */
501e4e70 1529
1e3594a3
YB
1530 /* Get the changed period bounds */
1531 updated_time_span = tsc->time_span;
1532
1533 if(ltt_time_compare(updated_time_span.start_time,
1534 initial_time_span.start_time) != 0) {
1535 /* The initial time should not change on a live update */
1536 g_assert(FALSE);
1537 }
1538
1539 /* Notify viewers (only on updates) */
1540 if(ltt_time_compare(updated_time_span.end_time,
1541 initial_time_span.end_time) != 0) {
1542
1543 notify_time_span_changed(tab);
1544 /* TODO ybrosseau 2011-01-12: Change the timebar to register
1545 to the time_span hook */
1546 timebar_set_minmax_time(TIMEBAR(tab->MTimebar),
1547 &updated_time_span.start_time,
1548 &updated_time_span.end_time );
1549
1550 /* To update the min max */
1551 time_change_manager(tab, tab->time_window);
1552 }
1553
1554 /* Timer will be recalled as long as there is files to update */
1555 return (updated_count > 0);
451aaf27 1556#endif /* BABEL_CLEANUP */
1e3594a3 1557}
abe346a3 1558
4266dc7f 1559static void lttvwindow_add_trace(Tab *tab, LttvTrace *trace_v)
1560{
9a366873 1561#ifdef BABEL_CLEANUP
4266dc7f 1562 LttvTraceset *traceset = tab->traceset_info->traceset;
1563 guint i;
91fd6881 1564 guint num_traces = lttv_traceset_number(traceset);
4266dc7f 1565
a1a2b649 1566 //Verify if trace is already present.
91fd6881 1567 for(i=0; i<num_traces; i++)
a1a2b649 1568 {
1569 LttvTrace * trace = lttv_traceset_get(traceset, i);
1570 if(trace == trace_v)
1571 return;
1572 }
1573
4266dc7f 1574 //Keep a reference to the traces so they are not freed.
1575 for(i=0; i<lttv_traceset_number(traceset); i++)
1576 {
1577 LttvTrace * trace = lttv_traceset_get(traceset, i);
1578 lttv_trace_ref(trace);
1579 }
1580
1581 //remove state update hooks
1582 lttv_state_remove_event_hooks(
1583 (LttvTracesetState*)tab->traceset_info->traceset_context);
1584
1585 lttv_context_fini(LTTV_TRACESET_CONTEXT(
1586 tab->traceset_info->traceset_context));
1587 g_object_unref(tab->traceset_info->traceset_context);
1588
1589 lttv_traceset_add(traceset, trace_v);
a1a2b649 1590 lttv_trace_ref(trace_v); /* local ref */
4266dc7f 1591
1592 /* Create new context */
1593 tab->traceset_info->traceset_context =
1594 g_object_new(LTTV_TRACESET_STATS_TYPE, NULL);
1595 lttv_context_init(
1596 LTTV_TRACESET_CONTEXT(tab->traceset_info->
1597 traceset_context),
1598 traceset);
6ea08962 1599
6ea08962 1600
4266dc7f 1601 //add state update hooks
1602 lttv_state_add_event_hooks(
1603 (LttvTracesetState*)tab->traceset_info->traceset_context);
1604 //Remove local reference to the traces.
1605 for(i=0; i<lttv_traceset_number(traceset); i++)
1606 {
1607 LttvTrace * trace = lttv_traceset_get(traceset, i);
1608 lttv_trace_unref(trace);
1609 }
1610
b052368a 1611 //FIXME
1612 //add_trace_into_traceset_selector(GTK_MULTIVPANED(tab->multivpaned), lttv_trace(trace_v));
1e3594a3
YB
1613
1614
1615 if (lttv_trace(trace_v)->is_live) {
1616 /* Add timer for live update */
1617 /* TODO ybrosseau 2011-01-12: Parametrize the hardcoded 1 seconds */
1618 g_timeout_add_seconds (1,
1619 (GSourceFunc) live_trace_update_handler,
1620 tab);
1621 }
451aaf27 1622#endif /* BABEL_CLEANUP */
4266dc7f 1623}
1624
abe346a3 1625/* add_trace adds a trace into the current traceset. It first displays a
1626 * directory selection dialogue to let user choose a trace, then recreates
1627 * tracset_context, and redraws all the viewer of the current tab
1628 */
1629
561eba2a 1630void add_trace(GtkWidget * widget, gpointer user_data)
1631{
861fbe5f 1632
deb3d2f8 1633 LttvTraceset * traceset = NULL;
861fbe5f 1634 const char * path;
a1a2b649 1635 char abs_path[PATH_MAX];
2176f952 1636 gint id;
bca3b81f 1637 MainWindow * mw_data = get_window_data_struct(widget);
6ced96ef 1638 GtkWidget * notebook = lookup_widget(widget, "MNotebook");
1639
1640 GtkWidget *page = gtk_notebook_get_nth_page(GTK_NOTEBOOK(notebook),
1641 gtk_notebook_get_current_page(GTK_NOTEBOOK(notebook)));
e433e6d6 1642 LttvPluginTab *ptab;
6ced96ef 1643 Tab *tab;
1644
1645 if(!page) {
e433e6d6 1646 ptab = create_new_tab(widget, NULL);
1647 tab = ptab->tab;
6ced96ef 1648 } else {
e433e6d6 1649 ptab = (LttvPluginTab *)g_object_get_data(G_OBJECT(page), "Tab_Plugin");
1650 tab = ptab->tab;
6ced96ef 1651 }
1167062f 1652//TODO fdeslauriers 2012-07-06: Remove this popup when we support multiple traces
deb3d2f8 1653 traceset = lttvwindow_get_traceset(tab);
95544594 1654 if(traceset != NULL && lttv_traceset_number(traceset) > 0){
deb3d2f8
FD
1655 GtkWidget *dialogue =
1656 gtk_message_dialog_new(
1657 GTK_WINDOW(gtk_widget_get_toplevel(widget)),
1658 GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT,
1659 GTK_MESSAGE_ERROR,
1660 GTK_BUTTONS_OK,
1661 "Loading multiple traces is not supported at the moment.");
1662 gtk_dialog_run(GTK_DIALOG(dialogue));
1663 gtk_widget_destroy(dialogue);
1664 return;
1665 }
1666
861fbe5f
FD
1667 /* Create a new traceset*/
1668 traceset = lttv_traceset_new();
ba013432 1669 /* File open dialog management */
95544594
FD
1670#ifdef BABEL_CLEANUP
1671 GtkWidget *extra_live_button;
1672#endif //babel_cleanup
ba013432
MD
1673 GtkFileChooser * file_chooser =
1674 GTK_FILE_CHOOSER(
1675 gtk_file_chooser_dialog_new ("Select a trace",
1676 GTK_WINDOW(mw_data->mwindow),
1677 GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
1678 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
1679 GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
861fbe5f 1680 NULL));
95544594 1681#ifdef BABEL_CLEANUP
1e3594a3
YB
1682 /* Button to indicate the opening of a live trace */
1683 extra_live_button = gtk_check_button_new_with_mnemonic ("Trace is live (currently being writen)");
1684 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (extra_live_button), FALSE);
1685 gtk_file_chooser_set_extra_widget (GTK_FILE_CHOOSER (file_chooser), extra_live_button);
95544594 1686#endif //babel_cleanup
ba013432 1687 gtk_file_chooser_set_show_hidden (file_chooser, TRUE);
3658a338 1688 if(remember_trace_dir[0] != '\0')
ba013432
MD
1689 gtk_file_chooser_set_filename(file_chooser, remember_trace_dir);
1690
861fbe5f 1691 gboolean closeFileChooserDialog = TRUE;
1e3594a3 1692
861fbe5f
FD
1693 do
1694 {
1695 id = gtk_dialog_run(GTK_DIALOG(file_chooser));
1696 switch(id){
1697 case GTK_RESPONSE_ACCEPT:
1698 case GTK_RESPONSE_OK:
1699 path = gtk_file_chooser_get_filename (file_chooser);
1700
1701 strncpy(remember_trace_dir, path, PATH_MAX);
1702 strncat(remember_trace_dir, "/", PATH_MAX);
1703 if(!path || strlen(path) == 0){
1704 break;
1e3594a3 1705 }
861fbe5f
FD
1706 get_absolute_pathname(path, abs_path);
1707
1708 if(lttv_traceset_add_path(traceset,abs_path) != 0 ){ /*failure*/
49bf71b5 1709
861fbe5f
FD
1710 g_warning("cannot open trace %s", abs_path);
1711 strncpy(remember_trace_dir, "\0", PATH_MAX);
1712 GtkWidget *dialogue =
1713 gtk_message_dialog_new(
1714 GTK_WINDOW(gtk_widget_get_toplevel(widget)),
1715 GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT,
1716 GTK_MESSAGE_ERROR,
1717 GTK_BUTTONS_OK,
1718 "Cannot open trace : maybe you should enter in the directory "
1719 "to select it ?");
1720 gtk_dialog_run(GTK_DIALOG(dialogue));
1721 gtk_widget_destroy(dialogue);
1722 closeFileChooserDialog = FALSE;
1723 }
1724 else{
1725 closeFileChooserDialog = TRUE;
1726 SetTraceset(tab, traceset);
1727 }
1728 break;
1729 //update current tab
1730 //update_traceset(mw_data);
21e8c385 1731
861fbe5f
FD
1732 // in expose now call_pending_read_hooks(mw_data);
1733
1734 //lttvwindow_report_current_time(mw_data,&(tab->current_time));
a43d67ba 1735
861fbe5f
FD
1736 case GTK_RESPONSE_REJECT:
1737 case GTK_RESPONSE_CANCEL:
1738 default:
1739 closeFileChooserDialog = TRUE;
1740 break;
1741 }
1742 }while(!closeFileChooserDialog);
451aaf27 1743
861fbe5f 1744 gtk_widget_destroy((GtkWidget*)file_chooser);
ba013432 1745
49bf71b5 1746}
1747
abe346a3 1748/* remove_trace removes a trace from the current traceset if all viewers in
1749 * the current tab are not interested in the trace. It first displays a
1750 * dialogue, which shows all traces in the current traceset, to let user choose
1751 * a trace, then it checks if all viewers unselect the trace, if it is true,
1752 * it will remove the trace, recreate the traceset_contex,
1753 * and redraws all the viewer of the current tab. If there is on trace in the
1754 * current traceset, it will delete all viewers of the current tab
3a5f75c1 1755 *
1756 * It destroys the filter tree. FIXME... we should request for an update
1757 * instead.
abe346a3 1758 */
1759
b052368a 1760void remove_trace(GtkWidget *widget, gpointer user_data)
1761{
9a366873 1762#ifdef BABEL_CLEANUP
b052368a 1763 LttTrace *trace;
1764 LttvTrace * trace_v;
1765 LttvTraceset * traceset;
1766 gint i, j, nb_trace, index=-1;
1767 char ** name, *remove_trace_name;
1768 MainWindow * mw_data = get_window_data_struct(widget);
1769 GtkWidget * notebook = lookup_widget(widget, "MNotebook");
1770
1771 GtkWidget *page = gtk_notebook_get_nth_page(GTK_NOTEBOOK(notebook),
1772 gtk_notebook_get_current_page(GTK_NOTEBOOK(notebook)));
1773 Tab *tab;
1774
1775 if(!page) {
1776 return;
1777 } else {
e433e6d6 1778 LttvPluginTab *ptab;
1779 ptab = (LttvPluginTab *)g_object_get_data(G_OBJECT(page), "Tab_Plugin");
1780 tab = ptab->tab;
b052368a 1781 }
1782
1783 nb_trace =lttv_traceset_number(tab->traceset_info->traceset);
1784 name = g_new(char*,nb_trace);
1785 for(i = 0; i < nb_trace; i++){
1786 trace_v = lttv_traceset_get(tab->traceset_info->traceset, i);
1787 trace = lttv_trace(trace_v);
8d8c5ea7 1788 name[i] = (char *) g_quark_to_string(ltt_trace_name(trace));
b052368a 1789 }
1790
93ac601b 1791 remove_trace_name = get_remove_trace(mw_data, name, nb_trace);
b052368a 1792
1793
1794 if(remove_trace_name){
1795
1796 /* yuk, cut n paste from old code.. should be better (MD)*/
1797 for(i = 0; i<nb_trace; i++) {
1798 if(strcmp(remove_trace_name,name[i]) == 0){
1799 index = i;
1800 }
1801 }
1802
1803 traceset = tab->traceset_info->traceset;
1804 //Keep a reference to the traces so they are not freed.
1805 for(j=0; j<lttv_traceset_number(traceset); j++)
1806 {
1807 LttvTrace * trace = lttv_traceset_get(traceset, j);
1808 lttv_trace_ref(trace);
1809 }
1810
1811 //remove state update hooks
1812 lttv_state_remove_event_hooks(
1813 (LttvTracesetState*)tab->traceset_info->traceset_context);
1814 lttv_context_fini(LTTV_TRACESET_CONTEXT(tab->traceset_info->traceset_context));
1815 g_object_unref(tab->traceset_info->traceset_context);
1816
1817 trace_v = lttv_traceset_get(traceset, index);
1818
b052368a 1819 lttv_traceset_remove(traceset, index);
1820 lttv_trace_unref(trace_v); // Remove local reference
1821
d27948a3 1822 if(lttv_trace_get_ref_number(trace_v) <= 1) {
1ba187d3 1823 /* ref 1 : lttvwindowtraces only*/
1824 ltt_trace_close(lttv_trace(trace_v));
1825 /* lttvwindowtraces_remove_trace takes care of destroying
1826 * the traceset linked with the trace_v and also of destroying
1827 * the trace_v at the same time.
1828 */
d27948a3 1829 lttvwindowtraces_remove_trace(trace_v);
1830 }
b052368a 1831
1832 tab->traceset_info->traceset_context =
1833 g_object_new(LTTV_TRACESET_STATS_TYPE, NULL);
1834 lttv_context_init(
1835 LTTV_TRACESET_CONTEXT(tab->
1836 traceset_info->traceset_context),traceset);
1837 //add state update hooks
1838 lttv_state_add_event_hooks(
1839 (LttvTracesetState*)tab->traceset_info->traceset_context);
1840
1841 //Remove local reference to the traces.
1842 for(j=0; j<lttv_traceset_number(traceset); j++)
1843 {
1844 LttvTrace * trace = lttv_traceset_get(traceset, j);
1845 lttv_trace_unref(trace);
1846 }
1847
1848 SetTraceset(tab, (gpointer)traceset);
1849 }
1850 g_free(name);
451aaf27 1851#endif /* BABEL_CLEANUP */
b052368a 1852}
1853
1854#if 0
561eba2a 1855void remove_trace(GtkWidget * widget, gpointer user_data)
1856{
2176f952 1857 LttTrace *trace;
1858 LttvTrace * trace_v;
1859 LttvTraceset * traceset;
a43d67ba 1860 gint i, j, nb_trace;
2176f952 1861 char ** name, *remove_trace_name;
bca3b81f 1862 MainWindow * mw_data = get_window_data_struct(widget);
49bf71b5 1863 LttvTracesetSelector * s;
1864 LttvTraceSelector * t;
1865 GtkWidget * w;
1866 gboolean selected;
6ced96ef 1867 GtkWidget * notebook = lookup_widget(widget, "MNotebook");
1868
1869 GtkWidget *page = gtk_notebook_get_nth_page(GTK_NOTEBOOK(notebook),
1870 gtk_notebook_get_current_page(GTK_NOTEBOOK(notebook)));
1871 Tab *tab;
1872
1873 if(!page) {
1874 return;
1875 } else {
1876 tab = (Tab *)g_object_get_data(G_OBJECT(page), "Tab_Info");
1877 }
1878
4266dc7f 1879 nb_trace =lttv_traceset_number(tab->traceset_info->traceset);
2176f952 1880 name = g_new(char*,nb_trace);
1881 for(i = 0; i < nb_trace; i++){
4266dc7f 1882 trace_v = lttv_traceset_get(tab->traceset_info->traceset, i);
2176f952 1883 trace = lttv_trace(trace_v);
a5dcde2f 1884 name[i] = ltt_trace_name(trace);
2176f952 1885 }
1886
1887 remove_trace_name = get_remove_trace(name, nb_trace);
1888
1889 if(remove_trace_name){
1890 for(i=0; i<nb_trace; i++){
1891 if(strcmp(remove_trace_name,name[i]) == 0){
6ced96ef 1892 //unselect the trace from the current viewer
b052368a 1893 //FIXME
1894 w = gtk_multivpaned_get_widget(GTK_MULTIVPANED(tab->multivpaned));
6ced96ef 1895 if(w){
1896 s = g_object_get_data(G_OBJECT(w), "Traceset_Selector");
1897 if(s){
1898 t = lttv_traceset_selector_trace_get(s,i);
1899 lttv_trace_selector_set_selected(t, FALSE);
1900 }
1901
1902 //check if other viewers select the trace
b052368a 1903 w = gtk_multivpaned_get_first_widget(GTK_MULTIVPANED(tab->multivpaned));
6ced96ef 1904 while(w){
1905 s = g_object_get_data(G_OBJECT(w), "Traceset_Selector");
1906 if(s){
1907 t = lttv_traceset_selector_trace_get(s,i);
1908 selected = lttv_trace_selector_get_selected(t);
1909 if(selected)break;
1910 }
b052368a 1911 w = gtk_multivpaned_get_next_widget(GTK_MULTIVPANED(tab->multivpaned));
6ced96ef 1912 }
1913 }else selected = FALSE;
49bf71b5 1914
6ced96ef 1915 //if no viewer selects the trace, remove it
1916 if(!selected){
b052368a 1917 remove_trace_from_traceset_selector(GTK_MULTIVPANED(tab->multivpaned), i);
49bf71b5 1918
6ced96ef 1919 traceset = tab->traceset_info->traceset;
1920 //Keep a reference to the traces so they are not freed.
1921 for(j=0; j<lttv_traceset_number(traceset); j++)
1922 {
1923 LttvTrace * trace = lttv_traceset_get(traceset, j);
1924 lttv_trace_ref(trace);
1925 }
a43d67ba 1926
6ced96ef 1927 //remove state update hooks
1928 lttv_state_remove_event_hooks(
1929 (LttvTracesetState*)tab->traceset_info->traceset_context);
1930 lttv_context_fini(LTTV_TRACESET_CONTEXT(tab->traceset_info->traceset_context));
1931 g_object_unref(tab->traceset_info->traceset_context);
a43d67ba 1932
a43d67ba 1933
6ced96ef 1934 trace_v = lttv_traceset_get(traceset, i);
a43d67ba 1935
a1a2b649 1936 if(lttv_trace_get_ref_number(trace_v) <= 2) {
1937 /* ref 2 : traceset, local */
1938 lttvwindowtraces_remove_trace(trace_v);
6ced96ef 1939 ltt_trace_close(lttv_trace(trace_v));
a1a2b649 1940 }
6ced96ef 1941
1942 lttv_traceset_remove(traceset, i);
1943 lttv_trace_unref(trace_v); // Remove local reference
c2619a30 1944
6ced96ef 1945 if(!lttv_trace_get_ref_number(trace_v))
1946 lttv_trace_destroy(trace_v);
1947
1948 tab->traceset_info->traceset_context =
1949 g_object_new(LTTV_TRACESET_STATS_TYPE, NULL);
1950 lttv_context_init(
1951 LTTV_TRACESET_CONTEXT(tab->
1952 traceset_info->traceset_context),traceset);
1953 //add state update hooks
1954 lttv_state_add_event_hooks(
1955 (LttvTracesetState*)tab->traceset_info->traceset_context);
1956
1957 //Remove local reference to the traces.
1958 for(j=0; j<lttv_traceset_number(traceset); j++)
1959 {
1960 LttvTrace * trace = lttv_traceset_get(traceset, j);
1961 lttv_trace_unref(trace);
1962 }
a43d67ba 1963
a43d67ba 1964
6ced96ef 1965 //update current tab
1966 //update_traceset(mw_data);
313bd6fc 1967 //if(nb_trace > 1){
6ced96ef 1968
313bd6fc 1969 SetTraceset(tab, (gpointer)traceset);
6ced96ef 1970 // in expose now call_pending_read_hooks(mw_data);
1971
1972 //lttvwindow_report_current_time(mw_data,&(tab->current_time));
313bd6fc 1973 //}else{
1974 // if(tab){
1975 // while(tab->multi_vpaned->num_children){
1976 // gtk_multi_vpaned_widget_delete(tab->multi_vpaned);
1977 // }
1978 // }
1979 //}
6ced96ef 1980 }
1981 break;
2176f952 1982 }
1983 }
1984 }
1985
1986 g_free(name);
561eba2a 1987}
b052368a 1988#endif //0
abe346a3 1989
9878c8a4 1990/* Redraw all the viewers in the current tab */
1991void redraw(GtkWidget *widget, gpointer user_data)
1992{
1993 GtkWidget * notebook = lookup_widget(widget, "MNotebook");
1994 GtkWidget *page = gtk_notebook_get_nth_page(GTK_NOTEBOOK(notebook),
1995 gtk_notebook_get_current_page(GTK_NOTEBOOK(notebook)));
1996 Tab *tab;
8f318283
BP
1997 gboolean retval;
1998
9878c8a4 1999 if(!page) {
2000 return;
2001 } else {
e433e6d6 2002 LttvPluginTab *ptab;
2003 ptab = (LttvPluginTab *)g_object_get_data(G_OBJECT(page), "Tab_Plugin");
2004 tab = ptab->tab;
9878c8a4 2005 }
2006
2007 LttvHooks * tmp;
2008 LttvAttributeValue value;
2009
8f318283
BP
2010 retval= lttv_iattribute_find_by_path(tab->attributes, "hooks/redraw", LTTV_POINTER, &value);
2011 g_assert(retval);
9878c8a4 2012
2013 tmp = (LttvHooks*)*(value.v_pointer);
c07e9b26 2014 if(tmp != NULL)
2015 lttv_hooks_call(tmp,NULL);
9878c8a4 2016}
2017
2018
2019void continue_processing(GtkWidget *widget, gpointer user_data)
2020{
2021 GtkWidget * notebook = lookup_widget(widget, "MNotebook");
2022 GtkWidget *page = gtk_notebook_get_nth_page(GTK_NOTEBOOK(notebook),
2023 gtk_notebook_get_current_page(GTK_NOTEBOOK(notebook)));
2024 Tab *tab;
8f318283
BP
2025 gboolean retval;
2026
9878c8a4 2027 if(!page) {
2028 return;
2029 } else {
e433e6d6 2030 LttvPluginTab *ptab;
2031 ptab = (LttvPluginTab *)g_object_get_data(G_OBJECT(page), "Tab_Plugin");
2032 tab = ptab->tab;
9878c8a4 2033 }
2034
2035 LttvHooks * tmp;
2036 LttvAttributeValue value;
2037
8f318283
BP
2038 retval= lttv_iattribute_find_by_path(tab->attributes, "hooks/continue",
2039 LTTV_POINTER, &value);
2040 g_assert(retval);
9878c8a4 2041
2042 tmp = (LttvHooks*)*(value.v_pointer);
c07e9b26 2043 if(tmp != NULL)
2044 lttv_hooks_call(tmp,NULL);
9878c8a4 2045}
2046
2047/* Stop the processing for the calling main window's current tab.
2048 * It removes every processing requests that are in its list. It does not call
2049 * the end request hooks, because the request is not finished.
2050 */
2051
2052void stop_processing(GtkWidget *widget, gpointer user_data)
2053{
2054 GtkWidget * notebook = lookup_widget(widget, "MNotebook");
2055 GtkWidget *page = gtk_notebook_get_nth_page(GTK_NOTEBOOK(notebook),
2056 gtk_notebook_get_current_page(GTK_NOTEBOOK(notebook)));
2057 Tab *tab;
2058 if(!page) {
2059 return;
2060 } else {
e433e6d6 2061 LttvPluginTab *ptab;
2062 ptab = (LttvPluginTab *)g_object_get_data(G_OBJECT(page), "Tab_Plugin");
2063 tab = ptab->tab;
9878c8a4 2064 }
a0577796 2065 GSList *iter = tab->events_requests;
9878c8a4 2066
2067 while(iter != NULL) {
2068 GSList *remove_iter = iter;
2069 iter = g_slist_next(iter);
2070
2071 g_free(remove_iter->data);
a0577796 2072 tab->events_requests =
2073 g_slist_remove_link(tab->events_requests, remove_iter);
9878c8a4 2074 }
a0577796 2075 tab->events_request_pending = FALSE;
5698740e 2076 tab->stop_foreground = TRUE;
a0577796 2077 g_idle_remove_by_data(tab);
2078 g_assert(g_slist_length(tab->events_requests) == 0);
9878c8a4 2079}
2080
2081
abe346a3 2082/* save will save the traceset to a file
a43d67ba 2083 * Not implemented yet FIXME
abe346a3 2084 */
2085
561eba2a 2086void save(GtkWidget * widget, gpointer user_data)
2087{
56e5a0f7 2088 g_info("Save\n");
561eba2a 2089}
2090
2091void save_as(GtkWidget * widget, gpointer user_data)
2092{
56e5a0f7 2093 g_info("Save as\n");
561eba2a 2094}
2095
abe346a3 2096
2097/* zoom will change the time_window of all the viewers of the
2098 * current tab, and redisplay them. The main functionality is to
2099 * determine the new time_window of the current tab
2100 */
2101
1f1ae829 2102void zoom(GtkWidget * widget, double size)
2103{
9a366873 2104#ifdef BABEL_CLEANUP
b052368a 2105 TimeInterval time_span;
a43d67ba 2106 TimeWindow new_time_window;
2eef04b5 2107 LttTime current_time, time_delta;
4266dc7f 2108 LttvTracesetContext *tsc;
6ced96ef 2109 GtkWidget * notebook = lookup_widget(widget, "MNotebook");
2110
2111 GtkWidget *page = gtk_notebook_get_nth_page(GTK_NOTEBOOK(notebook),
2112 gtk_notebook_get_current_page(GTK_NOTEBOOK(notebook)));
2113 Tab *tab;
2114
2115 if(!page) {
2116 return;
2117 } else {
e433e6d6 2118 LttvPluginTab *ptab;
2119 ptab = (LttvPluginTab *)g_object_get_data(G_OBJECT(page), "Tab_Plugin");
2120 tab = ptab->tab;
6ced96ef 2121 }
1f1ae829 2122
fda16332 2123 if(size == 1) return;
2124
4266dc7f 2125 tsc = LTTV_TRACESET_CONTEXT(tab->traceset_info->traceset_context);
b052368a 2126 time_span = tsc->time_span;
501e4e70 2127 new_time_window = tab->time_window;
2128 current_time = tab->current_time;
1f1ae829 2129
b052368a 2130 time_delta = ltt_time_sub(time_span.end_time,time_span.start_time);
1f1ae829 2131 if(size == 0){
b052368a 2132 new_time_window.start_time = time_span.start_time;
a43d67ba 2133 new_time_window.time_width = time_delta;
a18124ff 2134 new_time_window.time_width_double = ltt_time_to_double(time_delta);
6f26fc38 2135 new_time_window.end_time = ltt_time_add(new_time_window.start_time,
2136 new_time_window.time_width) ;
1f1ae829 2137 }else{
a43d67ba 2138 new_time_window.time_width = ltt_time_div(new_time_window.time_width, size);
a18124ff 2139 new_time_window.time_width_double =
2140 ltt_time_to_double(new_time_window.time_width);
a43d67ba 2141 if(ltt_time_compare(new_time_window.time_width,time_delta) > 0)
2142 { /* Case where zoom out is bigger than trace length */
b052368a 2143 new_time_window.start_time = time_span.start_time;
a43d67ba 2144 new_time_window.time_width = time_delta;
a18124ff 2145 new_time_window.time_width_double = ltt_time_to_double(time_delta);
6f26fc38 2146 new_time_window.end_time = ltt_time_add(new_time_window.start_time,
2147 new_time_window.time_width) ;
a8c0f09d 2148 }
a43d67ba 2149 else
2150 {
2151 /* Center the image on the current time */
a43d67ba 2152 new_time_window.start_time =
a18124ff 2153 ltt_time_sub(current_time,
2154 ltt_time_from_double(new_time_window.time_width_double/2.0));
6f26fc38 2155 new_time_window.end_time = ltt_time_add(new_time_window.start_time,
2156 new_time_window.time_width) ;
a43d67ba 2157 /* If on borders, don't fall off */
9e494e53 2158 if(ltt_time_compare(new_time_window.start_time, time_span.start_time) <0
2159 || ltt_time_compare(new_time_window.start_time, time_span.end_time) >0)
a43d67ba 2160 {
b052368a 2161 new_time_window.start_time = time_span.start_time;
6f26fc38 2162 new_time_window.end_time = ltt_time_add(new_time_window.start_time,
2163 new_time_window.time_width) ;
a43d67ba 2164 }
2165 else
2166 {
6f26fc38 2167 if(ltt_time_compare(new_time_window.end_time,
9e494e53 2168 time_span.end_time) > 0
2169 || ltt_time_compare(new_time_window.end_time,
2170 time_span.start_time) < 0)
a43d67ba 2171 {
2172 new_time_window.start_time =
b052368a 2173 ltt_time_sub(time_span.end_time, new_time_window.time_width);
6f26fc38 2174
2175 new_time_window.end_time = ltt_time_add(new_time_window.start_time,
2176 new_time_window.time_width) ;
a43d67ba 2177 }
2178 }
2179
1f1ae829 2180 }
1f1ae829 2181 }
a43d67ba 2182
f02b5e22 2183 if(ltt_time_compare(new_time_window.time_width, ltt_time_zero) == 0) {
2184 g_warning("Zoom more than 1 ns impossible");
b052368a 2185 } else {
e800cf84 2186 time_change_manager(tab, new_time_window);
b052368a 2187 }
451aaf27
FD
2188
2189#endif /* BABEL_CLEANUP */
1f1ae829 2190}
2191
561eba2a 2192void zoom_in(GtkWidget * widget, gpointer user_data)
2193{
1f1ae829 2194 zoom(widget, 2);
561eba2a 2195}
2196
2197void zoom_out(GtkWidget * widget, gpointer user_data)
2198{
1f1ae829 2199 zoom(widget, 0.5);
561eba2a 2200}
2201
2202void zoom_extended(GtkWidget * widget, gpointer user_data)
2203{
1f1ae829 2204 zoom(widget, 0);
561eba2a 2205}
2206
2207void go_to_time(GtkWidget * widget, gpointer user_data)
2208{
56e5a0f7 2209 g_info("Go to time\n");
561eba2a 2210}
2211
2212void show_time_frame(GtkWidget * widget, gpointer user_data)
2213{
56e5a0f7 2214 g_info("Show time frame\n");
561eba2a 2215}
2216
2217
2218/* callback function */
2219
2220void
2221on_empty_traceset_activate (GtkMenuItem *menuitem,
2222 gpointer user_data)
2223{
68b48a45 2224 create_new_window((GtkWidget*)menuitem, user_data, FALSE);
561eba2a 2225}
2226
2227
2228void
2229on_clone_traceset_activate (GtkMenuItem *menuitem,
2230 gpointer user_data)
2231{
68b48a45 2232 create_new_window((GtkWidget*)menuitem, user_data, TRUE);
561eba2a 2233}
2234
abe346a3 2235
2236/* create_new_tab calls create_tab to construct a new tab in the main window
2237 */
2238
e433e6d6 2239LttvPluginTab *create_new_tab(GtkWidget* widget, gpointer user_data)
2240{
a1a2b649 2241 gchar label[PATH_MAX];
2901f314 2242 MainWindow * mw_data = get_window_data_struct(widget);
4266dc7f 2243
2901f314 2244 GtkNotebook * notebook = (GtkNotebook *)lookup_widget(widget, "MNotebook");
561eba2a 2245 if(notebook == NULL){
56e5a0f7 2246 g_info("Notebook does not exist\n");
6ced96ef 2247 return NULL;
2248 }
2249 GtkWidget *page = gtk_notebook_get_nth_page(GTK_NOTEBOOK(notebook),
2250 gtk_notebook_get_current_page(GTK_NOTEBOOK(notebook)));
2251 Tab *copy_tab;
2252
2253 if(!page) {
2254 copy_tab = NULL;
2255 } else {
e433e6d6 2256 LttvPluginTab *ptab;
2257 ptab = (LttvPluginTab *)g_object_get_data(G_OBJECT(page), "Tab_Plugin");
2258 copy_tab = ptab->tab;
561eba2a 2259 }
4266dc7f 2260
6b1d3120 2261 strcpy(label,"Page");
e433e6d6 2262 if(get_label(mw_data, label,"Get the name of the tab","Please input tab's name")) {
2263 LttvPluginTab *ptab;
2264
2265 ptab = g_object_new(LTTV_TYPE_PLUGIN_TAB, NULL);
2266 init_tab (ptab->tab, mw_data, copy_tab, notebook, label);
2267 ptab->parent.top_widget = ptab->tab->top_widget;
2268 g_object_set_data_full(
2269 G_OBJECT(ptab->tab->vbox),
2270 "Tab_Plugin",
2271 ptab,
2272 (GDestroyNotify)tab_destructor);
2273 return ptab;
2274 }
2275 else return NULL;
561eba2a 2276}
2277
2901f314 2278void
2279on_tab_activate (GtkMenuItem *menuitem,
2280 gpointer user_data)
2281{
2282 create_new_tab((GtkWidget*)menuitem, user_data);
2283}
2284
561eba2a 2285
2286void
2287on_open_activate (GtkMenuItem *menuitem,
2288 gpointer user_data)
2289{
e865422c 2290#ifdef UNFINISHED_FEATURE
561eba2a 2291 open_traceset((GtkWidget*)menuitem, user_data);
e865422c 2292#endif
561eba2a 2293}
2294
2295
2296void
2297on_close_activate (GtkMenuItem *menuitem,
2298 gpointer user_data)
2299{
bca3b81f 2300 MainWindow * mw_data = get_window_data_struct((GtkWidget*)menuitem);
68b48a45 2301 main_window_destructor(mw_data);
561eba2a 2302}
2303
2304
4266dc7f 2305/* remove the current tab from the main window
abe346a3 2306 */
2307
561eba2a 2308void
27a559b9 2309on_close_tab_activate (GtkWidget *widget,
561eba2a 2310 gpointer user_data)
2311{
4266dc7f 2312 gint page_num;
2061e03d 2313 GtkWidget * notebook;
27a559b9 2314 notebook = lookup_widget(widget, "MNotebook");
2061e03d 2315 if(notebook == NULL){
56e5a0f7 2316 g_info("Notebook does not exist\n");
2061e03d 2317 return;
2318 }
4266dc7f 2319
2320 page_num = gtk_notebook_get_current_page(GTK_NOTEBOOK(notebook));
2061e03d 2321
4266dc7f 2322 gtk_notebook_remove_page(GTK_NOTEBOOK(notebook), page_num);
2061e03d 2323
561eba2a 2324}
2325
27a559b9 2326void
2327on_close_tab_X_clicked (GtkWidget *widget,
2328 gpointer user_data)
2329{
2330 gint page_num;
2331 GtkWidget *notebook = lookup_widget(widget, "MNotebook");
2332 if(notebook == NULL){
56e5a0f7 2333 g_info("Notebook does not exist\n");
27a559b9 2334 return;
2335 }
2336
2337 if((page_num = gtk_notebook_page_num(GTK_NOTEBOOK(notebook), widget)) != -1)
2338 gtk_notebook_remove_page(GTK_NOTEBOOK(notebook), page_num);
2339
2340}
2341
561eba2a 2342
2343void
2344on_add_trace_activate (GtkMenuItem *menuitem,
2345 gpointer user_data)
2346{
2347 add_trace((GtkWidget*)menuitem, user_data);
2348}
2349
2350
2351void
2352on_remove_trace_activate (GtkMenuItem *menuitem,
2353 gpointer user_data)
2354{
2355 remove_trace((GtkWidget*)menuitem, user_data);
2356}
2357
2358
2359void
2360on_save_activate (GtkMenuItem *menuitem,
2361 gpointer user_data)
2362{
2363 save((GtkWidget*)menuitem, user_data);
2364}
2365
2366
2367void
2368on_save_as_activate (GtkMenuItem *menuitem,
2369 gpointer user_data)
2370{
2371 save_as((GtkWidget*)menuitem, user_data);
2372}
2373
2374
2375void
2376on_quit_activate (GtkMenuItem *menuitem,
2377 gpointer user_data)
2378{
6f9c921e 2379 while (g_slist_length(g_main_window_list) != 0) {
2380 on_MWindow_destroy(((MainWindow *)g_main_window_list->data)->mwindow,
2381 user_data);
2382 }
561eba2a 2383}
2384
2385
2386void
2387on_cut_activate (GtkMenuItem *menuitem,
2388 gpointer user_data)
2389{
56e5a0f7 2390 g_info("Cut\n");
561eba2a 2391}
2392
2393
2394void
2395on_copy_activate (GtkMenuItem *menuitem,
2396 gpointer user_data)
2397{
56e5a0f7 2398 g_info("Copye\n");
561eba2a 2399}
2400
2401
2402void
2403on_paste_activate (GtkMenuItem *menuitem,
2404 gpointer user_data)
2405{
56e5a0f7 2406 g_info("Paste\n");
561eba2a 2407}
2408
2409
2410void
2411on_delete_activate (GtkMenuItem *menuitem,
2412 gpointer user_data)
2413{
56e5a0f7 2414 g_info("Delete\n");
561eba2a 2415}
2416
2417
2418void
2419on_zoom_in_activate (GtkMenuItem *menuitem,
2420 gpointer user_data)
2421{
2422 zoom_in((GtkWidget*)menuitem, user_data);
2423}
2424
2425
2426void
2427on_zoom_out_activate (GtkMenuItem *menuitem,
2428 gpointer user_data)
2429{
2430 zoom_out((GtkWidget*)menuitem, user_data);
2431}
2432
2433
2434void
2435on_zoom_extended_activate (GtkMenuItem *menuitem,
2436 gpointer user_data)
2437{
2438 zoom_extended((GtkWidget*)menuitem, user_data);
2439}
2440
2441
2442void
2443on_go_to_time_activate (GtkMenuItem *menuitem,
2444 gpointer user_data)
2445{
2446 go_to_time((GtkWidget*)menuitem, user_data);
2447}
2448
2449
2450void
2451on_show_time_frame_activate (GtkMenuItem *menuitem,
2452 gpointer user_data)
2453{
2454 show_time_frame((GtkWidget*)menuitem, user_data);
2455}
2456
2457
2458void
2459on_move_viewer_up_activate (GtkMenuItem *menuitem,
2460 gpointer user_data)
2461{
2462 move_up_viewer((GtkWidget*)menuitem, user_data);
2463}
2464
2465
2466void
2467on_move_viewer_down_activate (GtkMenuItem *menuitem,
2468 gpointer user_data)
2469{
2470 move_down_viewer((GtkWidget*)menuitem, user_data);
2471}
2472
2473
2474void
2475on_remove_viewer_activate (GtkMenuItem *menuitem,
2476 gpointer user_data)
2477{
2478 delete_viewer((GtkWidget*)menuitem, user_data);
2479}
2480
49bf71b5 2481void
2482on_trace_facility_activate (GtkMenuItem *menuitem,
2483 gpointer user_data)
2484{
43ed82b5 2485 g_info("Trace facility selector: %s\n", "");
49bf71b5 2486}
561eba2a 2487
abe346a3 2488
b052368a 2489/* Dispaly a file selection dialogue to let user select a library, then call
2490 * lttv_library_load().
2491 */
2492
2493void
2494on_load_library_activate (GtkMenuItem *menuitem,
2495 gpointer user_data)
2496{
2497 GError *error = NULL;
2498 MainWindow * mw_data = get_window_data_struct((GtkWidget*)menuitem);
2499
2500 gchar load_module_path_alter[PATH_MAX];
2501 {
2502 GPtrArray *name;
2503 guint nb,i;
2504 gchar *load_module_path;
2505 name = g_ptr_array_new();
2506 nb = lttv_library_path_number();
2507 /* ask for the library path */
2508
2509 for(i=0;i<nb;i++){
2510 gchar *path;
2511 path = lttv_library_path_get(i);
2512 g_ptr_array_add(name, path);
2513 }
2514
93ac601b 2515 load_module_path = get_selection(mw_data,
2516 (char **)(name->pdata), name->len,
b052368a 2517 "Select a library path", "Library paths");
2518 if(load_module_path != NULL)
2519 strncpy(load_module_path_alter, load_module_path, PATH_MAX-1); // -1 for /
2520
2521 g_ptr_array_free(name, TRUE);
2522
2523 if(load_module_path == NULL) return;
2524 }
2525
2526 {
2527 /* Make sure the module path ends with a / */
2528 gchar *ptr = load_module_path_alter;
2529
2530 ptr = strchr(ptr, '\0');
2531
2532 if(*(ptr-1) != '/') {
2533 *ptr = '/';
2534 *(ptr+1) = '\0';
2535 }
2536 }
2537
2538 {
2539 /* Ask for the library to load : list files in the previously selected
2540 * directory */
2541 gchar str[PATH_MAX];
2542 gchar ** dir;
2543 gint id;
2544 GtkFileSelection * file_selector =
2545 (GtkFileSelection *)gtk_file_selection_new("Select a module");
2546 gtk_file_selection_set_filename(file_selector, load_module_path_alter);
2547 gtk_file_selection_hide_fileop_buttons(file_selector);
2548
93ac601b 2549 gtk_window_set_transient_for(GTK_WINDOW(file_selector),
2550 GTK_WINDOW(mw_data->mwindow));
2551
b052368a 2552 str[0] = '\0';
2553 id = gtk_dialog_run(GTK_DIALOG(file_selector));
2554 switch(id){
2555 case GTK_RESPONSE_ACCEPT:
2556 case GTK_RESPONSE_OK:
2557 dir = gtk_file_selection_get_selections (file_selector);
2558 strncpy(str,dir[0],PATH_MAX);
2559 strncpy(remember_plugins_dir,dir[0],PATH_MAX);
2560 /* only keep file name */
2561 gchar *str1;
2562 str1 = strrchr(str,'/');
2563 if(str1)str1++;
2564 else{
2565 str1 = strrchr(str,'\\');
2566 str1++;
2567 }
2568#if 0
2569 /* remove "lib" */
2570 if(*str1 == 'l' && *(str1+1)== 'i' && *(str1+2)=='b')
2571 str1=str1+3;
2572 remove info after . */
2573 {
2574 gchar *str2 = str1;
2575
2576 str2 = strrchr(str2, '.');
2577 if(str2 != NULL) *str2 = '\0';
2578 }
2579 lttv_module_require(str1, &error);
2580#endif //0
2581 lttv_library_load(str1, &error);
2eef04b5 2582 if(error != NULL) g_warning("%s", error->message);
56e5a0f7 2583 else g_info("Load library: %s\n", str);
b052368a 2584 g_strfreev(dir);
2585 case GTK_RESPONSE_REJECT:
2586 case GTK_RESPONSE_CANCEL:
2587 default:
2588 gtk_widget_destroy((GtkWidget*)file_selector);
2589 break;
2590 }
2591
2592 }
2593
2594
2595
2596}
2597
2598
2599/* Display all loaded modules, let user to select a module to unload
2600 * by calling lttv_module_unload
2601 */
2602
2603void
2604on_unload_library_activate (GtkMenuItem *menuitem,
2605 gpointer user_data)
2606{
2607 MainWindow * mw_data = get_window_data_struct((GtkWidget*)menuitem);
2608
2eef04b5 2609 LttvLibrary *library = NULL;
b052368a 2610
2eef04b5 2611 GPtrArray *name;
2612 guint nb,i;
2613 gchar *lib_name;
2614 name = g_ptr_array_new();
2615 nb = lttv_library_number();
2616 LttvLibraryInfo *lib_info = g_new(LttvLibraryInfo,nb);
2617 /* ask for the library name */
2618
2619 for(i=0;i<nb;i++){
2620 LttvLibrary *iter_lib = lttv_library_get(i);
2621 lttv_library_info(iter_lib, &lib_info[i]);
2622
2623 gchar *path = lib_info[i].name;
2624 g_ptr_array_add(name, path);
2625 }
93ac601b 2626 lib_name = get_selection(mw_data, (char **)(name->pdata), name->len,
2eef04b5 2627 "Select a library", "Libraries");
2628 if(lib_name != NULL) {
b052368a 2629 for(i=0;i<nb;i++){
2eef04b5 2630 if(strcmp(lib_name, lib_info[i].name) == 0) {
2631 library = lttv_library_get(i);
2632 break;
b052368a 2633 }
2634 }
b052368a 2635 }
2eef04b5 2636 g_ptr_array_free(name, TRUE);
2637 g_free(lib_info);
2638
2639 if(lib_name == NULL) return;
2640
2641 if(library != NULL) lttv_library_unload(library);
b052368a 2642}
2643
2644
abe346a3 2645/* Dispaly a file selection dialogue to let user select a module, then call
b052368a 2646 * lttv_module_require().
abe346a3 2647 */
2648
561eba2a 2649void
2650on_load_module_activate (GtkMenuItem *menuitem,
2651 gpointer user_data)
2652{
b052368a 2653 GError *error = NULL;
bca3b81f 2654 MainWindow * mw_data = get_window_data_struct((GtkWidget*)menuitem);
b052368a 2655
2eef04b5 2656 LttvLibrary *library = NULL;
b052368a 2657 {
2658 GPtrArray *name;
2659 guint nb,i;
2660 gchar *lib_name;
2661 name = g_ptr_array_new();
2662 nb = lttv_library_number();
2663 LttvLibraryInfo *lib_info = g_new(LttvLibraryInfo,nb);
2664 /* ask for the library name */
2665
2666 for(i=0;i<nb;i++){
2667 LttvLibrary *iter_lib = lttv_library_get(i);
2668 lttv_library_info(iter_lib, &lib_info[i]);
2669
2670 gchar *path = lib_info[i].name;
2671 g_ptr_array_add(name, path);
2672 }
93ac601b 2673 lib_name = get_selection(mw_data,(char **)(name->pdata), name->len,
b052368a 2674 "Select a library", "Libraries");
2675 if(lib_name != NULL) {
2676 for(i=0;i<nb;i++){
2677 if(strcmp(lib_name, lib_info[i].name) == 0) {
2678 library = lttv_library_get(i);
2679 break;
2680 }
3872a20e 2681 }
b052368a 2682 }
2683 g_ptr_array_free(name, TRUE);
2684 g_free(lib_info);
2685
2686 if(lib_name == NULL) return;
36b3c068 2687 }
b052368a 2688
2689 //LttvModule *module;
2690 gchar module_name_out[PATH_MAX];
2691 {
2692 /* Ask for the module to load : list modules in the selected lib */
2693 GPtrArray *name;
2694 guint nb,i;
2695 gchar *module_name;
bbbd6c25 2696 nb = lttv_library_module_number(library);
b052368a 2697 LttvModuleInfo *module_info = g_new(LttvModuleInfo,nb);
2698 name = g_ptr_array_new();
b052368a 2699 /* ask for the module name */
2700
2701 for(i=0;i<nb;i++){
2702 LttvModule *iter_module = lttv_library_module_get(library, i);
2703 lttv_module_info(iter_module, &module_info[i]);
2704
2705 gchar *path = module_info[i].name;
2706 g_ptr_array_add(name, path);
2707 }
93ac601b 2708 module_name = get_selection(mw_data, (char **)(name->pdata), name->len,
b052368a 2709 "Select a module", "Modules");
2710 if(module_name != NULL) {
2711 for(i=0;i<nb;i++){
2712 if(strcmp(module_name, module_info[i].name) == 0) {
2713 strncpy(module_name_out, module_name, PATH_MAX);
2714 //module = lttv_library_module_get(i);
2715 break;
2716 }
2717 }
2718 }
2719
2720 g_ptr_array_free(name, TRUE);
2721 g_free(module_info);
2722
2723 if(module_name == NULL) return;
2724 }
2725
2726 lttv_module_require(module_name_out, &error);
2eef04b5 2727 if(error != NULL) g_warning("%s", error->message);
56e5a0f7 2728 else g_info("Load module: %s", module_name_out);
b052368a 2729
2730
2731#if 0
2732 {
2733
2734
2735 gchar str[PATH_MAX];
2736 gchar ** dir;
2737 gint id;
2738 GtkFileSelection * file_selector =
2739 (GtkFileSelection *)gtk_file_selection_new("Select a module");
2740 gtk_file_selection_set_filename(file_selector, load_module_path_alter);
2741 gtk_file_selection_hide_fileop_buttons(file_selector);
2742
2743 str[0] = '\0';
2744 id = gtk_dialog_run(GTK_DIALOG(file_selector));
2745 switch(id){
2746 case GTK_RESPONSE_ACCEPT:
2747 case GTK_RESPONSE_OK:
2748 dir = gtk_file_selection_get_selections (file_selector);
2749 strncpy(str,dir[0],PATH_MAX);
2750 strncpy(remember_plugins_dir,dir[0],PATH_MAX);
2751 {
2752 /* only keep file name */
2753 gchar *str1;
2754 str1 = strrchr(str,'/');
2755 if(str1)str1++;
2756 else{
2757 str1 = strrchr(str,'\\');
2758 str1++;
2759 }
2760#if 0
2761 /* remove "lib" */
2762 if(*str1 == 'l' && *(str1+1)== 'i' && *(str1+2)=='b')
2763 str1=str1+3;
2764 remove info after . */
2765 {
2766 gchar *str2 = str1;
2767
2768 str2 = strrchr(str2, '.');
2769 if(str2 != NULL) *str2 = '\0';
2770 }
2771 lttv_module_require(str1, &error);
2772#endif //0
2773 lttv_library_load(str1, &error);
2774 if(error != NULL) g_warning(error->message);
56e5a0f7 2775 else g_info("Load library: %s\n", str);
b052368a 2776 g_strfreev(dir);
2777 case GTK_RESPONSE_REJECT:
2778 case GTK_RESPONSE_CANCEL:
2779 default:
2780 gtk_widget_destroy((GtkWidget*)file_selector);
2781 break;
2782 }
2783
2784 }
2785#endif //0
2786
2787
561eba2a 2788}
2789
2790
b052368a 2791
abe346a3 2792/* Display all loaded modules, let user to select a module to unload
2793 * by calling lttv_module_unload
2794 */
2795
561eba2a 2796void
2797on_unload_module_activate (GtkMenuItem *menuitem,
2798 gpointer user_data)
2799{
bca3b81f 2800 MainWindow * mw_data = get_window_data_struct((GtkWidget*)menuitem);
08b1c66e 2801
43ed82b5 2802 LttvLibrary *library = NULL;
b052368a 2803 {
2804 GPtrArray *name;
2805 guint nb,i;
2806 gchar *lib_name;
2807 name = g_ptr_array_new();
2808 nb = lttv_library_number();
2809 LttvLibraryInfo *lib_info = g_new(LttvLibraryInfo,nb);
2810 /* ask for the library name */
36b3c068 2811
36b3c068 2812 for(i=0;i<nb;i++){
b052368a 2813 LttvLibrary *iter_lib = lttv_library_get(i);
2814 lttv_library_info(iter_lib, &lib_info[i]);
2815
2816 gchar *path = lib_info[i].name;
2817 g_ptr_array_add(name, path);
2818 }
93ac601b 2819 lib_name = get_selection(mw_data, (char **)(name->pdata), name->len,
b052368a 2820 "Select a library", "Libraries");
2821 if(lib_name != NULL) {
2822 for(i=0;i<nb;i++){
2823 if(strcmp(lib_name, lib_info[i].name) == 0) {
2824 library = lttv_library_get(i);
2825 break;
2826 }
36b3c068 2827 }
b052368a 2828 }
2829 g_ptr_array_free(name, TRUE);
2830 g_free(lib_info);
2831
2832 if(lib_name == NULL) return;
36b3c068 2833 }
2834
2eef04b5 2835 LttvModule *module = NULL;
b052368a 2836 {
2837 /* Ask for the module to load : list modules in the selected lib */
2838 GPtrArray *name;
2839 guint nb,i;
2840 gchar *module_name;
6d677a86 2841 nb = lttv_library_module_number(library);
b052368a 2842 LttvModuleInfo *module_info = g_new(LttvModuleInfo,nb);
2843 name = g_ptr_array_new();
b052368a 2844 /* ask for the module name */
2845
2846 for(i=0;i<nb;i++){
2847 LttvModule *iter_module = lttv_library_module_get(library, i);
2848 lttv_module_info(iter_module, &module_info[i]);
2849
2850 gchar *path = module_info[i].name;
2851 if(module_info[i].use_count > 0) g_ptr_array_add(name, path);
2852 }
93ac601b 2853 module_name = get_selection(mw_data, (char **)(name->pdata), name->len,
b052368a 2854 "Select a module", "Modules");
2855 if(module_name != NULL) {
2856 for(i=0;i<nb;i++){
2857 if(strcmp(module_name, module_info[i].name) == 0) {
2858 module = lttv_library_module_get(library, i);
2859 break;
2860 }
2861 }
2862 }
2863
2864 g_ptr_array_free(name, TRUE);
2865 g_free(module_info);
2866
2867 if(module_name == NULL) return;
2868 }
2869
b052368a 2870 LttvModuleInfo module_info;
2871 lttv_module_info(module, &module_info);
56e5a0f7 2872 g_info("Release module: %s\n", module_info.name);
fce9a2fc 2873
2874 lttv_module_release(module);
561eba2a 2875}
2876
2877
b052368a 2878/* Display a directory dialogue to let user select a path for library searching
abe346a3 2879 */
2880
561eba2a 2881void
b052368a 2882on_add_library_search_path_activate (GtkMenuItem *menuitem,
561eba2a 2883 gpointer user_data)
2884{
93ac601b 2885 MainWindow * mw_data = get_window_data_struct((GtkWidget*)menuitem);
0a946563 2886 //GtkDirSelection * file_selector = (GtkDirSelection *)gtk_dir_selection_new("Select library path");
2887 GtkFileSelection * file_selector = (GtkFileSelection *)gtk_file_selection_new("Select a trace");
2888 gtk_widget_hide( (file_selector)->file_list->parent) ;
93ac601b 2889
2890 gtk_window_set_transient_for(GTK_WINDOW(file_selector),
2891 GTK_WINDOW(mw_data->mwindow));
2892
67b98724 2893 const char * dir;
fc188b78 2894 gint id;
2895
3658a338 2896 if(remember_plugins_dir[0] != '\0')
0a946563 2897 gtk_file_selection_set_filename(file_selector, remember_plugins_dir);
fc188b78 2898
68b48a45 2899 id = gtk_dialog_run(GTK_DIALOG(file_selector));
fc188b78 2900 switch(id){
2901 case GTK_RESPONSE_ACCEPT:
2902 case GTK_RESPONSE_OK:
0a946563 2903 dir = gtk_file_selection_get_filename (file_selector);
a1a2b649 2904 strncpy(remember_plugins_dir,dir,PATH_MAX);
2905 strncat(remember_plugins_dir,"/",PATH_MAX);
08b1c66e 2906 lttv_library_path_add(dir);
fc188b78 2907 case GTK_RESPONSE_REJECT:
2908 case GTK_RESPONSE_CANCEL:
2909 default:
68b48a45 2910 gtk_widget_destroy((GtkWidget*)file_selector);
fc188b78 2911 break;
6b1d3120 2912 }
561eba2a 2913}
2914
2915
b052368a 2916/* Display a directory dialogue to let user select a path for library searching
2917 */
2918
2919void
2920on_remove_library_search_path_activate (GtkMenuItem *menuitem,
2921 gpointer user_data)
2922{
2923 MainWindow * mw_data = get_window_data_struct((GtkWidget*)menuitem);
2924
2925 const char *lib_path;
2926 {
2927 GPtrArray *name;
2928 guint nb,i;
b052368a 2929 name = g_ptr_array_new();
2930 nb = lttv_library_path_number();
2931 /* ask for the library name */
2932
2933 for(i=0;i<nb;i++){
2934 gchar *path = lttv_library_path_get(i);
2935 g_ptr_array_add(name, path);
2936 }
93ac601b 2937 lib_path = get_selection(mw_data, (char **)(name->pdata), name->len,
b052368a 2938 "Select a library path", "Library paths");
2939
2940 g_ptr_array_free(name, TRUE);
2941
2942 if(lib_path == NULL) return;
2943 }
2944
2945 lttv_library_path_remove(lib_path);
2946}
2947
561eba2a 2948void
2949on_color_activate (GtkMenuItem *menuitem,
2950 gpointer user_data)
2951{
56e5a0f7 2952 g_info("Color\n");
561eba2a 2953}
2954
2955
561eba2a 2956void
2957on_save_configuration_activate (GtkMenuItem *menuitem,
2958 gpointer user_data)
2959{
56e5a0f7 2960 g_info("Save configuration\n");
561eba2a 2961}
2962
2963
2964void
2965on_content_activate (GtkMenuItem *menuitem,
2966 gpointer user_data)
2967{
7e18bb76
F
2968 char* filename = NULL,
2969 *path;
2970 GdkScreen *screen;
2971 const char* relativePath = "doc/user/user_guide/html/index.html";
2972 filename = g_build_filename (g_get_current_dir(), relativePath, NULL);
2973 path = g_strdup_printf ("ghelp://%s", filename);
2974
2975 screen = gdk_screen_get_default();
2976 gtk_show_uri (screen, path, gtk_get_current_event_time(), NULL);
2977
2978 g_free(filename);
2979 g_free(path);
56e5a0f7 2980 g_info("Content\n");
561eba2a 2981}
2982
2983
51ef553b 2984static void
2985on_about_close_activate (GtkButton *button,
2986 gpointer user_data)
2987{
2988 GtkWidget *about_widget = GTK_WIDGET(user_data);
2989
2990 gtk_widget_destroy(about_widget);
2991}
2992
561eba2a 2993void
2994on_about_activate (GtkMenuItem *menuitem,
2995 gpointer user_data)
2996{
51ef553b 2997 MainWindow *main_window = get_window_data_struct(GTK_WIDGET(menuitem));
2998 GtkWidget *window_widget = main_window->mwindow;
2999 GtkWidget *about_widget = gtk_window_new(GTK_WINDOW_TOPLEVEL);
3000 GtkWindow *about_window = GTK_WINDOW(about_widget);
51ef553b 3001
3002 gtk_window_set_title(about_window, "About Linux Trace Toolkit");
3003
3004 gtk_window_set_resizable(about_window, FALSE);
f5f1a04e 3005 gtk_window_set_transient_for(about_window, GTK_WINDOW(window_widget));
51ef553b 3006 gtk_window_set_destroy_with_parent(about_window, TRUE);
3007 gtk_window_set_modal(about_window, FALSE);
3008
3009 /* Put the about window at the center of the screen */
7e18bb76
F
3010 gtk_window_set_position(about_window, GTK_WIN_POS_CENTER_ALWAYS);
3011
51ef553b 3012 GtkWidget *vbox = gtk_vbox_new(FALSE, 1);
3013
3014 gtk_container_add(GTK_CONTAINER(about_widget), vbox);
3015
51ef553b 3016 /* Text to show */
3017 GtkWidget *label1 = gtk_label_new("");
c8bba5fa 3018 gtk_misc_set_padding(GTK_MISC(label1), 10, 20);
51ef553b 3019 gtk_label_set_markup(GTK_LABEL(label1), "\
f5f1a04e 3020<big>Linux Trace Toolkit " VERSION "</big>");
51ef553b 3021 gtk_label_set_justify(GTK_LABEL(label1), GTK_JUSTIFY_CENTER);
3022
3023 GtkWidget *label2 = gtk_label_new("");
c8bba5fa 3024 gtk_misc_set_padding(GTK_MISC(label2), 10, 20);
51ef553b 3025 gtk_label_set_markup(GTK_LABEL(label2), "\
51ef553b 3026Contributors :\n\
3027\n\
3028Michel Dagenais (New trace format, lttv main)\n\
4b601423 3029Mathieu Desnoyers (Kernel Tracer, Directory structure, build with automake/conf,\n\
ef26c1ea 3030 lttv gui, control flow view, gui cooperative trace reading\n\
4b7bd7e1 3031 scheduler with interruptible foreground and background\n\
57ca4914 3032 computation, detailed event list (rewrite), trace reading\n\
3033 library (rewrite))\n\
7d2855bf 3034Benoit Des Ligneris, Eric Clement (Cluster adaptation, work in progress)\n\
51ef553b 3035Xang-Xiu Yang (new trace reading library and converter, lttv gui, \n\
3036 detailed event list and statistics view)\n\
e8ac6a5e 3037Tom Zanussi (RelayFS)\n\
3038\n\
f5f1a04e 3039Inspired from the original Linux Trace Toolkit Visualizer made by\n\
e8ac6a5e 3040Karim Yaghmour");
c8bba5fa 3041
3042 GtkWidget *label3 = gtk_label_new("");
3043 gtk_label_set_markup(GTK_LABEL(label3), "\
f5f1a04e 3044Linux Trace Toolkit Viewer, Copyright (C) 2004, 2005, 2006\n\
7d2855bf 3045 Michel Dagenais\n\
e8ac6a5e 3046 Mathieu Desnoyers\n\
3047 Xang-Xiu Yang\n\
c8bba5fa 3048Linux Trace Toolkit comes with ABSOLUTELY NO WARRANTY.\n\
3049This is free software, and you are welcome to redistribute it\n\
3050under certain conditions. See COPYING for details.");
3051 gtk_misc_set_padding(GTK_MISC(label3), 10, 20);
3052
51ef553b 3053 gtk_box_pack_start_defaults(GTK_BOX(vbox), label1);
3054 gtk_box_pack_start_defaults(GTK_BOX(vbox), label2);
c8bba5fa 3055 gtk_box_pack_start_defaults(GTK_BOX(vbox), label3);
51ef553b 3056
3057 GtkWidget *hbox = gtk_hbox_new(TRUE, 0);
3058 gtk_box_pack_end(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
3059 GtkWidget *close_button = gtk_button_new_with_mnemonic("_Close");
3060 gtk_box_pack_end(GTK_BOX(hbox), close_button, FALSE, FALSE, 0);
3061 gtk_container_set_border_width(GTK_CONTAINER(close_button), 20);
3062
3063 g_signal_connect(G_OBJECT(close_button), "clicked",
3064 G_CALLBACK(on_about_close_activate),
3065 (gpointer)about_widget);
3066
3067 gtk_widget_show_all(about_widget);
561eba2a 3068}
3069
3070
3071void
3072on_button_new_clicked (GtkButton *button,
3073 gpointer user_data)
3074{
6f7ad7ae 3075 create_new_window((GtkWidget*)button, user_data, TRUE);
561eba2a 3076}
3077
2901f314 3078void
3079on_button_new_tab_clicked (GtkButton *button,
3080 gpointer user_data)
3081{
3082 create_new_tab((GtkWidget*)button, user_data);
3083}
561eba2a 3084
3085void
3086on_button_open_clicked (GtkButton *button,
3087 gpointer user_data)
3088{
e865422c 3089#ifdef UNFINISHED_FEATURE
561eba2a 3090 open_traceset((GtkWidget*)button, user_data);
e865422c 3091#endif
561eba2a 3092}
3093
3094
3095void
3096on_button_add_trace_clicked (GtkButton *button,
3097 gpointer user_data)
3098{
3099 add_trace((GtkWidget*)button, user_data);
3100}
3101
3102
3103void
3104on_button_remove_trace_clicked (GtkButton *button,
3105 gpointer user_data)
3106{
3107 remove_trace((GtkWidget*)button, user_data);
3108}
3109
9878c8a4 3110void
3111on_button_redraw_clicked (GtkButton *button,
3112 gpointer user_data)
3113{
3114 redraw((GtkWidget*)button, user_data);
3115}
3116
3117void
3118on_button_continue_processing_clicked (GtkButton *button,
3119 gpointer user_data)
3120{
3121 continue_processing((GtkWidget*)button, user_data);
3122}
3123
3124void
3125on_button_stop_processing_clicked (GtkButton *button,
3126 gpointer user_data)
3127{
3128 stop_processing((GtkWidget*)button, user_data);
3129}
3130
3131
561eba2a 3132
3133void
3134on_button_save_clicked (GtkButton *button,
3135 gpointer user_data)
3136{
3137 save((GtkWidget*)button, user_data);
3138}
3139
3140
3141void
3142on_button_save_as_clicked (GtkButton *button,
3143 gpointer user_data)
3144{
3145 save_as((GtkWidget*)button, user_data);
3146}
3147
3148
3149void
3150on_button_zoom_in_clicked (GtkButton *button,
3151 gpointer user_data)
3152{
3153 zoom_in((GtkWidget*)button, user_data);
3154}
3155
3156
3157void
3158on_button_zoom_out_clicked (GtkButton *button,
3159 gpointer user_data)
3160{
3161 zoom_out((GtkWidget*)button, user_data);
3162}
3163
3164
3165void
3166on_button_zoom_extended_clicked (GtkButton *button,
3167 gpointer user_data)
3168{
3169 zoom_extended((GtkWidget*)button, user_data);
3170}
3171
3172
3173void
3174on_button_go_to_time_clicked (GtkButton *button,
3175 gpointer user_data)
3176{
3177 go_to_time((GtkWidget*)button, user_data);
3178}
3179
3180
3181void
3182on_button_show_time_frame_clicked (GtkButton *button,
3183 gpointer user_data)
3184{
3185 show_time_frame((GtkWidget*)button, user_data);
3186}
3187
3188
3189void
3190on_button_move_up_clicked (GtkButton *button,
3191 gpointer user_data)
3192{
3193 move_up_viewer((GtkWidget*)button, user_data);
3194}
3195
3196
3197void
3198on_button_move_down_clicked (GtkButton *button,
3199 gpointer user_data)
3200{
3201 move_down_viewer((GtkWidget*)button, user_data);
3202}
3203
3204
3205void
3206on_button_delete_viewer_clicked (GtkButton *button,
3207 gpointer user_data)
3208{
3209 delete_viewer((GtkWidget*)button, user_data);
3210}
3211
3212void
2d262115 3213on_MWindow_destroy (GtkWidget *widget,
561eba2a 3214 gpointer user_data)
3215{
2d262115 3216 MainWindow *main_window = get_window_data_struct(widget);
ef68c3ac 3217 LttvIAttribute *attributes = main_window->attributes;
3218 LttvAttributeValue value;
8f318283 3219 gboolean retval;
e4d09234 3220
ef68c3ac 3221 //This is unnecessary, since widgets will be destroyed
3222 //by the main window widget anyway.
3223 //remove_all_menu_toolbar_constructors(main_window, NULL);
3224
8f318283
BP
3225 retval= lttv_iattribute_find_by_path(attributes, "viewers/menu",
3226 LTTV_POINTER, &value);
3227 g_assert(retval);
ef68c3ac 3228 lttv_menus_destroy((LttvMenus*)*(value.v_pointer));
3229
8f318283
BP
3230 retval= lttv_iattribute_find_by_path(attributes, "viewers/toolbar",
3231 LTTV_POINTER, &value);
3232 g_assert(retval);
ef68c3ac 3233 lttv_toolbars_destroy((LttvToolbars*)*(value.v_pointer));
2d262115 3234
ef68c3ac 3235 g_object_unref(main_window->attributes);
3236 g_main_window_list = g_slist_remove(g_main_window_list, main_window);
561eba2a 3237
56e5a0f7 3238 g_info("There are now : %d windows\n",g_slist_length(g_main_window_list));
2d262115 3239 if(g_slist_length(g_main_window_list) == 0)
d27948a3 3240 mainwindow_quit();
561eba2a 3241}
3242
58eecf4a 3243gboolean
3244on_MWindow_configure (GtkWidget *widget,
3245 GdkEventConfigure *event,
3246 gpointer user_data)
3247{
bd24a9af 3248 // MD : removed time width modification upon resizing of the main window.
3249 // The viewers will redraw themselves completely, without time interval
3250 // modification.
3251/* while(tab){
58eecf4a 3252 if(mw_data->window_width){
3253 time_span = LTTV_TRACESET_CONTEXT(tab->traceset_info->traceset_context)->Time_Span ;
3254 time_win = tab->time_window;
3255 ratio = width / mw_data->window_width;
3256 tab->time_window.time_width = ltt_time_mul(time_win.time_width,ratio);
3257 time = ltt_time_sub(time_span->endTime, time_win.start_time);
3258 if(ltt_time_compare(time, tab->time_window.time_width) < 0){
3259 tab->time_window.time_width = time;
3260 }
3261 }
3262 tab = tab->next;
3263 }
3264
3265 mw_data->window_width = (int)width;
bd24a9af 3266 */
58eecf4a 3267 return FALSE;
3268}
561eba2a 3269
abe346a3 3270/* Set current tab
3271 */
3272
561eba2a 3273void
3274on_MNotebook_switch_page (GtkNotebook *notebook,
3275 GtkNotebookPage *page,
3276 guint page_num,
3277 gpointer user_data)
3278{
47cd8a09 3279
561eba2a 3280}
3281
abe346a3 3282
e800cf84 3283void time_change_manager (Tab *tab,
3284 TimeWindow new_time_window)
451aaf27
FD
3285{
3286
e800cf84 3287 /* Only one source of time change */
3288 if(tab->time_manager_lock == TRUE) return;
3289
3290 tab->time_manager_lock = TRUE;
451aaf27
FD
3291 TimeInterval time_span;
3292
3293 LttvTraceset *ts = tab->traceset_info->traceset;
3294 time_span.start_time =ltt_time_from_uint64( lttv_traceset_get_timestamp_begin(ts));
3295 time_span.end_time = ltt_time_from_uint64(lttv_traceset_get_timestamp_end(ts));
3296
e800cf84 3297
e800cf84 3298 LttTime start_time = new_time_window.start_time;
6f26fc38 3299 LttTime end_time = new_time_window.end_time;
e800cf84 3300
a998b781 3301 g_assert(ltt_time_compare(start_time, end_time) < 0);
3302
e800cf84 3303 /* Set scrollbar */
3304 GtkAdjustment *adjustment = gtk_range_get_adjustment(GTK_RANGE(tab->scrollbar));
451aaf27
FD
3305 LttTime upper = ltt_time_sub(time_span.end_time, time_span.start_time);
3306
e800cf84 3307#if 0
3308 gtk_range_set_increments(GTK_RANGE(tab->scrollbar),
3309 ltt_time_to_double(new_time_window.time_width)
3310 / SCROLL_STEP_PER_PAGE
3311 * NANOSECONDS_PER_SECOND, /* step increment */
3312 ltt_time_to_double(new_time_window.time_width)
3313 * NANOSECONDS_PER_SECOND); /* page increment */
3314 gtk_range_set_range(GTK_RANGE(tab->scrollbar),
3315 0.0, /* lower */
3316 ltt_time_to_double(upper)
3317 * NANOSECONDS_PER_SECOND); /* upper */
3318#endif //0
3319 g_object_set(G_OBJECT(adjustment),
3320 "lower",
3321 0.0, /* lower */
3322 "upper",
c74e0cf9 3323 ltt_time_to_double(upper), /* upper */
e800cf84 3324 "step_increment",
a18124ff 3325 new_time_window.time_width_double
c74e0cf9 3326 / SCROLL_STEP_PER_PAGE, /* step increment */
e800cf84 3327 "page_increment",
a18124ff 3328 new_time_window.time_width_double,
c74e0cf9 3329 /* page increment */
e800cf84 3330 "page_size",
a18124ff 3331 new_time_window.time_width_double, /* page size */
e800cf84 3332 NULL);
3333 gtk_adjustment_changed(adjustment);
3334
3335 // g_object_set(G_OBJECT(adjustment),
3336 // "value",
3337 // ltt_time_to_double(
3338 // ltt_time_sub(start_time, time_span.start_time))
c74e0cf9 3339 // , /* value */
e800cf84 3340 // NULL);
3341 //gtk_adjustment_value_changed(adjustment);
3342 gtk_range_set_value(GTK_RANGE(tab->scrollbar),
3343 ltt_time_to_double(
c74e0cf9 3344 ltt_time_sub(start_time, time_span.start_time)) /* value */);
e800cf84 3345
3346 /* set the time bar. */
e800cf84 3347
6f26fc38 3348
4172f013
YB
3349 timebar_set_minmax_time(TIMEBAR(tab->MTimebar),
3350 &time_span.start_time,
3351 &time_span.end_time );
3352 timebar_set_start_time(TIMEBAR(tab->MTimebar),&start_time);
3353 timebar_set_end_time(TIMEBAR(tab->MTimebar),&end_time);
e800cf84 3354
e800cf84 3355
58de9fc1 3356
4172f013
YB
3357 /* call viewer hooks for new time window */
3358 set_time_window(tab, &new_time_window);
58de9fc1 3359
4172f013 3360 tab->time_manager_lock = FALSE;
451aaf27
FD
3361
3362
58de9fc1 3363}
3364
58de9fc1 3365
58de9fc1 3366
3367
e800cf84 3368
3369void current_time_change_manager (Tab *tab,
3370 LttTime new_current_time)
3371{
3372 /* Only one source of time change */
3373 if(tab->current_time_manager_lock == TRUE) return;
3374
3375 tab->current_time_manager_lock = TRUE;
3376
4172f013 3377 timebar_set_current_time(TIMEBAR(tab->MTimebar), &new_current_time);
e800cf84 3378
db8bc917 3379 set_current_time(tab, &new_current_time);
e800cf84 3380
3381 tab->current_time_manager_lock = FALSE;
3382}
3383
9a366873 3384void current_position_change_manager(Tab *tab, LttvTracesetPosition *pos)
5290ec02 3385{
9a366873 3386 lttv_traceset_seek_to_position( pos);
5290ec02 3387
9a366873 3388 LttTime new_time = lttv_traceset_position_get_time(pos);
16e2bb34 3389 /* Put the context in a state coherent position */
9a366873
FD
3390#ifdef BABEL_CLEANUP
3391 lttv_state_traceset_seek_time_closest((LttvTracesetState*)tsc, ltt_time_zero);
3392#endif /* BABEL_CLEANUP */
5290ec02 3393 current_time_change_manager(tab, new_time);
3394
3395 set_current_position(tab, pos);
3396}
3397
4172f013
YB
3398static void on_timebar_starttime_changed(Timebar *timebar,
3399 gpointer user_data)
e800cf84 3400{
4172f013 3401 Tab *tab = (Tab *)user_data;
9aaa78dc
FD
3402 LttvTraceset * ts =tab->traceset_info->traceset;
3403 TimeInterval time_span = lttv_traceset_get_time_span(ts);
4172f013
YB
3404
3405 TimeWindow new_time_window = tab->time_window;
3406 new_time_window.start_time = timebar_get_start_time(timebar);
3407
3408 LttTime end_time = new_time_window.end_time;
3409
3410 /* TODO ybrosseau 2010-12-02: This if should have been checked
3411 by the timebar already */
3412 if(ltt_time_compare(new_time_window.start_time, end_time) >= 0) {
3413 /* Then, we must push back end time : keep the same time width
3414 * if possible, else end traceset time */
3415 end_time = LTT_TIME_MIN(ltt_time_add(new_time_window.start_time,
3416 new_time_window.time_width),
3417 time_span.end_time);
3418 }
3419
3420 /* Fix the time width to fit start time and end time */
3421 new_time_window.time_width = ltt_time_sub(end_time,
3422 new_time_window.start_time);
3423
3424 new_time_window.time_width_double =
3425 ltt_time_to_double(new_time_window.time_width);
3426
3427 new_time_window.end_time = end_time;
3428
3429 /* Notify the time_manager */
3430 time_change_manager(tab, new_time_window);
9aaa78dc 3431
e800cf84 3432}
3433
4172f013
YB
3434static void on_timebar_endtime_changed(Timebar *timebar,
3435 gpointer user_data)
e800cf84 3436{
4172f013 3437 Tab *tab = (Tab *)user_data;
9aaa78dc
FD
3438 LttvTraceset * ts =tab->traceset_info->traceset;
3439 TimeInterval time_span = lttv_traceset_get_time_span(ts);
e800cf84 3440
4172f013
YB
3441 TimeWindow new_time_window = tab->time_window;
3442
3443 LttTime end_time = timebar_get_end_time(timebar);
3444
3445 /* TODO ybrosseau 2010-12-02: This if should have been
3446 checked by the timebar already */
3447 if(ltt_time_compare(new_time_window.start_time, end_time) >= 0) {
3448 /* Then, we must push front start time : keep the same time
3449 width if possible, else end traceset time */
3450 new_time_window.start_time = LTT_TIME_MAX(
3451 ltt_time_sub(end_time,
3452 new_time_window.time_width),
3453 time_span.start_time);
3454 }
e800cf84 3455
4172f013
YB
3456 /* Fix the time width to fit start time and end time */
3457 new_time_window.time_width = ltt_time_sub(end_time,
3458 new_time_window.start_time);
3459
3460 new_time_window.time_width_double =
3461 ltt_time_to_double(new_time_window.time_width);
3462
3463 new_time_window.end_time = end_time;
3464
3465 /* Notify the time_manager */
9aaa78dc 3466 time_change_manager(tab, new_time_window);
4172f013
YB
3467}
3468static void on_timebar_currenttime_changed(Timebar *timebar,
3469 gpointer user_data)
3470{
3471 Tab *tab = (Tab *)user_data;
3472
3473 LttTime new_current_time = timebar_get_current_time(timebar);
3474
3475 current_time_change_manager(tab, new_current_time);
3476}
e800cf84 3477
b052368a 3478void scroll_value_changed_cb(GtkWidget *scrollbar,
3479 gpointer user_data)
3480{
3481 Tab *tab = (Tab *)user_data;
e800cf84 3482 TimeWindow new_time_window;
b052368a 3483 LttTime time;
3484 GtkAdjustment *adjust = gtk_range_get_adjustment(GTK_RANGE(scrollbar));
3485 gdouble value = gtk_adjustment_get_value(adjust);
e800cf84 3486 // gdouble upper, lower, ratio, page_size;
3487 gdouble page_size;
9aaa78dc
FD
3488
3489 LttvTraceset * ts = tab->traceset_info->traceset;
3490 TimeInterval time_span = lttv_traceset_get_time_span(ts);
b052368a 3491
c74e0cf9 3492 time = ltt_time_add(ltt_time_from_double(value),
e800cf84 3493 time_span.start_time);
3494
3495 new_time_window.start_time = time;
3496
3497 page_size = adjust->page_size;
3498
3499 new_time_window.time_width =
c74e0cf9 3500 ltt_time_from_double(page_size);
e800cf84 3501
a18124ff 3502 new_time_window.time_width_double =
3503 page_size;
3504
6f26fc38 3505 new_time_window.end_time = ltt_time_add(new_time_window.start_time,
3506 new_time_window.time_width);
3507
e800cf84 3508
3509 time_change_manager(tab, new_time_window);
9aaa78dc 3510
e800cf84 3511#if 0
b052368a 3512 //time_window = tab->time_window;
3513
b052368a 3514 lower = adjust->lower;
3515 upper = adjust->upper;
3516 ratio = (value - lower) / (upper - lower);
2b5cc5a5 3517 g_info("lower %lu, upper %lu, value %lu, ratio %lu", lower, upper, value, ratio);
b052368a 3518
3519 //time = ltt_time_sub(time_span->end_time, time_span->start_time);
3520 //time = ltt_time_mul(time, (float)ratio);
3521 //time = ltt_time_add(time_span->start_time, time);
c74e0cf9 3522 time = ltt_time_add(ltt_time_from_double(value),
b9a010a2 3523 time_span.start_time);
b052368a 3524
3525 time_window.start_time = time;
3526
3527 page_size = adjust->page_size;
3528
3529 time_window.time_width =
c74e0cf9 3530 ltt_time_from_double(page_size);
b9a010a2 3531 //time = ltt_time_sub(time_span.end_time, time);
b052368a 3532 //if(ltt_time_compare(time,time_window.time_width) < 0){
3533 // time_window.time_width = time;
3534 //}
3535
3536 /* call viewer hooks for new time window */
3537 set_time_window(tab, &time_window);
e800cf84 3538#endif //0
9aaa78dc 3539
b052368a 3540}
3541
3542
abe346a3 3543/* Display a dialogue showing all eventtypes and traces, let user to select the interested
3544 * eventtypes, tracefiles and traces (filter)
3545 */
3546
abe346a3 3547/* Select a trace which will be removed from traceset
3548 */
3549
93ac601b 3550char * get_remove_trace(MainWindow *mw_data,
3551 char ** all_trace_name, int nb_trace)
2176f952 3552{
93ac601b 3553 return get_selection(mw_data, all_trace_name, nb_trace,
2176f952 3554 "Select a trace", "Trace pathname");
3555}
abe346a3 3556
3557
b052368a 3558/* Select a module which will be loaded
3559 */
3560
93ac601b 3561char * get_load_module(MainWindow *mw_data,
3562 char ** load_module_name, int nb_module)
b052368a 3563{
93ac601b 3564 return get_selection(mw_data, load_module_name, nb_module,
b052368a 3565 "Select a module to load", "Module name");
3566}
3567
3568
3569
3570
abe346a3 3571/* Select a module which will be unloaded
3572 */
3573
93ac601b 3574char * get_unload_module(MainWindow *mw_data,
3575 char ** loaded_module_name, int nb_module)
2176f952 3576{
93ac601b 3577 return get_selection(mw_data, loaded_module_name, nb_module,
b052368a 3578 "Select a module to unload", "Module name");
2176f952 3579}
3580
abe346a3 3581
3582/* Display a dialogue which shows all selectable items, let user to
3583 * select one of them
3584 */
3585
93ac601b 3586char * get_selection(MainWindow *mw_data,
3587 char ** loaded_module_name, int nb_module,
3588 char *title, char * column_title)
36b3c068 3589{
3590 GtkWidget * dialogue;
3591 GtkWidget * scroll_win;
3592 GtkWidget * tree;
3593 GtkListStore * store;
3594 GtkTreeViewColumn * column;
3595 GtkCellRenderer * renderer;
3596 GtkTreeSelection * select;
3597 GtkTreeIter iter;
3598 gint id, i;
3599 char * unload_module_name = NULL;
3600
2176f952 3601 dialogue = gtk_dialog_new_with_buttons(title,
36b3c068 3602 NULL,
3603 GTK_DIALOG_MODAL,
3604 GTK_STOCK_OK,GTK_RESPONSE_ACCEPT,
3605 GTK_STOCK_CANCEL,GTK_RESPONSE_REJECT,
3606 NULL);
3607 gtk_window_set_default_size((GtkWindow*)dialogue, 500, 200);
93ac601b 3608 gtk_window_set_transient_for(GTK_WINDOW(dialogue),
3609 GTK_WINDOW(mw_data->mwindow));
36b3c068 3610
3611 scroll_win = gtk_scrolled_window_new (NULL, NULL);
3612 gtk_widget_show ( scroll_win);
3613 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroll_win),
3614 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
3615
3616 store = gtk_list_store_new (N_COLUMNS,G_TYPE_STRING);
3617 tree = gtk_tree_view_new_with_model(GTK_TREE_MODEL (store));
3618 gtk_widget_show ( tree);
3619 g_object_unref (G_OBJECT (store));
3620
3621 renderer = gtk_cell_renderer_text_new ();
2176f952 3622 column = gtk_tree_view_column_new_with_attributes (column_title,
36b3c068 3623 renderer,
3624 "text", MODULE_COLUMN,
3625 NULL);
3626 gtk_tree_view_column_set_alignment (column, 0.5);
3627 gtk_tree_view_column_set_fixed_width (column, 150);
3628 gtk_tree_view_append_column (GTK_TREE_VIEW (tree), column);
3629
3630 select = gtk_tree_view_get_selection (GTK_TREE_VIEW (tree));
3631 gtk_tree_selection_set_mode (select, GTK_SELECTION_SINGLE);
3632
3633 gtk_container_add (GTK_CONTAINER (scroll_win), tree);
3634
3635 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialogue)->vbox), scroll_win,TRUE, TRUE,0);
3636
3637 for(i=0;i<nb_module;i++){
3638 gtk_list_store_append (store, &iter);
3639 gtk_list_store_set (store, &iter, MODULE_COLUMN,loaded_module_name[i],-1);
3640 }
3641
3642 id = gtk_dialog_run(GTK_DIALOG(dialogue));
d27948a3 3643 GtkTreeModel **store_model = (GtkTreeModel**)&store;
36b3c068 3644 switch(id){
3645 case GTK_RESPONSE_ACCEPT:
3646 case GTK_RESPONSE_OK:
2eef04b5 3647 if (gtk_tree_selection_get_selected (select, store_model, &iter)){
36b3c068 3648 gtk_tree_model_get ((GtkTreeModel*)store, &iter, MODULE_COLUMN, &unload_module_name, -1);
3649 }
3650 case GTK_RESPONSE_REJECT:
3651 case GTK_RESPONSE_CANCEL:
3652 default:
3653 gtk_widget_destroy(dialogue);
3654 break;
3655 }
3656
3657 return unload_module_name;
3658}
5723fa24 3659
abe346a3 3660
ef68c3ac 3661/* Insert all menu entry and tool buttons into this main window
001d8606 3662 * for modules.
3663 *
abe346a3 3664 */
3665
6c9d86dd 3666void add_all_menu_toolbar_constructors(MainWindow * mw, gpointer user_data)
5723fa24 3667{
2eef04b5 3668 guint i;
5723fa24 3669 GdkPixbuf *pixbuf;
42fcbb71 3670 lttvwindow_viewer_constructor constructor;
001d8606 3671 LttvMenus * global_menu, * instance_menu;
3672 LttvToolbars * global_toolbar, * instance_toolbar;
6c9d86dd 3673 LttvMenuClosure *menu_item;
3674 LttvToolbarClosure *toolbar_item;
5723fa24 3675 LttvAttributeValue value;
001d8606 3676 LttvIAttribute *global_attributes = LTTV_IATTRIBUTE(lttv_global_attributes());
501e4e70 3677 LttvIAttribute *attributes = mw->attributes;
001d8606 3678 GtkWidget * tool_menu_title_menu, *new_widget, *pixmap;
8f318283 3679 gboolean retval;
001d8606 3680
8f318283
BP
3681 retval= lttv_iattribute_find_by_path(global_attributes, "viewers/menu",
3682 LTTV_POINTER, &value);
3683 g_assert(retval);
001d8606 3684 if(*(value.v_pointer) == NULL)
501e4e70 3685 *(value.v_pointer) = lttv_menus_new();
001d8606 3686 global_menu = (LttvMenus*)*(value.v_pointer);
5723fa24 3687
8f318283
BP
3688 retval= lttv_iattribute_find_by_path(attributes, "viewers/menu",
3689 LTTV_POINTER, &value);
3690 g_assert(retval);
001d8606 3691 if(*(value.v_pointer) == NULL)
501e4e70 3692 *(value.v_pointer) = lttv_menus_new();
001d8606 3693 instance_menu = (LttvMenus*)*(value.v_pointer);
5723fa24 3694
8f318283
BP
3695 retval= lttv_iattribute_find_by_path(global_attributes, "viewers/toolbar",
3696 LTTV_POINTER, &value);
3697 g_assert(retval);
001d8606 3698 if(*(value.v_pointer) == NULL)
501e4e70 3699 *(value.v_pointer) = lttv_toolbars_new();
001d8606 3700 global_toolbar = (LttvToolbars*)*(value.v_pointer);
3701
8f318283
BP
3702 retval= lttv_iattribute_find_by_path(attributes, "viewers/toolbar",
3703 LTTV_POINTER, &value);
3704 g_assert(retval);
001d8606 3705 if(*(value.v_pointer) == NULL)
501e4e70 3706 *(value.v_pointer) = lttv_toolbars_new();
001d8606 3707 instance_toolbar = (LttvToolbars*)*(value.v_pointer);
3708
3709 /* Add missing menu entries to window instance */
3710 for(i=0;i<global_menu->len;i++) {
6c9d86dd 3711 menu_item = &g_array_index(global_menu, LttvMenuClosure, i);
3712
3713 //add menu_item to window instance;
3714 constructor = menu_item->con;
3715 tool_menu_title_menu = lookup_widget(mw->mwindow,"ToolMenuTitle_menu");
3716 new_widget =
501e4e70 3717 gtk_menu_item_new_with_mnemonic (menu_item->menu_text);
6c9d86dd 3718 gtk_container_add (GTK_CONTAINER (tool_menu_title_menu),
3719 new_widget);
3720 g_signal_connect ((gpointer) new_widget, "activate",
3721 G_CALLBACK (insert_viewer_wrap),
3722 constructor);
3723 gtk_widget_show (new_widget);
3724 lttv_menus_add(instance_menu, menu_item->con,
3725 menu_item->menu_path,
3726 menu_item->menu_text,
3727 new_widget);
001d8606 3728
001d8606 3729 }
3730
3731 /* Add missing toolbar entries to window instance */
3732 for(i=0;i<global_toolbar->len;i++) {
6c9d86dd 3733 toolbar_item = &g_array_index(global_toolbar, LttvToolbarClosure, i);
3734
3735 //add toolbar_item to window instance;
3736 constructor = toolbar_item->con;
3737 tool_menu_title_menu = lookup_widget(mw->mwindow,"MToolbar1");
3738 pixbuf = gdk_pixbuf_new_from_xpm_data((const char**)toolbar_item->pixmap);
3739 pixmap = gtk_image_new_from_pixbuf(pixbuf);
3740 new_widget =
3741 gtk_toolbar_append_element (GTK_TOOLBAR (tool_menu_title_menu),
3742 GTK_TOOLBAR_CHILD_BUTTON,
3743 NULL,
3744 "",
3745 toolbar_item->tooltip, NULL,
3746 pixmap, NULL, NULL);
3747 gtk_label_set_use_underline(
3748 GTK_LABEL (((GtkToolbarChild*) (
3749 g_list_last (GTK_TOOLBAR
3750 (tool_menu_title_menu)->children)->data))->label),
3751 TRUE);
3752 gtk_container_set_border_width (GTK_CONTAINER (new_widget), 1);
3753 g_signal_connect ((gpointer) new_widget,
3754 "clicked",
3755 G_CALLBACK (insert_viewer_wrap),
3756 constructor);
3757 gtk_widget_show (new_widget);
001d8606 3758
6c9d86dd 3759 lttv_toolbars_add(instance_toolbar, toolbar_item->con,
3760 toolbar_item->tooltip,
3761 toolbar_item->pixmap,
3762 new_widget);
001d8606 3763
5723fa24 3764 }
6c9d86dd 3765
5723fa24 3766}
3767
abe346a3 3768
3769/* Create a main window
3770 */
3771
8321ae6a 3772MainWindow *construct_main_window(MainWindow * parent)
5723fa24 3773{
8f318283
BP
3774 gboolean retval;
3775
2a2fa4f0 3776 g_debug("construct_main_window()");
68b48a45 3777 GtkWidget * new_window; /* New generated main window */
bca3b81f 3778 MainWindow * new_m_window;/* New main window structure */
5723fa24 3779 GtkNotebook * notebook;
f7afe191 3780 LttvIAttribute *attributes =
3781 LTTV_IATTRIBUTE(g_object_new(LTTV_ATTRIBUTE_TYPE, NULL));
3782 LttvAttributeValue value;
e865422c 3783
bca3b81f 3784 new_m_window = g_new(MainWindow, 1);
5723fa24 3785
3786 // Add the object's information to the module's array
68b48a45 3787 g_main_window_list = g_slist_append(g_main_window_list, new_m_window);
5723fa24 3788
68b48a45 3789 new_window = create_MWindow();
3790 gtk_widget_show (new_window);
5723fa24 3791
bca3b81f 3792 new_m_window->mwindow = new_window;
a43d67ba 3793 new_m_window->attributes = attributes;
5723fa24 3794
8f318283
BP
3795 retval= lttv_iattribute_find_by_path(attributes, "viewers/menu",
3796 LTTV_POINTER, &value);
3797 g_assert(retval);
501e4e70 3798 *(value.v_pointer) = lttv_menus_new();
001d8606 3799
8f318283
BP
3800 retval= lttv_iattribute_find_by_path(attributes, "viewers/toolbar",
3801 LTTV_POINTER, &value);
3802 g_assert(retval);
501e4e70 3803 *(value.v_pointer) = lttv_toolbars_new();
2061e03d 3804
6c9d86dd 3805 add_all_menu_toolbar_constructors(new_m_window, NULL);
5723fa24 3806
2d262115 3807 g_object_set_data_full(G_OBJECT(new_window),
3808 "main_window_data",
3809 (gpointer)new_m_window,
3810 (GDestroyNotify)g_free);
5723fa24 3811 //create a default tab
bca3b81f 3812 notebook = (GtkNotebook *)lookup_widget(new_m_window->mwindow, "MNotebook");
5723fa24 3813 if(notebook == NULL){
56e5a0f7 3814 g_info("Notebook does not exist\n");
8321ae6a 3815 /* FIXME : destroy partially created widgets */
3816 g_free(new_m_window);
3817 return NULL;
5723fa24 3818 }
e800cf84 3819 //gtk_notebook_popup_enable (GTK_NOTEBOOK(notebook));
5723fa24 3820 //for now there is no name field in LttvTraceset structure
3821 //Use "Traceset" as the label for the default tab
6ced96ef 3822 if(parent) {
3823 GtkWidget * parent_notebook = lookup_widget(parent->mwindow, "MNotebook");
3824 GtkWidget *page = gtk_notebook_get_nth_page(GTK_NOTEBOOK(parent_notebook),
3825 gtk_notebook_get_current_page(GTK_NOTEBOOK(parent_notebook)));
3826 Tab *parent_tab;
3827
3828 if(!page) {
3829 parent_tab = NULL;
3830 } else {
e433e6d6 3831 LttvPluginTab *ptab;
3832 ptab = (LttvPluginTab *)g_object_get_data(G_OBJECT(page), "Tab_Plugin");
3833 parent_tab = ptab->tab;
6ced96ef 3834 }
e433e6d6 3835 LttvPluginTab *ptab = g_object_new(LTTV_TYPE_PLUGIN_TAB, NULL);
3836 init_tab(ptab->tab,
3837 new_m_window, parent_tab, notebook, "Traceset");
3838 ptab->parent.top_widget = ptab->tab->top_widget;
3839 g_object_set_data_full(
3840 G_OBJECT(ptab->tab->vbox),
3841 "Tab_Plugin",
3842 ptab,
3843 (GDestroyNotify)tab_destructor);
6ced96ef 3844 } else {
e433e6d6 3845 LttvPluginTab *ptab = g_object_new(LTTV_TYPE_PLUGIN_TAB, NULL);
3846 init_tab(ptab->tab, new_m_window, NULL, notebook, "Traceset");
3847 ptab->parent.top_widget = ptab->tab->top_widget;
3848 g_object_set_data_full(
3849 G_OBJECT(ptab->tab->vbox),
3850 "Tab_Plugin",
3851 ptab,
3852 (GDestroyNotify)tab_destructor);
6cec4cd2 3853 }
91fd6881 3854
6cec4cd2 3855 /* Insert default viewers */
3856 {
3857 LttvAttributeType type;
3858 LttvAttributeName name;
3859 LttvAttributeValue value;
3860 LttvAttribute *attribute;
3861
3862 LttvIAttribute *attributes_global =
3863 LTTV_IATTRIBUTE(lttv_global_attributes());
3864
43ed82b5 3865 attribute = LTTV_ATTRIBUTE(lttv_iattribute_find_subdir(
3866 LTTV_IATTRIBUTE(attributes_global),
3867 LTTV_VIEWER_CONSTRUCTORS));
3868 g_assert(attribute);
6cec4cd2 3869
3870 name = g_quark_from_string("guievents");
3871 type = lttv_iattribute_get_by_name(LTTV_IATTRIBUTE(attribute),
3872 name, &value);
3873 if(type == LTTV_POINTER) {
3874 lttvwindow_viewer_constructor viewer_constructor =
3875 (lttvwindow_viewer_constructor)*value.v_pointer;
3876 insert_viewer(new_window, viewer_constructor);
4266dc7f 3877 }
e025a729 3878
6cec4cd2 3879 name = g_quark_from_string("guicontrolflow");
3880 type = lttv_iattribute_get_by_name(LTTV_IATTRIBUTE(attribute),
3881 name, &value);
3882 if(type == LTTV_POINTER) {
3883 lttvwindow_viewer_constructor viewer_constructor =
3884 (lttvwindow_viewer_constructor)*value.v_pointer;
3885 insert_viewer(new_window, viewer_constructor);
3886 }
e025a729 3887
6cec4cd2 3888 name = g_quark_from_string("guistatistics");
3889 type = lttv_iattribute_get_by_name(LTTV_IATTRIBUTE(attribute),
3890 name, &value);
3891 if(type == LTTV_POINTER) {
3892 lttvwindow_viewer_constructor viewer_constructor =
3893 (lttvwindow_viewer_constructor)*value.v_pointer;
3894 insert_viewer(new_window, viewer_constructor);
e025a729 3895 }
4266dc7f 3896 }
5723fa24 3897
56e5a0f7 3898 g_info("There are now : %d windows\n",g_slist_length(g_main_window_list));
8321ae6a 3899
3900 return new_m_window;
5723fa24 3901}
3902
abe346a3 3903
3904/* Free the memory occupied by a tab structure
3905 * destroy the tab
3906 */
3907
e433e6d6 3908void tab_destructor(LttvPluginTab * ptab)
f7afe191 3909{
451aaf27 3910#ifdef BABEL_CLEANUP
716e4367 3911 int i, nb, ref_count;
3912 LttvTrace * trace;
e433e6d6 3913 Tab *tab = ptab->tab;
716e4367 3914
3234f094 3915 if(tab->attributes)
3916 g_object_unref(tab->attributes);
501e4e70 3917
3234f094 3918 if(tab->interrupted_state)
3919 g_object_unref(tab->interrupted_state);
501e4e70 3920
2061e03d 3921
3234f094 3922 if(tab->traceset_info->traceset_context != NULL){
784705cc 3923 //remove state update hooks
3924 lttv_state_remove_event_hooks(
3234f094 3925 (LttvTracesetState*)tab->traceset_info->
784705cc 3926 traceset_context);
3234f094 3927 lttv_context_fini(LTTV_TRACESET_CONTEXT(tab->traceset_info->
716e4367 3928 traceset_context));
3234f094 3929 g_object_unref(tab->traceset_info->traceset_context);
716e4367 3930 }
3234f094 3931 if(tab->traceset_info->traceset != NULL) {
3932 nb = lttv_traceset_number(tab->traceset_info->traceset);
716e4367 3933 for(i = 0 ; i < nb ; i++) {
3234f094 3934 trace = lttv_traceset_get(tab->traceset_info->traceset, i);
716e4367 3935 ref_count = lttv_trace_get_ref_number(trace);
49bf71b5 3936 if(ref_count <= 1){
a1a2b649 3937 ltt_trace_close(lttv_trace(trace));
49bf71b5 3938 }
716e4367 3939 }
dc5e5266 3940 }
3234f094 3941 lttv_traceset_destroy(tab->traceset_info->traceset);
501e4e70 3942 /* Remove the idle events requests processing function of the tab */
3234f094 3943 g_idle_remove_by_data(tab);
501e4e70 3944
3234f094 3945 g_slist_free(tab->events_requests);
3946 g_free(tab->traceset_info);
e433e6d6 3947 //g_free(tab);
3948 g_object_unref(ptab);
451aaf27 3949#endif /* BABEL_CLEANUP */
f7afe191 3950}
3951
abe346a3 3952
3953/* Create a tab and insert it into the current main window
3954 */
3955
e433e6d6 3956void init_tab(Tab *tab, MainWindow * mw, Tab *copy_tab,
716e4367 3957 GtkNotebook * notebook, char * label)
5723fa24 3958{
451aaf27 3959
5723fa24 3960 GList * list;
e433e6d6 3961 //Tab * tab;
3962 //LttvFilter *filter = NULL;
a43d67ba 3963
abe346a3 3964 //create a new tab data structure
e433e6d6 3965 //tab = g_new(Tab,1);
716e4367 3966
abe346a3 3967 //construct and initialize the traceset_info
6ced96ef 3968 tab->traceset_info = g_new(TracesetInfo,1);
a43d67ba 3969
4266dc7f 3970 if(copy_tab) {
6ced96ef 3971 tab->traceset_info->traceset =
4266dc7f 3972 lttv_traceset_copy(copy_tab->traceset_info->traceset);
dc5e5266 3973
3974 /* Copy the previous tab's filter */
3975 /* We can clone the filter, as we copy the trace set also */
3976 /* The filter must always be in sync with the trace set */
451aaf27
FD
3977
3978#ifdef BABEL_CLEANUP
ebcead4a 3979 tab->filter = lttv_filter_clone(copy_tab->filter);
451aaf27 3980#endif /* BABEL_CLEANUP */
4266dc7f 3981 } else {
6ced96ef 3982 tab->traceset_info->traceset = lttv_traceset_new();
451aaf27 3983
dc5e5266 3984 tab->filter = NULL;
716e4367 3985 }
84ddf5c9 3986#ifdef DEBUG
20fde85f 3987 lttv_attribute_write_xml(
6ced96ef 3988 lttv_traceset_attribute(tab->traceset_info->traceset),
20fde85f 3989 stdout,
3990 0, 4);
3991 fflush(stdout);
84ddf5c9 3992#endif //DEBUG
451aaf27 3993//
e800cf84 3994 tab->time_manager_lock = FALSE;
3995 tab->current_time_manager_lock = FALSE;
451aaf27 3996#ifdef BABEL_CLEANUP
716e4367 3997 //FIXME copy not implemented in lower level
6ced96ef 3998 tab->traceset_info->traceset_context =
716e4367 3999 g_object_new(LTTV_TRACESET_STATS_TYPE, NULL);
784705cc 4000 //add state update hooks
4001 lttv_state_add_event_hooks(
6ced96ef 4002 (LttvTracesetState*)tab->traceset_info->traceset_context);
451aaf27 4003#endif //BABEL_CLEANUP
abe346a3 4004 //determine the current_time and time_window of the tab
e800cf84 4005#if 0
6ced96ef 4006 if(copy_tab != NULL){
4007 tab->time_window = copy_tab->time_window;
4008 tab->current_time = copy_tab->current_time;
5723fa24 4009 }else{
6ced96ef 4010 tab->time_window.start_time =
4011 LTTV_TRACESET_CONTEXT(tab->traceset_info->traceset_context)->
4012 time_span.start_time;
f7afe191 4013 if(DEFAULT_TIME_WIDTH_S <
6ced96ef 4014 LTTV_TRACESET_CONTEXT(tab->traceset_info->traceset_context)->
4015 time_span.end_time.tv_sec)
68b48a45 4016 tmp_time.tv_sec = DEFAULT_TIME_WIDTH_S;
f7afe191 4017 else
68b48a45 4018 tmp_time.tv_sec =
6ced96ef 4019 LTTV_TRACESET_CONTEXT(tab->traceset_info->traceset_context)->
4020 time_span.end_time.tv_sec;
68b48a45 4021 tmp_time.tv_nsec = 0;
6ced96ef 4022 tab->time_window.time_width = tmp_time ;
4023 tab->current_time.tv_sec =
4024 LTTV_TRACESET_CONTEXT(tab->traceset_info->traceset_context)->
4025 time_span.start_time.tv_sec;
4026 tab->current_time.tv_nsec =
4027 LTTV_TRACESET_CONTEXT(tab->traceset_info->traceset_context)->
4028 time_span.start_time.tv_nsec;
5723fa24 4029 }
e800cf84 4030#endif //0
6ced96ef 4031 tab->attributes = LTTV_IATTRIBUTE(g_object_new(LTTV_ATTRIBUTE_TYPE, NULL));
4032 tab->interrupted_state = g_object_new(LTTV_ATTRIBUTE_TYPE, NULL);
b052368a 4033
58f6c2a4 4034 tab->vbox = gtk_vbox_new(FALSE, 2);
e433e6d6 4035 tab->top_widget = tab->vbox;
4036 //g_object_set_data_full(G_OBJECT(tab->top_widget), "filter",
4037// filter, (GDestroyNotify)lttv_filter_destroy);
4038
4039// g_signal_connect (G_OBJECT(tab->top_widget),
4040// "notify",
4041// G_CALLBACK (on_top_notify),
4042// (gpointer)tab);
4043
58f6c2a4 4044 tab->viewer_container = gtk_vbox_new(TRUE, 2);
b052368a 4045 tab->scrollbar = gtk_hscrollbar_new(NULL);
4046 //tab->multivpaned = gtk_multi_vpaned_new();
6c35c853 4047
b052368a 4048 gtk_box_pack_start(GTK_BOX(tab->vbox),
4049 tab->viewer_container,
4050 TRUE, /* expand */
4051 TRUE, /* Give the extra space to the child */
4052 0); /* No padding */
4249a3e8 4053
4054// if(copy_tab) {
4055// tab->time_window = copy_tab->time_window;
4056// tab->current_time = copy_tab->current_time;
4057// }
e800cf84 4058
4059 /* Create the timebar */
4172f013
YB
4060
4061 tab->MTimebar = timebar_new();
e800cf84 4062
b052368a 4063 gtk_box_pack_end(GTK_BOX(tab->vbox),
4064 tab->scrollbar,
4065 FALSE, /* Do not expand */
4066 FALSE, /* Fill has no effect here (expand false) */
4067 0); /* No padding */
e800cf84 4068
4069 gtk_box_pack_end(GTK_BOX(tab->vbox),
4070 tab->MTimebar,
4071 FALSE, /* Do not expand */
4072 FALSE, /* Fill has no effect here (expand false) */
4073 0); /* No padding */
4074
b052368a 4075 g_object_set_data(G_OBJECT(tab->viewer_container), "focused_viewer", NULL);
4076
4077
6ced96ef 4078 tab->mw = mw;
27a559b9 4079
3c031040 4080 /*{
4081 // Display a label with a X
27a559b9 4082 GtkWidget *w_hbox = gtk_hbox_new(FALSE, 4);
4083 GtkWidget *w_label = gtk_label_new (label);
4084 GtkWidget *pixmap = create_pixmap(GTK_WIDGET(notebook), "close.png");
4085 GtkWidget *w_button = gtk_button_new ();
4086 gtk_container_add(GTK_CONTAINER(w_button), pixmap);
4087 //GtkWidget *w_button = gtk_button_new_with_label("x");
4088
4089 gtk_button_set_relief(GTK_BUTTON(w_button), GTK_RELIEF_NONE);
4090
4091 gtk_box_pack_start(GTK_BOX(w_hbox), w_label, TRUE, TRUE, 0);
4092 gtk_box_pack_end(GTK_BOX(w_hbox), w_button, FALSE,
4093 FALSE, 0);
a43d67ba 4094
27a559b9 4095 g_signal_connect_swapped (w_button, "clicked",
4096 G_CALLBACK (on_close_tab_X_clicked),
4097 tab->multi_vpaned);
5723fa24 4098
3c031040 4099 gtk_widget_set_state(w_button, GTK_STATE_ACTIVE);
4100
27a559b9 4101 gtk_widget_show (w_label);
4102 gtk_widget_show (pixmap);
4103 gtk_widget_show (w_button);
4104 gtk_widget_show (w_hbox);
4105
4106 tab->label = w_hbox;
3c031040 4107 }*/
4108
4109
4110 tab->label = gtk_label_new (label);
b052368a 4111
4112 gtk_widget_show(tab->label);
4113 gtk_widget_show(tab->scrollbar);
4172f013 4114 gtk_widget_show(tab->MTimebar);
b052368a 4115 gtk_widget_show(tab->viewer_container);
4116 gtk_widget_show(tab->vbox);
4172f013 4117
b052368a 4118 //gtk_widget_show(tab->multivpaned);
3c031040 4119
4120
501e4e70 4121 /* Start with empty events requests list */
6ced96ef 4122 tab->events_requests = NULL;
4123 tab->events_request_pending = FALSE;
5698740e 4124 tab->stop_foreground = FALSE;
4125
a43d67ba 4126
540edb40 4127
b052368a 4128 g_signal_connect(G_OBJECT(tab->scrollbar), "value-changed",
4129 G_CALLBACK(scroll_value_changed_cb), tab);
e800cf84 4130
4172f013
YB
4131
4132 /* Timebar signal handler */
4133 g_signal_connect(G_OBJECT(tab->MTimebar), "start-time-changed",
4134 G_CALLBACK(on_timebar_starttime_changed), tab);
4135 g_signal_connect(G_OBJECT(tab->MTimebar), "end-time-changed",
4136 G_CALLBACK(on_timebar_endtime_changed), tab);
4137 g_signal_connect(G_OBJECT(tab->MTimebar), "current-time-changed",
4138 G_CALLBACK(on_timebar_currenttime_changed), tab);
e800cf84 4139
b052368a 4140 //g_signal_connect(G_OBJECT(tab->scrollbar), "changed",
4141 // G_CALLBACK(scroll_value_changed_cb), tab);
4142
4143
784705cc 4144 //insert tab into notebook
6ced96ef 4145 gtk_notebook_append_page(notebook,
b052368a 4146 tab->vbox,
4147 tab->label);
5723fa24 4148 list = gtk_container_get_children(GTK_CONTAINER(notebook));
4149 gtk_notebook_set_current_page(notebook,g_list_length(list)-1);
a43d67ba 4150 // always show : not if(g_list_length(list)>1)
4151 gtk_notebook_set_show_tabs(notebook, TRUE);
4152
4249a3e8 4153 if(copy_tab) {
4154 lttvwindow_report_time_window(tab, copy_tab->time_window);
4155 lttvwindow_report_current_time(tab, copy_tab->current_time);
4156 } else {
4157 TimeWindow time_window;
4158
4159 time_window.start_time = ltt_time_zero;
4160 time_window.end_time = ltt_time_add(time_window.start_time,
4161 lttvwindow_default_time_width);
4162 time_window.time_width = lttvwindow_default_time_width;
4163 time_window.time_width_double = ltt_time_to_double(time_window.time_width);
4164
4165 lttvwindow_report_time_window(tab, time_window);
4166 lttvwindow_report_current_time(tab, ltt_time_zero);
4167 }
451aaf27 4168
4249a3e8 4169 LttvTraceset *traceset = tab->traceset_info->traceset;
4170 SetTraceset(tab, traceset);
a43d67ba 4171}
4172
501e4e70 4173/*
4174 * execute_events_requests
4175 *
4176 * Idle function that executes the pending requests for a tab.
4177 *
4178 * @return return value : TRUE : keep the idle function, FALSE : remove it.
4179 */
4180gboolean execute_events_requests(Tab *tab)
a43d67ba 4181{
501e4e70 4182 return ( lttvwindow_process_pending_requests(tab) );
a43d67ba 4183}
4184
8321ae6a 4185
451aaf27 4186__EXPORT void create_main_window_with_trace_list(GSList *traces)
8321ae6a 4187{
451aaf27 4188
8e3a7c75 4189 GSList *iter = NULL;
8321ae6a 4190
4191 /* Create window */
4192 MainWindow *mw = construct_main_window(NULL);
4193 GtkWidget *widget = mw->mwindow;
4194
4195 GtkWidget * notebook = lookup_widget(widget, "MNotebook");
4196 GtkWidget *page = gtk_notebook_get_nth_page(GTK_NOTEBOOK(notebook),
4197 gtk_notebook_get_current_page(GTK_NOTEBOOK(notebook)));
e433e6d6 4198 LttvPluginTab *ptab;
8321ae6a 4199 Tab *tab;
4200
4201 if(!page) {
e433e6d6 4202 ptab = create_new_tab(widget, NULL);
4203 tab = ptab->tab;
8321ae6a 4204 } else {
e433e6d6 4205 ptab = (LttvPluginTab *)g_object_get_data(G_OBJECT(page), "Tab_Plugin");
4206 tab = ptab->tab;
8321ae6a 4207 }
451aaf27
FD
4208
4209 LttvTraceset * traceset = lttv_traceset_new();
8e3a7c75 4210 for(iter=traces; iter!=NULL; iter=g_slist_next(iter)) {
4211 gchar *path = (gchar*)iter->data;
4212 /* Add trace */
4213 gchar abs_path[PATH_MAX];
8e3a7c75 4214
451aaf27 4215
8e3a7c75 4216 get_absolute_pathname(path, abs_path);
451aaf27
FD
4217
4218 if(lttv_traceset_add_path(traceset,abs_path) != 0 ){ /*failure*/
4219
4220 g_warning("cannot open trace %s", abs_path);
8e3a7c75 4221
4222 GtkWidget *dialogue =
4223 gtk_message_dialog_new(
4224 GTK_WINDOW(gtk_widget_get_toplevel(widget)),
4225 GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT,
4226 GTK_MESSAGE_ERROR,
4227 GTK_BUTTONS_OK,
0246f776 4228 "Cannot open trace : maybe you should enter in the directory "
8e3a7c75 4229 "to select it ?");
4230 gtk_dialog_run(GTK_DIALOG(dialogue));
4231 gtk_widget_destroy(dialogue);
8321ae6a 4232 }
451aaf27
FD
4233 else{
4234 SetTraceset(tab, traceset);
4235 }
4236 }
8321ae6a 4237}
4238
This page took 0.342695 seconds and 4 git commands to generate.