diff --git a/lib/c/Makefile b/lib/c/Makefile index a17c72d4a7f6807c43c630da5095d5e8392d96dd..6d6c81f5368452f986348eb72435d4c7282fb821 100644 --- a/lib/c/Makefile +++ b/lib/c/Makefile @@ -16,8 +16,8 @@ TEST_GEN_DIR=$(TESTDATA_DIR)/gen CREATED_DIRS=$(TEST_DIR) $(TESTDATA_DIR) $(TEST_GEN_DIR) -# Disable experimental objects by invoking make like `make -e LABCOMM_NO_EXPERIMENTAL=true` -ifneq ($(LABCOMM_NO_EXPERIMENTAL),true) +# Enable experimental objects by invoking make like `make -e LABCOMM_EXPERIMENTAL=true` +ifeq ($(LABCOMM_EXPERIMENTAL),true) OBJS += experimental/udp_hack.o experimental/ethaddr.o \ experimental/labcomm_thr_reader_writer.o \ experimental/ThrottleDrv/ethernet_drv.o \ @@ -48,7 +48,9 @@ ethaddr.o: ethaddr.c $(CREATED_DIRS): mkdir -p $@ -run-test: $(TEST_DIR)/test_labcomm_errors |$(TEST_DIR) +## NB! the tests need CUnit to be installed +run-test: $(TEST_DIR)/test_labcomm $(TEST_DIR)/test_labcomm_errors |$(TEST_DIR) + test/test_labcomm test/test_labcomm_errors $(TEST_DIR)/test_labcomm_errors: $(TEST_DIR)/test_labcomm_errors.o liblabcomm.a |$(TEST_DIR) diff --git a/lib/c/labcomm_fd_reader_writer.c b/lib/c/labcomm_fd_reader_writer.c index 7f3e3e39d3c8c6be95d9fef6997070fda34f0a33..c76f7aca6209b5ba914ee93386b78d1530187e82 100644 --- a/lib/c/labcomm_fd_reader_writer.c +++ b/lib/c/labcomm_fd_reader_writer.c @@ -108,9 +108,7 @@ int labcomm_fd_writer( struct labcomm_encoder *e = va_arg(argp, struct labcomm_encoder*); va_end(argp); - printf("Sending signature: %s\n", signature->name); labcomm_encode_signature(e, signature); - } break; case labcomm_writer_user_action: { result = -ENOTSUP; diff --git a/lib/c/labcomm_mem_writer.c b/lib/c/labcomm_mem_writer.c index 7275649e2bf901ff24f47bff395e58b5a9226271..dab69f17de4094dcaf13bcf180912245fd06bc96 100644 --- a/lib/c/labcomm_mem_writer.c +++ b/lib/c/labcomm_mem_writer.c @@ -1,6 +1,7 @@ #include "labcomm_mem_writer.h" -#include "stddef.h" // For size_t. +#include <stddef.h> // For size_t. +#include <stdarg.h> #include <errno.h> #include "labcomm.h" @@ -26,8 +27,9 @@ static void copy_data(labcomm_writer_t *w, labcomm_mem_writer_context_t *mcontex * Write encoded messages to memory. w->context is assumed to be a pointer to a * labcomm_mem_writer_context_t structure. */ -int labcomm_mem_writer(labcomm_writer_t *w, labcomm_writer_action_t action) +int labcomm_mem_writer(labcomm_writer_t *w, labcomm_writer_action_t action, ...) { + va_list argp; int result = 0; // Unwrap pointers for easy access. labcomm_mem_writer_context_t *mcontext = (labcomm_mem_writer_context_t *) w->context; @@ -93,7 +95,17 @@ int labcomm_mem_writer(labcomm_writer_t *w, labcomm_writer_action_t action) } break; case labcomm_writer_available:{ result = w->count - w->pos; - } break; + } break; + case labcomm_writer_send_signature: { + va_start(argp, action); + labcomm_signature_t *signature = va_arg(argp, labcomm_signature_t*); + struct labcomm_encoder *e = va_arg(argp, struct labcomm_encoder*); + va_end(argp); + labcomm_encode_signature(e, signature); + } break; + case labcomm_writer_user_action:{ + result = -ENOTSUP; + } break; } return result; } diff --git a/lib/c/labcomm_mem_writer.h b/lib/c/labcomm_mem_writer.h index 4585903c93beea5ae17bd2a845c216b801a59539..7506342a9844f442008eafae0a565432d0e06f2d 100644 --- a/lib/c/labcomm_mem_writer.h +++ b/lib/c/labcomm_mem_writer.h @@ -11,7 +11,7 @@ struct labcomm_mem_writer_context_t { unsigned char *buf; // Allocated destination buffer. }; -int labcomm_mem_writer(labcomm_writer_t *w, labcomm_writer_action_t action); +int labcomm_mem_writer(labcomm_writer_t *w, labcomm_writer_action_t action, ...); /* Wrapper the internal static function copy_data. This is needed so that the exceptions can be unit tested. */ void test_copy_data(labcomm_writer_t *w, labcomm_mem_writer_context_t *mcontext, unsigned char *mbuf);