67 */ |
67 */ |
68 struct module { |
68 struct module { |
69 /** The identifying info for the module */ |
69 /** The identifying info for the module */ |
70 struct module_info info; |
70 struct module_info info; |
71 |
71 |
|
72 /** Possible dynamically allocated path */ |
|
73 char *path_buf; |
|
74 |
72 /** The dlopen handle */ |
75 /** The dlopen handle */ |
73 void *handle; |
76 void *handle; |
74 |
77 |
75 /** The module entry point */ |
78 /** The module entry point */ |
76 struct module_desc *desc; |
79 struct module_desc *desc; |
95 */ |
98 */ |
96 struct modules { |
99 struct modules { |
97 /** The nexus in use */ |
100 /** The nexus in use */ |
98 struct nexus *nexus; |
101 struct nexus *nexus; |
99 |
102 |
|
103 /** Module search path */ |
|
104 const char *path; |
|
105 |
100 /** List of loaded modules */ |
106 /** List of loaded modules */ |
101 TAILQ_HEAD(module_ctx_modules, module) list; |
107 TAILQ_HEAD(module_ctx_modules, module) list; |
102 }; |
108 }; |
103 |
109 |
104 /** |
110 /** |
105 * Possible error codes |
111 * Possible error codes |
106 */ |
112 */ |
107 enum module_error_code { |
113 enum module_error_code { |
108 _ERR_MODULE_BEGIN = _ERR_MODULE, |
114 _ERR_MODULE_BEGIN = _ERR_MODULE, |
109 |
115 |
|
116 ERR_MODULE_NAME, ///< invalid module_info.name |
|
117 ERR_MODULE_DUP, ///< module already opened |
|
118 ERR_MODULE_PATH, ///< resolving the path failed |
110 ERR_MODULE_OPEN, ///< dlopen() failed |
119 ERR_MODULE_OPEN, ///< dlopen() failed |
111 ERR_MODULE_NAME, ///< invalid module_info.name |
|
112 ERR_MODULE_SYM, ///< invalid symbol |
120 ERR_MODULE_SYM, ///< invalid symbol |
113 ERR_MODULE_INIT_FUNC, ///< invalid module_init_func_t |
121 ERR_MODULE_INIT_FUNC, ///< invalid module_init_func_t |
114 ERR_MODULE_CONF, ///< value error in configuration data |
122 ERR_MODULE_CONF, ///< value error in configuration data |
115 }; |
123 }; |
116 |
124 |
134 * Create a new modules state |
142 * Create a new modules state |
135 */ |
143 */ |
136 err_t modules_create (struct modules **modules_ptr, struct nexus *nexus); |
144 err_t modules_create (struct modules **modules_ptr, struct nexus *nexus); |
137 |
145 |
138 /** |
146 /** |
|
147 * Set a search path for finding modules by name. The given string won't be copied. |
|
148 * |
|
149 * A module called "<name>" will be searched for at "<path>/mod_<name>.so" |
|
150 * |
|
151 * If path is NULL, this doesn't change anything. This returns the old path, which may be NULL. |
|
152 * |
|
153 * @param modules the modules state |
|
154 * @param path the new search path, or NULL to just get the old one |
|
155 * @return the old search path |
|
156 */ |
|
157 const char* modules_path (struct modules *modules, const char *path); |
|
158 |
|
159 /** |
139 * Return a module's name |
160 * Return a module's name |
140 */ |
161 */ |
141 const char* module_name (struct module *module); |
162 const char* module_name (struct module *module); |
142 |
163 |
143 /** |
164 /** |
144 * Load a new module |
165 * Load a new module, as named by info. |
|
166 * |
|
167 * If info->path is not given, the module will be searched for using the path set by modules_path(). |
145 * |
168 * |
146 * @param modules the module-loading context |
169 * @param modules the module-loading context |
147 * @param module_ptr return the new module via this, if not NULL |
170 * @param module_ptr return the new module via this, if not NULL |
148 * @param info the info required to identify and load the module |
171 * @param info the info required to identify and load the module |
149 * @param err return error info |
172 * @param err return error info |