501e4e70 |
1 | /* This file is part of the Linux Trace Toolkit viewer |
2 | * Copyright (C) 2003-2004 XangXiu Yang |
3 | * |
4 | * This program is free software; you can redistribute it and/or modify |
5 | * it under the terms of the GNU General Public License Version 2 as |
6 | * published by the Free Software Foundation; |
7 | * |
8 | * This program is distributed in the hope that it will be useful, |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 | * GNU General Public License for more details. |
12 | * |
13 | * You should have received a copy of the GNU General Public License |
14 | * along with this program; if not, write to the Free Software |
15 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, |
16 | * MA 02111-1307, USA. |
17 | */ |
18 | |
19 | /*! \file lttvwindow.c |
20 | * \brief API used by the graphical viewers to interact with their tab. |
21 | * |
22 | * Main window (gui module) is the place to contain and display viewers. |
23 | * Viewers (lttv plugins) interact with tab and main window through this API |
24 | * and events sent by gtk. |
25 | * This header file should be included in each graphic module. |
26 | * This library is used by graphical modules to interact with their tab and |
27 | * main window. |
28 | * |
29 | */ |
30 | |
4e4d11b3 |
31 | #ifdef HAVE_CONFIG_H |
32 | #include <config.h> |
33 | #endif |
34 | |
501e4e70 |
35 | #include <ltt/ltt.h> |
36 | #include <lttv/lttv.h> |
37 | #include <lttv/state.h> |
38 | #include <lttv/stats.h> |
39 | #include <lttv/tracecontext.h> |
501e4e70 |
40 | #include <lttvwindow/mainwindow.h> |
2d262115 |
41 | #include <lttvwindow/mainwindow-private.h> |
501e4e70 |
42 | #include <lttvwindow/lttvwindow.h> |
43 | #include <lttvwindow/toolbar.h> |
44 | #include <lttvwindow/menu.h> |
45 | #include <lttvwindow/callbacks.h> // for execute_events_requests |
46 | #include <lttvwindow/support.h> |
47 | |
501e4e70 |
48 | /** |
49 | * Internal function parts |
50 | */ |
51 | |
52 | extern GSList * g_main_window_list; |
53 | |
b052368a |
54 | /* set_time_window |
55 | * |
56 | * It updates the time window of the tab, then calls the updatetimewindow |
57 | * hooks of each viewer. |
58 | * |
59 | * This is called whenever the scrollbar value changes. |
60 | */ |
501e4e70 |
61 | |
62 | void set_time_window(Tab *tab, const TimeWindow *time_window) |
63 | { |
64 | LttvAttributeValue value; |
65 | LttvHooks * tmp; |
66 | |
67 | TimeWindowNotifyData time_window_notify_data; |
68 | TimeWindow old_time_window = tab->time_window; |
69 | time_window_notify_data.old_time_window = &old_time_window; |
70 | tab->time_window = *time_window; |
71 | time_window_notify_data.new_time_window = |
72 | &(tab->time_window); |
73 | |
74 | g_assert(lttv_iattribute_find_by_path(tab->attributes, |
75 | "hooks/updatetimewindow", LTTV_POINTER, &value)); |
76 | tmp = (LttvHooks*)*(value.v_pointer); |
b052368a |
77 | if(tmp != NULL) lttv_hooks_call(tmp, &time_window_notify_data); |
501e4e70 |
78 | |
b052368a |
79 | //gtk_multi_vpaned_set_adjust(tab->multi_vpaned, new_time_window, FALSE); |
501e4e70 |
80 | |
81 | } |
82 | |
db8bc917 |
83 | /* set_current_time |
84 | * |
85 | * It updates the current time of the tab, then calls the updatetimewindow |
86 | * hooks of each viewer. |
87 | * |
88 | * This is called whenever the current time value changes. |
89 | */ |
90 | |
91 | void set_current_time(Tab *tab, const LttTime *current_time) |
92 | { |
93 | LttvAttributeValue value; |
94 | LttvHooks * tmp; |
95 | |
96 | tab->current_time = *current_time; |
97 | |
98 | g_assert(lttv_iattribute_find_by_path(tab->attributes, |
99 | "hooks/updatecurrenttime", LTTV_POINTER, &value)); |
100 | tmp = (LttvHooks*)*(value.v_pointer); |
101 | if(tmp != NULL) lttv_hooks_call(tmp, &tab->current_time); |
102 | } |
103 | |
5290ec02 |
104 | /* set_current_position |
105 | * |
106 | * It updates the current time of the tab, then calls the updatetimewindow |
107 | * hooks of each viewer. |
108 | * |
109 | * This is called whenever the current time value changes. |
110 | */ |
111 | |
112 | void set_current_position(Tab *tab, const LttvTracesetContextPosition *pos) |
113 | { |
114 | LttvAttributeValue value; |
115 | LttvHooks * tmp; |
116 | |
117 | tab->current_time = lttv_traceset_context_position_get_time(pos); |
118 | |
119 | g_assert(lttv_iattribute_find_by_path(tab->attributes, |
120 | "hooks/updatecurrentposition", LTTV_POINTER, &value)); |
121 | tmp = (LttvHooks*)*(value.v_pointer); |
122 | if(tmp != NULL) lttv_hooks_call(tmp, &pos); |
123 | } |
124 | |
501e4e70 |
125 | void add_toolbar_constructor(MainWindow *mw, LttvToolbarClosure *toolbar_c) |
126 | { |
127 | LttvIAttribute *attributes = mw->attributes; |
128 | LttvAttributeValue value; |
129 | LttvToolbars * instance_toolbar; |
130 | lttvwindow_viewer_constructor constructor; |
131 | GtkWidget * tool_menu_title_menu, *new_widget, *pixmap; |
132 | GdkPixbuf *pixbuf; |
133 | |
134 | g_assert(lttv_iattribute_find_by_path(attributes, |
135 | "viewers/toolbar", LTTV_POINTER, &value)); |
136 | if(*(value.v_pointer) == NULL) |
137 | *(value.v_pointer) = lttv_toolbars_new(); |
138 | instance_toolbar = (LttvToolbars*)*(value.v_pointer); |
139 | |
140 | constructor = toolbar_c->con; |
141 | tool_menu_title_menu = lookup_widget(mw->mwindow,"MToolbar1"); |
142 | pixbuf = gdk_pixbuf_new_from_xpm_data((const char**)toolbar_c->pixmap); |
143 | pixmap = gtk_image_new_from_pixbuf(pixbuf); |
144 | new_widget = |
145 | gtk_toolbar_append_element (GTK_TOOLBAR (tool_menu_title_menu), |
146 | GTK_TOOLBAR_CHILD_BUTTON, |
147 | NULL, |
148 | "", |
149 | toolbar_c->tooltip, NULL, |
150 | pixmap, NULL, NULL); |
151 | gtk_label_set_use_underline( |
152 | GTK_LABEL (((GtkToolbarChild*) ( |
153 | g_list_last (GTK_TOOLBAR |
154 | (tool_menu_title_menu)->children)->data))->label), |
155 | TRUE); |
156 | gtk_container_set_border_width (GTK_CONTAINER (new_widget), 1); |
157 | g_signal_connect ((gpointer) new_widget, |
158 | "clicked", |
159 | G_CALLBACK (insert_viewer_wrap), |
160 | constructor); |
161 | gtk_widget_show (new_widget); |
162 | |
163 | lttv_toolbars_add(instance_toolbar, toolbar_c->con, |
164 | toolbar_c->tooltip, |
165 | toolbar_c->pixmap, |
166 | new_widget); |
167 | |
168 | } |
169 | |
170 | void add_menu_constructor(MainWindow *mw, LttvMenuClosure *menu_c) |
171 | { |
172 | LttvIAttribute *attributes = mw->attributes; |
173 | LttvAttributeValue value; |
174 | LttvToolbars * instance_menu; |
175 | lttvwindow_viewer_constructor constructor; |
176 | GtkWidget * tool_menu_title_menu, *new_widget; |
177 | |
178 | g_assert(lttv_iattribute_find_by_path(attributes, |
179 | "viewers/menu", LTTV_POINTER, &value)); |
180 | if(*(value.v_pointer) == NULL) |
181 | *(value.v_pointer) = lttv_menus_new(); |
182 | instance_menu = (LttvMenus*)*(value.v_pointer); |
183 | |
184 | |
185 | constructor = menu_c->con; |
186 | tool_menu_title_menu = lookup_widget(mw->mwindow,"ToolMenuTitle_menu"); |
187 | new_widget = |
188 | gtk_menu_item_new_with_mnemonic (menu_c->menu_text); |
189 | gtk_container_add (GTK_CONTAINER (tool_menu_title_menu), |
190 | new_widget); |
191 | g_signal_connect ((gpointer) new_widget, "activate", |
192 | G_CALLBACK (insert_viewer_wrap), |
193 | constructor); |
194 | gtk_widget_show (new_widget); |
195 | lttv_menus_add(instance_menu, menu_c->con, |
196 | menu_c->menu_path, |
197 | menu_c->menu_text, |
198 | new_widget); |
199 | } |
200 | |
201 | void remove_toolbar_constructor(MainWindow *mw, lttvwindow_viewer_constructor viewer_constructor) |
202 | { |
203 | LttvIAttribute *attributes = mw->attributes; |
204 | LttvAttributeValue value; |
205 | LttvToolbars * instance_toolbar; |
206 | lttvwindow_viewer_constructor constructor; |
207 | GtkWidget * tool_menu_title_menu, *widget; |
208 | |
209 | g_assert(lttv_iattribute_find_by_path(attributes, |
210 | "viewers/toolbar", LTTV_POINTER, &value)); |
211 | if(*(value.v_pointer) == NULL) |
212 | *(value.v_pointer) = lttv_toolbars_new(); |
213 | instance_toolbar = (LttvToolbars*)*(value.v_pointer); |
214 | |
215 | tool_menu_title_menu = lookup_widget(mw->mwindow,"MToolbar1"); |
216 | widget = lttv_menus_remove(instance_toolbar, viewer_constructor); |
217 | gtk_container_remove (GTK_CONTAINER (tool_menu_title_menu), |
218 | widget); |
219 | } |
220 | |
221 | |
222 | void remove_menu_constructor(MainWindow *mw, lttvwindow_viewer_constructor viewer_constructor) |
223 | { |
224 | LttvIAttribute *attributes = mw->attributes; |
225 | LttvAttributeValue value; |
226 | LttvMenus * instance_menu; |
227 | lttvwindow_viewer_constructor constructor; |
228 | GtkWidget * tool_menu_title_menu, *widget; |
229 | LttvMenuClosure *menu_item_i; |
230 | |
231 | g_assert(lttv_iattribute_find_by_path(attributes, |
232 | "viewers/menu", LTTV_POINTER, &value)); |
233 | if(*(value.v_pointer) == NULL) |
234 | *(value.v_pointer) = lttv_menus_new(); |
235 | instance_menu = (LttvMenus*)*(value.v_pointer); |
236 | |
237 | widget = lttv_menus_remove(instance_menu, viewer_constructor); |
238 | tool_menu_title_menu = lookup_widget(mw->mwindow,"ToolMenuTitle_menu"); |
239 | gtk_container_remove (GTK_CONTAINER (tool_menu_title_menu), widget); |
240 | } |
241 | |
242 | |
243 | /** |
244 | * API parts |
245 | */ |
246 | |
247 | |
248 | /** |
249 | * Function to register a view constructor so that main window can generate |
250 | * a menu item and a toolbar item for the viewer in order to generate a new |
251 | * instance easily. A menu entry and toolbar item will be added to each main |
252 | * window. |
253 | * |
254 | * It should be called by init function of the module. |
255 | * |
e025a729 |
256 | * @param name name of the viewer |
501e4e70 |
257 | * @param menu_path path of the menu item. |
258 | * @param menu_text text of the menu item. |
259 | * @param pixmap Image shown on the toolbar item. |
260 | * @param tooltip tooltip of the toolbar item. |
261 | * @param view_constructor constructor of the viewer. |
262 | */ |
263 | |
264 | void lttvwindow_register_constructor |
e025a729 |
265 | (char * name, |
266 | char * menu_path, |
501e4e70 |
267 | char * menu_text, |
268 | char ** pixmap, |
269 | char * tooltip, |
270 | lttvwindow_viewer_constructor view_constructor) |
271 | { |
272 | LttvIAttribute *attributes_global = LTTV_IATTRIBUTE(lttv_global_attributes()); |
273 | LttvToolbars * toolbar; |
274 | LttvMenus * menu; |
275 | LttvToolbarClosure toolbar_c; |
276 | LttvMenuClosure menu_c; |
277 | LttvAttributeValue value; |
278 | |
e025a729 |
279 | if(view_constructor == NULL) return; |
280 | |
501e4e70 |
281 | if(pixmap != NULL) { |
282 | g_assert(lttv_iattribute_find_by_path(attributes_global, |
283 | "viewers/toolbar", LTTV_POINTER, &value)); |
284 | toolbar = (LttvToolbars*)*(value.v_pointer); |
285 | |
286 | if(toolbar == NULL) { |
287 | toolbar = lttv_toolbars_new(); |
288 | *(value.v_pointer) = toolbar; |
289 | } |
290 | toolbar_c = lttv_toolbars_add(toolbar, view_constructor, tooltip, pixmap, |
291 | NULL); |
292 | |
293 | g_slist_foreach(g_main_window_list, |
294 | (gpointer)add_toolbar_constructor, |
295 | &toolbar_c); |
296 | } |
297 | |
298 | if(menu_path != NULL) { |
299 | g_assert(lttv_iattribute_find_by_path(attributes_global, |
300 | "viewers/menu", LTTV_POINTER, &value)); |
301 | menu = (LttvMenus*)*(value.v_pointer); |
302 | |
303 | if(menu == NULL) { |
304 | menu = lttv_menus_new(); |
305 | *(value.v_pointer) = menu; |
306 | } |
307 | menu_c = lttv_menus_add(menu, view_constructor, menu_path, menu_text,NULL); |
308 | |
309 | g_slist_foreach(g_main_window_list, |
310 | (gpointer)add_menu_constructor, |
311 | &menu_c); |
312 | } |
e025a729 |
313 | { |
314 | LttvAttribute *attribute; |
315 | g_assert(attribute = |
316 | LTTV_ATTRIBUTE(lttv_iattribute_find_subdir( |
317 | LTTV_IATTRIBUTE(attributes_global), |
318 | LTTV_VIEWER_CONSTRUCTORS))); |
319 | |
320 | g_assert(lttv_iattribute_find_by_path(LTTV_IATTRIBUTE(attribute), |
321 | name, LTTV_POINTER, &value)); |
322 | |
323 | *(value.v_pointer) = view_constructor; |
324 | |
325 | } |
501e4e70 |
326 | } |
327 | |
328 | |
329 | /** |
330 | * Function to unregister the viewer's constructor, release the space |
331 | * occupied by menu_path, menu_text, pixmap, tooltip and constructor of the |
332 | * viewer. |
333 | * |
334 | * It will be called when a module is unloaded. |
335 | * |
336 | * @param view_constructor constructor of the viewer. |
337 | */ |
338 | |
339 | |
340 | void lttvwindow_unregister_constructor |
341 | (lttvwindow_viewer_constructor view_constructor) |
342 | { |
343 | LttvIAttribute *attributes_global = LTTV_IATTRIBUTE(lttv_global_attributes()); |
344 | LttvToolbars * toolbar; |
345 | LttvMenus * menu; |
346 | LttvAttributeValue value; |
347 | |
348 | g_assert(lttv_iattribute_find_by_path(attributes_global, |
349 | "viewers/toolbar", LTTV_POINTER, &value)); |
350 | toolbar = (LttvToolbars*)*(value.v_pointer); |
351 | |
352 | if(toolbar != NULL) { |
353 | g_slist_foreach(g_main_window_list, |
354 | (gpointer)remove_toolbar_constructor, |
355 | view_constructor); |
356 | lttv_toolbars_remove(toolbar, view_constructor); |
357 | } |
358 | |
359 | g_assert(lttv_iattribute_find_by_path(attributes_global, |
360 | "viewers/menu", LTTV_POINTER, &value)); |
361 | menu = (LttvMenus*)*(value.v_pointer); |
362 | |
363 | if(menu != NULL) { |
364 | g_slist_foreach(g_main_window_list, |
365 | (gpointer)remove_menu_constructor, |
366 | view_constructor); |
367 | lttv_menus_remove(menu, view_constructor); |
368 | } |
e025a729 |
369 | |
370 | { |
371 | LttvAttribute *attribute; |
372 | g_assert(attribute = |
373 | LTTV_ATTRIBUTE(lttv_iattribute_find_subdir( |
374 | LTTV_IATTRIBUTE(attributes_global), |
375 | LTTV_VIEWER_CONSTRUCTORS))); |
376 | |
377 | guint num = lttv_iattribute_get_number(LTTV_IATTRIBUTE(attribute)); |
378 | guint i; |
379 | LttvAttributeName name; |
380 | LttvAttributeValue value; |
381 | LttvAttributeType type; |
382 | |
383 | for(i=0;i<num;i++) { |
384 | type = lttv_iattribute_get(LTTV_IATTRIBUTE(attribute), i, &name, &value); |
385 | g_assert(type == LTTV_POINTER); |
386 | if(*(value.v_pointer) == view_constructor) { |
387 | lttv_iattribute_remove(LTTV_IATTRIBUTE(attribute), i); |
388 | break; |
389 | } |
390 | } |
391 | } |
501e4e70 |
392 | } |
393 | |
394 | |
395 | /** |
396 | * Function to register a hook function for a viewer to set/update its |
397 | * time interval. |
398 | * @param tab viewer's tab |
399 | * @param hook hook function of the viewer. |
400 | * @param hook_data hook data associated with the hook function. |
401 | */ |
402 | void lttvwindow_register_time_window_notify(Tab *tab, |
403 | LttvHook hook, gpointer hook_data) |
404 | { |
405 | LttvAttributeValue value; |
406 | LttvHooks * tmp; |
407 | g_assert(lttv_iattribute_find_by_path(tab->attributes, |
408 | "hooks/updatetimewindow", LTTV_POINTER, &value)); |
409 | tmp = (LttvHooks*)*(value.v_pointer); |
410 | if(tmp == NULL){ |
411 | tmp = lttv_hooks_new(); |
412 | *(value.v_pointer) = tmp; |
413 | } |
414 | lttv_hooks_add(tmp, hook,hook_data, LTTV_PRIO_DEFAULT); |
415 | } |
416 | |
417 | |
418 | /** |
419 | * Function to unregister a viewer's hook function which is used to |
420 | * set/update the time interval of the viewer. |
421 | * @param tab viewer's tab |
422 | * @param hook hook function of the viewer. |
423 | * @param hook_data hook data associated with the hook function. |
424 | */ |
425 | |
426 | void lttvwindow_unregister_time_window_notify(Tab *tab, |
427 | LttvHook hook, gpointer hook_data) |
428 | { |
429 | LttvAttributeValue value; |
430 | LttvHooks * tmp; |
431 | g_assert(lttv_iattribute_find_by_path(tab->attributes, |
432 | "hooks/updatetimewindow", LTTV_POINTER, &value)); |
433 | tmp = (LttvHooks*)*(value.v_pointer); |
434 | if(tmp == NULL) return; |
435 | lttv_hooks_remove_data(tmp, hook, hook_data); |
436 | } |
437 | |
438 | /** |
439 | * Function to register a hook function for a viewer to set/update its |
440 | * traceset. |
441 | * @param tab viewer's tab |
442 | * @param hook hook function of the viewer. |
443 | * @param hook_data hook data associated with the hook function. |
444 | */ |
445 | |
446 | void lttvwindow_register_traceset_notify(Tab *tab, |
447 | LttvHook hook, gpointer hook_data) |
448 | { |
449 | LttvAttributeValue value; |
450 | LttvHooks * tmp; |
451 | g_assert(lttv_iattribute_find_by_path(tab->attributes, |
452 | "hooks/updatetraceset", LTTV_POINTER, &value)); |
453 | tmp = (LttvHooks*)*(value.v_pointer); |
454 | if(tmp == NULL){ |
455 | tmp = lttv_hooks_new(); |
456 | *(value.v_pointer) = tmp; |
457 | } |
458 | lttv_hooks_add(tmp, hook, hook_data, LTTV_PRIO_DEFAULT); |
459 | } |
460 | |
461 | |
462 | /** |
463 | * Function to unregister a viewer's hook function which is used to |
464 | * set/update the traceset of the viewer. |
465 | * @param tab viewer's tab |
466 | * @param hook hook function of the viewer. |
467 | * @param hook_data hook data associated with the hook function. |
468 | */ |
469 | |
470 | void lttvwindow_unregister_traceset_notify(Tab *tab, |
471 | LttvHook hook, gpointer hook_data) |
472 | { |
473 | LttvAttributeValue value; |
474 | LttvHooks * tmp; |
475 | g_assert(lttv_iattribute_find_by_path(tab->attributes, |
476 | "hooks/updatetraceset", LTTV_POINTER, &value)); |
477 | tmp = (LttvHooks*)*(value.v_pointer); |
478 | if(tmp == NULL) return; |
479 | lttv_hooks_remove_data(tmp, hook, hook_data); |
480 | } |
481 | |
9878c8a4 |
482 | /** |
483 | * Function to register a hook function for a viewer be completely redrawn. |
484 | * |
485 | * @param tab viewer's tab |
486 | * @param hook hook function of the viewer. |
487 | * @param hook_data hook data associated with the hook function. |
488 | */ |
489 | |
490 | void lttvwindow_register_redraw_notify(Tab *tab, |
491 | LttvHook hook, gpointer hook_data) |
492 | { |
493 | LttvAttributeValue value; |
494 | LttvHooks * tmp; |
495 | g_assert(lttv_iattribute_find_by_path(tab->attributes, |
496 | "hooks/redraw", LTTV_POINTER, &value)); |
497 | tmp = (LttvHooks*)*(value.v_pointer); |
498 | if(tmp == NULL){ |
499 | tmp = lttv_hooks_new(); |
500 | *(value.v_pointer) = tmp; |
501 | } |
502 | lttv_hooks_add(tmp, hook, hook_data, LTTV_PRIO_DEFAULT); |
503 | } |
504 | |
505 | |
506 | /** |
507 | * Function to unregister a hook function for a viewer be completely redrawn. |
508 | * |
509 | * @param tab viewer's tab |
510 | * @param hook hook function of the viewer. |
511 | * @param hook_data hook data associated with the hook function. |
512 | */ |
513 | |
514 | void lttvwindow_unregister_redraw_notify(Tab *tab, |
515 | LttvHook hook, gpointer hook_data) |
516 | { |
517 | LttvAttributeValue value; |
518 | LttvHooks * tmp; |
519 | g_assert(lttv_iattribute_find_by_path(tab->attributes, |
520 | "hooks/redraw", LTTV_POINTER, &value)); |
521 | tmp = (LttvHooks*)*(value.v_pointer); |
522 | if(tmp == NULL) return; |
523 | lttv_hooks_remove_data(tmp, hook, hook_data); |
524 | } |
525 | |
526 | /** |
527 | * Function to register a hook function for a viewer to re-do the events |
528 | * requests for the needed interval. |
529 | * |
530 | * This action is typically done after a "stop". |
531 | * |
532 | * The typical hook will remove all current requests for the viewer |
533 | * and make requests for missing information. |
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_register_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){ |
549 | tmp = lttv_hooks_new(); |
550 | *(value.v_pointer) = tmp; |
551 | } |
552 | lttv_hooks_add(tmp, hook, hook_data, LTTV_PRIO_DEFAULT); |
553 | } |
554 | |
555 | |
556 | /** |
557 | * Function to unregister a hook function for a viewer to re-do the events |
558 | * requests for the needed interval. |
559 | * |
560 | * @param tab viewer's tab |
561 | * @param hook hook function of the viewer. |
562 | * @param hook_data hook data associated with the hook function. |
563 | */ |
564 | |
565 | void lttvwindow_unregister_continue_notify(Tab *tab, |
566 | LttvHook hook, gpointer hook_data) |
567 | { |
568 | LttvAttributeValue value; |
569 | LttvHooks * tmp; |
570 | g_assert(lttv_iattribute_find_by_path(tab->attributes, |
571 | "hooks/continue", LTTV_POINTER, &value)); |
572 | tmp = (LttvHooks*)*(value.v_pointer); |
573 | if(tmp == NULL) return; |
574 | lttv_hooks_remove_data(tmp, hook, hook_data); |
575 | } |
576 | |
577 | |
501e4e70 |
578 | /** |
579 | * Function to register a hook function for a viewer to set/update its |
580 | * filter. |
581 | * @param tab viewer's tab |
582 | * @param hook hook function of the viewer. |
583 | * @param hook_data hook data associated with the hook function. |
584 | */ |
585 | |
586 | void lttvwindow_register_filter_notify(Tab *tab, |
587 | LttvHook hook, 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){ |
595 | tmp = lttv_hooks_new(); |
596 | *(value.v_pointer) = tmp; |
597 | } |
598 | lttv_hooks_add(tmp, hook, hook_data, LTTV_PRIO_DEFAULT); |
599 | } |
600 | |
601 | |
602 | /** |
603 | * Function to unregister a viewer's hook function which is used to |
604 | * set/update the filter of the viewer. |
605 | * @param tab viewer's tab |
606 | * @param hook hook function of the viewer. |
607 | * @param hook_data hook data associated with the hook function. |
608 | */ |
609 | |
610 | void lttvwindow_unregister_filter_notify(Tab *tab, |
611 | LttvHook hook, |
612 | gpointer hook_data) |
613 | { |
614 | LttvAttributeValue value; |
615 | LttvHooks * tmp; |
616 | g_assert(lttv_iattribute_find_by_path(tab->attributes, |
617 | "hooks/updatefilter", LTTV_POINTER, &value)); |
618 | tmp = (LttvHooks*)*(value.v_pointer); |
619 | if(tmp == NULL) return; |
620 | lttv_hooks_remove_data(tmp, hook, hook_data); |
621 | } |
622 | |
623 | /** |
5290ec02 |
624 | * function to register a hook function for a viewer to set/update its |
501e4e70 |
625 | * current time. |
626 | * @param tab viewer's tab |
627 | * @param hook hook function of the viewer. |
628 | * @param hook_data hook data associated with the hook function. |
629 | */ |
630 | |
631 | void lttvwindow_register_current_time_notify(Tab *tab, |
632 | LttvHook hook, gpointer hook_data) |
633 | { |
634 | LttvAttributeValue value; |
635 | LttvHooks * tmp; |
636 | g_assert(lttv_iattribute_find_by_path(tab->attributes, |
637 | "hooks/updatecurrenttime", LTTV_POINTER, &value)); |
638 | tmp = (LttvHooks*)*(value.v_pointer); |
639 | if(tmp == NULL){ |
640 | tmp = lttv_hooks_new(); |
641 | *(value.v_pointer) = tmp; |
642 | } |
643 | lttv_hooks_add(tmp, hook, hook_data, LTTV_PRIO_DEFAULT); |
644 | } |
645 | |
646 | |
647 | /** |
5290ec02 |
648 | * function to unregister a viewer's hook function which is used to |
501e4e70 |
649 | * set/update the current time of the viewer. |
650 | * @param tab viewer's tab |
651 | * @param hook hook function of the viewer. |
652 | * @param hook_data hook data associated with the hook function. |
653 | */ |
654 | |
655 | void lttvwindow_unregister_current_time_notify(Tab *tab, |
656 | LttvHook hook, gpointer hook_data) |
657 | { |
658 | LttvAttributeValue value; |
659 | LttvHooks * tmp; |
660 | g_assert(lttv_iattribute_find_by_path(tab->attributes, |
661 | "hooks/updatecurrenttime", LTTV_POINTER, &value)); |
662 | tmp = (LttvHooks*)*(value.v_pointer); |
663 | if(tmp == NULL) return; |
664 | lttv_hooks_remove_data(tmp, hook, hook_data); |
665 | } |
666 | |
5290ec02 |
667 | /** |
668 | * function to register a hook function for a viewer to set/update its |
669 | * current position. |
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_register_current_position_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/updatecurrentposition", LTTV_POINTER, &value)); |
682 | tmp = (LttvHooks*)*(value.v_pointer); |
683 | if(tmp == NULL){ |
684 | tmp = lttv_hooks_new(); |
685 | *(value.v_pointer) = tmp; |
686 | } |
687 | lttv_hooks_add(tmp, hook, hook_data, LTTV_PRIO_DEFAULT); |
688 | } |
689 | |
690 | |
691 | /** |
692 | * function to unregister a viewer's hook function which is used to |
693 | * set/update the current position of the viewer. |
694 | * @param tab viewer's tab |
695 | * @param hook hook function of the viewer. |
696 | * @param hook_data hook data associated with the hook function. |
697 | */ |
698 | |
699 | void lttvwindow_unregister_current_position_notify(Tab *tab, |
700 | LttvHook hook, gpointer hook_data) |
701 | { |
702 | LttvAttributeValue value; |
703 | LttvHooks * tmp; |
704 | g_assert(lttv_iattribute_find_by_path(tab->attributes, |
705 | "hooks/updatecurrentposition", LTTV_POINTER, &value)); |
706 | tmp = (LttvHooks*)*(value.v_pointer); |
707 | if(tmp == NULL) return; |
708 | lttv_hooks_remove_data(tmp, hook, hook_data); |
709 | } |
710 | |
501e4e70 |
711 | |
712 | /** |
713 | * Function to register a hook function for a viewer to show |
714 | * the content 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_register_show_notify(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/showviewer", LTTV_POINTER, &value)); |
727 | tmp = (LttvHooks*)*(value.v_pointer); |
728 | if(tmp == NULL){ |
729 | tmp = lttv_hooks_new(); |
730 | *(value.v_pointer) = tmp; |
731 | } |
732 | lttv_hooks_add(tmp, hook, hook_data, LTTV_PRIO_DEFAULT); |
733 | } |
734 | |
735 | |
736 | /** |
737 | * Function to unregister a viewer's hook function which is used to |
738 | * show the content of the viewer.. |
739 | * @param tab viewer's tab |
740 | * @param hook hook function of the viewer. |
741 | * @param hook_data hook data associated with the hook function. |
742 | */ |
743 | |
744 | void lttvwindow_unregister_show_notify(Tab *tab, |
745 | LttvHook hook, gpointer hook_data) |
746 | { |
747 | LttvAttributeValue value; |
748 | LttvHooks * tmp; |
749 | g_assert(lttv_iattribute_find_by_path(tab->attributes, |
750 | "hooks/showviewer", LTTV_POINTER, &value)); |
751 | tmp = (LttvHooks*)*(value.v_pointer); |
752 | if(tmp == NULL) return; |
753 | lttv_hooks_remove_data(tmp, hook, hook_data); |
754 | } |
755 | |
756 | /** |
757 | * Function to register a hook function for a viewer to set/update the |
758 | * dividor of the hpane. |
759 | * @param tab viewer's tab |
760 | * @param hook hook function of the viewer. |
761 | * @param hook_data hook data associated with the hook function. |
762 | */ |
763 | |
764 | void lttvwindow_register_dividor(Tab *tab, |
765 | LttvHook hook, gpointer hook_data) |
766 | { |
767 | LttvAttributeValue value; |
768 | LttvHooks * tmp; |
769 | g_assert(lttv_iattribute_find_by_path(tab->attributes, |
770 | "hooks/hpanedividor", LTTV_POINTER, &value)); |
771 | tmp = (LttvHooks*)*(value.v_pointer); |
772 | if(tmp == NULL){ |
773 | tmp = lttv_hooks_new(); |
774 | *(value.v_pointer) = tmp; |
775 | } |
776 | lttv_hooks_add(tmp, hook, hook_data, LTTV_PRIO_DEFAULT); |
777 | } |
778 | |
779 | |
780 | /** |
781 | * Function to unregister a viewer's hook function which is used to |
782 | * set/update hpane's dividor of the viewer. |
783 | * It will be called by the destructor of the viewer. |
784 | * @param tab viewer's tab |
785 | * @param hook hook function of the viewer. |
786 | * @param hook_data hook data associated with the hook function. |
787 | */ |
788 | |
789 | void lttvwindow_unregister_dividor(Tab *tab, |
790 | LttvHook hook, gpointer hook_data) |
791 | { |
792 | LttvAttributeValue value; |
793 | LttvHooks * tmp; |
794 | g_assert(lttv_iattribute_find_by_path(tab->attributes, |
795 | "hooks/hpanedividor", LTTV_POINTER, &value)); |
796 | tmp = (LttvHooks*)*(value.v_pointer); |
797 | if(tmp == NULL) return; |
798 | lttv_hooks_remove_data(tmp, hook, hook_data); |
799 | } |
800 | |
801 | |
501e4e70 |
802 | /** |
803 | * Function to set the time interval of the current tab. |
804 | * It will be called by a viewer's signal handle associated with |
805 | * the move_slider signal |
806 | * @param tab viewer's tab |
807 | * @param time_interval a pointer where time interval is stored. |
808 | */ |
809 | |
810 | void lttvwindow_report_time_window(Tab *tab, |
e800cf84 |
811 | TimeWindow time_window) |
501e4e70 |
812 | { |
b052368a |
813 | //set_time_window(tab, time_window); |
814 | //set_time_window_adjustment(tab, time_window); |
815 | |
e800cf84 |
816 | time_change_manager(tab, time_window); |
817 | |
818 | |
819 | #if 0 |
b052368a |
820 | /* Set scrollbar */ |
821 | LttvTracesetContext *tsc = |
822 | LTTV_TRACESET_CONTEXT(tab->traceset_info->traceset_context); |
823 | TimeInterval time_span = tsc->time_span; |
824 | GtkAdjustment *adjustment = gtk_range_get_adjustment(GTK_RANGE(tab->scrollbar)); |
b052368a |
825 | g_object_set(G_OBJECT(adjustment), |
826 | "lower", |
0c5dbe3b |
827 | 0.0, /* lower */ |
b052368a |
828 | "upper", |
b9a010a2 |
829 | ltt_time_to_double( |
830 | ltt_time_sub(time_span.end_time, time_span.start_time)) |
c74e0cf9 |
831 | , /* upper */ |
b052368a |
832 | "step_increment", |
833 | ltt_time_to_double(time_window->time_width) |
834 | / SCROLL_STEP_PER_PAGE |
c74e0cf9 |
835 | , /* step increment */ |
b052368a |
836 | "page_increment", |
837 | ltt_time_to_double(time_window->time_width) |
c74e0cf9 |
838 | , /* page increment */ |
b052368a |
839 | "page_size", |
840 | ltt_time_to_double(time_window->time_width) |
c74e0cf9 |
841 | , /* page size */ |
b052368a |
842 | NULL); |
843 | gtk_adjustment_changed(adjustment); |
844 | |
845 | //g_object_set(G_OBJECT(adjustment), |
846 | // "value", |
847 | // ltt_time_to_double(time_window->start_time) |
c74e0cf9 |
848 | // , /* value */ |
b052368a |
849 | // NULL); |
850 | /* Note : the set value will call set_time_window if scrollbar value changed |
851 | */ |
852 | gtk_adjustment_set_value(adjustment, |
b9a010a2 |
853 | ltt_time_to_double( |
854 | ltt_time_sub(time_window->start_time, |
855 | time_span.start_time)) |
c74e0cf9 |
856 | ); |
e800cf84 |
857 | #endif //0 |
501e4e70 |
858 | } |
859 | |
860 | |
861 | /** |
5290ec02 |
862 | * Function to set the current time of the current tab. |
501e4e70 |
863 | * It will be called by a viewer's signal handle associated with |
864 | * the button-release-event signal |
865 | * @param tab viewer's tab |
866 | * @param time a pointer where time is stored. |
867 | */ |
868 | |
869 | void lttvwindow_report_current_time(Tab *tab, |
e800cf84 |
870 | LttTime time) |
501e4e70 |
871 | { |
872 | LttvAttributeValue value; |
873 | LttvHooks * tmp; |
e800cf84 |
874 | |
875 | current_time_change_manager(tab, time); |
501e4e70 |
876 | } |
877 | |
5290ec02 |
878 | /** |
879 | * Function to set the current event of the current tab. |
880 | * It will be called by a viewer's signal handle associated with |
881 | * the button-release-event signal |
882 | * @param tab viewer's tab |
883 | * @param time a pointer where time is stored. |
884 | */ |
885 | |
886 | void lttvwindow_report_current_position(Tab *tab, |
887 | LttvTracesetContextPosition *pos) |
888 | { |
889 | LttvAttributeValue value; |
890 | LttvHooks * tmp; |
891 | |
892 | current_position_change_manager(tab, pos); |
893 | } |
894 | |
895 | |
501e4e70 |
896 | /** |
897 | * Function to set the position of the hpane's dividor (viewer). |
898 | * It will be called by a viewer's signal handle associated with |
899 | * the motion_notify_event event/signal |
900 | * @param tab viewer's tab |
901 | * @param position position of the hpane's dividor. |
902 | */ |
903 | |
904 | void lttvwindow_report_dividor(Tab *tab, gint position) |
905 | { |
906 | LttvAttributeValue value; |
907 | LttvHooks * tmp; |
908 | g_assert(lttv_iattribute_find_by_path(tab->attributes, |
909 | "hooks/hpanedividor", LTTV_POINTER, &value)); |
910 | tmp = (LttvHooks*)*(value.v_pointer); |
911 | if(tmp == NULL) return; |
912 | lttv_hooks_call(tmp, &position); |
913 | } |
914 | |
501e4e70 |
915 | /** |
916 | * Function to request data in a specific time interval to the main window. The |
917 | * event request servicing is differed until the glib idle functions are |
918 | * called. |
919 | * |
920 | * The viewer has to provide hooks that should be associated with the event |
921 | * request. |
922 | * |
923 | * Either start time or start position must be defined in a EventRequest |
924 | * structure for it to be valid. |
925 | * |
926 | * end_time, end_position and num_events can all be defined. The first one |
927 | * to occur will be used as end criterion. |
928 | * |
929 | * @param tab viewer's tab |
930 | * @param events_requested the structure of request from. |
931 | */ |
932 | |
933 | void lttvwindow_events_request(Tab *tab, |
20fde85f |
934 | EventsRequest *events_request) |
501e4e70 |
935 | { |
20fde85f |
936 | tab->events_requests = g_slist_append(tab->events_requests, events_request); |
501e4e70 |
937 | |
938 | if(!tab->events_request_pending) |
939 | { |
553d1e7b |
940 | /* Redraw has +20 priority. We want to let the redraw be done while we do |
941 | * our job. */ |
942 | g_idle_add_full((G_PRIORITY_HIGH_IDLE + 21), |
501e4e70 |
943 | (GSourceFunc)execute_events_requests, |
944 | tab, |
945 | NULL); |
946 | tab->events_request_pending = TRUE; |
947 | } |
948 | } |
949 | |
950 | |
951 | /** |
952 | * Function to remove data requests related to a viewer. |
953 | * |
954 | * The existing requests's viewer gpointer is compared to the pointer |
955 | * given in argument to establish which data request should be removed. |
956 | * |
957 | * @param tab the tab the viewer belongs to. |
958 | * @param viewer a pointer to the viewer data structure |
959 | */ |
960 | |
961 | gint find_viewer (const EventsRequest *a, gconstpointer b) |
962 | { |
2d262115 |
963 | return (a->owner != b); |
501e4e70 |
964 | } |
965 | |
966 | |
967 | void lttvwindow_events_request_remove_all(Tab *tab, |
968 | gconstpointer viewer) |
969 | { |
6843100a |
970 | GSList *element = tab->events_requests; |
501e4e70 |
971 | |
972 | while((element = |
6843100a |
973 | g_slist_find_custom(element, viewer, |
501e4e70 |
974 | (GCompareFunc)find_viewer)) |
975 | != NULL) { |
2d262115 |
976 | EventsRequest *events_request = (EventsRequest *)element->data; |
3bafb436 |
977 | // Modified so a viewer being destroyed won't have its after_request |
978 | // called. Not so important anyway. Note that a viewer that call this |
979 | // remove_all function will not get its after_request called. |
980 | //if(events_request->servicing == TRUE) { |
981 | // lttv_hooks_call(events_request->after_request, NULL); |
982 | //} |
c5b5eee1 |
983 | events_request_free(events_request); |
984 | //g_free(events_request); |
501e4e70 |
985 | tab->events_requests = g_slist_remove_link(tab->events_requests, element); |
6843100a |
986 | element = g_slist_next(element); |
987 | if(element == NULL) break; /* end of list */ |
501e4e70 |
988 | } |
b052368a |
989 | if(g_slist_length(tab->events_requests) == 0) { |
990 | tab->events_request_pending = FALSE; |
991 | g_idle_remove_by_data(tab); |
992 | } |
993 | |
501e4e70 |
994 | } |
995 | |
50106726 |
996 | /** |
997 | * Function to get the current time interval shown on the current tab. |
998 | * It will be called by a viewer's hook function to update the |
999 | * shown time interval of the viewer and also be called by the constructor |
1000 | * of the viewer. |
1001 | * @param tab viewer's tab |
1002 | * @return time window. |
1003 | */ |
1004 | |
1005 | TimeWindow lttvwindow_get_time_window(Tab *tab) |
1006 | { |
1007 | return tab->time_window; |
1008 | } |
1009 | |
501e4e70 |
1010 | |
501e4e70 |
1011 | /** |
1012 | * Function to get the current time/event of the current tab. |
1013 | * It will be called by a viewer's hook function to update the |
1014 | * current time/event of the viewer. |
1015 | * @param tab viewer's tab |
6ea08962 |
1016 | * @return time |
501e4e70 |
1017 | */ |
1018 | |
6ea08962 |
1019 | LttTime lttvwindow_get_current_time(Tab *tab) |
501e4e70 |
1020 | { |
6ea08962 |
1021 | return tab->current_time; |
501e4e70 |
1022 | } |
1023 | |
1024 | |
1025 | /** |
1026 | * Function to get the filter of the current tab. |
dc5e5266 |
1027 | * @param main_win, the main window the viewer belongs to. |
501e4e70 |
1028 | * @param filter, a pointer to a filter. |
1029 | */ |
dc5e5266 |
1030 | |
1031 | LttvFilter *lttvwindow_get_filter(Tab *tab) |
501e4e70 |
1032 | { |
dc5e5266 |
1033 | return tab->filter; |
501e4e70 |
1034 | } |
1035 | |
dc5e5266 |
1036 | /** |
1037 | * Function to set the filter of the current tab. |
1038 | * It should be called by the filter GUI to tell the |
1039 | * main window to update the filter tab's lttv_filter. |
1040 | * |
1041 | * This function does change the current filter, removing the |
1042 | * old one when necessary, and call the updatefilter hooks |
1043 | * of the registered viewers. |
1044 | * |
1045 | * @param main_win, the main window the viewer belongs to. |
1046 | * @param filter, a pointer to a filter. |
1047 | */ |
1048 | |
1049 | void lttvwindow_report_filter(Tab *tab, LttvFilter *filter) |
1050 | { |
1051 | LttvAttributeValue value; |
1052 | LttvHooks * tmp; |
1053 | |
1054 | lttv_filter_destroy(tab->filter); |
1055 | tab->filter = filter; |
1056 | |
1057 | g_assert(lttv_iattribute_find_by_path(tab->attributes, |
1058 | "hooks/updatefilter", LTTV_POINTER, &value)); |
1059 | tmp = (LttvHooks*)*(value.v_pointer); |
1060 | if(tmp == NULL) return; |
962e2228 |
1061 | lttv_hooks_call(tmp, filter); |
dc5e5266 |
1062 | } |
1063 | |
1064 | |
501e4e70 |
1065 | |
1066 | /** |
1067 | * Function to get the stats of the traceset |
1068 | * @param tab viewer's tab |
1069 | */ |
1070 | |
1071 | LttvTracesetStats* lttvwindow_get_traceset_stats(Tab *tab) |
1072 | { |
1073 | return tab->traceset_info->traceset_context; |
1074 | } |
1075 | |
1076 | |
1077 | LttvTracesetContext* lttvwindow_get_traceset_context(Tab *tab) |
1078 | { |
1079 | return (LttvTracesetContext*)tab->traceset_info->traceset_context; |
1080 | } |
c5b5eee1 |
1081 | |
1082 | |
1083 | void events_request_free(EventsRequest *events_request) |
1084 | { |
1085 | if(events_request == NULL) return; |
1086 | |
1087 | if(events_request->start_position != NULL) |
1088 | lttv_traceset_context_position_destroy(events_request->start_position); |
1089 | if(events_request->end_position != NULL) |
1090 | lttv_traceset_context_position_destroy(events_request->end_position); |
1091 | if(events_request->hooks != NULL) { |
1092 | guint i; |
1093 | GArray *hooks = events_request->hooks; |
1094 | for(i=0;i<hooks->len;i++) { |
1095 | lttv_trace_hook_destroy(&g_array_index(hooks, LttvTraceHook, i)); |
1096 | } |
1097 | g_array_free(events_request->hooks, TRUE); |
1098 | } |
1099 | if(events_request->before_chunk_traceset != NULL) |
1100 | lttv_hooks_destroy(events_request->before_chunk_traceset); |
1101 | if(events_request->before_chunk_trace != NULL) |
1102 | lttv_hooks_destroy(events_request->before_chunk_trace); |
1103 | if(events_request->before_chunk_tracefile != NULL) |
1104 | lttv_hooks_destroy(events_request->before_chunk_tracefile); |
1105 | if(events_request->event != NULL) |
1106 | lttv_hooks_destroy(events_request->event); |
1107 | if(events_request->event_by_id != NULL) |
1108 | lttv_hooks_by_id_destroy(events_request->event_by_id); |
1109 | if(events_request->after_chunk_tracefile != NULL) |
1110 | lttv_hooks_destroy(events_request->after_chunk_tracefile); |
1111 | if(events_request->after_chunk_trace != NULL) |
1112 | lttv_hooks_destroy(events_request->after_chunk_trace); |
1113 | if(events_request->after_chunk_traceset != NULL) |
1114 | lttv_hooks_destroy(events_request->after_chunk_traceset); |
1115 | if(events_request->before_request != NULL) |
1116 | lttv_hooks_destroy(events_request->before_request); |
1117 | if(events_request->after_request != NULL) |
1118 | lttv_hooks_destroy(events_request->after_request); |
1119 | |
1120 | g_free(events_request); |
1121 | } |
1122 | |
1123 | |