module.h File Reference

Asterisk module definitions. More...

#include "asterisk/utils.h"

Include dependency graph for module.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_INFO_STANDARD_DEPRECATED(keystr, desc)
#define AST_MODULE_INFO_STANDARD_EXTENDED(keystr, desc)
#define ast_module_ref(mod)   __ast_module_ref(mod, __FILE__, __LINE__, __PRETTY_FUNCTION__)
 Hold a reference to the module.
#define ast_module_shutdown_ref(mod)   __ast_module_shutdown_ref(mod, __FILE__, __LINE__, __PRETTY_FUNCTION__)
 Prevent unload of the module before shutdown.
#define ast_module_unref(mod)   __ast_module_unref(mod, __FILE__, __LINE__, __PRETTY_FUNCTION__)
 Release a reference to the module.
#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 ast_register_application_xml(app, execute)   ast_register_application(app, execute, NULL, NULL)
 Register an application using XML documentation.
#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.
#define SCOPED_MODULE_USE(module)   RAII_VAR(struct ast_module *, __self__ ## __LINE__, ast_module_ref(module), ast_module_unref)

Enumerations

enum  ast_module_flags { AST_MODFLAG_DEFAULT = 0, AST_MODFLAG_GLOBAL_SYMBOLS = (1 << 0), AST_MODFLAG_LOAD_ORDER = (1 << 1) }
enum  ast_module_load_priority {
  AST_MODPRI_REALTIME_DEPEND = 10, AST_MODPRI_REALTIME_DEPEND2 = 20, AST_MODPRI_REALTIME_DRIVER = 30, AST_MODPRI_TIMING = 40,
  AST_MODPRI_CHANNEL_DEPEND = 50, AST_MODPRI_CHANNEL_DRIVER = 60, AST_MODPRI_APP_DEPEND = 70, AST_MODPRI_DEVSTATE_PROVIDER = 80,
  AST_MODPRI_DEVSTATE_PLUGIN = 90, AST_MODPRI_CDR_DRIVER = 100, AST_MODPRI_DEFAULT = 128, AST_MODPRI_DEVSTATE_CONSUMER = 150
}
enum  ast_module_load_result {
  AST_MODULE_LOAD_SUCCESS = 0, AST_MODULE_LOAD_DECLINE = 1, AST_MODULE_LOAD_SKIP = 2, AST_MODULE_LOAD_PRIORITY = 3,
  AST_MODULE_LOAD_FAILURE = -1
}
enum  ast_module_reload_result {
  AST_MODULE_RELOAD_SUCCESS = 0, AST_MODULE_RELOAD_QUEUED, AST_MODULE_RELOAD_NOT_FOUND, AST_MODULE_RELOAD_ERROR,
  AST_MODULE_RELOAD_IN_PROGRESS, AST_MODULE_RELOAD_UNINITIALIZED, AST_MODULE_RELOAD_NOT_IMPLEMENTED
}
 Possible return types for ast_module_reload. More...
enum  ast_module_support_level { AST_MODULE_SUPPORT_UNKNOWN, AST_MODULE_SUPPORT_CORE, AST_MODULE_SUPPORT_EXTENDED, AST_MODULE_SUPPORT_DEPRECATED }
enum  ast_module_unload_mode { AST_FORCE_SOFT = 0, AST_FORCE_FIRM = 1, AST_FORCE_HARD = 2 }

Functions

struct ast_module__ast_module_ref (struct ast_module *mod, const char *file, int line, const char *func)
void __ast_module_shutdown_ref (struct ast_module *mod, const char *file, int line, const char *func)
void __ast_module_unref (struct ast_module *mod, const char *file, int line, const char *func)
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.
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.
const char * ast_module_name (const struct ast_module *mod)
 Get the name of a module.
void ast_module_register (const struct ast_module_info *)
enum ast_module_reload_result ast_module_reload (const char *name)
 Reload asterisk modules.
void ast_module_shutdown (void)
 Run the unload() callback for all loaded modules.
const char * ast_module_support_level_to_string (enum ast_module_support_level support_level)
void ast_module_unregister (const struct ast_module_info *)
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.
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 *status, const char *like, enum ast_module_support_level support_level), const char *like)
 Ask for a list of modules, descriptions, use counts and status.
void ast_update_use_count (void)
 Notify when usecount has been changed.

Variables

static struct ast_module_infoast_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 __MODULE_INFO_GLOBALS

Definition at line 408 of file module.h.

#define __MODULE_INFO_SECTION

Definition at line 407 of file module.h.

#define AST_MODULE_CONFIG   "modules.conf"

Module configuration file.

Definition at line 59 of file module.h.

Referenced by load_modules().

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

Definition at line 465 of file module.h.

#define AST_MODULE_INFO_STANDARD ( keystr,
desc   ) 

Definition at line 487 of file module.h.

#define AST_MODULE_INFO_STANDARD_DEPRECATED ( keystr,
desc   ) 

Definition at line 503 of file module.h.

#define AST_MODULE_INFO_STANDARD_EXTENDED ( keystr,
desc   ) 

Definition at line 495 of file module.h.

#define ast_module_ref ( mod   )     __ast_module_ref(mod, __FILE__, __LINE__, __PRETTY_FUNCTION__)

Hold a reference to the module.

Parameters:
mod Module to reference
Returns:
mod
Note:
A module reference will prevent the module from being unloaded.
Examples:
/tmp/asterisk-trunk/trunk/main/app.c.

Definition at line 331 of file module.h.

Referenced by __ast_sorcery_apply_wizard_mapping(), agi_handle_command(), allocate_subscription_tree(), alsa_new(), ast_agi_register(), ast_app_exec_sub(), ast_app_expand_sub_args(), ast_ari_add_handler(), ast_fax_tech_register(), ast_hook_send_action(), ast_iax2_new(), ast_mwi_external_ref(), ast_rtp_instance_new(), ast_sip_register_authenticator(), ast_sip_register_endpoint_formatter(), ast_sip_register_endpoint_identifier_with_name(), ast_sip_register_outbound_authenticator(), ast_sip_register_publish_handler(), ast_sip_register_supplement(), ast_sip_session_register_sdp_handler(), ast_sip_session_register_supplement(), ast_srtp_create(), ast_timer_open(), ast_websocket_add_protocol(), ast_websocket_server_create(), bridge_builtin_set_limits(), dahdi_new(), data_result_generate_node(), fax_session_new(), fax_session_reserve(), find_best_technology(), get_filestream(), handle_cli_file_convert(), handle_orig(), init_hook(), instance_created_observer(), mgcp_new(), mixmonitor_exec(), moh_alloc(), moh_files_alloc(), newpvt(), ooh323_new(), ooh323c_start_call_thread(), oss_new(), phone_check_exception(), phone_new(), process_message(), register_service(), sip_handle_cc(), sip_new(), skinny_new(), smdi_load(), stasis_app_ref(), stasis_app_register_event_source(), and sub_add_handler().

#define ast_module_shutdown_ref ( mod   )     __ast_module_shutdown_ref(mod, __FILE__, __LINE__, __PRETTY_FUNCTION__)

Prevent unload of the module before shutdown.

Parameters:
mod Module to hold
Note:
This should not be balanced by a call to ast_module_unref.

Definition at line 338 of file module.h.

Referenced by __ast_bucket_scheme_register(), __ast_codec_register(), and load_module().

#define ast_module_unref ( mod   )     __ast_module_unref(mod, __FILE__, __LINE__, __PRETTY_FUNCTION__)

Release a reference to the module.

Parameters:
mod Module to release
Examples:
/tmp/asterisk-trunk/trunk/main/app.c.

Definition at line 343 of file module.h.

Referenced by agi_handle_command(), alsa_hangup(), ast_agi_unregister(), ast_app_exec_sub(), ast_app_expand_sub_args(), ast_ari_remove_handler(), ast_fax_tech_unregister(), ast_hook_send_action(), ast_module_shutdown(), ast_mwi_external_unref(), ast_rtp_instance_new(), ast_sip_session_unregister_supplement(), ast_sip_unregister_authenticator(), ast_sip_unregister_endpoint_formatter(), ast_sip_unregister_endpoint_identifier(), ast_sip_unregister_event_publisher_handler(), ast_sip_unregister_outbound_authenticator(), ast_sip_unregister_publish_handler(), ast_sip_unregister_subscription_handler(), ast_sip_unregister_supplement(), ast_srtp_destroy(), ast_timer_close(), ast_websocket_remove_protocol(), bridge_builtin_set_limits(), bridge_features_limits_dtor(), bridge_tech_deferred_destroy(), codec_dtor(), dahdi_destroy_channel_range(), dahdi_hangup(), data_result_generate_node(), destroy(), destroy_bridge(), destroy_session(), fax_session_new(), filestream_destructor(), handle_cli_file_convert(), handle_orig(), hook_datastore_destroy_callback(), iax2_predestroy(), instance_destroying_observer(), instance_destructor(), local_ast_moh_cleanup(), mgcp_hangup(), mixmonitor_exec(), mixmonitor_thread(), newpvt(), onCallCleared(), ooh323_destroy(), ooh323_hangup(), ooh323c_call_thread(), oss_hangup(), phone_check_exception(), phone_hangup(), process_message(), remove_handler(), sip_cc_monitor_destructor(), sip_hangup(), skinny_hangup(), smart_bridge_operation(), smdi_interface_destroy(), sorcery_object_wizard_destructor(), stasis_app_unref(), stasis_app_unregister_event_source(), subscription_tree_destructor(), unregister_service(), and websocket_server_dtor().

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

Definition at line 317 of file module.h.

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

Parameters:
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
This registers an application with Asterisk's internal application list.
Note:
The individual applications themselves are responsible for registering and unregistering and unregistering their own CLI commands.
Return values:
0 success
-1 failure.

Definition at line 530 of file module.h.

Referenced by load_module().

#define ast_register_application_xml ( app,
execute   )     ast_register_application(app, execute, NULL, NULL)

Register an application using XML documentation.

Parameters:
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.
This registers an application with Asterisk's internal application list.
Note:
The individual applications themselves are responsible for registering and unregistering and unregistering their own CLI commands.
Return values:
0 success
-1 failure.

Definition at line 546 of file module.h.

Referenced by load_module(), and load_parking_applications().

#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 46 of file module.h.

#define SCOPED_MODULE_USE ( module   )     RAII_VAR(struct ast_module *, __self__ ## __LINE__, ast_module_ref(module), ast_module_unref)

Macro to safely ref and unref the self module for the current scope

Definition at line 585 of file module.h.

Referenced by ast_parking_blind_transfer_park(), ast_parking_is_exten_park(), ast_parking_park_bridge_channel(), ast_parking_park_call(), ast_websocket_uri_cb(), feature_park_call(), and stasis_app_exec().


Enumeration Type Documentation

Enumerator:
AST_MODFLAG_DEFAULT 
AST_MODFLAG_GLOBAL_SYMBOLS 
AST_MODFLAG_LOAD_ORDER 

Definition at line 243 of file module.h.

00243                       {
00244    AST_MODFLAG_DEFAULT = 0,
00245    AST_MODFLAG_GLOBAL_SYMBOLS = (1 << 0),
00246    AST_MODFLAG_LOAD_ORDER = (1 << 1),
00247 };

Enumerator:
AST_MODPRI_REALTIME_DEPEND  Dependency for a realtime driver
AST_MODPRI_REALTIME_DEPEND2  Second level dependency for a realtime driver (func_curl needs res_curl, but is needed by res_config_curl)
AST_MODPRI_REALTIME_DRIVER  A realtime driver, which provides configuration services for other modules
AST_MODPRI_TIMING  Dependency for a channel (MOH needs timing interfaces to be fully loaded)
AST_MODPRI_CHANNEL_DEPEND  Channel driver dependency (may depend upon realtime, e.g. MOH)
AST_MODPRI_CHANNEL_DRIVER  Channel drivers (provide devicestate)
AST_MODPRI_APP_DEPEND  Dependency for an application
AST_MODPRI_DEVSTATE_PROVIDER  Applications and other modules that _provide_ devicestate (e.g. meetme)
AST_MODPRI_DEVSTATE_PLUGIN  Plugin for a module that provides devstate (e.g. res_calendar_*)
AST_MODPRI_CDR_DRIVER  CDR or CEL backend
AST_MODPRI_DEFAULT  Modules not otherwise defined (such as most apps) will load here
AST_MODPRI_DEVSTATE_CONSUMER  Certain modules, which consume devstate, need to load after all others (e.g. app_queue)

Definition at line 249 of file module.h.

00249                               {
00250    AST_MODPRI_REALTIME_DEPEND =    10,  /*!< Dependency for a realtime driver */
00251    AST_MODPRI_REALTIME_DEPEND2 =   20,  /*!< Second level dependency for a realtime driver (func_curl needs res_curl, but is needed by res_config_curl) */
00252    AST_MODPRI_REALTIME_DRIVER =    30,  /*!< A realtime driver, which provides configuration services for other modules */
00253    AST_MODPRI_TIMING =             40,  /*!< Dependency for a channel (MOH needs timing interfaces to be fully loaded) */
00254    AST_MODPRI_CHANNEL_DEPEND =     50,  /*!< Channel driver dependency (may depend upon realtime, e.g. MOH) */
00255    AST_MODPRI_CHANNEL_DRIVER =     60,  /*!< Channel drivers (provide devicestate) */
00256    AST_MODPRI_APP_DEPEND =         70,  /*!< Dependency for an application */
00257    AST_MODPRI_DEVSTATE_PROVIDER =  80,  /*!< Applications and other modules that _provide_ devicestate (e.g. meetme) */
00258    AST_MODPRI_DEVSTATE_PLUGIN =    90,  /*!< Plugin for a module that provides devstate (e.g. res_calendar_*) */
00259    AST_MODPRI_CDR_DRIVER =        100,  /*!< CDR or CEL backend */
00260    AST_MODPRI_DEFAULT =           128,  /*!< Modules not otherwise defined (such as most apps) will load here */
00261    AST_MODPRI_DEVSTATE_CONSUMER = 150,  /*!< Certain modules, which consume devstate, need to load after all others (e.g. app_queue) */
00262 };

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_PRIORITY  Module is not loaded yet, but is added to prioity heap
AST_MODULE_LOAD_FAILURE  Module could not be loaded properly

Definition at line 68 of file module.h.

00068                             {
00069    AST_MODULE_LOAD_SUCCESS = 0,    /*!< Module loaded and configured */
00070    AST_MODULE_LOAD_DECLINE = 1,    /*!< Module is not configured */
00071    AST_MODULE_LOAD_SKIP = 2,       /*!< Module was skipped for some reason */
00072    AST_MODULE_LOAD_PRIORITY = 3,   /*!< Module is not loaded yet, but is added to prioity heap */
00073    AST_MODULE_LOAD_FAILURE = -1,   /*!< Module could not be loaded properly */
00074 };

Possible return types for ast_module_reload.

Since:
12
Enumerator:
AST_MODULE_RELOAD_SUCCESS  The module was reloaded succesfully
AST_MODULE_RELOAD_QUEUED  The module reload request was queued
AST_MODULE_RELOAD_NOT_FOUND  The requested module was not found
AST_MODULE_RELOAD_ERROR  An error occurred while reloading the module
AST_MODULE_RELOAD_IN_PROGRESS  A module reload request is already in progress
AST_MODULE_RELOAD_UNINITIALIZED  The module has not been initialized
AST_MODULE_RELOAD_NOT_IMPLEMENTED  This module doesn't support reloading

Definition at line 80 of file module.h.

00080                               {
00081    AST_MODULE_RELOAD_SUCCESS = 0,      /*!< The module was reloaded succesfully */
00082    AST_MODULE_RELOAD_QUEUED,           /*!< The module reload request was queued */
00083    AST_MODULE_RELOAD_NOT_FOUND,        /*!< The requested module was not found */
00084    AST_MODULE_RELOAD_ERROR,            /*!< An error occurred while reloading the module */
00085    AST_MODULE_RELOAD_IN_PROGRESS,      /*!< A module reload request is already in progress */
00086    AST_MODULE_RELOAD_UNINITIALIZED,    /*!< The module has not been initialized */
00087    AST_MODULE_RELOAD_NOT_IMPLEMENTED,  /*!< This module doesn't support reloading */
00088 };

Enumerator:
AST_MODULE_SUPPORT_UNKNOWN 
AST_MODULE_SUPPORT_CORE 
AST_MODULE_SUPPORT_EXTENDED 
AST_MODULE_SUPPORT_DEPRECATED 

Definition at line 90 of file module.h.

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 61 of file module.h.

00061                             {
00062    AST_FORCE_SOFT = 0, /*!< Softly unload a module, only if not in use */
00063    AST_FORCE_FIRM = 1, /*!< Firmly unload a module, even if in use */
00064    AST_FORCE_HARD = 2, /*!< as FIRM, plus dlclose() on the module. Not recommended
00065             as it may cause crashes */
00066 };


Function Documentation

struct ast_module* __ast_module_ref ( struct ast_module mod,
const char *  file,
int  line,
const char *  func 
) [read]

Definition at line 1474 of file loader.c.

References __ao2_ref_debug(), ast_atomic_fetchadd_int(), ast_update_use_count(), NULL, and ast_module::usecount.

Referenced by __ast_module_shutdown_ref().

01475 {
01476    if (!mod) {
01477       return NULL;
01478    }
01479 
01480 #ifdef REF_DEBUG
01481    __ao2_ref_debug(mod->ref_debug, +1, "", file, line, func);
01482 #endif
01483 
01484    ast_atomic_fetchadd_int(&mod->usecount, +1);
01485    ast_update_use_count();
01486 
01487    return mod;
01488 }

void __ast_module_shutdown_ref ( struct ast_module mod,
const char *  file,
int  line,
const char *  func 
)

Definition at line 1490 of file loader.c.

References __ast_module_ref(), ast_module::flags, and ast_module::keepuntilshutdown.

01491 {
01492    if (!mod || mod->flags.keepuntilshutdown) {
01493       return;
01494    }
01495 
01496    __ast_module_ref(mod, file, line, func);
01497    mod->flags.keepuntilshutdown = 1;
01498 }

void __ast_module_unref ( struct ast_module mod,
const char *  file,
int  line,
const char *  func 
)

Definition at line 1500 of file loader.c.

References __ao2_ref_debug(), ast_atomic_fetchadd_int(), ast_update_use_count(), and ast_module::usecount.

01501 {
01502    if (!mod) {
01503       return;
01504    }
01505 
01506 #ifdef REF_DEBUG
01507    __ao2_ref_debug(mod->ref_debug, -1, "", file, line, func);
01508 #endif
01509 
01510    ast_atomic_fetchadd_int(&mod->usecount, -1);
01511    ast_update_use_count();
01512 }

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

Definition at line 258 of file loader.c.

References ao2_ref, ast_atomic_fetchadd_int(), ast_calloc, AST_LIST_INSERT_HEAD, AST_LIST_LOCK, AST_LIST_UNLOCK, ast_update_use_count(), ast_module_user::chan, NULL, ast_module::usecount, and ast_module::users.

Referenced by ast_func_read(), ast_func_read2(), ast_func_write(), and pbx_exec().

00259 {
00260    struct ast_module_user *u;
00261 
00262    u = ast_calloc(1, sizeof(*u));
00263    if (!u) {
00264       return NULL;
00265    }
00266 
00267    u->chan = chan;
00268 
00269    AST_LIST_LOCK(&mod->users);
00270    AST_LIST_INSERT_HEAD(&mod->users, u, entry);
00271    AST_LIST_UNLOCK(&mod->users);
00272 
00273 #ifdef REF_DEBUG
00274    ao2_ref(mod->ref_debug, +1);
00275 #endif
00276 
00277    ast_atomic_fetchadd_int(&mod->usecount, +1);
00278 
00279    ast_update_use_count();
00280 
00281    return u;
00282 }

void __ast_module_user_hangup_all ( struct ast_module  ) 

Definition at line 311 of file loader.c.

References ao2_ref, 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::usecount, and ast_module::users.

Referenced by ast_unload_resource().

00312 {
00313    struct ast_module_user *u;
00314 
00315    AST_LIST_LOCK(&mod->users);
00316    while ((u = AST_LIST_REMOVE_HEAD(&mod->users, entry))) {
00317       if (u->chan) {
00318          ast_softhangup(u->chan, AST_SOFTHANGUP_APPUNLOAD);
00319       }
00320 
00321 #ifdef REF_DEBUG
00322       ao2_ref(mod->ref_debug, -1);
00323 #endif
00324 
00325       ast_atomic_fetchadd_int(&mod->usecount, -1);
00326       ast_free(u);
00327    }
00328    AST_LIST_UNLOCK(&mod->users);
00329 
00330    ast_update_use_count();
00331 }

void __ast_module_user_remove ( struct ast_module ,
struct ast_module_user  
)

Definition at line 284 of file loader.c.

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

Referenced by ast_func_read(), ast_func_read2(), ast_func_write(), and pbx_exec().

00285 {
00286    if (!u) {
00287       return;
00288    }
00289 
00290    AST_LIST_LOCK(&mod->users);
00291    u = AST_LIST_REMOVE(&mod->users, u, entry);
00292    AST_LIST_UNLOCK(&mod->users);
00293    if (!u) {
00294       /*
00295        * Was not in the list.  Either a bad pointer or
00296        * __ast_module_user_hangup_all() has been called.
00297        */
00298       return;
00299    }
00300 
00301 #ifdef REF_DEBUG
00302    ao2_ref(mod->ref_debug, -1);
00303 #endif
00304 
00305    ast_atomic_fetchadd_int(&mod->usecount, -1);
00306    ast_free(u);
00307 
00308    ast_update_use_count();
00309 }

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 initialization 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 1116 of file loader.c.

References AST_DLLIST_LOCK, AST_DLLIST_UNLOCK, ast_test_suite_event_notify, load_resource(), and NULL.

Referenced by handle_load(), load_module(), and manager_moduleload().

01117 {
01118    int res;
01119    AST_DLLIST_LOCK(&module_list);
01120    res = load_resource(resource_name, 0, NULL, 0);
01121    if (!res) {
01122       ast_test_suite_event_notify("MODULE_LOAD", "Message: %s", resource_name);
01123    }
01124    AST_DLLIST_UNLOCK(&module_list);
01125 
01126    return res;
01127 }

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.

Return values:
0 on success
-1 on failure.

Definition at line 1442 of file loader.c.

References AST_LIST_INSERT_HEAD, AST_LIST_LOCK, AST_LIST_UNLOCK, ast_malloc, tmp(), and loadupdate::updater.

01443 {
01444    struct loadupdate *tmp;
01445 
01446    if (!(tmp = ast_malloc(sizeof(*tmp))))
01447       return -1;
01448 
01449    tmp->updater = v;
01450    AST_LIST_LOCK(&updaters);
01451    AST_LIST_INSERT_HEAD(&updaters, tmp, entry);
01452    AST_LIST_UNLOCK(&updaters);
01453 
01454    return 0;
01455 }

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.

Return values:
0 on success
-1 on failure.

Definition at line 1457 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.

01458 {
01459    struct loadupdate *cur;
01460 
01461    AST_LIST_LOCK(&updaters);
01462    AST_LIST_TRAVERSE_SAFE_BEGIN(&updaters, cur, entry) {
01463       if (cur->updater == v)  {
01464          AST_LIST_REMOVE_CURRENT(entry);
01465          break;
01466       }
01467    }
01468    AST_LIST_TRAVERSE_SAFE_END;
01469    AST_LIST_UNLOCK(&updaters);
01470 
01471    return cur ? 0 : -1;
01472 }

int ast_module_check ( const char *  name  ) 

Check if module with the name given is loaded.

Parameters:
name Module name, like "chan_sip.so"
Return values:
1 if true
0 if false

Definition at line 1429 of file loader.c.

References ast_strlen_zero, find_resource(), and NULL.

Referenced by ifmodule_read(), load_module(), manager_modulecheck(), and unload_module().

01430 {
01431    struct ast_module *cur;
01432 
01433    if (ast_strlen_zero(name))
01434       return 0;       /* FALSE */
01435 
01436    cur = find_resource(name, 1);
01437 
01438    return (cur != NULL);
01439 }

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.
Return values:
A possible completion of the partial match.
NULL if no matches were found.

Definition at line 741 of file loader.c.

References AST_DLLIST_LOCK, AST_DLLIST_TRAVERSE, AST_DLLIST_UNLOCK, ast_strdup, ast_module::info, NULL, ast_module_info::reload, and ast_module::resource.

Referenced by conf_run(), confbridge_exec(), handle_modlist(), handle_reload(), and handle_unload().

00742 {
00743    struct ast_module *cur;
00744    int i, which=0, l = strlen(word);
00745    char *ret = NULL;
00746 
00747    if (pos != rpos)
00748       return NULL;
00749 
00750    AST_DLLIST_LOCK(&module_list);
00751    AST_DLLIST_TRAVERSE(&module_list, cur, entry) {
00752       if (!strncasecmp(word, cur->resource, l) &&
00753           (cur->info->reload || !needsreload) &&
00754           ++which > state) {
00755          ret = ast_strdup(cur->resource);
00756          break;
00757       }
00758    }
00759    AST_DLLIST_UNLOCK(&module_list);
00760 
00761    if (!ret) {
00762       for (i=0; !ret && reload_classes[i].name; i++) {
00763          if (!strncasecmp(word, reload_classes[i].name, l) && ++which > state)
00764             ret = ast_strdup(reload_classes[i].name);
00765       }
00766    }
00767 
00768    return ret;
00769 }

const char* ast_module_name ( const struct ast_module mod  ) 

Get the name of a module.

Parameters:
mod A pointer to the module.
Returns:
the name of the module
Return values:
NULL if mod or mod->info is NULL

Definition at line 144 of file loader.c.

References NULL.

Referenced by acf_retrieve_docs(), and ast_register_application2().

00145 {
00146    if (!mod || !mod->info) {
00147       return NULL;
00148    }
00149 
00150    return mod->info->name;
00151 }

void ast_module_register ( const struct ast_module_info  ) 

Definition at line 187 of file loader.c.

References ao2_t_alloc, ast_calloc, ast_debug, AST_DLLIST_INSERT_TAIL, AST_DLLIST_LOCK, AST_DLLIST_UNLOCK, AST_LIST_HEAD_INIT, embedded_module_list, embedding, ast_module::info, NULL, ast_module::resource, and ast_module::users.

00188 {
00189    struct ast_module *mod;
00190 
00191    if (embedding) {
00192       if (!(mod = ast_calloc(1, sizeof(*mod) + strlen(info->name) + 1)))
00193          return;
00194       strcpy(mod->resource, info->name);
00195    } else {
00196       mod = resource_being_loaded;
00197    }
00198 
00199    ast_debug(5, "Registering module %s\n", info->name);
00200 
00201    mod->info = info;
00202 #ifdef REF_DEBUG
00203    mod->ref_debug = ao2_t_alloc(0, NULL, info->name);
00204 #endif
00205    AST_LIST_HEAD_INIT(&mod->users);
00206 
00207    /* during startup, before the loader has been initialized,
00208       there are no threads, so there is no need to take the lock
00209       on this list to manipulate it. it is also possible that it
00210       might be unsafe to use the list lock at that point... so
00211       let's avoid it altogether
00212    */
00213    if (embedding) {
00214       AST_DLLIST_INSERT_TAIL(&embedded_module_list, mod, entry);
00215    } else {
00216       AST_DLLIST_LOCK(&module_list);
00217       /* it is paramount that the new entry be placed at the tail of
00218          the list, otherwise the code that uses dlopen() to load
00219          dynamic modules won't be able to find out if the module it
00220          just opened was registered or failed to load
00221       */
00222       AST_DLLIST_INSERT_TAIL(&module_list, mod, entry);
00223       AST_DLLIST_UNLOCK(&module_list);
00224    }
00225 
00226    /* give the module a copy of its own handle, for later use in registrations and the like */
00227    *((struct ast_module **) &(info->self)) = mod;
00228 }

enum ast_module_reload_result ast_module_reload ( const char *  name  ) 

Reload asterisk modules.

Parameters:
name the name of the module to reload
This function reloads the specified module, or if no modules are specified, it will reload all loaded modules.

Note:
Modules are reloaded using their reload() functions, not unloading them and loading them again.
Return values:
The ast_module_reload_result status of the module load request

Definition at line 877 of file loader.c.

References ast_config_AST_CONFIG_DIR, AST_DLLIST_LOCK, AST_DLLIST_TRAVERSE, AST_DLLIST_UNLOCK, ast_lastreloadtime, ast_lock_path(), AST_LOCK_SUCCESS, AST_LOCK_TIMEOUT, ast_log, AST_LOG_WARNING, AST_MODULE_LOAD_SUCCESS, AST_MODULE_RELOAD_ERROR, AST_MODULE_RELOAD_IN_PROGRESS, AST_MODULE_RELOAD_NOT_FOUND, AST_MODULE_RELOAD_NOT_IMPLEMENTED, AST_MODULE_RELOAD_QUEUED, AST_MODULE_RELOAD_SUCCESS, AST_MODULE_RELOAD_UNINITIALIZED, ast_mutex_trylock, ast_mutex_unlock, ast_opt_lock_confdir, ast_tvnow(), ast_unlock_path(), ast_verb, ast_module::declined, ast_module_info::description, ast_module::flags, ast_module::info, LOG_WARNING, modules_loaded, publish_reload_message(), queue_reload_request(), ast_module_info::reload, ast_module::resource, resource_name_match(), and ast_module::running.

Referenced by action_reload(), action_updateconfig(), ast_process_pending_reloads(), handle_core_reload(), handle_reload(), manager_moduleload(), and monitor_sig_flags().

00878 {
00879    struct ast_module *cur;
00880    enum ast_module_reload_result res = AST_MODULE_RELOAD_NOT_FOUND;
00881    int i;
00882 
00883    /* If we aren't fully booted, we just pretend we reloaded but we queue this
00884       up to run once we are booted up. */
00885    if (!modules_loaded) {
00886       queue_reload_request(name);
00887       res = AST_MODULE_RELOAD_QUEUED;
00888       goto module_reload_exit;
00889    }
00890 
00891    if (ast_mutex_trylock(&reloadlock)) {
00892       ast_verb(3, "The previous reload command didn't finish yet\n");
00893       res = AST_MODULE_RELOAD_IN_PROGRESS;
00894       goto module_reload_exit;
00895    }
00896    ast_lastreloadtime = ast_tvnow();
00897 
00898    if (ast_opt_lock_confdir) {
00899       int try;
00900       int res;
00901       for (try = 1, res = AST_LOCK_TIMEOUT; try < 6 && (res == AST_LOCK_TIMEOUT); try++) {
00902          res = ast_lock_path(ast_config_AST_CONFIG_DIR);
00903          if (res == AST_LOCK_TIMEOUT) {
00904             ast_log(LOG_WARNING, "Failed to grab lock on %s, try %d\n", ast_config_AST_CONFIG_DIR, try);
00905          }
00906       }
00907       if (res != AST_LOCK_SUCCESS) {
00908          ast_log(AST_LOG_WARNING, "Cannot grab lock on %s\n", ast_config_AST_CONFIG_DIR);
00909          ast_mutex_unlock(&reloadlock);
00910          res = AST_MODULE_RELOAD_ERROR;
00911          goto module_reload_exit;
00912       }
00913    }
00914 
00915    /* Call "predefined" reload here first */
00916    for (i = 0; reload_classes[i].name; i++) {
00917       if (!name || !strcasecmp(name, reload_classes[i].name)) {
00918          if (reload_classes[i].reload_fn() == AST_MODULE_LOAD_SUCCESS) {
00919             res = AST_MODULE_RELOAD_SUCCESS;
00920          }
00921       }
00922    }
00923 
00924    if (name && res == AST_MODULE_RELOAD_SUCCESS) {
00925       if (ast_opt_lock_confdir) {
00926          ast_unlock_path(ast_config_AST_CONFIG_DIR);
00927       }
00928       ast_mutex_unlock(&reloadlock);
00929       goto module_reload_exit;
00930    }
00931 
00932    AST_DLLIST_LOCK(&module_list);
00933    AST_DLLIST_TRAVERSE(&module_list, cur, entry) {
00934       const struct ast_module_info *info = cur->info;
00935 
00936       if (name && resource_name_match(name, cur->resource))
00937          continue;
00938 
00939       if (!cur->flags.running || cur->flags.declined) {
00940          if (res == AST_MODULE_RELOAD_NOT_FOUND) {
00941             res = AST_MODULE_RELOAD_UNINITIALIZED;
00942          }
00943          if (!name) {
00944             continue;
00945          }
00946          break;
00947       }
00948 
00949       if (!info->reload) { /* cannot be reloaded */
00950          if (res == AST_MODULE_RELOAD_NOT_FOUND) {
00951             res = AST_MODULE_RELOAD_NOT_IMPLEMENTED;
00952          }
00953          if (!name) {
00954             continue;
00955          }
00956          break;
00957       }
00958       ast_verb(3, "Reloading module '%s' (%s)\n", cur->resource, info->description);
00959       if (info->reload() == AST_MODULE_LOAD_SUCCESS) {
00960          res = AST_MODULE_RELOAD_SUCCESS;
00961       }
00962       if (name) {
00963          break;
00964       }
00965    }
00966    AST_DLLIST_UNLOCK(&module_list);
00967 
00968    if (ast_opt_lock_confdir) {
00969       ast_unlock_path(ast_config_AST_CONFIG_DIR);
00970    }
00971    ast_mutex_unlock(&reloadlock);
00972 
00973 module_reload_exit:
00974    publish_reload_message(name, res);
00975    return res;
00976 }

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 612 of file loader.c.

References ao2_cleanup, ast_debug, AST_DLLIST_LOCK, AST_DLLIST_REMOVE_CURRENT, AST_DLLIST_TRAVERSE, AST_DLLIST_TRAVERSE_BACKWARDS_SAFE_BEGIN, AST_DLLIST_TRAVERSE_BACKWARDS_SAFE_END, AST_DLLIST_UNLOCK, ast_free, AST_LIST_HEAD_DESTROY, ast_module_unref, ast_verb, ast_module::declined, ast_module::flags, ast_module::info, ast_module::keepuntilshutdown, ast_module::resource, ast_module::running, ast_module_info::unload, ast_module::usecount, and ast_module::users.

Referenced by really_quit().

00613 {
00614    struct ast_module *mod;
00615    int somethingchanged = 1, final = 0;
00616 
00617    AST_DLLIST_LOCK(&module_list);
00618 
00619    /*!\note Some resources, like timers, are started up dynamically, and thus
00620     * may be still in use, even if all channels are dead.  We must therefore
00621     * check the usecount before asking modules to unload. */
00622    do {
00623       if (!somethingchanged) {
00624          /*!\note If we go through the entire list without changing
00625           * anything, ignore the usecounts and unload, then exit. */
00626          final = 1;
00627       }
00628 
00629       /* Reset flag before traversing the list */
00630       somethingchanged = 0;
00631 
00632       AST_DLLIST_TRAVERSE_BACKWARDS_SAFE_BEGIN(&module_list, mod, entry) {
00633          if (!final && mod->usecount) {
00634             ast_debug(1, "Passing on %s: its use count is %d\n",
00635                mod->resource, mod->usecount);
00636             continue;
00637          }
00638          AST_DLLIST_REMOVE_CURRENT(entry);
00639          if (mod->flags.running && !mod->flags.declined && mod->info->unload) {
00640             ast_verb(1, "Unloading %s\n", mod->resource);
00641             mod->info->unload();
00642          }
00643          AST_LIST_HEAD_DESTROY(&mod->users);
00644 #ifdef REF_DEBUG
00645          ao2_cleanup(mod->ref_debug);
00646 #endif
00647          ast_free(mod);
00648          somethingchanged = 1;
00649       }
00650       AST_DLLIST_TRAVERSE_BACKWARDS_SAFE_END;
00651       if (!somethingchanged) {
00652          AST_DLLIST_TRAVERSE(&module_list, mod, entry) {
00653             if (mod->flags.keepuntilshutdown) {
00654                ast_module_unref(mod);
00655                mod->flags.keepuntilshutdown = 0;
00656                somethingchanged = 1;
00657             }
00658          }
00659       }
00660    } while (somethingchanged && !final);
00661 
00662    AST_DLLIST_UNLOCK(&module_list);
00663 }

const char* ast_module_support_level_to_string ( enum ast_module_support_level  support_level  ) 

Definition at line 1521 of file loader.c.

References support_level_map.

Referenced by modlist_modentry().

01522 {
01523    return support_level_map[support_level];
01524 }

void ast_module_unregister ( const struct ast_module_info  ) 

Definition at line 230 of file loader.c.

References ao2_cleanup, ast_debug, AST_DLLIST_LOCK, AST_DLLIST_REMOVE_CURRENT, AST_DLLIST_TRAVERSE_BACKWARDS_SAFE_BEGIN, AST_DLLIST_TRAVERSE_BACKWARDS_SAFE_END, AST_DLLIST_UNLOCK, ast_free, AST_LIST_HEAD_DESTROY, ast_module::info, ast_module_info::name, NULL, and ast_module::users.

00231 {
00232    struct ast_module *mod = NULL;
00233 
00234    /* it is assumed that the users list in the module structure
00235       will already be empty, or we cannot have gotten to this
00236       point
00237    */
00238    AST_DLLIST_LOCK(&module_list);
00239    AST_DLLIST_TRAVERSE_BACKWARDS_SAFE_BEGIN(&module_list, mod, entry) {
00240       if (mod->info == info) {
00241          AST_DLLIST_REMOVE_CURRENT(entry);
00242          break;
00243       }
00244    }
00245    AST_DLLIST_TRAVERSE_BACKWARDS_SAFE_END;
00246    AST_DLLIST_UNLOCK(&module_list);
00247 
00248    if (mod) {
00249       ast_debug(5, "Unregistering module %s\n", info->name);
00250       AST_LIST_HEAD_DESTROY(&mod->users);
00251 #ifdef REF_DEBUG
00252       ao2_cleanup(mod->ref_debug);
00253 #endif
00254       ast_free(mod);
00255    }
00256 }

int ast_register_application2 ( const char *  app,
int(*)(struct ast_channel *, const char *)  execute,
const char *  synopsis,
const char *  description,
void *  mod 
)

Register an application.

Parameters:
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
This registers an application with Asterisk's internal application list.
Note:
The individual applications themselves are responsible for registering and unregistering and unregistering their own CLI commands.
Return values:
0 success
-1 failure.

Definition at line 7176 of file pbx.c.

References ast_app::arguments, ast_calloc, ast_free, ast_log, ast_module_name(), AST_RWLIST_INSERT_BEFORE_CURRENT, AST_RWLIST_INSERT_TAIL, AST_RWLIST_TRAVERSE_SAFE_BEGIN, AST_RWLIST_TRAVERSE_SAFE_END, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, AST_STATIC_DOC, ast_string_field_init, ast_string_field_set, ast_strlen_zero, ast_verb, AST_XML_DOC, COLOR_BRCYAN, COLORIZE, COLORIZE_FMT, ast_app::execute, LOG_WARNING, ast_app::module, ast_app::name, pbx_findapp_nolock(), ast_app::seealso, ast_app::syntax, and tmp().

Referenced by ast_cc_init(), ast_features_init(), ast_msg_init(), and load_pbx().

07177 {
07178    struct ast_app *tmp;
07179    struct ast_app *cur;
07180    int length;
07181 #ifdef AST_XML_DOCS
07182    char *tmpxml;
07183 #endif
07184 
07185    AST_RWLIST_WRLOCK(&apps);
07186    cur = pbx_findapp_nolock(app);
07187    if (cur) {
07188       ast_log(LOG_WARNING, "Already have an application '%s'\n", app);
07189       AST_RWLIST_UNLOCK(&apps);
07190       return -1;
07191    }
07192 
07193    length = sizeof(*tmp) + strlen(app) + 1;
07194 
07195    if (!(tmp = ast_calloc(1, length))) {
07196       AST_RWLIST_UNLOCK(&apps);
07197       return -1;
07198    }
07199 
07200    if (ast_string_field_init(tmp, 128)) {
07201       AST_RWLIST_UNLOCK(&apps);
07202       ast_free(tmp);
07203       return -1;
07204    }
07205 
07206    strcpy(tmp->name, app);
07207    tmp->execute = execute;
07208    tmp->module = mod;
07209 
07210 #ifdef AST_XML_DOCS
07211    /* Try to lookup the docs in our XML documentation database */
07212    if (ast_strlen_zero(synopsis) && ast_strlen_zero(description)) {
07213       /* load synopsis */
07214       tmpxml = ast_xmldoc_build_synopsis("application", app, ast_module_name(tmp->module));
07215       ast_string_field_set(tmp, synopsis, tmpxml);
07216       ast_free(tmpxml);
07217 
07218       /* load description */
07219       tmpxml = ast_xmldoc_build_description("application", app, ast_module_name(tmp->module));
07220       ast_string_field_set(tmp, description, tmpxml);
07221       ast_free(tmpxml);
07222 
07223       /* load syntax */
07224       tmpxml = ast_xmldoc_build_syntax("application", app, ast_module_name(tmp->module));
07225       ast_string_field_set(tmp, syntax, tmpxml);
07226       ast_free(tmpxml);
07227 
07228       /* load arguments */
07229       tmpxml = ast_xmldoc_build_arguments("application", app, ast_module_name(tmp->module));
07230       ast_string_field_set(tmp, arguments, tmpxml);
07231       ast_free(tmpxml);
07232 
07233       /* load seealso */
07234       tmpxml = ast_xmldoc_build_seealso("application", app, ast_module_name(tmp->module));
07235       ast_string_field_set(tmp, seealso, tmpxml);
07236       ast_free(tmpxml);
07237       tmp->docsrc = AST_XML_DOC;
07238    } else {
07239 #endif
07240       ast_string_field_set(tmp, synopsis, synopsis);
07241       ast_string_field_set(tmp, description, description);
07242 #ifdef AST_XML_DOCS
07243       tmp->docsrc = AST_STATIC_DOC;
07244    }
07245 #endif
07246 
07247    /* Store in alphabetical order */
07248    AST_RWLIST_TRAVERSE_SAFE_BEGIN(&apps, cur, list) {
07249       if (strcasecmp(tmp->name, cur->name) < 0) {
07250          AST_RWLIST_INSERT_BEFORE_CURRENT(tmp, list);
07251          break;
07252       }
07253    }
07254    AST_RWLIST_TRAVERSE_SAFE_END;
07255    if (!cur)
07256       AST_RWLIST_INSERT_TAIL(&apps, tmp, list);
07257 
07258    ast_verb(2, "Registered application '" COLORIZE_FMT "'\n", COLORIZE(COLOR_BRCYAN, 0, tmp->name));
07259 
07260    AST_RWLIST_UNLOCK(&apps);
07261 
07262    return 0;
07263 }

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

Return values:
0 on success.
-1 on error.

Definition at line 665 of file loader.c.

References __ast_module_user_hangup_all(), AST_DLLIST_LOCK, AST_DLLIST_UNLOCK, AST_FORCE_FIRM, ast_log, ast_test_suite_event_notify, ast_update_use_count(), ast_verb, ast_module::declined, find_resource(), ast_module::flags, ast_module::info, ast_module::lib, LOG_WARNING, ast_module::resource, ast_module_info::restore_globals, ast_module::running, ast_module_info::unload, and ast_module::usecount.

Referenced by handle_unload(), manager_moduleload(), and unload_module().

00666 {
00667    struct ast_module *mod;
00668    int res = -1;
00669    int error = 0;
00670 
00671    AST_DLLIST_LOCK(&module_list);
00672 
00673    if (!(mod = find_resource(resource_name, 0))) {
00674       AST_DLLIST_UNLOCK(&module_list);
00675       ast_log(LOG_WARNING, "Unload failed, '%s' could not be found\n", resource_name);
00676       return -1;
00677    }
00678 
00679    if (!mod->flags.running || mod->flags.declined) {
00680       ast_log(LOG_WARNING, "Unload failed, '%s' is not loaded.\n", resource_name);
00681       error = 1;
00682    }
00683 
00684    if (!error && (mod->usecount > 0)) {
00685       if (force)
00686          ast_log(LOG_WARNING, "Warning:  Forcing removal of module '%s' with use count %d\n",
00687             resource_name, mod->usecount);
00688       else {
00689          ast_log(LOG_WARNING, "Soft unload failed, '%s' has use count %d\n", resource_name,
00690             mod->usecount);
00691          error = 1;
00692       }
00693    }
00694 
00695    if (!error) {
00696       /* Request any channels attached to the module to hangup. */
00697       __ast_module_user_hangup_all(mod);
00698 
00699       ast_verb(1, "Unloading %s\n", mod->resource);
00700       res = mod->info->unload();
00701       if (res) {
00702          ast_log(LOG_WARNING, "Firm unload failed for %s\n", resource_name);
00703          if (force <= AST_FORCE_FIRM) {
00704             error = 1;
00705          } else {
00706             ast_log(LOG_WARNING, "** Dangerous **: Unloading resource anyway, at user request\n");
00707          }
00708       }
00709 
00710       if (!error) {
00711          /*
00712           * Request hangup on any channels that managed to get attached
00713           * while we called the module unload function.
00714           */
00715          __ast_module_user_hangup_all(mod);
00716          sched_yield();
00717       }
00718    }
00719 
00720    if (!error)
00721       mod->flags.running = mod->flags.declined = 0;
00722 
00723    AST_DLLIST_UNLOCK(&module_list);
00724 
00725    if (!error && !mod->lib && mod->info && mod->info->restore_globals)
00726       mod->info->restore_globals();
00727 
00728 #ifdef LOADABLE_MODULES
00729    if (!error) {
00730       unload_dynamic_module(mod);
00731       ast_test_suite_event_notify("MODULE_UNLOAD", "Message: %s", resource_name);
00732    }
00733 #endif
00734 
00735    if (!error)
00736       ast_update_use_count();
00737 
00738    return res;
00739 }

int ast_unregister_application ( const char *  app  ) 

Unregister an application.

Parameters:
app name of the application (does not have to be the same string as the one that was registered)
This unregisters an application from Asterisk's internal application list.

Return values:
0 success
-1 failure

Definition at line 8621 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_string_field_free_memory, ast_verb, ast_app::name, NULL, and unreference_cached_app().

Referenced by __unload_module(), cc_shutdown(), features_shutdown(), load_module(), message_shutdown(), unload_module(), unload_parking_applications(), and unload_pbx().

08622 {
08623    struct ast_app *cur;
08624    int cmp;
08625 
08626    AST_RWLIST_WRLOCK(&apps);
08627    AST_RWLIST_TRAVERSE_SAFE_BEGIN(&apps, cur, list) {
08628       cmp = strcasecmp(app, cur->name);
08629       if (cmp > 0) {
08630          continue;
08631       }
08632       if (!cmp) {
08633          /* Found it. */
08634          unreference_cached_app(cur);
08635          AST_RWLIST_REMOVE_CURRENT(list);
08636          ast_verb(2, "Unregistered application '%s'\n", cur->name);
08637          ast_string_field_free_memory(cur);
08638          ast_free(cur);
08639          break;
08640       }
08641       /* Not in container. */
08642       cur = NULL;
08643       break;
08644    }
08645    AST_RWLIST_TRAVERSE_SAFE_END;
08646    AST_RWLIST_UNLOCK(&apps);
08647 
08648    return cur ? 0 : -1;
08649 }

int ast_update_module_list ( int(*)(const char *module, const char *description, int usecnt, const char *status, const char *like, enum ast_module_support_level support_level)  modentry,
const char *  like 
)

Ask for a list of modules, descriptions, use counts and status.

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 1398 of file loader.c.

References AST_DLLIST_TRAVERSE, AST_DLLIST_TRYLOCK, AST_DLLIST_UNLOCK, AST_LIST_HEAD_NOLOCK, AST_LIST_HEAD_NOLOCK_INIT_VALUE, AST_LIST_INSERT_SORTALPHA, AST_LIST_REMOVE_HEAD, ast_module_info::description, ast_module::flags, ast_module::info, ast_module::list_entry, ast_module::resource, ast_module::running, ast_module_info::support_level, and ast_module::usecount.

Referenced by ast_var_Modules(), and handle_modlist().

01402 {
01403    struct ast_module *cur;
01404    int unlock = -1;
01405    int total_mod_loaded = 0;
01406    AST_LIST_HEAD_NOLOCK(, ast_module) alpha_module_list = AST_LIST_HEAD_NOLOCK_INIT_VALUE;
01407 
01408    if (AST_DLLIST_TRYLOCK(&module_list)) {
01409       unlock = 0;
01410    }
01411 
01412    AST_DLLIST_TRAVERSE(&module_list, cur, entry) {
01413       AST_LIST_INSERT_SORTALPHA(&alpha_module_list, cur, list_entry, resource);
01414    }
01415 
01416    while ((cur = AST_LIST_REMOVE_HEAD(&alpha_module_list, list_entry))) {
01417       total_mod_loaded += modentry(cur->resource, cur->info->description, cur->usecount,
01418                   cur->flags.running ? "Running" : "Not Running", like, cur->info->support_level);
01419    }
01420 
01421    if (unlock) {
01422       AST_DLLIST_UNLOCK(&module_list);
01423    }
01424 
01425    return total_mod_loaded;
01426 }

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 ast_module_user_* functions take care of calling this function for you.

Definition at line 1386 of file loader.c.

References AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, and loadupdate::updater.

Referenced by __ast_module_ref(), __ast_module_unref(), __ast_module_user_add(), __ast_module_user_hangup_all(), __ast_module_user_remove(), ast_unload_resource(), handle_request_do(), ooh323_hangup(), ooh323_new(), ooh323c_call_thread(), sip_request_call(), start_resource(), and unistim_new().

01387 {
01388    /* Notify any module monitors that the use count for a
01389       resource has changed */
01390    struct loadupdate *m;
01391 
01392    AST_LIST_LOCK(&updaters);
01393    AST_LIST_TRAVERSE(&updaters, m, entry)
01394       m->updater();
01395    AST_LIST_UNLOCK(&updaters);
01396 }


Variable Documentation

struct ast_module_info* ast_module_info [static]

Definition at line 404 of file module.h.


Generated on Thu Apr 16 06:32:02 2015 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6