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, |
56 | LTTV_NOTIFY_CURRENT; |
6ced96ef |
57 | |
ec25ff5e |
58 | /** Array containing instanced objects. */ |
68b48a45 |
59 | GSList * g_main_window_list = NULL ; |
ec25ff5e |
60 | |
f7afe191 |
61 | LttvHooks |
ec25ff5e |
62 | *main_hooks; |
63 | |
f7afe191 |
64 | /* Initial trace from command line */ |
68b48a45 |
65 | LttvTrace *g_init_trace = NULL; |
f7afe191 |
66 | |
ec25ff5e |
67 | static char *a_trace; |
68 | |
6ced96ef |
69 | |
ec25ff5e |
70 | void lttv_trace_option(void *hook_data) |
71 | { |
308711e5 |
72 | LttTrace *trace; |
a1a2b649 |
73 | gchar *abs_path; |
74 | |
75 | get_absolute_pathname(a_trace, abs_path); |
76 | g_init_trace = lttvwindowtraces_get_trace_by_name(abs_path); |
77 | if(g_init_trace == NULL) { |
78 | trace = ltt_trace_open(abs_path); |
79 | if(trace == NULL) g_critical("cannot open trace %s", abs_path); |
80 | g_init_trace = lttv_trace_new(trace); |
81 | lttvwindowtraces_add_trace(g_init_trace); |
82 | } |
ec25ff5e |
83 | } |
fb87279e |
84 | |
85 | /***************************************************************************** |
86 | * Functions for module loading/unloading * |
87 | *****************************************************************************/ |
88 | /** |
89 | * plugin's init function |
90 | * |
91 | * This function initializes the GUI. |
92 | */ |
93 | |
68b48a45 |
94 | static gboolean window_creation_hook(void *hook_data, void *call_data) |
fb87279e |
95 | { |
2a2fa4f0 |
96 | g_debug("GUI window_creation_hook()"); |
fb87279e |
97 | #ifdef ENABLE_NLS |
98 | bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR); |
99 | bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); |
100 | textdomain (GETTEXT_PACKAGE); |
101 | #endif |
102 | |
103 | gtk_set_locale (); |
08b1c66e |
104 | gtk_init (<tv_argc, <tv_argv); |
fb87279e |
105 | |
106 | add_pixmap_directory (PACKAGE_DATA_DIR "/" PACKAGE "/pixmaps"); |
107 | add_pixmap_directory ("pixmaps"); |
077ba5c0 |
108 | add_pixmap_directory ("../modules/gui/main/pixmaps"); |
fb87279e |
109 | |
08b1c66e |
110 | construct_main_window(NULL); |
fb87279e |
111 | |
112 | gtk_main (); |
0a6808c0 |
113 | |
ec25ff5e |
114 | return FALSE; |
0a6808c0 |
115 | } |
116 | |
08b1c66e |
117 | static void init() { |
0a6808c0 |
118 | |
ec25ff5e |
119 | LttvAttributeValue value; |
f7afe191 |
120 | |
121 | // Global attributes only used for interaction with main() here. |
ec25ff5e |
122 | LttvIAttribute *attributes = LTTV_IATTRIBUTE(lttv_global_attributes()); |
123 | |
a1a2b649 |
124 | LTTV_TRACES = g_quark_from_string("traces"); |
125 | LTTV_COMPUTATION = g_quark_from_string("computation"); |
126 | LTTV_REQUESTS_QUEUE = g_quark_from_string("requests_queue"); |
127 | LTTV_REQUESTS_CURRENT = g_quark_from_string("requests_current"); |
128 | LTTV_NOTIFY_QUEUE = g_quark_from_string("notify_queue"); |
129 | LTTV_NOTIFY_CURRENT = g_quark_from_string("notify_current"); |
558aa013 |
130 | |
6ced96ef |
131 | g_debug("GUI init()"); |
132 | |
ec25ff5e |
133 | lttv_option_add("trace", 't', |
134 | "add a trace to the trace set to analyse", |
135 | "pathname of the directory containing the trace", |
136 | LTTV_OPT_STRING, &a_trace, lttv_trace_option, NULL); |
137 | |
ec25ff5e |
138 | g_assert(lttv_iattribute_find_by_path(attributes, "hooks/main/before", |
139 | LTTV_POINTER, &value)); |
140 | g_assert((main_hooks = *(value.v_pointer)) != NULL); |
141 | |
2d262115 |
142 | lttv_hooks_add(main_hooks, window_creation_hook, NULL, LTTV_PRIO_DEFAULT); |
0a6808c0 |
143 | |
fb87279e |
144 | } |
145 | |
7a859036 |
146 | void |
bca3b81f |
147 | main_window_destructor(MainWindow * mw) |
7a859036 |
148 | { |
2d262115 |
149 | g_assert(GTK_IS_WIDGET(mw->mwindow)); |
150 | gtk_widget_destroy(mw->mwindow); |
fb87279e |
151 | } |
152 | |
153 | |
fb87279e |
154 | /** |
155 | * plugin's destroy function |
156 | * |
157 | * This function releases the memory reserved by the module and unregisters |
158 | * everything that has been registered in the gtkTraceSet API. |
159 | */ |
08b1c66e |
160 | static void destroy() { |
fb87279e |
161 | |
7a859036 |
162 | LttvAttributeValue value; |
308711e5 |
163 | LttvTrace *trace; |
2d262115 |
164 | GSList *iter = NULL; |
165 | |
ec25ff5e |
166 | lttv_option_remove("trace"); |
167 | |
08b1c66e |
168 | lttv_hooks_remove_data(main_hooks, window_creation_hook, NULL); |
ec25ff5e |
169 | |
2a2fa4f0 |
170 | g_debug("GUI destroy()"); |
fb87279e |
171 | |
68b48a45 |
172 | if(g_main_window_list){ |
2d262115 |
173 | for(iter=g_main_window_list;iter!=NULL;iter=g_slist_next(iter)) { |
174 | main_window_destructor((MainWindow*)iter->data); |
175 | } |
68b48a45 |
176 | g_slist_free(g_main_window_list); |
2176f952 |
177 | } |
ec25ff5e |
178 | |
fb87279e |
179 | } |
180 | |
181 | |
db2c9c14 |
182 | LTTV_MODULE("lttvwindow", "Viewer main window", \ |
08b1c66e |
183 | "Viewer with multiple windows, tabs and panes for graphical modules", \ |
2d262115 |
184 | init, destroy, "stats", "option") |