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