add plugin interface to objects
[lttv.git] / ltt / branches / poly / lttv / modules / gui / statistics / statistics.c
index 63ae23cf06256c27909d0966f4af58929336d408..8efa6b26a228ce06d2c689755d6e9133735fd785 100644 (file)
  * MA 02111-1307, USA.
  */
 
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
 #include <glib.h>
+#include <string.h>
 #include <gtk/gtk.h>
 #include <gdk/gdk.h>
 
@@ -34,6 +39,7 @@
 
 #include <lttvwindow/lttvwindow.h>
 #include <lttvwindow/lttvwindowtraces.h>
+#include <lttvwindow/lttv_plugin_tab.h>
 
 #include "hGuiStatisticInsert.xpm"
 
@@ -52,13 +58,12 @@ static void request_background_data(StatisticViewerData *svd);
 GtkWidget *guistatistic_get_widget(StatisticViewerData *svd);
 
 //! Statistic Viewer's constructor hook
-GtkWidget *h_gui_statistic(Tab *tab, LttvTracesetSelector * s, char * key);
+GtkWidget *h_gui_statistic(LttvPlugin *plugin);
 //! Statistic Viewer's constructor
-StatisticViewerData *gui_statistic(Tab *tab);
+StatisticViewerData *gui_statistic(LttvPluginTab *ptab);
 //! Statistic Viewer's destructor
 void gui_statistic_destructor(StatisticViewerData *statistic_viewer_data);
 
-void grab_focus(GtkWidget *widget, gpointer data);
 static void tree_selection_changed_cb (GtkTreeSelection *selection, gpointer data);
 
 void statistic_destroy_hash_key(gpointer key);
@@ -87,6 +92,7 @@ enum
 
 struct _StatisticViewerData{
   Tab *tab;
+  LttvPluginTab *ptab;
   //LttvTracesetStats * stats;
   int                 size;
 
@@ -164,9 +170,9 @@ static void request_background_data(StatisticViewerData *svd)
          * information. Happens when two viewers ask for it before servicing
          * starts.
          */
-        lttvwindowtraces_background_request_remove(trace, "stats");
-        lttvwindowtraces_background_request_queue(trace,
-                                                  "stats");
+        if(!lttvwindowtraces_background_request_find(trace, "stats"))
+          lttvwindowtraces_background_request_queue(
+              main_window_get_widget(svd->tab), trace, "stats");
         lttvwindowtraces_background_notify_queue(svd,
                                                  trace,
                                                  ltt_time_infinite,
@@ -181,6 +187,9 @@ static void request_background_data(StatisticViewerData *svd)
                                                    background_ready_hook);
       
       }
+    } else {
+      /* ready */
+      lttv_hooks_call(background_ready_hook, NULL);
     }
   }
   lttv_hooks_destroy(background_ready_hook);
@@ -225,9 +234,10 @@ gui_statistic_destructor(StatisticViewerData *statistic_viewer_data)
  * @return The widget created.
  */
 GtkWidget *
-h_gui_statistic(Tab *tab, LttvTracesetSelector * s, char * key)
+h_gui_statistic(LttvPlugin *plugin)
 {
-  StatisticViewerData* statistic_viewer_data = gui_statistic(tab) ;
+  LttvPluginTab *ptab = LTTV_PLUGIN_TAB(plugin);
+  StatisticViewerData* statistic_viewer_data = gui_statistic(ptab) ;
 
   if(statistic_viewer_data)
     return guistatistic_get_widget(statistic_viewer_data);
@@ -261,14 +271,15 @@ gboolean statistic_insert_traceset_stats(void * stats)
  * @return The Statistic viewer data created.
  */
 StatisticViewerData *
-gui_statistic(Tab *tab)
+gui_statistic(LttvPluginTab *ptab)
 {
   GtkCellRenderer *renderer;
   GtkTreeViewColumn *column;
 
   StatisticViewerData* statistic_viewer_data = g_new(StatisticViewerData,1);
-
+  Tab *tab = ptab->tab;
   statistic_viewer_data->tab  = tab;
+  statistic_viewer_data->ptab  = ptab;
  // statistic_viewer_data->stats  =
  //         lttvwindow_get_traceset_stats(statistic_viewer_data->tab);
  // statistic_viewer_data->calculate_stats = 
@@ -277,12 +288,11 @@ gui_statistic(Tab *tab)
   lttvwindow_register_traceset_notify(statistic_viewer_data->tab,
                                       statistic_traceset_changed,
                                       statistic_viewer_data);
-  request_background_data(statistic_viewer_data);
-  
   statistic_viewer_data->statistic_hash = g_hash_table_new_full(g_str_hash,
                                                   g_str_equal,
                                                   statistic_destroy_hash_key,
-                                                  statistic_destroy_hash_data);
+                                                  NULL);
 
   statistic_viewer_data->hpaned_v  = gtk_hpaned_new();
   statistic_viewer_data->store_m = gtk_tree_store_new (N_COLUMNS, G_TYPE_STRING);
@@ -291,10 +301,6 @@ gui_statistic(Tab *tab)
         GTK_TREE_MODEL (statistic_viewer_data->store_m));
   g_object_unref (G_OBJECT (statistic_viewer_data->store_m));
 
-  g_signal_connect (G_OBJECT (statistic_viewer_data->tree_v), "grab-focus",
-        G_CALLBACK (grab_focus),
-        statistic_viewer_data);
-
   // Setup the selection handler
   statistic_viewer_data->select_c = gtk_tree_view_get_selection (GTK_TREE_VIEW (statistic_viewer_data->tree_v));
   gtk_tree_selection_set_mode (statistic_viewer_data->select_c, GTK_SELECTION_SINGLE);
@@ -327,15 +333,15 @@ gui_statistic(Tab *tab)
          GTK_POLICY_AUTOMATIC,GTK_POLICY_AUTOMATIC);
 
   statistic_viewer_data->text_v = gtk_text_view_new ();
-  g_signal_connect (G_OBJECT (statistic_viewer_data->text_v), "grab-focus",
-        G_CALLBACK (grab_focus),
-        statistic_viewer_data);
   
   gtk_text_view_set_editable(GTK_TEXT_VIEW(statistic_viewer_data->text_v),FALSE);
   gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(statistic_viewer_data->text_v),FALSE);
   gtk_container_add (GTK_CONTAINER (statistic_viewer_data->scroll_win_text), statistic_viewer_data->text_v);
   gtk_paned_pack2(GTK_PANED(statistic_viewer_data->hpaned_v), statistic_viewer_data->scroll_win_text, TRUE, FALSE);
 
+  gtk_container_set_border_width(
+      GTK_CONTAINER(statistic_viewer_data->hpaned_v), 1);
+  
   gtk_widget_show(statistic_viewer_data->scroll_win_tree);
   gtk_widget_show(statistic_viewer_data->scroll_win_text);
   gtk_widget_show(statistic_viewer_data->tree_v);
@@ -353,16 +359,11 @@ gui_statistic(Tab *tab)
       g_statistic_viewer_data_list,
       statistic_viewer_data);
 
+  request_background_data(statistic_viewer_data);
   return statistic_viewer_data;
 }
 
-void grab_focus(GtkWidget *widget, gpointer data)
-{
-  StatisticViewerData *statistic_viewer_data = (StatisticViewerData *)data;
-  Tab * tab = statistic_viewer_data->tab;
-  lttvwindow_report_focus(tab, guistatistic_get_widget(statistic_viewer_data));
-}
-
 static void
 tree_selection_changed_cb (GtkTreeSelection *selection, gpointer data)
 {
@@ -403,15 +404,12 @@ void statistic_destroy_hash_key(gpointer key)
   g_free(key);
 }
 
-void statistic_destroy_hash_data(gpointer data)
-{
-  //  g_free(data);
-}
-
+#ifdef DEBUG
 #include <stdio.h>
 extern FILE *stdin;
 extern FILE *stdout;
 extern FILE *stderr;
+#endif //DEBUG
 
 void show_traceset_stats(StatisticViewerData * statistic_viewer_data)
 {
@@ -448,11 +446,15 @@ void show_traceset_stats(StatisticViewerData * statistic_viewer_data)
   //show stats for all traces
   for(i = 0 ; i < nb ; i++) {
     tcs = (LttvTraceStats *)(LTTV_TRACESET_CONTEXT(tscs)->traces[i]);
+#if 0 //FIXME
     desc = ltt_trace_system_description(tcs->parent.parent.t);    
-    sprintf(trace_str, "Trace on system %s at time %d secs", 
+    LttTime start_time = ltt_trace_system_description_trace_start_time(desc);
+    sprintf(trace_str, "Trace on system %s at time %lu.%09lu", 
             ltt_trace_system_description_node_name(desc),
-      (ltt_trace_system_description_trace_start_time(desc)).tv_sec);
-    
+            start_time.tv_sec,
+            start_time.tv_nsec);
+#endif //0
+    sprintf(trace_str, g_quark_to_string(ltt_trace_name(tcs->parent.parent.t)));
     gtk_tree_store_append (store, &iter, NULL);  
     gtk_tree_store_set (store, &iter,NAME_COLUMN,trace_str,-1);  
     path = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &iter);
@@ -474,6 +476,7 @@ void show_tree(StatisticViewerData * statistic_viewer_data,
   LttvAttributeName name;
   LttvAttributeValue value;
   LttvAttributeType type;
+       gboolean is_named;
   gchar * str, dir_str[PATH_LENGTH];
   GtkTreePath * path;
   GtkTreeIter   iter;
@@ -481,17 +484,20 @@ void show_tree(StatisticViewerData * statistic_viewer_data,
 
   nb = lttv_attribute_get_number(stats);
   for(i = 0 ; i < nb ; i++) {
-    type = lttv_attribute_get(stats, i, &name, &value);
+    type = lttv_attribute_get(stats, i, &name, &value, &is_named);
     switch(type) {
      case LTTV_GOBJECT:
         if(LTTV_IS_ATTRIBUTE(*(value.v_gobject))) {
-    sprintf(dir_str, "%s", g_quark_to_string(name));
           subtree = (LttvAttribute *)*(value.v_gobject);
-    gtk_tree_store_append (store, &iter, parent);  
-    gtk_tree_store_set (store, &iter,NAME_COLUMN,dir_str,-1);  
-    path = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &iter);
-    str = gtk_tree_path_to_string (path);
-    g_hash_table_insert(statistic_viewer_data->statistic_hash,
+          if(is_named)
+            sprintf(dir_str, "%s", g_quark_to_string(name));
+          else
+            sprintf(dir_str, "%u", name);
+          gtk_tree_store_append (store, &iter, parent);  
+          gtk_tree_store_set (store, &iter,NAME_COLUMN,dir_str,-1);  
+          path = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &iter);
+          str = gtk_tree_path_to_string (path);
+          g_hash_table_insert(statistic_viewer_data->statistic_hash,
             (gpointer)str, subtree);
           show_tree(statistic_viewer_data, subtree, &iter);
         }
@@ -506,18 +512,21 @@ void show_statistic(StatisticViewerData * statistic_viewer_data,
         LttvAttribute* stats, GtkTextBuffer* buf)
 {
   int i, nb , flag;
-  LttvAttribute *subtree;
   LttvAttributeName name;
   LttvAttributeValue value;
   LttvAttributeType type;
+       gboolean is_named;
   gchar type_name[PATH_LENGTH], type_value[PATH_LENGTH];
   GtkTextIter   text_iter;
   
   flag = 0;
   nb = lttv_attribute_get_number(stats);
   for(i = 0 ; i < nb ; i++) {
-    type = lttv_attribute_get(stats, i, &name, &value);
-    sprintf(type_name,"%s", g_quark_to_string(name));
+    type = lttv_attribute_get(stats, i, &name, &value, &is_named);
+               if(is_named)
+           sprintf(type_name,"%s", g_quark_to_string(name));
+               else
+           sprintf(type_name,"%u", name);
     type_value[0] = '\0';
     switch(type) {
       case LTTV_INT:
@@ -539,7 +548,7 @@ void show_statistic(StatisticViewerData * statistic_viewer_data,
         sprintf(type_value, " :  %f\n", *value.v_double);
         break;
       case LTTV_TIME:
-        sprintf(type_value, " :  %10u.%09u\n", value.v_time->tv_sec, 
+        sprintf(type_value, " :  %10lu.%09lu\n", value.v_time->tv_sec, 
             value.v_time->tv_nsec);
         break;
       case LTTV_POINTER:
@@ -675,7 +684,8 @@ void statistic_remove_context_hooks(StatisticViewerData * statistic_viewer_data,
  */
 static void init() {
 
-  lttvwindow_register_constructor("/",
+  lttvwindow_register_constructor("guistatistics",
+                                  "/",
                                   "Insert Statistic Viewer",
                                   hGuiStatisticInsert_xpm,
                                   "Insert Statistic Viewer",
@@ -699,7 +709,6 @@ void statistic_destroy_walk(gpointer data, gpointer user_data)
  * everything that has been registered in the gtkTraceSet API.
  */
 static void destroy() {
-  int i;
   
   g_slist_foreach(g_statistic_viewer_data_list, statistic_destroy_walk, NULL );    
   g_slist_free(g_statistic_viewer_data_list);
This page took 0.026719 seconds and 4 git commands to generate.