| 1 | /***************************************************************************** |
| 2 | * Hooks to be called by the main window * |
| 3 | *****************************************************************************/ |
| 4 | |
| 5 | |
| 6 | //#define PANGO_ENABLE_BACKEND |
| 7 | #include <gtk/gtk.h> |
| 8 | #include <gdk/gdk.h> |
| 9 | #include <glib.h> |
| 10 | |
| 11 | //#include <pango/pango.h> |
| 12 | |
| 13 | #include <lttv/hook.h> |
| 14 | #include <lttv/common.h> |
| 15 | |
| 16 | #include "Event_Hooks.h" |
| 17 | #include "CFV.h" |
| 18 | #include "Process_List.h" |
| 19 | #include "Drawing.h" |
| 20 | #include "CFV-private.h" |
| 21 | |
| 22 | |
| 23 | /* NOTE : no drawing data should be sent there, as the drawing widget |
| 24 | * has not been initialized */ |
| 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; |
| 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 | |
| 49 | |
| 50 | |
| 51 | |
| 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 | |
| 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 | |
| 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); |
| 143 | |
| 144 | |
| 145 | pango_font_description_set_size(FontDesc, Font_Size); |
| 146 | g_free(layout); |
| 147 | //g_free(context); |
| 148 | } |
| 149 | |
| 150 | void send_test_process(ProcessList *Process_List, Drawing_t *Drawing) |
| 151 | { |
| 152 | guint height, y; |
| 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; |
| 159 | |
| 160 | if(Process_List->Test_Process_Sent) return; |
| 161 | |
| 162 | birth.tv_sec = 12000; |
| 163 | birth.tv_nsec = 55500; |
| 164 | |
| 165 | ProcessList_add(Process_List, |
| 166 | 1, |
| 167 | &birth, |
| 168 | &y); |
| 169 | ProcessList_get_process_pixels(Process_List, |
| 170 | 1, |
| 171 | &birth, |
| 172 | &y, |
| 173 | &height); |
| 174 | Drawing_Insert_Square( Drawing, y, height); |
| 175 | |
| 176 | //g_critical("y : %u, height : %u", y, height); |
| 177 | |
| 178 | birth.tv_sec = 14000; |
| 179 | birth.tv_nsec = 55500; |
| 180 | |
| 181 | ProcessList_add(Process_List, |
| 182 | 156, |
| 183 | &birth, |
| 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 | |
| 194 | birth.tv_sec = 12000; |
| 195 | birth.tv_nsec = 55700; |
| 196 | |
| 197 | ProcessList_add(Process_List, |
| 198 | 10, |
| 199 | &birth, |
| 200 | &height); |
| 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 | |
| 210 | //Drawing_Insert_Square( Drawing, height, 5); |
| 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); |
| 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 | |
| 230 | } |
| 231 | //g_critical("height : %u", height); |
| 232 | |
| 233 | birth.tv_sec = 12000; |
| 234 | birth.tv_nsec = 55600; |
| 235 | |
| 236 | ProcessList_add(Process_List, |
| 237 | 10, |
| 238 | &birth, |
| 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 | |
| 249 | ProcessList_add(Process_List, |
| 250 | 10000, |
| 251 | &birth, |
| 252 | &height); |
| 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 | |
| 262 | //Drawing_Insert_Square( Drawing, height, 5); |
| 263 | //g_critical("height : %u", height); |
| 264 | |
| 265 | |
| 266 | ProcessList_get_process_pixels(Process_List, |
| 267 | 10000, |
| 268 | &birth, |
| 269 | &y, &height); |
| 270 | ProcessList_remove( Process_List, |
| 271 | 10000, |
| 272 | &birth); |
| 273 | |
| 274 | Drawing_Remove_Square( Drawing, y, height); |
| 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 | |
| 290 | Process_List->Test_Process_Sent = TRUE; |
| 291 | |
| 292 | } |
| 293 | |
| 294 | |
| 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 * |
| 305 | hGuiControlFlow(MainWindow *pmParentWindow) |
| 306 | { |
| 307 | g_critical("hGuiControlFlow"); |
| 308 | ControlFlowData *Control_Flow_Data = GuiControlFlow() ; |
| 309 | |
| 310 | get_time_window(pmParentWindow, |
| 311 | GuiControlFlow_get_Time_Window(Control_Flow_Data)); |
| 312 | get_current_time(pmParentWindow, |
| 313 | GuiControlFlow_get_Current_Time(Control_Flow_Data)); |
| 314 | |
| 315 | // Unreg done in the GuiControlFlow_Destructor |
| 316 | reg_update_time_window(Update_Time_Window_Hook, Control_Flow_Data, |
| 317 | pmParentWindow); |
| 318 | reg_update_current_time(Update_Current_Time_Hook, Control_Flow_Data, |
| 319 | pmParentWindow); |
| 320 | return GuiControlFlow_get_Widget(Control_Flow_Data) ; |
| 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 | |
| 338 | #ifdef DEBUG |
| 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 | } |
| 387 | #endif |
| 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", |
| 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); |
| 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 | |