#include "asterisk/utils.h"
Go to the source code of this file.
Data Structures | |
struct | ast_module_info |
Defines | |
#define | __MODULE_INFO_GLOBALS |
#define | __MODULE_INFO_SECTION |
#define | AST_MODULE_CONFIG "modules.conf" |
Module configuration file. | |
#define | AST_MODULE_INFO(keystr, flags_to_set, desc, fields...) |
#define | AST_MODULE_INFO_STANDARD(keystr, desc) |
#define | ast_module_user_add(chan) __ast_module_user_add(ast_module_info->self, chan) |
#define | ast_module_user_hangup_all() __ast_module_user_hangup_all(ast_module_info->self) |
#define | ast_module_user_remove(user) __ast_module_user_remove(ast_module_info->self, user) |
#define | ast_register_application(app, execute, synopsis, description) ast_register_application2(app, execute, synopsis, description, ast_module_info->self) |
Register an application. | |
#define | ASTERISK_GPL_KEY "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" |
The text the key() function should return. | |
Enumerations | |
enum | ast_module_flags { AST_MODFLAG_DEFAULT = 0, AST_MODFLAG_GLOBAL_SYMBOLS = (1 << 0) } |
enum | ast_module_load_result { AST_MODULE_LOAD_SUCCESS = 0, AST_MODULE_LOAD_DECLINE = 1, AST_MODULE_LOAD_SKIP = 2, AST_MODULE_LOAD_FAILURE = -1 } |
enum | ast_module_unload_mode { AST_FORCE_SOFT = 0, AST_FORCE_FIRM = 1, AST_FORCE_HARD = 2 } |
Functions | |
ast_module_user * | __ast_module_user_add (struct ast_module *, struct ast_channel *) |
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 | ast_load_resource (const char *resource_name) |
Load a module. | |
int | ast_loader_register (int(*updater)(void)) |
Add a procedure to be run when modules have been updated. | |
int | ast_loader_unregister (int(*updater)(void)) |
Remove a procedure to be run when modules are updated. | |
int | ast_module_check (const char *name) |
Check if module with the name given is loaded. | |
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. | |
ast_module * | ast_module_ref (struct ast_module *) |
void | ast_module_register (const struct ast_module_info *) |
void | ast_module_shutdown (void) |
Run the unload() callback for all loaded modules. | |
void | ast_module_unref (struct ast_module *) |
void | ast_module_unregister (const struct ast_module_info *) |
int | ast_register_application2 (const char *app, int(*execute)(struct ast_channel *, void *), const char *synopsis, const char *description, void *mod) |
Register an application. | |
int | ast_unload_resource (const char *resource_name, enum ast_module_unload_mode) |
Unload a module. | |
int | ast_unregister_application (const char *app) |
Unregister an application. | |
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 | ast_update_use_count (void) |
Notify when usecount has been changed. | |
Variables | |
static struct ast_module_info * | ast_module_info |
This file contains the definitons for functions Asterisk modules should provide and some other module related functions.
Definition in file module.h.
#define AST_MODULE_CONFIG "modules.conf" |
#define AST_MODULE_INFO | ( | keystr, | |||
flags_to_set, | |||||
desc, | |||||
fields... | ) |
#define AST_MODULE_INFO_STANDARD | ( | keystr, | |||
desc | ) |
Value:
AST_MODULE_INFO(keystr, AST_MODFLAG_DEFAULT, desc, \ .load = load_module, \ .unload = unload_module, \ )
#define ast_module_user_add | ( | chan | ) | __ast_module_user_add(ast_module_info->self, chan) |
Definition at line 231 of file module.h.
Referenced by canmatch(), dundi_query_read(), dundi_result_read(), dundifunc_read(), exec(), exists(), local_new(), login_exec(), matchmore(), nbs_new(), smdi_msg_read(), and smdi_msg_retrieve_read().
#define ast_module_user_hangup_all | ( | ) | __ast_module_user_hangup_all(ast_module_info->self) |
#define ast_module_user_remove | ( | user | ) | __ast_module_user_remove(ast_module_info->self, user) |
Definition at line 232 of file module.h.
Referenced by canmatch(), dundi_query_read(), dundi_result_read(), dundifunc_read(), exec(), exists(), local_hangup(), login_exec(), matchmore(), nbs_destroy(), smdi_msg_read(), and smdi_msg_retrieve_read().
#define ast_register_application | ( | app, | |||
execute, | |||||
synopsis, | |||||
description | ) | ast_register_application2(app, execute, synopsis, description, ast_module_info->self) |
Register an application.
app | Short name of the application | |
execute | a function callback to execute the application. It should return non-zero if the channel needs to be hung up. | |
synopsis | a short description (one line synopsis) of the application | |
description | long description with all of the details about the use of the application |
0 | success | |
-1 | failure. |
Definition at line 381 of file module.h.
Referenced by load_module().
#define ASTERISK_GPL_KEY "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" |
enum ast_module_flags |
Definition at line 189 of file module.h.
00189 { 00190 AST_MODFLAG_DEFAULT = 0, 00191 AST_MODFLAG_GLOBAL_SYMBOLS = (1 << 0), 00192 };
Definition at line 60 of file module.h.
00060 { 00061 AST_MODULE_LOAD_SUCCESS = 0, /*!< Module loaded and configured */ 00062 AST_MODULE_LOAD_DECLINE = 1, /*!< Module is not configured */ 00063 AST_MODULE_LOAD_SKIP = 2, /*!< Module was skipped for some reason */ 00064 AST_MODULE_LOAD_FAILURE = -1, /*!< Module could not be loaded properly */ 00065 };
Definition at line 53 of file module.h.
00053 { 00054 AST_FORCE_SOFT = 0, /*!< Softly unload a module, only if not in use */ 00055 AST_FORCE_FIRM = 1, /*!< Firmly unload a module, even if in use */ 00056 AST_FORCE_HARD = 2, /*!< as FIRM, plus dlclose() on the module. Not recommended 00057 as it may cause crashes */ 00058 };
struct ast_module_user* __ast_module_user_add | ( | struct ast_module * | , | |
struct ast_channel * | ||||
) |
Definition at line 185 of file loader.c.
References ast_atomic_fetchadd_int(), ast_calloc, AST_LIST_INSERT_HEAD, AST_LIST_LOCK, AST_LIST_UNLOCK, ast_update_use_count(), ast_module_user::chan, ast_module_user::entry, ast_module::usecount, and ast_module::users.
Referenced by ast_func_read(), ast_func_write(), and pbx_exec().
00187 { 00188 struct ast_module_user *u = ast_calloc(1, sizeof(*u)); 00189 00190 if (!u) 00191 return NULL; 00192 00193 u->chan = chan; 00194 00195 AST_LIST_LOCK(&mod->users); 00196 AST_LIST_INSERT_HEAD(&mod->users, u, entry); 00197 AST_LIST_UNLOCK(&mod->users); 00198 00199 ast_atomic_fetchadd_int(&mod->usecount, +1); 00200 00201 ast_update_use_count(); 00202 00203 return u; 00204 }
void __ast_module_user_hangup_all | ( | struct ast_module * | ) |
Definition at line 217 of file loader.c.
References ast_atomic_fetchadd_int(), ast_free, AST_LIST_LOCK, AST_LIST_REMOVE_HEAD, AST_LIST_UNLOCK, ast_softhangup(), AST_SOFTHANGUP_APPUNLOAD, ast_update_use_count(), ast_module_user::chan, ast_module_user::entry, ast_module::usecount, and ast_module::users.
Referenced by ast_unload_resource().
00218 { 00219 struct ast_module_user *u; 00220 00221 AST_LIST_LOCK(&mod->users); 00222 while ((u = AST_LIST_REMOVE_HEAD(&mod->users, entry))) { 00223 ast_softhangup(u->chan, AST_SOFTHANGUP_APPUNLOAD); 00224 ast_atomic_fetchadd_int(&mod->usecount, -1); 00225 ast_free(u); 00226 } 00227 AST_LIST_UNLOCK(&mod->users); 00228 00229 ast_update_use_count(); 00230 }
void __ast_module_user_remove | ( | struct ast_module * | , | |
struct ast_module_user * | ||||
) |
Definition at line 206 of file loader.c.
References ast_atomic_fetchadd_int(), ast_free, AST_LIST_LOCK, AST_LIST_REMOVE, AST_LIST_UNLOCK, ast_update_use_count(), ast_module_user::entry, ast_module::usecount, and ast_module::users.
Referenced by ast_func_read(), ast_func_write(), and pbx_exec().
00207 { 00208 AST_LIST_LOCK(&mod->users); 00209 AST_LIST_REMOVE(&mod->users, u, entry); 00210 AST_LIST_UNLOCK(&mod->users); 00211 ast_atomic_fetchadd_int(&mod->usecount, -1); 00212 ast_free(u); 00213 00214 ast_update_use_count(); 00215 }
enum ast_module_load_result ast_load_resource | ( | const char * | resource_name | ) |
Load a module.
resource_name | The name of the module to load. |
Definition at line 710 of file loader.c.
References AST_LIST_LOCK, AST_LIST_UNLOCK, and load_resource().
Referenced by file_ok_sel(), handle_load(), load_module(), manager_moduleload(), and reload().
00711 { 00712 int res; 00713 AST_LIST_LOCK(&module_list); 00714 res = load_resource(resource_name, 0); 00715 AST_LIST_UNLOCK(&module_list); 00716 00717 return res; 00718 }
int ast_loader_register | ( | int(*)(void) | updater | ) |
Add a procedure to be run when modules have been updated.
updater | The function to run when modules have been updated. |
0 | on success | |
-1 | on failure. |
Definition at line 964 of file loader.c.
References AST_LIST_INSERT_HEAD, AST_LIST_LOCK, AST_LIST_UNLOCK, and ast_malloc.
Referenced by show_console().
00965 { 00966 struct loadupdate *tmp; 00967 00968 if (!(tmp = ast_malloc(sizeof(*tmp)))) 00969 return -1; 00970 00971 tmp->updater = v; 00972 AST_LIST_LOCK(&updaters); 00973 AST_LIST_INSERT_HEAD(&updaters, tmp, entry); 00974 AST_LIST_UNLOCK(&updaters); 00975 00976 return 0; 00977 }
int ast_loader_unregister | ( | int(*)(void) | updater | ) |
Remove a procedure to be run when modules are updated.
updater | The updater function to unregister. |
0 | on success | |
-1 | on failure. |
Definition at line 979 of file loader.c.
References AST_LIST_LOCK, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, AST_LIST_UNLOCK, and loadupdate::updater.
Referenced by exit_now().
00980 { 00981 struct loadupdate *cur; 00982 00983 AST_LIST_LOCK(&updaters); 00984 AST_LIST_TRAVERSE_SAFE_BEGIN(&updaters, cur, entry) { 00985 if (cur->updater == v) { 00986 AST_LIST_REMOVE_CURRENT(entry); 00987 break; 00988 } 00989 } 00990 AST_LIST_TRAVERSE_SAFE_END; 00991 AST_LIST_UNLOCK(&updaters); 00992 00993 return cur ? 0 : -1; 00994 }
int ast_module_check | ( | const char * | name | ) |
Check if module with the name given is loaded.
name | Module name, like "chan_sip.so" |
1 | if true | |
0 | if false |
Definition at line 951 of file loader.c.
References ast_strlen_zero(), and find_resource().
Referenced by ifmodule_read(), load_module(), manager_modulecheck(), and unload_module().
00952 { 00953 struct ast_module *cur; 00954 00955 if (ast_strlen_zero(name)) 00956 return 0; /* FALSE */ 00957 00958 cur = find_resource(name, 1); 00959 00960 return (cur != NULL); 00961 }
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.
line | Unused by this function, but this should be the line we are matching. | |
word | The partial name to match. | |
pos | The position the word we are completing is in. | |
state | The possible match to return. | |
rpos | The position we should be matching. This should be the same as pos. | |
needsreload | This should be 1 if we need to reload this module and 0 otherwise. This function will only return modules that are reloadble if this is 1. |
A | possible completion of the partial match. | |
NULL | if no matches were found. |
Definition at line 518 of file loader.c.
References AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, ast_strdup, ast_module_user::entry, ast_module::info, name, ast_module_info::reload, and ast_module::resource.
Referenced by handle_modlist(), handle_reload(), handle_unload(), and load_module().
00519 { 00520 struct ast_module *cur; 00521 int i, which=0, l = strlen(word); 00522 char *ret = NULL; 00523 00524 if (pos != rpos) 00525 return NULL; 00526 00527 AST_LIST_LOCK(&module_list); 00528 AST_LIST_TRAVERSE(&module_list, cur, entry) { 00529 if (!strncasecmp(word, cur->resource, l) && 00530 (cur->info->reload || !needsreload) && 00531 ++which > state) { 00532 ret = ast_strdup(cur->resource); 00533 break; 00534 } 00535 } 00536 AST_LIST_UNLOCK(&module_list); 00537 00538 if (!ret) { 00539 for (i=0; !ret && reload_classes[i].name; i++) { 00540 if (!strncasecmp(word, reload_classes[i].name, l) && ++which > state) 00541 ret = ast_strdup(reload_classes[i].name); 00542 } 00543 } 00544 00545 return ret; 00546 }
struct ast_module* ast_module_ref | ( | struct ast_module * | ) |
Definition at line 996 of file loader.c.
References ast_atomic_fetchadd_int(), ast_update_use_count(), and ast_module::usecount.
Referenced by __oh323_new(), agi_handle_command(), alsa_new(), ast_agi_register(), ast_iax2_new(), ast_timer_open(), dahdi_new(), fn_wrapper(), gtalk_new(), handle_cli_file_convert(), handle_orig(), mgcp_new(), newpvt(), oss_new(), phone_check_exception(), phone_new(), sip_new(), skinny_new(), and usbradio_new().
00997 { 00998 ast_atomic_fetchadd_int(&mod->usecount, +1); 00999 ast_update_use_count(); 01000 01001 return mod; 01002 }
void ast_module_register | ( | const struct ast_module_info * | ) |
Definition at line 123 of file loader.c.
References ast_calloc, AST_LIST_HEAD_INIT, AST_LIST_INSERT_TAIL, AST_LIST_LOCK, AST_LIST_UNLOCK, embedding, ast_module_user::entry, ast_module::info, resource_being_loaded, and ast_module::users.
00124 { 00125 struct ast_module *mod; 00126 00127 if (embedding) { 00128 if (!(mod = ast_calloc(1, sizeof(*mod) + strlen(info->name) + 1))) 00129 return; 00130 strcpy(mod->resource, info->name); 00131 } else { 00132 mod = resource_being_loaded; 00133 } 00134 00135 mod->info = info; 00136 AST_LIST_HEAD_INIT(&mod->users); 00137 00138 /* during startup, before the loader has been initialized, 00139 there are no threads, so there is no need to take the lock 00140 on this list to manipulate it. it is also possible that it 00141 might be unsafe to use the list lock at that point... so 00142 let's avoid it altogether 00143 */ 00144 if (embedding) { 00145 AST_LIST_INSERT_TAIL(&embedded_module_list, mod, entry); 00146 } else { 00147 AST_LIST_LOCK(&module_list); 00148 /* it is paramount that the new entry be placed at the tail of 00149 the list, otherwise the code that uses dlopen() to load 00150 dynamic modules won't be able to find out if the module it 00151 just opened was registered or failed to load 00152 */ 00153 AST_LIST_INSERT_TAIL(&module_list, mod, entry); 00154 AST_LIST_UNLOCK(&module_list); 00155 } 00156 00157 /* give the module a copy of its own handle, for later use in registrations and the like */ 00158 *((struct ast_module **) &(info->self)) = mod; 00159 }
void ast_module_shutdown | ( | void | ) |
Run the unload() callback for all loaded modules.
This function should be called when Asterisk is shutting down gracefully.
Definition at line 433 of file loader.c.
References AST_LIST_HEAD_DESTROY, AST_LIST_HEAD_NOLOCK_STATIC, AST_LIST_INSERT_HEAD, AST_LIST_LOCK, AST_LIST_REMOVE_HEAD, AST_LIST_UNLOCK, ast_module_user::entry, free, ast_module::info, ast_module_info::unload, and ast_module::users.
Referenced by quit_handler().
00434 { 00435 struct ast_module *mod; 00436 AST_LIST_HEAD_NOLOCK_STATIC(local_module_list, ast_module); 00437 00438 /* We have to call the unload() callbacks in reverse order that the modules 00439 * exist in the module list so it is the reverse order of how they were 00440 * loaded. */ 00441 00442 AST_LIST_LOCK(&module_list); 00443 while ((mod = AST_LIST_REMOVE_HEAD(&module_list, entry))) 00444 AST_LIST_INSERT_HEAD(&local_module_list, mod, entry); 00445 AST_LIST_UNLOCK(&module_list); 00446 00447 while ((mod = AST_LIST_REMOVE_HEAD(&local_module_list, entry))) { 00448 if (mod->info->unload) 00449 mod->info->unload(); 00450 /* Since this should only be called when shutting down "gracefully", 00451 * all channels should be down before we get to this point, meaning 00452 * there will be no module users left. */ 00453 AST_LIST_HEAD_DESTROY(&mod->users); 00454 free(mod); 00455 } 00456 }
void ast_module_unref | ( | struct ast_module * | ) |
Definition at line 1004 of file loader.c.
References ast_atomic_fetchadd_int(), ast_update_use_count(), and ast_module::usecount.
Referenced by agi_handle_command(), alsa_hangup(), ast_agi_unregister(), ast_smdi_interface_destroy(), ast_timer_close(), dahdi_destroy_channel_bynum(), dahdi_hangup(), destroy(), filestream_destructor(), gtalk_hangup(), handle_cli_file_convert(), handle_orig(), iax2_predestroy(), mgcp_hangup(), oh323_hangup(), oss_hangup(), phone_check_exception(), phone_hangup(), sip_hangup(), and usbradio_hangup().
01005 { 01006 ast_atomic_fetchadd_int(&mod->usecount, -1); 01007 ast_update_use_count(); 01008 }
void ast_module_unregister | ( | const struct ast_module_info * | ) |
Definition at line 161 of file loader.c.
References ast_free, AST_LIST_HEAD_DESTROY, AST_LIST_LOCK, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, AST_LIST_UNLOCK, ast_module_user::entry, ast_module::info, and ast_module::users.
00162 { 00163 struct ast_module *mod = NULL; 00164 00165 /* it is assumed that the users list in the module structure 00166 will already be empty, or we cannot have gotten to this 00167 point 00168 */ 00169 AST_LIST_LOCK(&module_list); 00170 AST_LIST_TRAVERSE_SAFE_BEGIN(&module_list, mod, entry) { 00171 if (mod->info == info) { 00172 AST_LIST_REMOVE_CURRENT(entry); 00173 break; 00174 } 00175 } 00176 AST_LIST_TRAVERSE_SAFE_END; 00177 AST_LIST_UNLOCK(&module_list); 00178 00179 if (mod) { 00180 AST_LIST_HEAD_DESTROY(&mod->users); 00181 ast_free(mod); 00182 } 00183 }
int ast_register_application2 | ( | const char * | app, | |
int(*)(struct ast_channel *, void *) | execute, | |||
const char * | synopsis, | |||
const char * | description, | |||
void * | mod | |||
) |
Register an application.
app | Short name of the application | |
execute | a function callback to execute the application. It should return non-zero if the channel needs to be hung up. | |
synopsis | a short description (one line synopsis) of the application | |
description | long description with all of the details about the use of the application | |
mod | module this application belongs to |
0 | success | |
-1 | failure. |
Definition at line 4533 of file pbx.c.
References ast_calloc, ast_log(), AST_RWLIST_INSERT_BEFORE_CURRENT, AST_RWLIST_INSERT_TAIL, AST_RWLIST_TRAVERSE, AST_RWLIST_TRAVERSE_SAFE_BEGIN, AST_RWLIST_TRAVERSE_SAFE_END, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_verb, COLOR_BRCYAN, ast_app::description, ast_app::execute, ast_app::list, LOG_WARNING, ast_app::module, ast_app::name, ast_app::synopsis, and term_color().
Referenced by ast_features_init(), and load_pbx().
04534 { 04535 struct ast_app *tmp, *cur = NULL; 04536 char tmps[80]; 04537 int length, res; 04538 04539 AST_RWLIST_WRLOCK(&apps); 04540 AST_RWLIST_TRAVERSE(&apps, tmp, list) { 04541 if (!(res = strcasecmp(app, tmp->name))) { 04542 ast_log(LOG_WARNING, "Already have an application '%s'\n", app); 04543 AST_RWLIST_UNLOCK(&apps); 04544 return -1; 04545 } else if (res < 0) 04546 break; 04547 } 04548 04549 length = sizeof(*tmp) + strlen(app) + 1; 04550 04551 if (!(tmp = ast_calloc(1, length))) { 04552 AST_RWLIST_UNLOCK(&apps); 04553 return -1; 04554 } 04555 04556 strcpy(tmp->name, app); 04557 tmp->execute = execute; 04558 tmp->synopsis = synopsis; 04559 tmp->description = description; 04560 tmp->module = mod; 04561 04562 /* Store in alphabetical order */ 04563 AST_RWLIST_TRAVERSE_SAFE_BEGIN(&apps, cur, list) { 04564 if (strcasecmp(tmp->name, cur->name) < 0) { 04565 AST_RWLIST_INSERT_BEFORE_CURRENT(tmp, list); 04566 break; 04567 } 04568 } 04569 AST_RWLIST_TRAVERSE_SAFE_END; 04570 if (!cur) 04571 AST_RWLIST_INSERT_TAIL(&apps, tmp, list); 04572 04573 ast_verb(2, "Registered application '%s'\n", term_color(tmps, tmp->name, COLOR_BRCYAN, 0, sizeof(tmps))); 04574 04575 AST_RWLIST_UNLOCK(&apps); 04576 04577 return 0; 04578 }
int ast_unload_resource | ( | const char * | resource_name, | |
enum | ast_module_unload_mode | |||
) |
Unload a module.
resource_name | The name of the module to unload. | |
ast_module_unload_mode | The force flag. This should be set using one of the AST_FORCE flags. |
0 | on success. | |
-1 | on error. |
Definition at line 458 of file loader.c.
References __ast_module_user_hangup_all(), AST_FORCE_FIRM, AST_LIST_LOCK, AST_LIST_UNLOCK, ast_log(), ast_update_use_count(), ast_module::declined, find_resource(), ast_module::flags, ast_module::info, ast_module::lib, LOG_WARNING, ast_module_info::restore_globals, ast_module::running, unload_dynamic_module(), and ast_module::usecount.
Referenced by exit_now(), handle_unload(), manager_moduleload(), reload(), and remove_module().
00459 { 00460 struct ast_module *mod; 00461 int res = -1; 00462 int error = 0; 00463 00464 AST_LIST_LOCK(&module_list); 00465 00466 if (!(mod = find_resource(resource_name, 0))) { 00467 AST_LIST_UNLOCK(&module_list); 00468 ast_log(LOG_WARNING, "Unload failed, '%s' could not be found\n", resource_name); 00469 return 0; 00470 } 00471 00472 if (!(mod->flags.running || mod->flags.declined)) 00473 error = 1; 00474 00475 if (!error && (mod->usecount > 0)) { 00476 if (force) 00477 ast_log(LOG_WARNING, "Warning: Forcing removal of module '%s' with use count %d\n", 00478 resource_name, mod->usecount); 00479 else { 00480 ast_log(LOG_WARNING, "Soft unload failed, '%s' has use count %d\n", resource_name, 00481 mod->usecount); 00482 error = 1; 00483 } 00484 } 00485 00486 if (!error) { 00487 __ast_module_user_hangup_all(mod); 00488 res = mod->info->unload(); 00489 00490 if (res) { 00491 ast_log(LOG_WARNING, "Firm unload failed for %s\n", resource_name); 00492 if (force <= AST_FORCE_FIRM) 00493 error = 1; 00494 else 00495 ast_log(LOG_WARNING, "** Dangerous **: Unloading resource anyway, at user request\n"); 00496 } 00497 } 00498 00499 if (!error) 00500 mod->flags.running = mod->flags.declined = 0; 00501 00502 AST_LIST_UNLOCK(&module_list); 00503 00504 if (!error && !mod->lib && mod->info && mod->info->restore_globals) 00505 mod->info->restore_globals(); 00506 00507 #ifdef LOADABLE_MODULES 00508 if (!error) 00509 unload_dynamic_module(mod); 00510 #endif 00511 00512 if (!error) 00513 ast_update_use_count(); 00514 00515 return res; 00516 }
int ast_unregister_application | ( | const char * | app | ) |
Unregister an application.
app | name of the application (does not have to be the same string as the one that was registered) |
0 | success | |
-1 | failure |
Definition at line 5794 of file pbx.c.
References ast_free, AST_RWLIST_REMOVE_CURRENT, AST_RWLIST_TRAVERSE_SAFE_BEGIN, AST_RWLIST_TRAVERSE_SAFE_END, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_verb, ast_app::list, ast_app::name, and unreference_cached_app().
Referenced by __unload_module(), load_module(), and unload_module().
05795 { 05796 struct ast_app *tmp; 05797 05798 AST_RWLIST_WRLOCK(&apps); 05799 AST_RWLIST_TRAVERSE_SAFE_BEGIN(&apps, tmp, list) { 05800 if (!strcasecmp(app, tmp->name)) { 05801 unreference_cached_app(tmp); 05802 AST_RWLIST_REMOVE_CURRENT(list); 05803 ast_verb(2, "Unregistered application '%s'\n", tmp->name); 05804 ast_free(tmp); 05805 break; 05806 } 05807 } 05808 AST_RWLIST_TRAVERSE_SAFE_END; 05809 AST_RWLIST_UNLOCK(&apps); 05810 05811 return tmp ? 0 : -1; 05812 }
int ast_update_module_list | ( | int(*)(const char *module, const char *description, int usecnt, const char *like) | modentry, | |
const char * | like | |||
) |
Ask for a list of modules, descriptions, and use counts.
modentry | A callback to an updater function. | |
like | For each of the modules loaded, modentry will be executed with the resource, description, and usecount values of each particular module. |
Definition at line 930 of file loader.c.
References AST_LIST_TRAVERSE, AST_LIST_TRYLOCK, AST_LIST_UNLOCK, ast_module_info::description, ast_module::info, ast_module::resource, and ast_module::usecount.
Referenced by handle_modlist(), and mod_update().
00932 { 00933 struct ast_module *cur; 00934 int unlock = -1; 00935 int total_mod_loaded = 0; 00936 00937 if (AST_LIST_TRYLOCK(&module_list)) 00938 unlock = 0; 00939 00940 AST_LIST_TRAVERSE(&module_list, cur, entry) { 00941 total_mod_loaded += modentry(cur->resource, cur->info->description, cur->usecount, like); 00942 } 00943 00944 if (unlock) 00945 AST_LIST_UNLOCK(&module_list); 00946 00947 return total_mod_loaded; 00948 }
void ast_update_use_count | ( | void | ) |
Notify when usecount has been changed.
This function calulates use counts and notifies anyone trying to keep track of them. It should be called whenever your module's usecount changes.
Definition at line 918 of file loader.c.
References AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, and loadupdate::updater.
Referenced by __ast_module_user_add(), __ast_module_user_hangup_all(), __ast_module_user_remove(), ast_module_ref(), ast_module_unref(), ast_unload_resource(), exit_now(), handle_request_do(), load_module(), load_resource(), oh323_request(), sip_request_call(), and unistim_new().
00919 { 00920 /* Notify any module monitors that the use count for a 00921 resource has changed */ 00922 struct loadupdate *m; 00923 00924 AST_LIST_LOCK(&updaters); 00925 AST_LIST_TRAVERSE(&updaters, m, entry) 00926 m->updater(); 00927 AST_LIST_UNLOCK(&updaters); 00928 }
struct ast_module_info* ast_module_info [static] |