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