Fri Aug 7 11:04:27 2015

Asterisk developer's documentation


module.h File Reference

Asterisk module definitions. More...

#include "asterisk/utils.h"

Go to the source code of this file.

Data Structures

struct  ast_module_info

Defines

#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 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), AST_MODFLAG_BUILDSUM = (1 << 1), AST_MODFLAG_LOAD_FIRST = (1 << 2) }
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

struct 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.
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_moduleast_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_unload_resource (const char *resource_name, enum ast_module_unload_mode)
 Unload a module.
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 const struct
ast_module_info
ast_module_info

Detailed Description

Asterisk module definitions.

This file contains the definitons for functions Asterisk modules should provide and some other module related functions.

Definition in file module.h.


Define Documentation

#define AST_MODULE_CONFIG   "modules.conf"

Module configuration file.

Definition at line 51 of file module.h.

Referenced by load_modules().

#define AST_MODULE_INFO ( keystr,
flags_to_set,
desc,
fields...   ) 

Definition at line 270 of file module.h.

#define AST_MODULE_INFO_STANDARD ( keystr,
desc   ) 
Value:
AST_MODULE_INFO(keystr, AST_MODFLAG_DEFAULT, desc, \
         .load = load_module,       \
         .unload = unload_module,      \
             )

Definition at line 289 of file module.h.

#define ast_module_user_add ( chan   )     __ast_module_user_add(ast_module_info->self, chan)

Definition at line 228 of file module.h.

Referenced by __login_exec(), _macro_exec(), _while_exec(), acf_curl_exec(), acf_cut_exec(), acf_rand_exec(), acf_sort_exec(), acf_vmcount_exec(), admin_exec(), adsi_exec(), agi_exec_full(), alarmreceiver_exec(), amd_exec(), app_exec(), appendcdruserfield_exec(), aqm_exec(), asyncgoto_exec(), auth_exec(), background_detect_exec(), builtin_parkcall(), chanavail_exec(), chanspy_exec(), conf_exec(), controlplayback_exec(), count_exec(), cpeid_exec(), del_exec(), deltree_exec(), dictate_exec(), directory_exec(), disa_exec(), dumpchan_exec(), dundifunc_read(), echo_exec(), exec(), exec_exec(), execif_exec(), extenspy_exec(), festival_exec(), flash_exec(), forkcdr_exec(), function_enum(), function_realtime_read(), function_realtime_write(), function_txtcidname(), gosub_exec(), gosubif_exec(), hasvoicemail_exec(), ices_exec(), local_new(), log_exec(), lookupblacklist_exec(), lookupcidname_exec(), macroif_exec(), milliwatt_exec(), mixmonitor_exec(), morsecode_exec(), mp3_exec(), nbs_new(), NBScat_exec(), nocdr_exec(), ospauth_exec(), ospfinished_exec(), osplookup_exec(), ospnext_exec(), page_exec(), park_call_exec(), park_exec(), parkandannounce_exec(), pickup_exec(), playback_exec(), pqm_exec(), privacy_exec(), ql_exec(), queue_exec(), queue_function_exists(), queue_function_queuemembercount(), queue_function_queuememberlist(), queue_function_queuememberpaused(), queue_function_queuememberstatus(), queue_function_queuewaitingcount(), random_exec(), read_exec(), readfile_exec(), realtime_exec(), realtime_update_exec(), record_exec(), retrydial_exec(), rqm_exec(), sayunixtime_exec(), senddtmf_exec(), sendimage_exec(), sendtext_exec(), sendurl_exec(), setcallerid_exec(), setcallerid_pres_exec(), setcdruserfield_exec(), settransfercapability_exec(), skel_exec(), smdi_msg_read(), smdi_msg_retrieve_read(), sms_exec(), softhangup_exec(), speech_activate(), speech_background(), speech_create(), speech_deactivate(), speech_destroy(), speech_load(), speech_processing_sound(), speech_start(), speech_unload(), system_exec_helper(), testclient_exec(), testserver_exec(), transfer_exec(), tryexec_exec(), upqm_exec(), userevent_exec(), verbose_exec(), vm_box_exists(), vm_exec(), vm_execmain(), vmauthenticate(), waitforring_exec(), and zapateller_exec().

 
#define ast_module_user_hangup_all (  )     __ast_module_user_hangup_all(ast_module_info->self)

Definition at line 230 of file module.h.

Referenced by unload_module().

#define ast_module_user_remove ( user   )     __ast_module_user_remove(ast_module_info->self, user)

Definition at line 229 of file module.h.

Referenced by __login_exec(), _macro_exec(), acf_curl_exec(), acf_cut_exec(), acf_rand_exec(), acf_sort_exec(), acf_vmcount_exec(), admin_exec(), adsi_exec(), agi_exec_full(), alarmreceiver_exec(), amd_exec(), app_exec(), appendcdruserfield_exec(), aqm_exec(), asyncgoto_exec(), auth_exec(), background_detect_exec(), builtin_parkcall(), chanavail_exec(), chanspy_exec(), conf_exec(), controlplayback_exec(), count_exec(), cpeid_exec(), del_exec(), deltree_exec(), dictate_exec(), directory_exec(), disa_exec(), dumpchan_exec(), dundifunc_read(), echo_exec(), exec(), exec_exec(), execif_exec(), extenspy_exec(), festival_exec(), flash_exec(), forkcdr_exec(), function_enum(), function_realtime_read(), function_realtime_write(), function_txtcidname(), gosub_exec(), gosubif_exec(), hasvoicemail_exec(), ices_exec(), local_hangup(), log_exec(), lookupblacklist_exec(), lookupcidname_exec(), macroif_exec(), milliwatt_exec(), mixmonitor_exec(), morsecode_exec(), mp3_exec(), nbs_destroy(), NBScat_exec(), nocdr_exec(), ospauth_exec(), ospfinished_exec(), osplookup_exec(), ospnext_exec(), page_exec(), park_call_exec(), park_exec(), parkandannounce_exec(), pickup_exec(), playback_exec(), pqm_exec(), privacy_exec(), ql_exec(), queue_exec(), queue_function_exists(), queue_function_queuemembercount(), queue_function_queuememberlist(), queue_function_queuememberpaused(), queue_function_queuememberstatus(), queue_function_queuewaitingcount(), random_exec(), read_exec(), readfile_exec(), realtime_exec(), realtime_update_exec(), record_exec(), retrydial_exec(), rqm_exec(), sayunixtime_exec(), senddtmf_exec(), sendimage_exec(), sendtext_exec(), sendurl_exec(), setcallerid_exec(), setcallerid_pres_exec(), setcdruserfield_exec(), settransfercapability_exec(), skel_exec(), smdi_msg_read(), smdi_msg_retrieve_read(), sms_exec(), softhangup_exec(), speech_activate(), speech_background(), speech_create(), speech_deactivate(), speech_destroy(), speech_load(), speech_processing_sound(), speech_start(), speech_unload(), system_exec_helper(), testclient_exec(), testserver_exec(), transfer_exec(), tryexec_exec(), upqm_exec(), userevent_exec(), verbose_exec(), vm_box_exists(), vm_exec(), vm_execmain(), vmauthenticate(), waitforring_exec(), and zapateller_exec().

#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.

Definition at line 38 of file module.h.


Enumeration Type Documentation

Enumerator:
AST_MODFLAG_DEFAULT 
AST_MODFLAG_GLOBAL_SYMBOLS 
AST_MODFLAG_BUILDSUM 
AST_MODFLAG_LOAD_FIRST 

Load this module in the first pass on auto loading.

When module auto loading is used, modules with this flag set will be loaded after preloaded modules, but before all modules being automatically loaded without this flag set on them.

Definition at line 179 of file module.h.

00179                       {
00180    AST_MODFLAG_DEFAULT = 0,
00181    AST_MODFLAG_GLOBAL_SYMBOLS = (1 << 0),
00182    AST_MODFLAG_BUILDSUM = (1 << 1),
00183    /*!
00184     * \brief Load this module in the first pass on auto loading
00185     *
00186     * When module auto loading is used, modules with this flag set will
00187     * be loaded after preloaded modules, but before all modules being
00188     * automatically loaded without this flag set on them.
00189     */
00190    AST_MODFLAG_LOAD_FIRST = (1 << 2),
00191 };

Enumerator:
AST_MODULE_LOAD_SUCCESS 

Module loaded and configured

AST_MODULE_LOAD_DECLINE 

Module is not configured

AST_MODULE_LOAD_SKIP 

Module was skipped for some reason

AST_MODULE_LOAD_FAILURE 

Module could not be loaded properly

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 };

Enumerator:
AST_FORCE_SOFT 

Softly unload a module, only if not in use

AST_FORCE_FIRM 

Firmly unload a module, even if in use

AST_FORCE_HARD 

as FIRM, plus dlclose() on the module. Not recommended as it may cause crashes

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 };


Function Documentation

struct ast_module_user* __ast_module_user_add ( struct ast_module ,
struct ast_channel  
) [read]

Definition at line 197 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::usecount, and ast_module::users.

00199 {
00200    struct ast_module_user *u = ast_calloc(1, sizeof(*u));
00201 
00202    if (!u)
00203       return NULL;
00204 
00205    u->chan = chan;
00206 
00207    AST_LIST_LOCK(&mod->users);
00208    AST_LIST_INSERT_HEAD(&mod->users, u, entry);
00209    AST_LIST_UNLOCK(&mod->users);
00210 
00211    ast_atomic_fetchadd_int(&mod->usecount, +1);
00212 
00213    ast_update_use_count();
00214 
00215    return u;
00216 }

void __ast_module_user_hangup_all ( struct ast_module  ) 

Definition at line 229 of file loader.c.

References ast_atomic_fetchadd_int(), AST_LIST_LOCK, AST_LIST_REMOVE_HEAD, AST_LIST_UNLOCK, ast_softhangup(), AST_SOFTHANGUP_APPUNLOAD, ast_update_use_count(), ast_module_user::chan, free, ast_module::usecount, and ast_module::users.

Referenced by ast_unload_resource().

00230 {
00231    struct ast_module_user *u;
00232 
00233    AST_LIST_LOCK(&mod->users);
00234    while ((u = AST_LIST_REMOVE_HEAD(&mod->users, entry))) {
00235       ast_softhangup(u->chan, AST_SOFTHANGUP_APPUNLOAD);
00236       ast_atomic_fetchadd_int(&mod->usecount, -1);
00237       free(u);
00238    }
00239    AST_LIST_UNLOCK(&mod->users);
00240 
00241         ast_update_use_count();
00242 }

void __ast_module_user_remove ( struct ast_module ,
struct ast_module_user  
)

Definition at line 218 of file loader.c.

References ast_atomic_fetchadd_int(), AST_LIST_LOCK, AST_LIST_REMOVE, AST_LIST_UNLOCK, ast_update_use_count(), free, ast_module::usecount, and ast_module::users.

00219 {
00220    AST_LIST_LOCK(&mod->users);
00221    AST_LIST_REMOVE(&mod->users, u, entry);
00222    AST_LIST_UNLOCK(&mod->users);
00223    ast_atomic_fetchadd_int(&mod->usecount, -1);
00224    free(u);
00225 
00226    ast_update_use_count();
00227 }

enum ast_module_load_result ast_load_resource ( const char *  resource_name  ) 

Load a module.

Parameters:
resource_name The name of the module to load.

This function is run by the PBX to load the modules. It performs all loading and initilization tasks. Basically, to load a module, just give it the name of the module and it will do the rest.

Returns:
See possible enum values for ast_module_load_result.

Definition at line 831 of file loader.c.

References AST_LIST_LOCK, AST_LIST_UNLOCK, LOAD_ALL, and load_resource().

Referenced by file_ok_sel(), handle_load(), handle_load_deprecated(), and reload().

00832 {
00833        AST_LIST_LOCK(&module_list);
00834        load_resource(resource_name, LOAD_ALL);
00835        AST_LIST_UNLOCK(&module_list);
00836 
00837        return 0;
00838 }

int ast_loader_register ( int(*)(void)  updater  ) 

Add a procedure to be run when modules have been updated.

Parameters:
updater The function to run when modules have been updated.

This function adds the given function to a linked list of functions to be run when the modules are updated.

Returns:
Zero on success and -1 on failure.

Definition at line 1067 of file loader.c.

References AST_LIST_INSERT_HEAD, AST_LIST_LOCK, AST_LIST_UNLOCK, ast_malloc, and loadupdate::updater.

Referenced by show_console().

01068 {
01069    struct loadupdate *tmp;
01070 
01071    if (!(tmp = ast_malloc(sizeof(*tmp))))
01072       return -1;
01073 
01074    tmp->updater = v;
01075    AST_LIST_LOCK(&updaters);
01076    AST_LIST_INSERT_HEAD(&updaters, tmp, entry);
01077    AST_LIST_UNLOCK(&updaters);
01078 
01079    return 0;
01080 }

int ast_loader_unregister ( int(*)(void)  updater  ) 

Remove a procedure to be run when modules are updated.

Parameters:
updater The updater function to unregister.

This removes the given function from the updater list.

Returns:
Zero on success, -1 on failure.

Definition at line 1082 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().

01083 {
01084    struct loadupdate *cur;
01085 
01086    AST_LIST_LOCK(&updaters);
01087    AST_LIST_TRAVERSE_SAFE_BEGIN(&updaters, cur, entry) {
01088       if (cur->updater == v)  {
01089          AST_LIST_REMOVE_CURRENT(&updaters, entry);
01090          break;
01091       }
01092    }
01093    AST_LIST_TRAVERSE_SAFE_END;
01094    AST_LIST_UNLOCK(&updaters);
01095 
01096    return cur ? 0 : -1;
01097 }

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.

Parameters:
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.
Returns:
A possible completion of the partial match, or NULL if no matches were found.

Definition at line 551 of file loader.c.

References AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, ast_module::info, name, ast_module_info::reload, and strdup.

Referenced by complete_mod_2(), complete_mod_2_nr(), complete_mod_3(), complete_mod_3_nr(), complete_mod_4(), and load_module().

00552 {
00553    struct ast_module *cur;
00554    int i, which=0, l = strlen(word);
00555    char *ret = NULL;
00556 
00557    if (pos != rpos)
00558       return NULL;
00559 
00560    AST_LIST_LOCK(&module_list);
00561    AST_LIST_TRAVERSE(&module_list, cur, entry) {
00562       if (!strncasecmp(word, cur->resource, l) &&
00563           (cur->info->reload || !needsreload) &&
00564           ++which > state) {
00565          ret = strdup(cur->resource);
00566          break;
00567       }
00568    }
00569    AST_LIST_UNLOCK(&module_list);
00570 
00571    if (!ret) {
00572       for (i=0; !ret && reload_classes[i].name; i++) {
00573          if (!strncasecmp(word, reload_classes[i].name, l) && ++which > state)
00574             ret = strdup(reload_classes[i].name);
00575       }
00576    }
00577 
00578    return ret;
00579 }

struct ast_module* ast_module_ref ( struct ast_module  )  [read]
void ast_module_register ( const struct ast_module_info  ) 

Definition at line 135 of file loader.c.

References ast_calloc, AST_LIST_HEAD_INIT, AST_LIST_INSERT_TAIL, AST_LIST_LOCK, AST_LIST_UNLOCK, embedding, ast_module::info, ast_module_info::name, resource_being_loaded, ast_module_info::self, and ast_module::users.

00136 {
00137    struct ast_module *mod;
00138 
00139    if (embedding) {
00140       if (!(mod = ast_calloc(1, sizeof(*mod) + strlen(info->name) + 1)))
00141          return;
00142       strcpy(mod->resource, info->name);
00143    } else {
00144       mod = resource_being_loaded;
00145    }
00146 
00147    mod->info = info;
00148    AST_LIST_HEAD_INIT(&mod->users);
00149 
00150    /* during startup, before the loader has been initialized,
00151       there are no threads, so there is no need to take the lock
00152       on this list to manipulate it. it is also possible that it
00153       might be unsafe to use the list lock at that point... so
00154       let's avoid it altogether
00155    */
00156    if (!embedding)
00157       AST_LIST_LOCK(&module_list);
00158 
00159    /* it is paramount that the new entry be placed at the tail of
00160       the list, otherwise the code that uses dlopen() to load
00161       dynamic modules won't be able to find out if the module it
00162       just opened was registered or failed to load
00163    */
00164    AST_LIST_INSERT_TAIL(&module_list, mod, entry);
00165 
00166    if (!embedding)
00167       AST_LIST_UNLOCK(&module_list);
00168 
00169    /* give the module a copy of its own handle, for later use in registrations and the like */
00170    *((struct ast_module **) &(info->self)) = mod;
00171 }

void ast_module_shutdown ( void   ) 

Run the unload() callback for all loaded modules.

This function should be called when Asterisk is shutting down gracefully.

Note:
Some resources, like timers, are started up dynamically, and thus may be still in use, even if all channels are dead. We must therefore check the usecount before asking modules to unload.
If we go through the entire list without changing anything, ignore the usecounts and unload, then exit.

Definition at line 450 of file loader.c.

References 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::declined, ast_module::flags, free, ast_module::info, ast_module::running, ast_module_info::unload, ast_module::usecount, and ast_module::users.

Referenced by quit_handler().

00451 {
00452    struct ast_module *mod;
00453    int somethingchanged = 1, final = 0;
00454 
00455    AST_LIST_LOCK(&module_list);
00456 
00457    /*!\note Some resources, like timers, are started up dynamically, and thus
00458     * may be still in use, even if all channels are dead.  We must therefore
00459     * check the usecount before asking modules to unload. */
00460    do {
00461       if (!somethingchanged) {
00462          /*!\note If we go through the entire list without changing
00463           * anything, ignore the usecounts and unload, then exit. */
00464          final = 1;
00465       }
00466 
00467       /* Reset flag before traversing the list */
00468       somethingchanged = 0;
00469 
00470       AST_LIST_TRAVERSE_SAFE_BEGIN(&module_list, mod, entry) {
00471          if (!final && mod->usecount) {
00472             continue;
00473          }
00474          AST_LIST_REMOVE_CURRENT(&module_list, entry);
00475          if (mod->flags.running && !mod->flags.declined && mod->info->unload) {
00476             mod->info->unload();
00477          }
00478          AST_LIST_HEAD_DESTROY(&mod->users);
00479          free(mod);
00480          somethingchanged = 1;
00481       }
00482       AST_LIST_TRAVERSE_SAFE_END;
00483    } while (somethingchanged && !final);
00484 
00485    AST_LIST_UNLOCK(&module_list);
00486 }

void ast_module_unref ( struct ast_module  ) 
void ast_module_unregister ( const struct ast_module_info  ) 

Definition at line 173 of file loader.c.

References AST_LIST_HEAD_DESTROY, AST_LIST_LOCK, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, AST_LIST_UNLOCK, free, ast_module::info, and ast_module::users.

00174 {
00175    struct ast_module *mod = NULL;
00176 
00177    /* it is assumed that the users list in the module structure
00178       will already be empty, or we cannot have gotten to this
00179       point
00180    */
00181    AST_LIST_LOCK(&module_list);
00182    AST_LIST_TRAVERSE_SAFE_BEGIN(&module_list, mod, entry) {
00183       if (mod->info == info) {
00184          AST_LIST_REMOVE_CURRENT(&module_list, entry);
00185          break;
00186       }
00187    }
00188    AST_LIST_TRAVERSE_SAFE_END;
00189    AST_LIST_UNLOCK(&module_list);
00190 
00191    if (mod) {
00192       AST_LIST_HEAD_DESTROY(&mod->users);
00193       free(mod);
00194    }
00195 }

int ast_unload_resource ( const char *  resource_name,
enum  ast_module_unload_mode 
)

Unload a module.

Parameters:
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.

This function unloads a module. It will only unload modules that are not in use (usecount not zero), unless AST_FORCE_FIRM or AST_FORCE_HARD is specified. Setting AST_FORCE_FIRM or AST_FORCE_HARD will unload the module regardless of consequences (NOT RECOMMENDED).

Returns:
Zero on success, -1 on error.

Definition at line 488 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::running, ast_module_info::unload, and ast_module::usecount.

Referenced by exit_now(), handle_unload(), handle_unload_deprecated(), reload(), and remove_module().

00489 {
00490    struct ast_module *mod;
00491    int res = -1;
00492    int error = 0;
00493 
00494    AST_LIST_LOCK(&module_list);
00495 
00496    if (!(mod = find_resource(resource_name, 0))) {
00497       AST_LIST_UNLOCK(&module_list);
00498       return 0;
00499    }
00500 
00501    if (!mod->flags.running || mod->flags.declined) {
00502       ast_log(LOG_WARNING, "Unload failed, '%s' is not loaded.\n", resource_name);
00503       error = 1;
00504    }
00505 
00506    if (!mod->lib) {
00507       ast_log(LOG_WARNING, "Unloading embedded modules is not supported.\n");
00508       error = 1;
00509    }
00510 
00511    if (!error && (mod->usecount > 0)) {
00512       if (force)
00513          ast_log(LOG_WARNING, "Warning:  Forcing removal of module '%s' with use count %d\n",
00514             resource_name, mod->usecount);
00515       else {
00516          ast_log(LOG_WARNING, "Soft unload failed, '%s' has use count %d\n", resource_name,
00517             mod->usecount);
00518          error = 1;
00519       }
00520    }
00521 
00522    if (!error) {
00523       __ast_module_user_hangup_all(mod);
00524       res = mod->info->unload();
00525 
00526       if (res) {
00527          ast_log(LOG_WARNING, "Firm unload failed for %s\n", resource_name);
00528          if (force <= AST_FORCE_FIRM)
00529             error = 1;
00530          else
00531             ast_log(LOG_WARNING, "** Dangerous **: Unloading resource anyway, at user request\n");
00532       }
00533    }
00534 
00535    if (!error)
00536       mod->flags.running = mod->flags.declined = 0;
00537 
00538    AST_LIST_UNLOCK(&module_list);
00539 
00540 #ifdef LOADABLE_MODULES
00541    if (!error)
00542       unload_dynamic_module(mod);
00543 #endif
00544 
00545    if (!error)
00546       ast_update_use_count();
00547 
00548    return res;
00549 }

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.

Parameters:
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.
Returns:
the number of modules loaded

Definition at line 1047 of file loader.c.

References AST_LIST_TRAVERSE, AST_LIST_TRYLOCK, AST_LIST_UNLOCK, ast_module_info::description, ast_module::info, and ast_module::usecount.

Referenced by handle_modlist(), and mod_update().

01049 {
01050    struct ast_module *cur;
01051    int unlock = -1;
01052    int total_mod_loaded = 0;
01053 
01054    if (AST_LIST_TRYLOCK(&module_list))
01055       unlock = 0;
01056 
01057    AST_LIST_TRAVERSE(&module_list, cur, entry) {
01058       total_mod_loaded += modentry(cur->resource, cur->info->description, cur->usecount, like);
01059    }
01060 
01061    if (unlock)
01062       AST_LIST_UNLOCK(&module_list);
01063 
01064    return total_mod_loaded;
01065 }

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.

Note:
The LOCAL_USER macros take care of calling this function for you.

Definition at line 1035 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(), agent_new(), ast_module_ref(), ast_module_unref(), ast_unload_resource(), exit_now(), load_module(), load_resource(), oh323_request(), scheduler_process_request_queue(), sip_request_call(), and sipsock_read().

01036 {
01037    /* Notify any module monitors that the use count for a
01038       resource has changed */
01039    struct loadupdate *m;
01040 
01041    AST_LIST_LOCK(&updaters);
01042    AST_LIST_TRAVERSE(&updaters, m, entry)
01043       m->updater();
01044    AST_LIST_UNLOCK(&updaters);
01045 }


Variable Documentation

const struct ast_module_info* ast_module_info [static]

Definition at line 268 of file module.h.


Generated on 7 Aug 2015 for Asterisk - the Open Source PBX by  doxygen 1.6.1