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