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