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