28 #ifndef _ASTERISK_MODULE_H
29 #define _ASTERISK_MODULE_H
33 #if defined(__cplusplus) || defined(c_plusplus)
38 #define ASTERISK_GPL_KEY \
39 "This paragraph is copyright (c) 2006 by Digium, Inc. \
40 In order for your module to load, it must return this \
41 key via a function called \"key\". Any code which \
42 includes this paragraph must be licensed under the GNU \
43 General Public License version 2 or later (at your \
44 option). In addition to Digium's general reservations \
45 of rights, Digium expressly reserves the right to \
46 allow other parties to license this paragraph under \
47 different terms. Any use of Digium, Inc. trademarks or \
48 logos (including \"Asterisk\" or \"Digium\") without \
49 express written permission of Digium, Inc. is prohibited.\n"
51 #define AST_MODULE_CONFIG "modules.conf"
191 struct ast_module_user_list;
268 #define ast_module_user_add(chan) __ast_module_user_add(ast_module_info->self, chan)
269 #define ast_module_user_remove(user) __ast_module_user_remove(ast_module_info->self, user)
270 #define ast_module_user_hangup_all() __ast_module_user_hangup_all(ast_module_info->self)
275 #if defined(__cplusplus) || defined(c_plusplus)
276 #define AST_MODULE_INFO(keystr, flags_to_set, desc, load_func, unload_func, reload_func, load_pri) \
277 static struct ast_module_info __mod_info = { \
291 static void __attribute__((constructor)) __reg_module(void) \
293 ast_module_register(&__mod_info); \
295 static void __attribute__((destructor)) __unreg_module(void) \
297 ast_module_unregister(&__mod_info); \
299 static const __attribute__((unused)) struct ast_module_info *ast_module_info = &__mod_info
301 #define AST_MODULE_INFO_STANDARD(keystr, desc) \
302 AST_MODULE_INFO(keystr, AST_MODFLAG_LOAD_ORDER, desc, \
315 #if !defined(EMBEDDED_MODULE)
316 #define __MODULE_INFO_SECTION
317 #define __MODULE_INFO_GLOBALS
326 #define __MODULE_INFO_SECTION __attribute__((section(".embed_module")))
327 #define __MODULE_INFO_GLOBALS .backup_globals = __backup_globals, .restore_globals = __restore_globals,
329 #define make_var_sub(mod, type) __ ## mod ## _ ## type
330 #define make_var(mod, type) make_var_sub(mod, type)
332 extern void make_var(EMBEDDED_MODULE, bss_start);
333 extern void make_var(EMBEDDED_MODULE, bss_end);
334 extern void make_var(EMBEDDED_MODULE, data_start);
335 extern void make_var(EMBEDDED_MODULE, data_end);
337 static void * __attribute__((section(
".embed_module"))) __global_backup;
339 static
int __backup_globals(
void)
341 size_t data_size = & make_var(EMBEDDED_MODULE, data_end) - & make_var(EMBEDDED_MODULE, data_start);
349 if (!(__global_backup =
ast_malloc(data_size)))
352 memcpy(__global_backup, & make_var(EMBEDDED_MODULE, data_start), data_size);
357 static void __restore_globals(
void)
359 size_t data_size = & make_var(EMBEDDED_MODULE, data_end) - & make_var(EMBEDDED_MODULE, data_start);
360 size_t bss_size = & make_var(EMBEDDED_MODULE, bss_end) - & make_var(EMBEDDED_MODULE, bss_start);
363 memset(& make_var(EMBEDDED_MODULE, bss_start), 0, bss_size);
365 if (!data_size || !__global_backup)
368 memcpy(& make_var(EMBEDDED_MODULE, data_start), __global_backup, data_size);
374 #define AST_MODULE_INFO(keystr, flags_to_set, desc, fields...) \
375 static struct ast_module_info \
376 __MODULE_INFO_SECTION \
378 __MODULE_INFO_GLOBALS \
379 .name = AST_MODULE, \
380 .flags = flags_to_set, \
381 .description = desc, \
383 .buildopt_sum = AST_BUILDOPT_SUM, \
386 static void __attribute__((constructor)) __reg_module(void) \
388 ast_module_register(&__mod_info); \
390 static void __attribute__((destructor)) __unreg_module(void) \
392 ast_module_unregister(&__mod_info); \
394 static const struct ast_module_info *ast_module_info = &__mod_info
396 #define AST_MODULE_INFO_STANDARD(keystr, desc) \
397 AST_MODULE_INFO(keystr, AST_MODFLAG_LOAD_ORDER, desc, \
398 .load = load_module, \
399 .unload = unload_module, \
400 .load_pri = AST_MODPRI_DEFAULT, \
421 #define ast_register_application(app, execute, synopsis, description) ast_register_application2(app, execute, synopsis, description, ast_module_info->self)
437 #define ast_register_application_xml(app, execute) ast_register_application(app, execute, NULL, NULL)
459 const char *
synopsis,
const char *description,
void *mod);
474 #if defined(__cplusplus) || defined(c_plusplus)
Main Channel structure associated with a channel.
void ast_module_unref(struct ast_module *)
enum ast_module_load_result ast_load_resource(const char *resource_name)
Load a module.
void __ast_module_user_hangup_all(struct ast_module *)
void __ast_module_user_remove(struct ast_module *, struct ast_module_user *)
enum ast_module_load_result(* load)(void)
void ast_module_shutdown(void)
Run the unload() callback for all loaded modules.
void ast_update_use_count(void)
Notify when usecount has been changed.
int ast_unregister_application(const char *app)
Unregister an application.
int ast_module_check(const char *name)
Check if module with the name given is loaded.
void ast_module_unregister(const struct ast_module_info *)
char * ast_module_helper(const char *line, const char *word, int pos, int state, int rpos, int needsreload)
Match modules names for the Asterisk cli.
struct ast_module_user * __ast_module_user_add(struct ast_module *, struct ast_channel *)
int ast_loader_unregister(int(*updater)(void))
Remove a procedure to be run when modules are updated.
int ast_unload_resource(const char *resource_name, enum ast_module_unload_mode)
Unload a module.
int ast_loader_register(int(*updater)(void))
Add a procedure to be run when modules have been updated.
const char * ast_module_name(const struct ast_module *mod)
Get the name of a module.
int(* backup_globals)(void)
int ast_update_module_list(int(*modentry)(const char *module, const char *description, int usecnt, const char *like), const char *like)
Ask for a list of modules, descriptions, and use counts.
void(* restore_globals)(void)
int ast_register_application2(const char *app, int(*execute)(struct ast_channel *, const char *), const char *synopsis, const char *description, void *mod)
Register an application.
void ast_module_register(const struct ast_module_info *)
const char buildopt_sum[33]
struct ast_module * ast_module_ref(struct ast_module *)