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;
54 gint lttvwindow_preempt_count = 0;
58 * It updates the time window of the tab, then calls the updatetimewindow
59 * hooks of each viewer.
61 * This is called whenever the scrollbar value changes.
64 void set_time_window(Tab *tab, const TimeWindow *time_window)
66 LttvAttributeValue value;
69 TimeWindowNotifyData time_window_notify_data;
70 TimeWindow old_time_window = tab->time_window;
71 time_window_notify_data.old_time_window = &old_time_window;
72 tab->time_window = *time_window;
73 time_window_notify_data.new_time_window =
76 g_assert(lttv_iattribute_find_by_path(tab->attributes,
77 "hooks/updatetimewindow", LTTV_POINTER, &value));
78 tmp = (LttvHooks*)*(value.v_pointer);
79 if(tmp != NULL) lttv_hooks_call(tmp, &time_window_notify_data);
81 //gtk_multi_vpaned_set_adjust(tab->multi_vpaned, new_time_window, FALSE);
87 * It updates the current time of the tab, then calls the updatetimewindow
88 * hooks of each viewer.
90 * This is called whenever the current time value changes.
93 void set_current_time(Tab *tab, const LttTime *current_time)
95 LttvAttributeValue value;
98 tab->current_time = *current_time;
100 g_assert(lttv_iattribute_find_by_path(tab->attributes,
101 "hooks/updatecurrenttime", LTTV_POINTER, &value));
102 tmp = (LttvHooks*)*(value.v_pointer);
103 if(tmp != NULL) lttv_hooks_call(tmp, &tab->current_time);
106 /* set_current_position
108 * It updates the current time of the tab, then calls the updatetimewindow
109 * hooks of each viewer.
111 * This is called whenever the current time value changes.
114 void set_current_position(Tab *tab, const LttvTracesetContextPosition *pos)
116 LttvAttributeValue value;
119 tab->current_time = lttv_traceset_context_position_get_time(pos);
121 g_assert(lttv_iattribute_find_by_path(tab->attributes,
122 "hooks/updatecurrentposition", LTTV_POINTER, &value));
123 tmp = (LttvHooks*)*(value.v_pointer);
124 if(tmp != NULL) lttv_hooks_call(tmp, pos);
127 void add_toolbar_constructor(MainWindow *mw, LttvToolbarClosure *toolbar_c)
129 LttvIAttribute *attributes = mw->attributes;
130 LttvAttributeValue value;
131 LttvToolbars * instance_toolbar;
132 lttvwindow_viewer_constructor constructor;
133 GtkWidget * tool_menu_title_menu, *new_widget, *pixmap;
136 g_assert(lttv_iattribute_find_by_path(attributes,
137 "viewers/toolbar", LTTV_POINTER, &value));
138 if(*(value.v_pointer) == NULL)
139 *(value.v_pointer) = lttv_toolbars_new();
140 instance_toolbar = (LttvToolbars*)*(value.v_pointer);
142 constructor = toolbar_c->con;
143 tool_menu_title_menu = lookup_widget(mw->mwindow,"MToolbar1");
144 pixbuf = gdk_pixbuf_new_from_xpm_data((const char**)toolbar_c->pixmap);
145 pixmap = gtk_image_new_from_pixbuf(pixbuf);
147 gtk_toolbar_append_element (GTK_TOOLBAR (tool_menu_title_menu),
148 GTK_TOOLBAR_CHILD_BUTTON,
151 toolbar_c->tooltip, NULL,
153 gtk_label_set_use_underline(
154 GTK_LABEL (((GtkToolbarChild*) (
155 g_list_last (GTK_TOOLBAR
156 (tool_menu_title_menu)->children)->data))->label),
158 gtk_container_set_border_width (GTK_CONTAINER (new_widget), 1);
159 g_signal_connect ((gpointer) new_widget,
161 G_CALLBACK (insert_viewer_wrap),
163 gtk_widget_show (new_widget);
165 lttv_toolbars_add(instance_toolbar, toolbar_c->con,
172 void add_menu_constructor(MainWindow *mw, LttvMenuClosure *menu_c)
174 LttvIAttribute *attributes = mw->attributes;
175 LttvAttributeValue value;
176 LttvToolbars * instance_menu;
177 lttvwindow_viewer_constructor constructor;
178 GtkWidget * tool_menu_title_menu, *new_widget;
180 g_assert(lttv_iattribute_find_by_path(attributes,
181 "viewers/menu", LTTV_POINTER, &value));
182 if(*(value.v_pointer) == NULL)
183 *(value.v_pointer) = lttv_menus_new();
184 instance_menu = (LttvMenus*)*(value.v_pointer);
187 constructor = menu_c->con;
188 tool_menu_title_menu = lookup_widget(mw->mwindow,"ToolMenuTitle_menu");
190 gtk_menu_item_new_with_mnemonic (menu_c->menu_text);
191 gtk_container_add (GTK_CONTAINER (tool_menu_title_menu),
193 g_signal_connect ((gpointer) new_widget, "activate",
194 G_CALLBACK (insert_viewer_wrap),
196 gtk_widget_show (new_widget);
197 lttv_menus_add(instance_menu, menu_c->con,
203 void remove_toolbar_constructor(MainWindow *mw, lttvwindow_viewer_constructor viewer_constructor)
205 LttvIAttribute *attributes = mw->attributes;
206 LttvAttributeValue value;
207 LttvToolbars * instance_toolbar;
208 lttvwindow_viewer_constructor constructor;
209 GtkWidget * tool_menu_title_menu, *widget;
211 g_assert(lttv_iattribute_find_by_path(attributes,
212 "viewers/toolbar", LTTV_POINTER, &value));
213 if(*(value.v_pointer) == NULL)
214 *(value.v_pointer) = lttv_toolbars_new();
215 instance_toolbar = (LttvToolbars*)*(value.v_pointer);
217 tool_menu_title_menu = lookup_widget(mw->mwindow,"MToolbar1");
218 widget = lttv_menus_remove(instance_toolbar, viewer_constructor);
219 gtk_container_remove (GTK_CONTAINER (tool_menu_title_menu),
224 void remove_menu_constructor(MainWindow *mw, lttvwindow_viewer_constructor viewer_constructor)
226 LttvIAttribute *attributes = mw->attributes;
227 LttvAttributeValue value;
228 LttvMenus * instance_menu;
229 lttvwindow_viewer_constructor constructor;
230 GtkWidget * tool_menu_title_menu, *widget;
231 LttvMenuClosure *menu_item_i;
233 g_assert(lttv_iattribute_find_by_path(attributes,
234 "viewers/menu", LTTV_POINTER, &value));
235 if(*(value.v_pointer) == NULL)
236 *(value.v_pointer) = lttv_menus_new();
237 instance_menu = (LttvMenus*)*(value.v_pointer);
239 widget = lttv_menus_remove(instance_menu, viewer_constructor);
240 tool_menu_title_menu = lookup_widget(mw->mwindow,"ToolMenuTitle_menu");
241 gtk_container_remove (GTK_CONTAINER (tool_menu_title_menu), widget);
251 * Function to register a view constructor so that main window can generate
252 * a menu item and a toolbar item for the viewer in order to generate a new
253 * instance easily. A menu entry and toolbar item will be added to each main
256 * It should be called by init function of the module.
258 * @param name name of the viewer
259 * @param menu_path path of the menu item.
260 * @param menu_text text of the menu item.
261 * @param pixmap Image shown on the toolbar item.
262 * @param tooltip tooltip of the toolbar item.
263 * @param view_constructor constructor of the viewer.
266 void lttvwindow_register_constructor
272 lttvwindow_viewer_constructor view_constructor)
274 LttvIAttribute *attributes_global = LTTV_IATTRIBUTE(lttv_global_attributes());
275 LttvToolbars * toolbar;
277 LttvToolbarClosure toolbar_c;
278 LttvMenuClosure menu_c;
279 LttvAttributeValue value;
281 if(view_constructor == NULL) return;
284 g_assert(lttv_iattribute_find_by_path(attributes_global,
285 "viewers/toolbar", LTTV_POINTER, &value));
286 toolbar = (LttvToolbars*)*(value.v_pointer);
288 if(toolbar == NULL) {
289 toolbar = lttv_toolbars_new();
290 *(value.v_pointer) = toolbar;
292 toolbar_c = lttv_toolbars_add(toolbar, view_constructor, tooltip, pixmap,
295 g_slist_foreach(g_main_window_list,
296 (gpointer)add_toolbar_constructor,
300 if(menu_path != NULL) {
301 g_assert(lttv_iattribute_find_by_path(attributes_global,
302 "viewers/menu", LTTV_POINTER, &value));
303 menu = (LttvMenus*)*(value.v_pointer);
306 menu = lttv_menus_new();
307 *(value.v_pointer) = menu;
309 menu_c = lttv_menus_add(menu, view_constructor, menu_path, menu_text,NULL);
311 g_slist_foreach(g_main_window_list,
312 (gpointer)add_menu_constructor,
316 LttvAttribute *attribute;
318 LTTV_ATTRIBUTE(lttv_iattribute_find_subdir(
319 LTTV_IATTRIBUTE(attributes_global),
320 LTTV_VIEWER_CONSTRUCTORS)));
322 g_assert(lttv_iattribute_find_by_path(LTTV_IATTRIBUTE(attribute),
323 name, LTTV_POINTER, &value));
325 *(value.v_pointer) = view_constructor;
332 * Function to unregister the viewer's constructor, release the space
333 * occupied by menu_path, menu_text, pixmap, tooltip and constructor of the
336 * It will be called when a module is unloaded.
338 * @param view_constructor constructor of the viewer.
342 void lttvwindow_unregister_constructor
343 (lttvwindow_viewer_constructor view_constructor)
345 LttvIAttribute *attributes_global = LTTV_IATTRIBUTE(lttv_global_attributes());
346 LttvToolbars * toolbar;
348 LttvAttributeValue value;
351 g_assert(lttv_iattribute_find_by_path(attributes_global,
352 "viewers/toolbar", LTTV_POINTER, &value));
353 toolbar = (LttvToolbars*)*(value.v_pointer);
355 if(toolbar != NULL) {
356 g_slist_foreach(g_main_window_list,
357 (gpointer)remove_toolbar_constructor,
359 lttv_toolbars_remove(toolbar, view_constructor);
362 g_assert(lttv_iattribute_find_by_path(attributes_global,
363 "viewers/menu", LTTV_POINTER, &value));
364 menu = (LttvMenus*)*(value.v_pointer);
367 g_slist_foreach(g_main_window_list,
368 (gpointer)remove_menu_constructor,
370 lttv_menus_remove(menu, view_constructor);
374 LttvAttribute *attribute;
376 LTTV_ATTRIBUTE(lttv_iattribute_find_subdir(
377 LTTV_IATTRIBUTE(attributes_global),
378 LTTV_VIEWER_CONSTRUCTORS)));
380 guint num = lttv_iattribute_get_number(LTTV_IATTRIBUTE(attribute));
382 LttvAttributeName name;
383 LttvAttributeValue value;
384 LttvAttributeType type;
387 type = lttv_iattribute_get(LTTV_IATTRIBUTE(attribute), i, &name, &value,
389 g_assert(type == LTTV_POINTER);
390 if(*(value.v_pointer) == view_constructor) {
391 lttv_iattribute_remove(LTTV_IATTRIBUTE(attribute), i);
400 * Function to register a hook function for a viewer to set/update its
402 * @param tab viewer's tab
403 * @param hook hook function of the viewer.
404 * @param hook_data hook data associated with the hook function.
406 void lttvwindow_register_time_window_notify(Tab *tab,
407 LttvHook hook, gpointer hook_data)
409 LttvAttributeValue value;
411 g_assert(lttv_iattribute_find_by_path(tab->attributes,
412 "hooks/updatetimewindow", LTTV_POINTER, &value));
413 tmp = (LttvHooks*)*(value.v_pointer);
415 tmp = lttv_hooks_new();
416 *(value.v_pointer) = tmp;
418 lttv_hooks_add(tmp, hook,hook_data, LTTV_PRIO_DEFAULT);
423 * Function to unregister a viewer's hook function which is used to
424 * set/update the time interval of the viewer.
425 * @param tab viewer's tab
426 * @param hook hook function of the viewer.
427 * @param hook_data hook data associated with the hook function.
430 void lttvwindow_unregister_time_window_notify(Tab *tab,
431 LttvHook hook, gpointer hook_data)
433 LttvAttributeValue value;
435 g_assert(lttv_iattribute_find_by_path(tab->attributes,
436 "hooks/updatetimewindow", LTTV_POINTER, &value));
437 tmp = (LttvHooks*)*(value.v_pointer);
438 if(tmp == NULL) return;
439 lttv_hooks_remove_data(tmp, hook, hook_data);
443 * Function to register a hook function for a viewer to set/update its
445 * @param tab viewer's tab
446 * @param hook hook function of the viewer.
447 * @param hook_data hook data associated with the hook function.
450 void lttvwindow_register_traceset_notify(Tab *tab,
451 LttvHook hook, gpointer hook_data)
453 LttvAttributeValue value;
455 g_assert(lttv_iattribute_find_by_path(tab->attributes,
456 "hooks/updatetraceset", LTTV_POINTER, &value));
457 tmp = (LttvHooks*)*(value.v_pointer);
459 tmp = lttv_hooks_new();
460 *(value.v_pointer) = tmp;
462 lttv_hooks_add(tmp, hook, hook_data, LTTV_PRIO_DEFAULT);
467 * Function to unregister a viewer's hook function which is used to
468 * set/update the traceset of the viewer.
469 * @param tab viewer's tab
470 * @param hook hook function of the viewer.
471 * @param hook_data hook data associated with the hook function.
474 void lttvwindow_unregister_traceset_notify(Tab *tab,
475 LttvHook hook, gpointer hook_data)
477 LttvAttributeValue value;
479 g_assert(lttv_iattribute_find_by_path(tab->attributes,
480 "hooks/updatetraceset", LTTV_POINTER, &value));
481 tmp = (LttvHooks*)*(value.v_pointer);
482 if(tmp == NULL) return;
483 lttv_hooks_remove_data(tmp, hook, hook_data);
487 * Function to register a hook function for a viewer be completely redrawn.
489 * @param tab viewer's tab
490 * @param hook hook function of the viewer.
491 * @param hook_data hook data associated with the hook function.
494 void lttvwindow_register_redraw_notify(Tab *tab,
495 LttvHook hook, gpointer hook_data)
497 LttvAttributeValue value;
499 g_assert(lttv_iattribute_find_by_path(tab->attributes,
500 "hooks/redraw", LTTV_POINTER, &value));
501 tmp = (LttvHooks*)*(value.v_pointer);
503 tmp = lttv_hooks_new();
504 *(value.v_pointer) = tmp;
506 lttv_hooks_add(tmp, hook, hook_data, LTTV_PRIO_DEFAULT);
511 * Function to unregister a hook function for a viewer be completely redrawn.
513 * @param tab viewer's tab
514 * @param hook hook function of the viewer.
515 * @param hook_data hook data associated with the hook function.
518 void lttvwindow_unregister_redraw_notify(Tab *tab,
519 LttvHook hook, gpointer hook_data)
521 LttvAttributeValue value;
523 g_assert(lttv_iattribute_find_by_path(tab->attributes,
524 "hooks/redraw", LTTV_POINTER, &value));
525 tmp = (LttvHooks*)*(value.v_pointer);
526 if(tmp == NULL) return;
527 lttv_hooks_remove_data(tmp, hook, hook_data);
531 * Function to register a hook function for a viewer to re-do the events
532 * requests for the needed interval.
534 * This action is typically done after a "stop".
536 * The typical hook will remove all current requests for the viewer
537 * and make requests for missing information.
539 * @param tab viewer's tab
540 * @param hook hook function of the viewer.
541 * @param hook_data hook data associated with the hook function.
544 void lttvwindow_register_continue_notify(Tab *tab,
545 LttvHook hook, gpointer hook_data)
547 LttvAttributeValue value;
549 g_assert(lttv_iattribute_find_by_path(tab->attributes,
550 "hooks/continue", LTTV_POINTER, &value));
551 tmp = (LttvHooks*)*(value.v_pointer);
553 tmp = lttv_hooks_new();
554 *(value.v_pointer) = tmp;
556 lttv_hooks_add(tmp, hook, hook_data, LTTV_PRIO_DEFAULT);
561 * Function to unregister a hook function for a viewer to re-do the events
562 * requests for the needed interval.
564 * @param tab viewer's tab
565 * @param hook hook function of the viewer.
566 * @param hook_data hook data associated with the hook function.
569 void lttvwindow_unregister_continue_notify(Tab *tab,
570 LttvHook hook, gpointer hook_data)
572 LttvAttributeValue value;
574 g_assert(lttv_iattribute_find_by_path(tab->attributes,
575 "hooks/continue", LTTV_POINTER, &value));
576 tmp = (LttvHooks*)*(value.v_pointer);
577 if(tmp == NULL) return;
578 lttv_hooks_remove_data(tmp, hook, hook_data);
583 * Function to register a hook function for a viewer to set/update its
585 * @param tab viewer's tab
586 * @param hook hook function of the viewer.
587 * @param hook_data hook data associated with the hook function.
590 void lttvwindow_register_filter_notify(Tab *tab,
591 LttvHook hook, gpointer hook_data)
593 LttvAttributeValue value;
595 g_assert(lttv_iattribute_find_by_path(tab->attributes,
596 "hooks/updatefilter", LTTV_POINTER, &value));
597 tmp = (LttvHooks*)*(value.v_pointer);
599 tmp = lttv_hooks_new();
600 *(value.v_pointer) = tmp;
602 lttv_hooks_add(tmp, hook, hook_data, LTTV_PRIO_DEFAULT);
607 * Function to unregister a viewer's hook function which is used to
608 * set/update the filter of the viewer.
609 * @param tab viewer's tab
610 * @param hook hook function of the viewer.
611 * @param hook_data hook data associated with the hook function.
614 void lttvwindow_unregister_filter_notify(Tab *tab,
618 LttvAttributeValue value;
620 g_assert(lttv_iattribute_find_by_path(tab->attributes,
621 "hooks/updatefilter", LTTV_POINTER, &value));
622 tmp = (LttvHooks*)*(value.v_pointer);
623 if(tmp == NULL) return;
624 lttv_hooks_remove_data(tmp, hook, hook_data);
628 * function to register a hook function for a viewer to set/update its
630 * @param tab viewer's tab
631 * @param hook hook function of the viewer.
632 * @param hook_data hook data associated with the hook function.
635 void lttvwindow_register_current_time_notify(Tab *tab,
636 LttvHook hook, gpointer hook_data)
638 LttvAttributeValue value;
640 g_assert(lttv_iattribute_find_by_path(tab->attributes,
641 "hooks/updatecurrenttime", LTTV_POINTER, &value));
642 tmp = (LttvHooks*)*(value.v_pointer);
644 tmp = lttv_hooks_new();
645 *(value.v_pointer) = tmp;
647 lttv_hooks_add(tmp, hook, hook_data, LTTV_PRIO_DEFAULT);
652 * function to unregister a viewer's hook function which is used to
653 * set/update the current time of the viewer.
654 * @param tab viewer's tab
655 * @param hook hook function of the viewer.
656 * @param hook_data hook data associated with the hook function.
659 void lttvwindow_unregister_current_time_notify(Tab *tab,
660 LttvHook hook, gpointer hook_data)
662 LttvAttributeValue value;
664 g_assert(lttv_iattribute_find_by_path(tab->attributes,
665 "hooks/updatecurrenttime", LTTV_POINTER, &value));
666 tmp = (LttvHooks*)*(value.v_pointer);
667 if(tmp == NULL) return;
668 lttv_hooks_remove_data(tmp, hook, hook_data);
672 * function to register a hook function for a viewer to set/update its
674 * @param tab viewer's tab
675 * @param hook hook function of the viewer.
676 * @param hook_data hook data associated with the hook function.
679 void lttvwindow_register_current_position_notify(Tab *tab,
680 LttvHook hook, gpointer hook_data)
682 LttvAttributeValue value;
684 g_assert(lttv_iattribute_find_by_path(tab->attributes,
685 "hooks/updatecurrentposition", LTTV_POINTER, &value));
686 tmp = (LttvHooks*)*(value.v_pointer);
688 tmp = lttv_hooks_new();
689 *(value.v_pointer) = tmp;
691 lttv_hooks_add(tmp, hook, hook_data, LTTV_PRIO_DEFAULT);
696 * function to unregister a viewer's hook function which is used to
697 * set/update the current position of the viewer.
698 * @param tab viewer's tab
699 * @param hook hook function of the viewer.
700 * @param hook_data hook data associated with the hook function.
703 void lttvwindow_unregister_current_position_notify(Tab *tab,
704 LttvHook hook, gpointer hook_data)
706 LttvAttributeValue value;
708 g_assert(lttv_iattribute_find_by_path(tab->attributes,
709 "hooks/updatecurrentposition", LTTV_POINTER, &value));
710 tmp = (LttvHooks*)*(value.v_pointer);
711 if(tmp == NULL) return;
712 lttv_hooks_remove_data(tmp, hook, hook_data);
717 * Function to register a hook function for a viewer to show
718 * the content of the viewer.
719 * @param tab viewer's tab
720 * @param hook hook function of the viewer.
721 * @param hook_data hook data associated with the hook function.
724 void lttvwindow_register_show_notify(Tab *tab,
725 LttvHook hook, gpointer hook_data)
727 LttvAttributeValue value;
729 g_assert(lttv_iattribute_find_by_path(tab->attributes,
730 "hooks/showviewer", LTTV_POINTER, &value));
731 tmp = (LttvHooks*)*(value.v_pointer);
733 tmp = lttv_hooks_new();
734 *(value.v_pointer) = tmp;
736 lttv_hooks_add(tmp, hook, hook_data, LTTV_PRIO_DEFAULT);
741 * Function to unregister a viewer's hook function which is used to
742 * show the content of the viewer..
743 * @param tab viewer's tab
744 * @param hook hook function of the viewer.
745 * @param hook_data hook data associated with the hook function.
748 void lttvwindow_unregister_show_notify(Tab *tab,
749 LttvHook hook, gpointer hook_data)
751 LttvAttributeValue value;
753 g_assert(lttv_iattribute_find_by_path(tab->attributes,
754 "hooks/showviewer", LTTV_POINTER, &value));
755 tmp = (LttvHooks*)*(value.v_pointer);
756 if(tmp == NULL) return;
757 lttv_hooks_remove_data(tmp, hook, hook_data);
761 * Function to register a hook function for a viewer to set/update the
762 * dividor of the hpane.
763 * @param tab viewer's tab
764 * @param hook hook function of the viewer.
765 * @param hook_data hook data associated with the hook function.
768 void lttvwindow_register_dividor(Tab *tab,
769 LttvHook hook, gpointer hook_data)
771 LttvAttributeValue value;
773 g_assert(lttv_iattribute_find_by_path(tab->attributes,
774 "hooks/hpanedividor", LTTV_POINTER, &value));
775 tmp = (LttvHooks*)*(value.v_pointer);
777 tmp = lttv_hooks_new();
778 *(value.v_pointer) = tmp;
780 lttv_hooks_add(tmp, hook, hook_data, LTTV_PRIO_DEFAULT);
785 * Function to unregister a viewer's hook function which is used to
786 * set/update hpane's dividor of the viewer.
787 * It will be called by the destructor of the viewer.
788 * @param tab viewer's tab
789 * @param hook hook function of the viewer.
790 * @param hook_data hook data associated with the hook function.
793 void lttvwindow_unregister_dividor(Tab *tab,
794 LttvHook hook, gpointer hook_data)
796 LttvAttributeValue value;
798 g_assert(lttv_iattribute_find_by_path(tab->attributes,
799 "hooks/hpanedividor", LTTV_POINTER, &value));
800 tmp = (LttvHooks*)*(value.v_pointer);
801 if(tmp == NULL) return;
802 lttv_hooks_remove_data(tmp, hook, hook_data);
807 * Function to set the time interval of the current tab.
808 * It will be called by a viewer's signal handle associated with
809 * the move_slider signal
810 * @param tab viewer's tab
811 * @param time_interval a pointer where time interval is stored.
814 void lttvwindow_report_time_window(Tab *tab,
815 TimeWindow time_window)
817 //set_time_window(tab, time_window);
818 //set_time_window_adjustment(tab, time_window);
820 time_change_manager(tab, time_window);
825 LttvTracesetContext *tsc =
826 LTTV_TRACESET_CONTEXT(tab->traceset_info->traceset_context);
827 TimeInterval time_span = tsc->time_span;
828 GtkAdjustment *adjustment = gtk_range_get_adjustment(GTK_RANGE(tab->scrollbar));
829 g_object_set(G_OBJECT(adjustment),
834 ltt_time_sub(time_span.end_time, time_span.start_time))
837 ltt_time_to_double(time_window->time_width)
838 / SCROLL_STEP_PER_PAGE
839 , /* step increment */
841 ltt_time_to_double(time_window->time_width)
842 , /* page increment */
844 ltt_time_to_double(time_window->time_width)
847 gtk_adjustment_changed(adjustment);
849 //g_object_set(G_OBJECT(adjustment),
851 // ltt_time_to_double(time_window->start_time)
854 /* Note : the set value will call set_time_window if scrollbar value changed
856 gtk_adjustment_set_value(adjustment,
858 ltt_time_sub(time_window->start_time,
859 time_span.start_time))
866 * Function to set the current time of the current tab.
867 * It will be called by a viewer's signal handle associated with
868 * the button-release-event signal
869 * @param tab viewer's tab
870 * @param time a pointer where time is stored.
873 void lttvwindow_report_current_time(Tab *tab,
876 LttvAttributeValue value;
879 current_time_change_manager(tab, time);
883 * Function to set the current event of the current tab.
884 * It will be called by a viewer's signal handle associated with
885 * the button-release-event signal
886 * @param tab viewer's tab
887 * @param time a pointer where time is stored.
890 void lttvwindow_report_current_position(Tab *tab,
891 LttvTracesetContextPosition *pos)
893 LttvAttributeValue value;
896 current_position_change_manager(tab, pos);
901 * Function to set the position of the hpane's dividor (viewer).
902 * It will be called by a viewer's signal handle associated with
903 * the motion_notify_event event/signal
904 * @param tab viewer's tab
905 * @param position position of the hpane's dividor.
908 void lttvwindow_report_dividor(Tab *tab, gint position)
910 LttvAttributeValue value;
912 g_assert(lttv_iattribute_find_by_path(tab->attributes,
913 "hooks/hpanedividor", LTTV_POINTER, &value));
914 tmp = (LttvHooks*)*(value.v_pointer);
915 if(tmp == NULL) return;
916 lttv_hooks_call(tmp, &position);
920 * Function to request data in a specific time interval to the main window. The
921 * event request servicing is differed until the glib idle functions are
924 * The viewer has to provide hooks that should be associated with the event
927 * Either start time or start position must be defined in a EventRequest
928 * structure for it to be valid.
930 * end_time, end_position and num_events can all be defined. The first one
931 * to occur will be used as end criterion.
933 * @param tab viewer's tab
934 * @param events_requested the structure of request from.
937 void lttvwindow_events_request(Tab *tab,
938 EventsRequest *events_request)
940 tab->events_requests = g_slist_append(tab->events_requests, events_request);
942 if(!tab->events_request_pending)
944 /* Redraw has +20 priority. We want to let the redraw be done while we do
945 * our job. Mathieu : test with high prio higher than events for better
947 //g_idle_add_full((G_PRIORITY_HIGH_IDLE + 21),
948 g_idle_add_full((G_PRIORITY_DEFAULT + 2),
949 (GSourceFunc)execute_events_requests,
952 tab->events_request_pending = TRUE;
958 * Function to remove data requests related to a viewer.
960 * The existing requests's viewer gpointer is compared to the pointer
961 * given in argument to establish which data request should be removed.
963 * @param tab the tab the viewer belongs to.
964 * @param viewer a pointer to the viewer data structure
967 gint find_viewer (const EventsRequest *a, gconstpointer b)
969 return (a->owner != b);
973 void lttvwindow_events_request_remove_all(Tab *tab,
974 gconstpointer viewer)
976 GSList *element = tab->events_requests;
979 g_slist_find_custom(element, viewer,
980 (GCompareFunc)find_viewer))
982 EventsRequest *events_request = (EventsRequest *)element->data;
983 // Modified so a viewer being destroyed won't have its after_request
984 // called. Not so important anyway. Note that a viewer that call this
985 // remove_all function will not get its after_request called.
986 //if(events_request->servicing == TRUE) {
987 // lttv_hooks_call(events_request->after_request, NULL);
989 events_request_free(events_request);
990 //g_free(events_request);
991 tab->events_requests = g_slist_remove_link(tab->events_requests, element);
992 element = g_slist_next(element);
993 if(element == NULL) break; /* end of list */
995 if(g_slist_length(tab->events_requests) == 0) {
996 tab->events_request_pending = FALSE;
997 g_idle_remove_by_data(tab);
1004 * Function to see if there are events request pending.
1006 * It tells if events requests are pending. Useful for checks in some events,
1007 * i.e. detailed event list scrolling.
1009 * @param tab the tab the viewer belongs to.
1010 * @param viewer a pointer to the viewer data structure
1011 * @return : TRUE is events requests are pending, else FALSE.
1014 gboolean lttvwindow_events_request_pending(Tab *tab)
1016 GSList *element = tab->events_requests;
1018 if(element == NULL) return FALSE;
1024 * Function to get the current time interval shown on the current tab.
1025 * It will be called by a viewer's hook function to update the
1026 * shown time interval of the viewer and also be called by the constructor
1028 * @param tab viewer's tab
1029 * @return time window.
1032 TimeWindow lttvwindow_get_time_window(Tab *tab)
1034 return tab->time_window;
1039 * Function to get the current time/event of the current tab.
1040 * It will be called by a viewer's hook function to update the
1041 * current time/event of the viewer.
1042 * @param tab viewer's tab
1046 LttTime lttvwindow_get_current_time(Tab *tab)
1048 return tab->current_time;
1053 * Function to get the filter of the current tab.
1054 * @param filter, a pointer to a filter.
1056 * returns the current filter
1058 LttvFilter *lttvwindow_get_filter(Tab *tab)
1060 return g_object_get_data(G_OBJECT(tab->vbox), "filter");
1064 * Function to set the filter of the current tab.
1065 * It should be called by the filter GUI to tell the
1066 * main window to update the filter tab's lttv_filter.
1068 * This function does change the current filter, removing the
1069 * old one when necessary, and call the updatefilter hooks
1070 * of the registered viewers.
1072 * @param main_win, the main window the viewer belongs to.
1073 * @param filter, a pointer to a filter.
1075 void lttvwindow_report_filter(Tab *tab, LttvFilter *filter)
1077 LttvAttributeValue value;
1080 //lttv_filter_destroy(tab->filter);
1081 //tab->filter = filter;
1083 g_assert(lttv_iattribute_find_by_path(tab->attributes,
1084 "hooks/updatefilter", LTTV_POINTER, &value));
1085 tmp = (LttvHooks*)*(value.v_pointer);
1086 if(tmp == NULL) return;
1087 lttv_hooks_call(tmp, filter);
1093 * Function to get the stats of the traceset
1094 * @param tab viewer's tab
1097 LttvTracesetStats* lttvwindow_get_traceset_stats(Tab *tab)
1099 return tab->traceset_info->traceset_context;
1103 LttvTracesetContext* lttvwindow_get_traceset_context(Tab *tab)
1105 return (LttvTracesetContext*)tab->traceset_info->traceset_context;
1109 void events_request_free(EventsRequest *events_request)
1111 if(events_request == NULL) return;
1113 if(events_request->start_position != NULL)
1114 lttv_traceset_context_position_destroy(events_request->start_position);
1115 if(events_request->end_position != NULL)
1116 lttv_traceset_context_position_destroy(events_request->end_position);
1117 if(events_request->hooks != NULL) {
1119 GArray *hooks = events_request->hooks;
1120 for(i=0;i<hooks->len;i++) {
1121 lttv_trace_hook_destroy(&g_array_index(hooks, LttvTraceHook, i));
1123 g_array_free(events_request->hooks, TRUE);
1125 if(events_request->before_chunk_traceset != NULL)
1126 lttv_hooks_destroy(events_request->before_chunk_traceset);
1127 if(events_request->before_chunk_trace != NULL)
1128 lttv_hooks_destroy(events_request->before_chunk_trace);
1129 if(events_request->before_chunk_tracefile != NULL)
1130 lttv_hooks_destroy(events_request->before_chunk_tracefile);
1131 if(events_request->event != NULL)
1132 lttv_hooks_destroy(events_request->event);
1133 if(events_request->event_by_id != NULL)
1134 lttv_hooks_by_id_destroy(events_request->event_by_id);
1135 if(events_request->after_chunk_tracefile != NULL)
1136 lttv_hooks_destroy(events_request->after_chunk_tracefile);
1137 if(events_request->after_chunk_trace != NULL)
1138 lttv_hooks_destroy(events_request->after_chunk_trace);
1139 if(events_request->after_chunk_traceset != NULL)
1140 lttv_hooks_destroy(events_request->after_chunk_traceset);
1141 if(events_request->before_request != NULL)
1142 lttv_hooks_destroy(events_request->before_request);
1143 if(events_request->after_request != NULL)
1144 lttv_hooks_destroy(events_request->after_request);
1146 g_free(events_request);
1151 GtkWidget *main_window_get_widget(Tab *tab)
1153 return tab->mw->mwindow;