global traces works, interaction with mainwindow seems ok
authorcompudj <compudj@04897980-b3bd-0310-b5e0-8ef037075253>
Sat, 19 Jun 2004 19:35:43 +0000 (19:35 +0000)
committercompudj <compudj@04897980-b3bd-0310-b5e0-8ef037075253>
Sat, 19 Jun 2004 19:35:43 +0000 (19:35 +0000)
git-svn-id: http://ltt.polymtl.ca/svn@600 04897980-b3bd-0310-b5e0-8ef037075253

ltt/branches/poly/lttv/modules/gui/lttvwindow/lttvwindow/Makefile.am
ltt/branches/poly/lttv/modules/gui/lttvwindow/lttvwindow/callbacks.c
ltt/branches/poly/lttv/modules/gui/lttvwindow/lttvwindow/init_module.c
ltt/branches/poly/lttv/modules/gui/lttvwindow/lttvwindow/lttvwindow.h
ltt/branches/poly/lttv/modules/gui/lttvwindow/lttvwindow/lttvwindowtraces.c [new file with mode: 0644]
ltt/branches/poly/lttv/modules/gui/lttvwindow/lttvwindow/lttvwindowtraces.h [new file with mode: 0644]
ltt/branches/poly/lttv/modules/gui/lttvwindow/lttvwindow/mainwindow.h

index 77a82ecfece1e5c0d98a1a239bab8c67589b77a2..a5cddfb964e69ce17836e45057a3e9f1613958f5 100644 (file)
@@ -24,6 +24,7 @@ liblttvwindow_la_SOURCES = \
        gtkdirsel.c\
        gtkmultivpaned.c\
        lttvwindow.c \
+       lttvwindowtraces.c \
        init_module.c \
        support.c \
        interface.c \
@@ -40,6 +41,7 @@ lttvwindowinclude_HEADERS = \
        gtkdirsel.h\
        gtkmultivpaned.h\
        lttvwindow.h\
+       lttvwindowtraces.h\
        lttvfilter.h\
        mainwindow.h\
        menu.h\
index 300b4406b1503516e91745f1c3f3aef5efd444a1..c6f574d498c38832ec7c0afb93abf018dcbd4f04 100644 (file)
@@ -20,6 +20,9 @@
 #  include <config.h>
 #endif
 
+#include <limits.h> // for PATH_MAX
+#include <stdlib.h>
+
 #include <gtk/gtk.h>
 
 #include "callbacks.h"
 #include <lttvwindow/menu.h>
 #include <lttvwindow/toolbar.h>
 #include <lttvwindow/lttvwindow.h>
+#include <lttvwindow/lttvwindowtraces.h>
 #include <lttvwindow/gtkdirsel.h>
 #include <lttvwindow/lttvfilter.h>
 
-#define PATH_LENGTH          256
+
 #define DEFAULT_TIME_WIDTH_S   1
 
 extern LttvTrace *g_init_trace ;
@@ -51,8 +55,8 @@ extern LttvTrace *g_init_trace ;
 extern GSList * g_main_window_list;
 
 /** MD : keep old directory. */
-static char remember_plugins_dir[PATH_LENGTH] = "";
-static char remember_trace_dir[PATH_LENGTH] = "";
+static char remember_plugins_dir[PATH_MAX] = "";
+static char remember_trace_dir[PATH_MAX] = "";
 
 
 MainWindow * get_window_data_struct(GtkWidget * widget);
@@ -871,7 +875,9 @@ gboolean lttvwindow_process_pending_requests(Tab *tab)
       EventsRequest *events_request = (EventsRequest *)iter->data;
       
       /* 1.1. Use current postition as start position */
-      g_free(events_request->start_position);
+      if(events_request->start_position != NULL)
+        lttv_traceset_context_position_destroy(events_request->start_position);
+      events_request->start_position = ltt_traceset_context_position_new();
       lttv_traceset_context_position_save(tsc, events_request->start_position);
 
       /* 1.2. Remove start time */
@@ -975,6 +981,14 @@ static void lttvwindow_add_trace(Tab *tab, LttvTrace *trace_v)
   LttvTraceset *traceset = tab->traceset_info->traceset;
   guint i;
 
+ //Verify if trace is already present.
+  for(i=0; i<lttv_traceset_number(traceset); i++)
+  {
+    LttvTrace * trace = lttv_traceset_get(traceset, i);
+    if(trace == trace_v)
+      return;
+  }
+
   //Keep a reference to the traces so they are not freed.
   for(i=0; i<lttv_traceset_number(traceset); i++)
   {
@@ -991,6 +1005,7 @@ static void lttvwindow_add_trace(Tab *tab, LttvTrace *trace_v)
   g_object_unref(tab->traceset_info->traceset_context);
 
   lttv_traceset_add(traceset, trace_v);
+  lttv_trace_ref(trace_v);  /* local ref */
 
   /* Create new context */
   tab->traceset_info->traceset_context =
@@ -1023,6 +1038,7 @@ void add_trace(GtkWidget * widget, gpointer user_data)
   LttvTrace * trace_v;
   LttvTraceset * traceset;
   const char * dir;
+  char abs_path[PATH_MAX];
   gint id;
   gint i;
   MainWindow * mw_data = get_window_data_struct(widget);
@@ -1049,14 +1065,19 @@ void add_trace(GtkWidget * widget, gpointer user_data)
     case GTK_RESPONSE_ACCEPT:
     case GTK_RESPONSE_OK:
       dir = gtk_dir_selection_get_dir (file_selector);
-      strncpy(remember_trace_dir, dir, PATH_LENGTH);
+      strncpy(remember_trace_dir, dir, PATH_MAX);
       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);
+      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_critical("cannot open trace %s", abs_path);
+        trace_v = lttv_trace_new(trace);
+        lttvwindowtraces_add_trace(trace_v);
+      }
 
       lttvwindow_add_trace(tab, trace_v);
 
@@ -1195,8 +1216,11 @@ void remove_trace(GtkWidget * widget, gpointer user_data)
 
           trace_v = lttv_traceset_get(traceset, i);
 
-          if(lttv_trace_get_ref_number(trace_v) <= 1)
+          if(lttv_trace_get_ref_number(trace_v) <= 2) {
+            /* ref 2 : traceset, local */
+            lttvwindowtraces_remove_trace(trace_v);
             ltt_trace_close(lttv_trace(trace_v));
+          }
           
           lttv_traceset_remove(traceset, i);
           lttv_trace_unref(trace_v);  // Remove local reference
@@ -1232,7 +1256,7 @@ void remove_trace(GtkWidget * widget, gpointer user_data)
           }else{
             if(tab){
               while(tab->multi_vpaned->num_children){
-          gtk_multi_vpaned_widget_delete(tab->multi_vpaned);
+                gtk_multi_vpaned_widget_delete(tab->multi_vpaned);
               }    
             }      
           }
@@ -1402,7 +1426,7 @@ on_clone_traceset_activate             (GtkMenuItem     *menuitem,
  */
 
 Tab *create_new_tab(GtkWidget* widget, gpointer user_data){
-  gchar label[PATH_LENGTH];
+  gchar label[PATH_MAX];
   MainWindow * mw_data = get_window_data_struct(widget);
 
   GtkNotebook * notebook = (GtkNotebook *)lookup_widget(widget, "MNotebook");
@@ -1662,7 +1686,7 @@ on_load_module_activate                (GtkMenuItem     *menuitem,
 {
   char ** dir;
   gint id;
-  char str[PATH_LENGTH], *str1;
+  char str[PATH_MAX], *str1;
   MainWindow * mw_data = get_window_data_struct((GtkWidget*)menuitem);
   GtkFileSelection * file_selector = (GtkFileSelection *)gtk_file_selection_new("Select a module");
   if(remember_plugins_dir[0] != '\0')
@@ -1675,8 +1699,8 @@ on_load_module_activate                (GtkMenuItem     *menuitem,
     case GTK_RESPONSE_ACCEPT:
     case GTK_RESPONSE_OK:
       dir = gtk_file_selection_get_selections (file_selector);
-      strncpy(str,dir[0],PATH_LENGTH);
-      strncpy(remember_plugins_dir,dir[0],PATH_LENGTH);
+      strncpy(str,dir[0],PATH_MAX);
+      strncpy(remember_plugins_dir,dir[0],PATH_MAX);
       str1 = strrchr(str,'/');
       if(str1)str1++;
       else{
@@ -1757,8 +1781,8 @@ on_add_module_search_path_activate     (GtkMenuItem     *menuitem,
     case GTK_RESPONSE_ACCEPT:
     case GTK_RESPONSE_OK:
       dir = gtk_dir_selection_get_dir (file_selector);
-      strncpy(remember_plugins_dir,dir,PATH_LENGTH);
-      strncat(remember_plugins_dir,"/",PATH_LENGTH);
+      strncpy(remember_plugins_dir,dir,PATH_MAX);
+      strncat(remember_plugins_dir,"/",PATH_MAX);
       lttv_library_path_add(dir);
     case GTK_RESPONSE_REJECT:
     case GTK_RESPONSE_CANCEL:
@@ -2535,10 +2559,8 @@ void tab_destructor(Tab * tab_instance)
       trace = lttv_traceset_get(tab_instance->traceset_info->traceset, i);
       ref_count = lttv_trace_get_ref_number(trace);
       if(ref_count <= 1){
-       ltt_trace_close(lttv_trace(trace));
-       lttv_trace_destroy(trace);
+             ltt_trace_close(lttv_trace(trace));
       }
-      //      lttv_trace_destroy(trace);
     }
   }  
   lttv_traceset_destroy(tab_instance->traceset_info->traceset);
index 505cc86da3416398df06be904fe51c5c1d53b70d..604af308cbd1a2402c484dce2fc7cd4c936d0fa5 100644 (file)
@@ -26,6 +26,7 @@
 #endif
 
 #include <gtk/gtk.h>
+#include <glib.h>
 
 #include <lttv/lttv.h>
 #include <lttv/attribute.h>
@@ -37,6 +38,7 @@
 #include <lttv/stats.h>
 #include <lttvwindow/menu.h>
 #include <lttvwindow/toolbar.h>
+#include <lttvwindow/lttvwindowtraces.h>
 
 #include "interface.h"
 #include "support.h"
 #include <ltt/trace.h>
 
 
-GQuark LTTV_TRACES;
+LttvTraceInfo LTTV_TRACES,
+       LTTV_COMPUTATION,
+       LTTV_REQUESTS_QUEUE,
+       LTTV_REQUESTS_CURRENT,
+       LTTV_NOTIFY_QUEUE,
+       LTTV_NOTIFY_CURRENT;
 
 /** Array containing instanced objects. */
 GSList * g_main_window_list = NULL ;
@@ -63,12 +70,16 @@ static char *a_trace;
 void lttv_trace_option(void *hook_data)
 { 
   LttTrace *trace;
-  gchar *path;
-
-  trace = ltt_trace_open(a_trace);
-  if(trace == NULL) g_critical("cannot open trace %s", a_trace);
-  g_init_trace = lttv_trace_new(trace);
-
+  gchar *abs_path;
+
+  get_absolute_pathname(a_trace, abs_path);
+  g_init_trace = lttvwindowtraces_get_trace_by_name(abs_path);
+  if(g_init_trace == NULL) {
+    trace = ltt_trace_open(abs_path);
+    if(trace == NULL) g_critical("cannot open trace %s", abs_path);
+    g_init_trace = lttv_trace_new(trace);
+    lttvwindowtraces_add_trace(g_init_trace);
+  }
 }
 
 /*****************************************************************************
@@ -110,7 +121,12 @@ static void init() {
   // Global attributes only used for interaction with main() here.
   LttvIAttribute *attributes = LTTV_IATTRIBUTE(lttv_global_attributes());
   
-  LTTV_TRACES = g_quark_from_string("traces/");
+  LTTV_TRACES = g_quark_from_string("traces");
+  LTTV_COMPUTATION = g_quark_from_string("computation");
+  LTTV_REQUESTS_QUEUE = g_quark_from_string("requests_queue");
+  LTTV_REQUESTS_CURRENT = g_quark_from_string("requests_current");
+  LTTV_NOTIFY_QUEUE = g_quark_from_string("notify_queue");
+  LTTV_NOTIFY_CURRENT = g_quark_from_string("notify_current");
   
   g_debug("GUI init()");
 
index cbc2ced23293e49de3f2346e8619f300b0f5e19c..83a67d0219d2b191b6db15b8ced8d340d976545f 100644 (file)
@@ -631,48 +631,6 @@ void lttvwindow_events_request_remove_all(Tab            *tab,
                                           gconstpointer   viewer);
 
 
-typedef struct _BackgroundRequest {
-  gchar *hook_path; /* Hook path in global attributes, where all standard hooks
-                       are : i.e. /TraceState/Statistics/ModuleName */
-  gchar *trace_path; /* path_to_trace */
-} BackgroundRequest;
-
-typedef struct _BackgroundNotify {
-  gchar                       *trace_path; /* path_to_trace */
-  LttTime                      notify_time;
-  LttvTracesetContextPosition *notify_position;
-  LttvHooks                   *notify; /* Hook to call when the notify is
-                                          passed, or at the end of trace */
-} BackgroundNotify;
-
-/**
- * Function to request data from a specific trace
- * 
- * @param bg_request Request specification
- */
-
-void lttvwindow_background_request_queue(const BackgroundRequest  *bg_request);
-
-/**
- * Register a callback to be called when requested data is passed in the next
- * queued background processing.
- * 
- * @param bg_request Request specification
- */
-
-void lttvwindow_background_notify_queue(const BackgroundNotify  *bg_notify);
-
-
-/**
- * Register a callback to be called when requested data is passed in the current
- * background processing.
- * 
- * @param bg_request Request specification
- */
-
-void lttvwindow_background_notify_current(const BackgroundNotify  *bg_notify);
-
-
 /**
  * Function to get the current time window of the current tab.
  * 
diff --git a/ltt/branches/poly/lttv/modules/gui/lttvwindow/lttvwindow/lttvwindowtraces.c b/ltt/branches/poly/lttv/modules/gui/lttvwindow/lttvwindow/lttvwindowtraces.c
new file mode 100644 (file)
index 0000000..3a19000
--- /dev/null
@@ -0,0 +1,403 @@
+/* This file is part of the Linux Trace Toolkit Graphic User Interface
+ * Copyright (C) 2003-2004 Mathieu Desnoyers
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License Version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, 
+ * MA 02111-1307, USA.
+ */
+
+/* This file is the API used to launch any background computation on a trace */
+
+/* Here is the implementation of the API */
+
+#include <ltt/time.h>
+#include <ltt/trace.h>
+#include <glib.h>
+#include <lttv/lttv.h>
+#include <lttv/traceset.h>
+#include <lttv/attribute.h>
+#include <lttv/tracecontext.h>
+#include <lttvwindow/lttvwindowtraces.h>
+
+
+typedef struct _BackgroundRequest {
+  LttvAttributeName module_name; /* Hook path in global attributes,
+                                    where all standard hooks under computation/.
+                                    i.e. modulename */
+  LttvTrace *trace; /* trace concerned */
+} BackgroundRequest;
+
+typedef struct _BackgroundNotify {
+  gpointer                     owner;
+  LttvTrace                   *trace; /* trace */
+  LttTime                      notify_time;
+  LttvTracesetContextPosition *notify_position;
+  LttvHooks                   *notify; /* Hook to call when the notify is
+                                          passed, or at the end of trace */
+} BackgroundNotify;
+
+
+
+/* Get a trace by its path name. 
+ *
+ * @param path path of the trace on the virtual file system.
+ * @return Pointer to trace if found
+ *         NULL is returned if the trace is not present
+ */
+
+LttvTrace *lttvwindowtraces_get_trace_by_name(gchar *path)
+{
+  LttvAttribute *attribute = lttv_global_attributes();
+  guint i;
+
+  for(i=0;i<lttvwindowtraces_get_number();i++) {
+    LttvTrace *trace_v = lttvwindowtraces_get_trace(i);
+    LttTrace *trace;
+    gchar *name;
+    
+    g_assert(trace_v != NULL);
+
+    trace = lttv_trace(trace_v);
+    g_assert(trace != NULL);
+    name = ltt_trace_name(trace);
+
+    if(strcmp(name, path) == 0) {
+      /* Found */
+      return trace_v;
+    }
+  }
+  
+  return NULL;
+}
+
+/* Get a trace by its number identifier */
+
+LttvTrace *lttvwindowtraces_get_trace(guint num)
+{
+  LttvAttribute *g_attribute = lttv_global_attributes();
+  LttvAttribute *attribute;
+  LttvAttributeType type;
+  LttvAttributeName name;
+  LttvAttributeValue value;
+
+  g_assert(attribute = 
+      LTTV_ATTRIBUTE(lttv_iattribute_find_subdir(LTTV_IATTRIBUTE(g_attribute),
+                                LTTV_TRACES)));
+  
+  type = lttv_iattribute_get(LTTV_IATTRIBUTE(attribute), num, &name, &value);
+
+  if(type == LTTV_POINTER) {
+    return (LttvTrace *)*(value.v_pointer);
+  }
+
+  return NULL;
+}
+
+/* Total number of traces */
+
+guint lttvwindowtraces_get_number()
+{
+  LttvAttribute *g_attribute = lttv_global_attributes();
+  LttvAttribute *attribute;
+  LttvAttributeValue value;
+
+  g_assert(attribute = 
+      LTTV_ATTRIBUTE(lttv_iattribute_find_subdir(LTTV_IATTRIBUTE(g_attribute),
+                                LTTV_TRACES)));
+  return ( lttv_iattribute_get_number(LTTV_IATTRIBUTE(attribute)) );
+}
+
+/* Add a trace to the global attributes */
+
+void lttvwindowtraces_add_trace(LttvTrace *trace)
+{
+  LttvAttribute *g_attribute = lttv_global_attributes();
+  LttvAttribute *attribute;
+  LttvAttributeValue value;
+  guint num;
+
+  g_assert(attribute = 
+      LTTV_ATTRIBUTE(lttv_iattribute_find_subdir(LTTV_IATTRIBUTE(g_attribute),
+                                LTTV_TRACES)));
+  num = lttv_attribute_get_number(attribute);
+  value = lttv_attribute_add(attribute,
+                     num,
+                     LTTV_POINTER);
+
+  *(value.v_pointer) = (gpointer)trace;
+}
+
+/* Remove a trace from the global attributes */
+
+void lttvwindowtraces_remove_trace(LttvTrace *trace)
+{
+  LttvAttribute *g_attribute = lttv_global_attributes();
+  LttvAttribute *attribute;
+  LttvAttributeValue value;
+  guint i;
+
+  g_assert(attribute =
+      LTTV_ATTRIBUTE(lttv_iattribute_find_subdir(LTTV_IATTRIBUTE(g_attribute),
+                                LTTV_TRACES)));
+
+  for(i=0;i<lttvwindowtraces_get_number();i++) {
+    LttvTrace *trace_v = lttvwindowtraces_get_trace(i);
+    
+    g_assert(trace_v != NULL);
+
+    if(trace_v == trace) {
+      /* Found */
+      lttv_attribute_remove(attribute, i);
+      return;
+    }
+  }
+}
+
+
+/**
+ * Function to request data from a specific trace
+ *
+ * The memory allocated for the request will be managed by the API.
+ * 
+ * @param trace the trace to compute
+ * @param module_name the name of the module which registered global computation
+ *                    hooks.
+ */
+
+void lttvwindowtraces_background_request_queue
+                     (LttvTrace *trace, gchar *module_name)
+{
+  BackgroundRequest *bg_req;
+  LttvAttribute *attribute = lttv_trace_attribute(trace);
+  LttvAttributeValue value;
+  GSList **slist;
+  guint num;
+
+  g_assert(lttv_iattribute_find(LTTV_IATTRIBUTE(attribute),
+                                LTTV_REQUESTS_QUEUE,
+                                LTTV_POINTER,
+                                &value));
+  slist = (GSList**)(value.v_pointer);
+  
+  bg_req = g_new(BackgroundRequest,1);
+  bg_req->module_name = g_quark_from_string(module_name);
+  bg_req->trace = trace;
+
+  *slist = g_slist_append(*slist, bg_req);
+}
+
+/**
+ * Remove a background request from a trace.
+ *
+ * This should ONLY be used by the modules which registered the global hooks
+ * (module_name). If this is called by the viewers, it may lead to incomplete
+ * and incoherent background processing information.
+ *
+ * Even if the module which deals with the hooks removes the background
+ * requests, it may cause a problem if the module gets loaded again in the
+ * session : the data will be partially calculated. The calculation function
+ * must deal with this case correctly.
+ * 
+ * @param trace the trace to compute
+ * @param module_name the name of the module which registered global computation
+ *                    hooks.
+ */
+
+void lttvwindowtraces_background_request_remove
+                     (LttvTrace *trace, gchar *module_name)
+{
+  LttvAttribute *attribute = lttv_trace_attribute(trace);
+  LttvAttributeValue value;
+  GSList *iter = NULL;
+  GSList **slist;
+
+  g_assert(lttv_iattribute_find(LTTV_IATTRIBUTE(attribute),
+                                LTTV_REQUESTS_QUEUE,
+                                LTTV_POINTER,
+                                &value));
+  slist = (GSList**)(value.v_pointer);
+
+  for(iter=*slist;iter!=NULL;) {
+    BackgroundRequest *bg_req = 
+              (BackgroundRequest *)iter->data;
+
+    if(bg_req->module_name == g_quark_from_string(module_name)) {
+      GSList *rem_iter = iter;
+      iter=g_slist_next(iter);
+      g_free(bg_req); 
+      *slist = g_slist_delete_link(*slist, rem_iter);
+    } else {
+      iter=g_slist_next(iter);
+    }
+  }
+}
+/**
+ * Register a callback to be called when requested data is passed in the next
+ * queued background processing.
+ * 
+ * @param owner owner of the background notification
+ * @param trace the trace computed
+ * @param notify_time time when notification hooks must be called
+ * @param notify_position position when notification hooks must be called
+ * @param notify  Hook to call when the notify position is passed
+ */
+
+void lttvwindowtraces_background_notify_queue
+ (gpointer                     owner,
+  LttvTrace                   *trace,
+  LttTime                      notify_time,
+  const LttvTracesetContextPosition *notify_position,
+  const LttvHooks                   *notify)
+{
+  BackgroundNotify *bg_notify;
+  LttvAttribute *attribute = lttv_trace_attribute(trace);
+  LttvAttributeValue value;
+  GSList **slist;
+
+  g_assert(lttv_iattribute_find(LTTV_IATTRIBUTE(attribute),
+                                LTTV_NOTIFY_QUEUE,
+                                LTTV_POINTER,
+                                &value));
+  slist = (GSList**)(value.v_pointer);
+
+  bg_notify = g_new(BackgroundNotify,1);
+
+  bg_notify->owner = owner;
+  bg_notify->trace = trace;
+  bg_notify->notify_time = notify_time;
+  bg_notify->notify_position = ltt_traceset_context_position_new();
+  lttv_traceset_context_position_copy(bg_notify->notify_position,
+                                      notify_position);
+  bg_notify->notify = lttv_hooks_new();
+  lttv_hooks_add_list(bg_notify->notify, notify);
+
+  *slist = g_slist_append(*slist, bg_notify);
+}
+
+/**
+ * Register a callback to be called when requested data is passed in the current
+ * background processing.
+ * 
+ * @param owner owner of the background notification
+ * @param trace the trace computed
+ * @param notify_time time when notification hooks must be called
+ * @param notify_position position when notification hooks must be called
+ * @param notify  Hook to call when the notify position is passed
+ */
+
+void lttvwindowtraces_background_notify_current
+ (gpointer                     owner,
+  LttvTrace                   *trace,
+  LttTime                      notify_time,
+  const LttvTracesetContextPosition *notify_position,
+  const LttvHooks                   *notify)
+{
+  BackgroundNotify *bg_notify;
+  LttvAttribute *attribute = lttv_trace_attribute(trace);
+  LttvAttributeValue value;
+  GSList **slist;
+
+  g_assert(lttv_iattribute_find(LTTV_IATTRIBUTE(attribute),
+                                LTTV_NOTIFY_CURRENT,
+                                LTTV_POINTER,
+                                &value));
+  slist = (GSList**)(value.v_pointer);
+
+  bg_notify = g_new(BackgroundNotify,1);
+
+  bg_notify->owner = owner;
+  bg_notify->trace = trace;
+  bg_notify->notify_time = notify_time;
+  bg_notify->notify_position = ltt_traceset_context_position_new();
+  lttv_traceset_context_position_copy(bg_notify->notify_position,
+                                      notify_position);
+  bg_notify->notify = lttv_hooks_new();
+  lttv_hooks_add_list(bg_notify->notify, notify);
+
+  *slist = g_slist_append(*slist, bg_notify);
+}
+
+/**
+ * Removes all the notifications requests from a specific viewer.
+ * 
+ * @param owner owner of the background notification
+ */
+
+void lttvwindowtraces_background_notify_remove(gpointer owner)
+{
+  guint i;
+
+  for(i=0;i<lttvwindowtraces_get_number();i++) {
+    LttvAttribute *attribute;
+    LttvAttributeValue value;
+    LttvTrace *trace_v = lttvwindowtraces_get_trace(i);
+    GSList **slist;
+    GSList *iter = NULL;
+    
+    g_assert(trace_v != NULL);
+
+    LttvAttribute *t_a = lttv_trace_attribute(trace_v);
+
+    g_assert(lttv_iattribute_find(LTTV_IATTRIBUTE(attribute),
+                                  LTTV_NOTIFY_QUEUE,
+                                  LTTV_POINTER,
+                                  &value));
+    slist = (GSList**)(value.v_pointer);
+    for(iter=*slist;iter!=NULL;) {
+    
+      BackgroundNotify *bg_notify = (BackgroundNotify*)iter->data;
+
+      if(bg_notify->owner == owner) {
+        GSList *rem_iter = iter;
+        iter=g_slist_next(iter);
+        lttv_traceset_context_position_destroy(
+                      bg_notify->notify_position);
+        lttv_hooks_destroy(bg_notify->notify);
+        g_free(bg_notify); 
+        g_slist_remove_link(*slist, rem_iter);
+      } else {
+        iter=g_slist_next(iter);
+      }
+    }
+
+    g_assert(lttv_iattribute_find(LTTV_IATTRIBUTE(attribute),
+                                  LTTV_NOTIFY_CURRENT,
+                                  LTTV_POINTER,
+                                  &value));
+    slist = (GSList**)(value.v_pointer);
+    for(iter=*slist;iter!=NULL;) {
+    
+      BackgroundNotify *bg_notify = (BackgroundNotify*)iter->data;
+
+      if(bg_notify->owner == owner) {
+        GSList *rem_iter = iter;
+        iter=g_slist_next(iter);
+        lttv_traceset_context_position_destroy(
+                      bg_notify->notify_position);
+        lttv_hooks_destroy(bg_notify->notify);
+        g_free(bg_notify); 
+        g_slist_remove_link(*slist, rem_iter);
+      } else {
+        iter=g_slist_next(iter);
+      }
+    }
+  }
+}
+
diff --git a/ltt/branches/poly/lttv/modules/gui/lttvwindow/lttvwindow/lttvwindowtraces.h b/ltt/branches/poly/lttv/modules/gui/lttvwindow/lttvwindow/lttvwindowtraces.h
new file mode 100644 (file)
index 0000000..2a1c335
--- /dev/null
@@ -0,0 +1,140 @@
+/* This file is part of the Linux Trace Toolkit Graphic User Interface
+ * Copyright (C) 2003-2004 Mathieu Desnoyers
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License Version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, 
+ * MA 02111-1307, USA.
+ */
+
+/* This file is the API used to launch any background computation on a trace */
+
+#ifndef LTTVWINDOWTRACES_H
+#define LTTVWINDOWTRACES_H
+
+#include <ltt/time.h>
+#include <glib.h>
+
+typedef GQuark LttvTraceInfo;
+
+extern LttvTraceInfo LTTV_TRACES,
+              LTTV_COMPUTATION,
+              LTTV_REQUESTS_QUEUE,
+              LTTV_REQUESTS_CURRENT,
+              LTTV_NOTIFY_QUEUE,
+              LTTV_NOTIFY_CURRENT;
+
+/* Get a trace by its path name. 
+ *
+ * @param path path of the trace on the virtual file system.
+ * @return Pointer to trace if found
+ *        NULL is returned if the trace is not present
+ */
+
+LttvTrace *lttvwindowtraces_get_trace_by_name(gchar *path);
+
+/* Get a trace by its number identifier */
+
+LttvTrace *lttvwindowtraces_get_trace(guint num);
+
+/* Total number of traces */
+
+guint lttvwindowtraces_get_number();
+
+/* Add a trace to the global attributes */
+
+void lttvwindowtraces_add_trace(LttvTrace *trace);
+
+/* Remove a trace from the global attributes */
+
+void lttvwindowtraces_remove_trace(LttvTrace *trace);
+
+
+/**
+ * Function to request data from a specific trace
+ *
+ * The memory allocated for the request will be managed by the API.
+ * 
+ * @param trace the trace to compute
+ * @param module_name the name of the module which registered global computation
+ *                    hooks.
+ */
+
+void lttvwindowtraces_background_request_queue
+                     (LttvTrace *trace, gchar *module_name);
+
+/**
+ * Remove a background request from a trace.
+ *
+ * This should ONLY be used by the modules which registered the global hooks
+ * (module_name). If this is called by the viewers, it may lead to incomplete
+ * and incoherent background processing information.
+ *
+ * Even if the module which deals with the hooks removes the background
+ * requests, it may cause a problem if the module gets loaded again in the
+ * session : the data will be partially calculated. The calculation function
+ * must deal with this case correctly.
+ * 
+ * @param trace the trace to compute
+ * @param module_name the name of the module which registered global computation
+ *                    hooks.
+ */
+
+void lttvwindowtraces_background_request_remove
+                     (LttvTrace *trace, gchar *module_name);
+                     
+/**
+ * Register a callback to be called when requested data is passed in the next
+ * queued background processing.
+ * 
+ * @param owner owner of the background notification
+ * @param trace the trace computed
+ * @param notify_time time when notification hooks must be called
+ * @param notify_position position when notification hooks must be called
+ * @param notify  Hook to call when the notify position is passed
+ */
+
+void lttvwindowtraces_background_notify_queue
+ (gpointer                     owner,
+  LttvTrace                   *trace,
+  LttTime                      notify_time,
+  const LttvTracesetContextPosition *notify_position,
+  const LttvHooks                   *notify);
+
+/**
+ * Register a callback to be called when requested data is passed in the current
+ * background processing.
+ * 
+ * @param owner owner of the background notification
+ * @param trace the trace computed
+ * @param notify_time time when notification hooks must be called
+ * @param notify_position position when notification hooks must be called
+ * @param notify  Hook to call when the notify position is passed
+ */
+
+void lttvwindowtraces_background_notify_current
+ (gpointer                     owner,
+  LttvTrace                   *trace,
+  LttTime                      notify_time,
+  const LttvTracesetContextPosition *notify_position,
+  const LttvHooks                   *notify);
+
+/**
+ * Removes all the notifications requests from a specific viewer.
+ * 
+ * @param owner owner of the background notification
+ */
+
+void lttvwindowtraces_background_notify_remove(gpointer owner);
+
+
+#endif //LTTVWINDOWTRACES_H
index 6278814dffea5a9d2eb29331ada8458746e7b5ac..d46969b2d735485cb175d2cc676b00d49b1eb21e 100644 (file)
@@ -22,8 +22,6 @@
 #include <glib.h>
 #include <ltt/time.h>
 
-extern GQuark LTTV_TRACES;
-
 typedef struct _MainWindow MainWindow;
 typedef struct _TimeWindow TimeWindow;
 typedef struct _Tab Tab;
This page took 0.035486 seconds and 4 git commands to generate.