| 1 | /***************************************************************************** |
| 2 | * Hooks to be called by the main window * |
| 3 | *****************************************************************************/ |
| 4 | |
| 5 | |
| 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 | |
| 9 | //#define PANGO_ENABLE_BACKEND |
| 10 | #include <gtk/gtk.h> |
| 11 | #include <gdk/gdk.h> |
| 12 | #include <glib.h> |
| 13 | |
| 14 | //#include <pango/pango.h> |
| 15 | |
| 16 | #include <lttv/hook.h> |
| 17 | #include <lttv/common.h> |
| 18 | |
| 19 | #include "Event_Hooks.h" |
| 20 | #include "CFV.h" |
| 21 | #include "Process_List.h" |
| 22 | #include "Drawing.h" |
| 23 | #include "CFV-private.h" |
| 24 | |
| 25 | #define MAX_PATH_LEN 256 |
| 26 | |
| 27 | //FIXME : remove this include when tests finished. |
| 28 | #include <string.h> |
| 29 | |
| 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; |
| 65 | draw_icon(&properties_icon, &draw_context); |
| 66 | g_free(properties_icon.icon_name); |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | } |
| 71 | |
| 72 | /* NOTE : no drawing data should be sent there, since the drawing widget |
| 73 | * has not been initialized */ |
| 74 | void send_test_drawing(ProcessList *Process_List, |
| 75 | Drawing_t *Drawing, |
| 76 | GdkPixmap *Pixmap, |
| 77 | gint x, gint y, // y not used here? |
| 78 | gint width, |
| 79 | gint height) // height won't be used here ? |
| 80 | { |
| 81 | int i,j; |
| 82 | ProcessInfo Process_Info = {10000, 12000, 55600}; |
| 83 | //ProcessInfo Process_Info = {156, 14000, 55500}; |
| 84 | GtkTreeRowReference *got_RowRef; |
| 85 | PangoContext *context; |
| 86 | PangoLayout *layout; |
| 87 | PangoFontDescription *FontDesc;// = pango_font_description_new(); |
| 88 | gint Font_Size; |
| 89 | |
| 90 | //icon |
| 91 | //GdkBitmap *mask = g_new(GdkBitmap, 1); |
| 92 | //GdkPixmap *icon_pixmap = g_new(GdkPixmap, 1); |
| 93 | GdkGC * gc; |
| 94 | // rectangle |
| 95 | GdkColor color = { 0, 0xffff, 0x0000, 0x0000 }; |
| 96 | |
| 97 | gc = gdk_gc_new(Pixmap); |
| 98 | /* Sent text data */ |
| 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); |
| 105 | |
| 106 | |
| 107 | |
| 108 | |
| 109 | LttTime birth; |
| 110 | birth.tv_sec = 12000; |
| 111 | birth.tv_nsec = 55500; |
| 112 | g_info("we have : x : %u, y : %u, width : %u, height : %u", x, y, width, height); |
| 113 | processlist_get_process_pixels(Process_List, |
| 114 | 1, |
| 115 | &birth, |
| 116 | &y, |
| 117 | &height); |
| 118 | |
| 119 | g_info("we draw : x : %u, y : %u, width : %u, height : %u", x, y, width, height); |
| 120 | drawing_draw_line( |
| 121 | Drawing, Pixmap, x, |
| 122 | y+(height/2), x + width, y+(height/2), |
| 123 | Drawing->Drawing_Area_V->style->black_gc); |
| 124 | |
| 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); |
| 128 | |
| 129 | birth.tv_sec = 14000; |
| 130 | birth.tv_nsec = 55500; |
| 131 | |
| 132 | processlist_get_process_pixels(Process_List, |
| 133 | 156, |
| 134 | &birth, |
| 135 | &y, |
| 136 | &height); |
| 137 | |
| 138 | |
| 139 | drawing_draw_line( |
| 140 | Drawing, Pixmap, x, |
| 141 | y+(height/2), x + width, y+(height/2), |
| 142 | Drawing->Drawing_Area_V->style->black_gc); |
| 143 | |
| 144 | g_info("y : %u, height : %u", y, height); |
| 145 | |
| 146 | |
| 147 | |
| 148 | birth.tv_sec = 12000; |
| 149 | birth.tv_nsec = 55700; |
| 150 | |
| 151 | processlist_get_process_pixels(Process_List, |
| 152 | 10, |
| 153 | &birth, |
| 154 | &y, |
| 155 | &height); |
| 156 | |
| 157 | /* Draw rectangle (background color) */ |
| 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); |
| 163 | |
| 164 | drawing_draw_line( |
| 165 | Drawing, Pixmap, x, |
| 166 | y+(height/2), x + width, y+(height/2), |
| 167 | Drawing->Drawing_Area_V->style->black_gc); |
| 168 | |
| 169 | |
| 170 | /* Draw arc */ |
| 171 | gdk_draw_arc(Pixmap, Drawing->Drawing_Area_V->style->black_gc, |
| 172 | TRUE, 100, y, height/2, height/2, 0, 360*64); |
| 173 | |
| 174 | g_info("y : %u, height : %u", y, height); |
| 175 | |
| 176 | for(i=0; i<10; i++) |
| 177 | { |
| 178 | birth.tv_sec = i*12000; |
| 179 | birth.tv_nsec = i*55700; |
| 180 | |
| 181 | processlist_get_process_pixels(Process_List, |
| 182 | i, |
| 183 | &birth, |
| 184 | &y, |
| 185 | &height); |
| 186 | |
| 187 | |
| 188 | drawing_draw_line( |
| 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 | |
| 200 | processlist_get_process_pixels(Process_List, |
| 201 | 10, |
| 202 | &birth, |
| 203 | &y, |
| 204 | &height); |
| 205 | |
| 206 | |
| 207 | drawing_draw_line( |
| 208 | Drawing, Pixmap, x, |
| 209 | y+(height/2), x + width, y+(height/2), |
| 210 | Drawing->Drawing_Area_V->style->black_gc); |
| 211 | |
| 212 | g_info("y : %u, height : %u", y, height); |
| 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 | // } |
| 237 | |
| 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 | |
| 249 | |
| 250 | |
| 251 | pango_font_description_set_size(FontDesc, Font_Size); |
| 252 | g_object_unref(layout); |
| 253 | g_free(gc); |
| 254 | } |
| 255 | |
| 256 | void send_test_process(ProcessList *Process_List, Drawing_t *Drawing) |
| 257 | { |
| 258 | guint height, y; |
| 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; |
| 265 | |
| 266 | if(Process_List->Test_Process_Sent) return; |
| 267 | |
| 268 | birth.tv_sec = 12000; |
| 269 | birth.tv_nsec = 55500; |
| 270 | |
| 271 | processlist_add(Process_List, |
| 272 | 1, |
| 273 | &birth, |
| 274 | &y); |
| 275 | processlist_get_process_pixels(Process_List, |
| 276 | 1, |
| 277 | &birth, |
| 278 | &y, |
| 279 | &height); |
| 280 | drawing_insert_square( Drawing, y, height); |
| 281 | |
| 282 | //g_critical("y : %u, height : %u", y, height); |
| 283 | |
| 284 | birth.tv_sec = 14000; |
| 285 | birth.tv_nsec = 55500; |
| 286 | |
| 287 | processlist_add(Process_List, |
| 288 | 156, |
| 289 | &birth, |
| 290 | &y); |
| 291 | processlist_get_process_pixels(Process_List, |
| 292 | 156, |
| 293 | &birth, |
| 294 | &y, |
| 295 | &height); |
| 296 | drawing_insert_square( Drawing, y, height); |
| 297 | |
| 298 | //g_critical("y : %u, height : %u", y, height); |
| 299 | |
| 300 | birth.tv_sec = 12000; |
| 301 | birth.tv_nsec = 55700; |
| 302 | |
| 303 | processlist_add(Process_List, |
| 304 | 10, |
| 305 | &birth, |
| 306 | &height); |
| 307 | processlist_get_process_pixels(Process_List, |
| 308 | 10, |
| 309 | &birth, |
| 310 | &y, |
| 311 | &height); |
| 312 | drawing_insert_square( Drawing, y, height); |
| 313 | |
| 314 | //g_critical("y : %u, height : %u", y, height); |
| 315 | |
| 316 | //drawing_insert_square( Drawing, height, 5); |
| 317 | |
| 318 | for(i=0; i<10; i++) |
| 319 | { |
| 320 | birth.tv_sec = i*12000; |
| 321 | birth.tv_nsec = i*55700; |
| 322 | |
| 323 | processlist_add(Process_List, |
| 324 | i, |
| 325 | &birth, |
| 326 | &height); |
| 327 | processlist_get_process_pixels(Process_List, |
| 328 | i, |
| 329 | &birth, |
| 330 | &y, |
| 331 | &height); |
| 332 | drawing_insert_square( Drawing, y, height); |
| 333 | |
| 334 | // g_critical("y : %u, height : %u", y, height); |
| 335 | |
| 336 | } |
| 337 | //g_critical("height : %u", height); |
| 338 | |
| 339 | birth.tv_sec = 12000; |
| 340 | birth.tv_nsec = 55600; |
| 341 | |
| 342 | processlist_add(Process_List, |
| 343 | 10, |
| 344 | &birth, |
| 345 | &y); |
| 346 | processlist_get_process_pixels(Process_List, |
| 347 | 10, |
| 348 | &birth, |
| 349 | &y, |
| 350 | &height); |
| 351 | drawing_insert_square( Drawing, y, height); |
| 352 | |
| 353 | //g_critical("y : %u, height : %u", y, height); |
| 354 | |
| 355 | processlist_add(Process_List, |
| 356 | 10000, |
| 357 | &birth, |
| 358 | &height); |
| 359 | processlist_get_process_pixels(Process_List, |
| 360 | 10000, |
| 361 | &birth, |
| 362 | &y, |
| 363 | &height); |
| 364 | drawing_insert_square( Drawing, y, height); |
| 365 | |
| 366 | //g_critical("y : %u, height : %u", y, height); |
| 367 | |
| 368 | //drawing_insert_square( Drawing, height, 5); |
| 369 | //g_critical("height : %u", height); |
| 370 | |
| 371 | |
| 372 | processlist_get_process_pixels(Process_List, |
| 373 | 10000, |
| 374 | &birth, |
| 375 | &y, &height); |
| 376 | processlist_remove( Process_List, |
| 377 | 10000, |
| 378 | &birth); |
| 379 | |
| 380 | drawing_remove_square( Drawing, y, height); |
| 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 | |
| 396 | Process_List->Test_Process_Sent = TRUE; |
| 397 | |
| 398 | } |
| 399 | |
| 400 | |
| 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 * |
| 411 | h_guicontrolflow(MainWindow *pmParentWindow, LttvTracesetSelector * s, char * key) |
| 412 | { |
| 413 | g_info("h_guicontrolflow, %p, %p, %s", pmParentWindow, s, key); |
| 414 | ControlFlowData *Control_Flow_Data = guicontrolflow() ; |
| 415 | |
| 416 | Control_Flow_Data->Parent_Window = pmParentWindow; |
| 417 | |
| 418 | get_time_window(pmParentWindow, |
| 419 | guicontrolflow_get_time_window(Control_Flow_Data)); |
| 420 | get_current_time(pmParentWindow, |
| 421 | guicontrolflow_get_current_time(Control_Flow_Data)); |
| 422 | |
| 423 | // Unreg done in the GuiControlFlow_Destructor |
| 424 | reg_update_time_window(update_time_window_hook, Control_Flow_Data, |
| 425 | pmParentWindow); |
| 426 | reg_update_current_time(update_current_time_hook, Control_Flow_Data, |
| 427 | pmParentWindow); |
| 428 | return guicontrolflow_get_widget(Control_Flow_Data) ; |
| 429 | |
| 430 | } |
| 431 | |
| 432 | int event_selected_hook(void *hook_data, void *call_data) |
| 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 | |
| 442 | // tree_v_set_cursor(Control_Flow_Data); |
| 443 | |
| 444 | } |
| 445 | |
| 446 | #ifdef DEBUG |
| 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 | */ |
| 450 | int draw_before_hook(void *hook_data, void *call_data) |
| 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 | */ |
| 480 | int draw_event_hook(void *hook_data, void *call_data) |
| 481 | { |
| 482 | EventRequest *Event_Request = (EventRequest*)hook_data; |
| 483 | |
| 484 | return 0; |
| 485 | } |
| 486 | |
| 487 | |
| 488 | int draw_after_hook(void *hook_data, void *call_data) |
| 489 | { |
| 490 | EventRequest *Event_Request = (EventRequest*)hook_data; |
| 491 | |
| 492 | g_free(Event_Request); |
| 493 | return 0; |
| 494 | } |
| 495 | #endif |
| 496 | |
| 497 | |
| 498 | |
| 499 | |
| 500 | void update_time_window_hook(void *hook_data, void *call_data) |
| 501 | { |
| 502 | ControlFlowData *Control_Flow_Data = (ControlFlowData*) hook_data; |
| 503 | TimeWindow* Time_Window = |
| 504 | guicontrolflow_get_time_window(Control_Flow_Data); |
| 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; |
| 513 | g_info("New time window HOOK : %u, %u to %u, %u", |
| 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); |
| 518 | |
| 519 | drawing_data_request(Control_Flow_Data->Drawing, |
| 520 | &Control_Flow_Data->Drawing->Pixmap, |
| 521 | 0, 0, |
| 522 | Control_Flow_Data->Drawing->width, |
| 523 | Control_Flow_Data->Drawing->height); |
| 524 | |
| 525 | drawing_refresh(Control_Flow_Data->Drawing, |
| 526 | 0, 0, |
| 527 | Control_Flow_Data->Drawing->width, |
| 528 | Control_Flow_Data->Drawing->height); |
| 529 | |
| 530 | } |
| 531 | |
| 532 | void update_current_time_hook(void *hook_data, void *call_data) |
| 533 | { |
| 534 | ControlFlowData *Control_Flow_Data = (ControlFlowData*) hook_data; |
| 535 | LttTime* Current_Time = |
| 536 | guicontrolflow_get_current_time(Control_Flow_Data); |
| 537 | *Current_Time = *((LttTime*)call_data); |
| 538 | g_info("New Current time HOOK : %u, %u", Current_Time->tv_sec, |
| 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 | |