Commit | Line | Data |
---|---|---|
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 | |
b9ce0bad YB |
15 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
16 | * MA 02110-1301, USA. | |
e076699e | 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> | |
a1a2b649 | 29 | #include <glib.h> |
5e96e7e3 | 30 | #include <string.h> |
fb87279e | 31 | |
fb87279e | 32 | #include <lttv/lttv.h> |
0a6808c0 | 33 | #include <lttv/attribute.h> |
34 | #include <lttv/hook.h> | |
35 | #include <lttv/option.h> | |
36 | #include <lttv/module.h> | |
451aaf27 | 37 | |
ec25ff5e | 38 | #include <lttv/state.h> |
451aaf27 | 39 | #ifdef BABEL_CLEANUP |
6b1d3120 | 40 | #include <lttv/stats.h> |
451aaf27 | 41 | #endif /* BABEL_CLEANUP */ |
13f86ce2 | 42 | #include <lttvwindow/menu.h> |
43 | #include <lttvwindow/toolbar.h> | |
a1a2b649 | 44 | #include <lttvwindow/lttvwindowtraces.h> |
fb87279e | 45 | |
46 | #include "interface.h" | |
47 | #include "support.h" | |
13f86ce2 | 48 | #include <lttvwindow/mainwindow.h> |
2d262115 | 49 | #include <lttvwindow/mainwindow-private.h> |
fb87279e | 50 | #include "callbacks.h" |
a5dcde2f | 51 | |
fb87279e | 52 | |
f9240312 | 53 | __EXPORT LttvTraceInfo |
54 | LTTV_TRACES, | |
a1a2b649 | 55 | LTTV_COMPUTATION, |
e025a729 | 56 | LTTV_VIEWER_CONSTRUCTORS, |
a1a2b649 | 57 | LTTV_REQUESTS_QUEUE, |
58 | LTTV_REQUESTS_CURRENT, | |
59 | LTTV_NOTIFY_QUEUE, | |
8bc02ec8 | 60 | LTTV_NOTIFY_CURRENT, |
61 | LTTV_COMPUTATION_TRACESET, | |
62 | LTTV_COMPUTATION_TRACESET_CONTEXT, | |
79257ba5 | 63 | LTTV_COMPUTATION_SYNC_POSITION, |
8bc02ec8 | 64 | LTTV_BEFORE_CHUNK_TRACESET, |
65 | LTTV_BEFORE_CHUNK_TRACE, | |
66 | LTTV_BEFORE_CHUNK_TRACEFILE, | |
67 | LTTV_AFTER_CHUNK_TRACESET, | |
68 | LTTV_AFTER_CHUNK_TRACE, | |
69 | LTTV_AFTER_CHUNK_TRACEFILE, | |
70 | LTTV_BEFORE_REQUEST, | |
71 | LTTV_AFTER_REQUEST, | |
72 | LTTV_EVENT_HOOK, | |
750eb11a | 73 | LTTV_EVENT_HOOK_BY_ID_CHANNEL, |
313bd6fc | 74 | LTTV_HOOK_ADDER, |
75 | LTTV_HOOK_REMOVER, | |
8bc02ec8 | 76 | LTTV_IN_PROGRESS, |
b052368a | 77 | LTTV_READY, |
78 | LTTV_LOCK; | |
8bc02ec8 | 79 | |
6ced96ef | 80 | |
ec25ff5e | 81 | /** Array containing instanced objects. */ |
68b48a45 | 82 | GSList * g_main_window_list = NULL ; |
ec25ff5e | 83 | |
f7afe191 | 84 | LttvHooks |
ec25ff5e | 85 | *main_hooks; |
86 | ||
f7afe191 | 87 | /* Initial trace from command line */ |
8e3a7c75 | 88 | static GSList *g_init_trace = NULL; |
f7afe191 | 89 | |
ec25ff5e | 90 | static char *a_trace; |
8e3a7c75 | 91 | //static char g_init_trace[PATH_MAX] = ""; |
1e3594a3 | 92 | static gboolean a_live; |
ec25ff5e | 93 | |
6ced96ef | 94 | |
ec25ff5e | 95 | void lttv_trace_option(void *hook_data) |
96 | { | |
8e3a7c75 | 97 | //LttTrace *trace; |
6cec4cd2 | 98 | |
8e3a7c75 | 99 | //get_absolute_pathname(a_trace, g_init_trace); |
100 | g_init_trace = g_slist_append(g_init_trace, a_trace); | |
ec25ff5e | 101 | } |
fb87279e | 102 | |
103 | /***************************************************************************** | |
104 | * Functions for module loading/unloading * | |
105 | *****************************************************************************/ | |
106 | /** | |
107 | * plugin's init function | |
108 | * | |
109 | * This function initializes the GUI. | |
110 | */ | |
111 | ||
68b48a45 | 112 | static gboolean window_creation_hook(void *hook_data, void *call_data) |
fb87279e | 113 | { |
2a2fa4f0 | 114 | g_debug("GUI window_creation_hook()"); |
fb87279e | 115 | #ifdef ENABLE_NLS |
116 | bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR); | |
117 | bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); | |
118 | textdomain (GETTEXT_PACKAGE); | |
119 | #endif | |
120 | ||
121 | gtk_set_locale (); | |
08b1c66e | 122 | gtk_init (<tv_argc, <tv_argv); |
fb87279e | 123 | |
dced178e | 124 | add_pixmap_directory (PACKAGE_DATA_DIR "/pixmaps/" PACKAGE); |
fb87279e | 125 | add_pixmap_directory ("pixmaps"); |
077ba5c0 | 126 | add_pixmap_directory ("../modules/gui/main/pixmaps"); |
fb87279e | 127 | |
6cec4cd2 | 128 | /* First window, use command line trace */ |
451aaf27 | 129 | create_main_window_with_trace_list(g_init_trace); |
fb87279e | 130 | |
131 | gtk_main (); | |
0a6808c0 | 132 | |
ec25ff5e | 133 | return FALSE; |
0a6808c0 | 134 | } |
135 | ||
08b1c66e | 136 | static void init() { |
0a6808c0 | 137 | |
ec25ff5e | 138 | LttvAttributeValue value; |
8f318283 | 139 | gboolean retval; |
f7afe191 | 140 | |
141 | // Global attributes only used for interaction with main() here. | |
ec25ff5e | 142 | LttvIAttribute *attributes = LTTV_IATTRIBUTE(lttv_global_attributes()); |
143 | ||
a1a2b649 | 144 | LTTV_TRACES = g_quark_from_string("traces"); |
145 | LTTV_COMPUTATION = g_quark_from_string("computation"); | |
e025a729 | 146 | LTTV_VIEWER_CONSTRUCTORS = g_quark_from_string("viewer_constructors"); |
a1a2b649 | 147 | LTTV_REQUESTS_QUEUE = g_quark_from_string("requests_queue"); |
148 | LTTV_REQUESTS_CURRENT = g_quark_from_string("requests_current"); | |
149 | LTTV_NOTIFY_QUEUE = g_quark_from_string("notify_queue"); | |
150 | LTTV_NOTIFY_CURRENT = g_quark_from_string("notify_current"); | |
8bc02ec8 | 151 | LTTV_COMPUTATION_TRACESET = g_quark_from_string("computation_traceset"); |
152 | LTTV_COMPUTATION_TRACESET_CONTEXT = | |
153 | g_quark_from_string("computation_traceset_context"); | |
79257ba5 | 154 | LTTV_COMPUTATION_SYNC_POSITION = |
155 | g_quark_from_string("computation_sync_position"); | |
8bc02ec8 | 156 | LTTV_BEFORE_CHUNK_TRACESET = g_quark_from_string("before_chunk_traceset"); |
157 | LTTV_BEFORE_CHUNK_TRACE = g_quark_from_string("before_chunk_trace"); | |
158 | LTTV_BEFORE_CHUNK_TRACEFILE = g_quark_from_string("before_chunk_tracefile"); | |
159 | LTTV_AFTER_CHUNK_TRACESET = g_quark_from_string("after_chunk_traceset"); | |
160 | LTTV_AFTER_CHUNK_TRACE = g_quark_from_string("after_chunk_trace"); | |
161 | LTTV_AFTER_CHUNK_TRACEFILE = g_quark_from_string("after_chunk_tracefile"); | |
162 | LTTV_BEFORE_REQUEST = g_quark_from_string("before_request"); | |
163 | LTTV_AFTER_REQUEST = g_quark_from_string("after_request"); | |
164 | LTTV_EVENT_HOOK = g_quark_from_string("event_hook"); | |
750eb11a | 165 | LTTV_EVENT_HOOK_BY_ID_CHANNEL = g_quark_from_string("event_hook_by_id_channel"); |
313bd6fc | 166 | LTTV_HOOK_ADDER = g_quark_from_string("hook_adder"); |
167 | LTTV_HOOK_REMOVER = g_quark_from_string("hook_remover"); | |
8bc02ec8 | 168 | LTTV_IN_PROGRESS = g_quark_from_string("in_progress"); |
169 | LTTV_READY = g_quark_from_string("ready"); | |
b052368a | 170 | LTTV_LOCK = g_quark_from_string("lock"); |
8bc02ec8 | 171 | |
6ced96ef | 172 | g_debug("GUI init()"); |
173 | ||
ec25ff5e | 174 | lttv_option_add("trace", 't', |
175 | "add a trace to the trace set to analyse", | |
176 | "pathname of the directory containing the trace", | |
177 | LTTV_OPT_STRING, &a_trace, lttv_trace_option, NULL); | |
178 | ||
1e3594a3 YB |
179 | a_live = FALSE; |
180 | lttv_option_add("live", 0, | |
181 | "define if the traceset is receiving live informations", | |
182 | "", | |
183 | LTTV_OPT_NONE, &a_live, NULL, NULL); | |
184 | ||
8f318283 BP |
185 | retval= lttv_iattribute_find_by_path(attributes, "hooks/main/before", |
186 | LTTV_POINTER, &value); | |
187 | g_assert(retval); | |
ec25ff5e | 188 | g_assert((main_hooks = *(value.v_pointer)) != NULL); |
189 | ||
2d262115 | 190 | lttv_hooks_add(main_hooks, window_creation_hook, NULL, LTTV_PRIO_DEFAULT); |
451aaf27 | 191 | #ifdef BABEL_CLEANUP |
91fd6881 | 192 | { |
193 | /* Register state calculator */ | |
194 | LttvHooks *hook_adder = lttv_hooks_new(); | |
195 | lttv_hooks_add(hook_adder, lttv_state_save_hook_add_event_hooks, NULL, | |
196 | LTTV_PRIO_DEFAULT); | |
1ce324c6 | 197 | lttv_hooks_add(hook_adder, lttv_state_hook_add_event_hooks, NULL, |
198 | LTTV_PRIO_DEFAULT); | |
91fd6881 | 199 | LttvHooks *hook_remover = lttv_hooks_new(); |
200 | lttv_hooks_add(hook_remover, lttv_state_save_hook_remove_event_hooks, | |
201 | NULL, LTTV_PRIO_DEFAULT); | |
1ce324c6 | 202 | lttv_hooks_add(hook_remover, lttv_state_hook_remove_event_hooks, |
203 | NULL, LTTV_PRIO_DEFAULT); | |
91fd6881 | 204 | /* Add state computation background hook adder to attributes */ |
205 | lttvwindowtraces_register_computation_hooks(g_quark_from_string("state"), | |
206 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, | |
207 | hook_adder, hook_remover); | |
208 | } | |
209 | ||
210 | { | |
211 | /* Register statistics calculator */ | |
212 | LttvHooks *hook_adder = lttv_hooks_new(); | |
213 | lttv_hooks_add(hook_adder, lttv_stats_hook_add_event_hooks, NULL, | |
214 | LTTV_PRIO_DEFAULT); | |
1ce324c6 | 215 | lttv_hooks_add(hook_adder, lttv_state_hook_add_event_hooks, NULL, |
216 | LTTV_PRIO_DEFAULT); | |
91fd6881 | 217 | LttvHooks *hook_remover = lttv_hooks_new(); |
218 | lttv_hooks_add(hook_remover, lttv_stats_hook_remove_event_hooks, | |
219 | NULL, LTTV_PRIO_DEFAULT); | |
1ce324c6 | 220 | lttv_hooks_add(hook_remover, lttv_state_hook_remove_event_hooks, |
221 | NULL, LTTV_PRIO_DEFAULT); | |
91fd6881 | 222 | LttvHooks *after_request = lttv_hooks_new(); |
223 | lttv_hooks_add(after_request, lttv_stats_sum_traceset_hook, NULL, | |
224 | LTTV_PRIO_DEFAULT); | |
225 | /* Add state computation background hook adder to attributes */ | |
226 | lttvwindowtraces_register_computation_hooks(g_quark_from_string("stats"), | |
227 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, | |
228 | after_request, NULL, NULL, | |
229 | hook_adder, hook_remover); | |
230 | } | |
451aaf27 | 231 | #endif /* BABEL_CLEANUP */ |
fb87279e | 232 | } |
233 | ||
7a859036 | 234 | void |
bca3b81f | 235 | main_window_destructor(MainWindow * mw) |
7a859036 | 236 | { |
2d262115 | 237 | g_assert(GTK_IS_WIDGET(mw->mwindow)); |
238 | gtk_widget_destroy(mw->mwindow); | |
fb87279e | 239 | } |
240 | ||
d0724d16 | 241 | static void destroy_walk(gpointer data, gpointer user_data) |
242 | { | |
243 | main_window_destructor((MainWindow*)data); | |
244 | } | |
fb87279e | 245 | |
fb87279e | 246 | /** |
247 | * plugin's destroy function | |
248 | * | |
249 | * This function releases the memory reserved by the module and unregisters | |
250 | * everything that has been registered in the gtkTraceSet API. | |
251 | */ | |
08b1c66e | 252 | static void destroy() { |
fb87279e | 253 | |
ec25ff5e | 254 | lttv_option_remove("trace"); |
1e3594a3 | 255 | lttv_option_remove("live"); |
ec25ff5e | 256 | |
08b1c66e | 257 | lttv_hooks_remove_data(main_hooks, window_creation_hook, NULL); |
ec25ff5e | 258 | |
2a2fa4f0 | 259 | g_debug("GUI destroy()"); |
fb87279e | 260 | |
d0724d16 | 261 | g_slist_foreach(g_main_window_list, destroy_walk, NULL); |
262 | ||
263 | g_slist_free(g_main_window_list); | |
8e3a7c75 | 264 | |
265 | g_slist_free(g_init_trace); | |
ec25ff5e | 266 | |
fb87279e | 267 | } |
268 | ||
269 | ||
db2c9c14 | 270 | LTTV_MODULE("lttvwindow", "Viewer main window", \ |
08b1c66e | 271 | "Viewer with multiple windows, tabs and panes for graphical modules", \ |
451aaf27 | 272 | init, destroy, "option","state") |