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