git-svn-id: http://ltt.polymtl.ca/svn@309 04897980-b3bd-0310-b5e0-8ef037075253
[lttv.git] / ltt / branches / poly / lttv / modules / gui / mainWin / src / init_module.c
index 8ab4f5a30f56bae05ec00314188bbd7f16e8ccbf..ed724a42439717446a443158760ae2d75339e9c6 100644 (file)
@@ -14,6 +14,9 @@
 #include <lttv/hook.h>
 #include <lttv/option.h>
 #include <lttv/module.h>
+#include <lttv/processTrace.h>
+#include <lttv/state.h>
+#include <lttv/stats.h>
 #include <lttv/menu.h>
 #include <lttv/toolbar.h>
 
 #include "callbacks.h"
 
 /* global variable */
-systemView * gSysView;
+//LttvTracesetStats * gTracesetContext = NULL;
+//static LttvTraceset * traceset;
+WindowCreationData  gWinCreationData;
 
-static LttvHooks
-       *main_hooks;
+/** Array containing instanced objects. */
+GSList * Main_Window_List = NULL ;
 
+LttvHooks
+  *main_hooks;
+
+/* Initial trace from command line */
+LttvTrace *gInit_Trace = NULL;
+
+static char *a_trace;
+
+void lttv_trace_option(void *hook_data)
+{ 
+  LttTrace *trace;
+
+  trace = ltt_trace_open(a_trace);
+  if(trace == NULL) g_critical("cannot open trace %s", a_trace);
+  gInit_Trace = lttv_trace_new(trace);
+}
 
 /*****************************************************************************
  *                 Functions for module loading/unloading                    *
@@ -38,31 +59,11 @@ static LttvHooks
  * This function initializes the GUI.
  */
 
-typedef struct _WindowCreationData {
-       int argc;
-       char ** argv;
-} WindowCreationData;
-
-
 static gboolean Window_Creation_Hook(void *hook_data, void *call_data)
 {
-  int i;
-  GdkPixbuf *pixbuf;
-  view_constructor constructor;
-  LttvMenus * menu;
-  LttvToolbars * toolbar;
-  lttv_menu_closure *menuItem;
-  lttv_toolbar_closure *toolbarItem;
-  LttvAttributeValue value;
-  LttvIAttribute *attributes = LTTV_IATTRIBUTE(lttv_global_attributes());
-  GModule *gm;
-  GtkWidget * ToolMenuTitle_menu, *insert_view, *pixmap;
-  GtkWidget *window1;
-  mainWindow * mw = g_new(mainWindow, 1);
-  gSysView = g_new(systemView, 1);
-       WindowCreationData *Window_Creation_Data = (WindowCreationData*)call_data;
-
-       g_critical("GUI init()");
+  WindowCreationData* Window_Creation_Data = (WindowCreationData*)hook_data;
+
+  g_critical("GUI Window_Creation_Hook()");
 #ifdef ENABLE_NLS
   bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR);
   bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
@@ -76,105 +77,107 @@ static gboolean Window_Creation_Hook(void *hook_data, void *call_data)
   add_pixmap_directory ("pixmaps");
   add_pixmap_directory ("modules/gui/mainWin/pixmaps");
 
-  /*
-   * The following code was added by Glade to create one of each component
-   * (except popup menus), just so that you see something after building
-   * the project. Delete any components that you don't want shown initially.
-   */
-  window1 = create_MWindow ();
-  gtk_widget_show (window1);
-
-  mw->MWindow = window1;
-  mw->SystemView = gSysView;
-  mw->Tab = NULL;
-  mw->CurrentTab = NULL;
-  //  mw->Attributes = lttv_attributes_new();
-
-  //test
-  g_assert(lttv_iattribute_find_by_path(attributes,
-          "viewers/menu", LTTV_POINTER, &value));
-  menu = (LttvMenus*)*(value.v_pointer);
-
-  if(menu){
-    for(i=0;i<menu->len;i++){
-      menuItem = &g_array_index(menu, lttv_menu_closure, i);
-      constructor = menuItem->con;
-      ToolMenuTitle_menu = lookup_widget(mw->MWindow,"ToolMenuTitle_menu");
-      insert_view = gtk_menu_item_new_with_mnemonic (menuItem->menuText);
-      gtk_widget_show (insert_view);
-      gtk_container_add (GTK_CONTAINER (ToolMenuTitle_menu), insert_view);
-      g_signal_connect ((gpointer) insert_view, "activate",
-                       G_CALLBACK (insertViewTest),
-                       constructor);  
-    }
-  }
+  constructMainWin(NULL, Window_Creation_Data, TRUE);
 
-  g_assert(lttv_iattribute_find_by_path(attributes,
-          "viewers/toolbar", LTTV_POINTER, &value));
-  toolbar = (LttvToolbars*)*(value.v_pointer);
-
-  if(toolbar){
-    for(i=0;i<toolbar->len;i++){
-      toolbarItem = &g_array_index(toolbar, lttv_toolbar_closure, i);
-      constructor = toolbarItem->con;
-      ToolMenuTitle_menu = lookup_widget(mw->MWindow,"MToolbar2");
-      pixbuf = gdk_pixbuf_new_from_xpm_data ((const char**)toolbarItem->pixmap);
-      pixmap = gtk_image_new_from_pixbuf(pixbuf);
-      insert_view = gtk_toolbar_append_element (GTK_TOOLBAR (ToolMenuTitle_menu),
-                                               GTK_TOOLBAR_CHILD_BUTTON,
-                                               NULL,
-                                               "",
-                                               toolbarItem->tooltip, NULL,
-                                               pixmap, NULL, NULL);
-      gtk_label_set_use_underline (GTK_LABEL (((GtkToolbarChild*) (g_list_last (GTK_TOOLBAR (ToolMenuTitle_menu)->children)->data))->label), TRUE);
-      gtk_widget_show (insert_view);
-      gtk_container_set_border_width (GTK_CONTAINER (insert_view), 1);
-      g_signal_connect ((gpointer) insert_view, "clicked",G_CALLBACK (insertViewTest),constructor);       
-    }
-  }
+  gtk_main ();
 
-  //end
+  return FALSE;
+}
 
-  gSysView->EventDB = NULL;
-  gSysView->SystemInfo = NULL;
-  gSysView->Options  = NULL;
-  gSysView->Window = mw;
-  gSysView->Next = NULL;
 
-  g_object_set_data(G_OBJECT(window1), "systemView", (gpointer)gSysView);
-  g_object_set_data(G_OBJECT(window1), "mainWindow", (gpointer)mw);
 
-  gtk_main ();
 
-       return FALSE;
-}
+G_MODULE_EXPORT void init(LttvModule *self, int argc, char *argv[]) {
 
+  LttvAttributeValue value;
+  // Global attributes only used for interaction with main() here.
+  LttvIAttribute *attributes = LTTV_IATTRIBUTE(lttv_global_attributes());
+  
+  g_critical("GUI init()");
+  
+  lttv_option_add("trace", 't', 
+      "add a trace to the trace set to analyse", 
+      "pathname of the directory containing the trace", 
+      LTTV_OPT_STRING, &a_trace, lttv_trace_option, NULL);
+
+  g_assert(lttv_iattribute_find_by_path(attributes, "hooks/main/before",
+      LTTV_POINTER, &value));
+  g_assert((main_hooks = *(value.v_pointer)) != NULL);
+
+  gWinCreationData.argc = argc;
+  gWinCreationData.argv = argv;
+  
+  lttv_hooks_add(main_hooks, Window_Creation_Hook, &gWinCreationData);
 
+}
 
+void
+mainWindow_free(mainWindow * mw)
+{ 
+  guint i, nb;
+
+  if(mw){
+
+g_critical("begin remove");
+    lttv_hooks_destroy(mw->Traceset_Info->before_traceset);
+    lttv_hooks_destroy(mw->Traceset_Info->after_traceset);
+    lttv_hooks_destroy(mw->Traceset_Info->before_trace);
+    lttv_hooks_destroy(mw->Traceset_Info->after_trace);
+    lttv_hooks_destroy(mw->Traceset_Info->before_tracefile);
+    lttv_hooks_destroy(mw->Traceset_Info->after_tracefile);
+    lttv_hooks_destroy(mw->Traceset_Info->before_event);
+    lttv_hooks_destroy(mw->Traceset_Info->after_event);
+g_critical("end remove");
+    
+    if(mw->Traceset_Info->path != NULL)
+      g_free(mw->Traceset_Info->path);
+    if(mw->Traceset_Info->TracesetContext != NULL){
+      lttv_context_fini(LTTV_TRACESET_CONTEXT(mw->Traceset_Info->TracesetContext));
+      g_object_unref(mw->Traceset_Info->TracesetContext);
+    }
+    if(mw->Traceset_Info->traceset != NULL) {
+      nb = lttv_traceset_number(mw->Traceset_Info->traceset);
+      for(i = 0 ; i < nb ; i++) {
+        ltt_trace_close(
+           lttv_trace(lttv_traceset_get(mw->Traceset_Info->traceset, i)));
+      }
+    }
 
-G_MODULE_EXPORT void init(LttvModule *self, int argc, char *argv[]) {
+    lttv_traceset_destroy(mw->Traceset_Info->traceset); 
 
-       LttvAttributeValue value;
-       WindowCreationData *Window_Creation_Data = g_new(WindowCreationData, 1);
-       
-       LttvIAttribute *attributes = LTTV_IATTRIBUTE(lttv_global_attributes());
+    g_object_unref(mw->Attributes);
 
-       Window_Creation_Data->argc = argc;
-       Window_Creation_Data->argv = argv;
-       
-       g_assert(lttv_iattribute_find_by_path(
-                               attributes,
-                               "hooks/main/before",    LTTV_POINTER, &value));
-       
-       g_assert((main_hooks = *(value.v_pointer)) != NULL);
+    g_free(mw->Traceset_Info);
+    mw->Traceset_Info = NULL;
+      
+    Main_Window_List = g_slist_remove(Main_Window_List, mw);
 
-       lttv_hooks_add(main_hooks, Window_Creation_Hook, Window_Creation_Data);
+    g_hash_table_destroy(mw->hash_menu_item);
+    g_hash_table_destroy(mw->hash_toolbar_item);
+    
+    g_free(mw);
+    mw = NULL;
+  }
+}
 
+void
+mainWindow_Destructor(mainWindow * mw)
+{
+  if(GTK_IS_WIDGET(mw->MWindow)){
+    gtk_widget_destroy(mw->MWindow);
+    //    gtk_widget_destroy(mw->HelpContents);
+    //    gtk_widget_destroy(mw->AboutBox);    
+    mw = NULL;
+  }
+  //mainWindow_free called when the object mw in the widget is unref.
+  //mainWindow_free(mw);
 }
 
+
 void destroy_walk(gpointer data, gpointer user_data)
 {
-       //GuiControlFlow_Destructor((ControlFlowData*)data);
+  mainWindow_Destructor((mainWindow*)data);
 }
 
 
@@ -187,25 +190,18 @@ void destroy_walk(gpointer data, gpointer user_data)
  */
 G_MODULE_EXPORT void destroy() {
 
-       WindowCreationData *Window_Creation_Data;
-       LttvAttributeValue value;
+  LttvAttributeValue value;  
+  LttvTrace *trace;
 
-       g_critical("GUI destroy()");
-       //int i;
+  lttv_option_remove("trace");
 
-       //ControlFlowData *Control_Flow_Data;
-       
-
-       //g_slist_foreach(sControl_Flow_Data_List, destroy_walk, NULL );
-
-       lttv_iattribute_find_by_path(LTTV_IATTRIBUTE(lttv_global_attributes()),
-                       "/hooks/main/before",   LTTV_POINTER, &value);
-
-       //      Window_Creation_Data = lttv_hooks_remove(*(value.v_pointer),                                                                                                     Window_Creation_Hook);
-      
-       g_free(Window_Creation_Data);
+  lttv_hooks_remove_data(main_hooks, Window_Creation_Hook, &gWinCreationData);
 
+  g_critical("GUI destroy()");
 
+  g_slist_foreach(Main_Window_List, destroy_walk, NULL );
+  g_slist_free(Main_Window_List);
+  
 }
 
 
This page took 0.0259200000000001 seconds and 4 git commands to generate.