api documentation for ec_parse
[protos/libecoli.git] / include / ecoli_init.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright 2016, Olivier MATZ <zer0@droids-corp.org>
3  */
4
5 /**
6  * @defgroup nodes Nodes
7  * @{
8  *
9  * @brief Register initialization routines.
10  */
11
12 #ifndef ECOLI_INIT_
13 #define ECOLI_INIT_
14
15 #include <sys/queue.h>
16
17 #include <ecoli_log.h>
18 #include <ecoli_node.h>
19
20 /**
21  * Register initialization and exit callbacks. These callbacks are
22  * ordered by priority: for initialization, the lowest priority is called
23  * first. For exit, the callbacks are invoked in reverse order.
24  */
25 #define EC_INIT_REGISTER(t)                                             \
26         static void ec_init_init_##t(void);                             \
27         static void __attribute__((constructor, used))                  \
28         ec_init_init_##t(void)                                          \
29         {                                                               \
30                  ec_init_register(&t);                                  \
31         }
32
33 /**
34  * Type of init function. Return 0 on success, -1 on error.
35  */
36 typedef int (ec_init_t)(void);
37
38 /**
39  * Type of exit function.
40  */
41 typedef void (ec_exit_t)(void);
42
43 TAILQ_HEAD(ec_init_list, ec_init);
44
45 /**
46  * A structure describing a test case.
47  */
48 struct ec_init {
49         TAILQ_ENTRY(ec_init) next;  /**< Next in list. */
50         ec_init_t *init;            /**< Init function. */
51         ec_exit_t *exit;            /**< Exit function. */
52         unsigned int priority;      /**< Priority (0=first, 99=last) */
53 };
54
55 /**
56  * Register an initialization function.
57  *
58  * @param init
59  *   A pointer to a ec_init structure to be registered.
60  */
61 void ec_init_register(struct ec_init *test);
62
63 /**
64  * Initialize ecoli library.
65  *
66  * Must be called before any other function from libecoli, except
67  * ec_malloc_register().
68  *
69  * @return
70  *   0 on success, -1 on error (errno is set).
71  */
72 int ec_init(void);
73
74 /**
75  * Uninitialize ecoli library.
76  */
77 void ec_exit(void);
78
79 #endif
80
81 /** @} */