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