[svn-commits] file: branch file/usecnt-cleanup r54143 - in /team/file/usecnt-cleanup: chann...

svn-commits at lists.digium.com svn-commits at lists.digium.com
Mon Feb 12 17:42:38 MST 2007


Author: file
Date: Mon Feb 12 18:42:37 2007
New Revision: 54143

URL: http://svn.digium.com/view/asterisk?view=rev&rev=54143
Log:
Switch CLI commands over to using the module reference counting, but this time do it differently - use a macro to replace the old function's name and prefix the original one with __. Less work that way and modules automagically do things correctly in most cases.

Modified:
    team/file/usecnt-cleanup/channels/iax2-provision.c
    team/file/usecnt-cleanup/include/asterisk/cli.h
    team/file/usecnt-cleanup/main/asterisk.c
    team/file/usecnt-cleanup/main/cdr.c
    team/file/usecnt-cleanup/main/channel.c
    team/file/usecnt-cleanup/main/cli.c
    team/file/usecnt-cleanup/main/config.c
    team/file/usecnt-cleanup/main/db.c
    team/file/usecnt-cleanup/main/dnsmgr.c
    team/file/usecnt-cleanup/main/file.c
    team/file/usecnt-cleanup/main/frame.c
    team/file/usecnt-cleanup/main/http.c
    team/file/usecnt-cleanup/main/image.c
    team/file/usecnt-cleanup/main/logger.c
    team/file/usecnt-cleanup/main/manager.c
    team/file/usecnt-cleanup/main/pbx.c
    team/file/usecnt-cleanup/main/rtp.c
    team/file/usecnt-cleanup/main/translate.c
    team/file/usecnt-cleanup/main/udptl.c
    team/file/usecnt-cleanup/utils/ael_main.c

Modified: team/file/usecnt-cleanup/channels/iax2-provision.c
URL: http://svn.digium.com/view/asterisk/team/file/usecnt-cleanup/channels/iax2-provision.c?view=diff&rev=54143&r1=54142&r2=54143
==============================================================================
--- team/file/usecnt-cleanup/channels/iax2-provision.c (original)
+++ team/file/usecnt-cleanup/channels/iax2-provision.c Mon Feb 12 18:42:37 2007
@@ -474,7 +474,7 @@
 
 static int iax_provision_init(void)
 {
-	ast_cli_register_multiple(cli_iax2_provision, sizeof(cli_iax2_provision) / sizeof(struct ast_cli_entry));
+	__ast_cli_register_multiple(cli_iax2_provision, sizeof(cli_iax2_provision) / sizeof(struct ast_cli_entry), NULL);
 	provinit = 1;
 	return 0;
 }

Modified: team/file/usecnt-cleanup/include/asterisk/cli.h
URL: http://svn.digium.com/view/asterisk/team/file/usecnt-cleanup/include/asterisk/cli.h?view=diff&rev=54143&r1=54142&r2=54143
==============================================================================
--- team/file/usecnt-cleanup/include/asterisk/cli.h (original)
+++ team/file/usecnt-cleanup/include/asterisk/cli.h Mon Feb 12 18:42:37 2007
@@ -178,8 +178,7 @@
 	char *(*generator)(const char *line, const char *word, int pos, int n);
 	struct ast_cli_entry *deprecate_cmd;
 
-	int inuse; /*!< For keeping track of usage */
-	struct module *module;	/*!< module this belongs to */
+	struct ast_module *module; /*!< module this belongs to */
 	char *_full_cmd;	/*!< built at load time from cmda[] */
 	int cmdlen;		/*!< len up to the first invalid char [<{% */
 	/*! \brief This gets set in ast_cli_register()
@@ -228,14 +227,16 @@
  * Register your own command
  * Returns 0 on success, -1 on failure
  */
-int ast_cli_register(struct ast_cli_entry *e);
+#define ast_cli_register(a) __ast_cli_register(a, ast_module_info->self)
+int __ast_cli_register(struct ast_cli_entry *e, struct ast_module *mod);
 
 /*!
  * \brief Register multiple commands
  * \param e pointer to first cli entry to register
  * \param len number of entries to register
  */
-void ast_cli_register_multiple(struct ast_cli_entry *e, int len);
+#define ast_cli_register_multiple(a,b) __ast_cli_register_multiple(a, b, ast_module_info->self)
+void __ast_cli_register_multiple(struct ast_cli_entry *e, int len, struct ast_module *mod);
 
 /*! \brief Unregisters a command or an array of commands
  *

Modified: team/file/usecnt-cleanup/main/asterisk.c
URL: http://svn.digium.com/view/asterisk/team/file/usecnt-cleanup/main/asterisk.c?view=diff&rev=54143&r1=54142&r2=54143
==============================================================================
--- team/file/usecnt-cleanup/main/asterisk.c (original)
+++ team/file/usecnt-cleanup/main/asterisk.c Mon Feb 12 18:42:37 2007
@@ -2784,7 +2784,7 @@
 #endif	
 
 	time(&ast_startuptime);
-	ast_cli_register_multiple(cli_asterisk, sizeof(cli_asterisk) / sizeof(struct ast_cli_entry));
+	__ast_cli_register_multiple(cli_asterisk, sizeof(cli_asterisk) / sizeof(struct ast_cli_entry), NULL);
 
 	if (ast_opt_console) {
 		/* Console stuff now... */

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=54143&r1=54142&r2=54143
==============================================================================
--- team/file/usecnt-cleanup/main/cdr.c (original)
+++ team/file/usecnt-cleanup/main/cdr.c Mon Feb 12 18:42:37 2007
@@ -1107,7 +1107,7 @@
 			ast_log(LOG_ERROR, "Unable to start CDR thread.\n");
 			ast_sched_del(sched, cdr_sched);
 		} else {
-			ast_cli_register(&cli_submit);
+			__ast_cli_register(&cli_submit, NULL);
 			ast_register_atexit(ast_cdr_engine_term);
 			res = 0;
 		}
@@ -1148,7 +1148,7 @@
 		return -1;
 	}
 
-	ast_cli_register(&cli_status);
+	__ast_cli_register(&cli_status, NULL);
 
 	res = do_reload();
 	if (res) {

Modified: team/file/usecnt-cleanup/main/channel.c
URL: http://svn.digium.com/view/asterisk/team/file/usecnt-cleanup/main/channel.c?view=diff&rev=54143&r1=54142&r2=54143
==============================================================================
--- team/file/usecnt-cleanup/main/channel.c (original)
+++ team/file/usecnt-cleanup/main/channel.c Mon Feb 12 18:42:37 2007
@@ -4306,7 +4306,7 @@
 
 void ast_channels_init(void)
 {
-	ast_cli_register_multiple(cli_channel, sizeof(cli_channel) / sizeof(struct ast_cli_entry));
+	__ast_cli_register_multiple(cli_channel, sizeof(cli_channel) / sizeof(struct ast_cli_entry), NULL);
 }
 
 /*! \brief Print call group and pickup group ---*/

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=54143&r1=54142&r2=54143
==============================================================================
--- team/file/usecnt-cleanup/main/cli.c (original)
+++ team/file/usecnt-cleanup/main/cli.c Mon Feb 12 18:42:37 2007
@@ -1050,7 +1050,7 @@
 	for (e = builtins; e->cmda[0] != NULL; e++)
 		set_full_cmd(e);
 
-	ast_cli_register_multiple(cli_cli, sizeof(cli_cli) / sizeof(struct ast_cli_entry));
+	__ast_cli_register_multiple(cli_cli, sizeof(cli_cli) / sizeof(struct ast_cli_entry), NULL);
 }
 
 /*
@@ -1244,26 +1244,22 @@
 	if (e->deprecate_cmd) {
 		__ast_cli_unregister(e->deprecate_cmd, e);
 	}
-	if (e->inuse) {
-		ast_log(LOG_WARNING, "Can't remove command that is in use\n");
-	} else {
-		AST_LIST_LOCK(&helpers);
-		AST_LIST_REMOVE(&helpers, e, list);
-		AST_LIST_UNLOCK(&helpers);
-		free(e->_full_cmd);
-		e->_full_cmd = NULL;
-		if (e->new_handler) {
-			/* this is a new-style entry. Reset fields and free memory. */
-			bzero((char **)(e->cmda), sizeof(e->cmda));
-			free(e->command);
-			e->command = NULL;
-			e->usage = NULL;
-		}
+	AST_LIST_LOCK(&helpers);
+	AST_LIST_REMOVE(&helpers, e, list);
+	AST_LIST_UNLOCK(&helpers);
+	free(e->_full_cmd);
+	e->_full_cmd = NULL;
+	if (e->new_handler) {
+		/* this is a new-style entry. Reset fields and free memory. */
+		bzero((char **)(e->cmda), sizeof(e->cmda));
+		free(e->command);
+		e->command = NULL;
+		e->usage = NULL;
 	}
 	return 0;
 }
 
-static int __ast_cli_register(struct ast_cli_entry *e, struct ast_cli_entry *ed)
+static int ____ast_cli_register(struct ast_cli_entry *e, struct ast_cli_entry *ed, struct ast_module *mod)
 {
 	struct ast_cli_entry *cur;
 	int i, lf, ret = -1;
@@ -1333,7 +1329,7 @@
 
 	if (e->deprecate_cmd) {
 		/* This command deprecates another command.  Register that one also. */
-		__ast_cli_register(e->deprecate_cmd, e);
+		____ast_cli_register(e->deprecate_cmd, e, mod);
 	}
 	
 	return ret;
@@ -1346,20 +1342,20 @@
 }
 
 /* wrapper function, so we can register deprecated commands recursively */
-int ast_cli_register(struct ast_cli_entry *e)
-{
-	return __ast_cli_register(e, NULL);
+int __ast_cli_register(struct ast_cli_entry *e, struct ast_module *mod)
+{
+	return ____ast_cli_register(e, NULL, mod);
 }
 
 /*
  * register/unregister an array of entries.
  */
-void ast_cli_register_multiple(struct ast_cli_entry *e, int len)
+void __ast_cli_register_multiple(struct ast_cli_entry *e, int len, struct ast_module *mod)
 {
 	int i;
 
 	for (i = 0; i < len; i++)
-		ast_cli_register(e + i);
+		__ast_cli_register(e + i, mod);
 }
 
 void ast_cli_unregister_multiple(struct ast_cli_entry *e, int len)
@@ -1695,8 +1691,8 @@
 
 	AST_LIST_LOCK(&helpers);
 	e = find_cli(args + 1, 0);
-	if (e)
-		ast_atomic_fetchadd_int(&e->inuse, 1);
+	if (e && e->module)
+		ast_module_ref(e->module);
 	AST_LIST_UNLOCK(&helpers);
 	if (e == NULL) {
 		ast_cli(fd, "No such command '%s' (type 'help' for help)\n", find_best(args + 1));
@@ -1739,7 +1735,8 @@
 		AST_LIST_UNLOCK(&helpers);
 		break;
 	}
-	ast_atomic_fetchadd_int(&e->inuse, -1);
+	if (e->module)
+		ast_module_unref(e->module);
 done:
 	free(dup);
 	return 0;

Modified: team/file/usecnt-cleanup/main/config.c
URL: http://svn.digium.com/view/asterisk/team/file/usecnt-cleanup/main/config.c?view=diff&rev=54143&r1=54142&r2=54143
==============================================================================
--- team/file/usecnt-cleanup/main/config.c (original)
+++ team/file/usecnt-cleanup/main/config.c Mon Feb 12 18:42:37 2007
@@ -1453,6 +1453,6 @@
 
 int register_config_cli() 
 {
-	ast_cli_register_multiple(cli_config, sizeof(cli_config) / sizeof(struct ast_cli_entry));
+	__ast_cli_register_multiple(cli_config, sizeof(cli_config) / sizeof(struct ast_cli_entry), NULL);
 	return 0;
 }

Modified: team/file/usecnt-cleanup/main/db.c
URL: http://svn.digium.com/view/asterisk/team/file/usecnt-cleanup/main/db.c?view=diff&rev=54143&r1=54142&r2=54143
==============================================================================
--- team/file/usecnt-cleanup/main/db.c (original)
+++ team/file/usecnt-cleanup/main/db.c Mon Feb 12 18:42:37 2007
@@ -640,7 +640,7 @@
 int astdb_init(void)
 {
 	dbinit();
-	ast_cli_register_multiple(cli_database, sizeof(cli_database) / sizeof(struct ast_cli_entry));
+	__ast_cli_register_multiple(cli_database, sizeof(cli_database) / sizeof(struct ast_cli_entry), NULL);
 	ast_manager_register("DBGet", EVENT_FLAG_SYSTEM, manager_dbget, "Get DB Entry");
 	ast_manager_register("DBPut", EVENT_FLAG_SYSTEM, manager_dbput, "Put DB Entry");
 	ast_manager_register("DBDel", EVENT_FLAG_SYSTEM, manager_dbdel, "Delete DB Entry");

Modified: team/file/usecnt-cleanup/main/dnsmgr.c
URL: http://svn.digium.com/view/asterisk/team/file/usecnt-cleanup/main/dnsmgr.c?view=diff&rev=54143&r1=54142&r2=54143
==============================================================================
--- team/file/usecnt-cleanup/main/dnsmgr.c (original)
+++ team/file/usecnt-cleanup/main/dnsmgr.c Mon Feb 12 18:42:37 2007
@@ -339,8 +339,8 @@
 		ast_log(LOG_ERROR, "Unable to create schedule context.\n");
 		return -1;
 	}
-	ast_cli_register(&cli_reload);
-	ast_cli_register(&cli_status);
+	__ast_cli_register(&cli_reload, NULL);
+	__ast_cli_register(&cli_status, NULL);
 	return do_reload(1);
 }
 
@@ -394,7 +394,7 @@
 			if (ast_pthread_create_background(&refresh_thread, NULL, do_refresh, NULL) < 0) {
 				ast_log(LOG_ERROR, "Unable to start refresh thread.\n");
 			}
-			ast_cli_register(&cli_refresh);
+			__ast_cli_register(&cli_refresh, NULL);
 		}
 		/* make a background refresh happen right away */
 		refresh_sched = ast_sched_add_variable(sched, 100, refresh_list, &master_refresh_info, 1);

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=54143&r1=54142&r2=54143
==============================================================================
--- team/file/usecnt-cleanup/main/file.c (original)
+++ team/file/usecnt-cleanup/main/file.c Mon Feb 12 18:42:37 2007
@@ -1148,6 +1148,6 @@
 
 int ast_file_init(void)
 {
-	ast_cli_register_multiple(cli_file, sizeof(cli_file) / sizeof(struct ast_cli_entry));
+	__ast_cli_register_multiple(cli_file, sizeof(cli_file) / sizeof(struct ast_cli_entry), NULL);
 	return 0;
 }

Modified: team/file/usecnt-cleanup/main/frame.c
URL: http://svn.digium.com/view/asterisk/team/file/usecnt-cleanup/main/frame.c?view=diff&rev=54143&r1=54142&r2=54143
==============================================================================
--- team/file/usecnt-cleanup/main/frame.c (original)
+++ team/file/usecnt-cleanup/main/frame.c Mon Feb 12 18:42:37 2007
@@ -929,7 +929,7 @@
 
 int init_framer(void)
 {
-	ast_cli_register_multiple(my_clis, sizeof(my_clis) / sizeof(struct ast_cli_entry));
+	__ast_cli_register_multiple(my_clis, sizeof(my_clis) / sizeof(struct ast_cli_entry), NULL);
 	return 0;	
 }
 

Modified: team/file/usecnt-cleanup/main/http.c
URL: http://svn.digium.com/view/asterisk/team/file/usecnt-cleanup/main/http.c?view=diff&rev=54143&r1=54142&r2=54143
==============================================================================
--- team/file/usecnt-cleanup/main/http.c (original)
+++ team/file/usecnt-cleanup/main/http.c Mon Feb 12 18:42:37 2007
@@ -1006,6 +1006,6 @@
 {
 	ast_http_uri_link(&statusuri);
 	ast_http_uri_link(&staticuri);
-	ast_cli_register_multiple(cli_http, sizeof(cli_http) / sizeof(struct ast_cli_entry));
+	__ast_cli_register_multiple(cli_http, sizeof(cli_http) / sizeof(struct ast_cli_entry), NULL);
 	return __ast_http_load(0);
 }

Modified: team/file/usecnt-cleanup/main/image.c
URL: http://svn.digium.com/view/asterisk/team/file/usecnt-cleanup/main/image.c?view=diff&rev=54143&r1=54142&r2=54143
==============================================================================
--- team/file/usecnt-cleanup/main/image.c (original)
+++ team/file/usecnt-cleanup/main/image.c Mon Feb 12 18:42:37 2007
@@ -205,6 +205,6 @@
 
 int ast_image_init(void)
 {
-	ast_cli_register_multiple(cli_image, sizeof(cli_image) / sizeof(struct ast_cli_entry));
+	__ast_cli_register_multiple(cli_image, sizeof(cli_image) / sizeof(struct ast_cli_entry), NULL);
 	return 0;
 }

Modified: team/file/usecnt-cleanup/main/logger.c
URL: http://svn.digium.com/view/asterisk/team/file/usecnt-cleanup/main/logger.c?view=diff&rev=54143&r1=54142&r2=54143
==============================================================================
--- team/file/usecnt-cleanup/main/logger.c (original)
+++ team/file/usecnt-cleanup/main/logger.c Mon Feb 12 18:42:37 2007
@@ -792,7 +792,7 @@
 	}
 
 	/* register the logger cli commands */
-	ast_cli_register_multiple(cli_logger, sizeof(cli_logger) / sizeof(struct ast_cli_entry));
+	__ast_cli_register_multiple(cli_logger, sizeof(cli_logger) / sizeof(struct ast_cli_entry), NULL);
 
 	mkdir(ast_config_AST_LOG_DIR, 0755);
   

Modified: team/file/usecnt-cleanup/main/manager.c
URL: http://svn.digium.com/view/asterisk/team/file/usecnt-cleanup/main/manager.c?view=diff&rev=54143&r1=54142&r2=54143
==============================================================================
--- team/file/usecnt-cleanup/main/manager.c (original)
+++ team/file/usecnt-cleanup/main/manager.c Mon Feb 12 18:42:37 2007
@@ -2968,7 +2968,7 @@
 		ast_manager_register2("UserEvent", EVENT_FLAG_USER, action_userevent, "Send an arbitrary event", mandescr_userevent);
 		ast_manager_register2("WaitEvent", 0, action_waitevent, "Wait for an event to occur", mandescr_waitevent);
 
-		ast_cli_register_multiple(cli_manager, sizeof(cli_manager) / sizeof(struct ast_cli_entry));
+		__ast_cli_register_multiple(cli_manager, sizeof(cli_manager) / sizeof(struct ast_cli_entry), NULL);
 		ast_extension_state_add(NULL, NULL, manager_state_cb, NULL);
 		registered = 1;
 		/* Append placeholder event so master_eventq never runs dry */

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=54143&r1=54142&r2=54143
==============================================================================
--- team/file/usecnt-cleanup/main/pbx.c (original)
+++ team/file/usecnt-cleanup/main/pbx.c Mon Feb 12 18:42:37 2007
@@ -5968,7 +5968,7 @@
 		ast_verbose( "Asterisk PBX Core Initializing\n");
 		ast_verbose( "Registering builtin applications:\n");
 	}
-	ast_cli_register_multiple(pbx_cli, sizeof(pbx_cli) / sizeof(struct ast_cli_entry));
+	__ast_cli_register_multiple(pbx_cli, sizeof(pbx_cli) / sizeof(struct ast_cli_entry), NULL);
 
 	/* Register builtin applications */
 	for (x=0; x<sizeof(builtins) / sizeof(struct pbx_builtin); x++) {

Modified: team/file/usecnt-cleanup/main/rtp.c
URL: http://svn.digium.com/view/asterisk/team/file/usecnt-cleanup/main/rtp.c?view=diff&rev=54143&r1=54142&r2=54143
==============================================================================
--- team/file/usecnt-cleanup/main/rtp.c (original)
+++ team/file/usecnt-cleanup/main/rtp.c Mon Feb 12 18:42:37 2007
@@ -3671,7 +3671,7 @@
 /*! \brief Initialize the RTP system in Asterisk */
 void ast_rtp_init(void)
 {
-	ast_cli_register_multiple(cli_rtp, sizeof(cli_rtp) / sizeof(struct ast_cli_entry));
+	__ast_cli_register_multiple(cli_rtp, sizeof(cli_rtp) / sizeof(struct ast_cli_entry), NULL);
 	ast_rtp_reload();
 }
 

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=54143&r1=54142&r2=54143
==============================================================================
--- team/file/usecnt-cleanup/main/translate.c (original)
+++ team/file/usecnt-cleanup/main/translate.c Mon Feb 12 18:42:37 2007
@@ -635,7 +635,7 @@
 	}
 
 	if (!added_cli) {
-		ast_cli_register_multiple(cli_translate, sizeof(cli_translate) / sizeof(struct ast_cli_entry));
+		__ast_cli_register_multiple(cli_translate, sizeof(cli_translate) / sizeof(struct ast_cli_entry), NULL);
 		added_cli++;
 	}
 

Modified: team/file/usecnt-cleanup/main/udptl.c
URL: http://svn.digium.com/view/asterisk/team/file/usecnt-cleanup/main/udptl.c?view=diff&rev=54143&r1=54142&r2=54143
==============================================================================
--- team/file/usecnt-cleanup/main/udptl.c (original)
+++ team/file/usecnt-cleanup/main/udptl.c Mon Feb 12 18:42:37 2007
@@ -1285,6 +1285,6 @@
 
 void ast_udptl_init(void)
 {
-	ast_cli_register_multiple(cli_udptl, sizeof(cli_udptl) / sizeof(struct ast_cli_entry));
+	__ast_cli_register_multiple(cli_udptl, sizeof(cli_udptl) / sizeof(struct ast_cli_entry), NULL);
 	ast_udptl_reload();
 }

Modified: team/file/usecnt-cleanup/utils/ael_main.c
URL: http://svn.digium.com/view/asterisk/team/file/usecnt-cleanup/utils/ael_main.c?view=diff&rev=54143&r1=54142&r2=54143
==============================================================================
--- team/file/usecnt-cleanup/utils/ael_main.c (original)
+++ team/file/usecnt-cleanup/utils/ael_main.c Mon Feb 12 18:42:37 2007
@@ -75,7 +75,7 @@
 char ast_config_AST_VAR_DIR[PATH_MAX];
 
 void ast_add_profile(void);
-void ast_cli_register_multiple(void);
+void __ast_cli_register_multiple(void);
 void ast_register_file_version(void);
 void ast_unregister_file_version(void);
 int ast_add_extension2(struct ast_context *con,
@@ -134,7 +134,7 @@
 }
 
 
-void ast_cli_register_multiple(void)
+void __ast_cli_register_multiple(void)
 {
 	if(!no_comp)
         	printf("Executed ast_cli_register_multiple();\n");



More information about the svn-commits mailing list