libresman

changeset 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
files Makefile src/resman.h
diffstat 2 files changed, 115 insertions(+), 0 deletions(-) [+]
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/Makefile	Wed Jan 29 08:17:31 2014 +0200
     1.3 @@ -0,0 +1,62 @@
     1.4 +# change this if you want to install elsewhere
     1.5 +PREFIX = /usr/local
     1.6 +
     1.7 +src = $(wildcard src/*.c)
     1.8 +obj = $(src:.c=.o)
     1.9 +dep = $(obj:.o=.d)
    1.10 +
    1.11 +name = resman
    1.12 +lib_a = lib$(name).a
    1.13 +
    1.14 +api_major = 0
    1.15 +api_minor = 1
    1.16 +
    1.17 +CFLAGS = -pedantic -Wall -g
    1.18 +
    1.19 +ifeq ($(shell uname -s), Darwin)
    1.20 +	lib_so = lib$(name).dylib
    1.21 +	shared = -dynamiclib
    1.22 +else
    1.23 +	devlink = lib$(name).so
    1.24 +	soname = lib$(name).so.$(api_major)
    1.25 +	lib_so = lib$(name).so.$(api_major).$(api_minor)
    1.26 +	shared = -shared -Wl,-soname,$(soname)
    1.27 +	pic = -fPIC
    1.28 +endif
    1.29 +
    1.30 +.PHONY: all
    1.31 +all: $(lib_so) $(lib_a)
    1.32 +
    1.33 +$(lib_so): $(obj)
    1.34 +	$(CC) -o $@ $(shared) $(obj) $(LDFLAGS)
    1.35 +
    1.36 +$(lib_a): $(obj)
    1.37 +	$(AR) rcs $@ $(obj)
    1.38 +
    1.39 +-include $(dep)
    1.40 +
    1.41 +%.d: %.c
    1.42 +	@$(CPP) $(CFLAGS) $< -MM -MT $(@:.d=.o) >$@
    1.43 +
    1.44 +.PHONY: clean
    1.45 +clean:
    1.46 +	rm -f $(obj) $(lib_so) $(lib_a)
    1.47 +
    1.48 +.PHONY: install
    1.49 +install: $(lib_a) $(lib_so)
    1.50 +	mkdir -p $(DESTDIR)$(PREFIX)/lib $(DESTDIR)$(PREFIX)/include
    1.51 +	cp $(lib_a) $(DESTDIR)$(PREFIX)/lib/$(lib_a)
    1.52 +	cp $(lib_so) $(DESTDIR)$(PREFIX)/lib/$(lib_so)
    1.53 +	[ -n "$(devlink)" ] \
    1.54 +		&& cd $(DESTDIR)$(PREFIX)/lib \
    1.55 +		&& rm -f $(soname) $(devlink) \
    1.56 +		&& ln -s $(lib_so) $(soname) \
    1.57 +		&& ln -s $(soname) $(devlink) \
    1.58 +		|| true
    1.59 +	cp src/resman.h $(DESTDIR)$(PREFIX)/include/resman.h
    1.60 +
    1.61 +.PHONY: uninstall
    1.62 +uninstall:
    1.63 +	rm -f $(DESTDIR)$(PREFIX)/lib/$(lib_a)
    1.64 +	rm -f $(DESTDIR)$(PREFIX)/lib/$(lib_so)
    1.65 +	rm -f $(DESTDIR)$(PREFIX)/include/resman.h
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/src/resman.h	Wed Jan 29 08:17:31 2014 +0200
     2.3 @@ -0,0 +1,53 @@
     2.4 +#ifndef RESOURCE_MANAGER_H_
     2.5 +#define RESOURCE_MANAGER_H_
     2.6 +
     2.7 +/* TODO API */
     2.8 +
     2.9 +/* usage example:
    2.10 +int texload(const char *fname, void *cls)
    2.11 +{
    2.12 +	// open image, parse data ...
    2.13 +}
    2.14 +
    2.15 +struct resman rman;
    2.16 +
    2.17 +resman_init(&rman);
    2.18 +resman_set_load_func(&rman, texload, 0);
    2.19 +resman_set_done_func(&rman, texload_done, 0);
    2.20 +...
    2.21 +
    2.22 +struct texture *tex;
    2.23 +struct resman_job *rjob;
    2.24 +
    2.25 +rjob = resman_get(&rman, "tex.png", 0);
    2.26 +...
    2.27 +resman_wait_job(&rman, rjob);
    2.28 +tex = resman_get_job_data(rjob);
    2.29 +resman_free_job(&rman, rjob);
    2.30 +
    2.31 +...
    2.32 +resman_destroy(&rman);
    2.33 +*/
    2.34 +
    2.35 +struct resman;
    2.36 +
    2.37 +typedef int (*resman_load_func_t)(const char *fname, void *cls);
    2.38 +typedef void (*resman_done_func_t)(int status, void *cls);
    2.39 +
    2.40 +
    2.41 +int resman_init(struct resman *rman);
    2.42 +void resman_destroy(struct resman *rman);
    2.43 +
    2.44 +/* The load callback will be called to load a data file. It may be called in the
    2.45 + * context of a different loading thread.
    2.46 + */
    2.47 +void resman_set_load_func(struct resman *rman, resman_load_func_t func, void *cls);
    2.48 +
    2.49 +/* The "done" callback will be called in the context of the main thread, whenever a
    2.50 + * file was sucessfully loaded, or an error occured.
    2.51 + * It's first argument (status) is set to whatever the load function returned, and its
    2.52 + * closure pointer is the closure 
    2.53 + */
    2.54 +void resman_set_done_func(struct resman *rman, resman_done_func_t func);
    2.55 +
    2.56 +#endif	/* RESOURCE_MANAGER_H_ */