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 | |
1a31868c |
25 | #define MAX_PATH_LEN 256 |
26 | |
27 | //FIXME : remove this include when tests finished. |
1a31868c |
28 | #include <string.h> |
29 | |
1a31868c |
30 | void test_draw_item(Drawing_t *Drawing, |
31 | GdkPixmap *Pixmap) |
32 | { |
33 | PropertiesIcon properties_icon; |
34 | DrawContext draw_context; |
35 | |
36 | DrawInfo current, previous; |
37 | ItemInfo over, middle, under, modify_over, modify_middle, modify_under; |
38 | |
39 | int i,j; |
40 | |
41 | for(i=0; i<1024;i=i+15) |
42 | { |
43 | for(j=0;j<768;j=j+15) |
44 | { |
45 | over.x = i; |
46 | over.y = j; |
47 | over.ts = NULL; |
48 | over.tfs = NULL; |
49 | |
50 | current.modify_over = &over; |
51 | |
52 | draw_context.drawable = Pixmap; |
53 | draw_context.gc = Drawing->Drawing_Area_V->style->black_gc; |
54 | |
55 | draw_context.Current = ¤t; |
56 | draw_context.Previous = NULL; |
57 | |
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", |
61 | MAX_PATH_LEN); |
62 | properties_icon.width = -1; |
63 | properties_icon.height = -1; |
64 | properties_icon.position = OVER; |
1a31868c |
65 | draw_icon(&properties_icon, &draw_context); |
8d088fb2 |
66 | g_free(properties_icon.icon_name); |
1a31868c |
67 | } |
68 | } |
69 | |
70 | } |
f7afe191 |
71 | |
189a5d08 |
72 | /* NOTE : no drawing data should be sent there, since the drawing widget |
96cfe486 |
73 | * has not been initialized */ |
f7afe191 |
74 | void send_test_drawing(ProcessList *Process_List, |
75 | Drawing_t *Drawing, |
76 | GdkPixmap *Pixmap, |
77 | gint x, gint y, // y not used here? |
8d088fb2 |
78 | gint width, |
f7afe191 |
79 | gint height) // height won't be used here ? |
80 | { |
1a31868c |
81 | int i,j; |
f7afe191 |
82 | ProcessInfo Process_Info = {10000, 12000, 55600}; |
83 | //ProcessInfo Process_Info = {156, 14000, 55500}; |
84 | GtkTreeRowReference *got_RowRef; |
cf6cb7e0 |
85 | PangoContext *context; |
86 | PangoLayout *layout; |
87 | PangoFontDescription *FontDesc;// = pango_font_description_new(); |
88 | gint Font_Size; |
89 | |
189a5d08 |
90 | //icon |
8d088fb2 |
91 | //GdkBitmap *mask = g_new(GdkBitmap, 1); |
92 | //GdkPixmap *icon_pixmap = g_new(GdkPixmap, 1); |
93 | GdkGC * gc; |
6d5ed1c3 |
94 | // rectangle |
95 | GdkColor color = { 0, 0xffff, 0x0000, 0x0000 }; |
96 | |
8d088fb2 |
97 | //gc = gdk_gc_new(Pixmap); |
cf6cb7e0 |
98 | /* Sent text data */ |
8d088fb2 |
99 | //layout = gtk_widget_create_pango_layout(Drawing->Drawing_Area_V, |
100 | // NULL); |
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); |
cf6cb7e0 |
105 | |
f7afe191 |
106 | |
cf6cb7e0 |
107 | |
108 | |
f7afe191 |
109 | LttTime birth; |
110 | birth.tv_sec = 12000; |
111 | birth.tv_nsec = 55500; |
189a5d08 |
112 | g_info("we have : x : %u, y : %u, width : %u, height : %u", x, y, width, height); |
4c69e0cc |
113 | processlist_get_process_pixels(Process_List, |
f7afe191 |
114 | 1, |
115 | &birth, |
116 | &y, |
117 | &height); |
118 | |
189a5d08 |
119 | g_info("we draw : x : %u, y : %u, width : %u, height : %u", x, y, width, height); |
4c69e0cc |
120 | drawing_draw_line( |
f7afe191 |
121 | Drawing, Pixmap, x, |
122 | y+(height/2), x + width, y+(height/2), |
123 | Drawing->Drawing_Area_V->style->black_gc); |
124 | |
8d088fb2 |
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); |
cf6cb7e0 |
128 | |
f7afe191 |
129 | birth.tv_sec = 14000; |
130 | birth.tv_nsec = 55500; |
131 | |
4c69e0cc |
132 | processlist_get_process_pixels(Process_List, |
f7afe191 |
133 | 156, |
134 | &birth, |
135 | &y, |
136 | &height); |
137 | |
138 | |
4c69e0cc |
139 | drawing_draw_line( |
f7afe191 |
140 | Drawing, Pixmap, x, |
141 | y+(height/2), x + width, y+(height/2), |
142 | Drawing->Drawing_Area_V->style->black_gc); |
143 | |
189a5d08 |
144 | g_info("y : %u, height : %u", y, height); |
f7afe191 |
145 | |
6d5ed1c3 |
146 | |
147 | |
f7afe191 |
148 | birth.tv_sec = 12000; |
149 | birth.tv_nsec = 55700; |
150 | |
4c69e0cc |
151 | processlist_get_process_pixels(Process_List, |
f7afe191 |
152 | 10, |
153 | &birth, |
154 | &y, |
155 | &height); |
6d5ed1c3 |
156 | |
157 | /* Draw rectangle (background color) */ |
8d088fb2 |
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, |
161 | // TRUE, |
162 | // x, y, width, height); |
f7afe191 |
163 | |
4c69e0cc |
164 | drawing_draw_line( |
f7afe191 |
165 | Drawing, Pixmap, x, |
166 | y+(height/2), x + width, y+(height/2), |
167 | Drawing->Drawing_Area_V->style->black_gc); |
168 | |
6d5ed1c3 |
169 | |
170 | /* Draw arc */ |
171 | gdk_draw_arc(Pixmap, Drawing->Drawing_Area_V->style->black_gc, |
2f9f7ee0 |
172 | TRUE, 100, y, height/2, height/2, 0, 360*64); |
6d5ed1c3 |
173 | |
189a5d08 |
174 | g_info("y : %u, height : %u", y, height); |
f7afe191 |
175 | |
176 | for(i=0; i<10; i++) |
177 | { |
178 | birth.tv_sec = i*12000; |
179 | birth.tv_nsec = i*55700; |
180 | |
4c69e0cc |
181 | processlist_get_process_pixels(Process_List, |
f7afe191 |
182 | i, |
183 | &birth, |
184 | &y, |
185 | &height); |
186 | |
187 | |
4c69e0cc |
188 | drawing_draw_line( |
f7afe191 |
189 | Drawing, Pixmap, x, |
190 | y+(height/2), x + width, y+(height/2), |
191 | Drawing->Drawing_Area_V->style->black_gc); |
192 | |
193 | g_critical("y : %u, height : %u", y, height); |
194 | |
195 | } |
196 | |
197 | birth.tv_sec = 12000; |
198 | birth.tv_nsec = 55600; |
199 | |
4c69e0cc |
200 | processlist_get_process_pixels(Process_List, |
f7afe191 |
201 | 10, |
202 | &birth, |
203 | &y, |
204 | &height); |
205 | |
206 | |
4c69e0cc |
207 | drawing_draw_line( |
f7afe191 |
208 | Drawing, Pixmap, x, |
209 | y+(height/2), x + width, y+(height/2), |
210 | Drawing->Drawing_Area_V->style->black_gc); |
211 | |
189a5d08 |
212 | g_info("y : %u, height : %u", y, height); |
1a31868c |
213 | |
214 | |
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"); |
219 | |
220 | // gdk_gc_set_clip_mask(Drawing->Drawing_Area_V->style->black_gc, mask); |
221 | |
222 | // for(i=x;i<x+width;i=i+15) |
223 | // { |
224 | // for(j=0;j<height*20;j=j+15) |
225 | // { |
226 | |
227 | /* Draw icon */ |
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, |
232 | // icon_pixmap, |
233 | // 0, 0, i, j, -1, -1); |
234 | |
235 | // } |
236 | // } |
8d088fb2 |
237 | |
1a31868c |
238 | test_draw_item(Drawing,Pixmap); |
239 | |
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); |
242 | |
243 | //g_free(icon_pixmap); |
244 | //g_free(mask); |
245 | |
246 | |
247 | |
248 | |
cf6cb7e0 |
249 | |
250 | |
8d088fb2 |
251 | //pango_font_description_set_size(FontDesc, Font_Size); |
252 | //g_object_unref(layout); |
253 | //g_object_unref(gc); |
f7afe191 |
254 | } |
255 | |
256 | void send_test_process(ProcessList *Process_List, Drawing_t *Drawing) |
5f16133f |
257 | { |
f7afe191 |
258 | guint height, y; |
5f16133f |
259 | int i; |
260 | ProcessInfo Process_Info = {10000, 12000, 55600}; |
261 | //ProcessInfo Process_Info = {156, 14000, 55500}; |
262 | GtkTreeRowReference *got_RowRef; |
263 | |
264 | LttTime birth; |
f7afe191 |
265 | |
266 | if(Process_List->Test_Process_Sent) return; |
267 | |
5f16133f |
268 | birth.tv_sec = 12000; |
269 | birth.tv_nsec = 55500; |
270 | |
4c69e0cc |
271 | processlist_add(Process_List, |
5f16133f |
272 | 1, |
273 | &birth, |
f7afe191 |
274 | &y); |
4c69e0cc |
275 | processlist_get_process_pixels(Process_List, |
f7afe191 |
276 | 1, |
277 | &birth, |
278 | &y, |
279 | &height); |
4c69e0cc |
280 | drawing_insert_square( Drawing, y, height); |
1ab3d149 |
281 | |
f7afe191 |
282 | //g_critical("y : %u, height : %u", y, height); |
5f16133f |
283 | |
284 | birth.tv_sec = 14000; |
285 | birth.tv_nsec = 55500; |
286 | |
4c69e0cc |
287 | processlist_add(Process_List, |
5f16133f |
288 | 156, |
289 | &birth, |
f7afe191 |
290 | &y); |
4c69e0cc |
291 | processlist_get_process_pixels(Process_List, |
f7afe191 |
292 | 156, |
293 | &birth, |
294 | &y, |
295 | &height); |
4c69e0cc |
296 | drawing_insert_square( Drawing, y, height); |
f7afe191 |
297 | |
298 | //g_critical("y : %u, height : %u", y, height); |
299 | |
5f16133f |
300 | birth.tv_sec = 12000; |
301 | birth.tv_nsec = 55700; |
302 | |
4c69e0cc |
303 | processlist_add(Process_List, |
5f16133f |
304 | 10, |
305 | &birth, |
306 | &height); |
4c69e0cc |
307 | processlist_get_process_pixels(Process_List, |
f7afe191 |
308 | 10, |
309 | &birth, |
310 | &y, |
311 | &height); |
4c69e0cc |
312 | drawing_insert_square( Drawing, y, height); |
f7afe191 |
313 | |
314 | //g_critical("y : %u, height : %u", y, height); |
315 | |
4c69e0cc |
316 | //drawing_insert_square( Drawing, height, 5); |
5f16133f |
317 | |
318 | for(i=0; i<10; i++) |
319 | { |
320 | birth.tv_sec = i*12000; |
321 | birth.tv_nsec = i*55700; |
322 | |
4c69e0cc |
323 | processlist_add(Process_List, |
5f16133f |
324 | i, |
325 | &birth, |
326 | &height); |
4c69e0cc |
327 | processlist_get_process_pixels(Process_List, |
f7afe191 |
328 | i, |
329 | &birth, |
330 | &y, |
331 | &height); |
4c69e0cc |
332 | drawing_insert_square( Drawing, y, height); |
f7afe191 |
333 | |
334 | // g_critical("y : %u, height : %u", y, height); |
335 | |
5f16133f |
336 | } |
f7afe191 |
337 | //g_critical("height : %u", height); |
5f16133f |
338 | |
339 | birth.tv_sec = 12000; |
340 | birth.tv_nsec = 55600; |
341 | |
4c69e0cc |
342 | processlist_add(Process_List, |
5f16133f |
343 | 10, |
344 | &birth, |
f7afe191 |
345 | &y); |
4c69e0cc |
346 | processlist_get_process_pixels(Process_List, |
f7afe191 |
347 | 10, |
348 | &birth, |
349 | &y, |
350 | &height); |
4c69e0cc |
351 | drawing_insert_square( Drawing, y, height); |
f7afe191 |
352 | |
353 | //g_critical("y : %u, height : %u", y, height); |
354 | |
4c69e0cc |
355 | processlist_add(Process_List, |
5f16133f |
356 | 10000, |
357 | &birth, |
358 | &height); |
4c69e0cc |
359 | processlist_get_process_pixels(Process_List, |
f7afe191 |
360 | 10000, |
361 | &birth, |
362 | &y, |
363 | &height); |
4c69e0cc |
364 | drawing_insert_square( Drawing, y, height); |
f7afe191 |
365 | |
366 | //g_critical("y : %u, height : %u", y, height); |
367 | |
4c69e0cc |
368 | //drawing_insert_square( Drawing, height, 5); |
f7afe191 |
369 | //g_critical("height : %u", height); |
5f16133f |
370 | |
371 | |
4c69e0cc |
372 | processlist_get_process_pixels(Process_List, |
1ab3d149 |
373 | 10000, |
374 | &birth, |
f7afe191 |
375 | &y, &height); |
4c69e0cc |
376 | processlist_remove( Process_List, |
5f16133f |
377 | 10000, |
378 | &birth); |
1ab3d149 |
379 | |
4c69e0cc |
380 | drawing_remove_square( Drawing, y, height); |
5f16133f |
381 | |
382 | if(got_RowRef = |
383 | (GtkTreeRowReference*)g_hash_table_lookup( |
384 | Process_List->Process_Hash, |
385 | &Process_Info)) |
386 | { |
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) |
392 | )); |
393 | |
394 | } |
395 | |
f7afe191 |
396 | Process_List->Test_Process_Sent = TRUE; |
397 | |
5f16133f |
398 | } |
399 | |
400 | |
f0d936c0 |
401 | |
402 | /** |
403 | * Event Viewer's constructor hook |
404 | * |
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. |
409 | */ |
410 | GtkWidget * |
4c69e0cc |
411 | h_guicontrolflow(MainWindow *pmParentWindow, LttvTracesetSelector * s, char * key) |
f0d936c0 |
412 | { |
189a5d08 |
413 | g_info("h_guicontrolflow, %p, %p, %s", pmParentWindow, s, key); |
4c69e0cc |
414 | ControlFlowData *Control_Flow_Data = guicontrolflow() ; |
189a5d08 |
415 | |
416 | Control_Flow_Data->Parent_Window = pmParentWindow; |
f0d936c0 |
417 | |
41a76985 |
418 | get_time_window(pmParentWindow, |
cb1686f6 |
419 | guicontrolflow_get_time_window(Control_Flow_Data)); |
41a76985 |
420 | get_current_time(pmParentWindow, |
cb1686f6 |
421 | guicontrolflow_get_current_time(Control_Flow_Data)); |
f7afe191 |
422 | |
423 | // Unreg done in the GuiControlFlow_Destructor |
3cff8cc1 |
424 | reg_update_time_window(update_time_window_hook, Control_Flow_Data, |
f7afe191 |
425 | pmParentWindow); |
3cff8cc1 |
426 | reg_update_current_time(update_current_time_hook, Control_Flow_Data, |
f7afe191 |
427 | pmParentWindow); |
3cff8cc1 |
428 | return guicontrolflow_get_widget(Control_Flow_Data) ; |
f0d936c0 |
429 | |
430 | } |
431 | |
3cff8cc1 |
432 | int event_selected_hook(void *hook_data, void *call_data) |
f0d936c0 |
433 | { |
434 | ControlFlowData *Control_Flow_Data = (ControlFlowData*) hook_data; |
435 | guint *Event_Number = (guint*) call_data; |
436 | |
437 | g_critical("DEBUG : event selected by main window : %u", *Event_Number); |
438 | |
439 | // Control_Flow_Data->Currently_Selected_Event = *Event_Number; |
440 | // Control_Flow_Data->Selected_Event = TRUE ; |
441 | |
4c69e0cc |
442 | // tree_v_set_cursor(Control_Flow_Data); |
f0d936c0 |
443 | |
444 | } |
445 | |
558aa013 |
446 | #ifdef DEBUG |
f0d936c0 |
447 | /* Hook called before drawing. Gets the initial context at the beginning of the |
448 | * drawing interval and copy it to the context in Event_Request. |
449 | */ |
4c69e0cc |
450 | int draw_before_hook(void *hook_data, void *call_data) |
f0d936c0 |
451 | { |
452 | EventRequest *Event_Request = (EventRequest*)hook_data; |
453 | EventsContext Events_Context = (EventsContext*)call_data; |
454 | |
455 | Event_Request->Events_Context = Events_Context; |
456 | |
457 | return 0; |
458 | } |
459 | |
460 | /* |
461 | * The draw event hook is called by the reading API to have a |
462 | * particular event drawn on the screen. |
463 | * @param hook_data ControlFlowData structure of the viewer. |
464 | * @param call_data Event context. |
465 | * |
466 | * This function basically draw lines and icons. Two types of lines are drawn : |
467 | * one small (3 pixels?) representing the state of the process and the second |
468 | * type is thicker (10 pixels?) representing on which CPU a process is running |
469 | * (and this only in running state). |
470 | * |
471 | * Extremums of the lines : |
472 | * x_min : time of the last event context for this process kept in memory. |
473 | * x_max : time of the current event. |
474 | * y : middle of the process in the process list. The process is found in the |
475 | * list, therefore is it's position in pixels. |
476 | * |
477 | * The choice of lines'color is defined by the context of the last event for this |
478 | * process. |
479 | */ |
4c69e0cc |
480 | int draw_event_hook(void *hook_data, void *call_data) |
f0d936c0 |
481 | { |
482 | EventRequest *Event_Request = (EventRequest*)hook_data; |
483 | |
484 | return 0; |
485 | } |
486 | |
487 | |
4c69e0cc |
488 | int draw_after_hook(void *hook_data, void *call_data) |
f0d936c0 |
489 | { |
490 | EventRequest *Event_Request = (EventRequest*)hook_data; |
491 | |
492 | g_free(Event_Request); |
493 | return 0; |
494 | } |
558aa013 |
495 | #endif |
f7afe191 |
496 | |
497 | |
498 | |
499 | |
4c69e0cc |
500 | void update_time_window_hook(void *hook_data, void *call_data) |
f7afe191 |
501 | { |
502 | ControlFlowData *Control_Flow_Data = (ControlFlowData*) hook_data; |
503 | TimeWindow* Time_Window = |
3cff8cc1 |
504 | guicontrolflow_get_time_window(Control_Flow_Data); |
f7afe191 |
505 | TimeWindow *New_Time_Window = ((TimeWindow*)call_data); |
506 | |
507 | // As the time interval change will mostly be used for |
508 | // zoom in and out, it's not useful to keep old drawing |
509 | // sections, as scale will be changed. |
510 | |
511 | |
512 | *Time_Window = *New_Time_Window; |
189a5d08 |
513 | g_info("New time window HOOK : %u, %u to %u, %u", |
bca3b81f |
514 | Time_Window->start_time.tv_sec, |
515 | Time_Window->start_time.tv_nsec, |
516 | Time_Window->time_width.tv_sec, |
517 | Time_Window->time_width.tv_nsec); |
f7afe191 |
518 | |
6d5ed1c3 |
519 | drawing_data_request(Control_Flow_Data->Drawing, |
f7afe191 |
520 | &Control_Flow_Data->Drawing->Pixmap, |
521 | 0, 0, |
522 | Control_Flow_Data->Drawing->width, |
523 | Control_Flow_Data->Drawing->height); |
524 | |
4c69e0cc |
525 | drawing_refresh(Control_Flow_Data->Drawing, |
f7afe191 |
526 | 0, 0, |
527 | Control_Flow_Data->Drawing->width, |
528 | Control_Flow_Data->Drawing->height); |
529 | |
530 | } |
531 | |
4c69e0cc |
532 | void update_current_time_hook(void *hook_data, void *call_data) |
f7afe191 |
533 | { |
534 | ControlFlowData *Control_Flow_Data = (ControlFlowData*) hook_data; |
535 | LttTime* Current_Time = |
4c69e0cc |
536 | guicontrolflow_get_current_time(Control_Flow_Data); |
f7afe191 |
537 | *Current_Time = *((LttTime*)call_data); |
189a5d08 |
538 | g_info("New Current time HOOK : %u, %u", Current_Time->tv_sec, |
f7afe191 |
539 | Current_Time->tv_nsec); |
540 | |
541 | /* If current time is inside time interval, just move the highlight |
542 | * bar */ |
543 | |
544 | /* Else, we have to change the time interval. We have to tell it |
545 | * to the main window. */ |
546 | /* The time interval change will take care of placing the current |
547 | * time at the center of the visible area */ |
548 | |
549 | } |
550 | |