author | Tero Marttila <terom@fixme.fi> |
Sun, 15 Mar 2009 01:17:22 +0200 | |
branch | modules |
changeset 55 | 6f7f6ae729d0 |
parent 54 | 9f74e924b01a |
child 56 | 942370000450 |
permissions | -rw-r--r-- |
54 | 1 |
#ifndef MODULE_H |
2 |
#define MODULE_H |
|
3 |
||
4 |
/** |
|
5 |
* @file |
|
6 |
* |
|
55
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
7 |
* Dynamically loadable modules for use with nexus. |
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
8 |
* |
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
9 |
* The modules are loaded using dlopen(), and hence should be standard dynamic libraries. Module initialization happens |
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
10 |
* using a module_init_func_t named "<name>_init", which should return some kind of context pointer, which can later be |
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
11 |
* used to perform other operations on the module. |
54 | 12 |
*/ |
13 |
#include "nexus.h" |
|
14 |
#include "error.h" |
|
15 |
||
16 |
#include <sys/queue.h> |
|
17 |
||
18 |
/** |
|
19 |
* Information required to load/identify a module. |
|
20 |
*/ |
|
21 |
struct module_info { |
|
22 |
/** Human-readable name */ |
|
23 |
const char *name; |
|
24 |
||
25 |
/** Filesystem path to the .so */ |
|
26 |
const char *path; |
|
27 |
}; |
|
28 |
||
29 |
/** |
|
30 |
* A loaded module. |
|
31 |
*/ |
|
32 |
struct module { |
|
33 |
/** The identifying info for the module */ |
|
34 |
struct module_info info; |
|
35 |
||
55
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
36 |
/** The dlopen handle */ |
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
37 |
void *handle; |
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
38 |
|
54 | 39 |
/** The module context object */ |
40 |
void *ctx; |
|
41 |
||
55
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
42 |
/** Pointer back to the modules struct used to load this */ |
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
43 |
struct modules *modules; |
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
44 |
|
54 | 45 |
/** Our entry in the list of modules */ |
55
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
46 |
TAILQ_ENTRY(module) modules_list; |
54 | 47 |
}; |
48 |
||
49 |
/** |
|
50 |
* A set of loaded modules, and functionality to load more |
|
51 |
*/ |
|
52 |
struct modules { |
|
53 |
/** The nexus in use */ |
|
54 |
struct nexus *nexus; |
|
55 |
||
56 |
/** List of loaded modules */ |
|
55
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
57 |
TAILQ_HEAD(module_ctx_modules, module) list; |
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
58 |
}; |
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
59 |
|
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
60 |
/** |
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
61 |
* Possible error codes |
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
62 |
*/ |
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
63 |
enum module_error_code { |
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
64 |
_ERR_MODULE_BEGIN = _ERR_MODULE, |
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
65 |
|
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
66 |
ERR_MODULE_OPEN, ///< dlopen() failed |
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
67 |
ERR_MODULE_NAME, ///< invalid module_info.name |
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
68 |
ERR_MODULE_SYM, ///< invalid symbol |
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
69 |
ERR_MODULE_INIT_FUNC, ///< invalid module_init_func_t |
54 | 70 |
}; |
71 |
||
72 |
/** |
|
73 |
* Module initialization function type |
|
55
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
74 |
* |
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
75 |
* @param modules the module-loading context, containing the nexus |
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
76 |
* @param err returned error info |
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
77 |
* @return context pointer, or NULL on errors |
54 | 78 |
*/ |
55
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
79 |
typedef void* (*module_init_func_t) (struct modules *modules, struct error_info *err); |
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
80 |
|
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
81 |
/** |
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
82 |
* Module configuration function type |
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
83 |
* |
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
84 |
* @param ctx the module's context pointer |
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
85 |
* @param name the name of the configuration setting |
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
86 |
* @param value the value of the configuration setting |
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
87 |
* @return error code |
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
88 |
*/ |
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
89 |
typedef err_t (*module_conf_func_t) (struct module *module, const char *name, char *value); |
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
90 |
|
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
91 |
/** |
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
92 |
* Maximum length of a module name |
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
93 |
*/ |
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
94 |
#define MODULE_NAME_MAX 24 |
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
95 |
|
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
96 |
/** |
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
97 |
* Maximum length of module symbol suffix |
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
98 |
*/ |
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
99 |
#define MODULE_SUFFIX_MAX 16 |
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
100 |
|
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
101 |
/** |
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
102 |
* Maximum length of symbol name name, including terminating NUL |
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
103 |
*/ |
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
104 |
#define MODULE_SYMBOL_MAX (MODULE_NAME_MAX + 1 + MODULE_SUFFIX_MAX + 1) |
54 | 105 |
|
106 |
/** |
|
107 |
* Create a new modules state |
|
108 |
*/ |
|
109 |
err_t modules_create (struct modules **modules_ptr, struct nexus *nexus); |
|
110 |
||
111 |
/** |
|
55
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
112 |
* Load a new module |
54 | 113 |
*/ |
55
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
114 |
err_t module_load (struct modules *modules, struct module **module, const struct module_info *info, struct error_info *err); |
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
115 |
|
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
116 |
/** |
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
117 |
* Set a module configuration option |
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
118 |
*/ |
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
119 |
err_t module_conf (struct module *module, const char *name, char *value); |
54 | 120 |
|
121 |
/** |
|
122 |
* Unload a module |
|
55
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
123 |
* |
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
124 |
* XXX: not implemented |
54 | 125 |
*/ |
126 |
err_t module_unload (struct module *module); |
|
127 |
||
128 |
#endif |