git-svn-id: http://ltt.polymtl.ca/svn@309 04897980-b3bd-0310-b5e0-8ef037075253
[lttv.git] / ltt / branches / poly / lttv / modules / gui / API / gtkTraceSet.c
1 /*! \file gtkTraceSet.h
2 * \brief API used by the graphical viewers to interact with their top window.
3 *
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
6 * events sent by gtk.
7 * This header file should be included in each graphic module.
8 * This library is used by graphical modules to interact with the
9 * tracesetWindow.
10 *
11 */
12
13 #include <lttv/common.h>
14 #include <ltt/ltt.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>
23
24
25 /**
26 * Internal function parts
27 */
28
29 /**
30 * Function to set/update traceset for the viewers
31 * @param main_win main window
32 * @param traceset traceset of the main window.
33 */
34
35 void SetTraceset(mainWindow * main_win, gpointer traceset)
36 {
37 LttvHooks * tmp;
38 LttvAttributeValue value;
39
40 g_assert(lttv_iattribute_find_by_path(main_win->Attributes,
41 "hooks/updatetraceset", LTTV_POINTER, &value));
42 tmp = (LttvHooks*)*(value.v_pointer);
43 if(tmp == NULL)return;
44 lttv_hooks_call(tmp,traceset);
45 }
46
47
48 /**
49 * Function to set/update filter for the viewers
50 * @param main_win main window
51 * @param filter filter of the main window.
52 */
53
54 void SetFilter(mainWindow * main_win, gpointer filter)
55 {
56 LttvHooks * tmp;
57 LttvAttributeValue value;
58
59 g_assert(lttv_iattribute_find_by_path(main_win->Attributes,
60 "hooks/updatefilter", LTTV_POINTER, &value));
61 tmp = (LttvHooks*)*(value.v_pointer);
62
63 if(tmp == NULL)return;
64 lttv_hooks_call(tmp,filter);
65 }
66
67
68
69 /**
70 * API parts
71 */
72
73 /**
74 * Function to register a view constructor so that main window can generate
75 * a toolbar item for the viewer in order to generate a new instance easily.
76 * It will be called by init function of the module.
77 * @param ButtonPixmap image shown on the toolbar item.
78 * @param tooltip tooltip of the toolbar item.
79 * @param view_constructor constructor of the viewer.
80 */
81
82 void ToolbarItemReg(char ** pixmap, char *tooltip, lttv_constructor view_constructor)
83 {
84 LttvIAttribute *attributes_global = LTTV_IATTRIBUTE(lttv_global_attributes());
85 LttvToolbars * toolbar;
86 LttvAttributeValue value;
87
88 g_assert(lttv_iattribute_find_by_path(attributes_global,
89 "viewers/toolbar", LTTV_POINTER, &value));
90 toolbar = (LttvToolbars*)*(value.v_pointer);
91
92 if(toolbar == NULL){
93 toolbar = lttv_toolbars_new();
94 *(value.v_pointer) = toolbar;
95 }
96 lttv_toolbars_add(toolbar, view_constructor, tooltip, pixmap);
97 }
98
99
100 /**
101 * Function to unregister the viewer's constructor, release the space
102 * occupied by pixmap, tooltip and constructor of the viewer.
103 * It will be called when a module is unloaded.
104 * @param view_constructor constructor of the viewer which is used as
105 * a reference to find out where the pixmap and tooltip are.
106 */
107
108 void ToolbarItemUnreg(lttv_constructor view_constructor)
109 {
110 LttvIAttribute *attributes_global = LTTV_IATTRIBUTE(lttv_global_attributes());
111 LttvToolbars * toolbar;
112 LttvAttributeValue value;
113
114 g_assert(lttv_iattribute_find_by_path(attributes_global,
115 "viewers/toolbar", LTTV_POINTER, &value));
116 toolbar = (LttvToolbars*)*(value.v_pointer);
117
118 main_window_remove_toolbar_item(view_constructor);
119
120 lttv_toolbars_remove(toolbar, view_constructor);
121 }
122
123
124 /**
125 * Function to register a view constructor so that main window can generate
126 * a menu item for the viewer in order to generate a new instance easily.
127 * It will be called by init function of the module.
128 * @param menu_path path of the menu item.
129 * @param menu_text text of the menu item.
130 * @param view_constructor constructor of the viewer.
131 */
132
133 void MenuItemReg(char *menu_path, char *menu_text, lttv_constructor view_constructor)
134 {
135 LttvIAttribute *attributes_global = LTTV_IATTRIBUTE(lttv_global_attributes());
136 LttvMenus * menu;
137 LttvAttributeValue value;
138
139 g_assert(lttv_iattribute_find_by_path(attributes_global,
140 "viewers/menu", LTTV_POINTER, &value));
141 menu = (LttvMenus*)*(value.v_pointer);
142
143 if(menu == NULL){
144 menu = lttv_menus_new();
145 *(value.v_pointer) = menu;
146 }
147 lttv_menus_add(menu, view_constructor, menu_path, menu_text);
148 }
149
150 /**
151 * Function to unregister the viewer's constructor, release the space
152 * occupied by menu_path, menu_text and constructor of the viewer.
153 * It will be called when a module is unloaded.
154 * @param view_constructor constructor of the viewer which is used as
155 * a reference to find out where the menu_path and menu_text are.
156 */
157
158 void MenuItemUnreg(lttv_constructor view_constructor)
159 {
160 LttvIAttribute *attributes_global = LTTV_IATTRIBUTE(lttv_global_attributes());
161 LttvMenus * menu;
162 LttvAttributeValue value;
163
164 g_assert(lttv_iattribute_find_by_path(attributes_global,
165 "viewers/menu", LTTV_POINTER, &value));
166 menu = (LttvMenus*)*(value.v_pointer);
167
168 main_window_remove_menu_item(view_constructor);
169
170 lttv_menus_remove(menu, view_constructor);
171 }
172
173
174 /**
175 * Update the status bar whenever something changed in the viewer.
176 * @param main_win the main window the viewer belongs to.
177 * @param info the message which will be shown in the status bar.
178 */
179
180 void UpdateStatus(mainWindow *main_win, char *info)
181 {
182 }
183
184
185 /**
186 * Function to get the current time interval shown on the current tab.
187 * It will be called by a viewer's hook function to update the
188 * shown time interval of the viewer and also be called by the constructor
189 * of the viewer.
190 * @param main_win the main window the viewer belongs to.
191 * @param time_interval a pointer where time interval will be stored.
192 */
193
194 void GetTimeWindow(mainWindow *main_win, TimeWindow *Time_Window)
195 {
196 //Time_Window->startTime = main_win->CurrentTab->Time_Window.startTime;
197 //Time_Window->Time_Width = main_win->CurrentTab->Time_Window.Time_Width;
198 *Time_Window = main_win->CurrentTab->Time_Window;
199 }
200
201 /**
202 * Function to get the current time interval of the current traceset.
203 * It will be called by a viewer's hook function to update the
204 * time interval of the viewer and also be called by the constructor
205 * of the viewer.
206 * @param main_win the main window the viewer belongs to.
207 * @param time_interval a pointer where time interval will be stored.
208 */
209
210 void getTracesetTimeSpan(mainWindow *main_win, TimeInterval *Time_Interval)
211 {
212 //Time_Window->startTime = main_win->CurrentTab->Time_Window.startTime;
213 //Time_Window->Time_Width = main_win->CurrentTab->Time_Window.Time_Width;
214 *Time_Interval = *(LTTV_TRACESET_CONTEXT(main_win->Traceset_Info->TracesetContext)->Time_Span);
215 }
216
217
218
219 /**
220 * Function to set the time interval of the current tab.
221 * It will be called by a viewer's signal handle associated with
222 * the move_slider signal
223 * @param main_win the main window the viewer belongs to.
224 * @param time_interval a pointer where time interval is stored.
225 */
226
227 void SetTimeWindow(mainWindow *main_win, TimeWindow *Time_Window)
228 {
229 LttvAttributeValue value;
230 LttvHooks * tmp;
231 main_win->CurrentTab->Time_Window = *Time_Window;
232 g_assert(lttv_iattribute_find_by_path(main_win->CurrentTab->Attributes,
233 "hooks/updatetimewindow", LTTV_POINTER, &value));
234 tmp = (LttvHooks*)*(value.v_pointer);
235 if(tmp == NULL) return;
236 lttv_hooks_call(tmp, Time_Window);
237 }
238
239
240 /**
241 * Function to get the current time/event of the current tab.
242 * It will be called by a viewer's hook function to update the
243 * current time/event of the viewer.
244 * @param main_win the main window the viewer belongs to.
245 * @param time a pointer where time will be stored.
246 */
247
248 void GetCurrentTime(mainWindow *main_win, LttTime *time)
249 {
250 time = &main_win->CurrentTab->currentTime;
251 }
252
253
254 /**
255 * Function to set the current time/event of the current tab.
256 * It will be called by a viewer's signal handle associated with
257 * the button-release-event signal
258 * @param main_win the main window the viewer belongs to.
259 * @param time a pointer where time is stored.
260 */
261
262 void SetCurrentTime(mainWindow *main_win, LttTime *time)
263 {
264 LttvAttributeValue value;
265 LttvHooks * tmp;
266 main_win->CurrentTab->currentTime = *time;
267 g_assert(lttv_iattribute_find_by_path(main_win->CurrentTab->Attributes,
268 "hooks/updatecurrenttime", LTTV_POINTER, &value));
269 tmp = (LttvHooks*)*(value.v_pointer);
270
271 if(tmp == NULL)return;
272 lttv_hooks_call(tmp, time);
273 }
274
275
276 /**
277 * Function to get the traceset from the current tab.
278 * It will be called by the constructor of the viewer and also be
279 * called by a hook funtion of the viewer to update its traceset.
280 * @param main_win the main window the viewer belongs to.
281 * @param traceset a pointer to a traceset.
282 */
283 /*
284 void GetTraceset(mainWindow *main_win, Traceset *traceset)
285 {
286 }
287 */
288
289 /**
290 * Function to get the filter of the current tab.
291 * It will be called by the constructor of the viewer and also be
292 * called by a hook funtion of the viewer to update its filter.
293 * @param main_win, the main window the viewer belongs to.
294 * @param filter, a pointer to a filter.
295 */
296 /*
297 void GetFilter(mainWindow *main_win, Filter *filter)
298 {
299 }
300 */
301
302 /**
303 * Function to register a hook function for a viewer to set/update its
304 * time interval.
305 * It will be called by the constructor of the viewer.
306 * @param hook hook function of the viewer.
307 * @param hook_data hook data associated with the hook function.
308 * @param main_win the main window the viewer belongs to.
309 */
310
311 void RegUpdateTimeWindow(LttvHook hook, gpointer hook_data,
312 mainWindow * main_win)
313 {
314 LttvAttributeValue value;
315 LttvHooks * tmp;
316 g_assert(lttv_iattribute_find_by_path(main_win->CurrentTab->Attributes,
317 "hooks/updatetimewindow", LTTV_POINTER, &value));
318 tmp = (LttvHooks*)*(value.v_pointer);
319 if(tmp == NULL){
320 tmp = lttv_hooks_new();
321 *(value.v_pointer) = tmp;
322 }
323 lttv_hooks_add(tmp, hook,hook_data);
324 }
325
326
327 /**
328 * Function to unregister a viewer's hook function which is used to
329 * set/update the time interval of the viewer.
330 * It will be called by the destructor of the viewer.
331 * @param hook hook function of the viewer.
332 * @param hook_data hook data associated with the hook function.
333 * @param main_win the main window the viewer belongs to.
334 */
335
336 void UnregUpdateTimeWindow(LttvHook hook, gpointer hook_data,
337 mainWindow * main_win)
338 {
339 LttvAttributeValue value;
340 LttvHooks * tmp;
341 g_assert(lttv_iattribute_find_by_path(main_win->CurrentTab->Attributes,
342 "hooks/updatetimewindow", LTTV_POINTER, &value));
343 tmp = (LttvHooks*)*(value.v_pointer);
344 if(tmp == NULL) return;
345 lttv_hooks_remove_data(tmp, hook, hook_data);
346 }
347
348
349 /**
350 * Function to register a hook function for a viewer to set/update its
351 * traceset.
352 * It will be called by the constructor of the viewer.
353 * @param hook hook function of the viewer.
354 * @param hook_data hook data associated with the hook function.
355 * @param main_win the main window the viewer belongs to.
356 */
357
358 void RegUpdateTraceset(LttvHook hook, gpointer hook_data,
359 mainWindow * main_win)
360 {
361 LttvAttributeValue value;
362 LttvHooks * tmp;
363 g_assert(lttv_iattribute_find_by_path(main_win->Attributes,
364 "hooks/updatetraceset", LTTV_POINTER, &value));
365 tmp = (LttvHooks*)*(value.v_pointer);
366 if(tmp == NULL){
367 tmp = lttv_hooks_new();
368 *(value.v_pointer) = tmp;
369 }
370 lttv_hooks_add(tmp, hook, hook_data);
371 }
372
373
374 /**
375 * Function to unregister a viewer's hook function which is used to
376 * set/update the traceset of the viewer.
377 * It will be called by the destructor of the viewer.
378 * @param hook hook function of the viewer.
379 * @param hook_data hook data associated with the hook function.
380 * @param main_win the main window the viewer belongs to.
381 */
382
383 void UnregUpdateTraceset(LttvHook hook, gpointer hook_data,
384 mainWindow * main_win)
385 {
386 LttvAttributeValue value;
387 LttvHooks * tmp;
388 g_assert(lttv_iattribute_find_by_path(main_win->Attributes,
389 "hooks/updatetraceset", LTTV_POINTER, &value));
390 tmp = (LttvHooks*)*(value.v_pointer);
391 if(tmp == NULL) return;
392 lttv_hooks_remove_data(tmp, hook, hook_data);
393 }
394
395
396 /**
397 * Function to register a hook function for a viewer to set/update its
398 * filter.
399 * It will be called by the constructor of the viewer.
400 * @param hook hook function of the viewer.
401 * @param hook_data hook data associated with the hook function.
402 * @param main_win the main window the viewer belongs to.
403 */
404
405 void RegUpdateFilter(LttvHook hook, gpointer hook_data,
406 mainWindow *main_win)
407 {
408 LttvAttributeValue value;
409 LttvHooks * tmp;
410 g_assert(lttv_iattribute_find_by_path(main_win->Attributes,
411 "hooks/updatefilter", LTTV_POINTER, &value));
412 tmp = (LttvHooks*)*(value.v_pointer);
413 if(tmp == NULL){
414 tmp = lttv_hooks_new();
415 *(value.v_pointer) = tmp;
416 }
417 lttv_hooks_add(tmp, hook, hook_data);
418 }
419
420
421 /**
422 * Function to unregister a viewer's hook function which is used to
423 * set/update the filter of the viewer.
424 * It will be called by the destructor of the viewer.
425 * @param hook hook function of the viewer.
426 * @param hook_data hook data associated with the hook function.
427 * @param main_win the main window the viewer belongs to.
428 */
429
430 void UnregUpdateFilter(LttvHook hook, gpointer hook_data,
431 mainWindow * main_win)
432 {
433 LttvAttributeValue value;
434 LttvHooks * tmp;
435 g_assert(lttv_iattribute_find_by_path(main_win->Attributes,
436 "hooks/updatefilter", LTTV_POINTER, &value));
437 tmp = (LttvHooks*)*(value.v_pointer);
438 if(tmp == NULL) return;
439 lttv_hooks_remove_data(tmp, hook, hook_data);
440 }
441
442
443 /**
444 * Function to register a hook function for a viewer to set/update its
445 * current time.
446 * It will be called by the constructor of the viewer.
447 * @param hook hook function of the viewer.
448 * @param hook_data hook data associated with the hook function.
449 * @param main_win the main window the viewer belongs to.
450 */
451
452 void RegUpdateCurrentTime(LttvHook hook, gpointer hook_data,
453 mainWindow *main_win)
454 {
455 LttvAttributeValue value;
456 LttvHooks * tmp;
457 g_assert(lttv_iattribute_find_by_path(main_win->CurrentTab->Attributes,
458 "hooks/updatecurrenttime", LTTV_POINTER, &value));
459 tmp = (LttvHooks*)*(value.v_pointer);
460 if(tmp == NULL){
461 tmp = lttv_hooks_new();
462 *(value.v_pointer) = tmp;
463 }
464 lttv_hooks_add(tmp, hook, hook_data);
465 }
466
467
468 /**
469 * Function to unregister a viewer's hook function which is used to
470 * set/update the current time of the viewer.
471 * It will be called by the destructor of the viewer.
472 * @param hook hook function of the viewer.
473 * @param hook_data hook data associated with the hook function.
474 * @param main_win the main window the viewer belongs to.
475 */
476
477 void UnregUpdateCurrentTime(LttvHook hook, gpointer hook_data,
478 mainWindow * main_win)
479 {
480 LttvAttributeValue value;
481 LttvHooks * tmp;
482 g_assert(lttv_iattribute_find_by_path(main_win->CurrentTab->Attributes,
483 "hooks/updatecurrenttime", LTTV_POINTER, &value));
484 tmp = (LttvHooks*)*(value.v_pointer);
485 if(tmp == NULL) return;
486 lttv_hooks_remove_data(tmp, hook, hook_data);
487 }
488
489
490 /**
491 * Function to set the focused pane (viewer).
492 * It will be called by a viewer's signal handle associated with
493 * the grab_focus signal
494 * @param main_win the main window the viewer belongs to.
495 * @param paned a pointer to a pane where the viewer is contained.
496 */
497
498 void SetFocusedPane(mainWindow *main_win, gpointer paned)
499 {
500 gtk_custom_set_focus((GtkWidget*)main_win->CurrentTab->custom,paned);
501 }
502
503
504 /**
505 * Function to register a hook function for a viewer to set/update the
506 * dividor of the hpane.
507 * It will be called by the constructor of the viewer.
508 * @param hook hook function of the viewer.
509 * @param hook_data hook data associated with the hook function.
510 * @param main_win the main window the viewer belongs to.
511 */
512
513 void RegUpdateDividor(LttvHook hook, gpointer hook_data,
514 mainWindow *main_win)
515 {
516 LttvAttributeValue value;
517 LttvHooks * tmp;
518 g_assert(lttv_iattribute_find_by_path(main_win->CurrentTab->Attributes,
519 "hooks/hpanedividor", LTTV_POINTER, &value));
520 tmp = (LttvHooks*)*(value.v_pointer);
521 if(tmp == NULL){
522 tmp = lttv_hooks_new();
523 *(value.v_pointer) = tmp;
524 }
525 lttv_hooks_add(tmp, hook, hook_data);
526 }
527
528
529 /**
530 * Function to unregister a viewer's hook function which is used to
531 * set/update hpane's dividor of the viewer.
532 * It will be called by the destructor of the viewer.
533 * @param hook hook function of the viewer.
534 * @param hook_data hook data associated with the hook function.
535 * @param main_win the main window the viewer belongs to.
536 */
537
538 void UnregUpdateDividor(LttvHook hook, gpointer hook_data,
539 mainWindow *main_win)
540 {
541 LttvAttributeValue value;
542 LttvHooks * tmp;
543 g_assert(lttv_iattribute_find_by_path(main_win->CurrentTab->Attributes,
544 "hooks/hpanedividor", LTTV_POINTER, &value));
545 tmp = (LttvHooks*)*(value.v_pointer);
546 if(tmp == NULL) return;
547 lttv_hooks_remove_data(tmp, hook, hook_data);
548 }
549
550
551 /**
552 * Function to set the position of the hpane's dividor (viewer).
553 * It will be called by a viewer's signal handle associated with
554 * the motion_notify_event event/signal
555 * @param main_win the main window the viewer belongs to.
556 * @param position position of the hpane's dividor.
557 */
558
559 void SetHPaneDividor(mainWindow *main_win, gint position)
560 {
561 LttvAttributeValue value;
562 LttvHooks * tmp;
563 g_assert(lttv_iattribute_find_by_path(main_win->CurrentTab->Attributes,
564 "hooks/hpanedividor", LTTV_POINTER, &value));
565 tmp = (LttvHooks*)*(value.v_pointer);
566 if(tmp == NULL) return;
567 lttv_hooks_call(tmp, &position);
568 }
569
570
571 /**
572 * Function to process traceset. It will call lttv_process_trace,
573 * each view will call this api to get events.
574 * @param main_win the main window the viewer belongs to.
575 * @param start the start time of the first event to be processed.
576 * @param end the end time of the last event to be processed.
577 */
578
579 void processTraceset(mainWindow *main_win, LttTime start,
580 LttTime end, unsigned maxNumEvents)
581 {
582 lttv_process_traceset_seek_time(main_win->Traceset_Info->TracesetContext, start);
583 lttv_process_traceset(main_win->Traceset_Info->TracesetContext, end, maxNumEvents);
584 }
585
586 /**
587 * Function to add hooks into the context of a traceset,
588 * before reading events from traceset, viewer will call this api to
589 * register hooks
590 * @param main_win the main window the viewer belongs to.
591 * @param LttvHooks hooks to be registered.
592 */
593
594 void contextAddHooks(mainWindow *main_win ,
595 LttvHooks *before_traceset,
596 LttvHooks *after_traceset,
597 LttvHooks *check_trace,
598 LttvHooks *before_trace,
599 LttvHooks *after_trace,
600 LttvHooks *check_tracefile,
601 LttvHooks *before_tracefile,
602 LttvHooks *after_tracefile,
603 LttvHooks *check_event,
604 LttvHooks *before_event,
605 LttvHooks *after_event)
606 {
607 LttvTracesetContext * tsc =
608 LTTV_TRACESET_CONTEXT(main_win->Traceset_Info->TracesetContext);
609 lttv_traceset_context_add_hooks(tsc,before_traceset,after_traceset,
610 check_trace,before_trace,after_trace,
611 check_tracefile,before_tracefile,after_tracefile,
612 check_event,before_event, after_event);
613 }
614
615
616 /**
617 * Function to remove hooks from the context of a traceset,
618 * before reading events from traceset, viewer will call this api to
619 * unregister hooks
620 * @param main_win the main window the viewer belongs to.
621 * @param LttvHooks hooks to be registered.
622 */
623
624 void contextRemoveHooks(mainWindow *main_win ,
625 LttvHooks *before_traceset,
626 LttvHooks *after_traceset,
627 LttvHooks *check_trace,
628 LttvHooks *before_trace,
629 LttvHooks *after_trace,
630 LttvHooks *check_tracefile,
631 LttvHooks *before_tracefile,
632 LttvHooks *after_tracefile,
633 LttvHooks *check_event,
634 LttvHooks *before_event,
635 LttvHooks *after_event)
636 {
637 LttvTracesetContext * tsc =
638 LTTV_TRACESET_CONTEXT(main_win->Traceset_Info->TracesetContext);
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);
643 }
644
645
646 /**
647 * Function to add/remove event hooks for state
648 * @param main_win the main window the viewer belongs to.
649 */
650
651 void stateAddEventHooks(mainWindow *main_win )
652 {
653 lttv_state_add_event_hooks(
654 (LttvTracesetState*)main_win->Traceset_Info->TracesetContext);
655 }
656
657 void stateRemoveEventHooks(mainWindow *main_win )
658 {
659 lttv_state_remove_event_hooks(
660 (LttvTracesetState*)main_win->Traceset_Info->TracesetContext);
661 }
662
663
664 /**
665 * Function to add/remove event hooks for stats
666 * @param main_win the main window the viewer belongs to.
667 */
668
669 void statsAddEventHooks(mainWindow *main_win )
670 {
671 lttv_stats_add_event_hooks(
672 (LttvTracesetStats*)main_win->Traceset_Info->TracesetContext);
673 }
674
675 void statsRemoveEventHooks(mainWindow *main_win )
676 {
677 lttv_stats_remove_event_hooks(
678 (LttvTracesetStats*)main_win->Traceset_Info->TracesetContext);
679 }
680
681 /**
682 * Function to get the stats of the traceset
683 * @param main_win the main window the viewer belongs to.
684 */
685
686 LttvTracesetStats* getTracesetStats(mainWindow *main_win)
687 {
688 return main_win->Traceset_Info->TracesetContext;
689 }
This page took 0.043147 seconds and 4 git commands to generate.