From 2f48cae403429be0396f2b7bef0ba6d5d2bdc02f Mon Sep 17 00:00:00 2001 From: Philip Chimento Date: Wed, 24 Dec 2008 06:34:21 +0000 Subject: [PATCH] Implemented "started" and "stopped" signals git-svn-id: http://lassie.dyndns-server.com/svn/gargoyle-gtk@16 ddfedd41-794f-dd11-ae45-00112f111e67 --- src/abort.c | 3 ++- src/chimara-glk-private.h | 3 +++ src/chimara-glk.c | 32 +++++++++++++++++--------------- src/glk.c | 3 ++- src/main.c | 14 ++++++++++++++ 5 files changed, 38 insertions(+), 17 deletions(-) diff --git a/src/abort.c b/src/abort.c index b2d2b67..4580c0f 100644 --- a/src/abort.c +++ b/src/abort.c @@ -38,6 +38,7 @@ abort_glk() { if(glk_data->interrupt_handler) (*(glk_data->interrupt_handler))(); + g_signal_emit_by_name(glk_data->self, "stopped"); g_thread_exit(NULL); } @@ -46,7 +47,7 @@ mutex has already been freed. (That means the thread already ended.) */ void signal_abort() { - if(glk_data->abort_lock) { + if(glk_data && glk_data->abort_lock) { g_mutex_lock(glk_data->abort_lock); glk_data->abort_signalled = TRUE; g_mutex_unlock(glk_data->abort_lock); diff --git a/src/chimara-glk-private.h b/src/chimara-glk-private.h index c6fc556..dea8999 100644 --- a/src/chimara-glk-private.h +++ b/src/chimara-glk-private.h @@ -2,6 +2,7 @@ #define __CHIMARA_GLK_PRIVATE_H__ #include +#include #include "glk.h" #include "chimara-glk.h" @@ -16,6 +17,8 @@ struct _ChimaraGlkPrivate { gboolean interactive; /* Whether file operations are allowed */ gboolean protect; + /* Glk program loaded in widget */ + GModule *program; /* Thread in which Glk program is run */ GThread *thread; /* Event queue and threading stuff */ diff --git a/src/chimara-glk.c b/src/chimara-glk.c index a92377f..4484e81 100644 --- a/src/chimara-glk.c +++ b/src/chimara-glk.c @@ -6,6 +6,7 @@ #include "chimara-glk.h" #include "chimara-glk-private.h" #include "glk.h" +#include "abort.h" #include "window.h" #define CHIMARA_GLK_MIN_WIDTH 0 @@ -40,6 +41,7 @@ chimara_glk_init(ChimaraGlk *self) priv->self = self; priv->interactive = TRUE; priv->protect = FALSE; + priv->program = NULL; priv->thread = NULL; priv->event_queue = NULL; priv->event_lock = NULL; @@ -112,7 +114,7 @@ chimara_glk_finalize(GObject *object) g_mutex_unlock(priv->abort_lock); g_mutex_free(priv->abort_lock); priv->abort_lock = NULL; - + G_OBJECT_CLASS(chimara_glk_parent_class)->finalize(object); } @@ -172,7 +174,11 @@ chimara_glk_forall(GtkContainer *container, gboolean include_internals, static void chimara_glk_stopped(ChimaraGlk *self) { - /* TODO: Add default signal handler implementation here */ + ChimaraGlkPrivate *priv = CHIMARA_GLK_PRIVATE(self); + + /* Free the plugin */ + if( priv->program && !g_module_close(priv->program) ) + g_warning( "Error closing module: %s", g_module_error() ); } static void @@ -285,7 +291,10 @@ chimara_glk_get_protect(ChimaraGlk *glk) static gpointer glk_enter(gpointer glk_main) { + extern ChimaraGlkPrivate *glk_data; + g_signal_emit_by_name(glk_data->self, "started"); ((glk_main_t)glk_main)(); + g_signal_emit_by_name(glk_data->self, "stopped"); return NULL; } @@ -295,24 +304,24 @@ chimara_glk_run(ChimaraGlk *glk, gchar *plugin, GError **error) g_return_val_if_fail(glk || CHIMARA_IS_GLK(glk), FALSE); g_return_val_if_fail(plugin, FALSE); + ChimaraGlkPrivate *priv = CHIMARA_GLK_PRIVATE(glk); + /* Open the module to run */ - GModule *module; glk_main_t glk_main; g_assert( g_module_supported() ); - module = g_module_open(plugin, G_MODULE_BIND_LAZY); + priv->program = g_module_open(plugin, G_MODULE_BIND_LAZY); - if(!module) + if(!priv->program) { g_warning( "Error opening module: %s", g_module_error() ); return FALSE; } - if( !g_module_symbol(module, "glk_main", (gpointer *) &glk_main) ) + if( !g_module_symbol(priv->program, "glk_main", (gpointer *) &glk_main) ) { g_warning( "Error finding glk_main(): %s", g_module_error() ); return FALSE; } - - ChimaraGlkPrivate *priv = CHIMARA_GLK_PRIVATE(glk); + extern ChimaraGlkPrivate *glk_data; /* Set the thread's private data */ /* TODO: Do this with a GPrivate */ @@ -321,13 +330,6 @@ chimara_glk_run(ChimaraGlk *glk, gchar *plugin, GError **error) /* Run in a separate thread */ priv->thread = g_thread_create(glk_enter, glk_main, TRUE, error); - /* Close module */ -/* if( !g_module_close(module) ) - { - g_warning( "Error closing module: %s", g_module_error() ); - return FALSE; - }*/ - return !(priv->thread == NULL); } diff --git a/src/glk.c b/src/glk.c index 47c28cb..97673ac 100644 --- a/src/glk.c +++ b/src/glk.c @@ -27,8 +27,9 @@ ChimaraGlkPrivate *glk_data = NULL; void glk_exit(void) { + g_signal_emit_by_name(glk_data->self, "stopped"); + glk_data = NULL; g_thread_exit(NULL); - glk_data = NULL; } /** diff --git a/src/main.c b/src/main.c index edcb1d5..324e49e 100644 --- a/src/main.c +++ b/src/main.c @@ -49,6 +49,18 @@ GtkBuilder *builder = NULL; GtkWidget *window = NULL; GtkWidget *glk = NULL; +static void +on_started(ChimaraGlk *glk) +{ + g_printerr("Started!\n"); +} + +static void +on_stopped(ChimaraGlk *glk) +{ + g_printerr("Stopped!\n"); +} + static void create_window(void) { @@ -60,6 +72,8 @@ create_window(void) gtk_builder_connect_signals(builder, NULL); glk = chimara_glk_new(); + g_signal_connect(glk, "started", G_CALLBACK(on_started), NULL); + g_signal_connect(glk, "stopped", G_CALLBACK(on_stopped), NULL); GtkBox *vbox = GTK_BOX( gtk_builder_get_object(builder, "vbox") ); if(vbox == NULL) -- 2.30.2