bug fixed: module dependence is wrong
[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 */
f7afe191 29//LttvTracesetStats * gTracesetContext = NULL;
30//static LttvTraceset * traceset;
7a859036 31WindowCreationData gWinCreationData;
0a6808c0 32
ec25ff5e 33/** Array containing instanced objects. */
34GSList * Main_Window_List = NULL ;
35
f7afe191 36LttvHooks
ec25ff5e 37 *main_hooks;
38
f7afe191 39/* Initial trace from command line */
308711e5 40LttvTrace *gInit_Trace = NULL;
f7afe191 41
ec25ff5e 42static char *a_trace;
43
44void 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 62static 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
2061e03d 80 constructMainWin(NULL, Window_Creation_Data, TRUE);
fb87279e 81
82 gtk_main ();
0a6808c0 83
ec25ff5e 84 return FALSE;
0a6808c0 85}
86
0a6808c0 87G_MODULE_EXPORT void init(LttvModule *self, int argc, char *argv[]) {
88
ec25ff5e 89 LttvAttributeValue value;
f7afe191 90
91 // Global attributes only used for interaction with main() here.
ec25ff5e 92 LttvIAttribute *attributes = LTTV_IATTRIBUTE(lttv_global_attributes());
93
558aa013 94 g_critical("GUI init()");
95
ec25ff5e 96 lttv_option_add("trace", 't',
97 "add a trace to the trace set to analyse",
98 "pathname of the directory containing the trace",
99 LTTV_OPT_STRING, &a_trace, lttv_trace_option, NULL);
100
ec25ff5e 101 g_assert(lttv_iattribute_find_by_path(attributes, "hooks/main/before",
102 LTTV_POINTER, &value));
103 g_assert((main_hooks = *(value.v_pointer)) != NULL);
104
7a859036 105 gWinCreationData.argc = argc;
106 gWinCreationData.argv = argv;
ec25ff5e 107
7a859036 108 lttv_hooks_add(main_hooks, Window_Creation_Hook, &gWinCreationData);
0a6808c0 109
fb87279e 110}
111
7a859036 112void
113mainWindow_free(mainWindow * mw)
114{
2176f952 115 guint i, nb, ref_count;
116 LttvTrace * trace;
f7afe191 117
7a859036 118 if(mw){
2061e03d 119
f7afe191 120g_critical("begin remove");
121 lttv_hooks_destroy(mw->Traceset_Info->before_traceset);
122 lttv_hooks_destroy(mw->Traceset_Info->after_traceset);
123 lttv_hooks_destroy(mw->Traceset_Info->before_trace);
124 lttv_hooks_destroy(mw->Traceset_Info->after_trace);
125 lttv_hooks_destroy(mw->Traceset_Info->before_tracefile);
126 lttv_hooks_destroy(mw->Traceset_Info->after_tracefile);
127 lttv_hooks_destroy(mw->Traceset_Info->before_event);
128 lttv_hooks_destroy(mw->Traceset_Info->after_event);
129g_critical("end remove");
130
f7afe191 131 if(mw->Traceset_Info->path != NULL)
132 g_free(mw->Traceset_Info->path);
2061e03d 133 if(mw->Traceset_Info->TracesetContext != NULL){
f7afe191 134 lttv_context_fini(LTTV_TRACESET_CONTEXT(mw->Traceset_Info->TracesetContext));
2061e03d 135 g_object_unref(mw->Traceset_Info->TracesetContext);
136 }
f7afe191 137 if(mw->Traceset_Info->traceset != NULL) {
138 nb = lttv_traceset_number(mw->Traceset_Info->traceset);
139 for(i = 0 ; i < nb ; i++) {
2176f952 140 trace = lttv_traceset_get(mw->Traceset_Info->traceset, i);
141 ref_count = lttv_trace_get_ref_number(trace);
142 if(ref_count <= 1)
143 ltt_trace_close(lttv_trace(trace));
f7afe191 144 }
145 }
146
147 lttv_traceset_destroy(mw->Traceset_Info->traceset);
148
7a859036 149 g_object_unref(mw->Attributes);
150
f7afe191 151 g_free(mw->Traceset_Info);
152 mw->Traceset_Info = NULL;
153
154 Main_Window_List = g_slist_remove(Main_Window_List, mw);
2061e03d 155
156 g_hash_table_destroy(mw->hash_menu_item);
157 g_hash_table_destroy(mw->hash_toolbar_item);
f7afe191 158
159 g_free(mw);
160 mw = NULL;
7a859036 161 }
162}
163
164void
165mainWindow_Destructor(mainWindow * mw)
166{
167 if(GTK_IS_WIDGET(mw->MWindow)){
168 gtk_widget_destroy(mw->MWindow);
169 // gtk_widget_destroy(mw->HelpContents);
170 // gtk_widget_destroy(mw->AboutBox);
171 mw = NULL;
172 }
f7afe191 173 //mainWindow_free called when the object mw in the widget is unref.
174 //mainWindow_free(mw);
7a859036 175}
176
177
2176f952 178void main_window_destroy_walk(gpointer data, gpointer user_data)
fb87279e 179{
7a859036 180 mainWindow_Destructor((mainWindow*)data);
fb87279e 181}
182
183
184
185/**
186 * plugin's destroy function
187 *
188 * This function releases the memory reserved by the module and unregisters
189 * everything that has been registered in the gtkTraceSet API.
190 */
191G_MODULE_EXPORT void destroy() {
192
7a859036 193 LttvAttributeValue value;
308711e5 194 LttvTrace *trace;
ec25ff5e 195
ec25ff5e 196 lttv_option_remove("trace");
197
7a859036 198 lttv_hooks_remove_data(main_hooks, Window_Creation_Hook, &gWinCreationData);
ec25ff5e 199
ec25ff5e 200 g_critical("GUI destroy()");
fb87279e 201
2176f952 202 if(Main_Window_List){
203 g_slist_foreach(Main_Window_List, main_window_destroy_walk, NULL );
204 g_slist_free(Main_Window_List);
205 }
ec25ff5e 206
fb87279e 207}
208
209
210
211
This page took 0.032557 seconds and 4 git commands to generate.