| 1 | /* This file is part of the Linux Trace Toolkit viewer |
| 2 | * Copyright (C) 2003-2004 XangXiu Yang |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License Version 2 as |
| 6 | * published by the Free Software Foundation; |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
| 12 | * |
| 13 | * You should have received a copy of the GNU General Public License |
| 14 | * along with this program; if not, write to the Free Software |
| 15 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, |
| 16 | * MA 02111-1307, USA. |
| 17 | */ |
| 18 | |
| 19 | /*! \file lttvviewer.c |
| 20 | * \brief API used by the graphical viewers to interact with their top window. |
| 21 | * |
| 22 | * Main window (gui module) is the place to contain and display viewers. |
| 23 | * Viewers (lttv plugins) interacte with main window through this API and |
| 24 | * events sent by gtk. |
| 25 | * This header file should be included in each graphic module. |
| 26 | * This library is used by graphical modules to interact with the |
| 27 | * tracesetWindow. |
| 28 | * |
| 29 | */ |
| 30 | |
| 31 | #include <lttvwindow/common.h> |
| 32 | #include <ltt/ltt.h> |
| 33 | #include <lttv/lttv.h> |
| 34 | #include <lttvwindow/mainwindow.h> |
| 35 | #include <lttvwindow/viewer.h> |
| 36 | #include <lttv/tracecontext.h> |
| 37 | #include <lttvwindow/toolbar.h> |
| 38 | #include <lttvwindow/menu.h> |
| 39 | #include <lttv/state.h> |
| 40 | #include <lttv/stats.h> |
| 41 | |
| 42 | |
| 43 | /** |
| 44 | * Internal function parts |
| 45 | */ |
| 46 | |
| 47 | /** |
| 48 | * Function to set/update traceset for the viewers |
| 49 | * @param main_win main window |
| 50 | * @param traceset traceset of the main window. |
| 51 | */ |
| 52 | |
| 53 | void SetTraceset(MainWindow * main_win, gpointer traceset) |
| 54 | { |
| 55 | LttvHooks * tmp; |
| 56 | LttvAttributeValue value; |
| 57 | |
| 58 | g_assert(lttv_iattribute_find_by_path(main_win->attributes, |
| 59 | "hooks/updatetraceset", LTTV_POINTER, &value)); |
| 60 | tmp = (LttvHooks*)*(value.v_pointer); |
| 61 | if(tmp == NULL)return; |
| 62 | lttv_hooks_call(tmp,traceset); |
| 63 | } |
| 64 | |
| 65 | |
| 66 | /** |
| 67 | * Function to set/update filter for the viewers |
| 68 | * @param main_win main window |
| 69 | * @param filter filter of the main window. |
| 70 | */ |
| 71 | |
| 72 | void SetFilter(MainWindow * main_win, gpointer filter) |
| 73 | { |
| 74 | LttvHooks * tmp; |
| 75 | LttvAttributeValue value; |
| 76 | |
| 77 | g_assert(lttv_iattribute_find_by_path(main_win->attributes, |
| 78 | "hooks/updatefilter", LTTV_POINTER, &value)); |
| 79 | tmp = (LttvHooks*)*(value.v_pointer); |
| 80 | |
| 81 | if(tmp == NULL)return; |
| 82 | lttv_hooks_call(tmp,filter); |
| 83 | } |
| 84 | |
| 85 | |
| 86 | |
| 87 | /** |
| 88 | * API parts |
| 89 | */ |
| 90 | |
| 91 | /** |
| 92 | * Function to register a view constructor so that main window can generate |
| 93 | * a toolbar item for the viewer in order to generate a new instance easily. |
| 94 | * It will be called by init function of the module. |
| 95 | * @param ButtonPixmap image shown on the toolbar item. |
| 96 | * @param tooltip tooltip of the toolbar item. |
| 97 | * @param view_constructor constructor of the viewer. |
| 98 | */ |
| 99 | |
| 100 | void toolbar_item_reg(char ** pixmap, char *tooltip, lttv_constructor view_constructor) |
| 101 | { |
| 102 | LttvIAttribute *attributes_global = LTTV_IATTRIBUTE(lttv_global_attributes()); |
| 103 | LttvToolbars * toolbar; |
| 104 | LttvAttributeValue value; |
| 105 | |
| 106 | g_assert(lttv_iattribute_find_by_path(attributes_global, |
| 107 | "viewers/toolbar", LTTV_POINTER, &value)); |
| 108 | toolbar = (LttvToolbars*)*(value.v_pointer); |
| 109 | |
| 110 | if(toolbar == NULL){ |
| 111 | toolbar = lttv_toolbars_new(); |
| 112 | *(value.v_pointer) = toolbar; |
| 113 | } |
| 114 | lttv_toolbars_add(toolbar, view_constructor, tooltip, pixmap); |
| 115 | } |
| 116 | |
| 117 | |
| 118 | /** |
| 119 | * Function to unregister the viewer's constructor, release the space |
| 120 | * occupied by pixmap, tooltip and constructor of the viewer. |
| 121 | * It will be called when a module is unloaded. |
| 122 | * @param view_constructor constructor of the viewer which is used as |
| 123 | * a reference to find out where the pixmap and tooltip are. |
| 124 | */ |
| 125 | |
| 126 | void toolbar_item_unreg(lttv_constructor view_constructor) |
| 127 | { |
| 128 | LttvIAttribute *attributes_global = LTTV_IATTRIBUTE(lttv_global_attributes()); |
| 129 | LttvToolbars * toolbar; |
| 130 | LttvAttributeValue value; |
| 131 | |
| 132 | g_assert(lttv_iattribute_find_by_path(attributes_global, |
| 133 | "viewers/toolbar", LTTV_POINTER, &value)); |
| 134 | toolbar = (LttvToolbars*)*(value.v_pointer); |
| 135 | |
| 136 | main_window_remove_toolbar_item(view_constructor); |
| 137 | |
| 138 | lttv_toolbars_remove(toolbar, view_constructor); |
| 139 | } |
| 140 | |
| 141 | |
| 142 | /** |
| 143 | * Function to register a view constructor so that main window can generate |
| 144 | * a menu item for the viewer in order to generate a new instance easily. |
| 145 | * It will be called by init function of the module. |
| 146 | * @param menu_path path of the menu item. |
| 147 | * @param menu_text text of the menu item. |
| 148 | * @param view_constructor constructor of the viewer. |
| 149 | */ |
| 150 | |
| 151 | void menu_item_reg(char *menu_path, char *menu_text, lttv_constructor view_constructor) |
| 152 | { |
| 153 | LttvIAttribute *attributes_global = LTTV_IATTRIBUTE(lttv_global_attributes()); |
| 154 | LttvMenus * menu; |
| 155 | LttvAttributeValue value; |
| 156 | |
| 157 | g_assert(lttv_iattribute_find_by_path(attributes_global, |
| 158 | "viewers/menu", LTTV_POINTER, &value)); |
| 159 | menu = (LttvMenus*)*(value.v_pointer); |
| 160 | |
| 161 | if(menu == NULL){ |
| 162 | menu = lttv_menus_new(); |
| 163 | *(value.v_pointer) = menu; |
| 164 | } |
| 165 | lttv_menus_add(menu, view_constructor, menu_path, menu_text); |
| 166 | } |
| 167 | |
| 168 | /** |
| 169 | * Function to unregister the viewer's constructor, release the space |
| 170 | * occupied by menu_path, menu_text and constructor of the viewer. |
| 171 | * It will be called when a module is unloaded. |
| 172 | * @param view_constructor constructor of the viewer which is used as |
| 173 | * a reference to find out where the menu_path and menu_text are. |
| 174 | */ |
| 175 | |
| 176 | void menu_item_unreg(lttv_constructor view_constructor) |
| 177 | { |
| 178 | LttvIAttribute *attributes_global = LTTV_IATTRIBUTE(lttv_global_attributes()); |
| 179 | LttvMenus * menu; |
| 180 | LttvAttributeValue value; |
| 181 | |
| 182 | g_assert(lttv_iattribute_find_by_path(attributes_global, |
| 183 | "viewers/menu", LTTV_POINTER, &value)); |
| 184 | menu = (LttvMenus*)*(value.v_pointer); |
| 185 | |
| 186 | main_window_remove_menu_item(view_constructor); |
| 187 | |
| 188 | lttv_menus_remove(menu, view_constructor); |
| 189 | } |
| 190 | |
| 191 | |
| 192 | /** |
| 193 | * Update the status bar whenever something changed in the viewer. |
| 194 | * @param main_win the main window the viewer belongs to. |
| 195 | * @param info the message which will be shown in the status bar. |
| 196 | */ |
| 197 | |
| 198 | void update_status(MainWindow *main_win, char *info) |
| 199 | { |
| 200 | } |
| 201 | |
| 202 | |
| 203 | /** |
| 204 | * Function to get the current time interval shown on the current tab. |
| 205 | * It will be called by a viewer's hook function to update the |
| 206 | * shown time interval of the viewer and also be called by the constructor |
| 207 | * of the viewer. |
| 208 | * @param main_win the main window the viewer belongs to. |
| 209 | * @param time_interval a pointer where time interval will be stored. |
| 210 | */ |
| 211 | |
| 212 | void get_time_window(MainWindow *main_win, TimeWindow *time_window) |
| 213 | { |
| 214 | //time_window->start_time = main_win->current_tab->time_window.start_time; |
| 215 | //time_window->time_width = main_win->current_tab->time_window.time_width; |
| 216 | *time_window = main_win->current_tab->time_window; |
| 217 | } |
| 218 | |
| 219 | /** |
| 220 | * Function to get the current time interval of the current traceset. |
| 221 | * It will be called by a viewer's hook function to update the |
| 222 | * time interval of the viewer and also be called by the constructor |
| 223 | * of the viewer. |
| 224 | * @param main_win the main window the viewer belongs to. |
| 225 | * @param time_interval a pointer where time interval will be stored. |
| 226 | */ |
| 227 | |
| 228 | void get_traceset_time_span(MainWindow *main_win, TimeInterval *time_interval) |
| 229 | { |
| 230 | //time_window->start_time = main_win->current_tab->time_window.start_time; |
| 231 | //time_window->time_width = main_win->current_tab->time_window.time_width; |
| 232 | *time_interval = *(LTTV_TRACESET_CONTEXT(main_win->current_tab->traceset_info-> |
| 233 | traceset_context)->Time_Span); |
| 234 | } |
| 235 | |
| 236 | |
| 237 | |
| 238 | /** |
| 239 | * Function to set the time interval of the current tab. |
| 240 | * It will be called by a viewer's signal handle associated with |
| 241 | * the move_slider signal |
| 242 | * @param main_win the main window the viewer belongs to. |
| 243 | * @param time_interval a pointer where time interval is stored. |
| 244 | */ |
| 245 | |
| 246 | void set_time_window(MainWindow *main_win, TimeWindow *time_window) |
| 247 | { |
| 248 | LttvAttributeValue value; |
| 249 | LttvHooks * tmp; |
| 250 | main_win->current_tab->time_window = *time_window; |
| 251 | gtk_multi_vpaned_set_scroll_value(main_win->current_tab->multi_vpaned, |
| 252 | ltt_time_to_double(time_window->start_time) |
| 253 | * NANOSECONDS_PER_SECOND ); |
| 254 | g_assert(lttv_iattribute_find_by_path(main_win->current_tab->attributes, |
| 255 | "hooks/updatetimewindow", LTTV_POINTER, &value)); |
| 256 | tmp = (LttvHooks*)*(value.v_pointer); |
| 257 | if(tmp == NULL) return; |
| 258 | lttv_hooks_call(tmp, time_window); |
| 259 | } |
| 260 | |
| 261 | |
| 262 | /** |
| 263 | * Function to get the current time/event of the current tab. |
| 264 | * It will be called by a viewer's hook function to update the |
| 265 | * current time/event of the viewer. |
| 266 | * @param main_win the main window the viewer belongs to. |
| 267 | * @param time a pointer where time will be stored. |
| 268 | */ |
| 269 | |
| 270 | void get_current_time(MainWindow *main_win, LttTime *time) |
| 271 | { |
| 272 | time = &main_win->current_tab->current_time; |
| 273 | } |
| 274 | |
| 275 | |
| 276 | /** |
| 277 | * Function to set the current time/event of the current tab. |
| 278 | * It will be called by a viewer's signal handle associated with |
| 279 | * the button-release-event signal |
| 280 | * @param main_win the main window the viewer belongs to. |
| 281 | * @param time a pointer where time is stored. |
| 282 | */ |
| 283 | |
| 284 | void set_current_time(MainWindow *main_win, LttTime *time) |
| 285 | { |
| 286 | LttvAttributeValue value; |
| 287 | LttvHooks * tmp; |
| 288 | main_win->current_tab->current_time = *time; |
| 289 | g_assert(lttv_iattribute_find_by_path(main_win->current_tab->attributes, |
| 290 | "hooks/updatecurrenttime", LTTV_POINTER, &value)); |
| 291 | tmp = (LttvHooks*)*(value.v_pointer); |
| 292 | |
| 293 | if(tmp == NULL)return; |
| 294 | lttv_hooks_call(tmp, time); |
| 295 | } |
| 296 | |
| 297 | |
| 298 | /** |
| 299 | * Function to get the traceset from the current tab. |
| 300 | * It will be called by the constructor of the viewer and also be |
| 301 | * called by a hook funtion of the viewer to update its traceset. |
| 302 | * @param main_win the main window the viewer belongs to. |
| 303 | * @param traceset a pointer to a traceset. |
| 304 | */ |
| 305 | /* |
| 306 | void get_traceset(MainWindow *main_win, Traceset *traceset) |
| 307 | { |
| 308 | } |
| 309 | */ |
| 310 | |
| 311 | /** |
| 312 | * Function to get the filter of the current tab. |
| 313 | * It will be called by the constructor of the viewer and also be |
| 314 | * called by a hook funtion of the viewer to update its filter. |
| 315 | * @param main_win, the main window the viewer belongs to. |
| 316 | * @param filter, a pointer to a filter. |
| 317 | */ |
| 318 | /* |
| 319 | void get_filter(MainWindow *main_win, Filter *filter) |
| 320 | { |
| 321 | } |
| 322 | */ |
| 323 | |
| 324 | /** |
| 325 | * Function to register a hook function for a viewer to set/update its |
| 326 | * time interval. |
| 327 | * It will be called by the constructor of the viewer. |
| 328 | * @param hook hook function of the viewer. |
| 329 | * @param hook_data hook data associated with the hook function. |
| 330 | * @param main_win the main window the viewer belongs to. |
| 331 | */ |
| 332 | |
| 333 | void reg_update_time_window(LttvHook hook, gpointer hook_data, |
| 334 | MainWindow * main_win) |
| 335 | { |
| 336 | LttvAttributeValue value; |
| 337 | LttvHooks * tmp; |
| 338 | g_assert(lttv_iattribute_find_by_path(main_win->current_tab->attributes, |
| 339 | "hooks/updatetimewindow", LTTV_POINTER, &value)); |
| 340 | tmp = (LttvHooks*)*(value.v_pointer); |
| 341 | if(tmp == NULL){ |
| 342 | tmp = lttv_hooks_new(); |
| 343 | *(value.v_pointer) = tmp; |
| 344 | } |
| 345 | lttv_hooks_add(tmp, hook,hook_data); |
| 346 | } |
| 347 | |
| 348 | |
| 349 | /** |
| 350 | * Function to unregister a viewer's hook function which is used to |
| 351 | * set/update the time interval of the viewer. |
| 352 | * It will be called by the destructor of the viewer. |
| 353 | * @param hook hook function of the viewer. |
| 354 | * @param hook_data hook data associated with the hook function. |
| 355 | * @param main_win the main window the viewer belongs to. |
| 356 | */ |
| 357 | |
| 358 | void unreg_update_time_window(LttvHook hook, gpointer hook_data, |
| 359 | MainWindow * main_win) |
| 360 | { |
| 361 | LttvAttributeValue value; |
| 362 | LttvHooks * tmp; |
| 363 | g_assert(lttv_iattribute_find_by_path(main_win->current_tab->attributes, |
| 364 | "hooks/updatetimewindow", LTTV_POINTER, &value)); |
| 365 | tmp = (LttvHooks*)*(value.v_pointer); |
| 366 | if(tmp == NULL) return; |
| 367 | lttv_hooks_remove_data(tmp, hook, hook_data); |
| 368 | } |
| 369 | |
| 370 | |
| 371 | /** |
| 372 | * Function to register a hook function for a viewer to set/update its |
| 373 | * traceset. |
| 374 | * It will be called by the constructor of the viewer. |
| 375 | * @param hook hook function of the viewer. |
| 376 | * @param hook_data hook data associated with the hook function. |
| 377 | * @param main_win the main window the viewer belongs to. |
| 378 | */ |
| 379 | |
| 380 | void reg_update_traceset(LttvHook hook, gpointer hook_data, |
| 381 | MainWindow * main_win) |
| 382 | { |
| 383 | LttvAttributeValue value; |
| 384 | LttvHooks * tmp; |
| 385 | g_assert(lttv_iattribute_find_by_path(main_win->current_tab->attributes, |
| 386 | "hooks/updatetraceset", LTTV_POINTER, &value)); |
| 387 | tmp = (LttvHooks*)*(value.v_pointer); |
| 388 | if(tmp == NULL){ |
| 389 | tmp = lttv_hooks_new(); |
| 390 | *(value.v_pointer) = tmp; |
| 391 | } |
| 392 | lttv_hooks_add(tmp, hook, hook_data); |
| 393 | } |
| 394 | |
| 395 | |
| 396 | /** |
| 397 | * Function to unregister a viewer's hook function which is used to |
| 398 | * set/update the traceset of the viewer. |
| 399 | * It will be called by the destructor of the viewer. |
| 400 | * @param hook hook function of the viewer. |
| 401 | * @param hook_data hook data associated with the hook function. |
| 402 | * @param main_win the main window the viewer belongs to. |
| 403 | */ |
| 404 | |
| 405 | void unreg_update_traceset(LttvHook hook, gpointer hook_data, |
| 406 | MainWindow * main_win) |
| 407 | { |
| 408 | LttvAttributeValue value; |
| 409 | LttvHooks * tmp; |
| 410 | g_assert(lttv_iattribute_find_by_path(main_win->current_tab->attributes, |
| 411 | "hooks/updatetraceset", LTTV_POINTER, &value)); |
| 412 | tmp = (LttvHooks*)*(value.v_pointer); |
| 413 | if(tmp == NULL) return; |
| 414 | lttv_hooks_remove_data(tmp, hook, hook_data); |
| 415 | } |
| 416 | |
| 417 | |
| 418 | /** |
| 419 | * Function to redraw each viewer belonging to the current tab |
| 420 | * @param main_win the main window the viewer belongs to. |
| 421 | */ |
| 422 | |
| 423 | void update_traceset(MainWindow * main_win) |
| 424 | { |
| 425 | LttvAttributeValue value; |
| 426 | LttvHooks * tmp; |
| 427 | g_assert(lttv_iattribute_find_by_path(main_win->current_tab->attributes, |
| 428 | "hooks/updatetraceset", LTTV_POINTER, &value)); |
| 429 | tmp = (LttvHooks*)*(value.v_pointer); |
| 430 | if(tmp == NULL) return; |
| 431 | lttv_hooks_call(tmp, NULL); |
| 432 | } |
| 433 | |
| 434 | |
| 435 | /** |
| 436 | * Function to register a hook function for a viewer to set/update its |
| 437 | * filter. |
| 438 | * It will be called by the constructor of the viewer. |
| 439 | * @param hook hook function of the viewer. |
| 440 | * @param hook_data hook data associated with the hook function. |
| 441 | * @param main_win the main window the viewer belongs to. |
| 442 | */ |
| 443 | |
| 444 | void reg_update_filter(LttvHook hook, gpointer hook_data, |
| 445 | MainWindow *main_win) |
| 446 | { |
| 447 | LttvAttributeValue value; |
| 448 | LttvHooks * tmp; |
| 449 | g_assert(lttv_iattribute_find_by_path(main_win->attributes, |
| 450 | "hooks/updatefilter", LTTV_POINTER, &value)); |
| 451 | tmp = (LttvHooks*)*(value.v_pointer); |
| 452 | if(tmp == NULL){ |
| 453 | tmp = lttv_hooks_new(); |
| 454 | *(value.v_pointer) = tmp; |
| 455 | } |
| 456 | lttv_hooks_add(tmp, hook, hook_data); |
| 457 | } |
| 458 | |
| 459 | |
| 460 | /** |
| 461 | * Function to unregister a viewer's hook function which is used to |
| 462 | * set/update the filter of the viewer. |
| 463 | * It will be called by the destructor of the viewer. |
| 464 | * @param hook hook function of the viewer. |
| 465 | * @param hook_data hook data associated with the hook function. |
| 466 | * @param main_win the main window the viewer belongs to. |
| 467 | */ |
| 468 | |
| 469 | void unreg_update_filter(LttvHook hook, gpointer hook_data, |
| 470 | MainWindow * main_win) |
| 471 | { |
| 472 | LttvAttributeValue value; |
| 473 | LttvHooks * tmp; |
| 474 | g_assert(lttv_iattribute_find_by_path(main_win->attributes, |
| 475 | "hooks/updatefilter", LTTV_POINTER, &value)); |
| 476 | tmp = (LttvHooks*)*(value.v_pointer); |
| 477 | if(tmp == NULL) return; |
| 478 | lttv_hooks_remove_data(tmp, hook, hook_data); |
| 479 | } |
| 480 | |
| 481 | |
| 482 | /** |
| 483 | * Function to register a hook function for a viewer to set/update its |
| 484 | * current time. |
| 485 | * It will be called by the constructor of the viewer. |
| 486 | * @param hook hook function of the viewer. |
| 487 | * @param hook_data hook data associated with the hook function. |
| 488 | * @param main_win the main window the viewer belongs to. |
| 489 | */ |
| 490 | |
| 491 | void reg_update_current_time(LttvHook hook, gpointer hook_data, |
| 492 | MainWindow *main_win) |
| 493 | { |
| 494 | LttvAttributeValue value; |
| 495 | LttvHooks * tmp; |
| 496 | g_assert(lttv_iattribute_find_by_path(main_win->current_tab->attributes, |
| 497 | "hooks/updatecurrenttime", LTTV_POINTER, &value)); |
| 498 | tmp = (LttvHooks*)*(value.v_pointer); |
| 499 | if(tmp == NULL){ |
| 500 | tmp = lttv_hooks_new(); |
| 501 | *(value.v_pointer) = tmp; |
| 502 | } |
| 503 | lttv_hooks_add(tmp, hook, hook_data); |
| 504 | } |
| 505 | |
| 506 | |
| 507 | /** |
| 508 | * Function to unregister a viewer's hook function which is used to |
| 509 | * set/update the current time of the viewer. |
| 510 | * It will be called by the destructor of the viewer. |
| 511 | * @param hook hook function of the viewer. |
| 512 | * @param hook_data hook data associated with the hook function. |
| 513 | * @param main_win the main window the viewer belongs to. |
| 514 | */ |
| 515 | |
| 516 | void unreg_update_current_time(LttvHook hook, gpointer hook_data, |
| 517 | MainWindow * main_win) |
| 518 | { |
| 519 | LttvAttributeValue value; |
| 520 | LttvHooks * tmp; |
| 521 | g_assert(lttv_iattribute_find_by_path(main_win->current_tab->attributes, |
| 522 | "hooks/updatecurrenttime", LTTV_POINTER, &value)); |
| 523 | tmp = (LttvHooks*)*(value.v_pointer); |
| 524 | if(tmp == NULL) return; |
| 525 | lttv_hooks_remove_data(tmp, hook, hook_data); |
| 526 | } |
| 527 | |
| 528 | |
| 529 | /** |
| 530 | * Function to register a hook function for a viewer to show |
| 531 | *the content of the viewer. |
| 532 | * It will be called by the constructor of the viewer. |
| 533 | * @param hook hook function of the viewer. |
| 534 | * @param hook_data hook data associated with the hook function. |
| 535 | * @param main_win the main window the viewer belongs to. |
| 536 | */ |
| 537 | |
| 538 | void reg_show_viewer(LttvHook hook, gpointer hook_data, |
| 539 | MainWindow *main_win) |
| 540 | { |
| 541 | LttvAttributeValue value; |
| 542 | LttvHooks * tmp; |
| 543 | g_assert(lttv_iattribute_find_by_path(main_win->current_tab->attributes, |
| 544 | "hooks/showviewer", LTTV_POINTER, &value)); |
| 545 | tmp = (LttvHooks*)*(value.v_pointer); |
| 546 | if(tmp == NULL){ |
| 547 | tmp = lttv_hooks_new(); |
| 548 | *(value.v_pointer) = tmp; |
| 549 | } |
| 550 | lttv_hooks_add(tmp, hook, hook_data); |
| 551 | } |
| 552 | |
| 553 | |
| 554 | /** |
| 555 | * Function to unregister a viewer's hook function which is used to |
| 556 | * show the content of the viewer.. |
| 557 | * It will be called by the destructor of the viewer. |
| 558 | * @param hook hook function of the viewer. |
| 559 | * @param hook_data hook data associated with the hook function. |
| 560 | * @param main_win the main window the viewer belongs to. |
| 561 | */ |
| 562 | |
| 563 | void unreg_show_viewer(LttvHook hook, gpointer hook_data, |
| 564 | MainWindow * main_win) |
| 565 | { |
| 566 | LttvAttributeValue value; |
| 567 | LttvHooks * tmp; |
| 568 | g_assert(lttv_iattribute_find_by_path(main_win->current_tab->attributes, |
| 569 | "hooks/showviewer", LTTV_POINTER, &value)); |
| 570 | tmp = (LttvHooks*)*(value.v_pointer); |
| 571 | if(tmp == NULL) return; |
| 572 | lttv_hooks_remove_data(tmp, hook, hook_data); |
| 573 | } |
| 574 | |
| 575 | |
| 576 | /** |
| 577 | * Function to show each viewer in the current tab. |
| 578 | * It will be called by main window after it called process_traceset |
| 579 | * @param main_win the main window the viewer belongs to. |
| 580 | */ |
| 581 | |
| 582 | void show_viewer(MainWindow *main_win) |
| 583 | { |
| 584 | LttvAttributeValue value; |
| 585 | LttvHooks * tmp; |
| 586 | g_assert(lttv_iattribute_find_by_path(main_win->current_tab->attributes, |
| 587 | "hooks/showviewer", LTTV_POINTER, &value)); |
| 588 | tmp = (LttvHooks*)*(value.v_pointer); |
| 589 | if(tmp == NULL) return; |
| 590 | lttv_hooks_call(tmp, NULL); |
| 591 | } |
| 592 | |
| 593 | |
| 594 | /** |
| 595 | * Function to set the focused pane (viewer). |
| 596 | * It will be called by a viewer's signal handle associated with |
| 597 | * the grab_focus signal |
| 598 | * @param main_win the main window the viewer belongs to. |
| 599 | * @param paned a pointer to a pane where the viewer is contained. |
| 600 | */ |
| 601 | |
| 602 | void set_focused_pane(MainWindow *main_win, gpointer paned) |
| 603 | { |
| 604 | gtk_multi_vpaned_set_focus((GtkWidget*)main_win->current_tab->multi_vpaned,paned); |
| 605 | } |
| 606 | |
| 607 | |
| 608 | /** |
| 609 | * Function to register a hook function for a viewer to set/update the |
| 610 | * dividor of the hpane. |
| 611 | * It will be called by the constructor of the viewer. |
| 612 | * @param hook hook function of the viewer. |
| 613 | * @param hook_data hook data associated with the hook function. |
| 614 | * @param main_win the main window the viewer belongs to. |
| 615 | */ |
| 616 | |
| 617 | void reg_update_dividor(LttvHook hook, gpointer hook_data, |
| 618 | MainWindow *main_win) |
| 619 | { |
| 620 | LttvAttributeValue value; |
| 621 | LttvHooks * tmp; |
| 622 | g_assert(lttv_iattribute_find_by_path(main_win->current_tab->attributes, |
| 623 | "hooks/hpanedividor", LTTV_POINTER, &value)); |
| 624 | tmp = (LttvHooks*)*(value.v_pointer); |
| 625 | if(tmp == NULL){ |
| 626 | tmp = lttv_hooks_new(); |
| 627 | *(value.v_pointer) = tmp; |
| 628 | } |
| 629 | lttv_hooks_add(tmp, hook, hook_data); |
| 630 | } |
| 631 | |
| 632 | |
| 633 | /** |
| 634 | * Function to unregister a viewer's hook function which is used to |
| 635 | * set/update hpane's dividor of the viewer. |
| 636 | * It will be called by the destructor of the viewer. |
| 637 | * @param hook hook function of the viewer. |
| 638 | * @param hook_data hook data associated with the hook function. |
| 639 | * @param main_win the main window the viewer belongs to. |
| 640 | */ |
| 641 | |
| 642 | void unreg_update_dividor(LttvHook hook, gpointer hook_data, |
| 643 | MainWindow *main_win) |
| 644 | { |
| 645 | LttvAttributeValue value; |
| 646 | LttvHooks * tmp; |
| 647 | g_assert(lttv_iattribute_find_by_path(main_win->current_tab->attributes, |
| 648 | "hooks/hpanedividor", LTTV_POINTER, &value)); |
| 649 | tmp = (LttvHooks*)*(value.v_pointer); |
| 650 | if(tmp == NULL) return; |
| 651 | lttv_hooks_remove_data(tmp, hook, hook_data); |
| 652 | } |
| 653 | |
| 654 | |
| 655 | /** |
| 656 | * Function to set the position of the hpane's dividor (viewer). |
| 657 | * It will be called by a viewer's signal handle associated with |
| 658 | * the motion_notify_event event/signal |
| 659 | * @param main_win the main window the viewer belongs to. |
| 660 | * @param position position of the hpane's dividor. |
| 661 | */ |
| 662 | |
| 663 | void set_hpane_dividor(MainWindow *main_win, gint position) |
| 664 | { |
| 665 | LttvAttributeValue value; |
| 666 | LttvHooks * tmp; |
| 667 | g_assert(lttv_iattribute_find_by_path(main_win->current_tab->attributes, |
| 668 | "hooks/hpanedividor", LTTV_POINTER, &value)); |
| 669 | tmp = (LttvHooks*)*(value.v_pointer); |
| 670 | if(tmp == NULL) return; |
| 671 | lttv_hooks_call(tmp, &position); |
| 672 | } |
| 673 | |
| 674 | |
| 675 | /** |
| 676 | * Function to process traceset. It will call lttv_process_trace, |
| 677 | * each view will call this api to get events. |
| 678 | * @param main_win the main window the viewer belongs to. |
| 679 | * @param start the start time of the first event to be processed. |
| 680 | * @param end the end time of the last event to be processed. |
| 681 | */ |
| 682 | |
| 683 | void process_traceset_api(MainWindow *main_win, LttTime start, |
| 684 | LttTime end, unsigned maxNumEvents) |
| 685 | { |
| 686 | lttv_process_traceset_seek_time( |
| 687 | LTTV_TRACESET_CONTEXT(main_win->current_tab->traceset_info-> |
| 688 | traceset_context), |
| 689 | start); |
| 690 | lttv_process_traceset( |
| 691 | LTTV_TRACESET_CONTEXT(main_win->current_tab->traceset_info-> |
| 692 | traceset_context), |
| 693 | end, |
| 694 | maxNumEvents); |
| 695 | } |
| 696 | |
| 697 | /** |
| 698 | * Function to add hooks into the context of a traceset, |
| 699 | * before reading events from traceset, viewer will call this api to |
| 700 | * register hooks |
| 701 | * @param main_win the main window the viewer belongs to. |
| 702 | * @param LttvHooks hooks to be registered. |
| 703 | */ |
| 704 | |
| 705 | void context_add_hooks_api(MainWindow *main_win , |
| 706 | LttvHooks *before_traceset, |
| 707 | LttvHooks *after_traceset, |
| 708 | LttvHooks *check_trace, |
| 709 | LttvHooks *before_trace, |
| 710 | LttvHooks *after_trace, |
| 711 | LttvHooks *check_tracefile, |
| 712 | LttvHooks *before_tracefile, |
| 713 | LttvHooks *after_tracefile, |
| 714 | LttvHooks *check_event, |
| 715 | LttvHooks *before_event, |
| 716 | LttvHooks *after_event) |
| 717 | { |
| 718 | LttvTracesetContext * tsc = |
| 719 | LTTV_TRACESET_CONTEXT(main_win->current_tab->traceset_info-> |
| 720 | traceset_context); |
| 721 | lttv_traceset_context_add_hooks(tsc,before_traceset,after_traceset, |
| 722 | check_trace,before_trace,after_trace, |
| 723 | check_tracefile,before_tracefile,after_tracefile, |
| 724 | check_event,before_event, after_event); |
| 725 | } |
| 726 | |
| 727 | |
| 728 | /** |
| 729 | * Function to remove hooks from the context of a traceset, |
| 730 | * before reading events from traceset, viewer will call this api to |
| 731 | * unregister hooks |
| 732 | * @param main_win the main window the viewer belongs to. |
| 733 | * @param LttvHooks hooks to be registered. |
| 734 | */ |
| 735 | |
| 736 | void context_remove_hooks_api(MainWindow *main_win , |
| 737 | LttvHooks *before_traceset, |
| 738 | LttvHooks *after_traceset, |
| 739 | LttvHooks *check_trace, |
| 740 | LttvHooks *before_trace, |
| 741 | LttvHooks *after_trace, |
| 742 | LttvHooks *check_tracefile, |
| 743 | LttvHooks *before_tracefile, |
| 744 | LttvHooks *after_tracefile, |
| 745 | LttvHooks *check_event, |
| 746 | LttvHooks *before_event, |
| 747 | LttvHooks *after_event) |
| 748 | { |
| 749 | LttvTracesetContext * tsc = |
| 750 | LTTV_TRACESET_CONTEXT(main_win->current_tab->traceset_info->traceset_context); |
| 751 | lttv_traceset_context_remove_hooks(tsc,before_traceset,after_traceset, |
| 752 | check_trace,before_trace,after_trace, |
| 753 | check_tracefile,before_tracefile,after_tracefile, |
| 754 | check_event,before_event, after_event); |
| 755 | } |
| 756 | |
| 757 | |
| 758 | /** |
| 759 | * Function to add/remove event hooks for state |
| 760 | * @param main_win the main window the viewer belongs to. |
| 761 | */ |
| 762 | |
| 763 | void state_add_event_hooks_api(MainWindow *main_win ) |
| 764 | { |
| 765 | lttv_state_add_event_hooks( |
| 766 | (LttvTracesetState*)main_win->current_tab->traceset_info->traceset_context); |
| 767 | } |
| 768 | |
| 769 | void state_remove_event_hooks_api(MainWindow *main_win ) |
| 770 | { |
| 771 | lttv_state_remove_event_hooks( |
| 772 | (LttvTracesetState*)main_win->current_tab->traceset_info->traceset_context); |
| 773 | } |
| 774 | |
| 775 | |
| 776 | /** |
| 777 | * Function to add/remove event hooks for stats |
| 778 | * @param main_win the main window the viewer belongs to. |
| 779 | */ |
| 780 | |
| 781 | void stats_add_event_hooks_api(MainWindow *main_win ) |
| 782 | { |
| 783 | lttv_stats_add_event_hooks( |
| 784 | (LttvTracesetStats*)main_win->current_tab->traceset_info->traceset_context); |
| 785 | } |
| 786 | |
| 787 | void stats_remove_event_hooks_api(MainWindow *main_win ) |
| 788 | { |
| 789 | lttv_stats_remove_event_hooks( |
| 790 | (LttvTracesetStats*)main_win->current_tab->traceset_info->traceset_context); |
| 791 | } |
| 792 | |
| 793 | /** |
| 794 | * Function to get the stats of the traceset |
| 795 | * @param main_win the main window the viewer belongs to. |
| 796 | */ |
| 797 | |
| 798 | LttvTracesetStats* get_traceset_stats_api(MainWindow *main_win) |
| 799 | { |
| 800 | return main_win->current_tab->traceset_info->traceset_context; |
| 801 | } |
| 802 | |
| 803 | |
| 804 | LttvTracesetContext* get_traceset_context(MainWindow *main_win) |
| 805 | { |
| 806 | return (LttvTracesetContext*)main_win->current_tab->traceset_info->traceset_context; |
| 807 | } |