Commit 33fabe9f authored by Sven Robertz's avatar Sven Robertz
Browse files

updated mem_writer to varargs + turned experimental off by default

parent fc121fcb
...@@ -16,8 +16,8 @@ TEST_GEN_DIR=$(TESTDATA_DIR)/gen ...@@ -16,8 +16,8 @@ TEST_GEN_DIR=$(TESTDATA_DIR)/gen
CREATED_DIRS=$(TEST_DIR) $(TESTDATA_DIR) $(TEST_GEN_DIR) CREATED_DIRS=$(TEST_DIR) $(TESTDATA_DIR) $(TEST_GEN_DIR)
# Disable experimental objects by invoking make like `make -e LABCOMM_NO_EXPERIMENTAL=true` # Enable experimental objects by invoking make like `make -e LABCOMM_EXPERIMENTAL=true`
ifneq ($(LABCOMM_NO_EXPERIMENTAL),true) ifeq ($(LABCOMM_EXPERIMENTAL),true)
OBJS += experimental/udp_hack.o experimental/ethaddr.o \ OBJS += experimental/udp_hack.o experimental/ethaddr.o \
experimental/labcomm_thr_reader_writer.o \ experimental/labcomm_thr_reader_writer.o \
experimental/ThrottleDrv/ethernet_drv.o \ experimental/ThrottleDrv/ethernet_drv.o \
...@@ -48,7 +48,9 @@ ethaddr.o: ethaddr.c ...@@ -48,7 +48,9 @@ ethaddr.o: ethaddr.c
$(CREATED_DIRS): $(CREATED_DIRS):
mkdir -p $@ 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/test_labcomm_errors
$(TEST_DIR)/test_labcomm_errors: $(TEST_DIR)/test_labcomm_errors.o liblabcomm.a |$(TEST_DIR) $(TEST_DIR)/test_labcomm_errors: $(TEST_DIR)/test_labcomm_errors.o liblabcomm.a |$(TEST_DIR)
......
...@@ -108,9 +108,7 @@ int labcomm_fd_writer( ...@@ -108,9 +108,7 @@ int labcomm_fd_writer(
struct labcomm_encoder *e = va_arg(argp, struct labcomm_encoder*); struct labcomm_encoder *e = va_arg(argp, struct labcomm_encoder*);
va_end(argp); va_end(argp);
printf("Sending signature: %s\n", signature->name);
labcomm_encode_signature(e, signature); labcomm_encode_signature(e, signature);
} break; } break;
case labcomm_writer_user_action: { case labcomm_writer_user_action: {
result = -ENOTSUP; result = -ENOTSUP;
......
#include "labcomm_mem_writer.h" #include "labcomm_mem_writer.h"
#include "stddef.h" // For size_t. #include <stddef.h> // For size_t.
#include <stdarg.h>
#include <errno.h> #include <errno.h>
#include "labcomm.h" #include "labcomm.h"
...@@ -26,8 +27,9 @@ static void copy_data(labcomm_writer_t *w, labcomm_mem_writer_context_t *mcontex ...@@ -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 * Write encoded messages to memory. w->context is assumed to be a pointer to a
* labcomm_mem_writer_context_t structure. * 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; int result = 0;
// Unwrap pointers for easy access. // Unwrap pointers for easy access.
labcomm_mem_writer_context_t *mcontext = (labcomm_mem_writer_context_t *) w->context; 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) ...@@ -93,7 +95,17 @@ int labcomm_mem_writer(labcomm_writer_t *w, labcomm_writer_action_t action)
} break; } break;
case labcomm_writer_available:{ case labcomm_writer_available:{
result = w->count - w->pos; 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; return result;
} }
......
...@@ -11,7 +11,7 @@ struct labcomm_mem_writer_context_t { ...@@ -11,7 +11,7 @@ struct labcomm_mem_writer_context_t {
unsigned char *buf; // Allocated destination buffer. 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. */ /* 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); void test_copy_data(labcomm_writer_t *w, labcomm_mem_writer_context_t *mcontext, unsigned char *mbuf);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment