f0d936c0 |
1 | /***************************************************************************** |
2 | * Hooks to be called by the main window * |
3 | *****************************************************************************/ |
4 | |
f0d936c0 |
5 | |
cf6cb7e0 |
6 | //#define PANGO_ENABLE_BACKEND |
558aa013 |
7 | #include <gtk/gtk.h> |
8 | #include <gdk/gdk.h> |
5f16133f |
9 | #include <glib.h> |
10 | |
cf6cb7e0 |
11 | //#include <pango/pango.h> |
12 | |
558aa013 |
13 | #include <lttv/hook.h> |
14 | #include <lttv/common.h> |
f0d936c0 |
15 | |
1ab818de |
16 | #include "Event_Hooks.h" |
f0d936c0 |
17 | #include "CFV.h" |
5f16133f |
18 | #include "Process_List.h" |
1ab3d149 |
19 | #include "Drawing.h" |
f7afe191 |
20 | #include "CFV-private.h" |
5f16133f |
21 | |
f7afe191 |
22 | |
23 | /* NOTE : no drawing data should be sent there, as the drawing widget |
96cfe486 |
24 | * has not been initialized */ |
f7afe191 |
25 | void send_test_drawing(ProcessList *Process_List, |
26 | Drawing_t *Drawing, |
27 | GdkPixmap *Pixmap, |
28 | gint x, gint y, // y not used here? |
29 | gint width, |
30 | gint height) // height won't be used here ? |
31 | { |
32 | int i; |
33 | ProcessInfo Process_Info = {10000, 12000, 55600}; |
34 | //ProcessInfo Process_Info = {156, 14000, 55500}; |
35 | GtkTreeRowReference *got_RowRef; |
cf6cb7e0 |
36 | PangoContext *context; |
37 | PangoLayout *layout; |
38 | PangoFontDescription *FontDesc;// = pango_font_description_new(); |
39 | gint Font_Size; |
40 | |
41 | /* Sent text data */ |
42 | layout = gtk_widget_create_pango_layout(Drawing->Drawing_Area_V, |
43 | NULL); |
44 | context = pango_layout_get_context(layout); |
45 | FontDesc = pango_context_get_font_description(context); |
46 | Font_Size = pango_font_description_get_size(FontDesc); |
47 | pango_font_description_set_size(FontDesc, Font_Size-3*PANGO_SCALE); |
48 | |
f7afe191 |
49 | |
cf6cb7e0 |
50 | |
51 | |
f7afe191 |
52 | LttTime birth; |
53 | birth.tv_sec = 12000; |
54 | birth.tv_nsec = 55500; |
55 | g_critical("we have : x : %u, y : %u, width : %u, height : %u", x, y, width, height); |
56 | ProcessList_get_process_pixels(Process_List, |
57 | 1, |
58 | &birth, |
59 | &y, |
60 | &height); |
61 | |
62 | g_critical("we draw : x : %u, y : %u, width : %u, height : %u", x, y, width, height); |
63 | Drawing_draw_line( |
64 | Drawing, Pixmap, x, |
65 | y+(height/2), x + width, y+(height/2), |
66 | Drawing->Drawing_Area_V->style->black_gc); |
67 | |
cf6cb7e0 |
68 | pango_layout_set_text(layout, "Test", -1); |
69 | gdk_draw_layout(Pixmap, Drawing->Drawing_Area_V->style->black_gc, |
70 | 0, y+height, layout); |
71 | |
f7afe191 |
72 | birth.tv_sec = 14000; |
73 | birth.tv_nsec = 55500; |
74 | |
75 | ProcessList_get_process_pixels(Process_List, |
76 | 156, |
77 | &birth, |
78 | &y, |
79 | &height); |
80 | |
81 | |
82 | Drawing_draw_line( |
83 | Drawing, Pixmap, x, |
84 | y+(height/2), x + width, y+(height/2), |
85 | Drawing->Drawing_Area_V->style->black_gc); |
86 | |
87 | g_critical("y : %u, height : %u", y, height); |
88 | |
89 | birth.tv_sec = 12000; |
90 | birth.tv_nsec = 55700; |
91 | |
92 | ProcessList_get_process_pixels(Process_List, |
93 | 10, |
94 | &birth, |
95 | &y, |
96 | &height); |
97 | |
98 | |
99 | Drawing_draw_line( |
100 | Drawing, Pixmap, x, |
101 | y+(height/2), x + width, y+(height/2), |
102 | Drawing->Drawing_Area_V->style->black_gc); |
103 | |
104 | g_critical("y : %u, height : %u", y, height); |
105 | |
106 | for(i=0; i<10; i++) |
107 | { |
108 | birth.tv_sec = i*12000; |
109 | birth.tv_nsec = i*55700; |
110 | |
111 | ProcessList_get_process_pixels(Process_List, |
112 | i, |
113 | &birth, |
114 | &y, |
115 | &height); |
116 | |
117 | |
118 | Drawing_draw_line( |
119 | Drawing, Pixmap, x, |
120 | y+(height/2), x + width, y+(height/2), |
121 | Drawing->Drawing_Area_V->style->black_gc); |
122 | |
123 | g_critical("y : %u, height : %u", y, height); |
124 | |
125 | } |
126 | |
127 | birth.tv_sec = 12000; |
128 | birth.tv_nsec = 55600; |
129 | |
130 | ProcessList_get_process_pixels(Process_List, |
131 | 10, |
132 | &birth, |
133 | &y, |
134 | &height); |
135 | |
136 | |
137 | Drawing_draw_line( |
138 | Drawing, Pixmap, x, |
139 | y+(height/2), x + width, y+(height/2), |
140 | Drawing->Drawing_Area_V->style->black_gc); |
141 | |
142 | g_critical("y : %u, height : %u", y, height); |
cf6cb7e0 |
143 | |
144 | |
145 | pango_font_description_set_size(FontDesc, Font_Size); |
146 | g_free(layout); |
147 | //g_free(context); |
f7afe191 |
148 | } |
149 | |
150 | void send_test_process(ProcessList *Process_List, Drawing_t *Drawing) |
5f16133f |
151 | { |
f7afe191 |
152 | guint height, y; |
5f16133f |
153 | int i; |
154 | ProcessInfo Process_Info = {10000, 12000, 55600}; |
155 | //ProcessInfo Process_Info = {156, 14000, 55500}; |
156 | GtkTreeRowReference *got_RowRef; |
157 | |
158 | LttTime birth; |
f7afe191 |
159 | |
160 | if(Process_List->Test_Process_Sent) return; |
161 | |
5f16133f |
162 | birth.tv_sec = 12000; |
163 | birth.tv_nsec = 55500; |
164 | |
165 | ProcessList_add(Process_List, |
166 | 1, |
167 | &birth, |
f7afe191 |
168 | &y); |
169 | ProcessList_get_process_pixels(Process_List, |
170 | 1, |
171 | &birth, |
172 | &y, |
173 | &height); |
174 | Drawing_Insert_Square( Drawing, y, height); |
1ab3d149 |
175 | |
f7afe191 |
176 | //g_critical("y : %u, height : %u", y, height); |
5f16133f |
177 | |
178 | birth.tv_sec = 14000; |
179 | birth.tv_nsec = 55500; |
180 | |
181 | ProcessList_add(Process_List, |
182 | 156, |
183 | &birth, |
f7afe191 |
184 | &y); |
185 | ProcessList_get_process_pixels(Process_List, |
186 | 156, |
187 | &birth, |
188 | &y, |
189 | &height); |
190 | Drawing_Insert_Square( Drawing, y, height); |
191 | |
192 | //g_critical("y : %u, height : %u", y, height); |
193 | |
5f16133f |
194 | birth.tv_sec = 12000; |
195 | birth.tv_nsec = 55700; |
196 | |
197 | ProcessList_add(Process_List, |
198 | 10, |
199 | &birth, |
200 | &height); |
f7afe191 |
201 | ProcessList_get_process_pixels(Process_List, |
202 | 10, |
203 | &birth, |
204 | &y, |
205 | &height); |
206 | Drawing_Insert_Square( Drawing, y, height); |
207 | |
208 | //g_critical("y : %u, height : %u", y, height); |
209 | |
96cfe486 |
210 | //Drawing_Insert_Square( Drawing, height, 5); |
5f16133f |
211 | |
212 | for(i=0; i<10; i++) |
213 | { |
214 | birth.tv_sec = i*12000; |
215 | birth.tv_nsec = i*55700; |
216 | |
217 | ProcessList_add(Process_List, |
218 | i, |
219 | &birth, |
220 | &height); |
f7afe191 |
221 | ProcessList_get_process_pixels(Process_List, |
222 | i, |
223 | &birth, |
224 | &y, |
225 | &height); |
226 | Drawing_Insert_Square( Drawing, y, height); |
227 | |
228 | // g_critical("y : %u, height : %u", y, height); |
229 | |
5f16133f |
230 | } |
f7afe191 |
231 | //g_critical("height : %u", height); |
5f16133f |
232 | |
233 | birth.tv_sec = 12000; |
234 | birth.tv_nsec = 55600; |
235 | |
236 | ProcessList_add(Process_List, |
237 | 10, |
238 | &birth, |
f7afe191 |
239 | &y); |
240 | ProcessList_get_process_pixels(Process_List, |
241 | 10, |
242 | &birth, |
243 | &y, |
244 | &height); |
245 | Drawing_Insert_Square( Drawing, y, height); |
246 | |
247 | //g_critical("y : %u, height : %u", y, height); |
248 | |
5f16133f |
249 | ProcessList_add(Process_List, |
250 | 10000, |
251 | &birth, |
252 | &height); |
f7afe191 |
253 | ProcessList_get_process_pixels(Process_List, |
254 | 10000, |
255 | &birth, |
256 | &y, |
257 | &height); |
258 | Drawing_Insert_Square( Drawing, y, height); |
259 | |
260 | //g_critical("y : %u, height : %u", y, height); |
261 | |
96cfe486 |
262 | //Drawing_Insert_Square( Drawing, height, 5); |
f7afe191 |
263 | //g_critical("height : %u", height); |
5f16133f |
264 | |
265 | |
1ab3d149 |
266 | ProcessList_get_process_pixels(Process_List, |
267 | 10000, |
268 | &birth, |
f7afe191 |
269 | &y, &height); |
5f16133f |
270 | ProcessList_remove( Process_List, |
271 | 10000, |
272 | &birth); |
1ab3d149 |
273 | |
f7afe191 |
274 | Drawing_Remove_Square( Drawing, y, height); |
5f16133f |
275 | |
276 | if(got_RowRef = |
277 | (GtkTreeRowReference*)g_hash_table_lookup( |
278 | Process_List->Process_Hash, |
279 | &Process_Info)) |
280 | { |
281 | g_critical("key found"); |
282 | g_critical("position in the list : %s", |
283 | gtk_tree_path_to_string ( |
284 | gtk_tree_row_reference_get_path( |
285 | (GtkTreeRowReference*)got_RowRef) |
286 | )); |
287 | |
288 | } |
289 | |
f7afe191 |
290 | Process_List->Test_Process_Sent = TRUE; |
291 | |
5f16133f |
292 | } |
293 | |
294 | |
f0d936c0 |
295 | |
296 | /** |
297 | * Event Viewer's constructor hook |
298 | * |
299 | * This constructor is given as a parameter to the menuitem and toolbar button |
300 | * registration. It creates the list. |
301 | * @param pmParentWindow A pointer to the parent window. |
302 | * @return The widget created. |
303 | */ |
304 | GtkWidget * |
bca3b81f |
305 | hGuiControlFlow(MainWindow *pmParentWindow) |
f0d936c0 |
306 | { |
1ab818de |
307 | g_critical("hGuiControlFlow"); |
308 | ControlFlowData *Control_Flow_Data = GuiControlFlow() ; |
f0d936c0 |
309 | |
f7afe191 |
310 | GetTimeWindow(pmParentWindow, |
311 | GuiControlFlow_get_Time_Window(Control_Flow_Data)); |
312 | GetCurrentTime(pmParentWindow, |
313 | GuiControlFlow_get_Current_Time(Control_Flow_Data)); |
314 | |
315 | // Unreg done in the GuiControlFlow_Destructor |
316 | RegUpdateTimeWindow(Update_Time_Window_Hook, Control_Flow_Data, |
317 | pmParentWindow); |
318 | RegUpdateCurrentTime(Update_Current_Time_Hook, Control_Flow_Data, |
319 | pmParentWindow); |
558aa013 |
320 | return GuiControlFlow_get_Widget(Control_Flow_Data) ; |
f0d936c0 |
321 | |
322 | } |
323 | |
324 | int Event_Selected_Hook(void *hook_data, void *call_data) |
325 | { |
326 | ControlFlowData *Control_Flow_Data = (ControlFlowData*) hook_data; |
327 | guint *Event_Number = (guint*) call_data; |
328 | |
329 | g_critical("DEBUG : event selected by main window : %u", *Event_Number); |
330 | |
331 | // Control_Flow_Data->Currently_Selected_Event = *Event_Number; |
332 | // Control_Flow_Data->Selected_Event = TRUE ; |
333 | |
334 | // Tree_V_set_cursor(Control_Flow_Data); |
335 | |
336 | } |
337 | |
558aa013 |
338 | #ifdef DEBUG |
f0d936c0 |
339 | /* Hook called before drawing. Gets the initial context at the beginning of the |
340 | * drawing interval and copy it to the context in Event_Request. |
341 | */ |
342 | int Draw_Before_Hook(void *hook_data, void *call_data) |
343 | { |
344 | EventRequest *Event_Request = (EventRequest*)hook_data; |
345 | EventsContext Events_Context = (EventsContext*)call_data; |
346 | |
347 | Event_Request->Events_Context = Events_Context; |
348 | |
349 | return 0; |
350 | } |
351 | |
352 | /* |
353 | * The draw event hook is called by the reading API to have a |
354 | * particular event drawn on the screen. |
355 | * @param hook_data ControlFlowData structure of the viewer. |
356 | * @param call_data Event context. |
357 | * |
358 | * This function basically draw lines and icons. Two types of lines are drawn : |
359 | * one small (3 pixels?) representing the state of the process and the second |
360 | * type is thicker (10 pixels?) representing on which CPU a process is running |
361 | * (and this only in running state). |
362 | * |
363 | * Extremums of the lines : |
364 | * x_min : time of the last event context for this process kept in memory. |
365 | * x_max : time of the current event. |
366 | * y : middle of the process in the process list. The process is found in the |
367 | * list, therefore is it's position in pixels. |
368 | * |
369 | * The choice of lines'color is defined by the context of the last event for this |
370 | * process. |
371 | */ |
372 | int Draw_Event_Hook(void *hook_data, void *call_data) |
373 | { |
374 | EventRequest *Event_Request = (EventRequest*)hook_data; |
375 | |
376 | return 0; |
377 | } |
378 | |
379 | |
380 | int Draw_After_Hook(void *hook_data, void *call_data) |
381 | { |
382 | EventRequest *Event_Request = (EventRequest*)hook_data; |
383 | |
384 | g_free(Event_Request); |
385 | return 0; |
386 | } |
558aa013 |
387 | #endif |
f7afe191 |
388 | |
389 | |
390 | |
391 | |
392 | void Update_Time_Window_Hook(void *hook_data, void *call_data) |
393 | { |
394 | ControlFlowData *Control_Flow_Data = (ControlFlowData*) hook_data; |
395 | TimeWindow* Time_Window = |
396 | GuiControlFlow_get_Time_Window(Control_Flow_Data); |
397 | TimeWindow *New_Time_Window = ((TimeWindow*)call_data); |
398 | |
399 | // As the time interval change will mostly be used for |
400 | // zoom in and out, it's not useful to keep old drawing |
401 | // sections, as scale will be changed. |
402 | |
403 | |
404 | *Time_Window = *New_Time_Window; |
405 | g_critical("New time window HOOK : %u, %u to %u, %u", |
bca3b81f |
406 | Time_Window->start_time.tv_sec, |
407 | Time_Window->start_time.tv_nsec, |
408 | Time_Window->time_width.tv_sec, |
409 | Time_Window->time_width.tv_nsec); |
f7afe191 |
410 | |
411 | Drawing_Data_Request(Control_Flow_Data->Drawing, |
412 | &Control_Flow_Data->Drawing->Pixmap, |
413 | 0, 0, |
414 | Control_Flow_Data->Drawing->width, |
415 | Control_Flow_Data->Drawing->height); |
416 | |
417 | Drawing_Refresh(Control_Flow_Data->Drawing, |
418 | 0, 0, |
419 | Control_Flow_Data->Drawing->width, |
420 | Control_Flow_Data->Drawing->height); |
421 | |
422 | } |
423 | |
424 | void Update_Current_Time_Hook(void *hook_data, void *call_data) |
425 | { |
426 | ControlFlowData *Control_Flow_Data = (ControlFlowData*) hook_data; |
427 | LttTime* Current_Time = |
428 | GuiControlFlow_get_Current_Time(Control_Flow_Data); |
429 | *Current_Time = *((LttTime*)call_data); |
430 | g_critical("New Current time HOOK : %u, %u", Current_Time->tv_sec, |
431 | Current_Time->tv_nsec); |
432 | |
433 | /* If current time is inside time interval, just move the highlight |
434 | * bar */ |
435 | |
436 | /* Else, we have to change the time interval. We have to tell it |
437 | * to the main window. */ |
438 | /* The time interval change will take care of placing the current |
439 | * time at the center of the visible area */ |
440 | |
441 | } |
442 | |