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> |
29 | |
fb87279e |
30 | #include <lttv/lttv.h> |
0a6808c0 |
31 | #include <lttv/attribute.h> |
32 | #include <lttv/hook.h> |
33 | #include <lttv/option.h> |
34 | #include <lttv/module.h> |
d8f124de |
35 | #include <lttv/tracecontext.h> |
ec25ff5e |
36 | #include <lttv/state.h> |
6b1d3120 |
37 | #include <lttv/stats.h> |
13f86ce2 |
38 | #include <lttvwindow/menu.h> |
39 | #include <lttvwindow/toolbar.h> |
fb87279e |
40 | |
41 | #include "interface.h" |
42 | #include "support.h" |
13f86ce2 |
43 | #include <lttvwindow/mainwindow.h> |
2d262115 |
44 | #include <lttvwindow/mainwindow-private.h> |
fb87279e |
45 | #include "callbacks.h" |
a5dcde2f |
46 | #include <ltt/trace.h> |
47 | |
fb87279e |
48 | |
6ced96ef |
49 | GQuark LTTV_TRACES; |
50 | |
ec25ff5e |
51 | /** Array containing instanced objects. */ |
68b48a45 |
52 | GSList * g_main_window_list = NULL ; |
ec25ff5e |
53 | |
f7afe191 |
54 | LttvHooks |
ec25ff5e |
55 | *main_hooks; |
56 | |
f7afe191 |
57 | /* Initial trace from command line */ |
68b48a45 |
58 | LttvTrace *g_init_trace = NULL; |
f7afe191 |
59 | |
ec25ff5e |
60 | static char *a_trace; |
61 | |
6ced96ef |
62 | |
ec25ff5e |
63 | void lttv_trace_option(void *hook_data) |
64 | { |
308711e5 |
65 | LttTrace *trace; |
6ced96ef |
66 | gchar *path; |
308711e5 |
67 | |
68 | trace = ltt_trace_open(a_trace); |
69 | if(trace == NULL) g_critical("cannot open trace %s", a_trace); |
68b48a45 |
70 | g_init_trace = lttv_trace_new(trace); |
6ced96ef |
71 | |
ec25ff5e |
72 | } |
fb87279e |
73 | |
74 | /***************************************************************************** |
75 | * Functions for module loading/unloading * |
76 | *****************************************************************************/ |
77 | /** |
78 | * plugin's init function |
79 | * |
80 | * This function initializes the GUI. |
81 | */ |
82 | |
68b48a45 |
83 | static gboolean window_creation_hook(void *hook_data, void *call_data) |
fb87279e |
84 | { |
2a2fa4f0 |
85 | g_debug("GUI window_creation_hook()"); |
fb87279e |
86 | #ifdef ENABLE_NLS |
87 | bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR); |
88 | bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); |
89 | textdomain (GETTEXT_PACKAGE); |
90 | #endif |
91 | |
92 | gtk_set_locale (); |
08b1c66e |
93 | gtk_init (<tv_argc, <tv_argv); |
fb87279e |
94 | |
95 | add_pixmap_directory (PACKAGE_DATA_DIR "/" PACKAGE "/pixmaps"); |
96 | add_pixmap_directory ("pixmaps"); |
077ba5c0 |
97 | add_pixmap_directory ("../modules/gui/main/pixmaps"); |
fb87279e |
98 | |
08b1c66e |
99 | construct_main_window(NULL); |
fb87279e |
100 | |
101 | gtk_main (); |
0a6808c0 |
102 | |
ec25ff5e |
103 | return FALSE; |
0a6808c0 |
104 | } |
105 | |
08b1c66e |
106 | static void init() { |
0a6808c0 |
107 | |
ec25ff5e |
108 | LttvAttributeValue value; |
f7afe191 |
109 | |
110 | // Global attributes only used for interaction with main() here. |
ec25ff5e |
111 | LttvIAttribute *attributes = LTTV_IATTRIBUTE(lttv_global_attributes()); |
112 | |
6ced96ef |
113 | LTTV_TRACES = g_quark_from_string("traces/"); |
558aa013 |
114 | |
6ced96ef |
115 | g_debug("GUI init()"); |
116 | |
ec25ff5e |
117 | lttv_option_add("trace", 't', |
118 | "add a trace to the trace set to analyse", |
119 | "pathname of the directory containing the trace", |
120 | LTTV_OPT_STRING, &a_trace, lttv_trace_option, NULL); |
121 | |
ec25ff5e |
122 | g_assert(lttv_iattribute_find_by_path(attributes, "hooks/main/before", |
123 | LTTV_POINTER, &value)); |
124 | g_assert((main_hooks = *(value.v_pointer)) != NULL); |
125 | |
2d262115 |
126 | lttv_hooks_add(main_hooks, window_creation_hook, NULL, LTTV_PRIO_DEFAULT); |
0a6808c0 |
127 | |
fb87279e |
128 | } |
129 | |
7a859036 |
130 | void |
bca3b81f |
131 | main_window_destructor(MainWindow * mw) |
7a859036 |
132 | { |
2d262115 |
133 | g_assert(GTK_IS_WIDGET(mw->mwindow)); |
134 | gtk_widget_destroy(mw->mwindow); |
fb87279e |
135 | } |
136 | |
137 | |
fb87279e |
138 | /** |
139 | * plugin's destroy function |
140 | * |
141 | * This function releases the memory reserved by the module and unregisters |
142 | * everything that has been registered in the gtkTraceSet API. |
143 | */ |
08b1c66e |
144 | static void destroy() { |
fb87279e |
145 | |
7a859036 |
146 | LttvAttributeValue value; |
308711e5 |
147 | LttvTrace *trace; |
2d262115 |
148 | GSList *iter = NULL; |
149 | |
ec25ff5e |
150 | lttv_option_remove("trace"); |
151 | |
08b1c66e |
152 | lttv_hooks_remove_data(main_hooks, window_creation_hook, NULL); |
ec25ff5e |
153 | |
2a2fa4f0 |
154 | g_debug("GUI destroy()"); |
fb87279e |
155 | |
68b48a45 |
156 | if(g_main_window_list){ |
2d262115 |
157 | for(iter=g_main_window_list;iter!=NULL;iter=g_slist_next(iter)) { |
158 | main_window_destructor((MainWindow*)iter->data); |
159 | } |
68b48a45 |
160 | g_slist_free(g_main_window_list); |
2176f952 |
161 | } |
ec25ff5e |
162 | |
fb87279e |
163 | } |
164 | |
165 | |
db2c9c14 |
166 | LTTV_MODULE("lttvwindow", "Viewer main window", \ |
08b1c66e |
167 | "Viewer with multiple windows, tabs and panes for graphical modules", \ |
2d262115 |
168 | init, destroy, "stats", "option") |