4e8bc1e5e11219a9039f17b01ab1363efa703154
[protos/libecoli.git] / libecoli / ecoli_init.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright 2016, Olivier MATZ <zer0@droids-corp.org>
3  */
4
5 /**
6  * Register initialization routines.
7  */
8
9 #ifndef ECOLI_INIT_
10 #define ECOLI_INIT_
11
12 #include <sys/queue.h>
13
14 #include <ecoli_log.h>
15 #include <ecoli_node.h>
16
17 #define EC_INIT_REGISTER(t)                                             \
18         static void ec_init_init_##t(void);                             \
19         static void __attribute__((constructor, used))                  \
20         ec_init_init_##t(void)                                          \
21         {                                                               \
22                  ec_init_register(&t);                                  \
23         }
24
25 /**
26  * Type of init function. Return 0 on success, -1 on error.
27  */
28 typedef int (ec_init_t)(void);
29
30 TAILQ_HEAD(ec_init_list, ec_init);
31
32 /**
33  * A structure describing a test case.
34  */
35 struct ec_init {
36         TAILQ_ENTRY(ec_init) next;  /**< Next in list. */
37         ec_init_t *init;            /**< Init function. */
38         unsigned int priority;      /**< Priority (0=first, 99=last) */
39 };
40
41 /**
42  * Register an initialization function.
43  *
44  * @param init
45  *   A pointer to a ec_init structure to be registered.
46  */
47 void ec_init_register(struct ec_init *test);
48
49 /**
50  * Initialize ecoli library
51  *
52  * Must be called before any other function from libecoli, except
53  * ec_malloc_register().
54  *
55  * @return
56  *   0 on success, -1 on error (errno is set).
57  */
58 int ec_init(void);
59
60 #endif