1 /*****************************************************************************
2 * Hooks to be called by the main window *
3 *****************************************************************************/
6 #define g_info(format...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_INFO, format)
7 #define g_debug(format...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, format)
9 //#define PANGO_ENABLE_BACKEND
14 //#include <pango/pango.h>
16 #include <lttv/hook.h>
17 #include <lttv/common.h>
19 #include "Event_Hooks.h"
21 #include "Process_List.h"
23 #include "CFV-private.h"
25 #define MAX_PATH_LEN 256
27 //FIXME : remove this include when tests finished.
30 void test_draw_item(Drawing_t
*Drawing
,
33 PropertiesIcon properties_icon
;
34 DrawContext draw_context
;
36 DrawInfo current
, previous
;
37 ItemInfo over
, middle
, under
, modify_over
, modify_middle
, modify_under
;
41 for(i
=0; i
<1024;i
=i
+15)
50 current
.modify_over
= &over
;
52 draw_context
.drawable
= Pixmap
;
53 draw_context
.gc
= Drawing
->Drawing_Area_V
->style
->black_gc
;
55 draw_context
.Current
= ¤t
;
56 draw_context
.Previous
= NULL
;
58 properties_icon
.icon_name
= g_new(char, MAX_PATH_LEN
);
59 strncpy(properties_icon
.icon_name
,
60 "/home/compudj/local/share/LinuxTraceToolkit/pixmaps/mini-display.xpm",
62 properties_icon
.width
= -1;
63 properties_icon
.height
= -1;
64 properties_icon
.position
= OVER
;
65 draw_icon(&properties_icon
, &draw_context
);
66 g_free(properties_icon
.icon_name
);
72 /* NOTE : no drawing data should be sent there, since the drawing widget
73 * has not been initialized */
74 void send_test_drawing(ProcessList
*Process_List
,
77 gint x
, gint y
, // y not used here?
79 gint height
) // height won't be used here ?
82 ProcessInfo Process_Info
= {10000, 12000, 55600};
83 //ProcessInfo Process_Info = {156, 14000, 55500};
84 GtkTreeRowReference
*got_RowRef
;
85 PangoContext
*context
;
87 PangoFontDescription
*FontDesc
;// = pango_font_description_new();
91 //GdkBitmap *mask = g_new(GdkBitmap, 1);
92 //GdkPixmap *icon_pixmap = g_new(GdkPixmap, 1);
95 GdkColor color
= { 0, 0xffff, 0x0000, 0x0000 };
97 gc
= gdk_gc_new(Pixmap
);
99 layout
= gtk_widget_create_pango_layout(Drawing
->Drawing_Area_V
,
101 context
= pango_layout_get_context(layout
);
102 FontDesc
= pango_context_get_font_description(context
);
103 Font_Size
= pango_font_description_get_size(FontDesc
);
104 pango_font_description_set_size(FontDesc
, Font_Size
-3*PANGO_SCALE
);
110 birth
.tv_sec
= 12000;
111 birth
.tv_nsec
= 55500;
112 g_info("we have : x : %u, y : %u, width : %u, height : %u", x
, y
, width
, height
);
113 processlist_get_process_pixels(Process_List
,
119 g_info("we draw : x : %u, y : %u, width : %u, height : %u", x
, y
, width
, height
);
122 y
+(height
/2), x
+ width
, y
+(height
/2),
123 Drawing
->Drawing_Area_V
->style
->black_gc
);
125 pango_layout_set_text(layout
, "Test", -1);
126 gdk_draw_layout(Pixmap
, Drawing
->Drawing_Area_V
->style
->black_gc
,
127 0, y
+height
, layout
);
129 birth
.tv_sec
= 14000;
130 birth
.tv_nsec
= 55500;
132 processlist_get_process_pixels(Process_List
,
141 y
+(height
/2), x
+ width
, y
+(height
/2),
142 Drawing
->Drawing_Area_V
->style
->black_gc
);
144 g_info("y : %u, height : %u", y
, height
);
148 birth
.tv_sec
= 12000;
149 birth
.tv_nsec
= 55700;
151 processlist_get_process_pixels(Process_List
,
157 /* Draw rectangle (background color) */
158 gdk_gc_copy(gc
, Drawing
->Drawing_Area_V
->style
->black_gc
);
159 gdk_gc_set_rgb_fg_color(gc
, &color
);
160 gdk_draw_rectangle(Pixmap
, gc
,
162 x
, y
, width
, height
);
166 y
+(height
/2), x
+ width
, y
+(height
/2),
167 Drawing
->Drawing_Area_V
->style
->black_gc
);
171 gdk_draw_arc(Pixmap
, Drawing
->Drawing_Area_V
->style
->black_gc
,
172 TRUE
, 100, y
, height
/2, height
/2, 0, 360*64);
174 g_info("y : %u, height : %u", y
, height
);
178 birth
.tv_sec
= i
*12000;
179 birth
.tv_nsec
= i
*55700;
181 processlist_get_process_pixels(Process_List
,
190 y
+(height
/2), x
+ width
, y
+(height
/2),
191 Drawing
->Drawing_Area_V
->style
->black_gc
);
193 g_critical("y : %u, height : %u", y
, height
);
197 birth
.tv_sec
= 12000;
198 birth
.tv_nsec
= 55600;
200 processlist_get_process_pixels(Process_List
,
209 y
+(height
/2), x
+ width
, y
+(height
/2),
210 Drawing
->Drawing_Area_V
->style
->black_gc
);
212 g_info("y : %u, height : %u", y
, height
);
215 /* IMPORTANT : This action uses the cpu heavily! */
216 //icon_pixmap = gdk_pixmap_create_from_xpm(Pixmap, &mask, NULL,
217 // "/home/compudj/local/share/LinuxTraceToolkit/pixmaps/move_message.xpm");
218 // "/home/compudj/local/share/LinuxTraceToolkit/pixmaps/mini-display.xpm");
220 // gdk_gc_set_clip_mask(Drawing->Drawing_Area_V->style->black_gc, mask);
222 // for(i=x;i<x+width;i=i+15)
224 // for(j=0;j<height*20;j=j+15)
228 //gdk_gc_copy(gc, Drawing->Drawing_Area_V->style->black_gc);
229 // gdk_gc_set_clip_origin(Drawing->Drawing_Area_V->style->black_gc, i, j);
230 // gdk_draw_drawable(Pixmap,
231 // Drawing->Drawing_Area_V->style->black_gc,
233 // 0, 0, i, j, -1, -1);
238 test_draw_item(Drawing
,Pixmap
);
240 //gdk_gc_set_clip_origin(Drawing->Drawing_Area_V->style->black_gc, 0, 0);
241 //gdk_gc_set_clip_mask(Drawing->Drawing_Area_V->style->black_gc, NULL);
243 //g_free(icon_pixmap);
251 pango_font_description_set_size(FontDesc
, Font_Size
);
252 g_object_unref(layout
);
256 void send_test_process(ProcessList
*Process_List
, Drawing_t
*Drawing
)
260 ProcessInfo Process_Info
= {10000, 12000, 55600};
261 //ProcessInfo Process_Info = {156, 14000, 55500};
262 GtkTreeRowReference
*got_RowRef
;
266 if(Process_List
->Test_Process_Sent
) return;
268 birth
.tv_sec
= 12000;
269 birth
.tv_nsec
= 55500;
271 processlist_add(Process_List
,
275 processlist_get_process_pixels(Process_List
,
280 drawing_insert_square( Drawing
, y
, height
);
282 //g_critical("y : %u, height : %u", y, height);
284 birth
.tv_sec
= 14000;
285 birth
.tv_nsec
= 55500;
287 processlist_add(Process_List
,
291 processlist_get_process_pixels(Process_List
,
296 drawing_insert_square( Drawing
, y
, height
);
298 //g_critical("y : %u, height : %u", y, height);
300 birth
.tv_sec
= 12000;
301 birth
.tv_nsec
= 55700;
303 processlist_add(Process_List
,
307 processlist_get_process_pixels(Process_List
,
312 drawing_insert_square( Drawing
, y
, height
);
314 //g_critical("y : %u, height : %u", y, height);
316 //drawing_insert_square( Drawing, height, 5);
320 birth
.tv_sec
= i
*12000;
321 birth
.tv_nsec
= i
*55700;
323 processlist_add(Process_List
,
327 processlist_get_process_pixels(Process_List
,
332 drawing_insert_square( Drawing
, y
, height
);
334 // g_critical("y : %u, height : %u", y, height);
337 //g_critical("height : %u", height);
339 birth
.tv_sec
= 12000;
340 birth
.tv_nsec
= 55600;
342 processlist_add(Process_List
,
346 processlist_get_process_pixels(Process_List
,
351 drawing_insert_square( Drawing
, y
, height
);
353 //g_critical("y : %u, height : %u", y, height);
355 processlist_add(Process_List
,
359 processlist_get_process_pixels(Process_List
,
364 drawing_insert_square( Drawing
, y
, height
);
366 //g_critical("y : %u, height : %u", y, height);
368 //drawing_insert_square( Drawing, height, 5);
369 //g_critical("height : %u", height);
372 processlist_get_process_pixels(Process_List
,
376 processlist_remove( Process_List
,
380 drawing_remove_square( Drawing
, y
, height
);
383 (GtkTreeRowReference
*)g_hash_table_lookup(
384 Process_List
->Process_Hash
,
387 g_critical("key found");
388 g_critical("position in the list : %s",
389 gtk_tree_path_to_string (
390 gtk_tree_row_reference_get_path(
391 (GtkTreeRowReference
*)got_RowRef
)
396 Process_List
->Test_Process_Sent
= TRUE
;
403 * Event Viewer's constructor hook
405 * This constructor is given as a parameter to the menuitem and toolbar button
406 * registration. It creates the list.
407 * @param pmParentWindow A pointer to the parent window.
408 * @return The widget created.
411 h_guicontrolflow(MainWindow
*pmParentWindow
, LttvTracesetSelector
* s
, char * key
)
413 g_info("h_guicontrolflow, %p, %p, %s", pmParentWindow
, s
, key
);
414 ControlFlowData
*Control_Flow_Data
= guicontrolflow() ;
416 Control_Flow_Data
->Parent_Window
= pmParentWindow
;
417 TimeWindow
*time_window
= guicontrolflow_get_time_window(Control_Flow_Data
);
418 time_window
->start_time
.tv_sec
= 0;
419 time_window
->start_time
.tv_nsec
= 0;
420 time_window
->time_width
.tv_sec
= 0;
421 time_window
->time_width
.tv_nsec
= 0;
423 LttTime
*current_time
= guicontrolflow_get_current_time(Control_Flow_Data
);
424 current_time
->tv_sec
= 0;
425 current_time
->tv_nsec
= 0;
427 //g_critical("time width1 : %u",time_window->time_width);
429 get_time_window(pmParentWindow
,
431 get_current_time(pmParentWindow
,
434 //g_critical("time width2 : %u",time_window->time_width);
435 // Unreg done in the GuiControlFlow_Destructor
436 reg_update_time_window(update_time_window_hook
, Control_Flow_Data
,
438 reg_update_current_time(update_current_time_hook
, Control_Flow_Data
,
440 return guicontrolflow_get_widget(Control_Flow_Data
) ;
444 int event_selected_hook(void *hook_data
, void *call_data
)
446 ControlFlowData
*Control_Flow_Data
= (ControlFlowData
*) hook_data
;
447 guint
*Event_Number
= (guint
*) call_data
;
449 g_critical("DEBUG : event selected by main window : %u", *Event_Number
);
451 // Control_Flow_Data->Currently_Selected_Event = *Event_Number;
452 // Control_Flow_Data->Selected_Event = TRUE ;
454 // tree_v_set_cursor(Control_Flow_Data);
458 /* Hook called before drawing. Gets the initial context at the beginning of the
459 * drawing interval and copy it to the context in Event_Request.
461 int draw_before_hook(void *hook_data
, void *call_data
)
463 EventRequest
*Event_Request
= (EventRequest
*)hook_data
;
464 //EventsContext Events_Context = (EventsContext*)call_data;
466 //Event_Request->Events_Context = Events_Context;
472 * The draw event hook is called by the reading API to have a
473 * particular event drawn on the screen.
474 * @param hook_data ControlFlowData structure of the viewer.
475 * @param call_data Event context.
477 * This function basically draw lines and icons. Two types of lines are drawn :
478 * one small (3 pixels?) representing the state of the process and the second
479 * type is thicker (10 pixels?) representing on which CPU a process is running
480 * (and this only in running state).
482 * Extremums of the lines :
483 * x_min : time of the last event context for this process kept in memory.
484 * x_max : time of the current event.
485 * y : middle of the process in the process list. The process is found in the
486 * list, therefore is it's position in pixels.
488 * The choice of lines'color is defined by the context of the last event for this
491 int draw_event_hook(void *hook_data
, void *call_data
)
493 EventRequest
*Event_Request
= (EventRequest
*)hook_data
;
498 //g_critical("%i", i);
500 /* Text dumping if the information */
501 GString
*string
= g_string_new("");;
502 gboolean field_names
= TRUE
, state
= TRUE
;
503 LttvTracefileContext
*tfc
= (LttvTracefileContext
*)call_data
;
505 LttvTracefileState
*tfs
= (LttvTracefileState
*)call_data
;
511 lttv_event_to_string(e
, tfc
->tf
, string
, TRUE
, field_names
, tfs
);
512 g_string_append_printf(string
,"\n");
515 g_string_append_printf(string
, " %s",
516 g_quark_to_string(tfs
->process
->state
->s
));
519 g_info("%s",string
->str
);
521 g_string_free(string
, TRUE
);
523 /* End of text dump */
525 /* Add process to process list (if not present) and get drawing "y" from
526 * process position */
527 guint pid
= tfs
->process
->pid
;
528 LttTime birth
= tfs
->process
->creation_time
;
529 guint y
= 0, height
= 0;
530 ProcessList
*process_list
=
531 guicontrolflow_get_process_list(Event_Request
->Control_Flow_Data
);
533 if(processlist_get_process_pixels(process_list
,
539 /* Process not present */
540 processlist_add(process_list
,
544 drawing_insert_square( Event_Request
->Control_Flow_Data
->Drawing
, y
, height
);
547 /* Find pixels corresponding to time of the event. If the time does
548 * not fit in the window, show a warning, not supposed to happend. */
551 /* Finally, draw what represents the event. */
558 int draw_after_hook(void *hook_data
, void *call_data
)
560 EventRequest
*Event_Request
= (EventRequest
*)hook_data
;
562 g_free(Event_Request
);
569 void update_time_window_hook(void *hook_data
, void *call_data
)
571 ControlFlowData
*Control_Flow_Data
= (ControlFlowData
*) hook_data
;
572 TimeWindow
* Time_Window
=
573 guicontrolflow_get_time_window(Control_Flow_Data
);
574 TimeWindow
*New_Time_Window
= ((TimeWindow
*)call_data
);
576 // As the time interval change will mostly be used for
577 // zoom in and out, it's not useful to keep old drawing
578 // sections, as scale will be changed.
581 *Time_Window
= *New_Time_Window
;
582 g_info("New time window HOOK : %u, %u to %u, %u",
583 Time_Window
->start_time
.tv_sec
,
584 Time_Window
->start_time
.tv_nsec
,
585 Time_Window
->time_width
.tv_sec
,
586 Time_Window
->time_width
.tv_nsec
);
588 drawing_data_request(Control_Flow_Data
->Drawing
,
589 &Control_Flow_Data
->Drawing
->Pixmap
,
591 Control_Flow_Data
->Drawing
->width
,
592 Control_Flow_Data
->Drawing
->height
);
594 drawing_refresh(Control_Flow_Data
->Drawing
,
596 Control_Flow_Data
->Drawing
->width
,
597 Control_Flow_Data
->Drawing
->height
);
601 void update_current_time_hook(void *hook_data
, void *call_data
)
603 ControlFlowData
*Control_Flow_Data
= (ControlFlowData
*) hook_data
;
604 LttTime
* Current_Time
=
605 guicontrolflow_get_current_time(Control_Flow_Data
);
606 *Current_Time
= *((LttTime
*)call_data
);
607 g_info("New Current time HOOK : %u, %u", Current_Time
->tv_sec
,
608 Current_Time
->tv_nsec
);
610 /* If current time is inside time interval, just move the highlight
613 /* Else, we have to change the time interval. We have to tell it
614 * to the main window. */
615 /* The time interval change will take care of placing the current
616 * time at the center of the visible area */