fb87279e |
1 | /* |
2 | * Initial main.c file generated by Glade. Edit as required. |
3 | * Glade will not overwrite this file. |
4 | */ |
5 | |
6 | #ifdef HAVE_CONFIG_H |
7 | # include <config.h> |
8 | #endif |
9 | |
10 | #include <gtk/gtk.h> |
11 | |
fb87279e |
12 | #include <lttv/lttv.h> |
0a6808c0 |
13 | #include <lttv/attribute.h> |
14 | #include <lttv/hook.h> |
15 | #include <lttv/option.h> |
16 | #include <lttv/module.h> |
ec25ff5e |
17 | #include <lttv/processTrace.h> |
18 | #include <lttv/state.h> |
6b1d3120 |
19 | #include <lttv/stats.h> |
37d0eca6 |
20 | #include <lttv/menu.h> |
21 | #include <lttv/toolbar.h> |
fb87279e |
22 | |
23 | #include "interface.h" |
24 | #include "support.h" |
95cd67ef |
25 | #include <lttv/mainWindow.h> |
fb87279e |
26 | #include "callbacks.h" |
27 | |
28 | /* global variable */ |
6b1d3120 |
29 | LttvTracesetStats * gTracesetContext = NULL; |
ec25ff5e |
30 | static LttvTraceset * traceset; |
0a6808c0 |
31 | |
ec25ff5e |
32 | /** Array containing instanced objects. */ |
33 | GSList * Main_Window_List = NULL ; |
34 | |
35 | static LttvHooks |
36 | *before_traceset, |
37 | *after_traceset, |
38 | *before_trace, |
39 | *after_trace, |
40 | *before_tracefile, |
41 | *after_tracefile, |
42 | *before_event, |
43 | *after_event, |
44 | *main_hooks; |
45 | |
46 | static char *a_trace; |
47 | |
48 | void lttv_trace_option(void *hook_data) |
49 | { |
50 | LttTrace *trace; |
51 | |
52 | trace = ltt_trace_open(a_trace); |
53 | if(trace == NULL) g_critical("cannot open trace %s", a_trace); |
54 | lttv_traceset_add(traceset, trace); |
55 | } |
fb87279e |
56 | |
57 | /***************************************************************************** |
58 | * Functions for module loading/unloading * |
59 | *****************************************************************************/ |
60 | /** |
61 | * plugin's init function |
62 | * |
63 | * This function initializes the GUI. |
64 | */ |
65 | |
0a6808c0 |
66 | static gboolean Window_Creation_Hook(void *hook_data, void *call_data) |
fb87279e |
67 | { |
5723fa24 |
68 | WindowCreationData* Window_Creation_Data = (WindowCreationData*)hook_data; |
fb87279e |
69 | |
558aa013 |
70 | g_critical("GUI Window_Creation_Hook()"); |
fb87279e |
71 | #ifdef ENABLE_NLS |
72 | bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR); |
73 | bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); |
74 | textdomain (GETTEXT_PACKAGE); |
75 | #endif |
76 | |
77 | gtk_set_locale (); |
78 | gtk_init (&(Window_Creation_Data->argc), &(Window_Creation_Data->argv)); |
79 | |
80 | add_pixmap_directory (PACKAGE_DATA_DIR "/" PACKAGE "/pixmaps"); |
81 | add_pixmap_directory ("pixmaps"); |
0a6808c0 |
82 | add_pixmap_directory ("modules/gui/mainWin/pixmaps"); |
fb87279e |
83 | |
5723fa24 |
84 | |
ec25ff5e |
85 | if(!gTracesetContext){ |
6b1d3120 |
86 | gTracesetContext = g_object_new(LTTV_TRACESET_STATS_TYPE, NULL); |
ec25ff5e |
87 | //FIXME: lttv_context_fini should be called some where. |
88 | lttv_context_init(LTTV_TRACESET_CONTEXT(gTracesetContext), traceset); |
89 | } |
fb87279e |
90 | |
5723fa24 |
91 | constructMainWin(NULL, Window_Creation_Data); |
fb87279e |
92 | |
93 | gtk_main (); |
0a6808c0 |
94 | |
ec25ff5e |
95 | return FALSE; |
0a6808c0 |
96 | } |
97 | |
98 | |
99 | |
100 | |
101 | G_MODULE_EXPORT void init(LttvModule *self, int argc, char *argv[]) { |
102 | |
ec25ff5e |
103 | LttvAttributeValue value; |
104 | WindowCreationData *Window_Creation_Data = g_new(WindowCreationData, 1); |
105 | |
106 | LttvIAttribute *attributes = LTTV_IATTRIBUTE(lttv_global_attributes()); |
107 | |
558aa013 |
108 | g_critical("GUI init()"); |
109 | |
ec25ff5e |
110 | lttv_option_add("trace", 't', |
111 | "add a trace to the trace set to analyse", |
112 | "pathname of the directory containing the trace", |
113 | LTTV_OPT_STRING, &a_trace, lttv_trace_option, NULL); |
114 | |
115 | traceset = lttv_traceset_new(); |
116 | |
117 | before_traceset = lttv_hooks_new(); |
118 | after_traceset = lttv_hooks_new(); |
119 | before_trace = lttv_hooks_new(); |
120 | after_trace = lttv_hooks_new(); |
121 | before_tracefile = lttv_hooks_new(); |
122 | after_tracefile = lttv_hooks_new(); |
123 | before_event = lttv_hooks_new(); |
124 | after_event = lttv_hooks_new(); |
125 | |
126 | g_assert(lttv_iattribute_find_by_path(attributes, "hooks/traceset/before", |
127 | LTTV_POINTER, &value)); |
128 | *(value.v_pointer) = before_traceset; |
129 | g_assert(lttv_iattribute_find_by_path(attributes, "hooks/traceset/after", |
130 | LTTV_POINTER, &value)); |
131 | *(value.v_pointer) = after_traceset; |
132 | g_assert(lttv_iattribute_find_by_path(attributes, "hooks/trace/before", |
133 | LTTV_POINTER, &value)); |
134 | *(value.v_pointer) = before_trace; |
135 | g_assert(lttv_iattribute_find_by_path(attributes, "hooks/trace/after", |
136 | LTTV_POINTER, &value)); |
137 | *(value.v_pointer) = after_trace; |
138 | g_assert(lttv_iattribute_find_by_path(attributes, "hooks/tracefile/before", |
139 | LTTV_POINTER, &value)); |
140 | *(value.v_pointer) = before_tracefile; |
141 | g_assert(lttv_iattribute_find_by_path(attributes, "hooks/tracefile/after", |
142 | LTTV_POINTER, &value)); |
143 | *(value.v_pointer) = after_tracefile; |
144 | g_assert(lttv_iattribute_find_by_path(attributes, "hooks/event/before", |
145 | LTTV_POINTER, &value)); |
146 | *(value.v_pointer) = before_event; |
147 | g_assert(lttv_iattribute_find_by_path(attributes, "hooks/event/after", |
148 | LTTV_POINTER, &value)); |
149 | *(value.v_pointer) = after_event; |
150 | |
151 | g_assert(lttv_iattribute_find_by_path(attributes, "hooks/main/before", |
152 | LTTV_POINTER, &value)); |
153 | g_assert((main_hooks = *(value.v_pointer)) != NULL); |
154 | |
155 | Window_Creation_Data->argc = argc; |
156 | Window_Creation_Data->argv = argv; |
157 | |
158 | lttv_hooks_add(main_hooks, Window_Creation_Hook, Window_Creation_Data); |
0a6808c0 |
159 | |
fb87279e |
160 | } |
161 | |
162 | void destroy_walk(gpointer data, gpointer user_data) |
163 | { |
164 | //GuiControlFlow_Destructor((ControlFlowData*)data); |
165 | } |
166 | |
167 | |
168 | |
169 | /** |
170 | * plugin's destroy function |
171 | * |
172 | * This function releases the memory reserved by the module and unregisters |
173 | * everything that has been registered in the gtkTraceSet API. |
174 | */ |
175 | G_MODULE_EXPORT void destroy() { |
176 | |
ec25ff5e |
177 | WindowCreationData *Window_Creation_Data; |
178 | LttvAttributeValue value; |
179 | |
180 | guint i, nb; |
181 | |
182 | lttv_option_remove("trace"); |
183 | |
184 | lttv_hooks_destroy(before_traceset); |
185 | lttv_hooks_destroy(after_traceset); |
186 | lttv_hooks_destroy(before_trace); |
187 | lttv_hooks_destroy(after_trace); |
188 | lttv_hooks_destroy(before_tracefile); |
189 | lttv_hooks_destroy(after_tracefile); |
190 | lttv_hooks_destroy(before_event); |
191 | lttv_hooks_destroy(after_event); |
192 | lttv_hooks_remove_data(main_hooks, Window_Creation_Hook, NULL); |
193 | |
194 | nb = lttv_traceset_number(traceset); |
195 | for(i = 0 ; i < nb ; i++) { |
196 | ltt_trace_close(lttv_traceset_get(traceset, i)); |
197 | } |
198 | |
199 | lttv_traceset_destroy(traceset); |
fb87279e |
200 | |
ec25ff5e |
201 | g_critical("GUI destroy()"); |
fb87279e |
202 | |
fb87279e |
203 | |
fb87279e |
204 | |
ec25ff5e |
205 | //ControlFlowData *Control_Flow_Data; |
206 | |
fb87279e |
207 | |
ec25ff5e |
208 | g_slist_foreach(Main_Window_List, destroy_walk, NULL ); |
209 | |
210 | |
211 | //lttv_hooks_remove_data(main_hooks,Window_Creation_Hook, NULL); |
212 | //lttv_hooks_remove_data(before_traceset, get_traceset_context, NULL); |
fb87279e |
213 | |
ec25ff5e |
214 | // g_free(Window_Creation_Data); |
fb87279e |
215 | |
ec25ff5e |
216 | g_object_unref(gTracesetContext); |
fb87279e |
217 | } |
218 | |
219 | |
220 | |
221 | |