diff options
author | rizzo <rizzo@f38db490-d61c-443f-a65b-d21fe96a405b> | 2006-04-14 14:08:19 +0000 |
---|---|---|
committer | rizzo <rizzo@f38db490-d61c-443f-a65b-d21fe96a405b> | 2006-04-14 14:08:19 +0000 |
commit | 3664249356aa4768fcb0b3b8e6cf9365fcbd0c8d (patch) | |
tree | b68f48482e463e9c31126b2e3e24fca1dd2f6c82 /channels | |
parent | f9d382fc079246930a99640d7835d6ae3e4149db (diff) |
This rather large commit changes the way modules are loaded.
As partly documented in loader.c and include/asterisk/module.h,
modules are now expected to return all of their methods and flags
into a structure 'mod_data', and are normally loaded with RTLD_NOW
| RTLD_LOCAL, so symbols are resolved immediately and conflicts
should be less likely. Only in a small number of cases (res_*,
typically) modules are loaded RTLD_GLOBAL, so they can export
symbols.
The core of the change is only the two files loader.c and
include/asterisk/module.h, all the rest is simply adaptation of the
existing modules to the new API, a rather mechanical (but believe
me, time and finger-consuming!) process whose detail you can figure
out by svn diff'ing any single module.
Expect some minor compilation issue after this change, please
report it on mantis http://bugs.digium.com/view.php?id=6968
so we collect all the feedback in one place.
I am just sorry that this change missed SVN version number 20000!
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@20003 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'channels')
-rw-r--r-- | channels/chan_agent.c | 34 | ||||
-rw-r--r-- | channels/chan_features.c | 23 | ||||
-rw-r--r-- | channels/chan_iax2.c | 20 | ||||
-rw-r--r-- | channels/chan_local.c | 36 | ||||
-rw-r--r-- | channels/chan_mgcp.c | 31 | ||||
-rw-r--r-- | channels/chan_oss.c | 15 | ||||
-rw-r--r-- | channels/chan_phone.c | 15 | ||||
-rw-r--r-- | channels/chan_sip.c | 17 | ||||
-rw-r--r-- | channels/chan_skinny.c | 17 | ||||
-rw-r--r-- | channels/chan_zap.c | 34 |
10 files changed, 86 insertions, 156 deletions
diff --git a/channels/chan_agent.c b/channels/chan_agent.c index d5b565f55..46cce1f87 100644 --- a/channels/chan_agent.c +++ b/channels/chan_agent.c @@ -73,7 +73,6 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") #include "asterisk/monitor.h" #include "asterisk/stringfields.h" -static const char desc[] = "Agent Proxy Channel"; static const char tdesc[] = "Call Agent Proxy Channel"; static const char config[] = "agents.conf"; @@ -163,9 +162,6 @@ static int autologoffunavail = 0; static int maxlogintries = 3; static char agentgoodbye[AST_MAX_FILENAME_LEN] = "vm-goodbye"; -static int usecnt =0; -AST_MUTEX_DEFINE_STATIC(usecnt_lock); - static int recordagentcalls = 0; static char recordformat[AST_MAX_BUF] = ""; static char recordformatext[AST_MAX_BUF] = ""; @@ -727,9 +723,8 @@ static int agent_hangup(struct ast_channel *ast) * as in apps/app_chanisavail.c:chanavail_exec() */ - ast_mutex_lock(&usecnt_lock); - usecnt--; - ast_mutex_unlock(&usecnt_lock); + ast_atomic_fetchadd_int(&__mod_desc->usecnt, -1); + /* XXX do we need ast_update_use_count(); */ ast_log(LOG_DEBUG, "Hangup called for state %s\n", ast_state2str(ast->_state)); if (p->start && (ast->_state != AST_STATE_UP)) { @@ -931,9 +926,7 @@ static struct ast_channel *agent_new(struct agent_pvt *p, int state) ast_setstate(tmp, state); tmp->tech_pvt = p; p->owner = tmp; - ast_mutex_lock(&usecnt_lock); - usecnt++; - ast_mutex_unlock(&usecnt_lock); + ast_atomic_fetchadd_int(&__mod_desc->usecnt, +1); ast_update_use_count(); tmp->priority = 1; /* Wake up and wait for other applications (by definition the login app) @@ -1651,8 +1644,6 @@ static struct ast_cli_entry cli_agent_logoff = { { "agent", "logoff", NULL }, agent_logoff_cmd, "Sets an agent offline", agent_logoff_usage, complete_agent_logoff_cmd }; -LOCAL_USER_DECL; - /*! * \brief Log in agent application. * @@ -2484,8 +2475,9 @@ struct ast_custom_function agent_function = { * * @returns int Always 0. */ -int load_module() +static int load_module(void *mod) { + __mod_desc = mod; /* Make sure we can register our agent channel type */ if (ast_channel_register(&agent_tech)) { ast_log(LOG_ERROR, "Unable to register channel class 'Agent'\n"); @@ -2511,7 +2503,7 @@ int load_module() return 0; } -int reload() +static int reload(void *mod) { read_agent_config(); if (persistent_agents) @@ -2519,7 +2511,7 @@ int reload() return 0; } -int unload_module() +static int unload_module(void *mod) { struct agent_pvt *p; /* First, take us out of the channel loop */ @@ -2553,18 +2545,14 @@ int unload_module() return 0; } -int usecount() -{ - return usecnt; -} - -const char *key() +static const char *key(void) { return ASTERISK_GPL_KEY; } -const char *description() +static const char *description(void) { - return (char *) desc; + return "Agent Proxy Channel"; } +STD_MOD(MOD_0, reload, NULL, NULL); diff --git a/channels/chan_features.c b/channels/chan_features.c index 7dacc2e2c..a1eb195ab 100644 --- a/channels/chan_features.c +++ b/channels/chan_features.c @@ -63,7 +63,6 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") #include "asterisk/manager.h" #include "asterisk/stringfields.h" -static const char desc[] = "Feature Proxy Channel"; static const char tdesc[] = "Feature Proxy Channel Driver"; static int usecnt =0; @@ -535,7 +534,7 @@ static struct ast_cli_entry cli_show_features = { { "feature", "show", "channels", NULL }, features_show, "Show status of feature channels", show_features_usage, NULL }; -int load_module() +static int load_module(void *mod) { /* Make sure we can register our sip channel type */ if (ast_channel_register(&features_tech)) { @@ -546,12 +545,7 @@ int load_module() return 0; } -int reload() -{ - return 0; -} - -int unload_module() +static int unload_module(void *mod) { struct feature_pvt *p; @@ -574,18 +568,15 @@ int unload_module() return 0; } -int usecount() -{ - return usecnt; -} - -const char *key() +static const char *key(void) { return ASTERISK_GPL_KEY; } -const char *description() +static const char *description(void) { - return (char *) desc; + return "Feature Proxy Channel"; } +STD_MOD(MOD_1, NULL, NULL, NULL); + diff --git a/channels/chan_iax2.c b/channels/chan_iax2.c index 56ae4c03e..27270868e 100644 --- a/channels/chan_iax2.c +++ b/channels/chan_iax2.c @@ -152,7 +152,6 @@ static int nochecksums = 0; static struct ast_codec_pref prefs; -static const char desc[] = "Inter Asterisk eXchange (Ver 2)"; static const char tdesc[] = "Inter Asterisk eXchange Driver (Ver 2)"; static char context[80] = "default"; @@ -9358,7 +9357,7 @@ static int iax2_reload(int fd, int argc, char *argv[]) return reload_config(); } -int reload(void) +static int reload(void *mod) { return reload_config(); } @@ -10054,7 +10053,7 @@ static int __unload_module(void) return 0; } -int unload_module() +static int unload_module(void *mod) { ast_mutex_destroy(&iaxq.lock); ast_mutex_destroy(&userl.lock); @@ -10066,7 +10065,7 @@ int unload_module() /*! \brief Load IAX2 module, load configuraiton ---*/ -int load_module(void) +static int load_module(void *mod) { char *config = "iax.conf"; int res = 0; @@ -10158,17 +10157,14 @@ int load_module(void) return res; } -const char *description() +static const char *description(void) { - return (char *) desc; + return "Inter Asterisk eXchange (Ver 2)"; } -int usecount() -{ - return usecnt; -} - -const char *key() +static const char *key(void) { return ASTERISK_GPL_KEY; } + +STD_MOD(MOD_1, reload, NULL, NULL); diff --git a/channels/chan_local.c b/channels/chan_local.c index d994fb908..5705dc905 100644 --- a/channels/chan_local.c +++ b/channels/chan_local.c @@ -61,12 +61,8 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") #include "asterisk/manager.h" #include "asterisk/stringfields.h" -static const char desc[] = "Local Proxy Channel"; static const char tdesc[] = "Local Proxy Channel Driver"; -static int usecnt =0; -AST_MUTEX_DEFINE_STATIC(usecnt_lock); - #define IS_OUTBOUND(a,b) (a == b->chan ? 1 : 0) static struct ast_channel *local_request(const char *type, int format, void *data, int *cause); @@ -395,9 +391,7 @@ static int local_hangup(struct ast_channel *ast) p->owner = NULL; ast->tech_pvt = NULL; - ast_mutex_lock(&usecnt_lock); - usecnt--; - ast_mutex_unlock(&usecnt_lock); + ast_atomic_fetchadd_int(&__mod_desc->usecnt, -1); if (!p->owner && !p->chan) { /* Okay, done with the private part now, too. */ @@ -510,9 +504,7 @@ static struct ast_channel *local_new(struct local_pvt *p, int state) tmp2->tech_pvt = p; p->owner = tmp; p->chan = tmp2; - ast_mutex_lock(&usecnt_lock); - usecnt += 2; /* we allocate 2 new channels */ - ast_mutex_unlock(&usecnt_lock); + ast_atomic_fetchadd_int(&__mod_desc->usecnt, +2); /* we allocate 2 new channels */ ast_update_use_count(); ast_copy_string(tmp->context, p->context, sizeof(tmp->context)); ast_copy_string(tmp2->context, p->context, sizeof(tmp2->context)); @@ -564,8 +556,10 @@ static struct ast_cli_entry cli_show_locals = { "Show status of local channels", show_locals_usage, NULL }; /*! \brief Load module into PBX, register channel */ -int load_module() +static int load_module(void *mod) { + __mod_desc = mod; + /* Make sure we can register our channel type */ if (ast_channel_register(&local_tech)) { ast_log(LOG_ERROR, "Unable to register channel class 'Local'\n"); @@ -575,14 +569,8 @@ int load_module() return 0; } -/*! \brief Reload module */ -int reload() -{ - return 0; -} - /*! \brief Unload the local proxy channel from Asterisk */ -int unload_module() +static int unload_module(void *mod) { struct local_pvt *p; @@ -604,18 +592,14 @@ int unload_module() return 0; } -int usecount() -{ - return usecnt; -} - -const char *key() +static const char *key(void) { return ASTERISK_GPL_KEY; } -const char *description() +static const char *description(void) { - return (char *) desc; + return "Local Proxy Channel"; } +STD_MOD(MOD_1, NULL, NULL, NULL); diff --git a/channels/chan_mgcp.c b/channels/chan_mgcp.c index 6fda77a48..ffba65f70 100644 --- a/channels/chan_mgcp.c +++ b/channels/chan_mgcp.c @@ -137,7 +137,6 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") #define INADDR_NONE (in_addr_t)(-1) #endif -static const char desc[] = "Media Gateway Control Protocol (MGCP)"; static const char tdesc[] = "Media Gateway Control Protocol (MGCP)"; static const char config[] = "mgcp.conf"; @@ -242,8 +241,6 @@ static int amaflags = 0; static int adsi = 0; -static int usecnt =0; -AST_MUTEX_DEFINE_STATIC(usecnt_lock); /* SC: transaction id should always be positive */ static unsigned int oseq; @@ -1057,9 +1054,7 @@ static int mgcp_hangup(struct ast_channel *ast) } /* SC: Decrement use count */ - ast_mutex_lock(&usecnt_lock); - usecnt--; - ast_mutex_unlock(&usecnt_lock); + ast_atomic_fetchadd_int(&__mod_desc->usecnt, -1); ast_update_use_count(); /* SC: Decrement use count */ @@ -1480,9 +1475,7 @@ static struct ast_channel *mgcp_new(struct mgcp_subchannel *sub, int state) if (i->amaflags) tmp->amaflags = i->amaflags; sub->owner = tmp; - ast_mutex_lock(&usecnt_lock); - usecnt++; - ast_mutex_unlock(&usecnt_lock); + ast_atomic_fetchadd_int(&__mod_desc->usecnt, +1); ast_update_use_count(); tmp->callgroup = i->callgroup; tmp->pickupgroup = i->pickupgroup; @@ -4323,10 +4316,11 @@ static int reload_config(void) } /*! \brief load_module: PBX load module - initialization ---*/ -int load_module() +static int load_module(void *mod) { int res; + __mod_desc = mod; sched = sched_context_create(); if (!sched) { ast_log(LOG_WARNING, "Unable to create schedule context\n"); @@ -4377,13 +4371,13 @@ static int mgcp_reload(int fd, int argc, char *argv[]) return 0; } -int reload(void) +static int reload(void *mod) { mgcp_reload(0, 0, NULL); return 0; } -int unload_module() +static int unload_module(void *mod) { struct mgcp_endpoint *e; struct mgcp_gateway *g; @@ -4455,17 +4449,14 @@ int unload_module() return 0; } -int usecount() -{ - return usecnt; -} - -const char *key() +static const char *key(void) { return ASTERISK_GPL_KEY; } -const char *description() +static const char *description(void) { - return (char *) desc; + return "Media Gateway Control Protocol (MGCP)"; } + +STD_MOD(MOD_1, reload, NULL, NULL); diff --git a/channels/chan_oss.c b/channels/chan_oss.c index 140ed21bd..8ee16dc33 100644 --- a/channels/chan_oss.c +++ b/channels/chan_oss.c @@ -1462,7 +1462,7 @@ error: return NULL; } -int load_module(void) +static int load_module(void *mod) { int i; struct ast_config *cfg; @@ -1497,7 +1497,7 @@ int load_module(void) } -int unload_module() +static int unload_module(void *mod) { struct chan_oss_pvt *o; @@ -1521,17 +1521,14 @@ int unload_module() return 0; } -const char *description() +static const char *description(void) { return (char *)oss_tech.description; } -int usecount() -{ - return usecnt; -} - -const char *key() +static const char *key(void) { return ASTERISK_GPL_KEY; } + +STD_MOD(MOD_1, NULL, NULL, NULL); diff --git a/channels/chan_phone.c b/channels/chan_phone.c index b556aa820..15c87dad1 100644 --- a/channels/chan_phone.c +++ b/channels/chan_phone.c @@ -1303,12 +1303,12 @@ static int __unload_module(void) return 0; } -int unload_module(void) +static int unload_module(void *mod) { return __unload_module(); } -int load_module() +static int load_module(void *mod) { struct ast_config *cfg; struct ast_variable *v; @@ -1415,17 +1415,14 @@ int load_module() return 0; } -int usecount() -{ - return usecnt; -} - -const char *description() +static const char *description(void) { return (char *) desc; } -const char *key() +static const char *key(void) { return ASTERISK_GPL_KEY; } + +STD_MOD1; diff --git a/channels/chan_sip.c b/channels/chan_sip.c index 8bef7aa74..2f123918d 100644 --- a/channels/chan_sip.c +++ b/channels/chan_sip.c @@ -13675,7 +13675,7 @@ static int sip_reload(int fd, int argc, char *argv[]) } /*! \brief reload: Part of Asterisk module interface */ -int reload(void) +static int reload(void *mod) { return sip_reload(0, 0, NULL); } @@ -13711,7 +13711,7 @@ static struct ast_cli_entry my_clis[] = { }; /*! \brief load_module: PBX load module - initialization */ -int load_module() +static int load_module(void *mod) { ASTOBJ_CONTAINER_INIT(&userl); /* User object list */ ASTOBJ_CONTAINER_INIT(&peerl); /* Peer object list */ @@ -13766,7 +13766,7 @@ int load_module() return 0; } -int unload_module() +static int unload_module(void *mod) { struct sip_pvt *p, *pl; @@ -13852,19 +13852,14 @@ int unload_module() return 0; } -int usecount() -{ - return usecnt; -} - -const char *key() +static const char *key(void) { return ASTERISK_GPL_KEY; } -const char *description() +static const char *description(void) { return (char *) desc; } - +STD_MOD(MOD_1, reload, NULL, NULL); diff --git a/channels/chan_skinny.c b/channels/chan_skinny.c index e47864824..411215397 100644 --- a/channels/chan_skinny.c +++ b/channels/chan_skinny.c @@ -3259,7 +3259,7 @@ static void delete_devices(void) ast_mutex_unlock(&devicelock); } -int reload(void) +static int reload(void *mod) { delete_devices(); reload_config(); @@ -3268,7 +3268,7 @@ int reload(void) } -int load_module() +static int load_module(void *mod) { int res = 0; @@ -3305,7 +3305,7 @@ int load_module() return res; } -int unload_module() +static int unload_module(void *mod) { #if 0 struct skinny_session *session, s; @@ -3360,17 +3360,14 @@ int unload_module() return -1; } -int usecount() -{ - return usecnt; -} - -const char *key(void) +static const char *key(void) { return ASTERISK_GPL_KEY; } -const char *description(void) +static const char *description(void) { return "Skinny Client Control Protocol (Skinny)"; } + +STD_MOD(MOD_1, reload, NULL, NULL); diff --git a/channels/chan_zap.c b/channels/chan_zap.c index ce0bcd461..c7341d29c 100644 --- a/channels/chan_zap.c +++ b/channels/chan_zap.c @@ -148,14 +148,6 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") /*! \brief Signaling types that need to use MF detection should be placed in this macro */ #define NEED_MFDETECT(p) (((p)->sig == SIG_FEATDMF) || ((p)->sig == SIG_FEATDMF_TA) || ((p)->sig == SIG_E911) || ((p)->sig == SIG_FGC_CAMA) || ((p)->sig == SIG_FGC_CAMAMF) || ((p)->sig == SIG_FEATB)) -static const char desc[] = "Zapata Telephony" -#ifdef ZAPATA_PRI - " w/PRI" -#endif -#ifdef ZAPATA_R2 - " w/R2" -#endif -; static const char tdesc[] = "Zapata Telephony Driver" #ifdef ZAPATA_PRI @@ -10367,7 +10359,7 @@ static int __unload_module(void) return 0; } -int unload_module() +static int unload_module(void *mod) { #ifdef ZAPATA_PRI int y; @@ -11225,7 +11217,7 @@ static int setup_zap(int reload) return 0; } -int load_module(void) +static int load_module(void *mod) { int res; @@ -11374,7 +11366,7 @@ static int zt_sendtext(struct ast_channel *c, const char *text) } -int reload(void) +static int reload(void *mod) { int res = 0; @@ -11386,18 +11378,20 @@ int reload(void) return 0; } -int usecount() +static const char *description(void) { - return usecnt; -} - -const char *description() -{ - return (char *) desc; + return "Zapata Telephony" +#ifdef ZAPATA_PRI + " w/PRI" +#endif +#ifdef ZAPATA_R2 + " w/R2" +#endif + ; } -const char *key() +static const char *key(void) { return ASTERISK_GPL_KEY; } - +STD_MOD(MOD_1, reload, NULL, NULL); |