libresman
view src/resman.h @ 0:61d7ff6da54b
initial commit: figuring out the API
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Wed, 29 Jan 2014 08:17:31 +0200 |
parents | |
children | 469ce01809bc |
line source
1 #ifndef RESOURCE_MANAGER_H_
2 #define RESOURCE_MANAGER_H_
4 /* TODO API */
6 /* usage example:
7 int texload(const char *fname, void *cls)
8 {
9 // open image, parse data ...
10 }
12 struct resman rman;
14 resman_init(&rman);
15 resman_set_load_func(&rman, texload, 0);
16 resman_set_done_func(&rman, texload_done, 0);
17 ...
19 struct texture *tex;
20 struct resman_job *rjob;
22 rjob = resman_get(&rman, "tex.png", 0);
23 ...
24 resman_wait_job(&rman, rjob);
25 tex = resman_get_job_data(rjob);
26 resman_free_job(&rman, rjob);
28 ...
29 resman_destroy(&rman);
30 */
32 struct resman;
34 typedef int (*resman_load_func_t)(const char *fname, void *cls);
35 typedef void (*resman_done_func_t)(int status, void *cls);
38 int resman_init(struct resman *rman);
39 void resman_destroy(struct resman *rman);
41 /* The load callback will be called to load a data file. It may be called in the
42 * context of a different loading thread.
43 */
44 void resman_set_load_func(struct resman *rman, resman_load_func_t func, void *cls);
46 /* The "done" callback will be called in the context of the main thread, whenever a
47 * file was sucessfully loaded, or an error occured.
48 * It's first argument (status) is set to whatever the load function returned, and its
49 * closure pointer is the closure
50 */
51 void resman_set_done_func(struct resman *rman, resman_done_func_t func);
53 #endif /* RESOURCE_MANAGER_H_ */