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
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)
......
......@@ -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;
......
#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;
......@@ -94,6 +96,16 @@ int labcomm_mem_writer(labcomm_writer_t *w, labcomm_writer_action_t action)
case labcomm_writer_available:{
result = w->count - w->pos;
} 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;
}
......
......@@ -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);
......
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