X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=filter_common.c;h=7fa30803d6c02a87699b3cc927e0c8b7966e36c9;hp=ebda1ee74ad265275017d9ebe6eaf137de317fcb;hb=b7243e074d583c5977bf89b0a2d8ac4635aebbb6;hpb=318fbe90e08b6d9c5e781d9b517b670c5a1a04d7 diff --git a/filter_common.c b/filter_common.c index ebda1ee7..7fa30803 100644 --- a/filter_common.c +++ b/filter_common.c @@ -6,14 +6,17 @@ /** \file filter_common.c Common helper functions for filter input/output. */ +#include #include #include +#include #include "para.h" #include "list.h" #include "sched.h" #include "fd.h" #include "ggo.h" +#include "buffer_tree.h" #include "filter.h" #include "error.h" #include "string.h" @@ -43,7 +46,7 @@ void filter_init(void) */ static void close_filter_callback(struct filter_callback *fcb) { - PARA_NOTICE_LOG("closing filter_callback %p, data: %p\n", fcb, fcb->data); + PARA_NOTICE_LOG("closing filter_callback %p\n", fcb); list_del(&fcb->node); fcb->close(fcb); } @@ -99,13 +102,13 @@ static void call_callbacks(struct filter_node *fn, char *inbuf, size_t inlen, * there is input available for the filter node in question. If the convert * function consumed some or all of its input data, all registered input * callbacks are called. Similarly, if a convert function produced output, all - * registerd output callbacks get called. + * registered output callbacks get called. * * On errors a (negative) error code is stored in t->error. * * \sa filter_node, filter#convert, filter_callback. */ -void filter_pre_select(__a_unused struct sched *s, struct task *t) +void filter_post_select(__a_unused struct sched *s, struct task *t) { struct filter_chain *fc = container_of(t, struct filter_chain, task); struct filter_node *fn; @@ -125,8 +128,6 @@ again: struct filter *f = filters + fn->filter_num; if (fn->loaded < fn->bufsize) { size_t size, old_fn_loaded = fn->loaded; -// PARA_DEBUG_LOG("fc %p loaded: %zd, calling %s convert\n", -// fc, *loaded, fn->filter->name); t->error = f->convert(ib, *loaded, fn); if (t->error < 0) return; @@ -134,22 +135,14 @@ again: call_callbacks(fn, ib, size, fn->buf + old_fn_loaded, fn->loaded - old_fn_loaded); *loaded -= size; - conv += size; - if (*loaded && size) { -// PARA_DEBUG_LOG("moving %zd bytes in input " -// "buffer for %s filter\n", -// *loaded, fn->filter->name); + conv += size + fn->loaded - old_fn_loaded; + if (*loaded && size) memmove(ib, ib + size, *loaded); - } } ib = fn->buf; loaded = &fn->loaded; } conv_total += conv; -// PARA_DEBUG_LOG("eof (in/out/fc): %d/%d/%d out_loaded: %zd, " -// "conv: %d, conv_total: %d\n", *fc->input_eof, -// fc->output_eof? *fc->output_eof : -42, -// fc->eof, *fc->out_loaded, conv, conv_total); if (conv) goto again; if (*fc->input_error >= 0) @@ -186,6 +179,7 @@ void close_filters(struct filter_chain *fc) close_callbacks(fn); PARA_INFO_LOG("closing %s filter\n", f->name); f->close(fn); + free(fn->conf); } free(fc->filter_nodes); } @@ -205,15 +199,18 @@ static int parse_filter_args(int filter_num, char *options, void **conf) if (!f->parse_config) return strlen(options)? -E_BAD_FILTER_OPTIONS : filter_num; // PARA_DEBUG_LOG("options: %s\n", options); - argc = split_args(options, &argv, " \t"); -// PARA_DEBUG_LOG("argc = %d, argv[0]: %s\n", argc, argv[0]); + argc = create_argv(options, " \t", &argv); + if (argc < 0) + return -E_BAD_FILTER_OPTIONS; + PARA_DEBUG_LOG("argc = %d, argv[0]: %s\n", argc, argv[0]); for (i = argc - 1; i >= 0; i--) argv[i + 1] = argv[i]; argv[0] = para_strdup(f->name); - argc += 1; + argc++; ret = f->parse_config(argc, argv, conf); - free(argv[0]); - free(argv); + free(argv[argc - 1]); + argv[argc - 1] = NULL; + free_argv(argv); return ret < 0? ret : filter_num; } @@ -279,3 +276,15 @@ void print_filter_helps(int detailed) } } + +void generic_filter_pre_select(struct sched *s, struct task *t) +{ + struct filter_node *fn = container_of(t, struct filter_node, task); + + t->error = 0; + if (btr_node_status(fn->btrn, fn->min_iqs, BTR_NT_INTERNAL) != 0) { + s->timeout.tv_sec = 0; + s->timeout.tv_usec = 1; + } +} +