diff options
author | Akira TAGOH <akira@tagoh.org> | 2006-06-05 13:07:13 +0000 |
---|---|---|
committer | Akira TAGOH <akira@tagoh.org> | 2006-06-05 13:07:13 +0000 |
commit | ea05fdcfb28aaa618771d66fb746004108766c3a (patch) | |
tree | 9aaf45f3cef7affb0a9e351ec940d3503fcca446 /src | |
parent | e55ac06929f7b500fb8d90b21b5964939d8de8da (diff) |
* src/visualizer.c (hg_memory_visualizer_real_destroy): remove idle
timer.
(hg_memory_visualizer_real_size_allocate): implemented a bit.
(hg_memory_visualizer_real_unrealize): remove idle timer.
(hg_memory_visualizer_real_map): add idle timer.
(hg_memory_visualizer_real_unmap): remove idle timer.
(hg_memory_visualizer_class_init): add a signal, pool-updated.
(_hg_memory_visualizer_idle_handler_cb): new function.
(_hg_memory_visualizer_add_idle): new function.
(_hg_memory_visualizer_remove_idle): new function.
(hg_memory_visualizer_set_heap_state): set current pool and info.
(hg_memory_visualizer_set_chunk_state): set a flag to be updated.
(hg_memory_visualizer_change_pool): new function.
* src/hgspy.c (_hgspy_radio_menu_pool_activate_cb): new function.
(_hgspy_pool_updated_cb): new function.
Diffstat (limited to 'src')
-rw-r--r-- | src/hgspy.c | 82 | ||||
-rw-r--r-- | src/visualizer.c | 184 | ||||
-rw-r--r-- | src/visualizer.h | 2 |
3 files changed, 220 insertions, 48 deletions
diff --git a/src/hgspy.c b/src/hgspy.c index 0f2887e..43360c0 100644 --- a/src/hgspy.c +++ b/src/hgspy.c @@ -34,11 +34,12 @@ typedef struct _HieroGlyphSpy HgSpy; struct _HieroGlyphSpy { - GtkWidget *window; - GtkWidget *visualizer; - GThread *vm_thread; - LibrettoVM *vm; - gchar *file; + GtkWidget *window; + GtkWidget *visualizer; + GtkUIManager *ui; + GThread *vm_thread; + LibrettoVM *vm; + gchar *file; }; static gpointer __hg_spy_helper_get_widget = NULL; @@ -170,6 +171,61 @@ _hgspy_action_menubar_about_cb(GtkAction *action, NULL); } +static void +_hgspy_radio_menu_pool_activate_cb(GtkMenuItem *menuitem, + gpointer data) +{ + const gchar *name; + HgSpy *spy = data; + + if (gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM (menuitem))) { + name = g_object_get_data(G_OBJECT (menuitem), "user-data"); + hg_memory_visualizer_change_pool(HG_MEMORY_VISUALIZER (spy->visualizer), name); + } +} + +static void +_hgspy_pool_updated_cb(HgMemoryVisualizer *visual, + gpointer list, + gpointer data) +{ + GSList *slist = list, *l, *sigwidget = NULL; + HgSpy *spy = data; + GtkWidget *bin, *menu, *menuitem = NULL; + gulong sigid; + + g_return_if_fail (HG_IS_MEMORY_VISUALIZER (visual)); + g_return_if_fail (list != NULL); + + bin = gtk_ui_manager_get_widget(spy->ui, "/MenuBar/ViewMenu/PoolMenu"); + menu = gtk_menu_item_get_submenu(GTK_MENU_ITEM (bin)); + sigwidget = (GSList *)g_object_get_data(G_OBJECT (menu), "signal-widget-list"); + for (l = sigwidget; l != NULL; l = g_slist_next(l)) { + sigid = (gulong)g_object_get_data(G_OBJECT (l->data), "signal-id"); + if (sigid > 0) + g_signal_handler_disconnect(l->data, sigid); + } + gtk_menu_item_remove_submenu(GTK_MENU_ITEM (bin)); + menu = gtk_menu_new(); + sigwidget = NULL; + for (l = slist; l != NULL; l = g_slist_next(l)) { + if (menuitem == NULL) { + menuitem = gtk_radio_menu_item_new_with_label(NULL, l->data); + } else { + menuitem = gtk_radio_menu_item_new_with_label_from_widget(GTK_RADIO_MENU_ITEM (menuitem), l->data); + } + sigid = g_signal_connect(menuitem, "activate", + G_CALLBACK (_hgspy_radio_menu_pool_activate_cb), spy); + sigwidget = g_slist_append(sigwidget, menuitem); + g_object_set_data(G_OBJECT (menuitem), "signal-id", (gpointer)sigid); + g_object_set_data(G_OBJECT (menuitem), "user-data", l->data); + gtk_menu_shell_append(GTK_MENU_SHELL (menu), menuitem); + gtk_widget_show(menuitem); + } + g_object_set_data(G_OBJECT (menu), "signal-widget-list", sigwidget); + gtk_menu_item_set_submenu(GTK_MENU_ITEM (bin), menu); +} + /* * Public Functions */ @@ -180,7 +236,6 @@ main(int argc, GModule *module; HgSpy *spy; GtkWidget *menubar, *vbox, *none; - GtkUIManager *uiman; GtkActionGroup *actions; GtkActionEntry action_entries[] = { /* toplevel menu */ @@ -306,7 +361,7 @@ main(int argc, spy->window = gtk_window_new(GTK_WINDOW_TOPLEVEL); spy->vm_thread = NULL; actions = gtk_action_group_new("MenuBar"); - uiman = gtk_ui_manager_new(); + spy->ui = gtk_ui_manager_new(); vbox = gtk_vbox_new(FALSE, 0); spy->visualizer = ((GtkWidget * (*) (void))__hg_spy_helper_get_widget) (); @@ -322,22 +377,25 @@ main(int argc, spy); /* setup UI */ + gtk_window_set_default_size(GTK_WINDOW (spy->window), 100, 100); gtk_window_set_title(GTK_WINDOW (spy->window), "Memory Visualizer for Hieroglyph"); - gtk_ui_manager_add_ui_from_string(uiman, uixml, strlen(uixml), NULL); - gtk_ui_manager_insert_action_group(uiman, actions, 0); - none = gtk_ui_manager_get_widget(uiman, "/MenuBar/ViewMenu/PoolMenu/PoolNone"); + gtk_ui_manager_add_ui_from_string(spy->ui, uixml, strlen(uixml), NULL); + gtk_ui_manager_insert_action_group(spy->ui, actions, 0); + none = gtk_ui_manager_get_widget(spy->ui, "/MenuBar/ViewMenu/PoolMenu/PoolNone"); gtk_widget_set_sensitive(none, FALSE); /* setup accelerators */ - gtk_window_add_accel_group(GTK_WINDOW (spy->window), gtk_ui_manager_get_accel_group(uiman)); + gtk_window_add_accel_group(GTK_WINDOW (spy->window), gtk_ui_manager_get_accel_group(spy->ui)); /* widget connections */ - menubar = gtk_ui_manager_get_widget(uiman, "/MenuBar"); + menubar = gtk_ui_manager_get_widget(spy->ui, "/MenuBar"); gtk_box_pack_start(GTK_BOX (vbox), menubar, FALSE, TRUE, 0); gtk_box_pack_start(GTK_BOX (vbox), spy->visualizer, TRUE, TRUE, 0); gtk_container_add(GTK_CONTAINER (spy->window), vbox); /* setup signals */ + g_signal_connect(spy->visualizer, "pool-updated", + G_CALLBACK (_hgspy_pool_updated_cb), spy); g_signal_connect(spy->window, "delete-event", G_CALLBACK (gtk_main_quit), NULL); diff --git a/src/visualizer.c b/src/visualizer.c index 4386242..1a80895 100644 --- a/src/visualizer.c +++ b/src/visualizer.c @@ -37,20 +37,15 @@ enum { }; enum { + POOL_UPDATED, LAST_SIGNAL }; struct _HgMemoryVisualizerClass { GtkLayoutClass parent_class; -}; - -struct _HgMemoryVisualizer { - GtkLayout parent_instance; - /*< private >*/ - gdouble block_size; - GHashTable *pool2size; - GHashTable *pool2array; + void (* pool_updated) (HgMemoryVisualizer *visual, + gpointer list); }; struct Heap2Offset { @@ -60,13 +55,31 @@ struct Heap2Offset { gsize total_size; }; +struct _HgMemoryVisualizer { + GtkLayout parent_instance; + + /*< private >*/ + gdouble block_size; + GHashTable *pool2size; + GHashTable *pool2array; + GSList *pool_name_list; + const gchar *current_pool_name; + struct Heap2Offset *current_h2o; + gboolean need_update; + guint idle_id; +}; + -static struct Heap2Offset *_heap2offset_new (guint prealloc); -static void _heap2offset_free(gpointer data); +static struct Heap2Offset *_heap2offset_new (guint prealloc); +static void _heap2offset_free (gpointer data); +static void _hg_memory_visualizer_add_idle (HgMemoryVisualizer *visual); +static void _hg_memory_visualizer_remove_idle(HgMemoryVisualizer *visual); static GtkLayoutClass *parent_class = NULL; -//static guint signals[LAST_SIGNAL] = { 0 }; +static guint signals[LAST_SIGNAL] = { 0 }; + +G_LOCK_DEFINE_STATIC (visualizer); /* @@ -125,6 +138,7 @@ hg_memory_visualizer_real_destroy(GtkObject *object) g_hash_table_destroy(visual->pool2array); visual->pool2array = NULL; } + _hg_memory_visualizer_remove_idle(visual); /* FIXME: not yet implemented */ @@ -132,23 +146,37 @@ hg_memory_visualizer_real_destroy(GtkObject *object) } /* GtkWidget */ -static gboolean -hg_memory_visualizer_real_expose(GtkWidget *widget, - GdkEventExpose *event) +#if 0 +static void +hg_memory_visualizer_real_size_request(GtkWidget *widget, + GtkRequisition *requisition) +{ +} +#endif + +static void +hg_memory_visualizer_real_size_allocate(GtkWidget *widget, + GtkAllocation *allocation) { HgMemoryVisualizer *visual; - g_return_val_if_fail (HG_IS_MEMORY_VISUALIZER (widget), FALSE); - g_return_val_if_fail (event != NULL, FALSE); + g_return_if_fail (HG_IS_MEMORY_VISUALIZER (widget)); + g_return_if_fail (allocation != NULL); + + if (GTK_WIDGET_CLASS (parent_class)->size_allocate) + (* GTK_WIDGET_CLASS (parent_class)->size_allocate) (widget, allocation); visual = HG_MEMORY_VISUALIZER (widget); - if (!GTK_WIDGET_DRAWABLE (widget) || (event->window != visual->parent_instance.bin_window)) - return FALSE; + visual->parent_instance.hadjustment->page_size = allocation->width; + visual->parent_instance.hadjustment->page_increment = allocation->width / 2; + visual->parent_instance.vadjustment->page_size = allocation->height; + visual->parent_instance.vadjustment->page_increment = allocation->height / 2; - /* FIXME: not yet implemented */ + /* FIXME: scroll */ - return FALSE; + g_signal_emit_by_name(visual->parent_instance.hadjustment, "changed"); + g_signal_emit_by_name(visual->parent_instance.vadjustment, "changed"); } static void @@ -167,6 +195,7 @@ hg_memory_visualizer_real_realize(GtkWidget *widget) (gdk_window_get_events(visual->parent_instance.bin_window) | GDK_EXPOSURE_MASK)); + g_print("realize\n"); /* FIXME: not yet implemented */ } @@ -180,6 +209,8 @@ hg_memory_visualizer_real_unrealize(GtkWidget *widget) visual = HG_MEMORY_VISUALIZER (widget); + _hg_memory_visualizer_remove_idle(visual); + g_print("unrealize\n"); /* FIXME: not yet implemented */ if (GTK_WIDGET_CLASS (parent_class)->unrealize) @@ -198,6 +229,10 @@ hg_memory_visualizer_real_map(GtkWidget *widget) visual = HG_MEMORY_VISUALIZER (widget); + if (visual->need_update) + _hg_memory_visualizer_add_idle(visual); + + g_print("map\n"); /* FIXME: not yet implemented */ } @@ -211,34 +246,32 @@ hg_memory_visualizer_real_unmap(GtkWidget *widget) visual = HG_MEMORY_VISUALIZER (widget); + _hg_memory_visualizer_remove_idle(visual); + g_print("unmap\n"); /* FIXME: not yet implemented */ if (GTK_WIDGET_CLASS (parent_class)->unmap) (* GTK_WIDGET_CLASS (parent_class)->unmap) (widget); } -static void -hg_memory_visualizer_real_size_request(GtkWidget *widget, - GtkRequisition *requisition) -{ -} - -static void -hg_memory_visualizer_real_size_allocate(GtkWidget *widget, - GtkAllocation *allocation) +static gboolean +hg_memory_visualizer_real_expose(GtkWidget *widget, + GdkEventExpose *event) { HgMemoryVisualizer *visual; - g_return_if_fail (HG_IS_MEMORY_VISUALIZER (widget)); - g_return_if_fail (allocation != NULL); - - if (GTK_WIDGET_CLASS (parent_class)->size_allocate) - (* GTK_WIDGET_CLASS (parent_class)->size_allocate) (widget, allocation); + g_return_val_if_fail (HG_IS_MEMORY_VISUALIZER (widget), FALSE); + g_return_val_if_fail (event != NULL, FALSE); visual = HG_MEMORY_VISUALIZER (widget); + if (!GTK_WIDGET_DRAWABLE (widget) || (event->window != visual->parent_instance.bin_window)) + return FALSE; + + g_print("expose\n"); /* FIXME: not yet implemented */ + return FALSE; } /* @@ -266,7 +299,7 @@ hg_memory_visualizer_class_init(HgMemoryVisualizerClass *klass) widget_class->unrealize = hg_memory_visualizer_real_unrealize; widget_class->map = hg_memory_visualizer_real_map; widget_class->unmap = hg_memory_visualizer_real_unmap; - widget_class->size_request = hg_memory_visualizer_real_size_request; +// widget_class->size_request = hg_memory_visualizer_real_size_request; widget_class->size_allocate = hg_memory_visualizer_real_size_allocate; /* initialize HgMemoryVisualizer */ @@ -283,6 +316,14 @@ hg_memory_visualizer_class_init(HgMemoryVisualizerClass *klass) G_PARAM_READWRITE)); /* signals */ + signals[POOL_UPDATED] = g_signal_new("pool-updated", + G_OBJECT_CLASS_TYPE (klass), + G_SIGNAL_RUN_FIRST, + G_STRUCT_OFFSET (HgMemoryVisualizerClass, pool_updated), + NULL, NULL, + gtk_marshal_VOID__POINTER, + G_TYPE_NONE, 1, + G_TYPE_POINTER); } static void @@ -291,6 +332,11 @@ hg_memory_visualizer_instance_init(HgMemoryVisualizer *visual) visual->block_size = 0.0L; visual->pool2size = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL); visual->pool2array = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, _heap2offset_free); + visual->pool_name_list = NULL; + visual->current_pool_name = NULL; + visual->current_h2o = NULL; + visual->need_update = FALSE; + visual->idle_id = 0; } static struct Heap2Offset * @@ -323,6 +369,42 @@ _heap2offset_free(gpointer data) g_free(data); } +static gboolean +_hg_memory_visualizer_idle_handler_cb(gpointer data) +{ + HgMemoryVisualizer *visual; + + G_LOCK (visualizer); + + visual = HG_MEMORY_VISUALIZER (data); + gtk_widget_queue_draw(GTK_WIDGET (visual)); + visual->idle_id = 0; + visual->need_update = FALSE; + + G_UNLOCK (visualizer); + + return FALSE; +} + +static void +_hg_memory_visualizer_add_idle(HgMemoryVisualizer *visual) +{ + g_return_if_fail (visual->need_update); + + if (!visual->idle_id) { + visual->idle_id = gtk_idle_add(_hg_memory_visualizer_idle_handler_cb, visual); + } +} + +static void +_hg_memory_visualizer_remove_idle(HgMemoryVisualizer *visual) +{ + if (visual->idle_id != 0) { + gtk_idle_remove(visual->idle_id); + visual->idle_id = 0; + } +} + /* * Public Functions */ @@ -438,6 +520,13 @@ hg_memory_visualizer_set_heap_state(HgMemoryVisualizer *visual, } h2o->heap2offset[heap->serial] = current_size; hg_memory_visualizer_set_max_size(visual, name, current_size + heap->total_heap_size); + visual->pool_name_list = g_slist_append(visual->pool_name_list, + g_strdup(name)); + if (visual->current_pool_name == NULL) { + visual->current_pool_name = name; + visual->current_h2o = h2o; + } + g_signal_emit(visual, signals[POOL_UPDATED], 0, visual->pool_name_list); } void @@ -477,5 +566,28 @@ hg_memory_visualizer_set_chunk_state(HgMemoryVisualizer *visual, break; } } - /* FIXME: update window */ + G_LOCK (visualizer); + visual->need_update = TRUE; + _hg_memory_visualizer_add_idle(visual); + G_UNLOCK (visualizer); +} + +void +hg_memory_visualizer_change_pool(HgMemoryVisualizer *visual, + const gchar *name) +{ + g_return_if_fail (HG_IS_MEMORY_VISUALIZER (visual)); + g_return_if_fail (name != NULL); + + if (g_slist_find(visual->pool_name_list, name) != NULL) { + visual->current_pool_name = name; + visual->current_h2o = g_hash_table_lookup(visual->pool2array, name); + G_LOCK (visualizer); + visual->need_update = TRUE; + _hg_memory_visualizer_add_idle(visual); + G_UNLOCK (visualizer); + } else { + /* send a signal to update the out of date list */ + g_signal_emit(visual, signals[POOL_UPDATED], 0, visual->pool_name_list); + } } diff --git a/src/visualizer.h b/src/visualizer.h index 912238e..1798f4c 100644 --- a/src/visualizer.h +++ b/src/visualizer.h @@ -62,6 +62,8 @@ void hg_memory_visualizer_set_chunk_state(HgMemoryVisualizer *visual, gsize offset, gsize size, HgMemoryChunkState state); +void hg_memory_visualizer_change_pool (HgMemoryVisualizer *visual, + const gchar *name); G_END_DECLS |