# HG changeset patch # User John Tsiombikas # Date 1390976251 -7200 # Node ID 61d7ff6da54b9e6e66f661617f4af6cebbb3e401 initial commit: figuring out the API diff -r 000000000000 -r 61d7ff6da54b Makefile --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Makefile Wed Jan 29 08:17:31 2014 +0200 @@ -0,0 +1,62 @@ +# change this if you want to install elsewhere +PREFIX = /usr/local + +src = $(wildcard src/*.c) +obj = $(src:.c=.o) +dep = $(obj:.o=.d) + +name = resman +lib_a = lib$(name).a + +api_major = 0 +api_minor = 1 + +CFLAGS = -pedantic -Wall -g + +ifeq ($(shell uname -s), Darwin) + lib_so = lib$(name).dylib + shared = -dynamiclib +else + devlink = lib$(name).so + soname = lib$(name).so.$(api_major) + lib_so = lib$(name).so.$(api_major).$(api_minor) + shared = -shared -Wl,-soname,$(soname) + pic = -fPIC +endif + +.PHONY: all +all: $(lib_so) $(lib_a) + +$(lib_so): $(obj) + $(CC) -o $@ $(shared) $(obj) $(LDFLAGS) + +$(lib_a): $(obj) + $(AR) rcs $@ $(obj) + +-include $(dep) + +%.d: %.c + @$(CPP) $(CFLAGS) $< -MM -MT $(@:.d=.o) >$@ + +.PHONY: clean +clean: + rm -f $(obj) $(lib_so) $(lib_a) + +.PHONY: install +install: $(lib_a) $(lib_so) + mkdir -p $(DESTDIR)$(PREFIX)/lib $(DESTDIR)$(PREFIX)/include + cp $(lib_a) $(DESTDIR)$(PREFIX)/lib/$(lib_a) + cp $(lib_so) $(DESTDIR)$(PREFIX)/lib/$(lib_so) + [ -n "$(devlink)" ] \ + && cd $(DESTDIR)$(PREFIX)/lib \ + && rm -f $(soname) $(devlink) \ + && ln -s $(lib_so) $(soname) \ + && ln -s $(soname) $(devlink) \ + || true + cp src/resman.h $(DESTDIR)$(PREFIX)/include/resman.h + +.PHONY: uninstall +uninstall: + rm -f $(DESTDIR)$(PREFIX)/lib/$(lib_a) + rm -f $(DESTDIR)$(PREFIX)/lib/$(lib_so) + rm -f $(DESTDIR)$(PREFIX)/include/resman.h diff -r 000000000000 -r 61d7ff6da54b src/resman.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/resman.h Wed Jan 29 08:17:31 2014 +0200 @@ -0,0 +1,53 @@ +#ifndef RESOURCE_MANAGER_H_ +#define RESOURCE_MANAGER_H_ + +/* TODO API */ + +/* usage example: +int texload(const char *fname, void *cls) +{ + // open image, parse data ... +} + +struct resman rman; + +resman_init(&rman); +resman_set_load_func(&rman, texload, 0); +resman_set_done_func(&rman, texload_done, 0); +... + +struct texture *tex; +struct resman_job *rjob; + +rjob = resman_get(&rman, "tex.png", 0); +... +resman_wait_job(&rman, rjob); +tex = resman_get_job_data(rjob); +resman_free_job(&rman, rjob); + +... +resman_destroy(&rman); +*/ + +struct resman; + +typedef int (*resman_load_func_t)(const char *fname, void *cls); +typedef void (*resman_done_func_t)(int status, void *cls); + + +int resman_init(struct resman *rman); +void resman_destroy(struct resman *rman); + +/* The load callback will be called to load a data file. It may be called in the + * context of a different loading thread. + */ +void resman_set_load_func(struct resman *rman, resman_load_func_t func, void *cls); + +/* The "done" callback will be called in the context of the main thread, whenever a + * file was sucessfully loaded, or an error occured. + * It's first argument (status) is set to whatever the load function returned, and its + * closure pointer is the closure + */ +void resman_set_done_func(struct resman *rman, resman_done_func_t func); + +#endif /* RESOURCE_MANAGER_H_ */