libresman

diff 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 diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/resman.h	Wed Jan 29 08:17:31 2014 +0200
     1.3 @@ -0,0 +1,53 @@
     1.4 +#ifndef RESOURCE_MANAGER_H_
     1.5 +#define RESOURCE_MANAGER_H_
     1.6 +
     1.7 +/* TODO API */
     1.8 +
     1.9 +/* usage example:
    1.10 +int texload(const char *fname, void *cls)
    1.11 +{
    1.12 +	// open image, parse data ...
    1.13 +}
    1.14 +
    1.15 +struct resman rman;
    1.16 +
    1.17 +resman_init(&rman);
    1.18 +resman_set_load_func(&rman, texload, 0);
    1.19 +resman_set_done_func(&rman, texload_done, 0);
    1.20 +...
    1.21 +
    1.22 +struct texture *tex;
    1.23 +struct resman_job *rjob;
    1.24 +
    1.25 +rjob = resman_get(&rman, "tex.png", 0);
    1.26 +...
    1.27 +resman_wait_job(&rman, rjob);
    1.28 +tex = resman_get_job_data(rjob);
    1.29 +resman_free_job(&rman, rjob);
    1.30 +
    1.31 +...
    1.32 +resman_destroy(&rman);
    1.33 +*/
    1.34 +
    1.35 +struct resman;
    1.36 +
    1.37 +typedef int (*resman_load_func_t)(const char *fname, void *cls);
    1.38 +typedef void (*resman_done_func_t)(int status, void *cls);
    1.39 +
    1.40 +
    1.41 +int resman_init(struct resman *rman);
    1.42 +void resman_destroy(struct resman *rman);
    1.43 +
    1.44 +/* The load callback will be called to load a data file. It may be called in the
    1.45 + * context of a different loading thread.
    1.46 + */
    1.47 +void resman_set_load_func(struct resman *rman, resman_load_func_t func, void *cls);
    1.48 +
    1.49 +/* The "done" callback will be called in the context of the main thread, whenever a
    1.50 + * file was sucessfully loaded, or an error occured.
    1.51 + * It's first argument (status) is set to whatever the load function returned, and its
    1.52 + * closure pointer is the closure 
    1.53 + */
    1.54 +void resman_set_done_func(struct resman *rman, resman_done_func_t func);
    1.55 +
    1.56 +#endif	/* RESOURCE_MANAGER_H_ */