56a847e6159e0739229b625b61b1ae0eb3c57a78
[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 * allowed time span.
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 __EXPORT void lttvwindow_register_timespan_notify(Tab *tab,
478 LttvHook hook, gpointer hook_data)
479 {
480 LttvAttributeValue value;
481 LttvHooks * tmp;
482 gboolean retval;
483
484 retval= lttv_iattribute_find_by_path(tab->attributes,
485 "hooks/updatetimespan", LTTV_POINTER, &value);
486 g_assert(retval);
487 tmp = (LttvHooks*)*(value.v_pointer);
488 if(tmp == NULL){
489 tmp = lttv_hooks_new();
490 *(value.v_pointer) = tmp;
491 }
492 lttv_hooks_add(tmp, hook,hook_data, LTTV_PRIO_DEFAULT);
493 }
494 /**
495 * Function to unregister a viewer's hook function which is used to
496 * set/update the time span allowed for the viewer.
497 * @param tab viewer's tab
498 * @param hook hook function of the viewer.
499 * @param hook_data hook data associated with the hook function.
500 */
501
502 __EXPORT void lttvwindow_unregister_timespan_notify(Tab *tab,
503 LttvHook hook, gpointer hook_data)
504 {
505 LttvAttributeValue value;
506 LttvHooks * tmp;
507 gboolean retval;
508
509 retval= lttv_iattribute_find_by_path(tab->attributes,
510 "hooks/updatetimespan", LTTV_POINTER, &value);
511 g_assert(retval);
512 tmp = (LttvHooks*)*(value.v_pointer);
513 if(tmp == NULL) return;
514 lttv_hooks_remove_data(tmp, hook, hook_data);
515 }
516
517 /**
518 * Function to register a hook function for a viewer to set/update its
519 * traceset.
520 * @param tab viewer's tab
521 * @param hook hook function of the viewer.
522 * @param hook_data hook data associated with the hook function.
523 */
524
525 __EXPORT void lttvwindow_register_traceset_notify(Tab *tab,
526 LttvHook hook, gpointer hook_data)
527 {
528 LttvAttributeValue value;
529 LttvHooks * tmp;
530 gboolean retval;
531
532 retval= lttv_iattribute_find_by_path(tab->attributes,
533 "hooks/updatetraceset", LTTV_POINTER, &value);
534 g_assert(retval);
535 tmp = (LttvHooks*)*(value.v_pointer);
536 if(tmp == NULL){
537 tmp = lttv_hooks_new();
538 *(value.v_pointer) = tmp;
539 }
540 lttv_hooks_add(tmp, hook, hook_data, LTTV_PRIO_DEFAULT);
541 }
542
543
544 /**
545 * Function to unregister a viewer's hook function which is used to
546 * set/update the traceset of the viewer.
547 * @param tab viewer's tab
548 * @param hook hook function of the viewer.
549 * @param hook_data hook data associated with the hook function.
550 */
551
552 __EXPORT void lttvwindow_unregister_traceset_notify(Tab *tab,
553 LttvHook hook, gpointer hook_data)
554 {
555 LttvAttributeValue value;
556 LttvHooks * tmp;
557 gboolean retval;
558
559 retval= lttv_iattribute_find_by_path(tab->attributes,
560 "hooks/updatetraceset", LTTV_POINTER, &value);
561 g_assert(retval);
562 tmp = (LttvHooks*)*(value.v_pointer);
563 if(tmp == NULL) return;
564 lttv_hooks_remove_data(tmp, hook, hook_data);
565 }
566
567 /**
568 * Function to register a hook function for a viewer be completely redrawn.
569 *
570 * @param tab viewer's tab
571 * @param hook hook function of the viewer.
572 * @param hook_data hook data associated with the hook function.
573 */
574
575 __EXPORT void lttvwindow_register_redraw_notify(Tab *tab,
576 LttvHook hook, gpointer hook_data)
577 {
578 LttvAttributeValue value;
579 LttvHooks * tmp;
580 gboolean retval;
581
582 retval= lttv_iattribute_find_by_path(tab->attributes, "hooks/redraw",
583 LTTV_POINTER, &value);
584 g_assert(retval);
585 tmp = (LttvHooks*)*(value.v_pointer);
586 if(tmp == NULL){
587 tmp = lttv_hooks_new();
588 *(value.v_pointer) = tmp;
589 }
590 lttv_hooks_add(tmp, hook, hook_data, LTTV_PRIO_DEFAULT);
591 }
592
593
594 /**
595 * Function to unregister a hook function for a viewer be completely redrawn.
596 *
597 * @param tab viewer's tab
598 * @param hook hook function of the viewer.
599 * @param hook_data hook data associated with the hook function.
600 */
601
602 __EXPORT void lttvwindow_unregister_redraw_notify(Tab *tab,
603 LttvHook hook, gpointer hook_data)
604 {
605 LttvAttributeValue value;
606 LttvHooks * tmp;
607 gboolean retval;
608
609 retval= lttv_iattribute_find_by_path(tab->attributes, "hooks/redraw",
610 LTTV_POINTER, &value);
611 g_assert(retval);
612 tmp = (LttvHooks*)*(value.v_pointer);
613 if(tmp == NULL) return;
614 lttv_hooks_remove_data(tmp, hook, hook_data);
615 }
616
617 /**
618 * Function to register a hook function for a viewer to re-do the events
619 * requests for the needed interval.
620 *
621 * This action is typically done after a "stop".
622 *
623 * The typical hook will remove all current requests for the viewer
624 * and make requests for missing information.
625 *
626 * @param tab viewer's tab
627 * @param hook hook function of the viewer.
628 * @param hook_data hook data associated with the hook function.
629 */
630
631 __EXPORT void lttvwindow_register_continue_notify(Tab *tab,
632 LttvHook hook, gpointer hook_data)
633 {
634 LttvAttributeValue value;
635 LttvHooks * tmp;
636 gboolean retval;
637
638 retval= lttv_iattribute_find_by_path(tab->attributes, "hooks/continue",
639 LTTV_POINTER, &value);
640 g_assert(retval);
641 tmp = (LttvHooks*)*(value.v_pointer);
642 if(tmp == NULL){
643 tmp = lttv_hooks_new();
644 *(value.v_pointer) = tmp;
645 }
646 lttv_hooks_add(tmp, hook, hook_data, LTTV_PRIO_DEFAULT);
647 }
648
649
650 /**
651 * Function to unregister a hook function for a viewer to re-do the events
652 * requests for the needed interval.
653 *
654 * @param tab viewer's tab
655 * @param hook hook function of the viewer.
656 * @param hook_data hook data associated with the hook function.
657 */
658
659 __EXPORT void lttvwindow_unregister_continue_notify(Tab *tab,
660 LttvHook hook, gpointer hook_data)
661 {
662 LttvAttributeValue value;
663 LttvHooks * tmp;
664 gboolean retval;
665
666 retval= lttv_iattribute_find_by_path(tab->attributes, "hooks/continue",
667 LTTV_POINTER, &value);
668 g_assert(retval);
669 tmp = (LttvHooks*)*(value.v_pointer);
670 if(tmp == NULL) return;
671 lttv_hooks_remove_data(tmp, hook, hook_data);
672 }
673
674
675 /**
676 * Function to register a hook function for a viewer to set/update its
677 * filter.
678 * @param tab viewer's tab
679 * @param hook hook function of the viewer.
680 * @param hook_data hook data associated with the hook function.
681 */
682
683 __EXPORT void lttvwindow_register_filter_notify(Tab *tab,
684 LttvHook hook, gpointer hook_data)
685 {
686 LttvAttributeValue value;
687 LttvHooks * tmp;
688 gboolean retval;
689
690 retval= lttv_iattribute_find_by_path(tab->attributes, "hooks/updatefilter",
691 LTTV_POINTER, &value);
692 g_assert(retval);
693 tmp = (LttvHooks*)*(value.v_pointer);
694 if(tmp == NULL){
695 tmp = lttv_hooks_new();
696 *(value.v_pointer) = tmp;
697 }
698 lttv_hooks_add(tmp, hook, hook_data, LTTV_PRIO_DEFAULT);
699 }
700
701
702 /**
703 * Function to unregister a viewer's hook function which is used to
704 * set/update the filter of the viewer.
705 * @param tab viewer's tab
706 * @param hook hook function of the viewer.
707 * @param hook_data hook data associated with the hook function.
708 */
709
710 __EXPORT void lttvwindow_unregister_filter_notify(Tab *tab,
711 LttvHook hook,
712 gpointer hook_data)
713 {
714 LttvAttributeValue value;
715 LttvHooks * tmp;
716 gboolean retval;
717
718 retval= lttv_iattribute_find_by_path(tab->attributes, "hooks/updatefilter",
719 LTTV_POINTER, &value);
720 g_assert(retval);
721 tmp = (LttvHooks*)*(value.v_pointer);
722 if(tmp == NULL) return;
723 lttv_hooks_remove_data(tmp, hook, hook_data);
724 }
725
726 /**
727 * function to register a hook function for a viewer to set/update its
728 * current time.
729 * @param tab viewer's tab
730 * @param hook hook function of the viewer.
731 * @param hook_data hook data associated with the hook function.
732 */
733
734 __EXPORT void lttvwindow_register_current_time_notify(Tab *tab,
735 LttvHook hook, gpointer hook_data)
736 {
737 LttvAttributeValue value;
738 LttvHooks * tmp;
739 gboolean retval;
740
741 retval= lttv_iattribute_find_by_path(tab->attributes,
742 "hooks/updatecurrenttime", LTTV_POINTER, &value);
743 g_assert(retval);
744 tmp = (LttvHooks*)*(value.v_pointer);
745 if(tmp == NULL){
746 tmp = lttv_hooks_new();
747 *(value.v_pointer) = tmp;
748 }
749 lttv_hooks_add(tmp, hook, hook_data, LTTV_PRIO_DEFAULT);
750 }
751
752
753 /**
754 * function to unregister a viewer's hook function which is used to
755 * set/update the current time of the viewer.
756 * @param tab viewer's tab
757 * @param hook hook function of the viewer.
758 * @param hook_data hook data associated with the hook function.
759 */
760
761 __EXPORT void lttvwindow_unregister_current_time_notify(Tab *tab,
762 LttvHook hook, gpointer hook_data)
763 {
764 LttvAttributeValue value;
765 LttvHooks * tmp;
766 gboolean retval;
767
768 retval= lttv_iattribute_find_by_path(tab->attributes,
769 "hooks/updatecurrenttime", LTTV_POINTER, &value);
770 g_assert(retval);
771 tmp = (LttvHooks*)*(value.v_pointer);
772 if(tmp == NULL) return;
773 lttv_hooks_remove_data(tmp, hook, hook_data);
774 }
775
776 /**
777 * function to register a hook function for a viewer to set/update its
778 * current position.
779 * @param tab viewer's tab
780 * @param hook hook function of the viewer.
781 * @param hook_data hook data associated with the hook function.
782 */
783
784 __EXPORT void lttvwindow_register_current_position_notify(Tab *tab,
785 LttvHook hook, gpointer hook_data)
786 {
787 LttvAttributeValue value;
788 LttvHooks * tmp;
789 gboolean retval;
790
791 retval= lttv_iattribute_find_by_path(tab->attributes,
792 "hooks/updatecurrentposition", LTTV_POINTER, &value);
793 g_assert(retval);
794 tmp = (LttvHooks*)*(value.v_pointer);
795 if(tmp == NULL){
796 tmp = lttv_hooks_new();
797 *(value.v_pointer) = tmp;
798 }
799 lttv_hooks_add(tmp, hook, hook_data, LTTV_PRIO_DEFAULT);
800 }
801
802
803 /**
804 * function to unregister a viewer's hook function which is used to
805 * set/update the current position of the viewer.
806 * @param tab viewer's tab
807 * @param hook hook function of the viewer.
808 * @param hook_data hook data associated with the hook function.
809 */
810
811 __EXPORT void lttvwindow_unregister_current_position_notify(Tab *tab,
812 LttvHook hook, gpointer hook_data)
813 {
814 LttvAttributeValue value;
815 LttvHooks * tmp;
816 gboolean retval;
817
818 retval= lttv_iattribute_find_by_path(tab->attributes,
819 "hooks/updatecurrentposition", LTTV_POINTER, &value);
820 g_assert(retval);
821 tmp = (LttvHooks*)*(value.v_pointer);
822 if(tmp == NULL) return;
823 lttv_hooks_remove_data(tmp, hook, hook_data);
824 }
825
826
827 /**
828 * Function to register a hook function for a viewer to show
829 * the content of the viewer.
830 * @param tab viewer's tab
831 * @param hook hook function of the viewer.
832 * @param hook_data hook data associated with the hook function.
833 */
834
835 void lttvwindow_register_show_notify(Tab *tab,
836 LttvHook hook, gpointer hook_data)
837 {
838 LttvAttributeValue value;
839 LttvHooks * tmp;
840 gboolean retval;
841
842 retval= lttv_iattribute_find_by_path(tab->attributes, "hooks/showviewer",
843 LTTV_POINTER, &value);
844 g_assert(retval);
845 tmp = (LttvHooks*)*(value.v_pointer);
846 if(tmp == NULL){
847 tmp = lttv_hooks_new();
848 *(value.v_pointer) = tmp;
849 }
850 lttv_hooks_add(tmp, hook, hook_data, LTTV_PRIO_DEFAULT);
851 }
852
853
854 /**
855 * Function to unregister a viewer's hook function which is used to
856 * show the content of the viewer..
857 * @param tab viewer's tab
858 * @param hook hook function of the viewer.
859 * @param hook_data hook data associated with the hook function.
860 */
861
862 void lttvwindow_unregister_show_notify(Tab *tab,
863 LttvHook hook, gpointer hook_data)
864 {
865 LttvAttributeValue value;
866 LttvHooks * tmp;
867 gboolean retval;
868
869 retval= lttv_iattribute_find_by_path(tab->attributes, "hooks/showviewer",
870 LTTV_POINTER, &value);
871 g_assert(retval);
872 tmp = (LttvHooks*)*(value.v_pointer);
873 if(tmp == NULL) return;
874 lttv_hooks_remove_data(tmp, hook, hook_data);
875 }
876
877 /**
878 * Function to register a hook function for a viewer to set/update the
879 * dividor of the hpane.
880 * @param tab viewer's tab
881 * @param hook hook function of the viewer.
882 * @param hook_data hook data associated with the hook function.
883 */
884
885 void lttvwindow_register_dividor(Tab *tab,
886 LttvHook hook, gpointer hook_data)
887 {
888 LttvAttributeValue value;
889 LttvHooks * tmp;
890 gboolean retval;
891
892 retval= lttv_iattribute_find_by_path(tab->attributes, "hooks/hpanedividor",
893 LTTV_POINTER, &value);
894 g_assert(retval);
895 tmp = (LttvHooks*)*(value.v_pointer);
896 if(tmp == NULL){
897 tmp = lttv_hooks_new();
898 *(value.v_pointer) = tmp;
899 }
900 lttv_hooks_add(tmp, hook, hook_data, LTTV_PRIO_DEFAULT);
901 }
902
903
904 /**
905 * Function to unregister a viewer's hook function which is used to
906 * set/update hpane's dividor of the viewer.
907 * It will be called by the destructor of the viewer.
908 * @param tab viewer's tab
909 * @param hook hook function of the viewer.
910 * @param hook_data hook data associated with the hook function.
911 */
912
913 void lttvwindow_unregister_dividor(Tab *tab,
914 LttvHook hook, gpointer hook_data)
915 {
916 LttvAttributeValue value;
917 LttvHooks * tmp;
918 gboolean retval;
919
920 retval= lttv_iattribute_find_by_path(tab->attributes, "hooks/hpanedividor",
921 LTTV_POINTER, &value);
922 g_assert(retval);
923 tmp = (LttvHooks*)*(value.v_pointer);
924 if(tmp == NULL) return;
925 lttv_hooks_remove_data(tmp, hook, hook_data);
926 }
927
928
929 /**
930 * Function to set the time interval of the current tab.
931 * It will be called by a viewer's signal handle associated with
932 * the move_slider signal
933 * @param tab viewer's tab
934 * @param time_interval a pointer where time interval is stored.
935 */
936
937 __EXPORT void lttvwindow_report_time_window(Tab *tab,
938 TimeWindow time_window)
939 {
940 //set_time_window(tab, time_window);
941 //set_time_window_adjustment(tab, time_window);
942
943 time_change_manager(tab, time_window);
944
945
946 #if 0
947 /* Set scrollbar */
948 LttvTracesetContext *tsc =
949 LTTV_TRACESET_CONTEXT(tab->traceset_info->traceset_context);
950 TimeInterval time_span = tsc->time_span;
951 GtkAdjustment *adjustment = gtk_range_get_adjustment(GTK_RANGE(tab->scrollbar));
952 g_object_set(G_OBJECT(adjustment),
953 "lower",
954 0.0, /* lower */
955 "upper",
956 ltt_time_to_double(
957 ltt_time_sub(time_span.end_time, time_span.start_time))
958 , /* upper */
959 "step_increment",
960 ltt_time_to_double(time_window->time_width)
961 / SCROLL_STEP_PER_PAGE
962 , /* step increment */
963 "page_increment",
964 ltt_time_to_double(time_window->time_width)
965 , /* page increment */
966 "page_size",
967 ltt_time_to_double(time_window->time_width)
968 , /* page size */
969 NULL);
970 gtk_adjustment_changed(adjustment);
971
972 //g_object_set(G_OBJECT(adjustment),
973 // "value",
974 // ltt_time_to_double(time_window->start_time)
975 // , /* value */
976 // NULL);
977 /* Note : the set value will call set_time_window if scrollbar value changed
978 */
979 gtk_adjustment_set_value(adjustment,
980 ltt_time_to_double(
981 ltt_time_sub(time_window->start_time,
982 time_span.start_time))
983 );
984 #endif //0
985 }
986
987
988 /**
989 * Function to set the current time of the current tab.
990 * It will be called by a viewer's signal handle associated with
991 * the button-release-event signal
992 * @param tab viewer's tab
993 * @param time a pointer where time is stored.
994 */
995
996 __EXPORT void lttvwindow_report_current_time(Tab *tab,
997 LttTime time)
998 {
999 current_time_change_manager(tab, time);
1000 }
1001
1002 /**
1003 * Function to set the current event of the current tab.
1004 * It will be called by a viewer's signal handle associated with
1005 * the button-release-event signal
1006 * @param tab viewer's tab
1007 * @param time a pointer where time is stored.
1008 */
1009
1010 __EXPORT void lttvwindow_report_current_position(Tab *tab,
1011 LttvTracesetContextPosition *pos)
1012 {
1013 current_position_change_manager(tab, pos);
1014 }
1015
1016
1017 /**
1018 * Function to set the position of the hpane's dividor (viewer).
1019 * It will be called by a viewer's signal handle associated with
1020 * the motion_notify_event event/signal
1021 * @param tab viewer's tab
1022 * @param position position of the hpane's dividor.
1023 */
1024
1025 void lttvwindow_report_dividor(Tab *tab, gint position)
1026 {
1027 LttvAttributeValue value;
1028 LttvHooks * tmp;
1029 gboolean retval;
1030
1031 retval= lttv_iattribute_find_by_path(tab->attributes, "hooks/hpanedividor",
1032 LTTV_POINTER, &value);
1033 g_assert(retval);
1034 tmp = (LttvHooks*)*(value.v_pointer);
1035 if(tmp == NULL) return;
1036 lttv_hooks_call(tmp, &position);
1037 }
1038
1039 /**
1040 * Function to request data in a specific time interval to the main window. The
1041 * event request servicing is differed until the glib idle functions are
1042 * called.
1043 *
1044 * The viewer has to provide hooks that should be associated with the event
1045 * request.
1046 *
1047 * Either start time or start position must be defined in a EventRequest
1048 * structure for it to be valid.
1049 *
1050 * end_time, end_position and num_events can all be defined. The first one
1051 * to occur will be used as end criterion.
1052 *
1053 * @param tab viewer's tab
1054 * @param events_requested the structure of request from.
1055 */
1056
1057 __EXPORT void lttvwindow_events_request(Tab *tab,
1058 EventsRequest *events_request)
1059 {
1060 tab->events_requests = g_slist_append(tab->events_requests, events_request);
1061
1062 if(!tab->events_request_pending)
1063 {
1064 /* Redraw has +20 priority. We want to let the redraw be done while we do
1065 * our job. Mathieu : test with high prio higher than events for better
1066 * scrolling. */
1067 /* Mathieu, 2008 : ok, finally, the control flow view needs the cell updates
1068 * to come soon enough so we can have one active cell to get the pixmap
1069 * buffer height from. Therefore, let the gdk events run before the events
1070 * requests.
1071 */
1072 g_idle_add_full((G_PRIORITY_HIGH_IDLE + 21),
1073 //g_idle_add_full((G_PRIORITY_DEFAULT + 2),
1074 (GSourceFunc)execute_events_requests,
1075 tab,
1076 NULL);
1077 tab->events_request_pending = TRUE;
1078 }
1079 }
1080
1081
1082 /**
1083 * Function to remove data requests related to a viewer.
1084 *
1085 * The existing requests's viewer gpointer is compared to the pointer
1086 * given in argument to establish which data request should be removed.
1087 *
1088 * @param tab the tab the viewer belongs to.
1089 * @param viewer a pointer to the viewer data structure
1090 */
1091
1092 gint find_viewer (const EventsRequest *a, gconstpointer b)
1093 {
1094 return (a->owner != b);
1095 }
1096
1097
1098 __EXPORT void lttvwindow_events_request_remove_all(Tab *tab,
1099 gconstpointer viewer)
1100 {
1101 GSList *element = tab->events_requests;
1102
1103 while((element =
1104 g_slist_find_custom(element, viewer,
1105 (GCompareFunc)find_viewer))
1106 != NULL) {
1107 EventsRequest *events_request = (EventsRequest *)element->data;
1108 // Modified so a viewer being destroyed won't have its after_request
1109 // called. Not so important anyway. Note that a viewer that call this
1110 // remove_all function will not get its after_request called.
1111 //if(events_request->servicing == TRUE) {
1112 // lttv_hooks_call(events_request->after_request, NULL);
1113 //}
1114 events_request_free(events_request);
1115 //g_free(events_request);
1116 tab->events_requests = g_slist_remove_link(tab->events_requests, element);
1117 element = g_slist_next(element);
1118 if(element == NULL) break; /* end of list */
1119 }
1120 if(g_slist_length(tab->events_requests) == 0) {
1121 tab->events_request_pending = FALSE;
1122 g_idle_remove_by_data(tab);
1123 }
1124
1125 }
1126
1127
1128 /**
1129 * Function to see if there are events request pending.
1130 *
1131 * It tells if events requests are pending. Useful for checks in some events,
1132 * i.e. detailed event list scrolling.
1133 *
1134 * @param tab the tab the viewer belongs to.
1135 * @param viewer a pointer to the viewer data structure
1136 * @return : TRUE is events requests are pending, else FALSE.
1137 */
1138
1139 __EXPORT gboolean lttvwindow_events_request_pending(Tab *tab)
1140 {
1141 GSList *element = tab->events_requests;
1142
1143 if(element == NULL) return FALSE;
1144 else return TRUE;
1145 }
1146
1147
1148 /**
1149 * Function to get the current time interval shown on the current tab.
1150 * It will be called by a viewer's hook function to update the
1151 * shown time interval of the viewer and also be called by the constructor
1152 * of the viewer.
1153 * @param tab viewer's tab
1154 * @return time window.
1155 */
1156
1157 __EXPORT TimeWindow lttvwindow_get_time_window(Tab *tab)
1158 {
1159 return tab->time_window;
1160 }
1161
1162
1163 /**
1164 * Function to get the current time/event of the current tab.
1165 * It will be called by a viewer's hook function to update the
1166 * current time/event of the viewer.
1167 * @param tab viewer's tab
1168 * @return time
1169 */
1170
1171 __EXPORT LttTime lttvwindow_get_current_time(Tab *tab)
1172 {
1173 return tab->current_time;
1174 }
1175
1176
1177 /**
1178 * Function to get the filter of the current tab.
1179 * @param filter, a pointer to a filter.
1180 *
1181 * returns the current filter
1182 */
1183 __EXPORT LttvFilter *lttvwindow_get_filter(Tab *tab)
1184 {
1185 return g_object_get_data(G_OBJECT(tab->vbox), "filter");
1186 }
1187
1188 /**
1189 * Function to set the filter of the current tab.
1190 * It should be called by the filter GUI to tell the
1191 * main window to update the filter tab's lttv_filter.
1192 *
1193 * This function does change the current filter, removing the
1194 * old one when necessary, and call the updatefilter hooks
1195 * of the registered viewers.
1196 *
1197 * @param main_win, the main window the viewer belongs to.
1198 * @param filter, a pointer to a filter.
1199 */
1200 void lttvwindow_report_filter(Tab *tab, LttvFilter *filter)
1201 {
1202 LttvAttributeValue value;
1203 LttvHooks * tmp;
1204 gboolean retval;
1205
1206 //lttv_filter_destroy(tab->filter);
1207 //tab->filter = filter;
1208
1209 retval= lttv_iattribute_find_by_path(tab->attributes, "hooks/updatefilter",
1210 LTTV_POINTER, &value);
1211 g_assert(retval);
1212 tmp = (LttvHooks*)*(value.v_pointer);
1213 if(tmp == NULL) return;
1214 lttv_hooks_call(tmp, filter);
1215 }
1216
1217
1218
1219 /**
1220 * Function to get the stats of the traceset
1221 * @param tab viewer's tab
1222 */
1223
1224 __EXPORT LttvTracesetStats* lttvwindow_get_traceset_stats(Tab *tab)
1225 {
1226 return tab->traceset_info->traceset_context;
1227 }
1228
1229 __EXPORT LttvTracesetContext* lttvwindow_get_traceset_context(Tab *tab)
1230 {
1231 return (LttvTracesetContext*)tab->traceset_info->traceset_context;
1232 }
1233
1234
1235 void events_request_free(EventsRequest *events_request)
1236 {
1237 if(events_request == NULL) return;
1238
1239 if(events_request->start_position != NULL)
1240 lttv_traceset_context_position_destroy(events_request->start_position);
1241 if(events_request->end_position != NULL)
1242 lttv_traceset_context_position_destroy(events_request->end_position);
1243 if(events_request->hooks != NULL) {
1244 GArray *hooks = events_request->hooks;
1245 lttv_trace_hook_remove_all(&hooks);
1246 g_array_free(events_request->hooks, TRUE);
1247 }
1248 if(events_request->before_chunk_traceset != NULL)
1249 lttv_hooks_destroy(events_request->before_chunk_traceset);
1250 if(events_request->before_chunk_trace != NULL)
1251 lttv_hooks_destroy(events_request->before_chunk_trace);
1252 if(events_request->before_chunk_tracefile != NULL)
1253 lttv_hooks_destroy(events_request->before_chunk_tracefile);
1254 if(events_request->event != NULL)
1255 lttv_hooks_destroy(events_request->event);
1256 if(events_request->event_by_id_channel != NULL)
1257 lttv_hooks_by_id_channel_destroy(events_request->event_by_id_channel);
1258 if(events_request->after_chunk_tracefile != NULL)
1259 lttv_hooks_destroy(events_request->after_chunk_tracefile);
1260 if(events_request->after_chunk_trace != NULL)
1261 lttv_hooks_destroy(events_request->after_chunk_trace);
1262 if(events_request->after_chunk_traceset != NULL)
1263 lttv_hooks_destroy(events_request->after_chunk_traceset);
1264 if(events_request->before_request != NULL)
1265 lttv_hooks_destroy(events_request->before_request);
1266 if(events_request->after_request != NULL)
1267 lttv_hooks_destroy(events_request->after_request);
1268
1269 g_free(events_request);
1270 }
1271
1272
1273
1274 __EXPORT GtkWidget *main_window_get_widget(Tab *tab)
1275 {
1276 return tab->mw->mwindow;
1277 }
1278
This page took 0.056635 seconds and 3 git commands to generate.