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