5ff1c55c31f515ef7a3e1469028b61725eb80879
[lttv.git] /
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
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 GtkWidget * tool_menu_title_menu, *widget;
209
210 g_assert(lttv_iattribute_find_by_path(attributes,
211 "viewers/toolbar", LTTV_POINTER, &value));
212 if(*(value.v_pointer) == NULL)
213 *(value.v_pointer) = lttv_toolbars_new();
214 instance_toolbar = (LttvToolbars*)*(value.v_pointer);
215
216 tool_menu_title_menu = lookup_widget(mw->mwindow,"MToolbar1");
217 widget = lttv_menus_remove(instance_toolbar, viewer_constructor);
218 gtk_container_remove (GTK_CONTAINER (tool_menu_title_menu),
219 widget);
220 }
221
222
223 void remove_menu_constructor(MainWindow *mw, lttvwindow_viewer_constructor viewer_constructor)
224 {
225 LttvIAttribute *attributes = mw->attributes;
226 LttvAttributeValue value;
227 LttvMenus * instance_menu;
228 GtkWidget * tool_menu_title_menu, *widget;
229
230 g_assert(lttv_iattribute_find_by_path(attributes,
231 "viewers/menu", LTTV_POINTER, &value));
232 if(*(value.v_pointer) == NULL)
233 *(value.v_pointer) = lttv_menus_new();
234 instance_menu = (LttvMenus*)*(value.v_pointer);
235
236 widget = lttv_menus_remove(instance_menu, viewer_constructor);
237 tool_menu_title_menu = lookup_widget(mw->mwindow,"ToolMenuTitle_menu");
238 gtk_container_remove (GTK_CONTAINER (tool_menu_title_menu), widget);
239 }
240
241
242 /**
243 * API parts
244 */
245
246
247 /**
248 * Function to register a view constructor so that main window can generate
249 * a menu item and a toolbar item for the viewer in order to generate a new
250 * instance easily. A menu entry and toolbar item will be added to each main
251 * window.
252 *
253 * It should be called by init function of the module.
254 *
255 * @param name name of the viewer
256 * @param menu_path path of the menu item.
257 * @param menu_text text of the menu item.
258 * @param pixmap Image shown on the toolbar item.
259 * @param tooltip tooltip of the toolbar item.
260 * @param view_constructor constructor of the viewer.
261 */
262
263 __EXPORT void lttvwindow_register_constructor
264 (char * name,
265 char * menu_path,
266 char * menu_text,
267 char ** pixmap,
268 char * tooltip,
269 lttvwindow_viewer_constructor view_constructor)
270 {
271 LttvIAttribute *attributes_global = LTTV_IATTRIBUTE(lttv_global_attributes());
272 LttvToolbars * toolbar;
273 LttvMenus * menu;
274 LttvToolbarClosure toolbar_c;
275 LttvMenuClosure menu_c;
276 LttvAttributeValue value;
277
278 if(view_constructor == NULL) return;
279
280 if(pixmap != NULL) {
281 g_assert(lttv_iattribute_find_by_path(attributes_global,
282 "viewers/toolbar", LTTV_POINTER, &value));
283 toolbar = (LttvToolbars*)*(value.v_pointer);
284
285 if(toolbar == NULL) {
286 toolbar = lttv_toolbars_new();
287 *(value.v_pointer) = toolbar;
288 }
289 toolbar_c = lttv_toolbars_add(toolbar, view_constructor, tooltip, pixmap,
290 NULL);
291
292 g_slist_foreach(g_main_window_list,
293 (gpointer)add_toolbar_constructor,
294 &toolbar_c);
295 }
296
297 if(menu_path != NULL) {
298 g_assert(lttv_iattribute_find_by_path(attributes_global,
299 "viewers/menu", LTTV_POINTER, &value));
300 menu = (LttvMenus*)*(value.v_pointer);
301
302 if(menu == NULL) {
303 menu = lttv_menus_new();
304 *(value.v_pointer) = menu;
305 }
306 menu_c = lttv_menus_add(menu, view_constructor, menu_path, menu_text,NULL);
307
308 g_slist_foreach(g_main_window_list,
309 (gpointer)add_menu_constructor,
310 &menu_c);
311 }
312 {
313 LttvAttribute *attribute;
314 gboolean result;
315
316 attribute = LTTV_ATTRIBUTE(lttv_iattribute_find_subdir(
317 LTTV_IATTRIBUTE(attributes_global),
318 LTTV_VIEWER_CONSTRUCTORS));
319 g_assert(attribute);
320
321 result = lttv_iattribute_find_by_path(LTTV_IATTRIBUTE(attribute),
322 name, LTTV_POINTER, &value);
323 g_assert(result);
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 __EXPORT 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 attribute = LTTV_ATTRIBUTE(lttv_iattribute_find_subdir(
376 LTTV_IATTRIBUTE(attributes_global),
377 LTTV_VIEWER_CONSTRUCTORS));
378 g_assert(attribute);
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 __EXPORT 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 __EXPORT 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 __EXPORT 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 __EXPORT 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 __EXPORT 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 __EXPORT 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 __EXPORT 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 __EXPORT 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 __EXPORT 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 __EXPORT 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 __EXPORT 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 __EXPORT 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 __EXPORT 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 __EXPORT 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 __EXPORT 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 __EXPORT void lttvwindow_report_current_time(Tab *tab,
874 LttTime time)
875 {
876 current_time_change_manager(tab, time);
877 }
878
879 /**
880 * Function to set the current event of the current tab.
881 * It will be called by a viewer's signal handle associated with
882 * the button-release-event signal
883 * @param tab viewer's tab
884 * @param time a pointer where time is stored.
885 */
886
887 __EXPORT void lttvwindow_report_current_position(Tab *tab,
888 LttvTracesetContextPosition *pos)
889 {
890 current_position_change_manager(tab, pos);
891 }
892
893
894 /**
895 * Function to set the position of the hpane's dividor (viewer).
896 * It will be called by a viewer's signal handle associated with
897 * the motion_notify_event event/signal
898 * @param tab viewer's tab
899 * @param position position of the hpane's dividor.
900 */
901
902 void lttvwindow_report_dividor(Tab *tab, gint position)
903 {
904 LttvAttributeValue value;
905 LttvHooks * tmp;
906 g_assert(lttv_iattribute_find_by_path(tab->attributes,
907 "hooks/hpanedividor", LTTV_POINTER, &value));
908 tmp = (LttvHooks*)*(value.v_pointer);
909 if(tmp == NULL) return;
910 lttv_hooks_call(tmp, &position);
911 }
912
913 /**
914 * Function to request data in a specific time interval to the main window. The
915 * event request servicing is differed until the glib idle functions are
916 * called.
917 *
918 * The viewer has to provide hooks that should be associated with the event
919 * request.
920 *
921 * Either start time or start position must be defined in a EventRequest
922 * structure for it to be valid.
923 *
924 * end_time, end_position and num_events can all be defined. The first one
925 * to occur will be used as end criterion.
926 *
927 * @param tab viewer's tab
928 * @param events_requested the structure of request from.
929 */
930
931 __EXPORT void lttvwindow_events_request(Tab *tab,
932 EventsRequest *events_request)
933 {
934 tab->events_requests = g_slist_append(tab->events_requests, events_request);
935
936 if(!tab->events_request_pending)
937 {
938 /* Redraw has +20 priority. We want to let the redraw be done while we do
939 * our job. Mathieu : test with high prio higher than events for better
940 * scrolling. */
941 //g_idle_add_full((G_PRIORITY_HIGH_IDLE + 21),
942 g_idle_add_full((G_PRIORITY_DEFAULT + 2),
943 (GSourceFunc)execute_events_requests,
944 tab,
945 NULL);
946 tab->events_request_pending = TRUE;
947 }
948 }
949
950
951 /**
952 * Function to remove data requests related to a viewer.
953 *
954 * The existing requests's viewer gpointer is compared to the pointer
955 * given in argument to establish which data request should be removed.
956 *
957 * @param tab the tab the viewer belongs to.
958 * @param viewer a pointer to the viewer data structure
959 */
960
961 gint find_viewer (const EventsRequest *a, gconstpointer b)
962 {
963 return (a->owner != b);
964 }
965
966
967 __EXPORT void lttvwindow_events_request_remove_all(Tab *tab,
968 gconstpointer viewer)
969 {
970 GSList *element = tab->events_requests;
971
972 while((element =
973 g_slist_find_custom(element, viewer,
974 (GCompareFunc)find_viewer))
975 != NULL) {
976 EventsRequest *events_request = (EventsRequest *)element->data;
977 // Modified so a viewer being destroyed won't have its after_request
978 // called. Not so important anyway. Note that a viewer that call this
979 // remove_all function will not get its after_request called.
980 //if(events_request->servicing == TRUE) {
981 // lttv_hooks_call(events_request->after_request, NULL);
982 //}
983 events_request_free(events_request);
984 //g_free(events_request);
985 tab->events_requests = g_slist_remove_link(tab->events_requests, element);
986 element = g_slist_next(element);
987 if(element == NULL) break; /* end of list */
988 }
989 if(g_slist_length(tab->events_requests) == 0) {
990 tab->events_request_pending = FALSE;
991 g_idle_remove_by_data(tab);
992 }
993
994 }
995
996
997 /**
998 * Function to see if there are events request pending.
999 *
1000 * It tells if events requests are pending. Useful for checks in some events,
1001 * i.e. detailed event list scrolling.
1002 *
1003 * @param tab the tab the viewer belongs to.
1004 * @param viewer a pointer to the viewer data structure
1005 * @return : TRUE is events requests are pending, else FALSE.
1006 */
1007
1008 __EXPORT gboolean lttvwindow_events_request_pending(Tab *tab)
1009 {
1010 GSList *element = tab->events_requests;
1011
1012 if(element == NULL) return FALSE;
1013 else return TRUE;
1014 }
1015
1016
1017 /**
1018 * Function to get the current time interval shown on the current tab.
1019 * It will be called by a viewer's hook function to update the
1020 * shown time interval of the viewer and also be called by the constructor
1021 * of the viewer.
1022 * @param tab viewer's tab
1023 * @return time window.
1024 */
1025
1026 __EXPORT TimeWindow lttvwindow_get_time_window(Tab *tab)
1027 {
1028 return tab->time_window;
1029 }
1030
1031
1032 /**
1033 * Function to get the current time/event of the current tab.
1034 * It will be called by a viewer's hook function to update the
1035 * current time/event of the viewer.
1036 * @param tab viewer's tab
1037 * @return time
1038 */
1039
1040 __EXPORT LttTime lttvwindow_get_current_time(Tab *tab)
1041 {
1042 return tab->current_time;
1043 }
1044
1045
1046 /**
1047 * Function to get the filter of the current tab.
1048 * @param filter, a pointer to a filter.
1049 *
1050 * returns the current filter
1051 */
1052 __EXPORT LttvFilter *lttvwindow_get_filter(Tab *tab)
1053 {
1054 return g_object_get_data(G_OBJECT(tab->vbox), "filter");
1055 }
1056
1057 /**
1058 * Function to set the filter of the current tab.
1059 * It should be called by the filter GUI to tell the
1060 * main window to update the filter tab's lttv_filter.
1061 *
1062 * This function does change the current filter, removing the
1063 * old one when necessary, and call the updatefilter hooks
1064 * of the registered viewers.
1065 *
1066 * @param main_win, the main window the viewer belongs to.
1067 * @param filter, a pointer to a filter.
1068 */
1069 void lttvwindow_report_filter(Tab *tab, LttvFilter *filter)
1070 {
1071 LttvAttributeValue value;
1072 LttvHooks * tmp;
1073
1074 //lttv_filter_destroy(tab->filter);
1075 //tab->filter = filter;
1076
1077 g_assert(lttv_iattribute_find_by_path(tab->attributes,
1078 "hooks/updatefilter", LTTV_POINTER, &value));
1079 tmp = (LttvHooks*)*(value.v_pointer);
1080 if(tmp == NULL) return;
1081 lttv_hooks_call(tmp, filter);
1082 }
1083
1084
1085
1086 /**
1087 * Function to get the stats of the traceset
1088 * @param tab viewer's tab
1089 */
1090
1091 __EXPORT LttvTracesetStats* lttvwindow_get_traceset_stats(Tab *tab)
1092 {
1093 return tab->traceset_info->traceset_context;
1094 }
1095
1096 __EXPORT LttvTracesetContext* lttvwindow_get_traceset_context(Tab *tab)
1097 {
1098 return (LttvTracesetContext*)tab->traceset_info->traceset_context;
1099 }
1100
1101
1102 void events_request_free(EventsRequest *events_request)
1103 {
1104 if(events_request == NULL) return;
1105
1106 if(events_request->start_position != NULL)
1107 lttv_traceset_context_position_destroy(events_request->start_position);
1108 if(events_request->end_position != NULL)
1109 lttv_traceset_context_position_destroy(events_request->end_position);
1110 if(events_request->hooks != NULL) {
1111 guint i;
1112 GArray *hooks = events_request->hooks;
1113 lttv_trace_hook_remove_all(&hooks);
1114 g_array_free(events_request->hooks, TRUE);
1115 }
1116 if(events_request->before_chunk_traceset != NULL)
1117 lttv_hooks_destroy(events_request->before_chunk_traceset);
1118 if(events_request->before_chunk_trace != NULL)
1119 lttv_hooks_destroy(events_request->before_chunk_trace);
1120 if(events_request->before_chunk_tracefile != NULL)
1121 lttv_hooks_destroy(events_request->before_chunk_tracefile);
1122 if(events_request->event != NULL)
1123 lttv_hooks_destroy(events_request->event);
1124 if(events_request->event_by_id != NULL)
1125 lttv_hooks_by_id_destroy(events_request->event_by_id);
1126 if(events_request->after_chunk_tracefile != NULL)
1127 lttv_hooks_destroy(events_request->after_chunk_tracefile);
1128 if(events_request->after_chunk_trace != NULL)
1129 lttv_hooks_destroy(events_request->after_chunk_trace);
1130 if(events_request->after_chunk_traceset != NULL)
1131 lttv_hooks_destroy(events_request->after_chunk_traceset);
1132 if(events_request->before_request != NULL)
1133 lttv_hooks_destroy(events_request->before_request);
1134 if(events_request->after_request != NULL)
1135 lttv_hooks_destroy(events_request->after_request);
1136
1137 g_free(events_request);
1138 }
1139
1140
1141
1142 __EXPORT GtkWidget *main_window_get_widget(Tab *tab)
1143 {
1144 return tab->mw->mwindow;
1145 }
1146
This page took 0.048065 seconds and 3 git commands to generate.