X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=src%2Fecoli_node_dynamic.c;h=2ce2e32c2d9d9246fd7edcb5404d41050bd23dd7;hb=67b4d8d2b2593e3e64a848ce548bc0fd76bc440a;hp=8a3edf3f3337bfb98db3e70a312386af72e4cb3a;hpb=18d03456d96f7a086a2ccc82ce97fcf056848d90;p=protos%2Flibecoli.git diff --git a/src/ecoli_node_dynamic.c b/src/ecoli_node_dynamic.c index 8a3edf3..2ce2e32 100644 --- a/src/ecoli_node_dynamic.c +++ b/src/ecoli_node_dynamic.c @@ -11,7 +11,7 @@ #include #include #include -#include +#include #include #include #include @@ -24,37 +24,36 @@ EC_LOG_TYPE_REGISTER(node_dynamic); struct ec_node_dynamic { - struct ec_node gen; ec_node_dynamic_build_t build; void *opaque; }; static int -ec_node_dynamic_parse(const struct ec_node *gen_node, - struct ec_parse *parse, +ec_node_dynamic_parse(const struct ec_node *node, + struct ec_pnode *parse, const struct ec_strvec *strvec) { - struct ec_node_dynamic *node = (struct ec_node_dynamic *)gen_node; + struct ec_node_dynamic *priv = ec_node_priv(node); struct ec_node *child = NULL; void (*node_free)(struct ec_node *) = ec_node_free; char key[64]; int ret = -1; - child = node->build(parse, node->opaque); + child = priv->build(parse, priv->opaque); if (child == NULL) goto fail; /* add the node pointer in the attributes, so it will be freed * when parse is freed */ snprintf(key, sizeof(key), "_dyn_%p", child); - ret = ec_keyval_set(ec_parse_get_attrs(parse), key, child, + ret = ec_dict_set(ec_pnode_get_attrs(parse), key, child, (void *)node_free); if (ret < 0) { child = NULL; /* already freed */ goto fail; } - return ec_node_parse_child(child, parse, strvec); + return ec_parse_child(child, parse, strvec); fail: ec_node_free(child); @@ -62,33 +61,33 @@ fail: } static int -ec_node_dynamic_complete(const struct ec_node *gen_node, +ec_node_dynamic_complete(const struct ec_node *node, struct ec_comp *comp, const struct ec_strvec *strvec) { - struct ec_node_dynamic *node = (struct ec_node_dynamic *)gen_node; - struct ec_parse *parse; + struct ec_node_dynamic *priv = ec_node_priv(node); + struct ec_pnode *parse; struct ec_node *child = NULL; void (*node_free)(struct ec_node *) = ec_node_free; char key[64]; int ret = -1; parse = ec_comp_get_state(comp); - child = node->build(parse, node->opaque); + child = priv->build(parse, priv->opaque); if (child == NULL) goto fail; /* add the node pointer in the attributes, so it will be freed * when parse is freed */ snprintf(key, sizeof(key), "_dyn_%p", child); - ret = ec_keyval_set(comp->attrs, key, child, + ret = ec_dict_set(ec_comp_get_attrs(comp), key, child, (void *)node_free); if (ret < 0) { child = NULL; /* already freed */ goto fail; } - return ec_node_complete_child(child, comp, strvec); + return ec_complete_child(child, comp, strvec); fail: ec_node_free(child); @@ -105,26 +104,26 @@ static struct ec_node_type ec_node_dynamic_type = { struct ec_node * ec_node_dynamic(const char *id, ec_node_dynamic_build_t build, void *opaque) { - struct ec_node *gen_node = NULL; - struct ec_node_dynamic *node; + struct ec_node *node = NULL; + struct ec_node_dynamic *priv; if (build == NULL) { errno = EINVAL; goto fail; } - gen_node = ec_node_from_type(&ec_node_dynamic_type, id); - if (gen_node == NULL) + node = ec_node_from_type(&ec_node_dynamic_type, id); + if (node == NULL) goto fail; - node = (struct ec_node_dynamic *)gen_node; - node->build = build; - node->opaque = opaque; + priv = ec_node_priv(node); + priv->build = build; + priv->opaque = opaque; - return gen_node; + return node; fail: - ec_node_free(gen_node); + ec_node_free(node); return NULL; } @@ -132,18 +131,19 @@ fail: EC_NODE_TYPE_REGISTER(ec_node_dynamic_type); static struct ec_node * -build_counter(struct ec_parse *parse, void *opaque) +build_counter(struct ec_pnode *parse, void *opaque) { const struct ec_node *node; - struct ec_parse *iter; + struct ec_pnode *root, *iter; unsigned int count = 0; char buf[32]; (void)opaque; - for (iter = ec_parse_get_root(parse); iter != NULL; - iter = ec_parse_iter_next(iter)) { - node = ec_parse_get_node(iter); - if (node->id && !strcmp(node->id, "my-id")) + root = ec_pnode_get_root(parse); + for (iter = root; iter != NULL; + iter = EC_PNODE_ITER_NEXT(root, iter, 1)) { + node = ec_pnode_get_node(iter); + if (!strcmp(ec_node_id(node), "my-id")) count++; } snprintf(buf, sizeof(buf), "count-%u", count); @@ -171,11 +171,11 @@ static int ec_node_dynamic_testcase(void) /* test completion */ testres |= EC_TEST_CHECK_COMPLETE(node, - "c", EC_NODE_ENDLIST, - "count-0", EC_NODE_ENDLIST); + "c", EC_VA_END, + "count-0", EC_VA_END); testres |= EC_TEST_CHECK_COMPLETE(node, - "count-0", "", EC_NODE_ENDLIST, - "count-1", EC_NODE_ENDLIST, + "count-0", "", EC_VA_END, + "count-1", EC_VA_END, "count-1"); ec_node_free(node);