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