lttv_trace_destroy fix
[lttv.git] / ltt / branches / poly / lttv / modules / gui / lttvwindow / lttvwindow / init_module.c
CommitLineData
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>
a1a2b649 29#include <glib.h>
fb87279e 30
fb87279e 31#include <lttv/lttv.h>
0a6808c0 32#include <lttv/attribute.h>
33#include <lttv/hook.h>
34#include <lttv/option.h>
35#include <lttv/module.h>
d8f124de 36#include <lttv/tracecontext.h>
ec25ff5e 37#include <lttv/state.h>
6b1d3120 38#include <lttv/stats.h>
13f86ce2 39#include <lttvwindow/menu.h>
40#include <lttvwindow/toolbar.h>
a1a2b649 41#include <lttvwindow/lttvwindowtraces.h>
fb87279e 42
43#include "interface.h"
44#include "support.h"
13f86ce2 45#include <lttvwindow/mainwindow.h>
2d262115 46#include <lttvwindow/mainwindow-private.h>
fb87279e 47#include "callbacks.h"
a5dcde2f 48#include <ltt/trace.h>
49
fb87279e 50
a1a2b649 51LttvTraceInfo LTTV_TRACES,
52 LTTV_COMPUTATION,
53 LTTV_REQUESTS_QUEUE,
54 LTTV_REQUESTS_CURRENT,
55 LTTV_NOTIFY_QUEUE,
8bc02ec8 56 LTTV_NOTIFY_CURRENT,
57 LTTV_COMPUTATION_TRACESET,
58 LTTV_COMPUTATION_TRACESET_CONTEXT,
59 LTTV_BEFORE_CHUNK_TRACESET,
60 LTTV_BEFORE_CHUNK_TRACE,
61 LTTV_BEFORE_CHUNK_TRACEFILE,
62 LTTV_AFTER_CHUNK_TRACESET,
63 LTTV_AFTER_CHUNK_TRACE,
64 LTTV_AFTER_CHUNK_TRACEFILE,
65 LTTV_BEFORE_REQUEST,
66 LTTV_AFTER_REQUEST,
67 LTTV_EVENT_HOOK,
68 LTTV_EVENT_HOOK_BY_ID,
313bd6fc 69 LTTV_HOOK_ADDER,
70 LTTV_HOOK_REMOVER,
8bc02ec8 71 LTTV_IN_PROGRESS,
b052368a 72 LTTV_READY,
73 LTTV_LOCK;
8bc02ec8 74
6ced96ef 75
ec25ff5e 76/** Array containing instanced objects. */
68b48a45 77GSList * g_main_window_list = NULL ;
ec25ff5e 78
f7afe191 79LttvHooks
ec25ff5e 80 *main_hooks;
81
f7afe191 82/* Initial trace from command line */
68b48a45 83LttvTrace *g_init_trace = NULL;
f7afe191 84
ec25ff5e 85static char *a_trace;
86
6ced96ef 87
ec25ff5e 88void lttv_trace_option(void *hook_data)
89{
308711e5 90 LttTrace *trace;
91fd6881 91 gchar abs_path[PATH_MAX];
a1a2b649 92
93 get_absolute_pathname(a_trace, abs_path);
94 g_init_trace = lttvwindowtraces_get_trace_by_name(abs_path);
95 if(g_init_trace == NULL) {
96 trace = ltt_trace_open(abs_path);
2a74fbf4 97 if(trace == NULL) {
98 g_warning("cannot open trace %s", abs_path);
99 } else {
100 g_init_trace = lttv_trace_new(trace);
101 lttvwindowtraces_add_trace(g_init_trace);
102 }
a1a2b649 103 }
ec25ff5e 104}
fb87279e 105
106/*****************************************************************************
107 * Functions for module loading/unloading *
108 *****************************************************************************/
109/**
110 * plugin's init function
111 *
112 * This function initializes the GUI.
113 */
114
68b48a45 115static gboolean window_creation_hook(void *hook_data, void *call_data)
fb87279e 116{
2a2fa4f0 117 g_debug("GUI window_creation_hook()");
fb87279e 118#ifdef ENABLE_NLS
119 bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR);
120 bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
121 textdomain (GETTEXT_PACKAGE);
122#endif
123
124 gtk_set_locale ();
08b1c66e 125 gtk_init (&lttv_argc, &lttv_argv);
fb87279e 126
127 add_pixmap_directory (PACKAGE_DATA_DIR "/" PACKAGE "/pixmaps");
128 add_pixmap_directory ("pixmaps");
077ba5c0 129 add_pixmap_directory ("../modules/gui/main/pixmaps");
fb87279e 130
08b1c66e 131 construct_main_window(NULL);
fb87279e 132
133 gtk_main ();
0a6808c0 134
ec25ff5e 135 return FALSE;
0a6808c0 136}
137
08b1c66e 138static void init() {
0a6808c0 139
ec25ff5e 140 LttvAttributeValue value;
f7afe191 141
142 // Global attributes only used for interaction with main() here.
ec25ff5e 143 LttvIAttribute *attributes = LTTV_IATTRIBUTE(lttv_global_attributes());
144
a1a2b649 145 LTTV_TRACES = g_quark_from_string("traces");
146 LTTV_COMPUTATION = g_quark_from_string("computation");
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");
154 LTTV_BEFORE_CHUNK_TRACESET = g_quark_from_string("before_chunk_traceset");
155 LTTV_BEFORE_CHUNK_TRACE = g_quark_from_string("before_chunk_trace");
156 LTTV_BEFORE_CHUNK_TRACEFILE = g_quark_from_string("before_chunk_tracefile");
157 LTTV_AFTER_CHUNK_TRACESET = g_quark_from_string("after_chunk_traceset");
158 LTTV_AFTER_CHUNK_TRACE = g_quark_from_string("after_chunk_trace");
159 LTTV_AFTER_CHUNK_TRACEFILE = g_quark_from_string("after_chunk_tracefile");
160 LTTV_BEFORE_REQUEST = g_quark_from_string("before_request");
161 LTTV_AFTER_REQUEST = g_quark_from_string("after_request");
162 LTTV_EVENT_HOOK = g_quark_from_string("event_hook");
163 LTTV_EVENT_HOOK_BY_ID = g_quark_from_string("event_hook_by_id");
313bd6fc 164 LTTV_HOOK_ADDER = g_quark_from_string("hook_adder");
165 LTTV_HOOK_REMOVER = g_quark_from_string("hook_remover");
8bc02ec8 166 LTTV_IN_PROGRESS = g_quark_from_string("in_progress");
167 LTTV_READY = g_quark_from_string("ready");
b052368a 168 LTTV_LOCK = g_quark_from_string("lock");
8bc02ec8 169
6ced96ef 170 g_debug("GUI init()");
171
ec25ff5e 172 lttv_option_add("trace", 't',
173 "add a trace to the trace set to analyse",
174 "pathname of the directory containing the trace",
175 LTTV_OPT_STRING, &a_trace, lttv_trace_option, NULL);
176
ec25ff5e 177 g_assert(lttv_iattribute_find_by_path(attributes, "hooks/main/before",
178 LTTV_POINTER, &value));
179 g_assert((main_hooks = *(value.v_pointer)) != NULL);
180
2d262115 181 lttv_hooks_add(main_hooks, window_creation_hook, NULL, LTTV_PRIO_DEFAULT);
0a6808c0 182
91fd6881 183 {
184 /* Register state calculator */
185 LttvHooks *hook_adder = lttv_hooks_new();
186 lttv_hooks_add(hook_adder, lttv_state_save_hook_add_event_hooks, NULL,
187 LTTV_PRIO_DEFAULT);
188 LttvHooks *hook_remover = lttv_hooks_new();
189 lttv_hooks_add(hook_remover, lttv_state_save_hook_remove_event_hooks,
190 NULL, LTTV_PRIO_DEFAULT);
191 /* Add state computation background hook adder to attributes */
192 lttvwindowtraces_register_computation_hooks(g_quark_from_string("state"),
193 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
194 hook_adder, hook_remover);
195 }
196
197 {
198 /* Register statistics calculator */
199 LttvHooks *hook_adder = lttv_hooks_new();
200 lttv_hooks_add(hook_adder, lttv_stats_hook_add_event_hooks, NULL,
201 LTTV_PRIO_DEFAULT);
202 LttvHooks *hook_remover = lttv_hooks_new();
203 lttv_hooks_add(hook_remover, lttv_stats_hook_remove_event_hooks,
204 NULL, LTTV_PRIO_DEFAULT);
205 LttvHooks *after_request = lttv_hooks_new();
206 lttv_hooks_add(after_request, lttv_stats_sum_traceset_hook, NULL,
207 LTTV_PRIO_DEFAULT);
208 /* Add state computation background hook adder to attributes */
209 lttvwindowtraces_register_computation_hooks(g_quark_from_string("stats"),
210 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
211 after_request, NULL, NULL,
212 hook_adder, hook_remover);
213 }
fb87279e 214}
215
7a859036 216void
bca3b81f 217main_window_destructor(MainWindow * mw)
7a859036 218{
2d262115 219 g_assert(GTK_IS_WIDGET(mw->mwindow));
220 gtk_widget_destroy(mw->mwindow);
fb87279e 221}
222
223
fb87279e 224/**
225 * plugin's destroy function
226 *
227 * This function releases the memory reserved by the module and unregisters
228 * everything that has been registered in the gtkTraceSet API.
229 */
08b1c66e 230static void destroy() {
fb87279e 231
7a859036 232 LttvAttributeValue value;
308711e5 233 LttvTrace *trace;
2d262115 234 GSList *iter = NULL;
235
91fd6881 236 lttvwindowtraces_unregister_requests(g_quark_from_string("stats"));
313bd6fc 237 lttvwindowtraces_unregister_requests(g_quark_from_string("state"));
91fd6881 238 lttvwindowtraces_unregister_computation_hooks(g_quark_from_string("stats"));
313bd6fc 239 lttvwindowtraces_unregister_computation_hooks(g_quark_from_string("state"));
240
ec25ff5e 241 lttv_option_remove("trace");
242
08b1c66e 243 lttv_hooks_remove_data(main_hooks, window_creation_hook, NULL);
ec25ff5e 244
2a2fa4f0 245 g_debug("GUI destroy()");
fb87279e 246
68b48a45 247 if(g_main_window_list){
2d262115 248 for(iter=g_main_window_list;iter!=NULL;iter=g_slist_next(iter)) {
249 main_window_destructor((MainWindow*)iter->data);
250 }
68b48a45 251 g_slist_free(g_main_window_list);
2176f952 252 }
ec25ff5e 253
fb87279e 254}
255
256
db2c9c14 257LTTV_MODULE("lttvwindow", "Viewer main window", \
08b1c66e 258 "Viewer with multiple windows, tabs and panes for graphical modules", \
2d262115 259 init, destroy, "stats", "option")
This page took 0.040587 seconds and 4 git commands to generate.