1 /* This file is part of the Linux Trace Toolkit viewer
2 * Copyright (C) 2003-2004 XangXiu Yang
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;
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.
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,
19 /*! \file lttvwindow.c
20 * \brief API used by the graphical viewers to interact with their tab.
22 * Main window (gui module) is the place to contain and display viewers.
23 * Viewers (lttv plugins) interact with tab and main window through this API
24 * and events sent by gtk.
25 * This header file should be included in each graphic module.
26 * This library is used by graphical modules to interact with their tab and
36 #include <lttv/lttv.h>
37 #include <lttv/state.h>
38 #include <lttv/stats.h>
39 #include <lttv/tracecontext.h>
40 #include <lttvwindow/mainwindow.h>
41 #include <lttvwindow/mainwindow-private.h>
42 #include <lttvwindow/lttvwindow.h>
43 #include <lttvwindow/toolbar.h>
44 #include <lttvwindow/menu.h>
45 #include <lttvwindow/callbacks.h> // for execute_events_requests
46 #include <lttvwindow/support.h>
49 * Internal function parts
52 extern GSList
* g_main_window_list
;
56 * It updates the time window of the tab, then calls the updatetimewindow
57 * hooks of each viewer.
59 * This is called whenever the scrollbar value changes.
62 void set_time_window(Tab
*tab
, const TimeWindow
*time_window
)
64 LttvAttributeValue value
;
67 TimeWindowNotifyData time_window_notify_data
;
68 TimeWindow old_time_window
= tab
->time_window
;
69 time_window_notify_data
.old_time_window
= &old_time_window
;
70 tab
->time_window
= *time_window
;
71 time_window_notify_data
.new_time_window
=
74 g_assert(lttv_iattribute_find_by_path(tab
->attributes
,
75 "hooks/updatetimewindow", LTTV_POINTER
, &value
));
76 tmp
= (LttvHooks
*)*(value
.v_pointer
);
77 if(tmp
!= NULL
) lttv_hooks_call(tmp
, &time_window_notify_data
);
79 //gtk_multi_vpaned_set_adjust(tab->multi_vpaned, new_time_window, FALSE);
85 * It updates the current time of the tab, then calls the updatetimewindow
86 * hooks of each viewer.
88 * This is called whenever the current time value changes.
91 void set_current_time(Tab
*tab
, const LttTime
*current_time
)
93 LttvAttributeValue value
;
96 tab
->current_time
= *current_time
;
98 g_assert(lttv_iattribute_find_by_path(tab
->attributes
,
99 "hooks/updatecurrenttime", LTTV_POINTER
, &value
));
100 tmp
= (LttvHooks
*)*(value
.v_pointer
);
101 if(tmp
!= NULL
) lttv_hooks_call(tmp
, &tab
->current_time
);
104 /* set_current_position
106 * It updates the current time of the tab, then calls the updatetimewindow
107 * hooks of each viewer.
109 * This is called whenever the current time value changes.
112 void set_current_position(Tab
*tab
, const LttvTracesetContextPosition
*pos
)
114 LttvAttributeValue value
;
117 tab
->current_time
= lttv_traceset_context_position_get_time(pos
);
119 g_assert(lttv_iattribute_find_by_path(tab
->attributes
,
120 "hooks/updatecurrentposition", LTTV_POINTER
, &value
));
121 tmp
= (LttvHooks
*)*(value
.v_pointer
);
122 if(tmp
!= NULL
) lttv_hooks_call(tmp
, pos
);
125 void add_toolbar_constructor(MainWindow
*mw
, LttvToolbarClosure
*toolbar_c
)
127 LttvIAttribute
*attributes
= mw
->attributes
;
128 LttvAttributeValue value
;
129 LttvToolbars
* instance_toolbar
;
130 lttvwindow_viewer_constructor constructor
;
131 GtkWidget
* tool_menu_title_menu
, *new_widget
, *pixmap
;
134 g_assert(lttv_iattribute_find_by_path(attributes
,
135 "viewers/toolbar", LTTV_POINTER
, &value
));
136 if(*(value
.v_pointer
) == NULL
)
137 *(value
.v_pointer
) = lttv_toolbars_new();
138 instance_toolbar
= (LttvToolbars
*)*(value
.v_pointer
);
140 constructor
= toolbar_c
->con
;
141 tool_menu_title_menu
= lookup_widget(mw
->mwindow
,"MToolbar1");
142 pixbuf
= gdk_pixbuf_new_from_xpm_data((const char**)toolbar_c
->pixmap
);
143 pixmap
= gtk_image_new_from_pixbuf(pixbuf
);
145 gtk_toolbar_append_element (GTK_TOOLBAR (tool_menu_title_menu
),
146 GTK_TOOLBAR_CHILD_BUTTON
,
149 toolbar_c
->tooltip
, NULL
,
151 gtk_label_set_use_underline(
152 GTK_LABEL (((GtkToolbarChild
*) (
153 g_list_last (GTK_TOOLBAR
154 (tool_menu_title_menu
)->children
)->data
))->label
),
156 gtk_container_set_border_width (GTK_CONTAINER (new_widget
), 1);
157 g_signal_connect ((gpointer
) new_widget
,
159 G_CALLBACK (insert_viewer_wrap
),
161 gtk_widget_show (new_widget
);
163 lttv_toolbars_add(instance_toolbar
, toolbar_c
->con
,
170 void add_menu_constructor(MainWindow
*mw
, LttvMenuClosure
*menu_c
)
172 LttvIAttribute
*attributes
= mw
->attributes
;
173 LttvAttributeValue value
;
174 LttvToolbars
* instance_menu
;
175 lttvwindow_viewer_constructor constructor
;
176 GtkWidget
* tool_menu_title_menu
, *new_widget
;
178 g_assert(lttv_iattribute_find_by_path(attributes
,
179 "viewers/menu", LTTV_POINTER
, &value
));
180 if(*(value
.v_pointer
) == NULL
)
181 *(value
.v_pointer
) = lttv_menus_new();
182 instance_menu
= (LttvMenus
*)*(value
.v_pointer
);
185 constructor
= menu_c
->con
;
186 tool_menu_title_menu
= lookup_widget(mw
->mwindow
,"ToolMenuTitle_menu");
188 gtk_menu_item_new_with_mnemonic (menu_c
->menu_text
);
189 gtk_container_add (GTK_CONTAINER (tool_menu_title_menu
),
191 g_signal_connect ((gpointer
) new_widget
, "activate",
192 G_CALLBACK (insert_viewer_wrap
),
194 gtk_widget_show (new_widget
);
195 lttv_menus_add(instance_menu
, menu_c
->con
,
201 void remove_toolbar_constructor(MainWindow
*mw
, lttvwindow_viewer_constructor viewer_constructor
)
203 LttvIAttribute
*attributes
= mw
->attributes
;
204 LttvAttributeValue value
;
205 LttvToolbars
* instance_toolbar
;
206 lttvwindow_viewer_constructor constructor
;
207 GtkWidget
* tool_menu_title_menu
, *widget
;
209 g_assert(lttv_iattribute_find_by_path(attributes
,
210 "viewers/toolbar", LTTV_POINTER
, &value
));
211 if(*(value
.v_pointer
) == NULL
)
212 *(value
.v_pointer
) = lttv_toolbars_new();
213 instance_toolbar
= (LttvToolbars
*)*(value
.v_pointer
);
215 tool_menu_title_menu
= lookup_widget(mw
->mwindow
,"MToolbar1");
216 widget
= lttv_menus_remove(instance_toolbar
, viewer_constructor
);
217 gtk_container_remove (GTK_CONTAINER (tool_menu_title_menu
),
222 void remove_menu_constructor(MainWindow
*mw
, lttvwindow_viewer_constructor viewer_constructor
)
224 LttvIAttribute
*attributes
= mw
->attributes
;
225 LttvAttributeValue value
;
226 LttvMenus
* instance_menu
;
227 lttvwindow_viewer_constructor constructor
;
228 GtkWidget
* tool_menu_title_menu
, *widget
;
229 LttvMenuClosure
*menu_item_i
;
231 g_assert(lttv_iattribute_find_by_path(attributes
,
232 "viewers/menu", LTTV_POINTER
, &value
));
233 if(*(value
.v_pointer
) == NULL
)
234 *(value
.v_pointer
) = lttv_menus_new();
235 instance_menu
= (LttvMenus
*)*(value
.v_pointer
);
237 widget
= lttv_menus_remove(instance_menu
, viewer_constructor
);
238 tool_menu_title_menu
= lookup_widget(mw
->mwindow
,"ToolMenuTitle_menu");
239 gtk_container_remove (GTK_CONTAINER (tool_menu_title_menu
), widget
);
249 * Function to register a view constructor so that main window can generate
250 * a menu item and a toolbar item for the viewer in order to generate a new
251 * instance easily. A menu entry and toolbar item will be added to each main
254 * It should be called by init function of the module.
256 * @param name name of the viewer
257 * @param menu_path path of the menu item.
258 * @param menu_text text of the menu item.
259 * @param pixmap Image shown on the toolbar item.
260 * @param tooltip tooltip of the toolbar item.
261 * @param view_constructor constructor of the viewer.
264 void lttvwindow_register_constructor
270 lttvwindow_viewer_constructor view_constructor
)
272 LttvIAttribute
*attributes_global
= LTTV_IATTRIBUTE(lttv_global_attributes());
273 LttvToolbars
* toolbar
;
275 LttvToolbarClosure toolbar_c
;
276 LttvMenuClosure menu_c
;
277 LttvAttributeValue value
;
279 if(view_constructor
== NULL
) return;
282 g_assert(lttv_iattribute_find_by_path(attributes_global
,
283 "viewers/toolbar", LTTV_POINTER
, &value
));
284 toolbar
= (LttvToolbars
*)*(value
.v_pointer
);
286 if(toolbar
== NULL
) {
287 toolbar
= lttv_toolbars_new();
288 *(value
.v_pointer
) = toolbar
;
290 toolbar_c
= lttv_toolbars_add(toolbar
, view_constructor
, tooltip
, pixmap
,
293 g_slist_foreach(g_main_window_list
,
294 (gpointer
)add_toolbar_constructor
,
298 if(menu_path
!= NULL
) {
299 g_assert(lttv_iattribute_find_by_path(attributes_global
,
300 "viewers/menu", LTTV_POINTER
, &value
));
301 menu
= (LttvMenus
*)*(value
.v_pointer
);
304 menu
= lttv_menus_new();
305 *(value
.v_pointer
) = menu
;
307 menu_c
= lttv_menus_add(menu
, view_constructor
, menu_path
, menu_text
,NULL
);
309 g_slist_foreach(g_main_window_list
,
310 (gpointer
)add_menu_constructor
,
314 LttvAttribute
*attribute
;
316 LTTV_ATTRIBUTE(lttv_iattribute_find_subdir(
317 LTTV_IATTRIBUTE(attributes_global
),
318 LTTV_VIEWER_CONSTRUCTORS
)));
320 g_assert(lttv_iattribute_find_by_path(LTTV_IATTRIBUTE(attribute
),
321 name
, LTTV_POINTER
, &value
));
323 *(value
.v_pointer
) = view_constructor
;
330 * Function to unregister the viewer's constructor, release the space
331 * occupied by menu_path, menu_text, pixmap, tooltip and constructor of the
334 * It will be called when a module is unloaded.
336 * @param view_constructor constructor of the viewer.
340 void lttvwindow_unregister_constructor
341 (lttvwindow_viewer_constructor view_constructor
)
343 LttvIAttribute
*attributes_global
= LTTV_IATTRIBUTE(lttv_global_attributes());
344 LttvToolbars
* toolbar
;
346 LttvAttributeValue value
;
348 g_assert(lttv_iattribute_find_by_path(attributes_global
,
349 "viewers/toolbar", LTTV_POINTER
, &value
));
350 toolbar
= (LttvToolbars
*)*(value
.v_pointer
);
352 if(toolbar
!= NULL
) {
353 g_slist_foreach(g_main_window_list
,
354 (gpointer
)remove_toolbar_constructor
,
356 lttv_toolbars_remove(toolbar
, view_constructor
);
359 g_assert(lttv_iattribute_find_by_path(attributes_global
,
360 "viewers/menu", LTTV_POINTER
, &value
));
361 menu
= (LttvMenus
*)*(value
.v_pointer
);
364 g_slist_foreach(g_main_window_list
,
365 (gpointer
)remove_menu_constructor
,
367 lttv_menus_remove(menu
, view_constructor
);
371 LttvAttribute
*attribute
;
373 LTTV_ATTRIBUTE(lttv_iattribute_find_subdir(
374 LTTV_IATTRIBUTE(attributes_global
),
375 LTTV_VIEWER_CONSTRUCTORS
)));
377 guint num
= lttv_iattribute_get_number(LTTV_IATTRIBUTE(attribute
));
379 LttvAttributeName name
;
380 LttvAttributeValue value
;
381 LttvAttributeType type
;
384 type
= lttv_iattribute_get(LTTV_IATTRIBUTE(attribute
), i
, &name
, &value
);
385 g_assert(type
== LTTV_POINTER
);
386 if(*(value
.v_pointer
) == view_constructor
) {
387 lttv_iattribute_remove(LTTV_IATTRIBUTE(attribute
), i
);
396 * Function to register a hook function for a viewer to set/update its
398 * @param tab viewer's tab
399 * @param hook hook function of the viewer.
400 * @param hook_data hook data associated with the hook function.
402 void lttvwindow_register_time_window_notify(Tab
*tab
,
403 LttvHook hook
, gpointer hook_data
)
405 LttvAttributeValue value
;
407 g_assert(lttv_iattribute_find_by_path(tab
->attributes
,
408 "hooks/updatetimewindow", LTTV_POINTER
, &value
));
409 tmp
= (LttvHooks
*)*(value
.v_pointer
);
411 tmp
= lttv_hooks_new();
412 *(value
.v_pointer
) = tmp
;
414 lttv_hooks_add(tmp
, hook
,hook_data
, LTTV_PRIO_DEFAULT
);
419 * Function to unregister a viewer's hook function which is used to
420 * set/update the time interval of the viewer.
421 * @param tab viewer's tab
422 * @param hook hook function of the viewer.
423 * @param hook_data hook data associated with the hook function.
426 void lttvwindow_unregister_time_window_notify(Tab
*tab
,
427 LttvHook hook
, gpointer hook_data
)
429 LttvAttributeValue value
;
431 g_assert(lttv_iattribute_find_by_path(tab
->attributes
,
432 "hooks/updatetimewindow", LTTV_POINTER
, &value
));
433 tmp
= (LttvHooks
*)*(value
.v_pointer
);
434 if(tmp
== NULL
) return;
435 lttv_hooks_remove_data(tmp
, hook
, hook_data
);
439 * Function to register a hook function for a viewer to set/update its
441 * @param tab viewer's tab
442 * @param hook hook function of the viewer.
443 * @param hook_data hook data associated with the hook function.
446 void lttvwindow_register_traceset_notify(Tab
*tab
,
447 LttvHook hook
, gpointer hook_data
)
449 LttvAttributeValue value
;
451 g_assert(lttv_iattribute_find_by_path(tab
->attributes
,
452 "hooks/updatetraceset", LTTV_POINTER
, &value
));
453 tmp
= (LttvHooks
*)*(value
.v_pointer
);
455 tmp
= lttv_hooks_new();
456 *(value
.v_pointer
) = tmp
;
458 lttv_hooks_add(tmp
, hook
, hook_data
, LTTV_PRIO_DEFAULT
);
463 * Function to unregister a viewer's hook function which is used to
464 * set/update the traceset of the viewer.
465 * @param tab viewer's tab
466 * @param hook hook function of the viewer.
467 * @param hook_data hook data associated with the hook function.
470 void lttvwindow_unregister_traceset_notify(Tab
*tab
,
471 LttvHook hook
, gpointer hook_data
)
473 LttvAttributeValue value
;
475 g_assert(lttv_iattribute_find_by_path(tab
->attributes
,
476 "hooks/updatetraceset", LTTV_POINTER
, &value
));
477 tmp
= (LttvHooks
*)*(value
.v_pointer
);
478 if(tmp
== NULL
) return;
479 lttv_hooks_remove_data(tmp
, hook
, hook_data
);
483 * Function to register a hook function for a viewer be completely redrawn.
485 * @param tab viewer's tab
486 * @param hook hook function of the viewer.
487 * @param hook_data hook data associated with the hook function.
490 void lttvwindow_register_redraw_notify(Tab
*tab
,
491 LttvHook hook
, gpointer hook_data
)
493 LttvAttributeValue value
;
495 g_assert(lttv_iattribute_find_by_path(tab
->attributes
,
496 "hooks/redraw", LTTV_POINTER
, &value
));
497 tmp
= (LttvHooks
*)*(value
.v_pointer
);
499 tmp
= lttv_hooks_new();
500 *(value
.v_pointer
) = tmp
;
502 lttv_hooks_add(tmp
, hook
, hook_data
, LTTV_PRIO_DEFAULT
);
507 * Function to unregister a hook function for a viewer be completely redrawn.
509 * @param tab viewer's tab
510 * @param hook hook function of the viewer.
511 * @param hook_data hook data associated with the hook function.
514 void lttvwindow_unregister_redraw_notify(Tab
*tab
,
515 LttvHook hook
, gpointer hook_data
)
517 LttvAttributeValue value
;
519 g_assert(lttv_iattribute_find_by_path(tab
->attributes
,
520 "hooks/redraw", LTTV_POINTER
, &value
));
521 tmp
= (LttvHooks
*)*(value
.v_pointer
);
522 if(tmp
== NULL
) return;
523 lttv_hooks_remove_data(tmp
, hook
, hook_data
);
527 * Function to register a hook function for a viewer to re-do the events
528 * requests for the needed interval.
530 * This action is typically done after a "stop".
532 * The typical hook will remove all current requests for the viewer
533 * and make requests for missing information.
535 * @param tab viewer's tab
536 * @param hook hook function of the viewer.
537 * @param hook_data hook data associated with the hook function.
540 void lttvwindow_register_continue_notify(Tab
*tab
,
541 LttvHook hook
, gpointer hook_data
)
543 LttvAttributeValue value
;
545 g_assert(lttv_iattribute_find_by_path(tab
->attributes
,
546 "hooks/continue", LTTV_POINTER
, &value
));
547 tmp
= (LttvHooks
*)*(value
.v_pointer
);
549 tmp
= lttv_hooks_new();
550 *(value
.v_pointer
) = tmp
;
552 lttv_hooks_add(tmp
, hook
, hook_data
, LTTV_PRIO_DEFAULT
);
557 * Function to unregister a hook function for a viewer to re-do the events
558 * requests for the needed interval.
560 * @param tab viewer's tab
561 * @param hook hook function of the viewer.
562 * @param hook_data hook data associated with the hook function.
565 void lttvwindow_unregister_continue_notify(Tab
*tab
,
566 LttvHook hook
, gpointer hook_data
)
568 LttvAttributeValue value
;
570 g_assert(lttv_iattribute_find_by_path(tab
->attributes
,
571 "hooks/continue", LTTV_POINTER
, &value
));
572 tmp
= (LttvHooks
*)*(value
.v_pointer
);
573 if(tmp
== NULL
) return;
574 lttv_hooks_remove_data(tmp
, hook
, hook_data
);
579 * Function to register a hook function for a viewer to set/update its
581 * @param tab viewer's tab
582 * @param hook hook function of the viewer.
583 * @param hook_data hook data associated with the hook function.
586 void lttvwindow_register_filter_notify(Tab
*tab
,
587 LttvHook hook
, gpointer hook_data
)
589 LttvAttributeValue value
;
591 g_assert(lttv_iattribute_find_by_path(tab
->attributes
,
592 "hooks/updatefilter", LTTV_POINTER
, &value
));
593 tmp
= (LttvHooks
*)*(value
.v_pointer
);
595 tmp
= lttv_hooks_new();
596 *(value
.v_pointer
) = tmp
;
598 lttv_hooks_add(tmp
, hook
, hook_data
, LTTV_PRIO_DEFAULT
);
603 * Function to unregister a viewer's hook function which is used to
604 * set/update the filter of the viewer.
605 * @param tab viewer's tab
606 * @param hook hook function of the viewer.
607 * @param hook_data hook data associated with the hook function.
610 void lttvwindow_unregister_filter_notify(Tab
*tab
,
614 LttvAttributeValue value
;
616 g_assert(lttv_iattribute_find_by_path(tab
->attributes
,
617 "hooks/updatefilter", LTTV_POINTER
, &value
));
618 tmp
= (LttvHooks
*)*(value
.v_pointer
);
619 if(tmp
== NULL
) return;
620 lttv_hooks_remove_data(tmp
, hook
, hook_data
);
624 * function to register a hook function for a viewer to set/update its
626 * @param tab viewer's tab
627 * @param hook hook function of the viewer.
628 * @param hook_data hook data associated with the hook function.
631 void lttvwindow_register_current_time_notify(Tab
*tab
,
632 LttvHook hook
, gpointer hook_data
)
634 LttvAttributeValue value
;
636 g_assert(lttv_iattribute_find_by_path(tab
->attributes
,
637 "hooks/updatecurrenttime", LTTV_POINTER
, &value
));
638 tmp
= (LttvHooks
*)*(value
.v_pointer
);
640 tmp
= lttv_hooks_new();
641 *(value
.v_pointer
) = tmp
;
643 lttv_hooks_add(tmp
, hook
, hook_data
, LTTV_PRIO_DEFAULT
);
648 * function to unregister a viewer's hook function which is used to
649 * set/update the current time of the viewer.
650 * @param tab viewer's tab
651 * @param hook hook function of the viewer.
652 * @param hook_data hook data associated with the hook function.
655 void lttvwindow_unregister_current_time_notify(Tab
*tab
,
656 LttvHook hook
, gpointer hook_data
)
658 LttvAttributeValue value
;
660 g_assert(lttv_iattribute_find_by_path(tab
->attributes
,
661 "hooks/updatecurrenttime", LTTV_POINTER
, &value
));
662 tmp
= (LttvHooks
*)*(value
.v_pointer
);
663 if(tmp
== NULL
) return;
664 lttv_hooks_remove_data(tmp
, hook
, hook_data
);
668 * function to register a hook function for a viewer to set/update its
670 * @param tab viewer's tab
671 * @param hook hook function of the viewer.
672 * @param hook_data hook data associated with the hook function.
675 void lttvwindow_register_current_position_notify(Tab
*tab
,
676 LttvHook hook
, gpointer hook_data
)
678 LttvAttributeValue value
;
680 g_assert(lttv_iattribute_find_by_path(tab
->attributes
,
681 "hooks/updatecurrentposition", LTTV_POINTER
, &value
));
682 tmp
= (LttvHooks
*)*(value
.v_pointer
);
684 tmp
= lttv_hooks_new();
685 *(value
.v_pointer
) = tmp
;
687 lttv_hooks_add(tmp
, hook
, hook_data
, LTTV_PRIO_DEFAULT
);
692 * function to unregister a viewer's hook function which is used to
693 * set/update the current position of the viewer.
694 * @param tab viewer's tab
695 * @param hook hook function of the viewer.
696 * @param hook_data hook data associated with the hook function.
699 void lttvwindow_unregister_current_position_notify(Tab
*tab
,
700 LttvHook hook
, gpointer hook_data
)
702 LttvAttributeValue value
;
704 g_assert(lttv_iattribute_find_by_path(tab
->attributes
,
705 "hooks/updatecurrentposition", LTTV_POINTER
, &value
));
706 tmp
= (LttvHooks
*)*(value
.v_pointer
);
707 if(tmp
== NULL
) return;
708 lttv_hooks_remove_data(tmp
, hook
, hook_data
);
713 * Function to register a hook function for a viewer to show
714 * the content of the viewer.
715 * @param tab viewer's tab
716 * @param hook hook function of the viewer.
717 * @param hook_data hook data associated with the hook function.
720 void lttvwindow_register_show_notify(Tab
*tab
,
721 LttvHook hook
, gpointer hook_data
)
723 LttvAttributeValue value
;
725 g_assert(lttv_iattribute_find_by_path(tab
->attributes
,
726 "hooks/showviewer", LTTV_POINTER
, &value
));
727 tmp
= (LttvHooks
*)*(value
.v_pointer
);
729 tmp
= lttv_hooks_new();
730 *(value
.v_pointer
) = tmp
;
732 lttv_hooks_add(tmp
, hook
, hook_data
, LTTV_PRIO_DEFAULT
);
737 * Function to unregister a viewer's hook function which is used to
738 * show the content of the viewer..
739 * @param tab viewer's tab
740 * @param hook hook function of the viewer.
741 * @param hook_data hook data associated with the hook function.
744 void lttvwindow_unregister_show_notify(Tab
*tab
,
745 LttvHook hook
, gpointer hook_data
)
747 LttvAttributeValue value
;
749 g_assert(lttv_iattribute_find_by_path(tab
->attributes
,
750 "hooks/showviewer", LTTV_POINTER
, &value
));
751 tmp
= (LttvHooks
*)*(value
.v_pointer
);
752 if(tmp
== NULL
) return;
753 lttv_hooks_remove_data(tmp
, hook
, hook_data
);
757 * Function to register a hook function for a viewer to set/update the
758 * dividor of the hpane.
759 * @param tab viewer's tab
760 * @param hook hook function of the viewer.
761 * @param hook_data hook data associated with the hook function.
764 void lttvwindow_register_dividor(Tab
*tab
,
765 LttvHook hook
, gpointer hook_data
)
767 LttvAttributeValue value
;
769 g_assert(lttv_iattribute_find_by_path(tab
->attributes
,
770 "hooks/hpanedividor", LTTV_POINTER
, &value
));
771 tmp
= (LttvHooks
*)*(value
.v_pointer
);
773 tmp
= lttv_hooks_new();
774 *(value
.v_pointer
) = tmp
;
776 lttv_hooks_add(tmp
, hook
, hook_data
, LTTV_PRIO_DEFAULT
);
781 * Function to unregister a viewer's hook function which is used to
782 * set/update hpane's dividor of the viewer.
783 * It will be called by the destructor of the viewer.
784 * @param tab viewer's tab
785 * @param hook hook function of the viewer.
786 * @param hook_data hook data associated with the hook function.
789 void lttvwindow_unregister_dividor(Tab
*tab
,
790 LttvHook hook
, gpointer hook_data
)
792 LttvAttributeValue value
;
794 g_assert(lttv_iattribute_find_by_path(tab
->attributes
,
795 "hooks/hpanedividor", LTTV_POINTER
, &value
));
796 tmp
= (LttvHooks
*)*(value
.v_pointer
);
797 if(tmp
== NULL
) return;
798 lttv_hooks_remove_data(tmp
, hook
, hook_data
);
803 * Function to set the time interval of the current tab.
804 * It will be called by a viewer's signal handle associated with
805 * the move_slider signal
806 * @param tab viewer's tab
807 * @param time_interval a pointer where time interval is stored.
810 void lttvwindow_report_time_window(Tab
*tab
,
811 TimeWindow time_window
)
813 //set_time_window(tab, time_window);
814 //set_time_window_adjustment(tab, time_window);
816 time_change_manager(tab
, time_window
);
821 LttvTracesetContext
*tsc
=
822 LTTV_TRACESET_CONTEXT(tab
->traceset_info
->traceset_context
);
823 TimeInterval time_span
= tsc
->time_span
;
824 GtkAdjustment
*adjustment
= gtk_range_get_adjustment(GTK_RANGE(tab
->scrollbar
));
825 g_object_set(G_OBJECT(adjustment
),
830 ltt_time_sub(time_span
.end_time
, time_span
.start_time
))
833 ltt_time_to_double(time_window
->time_width
)
834 / SCROLL_STEP_PER_PAGE
835 , /* step increment */
837 ltt_time_to_double(time_window
->time_width
)
838 , /* page increment */
840 ltt_time_to_double(time_window
->time_width
)
843 gtk_adjustment_changed(adjustment
);
845 //g_object_set(G_OBJECT(adjustment),
847 // ltt_time_to_double(time_window->start_time)
850 /* Note : the set value will call set_time_window if scrollbar value changed
852 gtk_adjustment_set_value(adjustment
,
854 ltt_time_sub(time_window
->start_time
,
855 time_span
.start_time
))
862 * Function to set the current time of the current tab.
863 * It will be called by a viewer's signal handle associated with
864 * the button-release-event signal
865 * @param tab viewer's tab
866 * @param time a pointer where time is stored.
869 void lttvwindow_report_current_time(Tab
*tab
,
872 LttvAttributeValue value
;
875 current_time_change_manager(tab
, time
);
879 * Function to set the current event of the current tab.
880 * It will be called by a viewer's signal handle associated with
881 * the button-release-event signal
882 * @param tab viewer's tab
883 * @param time a pointer where time is stored.
886 void lttvwindow_report_current_position(Tab
*tab
,
887 LttvTracesetContextPosition
*pos
)
889 LttvAttributeValue value
;
892 current_position_change_manager(tab
, pos
);
897 * Function to set the position of the hpane's dividor (viewer).
898 * It will be called by a viewer's signal handle associated with
899 * the motion_notify_event event/signal
900 * @param tab viewer's tab
901 * @param position position of the hpane's dividor.
904 void lttvwindow_report_dividor(Tab
*tab
, gint position
)
906 LttvAttributeValue value
;
908 g_assert(lttv_iattribute_find_by_path(tab
->attributes
,
909 "hooks/hpanedividor", LTTV_POINTER
, &value
));
910 tmp
= (LttvHooks
*)*(value
.v_pointer
);
911 if(tmp
== NULL
) return;
912 lttv_hooks_call(tmp
, &position
);
916 * Function to request data in a specific time interval to the main window. The
917 * event request servicing is differed until the glib idle functions are
920 * The viewer has to provide hooks that should be associated with the event
923 * Either start time or start position must be defined in a EventRequest
924 * structure for it to be valid.
926 * end_time, end_position and num_events can all be defined. The first one
927 * to occur will be used as end criterion.
929 * @param tab viewer's tab
930 * @param events_requested the structure of request from.
933 void lttvwindow_events_request(Tab
*tab
,
934 EventsRequest
*events_request
)
936 tab
->events_requests
= g_slist_append(tab
->events_requests
, events_request
);
938 if(!tab
->events_request_pending
)
940 /* Redraw has +20 priority. We want to let the redraw be done while we do
942 g_idle_add_full((G_PRIORITY_HIGH_IDLE
+ 21),
943 (GSourceFunc
)execute_events_requests
,
946 tab
->events_request_pending
= TRUE
;
952 * Function to remove data requests related to a viewer.
954 * The existing requests's viewer gpointer is compared to the pointer
955 * given in argument to establish which data request should be removed.
957 * @param tab the tab the viewer belongs to.
958 * @param viewer a pointer to the viewer data structure
961 gint
find_viewer (const EventsRequest
*a
, gconstpointer b
)
963 return (a
->owner
!= b
);
967 void lttvwindow_events_request_remove_all(Tab
*tab
,
968 gconstpointer viewer
)
970 GSList
*element
= tab
->events_requests
;
973 g_slist_find_custom(element
, viewer
,
974 (GCompareFunc
)find_viewer
))
976 EventsRequest
*events_request
= (EventsRequest
*)element
->data
;
977 // Modified so a viewer being destroyed won't have its after_request
978 // called. Not so important anyway. Note that a viewer that call this
979 // remove_all function will not get its after_request called.
980 //if(events_request->servicing == TRUE) {
981 // lttv_hooks_call(events_request->after_request, NULL);
983 events_request_free(events_request
);
984 //g_free(events_request);
985 tab
->events_requests
= g_slist_remove_link(tab
->events_requests
, element
);
986 element
= g_slist_next(element
);
987 if(element
== NULL
) break; /* end of list */
989 if(g_slist_length(tab
->events_requests
) == 0) {
990 tab
->events_request_pending
= FALSE
;
991 g_idle_remove_by_data(tab
);
997 * Function to get the current time interval shown on the current tab.
998 * It will be called by a viewer's hook function to update the
999 * shown time interval of the viewer and also be called by the constructor
1001 * @param tab viewer's tab
1002 * @return time window.
1005 TimeWindow
lttvwindow_get_time_window(Tab
*tab
)
1007 return tab
->time_window
;
1012 * Function to get the current time/event of the current tab.
1013 * It will be called by a viewer's hook function to update the
1014 * current time/event of the viewer.
1015 * @param tab viewer's tab
1019 LttTime
lttvwindow_get_current_time(Tab
*tab
)
1021 return tab
->current_time
;
1026 * Function to get the filter of the current tab.
1027 * @param main_win, the main window the viewer belongs to.
1028 * @param filter, a pointer to a filter.
1031 LttvFilter
*lttvwindow_get_filter(Tab
*tab
)
1038 * Function to set the filter of the current tab.
1039 * It should be called by the filter GUI to tell the
1040 * main window to update the filter tab's lttv_filter.
1042 * This function does change the current filter, removing the
1043 * old one when necessary, and call the updatefilter hooks
1044 * of the registered viewers.
1046 * @param main_win, the main window the viewer belongs to.
1047 * @param filter, a pointer to a filter.
1050 void lttvwindow_report_filter(Tab
*tab
, LttvFilter
*filter
)
1052 LttvAttributeValue value
;
1055 lttv_filter_destroy(tab
->filter
);
1056 tab
->filter
= filter
;
1058 g_assert(lttv_iattribute_find_by_path(tab
->attributes
,
1059 "hooks/updatefilter", LTTV_POINTER
, &value
));
1060 tmp
= (LttvHooks
*)*(value
.v_pointer
);
1061 if(tmp
== NULL
) return;
1062 lttv_hooks_call(tmp
, filter
);
1068 * Function to get the stats of the traceset
1069 * @param tab viewer's tab
1072 LttvTracesetStats
* lttvwindow_get_traceset_stats(Tab
*tab
)
1074 return tab
->traceset_info
->traceset_context
;
1078 LttvTracesetContext
* lttvwindow_get_traceset_context(Tab
*tab
)
1080 return (LttvTracesetContext
*)tab
->traceset_info
->traceset_context
;
1084 void events_request_free(EventsRequest
*events_request
)
1086 if(events_request
== NULL
) return;
1088 if(events_request
->start_position
!= NULL
)
1089 lttv_traceset_context_position_destroy(events_request
->start_position
);
1090 if(events_request
->end_position
!= NULL
)
1091 lttv_traceset_context_position_destroy(events_request
->end_position
);
1092 if(events_request
->hooks
!= NULL
) {
1094 GArray
*hooks
= events_request
->hooks
;
1095 for(i
=0;i
<hooks
->len
;i
++) {
1096 lttv_trace_hook_destroy(&g_array_index(hooks
, LttvTraceHook
, i
));
1098 g_array_free(events_request
->hooks
, TRUE
);
1100 if(events_request
->before_chunk_traceset
!= NULL
)
1101 lttv_hooks_destroy(events_request
->before_chunk_traceset
);
1102 if(events_request
->before_chunk_trace
!= NULL
)
1103 lttv_hooks_destroy(events_request
->before_chunk_trace
);
1104 if(events_request
->before_chunk_tracefile
!= NULL
)
1105 lttv_hooks_destroy(events_request
->before_chunk_tracefile
);
1106 if(events_request
->event
!= NULL
)
1107 lttv_hooks_destroy(events_request
->event
);
1108 if(events_request
->event_by_id
!= NULL
)
1109 lttv_hooks_by_id_destroy(events_request
->event_by_id
);
1110 if(events_request
->after_chunk_tracefile
!= NULL
)
1111 lttv_hooks_destroy(events_request
->after_chunk_tracefile
);
1112 if(events_request
->after_chunk_trace
!= NULL
)
1113 lttv_hooks_destroy(events_request
->after_chunk_trace
);
1114 if(events_request
->after_chunk_traceset
!= NULL
)
1115 lttv_hooks_destroy(events_request
->after_chunk_traceset
);
1116 if(events_request
->before_request
!= NULL
)
1117 lttv_hooks_destroy(events_request
->before_request
);
1118 if(events_request
->after_request
!= NULL
)
1119 lttv_hooks_destroy(events_request
->after_request
);
1121 g_free(events_request
);
1125 void main_window_add_child_window(Tab
*tab
, gpointer data
,
1126 const gchar
*name
, GDestroyNotify destroy_fct
)
1128 g_object_set_data_full(G_OBJECT(tab
->mw
->mwindow
),
1134 void main_window_remove_child_window(Tab
*tab
,
1137 /* Might return NULL if called from the descructor upon main window close */
1138 g_object_steal_data(G_OBJECT(tab
->mw
->mwindow
), name
);