Commit 506eb33b authored by Sven Robertz's avatar Sven Robertz
Browse files

put back varargs in writer

parent 3b18c8bf
......@@ -641,7 +641,8 @@ aspect C_Encoder {
env.println(")");
env.println("{");
env.indent();
env.println("e->writer.write(&e->writer, labcomm_writer_start);");
env.println("labcomm_encoder_start(e, &labcomm_signature_" +
env.prefix + getName() + ");");
env.println("labcomm_encode_type_index(e, &labcomm_signature_" +
env.prefix + getName() + ");");
env.println("{");
......@@ -649,7 +650,8 @@ aspect C_Encoder {
getType().C_emitEncoder(env);
env.unindent();
env.println("}");
env.println("e->writer.write(&e->writer, labcomm_writer_end);");
env.println("labcomm_encoder_end(e, &labcomm_signature_" +
env.prefix + getName() + ");");
env.unindent();
env.println("}");
......
......@@ -183,6 +183,25 @@ static int get_encoder_index(
return result;
}
void labcomm_encoder_start(struct labcomm_encoder *e,
labcomm_signature_t *s)
{
int index = get_encoder_index(e, s);
e->writer.write(&e->writer, labcomm_writer_start, index);
}
void labcomm_encoder_end(struct labcomm_encoder *e,
labcomm_signature_t *s)
{
e->writer.write(&e->writer, labcomm_writer_end);
}
void labcomm_encode_type_index(labcomm_encoder_t *e, labcomm_signature_t *s)
{
int index = get_encoder_index(e, s);
labcomm_encode_packed32(e, index);
}
void labcomm_encode_signature(struct labcomm_encoder *e,
labcomm_signature_t *signature)
{
......@@ -248,7 +267,7 @@ static void do_encode(
}
labcomm_encoder_t *labcomm_encoder_new(
int (*writer)(labcomm_writer_t *, labcomm_writer_action_t),
int (*writer)(labcomm_writer_t *, labcomm_writer_action_t, ...),
void *writer_context)
{
labcomm_encoder_t *result = malloc(sizeof(labcomm_encoder_t));
......@@ -342,12 +361,6 @@ int labcomm_encoder_ioctl(struct labcomm_encoder *encoder,
}
void labcomm_encode_type_index(labcomm_encoder_t *e, labcomm_signature_t *s)
{
int index = get_encoder_index(e, s);
labcomm_encode_packed32(e, index);
}
static void collect_flat_signature(
labcomm_decoder_t *decoder,
labcomm_encoder_t *signature_writer)
......
......@@ -147,13 +147,13 @@ typedef struct labcomm_writer {
int count;
int pos;
int error;
int (*write)(struct labcomm_writer *, labcomm_writer_action_t);
int (*write)(struct labcomm_writer *, labcomm_writer_action_t, ...);
int (*ioctl)(struct labcomm_writer *, int, va_list);
labcomm_error_handler_callback on_error;
} labcomm_writer_t;
struct labcomm_encoder *labcomm_encoder_new(
int (*writer)(labcomm_writer_t *, labcomm_writer_action_t),
int (*writer)(labcomm_writer_t *, labcomm_writer_action_t, ...),
void *writer_context);
void labcomm_encoder_free(
struct labcomm_encoder *encoder);
......@@ -162,4 +162,10 @@ int labcomm_encoder_ioctl(struct labcomm_encoder *encoder,
int ioctl_action,
...);
void labcomm_encoder_start(struct labcomm_encoder *e,
labcomm_signature_t *s) ;
//HERE BE DRAGONS: is the signature_t* needed here?
void labcomm_encoder_end(struct labcomm_encoder *e,
labcomm_signature_t *s) ;
#endif
......@@ -2,7 +2,7 @@
int labcomm_dynamic_buffer_writer(
labcomm_writer_t *w,
labcomm_writer_action_t action)
labcomm_writer_action_t action, ...)
{
switch (action) {
case labcomm_writer_alloc: {
......
......@@ -9,6 +9,6 @@ extern int labcomm_dynamic_buffer_reader(
extern int labcomm_dynamic_buffer_writer(
labcomm_writer_t *writer,
labcomm_writer_action_t action);
labcomm_writer_action_t action, ...);
#endif
......@@ -62,7 +62,7 @@ int labcomm_fd_reader(
int labcomm_fd_writer(
labcomm_writer_t *w,
labcomm_writer_action_t action)
labcomm_writer_action_t action, ...)
{
int result = 0;
int *fd = w->context;
......
......@@ -9,6 +9,6 @@ extern int labcomm_fd_reader(
extern int labcomm_fd_writer(
labcomm_writer_t *writer,
labcomm_writer_action_t action);
labcomm_writer_action_t action, ...);
#endif
......@@ -331,7 +331,7 @@ static inline void labcomm_encode_string(labcomm_encoder_t *e,
void labcomm_encode_type_index(labcomm_encoder_t *e, labcomm_signature_t *s);
static inline int labcomm_buffer_write(struct labcomm_writer *w,
labcomm_writer_action_t action)
labcomm_writer_action_t action, ...)
{
// If this gets called, it is an error,
// so note error and let producer proceed
......
......@@ -27,7 +27,7 @@ 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, ...)
{
int result = 0;
// Unwrap pointers for easy access.
......
......@@ -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