viewer -> lttvwindow name change
[lttv.git] / ltt / branches / poly / lttv / modules / gui / lttvwindow / lttvwindow / viewer.c
CommitLineData
cef97e7c 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
36b40c74 19/*! \file lttvviewer.c
0ddddd91 20 * \brief API used by the graphical viewers to interact with their tab.
561f5852 21 *
22 * Main window (gui module) is the place to contain and display viewers.
0ddddd91 23 * Viewers (lttv plugins) interact with tab and main window through this API
24 * and events sent by gtk.
561f5852 25 * This header file should be included in each graphic module.
0ddddd91 26 * This library is used by graphical modules to interact with their tab and
27 * main window.
561f5852 28 *
29 */
30
561f5852 31#include <ltt/ltt.h>
32#include <lttv/lttv.h>
a43d67ba 33#include <lttv/state.h>
34#include <lttv/stats.h>
35#include <lttv/tracecontext.h>
36#include <lttvwindow/common.h>
13f86ce2 37#include <lttvwindow/mainwindow.h>
36b40c74 38#include <lttvwindow/viewer.h>
13f86ce2 39#include <lttvwindow/toolbar.h>
40#include <lttvwindow/menu.h>
0ddddd91 41#include <lttvwindow/callbacks.h> // for execute_events_requests
42#include <lttvwindow/support.h>
6b1d3120 43
561f5852 44
45/**
46 * Internal function parts
47 */
48
0ddddd91 49extern GSList * g_main_window_list;
50
561f5852 51/**
52 * Function to set/update traceset for the viewers
0ddddd91 53 * @param tab viewer's tab
561f5852 54 * @param traceset traceset of the main window.
224446ce 55 * return value :
56 * -1 : error
57 * 0 : traceset updated
58 * 1 : no traceset hooks to update; not an error.
561f5852 59 */
60
0ddddd91 61int SetTraceset(Tab * tab, gpointer traceset)
561f5852 62{
63 LttvHooks * tmp;
64 LttvAttributeValue value;
65
0ddddd91 66 if( lttv_iattribute_find_by_path(tab->attributes,
224446ce 67 "hooks/updatetraceset", LTTV_POINTER, &value) != 0)
68 return -1;
69
561f5852 70 tmp = (LttvHooks*)*(value.v_pointer);
224446ce 71 if(tmp == NULL) return 1;
a43d67ba 72
224446ce 73
561f5852 74 lttv_hooks_call(tmp,traceset);
a43d67ba 75
224446ce 76 return 0;
561f5852 77}
78
79
80/**
81 * Function to set/update filter for the viewers
0ddddd91 82 * @param tab viewer's tab
561f5852 83 * @param filter filter of the main window.
224446ce 84 * return value :
85 * -1 : error
86 * 0 : filters updated
87 * 1 : no filter hooks to update; not an error.
561f5852 88 */
89
0ddddd91 90int SetFilter(Tab * tab, gpointer filter)
561f5852 91{
92 LttvHooks * tmp;
93 LttvAttributeValue value;
94
0ddddd91 95 if(lttv_iattribute_find_by_path(tab->attributes,
224446ce 96 "hooks/updatefilter", LTTV_POINTER, &value) != 0)
97 return -1;
98
561f5852 99 tmp = (LttvHooks*)*(value.v_pointer);
100
224446ce 101 if(tmp == NULL) return 1;
561f5852 102 lttv_hooks_call(tmp,filter);
224446ce 103
104 return 0;
105}
106
107/**
108 * Function to redraw each viewer belonging to the current tab
0ddddd91 109 * @param tab viewer's tab
224446ce 110 */
111
0ddddd91 112void update_traceset(Tab *tab)
224446ce 113{
114 LttvAttributeValue value;
115 LttvHooks * tmp;
0ddddd91 116 g_assert(lttv_iattribute_find_by_path(tab->attributes,
224446ce 117 "hooks/updatetraceset", LTTV_POINTER, &value));
118 tmp = (LttvHooks*)*(value.v_pointer);
119 if(tmp == NULL) return;
120 lttv_hooks_call(tmp, NULL);
121}
122
0ddddd91 123void set_time_window_adjustment(Tab *tab, const TimeWindow* new_time_window)
a43d67ba 124{
0ddddd91 125 gtk_multi_vpaned_set_adjust(tab->multi_vpaned, new_time_window, FALSE);
a43d67ba 126}
224446ce 127
128
0ddddd91 129void set_time_window(Tab *tab, const TimeWindow *time_window)
224446ce 130{
131 LttvAttributeValue value;
132 LttvHooks * tmp;
a43d67ba 133
134 TimeWindowNotifyData time_window_notify_data;
0ddddd91 135 TimeWindow old_time_window = tab->time_window;
a43d67ba 136 time_window_notify_data.old_time_window = &old_time_window;
0ddddd91 137 tab->time_window = *time_window;
a43d67ba 138 time_window_notify_data.new_time_window =
0ddddd91 139 &(tab->time_window);
a43d67ba 140
0ddddd91 141 g_assert(lttv_iattribute_find_by_path(tab->attributes,
a43d67ba 142 "hooks/updatetimewindow", LTTV_POINTER, &value));
224446ce 143 tmp = (LttvHooks*)*(value.v_pointer);
144 if(tmp == NULL) return;
a43d67ba 145 lttv_hooks_call(tmp, &time_window_notify_data);
561f5852 146
147
a43d67ba 148}
224446ce 149
6c9d86dd 150void add_toolbar_constructor(MainWindow *mw, LttvToolbarClosure *toolbar_c)
151{
0ddddd91 152 LttvIAttribute *attributes = mw->attributes;
6c9d86dd 153 LttvAttributeValue value;
154 LttvToolbars * instance_toolbar;
155 lttvwindow_viewer_constructor constructor;
156 GtkWidget * tool_menu_title_menu, *new_widget, *pixmap;
157 GdkPixbuf *pixbuf;
158
159 g_assert(lttv_iattribute_find_by_path(attributes,
160 "viewers/toolbar", LTTV_POINTER, &value));
161 if(*(value.v_pointer) == NULL)
0ddddd91 162 *(value.v_pointer) = lttv_toolbars_new();
6c9d86dd 163 instance_toolbar = (LttvToolbars*)*(value.v_pointer);
164
165 constructor = toolbar_c->con;
166 tool_menu_title_menu = lookup_widget(mw->mwindow,"MToolbar1");
167 pixbuf = gdk_pixbuf_new_from_xpm_data((const char**)toolbar_c->pixmap);
168 pixmap = gtk_image_new_from_pixbuf(pixbuf);
169 new_widget =
170 gtk_toolbar_append_element (GTK_TOOLBAR (tool_menu_title_menu),
171 GTK_TOOLBAR_CHILD_BUTTON,
172 NULL,
173 "",
0ddddd91 174 toolbar_c->tooltip, NULL,
6c9d86dd 175 pixmap, NULL, NULL);
176 gtk_label_set_use_underline(
177 GTK_LABEL (((GtkToolbarChild*) (
178 g_list_last (GTK_TOOLBAR
179 (tool_menu_title_menu)->children)->data))->label),
180 TRUE);
181 gtk_container_set_border_width (GTK_CONTAINER (new_widget), 1);
182 g_signal_connect ((gpointer) new_widget,
183 "clicked",
184 G_CALLBACK (insert_viewer_wrap),
185 constructor);
186 gtk_widget_show (new_widget);
187
0ddddd91 188 lttv_toolbars_add(instance_toolbar, toolbar_c->con,
189 toolbar_c->tooltip,
190 toolbar_c->pixmap,
6c9d86dd 191 new_widget);
192
193}
194
195void add_menu_constructor(MainWindow *mw, LttvMenuClosure *menu_c)
196{
0ddddd91 197 LttvIAttribute *attributes = mw->attributes;
6c9d86dd 198 LttvAttributeValue value;
199 LttvToolbars * instance_menu;
200 lttvwindow_viewer_constructor constructor;
201 GtkWidget * tool_menu_title_menu, *new_widget;
202
203 g_assert(lttv_iattribute_find_by_path(attributes,
204 "viewers/menu", LTTV_POINTER, &value));
205 if(*(value.v_pointer) == NULL)
0ddddd91 206 *(value.v_pointer) = lttv_menus_new();
6c9d86dd 207 instance_menu = (LttvMenus*)*(value.v_pointer);
208
209
0ddddd91 210 constructor = menu_c->con;
6c9d86dd 211 tool_menu_title_menu = lookup_widget(mw->mwindow,"ToolMenuTitle_menu");
212 new_widget =
0ddddd91 213 gtk_menu_item_new_with_mnemonic (menu_c->menu_text);
6c9d86dd 214 gtk_container_add (GTK_CONTAINER (tool_menu_title_menu),
215 new_widget);
216 g_signal_connect ((gpointer) new_widget, "activate",
217 G_CALLBACK (insert_viewer_wrap),
218 constructor);
219 gtk_widget_show (new_widget);
220 lttv_menus_add(instance_menu, menu_c->con,
221 menu_c->menu_path,
222 menu_c->menu_text,
223 new_widget);
224}
225
226void remove_toolbar_constructor(MainWindow *mw, lttvwindow_viewer_constructor viewer_constructor)
227{
0ddddd91 228 LttvIAttribute *attributes = mw->attributes;
6c9d86dd 229 LttvAttributeValue value;
230 LttvToolbars * instance_toolbar;
231 lttvwindow_viewer_constructor constructor;
232 GtkWidget * tool_menu_title_menu, *widget;
233
234 g_assert(lttv_iattribute_find_by_path(attributes,
235 "viewers/toolbar", LTTV_POINTER, &value));
236 if(*(value.v_pointer) == NULL)
0ddddd91 237 *(value.v_pointer) = lttv_toolbars_new();
6c9d86dd 238 instance_toolbar = (LttvToolbars*)*(value.v_pointer);
239
240 tool_menu_title_menu = lookup_widget(mw->mwindow,"MToolbar1");
241 widget = lttv_menus_remove(instance_toolbar, viewer_constructor);
242 gtk_container_remove (GTK_CONTAINER (tool_menu_title_menu),
243 widget);
244}
245
246
247void remove_menu_constructor(MainWindow *mw, lttvwindow_viewer_constructor viewer_constructor)
248{
0ddddd91 249 LttvIAttribute *attributes = mw->attributes;
6c9d86dd 250 LttvAttributeValue value;
251 LttvMenus * instance_menu;
252 lttvwindow_viewer_constructor constructor;
253 GtkWidget * tool_menu_title_menu, *widget;
254 LttvMenuClosure *menu_item_i;
255
256 g_assert(lttv_iattribute_find_by_path(attributes,
257 "viewers/menu", LTTV_POINTER, &value));
258 if(*(value.v_pointer) == NULL)
0ddddd91 259 *(value.v_pointer) = lttv_menus_new();
6c9d86dd 260 instance_menu = (LttvMenus*)*(value.v_pointer);
261
262 widget = lttv_menus_remove(instance_menu, viewer_constructor);
263 tool_menu_title_menu = lookup_widget(mw->mwindow,"ToolMenuTitle_menu");
264 gtk_container_remove (GTK_CONTAINER (tool_menu_title_menu), widget);
265}
266
267
561f5852 268/**
269 * API parts
270 */
271
001d8606 272
561f5852 273/**
274 * Function to register a view constructor so that main window can generate
001d8606 275 * a menu item and a toolbar item for the viewer in order to generate a new
276 * instance easily. A menu entry and toolbar item will be added to each main
277 * window.
278 *
279 * It should be called by init function of the module.
280 *
281 * @param menu_path path of the menu item.
282 * @param menu_text text of the menu item.
283 * @param pixmap Image shown on the toolbar item.
561f5852 284 * @param tooltip tooltip of the toolbar item.
285 * @param view_constructor constructor of the viewer.
286 */
287
001d8606 288void lttvwindow_register_constructor
289 (char * menu_path,
290 char * menu_text,
291 char ** pixmap,
292 char * tooltip,
293 lttvwindow_viewer_constructor view_constructor)
561f5852 294{
295 LttvIAttribute *attributes_global = LTTV_IATTRIBUTE(lttv_global_attributes());
296 LttvToolbars * toolbar;
001d8606 297 LttvMenus * menu;
6c9d86dd 298 LttvToolbarClosure toolbar_c;
299 LttvMenuClosure menu_c;
561f5852 300 LttvAttributeValue value;
301
001d8606 302 if(pixmap != NULL) {
303 g_assert(lttv_iattribute_find_by_path(attributes_global,
304 "viewers/toolbar", LTTV_POINTER, &value));
305 toolbar = (LttvToolbars*)*(value.v_pointer);
561f5852 306
001d8606 307 if(toolbar == NULL) {
308 toolbar = lttv_toolbars_new();
309 *(value.v_pointer) = toolbar;
310 }
0ddddd91 311 toolbar_c = lttv_toolbars_add(toolbar, view_constructor, tooltip, pixmap,
312 NULL);
6c9d86dd 313
314 g_slist_foreach(g_main_window_list,
315 (gpointer)add_toolbar_constructor,
316 &toolbar_c);
001d8606 317 }
318
319 if(menu_path != NULL) {
320 g_assert(lttv_iattribute_find_by_path(attributes_global,
321 "viewers/menu", LTTV_POINTER, &value));
322 menu = (LttvMenus*)*(value.v_pointer);
323
324 if(menu == NULL) {
325 menu = lttv_menus_new();
326 *(value.v_pointer) = menu;
327 }
0ddddd91 328 menu_c = lttv_menus_add(menu, view_constructor, menu_path, menu_text,NULL);
6c9d86dd 329
330 g_slist_foreach(g_main_window_list,
331 (gpointer)add_menu_constructor,
332 &menu_c);
561f5852 333 }
561f5852 334}
335
336
337/**
338 * Function to unregister the viewer's constructor, release the space
001d8606 339 * occupied by menu_path, menu_text, pixmap, tooltip and constructor of the
340 * viewer.
341 *
561f5852 342 * It will be called when a module is unloaded.
001d8606 343 *
344 * @param view_constructor constructor of the viewer.
561f5852 345 */
346
001d8606 347
348void lttvwindow_unregister_constructor
349 (lttvwindow_viewer_constructor view_constructor)
561f5852 350{
351 LttvIAttribute *attributes_global = LTTV_IATTRIBUTE(lttv_global_attributes());
352 LttvToolbars * toolbar;
001d8606 353 LttvMenus * menu;
561f5852 354 LttvAttributeValue value;
355
356 g_assert(lttv_iattribute_find_by_path(attributes_global,
d2811a98 357 "viewers/toolbar", LTTV_POINTER, &value));
561f5852 358 toolbar = (LttvToolbars*)*(value.v_pointer);
359
001d8606 360 if(toolbar != NULL) {
6c9d86dd 361 g_slist_foreach(g_main_window_list,
362 (gpointer)remove_toolbar_constructor,
363 view_constructor);
001d8606 364 lttv_toolbars_remove(toolbar, view_constructor);
365 }
561f5852 366
367 g_assert(lttv_iattribute_find_by_path(attributes_global,
d2811a98 368 "viewers/menu", LTTV_POINTER, &value));
561f5852 369 menu = (LttvMenus*)*(value.v_pointer);
370
001d8606 371 if(menu != NULL) {
6c9d86dd 372 g_slist_foreach(g_main_window_list,
373 (gpointer)remove_menu_constructor,
374 view_constructor);
001d8606 375 lttv_menus_remove(menu, view_constructor);
561f5852 376 }
561f5852 377}
378
001d8606 379
561f5852 380/**
381 * Function to register a hook function for a viewer to set/update its
382 * time interval.
0ddddd91 383 * @param tab viewer's tab
561f5852 384 * @param hook hook function of the viewer.
385 * @param hook_data hook data associated with the hook function.
561f5852 386 */
0ddddd91 387void lttvwindow_register_time_window_notify(Tab *tab,
224446ce 388 LttvHook hook, gpointer hook_data)
561f5852 389{
390 LttvAttributeValue value;
391 LttvHooks * tmp;
0ddddd91 392 g_assert(lttv_iattribute_find_by_path(tab->attributes,
d2811a98 393 "hooks/updatetimewindow", LTTV_POINTER, &value));
561f5852 394 tmp = (LttvHooks*)*(value.v_pointer);
395 if(tmp == NULL){
396 tmp = lttv_hooks_new();
397 *(value.v_pointer) = tmp;
398 }
0ddddd91 399 lttv_hooks_add(tmp, hook,hook_data, LTTV_PRIO_DEFAULT);
561f5852 400}
401
402
403/**
404 * Function to unregister a viewer's hook function which is used to
405 * set/update the time interval of the viewer.
0ddddd91 406 * @param tab viewer's tab
561f5852 407 * @param hook hook function of the viewer.
408 * @param hook_data hook data associated with the hook function.
561f5852 409 */
410
0ddddd91 411void lttvwindow_unregister_time_window_notify(Tab *tab,
224446ce 412 LttvHook hook, gpointer hook_data)
561f5852 413{
414 LttvAttributeValue value;
415 LttvHooks * tmp;
0ddddd91 416 g_assert(lttv_iattribute_find_by_path(tab->attributes,
d2811a98 417 "hooks/updatetimewindow", LTTV_POINTER, &value));
561f5852 418 tmp = (LttvHooks*)*(value.v_pointer);
419 if(tmp == NULL) return;
420 lttv_hooks_remove_data(tmp, hook, hook_data);
421}
422
561f5852 423/**
424 * Function to register a hook function for a viewer to set/update its
425 * traceset.
0ddddd91 426 * @param tab viewer's tab
561f5852 427 * @param hook hook function of the viewer.
428 * @param hook_data hook data associated with the hook function.
561f5852 429 */
430
0ddddd91 431void lttvwindow_register_traceset_notify(Tab *tab,
224446ce 432 LttvHook hook, gpointer hook_data)
561f5852 433{
434 LttvAttributeValue value;
435 LttvHooks * tmp;
0ddddd91 436 g_assert(lttv_iattribute_find_by_path(tab->attributes,
d2811a98 437 "hooks/updatetraceset", LTTV_POINTER, &value));
561f5852 438 tmp = (LttvHooks*)*(value.v_pointer);
439 if(tmp == NULL){
440 tmp = lttv_hooks_new();
441 *(value.v_pointer) = tmp;
442 }
0ddddd91 443 lttv_hooks_add(tmp, hook, hook_data, LTTV_PRIO_DEFAULT);
561f5852 444}
445
446
447/**
448 * Function to unregister a viewer's hook function which is used to
449 * set/update the traceset of the viewer.
0ddddd91 450 * @param tab viewer's tab
561f5852 451 * @param hook hook function of the viewer.
452 * @param hook_data hook data associated with the hook function.
561f5852 453 */
454
0ddddd91 455void lttvwindow_unregister_traceset_notify(Tab *tab,
224446ce 456 LttvHook hook, gpointer hook_data)
561f5852 457{
458 LttvAttributeValue value;
459 LttvHooks * tmp;
0ddddd91 460 g_assert(lttv_iattribute_find_by_path(tab->attributes,
d2811a98 461 "hooks/updatetraceset", LTTV_POINTER, &value));
561f5852 462 tmp = (LttvHooks*)*(value.v_pointer);
463 if(tmp == NULL) return;
464 lttv_hooks_remove_data(tmp, hook, hook_data);
465}
466
561f5852 467/**
468 * Function to register a hook function for a viewer to set/update its
469 * filter.
0ddddd91 470 * @param tab viewer's tab
561f5852 471 * @param hook hook function of the viewer.
472 * @param hook_data hook data associated with the hook function.
561f5852 473 */
474
0ddddd91 475void lttvwindow_register_filter_notify(Tab *tab,
224446ce 476 LttvHook hook, gpointer hook_data)
561f5852 477{
478 LttvAttributeValue value;
479 LttvHooks * tmp;
0ddddd91 480 g_assert(lttv_iattribute_find_by_path(tab->attributes,
d2811a98 481 "hooks/updatefilter", LTTV_POINTER, &value));
561f5852 482 tmp = (LttvHooks*)*(value.v_pointer);
483 if(tmp == NULL){
484 tmp = lttv_hooks_new();
485 *(value.v_pointer) = tmp;
486 }
0ddddd91 487 lttv_hooks_add(tmp, hook, hook_data, LTTV_PRIO_DEFAULT);
561f5852 488}
489
490
491/**
492 * Function to unregister a viewer's hook function which is used to
493 * set/update the filter of the viewer.
0ddddd91 494 * @param tab viewer's tab
561f5852 495 * @param hook hook function of the viewer.
496 * @param hook_data hook data associated with the hook function.
561f5852 497 */
498
0ddddd91 499void lttvwindow_unregister_filter_notify(Tab *tab,
5a5b35c5 500 LttvHook hook,
501 gpointer hook_data)
561f5852 502{
503 LttvAttributeValue value;
504 LttvHooks * tmp;
0ddddd91 505 g_assert(lttv_iattribute_find_by_path(tab->attributes,
d2811a98 506 "hooks/updatefilter", LTTV_POINTER, &value));
561f5852 507 tmp = (LttvHooks*)*(value.v_pointer);
508 if(tmp == NULL) return;
509 lttv_hooks_remove_data(tmp, hook, hook_data);
510}
511
561f5852 512/**
513 * Function to register a hook function for a viewer to set/update its
514 * current time.
0ddddd91 515 * @param tab viewer's tab
561f5852 516 * @param hook hook function of the viewer.
517 * @param hook_data hook data associated with the hook function.
561f5852 518 */
519
0ddddd91 520void lttvwindow_register_current_time_notify(Tab *tab,
224446ce 521 LttvHook hook, gpointer hook_data)
561f5852 522{
523 LttvAttributeValue value;
524 LttvHooks * tmp;
0ddddd91 525 g_assert(lttv_iattribute_find_by_path(tab->attributes,
d2811a98 526 "hooks/updatecurrenttime", LTTV_POINTER, &value));
561f5852 527 tmp = (LttvHooks*)*(value.v_pointer);
528 if(tmp == NULL){
529 tmp = lttv_hooks_new();
530 *(value.v_pointer) = tmp;
531 }
0ddddd91 532 lttv_hooks_add(tmp, hook, hook_data, LTTV_PRIO_DEFAULT);
561f5852 533}
534
535
536/**
537 * Function to unregister a viewer's hook function which is used to
538 * set/update the current time of the viewer.
0ddddd91 539 * @param tab viewer's tab
561f5852 540 * @param hook hook function of the viewer.
541 * @param hook_data hook data associated with the hook function.
561f5852 542 */
543
0ddddd91 544void lttvwindow_unregister_current_time_notify(Tab *tab,
224446ce 545 LttvHook hook, gpointer hook_data)
561f5852 546{
547 LttvAttributeValue value;
548 LttvHooks * tmp;
0ddddd91 549 g_assert(lttv_iattribute_find_by_path(tab->attributes,
d2811a98 550 "hooks/updatecurrenttime", LTTV_POINTER, &value));
561f5852 551 tmp = (LttvHooks*)*(value.v_pointer);
552 if(tmp == NULL) return;
553 lttv_hooks_remove_data(tmp, hook, hook_data);
554}
555
556
202f6c8f 557/**
558 * Function to register a hook function for a viewer to show
224446ce 559 * the content of the viewer.
0ddddd91 560 * @param tab viewer's tab
202f6c8f 561 * @param hook hook function of the viewer.
562 * @param hook_data hook data associated with the hook function.
202f6c8f 563 */
564
0ddddd91 565void lttvwindow_register_show_notify(Tab *tab,
224446ce 566 LttvHook hook, gpointer hook_data)
202f6c8f 567{
568 LttvAttributeValue value;
569 LttvHooks * tmp;
0ddddd91 570 g_assert(lttv_iattribute_find_by_path(tab->attributes,
d2811a98 571 "hooks/showviewer", LTTV_POINTER, &value));
202f6c8f 572 tmp = (LttvHooks*)*(value.v_pointer);
573 if(tmp == NULL){
574 tmp = lttv_hooks_new();
575 *(value.v_pointer) = tmp;
576 }
0ddddd91 577 lttv_hooks_add(tmp, hook, hook_data, LTTV_PRIO_DEFAULT);
202f6c8f 578}
579
580
581/**
582 * Function to unregister a viewer's hook function which is used to
583 * show the content of the viewer..
0ddddd91 584 * @param tab viewer's tab
202f6c8f 585 * @param hook hook function of the viewer.
586 * @param hook_data hook data associated with the hook function.
202f6c8f 587 */
588
0ddddd91 589void lttvwindow_unregister_show_notify(Tab *tab,
224446ce 590 LttvHook hook, gpointer hook_data)
202f6c8f 591{
592 LttvAttributeValue value;
593 LttvHooks * tmp;
0ddddd91 594 g_assert(lttv_iattribute_find_by_path(tab->attributes,
d2811a98 595 "hooks/showviewer", LTTV_POINTER, &value));
202f6c8f 596 tmp = (LttvHooks*)*(value.v_pointer);
597 if(tmp == NULL) return;
598 lttv_hooks_remove_data(tmp, hook, hook_data);
599}
600
561f5852 601/**
602 * Function to register a hook function for a viewer to set/update the
603 * dividor of the hpane.
0ddddd91 604 * @param tab viewer's tab
561f5852 605 * @param hook hook function of the viewer.
606 * @param hook_data hook data associated with the hook function.
561f5852 607 */
608
0ddddd91 609void lttvwindow_register_dividor(Tab *tab,
224446ce 610 LttvHook hook, gpointer hook_data)
561f5852 611{
612 LttvAttributeValue value;
613 LttvHooks * tmp;
0ddddd91 614 g_assert(lttv_iattribute_find_by_path(tab->attributes,
d2811a98 615 "hooks/hpanedividor", LTTV_POINTER, &value));
561f5852 616 tmp = (LttvHooks*)*(value.v_pointer);
617 if(tmp == NULL){
618 tmp = lttv_hooks_new();
619 *(value.v_pointer) = tmp;
620 }
0ddddd91 621 lttv_hooks_add(tmp, hook, hook_data, LTTV_PRIO_DEFAULT);
561f5852 622}
623
624
625/**
626 * Function to unregister a viewer's hook function which is used to
627 * set/update hpane's dividor of the viewer.
628 * It will be called by the destructor of the viewer.
0ddddd91 629 * @param tab viewer's tab
561f5852 630 * @param hook hook function of the viewer.
631 * @param hook_data hook data associated with the hook function.
561f5852 632 */
633
0ddddd91 634void lttvwindow_unregister_dividor(Tab *tab,
224446ce 635 LttvHook hook, gpointer hook_data)
561f5852 636{
637 LttvAttributeValue value;
638 LttvHooks * tmp;
0ddddd91 639 g_assert(lttv_iattribute_find_by_path(tab->attributes,
d2811a98 640 "hooks/hpanedividor", LTTV_POINTER, &value));
561f5852 641 tmp = (LttvHooks*)*(value.v_pointer);
642 if(tmp == NULL) return;
643 lttv_hooks_remove_data(tmp, hook, hook_data);
644}
645
646
224446ce 647/**
648 * Update the status bar whenever something changed in the viewer.
0ddddd91 649 * @param tab viewer's tab
224446ce 650 * @param info the message which will be shown in the status bar.
651 */
652
0ddddd91 653void lttvwindow_report_status(Tab *tab, const char *info)
224446ce 654{
655 //FIXME
656 g_warning("update_status not implemented in viewer.c");
0ddddd91 657 // Use tab->mw for status
224446ce 658}
659
660/**
661 * Function to set the time interval of the current tab.
662 * It will be called by a viewer's signal handle associated with
663 * the move_slider signal
0ddddd91 664 * @param tab viewer's tab
224446ce 665 * @param time_interval a pointer where time interval is stored.
666 */
667
0ddddd91 668void lttvwindow_report_time_window(Tab *tab,
5a5b35c5 669 const TimeWindow *time_window)
224446ce 670{
0ddddd91 671 set_time_window(tab, time_window);
672 set_time_window_adjustment(tab, time_window);
224446ce 673}
674
a43d67ba 675
224446ce 676/**
677 * Function to set the current time/event of the current tab.
678 * It will be called by a viewer's signal handle associated with
679 * the button-release-event signal
0ddddd91 680 * @param tab viewer's tab
224446ce 681 * @param time a pointer where time is stored.
682 */
683
0ddddd91 684void lttvwindow_report_current_time(Tab *tab,
5a5b35c5 685 const LttTime *time)
224446ce 686{
687 LttvAttributeValue value;
688 LttvHooks * tmp;
0ddddd91 689 tab->current_time = *time;
690 g_assert(lttv_iattribute_find_by_path(tab->attributes,
224446ce 691 "hooks/updatecurrenttime", LTTV_POINTER, &value));
692 tmp = (LttvHooks*)*(value.v_pointer);
693
694 if(tmp == NULL)return;
0ddddd91 695 lttv_hooks_call(tmp, &tab->current_time);
224446ce 696}
697
561f5852 698/**
699 * Function to set the position of the hpane's dividor (viewer).
700 * It will be called by a viewer's signal handle associated with
701 * the motion_notify_event event/signal
0ddddd91 702 * @param tab viewer's tab
561f5852 703 * @param position position of the hpane's dividor.
704 */
705
0ddddd91 706void lttvwindow_report_dividor(Tab *tab, gint position)
561f5852 707{
708 LttvAttributeValue value;
709 LttvHooks * tmp;
0ddddd91 710 g_assert(lttv_iattribute_find_by_path(tab->attributes,
d2811a98 711 "hooks/hpanedividor", LTTV_POINTER, &value));
561f5852 712 tmp = (LttvHooks*)*(value.v_pointer);
713 if(tmp == NULL) return;
714 lttv_hooks_call(tmp, &position);
715}
716
224446ce 717/**
718 * Function to set the focused pane (viewer).
719 * It will be called by a viewer's signal handle associated with
720 * the grab_focus signal
0ddddd91 721 * @param tab viewer's tab
5a5b35c5 722 * @param top_widget the top widget containing all the other widgets of the
723 * viewer.
224446ce 724 */
725
0ddddd91 726void lttvwindow_report_focus(Tab *tab, GtkWidget *top_widget)
224446ce 727{
0ddddd91 728 gtk_multi_vpaned_set_focus((GtkWidget*)tab->multi_vpaned,
729 GTK_PANED(gtk_widget_get_parent(top_widget)));
224446ce 730}
731
732
a43d67ba 733/**
0ddddd91 734 * Function to request data in a specific time interval to the main window. The
735 * event request servicing is differed until the glib idle functions are
736 * called.
737 *
738 * The viewer has to provide hooks that should be associated with the event
739 * request.
740 *
741 * Either start time or start position must be defined in a EventRequest
742 * structure for it to be valid.
743 *
744 * end_time, end_position and num_events can all be defined. The first one
745 * to occur will be used as end criterion.
746 *
747 * @param tab viewer's tab
748 * @param events_requested the structure of request from.
a43d67ba 749 */
750
0ddddd91 751void lttvwindow_events_request(Tab *tab,
752 const EventsRequest *events_request)
a43d67ba 753{
0ddddd91 754 EventsRequest *alloc = g_new(sizeof(EventsRequest,1));
755 *alloc = *events_request;
a43d67ba 756
0ddddd91 757 tab->events_requests = g_slist_append(tab->events_requests, alloc);
a43d67ba 758
0ddddd91 759 if(!tab->events_request_pending)
a43d67ba 760 {
761 /* Redraw has +20 priority. We want a prio higher than that, so +19 */
762 g_idle_add_full((G_PRIORITY_HIGH_IDLE + 19),
0ddddd91 763 (GSourceFunc)execute_events_requests,
764 tab,
a43d67ba 765 NULL);
0ddddd91 766 tab->events_request_pending = TRUE;
a43d67ba 767 }
768}
769
0ddddd91 770
771/**
772 * Function to remove data requests related to a viewer.
773 *
774 * The existing requests's viewer gpointer is compared to the pointer
775 * given in argument to establish which data request should be removed.
776 *
777 * @param tab the tab the viewer belongs to.
778 * @param viewer a pointer to the viewer data structure
779 */
780
781gint find_viewer (const EventsRequest *a, gconstpointer b)
782{
783 return (a->viewer != b);
784}
785
786
787void lttvwindow_events_request_remove_all(Tab *tab,
788 gconstpointer viewer)
789{
790 GSList *element;
791
792 while((element =
793 g_slist_find_custom(tab->events_requests, viewer,
794 (GCompareFunc)find_viewer))
795 != NULL) {
796 EventRequest *events_request = (EventsRequest *)element->data;
797 if(events_request->servicing == TRUE) {
798 lttv_hooks_call(events_request->after_request, NULL);
799 }
800 g_free(events_request);
801 tab->events_requests = g_slist_remove_link(tab->events_requests, element);
802
803 }
804}
805
806
807
224446ce 808/**
809 * Function to get the current time interval shown on the current tab.
810 * It will be called by a viewer's hook function to update the
811 * shown time interval of the viewer and also be called by the constructor
812 * of the viewer.
0ddddd91 813 * @param tab viewer's tab
224446ce 814 * @param time_interval a pointer where time interval will be stored.
815 */
816
0ddddd91 817const TimeWindow *lttvwindow_get_time_window(Tab *tab)
224446ce 818{
0ddddd91 819 return &(tab->time_window);
224446ce 820
821}
822
823
824/**
825 * Function to get the current time/event of the current tab.
826 * It will be called by a viewer's hook function to update the
827 * current time/event of the viewer.
0ddddd91 828 * @param tab viewer's tab
224446ce 829 * @param time a pointer where time will be stored.
830 */
831
0ddddd91 832const LttTime *lttvwindow_get_current_time(Tab *tab)
224446ce 833{
0ddddd91 834 return &(tab->current_time);
224446ce 835}
836
837
224446ce 838/**
839 * Function to get the filter of the current tab.
840 * It will be called by the constructor of the viewer and also be
841 * called by a hook funtion of the viewer to update its filter.
0ddddd91 842 * @param tab viewer's tab
224446ce 843 * @param filter, a pointer to a filter.
844 */
0ddddd91 845const lttv_filter *lttvwindow_get_filter(Tab *tab)
224446ce 846{
847 //FIXME
848 g_warning("lttvwindow_get_filter not implemented in viewer.c");
849}
850
851
6b1d3120 852/**
853 * Function to get the stats of the traceset
0ddddd91 854 * @param tab viewer's tab
6b1d3120 855 */
856
0ddddd91 857LttvTracesetStats* lttvwindow_get_traceset_stats(Tab *tab)
6b1d3120 858{
0ddddd91 859 return tab->traceset_info->traceset_context;
6b1d3120 860}
a8c0f09d 861
862
0ddddd91 863LttvTracesetContext* lttvwindow_get_traceset_context(Tab *tab)
a8c0f09d 864{
0ddddd91 865 return (LttvTracesetContext*)tab->traceset_info->traceset_context;
a8c0f09d 866}
This page took 0.071326 seconds and 4 git commands to generate.