e076699e |
1 | /* This file is part of the Linux Trace Toolkit viewer |
2 | * Copyright (C) 2003-2004 Mathieu Desnoyers and XangXiu Yang |
3 | * |
4 | * This program is free software; you can redistribute it and/or modify |
5 | * it under the terms of the GNU General Public License Version 2 as |
6 | * published by the Free Software Foundation; |
7 | * |
8 | * This program is distributed in the hope that it will be useful, |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 | * GNU General Public License for more details. |
12 | * |
13 | * You should have received a copy of the GNU General Public License |
14 | * along with this program; if not, write to the Free Software |
15 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, |
16 | * MA 02111-1307, USA. |
17 | */ |
18 | |
fb87279e |
19 | /* |
20 | * Initial main.c file generated by Glade. Edit as required. |
21 | * Glade will not overwrite this file. |
22 | */ |
23 | |
24 | #ifdef HAVE_CONFIG_H |
25 | # include <config.h> |
26 | #endif |
27 | |
28 | #include <gtk/gtk.h> |
29 | |
fb87279e |
30 | #include <lttv/lttv.h> |
0a6808c0 |
31 | #include <lttv/attribute.h> |
32 | #include <lttv/hook.h> |
33 | #include <lttv/option.h> |
34 | #include <lttv/module.h> |
ec25ff5e |
35 | #include <lttv/processTrace.h> |
36 | #include <lttv/state.h> |
6b1d3120 |
37 | #include <lttv/stats.h> |
37d0eca6 |
38 | #include <lttv/menu.h> |
39 | #include <lttv/toolbar.h> |
fb87279e |
40 | |
41 | #include "interface.h" |
42 | #include "support.h" |
637bd544 |
43 | #include <lttv/mainwindow.h> |
fb87279e |
44 | #include "callbacks.h" |
a5dcde2f |
45 | #include <ltt/trace.h> |
46 | |
fb87279e |
47 | |
48 | /* global variable */ |
68b48a45 |
49 | static WindowCreationData win_creation_data; |
0a6808c0 |
50 | |
ec25ff5e |
51 | /** Array containing instanced objects. */ |
68b48a45 |
52 | GSList * g_main_window_list = NULL ; |
ec25ff5e |
53 | |
f7afe191 |
54 | LttvHooks |
ec25ff5e |
55 | *main_hooks; |
56 | |
f7afe191 |
57 | /* Initial trace from command line */ |
68b48a45 |
58 | LttvTrace *g_init_trace = NULL; |
f7afe191 |
59 | |
ec25ff5e |
60 | static char *a_trace; |
61 | |
62 | void lttv_trace_option(void *hook_data) |
63 | { |
308711e5 |
64 | LttTrace *trace; |
65 | |
66 | trace = ltt_trace_open(a_trace); |
67 | if(trace == NULL) g_critical("cannot open trace %s", a_trace); |
68b48a45 |
68 | g_init_trace = lttv_trace_new(trace); |
ec25ff5e |
69 | } |
fb87279e |
70 | |
71 | /***************************************************************************** |
72 | * Functions for module loading/unloading * |
73 | *****************************************************************************/ |
74 | /** |
75 | * plugin's init function |
76 | * |
77 | * This function initializes the GUI. |
78 | */ |
79 | |
68b48a45 |
80 | static gboolean window_creation_hook(void *hook_data, void *call_data) |
fb87279e |
81 | { |
68b48a45 |
82 | WindowCreationData* window_creation_data = (WindowCreationData*)hook_data; |
fb87279e |
83 | |
68b48a45 |
84 | g_critical("GUI window_creation_hook()"); |
fb87279e |
85 | #ifdef ENABLE_NLS |
86 | bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR); |
87 | bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); |
88 | textdomain (GETTEXT_PACKAGE); |
89 | #endif |
90 | |
91 | gtk_set_locale (); |
68b48a45 |
92 | gtk_init (&(window_creation_data->argc), &(window_creation_data->argv)); |
fb87279e |
93 | |
94 | add_pixmap_directory (PACKAGE_DATA_DIR "/" PACKAGE "/pixmaps"); |
95 | add_pixmap_directory ("pixmaps"); |
0a6808c0 |
96 | add_pixmap_directory ("modules/gui/mainWin/pixmaps"); |
fb87279e |
97 | |
716e4367 |
98 | construct_main_window(NULL, window_creation_data); |
fb87279e |
99 | |
100 | gtk_main (); |
0a6808c0 |
101 | |
ec25ff5e |
102 | return FALSE; |
0a6808c0 |
103 | } |
104 | |
0a6808c0 |
105 | G_MODULE_EXPORT void init(LttvModule *self, int argc, char *argv[]) { |
106 | |
ec25ff5e |
107 | LttvAttributeValue value; |
f7afe191 |
108 | |
109 | // Global attributes only used for interaction with main() here. |
ec25ff5e |
110 | LttvIAttribute *attributes = LTTV_IATTRIBUTE(lttv_global_attributes()); |
111 | |
558aa013 |
112 | g_critical("GUI init()"); |
113 | |
ec25ff5e |
114 | lttv_option_add("trace", 't', |
115 | "add a trace to the trace set to analyse", |
116 | "pathname of the directory containing the trace", |
117 | LTTV_OPT_STRING, &a_trace, lttv_trace_option, NULL); |
118 | |
ec25ff5e |
119 | g_assert(lttv_iattribute_find_by_path(attributes, "hooks/main/before", |
120 | LTTV_POINTER, &value)); |
121 | g_assert((main_hooks = *(value.v_pointer)) != NULL); |
122 | |
68b48a45 |
123 | win_creation_data.argc = argc; |
124 | win_creation_data.argv = argv; |
ec25ff5e |
125 | |
68b48a45 |
126 | lttv_hooks_add(main_hooks, window_creation_hook, &win_creation_data); |
0a6808c0 |
127 | |
fb87279e |
128 | } |
129 | |
7a859036 |
130 | void |
bca3b81f |
131 | main_window_free(MainWindow * mw) |
7a859036 |
132 | { |
133 | if(mw){ |
540edb40 |
134 | while(mw->tab){ |
135 | lttv_state_remove_event_hooks( |
136 | (LttvTracesetState*)mw->tab->traceset_info->traceset_context); |
137 | mw->tab = mw->tab->next; |
138 | } |
bca3b81f |
139 | g_object_unref(mw->attributes); |
68b48a45 |
140 | g_main_window_list = g_slist_remove(g_main_window_list, mw); |
2061e03d |
141 | |
142 | g_hash_table_destroy(mw->hash_menu_item); |
143 | g_hash_table_destroy(mw->hash_toolbar_item); |
f7afe191 |
144 | |
145 | g_free(mw); |
146 | mw = NULL; |
7a859036 |
147 | } |
148 | } |
149 | |
150 | void |
bca3b81f |
151 | main_window_destructor(MainWindow * mw) |
7a859036 |
152 | { |
bca3b81f |
153 | if(GTK_IS_WIDGET(mw->mwindow)){ |
154 | gtk_widget_destroy(mw->mwindow); |
7a859036 |
155 | // gtk_widget_destroy(mw->HelpContents); |
156 | // gtk_widget_destroy(mw->AboutBox); |
157 | mw = NULL; |
158 | } |
68b48a45 |
159 | //main_window_free called when the object mw in the widget is unref. |
160 | //main_window_free(mw); |
7a859036 |
161 | } |
162 | |
163 | |
2176f952 |
164 | void main_window_destroy_walk(gpointer data, gpointer user_data) |
fb87279e |
165 | { |
bca3b81f |
166 | main_window_destructor((MainWindow*)data); |
fb87279e |
167 | } |
168 | |
169 | |
170 | |
171 | /** |
172 | * plugin's destroy function |
173 | * |
174 | * This function releases the memory reserved by the module and unregisters |
175 | * everything that has been registered in the gtkTraceSet API. |
176 | */ |
177 | G_MODULE_EXPORT void destroy() { |
178 | |
7a859036 |
179 | LttvAttributeValue value; |
308711e5 |
180 | LttvTrace *trace; |
ec25ff5e |
181 | |
ec25ff5e |
182 | lttv_option_remove("trace"); |
183 | |
68b48a45 |
184 | lttv_hooks_remove_data(main_hooks, window_creation_hook, &win_creation_data); |
ec25ff5e |
185 | |
ec25ff5e |
186 | g_critical("GUI destroy()"); |
fb87279e |
187 | |
68b48a45 |
188 | if(g_main_window_list){ |
189 | g_slist_foreach(g_main_window_list, main_window_destroy_walk, NULL ); |
190 | g_slist_free(g_main_window_list); |
2176f952 |
191 | } |
ec25ff5e |
192 | |
fb87279e |
193 | } |
194 | |
195 | |
196 | |
197 | |