fix API, fix Makefile, add unit tests
This commit is contained in:
parent
170025ac5d
commit
b532574044
|
@ -1,4 +1,5 @@
|
|||
build/
|
||||
tests/build/
|
||||
*.a
|
||||
*.so
|
||||
*.pb.c
|
||||
|
|
11
Makefile
11
Makefile
|
@ -2,12 +2,15 @@ include deps/nanopb/extra/nanopb.mk
|
|||
include config.mk
|
||||
|
||||
SRC += $(shell find src/ -type f -name '*.c')
|
||||
SRC += $(NANOPB_DIR)/pb_encode.c
|
||||
SRC += $(NANOPB_DIR)/pb_decode.c
|
||||
SRC += $(NANOPB_DIR)/pb_common.c
|
||||
PROTO = $(shell find src/ -type f -name '*.proto')
|
||||
OBJ = $(PROTO:%.proto=$(BUILD_DIR)/%.pb.c.o)
|
||||
OBJ += $(SRC:%=$(BUILD_DIR)/%.o)
|
||||
H = include/libumumble.h
|
||||
|
||||
.PHONY: all static shared clean install-static install-shared install
|
||||
.PHONY: all static shared tests clean install-static install-shared install
|
||||
|
||||
all: static shared
|
||||
|
||||
|
@ -18,7 +21,7 @@ shared: $(DNAME)
|
|||
$(OBJ): config.mk $(PROTO)
|
||||
|
||||
$(SNAME): $(OBJ)
|
||||
ar -rcs $@ $^
|
||||
ar rcs $@ $?
|
||||
|
||||
$(DNAME): LDFLAGS += -shared
|
||||
$(DNAME): $(OBJ)
|
||||
|
@ -28,8 +31,12 @@ $(BUILD_DIR)/%.c.o: %.c
|
|||
mkdir -p '$(@D)'
|
||||
$(CC) -c -o $@ $(INCLUDES) $(CFLAGS) $<
|
||||
|
||||
tests:
|
||||
$(MAKE) -C tests
|
||||
|
||||
clean:
|
||||
rm -rf $(SNAME) $(DNAME) $(BUILD_DIR) src/*.pb.h src/*.pb.c
|
||||
$(MAKE) -C tests clean
|
||||
|
||||
install-header:
|
||||
install -m 644 $(H)
|
||||
|
|
|
@ -15,17 +15,17 @@ typedef struct mumble_ctx {
|
|||
* This function will allocate initial memory needed for storing e.g. the channel layout.
|
||||
* Make sure to call mumble_free_ctx() when you're done!
|
||||
*
|
||||
* \param ctx the context object to initialize.
|
||||
* \param ctx pointer to the context object to initialize.
|
||||
* \return int indicating success
|
||||
* \retval 1 error
|
||||
*/
|
||||
int mumble_init_ctx(mumble_ctx_t ctx);
|
||||
int mumble_init_ctx(mumble_ctx_t *ctx);
|
||||
|
||||
/* Free a mumble context.
|
||||
*
|
||||
* \param ctx the context object to free.
|
||||
* \param ctx pointer to the context object to free.
|
||||
*/
|
||||
void mumble_free_ctx(mumble_ctx_t ctx);
|
||||
void mumble_free_ctx(mumble_ctx_t *ctx);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
#include <libumumble.h>
|
||||
#include <uv.h>
|
||||
|
||||
int mumble_init_ctx(mumble_ctx_t ctx)
|
||||
int mumble_init_ctx(mumble_ctx_t *ctx)
|
||||
{
|
||||
int result;
|
||||
|
||||
result = uv_loop_init(&ctx.uv_loop);
|
||||
result = uv_loop_init(&ctx->uv_loop);
|
||||
return result;
|
||||
}
|
||||
|
||||
void mumble_free_ctx(mumble_ctx_t ctx)
|
||||
void mumble_free_ctx(mumble_ctx_t *ctx)
|
||||
{
|
||||
uv_loop_close(&ctx.uv_loop);
|
||||
uv_loop_close(&ctx->uv_loop);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
include ../config.mk
|
||||
INCLUDES = -I../include
|
||||
|
||||
SRC = $(shell find -type f -name '*.c')
|
||||
BIN = $(SRC:%.c=%)
|
||||
|
||||
LDLIBS = -luv -l:libumumble.a
|
||||
LDFLAGS = -L..
|
||||
|
||||
.PHONY: all
|
||||
|
||||
all: $(BIN)
|
||||
|
||||
$(BIN): $(SRC)
|
||||
mkdir -p '$(BUILD_DIR)'
|
||||
$(CC) -o $(BUILD_DIR)/$@ $(CFLAGS) $(INCLUDES) $(@:%=%.c) $(LDFLAGS) $(LDLIBS)
|
||||
|
||||
clean:
|
||||
rm -rf $(BUILD_DIR)
|
|
@ -0,0 +1,11 @@
|
|||
#include <libumumble.h>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
mumble_ctx_t ctx;
|
||||
printf("%ld\n", ctx.uv_loop.time);
|
||||
mumble_init_ctx(&ctx);
|
||||
printf("%ld\n", ctx.uv_loop.time);
|
||||
mumble_free_ctx(&ctx);
|
||||
printf("%ld\n", ctx.uv_loop.time);
|
||||
}
|
Loading…
Reference in New Issue