process trace connection : time interval too long : 1 second. Result for now : proces...
[lttv.git] / ltt / branches / poly / lttv / modules / guiControlFlow / Event_Hooks.c
CommitLineData
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 30void 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 = &current;
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 74void 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
80ff382d 97 gc = gdk_gc_new(Pixmap);
cf6cb7e0 98 /* Sent text data */
80ff382d 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
80ff382d 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) */
80ff382d 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
80ff382d 251 pango_font_description_set_size(FontDesc, Font_Size);
252 g_object_unref(layout);
253 g_free(gc);
f7afe191 254}
255
256void 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 */
410GtkWidget *
4c69e0cc 411h_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;
f66eba62 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;
f0d936c0 422
f66eba62 423 LttTime *current_time = guicontrolflow_get_current_time(Control_Flow_Data);
424 current_time->tv_sec = 0;
425 current_time->tv_nsec = 0;
426
427 //g_critical("time width1 : %u",time_window->time_width);
428
41a76985 429 get_time_window(pmParentWindow,
f66eba62 430 time_window);
41a76985 431 get_current_time(pmParentWindow,
f66eba62 432 current_time);
f7afe191 433
f66eba62 434 //g_critical("time width2 : %u",time_window->time_width);
f7afe191 435 // Unreg done in the GuiControlFlow_Destructor
3cff8cc1 436 reg_update_time_window(update_time_window_hook, Control_Flow_Data,
f7afe191 437 pmParentWindow);
3cff8cc1 438 reg_update_current_time(update_current_time_hook, Control_Flow_Data,
f7afe191 439 pmParentWindow);
3cff8cc1 440 return guicontrolflow_get_widget(Control_Flow_Data) ;
f0d936c0 441
442}
443
3cff8cc1 444int event_selected_hook(void *hook_data, void *call_data)
f0d936c0 445{
446 ControlFlowData *Control_Flow_Data = (ControlFlowData*) hook_data;
447 guint *Event_Number = (guint*) call_data;
448
449 g_critical("DEBUG : event selected by main window : %u", *Event_Number);
450
451// Control_Flow_Data->Currently_Selected_Event = *Event_Number;
452// Control_Flow_Data->Selected_Event = TRUE ;
453
4c69e0cc 454// tree_v_set_cursor(Control_Flow_Data);
f0d936c0 455
456}
457
f0d936c0 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.
460 */
4c69e0cc 461int draw_before_hook(void *hook_data, void *call_data)
f0d936c0 462{
463 EventRequest *Event_Request = (EventRequest*)hook_data;
f66eba62 464 //EventsContext Events_Context = (EventsContext*)call_data;
f0d936c0 465
f66eba62 466 //Event_Request->Events_Context = Events_Context;
f0d936c0 467
468 return 0;
469}
470
471/*
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.
476 *
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).
481 *
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.
487 *
488 * The choice of lines'color is defined by the context of the last event for this
489 * process.
490 */
4c69e0cc 491int draw_event_hook(void *hook_data, void *call_data)
f0d936c0 492{
493 EventRequest *Event_Request = (EventRequest*)hook_data;
494
f66eba62 495
f0d936c0 496 return 0;
497}
498
499
4c69e0cc 500int draw_after_hook(void *hook_data, void *call_data)
f0d936c0 501{
502 EventRequest *Event_Request = (EventRequest*)hook_data;
503
504 g_free(Event_Request);
505 return 0;
506}
f7afe191 507
508
509
510
4c69e0cc 511void update_time_window_hook(void *hook_data, void *call_data)
f7afe191 512{
513 ControlFlowData *Control_Flow_Data = (ControlFlowData*) hook_data;
514 TimeWindow* Time_Window =
3cff8cc1 515 guicontrolflow_get_time_window(Control_Flow_Data);
f7afe191 516 TimeWindow *New_Time_Window = ((TimeWindow*)call_data);
517
518 // As the time interval change will mostly be used for
519 // zoom in and out, it's not useful to keep old drawing
520 // sections, as scale will be changed.
521
522
523 *Time_Window = *New_Time_Window;
189a5d08 524 g_info("New time window HOOK : %u, %u to %u, %u",
bca3b81f 525 Time_Window->start_time.tv_sec,
526 Time_Window->start_time.tv_nsec,
527 Time_Window->time_width.tv_sec,
528 Time_Window->time_width.tv_nsec);
f7afe191 529
6d5ed1c3 530 drawing_data_request(Control_Flow_Data->Drawing,
f7afe191 531 &Control_Flow_Data->Drawing->Pixmap,
532 0, 0,
533 Control_Flow_Data->Drawing->width,
534 Control_Flow_Data->Drawing->height);
535
4c69e0cc 536 drawing_refresh(Control_Flow_Data->Drawing,
f7afe191 537 0, 0,
538 Control_Flow_Data->Drawing->width,
539 Control_Flow_Data->Drawing->height);
540
541}
542
4c69e0cc 543void update_current_time_hook(void *hook_data, void *call_data)
f7afe191 544{
545 ControlFlowData *Control_Flow_Data = (ControlFlowData*) hook_data;
546 LttTime* Current_Time =
4c69e0cc 547 guicontrolflow_get_current_time(Control_Flow_Data);
f7afe191 548 *Current_Time = *((LttTime*)call_data);
189a5d08 549 g_info("New Current time HOOK : %u, %u", Current_Time->tv_sec,
f7afe191 550 Current_Time->tv_nsec);
551
552 /* If current time is inside time interval, just move the highlight
553 * bar */
554
555 /* Else, we have to change the time interval. We have to tell it
556 * to the main window. */
557 /* The time interval change will take care of placing the current
558 * time at the center of the visible area */
559
560}
561
This page took 0.050893 seconds and 4 git commands to generate.