X-Git-Url: http://git.lttng.org/?a=blobdiff_plain;f=ltt%2Fbranches%2Fpoly%2Flttv%2Fmodules%2Fgui%2Flttvwindow%2Flttvwindow%2Fcallbacks.c;h=f42e5ea2ae7594cec40929fa8a92405cf8a7b17f;hb=0ddddd9112f15fd24249889362417a48945e5e14;hp=ecbde8e751c62092a8cdce4c1fcfd31c80b22bc2;hpb=784705ccc31109fe1befc593baf9643eb9d530da;p=lttv.git diff --git a/ltt/branches/poly/lttv/modules/gui/lttvwindow/lttvwindow/callbacks.c b/ltt/branches/poly/lttv/modules/gui/lttvwindow/lttvwindow/callbacks.c index ecbde8e7..f42e5ea2 100644 --- a/ltt/branches/poly/lttv/modules/gui/lttvwindow/lttvwindow/callbacks.c +++ b/ltt/branches/poly/lttv/modules/gui/lttvwindow/lttvwindow/callbacks.c @@ -25,17 +25,20 @@ #include "callbacks.h" #include "interface.h" #include "support.h" +#include +#include +#include +#include #include +#include +#include +#include #include #include #include #include -#include #include -#include #include -#include -#include #define PATH_LENGTH 256 #define DEFAULT_TIME_WIDTH_S 1 @@ -48,7 +51,7 @@ extern GSList * g_main_window_list; static int g_win_count = 0; -// MD : keep old directory +/** MD : keep old directory. */ static char remember_plugins_dir[PATH_LENGTH] = ""; static char remember_trace_dir[PATH_LENGTH] = ""; @@ -61,7 +64,7 @@ gboolean get_filter_selection(LttvTracesetSelector *s, char *title, char * colum void * create_tab(MainWindow * parent, MainWindow * current_window, GtkNotebook * notebook, char * label); -void insert_viewer(GtkWidget* widget, view_constructor constructor); +void insert_viewer(GtkWidget* widget, lttvwindow_viewer_constructor constructor); void update_filter(LttvTracesetSelector *s, GtkTreeStore *store ); void checkbox_changed(GtkTreeView *treeview, @@ -73,7 +76,7 @@ void add_trace_into_traceset_selector(GtkMultiVPaned * paned, LttTrace * trace); LttvTracesetSelector * construct_traceset_selector(LttvTraceset * traceset); -void redraw_viewer(MainWindow * mw_data, TimeWindow * time_window); +void call_pending_read_hooks(MainWindow * mw_data); unsigned get_max_event_number(MainWindow * mw_data); enum { @@ -153,20 +156,19 @@ insert_viewer_wrap(GtkWidget *menuitem, gpointer user_data) { guint val = 20; - insert_viewer((GtkWidget*)menuitem, (view_constructor)user_data); + insert_viewer((GtkWidget*)menuitem, (lttvwindow_viewer_constructor)user_data); // selected_hook(&val); } /* internal functions */ -void insert_viewer(GtkWidget* widget, view_constructor constructor) +void insert_viewer(GtkWidget* widget, lttvwindow_viewer_constructor constructor) { GtkMultiVPaned * multi_vpaned; MainWindow * mw_data; GtkWidget * viewer; LttvTracesetSelector * s; TimeInterval * time_interval; - TimeWindow time_window, t; mw_data = get_window_data_struct(widget); if(!mw_data->current_tab) return; @@ -177,22 +179,17 @@ void insert_viewer(GtkWidget* widget, view_constructor constructor) if(viewer) { gtk_multi_vpaned_widget_add(multi_vpaned, viewer); - // Added by MD - // g_object_unref(G_OBJECT(viewer)); - - time_window = mw_data->current_tab->time_window; - time_interval = (TimeInterval*)g_object_get_data(G_OBJECT(viewer), TRACESET_TIME_SPAN); - if(time_interval){ - t = time_window; - time_window.start_time = time_interval->startTime; - time_window.time_width = ltt_time_sub(time_interval->endTime,time_interval->startTime); - } - - redraw_viewer(mw_data,&time_window); - set_current_time(mw_data,&(mw_data->current_tab->current_time)); - if(time_interval){ - set_time_window(mw_data,&t); - } + // We unref here, because it is now referenced by the multi_vpaned! + g_object_unref(G_OBJECT(viewer)); + + // The viewer will show itself when it receives a show notify + // So we call the show notify hooks here. It will + // typically add hooks for reading, we call process trace, and the + // end of reading hook will call gtk_widget_show and unregister the + // hooks. + // Note that show notify gets the time_requested through the call_data. + //show_viewer(mw_data); + // in expose now call_pending_read_hooks(mw_data); } } @@ -319,6 +316,7 @@ void delete_viewer(GtkWidget * widget, gpointer user_data) /* open_traceset will open a traceset saved in a file * Right now, it is not finished yet, (not working) + * FIXME */ void open_traceset(GtkWidget * widget, gpointer user_data) @@ -377,17 +375,41 @@ unsigned get_max_event_number(MainWindow * mw_data) } -/* redraw_viewer parses the traceset first by calling - * process_traceset_api, then display all viewers of +/* call_pending_read_hooks parses the traceset first by calling + * process_traceset, then display all viewers of * the current tab + * It will then remove all entries from the time_requests array. + * CHECK : we give more events than requested to the viewers. They + * Have to filter them by themselves. */ -void redraw_viewer(MainWindow * mw_data, TimeWindow * time_window) +gint compare_time_request(TimeRequest *a, TimeRequest *b) +{ + return ltt_time_compare(a->time_window.start_time, b->time_window.start_time); +} + +void call_pending_read_hooks(MainWindow * mw_data) { unsigned max_nb_events; GdkWindow * win; GdkCursor * new; GtkWidget* widget; + int i; + LttvTracesetContext *tsc; + + /* Current tab check : if no current tab is present, no hooks to call. */ + /* It makes the expose works.. */ + if(mw_data->current_tab == NULL) + return; + + if(mw_data->current_tab->time_requests->len == 0) + return; + + LttvHooks *tmp_hooks = lttv_hooks_new(); + + tsc = + LTTV_TRACESET_CONTEXT(mw_data->current_tab->traceset_info-> + traceset_context); //set the cursor to be X shape, indicating that the computer is busy in doing its job new = gdk_cursor_new(GDK_X_CURSOR); @@ -397,19 +419,79 @@ void redraw_viewer(MainWindow * mw_data, TimeWindow * time_window) gdk_cursor_unref(new); gdk_window_stick(win); gdk_window_unstick(win); - + + + g_array_sort(mw_data->current_tab->time_requests, + (GCompareFunc)compare_time_request); + + //update time window of each viewer, let viewer insert hooks needed by process_traceset - set_time_window(mw_data, time_window); + //lttvwindow_report_time_window(mw_data, time_window); - max_nb_events = get_max_event_number(mw_data); - - process_traceset_api(mw_data, time_window->start_time, - ltt_time_add(time_window->start_time,time_window->time_width), - max_nb_events); + //max_nb_events = get_max_event_number(mw_data); //call hooks to show each viewer and let them remove hooks - show_viewer(mw_data); + //show_viewer(mw_data); + + // FIXME + // call process trace for each time interval + // Will have to be combined! + g_critical("SIZE time req len : %d", mw_data->current_tab->time_requests->len); + + //g_assert(mw_data->current_tab->time_requests->len <= 1); //FIXME + /* Go through each time request. As they are already sorted by start_time, + * we check with the current event time if processing is needed. */ + for(i=0; i < mw_data->current_tab->time_requests->len; i++) + { + g_critical("RUN i %d", i); + TimeRequest *time_request = + &g_array_index(mw_data->current_tab->time_requests, TimeRequest, i); + LttTime end_time = ltt_time_add( time_request->time_window.start_time, + time_request->time_window.time_width); + + if(i == 0 || !(ltt_time_compare(time_request->time_window.start_time, ltt_event_time(tsc->e))<0) ) + { + /* do it if first request or start_time >= last event's time */ + lttv_process_traceset_seek_time(tsc, time_request->time_window.start_time); + lttv_process_traceset(tsc, end_time, time_request->num_events); + } + else + { + if(ltt_time_compare(time_request->time_window.start_time, ltt_event_time(tsc->e))<0 + && !(ltt_time_compare(end_time, ltt_event_time(tsc->e))<0)) + { + /* Continue reading from current event */ + lttv_process_traceset(tsc, end_time, time_request->num_events); + } + else + { + if(ltt_time_compare(time_request->time_window.start_time, end_time) > 0) + { + /* This is a request for a minimum number of events, give + * more events than necessary */ + lttv_process_traceset(tsc, end_time, time_request->num_events); + } + } + } + + /* Call the end of process_traceset hook */ + lttv_hooks_add(tmp_hooks, + time_request->after_hook, + time_request->after_hook_data); + lttv_hooks_call(tmp_hooks, time_request); + lttv_hooks_remove(tmp_hooks, time_request->after_hook); + } + + /* Free the time requests */ + g_array_free(mw_data->current_tab->time_requests, TRUE); + mw_data->current_tab->time_requests = + g_array_new(FALSE, FALSE, sizeof(TimeRequest)); + + mw_data->current_tab->time_request_pending = FALSE; + + lttv_hooks_destroy(tmp_hooks); + //set the cursor back to normal gdk_window_set_cursor(win, NULL); } @@ -483,6 +565,7 @@ void add_trace(GtkWidget * widget, gpointer user_data) LttvTraceset * traceset; const char * dir; gint id; + gint i; MainWindow * mw_data = get_window_data_struct(widget); GtkDirSelection * file_selector = (GtkDirSelection *)gtk_dir_selection_new("Select a trace"); gtk_dir_selection_hide_fileop_buttons(file_selector); @@ -495,54 +578,82 @@ void add_trace(GtkWidget * widget, gpointer user_data) case GTK_RESPONSE_OK: dir = gtk_dir_selection_get_dir (file_selector); strncpy(remember_trace_dir, dir, PATH_LENGTH); - if(!dir || strlen(dir) ==0){ - gtk_widget_destroy((GtkWidget*)file_selector); - break; + if(!dir || strlen(dir) == 0){ + gtk_widget_destroy((GtkWidget*)file_selector); + break; } trace = ltt_trace_open(dir); if(trace == NULL) g_critical("cannot open trace %s", dir); trace_v = lttv_trace_new(trace); traceset = mw_data->current_tab->traceset_info->traceset; - if(mw_data->current_tab->traceset_info->traceset_context != NULL){ + + //Keep a reference to the traces so they are not freed. + for(i=0; icurrent_tab->traceset_info-> - traceset_context); - lttv_context_fini(LTTV_TRACESET_CONTEXT(mw_data->current_tab-> - traceset_info->traceset_context)); - g_object_unref(mw_data->current_tab->traceset_info->traceset_context); - } + (LttvTracesetState*)mw_data->current_tab->traceset_info->traceset_context); + + lttv_context_fini(LTTV_TRACESET_CONTEXT( + mw_data->current_tab->traceset_info->traceset_context)); + g_object_unref(mw_data->current_tab->traceset_info->traceset_context); + + lttv_traceset_add(traceset, trace_v); + + /* Create new context */ mw_data->current_tab->traceset_info->traceset_context = - g_object_new(LTTV_TRACESET_STATS_TYPE, NULL); + g_object_new(LTTV_TRACESET_STATS_TYPE, NULL); lttv_context_init( - LTTV_TRACESET_CONTEXT(mw_data->current_tab->traceset_info-> - traceset_context),traceset); + LTTV_TRACESET_CONTEXT(mw_data->current_tab->traceset_info-> + traceset_context), + traceset); //add state update hooks lttv_state_add_event_hooks( (LttvTracesetState*)mw_data->current_tab->traceset_info->traceset_context); - - + //Remove local reference to the traces. + for(i=0; icurrent_tab->multi_vpaned, trace); gtk_widget_destroy((GtkWidget*)file_selector); //update current tab - update_traceset(mw_data); - - get_traceset_time_span(mw_data,LTTV_TRACESET_CONTEXT(mw_data->current_tab->traceset_info->traceset_context)->Time_Span); - if(lttv_traceset_number(mw_data->current_tab->traceset_info->traceset) == 1 || - ltt_time_compare(mw_data->current_tab->current_time, - LTTV_TRACESET_CONTEXT(mw_data->current_tab->traceset_info->traceset_context)->Time_Span->startTime)<0){ - mw_data->current_tab->current_time = - LTTV_TRACESET_CONTEXT(mw_data->current_tab->traceset_info->traceset_context)->Time_Span->startTime; - mw_data->current_tab->time_window.start_time = mw_data->current_tab->current_time; - mw_data->current_tab->time_window.time_width.tv_sec = DEFAULT_TIME_WIDTH_S; - mw_data->current_tab->time_window.time_width.tv_nsec = 0; + //update_traceset(mw_data); + + //get_traceset_time_span(mw_data,LTTV_TRACESET_CONTEXT(mw_data->current_tab->traceset_info->traceset_context)->Time_Span); + if( + lttv_traceset_number(mw_data->current_tab->traceset_info->traceset) == 1 + || ltt_time_compare(mw_data->current_tab->current_time, + LTTV_TRACESET_CONTEXT(mw_data->current_tab->traceset_info-> + traceset_context)->Time_Span->startTime)<0) + { + /* Set initial time if this is the first trace in the traceset */ + mw_data->current_tab->current_time = + LTTV_TRACESET_CONTEXT(mw_data->current_tab->traceset_info-> + traceset_context)->Time_Span->startTime; + mw_data->current_tab->time_window.start_time = + mw_data->current_tab->current_time; + mw_data->current_tab->time_window.time_width.tv_sec = + DEFAULT_TIME_WIDTH_S; + mw_data->current_tab->time_window.time_width.tv_nsec = 0; } - redraw_viewer(mw_data, &(mw_data->current_tab->time_window)); - set_current_time(mw_data,&(mw_data->current_tab->current_time)); + /* Call the updatetraceset hooks */ + + SetTraceset(mw_data, (gpointer)traceset); + // in expose now call_pending_read_hooks(mw_data); + + //lttvwindow_report_current_time(mw_data,&(mw_data->current_tab->current_time)); break; case GTK_RESPONSE_REJECT: case GTK_RESPONSE_CANCEL: @@ -591,7 +702,7 @@ void remove_trace(GtkWidget * widget, gpointer user_data) LttTrace *trace; LttvTrace * trace_v; LttvTraceset * traceset; - gint i, nb_trace; + gint i, j, nb_trace; char ** name, *remove_trace_name; MainWindow * mw_data = get_window_data_struct(widget); LttvTracesetSelector * s; @@ -644,31 +755,50 @@ void remove_trace(GtkWidget * widget, gpointer user_data) if(lttv_trace_get_ref_number(trace_v) <= 1) ltt_trace_close(lttv_trace(trace_v)); - if(mw_data->current_tab->traceset_info->traceset_context != NULL){ - //remove state update hooks - lttv_state_remove_event_hooks( - (LttvTracesetState*)mw_data->current_tab->traceset_info-> - traceset_context); - lttv_context_fini(LTTV_TRACESET_CONTEXT(mw_data->current_tab-> - traceset_info->traceset_context)); - g_object_unref(mw_data->current_tab->traceset_info->traceset_context); - } + //Keep a reference to the traces so they are not freed. + for(j=0; jcurrent_tab->traceset_info->traceset_context); + lttv_context_fini(LTTV_TRACESET_CONTEXT(mw_data->current_tab->traceset_info->traceset_context)); + g_object_unref(mw_data->current_tab->traceset_info->traceset_context); + + lttv_traceset_remove(traceset, i); + lttv_trace_unref(trace_v); // Remove local reference if(!lttv_trace_get_ref_number(trace_v)) lttv_trace_destroy(trace_v); + mw_data->current_tab->traceset_info->traceset_context = g_object_new(LTTV_TRACESET_STATS_TYPE, NULL); - lttv_context_init( + lttv_context_init( LTTV_TRACESET_CONTEXT(mw_data->current_tab-> traceset_info->traceset_context),traceset); //add state update hooks - lttv_state_add_event_hooks( + lttv_state_add_event_hooks( (LttvTracesetState*)mw_data->current_tab->traceset_info->traceset_context); + + //Remove local reference to the traces. + for(j=0; j 1){ - redraw_viewer(mw_data, &(mw_data->current_tab->time_window)); - set_current_time(mw_data,&(mw_data->current_tab->current_time)); + + SetTraceset(mw_data, (gpointer)traceset); + // in expose now call_pending_read_hooks(mw_data); + + //lttvwindow_report_current_time(mw_data,&(mw_data->current_tab->current_time)); }else{ if(mw_data->current_tab){ while(mw_data->current_tab->multi_vpaned->num_children){ @@ -687,7 +817,7 @@ void remove_trace(GtkWidget * widget, gpointer user_data) /* save will save the traceset to a file - * Not implemented yet + * Not implemented yet FIXME */ void save(GtkWidget * widget, gpointer user_data) @@ -709,44 +839,77 @@ void save_as(GtkWidget * widget, gpointer user_data) void zoom(GtkWidget * widget, double size) { TimeInterval *time_span; - TimeWindow time_window; - LttTime current_time, time_delta, time_s, time_e, time_t; + TimeWindow new_time_window; + LttTime current_time, time_delta, time_s, time_e, time_tmp; MainWindow * mw_data = get_window_data_struct(widget); if(size == 1) return; time_span = LTTV_TRACESET_CONTEXT(mw_data->current_tab-> traceset_info->traceset_context)->Time_Span; - time_window = mw_data->current_tab->time_window; + new_time_window = mw_data->current_tab->time_window; current_time = mw_data->current_tab->current_time; time_delta = ltt_time_sub(time_span->endTime,time_span->startTime); if(size == 0){ - time_window.start_time = time_span->startTime; - time_window.time_width = time_delta; + new_time_window.start_time = time_span->startTime; + new_time_window.time_width = time_delta; }else{ - time_window.time_width = ltt_time_div(time_window.time_width, size); - if(ltt_time_compare(time_window.time_width,time_delta) > 0) - time_window.time_width = time_delta; - - time_t = ltt_time_div(time_window.time_width, 2); - if(ltt_time_compare(current_time, time_t) < 0){ - time_s = time_span->startTime; - } else { - time_s = ltt_time_sub(current_time,time_t); + new_time_window.time_width = ltt_time_div(new_time_window.time_width, size); + if(ltt_time_compare(new_time_window.time_width,time_delta) > 0) + { /* Case where zoom out is bigger than trace length */ + new_time_window.start_time = time_span->startTime; + new_time_window.time_width = time_delta; } - time_e = ltt_time_add(current_time,time_t); - if(ltt_time_compare(time_span->startTime, time_s) > 0){ - time_s = time_span->startTime; - }else if(ltt_time_compare(time_span->endTime, time_e) < 0){ - time_e = time_span->endTime; - time_s = ltt_time_sub(time_e,time_window.time_width); + else + { + /* Center the image on the current time */ + g_critical("update is HERE"); + new_time_window.start_time = + ltt_time_sub(current_time, ltt_time_div(new_time_window.time_width, 2.0)); + /* If on borders, don't fall off */ + if(ltt_time_compare(new_time_window.start_time, time_span->startTime) <0) + { + new_time_window.start_time = time_span->startTime; + } + else + { + if(ltt_time_compare( + ltt_time_add(new_time_window.start_time, new_time_window.time_width), + time_span->endTime) > 0) + { + new_time_window.start_time = + ltt_time_sub(time_span->endTime, new_time_window.time_width); + } + } + } - time_window.start_time = time_s; + + + + //time_tmp = ltt_time_div(new_time_window.time_width, 2); + //if(ltt_time_compare(current_time, time_tmp) < 0){ + // time_s = time_span->startTime; + //} else { + // time_s = ltt_time_sub(current_time,time_tmp); + //} + //time_e = ltt_time_add(current_time,time_tmp); + //if(ltt_time_compare(time_span->startTime, time_s) > 0){ + // time_s = time_span->startTime; + //}else if(ltt_time_compare(time_span->endTime, time_e) < 0){ + // time_e = time_span->endTime; + // time_s = ltt_time_sub(time_e,new_time_window.time_width); + //} + //new_time_window.start_time = time_s; } - redraw_viewer(mw_data, &time_window); - set_current_time(mw_data,&(mw_data->current_tab->current_time)); - gtk_multi_vpaned_set_adjust(mw_data->current_tab->multi_vpaned, FALSE); + + //lttvwindow_report_time_window(mw_data, &new_time_window); + //call_pending_read_hooks(mw_data); + + //lttvwindow_report_current_time(mw_data,&(mw_data->current_tab->current_time)); + set_time_window(mw_data, &new_time_window); + // in expose now call_pending_read_hooks(mw_data); + gtk_multi_vpaned_set_adjust(mw_data->current_tab->multi_vpaned, &new_time_window, FALSE); } void zoom_in(GtkWidget * widget, gpointer user_data) @@ -807,7 +970,7 @@ void create_new_tab(GtkWidget* widget, gpointer user_data){ strcpy(label,"Page"); if(get_label(mw_data, label,"Get the name of the tab","Please input tab's name")) - create_tab (mw_data, mw_data, notebook, label); + create_tab (NULL, mw_data, notebook, label); } void @@ -1022,9 +1185,10 @@ on_trace_filter_activate (GtkMenuItem *menuitem, return; } if(get_filter_selection(s, "Configure trace and tracefile filter", "Select traces and tracefiles")){ - update_traceset(mw_data); - redraw_viewer(mw_data, &(mw_data->current_tab->time_window)); - set_current_time(mw_data,&(mw_data->current_tab->current_time)); + //FIXME report filter change + //update_traceset(mw_data); + //call_pending_read_hooks(mw_data); + //lttvwindow_report_current_time(mw_data,&(mw_data->current_tab->current_time)); } } @@ -1069,8 +1233,6 @@ on_load_module_activate (GtkMenuItem *menuitem, str1++; } lttv_module_require(str1, NULL); - g_slist_foreach(g_main_window_list, (gpointer)insert_menu_toolbar_item, - NULL); g_strfreev(dir); case GTK_RESPONSE_REJECT: case GTK_RESPONSE_CANCEL: @@ -1114,7 +1276,7 @@ on_unload_module_activate (GtkMenuItem *menuitem, library = lttv_library_get(i); lttv_library_info(library, &library_info); if(strcmp(unload_module_name, library_info.name) == 0){ - lttv_library_unload(library); + lttv_library_unload(library); break; } } @@ -1317,13 +1479,34 @@ void on_MWindow_destroy (GtkObject *object, gpointer user_data) { - MainWindow *Main_Window = get_window_data_struct((GtkWidget*)object); + MainWindow *main_window = get_window_data_struct((GtkWidget*)object); GtkWidget *widget; - Tab *tab = Main_Window->tab; + Tab *tab = main_window->tab; + LttvIAttribute *attributes = main_window->attributes; + LttvAttributeValue value; - g_printf("There are : %d windows\n",g_slist_length(g_main_window_list)); + //This is unnecessary, since widgets will be destroyed + //by the main window widget anyway. + //remove_all_menu_toolbar_constructors(main_window, NULL); + + g_assert(lttv_iattribute_find_by_path(attributes, + "viewers/menu", LTTV_POINTER, &value)); + lttv_menus_destroy((LttvMenus*)*(value.v_pointer)); + + g_assert(lttv_iattribute_find_by_path(attributes_global, + "viewers/toolbar", LTTV_POINTER, &value)); + lttv_toolbars_destroy((LttvToolbars*)*(value.v_pointer)); + + while(main_window->tab){ + lttv_state_remove_event_hooks( + (LttvTracesetState*)main_window->tab->traceset_info->traceset_context); + main_window->tab = main_window->tab->next; + } + g_object_unref(main_window->attributes); + g_main_window_list = g_slist_remove(g_main_window_list, main_window); g_win_count--; + g_printf("There are now : %d windows\n",g_slist_length(g_main_window_list)); if(g_win_count == 0) gtk_main_quit (); } @@ -1363,7 +1546,6 @@ on_MWindow_configure (GtkWidget *widget, return FALSE; } - /* Set current tab */ @@ -1710,87 +1892,108 @@ char * get_selection(char ** loaded_module_name, int nb_module, } -/* hash funtions - */ - -void main_window_destroy_hash_key(gpointer key) -{ - g_free(key); -} - -void main_window_destroy_hash_data(gpointer data) -{ -} - - -/* Insert menu entry and tool button into all main windows for modules - * It checks whether the menu entry or tool button exists or not, - * if they do not exist, then construct the widget and insert them - * into all main windows +/* Insert all menu entry and tool buttons into this main window + * for modules. + * */ -void insert_menu_toolbar_item(MainWindow * mw, gpointer user_data) +void add_all_menu_toolbar_constructors(MainWindow * mw, gpointer user_data) { int i; GdkPixbuf *pixbuf; - view_constructor constructor; - LttvMenus * menu; - LttvToolbars * toolbar; - lttv_menu_closure *menu_item; - lttv_toolbar_closure *toolbar_item; + lttvwindow_viewer_constructor constructor; + LttvMenus * global_menu, * instance_menu; + LttvToolbars * global_toolbar, * instance_toolbar; + LttvMenuClosure *menu_item; + LttvToolbarClosure *toolbar_item; LttvAttributeValue value; - LttvIAttribute *attributes = LTTV_IATTRIBUTE(lttv_global_attributes()); - GtkWidget * tool_menu_title_menu, *insert_view, *pixmap, *tmp; + LttvIAttribute *global_attributes = LTTV_IATTRIBUTE(lttv_global_attributes()); + LttvIAttribute *attributes = LTTV_IATTRIBUTES(mw->attributes); + GtkWidget * tool_menu_title_menu, *new_widget, *pixmap; + + g_assert(lttv_iattribute_find_by_path(global_attributes, + "viewers/menu", LTTV_POINTER, &value)); + if(*(value.v_pointer) == NULL) + (LttvMenus*)*(value.v_pointer) = lttv_menus_new(); + global_menu = (LttvMenus*)*(value.v_pointer); g_assert(lttv_iattribute_find_by_path(attributes, "viewers/menu", LTTV_POINTER, &value)); - menu = (LttvMenus*)*(value.v_pointer); - - if(menu){ - for(i=0;ilen;i++){ - menu_item = &g_array_index(menu, lttv_menu_closure, i); - tmp = g_hash_table_lookup(mw->hash_menu_item, g_strdup(menu_item->menuText)); - if(tmp)continue; - constructor = menu_item->con; - tool_menu_title_menu = lookup_widget(mw->mwindow,"ToolMenuTitle_menu"); - insert_view = gtk_menu_item_new_with_mnemonic (menu_item->menuText); - gtk_widget_show (insert_view); - gtk_container_add (GTK_CONTAINER (tool_menu_title_menu), insert_view); - g_signal_connect ((gpointer) insert_view, "activate", - G_CALLBACK (insert_viewer_wrap), - constructor); - g_hash_table_insert(mw->hash_menu_item, g_strdup(menu_item->menuText), - insert_view); - } - } + if(*(value.v_pointer) == NULL) + (LttvMenus*)*(value.v_pointer) = lttv_menus_new(); + instance_menu = (LttvMenus*)*(value.v_pointer); + + + + g_assert(lttv_iattribute_find_by_path(global_attributes, + "viewers/toolbar", LTTV_POINTER, &value)); + if(*(value.v_pointer) == NULL) + (LttvToolbars*)*(value.v_pointer) = lttv_toolbars_new(); + global_toolbar = (LttvToolbars*)*(value.v_pointer); g_assert(lttv_iattribute_find_by_path(attributes, "viewers/toolbar", LTTV_POINTER, &value)); - toolbar = (LttvToolbars*)*(value.v_pointer); - - if(toolbar){ - for(i=0;ilen;i++){ - toolbar_item = &g_array_index(toolbar, lttv_toolbar_closure, i); - tmp = g_hash_table_lookup(mw->hash_toolbar_item, g_strdup(toolbar_item->tooltip)); - if(tmp)continue; - constructor = toolbar_item->con; - tool_menu_title_menu = lookup_widget(mw->mwindow,"MToolbar1"); - pixbuf = gdk_pixbuf_new_from_xpm_data ((const char**)toolbar_item->pixmap); - pixmap = gtk_image_new_from_pixbuf(pixbuf); - insert_view = gtk_toolbar_append_element (GTK_TOOLBAR (tool_menu_title_menu), - GTK_TOOLBAR_CHILD_BUTTON, - NULL, - "", - toolbar_item->tooltip, NULL, - pixmap, NULL, NULL); - gtk_label_set_use_underline (GTK_LABEL (((GtkToolbarChild*) (g_list_last (GTK_TOOLBAR (tool_menu_title_menu)->children)->data))->label), TRUE); - gtk_widget_show (insert_view); - gtk_container_set_border_width (GTK_CONTAINER (insert_view), 1); - g_signal_connect ((gpointer) insert_view, "clicked",G_CALLBACK (insert_viewer_wrap),constructor); - g_hash_table_insert(mw->hash_toolbar_item, g_strdup(toolbar_item->tooltip), - insert_view); - } + if(*(value.v_pointer) == NULL) + (LttvToolbars*)*(value.v_pointer) = lttv_toolbars_new(); + instance_toolbar = (LttvToolbars*)*(value.v_pointer); + + /* Add missing menu entries to window instance */ + for(i=0;ilen;i++) { + menu_item = &g_array_index(global_menu, LttvMenuClosure, i); + + //add menu_item to window instance; + constructor = menu_item->con; + tool_menu_title_menu = lookup_widget(mw->mwindow,"ToolMenuTitle_menu"); + new_widget = + gtk_menu_item_new_with_mnemonic (menu_item->menuText); + gtk_container_add (GTK_CONTAINER (tool_menu_title_menu), + new_widget); + g_signal_connect ((gpointer) new_widget, "activate", + G_CALLBACK (insert_viewer_wrap), + constructor); + gtk_widget_show (new_widget); + lttv_menus_add(instance_menu, menu_item->con, + menu_item->menu_path, + menu_item->menu_text, + new_widget); + } + + /* Add missing toolbar entries to window instance */ + for(i=0;ilen;i++) { + toolbar_item = &g_array_index(global_toolbar, LttvToolbarClosure, i); + + //add toolbar_item to window instance; + constructor = toolbar_item->con; + tool_menu_title_menu = lookup_widget(mw->mwindow,"MToolbar1"); + pixbuf = gdk_pixbuf_new_from_xpm_data((const char**)toolbar_item->pixmap); + pixmap = gtk_image_new_from_pixbuf(pixbuf); + new_widget = + gtk_toolbar_append_element (GTK_TOOLBAR (tool_menu_title_menu), + GTK_TOOLBAR_CHILD_BUTTON, + NULL, + "", + toolbar_item->tooltip, NULL, + pixmap, NULL, NULL); + gtk_label_set_use_underline( + GTK_LABEL (((GtkToolbarChild*) ( + g_list_last (GTK_TOOLBAR + (tool_menu_title_menu)->children)->data))->label), + TRUE); + gtk_container_set_border_width (GTK_CONTAINER (new_widget), 1); + g_signal_connect ((gpointer) new_widget, + "clicked", + G_CALLBACK (insert_viewer_wrap), + constructor); + gtk_widget_show (new_widget); + + lttv_toolbars_add(instance_toolbar, toolbar_item->con, + toolbar_item->tooltip, + toolbar_item->pixmap, + new_widget); + + } + } @@ -1816,24 +2019,22 @@ void construct_main_window(MainWindow * parent) new_window = create_MWindow(); gtk_widget_show (new_window); - new_m_window->attributes = attributes; - new_m_window->mwindow = new_window; new_m_window->tab = NULL; new_m_window->current_tab = NULL; - new_m_window->attributes = LTTV_IATTRIBUTE(g_object_new(LTTV_ATTRIBUTE_TYPE, NULL)); + new_m_window->attributes = attributes; + + g_assert(lttv_iattribute_find_by_path(attributes, + "viewers/menu", LTTV_POINTER, &value)); + (LttvMenus*)*(value.v_pointer) = lttv_menus_new(); - new_m_window->hash_menu_item = g_hash_table_new_full (g_str_hash, g_str_equal, - main_window_destroy_hash_key, - main_window_destroy_hash_data); - new_m_window->hash_toolbar_item = g_hash_table_new_full (g_str_hash, g_str_equal, - main_window_destroy_hash_key, - main_window_destroy_hash_data); + g_assert(lttv_iattribute_find_by_path(attributes_global, + "viewers/toolbar", LTTV_POINTER, &value)); + (LttvToolbars*)*(value.v_pointer) = lttv_toolbars_new(); - insert_menu_toolbar_item(new_m_window, NULL); + add_all_menu_toolbar_constructors(new_m_window, NULL); g_object_set_data(G_OBJECT(new_window), "mainWindow", (gpointer)new_m_window); - //create a default tab notebook = (GtkNotebook *)lookup_widget(new_m_window->mwindow, "MNotebook"); if(notebook == NULL){ @@ -1842,15 +2043,16 @@ void construct_main_window(MainWindow * parent) } //for now there is no name field in LttvTraceset structure //Use "Traceset" as the label for the default tab - create_tab(parent, new_m_window, notebook,"Traceset"); + create_tab(parent, new_m_window, notebook, "Traceset"); g_object_set_data_full( G_OBJECT(new_m_window->mwindow), "Main_Window_Data", new_m_window, - (GDestroyNotify)main_window_free); + NULL); g_win_count++; + g_printf("There are now : %d windows\n",g_slist_length(g_main_window_list)); } @@ -1898,7 +2100,8 @@ void tab_destructor(Tab * tab_instance) // lttv_trace_destroy(trace); } } - lttv_traceset_destroy(tab_instance->traceset_info->traceset); + lttv_traceset_destroy(tab_instance->traceset_info->traceset); + g_array_free(tab_instance->time_requests, TRUE); g_free(tab_instance->traceset_info); g_free(tab_instance); } @@ -1914,7 +2117,7 @@ void * create_tab(MainWindow * parent, MainWindow* current_window, Tab * tmp_tab; MainWindow * mw_data = current_window; LttTime tmp_time; - + //create a new tab data structure tmp_tab = mw_data->tab; while(tmp_tab && tmp_tab->next) tmp_tab = tmp_tab->next; @@ -1930,22 +2133,32 @@ void * create_tab(MainWindow * parent, MainWindow* current_window, //construct and initialize the traceset_info tmp_tab->traceset_info = g_new(TracesetInfo,1); if(parent){ - tmp_tab->traceset_info->traceset = - lttv_traceset_copy(parent->current_tab->traceset_info->traceset); - }else{ + if(parent->current_tab){ + tmp_tab->traceset_info->traceset = + lttv_traceset_new(); + //FIXME lttv_traceset_copy(parent->current_tab->traceset_info->traceset); + }else{ + tmp_tab->traceset_info->traceset = lttv_traceset_new(); + } + + }else{ /* Initial window */ if(mw_data->current_tab){ tmp_tab->traceset_info->traceset = - lttv_traceset_copy(mw_data->current_tab->traceset_info->traceset); + lttv_traceset_new(); + //FIXME lttv_traceset_copy(mw_data->current_tab->traceset_info->traceset); }else{ tmp_tab->traceset_info->traceset = lttv_traceset_new(); /* Add the command line trace */ - if(g_init_trace != NULL) + if(g_init_trace != NULL){ lttv_traceset_add(tmp_tab->traceset_info->traceset, g_init_trace); + } } } + //FIXME copy not implemented in lower level tmp_tab->traceset_info->traceset_context = g_object_new(LTTV_TRACESET_STATS_TYPE, NULL); + g_assert(tmp_tab->traceset_info->traceset_context != NULL); lttv_context_init( LTTV_TRACESET_CONTEXT(tmp_tab->traceset_info->traceset_context), tmp_tab->traceset_info->traceset); @@ -1953,7 +2166,6 @@ void * create_tab(MainWindow * parent, MainWindow* current_window, lttv_state_add_event_hooks( (LttvTracesetState*)tmp_tab->traceset_info->traceset_context); - //determine the current_time and time_window of the tab if(mw_data->current_tab){ // Will have to read directly at the main window level, as we want @@ -1979,8 +2191,10 @@ void * create_tab(MainWindow * parent, MainWindow* current_window, tmp_tab->current_time.tv_nsec = LTTV_TRACESET_CONTEXT(tmp_tab->traceset_info->traceset_context)->Time_Span->startTime.tv_nsec; } + /* Become the current tab */ + mw_data->current_tab = tmp_tab; + tmp_tab->attributes = LTTV_IATTRIBUTE(g_object_new(LTTV_ATTRIBUTE_TYPE, NULL)); - // mw_data->current_tab = tmp_tab; tmp_tab->multi_vpaned = (GtkMultiVPaned*)gtk_multi_vpaned_new(); tmp_tab->multi_vpaned->mw = mw_data; gtk_widget_show((GtkWidget*)tmp_tab->multi_vpaned); @@ -1990,6 +2204,9 @@ void * create_tab(MainWindow * parent, MainWindow* current_window, tmp_tab->label = gtk_label_new (label); gtk_widget_show (tmp_tab->label); + tmp_tab->time_requests = g_array_new(FALSE, FALSE, sizeof(TimeRequest)); + tmp_tab->time_request_pending = FALSE; + g_object_set_data_full( G_OBJECT(tmp_tab->multi_vpaned), "Tab_Info", @@ -2000,96 +2217,49 @@ void * create_tab(MainWindow * parent, MainWindow* current_window, gtk_notebook_append_page(notebook, (GtkWidget*)tmp_tab->multi_vpaned, tmp_tab->label); list = gtk_container_get_children(GTK_CONTAINER(notebook)); gtk_notebook_set_current_page(notebook,g_list_length(list)-1); - if(g_list_length(list)>1) - gtk_notebook_set_show_tabs(notebook, TRUE); + // always show : not if(g_list_length(list)>1) + gtk_notebook_set_show_tabs(notebook, TRUE); + } - -/* Remove menu entry and tool button from main window for the - * unloaded module +/** + * Function to show each viewer in the current tab. + * It will be called by main window, call show on each registered viewer, + * will call process traceset and then it will + * @param main_win the main window the viewer belongs to. */ - -void remove_menu_item(gpointer main_win, gpointer user_data) +//FIXME Only one time request maximum for now! +void show_viewer(MainWindow *main_win) { - MainWindow * mw = (MainWindow *) main_win; - lttv_menu_closure *menu_item = (lttv_menu_closure *)user_data; - GtkWidget * tool_menu_title_menu, *insert_view; - - tool_menu_title_menu = lookup_widget(mw->mwindow,"ToolMenuTitle_menu"); - insert_view = (GtkWidget*)g_hash_table_lookup(mw->hash_menu_item, - menu_item->menuText); - if(insert_view){ - g_hash_table_remove(mw->hash_menu_item, menu_item->menuText); - gtk_container_remove (GTK_CONTAINER (tool_menu_title_menu), insert_view); + LttvAttributeValue value; + LttvHooks * tmp; + int i; + LttvTracesetContext * tsc = + (LttvTracesetContext*)main_win->current_tab-> + traceset_info->traceset_context; + + g_assert(lttv_iattribute_find_by_path(main_win->current_tab->attributes, + "hooks/showviewer", LTTV_POINTER, &value)); + tmp = (LttvHooks*)*(value.v_pointer); + if(tmp == NULL) + { + g_warning("The viewer(s) did not add any show hook"); + return; } -} - -void remove_toolbar_item(gpointer main_win, gpointer user_data) -{ - MainWindow * mw = (MainWindow *) main_win; - lttv_toolbar_closure *toolbar_item = (lttv_toolbar_closure *)user_data; - GtkWidget * tool_menu_title_menu, *insert_view; + + // Call the show, where viewers add hooks to context and fill the + // time and number of events requested it the time_requests GArray. + lttv_hooks_call(tmp, NULL); - tool_menu_title_menu = lookup_widget(mw->mwindow,"MToolbar1"); - insert_view = (GtkWidget*)g_hash_table_lookup(mw->hash_toolbar_item, - toolbar_item->tooltip); - if(insert_view){ - g_hash_table_remove(mw->hash_toolbar_item, toolbar_item->tooltip); - gtk_container_remove (GTK_CONTAINER (tool_menu_title_menu), insert_view); - } + } -/** - * Remove menu and toolbar item when a module unloaded from all - * main windows - */ -void main_window_remove_menu_item(lttv_constructor constructor) +gboolean execute_time_requests(MainWindow * mw) { - int i; - LttvMenus * menu; - lttv_menu_closure *menu_item; - LttvAttributeValue value; - LttvIAttribute *attributes = LTTV_IATTRIBUTE(lttv_global_attributes()); + call_pending_read_hooks(mw); - g_assert(lttv_iattribute_find_by_path(attributes, - "viewers/menu", LTTV_POINTER, &value)); - menu = (LttvMenus*)*(value.v_pointer); - - if(menu){ - for(i=0;ilen;i++){ - menu_item = &g_array_index(menu, lttv_menu_closure, i); - if(menu_item->con != constructor) continue; - if(g_main_window_list){ - g_slist_foreach(g_main_window_list, remove_menu_item, menu_item); - } - break; - } - } - + return FALSE; // automatically removed from the list of event sources } -void main_window_remove_toolbar_item(lttv_constructor constructor) -{ - int i; - LttvToolbars * toolbar; - lttv_toolbar_closure *toolbar_item; - LttvAttributeValue value; - LttvIAttribute *attributes = LTTV_IATTRIBUTE(lttv_global_attributes()); - - g_assert(lttv_iattribute_find_by_path(attributes, - "viewers/toolbar", LTTV_POINTER, &value)); - toolbar = (LttvToolbars*)*(value.v_pointer); - - if(toolbar){ - for(i=0;ilen;i++){ - toolbar_item = &g_array_index(toolbar, lttv_toolbar_closure, i); - if(toolbar_item->con != constructor) continue; - if(g_main_window_list){ - g_slist_foreach(g_main_window_list, remove_toolbar_item, toolbar_item); - } - break; - } - } -}