[asterisk-commits] file: branch file/usecnt-cleanup r54284 - in
/team/file/usecnt-cleanup: inclu...
asterisk-commits at lists.digium.com
asterisk-commits at lists.digium.com
Tue Feb 13 15:36:22 MST 2007
Author: file
Date: Tue Feb 13 16:36:21 2007
New Revision: 54284
URL: http://svn.digium.com/view/asterisk?view=rev&rev=54284
Log:
Add module referencing to CDR handlers, and also add module linking to loader and registrations. The loader will now know about the registrations that each module does and during an unload it will be able to unregister them.
Modified:
team/file/usecnt-cleanup/include/asterisk/cdr.h
team/file/usecnt-cleanup/include/asterisk/module.h
team/file/usecnt-cleanup/include/asterisk/pbx.h
team/file/usecnt-cleanup/main/cdr.c
team/file/usecnt-cleanup/main/cli.c
team/file/usecnt-cleanup/main/file.c
team/file/usecnt-cleanup/main/loader.c
team/file/usecnt-cleanup/main/pbx.c
team/file/usecnt-cleanup/main/translate.c
Modified: team/file/usecnt-cleanup/include/asterisk/cdr.h
URL: http://svn.digium.com/view/asterisk/team/file/usecnt-cleanup/include/asterisk/cdr.h?view=diff&rev=54284&r1=54283&r2=54284
==============================================================================
--- team/file/usecnt-cleanup/include/asterisk/cdr.h (original)
+++ team/file/usecnt-cleanup/include/asterisk/cdr.h Tue Feb 13 16:36:21 2007
@@ -46,6 +46,8 @@
/* Include channel.h after relevant declarations it will need */
#include "asterisk/channel.h"
#include "asterisk/utils.h"
+
+struct ast_module;
/*! Responsible for call detail data */
struct ast_cdr {
@@ -143,7 +145,8 @@
* Used to register a Call Detail Record handler.
* Returns -1 on error, 0 on success.
*/
-int ast_cdr_register(const char *name, const char *desc, ast_cdrbe be);
+#define ast_cdr_register(a,b,c) __ast_cdr_register(a, b, c, ast_module_info->self)
+int __ast_cdr_register(const char *name, const char *desc, ast_cdrbe be, struct ast_module *mod);
/*! Unregister a CDR handling engine */
/*!
Modified: team/file/usecnt-cleanup/include/asterisk/module.h
URL: http://svn.digium.com/view/asterisk/team/file/usecnt-cleanup/include/asterisk/module.h?view=diff&rev=54284&r1=54283&r2=54284
==============================================================================
--- team/file/usecnt-cleanup/include/asterisk/module.h (original)
+++ team/file/usecnt-cleanup/include/asterisk/module.h Tue Feb 13 16:36:21 2007
@@ -65,12 +65,14 @@
};
enum ast_module_registered {
- AST_MODULE_REGISTERED_APPLICATION = (1 << 0), /*!< Module registered an application */
- AST_MODULE_REGISTERED_CHANNEL = (1 << 1), /*!< Module registered a channel tech */
- AST_MODULE_REGISTERED_CLI = (1 << 2), /*!< Module registered a CLI command */
- AST_MODULE_REGISTERED_SWITCH = (1 << 3), /*!< Module registered a PBX switch */
- AST_MODULE_REGISTERED_CODEC = (1 << 4), /*!< Module registered a codec */
- AST_MODULE_REGISTERED_FORMAT = (1 << 5), /*!< Module registered a format */
+ AST_MODULE_REGISTERED_APPLICATION = 0, /*!< Module registered an application */
+ AST_MODULE_REGISTERED_CHANNEL, /*!< Module registered a channel tech */
+ AST_MODULE_REGISTERED_CLI, /*!< Module registered a CLI command */
+ AST_MODULE_REGISTERED_SWITCH, /*!< Module registered a PBX switch */
+ AST_MODULE_REGISTERED_CODEC, /*!< Module registered a codec */
+ AST_MODULE_REGISTERED_FORMAT, /*!< Module registered a format */
+ AST_MODULE_REGISTERED_CDR, /*!< Module registered a CDR handler */
+ AST_MODULE_REGISTERED_FUNCTION, /*!< Module registered a dialplan function */
};
/*!
@@ -226,7 +228,8 @@
struct ast_module *ast_module_ref(struct ast_module *);
void ast_module_unref(struct ast_module *);
-void ast_module_registered(struct ast_module *, enum ast_module_registered registered);
+void ast_module_link(struct ast_module *, enum ast_module_registered registered, void *data);
+void ast_module_unlink(struct ast_module *, enum ast_module_registered registered, void *data);
#if defined(__cplusplus) || defined(c_plusplus)
#define AST_MODULE_INFO(keystr, flags_to_set, desc, load_func, unload_func, reload_func) \
Modified: team/file/usecnt-cleanup/include/asterisk/pbx.h
URL: http://svn.digium.com/view/asterisk/team/file/usecnt-cleanup/include/asterisk/pbx.h?view=diff&rev=54284&r1=54283&r2=54284
==============================================================================
--- team/file/usecnt-cleanup/include/asterisk/pbx.h (original)
+++ team/file/usecnt-cleanup/include/asterisk/pbx.h Tue Feb 13 16:36:21 2007
@@ -330,16 +330,6 @@
*/
int ast_unregister_application(const char *app);
-/*!
- * \brief Unregister all applications that are owned by a specific module
- *
- * \param mod Module that we should unload all applications for
- *
- * \retval 0 success
- * \retval -1 failure
- */
-int ast_unregister_module_applications(struct ast_module *mod);
-
/*!
* \brief Uses hint and devicestate callback to get the state of an extension
*
Modified: team/file/usecnt-cleanup/main/cdr.c
URL: http://svn.digium.com/view/asterisk/team/file/usecnt-cleanup/main/cdr.c?view=diff&rev=54284&r1=54283&r2=54284
==============================================================================
--- team/file/usecnt-cleanup/main/cdr.c (original)
+++ team/file/usecnt-cleanup/main/cdr.c Tue Feb 13 16:36:21 2007
@@ -54,6 +54,7 @@
#include "asterisk/config.h"
#include "asterisk/cli.h"
#include "asterisk/stringfields.h"
+#include "asterisk/module.h"
/*! Default AMA flag for billing records (CDR's) */
int ast_default_amaflags = AST_CDR_DOCUMENTATION;
@@ -62,6 +63,7 @@
struct ast_cdr_beitem {
char name[20];
char desc[80];
+ struct ast_module *module;
ast_cdrbe be;
AST_LIST_ENTRY(ast_cdr_beitem) list;
};
@@ -105,7 +107,7 @@
/*! Register a CDR driver. Each registered CDR driver generates a CDR
\return 0 on success, -1 on failure
*/
-int ast_cdr_register(const char *name, const char *desc, ast_cdrbe be)
+int __ast_cdr_register(const char *name, const char *desc, ast_cdrbe be, struct ast_module *mod)
{
struct ast_cdr_beitem *i;
@@ -131,6 +133,9 @@
if (!(i = ast_calloc(1, sizeof(*i))))
return -1;
+ if (mod)
+ ast_module_link(mod, AST_MODULE_REGISTERED_CDR, i);
+ i->module = mod;
i->be = be;
ast_copy_string(i->name, name, sizeof(i->name));
ast_copy_string(i->desc, desc, sizeof(i->desc));
@@ -150,6 +155,8 @@
AST_LIST_LOCK(&be_list);
AST_LIST_TRAVERSE_SAFE_BEGIN(&be_list, i, list) {
if (!strcasecmp(name, i->name)) {
+ if (i->module)
+ ast_module_unlink(i->module, AST_MODULE_REGISTERED_CDR, i);
AST_LIST_REMOVE_CURRENT(&be_list, list);
if (option_verbose > 1)
ast_verbose(VERBOSE_PREFIX_2 "Unregistered '%s' CDR backend\n", name);
@@ -732,7 +739,11 @@
ast_set_flag(cdr, AST_CDR_FLAG_POSTED);
AST_LIST_LOCK(&be_list);
AST_LIST_TRAVERSE(&be_list, i, list) {
+ if (i->module)
+ ast_module_ref(i->module);
i->be(cdr);
+ if (i->module)
+ ast_module_unref(i->module);
}
AST_LIST_UNLOCK(&be_list);
}
Modified: team/file/usecnt-cleanup/main/cli.c
URL: http://svn.digium.com/view/asterisk/team/file/usecnt-cleanup/main/cli.c?view=diff&rev=54284&r1=54283&r2=54284
==============================================================================
--- team/file/usecnt-cleanup/main/cli.c (original)
+++ team/file/usecnt-cleanup/main/cli.c Tue Feb 13 16:36:21 2007
@@ -1241,9 +1241,10 @@
static int __ast_cli_unregister(struct ast_cli_entry *e, struct ast_cli_entry *ed)
{
- if (e->deprecate_cmd) {
+ if (e->module)
+ ast_module_unlink(e->module, AST_MODULE_REGISTERED_CLI, e);
+ if (e->deprecate_cmd)
__ast_cli_unregister(e->deprecate_cmd, e);
- }
AST_LIST_LOCK(&helpers);
AST_LIST_REMOVE(&helpers, e, list);
AST_LIST_UNLOCK(&helpers);
@@ -1307,6 +1308,10 @@
*/
e->_deprecated_by = S_OR(ed->_deprecated_by, ed->_full_cmd);
}
+
+ e->module = mod;
+ if (mod)
+ ast_module_link(mod, AST_MODULE_REGISTERED_CLI, e);
lf = e->cmdlen;
AST_LIST_TRAVERSE_SAFE_BEGIN(&helpers, cur, list) {
Modified: team/file/usecnt-cleanup/main/file.c
URL: http://svn.digium.com/view/asterisk/team/file/usecnt-cleanup/main/file.c?view=diff&rev=54284&r1=54283&r2=54284
==============================================================================
--- team/file/usecnt-cleanup/main/file.c (original)
+++ team/file/usecnt-cleanup/main/file.c Tue Feb 13 16:36:21 2007
@@ -82,6 +82,8 @@
return -1;
}
*tmp = *f;
+ if (mod)
+ ast_module_link(mod, AST_MODULE_REGISTERED_FORMAT, tmp);
tmp->module = mod;
if (tmp->buf_size) {
/*
@@ -111,6 +113,8 @@
AST_RWLIST_WRLOCK(&formats);
AST_RWLIST_TRAVERSE_SAFE_BEGIN(&formats, tmp, list) {
if (!strcasecmp(name, tmp->name)) {
+ if (tmp->module)
+ ast_module_unlink(tmp->module, AST_MODULE_REGISTERED_FORMAT, tmp);
AST_RWLIST_REMOVE_CURRENT(&formats, list);
free(tmp);
res = 0;
Modified: team/file/usecnt-cleanup/main/loader.c
URL: http://svn.digium.com/view/asterisk/team/file/usecnt-cleanup/main/loader.c?view=diff&rev=54284&r1=54283&r2=54284
==============================================================================
--- team/file/usecnt-cleanup/main/loader.c (original)
+++ team/file/usecnt-cleanup/main/loader.c Tue Feb 13 16:36:21 2007
@@ -92,9 +92,15 @@
int usecount; /* the number of 'users' currently in this module */
struct module_user_list users; /* the list of users in the module */
unsigned int flags; /* flags for this module */
- unsigned int registered; /* what was registered by the module */
+ AST_LIST_HEAD_NOLOCK(, ast_module_link) links;
AST_LIST_ENTRY(ast_module) entry;
char resource[0];
+};
+
+struct ast_module_link {
+ enum ast_module_registered registered;
+ void *data;
+ AST_LIST_ENTRY(ast_module_link) list;
};
static AST_LIST_HEAD_STATIC(module_list, ast_module);
@@ -471,8 +477,6 @@
ast_log(LOG_WARNING, "** Dangerous **: Unloading resource anyway, at user request\n");
}
}
- if (mod->registered & AST_MODULE_REGISTERED_APPLICATION)
- res = ast_unregister_module_applications(mod);
}
if (!error)
@@ -938,7 +942,22 @@
ast_update_use_count();
}
-void ast_module_registered(struct ast_module *mod, enum ast_module_registered registered)
-{
- mod->registered |= registered;
-}
+void ast_module_link(struct ast_module *mod, enum ast_module_registered registered, void *data)
+{
+ struct ast_module_link *link = NULL;
+
+ if (!(link = ast_calloc(1, sizeof(*link))))
+ return;
+
+ link->registered = registered;
+ link->data = data;
+
+ AST_LIST_INSERT_TAIL(&mod->links, link, list);
+
+ return;
+}
+
+void ast_module_unlink(struct ast_module *mod, enum ast_module_registered registered, void *data)
+{
+ return;
+}
Modified: team/file/usecnt-cleanup/main/pbx.c
URL: http://svn.digium.com/view/asterisk/team/file/usecnt-cleanup/main/pbx.c?view=diff&rev=54284&r1=54283&r2=54284
==============================================================================
--- team/file/usecnt-cleanup/main/pbx.c (original)
+++ team/file/usecnt-cleanup/main/pbx.c Tue Feb 13 16:36:21 2007
@@ -1343,6 +1343,8 @@
AST_RWLIST_WRLOCK(&acf_root);
AST_RWLIST_TRAVERSE_SAFE_BEGIN(&acf_root, cur, acflist) {
if (cur == acf) {
+ if (acf->module)
+ ast_module_unlink(acf->module, AST_MODULE_REGISTERED_FUNCTION, acf);
AST_RWLIST_REMOVE_CURRENT(&acf_root, acflist);
if (option_verbose > 1)
ast_verbose(VERBOSE_PREFIX_2 "Unregistered custom function %s\n", acf->name);
@@ -1384,6 +1386,9 @@
AST_RWLIST_INSERT_TAIL(&acf_root, acf, acflist);
AST_RWLIST_UNLOCK(&acf_root);
+
+ if (mod)
+ ast_module_link(mod, AST_MODULE_REGISTERED_FUNCTION, acf);
acf->module = mod;
@@ -2857,8 +2862,10 @@
}
strcpy(tmp->name, app);
+
if (mod)
- ast_module_registered(mod, AST_MODULE_REGISTERED_APPLICATION);
+ ast_module_link(mod, AST_MODULE_REGISTERED_APPLICATION, tmp);
+
tmp->module = mod;
tmp->execute = execute;
tmp->synopsis = synopsis;
@@ -2899,6 +2906,8 @@
return -1;
}
}
+ if (mod)
+ ast_module_link(mod, AST_MODULE_REGISTERED_SWITCH, sw);
sw->module = mod;
AST_RWLIST_INSERT_TAIL(&switches, sw, list);
AST_RWLIST_UNLOCK(&switches);
@@ -2909,6 +2918,8 @@
void ast_unregister_switch(struct ast_switch *sw)
{
AST_RWLIST_WRLOCK(&switches);
+ if (sw->module)
+ ast_module_unlink(sw->module, AST_MODULE_REGISTERED_SWITCH, sw);
AST_RWLIST_REMOVE(&switches, sw, list);
AST_RWLIST_UNLOCK(&switches);
}
@@ -3763,6 +3774,8 @@
AST_RWLIST_WRLOCK(&apps);
AST_RWLIST_TRAVERSE_SAFE_BEGIN(&apps, tmp, list) {
if (!strcasecmp(app, tmp->name)) {
+ if (tmp->module)
+ ast_module_unlink(tmp->module, AST_MODULE_REGISTERED_APPLICATION, tmp);
unreference_cached_app(tmp);
AST_RWLIST_REMOVE_CURRENT(&apps, list);
if (option_verbose > 1)
@@ -3775,26 +3788,6 @@
AST_RWLIST_UNLOCK(&apps);
return tmp ? 0 : -1;
-}
-
-int ast_unregister_module_applications(struct ast_module *mod)
-{
- struct ast_app *tmp;
-
- AST_RWLIST_WRLOCK(&apps);
- AST_RWLIST_TRAVERSE_SAFE_BEGIN(&apps, tmp, list) {
- if (tmp->module == mod) {
- unreference_cached_app(tmp);
- AST_RWLIST_REMOVE_CURRENT(&apps, list);
- if (option_verbose > 1)
- ast_verbose( VERBOSE_PREFIX_2 "Unregistered application '%s'\n", tmp->name);
- free(tmp);
- }
- }
- AST_RWLIST_TRAVERSE_SAFE_END
- AST_RWLIST_UNLOCK(&apps);
-
- return 0;
}
static struct ast_context *__ast_context_create(struct ast_context **extcontexts, const char *name, const char *registrar, int existsokay)
Modified: team/file/usecnt-cleanup/main/translate.c
URL: http://svn.digium.com/view/asterisk/team/file/usecnt-cleanup/main/translate.c?view=diff&rev=54284&r1=54283&r2=54284
==============================================================================
--- team/file/usecnt-cleanup/main/translate.c (original)
+++ team/file/usecnt-cleanup/main/translate.c Tue Feb 13 16:36:21 2007
@@ -584,6 +584,9 @@
return -1;
}
+ if (mod)
+ ast_module_link(mod, AST_MODULE_REGISTERED_CODEC, t);
+
t->module = mod;
t->srcfmt = powerof(t->srcfmt);
@@ -675,6 +678,8 @@
AST_RWLIST_WRLOCK(&translators);
AST_RWLIST_TRAVERSE_SAFE_BEGIN(&translators, u, list) {
if (u == t) {
+ if (t->module)
+ ast_module_unlink(t->module, AST_MODULE_REGISTERED_CODEC, t);
AST_RWLIST_REMOVE_CURRENT(&translators, list);
if (option_verbose > 1)
ast_verbose(VERBOSE_PREFIX_2 "Unregistered translator '%s' from format %s to %s\n", term_color(tmp, t->name, COLOR_MAGENTA, COLOR_BLACK, sizeof(tmp)), ast_getformatname(1 << t->srcfmt), ast_getformatname(1 << t->dstfmt));
More information about the asterisk-commits
mailing list