fn->conf = a->filter_conf[i];
fn->task.pre_select = f->pre_select;
fn->task.post_select = f->post_select;
- fn->btrn = btr_new_node(f->name, parent, f->execute, fn);
+
+ fn->btrn = btr_new_node(&(struct btr_node_description)
+ EMBRACE(.name = f->name, .parent = parent,
+ .handler = f->execute, .context = fn));
+
f->open(fn);
register_task(&fn->task);
parent = fn->btrn;
rn = s->receiver_node;
rn->receiver = r;
rn->conf = a->receiver_conf;
- rn->btrn = btr_new_node(r->name, NULL, NULL, rn);
+ rn->btrn = btr_new_node(&(struct btr_node_description)
+ EMBRACE(.name = r->name, .context = rn));
ret = r->open(rn);
if (ret < 0) {
btr_free_node(rn->btrn);
#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(const char *name, struct btr_node *parent,
- btr_command_handler handler, void *context)
+/*
+ (parent, child):
+ (NULL, NULL): new, isolated node.
+ (NULL, c): new node becomes root, c must be old root
+ (p, NULL): new leaf node
+ (p, c): new internal node, ch must be child of p
+
+*/
+struct btr_node *btr_new_node(struct btr_node_description *bnd)
{
struct btr_node *btrn = para_malloc(sizeof(*btrn));
- btrn->name = para_strdup(name);
- btrn->parent = parent;
- btrn->execute = handler;
- btrn->context = context;
+ btrn->name = para_strdup(bnd->name);
+ btrn->parent = bnd->parent;
+ btrn->execute = bnd->handler;
+ btrn->context = bnd->context;
btrn->start.tv_sec = 0;
btrn->start.tv_usec = 0;
- if (parent)
- list_add_tail(&btrn->node, &parent->children);
+ if (bnd->parent)
+ list_add_tail(&btrn->node, &bnd->parent->children);
INIT_LIST_HEAD(&btrn->children);
INIT_LIST_HEAD(&btrn->input_queue);
- if (parent)
- PARA_INFO_LOG("added %s as child of %s\n", name, parent->name);
+ if (bnd->parent)
+ PARA_INFO_LOG("added %s as child of %s\n", bnd->name, bnd->parent->name);
else
- PARA_INFO_LOG("added %s as btr root\n", name);
+ PARA_INFO_LOG("added %s as btr root\n", bnd->name);
return btrn;
}
BTR_NT_LEAF,
};
+struct btr_node_description {
+ const char *name;
+ struct btr_node *parent;
+ btr_command_handler handler;
+ void *context;
+};
+
size_t btr_pool_size(struct btr_pool *btrp);
struct btr_pool *btr_pool_new(const char *name, size_t area_size);
void btr_pool_free(struct btr_pool *btrp);
void btr_copy(const void *src, size_t n, struct btr_pool *btrp,
struct btr_node *btrn);
-struct btr_node *btr_new_node(const char *name, struct btr_node *parent,
- btr_command_handler handler, void *context);
+struct btr_node *btr_new_node(struct btr_node_description *bnd);
void btr_remove_node(struct btr_node *btrn);
void btr_free_node(struct btr_node *btrn);
void btr_add_output(char *buf, size_t size, struct btr_node *btrn);
ret = parse_config(argc, argv);
if (ret < 0)
goto out;
- sit->btrn = btr_new_node("stdin", NULL, NULL, NULL);
+ sit->btrn = btr_new_node(&(struct btr_node_description)
+ EMBRACE(.name = "stdin"));
stdin_set_defaults(sit);
register_task(&sit->task);
f = filters + fn->filter_num;
sprintf(fn->task.status, "%s", f->name);
PARA_DEBUG_LOG("filter #%d: %s\n", i, f->name);
- fn->btrn = btr_new_node(f->name, parent, f->execute, fn);
+ fn->btrn = btr_new_node(&(struct btr_node_description)
+ EMBRACE(.name = f->name, .parent = parent,
+ .handler = f->execute, .context = fn));
fn->task.pre_select = f->pre_select;
fn->task.post_select = f->post_select;
f->open(fn);
register_task(&fn->task);
parent = fn->btrn;
}
- sot->btrn = btr_new_node("stdout", parent, NULL, NULL);
+ sot->btrn = btr_new_node(&(struct btr_node_description)
+ EMBRACE(.name = "stdout", .parent = parent));
stdout_set_defaults(sot);
register_task(&sot->task);
return;
PARA_INFO_LOG("activating fd %d\n", gc->fd);
list_move(&gc->node, &active_grab_client_list);
- gc->btrn = btr_new_node(name, parent, NULL, NULL);
+ gc->btrn = btr_new_node(&(struct btr_node_description)
+ EMBRACE(.name = name, .parent = parent));
if (!gc->task.pre_select) {
gc->task.pre_select = gc_pre_select;
gc->task.post_select = gc_post_select;
#define FEC_EOF_PACKET "\xec\x0d\xcc\xfe\0\0\0\0" \
"\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0"
#define FEC_EOF_PACKET_LEN 32
+
+/** Used to avoid a shortcoming in vim's syntax highlighting. */
+#define EMBRACE(...) { __VA_ARGS__}
+
}
/**
- * the main function of para_recv
+ * The main function of para_recv.
*
* \param argc number of arguments
* \param argv vector of arguments
}
r = &receivers[receiver_num];
rn.receiver = r;
- rn.btrn = btr_new_node("receiver", NULL, NULL, NULL);
+ rn.btrn = btr_new_node(&(struct btr_node_description)
+ EMBRACE(.name = r->name));
ret = r->open(&rn);
if (ret < 0)
goto out;
r_opened = 1;
- sot.btrn = btr_new_node("stdout", rn.btrn, NULL, NULL);
+ sot.btrn = btr_new_node(&(struct btr_node_description)
+ EMBRACE(.parent = rn.btrn, .name = "stdout"));
stdout_set_defaults(&sot);
register_task(&sot.task);
rn.task.pre_select = r->pre_select;
rn.task.post_select = r->post_select;
- sprintf(rn.task.status, "receiver node");
+ sprintf(rn.task.status, "%s", r->name);
register_task(&rn.task);
ret = schedule(&s);
struct writer_node *wns;
loglevel = get_loglevel_by_name(conf.loglevel_arg);
- sit.btrn = btr_new_node("stdin", NULL /* stdin has no parent */, NULL, NULL);
+ sit.btrn = btr_new_node(&(struct btr_node_description)
+ EMBRACE(.name = "stdin"));
stdin_set_defaults(&sit);
register_task(&sit.task);
cwt->state = CWS_NEED_HEADER;
cwt->min_iqs = WAV_HEADER_LEN;
- cwt->btrn = btr_new_node("check wav", sit.btrn, check_wav_exec, cwt);
- sprintf(cwt->task.status, "check wav");
+ cwt->btrn = btr_new_node(&(struct btr_node_description)
+ EMBRACE(.name = "check_wav", .parent = sit.btrn,
+ .handler = check_wav_exec, .context = cwt));
+ sprintf(cwt->task.status, "check_wav");
cwt->task.pre_select = check_wav_pre_select;
cwt->task.post_select = check_wav_post_select;
cwt->task.error = 0;
char *name = make_message("%s writer", writer_names[wn->writer_num]);
int ret;
- wn->btrn = btr_new_node(name, parent, w->execute, wn);
+ wn->btrn = btr_new_node(&(struct btr_node_description)
+ EMBRACE(.name = name, .parent = parent,
+ .handler = w->execute, .context = wn));
strcpy(wn->task.status, name);
free(name);
ret = w->open(wn);