mega modif by Mathieu Desnoyers. Independant main windows, multiple tracesets, contro...
[lttv.git] / ltt / branches / poly / lttv / modules / gui / mainWin / src / init_module.c
1 /*
2 * Initial main.c file generated by Glade. Edit as required.
3 * Glade will not overwrite this file.
4 */
5
6 #ifdef HAVE_CONFIG_H
7 # include <config.h>
8 #endif
9
10 #include <gtk/gtk.h>
11
12 #include <lttv/lttv.h>
13 #include <lttv/attribute.h>
14 #include <lttv/hook.h>
15 #include <lttv/option.h>
16 #include <lttv/module.h>
17 #include <lttv/processTrace.h>
18 #include <lttv/state.h>
19 #include <lttv/stats.h>
20 #include <lttv/menu.h>
21 #include <lttv/toolbar.h>
22
23 #include "interface.h"
24 #include "support.h"
25 #include <lttv/mainWindow.h>
26 #include "callbacks.h"
27
28 /* global variable */
29 //LttvTracesetStats * gTracesetContext = NULL;
30 //static LttvTraceset * traceset;
31 WindowCreationData gWinCreationData;
32
33 /** Array containing instanced objects. */
34 GSList * Main_Window_List = NULL ;
35
36 LttvHooks
37 *main_hooks;
38
39 /* Initial trace from command line */
40 LttTrace *gInit_Trace = NULL;
41
42 static char *a_trace;
43
44 void lttv_trace_option(void *hook_data)
45 {
46 gInit_Trace = ltt_trace_open(a_trace);
47 if(gInit_Trace == NULL) g_critical("cannot open trace %s", a_trace);
48 g_critical("lttv_trace_option : Init_Trace is %p", gInit_Trace);
49 }
50
51 /*****************************************************************************
52 * Functions for module loading/unloading *
53 *****************************************************************************/
54 /**
55 * plugin's init function
56 *
57 * This function initializes the GUI.
58 */
59
60 static gboolean Window_Creation_Hook(void *hook_data, void *call_data)
61 {
62 WindowCreationData* Window_Creation_Data = (WindowCreationData*)hook_data;
63
64 g_critical("GUI Window_Creation_Hook()");
65 #ifdef ENABLE_NLS
66 bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR);
67 bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
68 textdomain (GETTEXT_PACKAGE);
69 #endif
70
71 gtk_set_locale ();
72 gtk_init (&(Window_Creation_Data->argc), &(Window_Creation_Data->argv));
73
74 add_pixmap_directory (PACKAGE_DATA_DIR "/" PACKAGE "/pixmaps");
75 add_pixmap_directory ("pixmaps");
76 add_pixmap_directory ("modules/gui/mainWin/pixmaps");
77
78 constructMainWin(NULL, Window_Creation_Data);
79
80 gtk_main ();
81
82 return FALSE;
83 }
84
85
86
87
88 G_MODULE_EXPORT void init(LttvModule *self, int argc, char *argv[]) {
89
90 LttvAttributeValue value;
91
92 // Global attributes only used for interaction with main() here.
93 LttvIAttribute *attributes = LTTV_IATTRIBUTE(lttv_global_attributes());
94
95 g_critical("GUI init()");
96
97 lttv_option_add("trace", 't',
98 "add a trace to the trace set to analyse",
99 "pathname of the directory containing the trace",
100 LTTV_OPT_STRING, &a_trace, lttv_trace_option, NULL);
101
102 g_assert(lttv_iattribute_find_by_path(attributes, "hooks/main/before",
103 LTTV_POINTER, &value));
104 g_assert((main_hooks = *(value.v_pointer)) != NULL);
105
106 gWinCreationData.argc = argc;
107 gWinCreationData.argv = argv;
108
109 lttv_hooks_add(main_hooks, Window_Creation_Hook, &gWinCreationData);
110
111 }
112
113 //void
114 //free_system_view(systemView * SystemView)
115 //{
116 // if(!SystemView)return;
117 // //free_EventDB(SystemView->EventDB);
118 // //free_SystemInfo(SystemView->SystemInfo);
119 // //free_Options(SystemView->Options);
120 // if(SystemView->Next)
121 // free_system_view(SystemView->Next);
122 // g_free(SystemView);
123 //}
124
125 //MD : The tab is now only referenced by the notebook. The destroy will
126 //happend when notebook destroyed.
127 //void free_tab(tab * Tab)
128 //{
129 // if(!Tab) return;
130 // if(Tab->custom->vbox)
131 // gtk_widget_destroy(Tab->custom->vbox);
132 // if(Tab->Attributes)
133 // g_object_unref(Tab->Attributes);
134
135 // if(Tab->Next) free_tab(Tab->Next);
136 // g_free(Tab);
137 // Tab = NULL;
138 //}
139
140 void
141 mainWindow_free(mainWindow * mw)
142 {
143 guint i, nb;
144
145 if(mw){
146 //should free memory allocated dynamically first
147 // free_system_view(mw->SystemView);
148 //
149 //free_tab(mw->Tab);
150 g_critical("begin remove");
151 lttv_hooks_destroy(mw->Traceset_Info->before_traceset);
152 lttv_hooks_destroy(mw->Traceset_Info->after_traceset);
153 lttv_hooks_destroy(mw->Traceset_Info->before_trace);
154 lttv_hooks_destroy(mw->Traceset_Info->after_trace);
155 lttv_hooks_destroy(mw->Traceset_Info->before_tracefile);
156 lttv_hooks_destroy(mw->Traceset_Info->after_tracefile);
157 lttv_hooks_destroy(mw->Traceset_Info->before_event);
158 lttv_hooks_destroy(mw->Traceset_Info->after_event);
159 g_critical("end remove");
160
161
162 if(mw->Traceset_Info->path != NULL)
163 g_free(mw->Traceset_Info->path);
164 if(mw->Traceset_Info->TracesetContext != NULL)
165 lttv_context_fini(LTTV_TRACESET_CONTEXT(mw->Traceset_Info->TracesetContext));
166 if(mw->Traceset_Info->traceset != NULL) {
167 nb = lttv_traceset_number(mw->Traceset_Info->traceset);
168 for(i = 0 ; i < nb ; i++) {
169 ltt_trace_close(
170 lttv_traceset_get(mw->Traceset_Info->traceset, i));
171 }
172 }
173
174 lttv_traceset_destroy(mw->Traceset_Info->traceset);
175
176 g_object_unref(mw->Attributes);
177
178 g_free(mw->Traceset_Info);
179 mw->Traceset_Info = NULL;
180
181 Main_Window_List = g_slist_remove(Main_Window_List, mw);
182
183 g_free(mw);
184 mw = NULL;
185 }
186 }
187
188 void
189 mainWindow_Destructor(mainWindow * mw)
190 {
191 if(GTK_IS_WIDGET(mw->MWindow)){
192 gtk_widget_destroy(mw->MWindow);
193 // gtk_widget_destroy(mw->HelpContents);
194 // gtk_widget_destroy(mw->AboutBox);
195 mw = NULL;
196 }
197 //mainWindow_free called when the object mw in the widget is unref.
198 //mainWindow_free(mw);
199 }
200
201
202 void destroy_walk(gpointer data, gpointer user_data)
203 {
204 mainWindow_Destructor((mainWindow*)data);
205 }
206
207
208
209 /**
210 * plugin's destroy function
211 *
212 * This function releases the memory reserved by the module and unregisters
213 * everything that has been registered in the gtkTraceSet API.
214 */
215 G_MODULE_EXPORT void destroy() {
216
217 LttvAttributeValue value;
218
219 lttv_option_remove("trace");
220
221 lttv_hooks_remove_data(main_hooks, Window_Creation_Hook, &gWinCreationData);
222
223 g_critical("GUI destroy()");
224
225 g_slist_foreach(Main_Window_List, destroy_walk, NULL );
226 g_slist_free(Main_Window_List);
227
228 }
229
230
231
232
This page took 0.033829 seconds and 4 git commands to generate.