Add live trace read support to lttv base library and to command line modules
[lttv.git] / lttv / modules / gui / lttvwindow / lttvwindow / lttvwindow.c
CommitLineData
501e4e70 1/* This file is part of the Linux Trace Toolkit viewer
2 * Copyright (C) 2003-2004 XangXiu Yang
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License Version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
16 * MA 02111-1307, USA.
17 */
18
19/*! \file lttvwindow.c
20 * \brief API used by the graphical viewers to interact with their tab.
21 *
22 * Main window (gui module) is the place to contain and display viewers.
23 * Viewers (lttv plugins) interact with tab and main window through this API
24 * and events sent by gtk.
25 * This header file should be included in each graphic module.
26 * This library is used by graphical modules to interact with their tab and
27 * main window.
28 *
29 */
30
4e4d11b3 31#ifdef HAVE_CONFIG_H
32#include <config.h>
33#endif
34
501e4e70 35#include <ltt/ltt.h>
36#include <lttv/lttv.h>
37#include <lttv/state.h>
38#include <lttv/stats.h>
39#include <lttv/tracecontext.h>
501e4e70 40#include <lttvwindow/mainwindow.h>
2d262115 41#include <lttvwindow/mainwindow-private.h>
501e4e70 42#include <lttvwindow/lttvwindow.h>
43#include <lttvwindow/toolbar.h>
44#include <lttvwindow/menu.h>
45#include <lttvwindow/callbacks.h> // for execute_events_requests
46#include <lttvwindow/support.h>
47
501e4e70 48/**
49 * Internal function parts
50 */
51
52extern GSList * g_main_window_list;
53
f9240312 54__EXPORT gint lttvwindow_preempt_count = 0;
3c456a8a 55
b052368a 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 */
501e4e70 63
64void set_time_window(Tab *tab, const TimeWindow *time_window)
65{
66 LttvAttributeValue value;
67 LttvHooks * tmp;
8f318283 68 gboolean retval;
501e4e70 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
8f318283
BP
77 retval= lttv_iattribute_find_by_path(tab->attributes,
78 "hooks/updatetimewindow", LTTV_POINTER, &value);
79 g_assert(retval);
501e4e70 80 tmp = (LttvHooks*)*(value.v_pointer);
b052368a 81 if(tmp != NULL) lttv_hooks_call(tmp, &time_window_notify_data);
501e4e70 82
b052368a 83 //gtk_multi_vpaned_set_adjust(tab->multi_vpaned, new_time_window, FALSE);
501e4e70 84
85}
86
db8bc917 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
95void set_current_time(Tab *tab, const LttTime *current_time)
96{
97 LttvAttributeValue value;
98 LttvHooks * tmp;
8f318283 99 gboolean retval;
db8bc917 100
101 tab->current_time = *current_time;
102
8f318283
BP
103 retval= lttv_iattribute_find_by_path(tab->attributes,
104 "hooks/updatecurrenttime", LTTV_POINTER, &value);
105 g_assert(retval);
db8bc917 106 tmp = (LttvHooks*)*(value.v_pointer);
107 if(tmp != NULL) lttv_hooks_call(tmp, &tab->current_time);
108}
109
5290ec02 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
118void set_current_position(Tab *tab, const LttvTracesetContextPosition *pos)
119{
120 LttvAttributeValue value;
121 LttvHooks * tmp;
8f318283 122 gboolean retval;
5290ec02 123
124 tab->current_time = lttv_traceset_context_position_get_time(pos);
125
8f318283
BP
126 retval= lttv_iattribute_find_by_path(tab->attributes,
127 "hooks/updatecurrentposition", LTTV_POINTER, &value);
128 g_assert(retval);
5290ec02 129 tmp = (LttvHooks*)*(value.v_pointer);
8d8c5ea7
AM
130 if (tmp != NULL) {
131 lttv_hooks_call(tmp, (void *) pos);
132 }
5290ec02 133}
134
501e4e70 135void 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;
8f318283 143 gboolean retval;
501e4e70 144
8f318283
BP
145 retval= lttv_iattribute_find_by_path(attributes, "viewers/toolbar",
146 LTTV_POINTER, &value);
147 g_assert(retval);
501e4e70 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
182void 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;
8f318283 189 gboolean retval;
501e4e70 190
8f318283
BP
191 retval= lttv_iattribute_find_by_path(attributes, "viewers/menu",
192 LTTV_POINTER, &value);
193 g_assert(retval);
501e4e70 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
215void remove_toolbar_constructor(MainWindow *mw, lttvwindow_viewer_constructor viewer_constructor)
216{
217 LttvIAttribute *attributes = mw->attributes;
218 LttvAttributeValue value;
219 LttvToolbars * instance_toolbar;
501e4e70 220 GtkWidget * tool_menu_title_menu, *widget;
8f318283 221 gboolean retval;
501e4e70 222
8f318283
BP
223 retval= lttv_iattribute_find_by_path(attributes, "viewers/toolbar",
224 LTTV_POINTER, &value);
225 g_assert(retval);
501e4e70 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
237void remove_menu_constructor(MainWindow *mw, lttvwindow_viewer_constructor viewer_constructor)
238{
239 LttvIAttribute *attributes = mw->attributes;
240 LttvAttributeValue value;
241 LttvMenus * instance_menu;
501e4e70 242 GtkWidget * tool_menu_title_menu, *widget;
8f318283 243 gboolean retval;
501e4e70 244
8f318283
BP
245 retval= lttv_iattribute_find_by_path(attributes, "viewers/menu",
246 LTTV_POINTER, &value);
247 g_assert(retval);
501e4e70 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 *
e025a729 271 * @param name name of the viewer
501e4e70 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
f9240312 279__EXPORT void lttvwindow_register_constructor
e025a729 280 (char * name,
281 char * menu_path,
501e4e70 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;
8f318283 293 gboolean retval;
501e4e70 294
e025a729 295 if(view_constructor == NULL) return;
296
501e4e70 297 if(pixmap != NULL) {
8f318283
BP
298 retval= lttv_iattribute_find_by_path(attributes_global, "viewers/toolbar",
299 LTTV_POINTER, &value);
300 g_assert(retval);
501e4e70 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) {
8f318283
BP
316 retval= lttv_iattribute_find_by_path(attributes_global, "viewers/menu",
317 LTTV_POINTER, &value);
318 g_assert(retval);
501e4e70 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 }
e025a729 331 {
332 LttvAttribute *attribute;
96c9eb79 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);
e025a729 339
96c9eb79 340 result = lttv_iattribute_find_by_path(LTTV_IATTRIBUTE(attribute),
341 name, LTTV_POINTER, &value);
342 g_assert(result);
e025a729 343
344 *(value.v_pointer) = view_constructor;
345
346 }
501e4e70 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
f9240312 361__EXPORT void lttvwindow_unregister_constructor
501e4e70 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;
8f318283
BP
368 gboolean is_named;
369 gboolean retval;
501e4e70 370
8f318283
BP
371 retval= lttv_iattribute_find_by_path(attributes_global, "viewers/toolbar",
372 LTTV_POINTER, &value);
373 g_assert(retval);
501e4e70 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
8f318283
BP
383 retval= lttv_iattribute_find_by_path(attributes_global, "viewers/menu",
384 LTTV_POINTER, &value);
385 g_assert(retval);
501e4e70 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 }
e025a729 394
395 {
396 LttvAttribute *attribute;
96c9eb79 397 attribute = LTTV_ATTRIBUTE(lttv_iattribute_find_subdir(
398 LTTV_IATTRIBUTE(attributes_global),
399 LTTV_VIEWER_CONSTRUCTORS));
400 g_assert(attribute);
e025a729 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++) {
c0cb4d12 409 type = lttv_iattribute_get(LTTV_IATTRIBUTE(attribute), i, &name, &value,
410 &is_named);
e025a729 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 }
501e4e70 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 */
f9240312 428__EXPORT void lttvwindow_register_time_window_notify(Tab *tab,
501e4e70 429 LttvHook hook, gpointer hook_data)
430{
431 LttvAttributeValue value;
432 LttvHooks * tmp;
8f318283
BP
433 gboolean retval;
434
435 retval= lttv_iattribute_find_by_path(tab->attributes,
436 "hooks/updatetimewindow", LTTV_POINTER, &value);
437 g_assert(retval);
501e4e70 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
f9240312 455__EXPORT void lttvwindow_unregister_time_window_notify(Tab *tab,
501e4e70 456 LttvHook hook, gpointer hook_data)
457{
458 LttvAttributeValue value;
459 LttvHooks * tmp;
8f318283
BP
460 gboolean retval;
461
462 retval= lttv_iattribute_find_by_path(tab->attributes,
463 "hooks/updatetimewindow", LTTV_POINTER, &value);
464 g_assert(retval);
501e4e70 465 tmp = (LttvHooks*)*(value.v_pointer);
466 if(tmp == NULL) return;
467 lttv_hooks_remove_data(tmp, hook, hook_data);
468}
469
470/**
471 * Function to register a hook function for a viewer to set/update its
472 * traceset.
473 * @param tab viewer's tab
474 * @param hook hook function of the viewer.
475 * @param hook_data hook data associated with the hook function.
476 */
477
f9240312 478__EXPORT void lttvwindow_register_traceset_notify(Tab *tab,
501e4e70 479 LttvHook hook, gpointer hook_data)
480{
481 LttvAttributeValue value;
482 LttvHooks * tmp;
8f318283
BP
483 gboolean retval;
484
485 retval= lttv_iattribute_find_by_path(tab->attributes,
486 "hooks/updatetraceset", LTTV_POINTER, &value);
487 g_assert(retval);
501e4e70 488 tmp = (LttvHooks*)*(value.v_pointer);
489 if(tmp == NULL){
490 tmp = lttv_hooks_new();
491 *(value.v_pointer) = tmp;
492 }
493 lttv_hooks_add(tmp, hook, hook_data, LTTV_PRIO_DEFAULT);
494}
495
496
497/**
498 * Function to unregister a viewer's hook function which is used to
499 * set/update the traceset of the viewer.
500 * @param tab viewer's tab
501 * @param hook hook function of the viewer.
502 * @param hook_data hook data associated with the hook function.
503 */
504
f9240312 505__EXPORT void lttvwindow_unregister_traceset_notify(Tab *tab,
501e4e70 506 LttvHook hook, gpointer hook_data)
507{
508 LttvAttributeValue value;
509 LttvHooks * tmp;
8f318283
BP
510 gboolean retval;
511
512 retval= lttv_iattribute_find_by_path(tab->attributes,
513 "hooks/updatetraceset", LTTV_POINTER, &value);
514 g_assert(retval);
501e4e70 515 tmp = (LttvHooks*)*(value.v_pointer);
516 if(tmp == NULL) return;
517 lttv_hooks_remove_data(tmp, hook, hook_data);
518}
519
9878c8a4 520/**
521 * Function to register a hook function for a viewer be completely redrawn.
522 *
523 * @param tab viewer's tab
524 * @param hook hook function of the viewer.
525 * @param hook_data hook data associated with the hook function.
526 */
527
f9240312 528__EXPORT void lttvwindow_register_redraw_notify(Tab *tab,
9878c8a4 529 LttvHook hook, gpointer hook_data)
530{
531 LttvAttributeValue value;
532 LttvHooks * tmp;
8f318283
BP
533 gboolean retval;
534
535 retval= lttv_iattribute_find_by_path(tab->attributes, "hooks/redraw",
536 LTTV_POINTER, &value);
537 g_assert(retval);
9878c8a4 538 tmp = (LttvHooks*)*(value.v_pointer);
539 if(tmp == NULL){
540 tmp = lttv_hooks_new();
541 *(value.v_pointer) = tmp;
542 }
543 lttv_hooks_add(tmp, hook, hook_data, LTTV_PRIO_DEFAULT);
544}
545
546
547/**
548 * Function to unregister a hook function for a viewer be completely redrawn.
549 *
550 * @param tab viewer's tab
551 * @param hook hook function of the viewer.
552 * @param hook_data hook data associated with the hook function.
553 */
554
f9240312 555__EXPORT void lttvwindow_unregister_redraw_notify(Tab *tab,
9878c8a4 556 LttvHook hook, gpointer hook_data)
557{
558 LttvAttributeValue value;
559 LttvHooks * tmp;
8f318283
BP
560 gboolean retval;
561
562 retval= lttv_iattribute_find_by_path(tab->attributes, "hooks/redraw",
563 LTTV_POINTER, &value);
564 g_assert(retval);
9878c8a4 565 tmp = (LttvHooks*)*(value.v_pointer);
566 if(tmp == NULL) return;
567 lttv_hooks_remove_data(tmp, hook, hook_data);
568}
569
570/**
571 * Function to register a hook function for a viewer to re-do the events
572 * requests for the needed interval.
573 *
574 * This action is typically done after a "stop".
575 *
576 * The typical hook will remove all current requests for the viewer
577 * and make requests for missing information.
578 *
579 * @param tab viewer's tab
580 * @param hook hook function of the viewer.
581 * @param hook_data hook data associated with the hook function.
582 */
583
f9240312 584__EXPORT void lttvwindow_register_continue_notify(Tab *tab,
9878c8a4 585 LttvHook hook, gpointer hook_data)
586{
587 LttvAttributeValue value;
588 LttvHooks * tmp;
8f318283
BP
589 gboolean retval;
590
591 retval= lttv_iattribute_find_by_path(tab->attributes, "hooks/continue",
592 LTTV_POINTER, &value);
593 g_assert(retval);
9878c8a4 594 tmp = (LttvHooks*)*(value.v_pointer);
595 if(tmp == NULL){
596 tmp = lttv_hooks_new();
597 *(value.v_pointer) = tmp;
598 }
599 lttv_hooks_add(tmp, hook, hook_data, LTTV_PRIO_DEFAULT);
600}
601
602
603/**
604 * Function to unregister a hook function for a viewer to re-do the events
605 * requests for the needed interval.
606 *
607 * @param tab viewer's tab
608 * @param hook hook function of the viewer.
609 * @param hook_data hook data associated with the hook function.
610 */
611
f9240312 612__EXPORT void lttvwindow_unregister_continue_notify(Tab *tab,
9878c8a4 613 LttvHook hook, gpointer hook_data)
614{
615 LttvAttributeValue value;
616 LttvHooks * tmp;
8f318283
BP
617 gboolean retval;
618
619 retval= lttv_iattribute_find_by_path(tab->attributes, "hooks/continue",
620 LTTV_POINTER, &value);
621 g_assert(retval);
9878c8a4 622 tmp = (LttvHooks*)*(value.v_pointer);
623 if(tmp == NULL) return;
624 lttv_hooks_remove_data(tmp, hook, hook_data);
625}
626
627
501e4e70 628/**
629 * Function to register a hook function for a viewer to set/update its
630 * filter.
631 * @param tab viewer's tab
632 * @param hook hook function of the viewer.
633 * @param hook_data hook data associated with the hook function.
634 */
635
f9240312 636__EXPORT void lttvwindow_register_filter_notify(Tab *tab,
501e4e70 637 LttvHook hook, gpointer hook_data)
638{
639 LttvAttributeValue value;
640 LttvHooks * tmp;
8f318283
BP
641 gboolean retval;
642
643 retval= lttv_iattribute_find_by_path(tab->attributes, "hooks/updatefilter",
644 LTTV_POINTER, &value);
645 g_assert(retval);
501e4e70 646 tmp = (LttvHooks*)*(value.v_pointer);
647 if(tmp == NULL){
648 tmp = lttv_hooks_new();
649 *(value.v_pointer) = tmp;
650 }
651 lttv_hooks_add(tmp, hook, hook_data, LTTV_PRIO_DEFAULT);
652}
653
654
655/**
656 * Function to unregister a viewer's hook function which is used to
657 * set/update the filter of the viewer.
658 * @param tab viewer's tab
659 * @param hook hook function of the viewer.
660 * @param hook_data hook data associated with the hook function.
661 */
662
f9240312 663__EXPORT void lttvwindow_unregister_filter_notify(Tab *tab,
501e4e70 664 LttvHook hook,
665 gpointer hook_data)
666{
667 LttvAttributeValue value;
668 LttvHooks * tmp;
8f318283
BP
669 gboolean retval;
670
671 retval= lttv_iattribute_find_by_path(tab->attributes, "hooks/updatefilter",
672 LTTV_POINTER, &value);
673 g_assert(retval);
501e4e70 674 tmp = (LttvHooks*)*(value.v_pointer);
675 if(tmp == NULL) return;
676 lttv_hooks_remove_data(tmp, hook, hook_data);
677}
678
679/**
5290ec02 680 * function to register a hook function for a viewer to set/update its
501e4e70 681 * current time.
682 * @param tab viewer's tab
683 * @param hook hook function of the viewer.
684 * @param hook_data hook data associated with the hook function.
685 */
686
f9240312 687__EXPORT void lttvwindow_register_current_time_notify(Tab *tab,
501e4e70 688 LttvHook hook, gpointer hook_data)
689{
690 LttvAttributeValue value;
691 LttvHooks * tmp;
8f318283
BP
692 gboolean retval;
693
694 retval= lttv_iattribute_find_by_path(tab->attributes,
695 "hooks/updatecurrenttime", LTTV_POINTER, &value);
696 g_assert(retval);
501e4e70 697 tmp = (LttvHooks*)*(value.v_pointer);
698 if(tmp == NULL){
699 tmp = lttv_hooks_new();
700 *(value.v_pointer) = tmp;
701 }
702 lttv_hooks_add(tmp, hook, hook_data, LTTV_PRIO_DEFAULT);
703}
704
705
706/**
5290ec02 707 * function to unregister a viewer's hook function which is used to
501e4e70 708 * set/update the current time of the viewer.
709 * @param tab viewer's tab
710 * @param hook hook function of the viewer.
711 * @param hook_data hook data associated with the hook function.
712 */
713
f9240312 714__EXPORT void lttvwindow_unregister_current_time_notify(Tab *tab,
501e4e70 715 LttvHook hook, gpointer hook_data)
716{
717 LttvAttributeValue value;
718 LttvHooks * tmp;
8f318283
BP
719 gboolean retval;
720
721 retval= lttv_iattribute_find_by_path(tab->attributes,
722 "hooks/updatecurrenttime", LTTV_POINTER, &value);
723 g_assert(retval);
501e4e70 724 tmp = (LttvHooks*)*(value.v_pointer);
725 if(tmp == NULL) return;
726 lttv_hooks_remove_data(tmp, hook, hook_data);
727}
728
5290ec02 729/**
730 * function to register a hook function for a viewer to set/update its
731 * current position.
732 * @param tab viewer's tab
733 * @param hook hook function of the viewer.
734 * @param hook_data hook data associated with the hook function.
735 */
736
f9240312 737__EXPORT void lttvwindow_register_current_position_notify(Tab *tab,
5290ec02 738 LttvHook hook, gpointer hook_data)
739{
740 LttvAttributeValue value;
741 LttvHooks * tmp;
8f318283
BP
742 gboolean retval;
743
744 retval= lttv_iattribute_find_by_path(tab->attributes,
745 "hooks/updatecurrentposition", LTTV_POINTER, &value);
746 g_assert(retval);
5290ec02 747 tmp = (LttvHooks*)*(value.v_pointer);
748 if(tmp == NULL){
749 tmp = lttv_hooks_new();
750 *(value.v_pointer) = tmp;
751 }
752 lttv_hooks_add(tmp, hook, hook_data, LTTV_PRIO_DEFAULT);
753}
754
755
756/**
757 * function to unregister a viewer's hook function which is used to
758 * set/update the current position of the viewer.
759 * @param tab viewer's tab
760 * @param hook hook function of the viewer.
761 * @param hook_data hook data associated with the hook function.
762 */
763
f9240312 764__EXPORT void lttvwindow_unregister_current_position_notify(Tab *tab,
5290ec02 765 LttvHook hook, gpointer hook_data)
766{
767 LttvAttributeValue value;
768 LttvHooks * tmp;
8f318283
BP
769 gboolean retval;
770
771 retval= lttv_iattribute_find_by_path(tab->attributes,
772 "hooks/updatecurrentposition", LTTV_POINTER, &value);
773 g_assert(retval);
5290ec02 774 tmp = (LttvHooks*)*(value.v_pointer);
775 if(tmp == NULL) return;
776 lttv_hooks_remove_data(tmp, hook, hook_data);
777}
778
501e4e70 779
780/**
781 * Function to register a hook function for a viewer to show
782 * the content of the viewer.
783 * @param tab viewer's tab
784 * @param hook hook function of the viewer.
785 * @param hook_data hook data associated with the hook function.
786 */
787
788void lttvwindow_register_show_notify(Tab *tab,
789 LttvHook hook, gpointer hook_data)
790{
791 LttvAttributeValue value;
792 LttvHooks * tmp;
8f318283
BP
793 gboolean retval;
794
795 retval= lttv_iattribute_find_by_path(tab->attributes, "hooks/showviewer",
796 LTTV_POINTER, &value);
797 g_assert(retval);
501e4e70 798 tmp = (LttvHooks*)*(value.v_pointer);
799 if(tmp == NULL){
800 tmp = lttv_hooks_new();
801 *(value.v_pointer) = tmp;
802 }
803 lttv_hooks_add(tmp, hook, hook_data, LTTV_PRIO_DEFAULT);
804}
805
806
807/**
808 * Function to unregister a viewer's hook function which is used to
809 * show the content of the viewer..
810 * @param tab viewer's tab
811 * @param hook hook function of the viewer.
812 * @param hook_data hook data associated with the hook function.
813 */
814
815void lttvwindow_unregister_show_notify(Tab *tab,
816 LttvHook hook, gpointer hook_data)
817{
818 LttvAttributeValue value;
819 LttvHooks * tmp;
8f318283
BP
820 gboolean retval;
821
822 retval= lttv_iattribute_find_by_path(tab->attributes, "hooks/showviewer",
823 LTTV_POINTER, &value);
824 g_assert(retval);
501e4e70 825 tmp = (LttvHooks*)*(value.v_pointer);
826 if(tmp == NULL) return;
827 lttv_hooks_remove_data(tmp, hook, hook_data);
828}
829
830/**
831 * Function to register a hook function for a viewer to set/update the
832 * dividor of the hpane.
833 * @param tab viewer's tab
834 * @param hook hook function of the viewer.
835 * @param hook_data hook data associated with the hook function.
836 */
837
838void lttvwindow_register_dividor(Tab *tab,
839 LttvHook hook, gpointer hook_data)
840{
841 LttvAttributeValue value;
842 LttvHooks * tmp;
8f318283
BP
843 gboolean retval;
844
845 retval= lttv_iattribute_find_by_path(tab->attributes, "hooks/hpanedividor",
846 LTTV_POINTER, &value);
847 g_assert(retval);
501e4e70 848 tmp = (LttvHooks*)*(value.v_pointer);
849 if(tmp == NULL){
850 tmp = lttv_hooks_new();
851 *(value.v_pointer) = tmp;
852 }
853 lttv_hooks_add(tmp, hook, hook_data, LTTV_PRIO_DEFAULT);
854}
855
856
857/**
858 * Function to unregister a viewer's hook function which is used to
859 * set/update hpane's dividor of the viewer.
860 * It will be called by the destructor of the viewer.
861 * @param tab viewer's tab
862 * @param hook hook function of the viewer.
863 * @param hook_data hook data associated with the hook function.
864 */
865
866void lttvwindow_unregister_dividor(Tab *tab,
867 LttvHook hook, gpointer hook_data)
868{
869 LttvAttributeValue value;
870 LttvHooks * tmp;
8f318283
BP
871 gboolean retval;
872
873 retval= lttv_iattribute_find_by_path(tab->attributes, "hooks/hpanedividor",
874 LTTV_POINTER, &value);
875 g_assert(retval);
501e4e70 876 tmp = (LttvHooks*)*(value.v_pointer);
877 if(tmp == NULL) return;
878 lttv_hooks_remove_data(tmp, hook, hook_data);
879}
880
881
501e4e70 882/**
883 * Function to set the time interval of the current tab.
884 * It will be called by a viewer's signal handle associated with
885 * the move_slider signal
886 * @param tab viewer's tab
887 * @param time_interval a pointer where time interval is stored.
888 */
889
f9240312 890__EXPORT void lttvwindow_report_time_window(Tab *tab,
891 TimeWindow time_window)
501e4e70 892{
b052368a 893 //set_time_window(tab, time_window);
894 //set_time_window_adjustment(tab, time_window);
895
e800cf84 896 time_change_manager(tab, time_window);
897
898
899#if 0
b052368a 900 /* Set scrollbar */
901 LttvTracesetContext *tsc =
902 LTTV_TRACESET_CONTEXT(tab->traceset_info->traceset_context);
903 TimeInterval time_span = tsc->time_span;
904 GtkAdjustment *adjustment = gtk_range_get_adjustment(GTK_RANGE(tab->scrollbar));
b052368a 905 g_object_set(G_OBJECT(adjustment),
906 "lower",
0c5dbe3b 907 0.0, /* lower */
b052368a 908 "upper",
b9a010a2 909 ltt_time_to_double(
910 ltt_time_sub(time_span.end_time, time_span.start_time))
c74e0cf9 911 , /* upper */
b052368a 912 "step_increment",
913 ltt_time_to_double(time_window->time_width)
914 / SCROLL_STEP_PER_PAGE
c74e0cf9 915 , /* step increment */
b052368a 916 "page_increment",
917 ltt_time_to_double(time_window->time_width)
c74e0cf9 918 , /* page increment */
b052368a 919 "page_size",
920 ltt_time_to_double(time_window->time_width)
c74e0cf9 921 , /* page size */
b052368a 922 NULL);
923 gtk_adjustment_changed(adjustment);
924
925 //g_object_set(G_OBJECT(adjustment),
926 // "value",
927 // ltt_time_to_double(time_window->start_time)
c74e0cf9 928 // , /* value */
b052368a 929 // NULL);
930 /* Note : the set value will call set_time_window if scrollbar value changed
931 */
932 gtk_adjustment_set_value(adjustment,
b9a010a2 933 ltt_time_to_double(
934 ltt_time_sub(time_window->start_time,
935 time_span.start_time))
c74e0cf9 936 );
e800cf84 937#endif //0
501e4e70 938}
939
940
941/**
5290ec02 942 * Function to set the current time of the current tab.
501e4e70 943 * It will be called by a viewer's signal handle associated with
944 * the button-release-event signal
945 * @param tab viewer's tab
946 * @param time a pointer where time is stored.
947 */
948
f9240312 949__EXPORT void lttvwindow_report_current_time(Tab *tab,
e800cf84 950 LttTime time)
501e4e70 951{
e800cf84 952 current_time_change_manager(tab, time);
501e4e70 953}
954
5290ec02 955/**
956 * Function to set the current event of the current tab.
957 * It will be called by a viewer's signal handle associated with
958 * the button-release-event signal
959 * @param tab viewer's tab
960 * @param time a pointer where time is stored.
961 */
962
f9240312 963__EXPORT void lttvwindow_report_current_position(Tab *tab,
5290ec02 964 LttvTracesetContextPosition *pos)
965{
5290ec02 966 current_position_change_manager(tab, pos);
967}
968
969
501e4e70 970/**
971 * Function to set the position of the hpane's dividor (viewer).
972 * It will be called by a viewer's signal handle associated with
973 * the motion_notify_event event/signal
974 * @param tab viewer's tab
975 * @param position position of the hpane's dividor.
976 */
977
978void lttvwindow_report_dividor(Tab *tab, gint position)
979{
980 LttvAttributeValue value;
981 LttvHooks * tmp;
8f318283
BP
982 gboolean retval;
983
984 retval= lttv_iattribute_find_by_path(tab->attributes, "hooks/hpanedividor",
985 LTTV_POINTER, &value);
986 g_assert(retval);
501e4e70 987 tmp = (LttvHooks*)*(value.v_pointer);
988 if(tmp == NULL) return;
989 lttv_hooks_call(tmp, &position);
990}
991
501e4e70 992/**
993 * Function to request data in a specific time interval to the main window. The
994 * event request servicing is differed until the glib idle functions are
995 * called.
996 *
997 * The viewer has to provide hooks that should be associated with the event
998 * request.
999 *
1000 * Either start time or start position must be defined in a EventRequest
1001 * structure for it to be valid.
1002 *
1003 * end_time, end_position and num_events can all be defined. The first one
1004 * to occur will be used as end criterion.
1005 *
1006 * @param tab viewer's tab
1007 * @param events_requested the structure of request from.
1008 */
1009
f9240312 1010__EXPORT void lttvwindow_events_request(Tab *tab,
1011 EventsRequest *events_request)
501e4e70 1012{
20fde85f 1013 tab->events_requests = g_slist_append(tab->events_requests, events_request);
501e4e70 1014
1015 if(!tab->events_request_pending)
1016 {
553d1e7b 1017 /* Redraw has +20 priority. We want to let the redraw be done while we do
e140c5b3 1018 * our job. Mathieu : test with high prio higher than events for better
1019 * scrolling. */
c55068ce 1020 /* Mathieu, 2008 : ok, finally, the control flow view needs the cell updates
1021 * to come soon enough so we can have one active cell to get the pixmap
1022 * buffer height from. Therefore, let the gdk events run before the events
1023 * requests.
1024 */
1025 g_idle_add_full((G_PRIORITY_HIGH_IDLE + 21),
1026 //g_idle_add_full((G_PRIORITY_DEFAULT + 2),
501e4e70 1027 (GSourceFunc)execute_events_requests,
1028 tab,
1029 NULL);
1030 tab->events_request_pending = TRUE;
1031 }
1032}
1033
1034
1035/**
1036 * Function to remove data requests related to a viewer.
1037 *
1038 * The existing requests's viewer gpointer is compared to the pointer
1039 * given in argument to establish which data request should be removed.
1040 *
1041 * @param tab the tab the viewer belongs to.
1042 * @param viewer a pointer to the viewer data structure
1043 */
1044
1045gint find_viewer (const EventsRequest *a, gconstpointer b)
1046{
2d262115 1047 return (a->owner != b);
501e4e70 1048}
1049
1050
f9240312 1051__EXPORT void lttvwindow_events_request_remove_all(Tab *tab,
501e4e70 1052 gconstpointer viewer)
1053{
6843100a 1054 GSList *element = tab->events_requests;
501e4e70 1055
1056 while((element =
6843100a 1057 g_slist_find_custom(element, viewer,
501e4e70 1058 (GCompareFunc)find_viewer))
1059 != NULL) {
2d262115 1060 EventsRequest *events_request = (EventsRequest *)element->data;
3bafb436 1061 // Modified so a viewer being destroyed won't have its after_request
1062 // called. Not so important anyway. Note that a viewer that call this
1063 // remove_all function will not get its after_request called.
1064 //if(events_request->servicing == TRUE) {
1065 // lttv_hooks_call(events_request->after_request, NULL);
1066 //}
c5b5eee1 1067 events_request_free(events_request);
1068 //g_free(events_request);
501e4e70 1069 tab->events_requests = g_slist_remove_link(tab->events_requests, element);
6843100a 1070 element = g_slist_next(element);
1071 if(element == NULL) break; /* end of list */
501e4e70 1072 }
b052368a 1073 if(g_slist_length(tab->events_requests) == 0) {
1074 tab->events_request_pending = FALSE;
1075 g_idle_remove_by_data(tab);
1076 }
1077
501e4e70 1078}
1079
efcd775d 1080
1081/**
1082 * Function to see if there are events request pending.
1083 *
1084 * It tells if events requests are pending. Useful for checks in some events,
1085 * i.e. detailed event list scrolling.
1086 *
1087 * @param tab the tab the viewer belongs to.
1088 * @param viewer a pointer to the viewer data structure
1089 * @return : TRUE is events requests are pending, else FALSE.
1090 */
1091
f9240312 1092__EXPORT gboolean lttvwindow_events_request_pending(Tab *tab)
efcd775d 1093{
1094 GSList *element = tab->events_requests;
1095
1096 if(element == NULL) return FALSE;
1097 else return TRUE;
1098}
1099
1100
50106726 1101/**
1102 * Function to get the current time interval shown on the current tab.
1103 * It will be called by a viewer's hook function to update the
1104 * shown time interval of the viewer and also be called by the constructor
1105 * of the viewer.
1106 * @param tab viewer's tab
1107 * @return time window.
1108 */
1109
f9240312 1110__EXPORT TimeWindow lttvwindow_get_time_window(Tab *tab)
50106726 1111{
1112 return tab->time_window;
1113}
1114
501e4e70 1115
501e4e70 1116/**
1117 * Function to get the current time/event of the current tab.
1118 * It will be called by a viewer's hook function to update the
1119 * current time/event of the viewer.
1120 * @param tab viewer's tab
6ea08962 1121 * @return time
501e4e70 1122 */
1123
f9240312 1124__EXPORT LttTime lttvwindow_get_current_time(Tab *tab)
501e4e70 1125{
6ea08962 1126 return tab->current_time;
501e4e70 1127}
1128
1129
1130/**
1131 * Function to get the filter of the current tab.
501e4e70 1132 * @param filter, a pointer to a filter.
c790dfd9 1133 *
1134 * returns the current filter
501e4e70 1135 */
f9240312 1136__EXPORT LttvFilter *lttvwindow_get_filter(Tab *tab)
501e4e70 1137{
e433e6d6 1138 return g_object_get_data(G_OBJECT(tab->vbox), "filter");
501e4e70 1139}
1140
dc5e5266 1141/**
1142 * Function to set the filter of the current tab.
1143 * It should be called by the filter GUI to tell the
1144 * main window to update the filter tab's lttv_filter.
1145 *
1146 * This function does change the current filter, removing the
1147 * old one when necessary, and call the updatefilter hooks
1148 * of the registered viewers.
1149 *
1150 * @param main_win, the main window the viewer belongs to.
1151 * @param filter, a pointer to a filter.
1152 */
dc5e5266 1153void lttvwindow_report_filter(Tab *tab, LttvFilter *filter)
1154{
1155 LttvAttributeValue value;
1156 LttvHooks * tmp;
8f318283 1157 gboolean retval;
dc5e5266 1158
e433e6d6 1159 //lttv_filter_destroy(tab->filter);
1160 //tab->filter = filter;
dc5e5266 1161
8f318283
BP
1162 retval= lttv_iattribute_find_by_path(tab->attributes, "hooks/updatefilter",
1163 LTTV_POINTER, &value);
1164 g_assert(retval);
dc5e5266 1165 tmp = (LttvHooks*)*(value.v_pointer);
1166 if(tmp == NULL) return;
962e2228 1167 lttv_hooks_call(tmp, filter);
dc5e5266 1168}
1169
1170
501e4e70 1171
1172/**
1173 * Function to get the stats of the traceset
1174 * @param tab viewer's tab
1175 */
1176
f9240312 1177__EXPORT LttvTracesetStats* lttvwindow_get_traceset_stats(Tab *tab)
501e4e70 1178{
1179 return tab->traceset_info->traceset_context;
1180}
1181
f9240312 1182__EXPORT LttvTracesetContext* lttvwindow_get_traceset_context(Tab *tab)
501e4e70 1183{
1184 return (LttvTracesetContext*)tab->traceset_info->traceset_context;
1185}
c5b5eee1 1186
1187
1188void events_request_free(EventsRequest *events_request)
1189{
1190 if(events_request == NULL) return;
1191
1192 if(events_request->start_position != NULL)
1193 lttv_traceset_context_position_destroy(events_request->start_position);
1194 if(events_request->end_position != NULL)
1195 lttv_traceset_context_position_destroy(events_request->end_position);
1196 if(events_request->hooks != NULL) {
c5b5eee1 1197 GArray *hooks = events_request->hooks;
04348950 1198 lttv_trace_hook_remove_all(&hooks);
c5b5eee1 1199 g_array_free(events_request->hooks, TRUE);
1200 }
1201 if(events_request->before_chunk_traceset != NULL)
1202 lttv_hooks_destroy(events_request->before_chunk_traceset);
1203 if(events_request->before_chunk_trace != NULL)
1204 lttv_hooks_destroy(events_request->before_chunk_trace);
1205 if(events_request->before_chunk_tracefile != NULL)
1206 lttv_hooks_destroy(events_request->before_chunk_tracefile);
1207 if(events_request->event != NULL)
1208 lttv_hooks_destroy(events_request->event);
750eb11a 1209 if(events_request->event_by_id_channel != NULL)
1210 lttv_hooks_by_id_channel_destroy(events_request->event_by_id_channel);
c5b5eee1 1211 if(events_request->after_chunk_tracefile != NULL)
1212 lttv_hooks_destroy(events_request->after_chunk_tracefile);
1213 if(events_request->after_chunk_trace != NULL)
1214 lttv_hooks_destroy(events_request->after_chunk_trace);
1215 if(events_request->after_chunk_traceset != NULL)
1216 lttv_hooks_destroy(events_request->after_chunk_traceset);
1217 if(events_request->before_request != NULL)
1218 lttv_hooks_destroy(events_request->before_request);
1219 if(events_request->after_request != NULL)
1220 lttv_hooks_destroy(events_request->after_request);
1221
1222 g_free(events_request);
1223}
1224
1225
6a4f1205 1226
f9240312 1227__EXPORT GtkWidget *main_window_get_widget(Tab *tab)
6a4f1205 1228{
93ac601b 1229 return tab->mw->mwindow;
6a4f1205 1230}
1231
This page took 0.1237 seconds and 4 git commands to generate.