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 */ |
29 | systemView * gSysView; |
30 | |
6b1d3120 |
31 | LttvTracesetStats * gTracesetContext = NULL; |
ec25ff5e |
32 | static LttvTraceset * traceset; |
0a6808c0 |
33 | |
ec25ff5e |
34 | /** Array containing instanced objects. */ |
35 | GSList * Main_Window_List = NULL ; |
36 | |
37 | static LttvHooks |
38 | *before_traceset, |
39 | *after_traceset, |
40 | *before_trace, |
41 | *after_trace, |
42 | *before_tracefile, |
43 | *after_tracefile, |
44 | *before_event, |
45 | *after_event, |
46 | *main_hooks; |
47 | |
48 | static char *a_trace; |
49 | |
50 | void lttv_trace_option(void *hook_data) |
51 | { |
52 | LttTrace *trace; |
53 | |
54 | trace = ltt_trace_open(a_trace); |
55 | if(trace == NULL) g_critical("cannot open trace %s", a_trace); |
56 | lttv_traceset_add(traceset, trace); |
57 | } |
fb87279e |
58 | |
59 | /***************************************************************************** |
60 | * Functions for module loading/unloading * |
61 | *****************************************************************************/ |
62 | /** |
63 | * plugin's init function |
64 | * |
65 | * This function initializes the GUI. |
66 | */ |
67 | |
68 | typedef struct _WindowCreationData { |
69 | int argc; |
70 | char ** argv; |
71 | } WindowCreationData; |
72 | |
0a6808c0 |
73 | static gboolean Window_Creation_Hook(void *hook_data, void *call_data) |
fb87279e |
74 | { |
37d0eca6 |
75 | int i; |
76 | GdkPixbuf *pixbuf; |
77 | view_constructor constructor; |
78 | LttvMenus * menu; |
79 | LttvToolbars * toolbar; |
80 | lttv_menu_closure *menuItem; |
81 | lttv_toolbar_closure *toolbarItem; |
82 | LttvAttributeValue value; |
83 | LttvIAttribute *attributes = LTTV_IATTRIBUTE(lttv_global_attributes()); |
fb87279e |
84 | GModule *gm; |
37d0eca6 |
85 | GtkWidget * ToolMenuTitle_menu, *insert_view, *pixmap; |
fb87279e |
86 | GtkWidget *window1; |
87 | mainWindow * mw = g_new(mainWindow, 1); |
88 | gSysView = g_new(systemView, 1); |
ec25ff5e |
89 | WindowCreationData *Window_Creation_Data = (WindowCreationData*)call_data; |
90 | |
91 | /* Add the object's information to the module's array */ |
92 | Main_Window_List = g_slist_append(Main_Window_List, mw); |
fb87279e |
93 | |
558aa013 |
94 | g_critical("GUI Window_Creation_Hook()"); |
fb87279e |
95 | #ifdef ENABLE_NLS |
96 | bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR); |
97 | bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); |
98 | textdomain (GETTEXT_PACKAGE); |
99 | #endif |
100 | |
101 | gtk_set_locale (); |
102 | gtk_init (&(Window_Creation_Data->argc), &(Window_Creation_Data->argv)); |
103 | |
104 | add_pixmap_directory (PACKAGE_DATA_DIR "/" PACKAGE "/pixmaps"); |
105 | add_pixmap_directory ("pixmaps"); |
0a6808c0 |
106 | add_pixmap_directory ("modules/gui/mainWin/pixmaps"); |
fb87279e |
107 | |
108 | /* |
109 | * The following code was added by Glade to create one of each component |
110 | * (except popup menus), just so that you see something after building |
111 | * the project. Delete any components that you don't want shown initially. |
112 | */ |
113 | window1 = create_MWindow (); |
114 | gtk_widget_show (window1); |
115 | |
116 | mw->MWindow = window1; |
117 | mw->SystemView = gSysView; |
118 | mw->Tab = NULL; |
119 | mw->CurrentTab = NULL; |
ec25ff5e |
120 | mw->Attributes = LTTV_IATTRIBUTE(g_object_new(LTTV_ATTRIBUTE_TYPE, NULL)); |
121 | if(!gTracesetContext){ |
6b1d3120 |
122 | gTracesetContext = g_object_new(LTTV_TRACESET_STATS_TYPE, NULL); |
ec25ff5e |
123 | //FIXME: lttv_context_fini should be called some where. |
124 | lttv_context_init(LTTV_TRACESET_CONTEXT(gTracesetContext), traceset); |
125 | } |
126 | mw->traceset_context = LTTV_TRACESET_CONTEXT(gTracesetContext); |
127 | mw->traceset = (LTTV_TRACESET_CONTEXT(gTracesetContext))->ts; |
128 | g_object_ref(gTracesetContext); |
fb87279e |
129 | |
130 | //test |
37d0eca6 |
131 | g_assert(lttv_iattribute_find_by_path(attributes, |
132 | "viewers/menu", LTTV_POINTER, &value)); |
133 | menu = (LttvMenus*)*(value.v_pointer); |
134 | |
135 | if(menu){ |
136 | for(i=0;i<menu->len;i++){ |
137 | menuItem = &g_array_index(menu, lttv_menu_closure, i); |
138 | constructor = menuItem->con; |
139 | ToolMenuTitle_menu = lookup_widget(mw->MWindow,"ToolMenuTitle_menu"); |
140 | insert_view = gtk_menu_item_new_with_mnemonic (menuItem->menuText); |
141 | gtk_widget_show (insert_view); |
142 | gtk_container_add (GTK_CONTAINER (ToolMenuTitle_menu), insert_view); |
143 | g_signal_connect ((gpointer) insert_view, "activate", |
144 | G_CALLBACK (insertViewTest), |
145 | constructor); |
146 | } |
147 | } |
148 | |
149 | g_assert(lttv_iattribute_find_by_path(attributes, |
150 | "viewers/toolbar", LTTV_POINTER, &value)); |
151 | toolbar = (LttvToolbars*)*(value.v_pointer); |
152 | |
153 | if(toolbar){ |
154 | for(i=0;i<toolbar->len;i++){ |
155 | toolbarItem = &g_array_index(toolbar, lttv_toolbar_closure, i); |
156 | constructor = toolbarItem->con; |
157 | ToolMenuTitle_menu = lookup_widget(mw->MWindow,"MToolbar2"); |
158 | pixbuf = gdk_pixbuf_new_from_xpm_data ((const char**)toolbarItem->pixmap); |
159 | pixmap = gtk_image_new_from_pixbuf(pixbuf); |
160 | insert_view = gtk_toolbar_append_element (GTK_TOOLBAR (ToolMenuTitle_menu), |
161 | GTK_TOOLBAR_CHILD_BUTTON, |
162 | NULL, |
163 | "", |
164 | toolbarItem->tooltip, NULL, |
165 | pixmap, NULL, NULL); |
166 | gtk_label_set_use_underline (GTK_LABEL (((GtkToolbarChild*) (g_list_last (GTK_TOOLBAR (ToolMenuTitle_menu)->children)->data))->label), TRUE); |
167 | gtk_widget_show (insert_view); |
168 | gtk_container_set_border_width (GTK_CONTAINER (insert_view), 1); |
169 | g_signal_connect ((gpointer) insert_view, "clicked",G_CALLBACK (insertViewTest),constructor); |
170 | } |
171 | } |
fb87279e |
172 | |
fb87279e |
173 | //end |
174 | |
175 | gSysView->EventDB = NULL; |
176 | gSysView->SystemInfo = NULL; |
177 | gSysView->Options = NULL; |
178 | gSysView->Window = mw; |
179 | gSysView->Next = NULL; |
180 | |
181 | g_object_set_data(G_OBJECT(window1), "systemView", (gpointer)gSysView); |
182 | g_object_set_data(G_OBJECT(window1), "mainWindow", (gpointer)mw); |
183 | |
184 | gtk_main (); |
0a6808c0 |
185 | |
ec25ff5e |
186 | return FALSE; |
0a6808c0 |
187 | } |
188 | |
189 | |
190 | |
191 | |
192 | G_MODULE_EXPORT void init(LttvModule *self, int argc, char *argv[]) { |
193 | |
ec25ff5e |
194 | LttvAttributeValue value; |
195 | WindowCreationData *Window_Creation_Data = g_new(WindowCreationData, 1); |
196 | |
197 | LttvIAttribute *attributes = LTTV_IATTRIBUTE(lttv_global_attributes()); |
198 | |
558aa013 |
199 | g_critical("GUI init()"); |
200 | |
ec25ff5e |
201 | lttv_option_add("trace", 't', |
202 | "add a trace to the trace set to analyse", |
203 | "pathname of the directory containing the trace", |
204 | LTTV_OPT_STRING, &a_trace, lttv_trace_option, NULL); |
205 | |
206 | traceset = lttv_traceset_new(); |
207 | |
208 | before_traceset = lttv_hooks_new(); |
209 | after_traceset = lttv_hooks_new(); |
210 | before_trace = lttv_hooks_new(); |
211 | after_trace = lttv_hooks_new(); |
212 | before_tracefile = lttv_hooks_new(); |
213 | after_tracefile = lttv_hooks_new(); |
214 | before_event = lttv_hooks_new(); |
215 | after_event = lttv_hooks_new(); |
216 | |
217 | g_assert(lttv_iattribute_find_by_path(attributes, "hooks/traceset/before", |
218 | LTTV_POINTER, &value)); |
219 | *(value.v_pointer) = before_traceset; |
220 | g_assert(lttv_iattribute_find_by_path(attributes, "hooks/traceset/after", |
221 | LTTV_POINTER, &value)); |
222 | *(value.v_pointer) = after_traceset; |
223 | g_assert(lttv_iattribute_find_by_path(attributes, "hooks/trace/before", |
224 | LTTV_POINTER, &value)); |
225 | *(value.v_pointer) = before_trace; |
226 | g_assert(lttv_iattribute_find_by_path(attributes, "hooks/trace/after", |
227 | LTTV_POINTER, &value)); |
228 | *(value.v_pointer) = after_trace; |
229 | g_assert(lttv_iattribute_find_by_path(attributes, "hooks/tracefile/before", |
230 | LTTV_POINTER, &value)); |
231 | *(value.v_pointer) = before_tracefile; |
232 | g_assert(lttv_iattribute_find_by_path(attributes, "hooks/tracefile/after", |
233 | LTTV_POINTER, &value)); |
234 | *(value.v_pointer) = after_tracefile; |
235 | g_assert(lttv_iattribute_find_by_path(attributes, "hooks/event/before", |
236 | LTTV_POINTER, &value)); |
237 | *(value.v_pointer) = before_event; |
238 | g_assert(lttv_iattribute_find_by_path(attributes, "hooks/event/after", |
239 | LTTV_POINTER, &value)); |
240 | *(value.v_pointer) = after_event; |
241 | |
242 | g_assert(lttv_iattribute_find_by_path(attributes, "hooks/main/before", |
243 | LTTV_POINTER, &value)); |
244 | g_assert((main_hooks = *(value.v_pointer)) != NULL); |
245 | |
246 | Window_Creation_Data->argc = argc; |
247 | Window_Creation_Data->argv = argv; |
248 | |
249 | lttv_hooks_add(main_hooks, Window_Creation_Hook, Window_Creation_Data); |
0a6808c0 |
250 | |
fb87279e |
251 | } |
252 | |
253 | void destroy_walk(gpointer data, gpointer user_data) |
254 | { |
255 | //GuiControlFlow_Destructor((ControlFlowData*)data); |
256 | } |
257 | |
258 | |
259 | |
260 | /** |
261 | * plugin's destroy function |
262 | * |
263 | * This function releases the memory reserved by the module and unregisters |
264 | * everything that has been registered in the gtkTraceSet API. |
265 | */ |
266 | G_MODULE_EXPORT void destroy() { |
267 | |
ec25ff5e |
268 | WindowCreationData *Window_Creation_Data; |
269 | LttvAttributeValue value; |
270 | |
271 | guint i, nb; |
272 | |
273 | lttv_option_remove("trace"); |
274 | |
275 | lttv_hooks_destroy(before_traceset); |
276 | lttv_hooks_destroy(after_traceset); |
277 | lttv_hooks_destroy(before_trace); |
278 | lttv_hooks_destroy(after_trace); |
279 | lttv_hooks_destroy(before_tracefile); |
280 | lttv_hooks_destroy(after_tracefile); |
281 | lttv_hooks_destroy(before_event); |
282 | lttv_hooks_destroy(after_event); |
283 | lttv_hooks_remove_data(main_hooks, Window_Creation_Hook, NULL); |
284 | |
285 | nb = lttv_traceset_number(traceset); |
286 | for(i = 0 ; i < nb ; i++) { |
287 | ltt_trace_close(lttv_traceset_get(traceset, i)); |
288 | } |
289 | |
290 | lttv_traceset_destroy(traceset); |
fb87279e |
291 | |
ec25ff5e |
292 | g_critical("GUI destroy()"); |
fb87279e |
293 | |
fb87279e |
294 | |
fb87279e |
295 | |
ec25ff5e |
296 | //ControlFlowData *Control_Flow_Data; |
297 | |
fb87279e |
298 | |
ec25ff5e |
299 | g_slist_foreach(Main_Window_List, destroy_walk, NULL ); |
300 | |
301 | |
302 | //lttv_hooks_remove_data(main_hooks,Window_Creation_Hook, NULL); |
303 | //lttv_hooks_remove_data(before_traceset, get_traceset_context, NULL); |
fb87279e |
304 | |
ec25ff5e |
305 | // g_free(Window_Creation_Data); |
fb87279e |
306 | |
ec25ff5e |
307 | g_object_unref(gTracesetContext); |
fb87279e |
308 | } |
309 | |
310 | |
311 | |
312 | |