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