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 lttvviewer.c
20 * \brief API used by the graphical viewers to interact with their top window.
22 * Main window (gui module) is the place to contain and display viewers.
23 * Viewers (lttv plugins) interacte with main window through this API and
25 * This header file should be included in each graphic module.
26 * This library is used by graphical modules to interact with the
31 #include <lttvwindow/common.h>
33 #include <lttv/lttv.h>
34 #include <lttvwindow/mainwindow.h>
35 #include <lttvwindow/viewer.h>
36 #include <lttv/tracecontext.h>
37 #include <lttvwindow/toolbar.h>
38 #include <lttvwindow/menu.h>
39 #include <lttv/state.h>
40 #include <lttv/stats.h>
44 * Internal function parts
48 * Function to set/update traceset for the viewers
49 * @param main_win main window
50 * @param traceset traceset of the main window.
53 * 0 : traceset updated
54 * 1 : no traceset hooks to update; not an error.
57 int SetTraceset(MainWindow
* main_win
, gpointer traceset
)
60 LttvAttributeValue value
;
62 if( lttv_iattribute_find_by_path(main_win
->attributes
,
63 "hooks/updatetraceset", LTTV_POINTER
, &value
) != 0)
66 tmp
= (LttvHooks
*)*(value
.v_pointer
);
67 if(tmp
== NULL
) return 1;
69 lttv_hooks_call(tmp
,traceset
);
76 * Function to set/update filter for the viewers
77 * @param main_win main window
78 * @param filter filter of the main window.
82 * 1 : no filter hooks to update; not an error.
85 int SetFilter(MainWindow
* main_win
, gpointer filter
)
88 LttvAttributeValue value
;
90 if(lttv_iattribute_find_by_path(main_win
->attributes
,
91 "hooks/updatefilter", LTTV_POINTER
, &value
) != 0)
94 tmp
= (LttvHooks
*)*(value
.v_pointer
);
96 if(tmp
== NULL
) return 1;
97 lttv_hooks_call(tmp
,filter
);
103 * Function to redraw each viewer belonging to the current tab
104 * @param main_win the main window the viewer belongs to.
107 void update_traceset(MainWindow
* main_win
)
109 LttvAttributeValue value
;
111 g_assert(lttv_iattribute_find_by_path(main_win
->current_tab
->attributes
,
112 "hooks/updatetraceset", LTTV_POINTER
, &value
));
113 tmp
= (LttvHooks
*)*(value
.v_pointer
);
114 if(tmp
== NULL
) return;
115 lttv_hooks_call(tmp
, NULL
);
121 * Function to show each viewer in the current tab.
122 * It will be called by main window after it called process_traceset
123 * @param main_win the main window the viewer belongs to.
126 void show_viewer(MainWindow
*main_win
)
128 LttvAttributeValue value
;
130 g_assert(lttv_iattribute_find_by_path(main_win
->current_tab
->attributes
,
131 "hooks/showviewer", LTTV_POINTER
, &value
));
132 tmp
= (LttvHooks
*)*(value
.v_pointer
);
133 if(tmp
== NULL
) return;
134 lttv_hooks_call(tmp
, NULL
);
145 * Function to register a view constructor so that main window can generate
146 * a toolbar item for the viewer in order to generate a new instance easily.
147 * It will be called by init function of the module.
148 * @param ButtonPixmap image shown on the toolbar item.
149 * @param tooltip tooltip of the toolbar item.
150 * @param view_constructor constructor of the viewer.
153 void lttvwindow_register_toolbar(char ** pixmap
, char *tooltip
, lttvwindow_viewer_constructor view_constructor
)
155 LttvIAttribute
*attributes_global
= LTTV_IATTRIBUTE(lttv_global_attributes());
156 LttvToolbars
* toolbar
;
157 LttvAttributeValue value
;
159 g_assert(lttv_iattribute_find_by_path(attributes_global
,
160 "viewers/toolbar", LTTV_POINTER
, &value
));
161 toolbar
= (LttvToolbars
*)*(value
.v_pointer
);
164 toolbar
= lttv_toolbars_new();
165 *(value
.v_pointer
) = toolbar
;
167 lttv_toolbars_add(toolbar
, view_constructor
, tooltip
, pixmap
);
172 * Function to unregister the viewer's constructor, release the space
173 * occupied by pixmap, tooltip and constructor of the viewer.
174 * It will be called when a module is unloaded.
175 * @param view_constructor constructor of the viewer which is used as
176 * a reference to find out where the pixmap and tooltip are.
179 void lttvwindow_unregister_toolbar(lttvwindow_viewer_constructor view_constructor
)
181 LttvIAttribute
*attributes_global
= LTTV_IATTRIBUTE(lttv_global_attributes());
182 LttvToolbars
* toolbar
;
183 LttvAttributeValue value
;
185 g_assert(lttv_iattribute_find_by_path(attributes_global
,
186 "viewers/toolbar", LTTV_POINTER
, &value
));
187 toolbar
= (LttvToolbars
*)*(value
.v_pointer
);
189 main_window_remove_toolbar_item(view_constructor
);
191 lttv_toolbars_remove(toolbar
, view_constructor
);
196 * Function to register a view constructor so that main window can generate
197 * a menu item for the viewer in order to generate a new instance easily.
198 * It will be called by init function of the module.
199 * @param menu_path path of the menu item.
200 * @param menu_text text of the menu item.
201 * @param view_constructor constructor of the viewer.
204 void lttvwindow_register_menu(char *menu_path
, char *menu_text
, lttvwindow_viewer_constructor view_constructor
)
206 LttvIAttribute
*attributes_global
= LTTV_IATTRIBUTE(lttv_global_attributes());
208 LttvAttributeValue value
;
210 g_assert(lttv_iattribute_find_by_path(attributes_global
,
211 "viewers/menu", LTTV_POINTER
, &value
));
212 menu
= (LttvMenus
*)*(value
.v_pointer
);
215 menu
= lttv_menus_new();
216 *(value
.v_pointer
) = menu
;
218 lttv_menus_add(menu
, view_constructor
, menu_path
, menu_text
);
222 * Function to unregister the viewer's constructor, release the space
223 * occupied by menu_path, menu_text and constructor of the viewer.
224 * It will be called when a module is unloaded.
225 * @param view_constructor constructor of the viewer which is used as
226 * a reference to find out where the menu_path and menu_text are.
229 void lttvwindow_unregister_menu(lttvwindow_viewer_constructor view_constructor
)
231 LttvIAttribute
*attributes_global
= LTTV_IATTRIBUTE(lttv_global_attributes());
233 LttvAttributeValue value
;
235 g_assert(lttv_iattribute_find_by_path(attributes_global
,
236 "viewers/menu", LTTV_POINTER
, &value
));
237 menu
= (LttvMenus
*)*(value
.v_pointer
);
239 main_window_remove_menu_item(view_constructor
);
241 lttv_menus_remove(menu
, view_constructor
);
245 * Function to register a hook function for a viewer to set/update its
247 * @param hook hook function of the viewer.
248 * @param hook_data hook data associated with the hook function.
249 * @param main_win the main window the viewer belongs to.
251 void lttvwindow_register_time_window_notify(MainWindow
* main_win
,
252 LttvHook hook
, gpointer hook_data
)
254 LttvAttributeValue value
;
256 g_assert(lttv_iattribute_find_by_path(main_win
->current_tab
->attributes
,
257 "hooks/updatetimewindow", LTTV_POINTER
, &value
));
258 tmp
= (LttvHooks
*)*(value
.v_pointer
);
260 tmp
= lttv_hooks_new();
261 *(value
.v_pointer
) = tmp
;
263 lttv_hooks_add(tmp
, hook
,hook_data
);
268 * Function to unregister a viewer's hook function which is used to
269 * set/update the time interval of the viewer.
270 * @param hook hook function of the viewer.
271 * @param hook_data hook data associated with the hook function.
272 * @param main_win the main window the viewer belongs to.
275 void lttvwindow_unregister_time_window_notify(MainWindow
* main_win
,
276 LttvHook hook
, gpointer hook_data
)
278 LttvAttributeValue value
;
280 g_assert(lttv_iattribute_find_by_path(main_win
->current_tab
->attributes
,
281 "hooks/updatetimewindow", LTTV_POINTER
, &value
));
282 tmp
= (LttvHooks
*)*(value
.v_pointer
);
283 if(tmp
== NULL
) return;
284 lttv_hooks_remove_data(tmp
, hook
, hook_data
);
288 * Function to register a hook function for a viewer to set/update its
290 * @param hook hook function of the viewer.
291 * @param hook_data hook data associated with the hook function.
292 * @param main_win the main window the viewer belongs to.
295 void lttvwindow_register_traceset_notify(MainWindow
* main_win
,
296 LttvHook hook
, gpointer hook_data
)
298 LttvAttributeValue value
;
300 g_assert(lttv_iattribute_find_by_path(main_win
->current_tab
->attributes
,
301 "hooks/updatetraceset", LTTV_POINTER
, &value
));
302 tmp
= (LttvHooks
*)*(value
.v_pointer
);
304 tmp
= lttv_hooks_new();
305 *(value
.v_pointer
) = tmp
;
307 lttv_hooks_add(tmp
, hook
, hook_data
);
312 * Function to unregister a viewer's hook function which is used to
313 * set/update the traceset of the viewer.
314 * @param hook hook function of the viewer.
315 * @param hook_data hook data associated with the hook function.
316 * @param main_win the main window the viewer belongs to.
319 void lttvwindow_unregister_traceset_notify(MainWindow
* main_win
,
320 LttvHook hook
, gpointer hook_data
)
322 LttvAttributeValue value
;
324 g_assert(lttv_iattribute_find_by_path(main_win
->current_tab
->attributes
,
325 "hooks/updatetraceset", LTTV_POINTER
, &value
));
326 tmp
= (LttvHooks
*)*(value
.v_pointer
);
327 if(tmp
== NULL
) return;
328 lttv_hooks_remove_data(tmp
, hook
, hook_data
);
332 * Function to register a hook function for a viewer to set/update its
334 * @param hook hook function of the viewer.
335 * @param hook_data hook data associated with the hook function.
336 * @param main_win the main window the viewer belongs to.
339 void lttvwindow_register_filter_notify(MainWindow
*main_win
,
340 LttvHook hook
, gpointer hook_data
)
342 LttvAttributeValue value
;
344 g_assert(lttv_iattribute_find_by_path(main_win
->attributes
,
345 "hooks/updatefilter", LTTV_POINTER
, &value
));
346 tmp
= (LttvHooks
*)*(value
.v_pointer
);
348 tmp
= lttv_hooks_new();
349 *(value
.v_pointer
) = tmp
;
351 lttv_hooks_add(tmp
, hook
, hook_data
);
356 * Function to unregister a viewer's hook function which is used to
357 * set/update the filter of the viewer.
358 * @param hook hook function of the viewer.
359 * @param hook_data hook data associated with the hook function.
360 * @param main_win the main window the viewer belongs to.
363 void lttvwindow_unregister_filter_notify(LttvHook hook
, gpointer hook_data
,
364 MainWindow
* main_win
)
366 LttvAttributeValue value
;
368 g_assert(lttv_iattribute_find_by_path(main_win
->attributes
,
369 "hooks/updatefilter", LTTV_POINTER
, &value
));
370 tmp
= (LttvHooks
*)*(value
.v_pointer
);
371 if(tmp
== NULL
) return;
372 lttv_hooks_remove_data(tmp
, hook
, hook_data
);
377 * Function to register a hook function for a viewer to set/update its
379 * @param hook hook function of the viewer.
380 * @param hook_data hook data associated with the hook function.
381 * @param main_win the main window the viewer belongs to.
384 void lttvwindow_register_current_time_notify(MainWindow
*main_win
,
385 LttvHook hook
, gpointer hook_data
)
387 LttvAttributeValue value
;
389 g_assert(lttv_iattribute_find_by_path(main_win
->current_tab
->attributes
,
390 "hooks/updatecurrenttime", LTTV_POINTER
, &value
));
391 tmp
= (LttvHooks
*)*(value
.v_pointer
);
393 tmp
= lttv_hooks_new();
394 *(value
.v_pointer
) = tmp
;
396 lttv_hooks_add(tmp
, hook
, hook_data
);
401 * Function to unregister a viewer's hook function which is used to
402 * set/update the current time of the viewer.
403 * @param hook hook function of the viewer.
404 * @param hook_data hook data associated with the hook function.
405 * @param main_win the main window the viewer belongs to.
408 void lttvwindow_unregister_current_time_notify(MainWindow
* main_win
,
409 LttvHook hook
, gpointer hook_data
)
411 LttvAttributeValue value
;
413 g_assert(lttv_iattribute_find_by_path(main_win
->current_tab
->attributes
,
414 "hooks/updatecurrenttime", LTTV_POINTER
, &value
));
415 tmp
= (LttvHooks
*)*(value
.v_pointer
);
416 if(tmp
== NULL
) return;
417 lttv_hooks_remove_data(tmp
, hook
, hook_data
);
422 * Function to register a hook function for a viewer to show
423 * the content of the viewer.
424 * @param hook hook function of the viewer.
425 * @param hook_data hook data associated with the hook function.
426 * @param main_win the main window the viewer belongs to.
429 void lttvwindow_register_show(MainWindow
*main_win
,
430 LttvHook hook
, gpointer hook_data
)
432 LttvAttributeValue value
;
434 g_assert(lttv_iattribute_find_by_path(main_win
->current_tab
->attributes
,
435 "hooks/showviewer", LTTV_POINTER
, &value
));
436 tmp
= (LttvHooks
*)*(value
.v_pointer
);
438 tmp
= lttv_hooks_new();
439 *(value
.v_pointer
) = tmp
;
441 lttv_hooks_add(tmp
, hook
, hook_data
);
446 * Function to unregister a viewer's hook function which is used to
447 * show the content of the viewer..
448 * @param hook hook function of the viewer.
449 * @param hook_data hook data associated with the hook function.
450 * @param main_win the main window the viewer belongs to.
453 void lttvwindow_unregister_show(MainWindow
* main_win
,
454 LttvHook hook
, gpointer hook_data
)
456 LttvAttributeValue value
;
458 g_assert(lttv_iattribute_find_by_path(main_win
->current_tab
->attributes
,
459 "hooks/showviewer", LTTV_POINTER
, &value
));
460 tmp
= (LttvHooks
*)*(value
.v_pointer
);
461 if(tmp
== NULL
) return;
462 lttv_hooks_remove_data(tmp
, hook
, hook_data
);
466 * Function to register a hook function for a viewer to set/update the
467 * dividor of the hpane.
468 * @param hook hook function of the viewer.
469 * @param hook_data hook data associated with the hook function.
470 * @param main_win the main window the viewer belongs to.
473 void lttvwindow_register_dividor(MainWindow
*main_win
,
474 LttvHook hook
, gpointer hook_data
)
476 LttvAttributeValue value
;
478 g_assert(lttv_iattribute_find_by_path(main_win
->current_tab
->attributes
,
479 "hooks/hpanedividor", LTTV_POINTER
, &value
));
480 tmp
= (LttvHooks
*)*(value
.v_pointer
);
482 tmp
= lttv_hooks_new();
483 *(value
.v_pointer
) = tmp
;
485 lttv_hooks_add(tmp
, hook
, hook_data
);
490 * Function to unregister a viewer's hook function which is used to
491 * set/update hpane's dividor of the viewer.
492 * It will be called by the destructor of the viewer.
493 * @param hook hook function of the viewer.
494 * @param hook_data hook data associated with the hook function.
495 * @param main_win the main window the viewer belongs to.
498 void lttvwindow_unregister_dividor(MainWindow
*main_win
,
499 LttvHook hook
, gpointer hook_data
)
501 LttvAttributeValue value
;
503 g_assert(lttv_iattribute_find_by_path(main_win
->current_tab
->attributes
,
504 "hooks/hpanedividor", LTTV_POINTER
, &value
));
505 tmp
= (LttvHooks
*)*(value
.v_pointer
);
506 if(tmp
== NULL
) return;
507 lttv_hooks_remove_data(tmp
, hook
, hook_data
);
512 * Update the status bar whenever something changed in the viewer.
513 * @param main_win the main window the viewer belongs to.
514 * @param info the message which will be shown in the status bar.
517 void lttvwindow_report_status(MainWindow
*main_win
, char *info
)
520 g_warning("update_status not implemented in viewer.c");
524 * Function to set the time interval of the current tab.
525 * It will be called by a viewer's signal handle associated with
526 * the move_slider signal
527 * @param main_win the main window the viewer belongs to.
528 * @param time_interval a pointer where time interval is stored.
531 void lttvwindow_report_time_window(MainWindow
*main_win
,
532 TimeWindow
*time_window
)
534 LttvAttributeValue value
;
537 TimeWindowNotifyData time_window_notify_data
;
538 TimeWindow old_time_window
= main_win
->current_tab
->time_window
;
539 time_window_notify_data
.old_time_window
= &old_time_window
;
540 main_win
->current_tab
->time_window
= *time_window
;
541 time_window_notify_data
.new_time_window
=
542 &(main_win
->current_tab
->time_window
);
544 gtk_multi_vpaned_set_scroll_value(main_win
->current_tab
->multi_vpaned
,
545 ltt_time_to_double(time_window
->start_time
)
546 * NANOSECONDS_PER_SECOND
);
547 g_assert(lttv_iattribute_find_by_path(main_win
->current_tab
->attributes
,
548 "hooks/updatetimewindow", LTTV_POINTER
, &value
));
549 tmp
= (LttvHooks
*)*(value
.v_pointer
);
550 if(tmp
== NULL
) return;
551 lttv_hooks_call(tmp
, &time_window_notify_data
);
555 * Function to set the current time/event of the current tab.
556 * It will be called by a viewer's signal handle associated with
557 * the button-release-event signal
558 * @param main_win the main window the viewer belongs to.
559 * @param time a pointer where time is stored.
562 void lttvwindow_report_current_time(MainWindow
*main_win
, LttTime
*time
)
564 LttvAttributeValue value
;
566 main_win
->current_tab
->current_time
= *time
;
567 g_assert(lttv_iattribute_find_by_path(main_win
->current_tab
->attributes
,
568 "hooks/updatecurrenttime", LTTV_POINTER
, &value
));
569 tmp
= (LttvHooks
*)*(value
.v_pointer
);
571 if(tmp
== NULL
)return;
572 lttv_hooks_call(tmp
, time
);
576 * Function to set the position of the hpane's dividor (viewer).
577 * It will be called by a viewer's signal handle associated with
578 * the motion_notify_event event/signal
579 * @param main_win the main window the viewer belongs to.
580 * @param position position of the hpane's dividor.
583 void lttvwindow_report_dividor(MainWindow
*main_win
, gint position
)
585 LttvAttributeValue value
;
587 g_assert(lttv_iattribute_find_by_path(main_win
->current_tab
->attributes
,
588 "hooks/hpanedividor", LTTV_POINTER
, &value
));
589 tmp
= (LttvHooks
*)*(value
.v_pointer
);
590 if(tmp
== NULL
) return;
591 lttv_hooks_call(tmp
, &position
);
595 * Function to set the focused pane (viewer).
596 * It will be called by a viewer's signal handle associated with
597 * the grab_focus signal
598 * @param main_win the main window the viewer belongs to.
599 * @param paned a pointer to a pane where the viewer is contained.
602 void lttvwindow_report_focus(MainWindow
*main_win
, gpointer paned
)
604 gtk_multi_vpaned_set_focus((GtkWidget
*)main_win
->current_tab
->multi_vpaned
,paned
);
610 * Function to get the current time interval of the current traceset.
611 * It will be called by a viewer's hook function to update the
612 * time interval of the viewer and also be called by the constructor
614 * @param main_win the main window the viewer belongs to.
615 * @param time_interval a pointer where time interval will be stored.
618 const TimeInterval
*lttvwindow_get_time_span(MainWindow
*main_win
)
620 //time_window->start_time = main_win->current_tab->time_window.start_time;
621 //time_window->time_width = main_win->current_tab->time_window.time_width;
622 return (LTTV_TRACESET_CONTEXT(main_win
->current_tab
->traceset_info
->
623 traceset_context
)->Time_Span
);
629 * Function to get the current time interval shown on the current tab.
630 * It will be called by a viewer's hook function to update the
631 * shown time interval of the viewer and also be called by the constructor
633 * @param main_win the main window the viewer belongs to.
634 * @param time_interval a pointer where time interval will be stored.
637 const TimeWindow
*lttvwindow_get_time_window(MainWindow
*main_win
)
639 //time_window->start_time = main_win->current_tab->time_window.start_time;
640 //time_window->time_width = main_win->current_tab->time_window.time_width;
641 return &(main_win
->current_tab
->time_window
);
647 * Function to get the current time/event of the current tab.
648 * It will be called by a viewer's hook function to update the
649 * current time/event of the viewer.
650 * @param main_win the main window the viewer belongs to.
651 * @param time a pointer where time will be stored.
654 const LttTime
*lttvwindow_get_current_time(MainWindow
*main_win
)
656 return &(main_win
->current_tab
->current_time
);
661 * Function to get the traceset from the current tab.
662 * It will be called by the constructor of the viewer and also be
663 * called by a hook funtion of the viewer to update its traceset.
664 * @param main_win the main window the viewer belongs to.
665 * @param traceset a pointer to a traceset.
667 const LttvTraceset
*lttvwindow_get_traceset(MainWindow
*main_win
)
669 return main_win
->current_tab
->traceset_info
->traceset
;
673 * Function to get the filter of the current tab.
674 * It will be called by the constructor of the viewer and also be
675 * called by a hook funtion of the viewer to update its filter.
676 * @param main_win, the main window the viewer belongs to.
677 * @param filter, a pointer to a filter.
679 const lttv_filter
*lttvwindow_get_filter(MainWindow
*main_win
)
682 g_warning("lttvwindow_get_filter not implemented in viewer.c");
687 * Function to get the stats of the traceset
688 * @param main_win the main window the viewer belongs to.
691 LttvTracesetStats
* lttvwindow_get_traceset_stats(MainWindow
*main_win
)
693 return main_win
->current_tab
->traceset_info
->traceset_context
;
697 LttvTracesetContext
* lttvwindow_get_traceset_context(MainWindow
*main_win
)
699 return (LttvTracesetContext
*)main_win
->current_tab
->traceset_info
->traceset_context
;