Mercurial > ~mikael > mcabber > hg
comparison mcabber/mcabber/modules.h @ 1749:7ee390513463
Use api version for module checks
* Change module structures
* Check for supported api versions at loading time
* Add info command, description and module version fields
author | Myhailo Danylenko <isbear@ukrpost.net> |
---|---|
date | Sat, 13 Mar 2010 10:29:18 +0100 |
parents | 5093b5ca1572 |
children | d8442bcb33b7 |
comparison
equal
deleted
inserted
replaced
1748:51a23403cc80 | 1749:7ee390513463 |
---|---|
1 #ifndef __MCABBER_MODULES_H__ | 1 #ifndef __MCABBER_MODULES_H__ |
2 #define __MCABBER_MODULES_H__ 1 | 2 #define __MCABBER_MODULES_H__ 1 |
3 | 3 |
4 #include <glib.h> | 4 #include <glib.h> |
5 #include <gmodule.h> | |
6 #include <mcabber/config.h> // MCABBER_BRANCH, MCABBER_API_VERSION | |
5 | 7 |
6 // Module loading process looks like this: | 8 // Module loading process looks like this: |
7 // check, if module is loaded | 9 // check, if module is loaded |
8 // load module (+ run g_module_check_init) | 10 // load module (+ run g_module_check_init) |
9 // check <modulename>_info variable | 11 // check <modulename>_info variable |
18 // module unloaded | 20 // module unloaded |
19 | 21 |
20 typedef void (*module_init_t)(void); | 22 typedef void (*module_init_t)(void); |
21 typedef void (*module_uninit_t)(void); | 23 typedef void (*module_uninit_t)(void); |
22 | 24 |
23 // public module-describing structure | 25 // Structure, that module should provide |
24 typedef struct { | 26 typedef struct module_info_struct module_info_t; |
25 const gchar *mcabber_version; // Contains mcabber version string, that this module is written to work with | 27 struct module_info_struct { |
28 const gchar *branch; // Contains mcabber branch name, that this module is written to work with | |
26 module_init_t init; // Initialization callback to be called after all dependencies will be loaded | 29 module_init_t init; // Initialization callback to be called after all dependencies will be loaded |
27 module_uninit_t uninit; // Uninitialization callback to be called before module unloading | 30 module_uninit_t uninit; // Uninitialization callback to be called before module unloading |
28 const gchar **requires; // NULL-terminated list of module names, that must be loaded before this module | 31 const gchar **requires; // NULL-terminated list of module names, that must be loaded before this module |
29 } module_info_t; | 32 guint api; // Mcabber branch api version, that module is supposed to work with |
33 const gchar *version; // Module version string. Optional. | |
34 const gchar *description; // Module description. Can contain multiple lines. | |
35 module_info_t *next; // If module supports multiple branches, it can provide several branch structs. | |
36 }; | |
30 | 37 |
31 const gchar *module_load(const gchar *name, gboolean manual, gboolean force); | 38 const gchar *module_load(const gchar *name, gboolean manual, gboolean force); |
32 const gchar *module_unload(const gchar *name, gboolean manual, gboolean force); | 39 const gchar *module_unload(const gchar *name, gboolean manual, gboolean force); |
33 | 40 |
41 // Grey zone (these symbols are semi-private and are exposed only for compatibility modules) | |
42 | |
43 // Information about loaded module | |
44 typedef struct { | |
45 guint refcount; // Reference count | |
46 gboolean locked; // If true, one of references is manual | |
47 gchar *name; // Module name | |
48 GModule *module; // Module object | |
49 module_info_t *info; // Module information struct. May be NULL! | |
50 } loaded_module_t; | |
51 | |
52 // Registry of loaded modules | |
53 extern GSList *loaded_modules; | |
54 extern const gchar *mcabber_branch; | |
55 extern const guint mcabber_api_version; | |
56 | |
57 // Should be considered mcabber private and not a part of api | |
58 | |
34 void module_list_print(void); | 59 void module_list_print(void); |
60 void module_info_print(const gchar *name); | |
35 | 61 |
36 void modules_init(void); | 62 void modules_init(void); |
37 void modules_deinit(void); | 63 void modules_deinit(void); |
38 | 64 |
39 #endif | 65 #endif |