put print fields in print.c
[lttv.git] / ltt / branches / poly / lttv / modules / gui / lttvwindow / lttvwindow / lttvwindow.c
CommitLineData
501e4e70 1/* This file is part of the Linux Trace Toolkit viewer
2 * Copyright (C) 2003-2004 XangXiu Yang
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/*! \file lttvwindow.c
20 * \brief API used by the graphical viewers to interact with their tab.
21 *
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
27 * main window.
28 *
29 */
30
4e4d11b3 31#ifdef HAVE_CONFIG_H
32#include <config.h>
33#endif
34
501e4e70 35#include <ltt/ltt.h>
36#include <lttv/lttv.h>
37#include <lttv/state.h>
38#include <lttv/stats.h>
39#include <lttv/tracecontext.h>
501e4e70 40#include <lttvwindow/mainwindow.h>
2d262115 41#include <lttvwindow/mainwindow-private.h>
501e4e70 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>
47
501e4e70 48/**
49 * Internal function parts
50 */
51
52extern GSList * g_main_window_list;
53
b052368a 54/* set_time_window
55 *
56 * It updates the time window of the tab, then calls the updatetimewindow
57 * hooks of each viewer.
58 *
59 * This is called whenever the scrollbar value changes.
60 */
501e4e70 61
62void set_time_window(Tab *tab, const TimeWindow *time_window)
63{
64 LttvAttributeValue value;
65 LttvHooks * tmp;
66
67 TimeWindowNotifyData time_window_notify_data;
68 TimeWindow old_time_window = tab->time_window;
69 time_window_notify_data.old_time_window = &old_time_window;
70 tab->time_window = *time_window;
71 time_window_notify_data.new_time_window =
72 &(tab->time_window);
73
74 g_assert(lttv_iattribute_find_by_path(tab->attributes,
75 "hooks/updatetimewindow", LTTV_POINTER, &value));
76 tmp = (LttvHooks*)*(value.v_pointer);
b052368a 77 if(tmp != NULL) lttv_hooks_call(tmp, &time_window_notify_data);
501e4e70 78
b052368a 79 //gtk_multi_vpaned_set_adjust(tab->multi_vpaned, new_time_window, FALSE);
501e4e70 80
81}
82
db8bc917 83/* set_current_time
84 *
85 * It updates the current time of the tab, then calls the updatetimewindow
86 * hooks of each viewer.
87 *
88 * This is called whenever the current time value changes.
89 */
90
91void set_current_time(Tab *tab, const LttTime *current_time)
92{
93 LttvAttributeValue value;
94 LttvHooks * tmp;
95
96 tab->current_time = *current_time;
97
98 g_assert(lttv_iattribute_find_by_path(tab->attributes,
99 "hooks/updatecurrenttime", LTTV_POINTER, &value));
100 tmp = (LttvHooks*)*(value.v_pointer);
101 if(tmp != NULL) lttv_hooks_call(tmp, &tab->current_time);
102}
103
501e4e70 104void add_toolbar_constructor(MainWindow *mw, LttvToolbarClosure *toolbar_c)
105{
106 LttvIAttribute *attributes = mw->attributes;
107 LttvAttributeValue value;
108 LttvToolbars * instance_toolbar;
109 lttvwindow_viewer_constructor constructor;
110 GtkWidget * tool_menu_title_menu, *new_widget, *pixmap;
111 GdkPixbuf *pixbuf;
112
113 g_assert(lttv_iattribute_find_by_path(attributes,
114 "viewers/toolbar", LTTV_POINTER, &value));
115 if(*(value.v_pointer) == NULL)
116 *(value.v_pointer) = lttv_toolbars_new();
117 instance_toolbar = (LttvToolbars*)*(value.v_pointer);
118
119 constructor = toolbar_c->con;
120 tool_menu_title_menu = lookup_widget(mw->mwindow,"MToolbar1");
121 pixbuf = gdk_pixbuf_new_from_xpm_data((const char**)toolbar_c->pixmap);
122 pixmap = gtk_image_new_from_pixbuf(pixbuf);
123 new_widget =
124 gtk_toolbar_append_element (GTK_TOOLBAR (tool_menu_title_menu),
125 GTK_TOOLBAR_CHILD_BUTTON,
126 NULL,
127 "",
128 toolbar_c->tooltip, NULL,
129 pixmap, NULL, NULL);
130 gtk_label_set_use_underline(
131 GTK_LABEL (((GtkToolbarChild*) (
132 g_list_last (GTK_TOOLBAR
133 (tool_menu_title_menu)->children)->data))->label),
134 TRUE);
135 gtk_container_set_border_width (GTK_CONTAINER (new_widget), 1);
136 g_signal_connect ((gpointer) new_widget,
137 "clicked",
138 G_CALLBACK (insert_viewer_wrap),
139 constructor);
140 gtk_widget_show (new_widget);
141
142 lttv_toolbars_add(instance_toolbar, toolbar_c->con,
143 toolbar_c->tooltip,
144 toolbar_c->pixmap,
145 new_widget);
146
147}
148
149void add_menu_constructor(MainWindow *mw, LttvMenuClosure *menu_c)
150{
151 LttvIAttribute *attributes = mw->attributes;
152 LttvAttributeValue value;
153 LttvToolbars * instance_menu;
154 lttvwindow_viewer_constructor constructor;
155 GtkWidget * tool_menu_title_menu, *new_widget;
156
157 g_assert(lttv_iattribute_find_by_path(attributes,
158 "viewers/menu", LTTV_POINTER, &value));
159 if(*(value.v_pointer) == NULL)
160 *(value.v_pointer) = lttv_menus_new();
161 instance_menu = (LttvMenus*)*(value.v_pointer);
162
163
164 constructor = menu_c->con;
165 tool_menu_title_menu = lookup_widget(mw->mwindow,"ToolMenuTitle_menu");
166 new_widget =
167 gtk_menu_item_new_with_mnemonic (menu_c->menu_text);
168 gtk_container_add (GTK_CONTAINER (tool_menu_title_menu),
169 new_widget);
170 g_signal_connect ((gpointer) new_widget, "activate",
171 G_CALLBACK (insert_viewer_wrap),
172 constructor);
173 gtk_widget_show (new_widget);
174 lttv_menus_add(instance_menu, menu_c->con,
175 menu_c->menu_path,
176 menu_c->menu_text,
177 new_widget);
178}
179
180void remove_toolbar_constructor(MainWindow *mw, lttvwindow_viewer_constructor viewer_constructor)
181{
182 LttvIAttribute *attributes = mw->attributes;
183 LttvAttributeValue value;
184 LttvToolbars * instance_toolbar;
185 lttvwindow_viewer_constructor constructor;
186 GtkWidget * tool_menu_title_menu, *widget;
187
188 g_assert(lttv_iattribute_find_by_path(attributes,
189 "viewers/toolbar", LTTV_POINTER, &value));
190 if(*(value.v_pointer) == NULL)
191 *(value.v_pointer) = lttv_toolbars_new();
192 instance_toolbar = (LttvToolbars*)*(value.v_pointer);
193
194 tool_menu_title_menu = lookup_widget(mw->mwindow,"MToolbar1");
195 widget = lttv_menus_remove(instance_toolbar, viewer_constructor);
196 gtk_container_remove (GTK_CONTAINER (tool_menu_title_menu),
197 widget);
198}
199
200
201void remove_menu_constructor(MainWindow *mw, lttvwindow_viewer_constructor viewer_constructor)
202{
203 LttvIAttribute *attributes = mw->attributes;
204 LttvAttributeValue value;
205 LttvMenus * instance_menu;
206 lttvwindow_viewer_constructor constructor;
207 GtkWidget * tool_menu_title_menu, *widget;
208 LttvMenuClosure *menu_item_i;
209
210 g_assert(lttv_iattribute_find_by_path(attributes,
211 "viewers/menu", LTTV_POINTER, &value));
212 if(*(value.v_pointer) == NULL)
213 *(value.v_pointer) = lttv_menus_new();
214 instance_menu = (LttvMenus*)*(value.v_pointer);
215
216 widget = lttv_menus_remove(instance_menu, viewer_constructor);
217 tool_menu_title_menu = lookup_widget(mw->mwindow,"ToolMenuTitle_menu");
218 gtk_container_remove (GTK_CONTAINER (tool_menu_title_menu), widget);
219}
220
221
222/**
223 * API parts
224 */
225
226
227/**
228 * Function to register a view constructor so that main window can generate
229 * a menu item and a toolbar item for the viewer in order to generate a new
230 * instance easily. A menu entry and toolbar item will be added to each main
231 * window.
232 *
233 * It should be called by init function of the module.
234 *
e025a729 235 * @param name name of the viewer
501e4e70 236 * @param menu_path path of the menu item.
237 * @param menu_text text of the menu item.
238 * @param pixmap Image shown on the toolbar item.
239 * @param tooltip tooltip of the toolbar item.
240 * @param view_constructor constructor of the viewer.
241 */
242
243void lttvwindow_register_constructor
e025a729 244 (char * name,
245 char * menu_path,
501e4e70 246 char * menu_text,
247 char ** pixmap,
248 char * tooltip,
249 lttvwindow_viewer_constructor view_constructor)
250{
251 LttvIAttribute *attributes_global = LTTV_IATTRIBUTE(lttv_global_attributes());
252 LttvToolbars * toolbar;
253 LttvMenus * menu;
254 LttvToolbarClosure toolbar_c;
255 LttvMenuClosure menu_c;
256 LttvAttributeValue value;
257
e025a729 258 if(view_constructor == NULL) return;
259
501e4e70 260 if(pixmap != NULL) {
261 g_assert(lttv_iattribute_find_by_path(attributes_global,
262 "viewers/toolbar", LTTV_POINTER, &value));
263 toolbar = (LttvToolbars*)*(value.v_pointer);
264
265 if(toolbar == NULL) {
266 toolbar = lttv_toolbars_new();
267 *(value.v_pointer) = toolbar;
268 }
269 toolbar_c = lttv_toolbars_add(toolbar, view_constructor, tooltip, pixmap,
270 NULL);
271
272 g_slist_foreach(g_main_window_list,
273 (gpointer)add_toolbar_constructor,
274 &toolbar_c);
275 }
276
277 if(menu_path != NULL) {
278 g_assert(lttv_iattribute_find_by_path(attributes_global,
279 "viewers/menu", LTTV_POINTER, &value));
280 menu = (LttvMenus*)*(value.v_pointer);
281
282 if(menu == NULL) {
283 menu = lttv_menus_new();
284 *(value.v_pointer) = menu;
285 }
286 menu_c = lttv_menus_add(menu, view_constructor, menu_path, menu_text,NULL);
287
288 g_slist_foreach(g_main_window_list,
289 (gpointer)add_menu_constructor,
290 &menu_c);
291 }
e025a729 292 {
293 LttvAttribute *attribute;
294 g_assert(attribute =
295 LTTV_ATTRIBUTE(lttv_iattribute_find_subdir(
296 LTTV_IATTRIBUTE(attributes_global),
297 LTTV_VIEWER_CONSTRUCTORS)));
298
299 g_assert(lttv_iattribute_find_by_path(LTTV_IATTRIBUTE(attribute),
300 name, LTTV_POINTER, &value));
301
302 *(value.v_pointer) = view_constructor;
303
304 }
501e4e70 305}
306
307
308/**
309 * Function to unregister the viewer's constructor, release the space
310 * occupied by menu_path, menu_text, pixmap, tooltip and constructor of the
311 * viewer.
312 *
313 * It will be called when a module is unloaded.
314 *
315 * @param view_constructor constructor of the viewer.
316 */
317
318
319void lttvwindow_unregister_constructor
320 (lttvwindow_viewer_constructor view_constructor)
321{
322 LttvIAttribute *attributes_global = LTTV_IATTRIBUTE(lttv_global_attributes());
323 LttvToolbars * toolbar;
324 LttvMenus * menu;
325 LttvAttributeValue value;
326
327 g_assert(lttv_iattribute_find_by_path(attributes_global,
328 "viewers/toolbar", LTTV_POINTER, &value));
329 toolbar = (LttvToolbars*)*(value.v_pointer);
330
331 if(toolbar != NULL) {
332 g_slist_foreach(g_main_window_list,
333 (gpointer)remove_toolbar_constructor,
334 view_constructor);
335 lttv_toolbars_remove(toolbar, view_constructor);
336 }
337
338 g_assert(lttv_iattribute_find_by_path(attributes_global,
339 "viewers/menu", LTTV_POINTER, &value));
340 menu = (LttvMenus*)*(value.v_pointer);
341
342 if(menu != NULL) {
343 g_slist_foreach(g_main_window_list,
344 (gpointer)remove_menu_constructor,
345 view_constructor);
346 lttv_menus_remove(menu, view_constructor);
347 }
e025a729 348
349 {
350 LttvAttribute *attribute;
351 g_assert(attribute =
352 LTTV_ATTRIBUTE(lttv_iattribute_find_subdir(
353 LTTV_IATTRIBUTE(attributes_global),
354 LTTV_VIEWER_CONSTRUCTORS)));
355
356 guint num = lttv_iattribute_get_number(LTTV_IATTRIBUTE(attribute));
357 guint i;
358 LttvAttributeName name;
359 LttvAttributeValue value;
360 LttvAttributeType type;
361
362 for(i=0;i<num;i++) {
363 type = lttv_iattribute_get(LTTV_IATTRIBUTE(attribute), i, &name, &value);
364 g_assert(type == LTTV_POINTER);
365 if(*(value.v_pointer) == view_constructor) {
366 lttv_iattribute_remove(LTTV_IATTRIBUTE(attribute), i);
367 break;
368 }
369 }
370 }
501e4e70 371}
372
373
374/**
375 * Function to register a hook function for a viewer to set/update its
376 * time interval.
377 * @param tab viewer's tab
378 * @param hook hook function of the viewer.
379 * @param hook_data hook data associated with the hook function.
380 */
381void lttvwindow_register_time_window_notify(Tab *tab,
382 LttvHook hook, gpointer hook_data)
383{
384 LttvAttributeValue value;
385 LttvHooks * tmp;
386 g_assert(lttv_iattribute_find_by_path(tab->attributes,
387 "hooks/updatetimewindow", LTTV_POINTER, &value));
388 tmp = (LttvHooks*)*(value.v_pointer);
389 if(tmp == NULL){
390 tmp = lttv_hooks_new();
391 *(value.v_pointer) = tmp;
392 }
393 lttv_hooks_add(tmp, hook,hook_data, LTTV_PRIO_DEFAULT);
394}
395
396
397/**
398 * Function to unregister a viewer's hook function which is used to
399 * set/update the time interval of the viewer.
400 * @param tab viewer's tab
401 * @param hook hook function of the viewer.
402 * @param hook_data hook data associated with the hook function.
403 */
404
405void lttvwindow_unregister_time_window_notify(Tab *tab,
406 LttvHook hook, gpointer hook_data)
407{
408 LttvAttributeValue value;
409 LttvHooks * tmp;
410 g_assert(lttv_iattribute_find_by_path(tab->attributes,
411 "hooks/updatetimewindow", LTTV_POINTER, &value));
412 tmp = (LttvHooks*)*(value.v_pointer);
413 if(tmp == NULL) return;
414 lttv_hooks_remove_data(tmp, hook, hook_data);
415}
416
417/**
418 * Function to register a hook function for a viewer to set/update its
419 * traceset.
420 * @param tab viewer's tab
421 * @param hook hook function of the viewer.
422 * @param hook_data hook data associated with the hook function.
423 */
424
425void lttvwindow_register_traceset_notify(Tab *tab,
426 LttvHook hook, gpointer hook_data)
427{
428 LttvAttributeValue value;
429 LttvHooks * tmp;
430 g_assert(lttv_iattribute_find_by_path(tab->attributes,
431 "hooks/updatetraceset", LTTV_POINTER, &value));
432 tmp = (LttvHooks*)*(value.v_pointer);
433 if(tmp == NULL){
434 tmp = lttv_hooks_new();
435 *(value.v_pointer) = tmp;
436 }
437 lttv_hooks_add(tmp, hook, hook_data, LTTV_PRIO_DEFAULT);
438}
439
440
441/**
442 * Function to unregister a viewer's hook function which is used to
443 * set/update the traceset of the viewer.
444 * @param tab viewer's tab
445 * @param hook hook function of the viewer.
446 * @param hook_data hook data associated with the hook function.
447 */
448
449void lttvwindow_unregister_traceset_notify(Tab *tab,
450 LttvHook hook, gpointer hook_data)
451{
452 LttvAttributeValue value;
453 LttvHooks * tmp;
454 g_assert(lttv_iattribute_find_by_path(tab->attributes,
455 "hooks/updatetraceset", LTTV_POINTER, &value));
456 tmp = (LttvHooks*)*(value.v_pointer);
457 if(tmp == NULL) return;
458 lttv_hooks_remove_data(tmp, hook, hook_data);
459}
460
9878c8a4 461/**
462 * Function to register a hook function for a viewer be completely redrawn.
463 *
464 * @param tab viewer's tab
465 * @param hook hook function of the viewer.
466 * @param hook_data hook data associated with the hook function.
467 */
468
469void lttvwindow_register_redraw_notify(Tab *tab,
470 LttvHook hook, gpointer hook_data)
471{
472 LttvAttributeValue value;
473 LttvHooks * tmp;
474 g_assert(lttv_iattribute_find_by_path(tab->attributes,
475 "hooks/redraw", LTTV_POINTER, &value));
476 tmp = (LttvHooks*)*(value.v_pointer);
477 if(tmp == NULL){
478 tmp = lttv_hooks_new();
479 *(value.v_pointer) = tmp;
480 }
481 lttv_hooks_add(tmp, hook, hook_data, LTTV_PRIO_DEFAULT);
482}
483
484
485/**
486 * Function to unregister a hook function for a viewer be completely redrawn.
487 *
488 * @param tab viewer's tab
489 * @param hook hook function of the viewer.
490 * @param hook_data hook data associated with the hook function.
491 */
492
493void lttvwindow_unregister_redraw_notify(Tab *tab,
494 LttvHook hook, gpointer hook_data)
495{
496 LttvAttributeValue value;
497 LttvHooks * tmp;
498 g_assert(lttv_iattribute_find_by_path(tab->attributes,
499 "hooks/redraw", LTTV_POINTER, &value));
500 tmp = (LttvHooks*)*(value.v_pointer);
501 if(tmp == NULL) return;
502 lttv_hooks_remove_data(tmp, hook, hook_data);
503}
504
505/**
506 * Function to register a hook function for a viewer to re-do the events
507 * requests for the needed interval.
508 *
509 * This action is typically done after a "stop".
510 *
511 * The typical hook will remove all current requests for the viewer
512 * and make requests for missing information.
513 *
514 * @param tab viewer's tab
515 * @param hook hook function of the viewer.
516 * @param hook_data hook data associated with the hook function.
517 */
518
519void lttvwindow_register_continue_notify(Tab *tab,
520 LttvHook hook, gpointer hook_data)
521{
522 LttvAttributeValue value;
523 LttvHooks * tmp;
524 g_assert(lttv_iattribute_find_by_path(tab->attributes,
525 "hooks/continue", LTTV_POINTER, &value));
526 tmp = (LttvHooks*)*(value.v_pointer);
527 if(tmp == NULL){
528 tmp = lttv_hooks_new();
529 *(value.v_pointer) = tmp;
530 }
531 lttv_hooks_add(tmp, hook, hook_data, LTTV_PRIO_DEFAULT);
532}
533
534
535/**
536 * Function to unregister a hook function for a viewer to re-do the events
537 * requests for the needed interval.
538 *
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.
542 */
543
544void lttvwindow_unregister_continue_notify(Tab *tab,
545 LttvHook hook, gpointer hook_data)
546{
547 LttvAttributeValue value;
548 LttvHooks * tmp;
549 g_assert(lttv_iattribute_find_by_path(tab->attributes,
550 "hooks/continue", LTTV_POINTER, &value));
551 tmp = (LttvHooks*)*(value.v_pointer);
552 if(tmp == NULL) return;
553 lttv_hooks_remove_data(tmp, hook, hook_data);
554}
555
556
501e4e70 557/**
558 * Function to register a hook function for a viewer to set/update its
559 * filter.
560 * @param tab viewer's tab
561 * @param hook hook function of the viewer.
562 * @param hook_data hook data associated with the hook function.
563 */
564
565void lttvwindow_register_filter_notify(Tab *tab,
566 LttvHook hook, gpointer hook_data)
567{
568 LttvAttributeValue value;
569 LttvHooks * tmp;
570 g_assert(lttv_iattribute_find_by_path(tab->attributes,
571 "hooks/updatefilter", LTTV_POINTER, &value));
572 tmp = (LttvHooks*)*(value.v_pointer);
573 if(tmp == NULL){
574 tmp = lttv_hooks_new();
575 *(value.v_pointer) = tmp;
576 }
577 lttv_hooks_add(tmp, hook, hook_data, LTTV_PRIO_DEFAULT);
578}
579
580
581/**
582 * Function to unregister a viewer's hook function which is used to
583 * set/update the filter of the viewer.
584 * @param tab viewer's tab
585 * @param hook hook function of the viewer.
586 * @param hook_data hook data associated with the hook function.
587 */
588
589void lttvwindow_unregister_filter_notify(Tab *tab,
590 LttvHook hook,
591 gpointer hook_data)
592{
593 LttvAttributeValue value;
594 LttvHooks * tmp;
595 g_assert(lttv_iattribute_find_by_path(tab->attributes,
596 "hooks/updatefilter", LTTV_POINTER, &value));
597 tmp = (LttvHooks*)*(value.v_pointer);
598 if(tmp == NULL) return;
599 lttv_hooks_remove_data(tmp, hook, hook_data);
600}
601
602/**
603 * Function to register a hook function for a viewer to set/update its
604 * current time.
605 * @param tab viewer's tab
606 * @param hook hook function of the viewer.
607 * @param hook_data hook data associated with the hook function.
608 */
609
610void lttvwindow_register_current_time_notify(Tab *tab,
611 LttvHook hook, gpointer hook_data)
612{
613 LttvAttributeValue value;
614 LttvHooks * tmp;
615 g_assert(lttv_iattribute_find_by_path(tab->attributes,
616 "hooks/updatecurrenttime", LTTV_POINTER, &value));
617 tmp = (LttvHooks*)*(value.v_pointer);
618 if(tmp == NULL){
619 tmp = lttv_hooks_new();
620 *(value.v_pointer) = tmp;
621 }
622 lttv_hooks_add(tmp, hook, hook_data, LTTV_PRIO_DEFAULT);
623}
624
625
626/**
627 * Function to unregister a viewer's hook function which is used to
628 * set/update the current time of the viewer.
629 * @param tab viewer's tab
630 * @param hook hook function of the viewer.
631 * @param hook_data hook data associated with the hook function.
632 */
633
634void lttvwindow_unregister_current_time_notify(Tab *tab,
635 LttvHook hook, gpointer hook_data)
636{
637 LttvAttributeValue value;
638 LttvHooks * tmp;
639 g_assert(lttv_iattribute_find_by_path(tab->attributes,
640 "hooks/updatecurrenttime", LTTV_POINTER, &value));
641 tmp = (LttvHooks*)*(value.v_pointer);
642 if(tmp == NULL) return;
643 lttv_hooks_remove_data(tmp, hook, hook_data);
644}
645
646
647/**
648 * Function to register a hook function for a viewer to show
649 * the content of the viewer.
650 * @param tab viewer's tab
651 * @param hook hook function of the viewer.
652 * @param hook_data hook data associated with the hook function.
653 */
654
655void lttvwindow_register_show_notify(Tab *tab,
656 LttvHook hook, gpointer hook_data)
657{
658 LttvAttributeValue value;
659 LttvHooks * tmp;
660 g_assert(lttv_iattribute_find_by_path(tab->attributes,
661 "hooks/showviewer", LTTV_POINTER, &value));
662 tmp = (LttvHooks*)*(value.v_pointer);
663 if(tmp == NULL){
664 tmp = lttv_hooks_new();
665 *(value.v_pointer) = tmp;
666 }
667 lttv_hooks_add(tmp, hook, hook_data, LTTV_PRIO_DEFAULT);
668}
669
670
671/**
672 * Function to unregister a viewer's hook function which is used to
673 * show the content of the viewer..
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.
677 */
678
679void lttvwindow_unregister_show_notify(Tab *tab,
680 LttvHook hook, gpointer hook_data)
681{
682 LttvAttributeValue value;
683 LttvHooks * tmp;
684 g_assert(lttv_iattribute_find_by_path(tab->attributes,
685 "hooks/showviewer", LTTV_POINTER, &value));
686 tmp = (LttvHooks*)*(value.v_pointer);
687 if(tmp == NULL) return;
688 lttv_hooks_remove_data(tmp, hook, hook_data);
689}
690
691/**
692 * Function to register a hook function for a viewer to set/update the
693 * dividor of the hpane.
694 * @param tab viewer's tab
695 * @param hook hook function of the viewer.
696 * @param hook_data hook data associated with the hook function.
697 */
698
699void lttvwindow_register_dividor(Tab *tab,
700 LttvHook hook, gpointer hook_data)
701{
702 LttvAttributeValue value;
703 LttvHooks * tmp;
704 g_assert(lttv_iattribute_find_by_path(tab->attributes,
705 "hooks/hpanedividor", LTTV_POINTER, &value));
706 tmp = (LttvHooks*)*(value.v_pointer);
707 if(tmp == NULL){
708 tmp = lttv_hooks_new();
709 *(value.v_pointer) = tmp;
710 }
711 lttv_hooks_add(tmp, hook, hook_data, LTTV_PRIO_DEFAULT);
712}
713
714
715/**
716 * Function to unregister a viewer's hook function which is used to
717 * set/update hpane's dividor of the viewer.
718 * It will be called by the destructor 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.
722 */
723
724void lttvwindow_unregister_dividor(Tab *tab,
725 LttvHook hook, gpointer hook_data)
726{
727 LttvAttributeValue value;
728 LttvHooks * tmp;
729 g_assert(lttv_iattribute_find_by_path(tab->attributes,
730 "hooks/hpanedividor", LTTV_POINTER, &value));
731 tmp = (LttvHooks*)*(value.v_pointer);
732 if(tmp == NULL) return;
733 lttv_hooks_remove_data(tmp, hook, hook_data);
734}
735
736
501e4e70 737/**
738 * Function to set the time interval of the current tab.
739 * It will be called by a viewer's signal handle associated with
740 * the move_slider signal
741 * @param tab viewer's tab
742 * @param time_interval a pointer where time interval is stored.
743 */
744
745void lttvwindow_report_time_window(Tab *tab,
e800cf84 746 TimeWindow time_window)
501e4e70 747{
b052368a 748 //set_time_window(tab, time_window);
749 //set_time_window_adjustment(tab, time_window);
750
e800cf84 751 time_change_manager(tab, time_window);
752
753
754#if 0
b052368a 755 /* Set scrollbar */
756 LttvTracesetContext *tsc =
757 LTTV_TRACESET_CONTEXT(tab->traceset_info->traceset_context);
758 TimeInterval time_span = tsc->time_span;
759 GtkAdjustment *adjustment = gtk_range_get_adjustment(GTK_RANGE(tab->scrollbar));
b052368a 760 g_object_set(G_OBJECT(adjustment),
761 "lower",
0c5dbe3b 762 0.0, /* lower */
b052368a 763 "upper",
b9a010a2 764 ltt_time_to_double(
765 ltt_time_sub(time_span.end_time, time_span.start_time))
c74e0cf9 766 , /* upper */
b052368a 767 "step_increment",
768 ltt_time_to_double(time_window->time_width)
769 / SCROLL_STEP_PER_PAGE
c74e0cf9 770 , /* step increment */
b052368a 771 "page_increment",
772 ltt_time_to_double(time_window->time_width)
c74e0cf9 773 , /* page increment */
b052368a 774 "page_size",
775 ltt_time_to_double(time_window->time_width)
c74e0cf9 776 , /* page size */
b052368a 777 NULL);
778 gtk_adjustment_changed(adjustment);
779
780 //g_object_set(G_OBJECT(adjustment),
781 // "value",
782 // ltt_time_to_double(time_window->start_time)
c74e0cf9 783 // , /* value */
b052368a 784 // NULL);
785 /* Note : the set value will call set_time_window if scrollbar value changed
786 */
787 gtk_adjustment_set_value(adjustment,
b9a010a2 788 ltt_time_to_double(
789 ltt_time_sub(time_window->start_time,
790 time_span.start_time))
c74e0cf9 791 );
e800cf84 792#endif //0
501e4e70 793}
794
795
796/**
797 * Function to set the current time/event of the current tab.
798 * It will be called by a viewer's signal handle associated with
799 * the button-release-event signal
800 * @param tab viewer's tab
801 * @param time a pointer where time is stored.
802 */
803
804void lttvwindow_report_current_time(Tab *tab,
e800cf84 805 LttTime time)
501e4e70 806{
807 LttvAttributeValue value;
808 LttvHooks * tmp;
e800cf84 809
810 current_time_change_manager(tab, time);
501e4e70 811}
812
813/**
814 * Function to set the position of the hpane's dividor (viewer).
815 * It will be called by a viewer's signal handle associated with
816 * the motion_notify_event event/signal
817 * @param tab viewer's tab
818 * @param position position of the hpane's dividor.
819 */
820
821void lttvwindow_report_dividor(Tab *tab, gint position)
822{
823 LttvAttributeValue value;
824 LttvHooks * tmp;
825 g_assert(lttv_iattribute_find_by_path(tab->attributes,
826 "hooks/hpanedividor", LTTV_POINTER, &value));
827 tmp = (LttvHooks*)*(value.v_pointer);
828 if(tmp == NULL) return;
829 lttv_hooks_call(tmp, &position);
830}
831
501e4e70 832/**
833 * Function to request data in a specific time interval to the main window. The
834 * event request servicing is differed until the glib idle functions are
835 * called.
836 *
837 * The viewer has to provide hooks that should be associated with the event
838 * request.
839 *
840 * Either start time or start position must be defined in a EventRequest
841 * structure for it to be valid.
842 *
843 * end_time, end_position and num_events can all be defined. The first one
844 * to occur will be used as end criterion.
845 *
846 * @param tab viewer's tab
847 * @param events_requested the structure of request from.
848 */
849
850void lttvwindow_events_request(Tab *tab,
20fde85f 851 EventsRequest *events_request)
501e4e70 852{
20fde85f 853 tab->events_requests = g_slist_append(tab->events_requests, events_request);
501e4e70 854
855 if(!tab->events_request_pending)
856 {
553d1e7b 857 /* Redraw has +20 priority. We want to let the redraw be done while we do
858 * our job. */
859 g_idle_add_full((G_PRIORITY_HIGH_IDLE + 21),
501e4e70 860 (GSourceFunc)execute_events_requests,
861 tab,
862 NULL);
863 tab->events_request_pending = TRUE;
864 }
865}
866
867
868/**
869 * Function to remove data requests related to a viewer.
870 *
871 * The existing requests's viewer gpointer is compared to the pointer
872 * given in argument to establish which data request should be removed.
873 *
874 * @param tab the tab the viewer belongs to.
875 * @param viewer a pointer to the viewer data structure
876 */
877
878gint find_viewer (const EventsRequest *a, gconstpointer b)
879{
2d262115 880 return (a->owner != b);
501e4e70 881}
882
883
884void lttvwindow_events_request_remove_all(Tab *tab,
885 gconstpointer viewer)
886{
6843100a 887 GSList *element = tab->events_requests;
501e4e70 888
889 while((element =
6843100a 890 g_slist_find_custom(element, viewer,
501e4e70 891 (GCompareFunc)find_viewer))
892 != NULL) {
2d262115 893 EventsRequest *events_request = (EventsRequest *)element->data;
3bafb436 894 // Modified so a viewer being destroyed won't have its after_request
895 // called. Not so important anyway. Note that a viewer that call this
896 // remove_all function will not get its after_request called.
897 //if(events_request->servicing == TRUE) {
898 // lttv_hooks_call(events_request->after_request, NULL);
899 //}
c5b5eee1 900 events_request_free(events_request);
901 //g_free(events_request);
501e4e70 902 tab->events_requests = g_slist_remove_link(tab->events_requests, element);
6843100a 903 element = g_slist_next(element);
904 if(element == NULL) break; /* end of list */
501e4e70 905 }
b052368a 906 if(g_slist_length(tab->events_requests) == 0) {
907 tab->events_request_pending = FALSE;
908 g_idle_remove_by_data(tab);
909 }
910
501e4e70 911}
912
50106726 913/**
914 * Function to get the current time interval shown on the current tab.
915 * It will be called by a viewer's hook function to update the
916 * shown time interval of the viewer and also be called by the constructor
917 * of the viewer.
918 * @param tab viewer's tab
919 * @return time window.
920 */
921
922TimeWindow lttvwindow_get_time_window(Tab *tab)
923{
924 return tab->time_window;
925}
926
501e4e70 927
501e4e70 928/**
929 * Function to get the current time/event of the current tab.
930 * It will be called by a viewer's hook function to update the
931 * current time/event of the viewer.
932 * @param tab viewer's tab
6ea08962 933 * @return time
501e4e70 934 */
935
6ea08962 936LttTime lttvwindow_get_current_time(Tab *tab)
501e4e70 937{
6ea08962 938 return tab->current_time;
501e4e70 939}
940
941
942/**
943 * Function to get the filter of the current tab.
dc5e5266 944 * @param main_win, the main window the viewer belongs to.
501e4e70 945 * @param filter, a pointer to a filter.
946 */
dc5e5266 947
948LttvFilter *lttvwindow_get_filter(Tab *tab)
501e4e70 949{
dc5e5266 950 return tab->filter;
501e4e70 951}
952
dc5e5266 953/**
954 * Function to set the filter of the current tab.
955 * It should be called by the filter GUI to tell the
956 * main window to update the filter tab's lttv_filter.
957 *
958 * This function does change the current filter, removing the
959 * old one when necessary, and call the updatefilter hooks
960 * of the registered viewers.
961 *
962 * @param main_win, the main window the viewer belongs to.
963 * @param filter, a pointer to a filter.
964 */
965
966void lttvwindow_report_filter(Tab *tab, LttvFilter *filter)
967{
968 LttvAttributeValue value;
969 LttvHooks * tmp;
970
971 lttv_filter_destroy(tab->filter);
972 tab->filter = filter;
973
974 g_assert(lttv_iattribute_find_by_path(tab->attributes,
975 "hooks/updatefilter", LTTV_POINTER, &value));
976 tmp = (LttvHooks*)*(value.v_pointer);
977 if(tmp == NULL) return;
962e2228 978 lttv_hooks_call(tmp, filter);
dc5e5266 979}
980
981
501e4e70 982
983/**
984 * Function to get the stats of the traceset
985 * @param tab viewer's tab
986 */
987
988LttvTracesetStats* lttvwindow_get_traceset_stats(Tab *tab)
989{
990 return tab->traceset_info->traceset_context;
991}
992
993
994LttvTracesetContext* lttvwindow_get_traceset_context(Tab *tab)
995{
996 return (LttvTracesetContext*)tab->traceset_info->traceset_context;
997}
c5b5eee1 998
999
1000void events_request_free(EventsRequest *events_request)
1001{
1002 if(events_request == NULL) return;
1003
1004 if(events_request->start_position != NULL)
1005 lttv_traceset_context_position_destroy(events_request->start_position);
1006 if(events_request->end_position != NULL)
1007 lttv_traceset_context_position_destroy(events_request->end_position);
1008 if(events_request->hooks != NULL) {
1009 guint i;
1010 GArray *hooks = events_request->hooks;
1011 for(i=0;i<hooks->len;i++) {
1012 lttv_trace_hook_destroy(&g_array_index(hooks, LttvTraceHook, i));
1013 }
1014 g_array_free(events_request->hooks, TRUE);
1015 }
1016 if(events_request->before_chunk_traceset != NULL)
1017 lttv_hooks_destroy(events_request->before_chunk_traceset);
1018 if(events_request->before_chunk_trace != NULL)
1019 lttv_hooks_destroy(events_request->before_chunk_trace);
1020 if(events_request->before_chunk_tracefile != NULL)
1021 lttv_hooks_destroy(events_request->before_chunk_tracefile);
1022 if(events_request->event != NULL)
1023 lttv_hooks_destroy(events_request->event);
1024 if(events_request->event_by_id != NULL)
1025 lttv_hooks_by_id_destroy(events_request->event_by_id);
1026 if(events_request->after_chunk_tracefile != NULL)
1027 lttv_hooks_destroy(events_request->after_chunk_tracefile);
1028 if(events_request->after_chunk_trace != NULL)
1029 lttv_hooks_destroy(events_request->after_chunk_trace);
1030 if(events_request->after_chunk_traceset != NULL)
1031 lttv_hooks_destroy(events_request->after_chunk_traceset);
1032 if(events_request->before_request != NULL)
1033 lttv_hooks_destroy(events_request->before_request);
1034 if(events_request->after_request != NULL)
1035 lttv_hooks_destroy(events_request->after_request);
1036
1037 g_free(events_request);
1038}
1039
1040
This page took 0.070717 seconds and 4 git commands to generate.