[asterisk-commits] file: branch file/usecnt-cleanup r54146 - in /team/file/usecnt-cleanup: apps/...

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Mon Feb 12 18:22:04 MST 2007


Author: file
Date: Mon Feb 12 19:22:03 2007
New Revision: 54146

URL: http://svn.digium.com/view/asterisk?view=rev&rev=54146
Log:
It's the beginnings of the automatic unregistration madness. Now the loader knows (at least so far only applications) what the module registers and during an unload it is capable of going through and unregistering each so that the module doesn't have to do it in it's unload_module function. In the case of app_echo this makes the need for unload_module non-existant, so it's now been replaced with a 'MINIMAL' loader declaration that has no unload_module requirement.

Modified:
    team/file/usecnt-cleanup/apps/app_echo.c
    team/file/usecnt-cleanup/include/asterisk/module.h
    team/file/usecnt-cleanup/include/asterisk/pbx.h
    team/file/usecnt-cleanup/main/loader.c
    team/file/usecnt-cleanup/main/pbx.c

Modified: team/file/usecnt-cleanup/apps/app_echo.c
URL: http://svn.digium.com/view/asterisk/team/file/usecnt-cleanup/apps/app_echo.c?view=diff&rev=54146&r1=54145&r2=54146
==============================================================================
--- team/file/usecnt-cleanup/apps/app_echo.c (original)
+++ team/file/usecnt-cleanup/apps/app_echo.c Mon Feb 12 19:22:03 2007
@@ -81,20 +81,9 @@
 	return res;
 }
 
-static int unload_module(void)
-{
-	int res;
-
-	res = ast_unregister_application(app);
-
-	ast_module_user_hangup_all();
-
-	return res;
-}
-
 static int load_module(void)
 {
 	return ast_register_application(app, echo_exec, synopsis, descrip, ast_module_info->self);
 }
 
-AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Simple Echo Application");
+AST_MODULE_INFO_MINIMAL(ASTERISK_GPL_KEY, "Simple Echo Application");

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=54146&r1=54145&r2=54146
==============================================================================
--- team/file/usecnt-cleanup/include/asterisk/module.h (original)
+++ team/file/usecnt-cleanup/include/asterisk/module.h Mon Feb 12 19:22:03 2007
@@ -64,6 +64,15 @@
 	AST_MODULE_LOAD_FAILURE = -1,	/*!< Module could not be loaded properly */
 };
 
+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 */
+};
+
 /*! 
  * \brief Load a module.
  * \param resource_name The name of the module to load.
@@ -216,6 +225,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);
 
 #if defined(__cplusplus) || defined(c_plusplus)
 #define AST_MODULE_INFO(keystr, flags_to_set, desc, load_func, unload_func, reload_func)	\
@@ -245,6 +256,13 @@
 			unload_module,		\
 			NULL			\
 		       )
+
+#define AST_MODULE_INFO_MINIMAL(keystr, desc)          \
+        AST_MODULE_INFO(keystr, AST_MODFLAG_DEFAULT, desc,      \
+                        load_module,                    \
+                        NULL                    \
+                       )
+
 #else
 /* forward declare this pointer in modules, so that macro/function
    calls that need it can get it, since it will actually be declared
@@ -274,6 +292,12 @@
 			.load = load_module,			\
 			.unload = unload_module,		\
 		       )
+
+#define AST_MODULE_INFO_MINIMAL(keystr, desc)          \
+        AST_MODULE_INFO(keystr, AST_MODFLAG_DEFAULT, desc,      \
+                        .load = load_module,                    \
+                       )
+
 #endif
 
 #if defined(__cplusplus) || defined(c_plusplus)

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=54146&r1=54145&r2=54146
==============================================================================
--- team/file/usecnt-cleanup/include/asterisk/pbx.h (original)
+++ team/file/usecnt-cleanup/include/asterisk/pbx.h Mon Feb 12 19:22:03 2007
@@ -330,6 +330,16 @@
  */
 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/loader.c
URL: http://svn.digium.com/view/asterisk/team/file/usecnt-cleanup/main/loader.c?view=diff&rev=54146&r1=54145&r2=54146
==============================================================================
--- team/file/usecnt-cleanup/main/loader.c (original)
+++ team/file/usecnt-cleanup/main/loader.c Mon Feb 12 19:22:03 2007
@@ -51,6 +51,7 @@
 #include "asterisk/rtp.h"
 #include "asterisk/http.h"
 #include "asterisk/lock.h"
+#include "asterisk/pbx.h"
 
 #ifdef DLFCNCOMPAT
 #include "asterisk/dlfcn-compat.h"
@@ -91,6 +92,7 @@
 	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_ENTRY(ast_module) entry;
 	char resource[0];
 };
@@ -469,6 +471,8 @@
 					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)
@@ -933,3 +937,8 @@
 	ast_atomic_fetchadd_int(&mod->usecount, -1);
 	ast_update_use_count();
 }
+
+void ast_module_registered(struct ast_module *mod, enum ast_module_registered registered)
+{
+	mod->registered |= registered;
+}

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=54146&r1=54145&r2=54146
==============================================================================
--- team/file/usecnt-cleanup/main/pbx.c (original)
+++ team/file/usecnt-cleanup/main/pbx.c Mon Feb 12 19:22:03 2007
@@ -2857,6 +2857,8 @@
 	}
 
 	strcpy(tmp->name, app);
+	if (mod)
+		ast_module_registered(mod, AST_MODULE_REGISTERED_APPLICATION);
 	tmp->module = mod;
 	tmp->execute = execute;
 	tmp->synopsis = synopsis;
@@ -3773,6 +3775,26 @@
 	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)



More information about the asterisk-commits mailing list