1 /* This file is part of the Linux Trace Toolkit Graphic User Interface
2 * Copyright (C) 2003-2004 Xiangxiu Yang, Mathieu Desnoyers
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,
20 This file is what every viewer plugin writer should refer to.
25 A viewer plugin is, before anything, a plugin. As a dynamically loadable
26 module, it thus has an init and a destroy function called whenever it is
27 loaded/initialized and unloaded/destroyed. A graphical module depends on
28 lttvwindow for construction of its viewer instances. In order to achieve this,
29 it must register its constructor function to the main window along with
30 button description or text menu entry description. A module keeps a list of
31 every viewer that currently sits in memory so it can destroy them before the
32 module gets unloaded/destroyed.
35 Viewer Instance Related API
37 The lifetime of a viewer is as follows. The viewer constructor function is
38 called each time an instance view is created (one subwindow of this viewer
39 type is created by the user either by clicking on the menu item or the button
40 corresponding to the viewer). Thereafter, the viewer gets hooks called for
41 different purposes by the window containing it. These hooks are detailed
42 below. It also has to deal with GTK Events. Finally, it can be destructed by
43 having its top level widget unreferenced by the main window or by any
44 GTK Event causing a "destroy-event" signal on the its top widget. Another
45 possible way for it do be destroyed is if the module gets unloaded. The module
46 unload function will have to emit a "destroy" signal on each top level widget
47 of all instances of its viewers.
50 Notices from Main Window
52 time_window : This is the time interval visible on the viewer's tab. Every
53 viewer that cares about being synchronised by respect to the
54 time with other viewers should register to this notification.
55 They should redraw all or part of their display when this occurs.
57 traceset : This notification is called whenever a trace is added/removed
58 from the traceset. As it affects all the data displayed by the
59 viewer, it sould redraw itself totally.
61 filter : FIXME : describe..
63 current_time: Being able to zoom nearer a specific time or highlight a specific
64 time on every viewer in synchronicity implies that the viewer
65 has to shown a visual sign over the drawing or select an event
66 when it receives this notice. It should also inform the main
67 window with the appropriate report API function when a user
68 selects a specific time as being the current time.
70 dividor : This notice links the positions of the horizontal dividors
71 between the graphic display zone of every viewer and their Y axis,
72 typically showing processes, cpus, ...
75 FIXME : Add background computation explanation here
76 background_init: prepare for background computation (comes after show_end).
77 process_trace for background: done in small chunks in gtk_idle, hooks called.
78 background_end: remove the hooks and perhaps update the window.
81 Reporting Changes to the Main Window
83 In most cases, the enclosing window knows about updates such as described in the
84 Notification section higher. There are a few cases, however, where updates are
85 caused by actions known by a view instance. For example, clicking in a view may
86 update the current time; all viewers within the same window must be told about
87 the new current time to change the currently highlighted time point. A viewer
88 reports such events by calling lttvwindow_report_current_time on its lttvwindow.
89 The lttvwindow will consequently call current_time_notify for each of its
93 Available report methods are :
95 lttvwindow_report_status : reports the text of the status bar.
96 lttvwindow_report_time_window : reports the new time window.
97 lttvwindow_report_current_time : reports the new current time.
98 lttvwindow_report_dividor : reports the new horizontal dividor's position.
99 lttvwindow_report_focus : One on the widgets in the viewer has the keyboard's
104 Requesting Events to Main Window
106 Events can be requested by passing a EventsRequest structure to the main window.
107 They will be delivered later when the next g_idle functions will be called.
108 Event delivery is done by calling the middle hook for this event ID, or the
111 EventsRequest consists in
112 - a start timestamp or position
113 - a end timestamp and/or position and/or number of events to read
114 - hook lists to call for traceset/trace/tracefile begin and end, and for each
117 The main window will deliver events for every EventRequests it has pending
118 through an algorithm that guarantee that all events requested, and only them,
119 will be delivered to the viewer between the call of the tracefile_begin hooks
120 and the call of the tracefile_end hooks.
129 GTK is quite different from the other graphical toolkits around there. The main
130 difference resides in that there are many X Windows inside one GtkWindow,
131 instead of just one. That means that X events are delivered by the glib main
132 loop directly to the widget corresponding to the GdkWindow affected by the X
135 Event delivery to a widget emits a signal on this widget. Signal emission and
136 propagation is described there :
138 http://www.gtk.org/tutorial/sec-signalemissionandpropagation.html
140 For further information on the GTK main loop (now a wrapper over glib main loop)
143 http://developer.gnome.org/doc/API/2.0/gtk/gtk-General.html
144 http://developer.gnome.org/doc/API/2.0/glib/glib-The-Main-Event-Loop.html
147 For documentation on event handling in GTK/GDK, see :
149 http://developer.gnome.org/doc/API/2.0/gdk/gdk-Events.html
150 http://developer.gnome.org/doc/API/2.0/gdk/gdk-Event-Structures.html
153 Signals can be connected to handlers, emitted, propagated, blocked,
156 http://developer.gnome.org/doc/API/2.0/gobject/gobject-Signals.html
163 Provides the exposed region in the GdkEventExpose structure.
165 There are two ways of dealing with exposures. The first one is to directly draw
166 on the screen and the second one is to draw in a pixmap buffer, and then to
167 update the screen when necessary.
169 In the first case, the expose event will be responsible for registering hooks to
170 process_traceset and require time intervals to the main window. So, in this
171 scenario, if a part of the screen is damaged, the trace has to be read to
174 In the second case, with a pixmap buffer, the expose handler is only responsible
175 of showing the pixmap buffer on the screen. If the pixmap buffer has never
176 been filled with a drawing, the expose handler may ask for it to be filled.
178 It can add dotted lines and such visual effects to enhance the user's
182 FIXME : explain other important events
190 * \brief API used by the graphical viewers to interact with their top window.
192 * Main window (lttvwindow module) is the place to contain and display viewers.
193 * Viewers (lttv plugins) interact with main window through this API.
194 * This header file should be included in each graphic module.
200 #include <lttv/hook.h>
201 #include <lttvwindow/common.h>
202 #include <lttv/stats.h>
203 //FIXME (not ready yet) #include <lttv/filter.h>
206 /* Module Related API */
209 /* constructor a the viewer */
210 //FIXME explain LttvTracesetSelector and key
211 typedef GtkWidget
* (*lttvwindow_viewer_constructor
)
212 (MainWindow
* main_window
, LttvTracesetSelector
* s
, char *key
);
216 * Function to register a view constructor so that main window can generate
217 * a toolbar item for the viewer in order to generate a new instance easily.
219 * It should be called by init function of the module.
221 * @param pixmap Image shown on the toolbar item.
222 * @param tooltip tooltip of the toolbar item.
223 * @param view_constructor constructor of the viewer.
226 void lttvwindow_register_toolbar
229 lttvwindow_viewer_constructor view_constructor
);
233 * Function to unregister the viewer's constructor, release the space
234 * occupied by pixmap, tooltip and constructor of the viewer.
236 * It will be called when a module is unloaded.
238 * @param view_constructor constructor of the viewer.
241 void lttvwindow_unregister_toolbar
242 (lttvwindow_viewer_constructor view_constructor
);
246 * Function to register a view constructor so that main window can generate
247 * a menu item for the viewer in order to generate a new instance easily.
249 * It will be called by init function of the module.
251 * @param menu_path path of the menu item.
252 * @param menu_text text of the menu item.
253 * @param view_constructor constructor of the viewer.
256 void lttvwindow_register_menu(char *menu_path
,
258 lttvwindow_viewer_constructor view_constructor
);
262 * Function to unregister the viewer's constructor, release the space
263 * occupied by menu_path, menu_text and constructor of the viewer.
265 * It will be called when a module is unloaded.
267 * @param view_constructor constructor of the viewer.
270 void lttvwindow_unregister_menu(lttvwindow_viewer_constructor view_constructor
);
274 /* Viewer Instance Related API */
277 * Structure used as hook_data for the time_window_notify hook.
279 typedef struct _TimeWindowNotifyData
{
280 TimeWindow
*new_time_window
;
281 TimeWindow
*old_time_window
;
282 } TimeWindowNotifyData
;
286 * Function to register a hook function that will be called by the main window
287 * when the time interval needs to be updated.
289 * This register function is typically called by the constructor of the viewer.
291 * @param main_win the main window the viewer belongs to.
292 * @param hook hook that sould be called by the main window when the time
293 * interval changes. This hook function takes a
294 * TimeWindowNotifyData* as call_data.
295 * @param hook_data hook data associated with the hook function. It will
296 * be typically a pointer to the viewer's data structure.
299 void lttvwindow_register_time_window_notify(MainWindow
*main_win
,
305 * Function to unregister the time_window notification hook.
307 * This unregister function is typically called by the destructor of the viewer.
309 * @param main_win the main window the viewer belongs to.
310 * @param hook hook that sould be called by the main window when the time
311 * interval changes. This hook function takes a
312 * TimeWindowNotifyData* as call_data.
313 * @param hook_data hook data associated with the hook function. It will
314 * be typically a pointer to the viewer's data structure.
317 void lttvwindow_unregister_time_window_notify(MainWindow
*main_win
,
323 * Function to register a hook function that will be called by the main window
324 * when the traceset is changed. That means that the viewer must redraw
325 * itself completely or check if it's affected by the particular change to the
328 * This register function is typically called by the constructor of the viewer.
330 * @param main_win the main window the viewer belongs to.
331 * @param hook hook that should be called whenever a change to the traceset
332 * occurs. The call_data of this hook is a NULL pointer.
333 * @param hook_data hook data associated with the hook function. It will
334 * be typically a pointer to the viewer's data structure.
337 void lttvwindow_register_traceset_notify(MainWindow
*main_win
,
343 * Function to unregister the traceset_notify hook.
345 * @param main_win the main window the viewer belongs to.
346 * @param hook hook that should be called whenever a change to the traceset
347 * occurs. The call_data of this hook is a NULL pointer.
348 * @param hook_data hook data associated with the hook function. It will
349 * be typically a pointer to the viewer's data structure.
352 void lttvwindow_unregister_traceset_notify(MainWindow
*main_win
,
358 * Function to register a hook function for a viewer to set/update its
361 * FIXME : Add information about what a filter is as seen from a viewer and how
364 * This register function is typically called by the constructor of the viewer.
366 * @param main_win the main window the viewer belongs to.
367 * @param hook hook function called by the main window when a filter change
369 * @param hook_data hook data associated with the hook function. It will
370 * be typically a pointer to the viewer's data structure.
373 void lttvwindow_register_filter_notify(MainWindow
*main_win
,
379 * Function to unregister a viewer's hook function which is used to
380 * set/update the filter of the viewer.
382 * This unregistration is called by the destructor of the viewer.
384 * @param main_win the main window the viewer belongs to.
385 * @param hook hook function called by the main window when a filter change
387 * @param hook_data hook data associated with the hook function. It will
388 * be typically a pointer to the viewer's data structure.
391 void lttvwindow_unregister_filter_notify(MainWindow
* main_win
,
397 * Function to register a hook function for a viewer to set/update its
400 * @param main_win the main window the viewer belongs to.
401 * @param hook hook function of the viewer that updates the current time. The
402 * call_data is a LttTime* representing the new current time.
403 * @param hook_data hook data associated with the hook function. It will
404 * be typically a pointer to the viewer's data structure.
407 void lttvwindow_register_current_time_notify(MainWindow
*main_win
,
413 * Function to unregister a viewer's hook function which is used to
414 * set/update the current time of the viewer.
415 * @param main_win the main window the viewer belongs to.
416 * @param hook hook function of the viewer that updates the current time. The
417 * call_data is a LttTime* representing the new current time.
418 * @param hook_data hook data associated with the hook function. It will
419 * be typically a pointer to the viewer's data structure.
422 void lttvwindow_unregister_current_time_notify(MainWindow
*main_win
,
428 * Function to register a hook function for a viewer to set/update the
429 * dividor of the hpane. It provides a way to make the horizontal
430 * dividors of all the viewers linked together.
432 * @param main_win the main window the viewer belongs to.
433 * @param hook hook function of the viewer that will be called whenever a
434 * dividor changes in another viewer. The call_data of this hook
435 * is a gint*. The value of the integer is the new position of the
437 * @param hook_data hook data associated with the hook function. It will
438 * be typically a pointer to the viewer's data structure.
441 void lttvwindow_register_dividor(MainWindow
*main_win
,
447 * Function to unregister a viewer's hook function which is used to
448 * set/update hpane's dividor of the viewer.
450 * @param main_win the main window the viewer belongs to.
451 * @param hook hook function of the viewer that will be called whenever a
452 * dividor changes in another viewer. The call_data of this hook
453 * is a gint*. The value of the integer is the new position of the
455 * @param hook_data hook data associated with the hook function. It will
456 * be typically a pointer to the viewer's data structure.
459 void lttvwindow_unregister_dividor(MainWindow
*main_win
,
466 * This method reports the information to show on the status bar in the
469 * @param main_win the main window the viewer belongs to.
470 * @param info the message which will be shown in the status bar.
473 void lttvwindow_report_status(MainWindow
*main_win
, const char *info
);
477 * Function to set the time interval of the current tab.a
479 * @param main_win the main window the viewer belongs to.
480 * @param time_interval pointer to the time interval value.
483 void lttvwindow_report_time_window(MainWindow
*main_win
,
484 const TimeWindow
*time_window
);
487 * Function to set the current time/event of the current tab.
488 * It will be called by a viewer's signal handle associated with
489 * the button-release-event signal
490 * @param main_win the main window the viewer belongs to.
491 * @param time a pointer where time is stored.
494 void lttvwindow_report_current_time(MainWindow
*main_win
,
495 const LttTime
*time
);
499 * Function to set the position of the hpane's dividor (viewer).
500 * It will typically be called by a viewer's signal handle associated
501 * with the motion_notify_event event/signal.
503 * @param main_win the main window the viewer belongs to.
504 * @param position position of the hpane's dividor.
507 void lttvwindow_report_dividor(MainWindow
*main_win
, gint position
);
510 * Function to set the focused viewer of the tab.
511 * It will be called by a viewer's signal handle associated with
512 * the grab_focus signal of all widgets in the viewer.
514 * @param main_win the main window the viewer belongs to.
515 * @param top_widget the top widget containing all the other widgets of the
518 void lttvwindow_report_focus(MainWindow
*main_win
,
519 GtkWidget
*top_widget
);
523 /* Structure sent to the time request hook */
524 /* Value considered as empty */
525 typedef struct _EventsRequest
{
526 LttTime start_time
, /* Unset : { 0, 0 } */
527 LttvTracesetContextPosition start_position
, /* Unset : num_traces = 0 */
528 LttTime end_time
, /* Unset : { 0, 0 } */
529 guint num_events
, /* Unset : G_MAXUINT */
530 LttvTracesetContextPosition end_position
, /* Unset : num_traces = 0 */
531 LttvHooksById
*before_traceset
, /* Unset : NULL */
532 LttvHooksById
*before_trace
, /* Unset : NULL */
533 LttvHooksById
*before_tracefile
, /* Unset : NULL */
534 LttvHooksById
*middle
, /* Unset : NULL */
535 LttvHooksById
*after_tracefile
, /* Unset : NULL */
536 LttvHooksById
*after_trace
, /* Unset : NULL */
537 LttvHooksById
*after_traceset
/* Unset : NULL */
542 * Function to request data in a specific time interval to the main window. The
543 * time request servicing is differed until the glib idle functions are
546 * The viewer has to provide hooks that should be associated with the event
549 * Either start time or start position must be defined in a EventRequest
550 * structure for it to be valid.
552 * end_time, end_position and num_events can all be defined. The first one
553 * to occur will be used as end criterion.
555 * @param main_win the main window the viewer belongs to.
556 * @param events_requested the structure of request from.
559 void lttvwindow_events_request(MainWindow
*main_win
,
560 EventsRequest events_request
);
563 * Function to get the life span of the traceset
565 * @param main_win the main window the viewer belongs to.
566 * @return pointer to a time interval : the life span of the traceset.
569 const TimeInterval
*lttvwindow_get_time_span(MainWindow
*main_win
);
572 * Function to get the current time window of the current tab.
574 * @param main_win the main window the viewer belongs to.
575 * @return a pointer to the current tab's time interval.
578 const TimeWindow
*lttvwindow_get_time_window(MainWindow
*main_win
);
582 * Function to get the current time of the current tab.
584 * @param main_win the main window the viewer belongs to.
585 * @return a pointer to the current tab's current time.
588 const LttTime
*lttvwindow_get_current_time(MainWindow
*main_win
);
592 * Function to get the filter of the current tab.
593 * @param main_win, the main window the viewer belongs to.
594 * @param filter, a pointer to a filter.
598 typedef void lttv_filter
;
600 const lttv_filter
*lttvwindow_get_filter(MainWindow
*main_win
);
604 * Function to get the stats of the traceset
605 * It must be non const so the viewer can modify it.
606 * FIXME : a set/get pair of functions would be more appropriate here.
607 * @param main_win the main window the viewer belongs to.
608 * @return A pointer to Traceset statistics.
611 LttvTracesetStats
* lttvwindow_get_traceset_stats(MainWindow
*main_win
);
614 * Function to get the context of the traceset
615 * It must be non const so the viewer can add and remove hooks from it.
616 * @param main_win the main window the viewer belongs to.
617 * @return Context of the current tab.
621 LttvTracesetContext
* lttvwindow_get_traceset_context(MainWindow
*main_win
);