#ifndef lib_init_h #define lib_init_h /* Cesar project {{{ * * Copyright (C) 2009 Spidcom * * <<>> * * }}} */ /** * \file lib/init.h * \brief Init compiled lib modules. * \ingroup lib * * Permit to modules to register their init function in this init module * and particularly inside a specified init list. * The init programmer will be able to launch a specific list of init function. * * Practical example: * * Supposing you have a module called "bob" who is a part of the HAL list to * initialise and you may a bob_init function. Once your bob_init function * is defined, you have to put this line: * * INIT_REGISTER (INIT_LIST_HAL, bob) * * When you want to launch all initialise function of a specific list, you may * call init_exec () function with the list in argument. In this example: * * init_exec (INIT_LIST_HAL); * */ /** All lists. */ enum init_list_id_t { INIT_LIST_HAL, INIT_LIST_HAL_SERVICES, INIT_LIST_SERVICES, INIT_LIST_NB }; typedef enum init_list_id_t init_list_id_t; /** List structure. */ struct init_list_t { /** Next function to call. */ struct init_list_t *next; /** Init function to call. */ void (*init_function) (void); }; typedef struct init_list_t init_list_t; /** * INIT_REGISTER is a macro who need to be inserted in each module * in order to get registered inside the init system. */ #define INIT_REGISTER(list, module) \ void module ## _init_register (void) __attribute__ ((constructor)); \ void module ## _init_register (void) \ { \ static init_list_t i; \ i.init_function = &module ## _init; \ init_register (list, &i); \ } /** * Register a module's init to a specific list. * \param list list id, see init_enum for defined lists * \param module a list node containing a pointer to an init function * * This function may be called during the constructor function of * a module to be added to the list before the main function. */ void init_register (int list, init_list_t *module); /** * Execute all functions registered in a specific list. * \param list List ID, see init_enum for defined lists */ void init_exec (int list); #endif /* lib_init_h */