buffer_tree: Add code to splice out a node of the buffer tree.
authorAndre Noll <maan@systemlinux.org>
Tue, 29 Dec 2009 21:53:07 +0000 (22:53 +0100)
committerAndre Noll <maan@systemlinux.org>
Tue, 29 Dec 2009 21:53:07 +0000 (22:53 +0100)
buffer_tree.c
buffer_tree.h

index 2a52f097a325641c5695ae841eaa4608263d3d99..925667456a89f34921aca4a6cf01681c3e99824c 100644 (file)
@@ -216,6 +216,24 @@ size_t btr_get_input_queue_size(struct btr_node *btrn)
        return size;
 }
 
+int btr_splice_out_node(struct btr_node *btrn)
+{
+       struct btr_node *ch;
+
+       if (!btrn)
+               return -ERRNO_TO_PARA_ERROR(EINVAL);
+       if (btr_get_input_queue_size(btrn) != 0)
+               return -ERRNO_TO_PARA_ERROR(EINVAL);
+       PARA_NOTICE_LOG("splicing out %s\n", btrn->name);
+       if (btrn->parent)
+               list_del(&btrn->node);
+       FOR_EACH_CHILD(ch, btrn)
+               ch->parent = btrn->parent;
+       free(btrn->name);
+       free(btrn);
+       return 1;
+}
+
 /**
  * Return the size of the largest input queue.
  *
index c84a93058e575ed6a8fdbc79c49160b2d0271985..69886c7932b8c1f96ca59b7a6418ffe519e593fd 100644 (file)
@@ -15,3 +15,4 @@ size_t btr_next_buffer(struct btr_node *btrn, char **bufp);
 void btr_consume(struct btr_node *btrn, size_t numbytes);
 int btr_exec(struct btr_node *btrn, const char *command, char **value_result);
 int btr_exec_up(struct btr_node *btrn, const char *command, char **value_result);
+int btr_splice_out_node(struct btr_node *btrn);