main window with default tab
[lttv.git] / ltt / branches / poly / lttv / modules / gui / mainWin / src / init_module.c
index 1aa9c19df9784aa6348a8abfc3944e80b9c668e0..aad203e2bba511b98370e27ad5a877393157071d 100644 (file)
 #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 "interface.h"
 #include "support.h"
 #include "callbacks.h"
 
 /* global variable */
-systemView * gSysView;
-
-typedef view_constructor (* constructor)();
-constructor get_constructor = NULL;
-typedef void (*call_Event_Selected_Hook)(void * call_data);
-call_Event_Selected_Hook selected_hook = NULL;
-GModule *gm;
-view_constructor gConstructor = NULL;
-
-
-static LttvHooks
-       *main_hooks;
-
+LttvTracesetStats * gTracesetContext = NULL;
+static LttvTraceset * traceset;
+
+/** Array containing instanced objects. */
+GSList * Main_Window_List = NULL ;
+
+static LttvHooks 
+  *before_traceset,
+  *after_traceset,
+  *before_trace,
+  *after_trace,
+  *before_tracefile,
+  *after_tracefile,
+  *before_event,
+  *after_event,
+  *main_hooks;
+
+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);
+  lttv_traceset_add(traceset, trace);
+}
 
 /*****************************************************************************
  *                 Functions for module loading/unloading                    *
@@ -45,22 +63,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)
 {
-  GModule *gm;
-  GtkWidget * ToolMenuTitle_menu, *insert_view;
-  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");
@@ -74,53 +81,18 @@ 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
-
-  gm = g_module_open("/home1/yangxx/poly/lttv/modules/libguiEvents.la",0);
-  printf("Main : the address of gm : %d\n", gm);
-  if(!g_module_symbol(gm, "get_constructor", (gpointer)&get_constructor)){
-    g_error("can not get constructor\n");
-  }  
-  if(!g_module_symbol(gm, "call_Event_Selected_Hook", (gpointer)&selected_hook)){
-    g_error("can not get selected hook\n");
-  }  
-
-  gConstructor = get_constructor();
-  ToolMenuTitle_menu = lookup_widget(mw->MWindow,"ToolMenuTitle_menu");
-  insert_view = gtk_menu_item_new_with_mnemonic ("insert_view");
-  gtk_widget_show (insert_view);
-  gtk_container_add (GTK_CONTAINER (ToolMenuTitle_menu), insert_view);
-  g_signal_connect ((gpointer) insert_view, "activate",
-                    G_CALLBACK (insertViewTest),
-                    NULL);  
-  //end
-
-  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);
+
+  if(!gTracesetContext){
+    gTracesetContext = g_object_new(LTTV_TRACESET_STATS_TYPE, NULL);
+    //FIXME: lttv_context_fini should be called some where.
+    lttv_context_init(LTTV_TRACESET_CONTEXT(gTracesetContext), traceset);
+  }
+
+  constructMainWin(NULL, Window_Creation_Data);
 
   gtk_main ();
 
-       return FALSE;
+  return FALSE;
 }
 
 
@@ -128,21 +100,62 @@ static gboolean Window_Creation_Hook(void *hook_data, void *call_data)
 
 G_MODULE_EXPORT void init(LttvModule *self, int argc, char *argv[]) {
 
-       LttvAttributeValue value;
-       WindowCreationData *Window_Creation_Data = g_new(WindowCreationData, 1);
-       
-       LttvIAttribute *attributes = LTTV_IATTRIBUTE(lttv_global_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);
-
-       lttv_hooks_add(main_hooks, Window_Creation_Hook, Window_Creation_Data);
+  LttvAttributeValue value;
+  WindowCreationData *Window_Creation_Data = g_new(WindowCreationData, 1);
+  
+  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);
+
+  traceset = lttv_traceset_new();
+
+  before_traceset = lttv_hooks_new();
+  after_traceset = lttv_hooks_new();
+  before_trace = lttv_hooks_new();
+  after_trace = lttv_hooks_new();
+  before_tracefile = lttv_hooks_new();
+  after_tracefile = lttv_hooks_new();
+  before_event = lttv_hooks_new();
+  after_event = lttv_hooks_new();
+
+  g_assert(lttv_iattribute_find_by_path(attributes, "hooks/traceset/before",
+      LTTV_POINTER, &value));
+  *(value.v_pointer) = before_traceset;
+  g_assert(lttv_iattribute_find_by_path(attributes, "hooks/traceset/after",
+      LTTV_POINTER, &value));
+  *(value.v_pointer) = after_traceset;
+  g_assert(lttv_iattribute_find_by_path(attributes, "hooks/trace/before",
+      LTTV_POINTER, &value));
+  *(value.v_pointer) = before_trace;
+  g_assert(lttv_iattribute_find_by_path(attributes, "hooks/trace/after",
+      LTTV_POINTER, &value));
+  *(value.v_pointer) = after_trace;
+  g_assert(lttv_iattribute_find_by_path(attributes, "hooks/tracefile/before",
+      LTTV_POINTER, &value));
+  *(value.v_pointer) = before_tracefile;
+  g_assert(lttv_iattribute_find_by_path(attributes, "hooks/tracefile/after",
+      LTTV_POINTER, &value));
+  *(value.v_pointer) = after_tracefile;
+  g_assert(lttv_iattribute_find_by_path(attributes, "hooks/event/before",
+      LTTV_POINTER, &value));
+  *(value.v_pointer) = before_event;
+  g_assert(lttv_iattribute_find_by_path(attributes, "hooks/event/after",
+      LTTV_POINTER, &value));
+  *(value.v_pointer) = after_event;
+
+  g_assert(lttv_iattribute_find_by_path(attributes, "hooks/main/before",
+      LTTV_POINTER, &value));
+  g_assert((main_hooks = *(value.v_pointer)) != NULL);
+
+  Window_Creation_Data->argc = argc;
+  Window_Creation_Data->argv = argv;
+  
+  lttv_hooks_add(main_hooks, Window_Creation_Hook, Window_Creation_Data);
 
 }
 
@@ -161,26 +174,46 @@ void destroy_walk(gpointer data, gpointer user_data)
  */
 G_MODULE_EXPORT void destroy() {
 
-       WindowCreationData *Window_Creation_Data;
-       LttvAttributeValue value;
+  WindowCreationData *Window_Creation_Data;
+  LttvAttributeValue value;
+
+  guint i, nb;
+
+  lttv_option_remove("trace");
+
+  lttv_hooks_destroy(before_traceset);
+  lttv_hooks_destroy(after_traceset);
+  lttv_hooks_destroy(before_trace);
+  lttv_hooks_destroy(after_trace);
+  lttv_hooks_destroy(before_tracefile);
+  lttv_hooks_destroy(after_tracefile);
+  lttv_hooks_destroy(before_event);
+  lttv_hooks_destroy(after_event);
+  lttv_hooks_remove_data(main_hooks, Window_Creation_Hook, NULL);
+
+  nb = lttv_traceset_number(traceset);
+  for(i = 0 ; i < nb ; i++) {
+    ltt_trace_close(lttv_traceset_get(traceset, i));
+  }
 
-       g_critical("GUI destroy()");
-       //int i;
+  lttv_traceset_destroy(traceset); 
 
-       //ControlFlowData *Control_Flow_Data;
-       
+  g_critical("GUI destroy()");
 
-       //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);
+  //ControlFlowData *Control_Flow_Data;
+  
 
-       g_free(Window_Creation_Data);
+  g_slist_foreach(Main_Window_List, destroy_walk, NULL );
+  
+  
+  //lttv_hooks_remove_data(main_hooks,Window_Creation_Hook, NULL);
+  //lttv_hooks_remove_data(before_traceset, get_traceset_context, NULL);
 
+  //  g_free(Window_Creation_Data);
 
+  g_object_unref(gTracesetContext);
 }
 
 
This page took 0.025025 seconds and 4 git commands to generate.