a8a7ad9ed1ed3cd6b3321d9775bd0b5ee4028472
[lttv.git] / lttv / modules / gui / lttvwindow / lttvwindow / callbacks.c
1 /* This file is part of the Linux Trace Toolkit viewer
2 * Copyright (C) 2003-2004 XangXiu Yang, Mathieu Desnoyers
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License Version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
16 * MA 02111-1307, USA.
17 */
18
19 #ifdef HAVE_CONFIG_H
20 # include <config.h>
21 #endif
22
23 #include <limits.h> // for PATH_MAX
24 #include <stdlib.h>
25 #include <ctype.h>
26 #include <string.h>
27 #include <stdlib.h>
28
29 #include <gtk/gtk.h>
30
31 #include "callbacks.h"
32 #include "interface.h"
33 #include "support.h"
34 #include <ltt/trace.h>
35 #include <ltt/time.h>
36 #include <ltt/event.h>
37 #include <lttv/lttv.h>
38 #include <lttv/module.h>
39 #include <lttv/iattribute.h>
40 #include <lttv/traceset.h>
41 #ifdef BABEL_CLEANUP
42 #include <lttv/stats.h>
43 #include <lttv/sync/sync_chain_lttv.h>
44 #endif /* BABEL_CLEANUP */
45 #include <lttv/filter.h>
46 #include <lttvwindow/mainwindow.h>
47 #include <lttvwindow/mainwindow-private.h>
48 #include <lttvwindow/menu.h>
49 #include <lttvwindow/timebar.h>
50 #include <lttvwindow/toolbar.h>
51 #include <lttvwindow/lttvwindow.h>
52 #include <lttvwindow/lttvwindowtraces.h>
53 #include <lttvwindow/lttv_plugin_tab.h>
54
55 #include <babeltrace/babeltrace.h>
56 #include <babeltrace/ctf/events.h>
57 #include <babeltrace/ctf/iterator.h>
58
59 static LttTime lttvwindow_default_time_width = { 1, 0 };
60 #define CLIP_BUF 256 // size of clipboard buffer
61
62 extern LttvTrace *g_init_trace ;
63
64
65 /** Array containing instanced objects. */
66 extern GSList * g_main_window_list;
67
68 /** MD : keep old directory. */
69 static char remember_plugins_dir[PATH_MAX] = "";
70 static char remember_trace_dir[PATH_MAX] = "";
71
72 void tab_destructor(LttvPluginTab * ptab);
73
74 MainWindow * get_window_data_struct(GtkWidget * widget);
75 char * get_load_module(MainWindow *mw,
76 char ** load_module_name, int nb_module);
77 char * get_unload_module(MainWindow *mw,
78 char ** loaded_module_name, int nb_module);
79 char * get_remove_trace(MainWindow *mw, char ** all_trace_name, int nb_trace);
80 char * get_selection(MainWindow *mw,
81 char ** all_name, int nb, char *title, char * column_title);
82 void init_tab(Tab *tab, MainWindow * mw, Tab *copy_tab,
83 GtkNotebook * notebook, char * label);
84
85 int update_traceset(Tab *tab, LttvTraceset *traceset);
86
87 static void insert_viewer(GtkWidget* widget, lttvwindow_viewer_constructor constructor);
88
89 LttvPluginTab *create_new_tab(GtkWidget* widget, gpointer user_data);
90
91 static gboolean lttvwindow_process_pending_requests(Tab *tab);
92
93 static void on_timebar_starttime_changed(Timebar *timebar,
94 gpointer user_data);
95 static void on_timebar_endtime_changed(Timebar *timebar,
96 gpointer user_data);
97 static void on_timebar_currenttime_changed(Timebar *timebar,
98 gpointer user_data);
99
100 enum {
101 CHECKBOX_COLUMN,
102 NAME_COLUMN,
103 TOTAL_COLUMNS
104 };
105
106 enum
107 {
108 MODULE_COLUMN,
109 N_COLUMNS
110 };
111
112
113 #if 0
114 static 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");
120
121 }
122 #endif //0
123 static gboolean viewer_grab_focus(GtkWidget *widget, GdkEventButton *event,
124 gpointer data)
125 {
126 GtkWidget *viewer = GTK_WIDGET(data);
127 GtkWidget *viewer_container = gtk_widget_get_parent(viewer);
128
129 g_debug("FOCUS GRABBED");
130 g_object_set_data(G_OBJECT(viewer_container), "focused_viewer", viewer);
131 return 0;
132 }
133
134
135 static 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);
142
143 }
144 if(GTK_IS_TREE_VIEW(widget)) {
145 gtk_tree_view_set_headers_clickable(GTK_TREE_VIEW(widget), TRUE);
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 }
153
154 /* Stop all the processings and call gtk_main_quit() */
155 static 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
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
171 void
172 insert_viewer_wrap(GtkWidget *menuitem, gpointer user_data)
173 {
174 insert_viewer((GtkWidget*)menuitem, (lttvwindow_viewer_constructor)user_data);
175 }
176
177
178 /* internal functions */
179 void insert_viewer(GtkWidget* widget, lttvwindow_viewer_constructor constructor)
180 {
181 GtkWidget * viewer_container;
182 GtkWidget * notebook = lookup_widget(widget, "MNotebook");
183 GtkWidget * viewer;
184 GtkWidget *page = gtk_notebook_get_nth_page(GTK_NOTEBOOK(notebook),
185 gtk_notebook_get_current_page(GTK_NOTEBOOK(notebook)));
186 LttvPluginTab *ptab;
187 Tab *tab;
188
189 if(!page) {
190 ptab = create_new_tab(widget, NULL);
191 } else {
192 ptab = (LttvPluginTab *)g_object_get_data(G_OBJECT(page), "Tab_Plugin");
193 }
194 tab = ptab->tab;
195
196 viewer_container = tab->viewer_container;
197
198 viewer = (GtkWidget*)constructor(&ptab->parent);
199 if(viewer)
200 {
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
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 */
213 connect_focus_recursive(viewer, viewer);
214 }
215 }
216
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
226 int SetTraceset(Tab * tab, LttvTraceset *traceset)
227 {
228
229 TimeInterval time_span;
230 TimeWindow new_time_window;
231 LttTime new_current_time;
232
233 #ifdef BABEL_CLEANUP
234 // Perform time synchronization on the traces
235 if (syncTraceset(tsc))
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 }
283 #endif /*BABEL_CLEANUP*/
284
285 time_span = lttv_traceset_get_time_span(traceset);
286
287 tab->traceset_info->traceset = traceset;
288
289 new_time_window = tab->time_window;
290 new_current_time = tab->current_time;
291
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
295 || ltt_time_compare(tab->time_window.end_time,
296 time_span.end_time) > 0) {
297 new_time_window.start_time = time_span.start_time;
298
299 new_current_time = time_span.start_time;
300
301 LttTime tmp_time;
302
303 if(ltt_time_compare(lttvwindow_default_time_width,
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)
307 tmp_time = lttvwindow_default_time_width;
308 else
309 tmp_time = time_span.end_time;
310
311 new_time_window.time_width = tmp_time ;
312 new_time_window.time_width_double = ltt_time_to_double(tmp_time);
313 new_time_window.end_time = ltt_time_add(new_time_window.start_time,
314 new_time_window.time_width) ;
315 }
316
317 /* Finally, call the update hooks of the viewers */
318 gint retval = update_traceset(tab, traceset);
319
320 time_change_manager(tab, new_time_window);
321 current_time_change_manager(tab, new_current_time);
322
323 return retval;
324
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 */
336 #if 0
337 int 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 }
352 #endif //0
353
354
355 /**
356 * Function to redraw each viewer belonging to the current tab
357 * @param tab viewer's tab
358 */
359
360 int update_traceset(Tab *tab, LttvTraceset *traceset)
361 {
362 LttvAttributeValue value;
363 LttvHooks * tmp;
364 gboolean retval;
365
366 retval= lttv_iattribute_find_by_path(tab->attributes,
367 "hooks/updatetraceset",
368 LTTV_POINTER,
369 &value);
370 g_assert(retval);
371 tmp = (LttvHooks*)*(value.v_pointer);
372 if(tmp == NULL) {
373 retval = 1;
374 } else {
375 lttv_hooks_call(tmp, traceset);
376 }
377 return retval;
378 }
379
380 /**
381 Call hooks register to get update on traceset time span changes
382 */
383 int 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 }
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
407 void 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
414 gboolean get_label(MainWindow * mw, gchar * str, gchar* dialogue_title, gchar * label_str)
415 {
416 GtkWidget * dialogue;
417 GtkWidget * text;
418 GtkWidget * label;
419 gint id;
420
421 dialogue = gtk_dialog_new_with_buttons(dialogue_title,NULL,
422 GTK_DIALOG_MODAL,
423 GTK_STOCK_OK,GTK_RESPONSE_ACCEPT,
424 GTK_STOCK_CANCEL,GTK_RESPONSE_REJECT,
425 NULL);
426
427 label = gtk_label_new(label_str);
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);
445 return FALSE;
446 }
447 return TRUE;
448 }
449
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
456 MainWindow * get_window_data_struct(GtkWidget * widget)
457 {
458 GtkWidget * mw;
459 MainWindow * mw_data;
460
461 mw = lookup_widget(widget, "MWindow");
462 if(mw == NULL){
463 g_info("Main window does not exist\n");
464 return NULL;
465 }
466
467 mw_data = (MainWindow *) g_object_get_data(G_OBJECT(mw),"main_window_data");
468 if(mw_data == NULL){
469 g_warning("Main window data does not exist\n");
470 return NULL;
471 }
472 return mw_data;
473 }
474
475
476 /* create_new_window function, just constructs a new main window
477 */
478
479 void create_new_window(GtkWidget* widget, gpointer user_data, gboolean clone)
480 {
481 MainWindow * parent = get_window_data_struct(widget);
482
483 if(clone){
484 g_info("Clone : use the same traceset\n");
485 construct_main_window(parent);
486 }else{
487 g_info("Empty : traceset is set to NULL\n");
488 construct_main_window(NULL);
489 }
490 }
491
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 */
497 GtkWidget *viewer_container_focus(GtkWidget *container)
498 {
499 GtkWidget *widget;
500
501 widget = (GtkWidget*)g_object_get_data(G_OBJECT(container),
502 "focused_viewer");
503
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);
510 g_object_set_data(G_OBJECT(container),
511 "focused_viewer",
512 widget);
513 }
514
515 return widget;
516
517
518 }
519
520 gint viewer_container_position(GtkWidget *container, GtkWidget *child)
521 {
522
523 if(child == NULL) return -1;
524
525 gint pos;
526 GValue value;
527 memset(&value, 0, sizeof(GValue));
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
538
539 /* move_*_viewer functions move the selected view up/down in
540 * the current tab
541 */
542
543 void move_down_viewer(GtkWidget * widget, gpointer user_data)
544 {
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;
551 if(!page) {
552 return;
553 } else {
554 LttvPluginTab *ptab;
555 ptab = g_object_get_data(G_OBJECT(page), "Tab_Plugin");
556 tab = ptab->tab;
557 }
558
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
574 }
575
576 void move_up_viewer(GtkWidget * widget, gpointer user_data)
577 {
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 {
587 LttvPluginTab *ptab;
588 ptab = (LttvPluginTab *)g_object_get_data(G_OBJECT(page), "Tab_Plugin");
589 tab = ptab->tab;
590 }
591
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
610 }
611
612
613 /* delete_viewer deletes the selected viewer in the current tab
614 */
615
616 void delete_viewer(GtkWidget * widget, gpointer user_data)
617 {
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 {
627 LttvPluginTab *ptab;
628 ptab = g_object_get_data(G_OBJECT(page), "Tab_Plugin");
629 tab = ptab->tab;
630 }
631
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);
640 }
641
642 #if UNFINISHED_FEATURE
643 /* TODO ybrosseau 2012-03-15: Function is half implemented. Should be removed */
644 /* open_traceset will open a traceset saved in a file
645 * Right now, it is not finished yet, (not working)
646 * FIXME
647 */
648
649 void open_traceset(GtkWidget * widget, gpointer user_data)
650 {
651 char ** dir;
652 gint id;
653 LttvTraceset * traceset;
654 MainWindow * mw_data = get_window_data_struct(widget);
655 GtkFileSelection * file_selector =
656 (GtkFileSelection *)gtk_file_selection_new("Select a traceset");
657
658 gtk_file_selection_hide_fileop_buttons(file_selector);
659
660 gtk_window_set_transient_for(GTK_WINDOW(file_selector),
661 GTK_WINDOW(mw_data->mwindow));
662
663 id = gtk_dialog_run(GTK_DIALOG(file_selector));
664 switch(id){
665 case GTK_RESPONSE_ACCEPT:
666 case GTK_RESPONSE_OK:
667 dir = gtk_file_selection_get_selections (file_selector);
668 traceset = lttv_traceset_load(dir[0]);
669 g_info("Open a trace set %s\n", dir[0]);
670 //Not finished yet
671 g_strfreev(dir);
672 case GTK_RESPONSE_REJECT:
673 case GTK_RESPONSE_CANCEL:
674 default:
675 gtk_widget_destroy((GtkWidget*)file_selector);
676 break;
677 }
678
679 }
680 #endif
681 /* lttvwindow_process_pending_requests
682 *
683 * Process requests for parts of the trace from viewers.
684 *
685 * These requests are made by lttvwindow_events_request().
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 *
706 */
707
708 #define list_out tab->events_requests
709
710 gboolean lttvwindow_process_pending_requests(Tab *tab)
711 {
712
713 LttvTraceset *ts;
714
715 GSList *list_in = NULL;
716 LttTime end_time;
717 guint end_nb_events;
718 guint count;
719 LttvTracesetPosition *end_position;
720
721 if(lttvwindow_preempt_count > 0) return TRUE;
722
723 if(tab == NULL) {
724 g_critical("Foreground processing : tab does not exist. Processing removed.");
725 return FALSE;
726 }
727
728 /* There is no events requests pending : we should never have been called! */
729 g_assert(g_slist_length(list_out) != 0);
730
731 ts = tab->traceset_info->traceset;
732
733 //set the cursor to be X shape, indicating that the computer is busy in doing its job
734 #if 0
735 new = gdk_cursor_new(GDK_X_CURSOR);
736 widget = lookup_widget(tab->mw->mwindow, "MToolbar1");
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);
742 #endif //0
743
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 */
748 if(lttv_traceset_number(ts) == 0) {
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)
761 lttv_hooks_call(events_request->after_request, (gpointer)ts);
762
763 /* - remove req from list_out */
764 /* Destroy the request */
765 remove = TRUE;
766 free_data = TRUE;
767 //TODO ybrosseau: This if is always true
768 /* Go to next */
769 if(remove)
770 {
771 GSList *remove_iter = iter;
772
773 iter = g_slist_next(iter);
774 if(free_data) events_request_free((EventsRequest*)remove_iter->data);
775 list_out = g_slist_remove_link(list_out, remove_iter);
776 } else { // not remove
777 iter = g_slist_next(iter);
778 }
779 }
780 }
781
782 /* 0.1 Lock Traces */
783 {
784 guint iter_trace=0;
785
786 for(iter_trace=0;
787 iter_trace<lttv_traceset_number(ts);
788 iter_trace++) {
789 LttvTrace *trace_v = lttv_traceset_get(ts, iter_trace);
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 */
799 #ifdef BABEL_CLEANUP
800 //g_assert(lttv_process_traceset_seek_position(tsc, sync_position) == 0);
801 lttv_process_traceset_synchronize_tracefiles(tsc);
802 #endif
803
804 /* Events processing algorithm implementation */
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 */
808 /* A. Servicing loop */
809 //while( (g_slist_length(list_in) != 0 || g_slist_length(list_out) != 0)) {
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 ) {
814
815 /* list in is empty, need a seek */
816 {
817 /* 1.1 Add requests to list_in */
818 GSList *ltime = NULL;
819 GSList *lpos = NULL;
820 GSList *iter = NULL;
821
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 */
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 }
843 }
844
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 {
859 //TODO ybrosseau: this compare is in fact an equal, so the behavior might not be right.
860 comp = lttv_traceset_position_time_compare
861 (event_request_lpos->start_position,
862 event_request_list_out->start_position);
863 } else {
864 comp = -1;
865 }
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);
873 }
874 }
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;
880
881 if(event_request_lpos != NULL
882 && event_request_lpos->start_position != NULL) {
883 lpos_start_time = lttv_traceset_position_get_time(
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 }
916 }
917 g_slist_free(lpos);
918 g_slist_free(ltime);
919 }
920
921 /* 1.2 Seek */
922 {
923
924 g_assert(g_slist_length(list_in)>0);
925 EventsRequest *events_request = g_slist_nth_data(list_in, 0);
926 #ifdef DEBUG
927 guint seek_count;
928 #endif
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 */
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)
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);
940 lttv_process_traceset_seek_time(ts,
941 events_request->start_time);
942
943 /* Process the traceset with only state hooks */
944 #ifdef DEBUG
945 seek_count =
946 #endif //DEBUG
947 lttv_process_traceset_middle(ts,
948 events_request->start_time,
949 G_MAXUINT, NULL);
950 #ifdef DEBUG
951 g_assert(seek_count < LTTV_STATE_SAVE_INTERVAL);
952 #endif //DEBUG
953
954
955 } else {
956 //LttTime pos_time;
957 //LttvTracefileContext *tfc =
958 // lttv_traceset_context_get_current_tfc(tsc);
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",
963 lttv_traceset_position_get_time(
964 events_request->start_position).tv_sec,
965 lttv_traceset_position_get_time(
966 events_request->start_position).tv_nsec);
967
968 /*if(tfc) {*/ if(0) {
969 /* g_debug("SEEK POS context time : %lu, %lu",
970 tfc->timestamp.tv_sec,
971 tfc->timestamp.tv_nsec); */
972 } else {
973 g_debug("SEEK POS context time : %lu, %lu",
974 ltt_time_infinite.tv_sec,
975 ltt_time_infinite.tv_nsec);
976 }
977 g_assert(events_request->start_position != NULL);
978 //TODO ybrosseau: for now, always seek
979 if(/*lttv_traceset_context_ctx_pos_compare(tsc,
980 events_request->start_position) != 0*/1) {
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);
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);
990
991 /* Process the traceset with only state hooks */
992 #ifdef DEBUG
993 seek_count =
994
995 lttv_process_traceset_middle(ts,
996 ltt_time_infinite,
997 G_MAXUINT,
998 events_request->start_position);
999 #endif
1000 //g_assert(lttv_traceset_context_ctx_pos_compare(tsc,
1001 // events_request->start_position) == 0);
1002
1003
1004 }
1005 }
1006 }
1007
1008 /* 1.3 Add hooks and call before request for all list_in members */
1009 {
1010 GSList *iter = NULL;
1011
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 */
1015 if(events_request->servicing == FALSE) {
1016 /* - begin request hooks called
1017 * - servicing = TRUE
1018 */
1019 lttv_hooks_call(events_request->before_request, (gpointer)ts);
1020 events_request->servicing = TRUE;
1021 }
1022 /* 1.3.2 call before chunk
1023 * 1.3.3 events hooks added
1024 */
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,
1029 events_request->before_chunk_traceset,
1030 events_request->before_chunk_trace,
1031 events_request->event
1032 );
1033 else {
1034 guint nb_trace = lttv_traceset_number(ts);
1035 g_assert((guint)events_request->trace < nb_trace &&
1036 events_request->trace > -1);
1037 LttvTrace *trace = lttv_traceset_get(ts, events_request->trace);
1038
1039 lttv_hooks_call(events_request->before_chunk_traceset, ts);
1040
1041 lttv_trace_add_hooks(trace,
1042 events_request->before_chunk_trace,
1043
1044 events_request->event
1045 );
1046 }
1047 }
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) {
1057
1058 EventsRequest *events_request = (EventsRequest *)iter->data;
1059
1060 /* - Call before chunk
1061 * - events hooks added
1062 */
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,
1067 events_request->before_chunk_traceset,
1068 events_request->before_chunk_trace,
1069 events_request->event
1070 );
1071 else {
1072 guint nb_trace = lttv_traceset_number(ts);
1073 g_assert((guint)events_request->trace < nb_trace &&
1074 events_request->trace > -1);
1075 LttvTrace *trace = lttv_traceset_get(ts, events_request->trace);
1076
1077 lttv_hooks_call(events_request->before_chunk_traceset, ts);
1078
1079 lttv_trace_add_hooks(trace,
1080 events_request->before_chunk_trace,
1081
1082 events_request->event
1083 );
1084 }
1085
1086 iter = g_slist_next(iter);
1087 }
1088 }
1089
1090 {
1091
1092
1093 /* 2.1 For each req of list_out */
1094 GSList *iter = list_out;
1095
1096 while(iter != NULL) {
1097
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*/
1104 /* if( ltt_time_compare(events_request->start_time,
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 ) {
1112 */
1113 if(lttv_traceset_position_compare_current(ts, events_request->start_position) == 0) {
1114
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 */
1125 lttv_hooks_call(events_request->before_request, (gpointer)ts);
1126 events_request->servicing = TRUE;
1127 }
1128 /* call before chunk
1129 * events hooks added
1130 */
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,
1135 events_request->before_chunk_traceset,
1136 events_request->before_chunk_trace,
1137 events_request->event
1138 );
1139 else {
1140 guint nb_trace = lttv_traceset_number(ts);
1141 g_assert((guint)events_request->trace < nb_trace &&
1142 events_request->trace > -1);
1143 LttvTrace* trace = lttv_traceset_get(ts,events_request->trace);
1144
1145 lttv_hooks_call(events_request->before_chunk_traceset, ts);
1146
1147 lttv_trace_add_hooks(trace,
1148 events_request->before_chunk_trace,
1149
1150 events_request->event);
1151
1152 }
1153
1154
1155 }
1156
1157 /* Go to next */
1158 if(remove)
1159 {
1160 GSList *remove_iter = iter;
1161
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 }
1171
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;
1183
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;
1192
1193 if(ltt_time_compare(events_request->start_time,
1194 end_time) < 0)
1195 end_time = events_request->start_time;
1196 }
1197 }
1198
1199 {
1200 /* 3.2 Number of events */
1201
1202 /* 3.2.1 Find lowest number of events in list_in */
1203 GSList *iter;
1204
1205 end_nb_events = ((EventsRequest*)g_slist_nth_data(list_in,0))->num_events;
1206
1207 for(iter=g_slist_nth(list_in,1);iter!=NULL;iter=g_slist_next(iter)) {
1208 EventsRequest *events_request = (EventsRequest*)iter->data;
1209
1210 if(events_request->num_events < end_nb_events)
1211 end_nb_events = events_request->num_events;
1212 }
1213
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);
1218 }
1219
1220 {
1221 /* 3.3 End position */
1222
1223 /* 3.3.1 Find lowest end position in list_in */
1224 GSList *iter;
1225
1226 end_position =((EventsRequest*)g_slist_nth_data(list_in,0))->end_position;
1227
1228 for(iter=g_slist_nth(list_in,1);iter!=NULL;iter=g_slist_next(iter)) {
1229 EventsRequest *events_request = (EventsRequest*)iter->data;
1230
1231 if(events_request->end_position != NULL && end_position != NULL &&
1232 lttv_traceset_position_time_compare(events_request->end_position,
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;
1241
1242 for(iter=list_out;iter!=NULL;iter=g_slist_next(iter)) {
1243 EventsRequest *events_request = (EventsRequest*)iter->data;
1244
1245 if(events_request->end_position != NULL && end_position != NULL &&
1246 lttv_traceset_position_time_compare(events_request->end_position,
1247 end_position) <0)
1248 end_position = events_request->end_position;
1249 }
1250 }
1251
1252 {
1253 /* 4. Call process traceset middle */
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);
1256
1257 #ifdef BABEL_CLEANUP
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.");
1264 #endif
1265 }
1266
1267 {
1268 /* 5. After process traceset middle */
1269
1270 LttTime curTime = lttv_traceset_get_current_time(ts);
1271 /* - if current context time > traceset.end time */
1272 if(ltt_time_compare(curTime,
1273 lttv_traceset_get_time_span_real(ts).end_time) > 0) {
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 */
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,
1290 events_request->after_chunk_traceset,
1291 events_request->after_chunk_trace,
1292
1293 events_request->event);
1294
1295 else {
1296 guint nb_trace = lttv_traceset_number(ts);
1297 g_assert(events_request->trace < nb_trace &&
1298 events_request->trace > -1);
1299 LttvTrace *trace = lttv_traceset_get(ts,events_request->trace);
1300
1301 lttv_trace_remove_hooks(trace,
1302 events_request->after_chunk_trace,
1303
1304 events_request->event);
1305
1306 lttv_hooks_call(events_request->after_chunk_traceset, ts);
1307
1308
1309 }
1310
1311 /* - Call end request for req */
1312 lttv_hooks_call(events_request->after_request, (gpointer)ts);
1313
1314 /* - remove req from list_in */
1315 /* Destroy the request */
1316 remove = TRUE;
1317 free_data = TRUE;
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 }
1330 }
1331 }
1332 {
1333 /* 5.1 For each req in list_in */
1334 GSList *iter = list_in;
1335
1336 while(iter != NULL) {
1337
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 */
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,
1349 events_request->after_chunk_traceset,
1350 events_request->after_chunk_trace,
1351
1352 events_request->event);
1353
1354
1355 else {
1356 guint nb_trace = lttv_traceset_number(ts);
1357 g_assert(events_request->trace < nb_trace &&
1358 events_request->trace > -1);
1359 LttvTrace *trace = lttv_traceset_get(ts, events_request->trace);
1360
1361 lttv_trace_remove_hooks(trace,
1362 events_request->after_chunk_trace,
1363
1364 events_request->event);
1365
1366
1367 lttv_hooks_call(events_request->after_chunk_traceset, ts);
1368 }
1369
1370 /* - req.num -= count */
1371 g_assert(events_request->num_events >= count);
1372 events_request->num_events -= count;
1373
1374 //g_assert(tfc != NULL);
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 ||
1387 ltt_time_compare(lttv_traceset_get_current_time(ts),
1388 events_request->end_time) >= 0
1389 ||
1390 (events_request->end_position != NULL
1391 &&
1392 lttv_traceset_position_compare_current(ts,
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 */
1399 lttv_hooks_call(events_request->after_request, (gpointer)ts);
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 }
1417 }
1418 }
1419 }
1420 }
1421 /* End of removed servicing loop : leave control to GTK instead. */
1422 // if(gtk_events_pending()) break;
1423 //}
1424
1425 /* B. When interrupted between chunks */
1426
1427 {
1428 GSList *iter = list_in;
1429
1430 /* 1. for each request in list_in */
1431 while(iter != NULL) {
1432
1433 gboolean remove = FALSE;
1434 gboolean free_data = FALSE;
1435 EventsRequest *events_request = (EventsRequest *)iter->data;
1436
1437 /* 1.1. Use current postition as start position */
1438 if(events_request->start_position != NULL)
1439 lttv_traceset_destroy_position(events_request->start_position);
1440 events_request->start_position = lttv_traceset_create_current_position(ts);
1441
1442
1443 /* 1.2. Remove start time */
1444 events_request->start_time = ltt_time_infinite;
1445
1446 /* 1.3. Move from list_in to list_out */
1447 remove = TRUE;
1448 free_data = FALSE;
1449 list_out = g_slist_append(list_out, events_request);
1450
1451 /* Go to next */
1452 if(remove)
1453 {
1454 GSList *remove_iter = iter;
1455
1456 iter = g_slist_next(iter);
1457 if(free_data) events_request_free((EventsRequest*)remove_iter->data);
1458 list_in = g_slist_remove_link(list_in, remove_iter);
1459 } else { // not remove
1460 iter = g_slist_next(iter);
1461 }
1462 }
1463
1464
1465 }
1466 /* C Unlock Traces */
1467 {
1468 #ifdef BABEL_CLEANUP
1469 lttv_process_traceset_get_sync_data(tsc);
1470 #endif
1471 //lttv_traceset_context_position_save(tsc, sync_position);
1472
1473 guint iter_trace;
1474
1475 for(iter_trace=0;
1476 iter_trace<lttv_traceset_number(ts);
1477 iter_trace++) {
1478 LttvTrace *trace_v = lttv_traceset_get(ts, iter_trace);
1479
1480 lttvwindowtraces_unlock(trace_v);
1481 }
1482 }
1483 #if 0
1484 //set the cursor back to normal
1485 gdk_window_set_cursor(win, NULL);
1486 #endif //0
1487
1488 g_assert(g_slist_length(list_in) == 0);
1489
1490 if( g_slist_length(list_out) == 0 ) {
1491 /* Put tab's request pending flag back to normal */
1492 tab->events_request_pending = FALSE;
1493 g_debug("remove the idle fct");
1494 return FALSE; /* Remove the idle function */
1495 }
1496 g_debug("leave the idle fct");
1497 return TRUE; /* Leave the idle function */
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 */
1509
1510
1511 }
1512
1513 #undef list_out
1514 /**
1515 Manage the periodic update of a live trace
1516 */
1517 static gboolean
1518 live_trace_update_handler(Tab *tab)
1519 {
1520 #ifdef BABEL_CLEANUP
1521 unsigned int updated_count;
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 */
1529
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);
1556 #endif /* BABEL_CLEANUP */
1557 }
1558
1559 static void lttvwindow_add_trace(Tab *tab, LttvTrace *trace_v)
1560 {
1561 #ifdef BABEL_CLEANUP
1562 LttvTraceset *traceset = tab->traceset_info->traceset;
1563 guint i;
1564 guint num_traces = lttv_traceset_number(traceset);
1565
1566 //Verify if trace is already present.
1567 for(i=0; i<num_traces; i++)
1568 {
1569 LttvTrace * trace = lttv_traceset_get(traceset, i);
1570 if(trace == trace_v)
1571 return;
1572 }
1573
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);
1590 lttv_trace_ref(trace_v); /* local ref */
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);
1599
1600
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
1611 //FIXME
1612 //add_trace_into_traceset_selector(GTK_MULTIVPANED(tab->multivpaned), lttv_trace(trace_v));
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 }
1622 #endif /* BABEL_CLEANUP */
1623 }
1624
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
1630 void add_trace(GtkWidget * widget, gpointer user_data)
1631 {
1632
1633 LttvTraceset * traceset = NULL;
1634 const char * path;
1635 char abs_path[PATH_MAX];
1636 gint id;
1637 MainWindow * mw_data = get_window_data_struct(widget);
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)));
1642 LttvPluginTab *ptab;
1643 Tab *tab;
1644
1645 if(!page) {
1646 ptab = create_new_tab(widget, NULL);
1647 tab = ptab->tab;
1648 } else {
1649 ptab = (LttvPluginTab *)g_object_get_data(G_OBJECT(page), "Tab_Plugin");
1650 tab = ptab->tab;
1651 }
1652 //TODO fdeslauriers 2012-07-06: Remove this popup when we support multiple traces
1653 traceset = lttvwindow_get_traceset(tab);
1654 if(traceset != NULL && lttv_traceset_number(traceset) > 0){
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
1667 /* Create a new traceset*/
1668 traceset = lttv_traceset_new();
1669 /* File open dialog management */
1670 #ifdef BABEL_CLEANUP
1671 GtkWidget *extra_live_button;
1672 #endif //babel_cleanup
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,
1680 NULL));
1681 #ifdef BABEL_CLEANUP
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);
1686 #endif //babel_cleanup
1687 gtk_file_chooser_set_show_hidden (file_chooser, TRUE);
1688 if(remember_trace_dir[0] != '\0')
1689 gtk_file_chooser_set_filename(file_chooser, remember_trace_dir);
1690
1691 gboolean closeFileChooserDialog = TRUE;
1692
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;
1705 }
1706 get_absolute_pathname(path, abs_path);
1707
1708 if(lttv_traceset_add_path(traceset,abs_path) != 0 ){ /*failure*/
1709
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);
1731
1732 // in expose now call_pending_read_hooks(mw_data);
1733
1734 //lttvwindow_report_current_time(mw_data,&(tab->current_time));
1735
1736 case GTK_RESPONSE_REJECT:
1737 case GTK_RESPONSE_CANCEL:
1738 default:
1739 closeFileChooserDialog = TRUE;
1740 break;
1741 }
1742 }while(!closeFileChooserDialog);
1743
1744 gtk_widget_destroy((GtkWidget*)file_chooser);
1745
1746 }
1747
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
1755 *
1756 * It destroys the filter tree. FIXME... we should request for an update
1757 * instead.
1758 */
1759
1760 void remove_trace(GtkWidget *widget, gpointer user_data)
1761 {
1762 #ifdef BABEL_CLEANUP
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 {
1778 LttvPluginTab *ptab;
1779 ptab = (LttvPluginTab *)g_object_get_data(G_OBJECT(page), "Tab_Plugin");
1780 tab = ptab->tab;
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);
1788 name[i] = (char *) g_quark_to_string(ltt_trace_name(trace));
1789 }
1790
1791 remove_trace_name = get_remove_trace(mw_data, name, nb_trace);
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
1819 lttv_traceset_remove(traceset, index);
1820 lttv_trace_unref(trace_v); // Remove local reference
1821
1822 if(lttv_trace_get_ref_number(trace_v) <= 1) {
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 */
1829 lttvwindowtraces_remove_trace(trace_v);
1830 }
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);
1851 #endif /* BABEL_CLEANUP */
1852 }
1853
1854 #if 0
1855 void remove_trace(GtkWidget * widget, gpointer user_data)
1856 {
1857 LttTrace *trace;
1858 LttvTrace * trace_v;
1859 LttvTraceset * traceset;
1860 gint i, j, nb_trace;
1861 char ** name, *remove_trace_name;
1862 MainWindow * mw_data = get_window_data_struct(widget);
1863 LttvTracesetSelector * s;
1864 LttvTraceSelector * t;
1865 GtkWidget * w;
1866 gboolean selected;
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
1879 nb_trace =lttv_traceset_number(tab->traceset_info->traceset);
1880 name = g_new(char*,nb_trace);
1881 for(i = 0; i < nb_trace; i++){
1882 trace_v = lttv_traceset_get(tab->traceset_info->traceset, i);
1883 trace = lttv_trace(trace_v);
1884 name[i] = ltt_trace_name(trace);
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){
1892 //unselect the trace from the current viewer
1893 //FIXME
1894 w = gtk_multivpaned_get_widget(GTK_MULTIVPANED(tab->multivpaned));
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
1903 w = gtk_multivpaned_get_first_widget(GTK_MULTIVPANED(tab->multivpaned));
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 }
1911 w = gtk_multivpaned_get_next_widget(GTK_MULTIVPANED(tab->multivpaned));
1912 }
1913 }else selected = FALSE;
1914
1915 //if no viewer selects the trace, remove it
1916 if(!selected){
1917 remove_trace_from_traceset_selector(GTK_MULTIVPANED(tab->multivpaned), i);
1918
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 }
1926
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);
1932
1933
1934 trace_v = lttv_traceset_get(traceset, i);
1935
1936 if(lttv_trace_get_ref_number(trace_v) <= 2) {
1937 /* ref 2 : traceset, local */
1938 lttvwindowtraces_remove_trace(trace_v);
1939 ltt_trace_close(lttv_trace(trace_v));
1940 }
1941
1942 lttv_traceset_remove(traceset, i);
1943 lttv_trace_unref(trace_v); // Remove local reference
1944
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 }
1963
1964
1965 //update current tab
1966 //update_traceset(mw_data);
1967 //if(nb_trace > 1){
1968
1969 SetTraceset(tab, (gpointer)traceset);
1970 // in expose now call_pending_read_hooks(mw_data);
1971
1972 //lttvwindow_report_current_time(mw_data,&(tab->current_time));
1973 //}else{
1974 // if(tab){
1975 // while(tab->multi_vpaned->num_children){
1976 // gtk_multi_vpaned_widget_delete(tab->multi_vpaned);
1977 // }
1978 // }
1979 //}
1980 }
1981 break;
1982 }
1983 }
1984 }
1985
1986 g_free(name);
1987 }
1988 #endif //0
1989
1990 /* Redraw all the viewers in the current tab */
1991 void 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;
1997 gboolean retval;
1998
1999 if(!page) {
2000 return;
2001 } else {
2002 LttvPluginTab *ptab;
2003 ptab = (LttvPluginTab *)g_object_get_data(G_OBJECT(page), "Tab_Plugin");
2004 tab = ptab->tab;
2005 }
2006
2007 LttvHooks * tmp;
2008 LttvAttributeValue value;
2009
2010 retval= lttv_iattribute_find_by_path(tab->attributes, "hooks/redraw", LTTV_POINTER, &value);
2011 g_assert(retval);
2012
2013 tmp = (LttvHooks*)*(value.v_pointer);
2014 if(tmp != NULL)
2015 lttv_hooks_call(tmp,NULL);
2016 }
2017
2018
2019 void 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;
2025 gboolean retval;
2026
2027 if(!page) {
2028 return;
2029 } else {
2030 LttvPluginTab *ptab;
2031 ptab = (LttvPluginTab *)g_object_get_data(G_OBJECT(page), "Tab_Plugin");
2032 tab = ptab->tab;
2033 }
2034
2035 LttvHooks * tmp;
2036 LttvAttributeValue value;
2037
2038 retval= lttv_iattribute_find_by_path(tab->attributes, "hooks/continue",
2039 LTTV_POINTER, &value);
2040 g_assert(retval);
2041
2042 tmp = (LttvHooks*)*(value.v_pointer);
2043 if(tmp != NULL)
2044 lttv_hooks_call(tmp,NULL);
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
2052 void 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 {
2061 LttvPluginTab *ptab;
2062 ptab = (LttvPluginTab *)g_object_get_data(G_OBJECT(page), "Tab_Plugin");
2063 tab = ptab->tab;
2064 }
2065 GSList *iter = tab->events_requests;
2066
2067 while(iter != NULL) {
2068 GSList *remove_iter = iter;
2069 iter = g_slist_next(iter);
2070
2071 g_free(remove_iter->data);
2072 tab->events_requests =
2073 g_slist_remove_link(tab->events_requests, remove_iter);
2074 }
2075 tab->events_request_pending = FALSE;
2076 tab->stop_foreground = TRUE;
2077 g_idle_remove_by_data(tab);
2078 g_assert(g_slist_length(tab->events_requests) == 0);
2079 }
2080
2081
2082 /* save will save the traceset to a file
2083 * Not implemented yet FIXME
2084 */
2085
2086 void save(GtkWidget * widget, gpointer user_data)
2087 {
2088 g_info("Save\n");
2089 }
2090
2091 void save_as(GtkWidget * widget, gpointer user_data)
2092 {
2093 g_info("Save as\n");
2094 }
2095
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
2102 void zoom(GtkWidget * widget, double size)
2103 {
2104 #ifdef BABEL_CLEANUP
2105 TimeInterval time_span;
2106 TimeWindow new_time_window;
2107 LttTime current_time, time_delta;
2108 LttvTracesetContext *tsc;
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 {
2118 LttvPluginTab *ptab;
2119 ptab = (LttvPluginTab *)g_object_get_data(G_OBJECT(page), "Tab_Plugin");
2120 tab = ptab->tab;
2121 }
2122
2123 if(size == 1) return;
2124
2125 tsc = LTTV_TRACESET_CONTEXT(tab->traceset_info->traceset_context);
2126 time_span = tsc->time_span;
2127 new_time_window = tab->time_window;
2128 current_time = tab->current_time;
2129
2130 time_delta = ltt_time_sub(time_span.end_time,time_span.start_time);
2131 if(size == 0){
2132 new_time_window.start_time = time_span.start_time;
2133 new_time_window.time_width = time_delta;
2134 new_time_window.time_width_double = ltt_time_to_double(time_delta);
2135 new_time_window.end_time = ltt_time_add(new_time_window.start_time,
2136 new_time_window.time_width) ;
2137 }else{
2138 new_time_window.time_width = ltt_time_div(new_time_window.time_width, size);
2139 new_time_window.time_width_double =
2140 ltt_time_to_double(new_time_window.time_width);
2141 if(ltt_time_compare(new_time_window.time_width,time_delta) > 0)
2142 { /* Case where zoom out is bigger than trace length */
2143 new_time_window.start_time = time_span.start_time;
2144 new_time_window.time_width = time_delta;
2145 new_time_window.time_width_double = ltt_time_to_double(time_delta);
2146 new_time_window.end_time = ltt_time_add(new_time_window.start_time,
2147 new_time_window.time_width) ;
2148 }
2149 else
2150 {
2151 /* Center the image on the current time */
2152 new_time_window.start_time =
2153 ltt_time_sub(current_time,
2154 ltt_time_from_double(new_time_window.time_width_double/2.0));
2155 new_time_window.end_time = ltt_time_add(new_time_window.start_time,
2156 new_time_window.time_width) ;
2157 /* If on borders, don't fall off */
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)
2160 {
2161 new_time_window.start_time = time_span.start_time;
2162 new_time_window.end_time = ltt_time_add(new_time_window.start_time,
2163 new_time_window.time_width) ;
2164 }
2165 else
2166 {
2167 if(ltt_time_compare(new_time_window.end_time,
2168 time_span.end_time) > 0
2169 || ltt_time_compare(new_time_window.end_time,
2170 time_span.start_time) < 0)
2171 {
2172 new_time_window.start_time =
2173 ltt_time_sub(time_span.end_time, new_time_window.time_width);
2174
2175 new_time_window.end_time = ltt_time_add(new_time_window.start_time,
2176 new_time_window.time_width) ;
2177 }
2178 }
2179
2180 }
2181 }
2182
2183 if(ltt_time_compare(new_time_window.time_width, ltt_time_zero) == 0) {
2184 g_warning("Zoom more than 1 ns impossible");
2185 } else {
2186 time_change_manager(tab, new_time_window);
2187 }
2188
2189 #endif /* BABEL_CLEANUP */
2190 }
2191
2192 void zoom_in(GtkWidget * widget, gpointer user_data)
2193 {
2194 zoom(widget, 2);
2195 }
2196
2197 void zoom_out(GtkWidget * widget, gpointer user_data)
2198 {
2199 zoom(widget, 0.5);
2200 }
2201
2202 void zoom_extended(GtkWidget * widget, gpointer user_data)
2203 {
2204 zoom(widget, 0);
2205 }
2206
2207 void go_to_time(GtkWidget * widget, gpointer user_data)
2208 {
2209 g_info("Go to time\n");
2210 }
2211
2212 void show_time_frame(GtkWidget * widget, gpointer user_data)
2213 {
2214 g_info("Show time frame\n");
2215 }
2216
2217
2218 /* callback function */
2219
2220 void
2221 on_empty_traceset_activate (GtkMenuItem *menuitem,
2222 gpointer user_data)
2223 {
2224 create_new_window((GtkWidget*)menuitem, user_data, FALSE);
2225 }
2226
2227
2228 void
2229 on_clone_traceset_activate (GtkMenuItem *menuitem,
2230 gpointer user_data)
2231 {
2232 create_new_window((GtkWidget*)menuitem, user_data, TRUE);
2233 }
2234
2235
2236 /* create_new_tab calls create_tab to construct a new tab in the main window
2237 */
2238
2239 LttvPluginTab *create_new_tab(GtkWidget* widget, gpointer user_data)
2240 {
2241 gchar label[PATH_MAX];
2242 MainWindow * mw_data = get_window_data_struct(widget);
2243
2244 GtkNotebook * notebook = (GtkNotebook *)lookup_widget(widget, "MNotebook");
2245 if(notebook == NULL){
2246 g_info("Notebook does not exist\n");
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 {
2256 LttvPluginTab *ptab;
2257 ptab = (LttvPluginTab *)g_object_get_data(G_OBJECT(page), "Tab_Plugin");
2258 copy_tab = ptab->tab;
2259 }
2260
2261 strcpy(label,"Page");
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;
2276 }
2277
2278 void
2279 on_tab_activate (GtkMenuItem *menuitem,
2280 gpointer user_data)
2281 {
2282 create_new_tab((GtkWidget*)menuitem, user_data);
2283 }
2284
2285
2286 void
2287 on_open_activate (GtkMenuItem *menuitem,
2288 gpointer user_data)
2289 {
2290 #ifdef UNFINISHED_FEATURE
2291 open_traceset((GtkWidget*)menuitem, user_data);
2292 #endif
2293 }
2294
2295
2296 void
2297 on_close_activate (GtkMenuItem *menuitem,
2298 gpointer user_data)
2299 {
2300 MainWindow * mw_data = get_window_data_struct((GtkWidget*)menuitem);
2301 main_window_destructor(mw_data);
2302 }
2303
2304
2305 /* remove the current tab from the main window
2306 */
2307
2308 void
2309 on_close_tab_activate (GtkWidget *widget,
2310 gpointer user_data)
2311 {
2312 gint page_num;
2313 GtkWidget * notebook;
2314 notebook = lookup_widget(widget, "MNotebook");
2315 if(notebook == NULL){
2316 g_info("Notebook does not exist\n");
2317 return;
2318 }
2319
2320 page_num = gtk_notebook_get_current_page(GTK_NOTEBOOK(notebook));
2321
2322 gtk_notebook_remove_page(GTK_NOTEBOOK(notebook), page_num);
2323
2324 }
2325
2326 void
2327 on_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){
2333 g_info("Notebook does not exist\n");
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
2342
2343 void
2344 on_add_trace_activate (GtkMenuItem *menuitem,
2345 gpointer user_data)
2346 {
2347 add_trace((GtkWidget*)menuitem, user_data);
2348 }
2349
2350
2351 void
2352 on_remove_trace_activate (GtkMenuItem *menuitem,
2353 gpointer user_data)
2354 {
2355 remove_trace((GtkWidget*)menuitem, user_data);
2356 }
2357
2358
2359 void
2360 on_save_activate (GtkMenuItem *menuitem,
2361 gpointer user_data)
2362 {
2363 save((GtkWidget*)menuitem, user_data);
2364 }
2365
2366
2367 void
2368 on_save_as_activate (GtkMenuItem *menuitem,
2369 gpointer user_data)
2370 {
2371 save_as((GtkWidget*)menuitem, user_data);
2372 }
2373
2374
2375 void
2376 on_quit_activate (GtkMenuItem *menuitem,
2377 gpointer user_data)
2378 {
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 }
2383 }
2384
2385
2386 void
2387 on_cut_activate (GtkMenuItem *menuitem,
2388 gpointer user_data)
2389 {
2390 g_info("Cut\n");
2391 }
2392
2393
2394 void
2395 on_copy_activate (GtkMenuItem *menuitem,
2396 gpointer user_data)
2397 {
2398 g_info("Copye\n");
2399 }
2400
2401
2402 void
2403 on_paste_activate (GtkMenuItem *menuitem,
2404 gpointer user_data)
2405 {
2406 g_info("Paste\n");
2407 }
2408
2409
2410 void
2411 on_delete_activate (GtkMenuItem *menuitem,
2412 gpointer user_data)
2413 {
2414 g_info("Delete\n");
2415 }
2416
2417
2418 void
2419 on_zoom_in_activate (GtkMenuItem *menuitem,
2420 gpointer user_data)
2421 {
2422 zoom_in((GtkWidget*)menuitem, user_data);
2423 }
2424
2425
2426 void
2427 on_zoom_out_activate (GtkMenuItem *menuitem,
2428 gpointer user_data)
2429 {
2430 zoom_out((GtkWidget*)menuitem, user_data);
2431 }
2432
2433
2434 void
2435 on_zoom_extended_activate (GtkMenuItem *menuitem,
2436 gpointer user_data)
2437 {
2438 zoom_extended((GtkWidget*)menuitem, user_data);
2439 }
2440
2441
2442 void
2443 on_go_to_time_activate (GtkMenuItem *menuitem,
2444 gpointer user_data)
2445 {
2446 go_to_time((GtkWidget*)menuitem, user_data);
2447 }
2448
2449
2450 void
2451 on_show_time_frame_activate (GtkMenuItem *menuitem,
2452 gpointer user_data)
2453 {
2454 show_time_frame((GtkWidget*)menuitem, user_data);
2455 }
2456
2457
2458 void
2459 on_move_viewer_up_activate (GtkMenuItem *menuitem,
2460 gpointer user_data)
2461 {
2462 move_up_viewer((GtkWidget*)menuitem, user_data);
2463 }
2464
2465
2466 void
2467 on_move_viewer_down_activate (GtkMenuItem *menuitem,
2468 gpointer user_data)
2469 {
2470 move_down_viewer((GtkWidget*)menuitem, user_data);
2471 }
2472
2473
2474 void
2475 on_remove_viewer_activate (GtkMenuItem *menuitem,
2476 gpointer user_data)
2477 {
2478 delete_viewer((GtkWidget*)menuitem, user_data);
2479 }
2480
2481 void
2482 on_trace_facility_activate (GtkMenuItem *menuitem,
2483 gpointer user_data)
2484 {
2485 g_info("Trace facility selector: %s\n", "");
2486 }
2487
2488
2489 /* Dispaly a file selection dialogue to let user select a library, then call
2490 * lttv_library_load().
2491 */
2492
2493 void
2494 on_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
2515 load_module_path = get_selection(mw_data,
2516 (char **)(name->pdata), name->len,
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
2549 gtk_window_set_transient_for(GTK_WINDOW(file_selector),
2550 GTK_WINDOW(mw_data->mwindow));
2551
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);
2582 if(error != NULL) g_warning("%s", error->message);
2583 else g_info("Load library: %s\n", str);
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
2603 void
2604 on_unload_library_activate (GtkMenuItem *menuitem,
2605 gpointer user_data)
2606 {
2607 MainWindow * mw_data = get_window_data_struct((GtkWidget*)menuitem);
2608
2609 LttvLibrary *library = NULL;
2610
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 }
2626 lib_name = get_selection(mw_data, (char **)(name->pdata), name->len,
2627 "Select a library", "Libraries");
2628 if(lib_name != NULL) {
2629 for(i=0;i<nb;i++){
2630 if(strcmp(lib_name, lib_info[i].name) == 0) {
2631 library = lttv_library_get(i);
2632 break;
2633 }
2634 }
2635 }
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);
2642 }
2643
2644
2645 /* Dispaly a file selection dialogue to let user select a module, then call
2646 * lttv_module_require().
2647 */
2648
2649 void
2650 on_load_module_activate (GtkMenuItem *menuitem,
2651 gpointer user_data)
2652 {
2653 GError *error = NULL;
2654 MainWindow * mw_data = get_window_data_struct((GtkWidget*)menuitem);
2655
2656 LttvLibrary *library = NULL;
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 }
2673 lib_name = get_selection(mw_data,(char **)(name->pdata), name->len,
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 }
2681 }
2682 }
2683 g_ptr_array_free(name, TRUE);
2684 g_free(lib_info);
2685
2686 if(lib_name == NULL) return;
2687 }
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;
2696 nb = lttv_library_module_number(library);
2697 LttvModuleInfo *module_info = g_new(LttvModuleInfo,nb);
2698 name = g_ptr_array_new();
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 }
2708 module_name = get_selection(mw_data, (char **)(name->pdata), name->len,
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);
2727 if(error != NULL) g_warning("%s", error->message);
2728 else g_info("Load module: %s", module_name_out);
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);
2775 else g_info("Load library: %s\n", str);
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
2788 }
2789
2790
2791
2792 /* Display all loaded modules, let user to select a module to unload
2793 * by calling lttv_module_unload
2794 */
2795
2796 void
2797 on_unload_module_activate (GtkMenuItem *menuitem,
2798 gpointer user_data)
2799 {
2800 MainWindow * mw_data = get_window_data_struct((GtkWidget*)menuitem);
2801
2802 LttvLibrary *library = NULL;
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 */
2811
2812 for(i=0;i<nb;i++){
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 }
2819 lib_name = get_selection(mw_data, (char **)(name->pdata), name->len,
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 }
2827 }
2828 }
2829 g_ptr_array_free(name, TRUE);
2830 g_free(lib_info);
2831
2832 if(lib_name == NULL) return;
2833 }
2834
2835 LttvModule *module = NULL;
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;
2841 nb = lttv_library_module_number(library);
2842 LttvModuleInfo *module_info = g_new(LttvModuleInfo,nb);
2843 name = g_ptr_array_new();
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 }
2853 module_name = get_selection(mw_data, (char **)(name->pdata), name->len,
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
2870 LttvModuleInfo module_info;
2871 lttv_module_info(module, &module_info);
2872 g_info("Release module: %s\n", module_info.name);
2873
2874 lttv_module_release(module);
2875 }
2876
2877
2878 /* Display a directory dialogue to let user select a path for library searching
2879 */
2880
2881 void
2882 on_add_library_search_path_activate (GtkMenuItem *menuitem,
2883 gpointer user_data)
2884 {
2885 MainWindow * mw_data = get_window_data_struct((GtkWidget*)menuitem);
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) ;
2889
2890 gtk_window_set_transient_for(GTK_WINDOW(file_selector),
2891 GTK_WINDOW(mw_data->mwindow));
2892
2893 const char * dir;
2894 gint id;
2895
2896 if(remember_plugins_dir[0] != '\0')
2897 gtk_file_selection_set_filename(file_selector, remember_plugins_dir);
2898
2899 id = gtk_dialog_run(GTK_DIALOG(file_selector));
2900 switch(id){
2901 case GTK_RESPONSE_ACCEPT:
2902 case GTK_RESPONSE_OK:
2903 dir = gtk_file_selection_get_filename (file_selector);
2904 strncpy(remember_plugins_dir,dir,PATH_MAX);
2905 strncat(remember_plugins_dir,"/",PATH_MAX);
2906 lttv_library_path_add(dir);
2907 case GTK_RESPONSE_REJECT:
2908 case GTK_RESPONSE_CANCEL:
2909 default:
2910 gtk_widget_destroy((GtkWidget*)file_selector);
2911 break;
2912 }
2913 }
2914
2915
2916 /* Display a directory dialogue to let user select a path for library searching
2917 */
2918
2919 void
2920 on_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;
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 }
2937 lib_path = get_selection(mw_data, (char **)(name->pdata), name->len,
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
2948 void
2949 on_color_activate (GtkMenuItem *menuitem,
2950 gpointer user_data)
2951 {
2952 g_info("Color\n");
2953 }
2954
2955
2956 void
2957 on_save_configuration_activate (GtkMenuItem *menuitem,
2958 gpointer user_data)
2959 {
2960 g_info("Save configuration\n");
2961 }
2962
2963
2964 void
2965 on_content_activate (GtkMenuItem *menuitem,
2966 gpointer user_data)
2967 {
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);
2980 g_info("Content\n");
2981 }
2982
2983
2984 static void
2985 on_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
2993 void
2994 on_about_activate (GtkMenuItem *menuitem,
2995 gpointer user_data)
2996 {
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);
3001
3002 gtk_window_set_title(about_window, "About Linux Trace Toolkit");
3003
3004 gtk_window_set_resizable(about_window, FALSE);
3005 gtk_window_set_transient_for(about_window, GTK_WINDOW(window_widget));
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 */
3010 gtk_window_set_position(about_window, GTK_WIN_POS_CENTER_ALWAYS);
3011
3012 GtkWidget *vbox = gtk_vbox_new(FALSE, 1);
3013
3014 gtk_container_add(GTK_CONTAINER(about_widget), vbox);
3015
3016 /* Text to show */
3017 GtkWidget *label1 = gtk_label_new("");
3018 gtk_misc_set_padding(GTK_MISC(label1), 10, 20);
3019 gtk_label_set_markup(GTK_LABEL(label1), "\
3020 <big>Linux Trace Toolkit " VERSION "</big>");
3021 gtk_label_set_justify(GTK_LABEL(label1), GTK_JUSTIFY_CENTER);
3022
3023 GtkWidget *label2 = gtk_label_new("");
3024 gtk_misc_set_padding(GTK_MISC(label2), 10, 20);
3025 gtk_label_set_markup(GTK_LABEL(label2), "\
3026 Contributors :\n\
3027 \n\
3028 Michel Dagenais (New trace format, lttv main)\n\
3029 Mathieu Desnoyers (Kernel Tracer, Directory structure, build with automake/conf,\n\
3030 lttv gui, control flow view, gui cooperative trace reading\n\
3031 scheduler with interruptible foreground and background\n\
3032 computation, detailed event list (rewrite), trace reading\n\
3033 library (rewrite))\n\
3034 Benoit Des Ligneris, Eric Clement (Cluster adaptation, work in progress)\n\
3035 Xang-Xiu Yang (new trace reading library and converter, lttv gui, \n\
3036 detailed event list and statistics view)\n\
3037 Tom Zanussi (RelayFS)\n\
3038 \n\
3039 Inspired from the original Linux Trace Toolkit Visualizer made by\n\
3040 Karim Yaghmour");
3041
3042 GtkWidget *label3 = gtk_label_new("");
3043 gtk_label_set_markup(GTK_LABEL(label3), "\
3044 Linux Trace Toolkit Viewer, Copyright (C) 2004, 2005, 2006\n\
3045 Michel Dagenais\n\
3046 Mathieu Desnoyers\n\
3047 Xang-Xiu Yang\n\
3048 Linux Trace Toolkit comes with ABSOLUTELY NO WARRANTY.\n\
3049 This is free software, and you are welcome to redistribute it\n\
3050 under certain conditions. See COPYING for details.");
3051 gtk_misc_set_padding(GTK_MISC(label3), 10, 20);
3052
3053 gtk_box_pack_start_defaults(GTK_BOX(vbox), label1);
3054 gtk_box_pack_start_defaults(GTK_BOX(vbox), label2);
3055 gtk_box_pack_start_defaults(GTK_BOX(vbox), label3);
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);
3068 }
3069
3070
3071 void
3072 on_button_new_clicked (GtkButton *button,
3073 gpointer user_data)
3074 {
3075 create_new_window((GtkWidget*)button, user_data, TRUE);
3076 }
3077
3078 void
3079 on_button_new_tab_clicked (GtkButton *button,
3080 gpointer user_data)
3081 {
3082 create_new_tab((GtkWidget*)button, user_data);
3083 }
3084
3085 void
3086 on_button_open_clicked (GtkButton *button,
3087 gpointer user_data)
3088 {
3089 #ifdef UNFINISHED_FEATURE
3090 open_traceset((GtkWidget*)button, user_data);
3091 #endif
3092 }
3093
3094
3095 void
3096 on_button_add_trace_clicked (GtkButton *button,
3097 gpointer user_data)
3098 {
3099 add_trace((GtkWidget*)button, user_data);
3100 }
3101
3102
3103 void
3104 on_button_remove_trace_clicked (GtkButton *button,
3105 gpointer user_data)
3106 {
3107 remove_trace((GtkWidget*)button, user_data);
3108 }
3109
3110 void
3111 on_button_redraw_clicked (GtkButton *button,
3112 gpointer user_data)
3113 {
3114 redraw((GtkWidget*)button, user_data);
3115 }
3116
3117 void
3118 on_button_continue_processing_clicked (GtkButton *button,
3119 gpointer user_data)
3120 {
3121 continue_processing((GtkWidget*)button, user_data);
3122 }
3123
3124 void
3125 on_button_stop_processing_clicked (GtkButton *button,
3126 gpointer user_data)
3127 {
3128 stop_processing((GtkWidget*)button, user_data);
3129 }
3130
3131
3132
3133 void
3134 on_button_save_clicked (GtkButton *button,
3135 gpointer user_data)
3136 {
3137 save((GtkWidget*)button, user_data);
3138 }
3139
3140
3141 void
3142 on_button_save_as_clicked (GtkButton *button,
3143 gpointer user_data)
3144 {
3145 save_as((GtkWidget*)button, user_data);
3146 }
3147
3148
3149 void
3150 on_button_zoom_in_clicked (GtkButton *button,
3151 gpointer user_data)
3152 {
3153 zoom_in((GtkWidget*)button, user_data);
3154 }
3155
3156
3157 void
3158 on_button_zoom_out_clicked (GtkButton *button,
3159 gpointer user_data)
3160 {
3161 zoom_out((GtkWidget*)button, user_data);
3162 }
3163
3164
3165 void
3166 on_button_zoom_extended_clicked (GtkButton *button,
3167 gpointer user_data)
3168 {
3169 zoom_extended((GtkWidget*)button, user_data);
3170 }
3171
3172
3173 void
3174 on_button_go_to_time_clicked (GtkButton *button,
3175 gpointer user_data)
3176 {
3177 go_to_time((GtkWidget*)button, user_data);
3178 }
3179
3180
3181 void
3182 on_button_show_time_frame_clicked (GtkButton *button,
3183 gpointer user_data)
3184 {
3185 show_time_frame((GtkWidget*)button, user_data);
3186 }
3187
3188
3189 void
3190 on_button_move_up_clicked (GtkButton *button,
3191 gpointer user_data)
3192 {
3193 move_up_viewer((GtkWidget*)button, user_data);
3194 }
3195
3196
3197 void
3198 on_button_move_down_clicked (GtkButton *button,
3199 gpointer user_data)
3200 {
3201 move_down_viewer((GtkWidget*)button, user_data);
3202 }
3203
3204
3205 void
3206 on_button_delete_viewer_clicked (GtkButton *button,
3207 gpointer user_data)
3208 {
3209 delete_viewer((GtkWidget*)button, user_data);
3210 }
3211
3212 void
3213 on_MWindow_destroy (GtkWidget *widget,
3214 gpointer user_data)
3215 {
3216 MainWindow *main_window = get_window_data_struct(widget);
3217 LttvIAttribute *attributes = main_window->attributes;
3218 LttvAttributeValue value;
3219 gboolean retval;
3220
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
3225 retval= lttv_iattribute_find_by_path(attributes, "viewers/menu",
3226 LTTV_POINTER, &value);
3227 g_assert(retval);
3228 lttv_menus_destroy((LttvMenus*)*(value.v_pointer));
3229
3230 retval= lttv_iattribute_find_by_path(attributes, "viewers/toolbar",
3231 LTTV_POINTER, &value);
3232 g_assert(retval);
3233 lttv_toolbars_destroy((LttvToolbars*)*(value.v_pointer));
3234
3235 g_object_unref(main_window->attributes);
3236 g_main_window_list = g_slist_remove(g_main_window_list, main_window);
3237
3238 g_info("There are now : %d windows\n",g_slist_length(g_main_window_list));
3239 if(g_slist_length(g_main_window_list) == 0)
3240 mainwindow_quit();
3241 }
3242
3243 gboolean
3244 on_MWindow_configure (GtkWidget *widget,
3245 GdkEventConfigure *event,
3246 gpointer user_data)
3247 {
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){
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;
3266 */
3267 return FALSE;
3268 }
3269
3270 /* Set current tab
3271 */
3272
3273 void
3274 on_MNotebook_switch_page (GtkNotebook *notebook,
3275 GtkNotebookPage *page,
3276 guint page_num,
3277 gpointer user_data)
3278 {
3279
3280 }
3281
3282
3283 void time_change_manager (Tab *tab,
3284 TimeWindow new_time_window)
3285 {
3286
3287 /* Only one source of time change */
3288 if(tab->time_manager_lock == TRUE) return;
3289
3290 tab->time_manager_lock = TRUE;
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
3297
3298 LttTime start_time = new_time_window.start_time;
3299 LttTime end_time = new_time_window.end_time;
3300
3301 g_assert(ltt_time_compare(start_time, end_time) < 0);
3302
3303 /* Set scrollbar */
3304 GtkAdjustment *adjustment = gtk_range_get_adjustment(GTK_RANGE(tab->scrollbar));
3305 LttTime upper = ltt_time_sub(time_span.end_time, time_span.start_time);
3306
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",
3323 ltt_time_to_double(upper), /* upper */
3324 "step_increment",
3325 new_time_window.time_width_double
3326 / SCROLL_STEP_PER_PAGE, /* step increment */
3327 "page_increment",
3328 new_time_window.time_width_double,
3329 /* page increment */
3330 "page_size",
3331 new_time_window.time_width_double, /* page size */
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))
3339 // , /* value */
3340 // NULL);
3341 //gtk_adjustment_value_changed(adjustment);
3342 gtk_range_set_value(GTK_RANGE(tab->scrollbar),
3343 ltt_time_to_double(
3344 ltt_time_sub(start_time, time_span.start_time)) /* value */);
3345
3346 /* set the time bar. */
3347
3348
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);
3354
3355
3356
3357 /* call viewer hooks for new time window */
3358 set_time_window(tab, &new_time_window);
3359
3360 tab->time_manager_lock = FALSE;
3361
3362
3363 }
3364
3365
3366
3367
3368
3369 void 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
3377 timebar_set_current_time(TIMEBAR(tab->MTimebar), &new_current_time);
3378
3379 set_current_time(tab, &new_current_time);
3380
3381 tab->current_time_manager_lock = FALSE;
3382 }
3383
3384 void current_position_change_manager(Tab *tab, LttvTracesetPosition *pos)
3385 {
3386 lttv_traceset_seek_to_position( pos);
3387
3388 LttTime new_time = lttv_traceset_position_get_time(pos);
3389 /* Put the context in a state coherent position */
3390 #ifdef BABEL_CLEANUP
3391 lttv_state_traceset_seek_time_closest((LttvTracesetState*)tsc, ltt_time_zero);
3392 #endif /* BABEL_CLEANUP */
3393 current_time_change_manager(tab, new_time);
3394
3395 set_current_position(tab, pos);
3396 }
3397
3398 static void on_timebar_starttime_changed(Timebar *timebar,
3399 gpointer user_data)
3400 {
3401 Tab *tab = (Tab *)user_data;
3402 LttvTraceset * ts =tab->traceset_info->traceset;
3403 TimeInterval time_span = lttv_traceset_get_time_span(ts);
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);
3431
3432 }
3433
3434 static void on_timebar_endtime_changed(Timebar *timebar,
3435 gpointer user_data)
3436 {
3437 Tab *tab = (Tab *)user_data;
3438 LttvTraceset * ts =tab->traceset_info->traceset;
3439 TimeInterval time_span = lttv_traceset_get_time_span(ts);
3440
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 }
3455
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 */
3466 time_change_manager(tab, new_time_window);
3467 }
3468 static 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 }
3477
3478 void scroll_value_changed_cb(GtkWidget *scrollbar,
3479 gpointer user_data)
3480 {
3481 Tab *tab = (Tab *)user_data;
3482 TimeWindow new_time_window;
3483 LttTime time;
3484 GtkAdjustment *adjust = gtk_range_get_adjustment(GTK_RANGE(scrollbar));
3485 gdouble value = gtk_adjustment_get_value(adjust);
3486 // gdouble upper, lower, ratio, page_size;
3487 gdouble page_size;
3488
3489 LttvTraceset * ts = tab->traceset_info->traceset;
3490 TimeInterval time_span = lttv_traceset_get_time_span(ts);
3491
3492 time = ltt_time_add(ltt_time_from_double(value),
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 =
3500 ltt_time_from_double(page_size);
3501
3502 new_time_window.time_width_double =
3503 page_size;
3504
3505 new_time_window.end_time = ltt_time_add(new_time_window.start_time,
3506 new_time_window.time_width);
3507
3508
3509 time_change_manager(tab, new_time_window);
3510
3511 #if 0
3512 //time_window = tab->time_window;
3513
3514 lower = adjust->lower;
3515 upper = adjust->upper;
3516 ratio = (value - lower) / (upper - lower);
3517 g_info("lower %lu, upper %lu, value %lu, ratio %lu", lower, upper, value, ratio);
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);
3522 time = ltt_time_add(ltt_time_from_double(value),
3523 time_span.start_time);
3524
3525 time_window.start_time = time;
3526
3527 page_size = adjust->page_size;
3528
3529 time_window.time_width =
3530 ltt_time_from_double(page_size);
3531 //time = ltt_time_sub(time_span.end_time, time);
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);
3538 #endif //0
3539
3540 }
3541
3542
3543 /* Display a dialogue showing all eventtypes and traces, let user to select the interested
3544 * eventtypes, tracefiles and traces (filter)
3545 */
3546
3547 /* Select a trace which will be removed from traceset
3548 */
3549
3550 char * get_remove_trace(MainWindow *mw_data,
3551 char ** all_trace_name, int nb_trace)
3552 {
3553 return get_selection(mw_data, all_trace_name, nb_trace,
3554 "Select a trace", "Trace pathname");
3555 }
3556
3557
3558 /* Select a module which will be loaded
3559 */
3560
3561 char * get_load_module(MainWindow *mw_data,
3562 char ** load_module_name, int nb_module)
3563 {
3564 return get_selection(mw_data, load_module_name, nb_module,
3565 "Select a module to load", "Module name");
3566 }
3567
3568
3569
3570
3571 /* Select a module which will be unloaded
3572 */
3573
3574 char * get_unload_module(MainWindow *mw_data,
3575 char ** loaded_module_name, int nb_module)
3576 {
3577 return get_selection(mw_data, loaded_module_name, nb_module,
3578 "Select a module to unload", "Module name");
3579 }
3580
3581
3582 /* Display a dialogue which shows all selectable items, let user to
3583 * select one of them
3584 */
3585
3586 char * get_selection(MainWindow *mw_data,
3587 char ** loaded_module_name, int nb_module,
3588 char *title, char * column_title)
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
3601 dialogue = gtk_dialog_new_with_buttons(title,
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);
3608 gtk_window_set_transient_for(GTK_WINDOW(dialogue),
3609 GTK_WINDOW(mw_data->mwindow));
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 ();
3622 column = gtk_tree_view_column_new_with_attributes (column_title,
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));
3643 GtkTreeModel **store_model = (GtkTreeModel**)&store;
3644 switch(id){
3645 case GTK_RESPONSE_ACCEPT:
3646 case GTK_RESPONSE_OK:
3647 if (gtk_tree_selection_get_selected (select, store_model, &iter)){
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 }
3659
3660
3661 /* Insert all menu entry and tool buttons into this main window
3662 * for modules.
3663 *
3664 */
3665
3666 void add_all_menu_toolbar_constructors(MainWindow * mw, gpointer user_data)
3667 {
3668 guint i;
3669 GdkPixbuf *pixbuf;
3670 lttvwindow_viewer_constructor constructor;
3671 LttvMenus * global_menu, * instance_menu;
3672 LttvToolbars * global_toolbar, * instance_toolbar;
3673 LttvMenuClosure *menu_item;
3674 LttvToolbarClosure *toolbar_item;
3675 LttvAttributeValue value;
3676 LttvIAttribute *global_attributes = LTTV_IATTRIBUTE(lttv_global_attributes());
3677 LttvIAttribute *attributes = mw->attributes;
3678 GtkWidget * tool_menu_title_menu, *new_widget, *pixmap;
3679 gboolean retval;
3680
3681 retval= lttv_iattribute_find_by_path(global_attributes, "viewers/menu",
3682 LTTV_POINTER, &value);
3683 g_assert(retval);
3684 if(*(value.v_pointer) == NULL)
3685 *(value.v_pointer) = lttv_menus_new();
3686 global_menu = (LttvMenus*)*(value.v_pointer);
3687
3688 retval= lttv_iattribute_find_by_path(attributes, "viewers/menu",
3689 LTTV_POINTER, &value);
3690 g_assert(retval);
3691 if(*(value.v_pointer) == NULL)
3692 *(value.v_pointer) = lttv_menus_new();
3693 instance_menu = (LttvMenus*)*(value.v_pointer);
3694
3695 retval= lttv_iattribute_find_by_path(global_attributes, "viewers/toolbar",
3696 LTTV_POINTER, &value);
3697 g_assert(retval);
3698 if(*(value.v_pointer) == NULL)
3699 *(value.v_pointer) = lttv_toolbars_new();
3700 global_toolbar = (LttvToolbars*)*(value.v_pointer);
3701
3702 retval= lttv_iattribute_find_by_path(attributes, "viewers/toolbar",
3703 LTTV_POINTER, &value);
3704 g_assert(retval);
3705 if(*(value.v_pointer) == NULL)
3706 *(value.v_pointer) = lttv_toolbars_new();
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++) {
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 =
3717 gtk_menu_item_new_with_mnemonic (menu_item->menu_text);
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);
3728
3729 }
3730
3731 /* Add missing toolbar entries to window instance */
3732 for(i=0;i<global_toolbar->len;i++) {
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);
3758
3759 lttv_toolbars_add(instance_toolbar, toolbar_item->con,
3760 toolbar_item->tooltip,
3761 toolbar_item->pixmap,
3762 new_widget);
3763
3764 }
3765
3766 }
3767
3768
3769 /* Create a main window
3770 */
3771
3772 MainWindow *construct_main_window(MainWindow * parent)
3773 {
3774 gboolean retval;
3775
3776 g_debug("construct_main_window()");
3777 GtkWidget * new_window; /* New generated main window */
3778 MainWindow * new_m_window;/* New main window structure */
3779 GtkNotebook * notebook;
3780 LttvIAttribute *attributes =
3781 LTTV_IATTRIBUTE(g_object_new(LTTV_ATTRIBUTE_TYPE, NULL));
3782 LttvAttributeValue value;
3783
3784 new_m_window = g_new(MainWindow, 1);
3785
3786 // Add the object's information to the module's array
3787 g_main_window_list = g_slist_append(g_main_window_list, new_m_window);
3788
3789 new_window = create_MWindow();
3790 gtk_widget_show (new_window);
3791
3792 new_m_window->mwindow = new_window;
3793 new_m_window->attributes = attributes;
3794
3795 retval= lttv_iattribute_find_by_path(attributes, "viewers/menu",
3796 LTTV_POINTER, &value);
3797 g_assert(retval);
3798 *(value.v_pointer) = lttv_menus_new();
3799
3800 retval= lttv_iattribute_find_by_path(attributes, "viewers/toolbar",
3801 LTTV_POINTER, &value);
3802 g_assert(retval);
3803 *(value.v_pointer) = lttv_toolbars_new();
3804
3805 add_all_menu_toolbar_constructors(new_m_window, NULL);
3806
3807 g_object_set_data_full(G_OBJECT(new_window),
3808 "main_window_data",
3809 (gpointer)new_m_window,
3810 (GDestroyNotify)g_free);
3811 //create a default tab
3812 notebook = (GtkNotebook *)lookup_widget(new_m_window->mwindow, "MNotebook");
3813 if(notebook == NULL){
3814 g_info("Notebook does not exist\n");
3815 /* FIXME : destroy partially created widgets */
3816 g_free(new_m_window);
3817 return NULL;
3818 }
3819 //gtk_notebook_popup_enable (GTK_NOTEBOOK(notebook));
3820 //for now there is no name field in LttvTraceset structure
3821 //Use "Traceset" as the label for the default tab
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 {
3831 LttvPluginTab *ptab;
3832 ptab = (LttvPluginTab *)g_object_get_data(G_OBJECT(page), "Tab_Plugin");
3833 parent_tab = ptab->tab;
3834 }
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);
3844 } else {
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);
3853 }
3854
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
3865 attribute = LTTV_ATTRIBUTE(lttv_iattribute_find_subdir(
3866 LTTV_IATTRIBUTE(attributes_global),
3867 LTTV_VIEWER_CONSTRUCTORS));
3868 g_assert(attribute);
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);
3877 }
3878
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 }
3887
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);
3895 }
3896 }
3897
3898 g_info("There are now : %d windows\n",g_slist_length(g_main_window_list));
3899
3900 return new_m_window;
3901 }
3902
3903
3904 /* Free the memory occupied by a tab structure
3905 * destroy the tab
3906 */
3907
3908 void tab_destructor(LttvPluginTab * ptab)
3909 {
3910 #ifdef BABEL_CLEANUP
3911 int i, nb, ref_count;
3912 LttvTrace * trace;
3913 Tab *tab = ptab->tab;
3914
3915 if(tab->attributes)
3916 g_object_unref(tab->attributes);
3917
3918 if(tab->interrupted_state)
3919 g_object_unref(tab->interrupted_state);
3920
3921
3922 if(tab->traceset_info->traceset_context != NULL){
3923 //remove state update hooks
3924 lttv_state_remove_event_hooks(
3925 (LttvTracesetState*)tab->traceset_info->
3926 traceset_context);
3927 lttv_context_fini(LTTV_TRACESET_CONTEXT(tab->traceset_info->
3928 traceset_context));
3929 g_object_unref(tab->traceset_info->traceset_context);
3930 }
3931 if(tab->traceset_info->traceset != NULL) {
3932 nb = lttv_traceset_number(tab->traceset_info->traceset);
3933 for(i = 0 ; i < nb ; i++) {
3934 trace = lttv_traceset_get(tab->traceset_info->traceset, i);
3935 ref_count = lttv_trace_get_ref_number(trace);
3936 if(ref_count <= 1){
3937 ltt_trace_close(lttv_trace(trace));
3938 }
3939 }
3940 }
3941 lttv_traceset_destroy(tab->traceset_info->traceset);
3942 /* Remove the idle events requests processing function of the tab */
3943 g_idle_remove_by_data(tab);
3944
3945 g_slist_free(tab->events_requests);
3946 g_free(tab->traceset_info);
3947 //g_free(tab);
3948 g_object_unref(ptab);
3949 #endif /* BABEL_CLEANUP */
3950 }
3951
3952
3953 /* Create a tab and insert it into the current main window
3954 */
3955
3956 void init_tab(Tab *tab, MainWindow * mw, Tab *copy_tab,
3957 GtkNotebook * notebook, char * label)
3958 {
3959
3960 GList * list;
3961 //Tab * tab;
3962 //LttvFilter *filter = NULL;
3963
3964 //create a new tab data structure
3965 //tab = g_new(Tab,1);
3966
3967 //construct and initialize the traceset_info
3968 tab->traceset_info = g_new(TracesetInfo,1);
3969
3970 if(copy_tab) {
3971 tab->traceset_info->traceset =
3972 lttv_traceset_copy(copy_tab->traceset_info->traceset);
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 */
3977
3978 #ifdef BABEL_CLEANUP
3979 tab->filter = lttv_filter_clone(copy_tab->filter);
3980 #endif /* BABEL_CLEANUP */
3981 } else {
3982 tab->traceset_info->traceset = lttv_traceset_new();
3983
3984 tab->filter = NULL;
3985 }
3986 #ifdef DEBUG
3987 lttv_attribute_write_xml(
3988 lttv_traceset_attribute(tab->traceset_info->traceset),
3989 stdout,
3990 0, 4);
3991 fflush(stdout);
3992 #endif //DEBUG
3993 //
3994 tab->time_manager_lock = FALSE;
3995 tab->current_time_manager_lock = FALSE;
3996 #ifdef BABEL_CLEANUP
3997 //FIXME copy not implemented in lower level
3998 tab->traceset_info->traceset_context =
3999 g_object_new(LTTV_TRACESET_STATS_TYPE, NULL);
4000 //add state update hooks
4001 lttv_state_add_event_hooks(
4002 (LttvTracesetState*)tab->traceset_info->traceset_context);
4003 #endif //BABEL_CLEANUP
4004 //determine the current_time and time_window of the tab
4005 #if 0
4006 if(copy_tab != NULL){
4007 tab->time_window = copy_tab->time_window;
4008 tab->current_time = copy_tab->current_time;
4009 }else{
4010 tab->time_window.start_time =
4011 LTTV_TRACESET_CONTEXT(tab->traceset_info->traceset_context)->
4012 time_span.start_time;
4013 if(DEFAULT_TIME_WIDTH_S <
4014 LTTV_TRACESET_CONTEXT(tab->traceset_info->traceset_context)->
4015 time_span.end_time.tv_sec)
4016 tmp_time.tv_sec = DEFAULT_TIME_WIDTH_S;
4017 else
4018 tmp_time.tv_sec =
4019 LTTV_TRACESET_CONTEXT(tab->traceset_info->traceset_context)->
4020 time_span.end_time.tv_sec;
4021 tmp_time.tv_nsec = 0;
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;
4029 }
4030 #endif //0
4031 tab->attributes = LTTV_IATTRIBUTE(g_object_new(LTTV_ATTRIBUTE_TYPE, NULL));
4032 tab->interrupted_state = g_object_new(LTTV_ATTRIBUTE_TYPE, NULL);
4033
4034 tab->vbox = gtk_vbox_new(FALSE, 2);
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
4044 tab->viewer_container = gtk_vbox_new(TRUE, 2);
4045 tab->scrollbar = gtk_hscrollbar_new(NULL);
4046 //tab->multivpaned = gtk_multi_vpaned_new();
4047
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 */
4053
4054 // if(copy_tab) {
4055 // tab->time_window = copy_tab->time_window;
4056 // tab->current_time = copy_tab->current_time;
4057 // }
4058
4059 /* Create the timebar */
4060
4061 tab->MTimebar = timebar_new();
4062
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 */
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
4075 g_object_set_data(G_OBJECT(tab->viewer_container), "focused_viewer", NULL);
4076
4077
4078 tab->mw = mw;
4079
4080 /*{
4081 // Display a label with a X
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);
4094
4095 g_signal_connect_swapped (w_button, "clicked",
4096 G_CALLBACK (on_close_tab_X_clicked),
4097 tab->multi_vpaned);
4098
4099 gtk_widget_set_state(w_button, GTK_STATE_ACTIVE);
4100
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;
4107 }*/
4108
4109
4110 tab->label = gtk_label_new (label);
4111
4112 gtk_widget_show(tab->label);
4113 gtk_widget_show(tab->scrollbar);
4114 gtk_widget_show(tab->MTimebar);
4115 gtk_widget_show(tab->viewer_container);
4116 gtk_widget_show(tab->vbox);
4117
4118 //gtk_widget_show(tab->multivpaned);
4119
4120
4121 /* Start with empty events requests list */
4122 tab->events_requests = NULL;
4123 tab->events_request_pending = FALSE;
4124 tab->stop_foreground = FALSE;
4125
4126
4127
4128 g_signal_connect(G_OBJECT(tab->scrollbar), "value-changed",
4129 G_CALLBACK(scroll_value_changed_cb), tab);
4130
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);
4139
4140 //g_signal_connect(G_OBJECT(tab->scrollbar), "changed",
4141 // G_CALLBACK(scroll_value_changed_cb), tab);
4142
4143
4144 //insert tab into notebook
4145 gtk_notebook_append_page(notebook,
4146 tab->vbox,
4147 tab->label);
4148 list = gtk_container_get_children(GTK_CONTAINER(notebook));
4149 gtk_notebook_set_current_page(notebook,g_list_length(list)-1);
4150 // always show : not if(g_list_length(list)>1)
4151 gtk_notebook_set_show_tabs(notebook, TRUE);
4152
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 }
4168
4169 LttvTraceset *traceset = tab->traceset_info->traceset;
4170 SetTraceset(tab, traceset);
4171 }
4172
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 */
4180 gboolean execute_events_requests(Tab *tab)
4181 {
4182 return ( lttvwindow_process_pending_requests(tab) );
4183 }
4184
4185
4186 __EXPORT void create_main_window_with_trace_list(GSList *traces)
4187 {
4188
4189 GSList *iter = NULL;
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)));
4198 LttvPluginTab *ptab;
4199 Tab *tab;
4200
4201 if(!page) {
4202 ptab = create_new_tab(widget, NULL);
4203 tab = ptab->tab;
4204 } else {
4205 ptab = (LttvPluginTab *)g_object_get_data(G_OBJECT(page), "Tab_Plugin");
4206 tab = ptab->tab;
4207 }
4208
4209 LttvTraceset * traceset = lttv_traceset_new();
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];
4214
4215
4216 get_absolute_pathname(path, abs_path);
4217
4218 if(lttv_traceset_add_path(traceset,abs_path) != 0 ){ /*failure*/
4219
4220 g_warning("cannot open trace %s", abs_path);
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,
4228 "Cannot open trace : maybe you should enter in the directory "
4229 "to select it ?");
4230 gtk_dialog_run(GTK_DIALOG(dialogue));
4231 gtk_widget_destroy(dialogue);
4232 }
4233 else{
4234 SetTraceset(tab, traceset);
4235 }
4236 }
4237 }
4238
This page took 0.217514 seconds and 3 git commands to generate.