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