X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=buffer_tree.c;h=2a52f097a325641c5695ae841eaa4608263d3d99;hp=1ca4a1536cdd452116303bbf43f7f24de4ef9c42;hb=c4d243653174f3f4ffc331a4bfc54de94d612f34;hpb=8248f915d9ffef663f2a1d9c70393da6a4a5c7d2 diff --git a/buffer_tree.c b/buffer_tree.c index 1ca4a153..2a52f097 100644 --- a/buffer_tree.c +++ b/buffer_tree.c @@ -5,6 +5,7 @@ #include "list.h" #include "string.h" #include "buffer_tree.h" +#include "error.h" struct btr_buffer { @@ -34,6 +35,7 @@ struct btr_node { * used by this btr node. */ struct list_head input_queue; + btr_command_handler execute; }; #define FOR_EACH_CHILD(_tn, _btrn) list_for_each_entry((_tn), \ @@ -44,12 +46,14 @@ struct btr_node { #define FOR_EACH_BUFFER_REF_SAFE(_br, _tmp, _btrn) \ list_for_each_entry_safe((_br), (_tmp), &(_btrn)->input_queue, node) -struct btr_node *btr_new_node(char *name, struct btr_node *parent) +struct btr_node *btr_new_node(char *name, struct btr_node *parent, + btr_command_handler handler) { struct btr_node *btrn = para_malloc(sizeof(*btrn)); btrn->name = para_strdup(name); btrn->parent = parent; + btrn->execute = handler; if (parent) list_add_tail(&btrn->node, &parent->children); INIT_LIST_HEAD(&btrn->children); @@ -79,6 +83,7 @@ static void btr_drop_buffer_reference(struct btr_buffer_reference *br) { struct btr_buffer *btrb = br->btrb; + //PARA_CRIT_LOG("dropping buffer reference %p\n", br); list_del(&br->node); free(br); btrb->refcount--; @@ -204,8 +209,10 @@ size_t btr_get_input_queue_size(struct btr_node *btrn) struct btr_buffer_reference *br; size_t size = 0; - FOR_EACH_BUFFER_REF(br, btrn) + FOR_EACH_BUFFER_REF(br, btrn) { + //PARA_CRIT_LOG("size: %zu\n", size); size += br_available_bytes(br); + } return size; } @@ -225,3 +232,32 @@ size_t btr_bytes_pending(struct btr_node *btrn) } return max_size; } + +int btr_exec(struct btr_node *btrn, const char *command, char **value_result) +{ + if (!btrn) + return -ERRNO_TO_PARA_ERROR(EINVAL); + if (!btrn->execute) + return -ERRNO_TO_PARA_ERROR(ENOTSUP); + return btrn->execute(command, value_result); +} + +int btr_exec_up(struct btr_node *btrn, const char *command, char **value_result) +{ + int ret; + + for (; btrn; btrn = btrn->parent) { + struct btr_node *parent = btrn->parent; + PARA_CRIT_LOG("parent: %p\n", parent); + if (!parent) + return -ERRNO_TO_PARA_ERROR(ENOTSUP); + if (!parent->execute) + continue; + ret = parent->execute(command, value_result); + if (ret == -ERRNO_TO_PARA_ERROR(ENOTSUP)) + continue; + if (ret < 0) + return ret; + } + return -ERRNO_TO_PARA_ERROR(ENOTSUP); +}