1 /*! \file gtkTraceSet.h
2 * \brief API used by the graphical viewers to interact with their top window.
4 * Main window (gui module) is the place to contain and display viewers.
5 * Viewers (lttv plugins) interacte with main window through this API and
7 * This header file should be included in each graphic module.
8 * This library is used by graphical modules to interact with the
13 #include <lttv/common.h>
15 #include <lttv/lttv.h>
16 #include <lttv/mainWindow.h>
17 #include <lttv/gtkTraceSet.h>
18 #include <lttv/processTrace.h>
19 #include <lttv/toolbar.h>
20 #include <lttv/menu.h>
21 #include <lttv/state.h>
22 #include <lttv/stats.h>
26 * Internal function parts
30 * Function to remove toolbar from the GUI
31 * @param view_constructor constructor of the viewer.
34 void RemoveToolbar(lttv_constructor view_constructor
)
36 g_printf("Toolbar for the viewer will be removed\n");
40 * Function to remove menu entry from the GUI
41 * @param view_constructor constructor of the viewer.
44 void RemoveMenu(lttv_constructor view_constructor
)
46 g_printf("Menu entry for the viewer will be removed\n");
51 * Function to set/update traceset for the viewers
52 * @param main_win main window
53 * @param traceset traceset of the main window.
56 void SetTraceset(mainWindow
* main_win
, gpointer traceset
)
59 LttvAttributeValue value
;
61 g_assert(lttv_iattribute_find_by_path(main_win
->Attributes
,
62 "hooks/updatetraceset", LTTV_POINTER
, &value
));
63 tmp
= (LttvHooks
*)*(value
.v_pointer
);
64 if(tmp
== NULL
)return;
65 lttv_hooks_call(tmp
,traceset
);
70 * Function to set/update filter for the viewers
71 * @param main_win main window
72 * @param filter filter of the main window.
75 void SetFilter(mainWindow
* main_win
, gpointer filter
)
78 LttvAttributeValue value
;
80 g_assert(lttv_iattribute_find_by_path(main_win
->Attributes
,
81 "hooks/updatefilter", LTTV_POINTER
, &value
));
82 tmp
= (LttvHooks
*)*(value
.v_pointer
);
84 if(tmp
== NULL
)return;
85 lttv_hooks_call(tmp
,filter
);
95 * Function to register a view constructor so that main window can generate
96 * a toolbar item for the viewer in order to generate a new instance easily.
97 * It will be called by init function of the module.
98 * @param ButtonPixmap image shown on the toolbar item.
99 * @param tooltip tooltip of the toolbar item.
100 * @param view_constructor constructor of the viewer.
103 void ToolbarItemReg(char ** pixmap
, char *tooltip
, lttv_constructor view_constructor
)
105 LttvIAttribute
*attributes_global
= LTTV_IATTRIBUTE(lttv_global_attributes());
106 LttvToolbars
* toolbar
;
107 LttvAttributeValue value
;
109 g_assert(lttv_iattribute_find_by_path(attributes_global
,
110 "viewers/toolbar", LTTV_POINTER
, &value
));
111 toolbar
= (LttvToolbars
*)*(value
.v_pointer
);
114 toolbar
= lttv_toolbars_new();
115 *(value
.v_pointer
) = toolbar
;
117 lttv_toolbars_add(toolbar
, view_constructor
, tooltip
, pixmap
);
122 * Function to unregister the viewer's constructor, release the space
123 * occupied by pixmap, tooltip and constructor of the viewer.
124 * It will be called when a module is unloaded.
125 * @param view_constructor constructor of the viewer which is used as
126 * a reference to find out where the pixmap and tooltip are.
129 void ToolbarItemUnreg(lttv_constructor view_constructor
)
131 LttvIAttribute
*attributes_global
= LTTV_IATTRIBUTE(lttv_global_attributes());
132 LttvToolbars
* toolbar
;
133 LttvAttributeValue value
;
135 g_assert(lttv_iattribute_find_by_path(attributes_global
,
136 "viewers/toolbar", LTTV_POINTER
, &value
));
137 toolbar
= (LttvToolbars
*)*(value
.v_pointer
);
139 if(lttv_toolbars_remove(toolbar
, view_constructor
))
140 RemoveToolbar(view_constructor
);
145 * Function to register a view constructor so that main window can generate
146 * a menu item for the viewer in order to generate a new instance easily.
147 * It will be called by init function of the module.
148 * @param menu_path path of the menu item.
149 * @param menu_text text of the menu item.
150 * @param view_constructor constructor of the viewer.
153 void MenuItemReg(char *menu_path
, char *menu_text
, lttv_constructor view_constructor
)
155 LttvIAttribute
*attributes_global
= LTTV_IATTRIBUTE(lttv_global_attributes());
157 LttvAttributeValue value
;
159 g_assert(lttv_iattribute_find_by_path(attributes_global
,
160 "viewers/menu", LTTV_POINTER
, &value
));
161 menu
= (LttvMenus
*)*(value
.v_pointer
);
164 menu
= lttv_menus_new();
165 *(value
.v_pointer
) = menu
;
167 lttv_menus_add(menu
, view_constructor
, menu_path
, menu_text
);
171 * Function to unregister the viewer's constructor, release the space
172 * occupied by menu_path, menu_text and constructor of the viewer.
173 * It will be called when a module is unloaded.
174 * @param view_constructor constructor of the viewer which is used as
175 * a reference to find out where the menu_path and menu_text are.
178 void MenuItemUnreg(lttv_constructor view_constructor
)
180 LttvIAttribute
*attributes_global
= LTTV_IATTRIBUTE(lttv_global_attributes());
182 LttvAttributeValue value
;
184 g_assert(lttv_iattribute_find_by_path(attributes_global
,
185 "viewers/menu", LTTV_POINTER
, &value
));
186 menu
= (LttvMenus
*)*(value
.v_pointer
);
188 if(lttv_menus_remove(menu
, view_constructor
))
189 RemoveMenu(view_constructor
);
194 * Update the status bar whenever something changed in the viewer.
195 * @param main_win the main window the viewer belongs to.
196 * @param info the message which will be shown in the status bar.
199 void UpdateStatus(mainWindow
*main_win
, char *info
)
205 * Function to get the current time interval of the current tab.
206 * It will be called by a viewer's hook function to update the
207 * time interval of the viewer and also be called by the constructor
209 * @param main_win the main window the viewer belongs to.
210 * @param time_interval a pointer where time interval will be stored.
213 void GetTimeInterval(mainWindow
*main_win
, TimeInterval
*time_interval
)
215 time_interval
->startTime
= main_win
->CurrentTab
->startTime
;
216 time_interval
->endTime
= main_win
->CurrentTab
->endTime
;
221 * Function to set the time interval of the current tab.
222 * It will be called by a viewer's signal handle associated with
223 * the move_slider signal
224 * @param main_win the main window the viewer belongs to.
225 * @param time_interval a pointer where time interval is stored.
228 void SetTimeInterval(mainWindow
*main_win
, TimeInterval
*time_interval
)
230 LttvAttributeValue value
;
232 main_win
->CurrentTab
->startTime
= time_interval
->startTime
;
233 main_win
->CurrentTab
->endTime
= time_interval
->endTime
;
234 g_assert(lttv_iattribute_find_by_path(main_win
->CurrentTab
->Attributes
,
235 "hooks/updatetimeinterval", LTTV_POINTER
, &value
));
236 tmp
= (LttvHooks
*)*(value
.v_pointer
);
237 if(tmp
== NULL
)return;
238 lttv_hooks_call(tmp
, time_interval
);
243 * Function to get the current time/event of the current tab.
244 * It will be called by a viewer's hook function to update the
245 * current time/event of the viewer.
246 * @param main_win the main window the viewer belongs to.
247 * @param time a pointer where time will be stored.
250 void GetCurrentTime(mainWindow
*main_win
, LttTime
*time
)
252 time
= &main_win
->CurrentTab
->currentTime
;
257 * Function to set the current time/event of the current tab.
258 * It will be called by a viewer's signal handle associated with
259 * the button-release-event signal
260 * @param main_win the main window the viewer belongs to.
261 * @param time a pointer where time is stored.
264 void SetCurrentTime(mainWindow
*main_win
, LttTime
*time
)
266 LttvAttributeValue value
;
268 main_win
->CurrentTab
->currentTime
= *time
;
269 g_assert(lttv_iattribute_find_by_path(main_win
->CurrentTab
->Attributes
,
270 "hooks/updatecurrenttime", LTTV_POINTER
, &value
));
271 tmp
= (LttvHooks
*)*(value
.v_pointer
);
273 if(tmp
== NULL
)return;
274 lttv_hooks_call(tmp
, time
);
279 * Function to get the traceset from the current tab.
280 * It will be called by the constructor of the viewer and also be
281 * called by a hook funtion of the viewer to update its traceset.
282 * @param main_win the main window the viewer belongs to.
283 * @param traceset a pointer to a traceset.
286 void GetTraceset(mainWindow *main_win, Traceset *traceset)
292 * Function to get the filter of the current tab.
293 * It will be called by the constructor of the viewer and also be
294 * called by a hook funtion of the viewer to update its filter.
295 * @param main_win, the main window the viewer belongs to.
296 * @param filter, a pointer to a filter.
299 void GetFilter(mainWindow *main_win, Filter *filter)
305 * Function to register a hook function for a viewer to set/update its
307 * It will be called by the constructor of the viewer.
308 * @param hook hook function of the viewer.
309 * @param hook_data hook data associated with the hook function.
310 * @param main_win the main window the viewer belongs to.
313 void RegUpdateTimeInterval(LttvHook hook
, gpointer hook_data
,
314 mainWindow
* main_win
)
316 LttvAttributeValue value
;
318 g_assert(lttv_iattribute_find_by_path(main_win
->CurrentTab
->Attributes
,
319 "hooks/updatetimeinterval", LTTV_POINTER
, &value
));
320 tmp
= (LttvHooks
*)*(value
.v_pointer
);
322 tmp
= lttv_hooks_new();
323 *(value
.v_pointer
) = tmp
;
325 lttv_hooks_add(tmp
, hook
,hook_data
);
330 * Function to unregister a viewer's hook function which is used to
331 * set/update the time interval of the viewer.
332 * It will be called by the destructor of the viewer.
333 * @param hook hook function of the viewer.
334 * @param hook_data hook data associated with the hook function.
335 * @param main_win the main window the viewer belongs to.
338 void UnregUpdateTimeInterval(LttvHook hook
, gpointer hook_data
,
339 mainWindow
* main_win
)
341 LttvAttributeValue value
;
343 g_assert(lttv_iattribute_find_by_path(main_win
->CurrentTab
->Attributes
,
344 "hooks/updatetimeinterval", LTTV_POINTER
, &value
));
345 tmp
= (LttvHooks
*)*(value
.v_pointer
);
346 if(tmp
== NULL
) return;
347 lttv_hooks_remove_data(tmp
, hook
, hook_data
);
352 * Function to register a hook function for a viewer to set/update its
354 * It will be called by the constructor of the viewer.
355 * @param hook hook function of the viewer.
356 * @param hook_data hook data associated with the hook function.
357 * @param main_win the main window the viewer belongs to.
360 void RegUpdateTraceset(LttvHook hook
, gpointer hook_data
,
361 mainWindow
* main_win
)
363 LttvAttributeValue value
;
365 g_assert(lttv_iattribute_find_by_path(main_win
->Attributes
,
366 "hooks/updatetraceset", LTTV_POINTER
, &value
));
367 tmp
= (LttvHooks
*)*(value
.v_pointer
);
369 tmp
= lttv_hooks_new();
370 *(value
.v_pointer
) = tmp
;
372 lttv_hooks_add(tmp
, hook
, hook_data
);
377 * Function to unregister a viewer's hook function which is used to
378 * set/update the traceset of the viewer.
379 * It will be called by the destructor of the viewer.
380 * @param hook hook function of the viewer.
381 * @param hook_data hook data associated with the hook function.
382 * @param main_win the main window the viewer belongs to.
385 void UnregUpdateTraceset(LttvHook hook
, gpointer hook_data
,
386 mainWindow
* main_win
)
388 LttvAttributeValue value
;
390 g_assert(lttv_iattribute_find_by_path(main_win
->Attributes
,
391 "hooks/updatetraceset", LTTV_POINTER
, &value
));
392 tmp
= (LttvHooks
*)*(value
.v_pointer
);
393 if(tmp
== NULL
) return;
394 lttv_hooks_remove_data(tmp
, hook
, hook_data
);
399 * Function to register a hook function for a viewer to set/update its
401 * It will be called by the constructor of the viewer.
402 * @param hook hook function of the viewer.
403 * @param hook_data hook data associated with the hook function.
404 * @param main_win the main window the viewer belongs to.
407 void RegUpdateFilter(LttvHook hook
, gpointer hook_data
,
408 mainWindow
*main_win
)
410 LttvAttributeValue value
;
412 g_assert(lttv_iattribute_find_by_path(main_win
->Attributes
,
413 "hooks/updatefilter", LTTV_POINTER
, &value
));
414 tmp
= (LttvHooks
*)*(value
.v_pointer
);
416 tmp
= lttv_hooks_new();
417 *(value
.v_pointer
) = tmp
;
419 lttv_hooks_add(tmp
, hook
, hook_data
);
424 * Function to unregister a viewer's hook function which is used to
425 * set/update the filter of the viewer.
426 * It will be called by the destructor of the viewer.
427 * @param hook hook function of the viewer.
428 * @param hook_data hook data associated with the hook function.
429 * @param main_win the main window the viewer belongs to.
432 void UnregUpdateFilter(LttvHook hook
, gpointer hook_data
,
433 mainWindow
* main_win
)
435 LttvAttributeValue value
;
437 g_assert(lttv_iattribute_find_by_path(main_win
->Attributes
,
438 "hooks/updatefilter", LTTV_POINTER
, &value
));
439 tmp
= (LttvHooks
*)*(value
.v_pointer
);
440 if(tmp
== NULL
) return;
441 lttv_hooks_remove_data(tmp
, hook
, hook_data
);
446 * Function to register a hook function for a viewer to set/update its
448 * It will be called by the constructor of the viewer.
449 * @param hook hook function of the viewer.
450 * @param hook_data hook data associated with the hook function.
451 * @param main_win the main window the viewer belongs to.
454 void RegUpdateCurrentTime(LttvHook hook
, gpointer hook_data
,
455 mainWindow
*main_win
)
457 LttvAttributeValue value
;
459 g_assert(lttv_iattribute_find_by_path(main_win
->CurrentTab
->Attributes
,
460 "hooks/updatecurrenttime", LTTV_POINTER
, &value
));
461 tmp
= (LttvHooks
*)*(value
.v_pointer
);
463 tmp
= lttv_hooks_new();
464 *(value
.v_pointer
) = tmp
;
466 lttv_hooks_add(tmp
, hook
, hook_data
);
471 * Function to unregister a viewer's hook function which is used to
472 * set/update the current time of the viewer.
473 * It will be called by the destructor of the viewer.
474 * @param hook hook function of the viewer.
475 * @param hook_data hook data associated with the hook function.
476 * @param main_win the main window the viewer belongs to.
479 void UnregUpdateCurrentTime(LttvHook hook
, gpointer hook_data
,
480 mainWindow
* main_win
)
482 LttvAttributeValue value
;
484 g_assert(lttv_iattribute_find_by_path(main_win
->CurrentTab
->Attributes
,
485 "hooks/updatecurrenttime", LTTV_POINTER
, &value
));
486 tmp
= (LttvHooks
*)*(value
.v_pointer
);
487 if(tmp
== NULL
) return;
488 lttv_hooks_remove_data(tmp
, hook
, hook_data
);
493 * Function to set the focused pane (viewer).
494 * It will be called by a viewer's signal handle associated with
495 * the grab_focus signal
496 * @param main_win the main window the viewer belongs to.
497 * @param paned a pointer to a pane where the viewer is contained.
500 void SetFocusedPane(mainWindow
*main_win
, gpointer paned
)
502 gtk_custom_set_focus((GtkWidget
*)main_win
->CurrentTab
->custom
,paned
);
507 * Function to register a hook function for a viewer to set/update the
508 * dividor of the hpane.
509 * It will be called by the constructor of the viewer.
510 * @param hook hook function of the viewer.
511 * @param hook_data hook data associated with the hook function.
512 * @param main_win the main window the viewer belongs to.
515 void RegUpdateDividor(LttvHook hook
, gpointer hook_data
,
516 mainWindow
*main_win
)
518 LttvAttributeValue value
;
520 g_assert(lttv_iattribute_find_by_path(main_win
->CurrentTab
->Attributes
,
521 "hooks/hpanedividor", LTTV_POINTER
, &value
));
522 tmp
= (LttvHooks
*)*(value
.v_pointer
);
524 tmp
= lttv_hooks_new();
525 *(value
.v_pointer
) = tmp
;
527 lttv_hooks_add(tmp
, hook
, hook_data
);
532 * Function to unregister a viewer's hook function which is used to
533 * set/update hpane's dividor of the viewer.
534 * It will be called by the destructor of the viewer.
535 * @param hook hook function of the viewer.
536 * @param hook_data hook data associated with the hook function.
537 * @param main_win the main window the viewer belongs to.
540 void UnregUpdateDividor(LttvHook hook
, gpointer hook_data
,
541 mainWindow
*main_win
)
543 LttvAttributeValue value
;
545 g_assert(lttv_iattribute_find_by_path(main_win
->CurrentTab
->Attributes
,
546 "hooks/hpanedividor", LTTV_POINTER
, &value
));
547 tmp
= (LttvHooks
*)*(value
.v_pointer
);
548 if(tmp
== NULL
) return;
549 lttv_hooks_remove_data(tmp
, hook
, hook_data
);
554 * Function to set the position of the hpane's dividor (viewer).
555 * It will be called by a viewer's signal handle associated with
556 * the motion_notify_event event/signal
557 * @param main_win the main window the viewer belongs to.
558 * @param position position of the hpane's dividor.
561 void SetHPaneDividor(mainWindow
*main_win
, gint position
)
563 LttvAttributeValue value
;
565 g_assert(lttv_iattribute_find_by_path(main_win
->CurrentTab
->Attributes
,
566 "hooks/hpanedividor", LTTV_POINTER
, &value
));
567 tmp
= (LttvHooks
*)*(value
.v_pointer
);
568 if(tmp
== NULL
) return;
569 lttv_hooks_call(tmp
, &position
);
574 * Function to process traceset. It will call lttv_process_trace,
575 * each view will call this api to get events.
576 * @param main_win the main window the viewer belongs to.
577 * @param start the start time of the first event to be processed.
578 * @param end the end time of the last event to be processed.
581 void processTraceset(mainWindow
*main_win
, LttTime start
,
582 LttTime end
, unsigned maxNumEvents
)
584 lttv_process_trace(start
, end
, main_win
->traceset
,
585 main_win
->traceset_context
, maxNumEvents
);
589 * Function to add hooks into the context of a traceset,
590 * before reading events from traceset, viewer will call this api to
592 * @param main_win the main window the viewer belongs to.
593 * @param LttvHooks hooks to be registered.
596 void contextAddHooks(mainWindow
*main_win
,
597 LttvHooks
*before_traceset
,
598 LttvHooks
*after_traceset
,
599 LttvHooks
*check_trace
,
600 LttvHooks
*before_trace
,
601 LttvHooks
*after_trace
,
602 LttvHooks
*check_tracefile
,
603 LttvHooks
*before_tracefile
,
604 LttvHooks
*after_tracefile
,
605 LttvHooks
*check_event
,
606 LttvHooks
*before_event
,
607 LttvHooks
*after_event
)
609 LttvTracesetContext
* tsc
= main_win
->traceset_context
;
610 lttv_traceset_context_add_hooks(tsc
,before_traceset
,after_traceset
,
611 check_trace
,before_trace
,after_trace
,
612 check_tracefile
,before_tracefile
,after_tracefile
,
613 check_event
,before_event
, after_event
);
618 * Function to remove hooks from the context of a traceset,
619 * before reading events from traceset, viewer will call this api to
621 * @param main_win the main window the viewer belongs to.
622 * @param LttvHooks hooks to be registered.
625 void contextRemoveHooks(mainWindow
*main_win
,
626 LttvHooks
*before_traceset
,
627 LttvHooks
*after_traceset
,
628 LttvHooks
*check_trace
,
629 LttvHooks
*before_trace
,
630 LttvHooks
*after_trace
,
631 LttvHooks
*check_tracefile
,
632 LttvHooks
*before_tracefile
,
633 LttvHooks
*after_tracefile
,
634 LttvHooks
*check_event
,
635 LttvHooks
*before_event
,
636 LttvHooks
*after_event
)
638 LttvTracesetContext
* tsc
= main_win
->traceset_context
;
639 lttv_traceset_context_remove_hooks(tsc
,before_traceset
,after_traceset
,
640 check_trace
,before_trace
,after_trace
,
641 check_tracefile
,before_tracefile
,after_tracefile
,
642 check_event
,before_event
, after_event
);
647 * Function to get the life span of the traceset
648 * @param main_win the main window the viewer belongs to.
649 * @param start start time of the traceset.
650 * @param end end time of the traceset.
653 void getTracesetTimeSpan(mainWindow
*main_win
, LttTime
* start
, LttTime
* end
)
655 LttvTraceset
* traceset
= main_win
->traceset
;
656 int numTraces
= lttv_traceset_number(traceset
);
659 LttvTraceContext
*tc
;
662 for(i
=0; i
<numTraces
;i
++){
663 tc
= main_win
->traceset_context
->traces
[i
];
666 ltt_trace_time_span_get(trace
, &s
, &e
);
672 if(s
.tv_sec
< start
->tv_sec
||
673 (s
.tv_sec
== start
->tv_sec
&& s
.tv_nsec
< start
->tv_nsec
))
675 if(e
.tv_sec
> end
->tv_sec
||
676 (e
.tv_sec
== end
->tv_sec
&& e
.tv_nsec
> end
->tv_nsec
))
684 * Function to add/remove event hooks for state
685 * @param main_win the main window the viewer belongs to.
688 void stateAddEventHooks(mainWindow
*main_win
)
690 lttv_state_add_event_hooks((LttvTracesetState
*)main_win
->traceset_context
);
693 void stateRemoveEventHooks(mainWindow
*main_win
)
695 lttv_state_remove_event_hooks((LttvTracesetState
*)main_win
->traceset_context
);
700 * Function to add/remove event hooks for stats
701 * @param main_win the main window the viewer belongs to.
704 void statsAddEventHooks(mainWindow
*main_win
)
706 lttv_stats_add_event_hooks((LttvTracesetStats
*)main_win
->traceset_context
);
709 void statsRemoveEventHooks(mainWindow
*main_win
)
711 lttv_stats_remove_event_hooks((LttvTracesetStats
*)main_win
->traceset_context
);
715 * Function to get the stats of the traceset
716 * @param main_win the main window the viewer belongs to.
719 LttvTracesetStats
* getTracesetStats(mainWindow
*main_win
)
721 return (LttvTracesetStats
*)main_win
->traceset_context
;