stats major rework, with addition of function support
[lttv.git] / ltt / branches / poly / lttv / modules / gui / lttvwindow / lttvwindow / lttvwindow.c
index 9f153a75ed54169a1b92dc388a383c1ec113e98d..a379df5d8152a03ffdafcb7baa53967a92a404b6 100644 (file)
  * 
  */
 
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
 #include <ltt/ltt.h>
 #include <lttv/lttv.h>
 #include <lttv/state.h>
@@ -97,6 +101,27 @@ void set_current_time(Tab *tab, const LttTime *current_time)
   if(tmp != NULL) lttv_hooks_call(tmp, &tab->current_time);
 }
 
+/* set_current_position
+ *
+ * It updates the current time of the tab, then calls the updatetimewindow
+ * hooks of each viewer.
+ *
+ * This is called whenever the current time value changes.
+ */
+
+void set_current_position(Tab *tab, const LttvTracesetContextPosition *pos)
+{
+  LttvAttributeValue value;
+  LttvHooks * tmp;
+
+  tab->current_time = lttv_traceset_context_position_get_time(pos);
+
+  g_assert(lttv_iattribute_find_by_path(tab->attributes,
+           "hooks/updatecurrentposition", LTTV_POINTER, &value));
+  tmp = (LttvHooks*)*(value.v_pointer);
+  if(tmp != NULL) lttv_hooks_call(tmp, pos);
+}
+
 void add_toolbar_constructor(MainWindow *mw, LttvToolbarClosure *toolbar_c)
 {
   LttvIAttribute *attributes = mw->attributes;
@@ -228,6 +253,7 @@ void remove_menu_constructor(MainWindow *mw, lttvwindow_viewer_constructor viewe
  * 
  * It should be called by init function of the module.
  * 
+ * @param name name of the viewer
  * @param menu_path path of the menu item.
  * @param menu_text text of the menu item.
  * @param pixmap Image shown on the toolbar item.
@@ -236,7 +262,8 @@ void remove_menu_constructor(MainWindow *mw, lttvwindow_viewer_constructor viewe
  */
 
 void lttvwindow_register_constructor
-                            (char *  menu_path, 
+                            (char *  name,
+                             char *  menu_path, 
                              char *  menu_text,
                              char ** pixmap,
                              char *  tooltip,
@@ -249,6 +276,8 @@ void lttvwindow_register_constructor
   LttvMenuClosure menu_c;
   LttvAttributeValue value;
 
+  if(view_constructor == NULL) return;
+  
   if(pixmap != NULL) {
     g_assert(lttv_iattribute_find_by_path(attributes_global,
        "viewers/toolbar", LTTV_POINTER, &value));
@@ -281,6 +310,19 @@ void lttvwindow_register_constructor
                     (gpointer)add_menu_constructor,
                     &menu_c);
   }
+  {
+    LttvAttribute *attribute;
+    g_assert(attribute = 
+      LTTV_ATTRIBUTE(lttv_iattribute_find_subdir(
+                                LTTV_IATTRIBUTE(attributes_global),
+                                LTTV_VIEWER_CONSTRUCTORS)));
+  
+    g_assert(lttv_iattribute_find_by_path(LTTV_IATTRIBUTE(attribute),
+                            name, LTTV_POINTER, &value));
+
+    *(value.v_pointer) = view_constructor;
+
+  }
 }
 
 
@@ -324,6 +366,29 @@ void lttvwindow_unregister_constructor
                     view_constructor);
     lttv_menus_remove(menu, view_constructor);
   }
+
+  {
+    LttvAttribute *attribute;
+    g_assert(attribute = 
+      LTTV_ATTRIBUTE(lttv_iattribute_find_subdir(
+                                LTTV_IATTRIBUTE(attributes_global),
+                                LTTV_VIEWER_CONSTRUCTORS)));
+  
+    guint num = lttv_iattribute_get_number(LTTV_IATTRIBUTE(attribute));
+    guint i;
+    LttvAttributeName name;
+    LttvAttributeValue value;
+    LttvAttributeType type;
+    
+    for(i=0;i<num;i++) {
+      type = lttv_iattribute_get(LTTV_IATTRIBUTE(attribute), i, &name, &value);
+      g_assert(type == LTTV_POINTER);
+      if(*(value.v_pointer) == view_constructor) {
+        lttv_iattribute_remove(LTTV_IATTRIBUTE(attribute), i);
+        break;
+      }
+    }
+  }
 }
 
 
@@ -556,7 +621,7 @@ void lttvwindow_unregister_filter_notify(Tab *tab,
 }
 
 /**
- * Function to register a hook function for a viewer to set/update its 
+ * function to register a hook function for a viewer to set/update its 
  * current time.
  * @param tab viewer's tab 
  * @param hook hook function of the viewer.
@@ -580,7 +645,7 @@ void lttvwindow_register_current_time_notify(Tab *tab,
 
 
 /**
- * Function to unregister a viewer's hook function which is used to 
+ * function to unregister a viewer's hook function which is used to 
  * set/update the current time of the viewer.
  * @param tab viewer's tab 
  * @param hook hook function of the viewer.
@@ -599,6 +664,50 @@ void lttvwindow_unregister_current_time_notify(Tab *tab,
   lttv_hooks_remove_data(tmp, hook, hook_data);
 }
 
+/**
+ * function to register a hook function for a viewer to set/update its 
+ * current position.
+ * @param tab viewer's tab 
+ * @param hook hook function of the viewer.
+ * @param hook_data hook data associated with the hook function.
+ */
+
+void lttvwindow_register_current_position_notify(Tab *tab,
+            LttvHook hook, gpointer hook_data)
+{
+  LttvAttributeValue value;
+  LttvHooks * tmp;
+  g_assert(lttv_iattribute_find_by_path(tab->attributes,
+           "hooks/updatecurrentposition", LTTV_POINTER, &value));
+  tmp = (LttvHooks*)*(value.v_pointer);
+  if(tmp == NULL){    
+    tmp = lttv_hooks_new();
+    *(value.v_pointer) = tmp;
+  }
+  lttv_hooks_add(tmp, hook, hook_data, LTTV_PRIO_DEFAULT);
+}
+
+
+/**
+ * function to unregister a viewer's hook function which is used to 
+ * set/update the current position of the viewer.
+ * @param tab viewer's tab 
+ * @param hook hook function of the viewer.
+ * @param hook_data hook data associated with the hook function.
+ */
+
+void lttvwindow_unregister_current_position_notify(Tab *tab,
+            LttvHook hook, gpointer hook_data)
+{
+  LttvAttributeValue value;
+  LttvHooks * tmp;
+  g_assert(lttv_iattribute_find_by_path(tab->attributes,
+           "hooks/updatecurrentposition", LTTV_POINTER, &value));
+  tmp = (LttvHooks*)*(value.v_pointer);
+  if(tmp == NULL) return;
+  lttv_hooks_remove_data(tmp, hook, hook_data);
+}
+
 
 /**
  * Function to register a hook function for a viewer to show 
@@ -719,24 +828,24 @@ void lttvwindow_report_time_window(Tab *tab,
                "upper",
                ltt_time_to_double(
                  ltt_time_sub(time_span.end_time, time_span.start_time)) 
-                 * NANOSECONDS_PER_SECOND, /* upper */
+                 , /* upper */
                "step_increment",
                ltt_time_to_double(time_window->time_width)
                              / SCROLL_STEP_PER_PAGE
-                             * NANOSECONDS_PER_SECOND, /* step increment */
+                            , /* step increment */
                "page_increment",
                ltt_time_to_double(time_window->time_width) 
-                 * NANOSECONDS_PER_SECOND, /* page increment */
+                 , /* page increment */
                "page_size",
                ltt_time_to_double(time_window->time_width) 
-                 * NANOSECONDS_PER_SECOND, /* page size */
+                 , /* page size */
                NULL);
   gtk_adjustment_changed(adjustment);
 
   //g_object_set(G_OBJECT(adjustment),
   //             "value",
   //             ltt_time_to_double(time_window->start_time) 
-  //               * NANOSECONDS_PER_SECOND, /* value */
+  //               , /* value */
   //               NULL);
   /* Note : the set value will call set_time_window if scrollbar value changed
    */
@@ -744,13 +853,13 @@ void lttvwindow_report_time_window(Tab *tab,
                            ltt_time_to_double(
                              ltt_time_sub(time_window->start_time,
                                           time_span.start_time))
-                           * NANOSECONDS_PER_SECOND);
+                           );
 #endif //0
 }
 
 
 /**
- * Function to set the current time/event of the current tab.
+ * Function to set the current time of the current tab.
  * It will be called by a viewer's signal handle associated with 
  * the button-release-event signal
  * @param tab viewer's tab 
@@ -766,6 +875,24 @@ void lttvwindow_report_current_time(Tab *tab,
   current_time_change_manager(tab, time);
 }
 
+/**
+ * Function to set the current event of the current tab.
+ * It will be called by a viewer's signal handle associated with 
+ * the button-release-event signal
+ * @param tab viewer's tab 
+ * @param time a pointer where time is stored.
+ */
+
+void lttvwindow_report_current_position(Tab *tab,
+                                        LttvTracesetContextPosition *pos)
+{
+  LttvAttributeValue value;
+  LttvHooks * tmp;
+  
+  current_position_change_manager(tab, pos);
+}
+
+
 /**
  * Function to set the position of the hpane's dividor (viewer).
  * It will be called by a viewer's signal handle associated with 
@@ -811,8 +938,10 @@ void lttvwindow_events_request(Tab *tab,
   if(!tab->events_request_pending)
   {
     /* Redraw has +20 priority. We want to let the redraw be done while we do
-     * our job.  */
-    g_idle_add_full((G_PRIORITY_HIGH_IDLE + 21),
+     * our job. Mathieu : test with high prio higher than events for better
+     * scrolling. */
+    //g_idle_add_full((G_PRIORITY_HIGH_IDLE + 21),
+    g_idle_add_full((G_PRIORITY_DEFAULT + 2),
                     (GSourceFunc)execute_events_requests,
                     tab,
                     NULL);
@@ -840,10 +969,10 @@ gint find_viewer (const EventsRequest *a, gconstpointer b)
 void lttvwindow_events_request_remove_all(Tab       *tab,
                                           gconstpointer   viewer)
 {
-  GSList *element;
+  GSList *element = tab->events_requests;
   
   while((element = 
-            g_slist_find_custom(tab->events_requests, viewer,
+            g_slist_find_custom(element, viewer,
                                 (GCompareFunc)find_viewer))
               != NULL) {
     EventsRequest *events_request = (EventsRequest *)element->data;
@@ -853,8 +982,11 @@ void lttvwindow_events_request_remove_all(Tab       *tab,
     //if(events_request->servicing == TRUE) {
     //  lttv_hooks_call(events_request->after_request, NULL);
     //}
-    g_free(events_request);
+    events_request_free(events_request);
+    //g_free(events_request);
     tab->events_requests = g_slist_remove_link(tab->events_requests, element);
+    element = g_slist_next(element);
+    if(element == NULL) break;   /* end of list */
   }
   if(g_slist_length(tab->events_requests) == 0) {
     tab->events_request_pending = FALSE;
@@ -864,6 +996,27 @@ void lttvwindow_events_request_remove_all(Tab       *tab,
 }
 
 
+/**
+ * Function to see if there are events request pending.
+ *
+ * It tells if events requests are pending. Useful for checks in some events,
+ * i.e. detailed event list scrolling.
+ * 
+ * @param tab the tab the viewer belongs to.
+ * @param viewer a pointer to the viewer data structure
+ * @return : TRUE is events requests are pending, else FALSE.
+ */
+
+gboolean lttvwindow_events_request_pending(Tab            *tab)
+{
+  GSList *element = tab->events_requests;
+
+  if(element == NULL) return FALSE;
+  else return TRUE;
+}
+
+
+
 
 /**
  * Function to get the current time interval shown on the current tab.
@@ -877,7 +1030,6 @@ void lttvwindow_events_request_remove_all(Tab       *tab,
 TimeWindow lttvwindow_get_time_window(Tab *tab)
 {
   return tab->time_window;
-  
 }
 
 
@@ -897,17 +1049,44 @@ LttTime lttvwindow_get_current_time(Tab *tab)
 
 /**
  * Function to get the filter of the current tab.
- * It will be called by the constructor of the viewer and also be
- * called by a hook funtion of the viewer to update its filter.
- * @param tab viewer's tab 
  * @param filter, a pointer to a filter.
+ *
+ * returns the current filter
  */
-const lttv_filter *lttvwindow_get_filter(Tab *tab)
+LttvFilter *lttvwindow_get_filter(Tab *tab)
 {
-  //FIXME
-  g_warning("lttvwindow_get_filter not implemented in viewer.c");
+  return tab->filter;
 }
 
+/**
+ * Function to set the filter of the current tab.
+ * It should be called by the filter GUI to tell the
+ * main window to update the filter tab's lttv_filter.
+ *
+ * This function does change the current filter, removing the
+ * old one when necessary, and call the updatefilter hooks
+ * of the registered viewers.
+ *
+ * @param main_win, the main window the viewer belongs to.
+ * @param filter, a pointer to a filter.
+ */
+
+void lttvwindow_report_filter(Tab *tab, LttvFilter *filter)
+{
+  LttvAttributeValue value;
+  LttvHooks * tmp;
+
+  lttv_filter_destroy(tab->filter);
+  tab->filter = filter;
+  
+  g_assert(lttv_iattribute_find_by_path(tab->attributes,
+           "hooks/updatefilter", LTTV_POINTER, &value));
+  tmp = (LttvHooks*)*(value.v_pointer);
+  if(tmp == NULL) return;
+  lttv_hooks_call(tmp, filter);
+}
+
+
 
 /**
  * Function to get the stats of the traceset 
@@ -924,3 +1103,52 @@ LttvTracesetContext* lttvwindow_get_traceset_context(Tab *tab)
 {
   return (LttvTracesetContext*)tab->traceset_info->traceset_context;
 }
+
+
+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) {
+    guint i;
+    GArray *hooks = events_request->hooks;
+    for(i=0;i<hooks->len;i++) {
+      lttv_trace_hook_destroy(&g_array_index(hooks, LttvTraceHook, i));
+    }
+    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);
+}
+
+
+
+GtkWidget *main_window_get_widget(Tab *tab)
+{
+  return tab->mw->mwindow;
+}
+
This page took 0.03285 seconds and 4 git commands to generate.