f0d936c0 |
1 | /***************************************************************************** |
2 | * Hooks to be called by the main window * |
3 | *****************************************************************************/ |
4 | |
f0d936c0 |
5 | |
189a5d08 |
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) |
8 | |
cf6cb7e0 |
9 | //#define PANGO_ENABLE_BACKEND |
558aa013 |
10 | #include <gtk/gtk.h> |
11 | #include <gdk/gdk.h> |
5f16133f |
12 | #include <glib.h> |
13 | |
cf6cb7e0 |
14 | //#include <pango/pango.h> |
15 | |
558aa013 |
16 | #include <lttv/hook.h> |
17 | #include <lttv/common.h> |
f0d936c0 |
18 | |
1ab818de |
19 | #include "Event_Hooks.h" |
f0d936c0 |
20 | #include "CFV.h" |
5f16133f |
21 | #include "Process_List.h" |
1ab3d149 |
22 | #include "Drawing.h" |
f7afe191 |
23 | #include "CFV-private.h" |
5f16133f |
24 | |
f7afe191 |
25 | |
189a5d08 |
26 | /* NOTE : no drawing data should be sent there, since the drawing widget |
96cfe486 |
27 | * has not been initialized */ |
f7afe191 |
28 | void send_test_drawing(ProcessList *Process_List, |
29 | Drawing_t *Drawing, |
30 | GdkPixmap *Pixmap, |
31 | gint x, gint y, // y not used here? |
32 | gint width, |
33 | gint height) // height won't be used here ? |
34 | { |
35 | int i; |
36 | ProcessInfo Process_Info = {10000, 12000, 55600}; |
37 | //ProcessInfo Process_Info = {156, 14000, 55500}; |
38 | GtkTreeRowReference *got_RowRef; |
cf6cb7e0 |
39 | PangoContext *context; |
40 | PangoLayout *layout; |
41 | PangoFontDescription *FontDesc;// = pango_font_description_new(); |
42 | gint Font_Size; |
43 | |
189a5d08 |
44 | //icon |
45 | GdkBitmap *mask = g_new(GdkBitmap, 1); |
46 | GdkPixmap *icon_pixmap = g_new(GdkPixmap, 1); |
47 | GdkGC * gc = gdk_gc_new(Pixmap); |
48 | |
6d5ed1c3 |
49 | // rectangle |
50 | GdkColor color = { 0, 0xffff, 0x0000, 0x0000 }; |
51 | |
cf6cb7e0 |
52 | /* Sent text data */ |
53 | layout = gtk_widget_create_pango_layout(Drawing->Drawing_Area_V, |
54 | NULL); |
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); |
59 | |
f7afe191 |
60 | |
cf6cb7e0 |
61 | |
62 | |
f7afe191 |
63 | LttTime birth; |
64 | birth.tv_sec = 12000; |
65 | birth.tv_nsec = 55500; |
189a5d08 |
66 | g_info("we have : x : %u, y : %u, width : %u, height : %u", x, y, width, height); |
4c69e0cc |
67 | processlist_get_process_pixels(Process_List, |
f7afe191 |
68 | 1, |
69 | &birth, |
70 | &y, |
71 | &height); |
72 | |
189a5d08 |
73 | g_info("we draw : x : %u, y : %u, width : %u, height : %u", x, y, width, height); |
4c69e0cc |
74 | drawing_draw_line( |
f7afe191 |
75 | Drawing, Pixmap, x, |
76 | y+(height/2), x + width, y+(height/2), |
77 | Drawing->Drawing_Area_V->style->black_gc); |
78 | |
cf6cb7e0 |
79 | pango_layout_set_text(layout, "Test", -1); |
80 | gdk_draw_layout(Pixmap, Drawing->Drawing_Area_V->style->black_gc, |
81 | 0, y+height, layout); |
82 | |
f7afe191 |
83 | birth.tv_sec = 14000; |
84 | birth.tv_nsec = 55500; |
85 | |
4c69e0cc |
86 | processlist_get_process_pixels(Process_List, |
f7afe191 |
87 | 156, |
88 | &birth, |
89 | &y, |
90 | &height); |
91 | |
92 | |
4c69e0cc |
93 | drawing_draw_line( |
f7afe191 |
94 | Drawing, Pixmap, x, |
95 | y+(height/2), x + width, y+(height/2), |
96 | Drawing->Drawing_Area_V->style->black_gc); |
97 | |
189a5d08 |
98 | |
99 | /* Draw icon */ |
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, |
106 | gc, |
107 | icon_pixmap, |
108 | 0, 0, 0, 0, -1, -1); |
109 | |
110 | g_free(icon_pixmap); |
111 | g_free(mask); |
189a5d08 |
112 | |
113 | g_info("y : %u, height : %u", y, height); |
f7afe191 |
114 | |
6d5ed1c3 |
115 | |
116 | |
f7afe191 |
117 | birth.tv_sec = 12000; |
118 | birth.tv_nsec = 55700; |
119 | |
4c69e0cc |
120 | processlist_get_process_pixels(Process_List, |
f7afe191 |
121 | 10, |
122 | &birth, |
123 | &y, |
124 | &height); |
6d5ed1c3 |
125 | |
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, |
130 | TRUE, |
131 | x, y, width, height); |
f7afe191 |
132 | |
4c69e0cc |
133 | drawing_draw_line( |
f7afe191 |
134 | Drawing, Pixmap, x, |
135 | y+(height/2), x + width, y+(height/2), |
136 | Drawing->Drawing_Area_V->style->black_gc); |
137 | |
6d5ed1c3 |
138 | |
139 | /* Draw arc */ |
140 | gdk_draw_arc(Pixmap, Drawing->Drawing_Area_V->style->black_gc, |
141 | TRUE, 100, y, 5, 5, 0, 360*64); |
142 | |
189a5d08 |
143 | g_info("y : %u, height : %u", y, height); |
f7afe191 |
144 | |
145 | for(i=0; i<10; i++) |
146 | { |
147 | birth.tv_sec = i*12000; |
148 | birth.tv_nsec = i*55700; |
149 | |
4c69e0cc |
150 | processlist_get_process_pixels(Process_List, |
f7afe191 |
151 | i, |
152 | &birth, |
153 | &y, |
154 | &height); |
155 | |
156 | |
4c69e0cc |
157 | drawing_draw_line( |
f7afe191 |
158 | Drawing, Pixmap, x, |
159 | y+(height/2), x + width, y+(height/2), |
160 | Drawing->Drawing_Area_V->style->black_gc); |
161 | |
162 | g_critical("y : %u, height : %u", y, height); |
163 | |
164 | } |
165 | |
166 | birth.tv_sec = 12000; |
167 | birth.tv_nsec = 55600; |
168 | |
4c69e0cc |
169 | processlist_get_process_pixels(Process_List, |
f7afe191 |
170 | 10, |
171 | &birth, |
172 | &y, |
173 | &height); |
174 | |
175 | |
4c69e0cc |
176 | drawing_draw_line( |
f7afe191 |
177 | Drawing, Pixmap, x, |
178 | y+(height/2), x + width, y+(height/2), |
179 | Drawing->Drawing_Area_V->style->black_gc); |
180 | |
189a5d08 |
181 | g_info("y : %u, height : %u", y, height); |
cf6cb7e0 |
182 | |
183 | |
184 | pango_font_description_set_size(FontDesc, Font_Size); |
6d5ed1c3 |
185 | g_free(gc); |
cf6cb7e0 |
186 | g_free(layout); |
187 | //g_free(context); |
f7afe191 |
188 | } |
189 | |
190 | void send_test_process(ProcessList *Process_List, Drawing_t *Drawing) |
5f16133f |
191 | { |
f7afe191 |
192 | guint height, y; |
5f16133f |
193 | int i; |
194 | ProcessInfo Process_Info = {10000, 12000, 55600}; |
195 | //ProcessInfo Process_Info = {156, 14000, 55500}; |
196 | GtkTreeRowReference *got_RowRef; |
197 | |
198 | LttTime birth; |
f7afe191 |
199 | |
200 | if(Process_List->Test_Process_Sent) return; |
201 | |
5f16133f |
202 | birth.tv_sec = 12000; |
203 | birth.tv_nsec = 55500; |
204 | |
4c69e0cc |
205 | processlist_add(Process_List, |
5f16133f |
206 | 1, |
207 | &birth, |
f7afe191 |
208 | &y); |
4c69e0cc |
209 | processlist_get_process_pixels(Process_List, |
f7afe191 |
210 | 1, |
211 | &birth, |
212 | &y, |
213 | &height); |
4c69e0cc |
214 | drawing_insert_square( Drawing, y, height); |
1ab3d149 |
215 | |
f7afe191 |
216 | //g_critical("y : %u, height : %u", y, height); |
5f16133f |
217 | |
218 | birth.tv_sec = 14000; |
219 | birth.tv_nsec = 55500; |
220 | |
4c69e0cc |
221 | processlist_add(Process_List, |
5f16133f |
222 | 156, |
223 | &birth, |
f7afe191 |
224 | &y); |
4c69e0cc |
225 | processlist_get_process_pixels(Process_List, |
f7afe191 |
226 | 156, |
227 | &birth, |
228 | &y, |
229 | &height); |
4c69e0cc |
230 | drawing_insert_square( Drawing, y, height); |
f7afe191 |
231 | |
232 | //g_critical("y : %u, height : %u", y, height); |
233 | |
5f16133f |
234 | birth.tv_sec = 12000; |
235 | birth.tv_nsec = 55700; |
236 | |
4c69e0cc |
237 | processlist_add(Process_List, |
5f16133f |
238 | 10, |
239 | &birth, |
240 | &height); |
4c69e0cc |
241 | processlist_get_process_pixels(Process_List, |
f7afe191 |
242 | 10, |
243 | &birth, |
244 | &y, |
245 | &height); |
4c69e0cc |
246 | drawing_insert_square( Drawing, y, height); |
f7afe191 |
247 | |
248 | //g_critical("y : %u, height : %u", y, height); |
249 | |
4c69e0cc |
250 | //drawing_insert_square( Drawing, height, 5); |
5f16133f |
251 | |
252 | for(i=0; i<10; i++) |
253 | { |
254 | birth.tv_sec = i*12000; |
255 | birth.tv_nsec = i*55700; |
256 | |
4c69e0cc |
257 | processlist_add(Process_List, |
5f16133f |
258 | i, |
259 | &birth, |
260 | &height); |
4c69e0cc |
261 | processlist_get_process_pixels(Process_List, |
f7afe191 |
262 | i, |
263 | &birth, |
264 | &y, |
265 | &height); |
4c69e0cc |
266 | drawing_insert_square( Drawing, y, height); |
f7afe191 |
267 | |
268 | // g_critical("y : %u, height : %u", y, height); |
269 | |
5f16133f |
270 | } |
f7afe191 |
271 | //g_critical("height : %u", height); |
5f16133f |
272 | |
273 | birth.tv_sec = 12000; |
274 | birth.tv_nsec = 55600; |
275 | |
4c69e0cc |
276 | processlist_add(Process_List, |
5f16133f |
277 | 10, |
278 | &birth, |
f7afe191 |
279 | &y); |
4c69e0cc |
280 | processlist_get_process_pixels(Process_List, |
f7afe191 |
281 | 10, |
282 | &birth, |
283 | &y, |
284 | &height); |
4c69e0cc |
285 | drawing_insert_square( Drawing, y, height); |
f7afe191 |
286 | |
287 | //g_critical("y : %u, height : %u", y, height); |
288 | |
4c69e0cc |
289 | processlist_add(Process_List, |
5f16133f |
290 | 10000, |
291 | &birth, |
292 | &height); |
4c69e0cc |
293 | processlist_get_process_pixels(Process_List, |
f7afe191 |
294 | 10000, |
295 | &birth, |
296 | &y, |
297 | &height); |
4c69e0cc |
298 | drawing_insert_square( Drawing, y, height); |
f7afe191 |
299 | |
300 | //g_critical("y : %u, height : %u", y, height); |
301 | |
4c69e0cc |
302 | //drawing_insert_square( Drawing, height, 5); |
f7afe191 |
303 | //g_critical("height : %u", height); |
5f16133f |
304 | |
305 | |
4c69e0cc |
306 | processlist_get_process_pixels(Process_List, |
1ab3d149 |
307 | 10000, |
308 | &birth, |
f7afe191 |
309 | &y, &height); |
4c69e0cc |
310 | processlist_remove( Process_List, |
5f16133f |
311 | 10000, |
312 | &birth); |
1ab3d149 |
313 | |
4c69e0cc |
314 | drawing_remove_square( Drawing, y, height); |
5f16133f |
315 | |
316 | if(got_RowRef = |
317 | (GtkTreeRowReference*)g_hash_table_lookup( |
318 | Process_List->Process_Hash, |
319 | &Process_Info)) |
320 | { |
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) |
326 | )); |
327 | |
328 | } |
329 | |
f7afe191 |
330 | Process_List->Test_Process_Sent = TRUE; |
331 | |
5f16133f |
332 | } |
333 | |
334 | |
f0d936c0 |
335 | |
336 | /** |
337 | * Event Viewer's constructor hook |
338 | * |
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. |
343 | */ |
344 | GtkWidget * |
4c69e0cc |
345 | h_guicontrolflow(MainWindow *pmParentWindow, LttvTracesetSelector * s, char * key) |
f0d936c0 |
346 | { |
189a5d08 |
347 | g_info("h_guicontrolflow, %p, %p, %s", pmParentWindow, s, key); |
4c69e0cc |
348 | ControlFlowData *Control_Flow_Data = guicontrolflow() ; |
189a5d08 |
349 | |
350 | Control_Flow_Data->Parent_Window = pmParentWindow; |
f0d936c0 |
351 | |
41a76985 |
352 | get_time_window(pmParentWindow, |
cb1686f6 |
353 | guicontrolflow_get_time_window(Control_Flow_Data)); |
41a76985 |
354 | get_current_time(pmParentWindow, |
cb1686f6 |
355 | guicontrolflow_get_current_time(Control_Flow_Data)); |
f7afe191 |
356 | |
357 | // Unreg done in the GuiControlFlow_Destructor |
3cff8cc1 |
358 | reg_update_time_window(update_time_window_hook, Control_Flow_Data, |
f7afe191 |
359 | pmParentWindow); |
3cff8cc1 |
360 | reg_update_current_time(update_current_time_hook, Control_Flow_Data, |
f7afe191 |
361 | pmParentWindow); |
3cff8cc1 |
362 | return guicontrolflow_get_widget(Control_Flow_Data) ; |
f0d936c0 |
363 | |
364 | } |
365 | |
3cff8cc1 |
366 | int event_selected_hook(void *hook_data, void *call_data) |
f0d936c0 |
367 | { |
368 | ControlFlowData *Control_Flow_Data = (ControlFlowData*) hook_data; |
369 | guint *Event_Number = (guint*) call_data; |
370 | |
371 | g_critical("DEBUG : event selected by main window : %u", *Event_Number); |
372 | |
373 | // Control_Flow_Data->Currently_Selected_Event = *Event_Number; |
374 | // Control_Flow_Data->Selected_Event = TRUE ; |
375 | |
4c69e0cc |
376 | // tree_v_set_cursor(Control_Flow_Data); |
f0d936c0 |
377 | |
378 | } |
379 | |
558aa013 |
380 | #ifdef DEBUG |
f0d936c0 |
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. |
383 | */ |
4c69e0cc |
384 | int draw_before_hook(void *hook_data, void *call_data) |
f0d936c0 |
385 | { |
386 | EventRequest *Event_Request = (EventRequest*)hook_data; |
387 | EventsContext Events_Context = (EventsContext*)call_data; |
388 | |
389 | Event_Request->Events_Context = Events_Context; |
390 | |
391 | return 0; |
392 | } |
393 | |
394 | /* |
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. |
399 | * |
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). |
404 | * |
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. |
410 | * |
411 | * The choice of lines'color is defined by the context of the last event for this |
412 | * process. |
413 | */ |
4c69e0cc |
414 | int draw_event_hook(void *hook_data, void *call_data) |
f0d936c0 |
415 | { |
416 | EventRequest *Event_Request = (EventRequest*)hook_data; |
417 | |
418 | return 0; |
419 | } |
420 | |
421 | |
4c69e0cc |
422 | int draw_after_hook(void *hook_data, void *call_data) |
f0d936c0 |
423 | { |
424 | EventRequest *Event_Request = (EventRequest*)hook_data; |
425 | |
426 | g_free(Event_Request); |
427 | return 0; |
428 | } |
558aa013 |
429 | #endif |
f7afe191 |
430 | |
431 | |
432 | |
433 | |
4c69e0cc |
434 | void update_time_window_hook(void *hook_data, void *call_data) |
f7afe191 |
435 | { |
436 | ControlFlowData *Control_Flow_Data = (ControlFlowData*) hook_data; |
437 | TimeWindow* Time_Window = |
3cff8cc1 |
438 | guicontrolflow_get_time_window(Control_Flow_Data); |
f7afe191 |
439 | TimeWindow *New_Time_Window = ((TimeWindow*)call_data); |
440 | |
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. |
444 | |
445 | |
446 | *Time_Window = *New_Time_Window; |
189a5d08 |
447 | g_info("New time window HOOK : %u, %u to %u, %u", |
bca3b81f |
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); |
f7afe191 |
452 | |
6d5ed1c3 |
453 | drawing_data_request(Control_Flow_Data->Drawing, |
f7afe191 |
454 | &Control_Flow_Data->Drawing->Pixmap, |
455 | 0, 0, |
456 | Control_Flow_Data->Drawing->width, |
457 | Control_Flow_Data->Drawing->height); |
458 | |
4c69e0cc |
459 | drawing_refresh(Control_Flow_Data->Drawing, |
f7afe191 |
460 | 0, 0, |
461 | Control_Flow_Data->Drawing->width, |
462 | Control_Flow_Data->Drawing->height); |
463 | |
464 | } |
465 | |
4c69e0cc |
466 | void update_current_time_hook(void *hook_data, void *call_data) |
f7afe191 |
467 | { |
468 | ControlFlowData *Control_Flow_Data = (ControlFlowData*) hook_data; |
469 | LttTime* Current_Time = |
4c69e0cc |
470 | guicontrolflow_get_current_time(Control_Flow_Data); |
f7afe191 |
471 | *Current_Time = *((LttTime*)call_data); |
189a5d08 |
472 | g_info("New Current time HOOK : %u, %u", Current_Time->tv_sec, |
f7afe191 |
473 | Current_Time->tv_nsec); |
474 | |
475 | /* If current time is inside time interval, just move the highlight |
476 | * bar */ |
477 | |
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 */ |
482 | |
483 | } |
484 | |