b3c98ecbdc1ee9724daed6849b2bee1ad1f46136
[rodin/chimara.git] / libchimara / resource.c
1 #include "resource.h"
2
3 extern GPrivate *glk_data_key;
4
5 /**
6  * giblorb_set_resource_map:
7  * @file: The file stream to read the resource map from
8  *
9  * This function tells the library that the file is indeed the Blorby source
10  * of all resource goodness. Whenever your program calls an image or sound
11  * function, such as glk_image_draw(), the library will search this file for
12  * the resource you request. 
13  *
14  * Do <emphasis>not</emphasis> close the stream after calling this function. 
15  * The library is responsible for closing the stream at shutdown time.
16  *
17  * Returns: a Blorb error code.
18  */
19 giblorb_err_t
20 giblorb_set_resource_map(strid_t file)
21 {
22         ChimaraGlkPrivate *glk_data = g_private_get(glk_data_key);
23         giblorb_map_t *newmap; /* create map allocates memory */
24         giblorb_err_t error = giblorb_create_map(file, &newmap);
25
26         if(error != giblorb_err_None) {
27                 g_free(newmap);
28                 return error;
29         }
30
31         /* Check if there was already an existing resource map */
32         if(glk_data->resource_map != NULL) {
33                 WARNING("Overwriting existing resource map.\n");
34                 giblorb_destroy_map(glk_data->resource_map);
35                 glk_stream_close(glk_data->resource_file, NULL);
36         }
37
38         glk_data->resource_map = newmap;
39         glk_data->resource_file = file;
40         return giblorb_err_None;
41 }
42
43 /**
44  * giblorb_get_resource_map:
45  * 
46  * This function returns the current resource map being used. Returns %NULL
47  * if giblorb_set_resource_map() has not been called yet.
48  *
49  * Returns: a resource map, or %NULL.
50  */
51 giblorb_map_t*
52 giblorb_get_resource_map()
53 {
54         ChimaraGlkPrivate *glk_data = g_private_get(glk_data_key);
55         
56         if(glk_data->resource_map == NULL) {
57                 WARNING("Resource map not set yet.\n");
58         }
59
60         return glk_data->resource_map;
61 }