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
32 #include <lttv/lttv.h>
33 #include <lttv/state.h>
34 #include <lttv/stats.h>
35 #include <lttv/tracecontext.h>
36 #include <lttvwindow/common.h>
37 #include <lttvwindow/mainwindow.h>
38 #include <lttvwindow/viewer.h>
39 #include <lttvwindow/toolbar.h>
40 #include <lttvwindow/menu.h>
41 #include <lttvwindow/callbacks.h> // for execute_time_requests
45 * Internal function parts
49 * Function to set/update traceset for the viewers
50 * @param main_win main window
51 * @param traceset traceset of the main window.
54 * 0 : traceset updated
55 * 1 : no traceset hooks to update; not an error.
58 int SetTraceset(MainWindow
* main_win
, gpointer traceset
)
61 LttvAttributeValue value
;
63 if( lttv_iattribute_find_by_path(main_win
->attributes
,
64 "hooks/updatetraceset", LTTV_POINTER
, &value
) != 0)
67 tmp
= (LttvHooks
*)*(value
.v_pointer
);
68 if(tmp
== NULL
) return 1;
71 lttv_hooks_call(tmp
,traceset
);
78 * Function to set/update filter for the viewers
79 * @param main_win main window
80 * @param filter filter of the main window.
84 * 1 : no filter hooks to update; not an error.
87 int SetFilter(MainWindow
* main_win
, gpointer filter
)
90 LttvAttributeValue value
;
92 if(lttv_iattribute_find_by_path(main_win
->attributes
,
93 "hooks/updatefilter", LTTV_POINTER
, &value
) != 0)
96 tmp
= (LttvHooks
*)*(value
.v_pointer
);
98 if(tmp
== NULL
) return 1;
99 lttv_hooks_call(tmp
,filter
);
105 * Function to redraw each viewer belonging to the current tab
106 * @param main_win the main window the viewer belongs to.
109 void update_traceset(MainWindow
* main_win
)
111 LttvAttributeValue value
;
113 g_assert(lttv_iattribute_find_by_path(main_win
->current_tab
->attributes
,
114 "hooks/updatetraceset", LTTV_POINTER
, &value
));
115 tmp
= (LttvHooks
*)*(value
.v_pointer
);
116 if(tmp
== NULL
) return;
117 lttv_hooks_call(tmp
, NULL
);
120 void set_time_window_adjustment(MainWindow
* main_win
, const TimeWindow
* new_time_window
)
122 gtk_multi_vpaned_set_adjust(main_win
->current_tab
->multi_vpaned
, new_time_window
, FALSE
);
126 void set_time_window(MainWindow
* main_win
, const TimeWindow
*time_window
)
128 LttvAttributeValue value
;
131 TimeWindowNotifyData time_window_notify_data
;
132 TimeWindow old_time_window
= main_win
->current_tab
->time_window
;
133 time_window_notify_data
.old_time_window
= &old_time_window
;
134 main_win
->current_tab
->time_window
= *time_window
;
135 time_window_notify_data
.new_time_window
=
136 &(main_win
->current_tab
->time_window
);
138 g_assert(lttv_iattribute_find_by_path(main_win
->current_tab
->attributes
,
139 "hooks/updatetimewindow", LTTV_POINTER
, &value
));
140 tmp
= (LttvHooks
*)*(value
.v_pointer
);
141 if(tmp
== NULL
) return;
142 lttv_hooks_call(tmp
, &time_window_notify_data
);
153 * Function to register a view constructor so that main window can generate
154 * a menu item and a toolbar item for the viewer in order to generate a new
155 * instance easily. A menu entry and toolbar item will be added to each main
158 * It should be called by init function of the module.
160 * @param menu_path path of the menu item.
161 * @param menu_text text of the menu item.
162 * @param pixmap Image shown on the toolbar item.
163 * @param tooltip tooltip of the toolbar item.
164 * @param view_constructor constructor of the viewer.
167 void lttvwindow_register_constructor
172 lttvwindow_viewer_constructor view_constructor
)
174 LttvIAttribute
*attributes_global
= LTTV_IATTRIBUTE(lttv_global_attributes());
175 LttvToolbars
* toolbar
;
177 LttvAttributeValue value
;
180 g_assert(lttv_iattribute_find_by_path(attributes_global
,
181 "viewers/toolbar", LTTV_POINTER
, &value
));
182 toolbar
= (LttvToolbars
*)*(value
.v_pointer
);
184 if(toolbar
== NULL
) {
185 toolbar
= lttv_toolbars_new();
186 *(value
.v_pointer
) = toolbar
;
188 lttv_toolbars_add(toolbar
, view_constructor
, tooltip
, pixmap
);
189 main_window_add_toolbars_item(toolbar
, view_constructor
, tooltip
, pixmap
);
192 if(menu_path
!= NULL
) {
193 g_assert(lttv_iattribute_find_by_path(attributes_global
,
194 "viewers/menu", LTTV_POINTER
, &value
));
195 menu
= (LttvMenus
*)*(value
.v_pointer
);
198 menu
= lttv_menus_new();
199 *(value
.v_pointer
) = menu
;
201 lttv_menus_add(menu
, view_constructor
, menu_path
, menu_text
);
202 main_window_add_menu_item(menu
, view_constructor
, menu_path
, menu_text
);
208 * Function to unregister the viewer's constructor, release the space
209 * occupied by menu_path, menu_text, pixmap, tooltip and constructor of the
212 * It will be called when a module is unloaded.
214 * @param view_constructor constructor of the viewer.
218 void lttvwindow_unregister_constructor
219 (lttvwindow_viewer_constructor view_constructor
)
221 LttvIAttribute
*attributes_global
= LTTV_IATTRIBUTE(lttv_global_attributes());
222 LttvToolbars
* toolbar
;
224 LttvAttributeValue value
;
226 g_assert(lttv_iattribute_find_by_path(attributes_global
,
227 "viewers/toolbar", LTTV_POINTER
, &value
));
228 toolbar
= (LttvToolbars
*)*(value
.v_pointer
);
230 if(toolbar
!= NULL
) {
231 main_window_remove_toolbar_item(view_constructor
);
232 lttv_toolbars_remove(toolbar
, view_constructor
);
235 g_assert(lttv_iattribute_find_by_path(attributes_global
,
236 "viewers/menu", LTTV_POINTER
, &value
));
237 menu
= (LttvMenus
*)*(value
.v_pointer
);
240 main_window_remove_menu_item(view_constructor
);
241 lttv_menus_remove(menu
, view_constructor
);
249 * Function to register a hook function for a viewer to set/update its
251 * @param hook hook function of the viewer.
252 * @param hook_data hook data associated with the hook function.
253 * @param main_win the main window the viewer belongs to.
255 void lttvwindow_register_time_window_notify(MainWindow
* main_win
,
256 LttvHook hook
, gpointer hook_data
)
258 LttvAttributeValue value
;
260 g_assert(lttv_iattribute_find_by_path(main_win
->current_tab
->attributes
,
261 "hooks/updatetimewindow", LTTV_POINTER
, &value
));
262 tmp
= (LttvHooks
*)*(value
.v_pointer
);
264 tmp
= lttv_hooks_new();
265 *(value
.v_pointer
) = tmp
;
267 lttv_hooks_add(tmp
, hook
,hook_data
);
272 * Function to unregister a viewer's hook function which is used to
273 * set/update the time interval of the viewer.
274 * @param hook hook function of the viewer.
275 * @param hook_data hook data associated with the hook function.
276 * @param main_win the main window the viewer belongs to.
279 void lttvwindow_unregister_time_window_notify(MainWindow
* main_win
,
280 LttvHook hook
, gpointer hook_data
)
282 LttvAttributeValue value
;
284 g_assert(lttv_iattribute_find_by_path(main_win
->current_tab
->attributes
,
285 "hooks/updatetimewindow", LTTV_POINTER
, &value
));
286 tmp
= (LttvHooks
*)*(value
.v_pointer
);
287 if(tmp
== NULL
) return;
288 lttv_hooks_remove_data(tmp
, hook
, hook_data
);
292 * Function to register a hook function for a viewer to set/update its
294 * @param hook hook function of the viewer.
295 * @param hook_data hook data associated with the hook function.
296 * @param main_win the main window the viewer belongs to.
299 void lttvwindow_register_traceset_notify(MainWindow
* main_win
,
300 LttvHook hook
, gpointer hook_data
)
302 LttvAttributeValue value
;
304 g_assert(lttv_iattribute_find_by_path(main_win
->current_tab
->attributes
,
305 "hooks/updatetraceset", LTTV_POINTER
, &value
));
306 tmp
= (LttvHooks
*)*(value
.v_pointer
);
308 tmp
= lttv_hooks_new();
309 *(value
.v_pointer
) = tmp
;
311 lttv_hooks_add(tmp
, hook
, hook_data
);
316 * Function to unregister a viewer's hook function which is used to
317 * set/update the traceset of the viewer.
318 * @param hook hook function of the viewer.
319 * @param hook_data hook data associated with the hook function.
320 * @param main_win the main window the viewer belongs to.
323 void lttvwindow_unregister_traceset_notify(MainWindow
* main_win
,
324 LttvHook hook
, gpointer hook_data
)
326 LttvAttributeValue value
;
328 g_assert(lttv_iattribute_find_by_path(main_win
->current_tab
->attributes
,
329 "hooks/updatetraceset", LTTV_POINTER
, &value
));
330 tmp
= (LttvHooks
*)*(value
.v_pointer
);
331 if(tmp
== NULL
) return;
332 lttv_hooks_remove_data(tmp
, hook
, hook_data
);
336 * Function to register a hook function for a viewer to set/update its
338 * @param hook hook function of the viewer.
339 * @param hook_data hook data associated with the hook function.
340 * @param main_win the main window the viewer belongs to.
343 void lttvwindow_register_filter_notify(MainWindow
*main_win
,
344 LttvHook hook
, gpointer hook_data
)
346 LttvAttributeValue value
;
348 g_assert(lttv_iattribute_find_by_path(main_win
->attributes
,
349 "hooks/updatefilter", LTTV_POINTER
, &value
));
350 tmp
= (LttvHooks
*)*(value
.v_pointer
);
352 tmp
= lttv_hooks_new();
353 *(value
.v_pointer
) = tmp
;
355 lttv_hooks_add(tmp
, hook
, hook_data
);
360 * Function to unregister a viewer's hook function which is used to
361 * set/update the filter of the viewer.
362 * @param hook hook function of the viewer.
363 * @param hook_data hook data associated with the hook function.
364 * @param main_win the main window the viewer belongs to.
367 void lttvwindow_unregister_filter_notify(MainWindow
* main_win
,
371 LttvAttributeValue value
;
373 g_assert(lttv_iattribute_find_by_path(main_win
->attributes
,
374 "hooks/updatefilter", LTTV_POINTER
, &value
));
375 tmp
= (LttvHooks
*)*(value
.v_pointer
);
376 if(tmp
== NULL
) return;
377 lttv_hooks_remove_data(tmp
, hook
, hook_data
);
381 * Function to register a hook function for a viewer to set/update its
383 * @param hook hook function of the viewer.
384 * @param hook_data hook data associated with the hook function.
385 * @param main_win the main window the viewer belongs to.
388 void lttvwindow_register_current_time_notify(MainWindow
*main_win
,
389 LttvHook hook
, gpointer hook_data
)
391 LttvAttributeValue value
;
393 g_assert(lttv_iattribute_find_by_path(main_win
->current_tab
->attributes
,
394 "hooks/updatecurrenttime", LTTV_POINTER
, &value
));
395 tmp
= (LttvHooks
*)*(value
.v_pointer
);
397 tmp
= lttv_hooks_new();
398 *(value
.v_pointer
) = tmp
;
400 lttv_hooks_add(tmp
, hook
, hook_data
);
405 * Function to unregister a viewer's hook function which is used to
406 * set/update the current time of the viewer.
407 * @param hook hook function of the viewer.
408 * @param hook_data hook data associated with the hook function.
409 * @param main_win the main window the viewer belongs to.
412 void lttvwindow_unregister_current_time_notify(MainWindow
* main_win
,
413 LttvHook hook
, gpointer hook_data
)
415 LttvAttributeValue value
;
417 g_assert(lttv_iattribute_find_by_path(main_win
->current_tab
->attributes
,
418 "hooks/updatecurrenttime", LTTV_POINTER
, &value
));
419 tmp
= (LttvHooks
*)*(value
.v_pointer
);
420 if(tmp
== NULL
) return;
421 lttv_hooks_remove_data(tmp
, hook
, hook_data
);
426 * Function to register a hook function for a viewer to show
427 * the content of the viewer.
428 * @param hook hook function of the viewer.
429 * @param hook_data hook data associated with the hook function.
430 * @param main_win the main window the viewer belongs to.
433 void lttvwindow_register_show_notify(MainWindow
*main_win
,
434 LttvHook hook
, gpointer hook_data
)
436 LttvAttributeValue value
;
438 g_assert(lttv_iattribute_find_by_path(main_win
->current_tab
->attributes
,
439 "hooks/showviewer", LTTV_POINTER
, &value
));
440 tmp
= (LttvHooks
*)*(value
.v_pointer
);
442 tmp
= lttv_hooks_new();
443 *(value
.v_pointer
) = tmp
;
445 lttv_hooks_add(tmp
, hook
, hook_data
);
450 * Function to unregister a viewer's hook function which is used to
451 * show the content of the viewer..
452 * @param hook hook function of the viewer.
453 * @param hook_data hook data associated with the hook function.
454 * @param main_win the main window the viewer belongs to.
457 void lttvwindow_unregister_show_notify(MainWindow
* main_win
,
458 LttvHook hook
, gpointer hook_data
)
460 LttvAttributeValue value
;
462 g_assert(lttv_iattribute_find_by_path(main_win
->current_tab
->attributes
,
463 "hooks/showviewer", LTTV_POINTER
, &value
));
464 tmp
= (LttvHooks
*)*(value
.v_pointer
);
465 if(tmp
== NULL
) return;
466 lttv_hooks_remove_data(tmp
, hook
, hook_data
);
470 * Function to register a hook function for a viewer to set/update the
471 * dividor of the hpane.
472 * @param hook hook function of the viewer.
473 * @param hook_data hook data associated with the hook function.
474 * @param main_win the main window the viewer belongs to.
477 void lttvwindow_register_dividor(MainWindow
*main_win
,
478 LttvHook hook
, gpointer hook_data
)
480 LttvAttributeValue value
;
482 g_assert(lttv_iattribute_find_by_path(main_win
->current_tab
->attributes
,
483 "hooks/hpanedividor", LTTV_POINTER
, &value
));
484 tmp
= (LttvHooks
*)*(value
.v_pointer
);
486 tmp
= lttv_hooks_new();
487 *(value
.v_pointer
) = tmp
;
489 lttv_hooks_add(tmp
, hook
, hook_data
);
494 * Function to unregister a viewer's hook function which is used to
495 * set/update hpane's dividor of the viewer.
496 * It will be called by the destructor of the viewer.
497 * @param hook hook function of the viewer.
498 * @param hook_data hook data associated with the hook function.
499 * @param main_win the main window the viewer belongs to.
502 void lttvwindow_unregister_dividor(MainWindow
*main_win
,
503 LttvHook hook
, gpointer hook_data
)
505 LttvAttributeValue value
;
507 g_assert(lttv_iattribute_find_by_path(main_win
->current_tab
->attributes
,
508 "hooks/hpanedividor", LTTV_POINTER
, &value
));
509 tmp
= (LttvHooks
*)*(value
.v_pointer
);
510 if(tmp
== NULL
) return;
511 lttv_hooks_remove_data(tmp
, hook
, hook_data
);
516 * Update the status bar whenever something changed in the viewer.
517 * @param main_win the main window the viewer belongs to.
518 * @param info the message which will be shown in the status bar.
521 void lttvwindow_report_status(MainWindow
*main_win
, const char *info
)
524 g_warning("update_status not implemented in viewer.c");
528 * Function to set the time interval of the current tab.
529 * It will be called by a viewer's signal handle associated with
530 * the move_slider signal
531 * @param main_win the main window the viewer belongs to.
532 * @param time_interval a pointer where time interval is stored.
535 void lttvwindow_report_time_window(MainWindow
*main_win
,
536 const TimeWindow
*time_window
)
538 set_time_window(main_win
, time_window
);
539 set_time_window_adjustment(main_win
, time_window
);
544 * Function to set the current time/event of the current tab.
545 * It will be called by a viewer's signal handle associated with
546 * the button-release-event signal
547 * @param main_win the main window the viewer belongs to.
548 * @param time a pointer where time is stored.
551 void lttvwindow_report_current_time(MainWindow
*main_win
,
554 LttvAttributeValue value
;
556 main_win
->current_tab
->current_time
= *time
;
557 g_assert(lttv_iattribute_find_by_path(main_win
->current_tab
->attributes
,
558 "hooks/updatecurrenttime", LTTV_POINTER
, &value
));
559 tmp
= (LttvHooks
*)*(value
.v_pointer
);
561 if(tmp
== NULL
)return;
562 lttv_hooks_call(tmp
, &main_win
->current_tab
->current_time
);
566 * Function to set the position of the hpane's dividor (viewer).
567 * It will be called by a viewer's signal handle associated with
568 * the motion_notify_event event/signal
569 * @param main_win the main window the viewer belongs to.
570 * @param position position of the hpane's dividor.
573 void lttvwindow_report_dividor(MainWindow
*main_win
, gint position
)
575 LttvAttributeValue value
;
577 g_assert(lttv_iattribute_find_by_path(main_win
->current_tab
->attributes
,
578 "hooks/hpanedividor", LTTV_POINTER
, &value
));
579 tmp
= (LttvHooks
*)*(value
.v_pointer
);
580 if(tmp
== NULL
) return;
581 lttv_hooks_call(tmp
, &position
);
585 * Function to set the focused pane (viewer).
586 * It will be called by a viewer's signal handle associated with
587 * the grab_focus signal
588 * @param main_win the main window the viewer belongs to.
589 * @param top_widget the top widget containing all the other widgets of the
593 void lttvwindow_report_focus(MainWindow
*main_win
, GtkWidget
*top_widget
)
595 gtk_multi_vpaned_set_focus((GtkWidget
*)main_win
->current_tab
->multi_vpaned
,
596 gtk_widget_get_parent(top_widget
));
601 * Function to request data in a specific time interval to the main window.
602 * The main window will use this time interval and the others present
603 * to get the data from the process trace.
604 * @param main_win the main window the viewer belongs to.
605 * @param paned a pointer to a pane where the viewer is contained.
608 void lttvwindow_time_interval_request(MainWindow
*main_win
,
609 TimeWindow time_requested
, guint num_events
,
610 LttvHook after_process_traceset
,
611 gpointer after_process_traceset_data
)
613 TimeRequest time_request
;
615 time_request
.time_window
= time_requested
;
616 time_request
.num_events
= num_events
;
617 time_request
.after_hook
= after_process_traceset
;
618 time_request
.after_hook_data
= after_process_traceset_data
;
620 g_array_append_val(main_win
->current_tab
->time_requests
, time_request
);
622 if(!main_win
->current_tab
->time_request_pending
)
624 /* Redraw has +20 priority. We want a prio higher than that, so +19 */
625 g_idle_add_full((G_PRIORITY_HIGH_IDLE
+ 19),
626 (GSourceFunc
)execute_time_requests
,
629 main_win
->current_tab
->time_request_pending
= TRUE
;
634 * Function to get the current time interval shown on the current tab.
635 * It will be called by a viewer's hook function to update the
636 * shown time interval of the viewer and also be called by the constructor
638 * @param main_win the main window the viewer belongs to.
639 * @param time_interval a pointer where time interval will be stored.
642 const TimeWindow
*lttvwindow_get_time_window(MainWindow
*main_win
)
644 //time_window->start_time = main_win->current_tab->time_window.start_time;
645 //time_window->time_width = main_win->current_tab->time_window.time_width;
646 return &(main_win
->current_tab
->time_window
);
652 * Function to get the current time/event of the current tab.
653 * It will be called by a viewer's hook function to update the
654 * current time/event of the viewer.
655 * @param main_win the main window the viewer belongs to.
656 * @param time a pointer where time will be stored.
659 const LttTime
*lttvwindow_get_current_time(MainWindow
*main_win
)
661 return &(main_win
->current_tab
->current_time
);
666 * Function to get the filter of the current tab.
667 * It will be called by the constructor of the viewer and also be
668 * called by a hook funtion of the viewer to update its filter.
669 * @param main_win, the main window the viewer belongs to.
670 * @param filter, a pointer to a filter.
672 const lttv_filter
*lttvwindow_get_filter(MainWindow
*main_win
)
675 g_warning("lttvwindow_get_filter not implemented in viewer.c");
680 * Function to get the stats of the traceset
681 * @param main_win the main window the viewer belongs to.
684 LttvTracesetStats
* lttvwindow_get_traceset_stats(MainWindow
*main_win
)
686 return main_win
->current_tab
->traceset_info
->traceset_context
;
690 LttvTracesetContext
* lttvwindow_get_traceset_context(MainWindow
*main_win
)
692 return (LttvTracesetContext
*)main_win
->current_tab
->traceset_info
->traceset_context
;