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 | |
31 | #include <ltt/ltt.h> |
32 | #include <lttv/lttv.h> |
33 | #include <lttv/state.h> |
34 | #include <lttv/stats.h> |
35 | #include <lttv/tracecontext.h> |
501e4e70 |
36 | #include <lttvwindow/mainwindow.h> |
2d262115 |
37 | #include <lttvwindow/mainwindow-private.h> |
501e4e70 |
38 | #include <lttvwindow/lttvwindow.h> |
39 | #include <lttvwindow/toolbar.h> |
40 | #include <lttvwindow/menu.h> |
41 | #include <lttvwindow/callbacks.h> // for execute_events_requests |
42 | #include <lttvwindow/support.h> |
43 | |
44 | |
45 | /** |
46 | * Internal function parts |
47 | */ |
48 | |
49 | extern GSList * g_main_window_list; |
50 | |
51 | /** |
52 | * Function to set/update traceset for the viewers |
53 | * @param tab viewer's tab |
54 | * @param traceset traceset of the main window. |
55 | * return value : |
56 | * -1 : error |
57 | * 0 : traceset updated |
58 | * 1 : no traceset hooks to update; not an error. |
59 | */ |
60 | |
2d262115 |
61 | int SetTraceset(Tab * tab, LttvTraceset *traceset) |
501e4e70 |
62 | { |
63 | LttvHooks * tmp; |
64 | LttvAttributeValue value; |
65 | |
66 | if( lttv_iattribute_find_by_path(tab->attributes, |
67 | "hooks/updatetraceset", LTTV_POINTER, &value) != 0) |
68 | return -1; |
69 | |
70 | tmp = (LttvHooks*)*(value.v_pointer); |
71 | if(tmp == NULL) return 1; |
72 | |
73 | |
74 | lttv_hooks_call(tmp,traceset); |
75 | |
76 | return 0; |
77 | } |
78 | |
79 | |
80 | /** |
81 | * Function to set/update filter for the viewers |
82 | * @param tab viewer's tab |
83 | * @param filter filter of the main window. |
84 | * return value : |
85 | * -1 : error |
86 | * 0 : filters updated |
87 | * 1 : no filter hooks to update; not an error. |
88 | */ |
89 | |
90 | int SetFilter(Tab * tab, gpointer filter) |
91 | { |
92 | LttvHooks * tmp; |
93 | LttvAttributeValue value; |
94 | |
95 | if(lttv_iattribute_find_by_path(tab->attributes, |
96 | "hooks/updatefilter", LTTV_POINTER, &value) != 0) |
97 | return -1; |
98 | |
99 | tmp = (LttvHooks*)*(value.v_pointer); |
100 | |
101 | if(tmp == NULL) return 1; |
102 | lttv_hooks_call(tmp,filter); |
103 | |
104 | return 0; |
105 | } |
106 | |
107 | /** |
108 | * Function to redraw each viewer belonging to the current tab |
109 | * @param tab viewer's tab |
110 | */ |
111 | |
112 | void update_traceset(Tab *tab) |
113 | { |
114 | LttvAttributeValue value; |
115 | LttvHooks * tmp; |
116 | g_assert(lttv_iattribute_find_by_path(tab->attributes, |
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 | |
123 | void set_time_window_adjustment(Tab *tab, const TimeWindow* new_time_window) |
124 | { |
125 | gtk_multi_vpaned_set_adjust(tab->multi_vpaned, new_time_window, FALSE); |
126 | } |
127 | |
128 | |
129 | void set_time_window(Tab *tab, const TimeWindow *time_window) |
130 | { |
131 | LttvAttributeValue value; |
132 | LttvHooks * tmp; |
133 | |
134 | TimeWindowNotifyData time_window_notify_data; |
135 | TimeWindow old_time_window = tab->time_window; |
136 | time_window_notify_data.old_time_window = &old_time_window; |
137 | tab->time_window = *time_window; |
138 | time_window_notify_data.new_time_window = |
139 | &(tab->time_window); |
140 | |
141 | g_assert(lttv_iattribute_find_by_path(tab->attributes, |
142 | "hooks/updatetimewindow", LTTV_POINTER, &value)); |
143 | tmp = (LttvHooks*)*(value.v_pointer); |
144 | if(tmp == NULL) return; |
145 | lttv_hooks_call(tmp, &time_window_notify_data); |
146 | |
147 | |
148 | } |
149 | |
150 | void add_toolbar_constructor(MainWindow *mw, LttvToolbarClosure *toolbar_c) |
151 | { |
152 | LttvIAttribute *attributes = mw->attributes; |
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) |
162 | *(value.v_pointer) = lttv_toolbars_new(); |
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 | "", |
174 | toolbar_c->tooltip, NULL, |
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 | |
188 | lttv_toolbars_add(instance_toolbar, toolbar_c->con, |
189 | toolbar_c->tooltip, |
190 | toolbar_c->pixmap, |
191 | new_widget); |
192 | |
193 | } |
194 | |
195 | void add_menu_constructor(MainWindow *mw, LttvMenuClosure *menu_c) |
196 | { |
197 | LttvIAttribute *attributes = mw->attributes; |
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) |
206 | *(value.v_pointer) = lttv_menus_new(); |
207 | instance_menu = (LttvMenus*)*(value.v_pointer); |
208 | |
209 | |
210 | constructor = menu_c->con; |
211 | tool_menu_title_menu = lookup_widget(mw->mwindow,"ToolMenuTitle_menu"); |
212 | new_widget = |
213 | gtk_menu_item_new_with_mnemonic (menu_c->menu_text); |
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 | |
226 | void remove_toolbar_constructor(MainWindow *mw, lttvwindow_viewer_constructor viewer_constructor) |
227 | { |
228 | LttvIAttribute *attributes = mw->attributes; |
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) |
237 | *(value.v_pointer) = lttv_toolbars_new(); |
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 | |
247 | void remove_menu_constructor(MainWindow *mw, lttvwindow_viewer_constructor viewer_constructor) |
248 | { |
249 | LttvIAttribute *attributes = mw->attributes; |
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) |
259 | *(value.v_pointer) = lttv_menus_new(); |
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 | |
268 | /** |
269 | * API parts |
270 | */ |
271 | |
272 | |
273 | /** |
274 | * Function to register a view constructor so that main window can generate |
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. |
284 | * @param tooltip tooltip of the toolbar item. |
285 | * @param view_constructor constructor of the viewer. |
286 | */ |
287 | |
288 | void lttvwindow_register_constructor |
289 | (char * menu_path, |
290 | char * menu_text, |
291 | char ** pixmap, |
292 | char * tooltip, |
293 | lttvwindow_viewer_constructor view_constructor) |
294 | { |
295 | LttvIAttribute *attributes_global = LTTV_IATTRIBUTE(lttv_global_attributes()); |
296 | LttvToolbars * toolbar; |
297 | LttvMenus * menu; |
298 | LttvToolbarClosure toolbar_c; |
299 | LttvMenuClosure menu_c; |
300 | LttvAttributeValue value; |
301 | |
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); |
306 | |
307 | if(toolbar == NULL) { |
308 | toolbar = lttv_toolbars_new(); |
309 | *(value.v_pointer) = toolbar; |
310 | } |
311 | toolbar_c = lttv_toolbars_add(toolbar, view_constructor, tooltip, pixmap, |
312 | NULL); |
313 | |
314 | g_slist_foreach(g_main_window_list, |
315 | (gpointer)add_toolbar_constructor, |
316 | &toolbar_c); |
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 | } |
328 | menu_c = lttv_menus_add(menu, view_constructor, menu_path, menu_text,NULL); |
329 | |
330 | g_slist_foreach(g_main_window_list, |
331 | (gpointer)add_menu_constructor, |
332 | &menu_c); |
333 | } |
334 | } |
335 | |
336 | |
337 | /** |
338 | * Function to unregister the viewer's constructor, release the space |
339 | * occupied by menu_path, menu_text, pixmap, tooltip and constructor of the |
340 | * viewer. |
341 | * |
342 | * It will be called when a module is unloaded. |
343 | * |
344 | * @param view_constructor constructor of the viewer. |
345 | */ |
346 | |
347 | |
348 | void lttvwindow_unregister_constructor |
349 | (lttvwindow_viewer_constructor view_constructor) |
350 | { |
351 | LttvIAttribute *attributes_global = LTTV_IATTRIBUTE(lttv_global_attributes()); |
352 | LttvToolbars * toolbar; |
353 | LttvMenus * menu; |
354 | LttvAttributeValue value; |
355 | |
356 | g_assert(lttv_iattribute_find_by_path(attributes_global, |
357 | "viewers/toolbar", LTTV_POINTER, &value)); |
358 | toolbar = (LttvToolbars*)*(value.v_pointer); |
359 | |
360 | if(toolbar != NULL) { |
361 | g_slist_foreach(g_main_window_list, |
362 | (gpointer)remove_toolbar_constructor, |
363 | view_constructor); |
364 | lttv_toolbars_remove(toolbar, view_constructor); |
365 | } |
366 | |
367 | g_assert(lttv_iattribute_find_by_path(attributes_global, |
368 | "viewers/menu", LTTV_POINTER, &value)); |
369 | menu = (LttvMenus*)*(value.v_pointer); |
370 | |
371 | if(menu != NULL) { |
372 | g_slist_foreach(g_main_window_list, |
373 | (gpointer)remove_menu_constructor, |
374 | view_constructor); |
375 | lttv_menus_remove(menu, view_constructor); |
376 | } |
377 | } |
378 | |
379 | |
380 | /** |
381 | * Function to register a hook function for a viewer to set/update its |
382 | * time interval. |
383 | * @param tab viewer's tab |
384 | * @param hook hook function of the viewer. |
385 | * @param hook_data hook data associated with the hook function. |
386 | */ |
387 | void lttvwindow_register_time_window_notify(Tab *tab, |
388 | LttvHook hook, gpointer hook_data) |
389 | { |
390 | LttvAttributeValue value; |
391 | LttvHooks * tmp; |
392 | g_assert(lttv_iattribute_find_by_path(tab->attributes, |
393 | "hooks/updatetimewindow", LTTV_POINTER, &value)); |
394 | tmp = (LttvHooks*)*(value.v_pointer); |
395 | if(tmp == NULL){ |
396 | tmp = lttv_hooks_new(); |
397 | *(value.v_pointer) = tmp; |
398 | } |
399 | lttv_hooks_add(tmp, hook,hook_data, LTTV_PRIO_DEFAULT); |
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. |
406 | * @param tab viewer's tab |
407 | * @param hook hook function of the viewer. |
408 | * @param hook_data hook data associated with the hook function. |
409 | */ |
410 | |
411 | void lttvwindow_unregister_time_window_notify(Tab *tab, |
412 | LttvHook hook, gpointer hook_data) |
413 | { |
414 | LttvAttributeValue value; |
415 | LttvHooks * tmp; |
416 | g_assert(lttv_iattribute_find_by_path(tab->attributes, |
417 | "hooks/updatetimewindow", LTTV_POINTER, &value)); |
418 | tmp = (LttvHooks*)*(value.v_pointer); |
419 | if(tmp == NULL) return; |
420 | lttv_hooks_remove_data(tmp, hook, hook_data); |
421 | } |
422 | |
423 | /** |
424 | * Function to register a hook function for a viewer to set/update its |
425 | * traceset. |
426 | * @param tab viewer's tab |
427 | * @param hook hook function of the viewer. |
428 | * @param hook_data hook data associated with the hook function. |
429 | */ |
430 | |
431 | void lttvwindow_register_traceset_notify(Tab *tab, |
432 | LttvHook hook, gpointer hook_data) |
433 | { |
434 | LttvAttributeValue value; |
435 | LttvHooks * tmp; |
436 | g_assert(lttv_iattribute_find_by_path(tab->attributes, |
437 | "hooks/updatetraceset", LTTV_POINTER, &value)); |
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 traceset of the viewer. |
450 | * @param tab viewer's tab |
451 | * @param hook hook function of the viewer. |
452 | * @param hook_data hook data associated with the hook function. |
453 | */ |
454 | |
455 | void lttvwindow_unregister_traceset_notify(Tab *tab, |
456 | LttvHook hook, gpointer hook_data) |
457 | { |
458 | LttvAttributeValue value; |
459 | LttvHooks * tmp; |
460 | g_assert(lttv_iattribute_find_by_path(tab->attributes, |
461 | "hooks/updatetraceset", LTTV_POINTER, &value)); |
462 | tmp = (LttvHooks*)*(value.v_pointer); |
463 | if(tmp == NULL) return; |
464 | lttv_hooks_remove_data(tmp, hook, hook_data); |
465 | } |
466 | |
9878c8a4 |
467 | /** |
468 | * Function to register a hook function for a viewer be completely redrawn. |
469 | * |
470 | * @param tab viewer's tab |
471 | * @param hook hook function of the viewer. |
472 | * @param hook_data hook data associated with the hook function. |
473 | */ |
474 | |
475 | void lttvwindow_register_redraw_notify(Tab *tab, |
476 | LttvHook hook, gpointer hook_data) |
477 | { |
478 | LttvAttributeValue value; |
479 | LttvHooks * tmp; |
480 | g_assert(lttv_iattribute_find_by_path(tab->attributes, |
481 | "hooks/redraw", LTTV_POINTER, &value)); |
482 | tmp = (LttvHooks*)*(value.v_pointer); |
483 | if(tmp == NULL){ |
484 | tmp = lttv_hooks_new(); |
485 | *(value.v_pointer) = tmp; |
486 | } |
487 | lttv_hooks_add(tmp, hook, hook_data, LTTV_PRIO_DEFAULT); |
488 | } |
489 | |
490 | |
491 | /** |
492 | * Function to unregister a hook function for a viewer be completely redrawn. |
493 | * |
494 | * @param tab viewer's tab |
495 | * @param hook hook function of the viewer. |
496 | * @param hook_data hook data associated with the hook function. |
497 | */ |
498 | |
499 | void lttvwindow_unregister_redraw_notify(Tab *tab, |
500 | LttvHook hook, gpointer hook_data) |
501 | { |
502 | LttvAttributeValue value; |
503 | LttvHooks * tmp; |
504 | g_assert(lttv_iattribute_find_by_path(tab->attributes, |
505 | "hooks/redraw", LTTV_POINTER, &value)); |
506 | tmp = (LttvHooks*)*(value.v_pointer); |
507 | if(tmp == NULL) return; |
508 | lttv_hooks_remove_data(tmp, hook, hook_data); |
509 | } |
510 | |
511 | /** |
512 | * Function to register a hook function for a viewer to re-do the events |
513 | * requests for the needed interval. |
514 | * |
515 | * This action is typically done after a "stop". |
516 | * |
517 | * The typical hook will remove all current requests for the viewer |
518 | * and make requests for missing information. |
519 | * |
520 | * @param tab viewer's tab |
521 | * @param hook hook function of the viewer. |
522 | * @param hook_data hook data associated with the hook function. |
523 | */ |
524 | |
525 | void lttvwindow_register_continue_notify(Tab *tab, |
526 | LttvHook hook, gpointer hook_data) |
527 | { |
528 | LttvAttributeValue value; |
529 | LttvHooks * tmp; |
530 | g_assert(lttv_iattribute_find_by_path(tab->attributes, |
531 | "hooks/continue", LTTV_POINTER, &value)); |
532 | tmp = (LttvHooks*)*(value.v_pointer); |
533 | if(tmp == NULL){ |
534 | tmp = lttv_hooks_new(); |
535 | *(value.v_pointer) = tmp; |
536 | } |
537 | lttv_hooks_add(tmp, hook, hook_data, LTTV_PRIO_DEFAULT); |
538 | } |
539 | |
540 | |
541 | /** |
542 | * Function to unregister a hook function for a viewer to re-do the events |
543 | * requests for the needed interval. |
544 | * |
545 | * @param tab viewer's tab |
546 | * @param hook hook function of the viewer. |
547 | * @param hook_data hook data associated with the hook function. |
548 | */ |
549 | |
550 | void lttvwindow_unregister_continue_notify(Tab *tab, |
551 | LttvHook hook, gpointer hook_data) |
552 | { |
553 | LttvAttributeValue value; |
554 | LttvHooks * tmp; |
555 | g_assert(lttv_iattribute_find_by_path(tab->attributes, |
556 | "hooks/continue", LTTV_POINTER, &value)); |
557 | tmp = (LttvHooks*)*(value.v_pointer); |
558 | if(tmp == NULL) return; |
559 | lttv_hooks_remove_data(tmp, hook, hook_data); |
560 | } |
561 | |
562 | |
501e4e70 |
563 | /** |
564 | * Function to register a hook function for a viewer to set/update its |
565 | * filter. |
566 | * @param tab viewer's tab |
567 | * @param hook hook function of the viewer. |
568 | * @param hook_data hook data associated with the hook function. |
569 | */ |
570 | |
571 | void lttvwindow_register_filter_notify(Tab *tab, |
572 | LttvHook hook, gpointer hook_data) |
573 | { |
574 | LttvAttributeValue value; |
575 | LttvHooks * tmp; |
576 | g_assert(lttv_iattribute_find_by_path(tab->attributes, |
577 | "hooks/updatefilter", LTTV_POINTER, &value)); |
578 | tmp = (LttvHooks*)*(value.v_pointer); |
579 | if(tmp == NULL){ |
580 | tmp = lttv_hooks_new(); |
581 | *(value.v_pointer) = tmp; |
582 | } |
583 | lttv_hooks_add(tmp, hook, hook_data, LTTV_PRIO_DEFAULT); |
584 | } |
585 | |
586 | |
587 | /** |
588 | * Function to unregister a viewer's hook function which is used to |
589 | * set/update the filter of the viewer. |
590 | * @param tab viewer's tab |
591 | * @param hook hook function of the viewer. |
592 | * @param hook_data hook data associated with the hook function. |
593 | */ |
594 | |
595 | void lttvwindow_unregister_filter_notify(Tab *tab, |
596 | LttvHook hook, |
597 | gpointer hook_data) |
598 | { |
599 | LttvAttributeValue value; |
600 | LttvHooks * tmp; |
601 | g_assert(lttv_iattribute_find_by_path(tab->attributes, |
602 | "hooks/updatefilter", LTTV_POINTER, &value)); |
603 | tmp = (LttvHooks*)*(value.v_pointer); |
604 | if(tmp == NULL) return; |
605 | lttv_hooks_remove_data(tmp, hook, hook_data); |
606 | } |
607 | |
608 | /** |
609 | * Function to register a hook function for a viewer to set/update its |
610 | * current time. |
611 | * @param tab viewer's tab |
612 | * @param hook hook function of the viewer. |
613 | * @param hook_data hook data associated with the hook function. |
614 | */ |
615 | |
616 | void lttvwindow_register_current_time_notify(Tab *tab, |
617 | LttvHook hook, gpointer hook_data) |
618 | { |
619 | LttvAttributeValue value; |
620 | LttvHooks * tmp; |
621 | g_assert(lttv_iattribute_find_by_path(tab->attributes, |
622 | "hooks/updatecurrenttime", LTTV_POINTER, &value)); |
623 | tmp = (LttvHooks*)*(value.v_pointer); |
624 | if(tmp == NULL){ |
625 | tmp = lttv_hooks_new(); |
626 | *(value.v_pointer) = tmp; |
627 | } |
628 | lttv_hooks_add(tmp, hook, hook_data, LTTV_PRIO_DEFAULT); |
629 | } |
630 | |
631 | |
632 | /** |
633 | * Function to unregister a viewer's hook function which is used to |
634 | * set/update the current time of the viewer. |
635 | * @param tab viewer's tab |
636 | * @param hook hook function of the viewer. |
637 | * @param hook_data hook data associated with the hook function. |
638 | */ |
639 | |
640 | void lttvwindow_unregister_current_time_notify(Tab *tab, |
641 | LttvHook hook, gpointer hook_data) |
642 | { |
643 | LttvAttributeValue value; |
644 | LttvHooks * tmp; |
645 | g_assert(lttv_iattribute_find_by_path(tab->attributes, |
646 | "hooks/updatecurrenttime", LTTV_POINTER, &value)); |
647 | tmp = (LttvHooks*)*(value.v_pointer); |
648 | if(tmp == NULL) return; |
649 | lttv_hooks_remove_data(tmp, hook, hook_data); |
650 | } |
651 | |
652 | |
653 | /** |
654 | * Function to register a hook function for a viewer to show |
655 | * the content of the viewer. |
656 | * @param tab viewer's tab |
657 | * @param hook hook function of the viewer. |
658 | * @param hook_data hook data associated with the hook function. |
659 | */ |
660 | |
661 | void lttvwindow_register_show_notify(Tab *tab, |
662 | LttvHook hook, gpointer hook_data) |
663 | { |
664 | LttvAttributeValue value; |
665 | LttvHooks * tmp; |
666 | g_assert(lttv_iattribute_find_by_path(tab->attributes, |
667 | "hooks/showviewer", LTTV_POINTER, &value)); |
668 | tmp = (LttvHooks*)*(value.v_pointer); |
669 | if(tmp == NULL){ |
670 | tmp = lttv_hooks_new(); |
671 | *(value.v_pointer) = tmp; |
672 | } |
673 | lttv_hooks_add(tmp, hook, hook_data, LTTV_PRIO_DEFAULT); |
674 | } |
675 | |
676 | |
677 | /** |
678 | * Function to unregister a viewer's hook function which is used to |
679 | * show the content of the viewer.. |
680 | * @param tab viewer's tab |
681 | * @param hook hook function of the viewer. |
682 | * @param hook_data hook data associated with the hook function. |
683 | */ |
684 | |
685 | void lttvwindow_unregister_show_notify(Tab *tab, |
686 | LttvHook hook, gpointer hook_data) |
687 | { |
688 | LttvAttributeValue value; |
689 | LttvHooks * tmp; |
690 | g_assert(lttv_iattribute_find_by_path(tab->attributes, |
691 | "hooks/showviewer", LTTV_POINTER, &value)); |
692 | tmp = (LttvHooks*)*(value.v_pointer); |
693 | if(tmp == NULL) return; |
694 | lttv_hooks_remove_data(tmp, hook, hook_data); |
695 | } |
696 | |
697 | /** |
698 | * Function to register a hook function for a viewer to set/update the |
699 | * dividor of the hpane. |
700 | * @param tab viewer's tab |
701 | * @param hook hook function of the viewer. |
702 | * @param hook_data hook data associated with the hook function. |
703 | */ |
704 | |
705 | void lttvwindow_register_dividor(Tab *tab, |
706 | LttvHook hook, gpointer hook_data) |
707 | { |
708 | LttvAttributeValue value; |
709 | LttvHooks * tmp; |
710 | g_assert(lttv_iattribute_find_by_path(tab->attributes, |
711 | "hooks/hpanedividor", LTTV_POINTER, &value)); |
712 | tmp = (LttvHooks*)*(value.v_pointer); |
713 | if(tmp == NULL){ |
714 | tmp = lttv_hooks_new(); |
715 | *(value.v_pointer) = tmp; |
716 | } |
717 | lttv_hooks_add(tmp, hook, hook_data, LTTV_PRIO_DEFAULT); |
718 | } |
719 | |
720 | |
721 | /** |
722 | * Function to unregister a viewer's hook function which is used to |
723 | * set/update hpane's dividor of the viewer. |
724 | * It will be called by the destructor of the viewer. |
725 | * @param tab viewer's tab |
726 | * @param hook hook function of the viewer. |
727 | * @param hook_data hook data associated with the hook function. |
728 | */ |
729 | |
730 | void lttvwindow_unregister_dividor(Tab *tab, |
731 | LttvHook hook, gpointer hook_data) |
732 | { |
733 | LttvAttributeValue value; |
734 | LttvHooks * tmp; |
735 | g_assert(lttv_iattribute_find_by_path(tab->attributes, |
736 | "hooks/hpanedividor", LTTV_POINTER, &value)); |
737 | tmp = (LttvHooks*)*(value.v_pointer); |
738 | if(tmp == NULL) return; |
739 | lttv_hooks_remove_data(tmp, hook, hook_data); |
740 | } |
741 | |
742 | |
743 | /** |
744 | * Update the status bar whenever something changed in the viewer. |
745 | * @param tab viewer's tab |
746 | * @param info the message which will be shown in the status bar. |
747 | */ |
748 | |
749 | void lttvwindow_report_status(Tab *tab, const char *info) |
750 | { |
751 | //FIXME |
752 | g_warning("update_status not implemented in viewer.c"); |
753 | // Use tab->mw for status |
754 | } |
755 | |
756 | /** |
757 | * Function to set the time interval of the current tab. |
758 | * It will be called by a viewer's signal handle associated with |
759 | * the move_slider signal |
760 | * @param tab viewer's tab |
761 | * @param time_interval a pointer where time interval is stored. |
762 | */ |
763 | |
764 | void lttvwindow_report_time_window(Tab *tab, |
765 | const TimeWindow *time_window) |
766 | { |
767 | set_time_window(tab, time_window); |
768 | set_time_window_adjustment(tab, time_window); |
769 | } |
770 | |
771 | |
772 | /** |
773 | * Function to set the current time/event of the current tab. |
774 | * It will be called by a viewer's signal handle associated with |
775 | * the button-release-event signal |
776 | * @param tab viewer's tab |
777 | * @param time a pointer where time is stored. |
778 | */ |
779 | |
780 | void lttvwindow_report_current_time(Tab *tab, |
781 | const LttTime *time) |
782 | { |
783 | LttvAttributeValue value; |
784 | LttvHooks * tmp; |
785 | tab->current_time = *time; |
786 | g_assert(lttv_iattribute_find_by_path(tab->attributes, |
787 | "hooks/updatecurrenttime", LTTV_POINTER, &value)); |
788 | tmp = (LttvHooks*)*(value.v_pointer); |
789 | |
790 | if(tmp == NULL)return; |
791 | lttv_hooks_call(tmp, &tab->current_time); |
792 | } |
793 | |
794 | /** |
795 | * Function to set the position of the hpane's dividor (viewer). |
796 | * It will be called by a viewer's signal handle associated with |
797 | * the motion_notify_event event/signal |
798 | * @param tab viewer's tab |
799 | * @param position position of the hpane's dividor. |
800 | */ |
801 | |
802 | void lttvwindow_report_dividor(Tab *tab, gint position) |
803 | { |
804 | LttvAttributeValue value; |
805 | LttvHooks * tmp; |
806 | g_assert(lttv_iattribute_find_by_path(tab->attributes, |
807 | "hooks/hpanedividor", LTTV_POINTER, &value)); |
808 | tmp = (LttvHooks*)*(value.v_pointer); |
809 | if(tmp == NULL) return; |
810 | lttv_hooks_call(tmp, &position); |
811 | } |
812 | |
813 | /** |
814 | * Function to set the focused pane (viewer). |
815 | * It will be called by a viewer's signal handle associated with |
816 | * the grab_focus signal |
817 | * @param tab viewer's tab |
818 | * @param top_widget the top widget containing all the other widgets of the |
819 | * viewer. |
820 | */ |
821 | |
822 | void lttvwindow_report_focus(Tab *tab, GtkWidget *top_widget) |
823 | { |
824 | gtk_multi_vpaned_set_focus((GtkWidget*)tab->multi_vpaned, |
825 | GTK_PANED(gtk_widget_get_parent(top_widget))); |
826 | } |
827 | |
828 | |
829 | /** |
830 | * Function to request data in a specific time interval to the main window. The |
831 | * event request servicing is differed until the glib idle functions are |
832 | * called. |
833 | * |
834 | * The viewer has to provide hooks that should be associated with the event |
835 | * request. |
836 | * |
837 | * Either start time or start position must be defined in a EventRequest |
838 | * structure for it to be valid. |
839 | * |
840 | * end_time, end_position and num_events can all be defined. The first one |
841 | * to occur will be used as end criterion. |
842 | * |
843 | * @param tab viewer's tab |
844 | * @param events_requested the structure of request from. |
845 | */ |
846 | |
847 | void lttvwindow_events_request(Tab *tab, |
20fde85f |
848 | EventsRequest *events_request) |
501e4e70 |
849 | { |
20fde85f |
850 | tab->events_requests = g_slist_append(tab->events_requests, events_request); |
501e4e70 |
851 | |
852 | if(!tab->events_request_pending) |
853 | { |
854 | /* Redraw has +20 priority. We want a prio higher than that, so +19 */ |
855 | g_idle_add_full((G_PRIORITY_HIGH_IDLE + 19), |
856 | (GSourceFunc)execute_events_requests, |
857 | tab, |
858 | NULL); |
859 | tab->events_request_pending = TRUE; |
860 | } |
861 | } |
862 | |
863 | |
864 | /** |
865 | * Function to remove data requests related to a viewer. |
866 | * |
867 | * The existing requests's viewer gpointer is compared to the pointer |
868 | * given in argument to establish which data request should be removed. |
869 | * |
870 | * @param tab the tab the viewer belongs to. |
871 | * @param viewer a pointer to the viewer data structure |
872 | */ |
873 | |
874 | gint find_viewer (const EventsRequest *a, gconstpointer b) |
875 | { |
2d262115 |
876 | return (a->owner != b); |
501e4e70 |
877 | } |
878 | |
879 | |
880 | void lttvwindow_events_request_remove_all(Tab *tab, |
881 | gconstpointer viewer) |
882 | { |
883 | GSList *element; |
884 | |
885 | while((element = |
886 | g_slist_find_custom(tab->events_requests, viewer, |
887 | (GCompareFunc)find_viewer)) |
888 | != NULL) { |
2d262115 |
889 | EventsRequest *events_request = (EventsRequest *)element->data; |
501e4e70 |
890 | if(events_request->servicing == TRUE) { |
891 | lttv_hooks_call(events_request->after_request, NULL); |
892 | } |
893 | g_free(events_request); |
894 | tab->events_requests = g_slist_remove_link(tab->events_requests, element); |
895 | |
896 | } |
897 | } |
898 | |
899 | |
900 | |
901 | /** |
902 | * Function to get the current time interval shown on the current tab. |
903 | * It will be called by a viewer's hook function to update the |
904 | * shown time interval of the viewer and also be called by the constructor |
905 | * of the viewer. |
906 | * @param tab viewer's tab |
907 | * @param time_interval a pointer where time interval will be stored. |
908 | */ |
909 | |
910 | const TimeWindow *lttvwindow_get_time_window(Tab *tab) |
911 | { |
912 | return &(tab->time_window); |
913 | |
914 | } |
915 | |
916 | |
917 | /** |
918 | * Function to get the current time/event of the current tab. |
919 | * It will be called by a viewer's hook function to update the |
920 | * current time/event of the viewer. |
921 | * @param tab viewer's tab |
922 | * @param time a pointer where time will be stored. |
923 | */ |
924 | |
925 | const LttTime *lttvwindow_get_current_time(Tab *tab) |
926 | { |
927 | return &(tab->current_time); |
928 | } |
929 | |
930 | |
931 | /** |
932 | * Function to get the filter of the current tab. |
933 | * It will be called by the constructor of the viewer and also be |
934 | * called by a hook funtion of the viewer to update its filter. |
935 | * @param tab viewer's tab |
936 | * @param filter, a pointer to a filter. |
937 | */ |
938 | const lttv_filter *lttvwindow_get_filter(Tab *tab) |
939 | { |
940 | //FIXME |
941 | g_warning("lttvwindow_get_filter not implemented in viewer.c"); |
942 | } |
943 | |
944 | |
945 | /** |
946 | * Function to get the stats of the traceset |
947 | * @param tab viewer's tab |
948 | */ |
949 | |
950 | LttvTracesetStats* lttvwindow_get_traceset_stats(Tab *tab) |
951 | { |
952 | return tab->traceset_info->traceset_context; |
953 | } |
954 | |
955 | |
956 | LttvTracesetContext* lttvwindow_get_traceset_context(Tab *tab) |
957 | { |
958 | return (LttvTracesetContext*)tab->traceset_info->traceset_context; |
959 | } |