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" |
a5dcde2f |
27 | #include <ltt/trace.h> |
28 | |
fb87279e |
29 | |
30 | /* global variable */ |
68b48a45 |
31 | static WindowCreationData win_creation_data; |
0a6808c0 |
32 | |
ec25ff5e |
33 | /** Array containing instanced objects. */ |
68b48a45 |
34 | GSList * g_main_window_list = NULL ; |
ec25ff5e |
35 | |
f7afe191 |
36 | LttvHooks |
ec25ff5e |
37 | *main_hooks; |
38 | |
f7afe191 |
39 | /* Initial trace from command line */ |
68b48a45 |
40 | LttvTrace *g_init_trace = NULL; |
f7afe191 |
41 | |
ec25ff5e |
42 | static char *a_trace; |
43 | |
44 | void 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); |
68b48a45 |
50 | g_init_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 | |
68b48a45 |
62 | static gboolean window_creation_hook(void *hook_data, void *call_data) |
fb87279e |
63 | { |
68b48a45 |
64 | WindowCreationData* window_creation_data = (WindowCreationData*)hook_data; |
fb87279e |
65 | |
68b48a45 |
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 (); |
68b48a45 |
74 | gtk_init (&(window_creation_data->argc), &(window_creation_data->argv)); |
fb87279e |
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 | |
716e4367 |
80 | construct_main_window(NULL, window_creation_data); |
fb87279e |
81 | |
82 | gtk_main (); |
0a6808c0 |
83 | |
ec25ff5e |
84 | return FALSE; |
0a6808c0 |
85 | } |
86 | |
0a6808c0 |
87 | G_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 | |
68b48a45 |
105 | win_creation_data.argc = argc; |
106 | win_creation_data.argv = argv; |
ec25ff5e |
107 | |
68b48a45 |
108 | lttv_hooks_add(main_hooks, window_creation_hook, &win_creation_data); |
0a6808c0 |
109 | |
fb87279e |
110 | } |
111 | |
7a859036 |
112 | void |
bca3b81f |
113 | main_window_free(MainWindow * mw) |
7a859036 |
114 | { |
115 | if(mw){ |
540edb40 |
116 | while(mw->tab){ |
117 | lttv_state_remove_event_hooks( |
118 | (LttvTracesetState*)mw->tab->traceset_info->traceset_context); |
119 | mw->tab = mw->tab->next; |
120 | } |
bca3b81f |
121 | g_object_unref(mw->attributes); |
68b48a45 |
122 | g_main_window_list = g_slist_remove(g_main_window_list, mw); |
2061e03d |
123 | |
124 | g_hash_table_destroy(mw->hash_menu_item); |
125 | g_hash_table_destroy(mw->hash_toolbar_item); |
f7afe191 |
126 | |
127 | g_free(mw); |
128 | mw = NULL; |
7a859036 |
129 | } |
130 | } |
131 | |
132 | void |
bca3b81f |
133 | main_window_destructor(MainWindow * mw) |
7a859036 |
134 | { |
bca3b81f |
135 | if(GTK_IS_WIDGET(mw->mwindow)){ |
136 | gtk_widget_destroy(mw->mwindow); |
7a859036 |
137 | // gtk_widget_destroy(mw->HelpContents); |
138 | // gtk_widget_destroy(mw->AboutBox); |
139 | mw = NULL; |
140 | } |
68b48a45 |
141 | //main_window_free called when the object mw in the widget is unref. |
142 | //main_window_free(mw); |
7a859036 |
143 | } |
144 | |
145 | |
2176f952 |
146 | void main_window_destroy_walk(gpointer data, gpointer user_data) |
fb87279e |
147 | { |
bca3b81f |
148 | main_window_destructor((MainWindow*)data); |
fb87279e |
149 | } |
150 | |
151 | |
152 | |
153 | /** |
154 | * plugin's destroy function |
155 | * |
156 | * This function releases the memory reserved by the module and unregisters |
157 | * everything that has been registered in the gtkTraceSet API. |
158 | */ |
159 | G_MODULE_EXPORT void destroy() { |
160 | |
7a859036 |
161 | LttvAttributeValue value; |
308711e5 |
162 | LttvTrace *trace; |
ec25ff5e |
163 | |
ec25ff5e |
164 | lttv_option_remove("trace"); |
165 | |
68b48a45 |
166 | lttv_hooks_remove_data(main_hooks, window_creation_hook, &win_creation_data); |
ec25ff5e |
167 | |
ec25ff5e |
168 | g_critical("GUI destroy()"); |
fb87279e |
169 | |
68b48a45 |
170 | if(g_main_window_list){ |
171 | g_slist_foreach(g_main_window_list, main_window_destroy_walk, NULL ); |
172 | g_slist_free(g_main_window_list); |
2176f952 |
173 | } |
ec25ff5e |
174 | |
fb87279e |
175 | } |
176 | |
177 | |
178 | |
179 | |