X-Git-Url: http://git.droids-corp.org/?p=protos%2Flibecoli.git;a=blobdiff_plain;f=src%2Fecoli_node.c;fp=src%2Fecoli_node.c;h=935f4e6c0cbc8e8ab0d6adf9d9513e5609ccd3ef;hp=07ef9e5e7d9e5f332006727c1f33c9aa76028715;hb=376f5016e3979247bf0db515e47df49ba1eb82ac;hpb=249ab86786242560a3da422eb59b96479d47859a diff --git a/src/ecoli_node.c b/src/ecoli_node.c index 07ef9e5..935f4e6 100644 --- a/src/ecoli_node.c +++ b/src/ecoli_node.c @@ -25,6 +25,20 @@ EC_LOG_TYPE_REGISTER(node); +struct ec_node { + const struct ec_node_type *type; + struct ec_config *config; /**< Generic configuration. */ + char *id; + char *desc; + struct ec_dict *attrs; + unsigned int refcnt; + struct { + enum ec_node_free_state state; /**< State of loop detection */ + unsigned int refcnt; /**< Number of reachable references + * starting from node beeing freed */ + } free; /**< Freeing state: used for loop detection */ +}; + static struct ec_node_type_list node_type_list = TAILQ_HEAD_INITIALIZER(node_type_list); @@ -44,8 +58,6 @@ ec_node_type_lookup(const char *name) int ec_node_type_register(struct ec_node_type *type) { - EC_CHECK_ARG(type->size >= sizeof(struct ec_node), -1, EINVAL); - if (ec_node_type_lookup(type->name) != NULL) { errno = EEXIST; return -1; @@ -75,7 +87,7 @@ struct ec_node *ec_node_from_type(const struct ec_node_type *type, const char *i goto fail; } - node = ec_calloc(1, type->size); + node = ec_calloc(1, sizeof(*node) + type->size); if (node == NULL) goto fail; @@ -428,6 +440,18 @@ int ec_node_check_type(const struct ec_node *node, return 0; } +const char *ec_node_get_type_name(const struct ec_node *node) +{ + return node->type->name; +} + +void *ec_node_priv(const struct ec_node *node) +{ + if (node == NULL) + return NULL; + return (void *)(node + 1); +} + /* LCOV_EXCL_START */ static int ec_node_testcase(void) {