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