Separated library source code from testing code, fixing #6
[projects/chimara/chimara.git] / libchimara / resource.c
1 #include "resource.h"
2
3 extern ChimaraGlkPrivate *glk_data;
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 not close the stream after calling this function. The library is
15  * responsible for closing the stream at shutdown time.
16  */
17 giblorb_err_t
18 giblorb_set_resource_map(strid_t file)
19 {
20         giblorb_map_t *newmap; /* create map allocates memory */
21         giblorb_err_t error = giblorb_create_map(file, &newmap);
22
23         if(error != giblorb_err_None) {
24                 g_free(newmap);
25                 return error;
26         }
27
28         /* Check if there was already an existing resource map */
29         if(glk_data->resource_map != NULL) {
30                 WARNING("Overwriting existing resource map.\n");
31                 giblorb_destroy_map(glk_data->resource_map);
32                 glk_stream_close(glk_data->resource_file, NULL);
33         }
34
35         glk_data->resource_map = newmap;
36         glk_data->resource_file = file;
37         return giblorb_err_None;
38 }
39
40 /**
41  * giblorb_get_resource_map:
42  * 
43  * This function returns the current resource map being used. Returns NULL
44  * if #giblorb_set_resource_map() has not been called yet.
45  */
46 giblorb_map_t*
47 giblorb_get_resource_map()
48 {
49         if(glk_data->resource_map == NULL) {
50                 WARNING("Resource map not set yet.\n");
51         }
52
53         return glk_data->resource_map;
54 }