Add Callgrind as an Helper to run lttv
[lttv.git] / lttv / modules / gui / lttvwindow / lttvwindow / callbacks.c
index d2e397f3b2df6598a3fbfbe234255ceae0c81ebf..7c113118ac79b0bd58d410a0900e5dff97e27b70 100644 (file)
 #include <lttv/lttv.h>
 #include <lttv/module.h>
 #include <lttv/iattribute.h>
+#include <lttv/traceset.h>
+#ifdef BABEL_CLEANUP
 #include <lttv/stats.h>
-#include <lttv/filter.h>
 #include <lttv/sync/sync_chain_lttv.h>
+#endif /* BABEL_CLEANUP */
+#include <lttv/filter.h>
 #include <lttvwindow/mainwindow.h>
 #include <lttvwindow/mainwindow-private.h>
 #include <lttvwindow/menu.h>
 #include <lttvwindow/lttvwindowtraces.h>
 #include <lttvwindow/lttv_plugin_tab.h>
 
+#include <babeltrace/babeltrace.h>
+#include <babeltrace/ctf/events.h>
+#include <babeltrace/ctf/iterator.h>
+
 static LttTime lttvwindow_default_time_width = { 1, 0 };
 #define CLIP_BUF 256 // size of clipboard buffer
 
@@ -75,6 +82,8 @@ char * get_selection(MainWindow *mw,
 void init_tab(Tab *tab, MainWindow * mw, Tab *copy_tab,
                  GtkNotebook * notebook, char * label);
 
+int update_traceset(Tab *tab, LttvTraceset *traceset);
+
 static void insert_viewer(GtkWidget* widget, lttvwindow_viewer_constructor constructor);
 
 LttvPluginTab *create_new_tab(GtkWidget* widget, gpointer user_data);
@@ -101,7 +110,6 @@ enum
 };
 
 
-
 #if 0
 static void on_top_notify(GObject    *gobject,
                GParamSpec *arg1,
@@ -217,13 +225,12 @@ void insert_viewer(GtkWidget* widget, lttvwindow_viewer_constructor constructor)
 
 int SetTraceset(Tab * tab, LttvTraceset *traceset)
 {
-  guint i;
+  
   TimeInterval time_span;
   TimeWindow new_time_window;
   LttTime new_current_time;
-  LttvTracesetContext *tsc =
-    LTTV_TRACESET_CONTEXT(tab->traceset_info->traceset_context);
 
+#ifdef BABEL_CLEANUP
   // Perform time synchronization on the traces
   if (syncTraceset(tsc))
   {
@@ -273,11 +280,15 @@ int SetTraceset(Tab * tab, LttvTraceset *traceset)
 
     tsc = LTTV_TRACESET_CONTEXT(tab->traceset_info->traceset_context);
   }
+#endif /*BABEL_CLEANUP*/
 
-  time_span = tsc->time_span;
+  time_span = lttv_traceset_get_time_span(traceset);
+  
+  tab->traceset_info->traceset = traceset;
+  
   new_time_window = tab->time_window;
-  new_current_time = tab->current_time;
-
+  new_current_time = tab->current_time;        
   /* Set the tab's time window and current time if
    * out of bounds */
   if(ltt_time_compare(tab->time_window.start_time, time_span.start_time) < 0
@@ -303,76 +314,14 @@ int SetTraceset(Tab * tab, LttvTraceset *traceset)
                                             new_time_window.time_width) ;
   }
 
-#if 0
-  /* Set scrollbar */
-  GtkAdjustment *adjustment = gtk_range_get_adjustment(GTK_RANGE(tab->scrollbar));
-  LttTime upper = ltt_time_sub(time_span.end_time, time_span.start_time);
-      
-  g_object_set(G_OBJECT(adjustment),
-               "lower",
-                 0.0, /* lower */
-               "upper",
-               ltt_time_to_double(upper) 
-                 * NANOSECONDS_PER_SECOND, /* upper */
-               "step_increment",
-               ltt_time_to_double(tab->time_window.time_width)
-                             / SCROLL_STEP_PER_PAGE
-                             * NANOSECONDS_PER_SECOND, /* step increment */
-               "page_increment",
-               ltt_time_to_double(tab->time_window.time_width) 
-                 * NANOSECONDS_PER_SECOND, /* page increment */
-               "page_size",
-               ltt_time_to_double(tab->time_window.time_width) 
-                 * NANOSECONDS_PER_SECOND, /* page size */
-               NULL);
-  gtk_adjustment_changed(adjustment);
-
-  g_object_set(G_OBJECT(adjustment),
-               "value",
-               ltt_time_to_double(
-                ltt_time_sub(tab->time_window.start_time, time_span.start_time))
-                   * NANOSECONDS_PER_SECOND, /* value */
-               NULL);
-  gtk_adjustment_value_changed(adjustment);
-
-  /* set the time bar. The value callbacks will change their nsec themself */
-  /* start seconds */
-  gtk_spin_button_set_range(GTK_SPIN_BUTTON(tab->MEntry1),
-                            (double)time_span.start_time.tv_sec,
-                            (double)time_span.end_time.tv_sec);
-
-  /* end seconds */
-  gtk_spin_button_set_range(GTK_SPIN_BUTTON(tab->MEntry3),
-                            (double)time_span.start_time.tv_sec,
-                            (double)time_span.end_time.tv_sec);
-
-   /* current seconds */
-  gtk_spin_button_set_range(GTK_SPIN_BUTTON(tab->MEntry5),
-                            (double)time_span.start_time.tv_sec,
-                            (double)time_span.end_time.tv_sec);
-#endif //0
-  
   /* Finally, call the update hooks of the viewers */
-  LttvHooks * tmp;
-  LttvAttributeValue value;
-  gint retval = 0;
-  retval= lttv_iattribute_find_by_path(tab->attributes,
-    "hooks/updatetraceset", LTTV_POINTER, &value);
-  g_assert(retval);
-
-  tmp = (LttvHooks*)*(value.v_pointer);
-  if(tmp == NULL)
-         retval = 1;
-  else
-         lttv_hooks_call(tmp,traceset);
+  gint retval = update_traceset(tab, traceset);
 
   time_change_manager(tab, new_time_window);
   current_time_change_manager(tab, new_current_time);
 
   return retval;
+  
 }
 
 /**
@@ -408,20 +357,48 @@ int SetFilter(Tab * tab, gpointer filter)
  * @param tab viewer's tab 
  */
 
-void update_traceset(Tab *tab)
+int update_traceset(Tab *tab, LttvTraceset *traceset)
 {
   LttvAttributeValue value;
   LttvHooks * tmp;
   gboolean retval;
 
   retval= lttv_iattribute_find_by_path(tab->attributes,
-    "hooks/updatetraceset", LTTV_POINTER, &value);
+                                 "hooks/updatetraceset", 
+                                 LTTV_POINTER, 
+                                 &value);
   g_assert(retval);
   tmp = (LttvHooks*)*(value.v_pointer);
-  if(tmp == NULL) return;
-  lttv_hooks_call(tmp, NULL);
+  if(tmp == NULL) {
+         retval = 1;
+  } else {
+         lttv_hooks_call(tmp, traceset);
+  }
+  return retval;
 }
 
+/** 
+    Call hooks register to get update on traceset time span changes
+*/
+int notify_time_span_changed(Tab *tab)
+{
+  LttvAttributeValue value;
+  LttvHooks * tmp;
+  gboolean retval;
+
+  retval= lttv_iattribute_find_by_path(tab->attributes,
+                                 "hooks/updatetimespan", 
+                                 LTTV_POINTER, 
+                                 &value);
+  g_assert(retval);
+  tmp = (LttvHooks*)*(value.v_pointer);
+  if(tmp == NULL) {
+         retval = 1;
+  } else {
+         lttv_hooks_call(tmp, NULL);
+  }
+  return retval;
+}
 
 /* get_label function is used to get user input, it displays an input
  * box, which allows user to input a string 
@@ -662,7 +639,8 @@ void delete_viewer(GtkWidget * widget, gpointer user_data)
   g_object_set_data(G_OBJECT(tab->viewer_container), "focused_viewer", NULL);
 }
 
-
+#if UNFINISHED_FEATURE
+/* TODO ybrosseau 2012-03-15: Function is half implemented. Should be removed */
 /* open_traceset will open a traceset saved in a file
  * Right now, it is not finished yet, (not working)
  * FIXME
@@ -699,7 +677,7 @@ void open_traceset(GtkWidget * widget, gpointer user_data)
   }
 
 }
-
+#endif
 /* lttvwindow_process_pending_requests
  *
  * Process requests for parts of the trace from viewers.
@@ -731,6 +709,7 @@ void open_traceset(GtkWidget * widget, gpointer user_data)
 
 gboolean lttvwindow_process_pending_requests(Tab *tab)
 {
+#ifdef BABEL_CLEANUP
   LttvTracesetContext *tsc;
   LttvTracefileContext *tfc;
   GSList *list_in = NULL;
@@ -942,7 +921,9 @@ gboolean lttvwindow_process_pending_requests(Tab *tab)
         tfc = lttv_traceset_context_get_current_tfc(tsc);
         g_assert(g_slist_length(list_in)>0);
         EventsRequest *events_request = g_slist_nth_data(list_in, 0);
+#ifdef DEBUG
         guint seek_count;
+#endif
 
         /* 1.2.1 If first request in list_in is a time request */
         if(events_request->start_position == NULL) {
@@ -957,7 +938,9 @@ gboolean lttvwindow_process_pending_requests(Tab *tab)
                                                   events_request->start_time);
 
             /* Process the traceset with only state hooks */
+#ifdef DEBUG
             seek_count =
+#endif //DEBUG
                lttv_process_traceset_middle(tsc,
                                             events_request->start_time,
                                             G_MAXUINT, NULL);
@@ -1001,11 +984,14 @@ gboolean lttvwindow_process_pending_requests(Tab *tab)
                                                   pos_time);
 
             /* Process the traceset with only state hooks */
+#ifdef DEBUG
             seek_count =
+
                lttv_process_traceset_middle(tsc,
                                             ltt_time_infinite,
                                             G_MAXUINT,
                                             events_request->start_position);
+#endif
             g_assert(lttv_traceset_context_ctx_pos_compare(tsc,
                          events_request->start_position) == 0);
 
@@ -1503,13 +1489,59 @@ gboolean lttvwindow_process_pending_requests(Tab *tab)
                   NULL);
   return FALSE;
   */
+  
+  #endif /* BABEL_CLEANUP */
 }
 
 #undef list_out
+/** 
+    Manage the periodic update of a live trace
+*/
+static gboolean
+live_trace_update_handler(Tab *tab)
+{  
+#ifdef BABEL_CLEANUP
+       unsigned int updated_count;
+       LttvTracesetContext *tsc = LTTV_TRACESET_CONTEXT(tab->traceset_info->traceset_context);
+       TimeInterval initial_time_span = tsc->time_span;
+       TimeInterval updated_time_span;
+
+       updated_count = lttv_process_traceset_update(tsc);
+       
+       /* TODO ybrosseau 2011-01-12: Add trace resynchronization  */
+
+       /* Get the changed period bounds */
+       updated_time_span = tsc->time_span;
+
+       if(ltt_time_compare(updated_time_span.start_time, 
+                               initial_time_span.start_time) != 0) {
+               /* The initial time should not change on a live update */
+               g_assert(FALSE);
+       }
 
+       /* Notify viewers (only on updates) */
+       if(ltt_time_compare(updated_time_span.end_time, 
+                               initial_time_span.end_time) != 0) {
+               
+               notify_time_span_changed(tab);
+               /* TODO ybrosseau 2011-01-12: Change the timebar to register 
+                  to the time_span hook */
+               timebar_set_minmax_time(TIMEBAR(tab->MTimebar),
+                                       &updated_time_span.start_time,
+                                       &updated_time_span.end_time );
+               
+               /* To update the min max */
+               time_change_manager(tab, tab->time_window);
+       }
+
+       /* Timer will be recalled as long as there is files to update */
+       return (updated_count > 0);
+#endif /* BABEL_CLEANUP */
+}
 
 static void lttvwindow_add_trace(Tab *tab, LttvTrace *trace_v)
 {
+#ifdef BABEL_CLEANUP
   LttvTraceset *traceset = tab->traceset_info->traceset;
   guint i;
   guint num_traces = lttv_traceset_number(traceset);
@@ -1561,6 +1593,16 @@ static void lttvwindow_add_trace(Tab *tab, LttvTrace *trace_v)
 
   //FIXME
   //add_trace_into_traceset_selector(GTK_MULTIVPANED(tab->multivpaned), lttv_trace(trace_v));
+
+
+  if (lttv_trace(trace_v)->is_live) {
+         /* Add timer for live update */
+         /* TODO ybrosseau 2011-01-12: Parametrize the hardcoded 1 seconds */
+         g_timeout_add_seconds (1,
+                                (GSourceFunc) live_trace_update_handler,
+                                tab);
+  }
+#endif /* BABEL_CLEANUP */
 }
 
 /* add_trace adds a trace into the current traceset. It first displays a 
@@ -1570,10 +1612,9 @@ static void lttvwindow_add_trace(Tab *tab, LttvTrace *trace_v)
 
 void add_trace(GtkWidget * widget, gpointer user_data)
 {
-  LttTrace *trace;
-  LttvTrace * trace_v;
-  LttvTraceset * traceset;
-  const char * dir;
+  
+  LttvTraceset * traceset = NULL;
+  const char * path;
   char abs_path[PATH_MAX];
   gint id;
   MainWindow * mw_data = get_window_data_struct(widget);
@@ -1591,8 +1632,27 @@ void add_trace(GtkWidget * widget, gpointer user_data)
     ptab = (LttvPluginTab *)g_object_get_data(G_OBJECT(page), "Tab_Plugin");
     tab = ptab->tab;
   }
-
+//TODO fdeslauriers 2012-07-06: Remove this popup when we support multiple traces
+  traceset = lttvwindow_get_traceset(tab);
+  if(traceset != NULL && lttv_traceset_number(traceset) > 0){
+         GtkWidget *dialogue = 
+           gtk_message_dialog_new(
+             GTK_WINDOW(gtk_widget_get_toplevel(widget)),
+             GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT,
+             GTK_MESSAGE_ERROR,
+             GTK_BUTTONS_OK,
+             "Loading multiple traces is not supported at the moment.");
+         gtk_dialog_run(GTK_DIALOG(dialogue));
+         gtk_widget_destroy(dialogue);
+         return;
+       }
+  
+  /* Create a new traceset*/
+  traceset = lttv_traceset_new();
   /* File open dialog management */
+#ifdef BABEL_CLEANUP
+  GtkWidget *extra_live_button;
+#endif //babel_cleanup
   GtkFileChooser * file_chooser = 
          GTK_FILE_CHOOSER(
                  gtk_file_chooser_dialog_new ("Select a trace",
@@ -1600,67 +1660,70 @@ void add_trace(GtkWidget * widget, gpointer user_data)
                                          GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
                                          GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
                                          GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
-                                         NULL));
-
+                                         NULL));
+#ifdef BABEL_CLEANUP
+  /* Button to indicate the opening of a live trace */
+  extra_live_button = gtk_check_button_new_with_mnemonic ("Trace is live (currently being writen)");
+  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (extra_live_button), FALSE);
+  gtk_file_chooser_set_extra_widget (GTK_FILE_CHOOSER (file_chooser), extra_live_button);
+#endif //babel_cleanup
   gtk_file_chooser_set_show_hidden (file_chooser, TRUE);
   if(remember_trace_dir[0] != '\0')
          gtk_file_chooser_set_filename(file_chooser, remember_trace_dir);
 
-  id = gtk_dialog_run(GTK_DIALOG(file_chooser));
-
-  switch(id){
-    case GTK_RESPONSE_ACCEPT:
-    case GTK_RESPONSE_OK:
-      dir = gtk_file_chooser_get_filename (file_chooser);
-      strncpy(remember_trace_dir, dir, PATH_MAX);
-      strncat(remember_trace_dir, "/", PATH_MAX);
-      if(!dir || strlen(dir) == 0){
-       break;
-      }
-      get_absolute_pathname(dir, abs_path);
-      trace_v = lttvwindowtraces_get_trace_by_name(abs_path);
-      if(trace_v == NULL) {
-        trace = ltt_trace_open(abs_path);
-        if(trace == NULL) {
-          g_warning("cannot open trace %s", abs_path);
-
-          GtkWidget *dialogue = 
-            gtk_message_dialog_new(
-              GTK_WINDOW(gtk_widget_get_toplevel(widget)),
-              GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT,
-              GTK_MESSAGE_ERROR,
-              GTK_BUTTONS_OK,
-              "Cannot open trace : maybe you should enter in the trace "
-              "directory to select it ?");
-          gtk_dialog_run(GTK_DIALOG(dialogue));
-          gtk_widget_destroy(dialogue);
+   gboolean closeFileChooserDialog = TRUE;
 
-        } else {
-          trace_v = lttv_trace_new(trace);
-          lttvwindowtraces_add_trace(trace_v);
-          lttvwindow_add_trace(tab, trace_v);
-        }
-      } else {
-        lttvwindow_add_trace(tab, trace_v);
-      }
+  do 
+  {
+    id = gtk_dialog_run(GTK_DIALOG(file_chooser));
+    switch(id){
+      case GTK_RESPONSE_ACCEPT:
+      case GTK_RESPONSE_OK:
+       path = gtk_file_chooser_get_filename (file_chooser);
 
+       strncpy(remember_trace_dir, path, PATH_MAX);
+       strncat(remember_trace_dir, "/", PATH_MAX);
+       if(!path || strlen(path) == 0){
+         break;
+       }
+       get_absolute_pathname(path, abs_path);
+       
+      if(lttv_traceset_add_path(traceset,abs_path) != 0 ){ /*failure*/
       
-      //update current tab
-      //update_traceset(mw_data);
+       g_warning("cannot open trace %s", abs_path);
+       strncpy(remember_trace_dir, "\0", PATH_MAX);
+         GtkWidget *dialogue = 
+           gtk_message_dialog_new(
+             GTK_WINDOW(gtk_widget_get_toplevel(widget)),
+             GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT,
+             GTK_MESSAGE_ERROR,
+             GTK_BUTTONS_OK,
+             "Cannot open trace : maybe you should enter in the directory "
+             "to select it ?");
+         gtk_dialog_run(GTK_DIALOG(dialogue));
+         gtk_widget_destroy(dialogue);
+         closeFileChooserDialog = FALSE;
+       }
+       else{
+         closeFileChooserDialog = TRUE;
+         SetTraceset(tab, traceset);    
+       }
+       break;
+       //update current tab
+       //update_traceset(mw_data);
 
-      /* Call the updatetraceset hooks */
-      
-      traceset = tab->traceset_info->traceset;
-      SetTraceset(tab, traceset);
-      // in expose now call_pending_read_hooks(mw_data);
+       // in expose now call_pending_read_hooks(mw_data);
+       
+       //lttvwindow_report_current_time(mw_data,&(tab->current_time));
       
-      //lttvwindow_report_current_time(mw_data,&(tab->current_time));
-      break;
-    case GTK_RESPONSE_REJECT:
-    case GTK_RESPONSE_CANCEL:
-    default:
-           break;
-  }
+      case GTK_RESPONSE_REJECT:
+      case GTK_RESPONSE_CANCEL:
+      default:
+       closeFileChooserDialog = TRUE;
+             break;    
+    }
+  }while(!closeFileChooserDialog);
+  
   gtk_widget_destroy((GtkWidget*)file_chooser);
 
 }
@@ -1679,6 +1742,7 @@ void add_trace(GtkWidget * widget, gpointer user_data)
 
 void remove_trace(GtkWidget *widget, gpointer user_data)
 {
+#ifdef BABEL_CLEANUP
   LttTrace *trace;
   LttvTrace * trace_v;
   LttvTraceset * traceset;
@@ -1767,6 +1831,7 @@ void remove_trace(GtkWidget *widget, gpointer user_data)
     SetTraceset(tab, (gpointer)traceset);
   }
   g_free(name);
+#endif /* BABEL_CLEANUP */ 
 }
 
 #if 0
@@ -2019,6 +2084,7 @@ void save_as(GtkWidget * widget, gpointer user_data)
 
 void zoom(GtkWidget * widget, double size)
 {
+#ifdef BABEL_CLEANUP
   TimeInterval time_span;
   TimeWindow new_time_window;
   LttTime    current_time, time_delta;
@@ -2102,6 +2168,8 @@ void zoom(GtkWidget * widget, double size)
  } else {
    time_change_manager(tab, new_time_window);
   }
+  
+#endif /* BABEL_CLEANUP */
 }
 
 void zoom_in(GtkWidget * widget, gpointer user_data)
@@ -2202,7 +2270,9 @@ void
 on_open_activate                       (GtkMenuItem     *menuitem,
                                         gpointer         user_data)
 {
+#ifdef UNFINISHED_FEATURE
   open_traceset((GtkWidget*)menuitem, user_data);
+#endif
 }
 
 
@@ -2878,6 +2948,18 @@ void
 on_content_activate                    (GtkMenuItem     *menuitem,
                                         gpointer         user_data)
 {
+  char* filename = NULL,
+                  *path;
+  GdkScreen *screen;
+  const char* relativePath = "doc/user/user_guide/html/index.html";
+  filename = g_build_filename (g_get_current_dir(), relativePath, NULL);
+  path = g_strdup_printf ("ghelp://%s", filename);
+
+  screen = gdk_screen_get_default();
+  gtk_show_uri (screen, path, gtk_get_current_event_time(), NULL);
+
+  g_free(filename);
+  g_free(path);
   g_info("Content\n");
 }
 
@@ -2899,7 +2981,6 @@ on_about_activate                      (GtkMenuItem     *menuitem,
   GtkWidget *window_widget = main_window->mwindow;
   GtkWidget *about_widget = gtk_window_new(GTK_WINDOW_TOPLEVEL);
   GtkWindow *about_window = GTK_WINDOW(about_widget);
-  gint window_width, window_height;
   
   gtk_window_set_title(about_window, "About Linux Trace Toolkit");
 
@@ -2909,16 +2990,12 @@ on_about_activate                      (GtkMenuItem     *menuitem,
   gtk_window_set_modal(about_window, FALSE);
 
   /* Put the about window at the center of the screen */
-  gtk_window_get_size(about_window, &window_width, &window_height);
-  gtk_window_move (about_window,
-                   (gdk_screen_width() - window_width)/2,
-                   (gdk_screen_height() - window_height)/2);
+  gtk_window_set_position(about_window, GTK_WIN_POS_CENTER_ALWAYS);
+
   GtkWidget *vbox = gtk_vbox_new(FALSE, 1);
 
   gtk_container_add(GTK_CONTAINER(about_widget), vbox);
 
-    
   /* Text to show */
   GtkWidget *label1 = gtk_label_new("");
   gtk_misc_set_padding(GTK_MISC(label1), 10, 20);
@@ -2992,7 +3069,9 @@ void
 on_button_open_clicked                 (GtkButton       *button,
                                         gpointer         user_data)
 {
+#ifdef UNFINISHED_FEATURE
   open_traceset((GtkWidget*)button, user_data);
+#endif
 }
 
 
@@ -3186,14 +3265,19 @@ on_MNotebook_switch_page               (GtkNotebook     *notebook,
 
 void time_change_manager               (Tab *tab,
                                         TimeWindow new_time_window)
-{
+{ 
+  
   /* Only one source of time change */
   if(tab->time_manager_lock == TRUE) return;
 
   tab->time_manager_lock = TRUE;
+  TimeInterval time_span;
+  
+  LttvTraceset *ts = tab->traceset_info->traceset;
+  time_span.start_time =ltt_time_from_uint64( lttv_traceset_get_timestamp_begin(ts));
+  time_span.end_time = ltt_time_from_uint64(lttv_traceset_get_timestamp_end(ts));
+  
 
-  LttvTracesetContext *tsc = LTTV_TRACESET_CONTEXT(tab->traceset_info->traceset_context);
-  TimeInterval time_span = tsc->time_span;
   LttTime start_time = new_time_window.start_time;
   LttTime end_time = new_time_window.end_time;
 
@@ -3201,7 +3285,8 @@ void time_change_manager               (Tab *tab,
   
   /* Set scrollbar */
   GtkAdjustment *adjustment = gtk_range_get_adjustment(GTK_RANGE(tab->scrollbar));
-  LttTime upper = ltt_time_sub(time_span.end_time, time_span.start_time);
+  LttTime upper = ltt_time_sub(time_span.end_time, time_span.start_time); 
+
 #if 0  
   gtk_range_set_increments(GTK_RANGE(tab->scrollbar),
                ltt_time_to_double(new_time_window.time_width)
@@ -3256,6 +3341,8 @@ void time_change_manager               (Tab *tab,
   set_time_window(tab, &new_time_window);
 
   tab->time_manager_lock = FALSE;
+  
+
 }
 
 
@@ -3277,32 +3364,26 @@ void current_time_change_manager       (Tab *tab,
   tab->current_time_manager_lock = FALSE;
 }
 
-void current_position_change_manager(Tab *tab,
-                                     LttvTracesetContextPosition *pos)
+void current_position_change_manager(Tab *tab, LttvTracesetPosition *pos)
 {
-  LttvTracesetContext *tsc =
-    LTTV_TRACESET_CONTEXT(tab->traceset_info->traceset_context);
-  int retval;
+  lttv_traceset_seek_to_position( pos);
 
-  retval= lttv_process_traceset_seek_position(tsc, pos);
-  g_assert_cmpint(retval, ==, 0);
-  LttTime new_time = lttv_traceset_context_position_get_time(pos);
+  LttTime new_time = lttv_traceset_position_get_time(pos);
   /* Put the context in a state coherent position */
-  lttv_state_traceset_seek_time_closest((LttvTracesetState*)tsc, ltt_time_zero);
-  
+#ifdef BABEL_CLEANUP
+   lttv_state_traceset_seek_time_closest((LttvTracesetState*)tsc, ltt_time_zero);
+#endif /* BABEL_CLEANUP */
   current_time_change_manager(tab, new_time);
   
   set_current_position(tab, pos);
 }
 
-
 static void on_timebar_starttime_changed(Timebar *timebar,
                                gpointer user_data)
 {
        Tab *tab = (Tab *)user_data;
-       LttvTracesetContext * tsc =
-               LTTV_TRACESET_CONTEXT(tab->traceset_info->traceset_context);
-       TimeInterval time_span = tsc->time_span;
+       LttvTraceset * ts =tab->traceset_info->traceset;
+       TimeInterval time_span = lttv_traceset_get_time_span(ts);
 
        TimeWindow new_time_window = tab->time_window;
        new_time_window.start_time = timebar_get_start_time(timebar);
@@ -3337,9 +3418,8 @@ static void on_timebar_endtime_changed(Timebar *timebar,
                                gpointer user_data)
 {
        Tab *tab = (Tab *)user_data;
-       LttvTracesetContext * tsc = 
-               LTTV_TRACESET_CONTEXT(tab->traceset_info->traceset_context);
-       TimeInterval time_span = tsc->time_span;
+        LttvTraceset * ts =tab->traceset_info->traceset;
+        TimeInterval time_span = lttv_traceset_get_time_span(ts);
 
        TimeWindow new_time_window = tab->time_window;
 
@@ -3366,7 +3446,7 @@ static void on_timebar_endtime_changed(Timebar *timebar,
        new_time_window.end_time = end_time;
 
        /* Notify the time_manager */
-       time_change_manager(tab, new_time_window);  
+       time_change_manager(tab, new_time_window);
 }
 static void on_timebar_currenttime_changed(Timebar *timebar,
                                gpointer user_data)
@@ -3388,9 +3468,9 @@ void scroll_value_changed_cb(GtkWidget *scrollbar,
   gdouble value = gtk_adjustment_get_value(adjust);
  // gdouble upper, lower, ratio, page_size;
   gdouble page_size;
-  LttvTracesetContext * tsc = 
-    LTTV_TRACESET_CONTEXT(tab->traceset_info->traceset_context);
-  TimeInterval time_span = tsc->time_span;
+  
+  LttvTraceset * ts = tab->traceset_info->traceset;
+  TimeInterval time_span = lttv_traceset_get_time_span(ts);
 
   time = ltt_time_add(ltt_time_from_double(value),
                       time_span.start_time);
@@ -3410,6 +3490,7 @@ void scroll_value_changed_cb(GtkWidget *scrollbar,
 
 
   time_change_manager(tab, new_time_window);
+
 #if 0
   //time_window = tab->time_window;
 
@@ -3438,6 +3519,7 @@ void scroll_value_changed_cb(GtkWidget *scrollbar,
   /* call viewer hooks for new time window */
   set_time_window(tab, &time_window);
 #endif //0
+
 }
 
 
@@ -3681,8 +3763,7 @@ MainWindow *construct_main_window(MainWindow * parent)
   LttvIAttribute *attributes =
          LTTV_IATTRIBUTE(g_object_new(LTTV_ATTRIBUTE_TYPE, NULL));
   LttvAttributeValue value;
-  Tab *new_tab;
-         
+
   new_m_window = g_new(MainWindow, 1);
 
   // Add the object's information to the module's array 
@@ -3743,7 +3824,6 @@ MainWindow *construct_main_window(MainWindow * parent)
            "Tab_Plugin",
            ptab,
           (GDestroyNotify)tab_destructor);
-    new_tab = ptab->tab;
   } else {
     LttvPluginTab *ptab = g_object_new(LTTV_TYPE_PLUGIN_TAB, NULL);
     init_tab(ptab->tab, new_m_window, NULL, notebook, "Traceset");
@@ -3753,7 +3833,6 @@ MainWindow *construct_main_window(MainWindow * parent)
            "Tab_Plugin",
            ptab,
           (GDestroyNotify)tab_destructor);
-    new_tab = ptab->tab;
   }
 
   /* Insert default viewers */
@@ -3811,6 +3890,7 @@ MainWindow *construct_main_window(MainWindow * parent)
 
 void tab_destructor(LttvPluginTab * ptab)
 {
+#ifdef BABEL_CLEANUP
   int i, nb, ref_count;
   LttvTrace * trace;
   Tab *tab = ptab->tab;
@@ -3849,6 +3929,7 @@ void tab_destructor(LttvPluginTab * ptab)
   g_free(tab->traceset_info);
   //g_free(tab);
   g_object_unref(ptab);
+#endif /* BABEL_CLEANUP */
 }
 
 
@@ -3858,6 +3939,7 @@ void tab_destructor(LttvPluginTab * ptab)
 void init_tab(Tab *tab, MainWindow * mw, Tab *copy_tab, 
                  GtkNotebook * notebook, char * label)
 {
+
   GList * list;
   //Tab * tab;
   //LttvFilter *filter = NULL;
@@ -3875,9 +3957,13 @@ void init_tab(Tab *tab, MainWindow * mw, Tab *copy_tab,
     /* Copy the previous tab's filter */
     /* We can clone the filter, as we copy the trace set also */
     /* The filter must always be in sync with the trace set */
+   
+#ifdef BABEL_CLEANUP
     tab->filter = lttv_filter_clone(copy_tab->filter);
+#endif /* BABEL_CLEANUP */
   } else {
     tab->traceset_info->traceset = lttv_traceset_new();
+
     tab->filter = NULL;
   }
 #ifdef DEBUG
@@ -3887,21 +3973,17 @@ void init_tab(Tab *tab, MainWindow * mw, Tab *copy_tab,
       0, 4);
   fflush(stdout);
 #endif //DEBUG
-
+// 
   tab->time_manager_lock = FALSE;
   tab->current_time_manager_lock = FALSE;
-
+#ifdef BABEL_CLEANUP
   //FIXME copy not implemented in lower level
   tab->traceset_info->traceset_context =
     g_object_new(LTTV_TRACESET_STATS_TYPE, NULL);
-  g_assert(tab->traceset_info->traceset_context != NULL);
-  lttv_context_init(
-           LTTV_TRACESET_CONTEXT(tab->traceset_info->traceset_context),
-                                 tab->traceset_info->traceset);
   //add state update hooks
   lttv_state_add_event_hooks(
        (LttvTracesetState*)tab->traceset_info->traceset_context);
-  
+#endif //BABEL_CLEANUP
   //determine the current_time and time_window of the tab
 #if 0
   if(copy_tab != NULL){
@@ -4066,7 +4148,7 @@ void init_tab(Tab *tab, MainWindow * mw, Tab *copy_tab,
     lttvwindow_report_time_window(tab, time_window);
     lttvwindow_report_current_time(tab, ltt_time_zero);
   }
+
   LttvTraceset *traceset = tab->traceset_info->traceset;
   SetTraceset(tab, traceset);
 }
@@ -4086,6 +4168,7 @@ gboolean execute_events_requests(Tab *tab)
 
 __EXPORT void create_main_window_with_trace_list(GSList *traces)
 {
+
   GSList *iter = NULL;
 
   /* Create window */
@@ -4105,20 +4188,19 @@ __EXPORT void create_main_window_with_trace_list(GSList *traces)
     ptab = (LttvPluginTab *)g_object_get_data(G_OBJECT(page), "Tab_Plugin");
     tab = ptab->tab;
   }
-
+  
+  LttvTraceset * traceset = lttv_traceset_new();
   for(iter=traces; iter!=NULL; iter=g_slist_next(iter)) {
     gchar *path = (gchar*)iter->data;
     /* Add trace */
     gchar abs_path[PATH_MAX];
-    LttvTrace *trace_v;
-    LttTrace *trace;
 
     get_absolute_pathname(path, abs_path);
-    trace_v = lttvwindowtraces_get_trace_by_name(abs_path);
-    if(trace_v == NULL) {
-      trace = ltt_trace_open(abs_path);
-      if(trace == NULL) {
-        g_warning("cannot open trace %s", abs_path);
+    
+    if(lttv_traceset_add_path(traceset,abs_path) != 0 ){ /*failure*/
+    
+      g_warning("cannot open trace %s", abs_path);
 
         GtkWidget *dialogue = 
           gtk_message_dialog_new(
@@ -4130,19 +4212,10 @@ __EXPORT void create_main_window_with_trace_list(GSList *traces)
             "to select it ?");
         gtk_dialog_run(GTK_DIALOG(dialogue));
         gtk_widget_destroy(dialogue);
-      } else {
-        trace_v = lttv_trace_new(trace);
-        lttvwindowtraces_add_trace(trace_v);
-        lttvwindow_add_trace(tab, trace_v);
-      }
-    } else {
-      lttvwindow_add_trace(tab, trace_v);
     }
-  }
-  
-  LttvTraceset *traceset;
-
-  traceset = tab->traceset_info->traceset;
-  SetTraceset(tab, traceset);
+    else{
+        SetTraceset(tab, traceset);
+    }
+  } 
 }
 
This page took 0.032252 seconds and 4 git commands to generate.