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