Implemented "started" and "stopped" signals
authorPhilip Chimento <philip.chimento@gmail.com>
Wed, 24 Dec 2008 06:34:21 +0000 (06:34 +0000)
committerPhilip Chimento <philip.chimento@gmail.com>
Wed, 24 Dec 2008 06:34:21 +0000 (06:34 +0000)
git-svn-id: http://lassie.dyndns-server.com/svn/gargoyle-gtk@16 ddfedd41-794f-dd11-ae45-00112f111e67

src/abort.c
src/chimara-glk-private.h
src/chimara-glk.c
src/glk.c
src/main.c

index b2d2b67ab2122e3d840de23c425199352fe96401..4580c0f6ad82d8ce6b7037046bccdefef857c26a 100644 (file)
@@ -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);
index c6fc556495ebe1879f0c7a9799b7c22a58cd7b12..dea8999a211fb1029ff66a8e5e5f0290299a0d3d 100644 (file)
@@ -2,6 +2,7 @@
 #define __CHIMARA_GLK_PRIVATE_H__
 
 #include <glib.h>
+#include <gmodule.h>
 #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 */
index a92377f3925f67c679e148ef604deea2402e698b..4484e81f87092b915f0e68cd1db4c402b70210e6 100644 (file)
@@ -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);
 }
 
index 47c28cb521a89b9a003922c00527b4e948873a07..97673ac4ca11e13bb6d2450f193affbd8a544850 100644 (file)
--- 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;
 }
 
 /**
index edcb1d54be1a92cb4c55b48d2e15cbbda2983567..324e49e1a2201bf692e15ca617402c096a250843 100644 (file)
@@ -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)