api documentation
[protos/libecoli.git] / include / ecoli_node_helper.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright 2018, Olivier MATZ <zer0@droids-corp.org>
3  */
4
5 /**
6  * Helpers that are commonly used in nodes.
7  */
8
9 #ifndef ECOLI_NODE_HELPERS_
10 #define ECOLI_NODE_HELPERS
11
12 struct ec_node;
13
14 /**
15  * Build a node table from a node list in a ec_config.
16  *
17  * The function takes a node configuration as parameter, which must be a
18  * node list. From it, a node table is built. A reference is taken for
19  * each node.
20  *
21  * On error, no reference is taken.
22  *
23  * @param config
24  *   The configuration (type must be a list of nodes). If it is
25  *   NULL, an error is returned.
26  * @param len
27  *   The length of the allocated table on success, or 0 on error.
28  * @return
29  *   The allocated node table, that must be freed by the caller:
30  *   each entry must be freed with ec_node_free() and the table
31  *   with ec_free(). On error, NULL is returned and errno is set.
32  */
33 struct ec_node **
34 ec_node_config_node_list_to_table(const struct ec_config *config,
35                                 size_t *len);
36
37 /**
38  * Build a list of config nodes from variable arguments.
39  *
40  * The va_list argument is a list of pointer to ec_node structures,
41  * terminated with EC_VA_END.
42  *
43  * This helper is used by nodes that contain a list of nodes,
44  * like "seq", "or", ...
45  *
46  * @param ap
47  *   List of pointer to ec_node structures, terminated with
48  *   EC_VA_END.
49  * @return
50  *   A pointer to an ec_config structure. In this case, the
51  *   nodes will be freed when the config structure will be freed.
52  *   On error, NULL is returned (and errno is set), and the
53  *   nodes are freed.
54  */
55 struct ec_config *
56 ec_node_config_node_list_from_vargs(va_list ap);
57
58 #endif