fix main window lib unload : still FIXME status though..
[lttv.git] / ltt / branches / poly / lttv / modules / gui / lttvwindow / lttvwindow / callbacks.c
index a9bdac212f730a5464da842e91fe9f16269daae6..d3eb158b941ba5e450d1dd06b78270d6847eb51a 100644 (file)
@@ -49,7 +49,7 @@
 #include <lttvwindow/gtkdirsel.h>
 
 
-#define DEFAULT_TIME_WIDTH_S   1
+static LttTime lttvwindow_default_time_width = { 1, 0 };
 #define CLIP_BUF 256 // size of clipboard buffer
 
 extern LttvTrace *g_init_trace ;
@@ -73,12 +73,6 @@ Tab* create_tab(MainWindow * mw, Tab *copy_tab,
 
 static void insert_viewer(GtkWidget* widget, lttvwindow_viewer_constructor constructor);
 
-void checkbox_changed(GtkTreeView *treeview,
-                     GtkTreePath *arg1,
-                     GtkTreeViewColumn *arg2,
-                     gpointer user_data);
-void remove_trace_from_traceset_selector(GtkWidget * paned, unsigned i);
-void add_trace_into_traceset_selector(GtkWidget * paned, LttTrace * trace);
 Tab *create_new_tab(GtkWidget* widget, gpointer user_data);
 
 static gboolean lttvwindow_process_pending_requests(Tab *tab);
@@ -337,6 +331,18 @@ static void connect_focus_recursive(GtkWidget *widget,
                     (gpointer)viewer);
 }
 
+/* Stop all the processings and call gtk_main_quit() */
+static void mainwindow_quit()
+{
+  lttvwindowtraces_unregister_requests(g_quark_from_string("stats"));
+  lttvwindowtraces_unregister_requests(g_quark_from_string("state"));
+  lttvwindowtraces_unregister_computation_hooks(g_quark_from_string("stats"));
+  lttvwindowtraces_unregister_computation_hooks(g_quark_from_string("state"));
+
+  gtk_main_quit();
+}
+
+
 /* insert_viewer function constructs an instance of a viewer first,
  * then inserts the widget of the instance into the container of the
  * main window
@@ -402,8 +408,8 @@ int SetTraceset(Tab * tab, LttvTraceset *traceset)
   LttvTracesetContext *tsc =
         LTTV_TRACESET_CONTEXT(tab->traceset_info->traceset_context);
   TimeInterval time_span = tsc->time_span;
-  TimeWindow new_time_window;
-  LttTime new_current_time;
+  TimeWindow new_time_window = tab->time_window;
+  LttTime new_current_time = tab->current_time;
 
   /* Set the tab's time window and current time if
    * out of bounds */
@@ -415,20 +421,23 @@ int SetTraceset(Tab * tab, LttvTraceset *traceset)
     new_current_time = time_span.start_time;
     
     LttTime tmp_time;
-
-    if(DEFAULT_TIME_WIDTH_S < time_span.end_time.tv_sec)
-      tmp_time.tv_sec = DEFAULT_TIME_WIDTH_S;
+    
+    if(ltt_time_compare(lttvwindow_default_time_width,
+          ltt_time_sub(time_span.end_time, time_span.start_time)) < 0
+        ||
+       ltt_time_compare(time_span.end_time, time_span.start_time) == 0)
+      tmp_time = lttvwindow_default_time_width;
     else
-      tmp_time.tv_sec = time_span.end_time.tv_sec;
-    tmp_time.tv_nsec = 0;
+      tmp_time = time_span.end_time;
+
     new_time_window.time_width = tmp_time ;
     new_time_window.time_width_double = ltt_time_to_double(tmp_time);
     new_time_window.end_time = ltt_time_add(new_time_window.start_time,
                                             new_time_window.time_width) ;
   }
-  time_change_manager(tab, new_time_window);
-  current_time_change_manager(tab, new_current_time);
 
 #if 0
   /* Set scrollbar */
   GtkAdjustment *adjustment = gtk_range_get_adjustment(GTK_RANGE(tab->scrollbar));
@@ -491,7 +500,9 @@ int SetTraceset(Tab * tab, LttvTraceset *traceset)
   if(tmp == NULL) retval = 1;
   else lttv_hooks_call(tmp,traceset);
 
+  time_change_manager(tab, new_time_window);
+  current_time_change_manager(tab, new_current_time);
+
   return retval;
 }
 
@@ -504,7 +515,7 @@ int SetTraceset(Tab * tab, LttvTraceset *traceset)
  *  0 : filters updated
  *  1 : no filter hooks to update; not an error.
  */
-
+#if 0
 int SetFilter(Tab * tab, gpointer filter)
 {
   LttvHooks * tmp;
@@ -520,7 +531,7 @@ int SetFilter(Tab * tab, gpointer filter)
 
   return 0;
 }
-
+#endif //0
 
 
 /**
@@ -811,42 +822,6 @@ void open_traceset(GtkWidget * widget, gpointer user_data)
 
 }
 
-static void events_request_free(EventsRequest *events_request)
-{
-  if(events_request == NULL) return;
-
-  if(events_request->start_position != NULL)
-       lttv_traceset_context_position_destroy(events_request->start_position);
-  if(events_request->end_position != NULL)
-       lttv_traceset_context_position_destroy(events_request->end_position);
-  if(events_request->hooks != NULL)
-    g_array_free(events_request->hooks, TRUE);
-  if(events_request->before_chunk_traceset != NULL)
-       lttv_hooks_destroy(events_request->before_chunk_traceset);
-  if(events_request->before_chunk_trace != NULL)
-       lttv_hooks_destroy(events_request->before_chunk_trace);
-  if(events_request->before_chunk_tracefile != NULL)
-       lttv_hooks_destroy(events_request->before_chunk_tracefile);
-  if(events_request->event != NULL)
-       lttv_hooks_destroy(events_request->event);
-  if(events_request->event_by_id != NULL)
-       lttv_hooks_by_id_destroy(events_request->event_by_id);
-  if(events_request->after_chunk_tracefile != NULL)
-       lttv_hooks_destroy(events_request->after_chunk_tracefile);
-  if(events_request->after_chunk_trace != NULL)
-       lttv_hooks_destroy(events_request->after_chunk_trace);
-  if(events_request->after_chunk_traceset != NULL)
-       lttv_hooks_destroy(events_request->after_chunk_traceset);
-  if(events_request->before_request != NULL)
-       lttv_hooks_destroy(events_request->before_request);
-  if(events_request->after_request != NULL)
-       lttv_hooks_destroy(events_request->after_request);
-
-  g_free(events_request);
-}
-
-
-
 /* lttvwindow_process_pending_requests
  * 
  * This internal function gets called by g_idle, taking care of the pending
@@ -959,8 +934,9 @@ gboolean lttvwindow_process_pending_requests(Tab *tab)
   }
 
   /* 0.2 Seek tracefiles positions to context position */
+  //g_assert(lttv_process_traceset_seek_position(tsc, sync_position) == 0);
   lttv_process_traceset_synchronize_tracefiles(tsc);
-
+  
   
   /* Events processing algorithm implementation */
   /* Warning : the gtk_events_pending takes a LOT of cpu time. So what we do
@@ -1102,6 +1078,9 @@ gboolean lttvwindow_process_pending_requests(Tab *tab)
                lttv_process_traceset_middle(tsc,
                                             events_request->start_time,
                                             G_MAXUINT, NULL);
+#ifdef DEBUG
+            g_assert(seek_count < LTTV_STATE_SAVE_INTERVAL);
+#endif //DEBUG
 
 
         } else {
@@ -1566,7 +1545,7 @@ gboolean lttvwindow_process_pending_requests(Tab *tab)
       /* 1.1. Use current postition as start position */
       if(events_request->start_position != NULL)
         lttv_traceset_context_position_destroy(events_request->start_position);
-      events_request->start_position = lttv_traceset_context_position_new();
+      events_request->start_position = lttv_traceset_context_position_new(tsc);
       lttv_traceset_context_position_save(tsc, events_request->start_position);
 
       /* 1.2. Remove start time */
@@ -1592,10 +1571,10 @@ gboolean lttvwindow_process_pending_requests(Tab *tab)
 
 
   }
-  
   /* C Unlock Traces */
   {
-    //lttv_process_traceset_get_sync_data(tsc);
+    lttv_process_traceset_get_sync_data(tsc);
+    //lttv_traceset_context_position_save(tsc, sync_position);
     
     guint iter_trace;
     
@@ -1607,7 +1586,6 @@ gboolean lttvwindow_process_pending_requests(Tab *tab)
       lttvwindowtraces_unlock(trace_v);
     }
   }
-
 #if 0
   //set the cursor back to normal
   gdk_window_set_cursor(win, NULL);  
@@ -1779,9 +1757,11 @@ void add_trace(GtkWidget * widget, gpointer user_data)
  * it will remove the trace,  recreate the traceset_contex,
  * and redraws all the viewer of the current tab. If there is on trace in the
  * current traceset, it will delete all viewers of the current tab
+ *
+ * It destroys the filter tree. FIXME... we should request for an update
+ * instead.
  */
 
-// MD : no filter version.
 void remove_trace(GtkWidget *widget, gpointer user_data)
 {
   LttTrace *trace;
@@ -1807,7 +1787,7 @@ void remove_trace(GtkWidget *widget, gpointer user_data)
   for(i = 0; i < nb_trace; i++){
     trace_v = lttv_traceset_get(tab->traceset_info->traceset, i);
     trace = lttv_trace(trace_v);
-    name[i] = ltt_trace_name(trace);
+    name[i] = g_quark_to_string(ltt_trace_name(trace));
   }
 
   remove_trace_name = get_remove_trace(name, nb_trace);
@@ -2259,6 +2239,8 @@ Tab *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"))    
     return (create_tab (mw_data, copy_tab, notebook, label));
+  else
+    return NULL;
 }
 
 void
@@ -2362,7 +2344,7 @@ void
 on_quit_activate                       (GtkMenuItem     *menuitem,
                                         gpointer         user_data)
 {
-  gtk_main_quit ();
+  mainwindow_quit();
 }
 
 
@@ -3199,7 +3181,7 @@ on_MWindow_destroy                     (GtkWidget       *widget,
 
   g_info("There are now : %d windows\n",g_slist_length(g_main_window_list));
   if(g_slist_length(g_main_window_list) == 0)
-    gtk_main_quit ();
+    mainwindow_quit();
 }
 
 gboolean    
@@ -3257,6 +3239,8 @@ void time_change_manager               (Tab *tab,
   LttTime start_time = new_time_window.start_time;
   LttTime end_time = new_time_window.end_time;
 
+  g_assert(ltt_time_compare(start_time, end_time) < 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);
@@ -3607,6 +3591,22 @@ void current_time_change_manager       (Tab *tab,
   tab->current_time_manager_lock = FALSE;
 }
 
+void current_position_change_manager(Tab *tab,
+                                     LttvTracesetContextPosition *pos)
+{
+  LttvTracesetContext *tsc =
+    LTTV_TRACESET_CONTEXT(tab->traceset_info->traceset_context);
+  TimeInterval time_span = tsc->time_span;
+
+  g_assert(lttv_process_traceset_seek_position(tsc, pos) == 0);
+  LttTime new_time = lttv_traceset_context_position_get_time(pos);
+  
+  current_time_change_manager(tab, new_time);
+  
+  set_current_position(tab, pos);
+}
+
+
 void
 on_MEntry5_value_changed               (GtkSpinButton *spinbutton,
                                         gpointer user_data)
@@ -3809,7 +3809,7 @@ char * get_selection(char ** loaded_module_name, int nb_module,
   }
 
   id = gtk_dialog_run(GTK_DIALOG(dialogue));
-  GtkTreeModel **store_model = (GtkTreeModel**)&store;  /* for strict aliasing */
+  GtkTreeModel **store_model = (GtkTreeModel**)&store;
   switch(id){
     case GTK_RESPONSE_ACCEPT:
     case GTK_RESPONSE_OK:
@@ -4123,12 +4123,10 @@ Tab* create_tab(MainWindow * mw, Tab *copy_tab,
     /* We can clone the filter, as we copy the trace set also */
     /* The filter must always be in sync with the trace set */
     tab->filter = lttv_filter_clone(copy_tab->filter);
-
   } else {
     tab->traceset_info->traceset = lttv_traceset_new();
     tab->filter = NULL;
   }
-
 #ifdef DEBUG
   lttv_attribute_write_xml(
       lttv_traceset_attribute(tab->traceset_info->traceset),
@@ -4185,12 +4183,17 @@ Tab* create_tab(MainWindow * mw, Tab *copy_tab,
   tab->viewer_container = gtk_vbox_new(TRUE, 2);
   tab->scrollbar = gtk_hscrollbar_new(NULL);
   //tab->multivpaned = gtk_multi_vpaned_new();
-  
   gtk_box_pack_start(GTK_BOX(tab->vbox),
                      tab->viewer_container,
                      TRUE, /* expand */
                      TRUE, /* Give the extra space to the child */
                      0);    /* No padding */
+  
+//  if(copy_tab) {
+//    tab->time_window = copy_tab->time_window;
+//    tab->current_time = copy_tab->current_time;
+//  }
 
   /* Create the timebar */
   {
@@ -4434,6 +4437,25 @@ Tab* create_tab(MainWindow * mw, Tab *copy_tab,
   // always show : not if(g_list_length(list)>1)
   gtk_notebook_set_show_tabs(notebook, TRUE);
  
+  if(copy_tab) {
+    lttvwindow_report_time_window(tab, copy_tab->time_window);
+    lttvwindow_report_current_time(tab, copy_tab->current_time);
+  } else {
+    TimeWindow time_window;
+
+    time_window.start_time = ltt_time_zero;
+    time_window.end_time = ltt_time_add(time_window.start_time,
+        lttvwindow_default_time_width);
+    time_window.time_width = lttvwindow_default_time_width;
+    time_window.time_width_double = ltt_time_to_double(time_window.time_width);
+
+    lttvwindow_report_time_window(tab, time_window);
+    lttvwindow_report_current_time(tab, ltt_time_zero);
+  }
+  LttvTraceset *traceset = tab->traceset_info->traceset;
+  SetTraceset(tab, traceset);
+
   return tab;
 }
 
This page took 0.027595 seconds and 4 git commands to generate.