| 1 | /* This file is part of the Linux Trace Toolkit viewer |
| 2 | * Copyright (C) 2003-2004 Michel Dagenais |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License Version 2 as |
| 6 | * published by the Free Software Foundation; |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
| 12 | * |
| 13 | * You should have received a copy of the GNU General Public License |
| 14 | * along with this program; if not, write to the Free Software |
| 15 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, |
| 16 | * MA 02111-1307, USA. |
| 17 | */ |
| 18 | |
| 19 | #ifndef MODULES_H |
| 20 | #define MODULES_H |
| 21 | |
| 22 | #include <gmodule.h> |
| 23 | |
| 24 | /* lttv modules are shared object files, to be loaded dynamically, which |
| 25 | interact with the main module to provide additional capabilities. They |
| 26 | typically register hooks to be called at various places, read and add |
| 27 | attributes... |
| 28 | |
| 29 | Each lttv module must define a function named "init" with |
| 30 | the following signature. The init function may itself require other |
| 31 | modules using lttv_module_require. |
| 32 | |
| 33 | It should also define a function named "destroy" to free the |
| 34 | resources reserved during execution. |
| 35 | |
| 36 | Most modules will not use the command line arguments passed as init |
| 37 | arguments. It is easier to simply register command line options |
| 38 | to be parsed by the main module. However, some modules |
| 39 | may require an "early access" to these arguments, for example an embedded |
| 40 | python interpreter module which needs to know the modules written in |
| 41 | python to load. */ |
| 42 | |
| 43 | typedef struct _LttvModule LttvModule; |
| 44 | |
| 45 | typedef void (*LttvModuleInit)(LttvModule *self, int argc, char **argv); |
| 46 | |
| 47 | typedef void (*LttvModuleDestroy)(); |
| 48 | |
| 49 | |
| 50 | /* Additional module search paths may be defined. */ |
| 51 | |
| 52 | void lttv_module_path_add(const char *name); |
| 53 | |
| 54 | |
| 55 | /* Load (or increment its reference count if already loaded) the named module. |
| 56 | The init function of the module is executed upon loading. */ |
| 57 | |
| 58 | LttvModule *lttv_module_load(const char *name, int argc, char **argv); |
| 59 | |
| 60 | |
| 61 | /* Module m depends on the named module. The named module will be loaded, |
| 62 | remembered by m as a dependent, and unloaded when m is unloaded. */ |
| 63 | |
| 64 | LttvModule *lttv_module_require(LttvModule *m, const char *name, int argc, |
| 65 | char **argv); |
| 66 | |
| 67 | |
| 68 | /* Decrement the reference count of the specified module and unload it if 0. |
| 69 | The destroy function of the module is executed before unloading. |
| 70 | Dependent modules are unloaded. */ |
| 71 | |
| 72 | void lttv_module_unload(LttvModule *m) ; |
| 73 | |
| 74 | |
| 75 | /* List the loaded modules. The returned array contains nb elements and |
| 76 | must be freed with g_free. */ |
| 77 | |
| 78 | LttvModule **lttv_module_list(guint *nb); |
| 79 | |
| 80 | |
| 81 | /* Obtain information about a module. The list of dependent module is |
| 82 | returned and must be freed with g_free. */ |
| 83 | |
| 84 | LttvModule **lttv_module_info(LttvModule *m, const char **name, |
| 85 | guint *ref_count, guint *load_count, guint *nb_dependents); |
| 86 | |
| 87 | char * lttv_module_name(LttvModule *m); |
| 88 | #endif // MODULES_H |