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