Focus works
[lttv.git] / ltt / branches / poly / lttv / modules / gui / lttvwindow / lttvwindow / lttvwindow.h
1 /* This file is part of the Linux Trace Toolkit Graphic User Interface
2 * Copyright (C) 2003-2004 Xiangxiu Yang, Mathieu Desnoyers
3 *
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;
7 *
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.
12 *
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,
16 * MA 02111-1307, USA.
17 */
18
19 /*
20 This file is what every viewer plugin writer should refer to.
21
22
23 Module Related API
24
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
29 this, it must register its constructor function to the main window along
30 with button description or text menu entry description. A module keeps
31 a list of every viewer that currently sits in memory so it can destroy
32 them before the module gets unloaded/destroyed.
33
34 The contructor registration to the main windows adds button and menu
35 entry to each main window, thus allowing instanciation of viewers.
36
37
38 Main Window
39
40 The main window is a container that offers menus, buttons and a
41 notebook. Some of those menus and buttons are part of the core of the
42 main window, others are dynamically added and removed when modules are
43 loaded/unloaded.
44
45 The notebook contains as much tabs as wanted. Each tab is linked with
46 a set of traces (traceset). Each trace contains many tracefiles (one
47 per cpu). A trace corresponds to a kernel being traced. A traceset
48 corresponds to many traces read together. The time span of a traceset
49 goes from the earliest start of all the traces to the latest end of all
50 the traces.
51
52 Inside each tab are added the viewers. When they interact with the main
53 window through the lttvwindow API, they affect the other viewers located
54 in the same tab as they are.
55
56 The insertion of many viewers in a tab permits a quick look at all the
57 information wanted in a glance. The main window does merge the read
58 requests from all the viewers in the same tab in a way that every viewer
59 will get exactly the events it asked for, while the event reading loop
60 and state update are shared. It improves performance of events delivery
61 to the viewers.
62
63
64
65 Viewer Instance Related API
66
67 The lifetime of a viewer is as follows. The viewer constructor function
68 is called each time an instance view is created (one subwindow of this
69 viewer type is created by the user either by clicking on the menu item
70 or the button corresponding to the viewer). Thereafter, the viewer gets
71 hooks called for different purposes by the window containing it. These
72 hooks are detailed below. It also has to deal with GTK Events. Finally,
73 it can be destructed by having its top level widget unreferenced by the
74 main window or by any GTK Event causing a "destroy-event" signal on the
75 its top widget. Another possible way for it do be destroyed is if the
76 module gets unloaded. The module unload function will have to emit a
77 "destroy" signal on each top level widget of all instances of its viewers.
78
79
80 Notices from Main Window
81
82 time_window : This is the time interval visible on the viewer's tab. Every
83 viewer that cares about being synchronised by respect to the
84 time with other viewers should register to this notification.
85 They should redraw all or part of their display when this occurs.
86
87 traceset : This notification is called whenever a trace is added/removed
88 from the traceset. As it affects all the data displayed by the
89 viewer, it sould redraw itself totally.
90
91 filter : FIXME : describe..
92
93 current_time: Being able to zoom nearer a specific time or highlight a specific
94 time on every viewer in synchronicity implies that the viewer
95 has to shown a visual sign over the drawing or select an event
96 when it receives this notice. It should also inform the main
97 window with the appropriate report API function when a user
98 selects a specific time as being the current time.
99
100 dividor : This notice links the positions of the horizontal dividors
101 between the graphic display zone of every viewer and their Y axis,
102 typically showing processes, cpus, ...
103
104
105 Reporting Changes to the Main Window
106
107 In most cases, the enclosing window knows about updates such as described
108 in the Notification section higher. There are a few cases, however, where
109 updates are caused by actions known by a view instance. For example,
110 clicking in a view may update the current time; all viewers within
111 the same window must be told about the new current time to change the
112 currently highlighted time point. A viewer reports such events by calling
113 lttvwindow_report_current_time on its lttvwindow. The lttvwindow will
114 consequently call current_time_notify for each of its contained viewers.
115
116
117 Available report methods are :
118
119 lttvwindow_report_time_window : reports the new time window.
120 lttvwindow_report_current_time : reports the new current time.
121 lttvwindow_report_dividor : reports the new horizontal dividor's position.
122
123
124
125 Requesting Events to Main Window
126
127 Events can be requested by passing a EventsRequest structure to the main
128 window. They will be delivered later when the next g_idle functions
129 will be called. Event delivery is done by calling the event hook for
130 this event ID, or the main event hooks. A pointer to the EventsRequest
131 structure is passed as hook_data to the event hooks of the viewers.
132
133 EventsRequest consists in
134 - a pointer to the viewer specific data structure
135 - a start timestamp or position
136 - a stop_flag, ending the read process when set to TRUE
137 - a end timestamp and/or position and/or number of events to read
138 - hook lists to call for traceset/trace/tracefile begin and end, and for each
139 event (event hooks and event_by_id hooks).
140
141 The main window will deliver events for every EventRequests it has
142 pending through an algorithm that guarantee that all events requested,
143 and only them, will be delivered to the viewer between the call of the
144 tracefile_begin hooks and the call of the tracefile_end hooks.
145
146 If a viewer wants to stop the event request at a certain point inside the
147 event hooks, it has to set the stop_flag to TRUE and return TRUE from the
148 hook function. Then return value will stop the process traceset. Then,
149 the main window will look for the stop_flag and remove the EventRequests
150 from its lists, calling the process_traceset_end for this request (it
151 removes hooks from the context and calls the after hooks).
152
153 It no stop_flag is risen, the end timestamp, end position or number
154 of events to read has to be reached to determine the end of the
155 request. Otherwise, the end of traceset does determine it.
156
157
158 GTK Events
159
160 Events and Signals
161
162 GTK is quite different from the other graphical toolkits around
163 there. The main difference resides in that there are many X Windows
164 inside one GtkWindow, instead of just one. That means that X events are
165 delivered by the glib main loop directly to the widget corresponding to
166 the GdkWindow affected by the X event.
167
168 Event delivery to a widget emits a signal on that widget. Then, if a
169 handler is connected to this widget's signal, it will be executed. There
170 are default handlers for signals, connected at class instantiation
171 time. There is also the possibility to connect other handlers to these
172 signals, which is what should be done in most cases when a viewer needs
173 to interact with X in any way.
174
175
176
177 Signal emission and propagation is described there :
178
179 http://www.gtk.org/tutorial/sec-signalemissionandpropagation.html
180
181 For further information on the GTK main loop (now a wrapper over glib main loop)
182 see :
183
184 http://developer.gnome.org/doc/API/2.0/gtk/gtk-General.html
185 http://developer.gnome.org/doc/API/2.0/glib/glib-The-Main-Event-Loop.html
186
187
188 For documentation on event handling in GTK/GDK, see :
189
190 http://developer.gnome.org/doc/API/2.0/gdk/gdk-Events.html
191 http://developer.gnome.org/doc/API/2.0/gdk/gdk-Event-Structures.html
192
193
194 Signals can be connected to handlers, emitted, propagated, blocked,
195 stopped. See :
196
197 http://developer.gnome.org/doc/API/2.0/gobject/gobject-Signals.html
198
199
200
201
202 The "expose_event"
203
204 Provides the exposed region in the GdkEventExpose structure.
205
206 There are two ways of dealing with exposures. The first one is to directly
207 draw on the screen and the second one is to draw in a pixmap buffer,
208 and then to update the screen when necessary.
209
210 In the first case, the expose event will be responsible for registering
211 hooks to process_traceset and require time intervals to the main
212 window. So, in this scenario, if a part of the screen is damaged, the
213 trace has to be read to redraw the screen.
214
215 In the second case, with a pixmap buffer, the expose handler is only
216 responsible of showing the pixmap buffer on the screen. If the pixmap
217 buffer has never been filled with a drawing, the expose handler may ask
218 for it to be filled.
219
220 The interest of using events request to the main window instead of reading
221 the events directly from the trace comes from the fact that the main
222 window does merge requests from the different viewers in the same tab so
223 that the read loop and the state update is shared. As viewers will, in
224 the common scenario, request the same events, only one pass through the
225 trace that will call the right hooks for the right intervals will be done.
226
227 When the traceset read is over for a events request, the traceset_end
228 hook is called. It has the responsibility of finishing the drawing if
229 some parts still need to be drawn and to show it on the screen (if the
230 viewer uses a pixmap buffer).
231
232 It can add dotted lines and such visual effects to enhance the user's
233 experience.
234
235
236 FIXME : explain other important events
237
238 */
239
240
241 #ifndef VIEWER_H
242 #define VIEWER_H
243
244 /*! \file lttvwindow.h
245 * \brief API used by the graphical viewers to interact with their top window.
246 *
247 * Main window (lttvwindow module) is the place to contain and display viewers.
248 * Viewers (lttv plugins) interact with main window through this API.
249 * This header file should be included in each graphic module.
250 *
251 */
252
253 #include <gtk/gtk.h>
254 #include <ltt/ltt.h>
255 #include <ltt/time.h>
256 #include <lttv/hook.h>
257 #include <lttv/tracecontext.h>
258 #include <lttv/stats.h>
259 #include <lttvwindow/mainwindow.h>
260 #include <lttvwindow/lttvfilter.h>
261 //FIXME (not ready yet) #include <lttv/filter.h>
262
263 /* Module Related API */
264
265
266 /* constructor a the viewer */
267 //FIXME explain LttvTracesetSelector and key
268 typedef GtkWidget * (*lttvwindow_viewer_constructor)
269 (Tab *tab, LttvTracesetSelector * s, char *key);
270
271
272 /**
273 * Function to register a view constructor so that main window can generate
274 * a menu item and a toolbar item for the viewer in order to generate a new
275 * instance easily. A menu entry and toolbar item will be added to each main
276 * window.
277 *
278 * It should be called by init function of the module.
279 *
280 * @param menu_path path of the menu item. NULL : no menu entry.
281 * @param menu_text text of the menu item.
282 * @param pixmap Image shown on the toolbar item. NULL : no button.
283 * @param tooltip tooltip of the toolbar item.
284 * @param view_constructor constructor of the viewer.
285 */
286
287 void lttvwindow_register_constructor
288 (char * menu_path,
289 char * menu_text,
290 char ** pixmap,
291 char * tooltip,
292 lttvwindow_viewer_constructor view_constructor);
293
294
295 /**
296 * Function to unregister the viewer's constructor, release the space
297 * occupied by menu_path, menu_text, pixmap, tooltip and constructor of the
298 * viewer.
299 *
300 * It will be called when a module is unloaded.
301 *
302 * @param view_constructor constructor of the viewer.
303 */
304
305 void lttvwindow_unregister_constructor
306 (lttvwindow_viewer_constructor view_constructor);
307
308
309
310
311 /* Viewer Instance Related API */
312
313 /**
314 * Structure used as hook_data for the time_window_notify hook.
315 */
316 typedef struct _TimeWindowNotifyData {
317 TimeWindow *new_time_window;
318 TimeWindow *old_time_window;
319 } TimeWindowNotifyData;
320
321
322 /**
323 * Function to register a hook function that will be called by the main window
324 * when the time interval needs to be updated.
325 *
326 * This register function is typically called by the constructor of the viewer.
327 *
328 * @param tab the tab the viewer belongs to.
329 * @param hook hook that sould be called by the main window when the time
330 * interval changes. This hook function takes a
331 * TimeWindowNotifyData* as call_data.
332 * @param hook_data hook data associated with the hook function. It will
333 * be typically a pointer to the viewer's data structure.
334 */
335
336 void lttvwindow_register_time_window_notify(Tab *tab,
337 LttvHook hook,
338 gpointer hook_data);
339
340
341 /**
342 * Function to unregister the time_window notification hook.
343 *
344 * This unregister function is typically called by the destructor of the viewer.
345 *
346 * @param tab the tab the viewer belongs to.
347 * @param hook hook that sould be called by the main window when the time
348 * interval changes. This hook function takes a
349 * TimeWindowNotifyData* as call_data.
350 * @param hook_data hook data associated with the hook function. It will
351 * be typically a pointer to the viewer's data structure.
352 */
353
354 void lttvwindow_unregister_time_window_notify(Tab *tab,
355 LttvHook hook,
356 gpointer hook_data);
357
358
359 /**
360 * Function to register a hook function that will be called by the main window
361 * when the traceset is changed. That means that the viewer must redraw
362 * itself completely or check if it's affected by the particular change to the
363 * traceset.
364 *
365 * This register function is typically called by the constructor of the viewer.
366 *
367 * @param tab the tab the viewer belongs to.
368 * @param hook hook that should be called whenever a change to the traceset
369 * occurs. The call_data of this hook is a NULL pointer.
370 * @param hook_data hook data associated with the hook function. It will
371 * be typically a pointer to the viewer's data structure.
372 */
373
374 void lttvwindow_register_traceset_notify(Tab *tab,
375 LttvHook hook,
376 gpointer hook_data);
377
378
379 /**
380 * Function to unregister the traceset_notify hook.
381 *
382 * @param tab the tab the viewer belongs to.
383 * @param hook hook that should be called whenever a change to the traceset
384 * occurs. The call_data of this hook is a NULL pointer.
385 * @param hook_data hook data associated with the hook function. It will
386 * be typically a pointer to the viewer's data structure.
387 */
388
389 void lttvwindow_unregister_traceset_notify(Tab *tab,
390 LttvHook hook,
391 gpointer hook_data);
392
393
394 /**
395 * Function to register a hook function for a viewer be completely redrawn.
396 *
397 * @param tab viewer's tab
398 * @param hook hook function of the viewer.
399 * @param hook_data hook data associated with the hook function.
400 */
401
402 void lttvwindow_register_redraw_notify(Tab *tab,
403 LttvHook hook, gpointer hook_data);
404
405 /**
406 * Function to unregister a hook function for a viewer be completely redrawn.
407 *
408 * @param tab viewer's tab
409 * @param hook hook function of the viewer.
410 * @param hook_data hook data associated with the hook function.
411 */
412
413 void lttvwindow_unregister_redraw_notify(Tab *tab,
414 LttvHook hook, gpointer hook_data);
415
416
417 /**
418 * Function to register a hook function for a viewer to re-do the events
419 * requests for the needed interval.
420 *
421 * This action is typically done after a "stop".
422 *
423 * The typical hook will remove all current requests for the viewer
424 * and make requests for missing information.
425 *
426 * @param tab viewer's tab
427 * @param hook hook function of the viewer.
428 * @param hook_data hook data associated with the hook function.
429 */
430
431 void lttvwindow_register_continue_notify(Tab *tab,
432 LttvHook hook, gpointer hook_data);
433
434
435 /**
436 * Function to unregister a hook function for a viewer to re-do the events
437 * requests for the needed interval.
438 *
439 * @param tab viewer's tab
440 * @param hook hook function of the viewer.
441 * @param hook_data hook data associated with the hook function.
442 */
443
444 void lttvwindow_unregister_continue_notify(Tab *tab,
445 LttvHook hook, gpointer hook_data);
446
447
448 /**
449 * Function to register a hook function for a viewer to set/update its
450 * filter.
451 *
452 * FIXME : Add information about what a filter is as seen from a viewer and how
453 * to use it.
454 *
455 * This register function is typically called by the constructor of the viewer.
456 *
457 * @param tab the tab the viewer belongs to.
458 * @param hook hook function called by the main window when a filter change
459 * occurs.
460 * @param hook_data hook data associated with the hook function. It will
461 * be typically a pointer to the viewer's data structure.
462 */
463
464 void lttvwindow_register_filter_notify(Tab *tab,
465 LttvHook hook,
466 gpointer hook_data);
467
468
469 /**
470 * Function to unregister a viewer's hook function which is used to
471 * set/update the filter of the viewer.
472 *
473 * This unregistration is called by the destructor of the viewer.
474 *
475 * @param tab the tab the viewer belongs to.
476 * @param hook hook function called by the main window when a filter change
477 * occurs.
478 * @param hook_data hook data associated with the hook function. It will
479 * be typically a pointer to the viewer's data structure.
480 */
481
482 void lttvwindow_unregister_filter_notify(Tab *tab,
483 LttvHook hook,
484 gpointer hook_data);
485
486
487 /**
488 * Function to register a hook function for a viewer to set/update its
489 * current time.
490 *
491 * @param tab the tab the viewer belongs to.
492 * @param hook hook function of the viewer that updates the current time. The
493 * call_data is a LttTime* representing the new current time.
494 * @param hook_data hook data associated with the hook function. It will
495 * be typically a pointer to the viewer's data structure.
496 */
497
498 void lttvwindow_register_current_time_notify(Tab *tab,
499 LttvHook hook,
500 gpointer hook_data);
501
502
503 /**
504 * Function to unregister a viewer's hook function which is used to
505 * set/update the current time of the viewer.
506 * @param tab the tab the viewer belongs to.
507 * @param hook hook function of the viewer that updates the current time. The
508 * call_data is a LttTime* representing the new current time.
509 * @param hook_data hook data associated with the hook function. It will
510 * be typically a pointer to the viewer's data structure.
511 */
512
513 void lttvwindow_unregister_current_time_notify(Tab *tab,
514 LttvHook hook,
515 gpointer hook_data);
516
517
518 /**
519 * Function to register a hook function for a viewer to set/update the
520 * dividor of the hpane. It provides a way to make the horizontal
521 * dividors of all the viewers linked together.
522 *
523 * @param tab the tab the viewer belongs to.
524 * @param hook hook function of the viewer that will be called whenever a
525 * dividor changes in another viewer. The call_data of this hook
526 * is a gint*. The value of the integer is the new position of the
527 * hpane dividor.
528 * @param hook_data hook data associated with the hook function. It will
529 * be typically a pointer to the viewer's data structure.
530 */
531
532 void lttvwindow_register_dividor(Tab *tab,
533 LttvHook hook,
534 gpointer hook_data);
535
536
537 /**
538 * Function to unregister a viewer's hook function which is used to
539 * set/update hpane's dividor of the viewer.
540 *
541 * @param tab the tab the viewer belongs to.
542 * @param hook hook function of the viewer that will be called whenever a
543 * dividor changes in another viewer. The call_data of this hook
544 * is a gint*. The value of the integer is the new position of the
545 * hpane dividor.
546 * @param hook_data hook data associated with the hook function. It will
547 * be typically a pointer to the viewer's data structure.
548 */
549
550 void lttvwindow_unregister_dividor(Tab *tab,
551 LttvHook hook,
552 gpointer hook_data);
553
554
555
556 /**
557 * Function to set the time interval of the current tab.a
558 *
559 * @param tab the tab the viewer belongs to.
560 * @param time_interval new time window.
561 */
562
563 void lttvwindow_report_time_window(Tab *tab,
564 TimeWindow time_window);
565
566 /**
567 * Function to set the current time/event of the current tab.
568 * It will be called by a viewer's signal handle associated with
569 * the button-release-event signal
570 * @param tab the tab the viewer belongs to.
571 * @param new current time.
572 */
573
574 void lttvwindow_report_current_time(Tab *tab,
575 LttTime time);
576
577
578 /**
579 * Function to set the position of the hpane's dividor (viewer).
580 * It will typically be called by a viewer's signal handle associated
581 * with the motion_notify_event event/signal.
582 *
583 * @param tab the tab the viewer belongs to.
584 * @param position position of the hpane's dividor.
585 */
586
587 void lttvwindow_report_dividor(Tab *tab, gint position);
588
589
590 /* Structure sent to the events request hook */
591 /* Value considered as empty*/
592 typedef struct _EventsRequest {
593 gpointer owner; /* Owner of the request */
594 gpointer viewer_data; /* Unset : NULL */
595 gboolean servicing; /* service in progress: TRUE*/
596 LttTime start_time; /* Unset : ltt_time_infinite*/
597 LttvTracesetContextPosition *start_position; /* Unset : NULL */
598 gboolean stop_flag; /* Continue:TRUE Stop:FALSE */
599 LttTime end_time; /* Unset : ltt_time_infinite*/
600 guint num_events; /* Unset : G_MAXUINT */
601 LttvTracesetContextPosition *end_position; /* Unset : NULL */
602 LttvHooks *before_chunk_traceset; /* Unset : NULL */
603 LttvHooks *before_chunk_trace; /* Unset : NULL */
604 LttvHooks *before_chunk_tracefile;/* Unset : NULL */
605 LttvHooks *event; /* Unset : NULL */
606 LttvHooksById *event_by_id; /* Unset : NULL */
607 LttvHooks *after_chunk_tracefile; /* Unset : NULL */
608 LttvHooks *after_chunk_trace; /* Unset : NULL */
609 LttvHooks *after_chunk_traceset; /* Unset : NULL */
610 LttvHooks *before_request; /* Unset : NULL */
611 LttvHooks *after_request; /* Unset : NULL */
612 } EventsRequest;
613
614 /* Maximum number of events to proceed at once in a chunk */
615 #define CHUNK_NUM_EVENTS 200
616
617
618 /**
619 * Function to request data in a specific time interval to the main window. The
620 * event request servicing is differed until the glib idle functions are
621 * called.
622 *
623 * The viewer has to provide hooks that should be associated with the event
624 * request.
625 *
626 * Either start time or start position must be defined in a EventRequest
627 * structure for it to be valid.
628 *
629 * end_time, end_position and num_events can all be defined. The first one
630 * to occur will be used as end criterion.
631 *
632 * The events_request memory will be managed by the main window once its
633 * pointer is passed by this function.
634 *
635 * @param tab the tab the viewer belongs to.
636 * @param events_requested Details about the event request.
637 */
638
639 void lttvwindow_events_request(Tab *tab,
640 EventsRequest *events_request);
641
642 /**
643 * Function to remove data requests related to a viewer.
644 *
645 * The existing requests's viewer gpointer is compared to the pointer
646 * given in argument to establish which data request should be removed.
647 *
648 * @param tab the tab the viewer belongs to.
649 * @param viewer a pointer to the viewer data structure
650 */
651
652 void lttvwindow_events_request_remove_all(Tab *tab,
653 gconstpointer viewer);
654
655
656 /**
657 * Function to get the current time window of the current tab.
658 *
659 * @param tab the tab the viewer belongs to.
660 * @return the current tab's time interval.
661 */
662
663 TimeWindow lttvwindow_get_time_window(Tab *tab);
664
665
666 /**
667 * Function to get the current time of the current tab.
668 *
669 * @param tab the tab the viewer belongs to.
670 * @return the current tab's current time.
671 */
672
673 LttTime lttvwindow_get_current_time(Tab *tab);
674
675
676 /**
677 * Function to get the filter of the current tab.
678 * @param main_win, the main window the viewer belongs to.
679 * @param filter, a pointer to a filter.
680 */
681
682 //FIXME
683 typedef void lttv_filter;
684 //FIXME
685 const lttv_filter *lttvwindow_get_filter(Tab *tab);
686
687
688 /**
689 * Function to get the stats of the traceset
690 * It must be non const so the viewer can modify it.
691 * FIXME : a set/get pair of functions would be more appropriate here.
692 * @param tab the tab the viewer belongs to.
693 * @return A pointer to Traceset statistics.
694 */
695
696 LttvTracesetStats* lttvwindow_get_traceset_stats(Tab *tab);
697
698 /**
699 * Function to get the context of the traceset
700 * It must be non const so the viewer can add and remove hooks from it.
701 * @param tab the tab the viewer belongs to.
702 * @return Context of the current tab.
703 */
704
705
706 LttvTracesetContext* lttvwindow_get_traceset_context(Tab *tab);
707
708
709 #endif //VIEWER_H
This page took 0.043593 seconds and 4 git commands to generate.