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"
26 /* NOTE : no drawing data should be sent there, since the drawing widget
27 * has not been initialized */
28 void send_test_drawing(ProcessList
*Process_List
,
31 gint x
, gint y
, // y not used here?
33 gint height
) // height won't be used here ?
36 ProcessInfo Process_Info
= {10000, 12000, 55600};
37 //ProcessInfo Process_Info = {156, 14000, 55500};
38 GtkTreeRowReference
*got_RowRef
;
39 PangoContext
*context
;
41 PangoFontDescription
*FontDesc
;// = pango_font_description_new();
45 GdkBitmap
*mask
= g_new(GdkBitmap
, 1);
46 GdkPixmap
*icon_pixmap
= g_new(GdkPixmap
, 1);
47 GdkGC
* gc
= gdk_gc_new(Pixmap
);
50 GdkColor color
= { 0, 0xffff, 0x0000, 0x0000 };
53 layout
= gtk_widget_create_pango_layout(Drawing
->Drawing_Area_V
,
55 context
= pango_layout_get_context(layout
);
56 FontDesc
= pango_context_get_font_description(context
);
57 Font_Size
= pango_font_description_get_size(FontDesc
);
58 pango_font_description_set_size(FontDesc
, Font_Size
-3*PANGO_SCALE
);
65 birth
.tv_nsec
= 55500;
66 g_info("we have : x : %u, y : %u, width : %u, height : %u", x
, y
, width
, height
);
67 processlist_get_process_pixels(Process_List
,
73 g_info("we draw : x : %u, y : %u, width : %u, height : %u", x
, y
, width
, height
);
76 y
+(height
/2), x
+ width
, y
+(height
/2),
77 Drawing
->Drawing_Area_V
->style
->black_gc
);
79 pango_layout_set_text(layout
, "Test", -1);
80 gdk_draw_layout(Pixmap
, Drawing
->Drawing_Area_V
->style
->black_gc
,
84 birth
.tv_nsec
= 55500;
86 processlist_get_process_pixels(Process_List
,
95 y
+(height
/2), x
+ width
, y
+(height
/2),
96 Drawing
->Drawing_Area_V
->style
->black_gc
);
100 icon_pixmap
= gdk_pixmap_create_from_xpm(Pixmap
, &mask
, NULL
,
101 // "/home/compudj/local/share/LinuxTraceToolkit/pixmaps/move_message.xpm");
102 "/home/compudj/local/share/LinuxTraceToolkit/pixmaps/mini-display.xpm");
103 gdk_gc_copy(gc
, Drawing
->Drawing_Area_V
->style
->black_gc
);
104 gdk_gc_set_clip_mask(gc
, mask
);
105 gdk_draw_drawable(Pixmap
,
113 g_info("y : %u, height : %u", y
, height
);
117 birth
.tv_sec
= 12000;
118 birth
.tv_nsec
= 55700;
120 processlist_get_process_pixels(Process_List
,
126 /* Draw rectangle (background color) */
127 gdk_gc_copy(gc
, Drawing
->Drawing_Area_V
->style
->black_gc
);
128 gdk_gc_set_rgb_fg_color(gc
, &color
);
129 gdk_draw_rectangle(Pixmap
, gc
,
131 x
, y
, width
, height
);
135 y
+(height
/2), x
+ width
, y
+(height
/2),
136 Drawing
->Drawing_Area_V
->style
->black_gc
);
140 gdk_draw_arc(Pixmap
, Drawing
->Drawing_Area_V
->style
->black_gc
,
141 TRUE
, 100, y
, height
/2, height
/2, 0, 360*64);
143 g_info("y : %u, height : %u", y
, height
);
147 birth
.tv_sec
= i
*12000;
148 birth
.tv_nsec
= i
*55700;
150 processlist_get_process_pixels(Process_List
,
159 y
+(height
/2), x
+ width
, y
+(height
/2),
160 Drawing
->Drawing_Area_V
->style
->black_gc
);
162 g_critical("y : %u, height : %u", y
, height
);
166 birth
.tv_sec
= 12000;
167 birth
.tv_nsec
= 55600;
169 processlist_get_process_pixels(Process_List
,
178 y
+(height
/2), x
+ width
, y
+(height
/2),
179 Drawing
->Drawing_Area_V
->style
->black_gc
);
181 g_info("y : %u, height : %u", y
, height
);
184 pango_font_description_set_size(FontDesc
, Font_Size
);
190 void send_test_process(ProcessList
*Process_List
, Drawing_t
*Drawing
)
194 ProcessInfo Process_Info
= {10000, 12000, 55600};
195 //ProcessInfo Process_Info = {156, 14000, 55500};
196 GtkTreeRowReference
*got_RowRef
;
200 if(Process_List
->Test_Process_Sent
) return;
202 birth
.tv_sec
= 12000;
203 birth
.tv_nsec
= 55500;
205 processlist_add(Process_List
,
209 processlist_get_process_pixels(Process_List
,
214 drawing_insert_square( Drawing
, y
, height
);
216 //g_critical("y : %u, height : %u", y, height);
218 birth
.tv_sec
= 14000;
219 birth
.tv_nsec
= 55500;
221 processlist_add(Process_List
,
225 processlist_get_process_pixels(Process_List
,
230 drawing_insert_square( Drawing
, y
, height
);
232 //g_critical("y : %u, height : %u", y, height);
234 birth
.tv_sec
= 12000;
235 birth
.tv_nsec
= 55700;
237 processlist_add(Process_List
,
241 processlist_get_process_pixels(Process_List
,
246 drawing_insert_square( Drawing
, y
, height
);
248 //g_critical("y : %u, height : %u", y, height);
250 //drawing_insert_square( Drawing, height, 5);
254 birth
.tv_sec
= i
*12000;
255 birth
.tv_nsec
= i
*55700;
257 processlist_add(Process_List
,
261 processlist_get_process_pixels(Process_List
,
266 drawing_insert_square( Drawing
, y
, height
);
268 // g_critical("y : %u, height : %u", y, height);
271 //g_critical("height : %u", height);
273 birth
.tv_sec
= 12000;
274 birth
.tv_nsec
= 55600;
276 processlist_add(Process_List
,
280 processlist_get_process_pixels(Process_List
,
285 drawing_insert_square( Drawing
, y
, height
);
287 //g_critical("y : %u, height : %u", y, height);
289 processlist_add(Process_List
,
293 processlist_get_process_pixels(Process_List
,
298 drawing_insert_square( Drawing
, y
, height
);
300 //g_critical("y : %u, height : %u", y, height);
302 //drawing_insert_square( Drawing, height, 5);
303 //g_critical("height : %u", height);
306 processlist_get_process_pixels(Process_List
,
310 processlist_remove( Process_List
,
314 drawing_remove_square( Drawing
, y
, height
);
317 (GtkTreeRowReference
*)g_hash_table_lookup(
318 Process_List
->Process_Hash
,
321 g_critical("key found");
322 g_critical("position in the list : %s",
323 gtk_tree_path_to_string (
324 gtk_tree_row_reference_get_path(
325 (GtkTreeRowReference
*)got_RowRef
)
330 Process_List
->Test_Process_Sent
= TRUE
;
337 * Event Viewer's constructor hook
339 * This constructor is given as a parameter to the menuitem and toolbar button
340 * registration. It creates the list.
341 * @param pmParentWindow A pointer to the parent window.
342 * @return The widget created.
345 h_guicontrolflow(MainWindow
*pmParentWindow
, LttvTracesetSelector
* s
, char * key
)
347 g_info("h_guicontrolflow, %p, %p, %s", pmParentWindow
, s
, key
);
348 ControlFlowData
*Control_Flow_Data
= guicontrolflow() ;
350 Control_Flow_Data
->Parent_Window
= pmParentWindow
;
352 get_time_window(pmParentWindow
,
353 guicontrolflow_get_time_window(Control_Flow_Data
));
354 get_current_time(pmParentWindow
,
355 guicontrolflow_get_current_time(Control_Flow_Data
));
357 // Unreg done in the GuiControlFlow_Destructor
358 reg_update_time_window(update_time_window_hook
, Control_Flow_Data
,
360 reg_update_current_time(update_current_time_hook
, Control_Flow_Data
,
362 return guicontrolflow_get_widget(Control_Flow_Data
) ;
366 int event_selected_hook(void *hook_data
, void *call_data
)
368 ControlFlowData
*Control_Flow_Data
= (ControlFlowData
*) hook_data
;
369 guint
*Event_Number
= (guint
*) call_data
;
371 g_critical("DEBUG : event selected by main window : %u", *Event_Number
);
373 // Control_Flow_Data->Currently_Selected_Event = *Event_Number;
374 // Control_Flow_Data->Selected_Event = TRUE ;
376 // tree_v_set_cursor(Control_Flow_Data);
381 /* Hook called before drawing. Gets the initial context at the beginning of the
382 * drawing interval and copy it to the context in Event_Request.
384 int draw_before_hook(void *hook_data
, void *call_data
)
386 EventRequest
*Event_Request
= (EventRequest
*)hook_data
;
387 EventsContext Events_Context
= (EventsContext
*)call_data
;
389 Event_Request
->Events_Context
= Events_Context
;
395 * The draw event hook is called by the reading API to have a
396 * particular event drawn on the screen.
397 * @param hook_data ControlFlowData structure of the viewer.
398 * @param call_data Event context.
400 * This function basically draw lines and icons. Two types of lines are drawn :
401 * one small (3 pixels?) representing the state of the process and the second
402 * type is thicker (10 pixels?) representing on which CPU a process is running
403 * (and this only in running state).
405 * Extremums of the lines :
406 * x_min : time of the last event context for this process kept in memory.
407 * x_max : time of the current event.
408 * y : middle of the process in the process list. The process is found in the
409 * list, therefore is it's position in pixels.
411 * The choice of lines'color is defined by the context of the last event for this
414 int draw_event_hook(void *hook_data
, void *call_data
)
416 EventRequest
*Event_Request
= (EventRequest
*)hook_data
;
422 int draw_after_hook(void *hook_data
, void *call_data
)
424 EventRequest
*Event_Request
= (EventRequest
*)hook_data
;
426 g_free(Event_Request
);
434 void update_time_window_hook(void *hook_data
, void *call_data
)
436 ControlFlowData
*Control_Flow_Data
= (ControlFlowData
*) hook_data
;
437 TimeWindow
* Time_Window
=
438 guicontrolflow_get_time_window(Control_Flow_Data
);
439 TimeWindow
*New_Time_Window
= ((TimeWindow
*)call_data
);
441 // As the time interval change will mostly be used for
442 // zoom in and out, it's not useful to keep old drawing
443 // sections, as scale will be changed.
446 *Time_Window
= *New_Time_Window
;
447 g_info("New time window HOOK : %u, %u to %u, %u",
448 Time_Window
->start_time
.tv_sec
,
449 Time_Window
->start_time
.tv_nsec
,
450 Time_Window
->time_width
.tv_sec
,
451 Time_Window
->time_width
.tv_nsec
);
453 drawing_data_request(Control_Flow_Data
->Drawing
,
454 &Control_Flow_Data
->Drawing
->Pixmap
,
456 Control_Flow_Data
->Drawing
->width
,
457 Control_Flow_Data
->Drawing
->height
);
459 drawing_refresh(Control_Flow_Data
->Drawing
,
461 Control_Flow_Data
->Drawing
->width
,
462 Control_Flow_Data
->Drawing
->height
);
466 void update_current_time_hook(void *hook_data
, void *call_data
)
468 ControlFlowData
*Control_Flow_Data
= (ControlFlowData
*) hook_data
;
469 LttTime
* Current_Time
=
470 guicontrolflow_get_current_time(Control_Flow_Data
);
471 *Current_Time
= *((LttTime
*)call_data
);
472 g_info("New Current time HOOK : %u, %u", Current_Time
->tv_sec
,
473 Current_Time
->tv_nsec
);
475 /* If current time is inside time interval, just move the highlight
478 /* Else, we have to change the time interval. We have to tell it
479 * to the main window. */
480 /* The time interval change will take care of placing the current
481 * time at the center of the visible area */