X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=buffer_tree.c;h=7b3355a28b98aa601431029c83063aac016d2d9d;hp=925667456a89f34921aca4a6cf01681c3e99824c;hb=e4713d70469e7ca1afd8e8b9a3e67c3764cf3933;hpb=5587494468627e20fe622b6055689717262d09ab diff --git a/buffer_tree.c b/buffer_tree.c index 92566745..7b3355a2 100644 --- a/buffer_tree.c +++ b/buffer_tree.c @@ -36,6 +36,7 @@ struct btr_node { */ struct list_head input_queue; btr_command_handler execute; + void *context; }; #define FOR_EACH_CHILD(_tn, _btrn) list_for_each_entry((_tn), \ @@ -47,13 +48,14 @@ struct btr_node { list_for_each_entry_safe((_br), (_tmp), &(_btrn)->input_queue, node) struct btr_node *btr_new_node(char *name, struct btr_node *parent, - btr_command_handler handler) + btr_command_handler handler, void *context) { struct btr_node *btrn = para_malloc(sizeof(*btrn)); btrn->name = para_strdup(name); btrn->parent = parent; btrn->execute = handler; + btrn->context = context; if (parent) list_add_tail(&btrn->node, &parent->children); INIT_LIST_HEAD(&btrn->children); @@ -93,14 +95,15 @@ static void btr_drop_buffer_reference(struct btr_buffer_reference *br) } } -static void add_btrb_to_children(struct btr_buffer *btrb, struct btr_node *btrn) +static void add_btrb_to_children(struct btr_buffer *btrb, + struct btr_node *btrn, size_t consumed) { struct btr_node *ch; FOR_EACH_CHILD(ch, btrn) { struct btr_buffer_reference *br = para_malloc(sizeof(*br)); br->btrb = btrb; - br->consumed = 0; + br->consumed = consumed; list_add_tail(&br->node, &ch->input_queue); btrb->refcount++; } @@ -111,12 +114,12 @@ void btr_add_output(char *buf, size_t size, struct btr_node *btrn) struct btr_buffer *btrb; btrb = new_btrb(buf, size); - add_btrb_to_children(btrb, btrn); + add_btrb_to_children(btrb, btrn, 0); } static void btr_pushdown_br(struct btr_buffer_reference *br, struct btr_node *btrn) { - add_btrb_to_children(br->btrb, btrn); + add_btrb_to_children(br->btrb, btrn, br->consumed); btr_drop_buffer_reference(br); } @@ -257,7 +260,7 @@ int btr_exec(struct btr_node *btrn, const char *command, char **value_result) return -ERRNO_TO_PARA_ERROR(EINVAL); if (!btrn->execute) return -ERRNO_TO_PARA_ERROR(ENOTSUP); - return btrn->execute(command, value_result); + return btrn->execute(btrn, command, value_result); } int btr_exec_up(struct btr_node *btrn, const char *command, char **value_result) @@ -271,7 +274,7 @@ int btr_exec_up(struct btr_node *btrn, const char *command, char **value_result) return -ERRNO_TO_PARA_ERROR(ENOTSUP); if (!parent->execute) continue; - ret = parent->execute(command, value_result); + ret = parent->execute(parent, command, value_result); if (ret == -ERRNO_TO_PARA_ERROR(ENOTSUP)) continue; if (ret < 0) @@ -279,3 +282,8 @@ int btr_exec_up(struct btr_node *btrn, const char *command, char **value_result) } return -ERRNO_TO_PARA_ERROR(ENOTSUP); } + +void *btr_context(struct btr_node *btrn) +{ + return btrn->context; +}