James Kuszmaul | 82f6c04 | 2021-01-17 11:30:16 -0800 | [diff] [blame^] | 1 | /** |
| 2 | * @file re_mod.h Interface to loadable modules |
| 3 | * |
| 4 | * Copyright (C) 2010 Creytiv.com |
| 5 | */ |
| 6 | |
| 7 | |
| 8 | /** |
| 9 | * @def MOD_PRE |
| 10 | * |
| 11 | * Module Prefix |
| 12 | * |
| 13 | * @def MOD_EXT |
| 14 | * |
| 15 | * Module Extension |
| 16 | */ |
| 17 | #if defined (WIN32) |
| 18 | #define MOD_PRE "" |
| 19 | #define MOD_EXT ".dll" |
| 20 | #else |
| 21 | #define MOD_PRE "" |
| 22 | #define MOD_EXT ".so" |
| 23 | #endif |
| 24 | |
| 25 | |
| 26 | /** Symbol to enable exporting of functions from a module */ |
| 27 | #ifdef WIN32 |
| 28 | #define EXPORT_SYM __declspec(dllexport) |
| 29 | #else |
| 30 | #define EXPORT_SYM |
| 31 | #endif |
| 32 | |
| 33 | |
| 34 | /* ----- Module API ----- */ |
| 35 | |
| 36 | |
| 37 | /** |
| 38 | * Defines the module initialisation handler |
| 39 | * |
| 40 | * @return 0 for success, otherwise errorcode |
| 41 | */ |
| 42 | typedef int (mod_init_h)(void); |
| 43 | |
| 44 | /** |
| 45 | * Defines the module close handler |
| 46 | * |
| 47 | * @return 0 for success, otherwise errorcode |
| 48 | */ |
| 49 | typedef int (mod_close_h)(void); |
| 50 | |
| 51 | |
| 52 | struct mod; |
| 53 | struct re_printf; |
| 54 | |
| 55 | |
| 56 | /** Defines the module export */ |
| 57 | struct mod_export { |
| 58 | const char *name; /**< Module name */ |
| 59 | const char *type; /**< Module type */ |
| 60 | mod_init_h *init; /**< Module init handler */ |
| 61 | mod_close_h *close; /**< Module close handler */ |
| 62 | }; |
| 63 | |
| 64 | |
| 65 | /* ----- Application API ----- */ |
| 66 | |
| 67 | void mod_init(void); |
| 68 | void mod_close(void); |
| 69 | |
| 70 | int mod_load(struct mod **mp, const char *name); |
| 71 | int mod_add(struct mod **mp, const struct mod_export *me); |
| 72 | struct mod *mod_find(const char *name); |
| 73 | const struct mod_export *mod_export(const struct mod *m); |
| 74 | struct list *mod_list(void); |
| 75 | int mod_debug(struct re_printf *pf, void *unused); |