| 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 | |
| 12 | #include <lttv/lttv.h> |
| 13 | #include <lttv/attribute.h> |
| 14 | #include <lttv/hook.h> |
| 15 | #include <lttv/option.h> |
| 16 | #include <lttv/module.h> |
| 17 | #include <lttv/processTrace.h> |
| 18 | #include <lttv/state.h> |
| 19 | #include <lttv/stats.h> |
| 20 | #include <lttv/menu.h> |
| 21 | #include <lttv/toolbar.h> |
| 22 | |
| 23 | #include "interface.h" |
| 24 | #include "support.h" |
| 25 | #include <lttv/mainWindow.h> |
| 26 | #include "callbacks.h" |
| 27 | |
| 28 | /* global variable */ |
| 29 | //LttvTracesetStats * gTracesetContext = NULL; |
| 30 | //static LttvTraceset * traceset; |
| 31 | static WindowCreationData win_creation_data; |
| 32 | |
| 33 | /** Array containing instanced objects. */ |
| 34 | GSList * g_main_window_list = NULL ; |
| 35 | |
| 36 | LttvHooks |
| 37 | *main_hooks; |
| 38 | |
| 39 | /* Initial trace from command line */ |
| 40 | LttvTrace *g_init_trace = NULL; |
| 41 | |
| 42 | static char *a_trace; |
| 43 | |
| 44 | void lttv_trace_option(void *hook_data) |
| 45 | { |
| 46 | LttTrace *trace; |
| 47 | |
| 48 | trace = ltt_trace_open(a_trace); |
| 49 | if(trace == NULL) g_critical("cannot open trace %s", a_trace); |
| 50 | g_init_trace = lttv_trace_new(trace); |
| 51 | } |
| 52 | |
| 53 | /***************************************************************************** |
| 54 | * Functions for module loading/unloading * |
| 55 | *****************************************************************************/ |
| 56 | /** |
| 57 | * plugin's init function |
| 58 | * |
| 59 | * This function initializes the GUI. |
| 60 | */ |
| 61 | |
| 62 | static gboolean window_creation_hook(void *hook_data, void *call_data) |
| 63 | { |
| 64 | WindowCreationData* window_creation_data = (WindowCreationData*)hook_data; |
| 65 | |
| 66 | g_critical("GUI window_creation_hook()"); |
| 67 | #ifdef ENABLE_NLS |
| 68 | bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR); |
| 69 | bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); |
| 70 | textdomain (GETTEXT_PACKAGE); |
| 71 | #endif |
| 72 | |
| 73 | gtk_set_locale (); |
| 74 | gtk_init (&(window_creation_data->argc), &(window_creation_data->argv)); |
| 75 | |
| 76 | add_pixmap_directory (PACKAGE_DATA_DIR "/" PACKAGE "/pixmaps"); |
| 77 | add_pixmap_directory ("pixmaps"); |
| 78 | add_pixmap_directory ("modules/gui/mainWin/pixmaps"); |
| 79 | |
| 80 | construct_main_window(NULL, window_creation_data, TRUE); |
| 81 | |
| 82 | gtk_main (); |
| 83 | |
| 84 | return FALSE; |
| 85 | } |
| 86 | |
| 87 | G_MODULE_EXPORT void init(LttvModule *self, int argc, char *argv[]) { |
| 88 | |
| 89 | LttvAttributeValue value; |
| 90 | |
| 91 | // Global attributes only used for interaction with main() here. |
| 92 | LttvIAttribute *attributes = LTTV_IATTRIBUTE(lttv_global_attributes()); |
| 93 | |
| 94 | g_critical("GUI init()"); |
| 95 | |
| 96 | lttv_option_add("trace", 't', |
| 97 | "add a trace to the trace set to analyse", |
| 98 | "pathname of the directory containing the trace", |
| 99 | LTTV_OPT_STRING, &a_trace, lttv_trace_option, NULL); |
| 100 | |
| 101 | g_assert(lttv_iattribute_find_by_path(attributes, "hooks/main/before", |
| 102 | LTTV_POINTER, &value)); |
| 103 | g_assert((main_hooks = *(value.v_pointer)) != NULL); |
| 104 | |
| 105 | win_creation_data.argc = argc; |
| 106 | win_creation_data.argv = argv; |
| 107 | |
| 108 | lttv_hooks_add(main_hooks, window_creation_hook, &win_creation_data); |
| 109 | |
| 110 | } |
| 111 | |
| 112 | void |
| 113 | main_window_free(mainWindow * mw) |
| 114 | { |
| 115 | guint i, nb, ref_count; |
| 116 | LttvTrace * trace; |
| 117 | |
| 118 | if(mw){ |
| 119 | |
| 120 | g_critical("begin remove"); |
| 121 | lttv_hooks_destroy(mw->Traceset_Info->before_traceset); |
| 122 | lttv_hooks_destroy(mw->Traceset_Info->after_traceset); |
| 123 | lttv_hooks_destroy(mw->Traceset_Info->before_trace); |
| 124 | lttv_hooks_destroy(mw->Traceset_Info->after_trace); |
| 125 | lttv_hooks_destroy(mw->Traceset_Info->before_tracefile); |
| 126 | lttv_hooks_destroy(mw->Traceset_Info->after_tracefile); |
| 127 | lttv_hooks_destroy(mw->Traceset_Info->before_event); |
| 128 | lttv_hooks_destroy(mw->Traceset_Info->after_event); |
| 129 | g_critical("end remove"); |
| 130 | |
| 131 | if(mw->Traceset_Info->path != NULL) |
| 132 | g_free(mw->Traceset_Info->path); |
| 133 | if(mw->Traceset_Info->TracesetContext != NULL){ |
| 134 | lttv_context_fini(LTTV_TRACESET_CONTEXT(mw->Traceset_Info->TracesetContext)); |
| 135 | g_object_unref(mw->Traceset_Info->TracesetContext); |
| 136 | } |
| 137 | if(mw->Traceset_Info->traceset != NULL) { |
| 138 | nb = lttv_traceset_number(mw->Traceset_Info->traceset); |
| 139 | for(i = 0 ; i < nb ; i++) { |
| 140 | trace = lttv_traceset_get(mw->Traceset_Info->traceset, i); |
| 141 | ref_count = lttv_trace_get_ref_number(trace); |
| 142 | if(ref_count <= 1) |
| 143 | ltt_trace_close(lttv_trace(trace)); |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | lttv_traceset_destroy(mw->Traceset_Info->traceset); |
| 148 | |
| 149 | g_object_unref(mw->Attributes); |
| 150 | |
| 151 | g_free(mw->Traceset_Info); |
| 152 | mw->Traceset_Info = NULL; |
| 153 | |
| 154 | g_main_window_list = g_slist_remove(g_main_window_list, mw); |
| 155 | |
| 156 | g_hash_table_destroy(mw->hash_menu_item); |
| 157 | g_hash_table_destroy(mw->hash_toolbar_item); |
| 158 | |
| 159 | g_free(mw); |
| 160 | mw = NULL; |
| 161 | } |
| 162 | } |
| 163 | |
| 164 | void |
| 165 | main_window_destructor(mainWindow * mw) |
| 166 | { |
| 167 | if(GTK_IS_WIDGET(mw->MWindow)){ |
| 168 | gtk_widget_destroy(mw->MWindow); |
| 169 | // gtk_widget_destroy(mw->HelpContents); |
| 170 | // gtk_widget_destroy(mw->AboutBox); |
| 171 | mw = NULL; |
| 172 | } |
| 173 | //main_window_free called when the object mw in the widget is unref. |
| 174 | //main_window_free(mw); |
| 175 | } |
| 176 | |
| 177 | |
| 178 | void main_window_destroy_walk(gpointer data, gpointer user_data) |
| 179 | { |
| 180 | main_window_destructor((mainWindow*)data); |
| 181 | } |
| 182 | |
| 183 | |
| 184 | |
| 185 | /** |
| 186 | * plugin's destroy function |
| 187 | * |
| 188 | * This function releases the memory reserved by the module and unregisters |
| 189 | * everything that has been registered in the gtkTraceSet API. |
| 190 | */ |
| 191 | G_MODULE_EXPORT void destroy() { |
| 192 | |
| 193 | LttvAttributeValue value; |
| 194 | LttvTrace *trace; |
| 195 | |
| 196 | lttv_option_remove("trace"); |
| 197 | |
| 198 | lttv_hooks_remove_data(main_hooks, window_creation_hook, &win_creation_data); |
| 199 | |
| 200 | g_critical("GUI destroy()"); |
| 201 | |
| 202 | if(g_main_window_list){ |
| 203 | g_slist_foreach(g_main_window_list, main_window_destroy_walk, NULL ); |
| 204 | g_slist_free(g_main_window_list); |
| 205 | } |
| 206 | |
| 207 | } |
| 208 | |
| 209 | |
| 210 | |
| 211 | |