* Implemented the library-dependant functionality of BLORBs
authorMarijn van Vliet <marijn.vanvliet@med.kuleuven.be>
Fri, 22 May 2009 13:08:23 +0000 (13:08 +0000)
committerMarijn van Vliet <marijn.vanvliet@med.kuleuven.be>
Fri, 22 May 2009 13:08:23 +0000 (13:08 +0000)
git-svn-id: http://lassie.dyndns-server.com/svn/gargoyle-gtk@70 ddfedd41-794f-dd11-ae45-00112f111e67

src/Makefile.am
src/chimara-glk-private.h
src/glk.c
src/resource.c [new file with mode: 0644]
src/resource.h [new file with mode: 0644]

index 894db95dd66fa89aba11459c3524698dd1371d9a..6da19f9bb441b45725ece12d436013a88bbc60d9 100644 (file)
@@ -32,7 +32,8 @@ libchimara_la_SOURCES = \
        style.c \
        timer.c timer.h \
        window.c window.h \
-       gi_blorb.c gi_blorb.h
+       gi_blorb.c gi_blorb.h \
+       resource.c resource.h
 libchimara_la_CPPFLAGS = \
        -DG_LOG_DOMAIN=\"Chimara\"
 libchimara_la_CFLAGS = @CHIMARA_CFLAGS@ $(AM_CFLAGS)
index 35fac923f73086a5d83923676b75480a1950c00c..9520f1b909fcf0e08e8ec21e06b9a67fd0ab449c 100644 (file)
@@ -5,6 +5,7 @@
 #include <gmodule.h>
 #include <pango/pango.h>
 #include "glk.h"
+#include "gi_blorb.h"
 #include "chimara-glk.h"
 
 G_BEGIN_DECLS
@@ -48,6 +49,10 @@ struct _ChimaraGlkPrivate {
     GList *stream_list;
        /* Current timer */
        guint timer_id;
+       /* Current resource blorb map */
+       giblorb_map_t *resource_map;
+       /* File stream pointing to the blorb used as current resource map */
+       strid_t *resource_file;
 };
 
 #define CHIMARA_GLK_PRIVATE(obj) \
index 1c29ebbe2ad8d7da26f72dc2b3365382aea7c07a..c4f395441de42e7331bdc3cb3bf4be1bc9236ee7 100644 (file)
--- a/src/glk.c
+++ b/src/glk.c
@@ -4,6 +4,7 @@
 #include "abort.h"
 #include "chimara-glk.h"
 #include "chimara-glk-private.h"
+#include "gi_blorb.h"
 
 ChimaraGlkPrivate *glk_data = NULL;
 
@@ -46,6 +47,12 @@ glk_exit(void)
        /* Stop any timers */
        glk_request_timer_events(0);
 
+       /* Close any open resource files */
+       if(glk_data->resource_map != NULL) {
+               giblorb_destroy_map(glk_data->resource_map);
+               glk_stream_close(glk_data->resource_file, NULL);
+       }
+
     glk_data = NULL;
        g_thread_exit(NULL);
 }
diff --git a/src/resource.c b/src/resource.c
new file mode 100644 (file)
index 0000000..c6b4d34
--- /dev/null
@@ -0,0 +1,54 @@
+#include "resource.h"
+
+extern ChimaraGlkPrivate *glk_data;
+
+/**
+ * giblorb_set_resource_map:
+ * @file The file stream to read the resource map from
+ *
+ * This function tells the library that the file is indeed the Blorby source
+ * of all resource goodness. Whenever your program calls an image or sound
+ * function, such as glk_image_draw(), the library will search this file for
+ * the resource you request. 
+ *
+ * Do not close the stream after calling this function. The library is
+ * responsible for closing the stream at shutdown time.
+ */
+giblorb_err_t
+giblorb_set_resource_map(strid_t file)
+{
+       giblorb_map_t *newmap; /* create map allocates memory */
+       giblorb_err_t error = giblorb_create_map(file, &newmap);
+
+       if(error != giblorb_err_None) {
+               g_free(newmap);
+               return error;
+       }
+
+       /* Check if there was already an existing resource map */
+       if(glk_data->resource_map != NULL) {
+               WARNING("Overwriting existing resource map.\n");
+               giblorb_destroy_map(glk_data->resource_map);
+               glk_stream_close(glk_data->resource_file, NULL);
+       }
+
+       glk_data->resource_map = newmap;
+       glk_data->resource_file = file;
+       return giblorb_err_None;
+}
+
+/**
+ * giblorb_get_resource_map:
+ * 
+ * This function returns the current resource map being used. Returns NULL
+ * if #giblorb_set_resource_map() has not been called yet.
+ */
+giblorb_map_t*
+giblorb_get_resource_map()
+{
+       if(glk_data->resource_map == NULL) {
+               WARNING("Resource map not set yet.\n");
+       }
+
+       return glk_data->resource_map;
+}
diff --git a/src/resource.h b/src/resource.h
new file mode 100644 (file)
index 0000000..7db741e
--- /dev/null
@@ -0,0 +1,10 @@
+#ifndef RESOURCE_H
+#define RESOURCE_H
+
+#include <glib.h>
+#include "glk.h"
+#include "gi_blorb.h"
+#include "chimara-glk-private.h"
+#include "magic.h"
+
+#endif