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 */ |
40 | LttTrace *gInit_Trace = NULL; |
41 | |
ec25ff5e |
42 | static char *a_trace; |
43 | |
44 | void lttv_trace_option(void *hook_data) |
45 | { |
f7afe191 |
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); |
ec25ff5e |
49 | } |
fb87279e |
50 | |
51 | /***************************************************************************** |
52 | * Functions for module loading/unloading * |
53 | *****************************************************************************/ |
54 | /** |
55 | * plugin's init function |
56 | * |
57 | * This function initializes the GUI. |
58 | */ |
59 | |
0a6808c0 |
60 | static gboolean Window_Creation_Hook(void *hook_data, void *call_data) |
fb87279e |
61 | { |
5723fa24 |
62 | WindowCreationData* Window_Creation_Data = (WindowCreationData*)hook_data; |
fb87279e |
63 | |
558aa013 |
64 | g_critical("GUI Window_Creation_Hook()"); |
fb87279e |
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"); |
0a6808c0 |
76 | add_pixmap_directory ("modules/gui/mainWin/pixmaps"); |
fb87279e |
77 | |
5723fa24 |
78 | constructMainWin(NULL, Window_Creation_Data); |
fb87279e |
79 | |
80 | gtk_main (); |
0a6808c0 |
81 | |
ec25ff5e |
82 | return FALSE; |
0a6808c0 |
83 | } |
84 | |
85 | |
86 | |
87 | |
88 | G_MODULE_EXPORT void init(LttvModule *self, int argc, char *argv[]) { |
89 | |
ec25ff5e |
90 | LttvAttributeValue value; |
f7afe191 |
91 | |
92 | // Global attributes only used for interaction with main() here. |
ec25ff5e |
93 | LttvIAttribute *attributes = LTTV_IATTRIBUTE(lttv_global_attributes()); |
94 | |
558aa013 |
95 | g_critical("GUI init()"); |
96 | |
ec25ff5e |
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 | |
ec25ff5e |
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 | |
7a859036 |
106 | gWinCreationData.argc = argc; |
107 | gWinCreationData.argv = argv; |
ec25ff5e |
108 | |
7a859036 |
109 | lttv_hooks_add(main_hooks, Window_Creation_Hook, &gWinCreationData); |
0a6808c0 |
110 | |
fb87279e |
111 | } |
112 | |
f7afe191 |
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 | //} |
7a859036 |
139 | |
140 | void |
141 | mainWindow_free(mainWindow * mw) |
142 | { |
f7afe191 |
143 | guint i, nb; |
144 | |
7a859036 |
145 | if(mw){ |
7a859036 |
146 | //should free memory allocated dynamically first |
f7afe191 |
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 | |
7a859036 |
176 | g_object_unref(mw->Attributes); |
177 | |
f7afe191 |
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; |
7a859036 |
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 | } |
f7afe191 |
197 | //mainWindow_free called when the object mw in the widget is unref. |
198 | //mainWindow_free(mw); |
7a859036 |
199 | } |
200 | |
201 | |
fb87279e |
202 | void destroy_walk(gpointer data, gpointer user_data) |
203 | { |
7a859036 |
204 | mainWindow_Destructor((mainWindow*)data); |
fb87279e |
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 | |
7a859036 |
217 | LttvAttributeValue value; |
ec25ff5e |
218 | |
ec25ff5e |
219 | lttv_option_remove("trace"); |
220 | |
7a859036 |
221 | lttv_hooks_remove_data(main_hooks, Window_Creation_Hook, &gWinCreationData); |
ec25ff5e |
222 | |
ec25ff5e |
223 | g_critical("GUI destroy()"); |
fb87279e |
224 | |
ec25ff5e |
225 | g_slist_foreach(Main_Window_List, destroy_walk, NULL ); |
7a859036 |
226 | g_slist_free(Main_Window_List); |
ec25ff5e |
227 | |
fb87279e |
228 | } |
229 | |
230 | |
231 | |
232 | |